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.

251917 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. #ifndef JUCE_STRINGS_ARE_UNICODE
  217. #define JUCE_STRINGS_ARE_UNICODE 1
  218. #endif
  219. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  220. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  221. #undef JUCE_QUICKTIME
  222. #define JUCE_QUICKTIME 0
  223. #undef JUCE_OPENGL
  224. #define JUCE_OPENGL 0
  225. #undef JUCE_USE_CDBURNER
  226. #define JUCE_USE_CDBURNER 0
  227. #undef JUCE_USE_CDREADER
  228. #define JUCE_USE_CDREADER 0
  229. #undef JUCE_WEB_BROWSER
  230. #define JUCE_WEB_BROWSER 0
  231. #undef JUCE_PLUGINHOST_AU
  232. #define JUCE_PLUGINHOST_AU 0
  233. #undef JUCE_PLUGINHOST_VST
  234. #define JUCE_PLUGINHOST_VST 0
  235. #endif
  236. #endif
  237. /*** End of inlined file: juce_Config.h ***/
  238. // FORCE_AMALGAMATOR_INCLUDE
  239. #ifndef JUCE_BUILD_CORE
  240. #define JUCE_BUILD_CORE 1
  241. #endif
  242. #ifndef JUCE_BUILD_MISC
  243. #define JUCE_BUILD_MISC 1
  244. #endif
  245. #ifndef JUCE_BUILD_GUI
  246. #define JUCE_BUILD_GUI 1
  247. #endif
  248. #ifndef JUCE_BUILD_NATIVE
  249. #define JUCE_BUILD_NATIVE 1
  250. #endif
  251. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  252. #undef JUCE_BUILD_MISC
  253. #undef JUCE_BUILD_GUI
  254. #endif
  255. //==============================================================================
  256. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  257. #if JUCE_WINDOWS
  258. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  259. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  260. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  261. #ifndef STRICT
  262. #define STRICT 1
  263. #endif
  264. #undef WIN32_LEAN_AND_MEAN
  265. #define WIN32_LEAN_AND_MEAN 1
  266. #ifdef _MSC_VER
  267. #pragma warning (push)
  268. #pragma warning (disable : 4100 4201 4514 4312 4995)
  269. #endif
  270. #define _WIN32_WINNT 0x0500
  271. #define _UNICODE 1
  272. #define UNICODE 1
  273. #ifndef _WIN32_IE
  274. #define _WIN32_IE 0x0400
  275. #endif
  276. #include <windows.h>
  277. #include <windowsx.h>
  278. #include <commdlg.h>
  279. #include <shellapi.h>
  280. #include <mmsystem.h>
  281. #include <vfw.h>
  282. #include <tchar.h>
  283. #include <stddef.h>
  284. #include <ctime>
  285. #include <wininet.h>
  286. #include <nb30.h>
  287. #include <iphlpapi.h>
  288. #include <mapi.h>
  289. #include <float.h>
  290. #include <process.h>
  291. #include <Exdisp.h>
  292. #include <exdispid.h>
  293. #include <shlobj.h>
  294. #if ! JUCE_MINGW
  295. #include <crtdbg.h>
  296. #include <comutil.h>
  297. #endif
  298. #if JUCE_OPENGL
  299. #include <gl/gl.h>
  300. #endif
  301. #undef PACKED
  302. #if JUCE_ASIO
  303. #include "iasiodrv.h"
  304. #endif
  305. #if JUCE_USE_CDBURNER
  306. #include <imapi.h>
  307. #include <imapierror.h>
  308. #endif
  309. #if JUCE_USE_CAMERA
  310. #include <dshow.h>
  311. #include <qedit.h>
  312. #endif
  313. #if JUCE_WASAPI
  314. #include <MMReg.h>
  315. #include <mmdeviceapi.h>
  316. #include <Audioclient.h>
  317. #include <Avrt.h>
  318. #include <functiondiscoverykeys.h>
  319. #endif
  320. #if JUCE_QUICKTIME
  321. #include <Movies.h>
  322. #include <QTML.h>
  323. #include <QuickTimeComponents.h>
  324. #include <MediaHandlers.h>
  325. #include <ImageCodec.h>
  326. #import <QTOLibrary.dll>
  327. #import <QTOControl.dll>
  328. #endif
  329. #ifdef _MSC_VER
  330. #pragma warning (pop)
  331. #endif
  332. template <class T>
  333. class ComSmartPtr
  334. {
  335. public:
  336. ComSmartPtr() throw() : p (0) {}
  337. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  338. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  339. ~ComSmartPtr() { if (p != 0) p->Release(); }
  340. operator T*() const throw() { return p; }
  341. T& operator*() const throw() { return *p; }
  342. T** operator&() throw() { return &p; }
  343. T* operator->() const throw() { return p; }
  344. T* operator= (T* const newP)
  345. {
  346. if (newP != 0)
  347. newP->AddRef();
  348. if (p != 0)
  349. p->Release();
  350. p = newP;
  351. return newP;
  352. }
  353. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  354. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  355. {
  356. #ifndef __MINGW32__
  357. operator= (0);
  358. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  359. #else
  360. return S_FALSE;
  361. #endif
  362. }
  363. T* p;
  364. };
  365. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  366. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  367. #elif JUCE_LINUX
  368. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  369. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  370. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  371. #include <sched.h>
  372. #include <pthread.h>
  373. #include <sys/time.h>
  374. #include <errno.h>
  375. #include <sys/stat.h>
  376. #include <sys/dir.h>
  377. #include <sys/ptrace.h>
  378. #include <sys/vfs.h>
  379. #include <sys/wait.h>
  380. #include <fnmatch.h>
  381. #include <utime.h>
  382. #include <pwd.h>
  383. #include <fcntl.h>
  384. #include <dlfcn.h>
  385. #include <netdb.h>
  386. #include <arpa/inet.h>
  387. #include <netinet/in.h>
  388. #include <sys/types.h>
  389. #include <sys/ioctl.h>
  390. #include <sys/socket.h>
  391. #include <linux/if.h>
  392. #include <sys/sysinfo.h>
  393. #include <sys/file.h>
  394. #include <signal.h>
  395. #include <ft2build.h>
  396. #include FT_FREETYPE_H
  397. #include <X11/Xlib.h>
  398. #include <X11/Xatom.h>
  399. #include <X11/Xresource.h>
  400. #include <X11/Xutil.h>
  401. #include <X11/Xmd.h>
  402. #include <X11/keysym.h>
  403. #include <X11/cursorfont.h>
  404. #if JUCE_USE_XINERAMA
  405. #include <X11/extensions/Xinerama.h>
  406. #endif
  407. #if JUCE_USE_XSHM
  408. #include <X11/extensions/XShm.h>
  409. #include <sys/shm.h>
  410. #include <sys/ipc.h>
  411. #endif
  412. #if JUCE_OPENGL
  413. #include <GL/glx.h>
  414. #endif
  415. #undef KeyPress
  416. #if JUCE_ALSA
  417. #include <alsa/asoundlib.h>
  418. #endif
  419. #if JUCE_JACK
  420. #include <jack/jack.h>
  421. //#include <jack/transport.h>
  422. #endif
  423. #undef SIZEOF
  424. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  425. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  426. #elif JUCE_MAC || JUCE_IPHONE
  427. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  428. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  429. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  430. #define USE_COREGRAPHICS_RENDERING 1
  431. #if JUCE_IPHONE
  432. #import <Foundation/Foundation.h>
  433. #import <UIKit/UIKit.h>
  434. #import <AudioToolbox/AudioToolbox.h>
  435. #import <AVFoundation/AVFoundation.h>
  436. #import <CoreData/CoreData.h>
  437. #import <MobileCoreServices/MobileCoreServices.h>
  438. #include <sys/fcntl.h>
  439. #else
  440. #import <Cocoa/Cocoa.h>
  441. #import <CoreAudio/HostTime.h>
  442. #import <CoreAudio/AudioHardware.h>
  443. #import <CoreMIDI/MIDIServices.h>
  444. #import <QTKit/QTKit.h>
  445. #import <WebKit/WebKit.h>
  446. #import <DiscRecording/DiscRecording.h>
  447. #import <IOKit/IOKitLib.h>
  448. #import <IOKit/IOCFPlugIn.h>
  449. #import <IOKit/hid/IOHIDLib.h>
  450. #import <IOKit/hid/IOHIDKeys.h>
  451. #import <IOKit/pwr_mgt/IOPMLib.h>
  452. #include <Carbon/Carbon.h>
  453. #include <sys/dir.h>
  454. #include <sys/socket.h>
  455. #endif
  456. #include <sys/sysctl.h>
  457. #include <sys/stat.h>
  458. #include <sys/param.h>
  459. #include <sys/mount.h>
  460. #include <fnmatch.h>
  461. #include <utime.h>
  462. #include <dlfcn.h>
  463. #include <ifaddrs.h>
  464. #include <net/if_dl.h>
  465. #include <mach/mach_time.h>
  466. #if MACOS_10_4_OR_EARLIER
  467. #include <GLUT/glut.h>
  468. #endif
  469. #if ! CGFLOAT_DEFINED
  470. #define CGFloat float
  471. #endif
  472. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  473. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  474. #else
  475. #error "Unknown platform!"
  476. #endif
  477. #endif
  478. //==============================================================================
  479. #define DONT_SET_USING_JUCE_NAMESPACE 1
  480. #undef max
  481. #undef min
  482. #define NO_DUMMY_DECL
  483. #if JUCE_BUILD_NATIVE
  484. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  485. #endif
  486. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  487. #pragma warning (disable: 4309 4305)
  488. #endif
  489. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  490. BEGIN_JUCE_NAMESPACE
  491. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  492. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  493. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  494. class CarbonViewWrapperComponent : public Component,
  495. public ComponentMovementWatcher,
  496. public Timer
  497. {
  498. public:
  499. CarbonViewWrapperComponent()
  500. : ComponentMovementWatcher (this),
  501. wrapperWindow (0),
  502. embeddedView (0),
  503. recursiveResize (false)
  504. {
  505. }
  506. virtual ~CarbonViewWrapperComponent()
  507. {
  508. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  509. }
  510. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  511. virtual void removeView (HIViewRef embeddedView) = 0;
  512. virtual void mouseDown (int x, int y) {}
  513. virtual void paint() {}
  514. virtual bool getEmbeddedViewSize (int& w, int& h)
  515. {
  516. if (embeddedView == 0)
  517. return false;
  518. HIRect bounds;
  519. HIViewGetBounds (embeddedView, &bounds);
  520. w = jmax (1, roundToInt (bounds.size.width));
  521. h = jmax (1, roundToInt (bounds.size.height));
  522. return true;
  523. }
  524. void createWindow()
  525. {
  526. if (wrapperWindow == 0)
  527. {
  528. Rect r;
  529. r.left = getScreenX();
  530. r.top = getScreenY();
  531. r.right = r.left + getWidth();
  532. r.bottom = r.top + getHeight();
  533. CreateNewWindow (kDocumentWindowClass,
  534. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  535. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  536. &r, &wrapperWindow);
  537. jassert (wrapperWindow != 0);
  538. if (wrapperWindow == 0)
  539. return;
  540. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  541. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  542. [ownerWindow addChildWindow: carbonWindow
  543. ordered: NSWindowAbove];
  544. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  545. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  546. { kEventClassWindow, kEventWindowHandleDeactivate } };
  547. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  548. InstallWindowEventHandler (wrapperWindow, upp,
  549. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  550. windowEventTypes, this, &eventHandlerRef);
  551. setOurSizeToEmbeddedViewSize();
  552. setEmbeddedWindowToOurSize();
  553. creationTime = Time::getCurrentTime();
  554. }
  555. }
  556. void deleteWindow()
  557. {
  558. removeView (embeddedView);
  559. embeddedView = 0;
  560. if (wrapperWindow != 0)
  561. {
  562. RemoveEventHandler (eventHandlerRef);
  563. DisposeWindow (wrapperWindow);
  564. wrapperWindow = 0;
  565. }
  566. }
  567. void setOurSizeToEmbeddedViewSize()
  568. {
  569. int w, h;
  570. if (getEmbeddedViewSize (w, h))
  571. {
  572. if (w != getWidth() || h != getHeight())
  573. {
  574. startTimer (50);
  575. setSize (w, h);
  576. if (getParentComponent() != 0)
  577. getParentComponent()->setSize (w, h);
  578. }
  579. else
  580. {
  581. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  582. }
  583. }
  584. else
  585. {
  586. stopTimer();
  587. }
  588. }
  589. void setEmbeddedWindowToOurSize()
  590. {
  591. if (! recursiveResize)
  592. {
  593. recursiveResize = true;
  594. if (embeddedView != 0)
  595. {
  596. HIRect r;
  597. r.origin.x = 0;
  598. r.origin.y = 0;
  599. r.size.width = (float) getWidth();
  600. r.size.height = (float) getHeight();
  601. HIViewSetFrame (embeddedView, &r);
  602. }
  603. if (wrapperWindow != 0)
  604. {
  605. Rect wr;
  606. wr.left = getScreenX();
  607. wr.top = getScreenY();
  608. wr.right = wr.left + getWidth();
  609. wr.bottom = wr.top + getHeight();
  610. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  611. ShowWindow (wrapperWindow);
  612. }
  613. recursiveResize = false;
  614. }
  615. }
  616. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  617. {
  618. setEmbeddedWindowToOurSize();
  619. }
  620. void componentPeerChanged()
  621. {
  622. deleteWindow();
  623. createWindow();
  624. }
  625. void componentVisibilityChanged (Component&)
  626. {
  627. if (isShowing())
  628. createWindow();
  629. else
  630. deleteWindow();
  631. setEmbeddedWindowToOurSize();
  632. }
  633. static void recursiveHIViewRepaint (HIViewRef view)
  634. {
  635. HIViewSetNeedsDisplay (view, true);
  636. HIViewRef child = HIViewGetFirstSubview (view);
  637. while (child != 0)
  638. {
  639. recursiveHIViewRepaint (child);
  640. child = HIViewGetNextView (child);
  641. }
  642. }
  643. void timerCallback()
  644. {
  645. setOurSizeToEmbeddedViewSize();
  646. // To avoid strange overpainting problems when the UI is first opened, we'll
  647. // repaint it a few times during the first second that it's on-screen..
  648. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  649. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  650. }
  651. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  652. EventRef event)
  653. {
  654. switch (GetEventKind (event))
  655. {
  656. case kEventWindowHandleDeactivate:
  657. ActivateWindow (wrapperWindow, TRUE);
  658. break;
  659. case kEventWindowGetClickActivation:
  660. {
  661. getTopLevelComponent()->toFront (false);
  662. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  663. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  664. sizeof (ClickActivationResult), &howToHandleClick);
  665. HIViewSetNeedsDisplay (embeddedView, true);
  666. }
  667. break;
  668. }
  669. return noErr;
  670. }
  671. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  672. EventRef event, void* userData)
  673. {
  674. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  675. }
  676. protected:
  677. WindowRef wrapperWindow;
  678. HIViewRef embeddedView;
  679. bool recursiveResize;
  680. Time creationTime;
  681. EventHandlerRef eventHandlerRef;
  682. };
  683. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  684. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  685. END_JUCE_NAMESPACE
  686. #endif
  687. #define JUCE_AMALGAMATED_TEMPLATE 1
  688. //==============================================================================
  689. #if JUCE_BUILD_CORE
  690. /*** Start of inlined file: juce_FileLogger.cpp ***/
  691. BEGIN_JUCE_NAMESPACE
  692. FileLogger::FileLogger (const File& logFile_,
  693. const String& welcomeMessage,
  694. const int maxInitialFileSizeBytes)
  695. : logFile (logFile_)
  696. {
  697. if (maxInitialFileSizeBytes >= 0)
  698. trimFileSize (maxInitialFileSizeBytes);
  699. if (! logFile_.exists())
  700. {
  701. // do this so that the parent directories get created..
  702. logFile_.create();
  703. }
  704. logStream = logFile_.createOutputStream (256);
  705. jassert (logStream != 0);
  706. String welcome;
  707. welcome << "\r\n**********************************************************\r\n"
  708. << welcomeMessage
  709. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  710. << "\r\n";
  711. logMessage (welcome);
  712. }
  713. FileLogger::~FileLogger()
  714. {
  715. }
  716. void FileLogger::logMessage (const String& message)
  717. {
  718. if (logStream != 0)
  719. {
  720. DBG (message);
  721. const ScopedLock sl (logLock);
  722. (*logStream) << message << T("\r\n");
  723. logStream->flush();
  724. }
  725. }
  726. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  727. {
  728. if (maxFileSizeBytes <= 0)
  729. {
  730. logFile.deleteFile();
  731. }
  732. else
  733. {
  734. const int64 fileSize = logFile.getSize();
  735. if (fileSize > maxFileSizeBytes)
  736. {
  737. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  738. jassert (in != 0);
  739. if (in != 0)
  740. {
  741. in->setPosition (fileSize - maxFileSizeBytes);
  742. String content;
  743. {
  744. MemoryBlock contentToSave;
  745. contentToSave.setSize (maxFileSizeBytes + 4);
  746. contentToSave.fillWith (0);
  747. in->read (contentToSave.getData(), maxFileSizeBytes);
  748. in = 0;
  749. content = contentToSave.toString();
  750. }
  751. int newStart = 0;
  752. while (newStart < fileSize
  753. && content[newStart] != '\n'
  754. && content[newStart] != '\r')
  755. ++newStart;
  756. logFile.deleteFile();
  757. logFile.appendText (content.substring (newStart), false, false);
  758. }
  759. }
  760. }
  761. }
  762. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  763. const String& logFileName,
  764. const String& welcomeMessage,
  765. const int maxInitialFileSizeBytes)
  766. {
  767. #if JUCE_MAC
  768. File logFile ("~/Library/Logs");
  769. logFile = logFile.getChildFile (logFileSubDirectoryName)
  770. .getChildFile (logFileName);
  771. #else
  772. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  773. if (logFile.isDirectory())
  774. {
  775. logFile = logFile.getChildFile (logFileSubDirectoryName)
  776. .getChildFile (logFileName);
  777. }
  778. #endif
  779. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  780. }
  781. END_JUCE_NAMESPACE
  782. /*** End of inlined file: juce_FileLogger.cpp ***/
  783. /*** Start of inlined file: juce_Logger.cpp ***/
  784. BEGIN_JUCE_NAMESPACE
  785. Logger::Logger()
  786. {
  787. }
  788. Logger::~Logger()
  789. {
  790. }
  791. static Logger* currentLogger = 0;
  792. void Logger::setCurrentLogger (Logger* const newLogger,
  793. const bool deleteOldLogger)
  794. {
  795. Logger* const oldLogger = currentLogger;
  796. currentLogger = newLogger;
  797. if (deleteOldLogger)
  798. delete oldLogger;
  799. }
  800. void Logger::writeToLog (const String& message)
  801. {
  802. if (currentLogger != 0)
  803. currentLogger->logMessage (message);
  804. else
  805. outputDebugString (message);
  806. }
  807. #if JUCE_LOG_ASSERTIONS
  808. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  809. {
  810. String m ("JUCE Assertion failure in ");
  811. m << filename << ", line " << lineNum;
  812. Logger::writeToLog (m);
  813. }
  814. #endif
  815. END_JUCE_NAMESPACE
  816. /*** End of inlined file: juce_Logger.cpp ***/
  817. /*** Start of inlined file: juce_Random.cpp ***/
  818. BEGIN_JUCE_NAMESPACE
  819. Random::Random (const int64 seedValue) throw()
  820. : seed (seedValue)
  821. {
  822. }
  823. Random::~Random() throw()
  824. {
  825. }
  826. void Random::setSeed (const int64 newSeed) throw()
  827. {
  828. seed = newSeed;
  829. }
  830. void Random::combineSeed (const int64 seedValue) throw()
  831. {
  832. seed ^= nextInt64() ^ seedValue;
  833. }
  834. void Random::setSeedRandomly()
  835. {
  836. combineSeed ((int64) (pointer_sized_int) this);
  837. combineSeed (Time::getMillisecondCounter());
  838. combineSeed (Time::getHighResolutionTicks());
  839. combineSeed (Time::getHighResolutionTicksPerSecond());
  840. combineSeed (Time::currentTimeMillis());
  841. }
  842. int Random::nextInt() throw()
  843. {
  844. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  845. return (int) (seed >> 16);
  846. }
  847. int Random::nextInt (const int maxValue) throw()
  848. {
  849. jassert (maxValue > 0);
  850. return (nextInt() & 0x7fffffff) % maxValue;
  851. }
  852. int64 Random::nextInt64() throw()
  853. {
  854. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  855. }
  856. bool Random::nextBool() throw()
  857. {
  858. return (nextInt() & 0x80000000) != 0;
  859. }
  860. float Random::nextFloat() throw()
  861. {
  862. return ((uint32) nextInt()) / (float) 0xffffffff;
  863. }
  864. double Random::nextDouble() throw()
  865. {
  866. return ((uint32) nextInt()) / (double) 0xffffffff;
  867. }
  868. const BitArray Random::nextLargeNumber (const BitArray& maximumValue) throw()
  869. {
  870. BitArray n;
  871. do
  872. {
  873. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  874. }
  875. while (n.compare (maximumValue) >= 0);
  876. return n;
  877. }
  878. void Random::fillBitsRandomly (BitArray& arrayToChange, int startBit, int numBits) throw()
  879. {
  880. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  881. while ((startBit & 31) != 0 && numBits > 0)
  882. {
  883. arrayToChange.setBit (startBit++, nextBool());
  884. --numBits;
  885. }
  886. while (numBits >= 32)
  887. {
  888. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  889. startBit += 32;
  890. numBits -= 32;
  891. }
  892. while (--numBits >= 0)
  893. arrayToChange.setBit (startBit + numBits, nextBool());
  894. }
  895. Random& Random::getSystemRandom() throw()
  896. {
  897. static Random sysRand (1);
  898. return sysRand;
  899. }
  900. END_JUCE_NAMESPACE
  901. /*** End of inlined file: juce_Random.cpp ***/
  902. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  903. BEGIN_JUCE_NAMESPACE
  904. RelativeTime::RelativeTime (const double seconds_) throw()
  905. : seconds (seconds_)
  906. {
  907. }
  908. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  909. : seconds (other.seconds)
  910. {
  911. }
  912. RelativeTime::~RelativeTime() throw()
  913. {
  914. }
  915. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  916. {
  917. return RelativeTime (milliseconds * 0.001);
  918. }
  919. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  920. {
  921. return RelativeTime (milliseconds * 0.001);
  922. }
  923. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  924. {
  925. return RelativeTime (numberOfMinutes * 60.0);
  926. }
  927. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  928. {
  929. return RelativeTime (numberOfHours * (60.0 * 60.0));
  930. }
  931. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  932. {
  933. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  934. }
  935. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  936. {
  937. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  938. }
  939. int64 RelativeTime::inMilliseconds() const throw()
  940. {
  941. return (int64)(seconds * 1000.0);
  942. }
  943. double RelativeTime::inMinutes() const throw()
  944. {
  945. return seconds / 60.0;
  946. }
  947. double RelativeTime::inHours() const throw()
  948. {
  949. return seconds / (60.0 * 60.0);
  950. }
  951. double RelativeTime::inDays() const throw()
  952. {
  953. return seconds / (60.0 * 60.0 * 24.0);
  954. }
  955. double RelativeTime::inWeeks() const throw()
  956. {
  957. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  958. }
  959. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  960. {
  961. if (seconds < 0.001 && seconds > -0.001)
  962. return returnValueForZeroTime;
  963. String result;
  964. if (seconds < 0)
  965. result = T("-");
  966. int fieldsShown = 0;
  967. int n = abs ((int) inWeeks());
  968. if (n > 0)
  969. {
  970. result << n << ((n == 1) ? TRANS(" week ")
  971. : TRANS(" weeks "));
  972. ++fieldsShown;
  973. }
  974. n = abs ((int) inDays()) % 7;
  975. if (n > 0)
  976. {
  977. result << n << ((n == 1) ? TRANS(" day ")
  978. : TRANS(" days "));
  979. ++fieldsShown;
  980. }
  981. if (fieldsShown < 2)
  982. {
  983. n = abs ((int) inHours()) % 24;
  984. if (n > 0)
  985. {
  986. result << n << ((n == 1) ? TRANS(" hr ")
  987. : TRANS(" hrs "));
  988. ++fieldsShown;
  989. }
  990. if (fieldsShown < 2)
  991. {
  992. n = abs ((int) inMinutes()) % 60;
  993. if (n > 0)
  994. {
  995. result << n << ((n == 1) ? TRANS(" min ")
  996. : TRANS(" mins "));
  997. ++fieldsShown;
  998. }
  999. if (fieldsShown < 2)
  1000. {
  1001. n = abs ((int) inSeconds()) % 60;
  1002. if (n > 0)
  1003. {
  1004. result << n << ((n == 1) ? TRANS(" sec ")
  1005. : TRANS(" secs "));
  1006. ++fieldsShown;
  1007. }
  1008. if (fieldsShown < 1)
  1009. {
  1010. n = abs ((int) inMilliseconds()) % 1000;
  1011. if (n > 0)
  1012. {
  1013. result << n << TRANS(" ms");
  1014. ++fieldsShown;
  1015. }
  1016. }
  1017. }
  1018. }
  1019. }
  1020. return result.trimEnd();
  1021. }
  1022. const RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1023. {
  1024. seconds = other.seconds;
  1025. return *this;
  1026. }
  1027. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1028. {
  1029. return seconds == other.seconds;
  1030. }
  1031. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1032. {
  1033. return seconds != other.seconds;
  1034. }
  1035. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1036. {
  1037. return seconds > other.seconds;
  1038. }
  1039. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1040. {
  1041. return seconds < other.seconds;
  1042. }
  1043. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1044. {
  1045. return seconds >= other.seconds;
  1046. }
  1047. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1048. {
  1049. return seconds <= other.seconds;
  1050. }
  1051. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1052. {
  1053. return RelativeTime (seconds + timeToAdd.seconds);
  1054. }
  1055. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1056. {
  1057. return RelativeTime (seconds - timeToSubtract.seconds);
  1058. }
  1059. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1060. {
  1061. return RelativeTime (seconds + secondsToAdd);
  1062. }
  1063. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1064. {
  1065. return RelativeTime (seconds - secondsToSubtract);
  1066. }
  1067. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1068. {
  1069. seconds += timeToAdd.seconds;
  1070. return *this;
  1071. }
  1072. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1073. {
  1074. seconds -= timeToSubtract.seconds;
  1075. return *this;
  1076. }
  1077. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1078. {
  1079. seconds += secondsToAdd;
  1080. return *this;
  1081. }
  1082. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1083. {
  1084. seconds -= secondsToSubtract;
  1085. return *this;
  1086. }
  1087. END_JUCE_NAMESPACE
  1088. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1089. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1090. BEGIN_JUCE_NAMESPACE
  1091. void juce_initialiseStrings();
  1092. const String SystemStats::getJUCEVersion() throw()
  1093. {
  1094. return "JUCE v" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION);
  1095. }
  1096. static bool juceInitialisedNonGUI = false;
  1097. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1098. {
  1099. if (! juceInitialisedNonGUI)
  1100. {
  1101. #if JUCE_MAC || JUCE_IPHONE
  1102. const ScopedAutoReleasePool pool;
  1103. #endif
  1104. #ifdef JUCE_DEBUG
  1105. {
  1106. // Some simple test code to keep an eye on things and make sure these functions
  1107. // work ok on all platforms. Let me know if any of these assertions fail!
  1108. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1109. char a1[7];
  1110. jassert (numElementsInArray(a1) == 7);
  1111. int a2[3];
  1112. jassert (numElementsInArray(a2) == 3);
  1113. int n = 1;
  1114. Atomic::increment (n);
  1115. jassert (Atomic::incrementAndReturn (n) == 3);
  1116. Atomic::decrement (n);
  1117. jassert (Atomic::decrementAndReturn (n) == 1);
  1118. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1119. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1120. // Some quick stream tests..
  1121. int randomInt = Random::getSystemRandom().nextInt();
  1122. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1123. double randomDouble = Random::getSystemRandom().nextDouble();
  1124. String randomString;
  1125. for (int i = 50; --i >= 0;)
  1126. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1127. MemoryOutputStream mo;
  1128. mo.writeInt (randomInt);
  1129. mo.writeIntBigEndian (randomInt);
  1130. mo.writeCompressedInt (randomInt);
  1131. mo.writeString (randomString);
  1132. mo.writeInt64 (randomInt64);
  1133. mo.writeInt64BigEndian (randomInt64);
  1134. mo.writeDouble (randomDouble);
  1135. mo.writeDoubleBigEndian (randomDouble);
  1136. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1137. jassert (mi.readInt() == randomInt);
  1138. jassert (mi.readIntBigEndian() == randomInt);
  1139. jassert (mi.readCompressedInt() == randomInt);
  1140. jassert (mi.readString() == randomString);
  1141. jassert (mi.readInt64() == randomInt64);
  1142. jassert (mi.readInt64BigEndian() == randomInt64);
  1143. jassert (mi.readDouble() == randomDouble);
  1144. jassert (mi.readDoubleBigEndian() == randomDouble);
  1145. }
  1146. #endif
  1147. // Now the real initialisation..
  1148. juceInitialisedNonGUI = true;
  1149. DBG (SystemStats::getJUCEVersion());
  1150. juce_initialiseStrings();
  1151. SystemStats::initialiseStats();
  1152. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1153. }
  1154. }
  1155. #if JUCE_WINDOWS
  1156. // This is imported from the sockets code..
  1157. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1158. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1159. #endif
  1160. #if JUCE_DEBUG
  1161. extern void juce_CheckForDanglingStreams();
  1162. #endif
  1163. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1164. {
  1165. if (juceInitialisedNonGUI)
  1166. {
  1167. #if JUCE_MAC || JUCE_IPHONE
  1168. const ScopedAutoReleasePool pool;
  1169. #endif
  1170. #if JUCE_WINDOWS
  1171. // need to shut down sockets if they were used..
  1172. if (juce_CloseWin32SocketLib != 0)
  1173. (*juce_CloseWin32SocketLib)();
  1174. #endif
  1175. LocalisedStrings::setCurrentMappings (0);
  1176. Thread::stopAllThreads (3000);
  1177. #if JUCE_DEBUG
  1178. juce_CheckForDanglingStreams();
  1179. #endif
  1180. juceInitialisedNonGUI = false;
  1181. }
  1182. }
  1183. #ifdef JUCE_DLL
  1184. void* juce_Malloc (const int size)
  1185. {
  1186. return malloc (size);
  1187. }
  1188. void* juce_Calloc (const int size)
  1189. {
  1190. return calloc (1, size);
  1191. }
  1192. void* juce_Realloc (void* const block, const int size)
  1193. {
  1194. return realloc (block, size);
  1195. }
  1196. void juce_Free (void* const block)
  1197. {
  1198. free (block);
  1199. }
  1200. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1201. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1202. {
  1203. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1204. }
  1205. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1206. {
  1207. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1208. }
  1209. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1210. {
  1211. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1212. }
  1213. void juce_DebugFree (void* const block)
  1214. {
  1215. _free_dbg (block, _NORMAL_BLOCK);
  1216. }
  1217. #endif
  1218. #endif
  1219. END_JUCE_NAMESPACE
  1220. /*** End of inlined file: juce_SystemStats.cpp ***/
  1221. /*** Start of inlined file: juce_Time.cpp ***/
  1222. #ifdef _MSC_VER
  1223. #pragma warning (disable: 4514)
  1224. #pragma warning (push)
  1225. #endif
  1226. #ifndef JUCE_WINDOWS
  1227. #include <sys/time.h>
  1228. #else
  1229. #include <ctime>
  1230. #endif
  1231. #include <sys/timeb.h>
  1232. BEGIN_JUCE_NAMESPACE
  1233. #ifdef _MSC_VER
  1234. #pragma warning (pop)
  1235. #ifdef _INC_TIME_INL
  1236. #define USE_NEW_SECURE_TIME_FNS
  1237. #endif
  1238. #endif
  1239. static void millisToLocal (const int64 millis, struct tm& result) throw()
  1240. {
  1241. const int64 seconds = millis / 1000;
  1242. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1243. {
  1244. // use extended maths for dates beyond 1970 to 2037..
  1245. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1246. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1247. const int days = (int) (jdm / literal64bit (86400));
  1248. const int a = 32044 + days;
  1249. const int b = (4 * a + 3) / 146097;
  1250. const int c = a - (b * 146097) / 4;
  1251. const int d = (4 * c + 3) / 1461;
  1252. const int e = c - (d * 1461) / 4;
  1253. const int m = (5 * e + 2) / 153;
  1254. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1255. result.tm_mon = m + 2 - 12 * (m / 10);
  1256. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1257. result.tm_wday = (days + 1) % 7;
  1258. result.tm_yday = -1;
  1259. int t = (int) (jdm % literal64bit (86400));
  1260. result.tm_hour = t / 3600;
  1261. t %= 3600;
  1262. result.tm_min = t / 60;
  1263. result.tm_sec = t % 60;
  1264. result.tm_isdst = -1;
  1265. }
  1266. else
  1267. {
  1268. time_t now = (time_t) (seconds);
  1269. #if JUCE_WINDOWS
  1270. #ifdef USE_NEW_SECURE_TIME_FNS
  1271. if (now >= 0 && now <= 0x793406fff)
  1272. localtime_s (&result, &now);
  1273. else
  1274. zeromem (&result, sizeof (result));
  1275. #else
  1276. result = *localtime (&now);
  1277. #endif
  1278. #else
  1279. // more thread-safe
  1280. localtime_r (&now, &result);
  1281. #endif
  1282. }
  1283. }
  1284. Time::Time() throw()
  1285. : millisSinceEpoch (0)
  1286. {
  1287. }
  1288. Time::Time (const Time& other) throw()
  1289. : millisSinceEpoch (other.millisSinceEpoch)
  1290. {
  1291. }
  1292. Time::Time (const int64 ms) throw()
  1293. : millisSinceEpoch (ms)
  1294. {
  1295. }
  1296. Time::Time (const int year,
  1297. const int month,
  1298. const int day,
  1299. const int hours,
  1300. const int minutes,
  1301. const int seconds,
  1302. const int milliseconds,
  1303. const bool useLocalTime) throw()
  1304. {
  1305. jassert (year > 100); // year must be a 4-digit version
  1306. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1307. {
  1308. // use extended maths for dates beyond 1970 to 2037..
  1309. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1310. : 0;
  1311. const int a = (13 - month) / 12;
  1312. const int y = year + 4800 - a;
  1313. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1314. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1315. - 32045;
  1316. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1317. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1318. + milliseconds;
  1319. }
  1320. else
  1321. {
  1322. struct tm t;
  1323. t.tm_year = year - 1900;
  1324. t.tm_mon = month;
  1325. t.tm_mday = day;
  1326. t.tm_hour = hours;
  1327. t.tm_min = minutes;
  1328. t.tm_sec = seconds;
  1329. t.tm_isdst = -1;
  1330. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1331. if (millisSinceEpoch < 0)
  1332. millisSinceEpoch = 0;
  1333. else
  1334. millisSinceEpoch += milliseconds;
  1335. }
  1336. }
  1337. Time::~Time() throw()
  1338. {
  1339. }
  1340. const Time& Time::operator= (const Time& other) throw()
  1341. {
  1342. millisSinceEpoch = other.millisSinceEpoch;
  1343. return *this;
  1344. }
  1345. int64 Time::currentTimeMillis() throw()
  1346. {
  1347. static uint32 lastCounterResult = 0xffffffff;
  1348. static int64 correction = 0;
  1349. const uint32 now = getMillisecondCounter();
  1350. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1351. if (now < lastCounterResult)
  1352. {
  1353. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1354. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1355. {
  1356. // get the time once using normal library calls, and store the difference needed to
  1357. // turn the millisecond counter into a real time.
  1358. #if JUCE_WINDOWS
  1359. struct _timeb t;
  1360. #ifdef USE_NEW_SECURE_TIME_FNS
  1361. _ftime_s (&t);
  1362. #else
  1363. _ftime (&t);
  1364. #endif
  1365. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1366. #else
  1367. struct timeval tv;
  1368. struct timezone tz;
  1369. gettimeofday (&tv, &tz);
  1370. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1371. #endif
  1372. }
  1373. }
  1374. lastCounterResult = now;
  1375. return correction + now;
  1376. }
  1377. uint32 juce_millisecondsSinceStartup() throw();
  1378. static uint32 lastMSCounterValue = 0;
  1379. uint32 Time::getMillisecondCounter() throw()
  1380. {
  1381. const uint32 now = juce_millisecondsSinceStartup();
  1382. if (now < lastMSCounterValue)
  1383. {
  1384. // in multi-threaded apps this might be called concurrently, so
  1385. // make sure that our last counter value only increases and doesn't
  1386. // go backwards..
  1387. if (now < lastMSCounterValue - 1000)
  1388. lastMSCounterValue = now;
  1389. }
  1390. else
  1391. {
  1392. lastMSCounterValue = now;
  1393. }
  1394. return now;
  1395. }
  1396. uint32 Time::getApproximateMillisecondCounter() throw()
  1397. {
  1398. jassert (lastMSCounterValue != 0);
  1399. return lastMSCounterValue;
  1400. }
  1401. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1402. {
  1403. for (;;)
  1404. {
  1405. const uint32 now = getMillisecondCounter();
  1406. if (now >= targetTime)
  1407. break;
  1408. const int toWait = targetTime - now;
  1409. if (toWait > 2)
  1410. {
  1411. Thread::sleep (jmin (20, toWait >> 1));
  1412. }
  1413. else
  1414. {
  1415. // xxx should consider using mutex_pause on the mac as it apparently
  1416. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1417. for (int i = 10; --i >= 0;)
  1418. Thread::yield();
  1419. }
  1420. }
  1421. }
  1422. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1423. {
  1424. return ticks / (double) getHighResolutionTicksPerSecond();
  1425. }
  1426. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1427. {
  1428. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1429. }
  1430. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1431. {
  1432. return Time (currentTimeMillis());
  1433. }
  1434. const String Time::toString (const bool includeDate,
  1435. const bool includeTime,
  1436. const bool includeSeconds,
  1437. const bool use24HourClock) const throw()
  1438. {
  1439. String result;
  1440. if (includeDate)
  1441. {
  1442. result << getDayOfMonth() << ' '
  1443. << getMonthName (true) << ' '
  1444. << getYear();
  1445. if (includeTime)
  1446. result << ' ';
  1447. }
  1448. if (includeTime)
  1449. {
  1450. if (includeSeconds)
  1451. {
  1452. result += String::formatted (T("%d:%02d:%02d "),
  1453. (use24HourClock) ? getHours()
  1454. : getHoursInAmPmFormat(),
  1455. getMinutes(),
  1456. getSeconds());
  1457. }
  1458. else
  1459. {
  1460. result += String::formatted (T("%d.%02d"),
  1461. (use24HourClock) ? getHours()
  1462. : getHoursInAmPmFormat(),
  1463. getMinutes());
  1464. }
  1465. if (! use24HourClock)
  1466. result << (isAfternoon() ? "pm" : "am");
  1467. }
  1468. return result.trimEnd();
  1469. }
  1470. const String Time::formatted (const tchar* const format) const throw()
  1471. {
  1472. String buffer;
  1473. int bufferSize = 128;
  1474. buffer.preallocateStorage (bufferSize);
  1475. struct tm t;
  1476. millisToLocal (millisSinceEpoch, t);
  1477. while (CharacterFunctions::ftime ((tchar*) (const tchar*) buffer, bufferSize, format, &t) <= 0)
  1478. {
  1479. bufferSize += 128;
  1480. buffer.preallocateStorage (bufferSize);
  1481. }
  1482. return buffer;
  1483. }
  1484. int Time::getYear() const throw()
  1485. {
  1486. struct tm t;
  1487. millisToLocal (millisSinceEpoch, t);
  1488. return t.tm_year + 1900;
  1489. }
  1490. int Time::getMonth() const throw()
  1491. {
  1492. struct tm t;
  1493. millisToLocal (millisSinceEpoch, t);
  1494. return t.tm_mon;
  1495. }
  1496. int Time::getDayOfMonth() const throw()
  1497. {
  1498. struct tm t;
  1499. millisToLocal (millisSinceEpoch, t);
  1500. return t.tm_mday;
  1501. }
  1502. int Time::getDayOfWeek() const throw()
  1503. {
  1504. struct tm t;
  1505. millisToLocal (millisSinceEpoch, t);
  1506. return t.tm_wday;
  1507. }
  1508. int Time::getHours() const throw()
  1509. {
  1510. struct tm t;
  1511. millisToLocal (millisSinceEpoch, t);
  1512. return t.tm_hour;
  1513. }
  1514. int Time::getHoursInAmPmFormat() const throw()
  1515. {
  1516. const int hours = getHours();
  1517. if (hours == 0)
  1518. return 12;
  1519. else if (hours <= 12)
  1520. return hours;
  1521. else
  1522. return hours - 12;
  1523. }
  1524. bool Time::isAfternoon() const throw()
  1525. {
  1526. return getHours() >= 12;
  1527. }
  1528. static int extendedModulo (const int64 value, const int modulo) throw()
  1529. {
  1530. return (int) (value >= 0 ? (value % modulo)
  1531. : (value - ((value / modulo) + 1) * modulo));
  1532. }
  1533. int Time::getMinutes() const throw()
  1534. {
  1535. struct tm t;
  1536. millisToLocal (millisSinceEpoch, t);
  1537. return t.tm_min;
  1538. }
  1539. int Time::getSeconds() const throw()
  1540. {
  1541. return extendedModulo (millisSinceEpoch / 1000, 60);
  1542. }
  1543. int Time::getMilliseconds() const throw()
  1544. {
  1545. return extendedModulo (millisSinceEpoch, 1000);
  1546. }
  1547. bool Time::isDaylightSavingTime() const throw()
  1548. {
  1549. struct tm t;
  1550. millisToLocal (millisSinceEpoch, t);
  1551. return t.tm_isdst != 0;
  1552. }
  1553. const String Time::getTimeZone() const throw()
  1554. {
  1555. String zone[2];
  1556. #if JUCE_WINDOWS
  1557. _tzset();
  1558. #ifdef USE_NEW_SECURE_TIME_FNS
  1559. {
  1560. char name [128];
  1561. size_t length;
  1562. for (int i = 0; i < 2; ++i)
  1563. {
  1564. zeromem (name, sizeof (name));
  1565. _get_tzname (&length, name, 127, i);
  1566. zone[i] = name;
  1567. }
  1568. }
  1569. #else
  1570. const char** const zonePtr = (const char**) _tzname;
  1571. zone[0] = zonePtr[0];
  1572. zone[1] = zonePtr[1];
  1573. #endif
  1574. #else
  1575. tzset();
  1576. const char** const zonePtr = (const char**) tzname;
  1577. zone[0] = zonePtr[0];
  1578. zone[1] = zonePtr[1];
  1579. #endif
  1580. if (isDaylightSavingTime())
  1581. {
  1582. zone[0] = zone[1];
  1583. if (zone[0].length() > 3
  1584. && zone[0].containsIgnoreCase (T("daylight"))
  1585. && zone[0].contains (T("GMT")))
  1586. zone[0] = "BST";
  1587. }
  1588. return zone[0].substring (0, 3);
  1589. }
  1590. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1591. {
  1592. return getMonthName (getMonth(), threeLetterVersion);
  1593. }
  1594. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1595. {
  1596. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1597. }
  1598. const String Time::getMonthName (int monthNumber,
  1599. const bool threeLetterVersion) throw()
  1600. {
  1601. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1602. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1603. monthNumber %= 12;
  1604. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1605. : longMonthNames [monthNumber]);
  1606. }
  1607. const String Time::getWeekdayName (int day,
  1608. const bool threeLetterVersion) throw()
  1609. {
  1610. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1611. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1612. day %= 7;
  1613. return TRANS (threeLetterVersion ? shortDayNames [day]
  1614. : longDayNames [day]);
  1615. }
  1616. END_JUCE_NAMESPACE
  1617. /*** End of inlined file: juce_Time.cpp ***/
  1618. /*** Start of inlined file: juce_BitArray.cpp ***/
  1619. BEGIN_JUCE_NAMESPACE
  1620. BitArray::BitArray() throw()
  1621. : numValues (4),
  1622. highestBit (-1),
  1623. negative (false)
  1624. {
  1625. values.calloc (numValues + 1);
  1626. }
  1627. BitArray::BitArray (const int value) throw()
  1628. : numValues (4),
  1629. highestBit (31),
  1630. negative (value < 0)
  1631. {
  1632. values.calloc (numValues + 1);
  1633. values[0] = abs (value);
  1634. highestBit = getHighestBit();
  1635. }
  1636. BitArray::BitArray (int64 value) throw()
  1637. : numValues (4),
  1638. highestBit (63),
  1639. negative (value < 0)
  1640. {
  1641. values.calloc (numValues + 1);
  1642. if (value < 0)
  1643. value = -value;
  1644. values[0] = (unsigned int) value;
  1645. values[1] = (unsigned int) (value >> 32);
  1646. highestBit = getHighestBit();
  1647. }
  1648. BitArray::BitArray (const unsigned int value) throw()
  1649. : numValues (4),
  1650. highestBit (31),
  1651. negative (false)
  1652. {
  1653. values.calloc (numValues + 1);
  1654. values[0] = value;
  1655. highestBit = getHighestBit();
  1656. }
  1657. BitArray::BitArray (const BitArray& other) throw()
  1658. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1659. highestBit (other.getHighestBit()),
  1660. negative (other.negative)
  1661. {
  1662. values.malloc (numValues + 1);
  1663. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1664. }
  1665. BitArray::~BitArray() throw()
  1666. {
  1667. }
  1668. BitArray& BitArray::operator= (const BitArray& other) throw()
  1669. {
  1670. if (this != &other)
  1671. {
  1672. highestBit = other.getHighestBit();
  1673. numValues = jmax (4, (highestBit >> 5) + 1);
  1674. negative = other.negative;
  1675. values.malloc (numValues + 1);
  1676. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1677. }
  1678. return *this;
  1679. }
  1680. // result == 0 = the same
  1681. // result < 0 = this number is smaller
  1682. // result > 0 = this number is bigger
  1683. int BitArray::compare (const BitArray& other) const throw()
  1684. {
  1685. if (isNegative() == other.isNegative())
  1686. {
  1687. const int absComp = compareAbsolute (other);
  1688. return isNegative() ? -absComp : absComp;
  1689. }
  1690. else
  1691. {
  1692. return isNegative() ? -1 : 1;
  1693. }
  1694. }
  1695. int BitArray::compareAbsolute (const BitArray& other) const throw()
  1696. {
  1697. const int h1 = getHighestBit();
  1698. const int h2 = other.getHighestBit();
  1699. if (h1 > h2)
  1700. return 1;
  1701. else if (h1 < h2)
  1702. return -1;
  1703. for (int i = (h1 >> 5) + 1; --i >= 0;)
  1704. if (values[i] != other.values[i])
  1705. return (values[i] > other.values[i]) ? 1 : -1;
  1706. return 0;
  1707. }
  1708. bool BitArray::operator== (const BitArray& other) const throw()
  1709. {
  1710. return compare (other) == 0;
  1711. }
  1712. bool BitArray::operator!= (const BitArray& other) const throw()
  1713. {
  1714. return compare (other) != 0;
  1715. }
  1716. bool BitArray::operator[] (const int bit) const throw()
  1717. {
  1718. return bit >= 0 && bit <= highestBit
  1719. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1720. }
  1721. bool BitArray::isEmpty() const throw()
  1722. {
  1723. return getHighestBit() < 0;
  1724. }
  1725. void BitArray::clear() throw()
  1726. {
  1727. if (numValues > 16)
  1728. {
  1729. numValues = 4;
  1730. values.calloc (numValues + 1);
  1731. }
  1732. else
  1733. {
  1734. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1735. }
  1736. highestBit = -1;
  1737. negative = false;
  1738. }
  1739. void BitArray::setBit (const int bit) throw()
  1740. {
  1741. if (bit >= 0)
  1742. {
  1743. if (bit > highestBit)
  1744. {
  1745. ensureSize (bit >> 5);
  1746. highestBit = bit;
  1747. }
  1748. values [bit >> 5] |= (1 << (bit & 31));
  1749. }
  1750. }
  1751. void BitArray::setBit (const int bit,
  1752. const bool shouldBeSet) throw()
  1753. {
  1754. if (shouldBeSet)
  1755. setBit (bit);
  1756. else
  1757. clearBit (bit);
  1758. }
  1759. void BitArray::clearBit (const int bit) throw()
  1760. {
  1761. if (bit >= 0 && bit <= highestBit)
  1762. values [bit >> 5] &= ~(1 << (bit & 31));
  1763. }
  1764. void BitArray::setRange (int startBit,
  1765. int numBits,
  1766. const bool shouldBeSet) throw()
  1767. {
  1768. while (--numBits >= 0)
  1769. setBit (startBit++, shouldBeSet);
  1770. }
  1771. void BitArray::insertBit (const int bit,
  1772. const bool shouldBeSet) throw()
  1773. {
  1774. if (bit >= 0)
  1775. shiftBits (1, bit);
  1776. setBit (bit, shouldBeSet);
  1777. }
  1778. void BitArray::andWith (const BitArray& other) throw()
  1779. {
  1780. // this operation will only work with the absolute values
  1781. jassert (isNegative() == other.isNegative());
  1782. int n = numValues;
  1783. while (n > other.numValues)
  1784. values[--n] = 0;
  1785. while (--n >= 0)
  1786. values[n] &= other.values[n];
  1787. if (other.highestBit < highestBit)
  1788. highestBit = other.highestBit;
  1789. highestBit = getHighestBit();
  1790. }
  1791. void BitArray::orWith (const BitArray& other) throw()
  1792. {
  1793. if (other.highestBit < 0)
  1794. return;
  1795. // this operation will only work with the absolute values
  1796. jassert (isNegative() == other.isNegative());
  1797. ensureSize (other.highestBit >> 5);
  1798. int n = (other.highestBit >> 5) + 1;
  1799. while (--n >= 0)
  1800. values[n] |= other.values[n];
  1801. if (other.highestBit > highestBit)
  1802. highestBit = other.highestBit;
  1803. highestBit = getHighestBit();
  1804. }
  1805. void BitArray::xorWith (const BitArray& other) throw()
  1806. {
  1807. if (other.highestBit < 0)
  1808. return;
  1809. // this operation will only work with the absolute values
  1810. jassert (isNegative() == other.isNegative());
  1811. ensureSize (other.highestBit >> 5);
  1812. int n = (other.highestBit >> 5) + 1;
  1813. while (--n >= 0)
  1814. values[n] ^= other.values[n];
  1815. if (other.highestBit > highestBit)
  1816. highestBit = other.highestBit;
  1817. highestBit = getHighestBit();
  1818. }
  1819. void BitArray::add (const BitArray& other) throw()
  1820. {
  1821. if (other.isNegative())
  1822. {
  1823. BitArray o (other);
  1824. o.negate();
  1825. subtract (o);
  1826. return;
  1827. }
  1828. if (isNegative())
  1829. {
  1830. if (compareAbsolute (other) < 0)
  1831. {
  1832. BitArray temp (*this);
  1833. temp.negate();
  1834. *this = other;
  1835. subtract (temp);
  1836. }
  1837. else
  1838. {
  1839. negate();
  1840. subtract (other);
  1841. negate();
  1842. }
  1843. return;
  1844. }
  1845. if (other.highestBit > highestBit)
  1846. highestBit = other.highestBit;
  1847. ++highestBit;
  1848. const int numInts = (highestBit >> 5) + 1;
  1849. ensureSize (numInts);
  1850. int64 remainder = 0;
  1851. for (int i = 0; i <= numInts; ++i)
  1852. {
  1853. if (i < numValues)
  1854. remainder += values[i];
  1855. if (i < other.numValues)
  1856. remainder += other.values[i];
  1857. values[i] = (unsigned int) remainder;
  1858. remainder >>= 32;
  1859. }
  1860. jassert (remainder == 0);
  1861. highestBit = getHighestBit();
  1862. }
  1863. void BitArray::subtract (const BitArray& other) throw()
  1864. {
  1865. if (other.isNegative())
  1866. {
  1867. BitArray o (other);
  1868. o.negate();
  1869. add (o);
  1870. return;
  1871. }
  1872. if (! isNegative())
  1873. {
  1874. if (compareAbsolute (other) < 0)
  1875. {
  1876. BitArray temp (*this);
  1877. *this = other;
  1878. subtract (temp);
  1879. negate();
  1880. return;
  1881. }
  1882. }
  1883. else
  1884. {
  1885. negate();
  1886. add (other);
  1887. negate();
  1888. return;
  1889. }
  1890. const int numInts = (highestBit >> 5) + 1;
  1891. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1892. int64 amountToSubtract = 0;
  1893. for (int i = 0; i <= numInts; ++i)
  1894. {
  1895. if (i <= maxOtherInts)
  1896. amountToSubtract += (int64)other.values[i];
  1897. if (values[i] >= amountToSubtract)
  1898. {
  1899. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1900. amountToSubtract = 0;
  1901. }
  1902. else
  1903. {
  1904. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1905. values[i] = (unsigned int) n;
  1906. amountToSubtract = 1;
  1907. }
  1908. }
  1909. }
  1910. void BitArray::multiplyBy (const BitArray& other) throw()
  1911. {
  1912. BitArray total;
  1913. highestBit = getHighestBit();
  1914. const bool wasNegative = isNegative();
  1915. setNegative (false);
  1916. for (int i = 0; i <= highestBit; ++i)
  1917. {
  1918. if (operator[](i))
  1919. {
  1920. BitArray n (other);
  1921. n.setNegative (false);
  1922. n.shiftBits (i);
  1923. total.add (n);
  1924. }
  1925. }
  1926. *this = total;
  1927. negative = wasNegative ^ other.isNegative();
  1928. }
  1929. void BitArray::divideBy (const BitArray& divisor, BitArray& remainder) throw()
  1930. {
  1931. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1932. const int divHB = divisor.getHighestBit();
  1933. const int ourHB = getHighestBit();
  1934. if (divHB < 0 || ourHB < 0)
  1935. {
  1936. // division by zero
  1937. remainder.clear();
  1938. clear();
  1939. }
  1940. else
  1941. {
  1942. remainder = *this;
  1943. remainder.setNegative (false);
  1944. const bool wasNegative = isNegative();
  1945. clear();
  1946. BitArray temp (divisor);
  1947. temp.setNegative (false);
  1948. int leftShift = ourHB - divHB;
  1949. temp.shiftBits (leftShift);
  1950. while (leftShift >= 0)
  1951. {
  1952. if (remainder.compareAbsolute (temp) >= 0)
  1953. {
  1954. remainder.subtract (temp);
  1955. setBit (leftShift);
  1956. }
  1957. if (--leftShift >= 0)
  1958. temp.shiftBits (-1);
  1959. }
  1960. negative = wasNegative ^ divisor.isNegative();
  1961. remainder.setNegative (wasNegative);
  1962. }
  1963. }
  1964. void BitArray::modulo (const BitArray& divisor) throw()
  1965. {
  1966. BitArray remainder;
  1967. divideBy (divisor, remainder);
  1968. *this = remainder;
  1969. }
  1970. static const BitArray simpleGCD (BitArray* m, BitArray* n) throw()
  1971. {
  1972. while (! m->isEmpty())
  1973. {
  1974. if (n->compareAbsolute (*m) > 0)
  1975. swapVariables (m, n);
  1976. m->subtract (*n);
  1977. }
  1978. return *n;
  1979. }
  1980. const BitArray BitArray::findGreatestCommonDivisor (BitArray n) const throw()
  1981. {
  1982. BitArray m (*this);
  1983. while (! n.isEmpty())
  1984. {
  1985. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  1986. return simpleGCD (&m, &n);
  1987. BitArray temp1 (m), temp2;
  1988. temp1.divideBy (n, temp2);
  1989. m = n;
  1990. n = temp2;
  1991. }
  1992. return m;
  1993. }
  1994. void BitArray::exponentModulo (const BitArray& exponent,
  1995. const BitArray& modulus) throw()
  1996. {
  1997. BitArray exp (exponent);
  1998. exp.modulo (modulus);
  1999. BitArray value (*this);
  2000. value.modulo (modulus);
  2001. clear();
  2002. setBit (0);
  2003. while (! exp.isEmpty())
  2004. {
  2005. if (exp [0])
  2006. {
  2007. multiplyBy (value);
  2008. this->modulo (modulus);
  2009. }
  2010. value.multiplyBy (value);
  2011. value.modulo (modulus);
  2012. exp.shiftBits (-1);
  2013. }
  2014. }
  2015. void BitArray::inverseModulo (const BitArray& modulus) throw()
  2016. {
  2017. const BitArray one (1);
  2018. if (modulus == one || modulus.isNegative())
  2019. {
  2020. clear();
  2021. return;
  2022. }
  2023. if (isNegative() || compareAbsolute (modulus) >= 0)
  2024. this->modulo (modulus);
  2025. if (*this == one)
  2026. return;
  2027. if (! (*this)[0])
  2028. {
  2029. // not invertible
  2030. clear();
  2031. return;
  2032. }
  2033. BitArray a1 (modulus);
  2034. BitArray a2 (*this);
  2035. BitArray b1 (modulus);
  2036. BitArray b2 (1);
  2037. while (a2 != one)
  2038. {
  2039. BitArray temp1, temp2, multiplier (a1);
  2040. multiplier.divideBy (a2, temp1);
  2041. temp1 = a2;
  2042. temp1.multiplyBy (multiplier);
  2043. temp2 = a1;
  2044. temp2.subtract (temp1);
  2045. a1 = a2;
  2046. a2 = temp2;
  2047. temp1 = b2;
  2048. temp1.multiplyBy (multiplier);
  2049. temp2 = b1;
  2050. temp2.subtract (temp1);
  2051. b1 = b2;
  2052. b2 = temp2;
  2053. }
  2054. while (b2.isNegative())
  2055. b2.add (modulus);
  2056. b2.modulo (modulus);
  2057. *this = b2;
  2058. }
  2059. void BitArray::shiftBits (int bits, const int startBit) throw()
  2060. {
  2061. if (highestBit < 0)
  2062. return;
  2063. if (startBit > 0)
  2064. {
  2065. if (bits < 0)
  2066. {
  2067. // right shift
  2068. for (int i = startBit; i <= highestBit; ++i)
  2069. setBit (i, operator[] (i - bits));
  2070. highestBit = getHighestBit();
  2071. }
  2072. else if (bits > 0)
  2073. {
  2074. // left shift
  2075. for (int i = highestBit + 1; --i >= startBit;)
  2076. setBit (i + bits, operator[] (i));
  2077. while (--bits >= 0)
  2078. clearBit (bits + startBit);
  2079. }
  2080. }
  2081. else
  2082. {
  2083. if (bits < 0)
  2084. {
  2085. // right shift
  2086. bits = -bits;
  2087. if (bits > highestBit)
  2088. {
  2089. clear();
  2090. }
  2091. else
  2092. {
  2093. const int wordsToMove = bits >> 5;
  2094. int top = 1 + (highestBit >> 5) - wordsToMove;
  2095. highestBit -= bits;
  2096. if (wordsToMove > 0)
  2097. {
  2098. int i;
  2099. for (i = 0; i < top; ++i)
  2100. values [i] = values [i + wordsToMove];
  2101. for (i = 0; i < wordsToMove; ++i)
  2102. values [top + i] = 0;
  2103. bits &= 31;
  2104. }
  2105. if (bits != 0)
  2106. {
  2107. const int invBits = 32 - bits;
  2108. --top;
  2109. for (int i = 0; i < top; ++i)
  2110. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2111. values[top] = (values[top] >> bits);
  2112. }
  2113. highestBit = getHighestBit();
  2114. }
  2115. }
  2116. else if (bits > 0)
  2117. {
  2118. // left shift
  2119. ensureSize (((highestBit + bits) >> 5) + 1);
  2120. const int wordsToMove = bits >> 5;
  2121. int top = 1 + (highestBit >> 5);
  2122. highestBit += bits;
  2123. if (wordsToMove > 0)
  2124. {
  2125. int i;
  2126. for (i = top; --i >= 0;)
  2127. values [i + wordsToMove] = values [i];
  2128. for (i = 0; i < wordsToMove; ++i)
  2129. values [i] = 0;
  2130. bits &= 31;
  2131. }
  2132. if (bits != 0)
  2133. {
  2134. const int invBits = 32 - bits;
  2135. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2136. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2137. values [wordsToMove] = values [wordsToMove] << bits;
  2138. }
  2139. highestBit = getHighestBit();
  2140. }
  2141. }
  2142. }
  2143. const BitArray BitArray::getBitRange (int startBit, int numBits) const throw()
  2144. {
  2145. BitArray r;
  2146. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  2147. r.ensureSize (numBits >> 5);
  2148. r.highestBit = numBits;
  2149. int i = 0;
  2150. while (numBits > 0)
  2151. {
  2152. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  2153. numBits -= 32;
  2154. startBit += 32;
  2155. }
  2156. r.highestBit = r.getHighestBit();
  2157. return r;
  2158. }
  2159. int BitArray::getBitRangeAsInt (const int startBit, int numBits) const throw()
  2160. {
  2161. if (numBits > 32)
  2162. {
  2163. jassertfalse // use getBitRange() if you need more than 32 bits..
  2164. numBits = 32;
  2165. }
  2166. numBits = jmin (numBits, highestBit + 1 - startBit);
  2167. if (numBits <= 0)
  2168. return 0;
  2169. const int pos = startBit >> 5;
  2170. const int offset = startBit & 31;
  2171. const int endSpace = 32 - numBits;
  2172. uint32 n = ((uint32) values [pos]) >> offset;
  2173. if (offset > endSpace)
  2174. n |= ((uint32) values [pos + 1]) << (32 - offset);
  2175. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  2176. }
  2177. void BitArray::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet) throw()
  2178. {
  2179. if (numBits > 32)
  2180. {
  2181. jassertfalse
  2182. numBits = 32;
  2183. }
  2184. for (int i = 0; i < numBits; ++i)
  2185. {
  2186. setBit (startBit + i, (valueToSet & 1) != 0);
  2187. valueToSet >>= 1;
  2188. }
  2189. }
  2190. bool BitArray::isNegative() const throw()
  2191. {
  2192. return negative && ! isEmpty();
  2193. }
  2194. void BitArray::setNegative (const bool neg) throw()
  2195. {
  2196. negative = neg;
  2197. }
  2198. void BitArray::negate() throw()
  2199. {
  2200. negative = (! negative) && ! isEmpty();
  2201. }
  2202. int BitArray::countNumberOfSetBits() const throw()
  2203. {
  2204. int total = 0;
  2205. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  2206. {
  2207. unsigned int n = values[i];
  2208. if (n == 0xffffffff)
  2209. {
  2210. total += 32;
  2211. }
  2212. else
  2213. {
  2214. while (n != 0)
  2215. {
  2216. total += (n & 1);
  2217. n >>= 1;
  2218. }
  2219. }
  2220. }
  2221. return total;
  2222. }
  2223. int BitArray::getHighestBit() const throw()
  2224. {
  2225. for (int i = highestBit + 1; --i >= 0;)
  2226. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2227. return i;
  2228. return -1;
  2229. }
  2230. int BitArray::findNextSetBit (int i) const throw()
  2231. {
  2232. for (; i <= highestBit; ++i)
  2233. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2234. return i;
  2235. return -1;
  2236. }
  2237. int BitArray::findNextClearBit (int i) const throw()
  2238. {
  2239. for (; i <= highestBit; ++i)
  2240. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  2241. break;
  2242. return i;
  2243. }
  2244. void BitArray::ensureSize (const int numVals) throw()
  2245. {
  2246. if (numVals + 2 >= numValues)
  2247. {
  2248. int oldSize = numValues;
  2249. numValues = ((numVals + 2) * 3) / 2;
  2250. values.realloc (numValues + 1);
  2251. while (oldSize < numValues)
  2252. values [oldSize++] = 0;
  2253. }
  2254. }
  2255. const String BitArray::toString (const int base, const int minimumNumCharacters) const throw()
  2256. {
  2257. String s;
  2258. BitArray v (*this);
  2259. if (base == 2 || base == 8 || base == 16)
  2260. {
  2261. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2262. static const tchar* const hexDigits = T("0123456789abcdef");
  2263. for (;;)
  2264. {
  2265. const int remainder = v.getBitRangeAsInt (0, bits);
  2266. v.shiftBits (-bits);
  2267. if (remainder == 0 && v.isEmpty())
  2268. break;
  2269. s = String::charToString (hexDigits [remainder]) + s;
  2270. }
  2271. }
  2272. else if (base == 10)
  2273. {
  2274. const BitArray ten (10);
  2275. BitArray remainder;
  2276. for (;;)
  2277. {
  2278. v.divideBy (ten, remainder);
  2279. if (remainder.isEmpty() && v.isEmpty())
  2280. break;
  2281. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2282. }
  2283. }
  2284. else
  2285. {
  2286. jassertfalse // can't do the specified base
  2287. return String::empty;
  2288. }
  2289. const int length = s.length();
  2290. if (length < minimumNumCharacters)
  2291. s = String::repeatedString (T("0"), minimumNumCharacters - length) + s;
  2292. return isNegative() ? T("-") + s : s;
  2293. }
  2294. void BitArray::parseString (const String& text,
  2295. const int base) throw()
  2296. {
  2297. clear();
  2298. const tchar* t = (const tchar*) text;
  2299. if (base == 2 || base == 8 || base == 16)
  2300. {
  2301. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2302. for (;;)
  2303. {
  2304. const tchar c = *t++;
  2305. const int digit = CharacterFunctions::getHexDigitValue (c);
  2306. if (((unsigned int) digit) < (unsigned int) base)
  2307. {
  2308. shiftBits (bits);
  2309. add (digit);
  2310. }
  2311. else if (c == 0)
  2312. {
  2313. break;
  2314. }
  2315. }
  2316. }
  2317. else if (base == 10)
  2318. {
  2319. const BitArray ten ((unsigned int) 10);
  2320. for (;;)
  2321. {
  2322. const tchar c = *t++;
  2323. if (c >= T('0') && c <= T('9'))
  2324. {
  2325. multiplyBy (ten);
  2326. add ((int) (c - T('0')));
  2327. }
  2328. else if (c == 0)
  2329. {
  2330. break;
  2331. }
  2332. }
  2333. }
  2334. setNegative (text.trimStart().startsWithChar (T('-')));
  2335. }
  2336. const MemoryBlock BitArray::toMemoryBlock() const throw()
  2337. {
  2338. const int numBytes = (getHighestBit() + 8) >> 3;
  2339. MemoryBlock mb ((size_t) numBytes);
  2340. for (int i = 0; i < numBytes; ++i)
  2341. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2342. return mb;
  2343. }
  2344. void BitArray::loadFromMemoryBlock (const MemoryBlock& data) throw()
  2345. {
  2346. clear();
  2347. for (int i = (int) data.getSize(); --i >= 0;)
  2348. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2349. }
  2350. END_JUCE_NAMESPACE
  2351. /*** End of inlined file: juce_BitArray.cpp ***/
  2352. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2353. BEGIN_JUCE_NAMESPACE
  2354. MemoryBlock::MemoryBlock() throw()
  2355. : size (0)
  2356. {
  2357. }
  2358. MemoryBlock::MemoryBlock (const size_t initialSize,
  2359. const bool initialiseToZero) throw()
  2360. {
  2361. if (initialSize > 0)
  2362. {
  2363. size = initialSize;
  2364. data.allocate (initialSize, initialiseToZero);
  2365. }
  2366. else
  2367. {
  2368. size = 0;
  2369. }
  2370. }
  2371. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2372. : size (other.size)
  2373. {
  2374. if (size > 0)
  2375. {
  2376. jassert (other.data != 0);
  2377. data.malloc (size);
  2378. memcpy (data, other.data, size);
  2379. }
  2380. }
  2381. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2382. const size_t sizeInBytes) throw()
  2383. : size (jmax ((size_t) 0, sizeInBytes))
  2384. {
  2385. jassert (sizeInBytes >= 0);
  2386. if (size > 0)
  2387. {
  2388. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2389. data.malloc (size);
  2390. if (dataToInitialiseFrom != 0)
  2391. memcpy (data, dataToInitialiseFrom, size);
  2392. }
  2393. }
  2394. MemoryBlock::~MemoryBlock() throw()
  2395. {
  2396. jassert (size >= 0); // should never happen
  2397. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2398. }
  2399. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2400. {
  2401. if (this != &other)
  2402. {
  2403. setSize (other.size, false);
  2404. memcpy (data, other.data, size);
  2405. }
  2406. return *this;
  2407. }
  2408. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2409. {
  2410. return matches (other.data, other.size);
  2411. }
  2412. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2413. {
  2414. return ! operator== (other);
  2415. }
  2416. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2417. {
  2418. return size == dataSize
  2419. && memcmp (data, dataToCompare, size) == 0;
  2420. }
  2421. // this will resize the block to this size
  2422. void MemoryBlock::setSize (const size_t newSize,
  2423. const bool initialiseToZero) throw()
  2424. {
  2425. if (size != newSize)
  2426. {
  2427. if (newSize <= 0)
  2428. {
  2429. data.free();
  2430. size = 0;
  2431. }
  2432. else
  2433. {
  2434. if (data != 0)
  2435. {
  2436. data.realloc (newSize);
  2437. if (initialiseToZero && (newSize > size))
  2438. zeromem (data + size, newSize - size);
  2439. }
  2440. else
  2441. {
  2442. data.allocate (newSize, initialiseToZero);
  2443. }
  2444. size = newSize;
  2445. }
  2446. }
  2447. }
  2448. void MemoryBlock::ensureSize (const size_t minimumSize,
  2449. const bool initialiseToZero) throw()
  2450. {
  2451. if (size < minimumSize)
  2452. setSize (minimumSize, initialiseToZero);
  2453. }
  2454. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2455. {
  2456. swapVariables (size, other.size);
  2457. data.swapWith (other.data);
  2458. }
  2459. void MemoryBlock::fillWith (const uint8 value) throw()
  2460. {
  2461. memset (data, (int) value, size);
  2462. }
  2463. void MemoryBlock::append (const void* const srcData,
  2464. const size_t numBytes) throw()
  2465. {
  2466. if (numBytes > 0)
  2467. {
  2468. const size_t oldSize = size;
  2469. setSize (size + numBytes);
  2470. memcpy (data + oldSize, srcData, numBytes);
  2471. }
  2472. }
  2473. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2474. {
  2475. const char* d = (const char*) src;
  2476. if (offset < 0)
  2477. {
  2478. d -= offset;
  2479. num -= offset;
  2480. offset = 0;
  2481. }
  2482. if (offset + num > size)
  2483. num = size - offset;
  2484. if (num > 0)
  2485. memcpy (data + offset, d, num);
  2486. }
  2487. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2488. {
  2489. char* d = (char*) dst;
  2490. if (offset < 0)
  2491. {
  2492. zeromem (d, -offset);
  2493. d -= offset;
  2494. num += offset;
  2495. offset = 0;
  2496. }
  2497. if (offset + num > size)
  2498. {
  2499. const size_t newNum = size - offset;
  2500. zeromem (d + newNum, num - newNum);
  2501. num = newNum;
  2502. }
  2503. if (num > 0)
  2504. memcpy (d, data + offset, num);
  2505. }
  2506. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2507. {
  2508. if (startByte < 0)
  2509. {
  2510. numBytesToRemove += startByte;
  2511. startByte = 0;
  2512. }
  2513. if (startByte + numBytesToRemove >= size)
  2514. {
  2515. setSize (startByte);
  2516. }
  2517. else if (numBytesToRemove > 0)
  2518. {
  2519. memmove (data + startByte,
  2520. data + startByte + numBytesToRemove,
  2521. size - (startByte + numBytesToRemove));
  2522. setSize (size - numBytesToRemove);
  2523. }
  2524. }
  2525. const String MemoryBlock::toString() const throw()
  2526. {
  2527. return String ((const char*) data, size);
  2528. }
  2529. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2530. {
  2531. int res = 0;
  2532. size_t byte = bitRangeStart >> 3;
  2533. int offsetInByte = bitRangeStart & 7;
  2534. size_t bitsSoFar = 0;
  2535. while (numBits > 0 && (size_t) byte < size)
  2536. {
  2537. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2538. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2539. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2540. bitsSoFar += bitsThisTime;
  2541. numBits -= bitsThisTime;
  2542. ++byte;
  2543. offsetInByte = 0;
  2544. }
  2545. return res;
  2546. }
  2547. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2548. {
  2549. size_t byte = bitRangeStart >> 3;
  2550. int offsetInByte = bitRangeStart & 7;
  2551. unsigned int mask = ~((((unsigned int)0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2552. while (numBits > 0 && (size_t) byte < size)
  2553. {
  2554. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2555. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int)0xffffffff) >> offsetInByte) << offsetInByte);
  2556. const unsigned int tempBits = bitsToSet << offsetInByte;
  2557. data[byte] = (char)((data[byte] & tempMask) | tempBits);
  2558. ++byte;
  2559. numBits -= bitsThisTime;
  2560. bitsToSet >>= bitsThisTime;
  2561. mask >>= bitsThisTime;
  2562. offsetInByte = 0;
  2563. }
  2564. }
  2565. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2566. {
  2567. ensureSize (hex.length() >> 1);
  2568. char* dest = data;
  2569. int i = 0;
  2570. for (;;)
  2571. {
  2572. int byte = 0;
  2573. for (int loop = 2; --loop >= 0;)
  2574. {
  2575. byte <<= 4;
  2576. for (;;)
  2577. {
  2578. const tchar c = hex [i++];
  2579. if (c >= T('0') && c <= T('9'))
  2580. {
  2581. byte |= c - T('0');
  2582. break;
  2583. }
  2584. else if (c >= T('a') && c <= T('z'))
  2585. {
  2586. byte |= c - (T('a') - 10);
  2587. break;
  2588. }
  2589. else if (c >= T('A') && c <= T('Z'))
  2590. {
  2591. byte |= c - (T('A') - 10);
  2592. break;
  2593. }
  2594. else if (c == 0)
  2595. {
  2596. setSize ((int) (dest - data));
  2597. return;
  2598. }
  2599. }
  2600. }
  2601. *dest++ = (char) byte;
  2602. }
  2603. }
  2604. static const char* const encodingTable
  2605. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2606. const String MemoryBlock::toBase64Encoding() const throw()
  2607. {
  2608. const size_t numChars = ((size << 3) + 5) / 6;
  2609. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2610. const int initialLen = destString.length();
  2611. destString.preallocateStorage (initialLen + 2 + numChars);
  2612. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2613. *d++ = T('.');
  2614. for (size_t i = 0; i < numChars; ++i)
  2615. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2616. *d++ = 0;
  2617. return destString;
  2618. }
  2619. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2620. {
  2621. const int startPos = s.indexOfChar (T('.')) + 1;
  2622. if (startPos <= 0)
  2623. return false;
  2624. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2625. setSize (numBytesNeeded, true);
  2626. const int numChars = s.length() - startPos;
  2627. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2628. int pos = 0;
  2629. for (int i = 0; i < numChars; ++i)
  2630. {
  2631. const char c = (char) srcChars[i];
  2632. for (int j = 0; j < 64; ++j)
  2633. {
  2634. if (encodingTable[j] == c)
  2635. {
  2636. setBitRange (pos, 6, j);
  2637. pos += 6;
  2638. break;
  2639. }
  2640. }
  2641. }
  2642. return true;
  2643. }
  2644. END_JUCE_NAMESPACE
  2645. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2646. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2647. BEGIN_JUCE_NAMESPACE
  2648. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2649. : properties (ignoreCaseOfKeyNames),
  2650. fallbackProperties (0),
  2651. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2652. {
  2653. }
  2654. PropertySet::PropertySet (const PropertySet& other) throw()
  2655. : properties (other.properties),
  2656. fallbackProperties (other.fallbackProperties),
  2657. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2658. {
  2659. }
  2660. const PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2661. {
  2662. properties = other.properties;
  2663. fallbackProperties = other.fallbackProperties;
  2664. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2665. propertyChanged();
  2666. return *this;
  2667. }
  2668. PropertySet::~PropertySet()
  2669. {
  2670. }
  2671. void PropertySet::clear()
  2672. {
  2673. const ScopedLock sl (lock);
  2674. if (properties.size() > 0)
  2675. {
  2676. properties.clear();
  2677. propertyChanged();
  2678. }
  2679. }
  2680. const String PropertySet::getValue (const String& keyName,
  2681. const String& defaultValue) const throw()
  2682. {
  2683. const ScopedLock sl (lock);
  2684. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2685. if (index >= 0)
  2686. return properties.getAllValues() [index];
  2687. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2688. : defaultValue;
  2689. }
  2690. int PropertySet::getIntValue (const String& keyName,
  2691. const int defaultValue) const throw()
  2692. {
  2693. const ScopedLock sl (lock);
  2694. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2695. if (index >= 0)
  2696. return properties.getAllValues() [index].getIntValue();
  2697. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2698. : defaultValue;
  2699. }
  2700. double PropertySet::getDoubleValue (const String& keyName,
  2701. const double defaultValue) const throw()
  2702. {
  2703. const ScopedLock sl (lock);
  2704. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2705. if (index >= 0)
  2706. return properties.getAllValues()[index].getDoubleValue();
  2707. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2708. : defaultValue;
  2709. }
  2710. bool PropertySet::getBoolValue (const String& keyName,
  2711. const bool defaultValue) const throw()
  2712. {
  2713. const ScopedLock sl (lock);
  2714. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2715. if (index >= 0)
  2716. return properties.getAllValues() [index].getIntValue() != 0;
  2717. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2718. : defaultValue;
  2719. }
  2720. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2721. {
  2722. XmlDocument doc (getValue (keyName));
  2723. return doc.getDocumentElement();
  2724. }
  2725. void PropertySet::setValue (const String& keyName,
  2726. const String& value) throw()
  2727. {
  2728. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2729. if (keyName.isNotEmpty())
  2730. {
  2731. const ScopedLock sl (lock);
  2732. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2733. if (index < 0 || properties.getAllValues() [index] != value)
  2734. {
  2735. properties.set (keyName, value);
  2736. propertyChanged();
  2737. }
  2738. }
  2739. }
  2740. void PropertySet::removeValue (const String& keyName) throw()
  2741. {
  2742. if (keyName.isNotEmpty())
  2743. {
  2744. const ScopedLock sl (lock);
  2745. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2746. if (index >= 0)
  2747. {
  2748. properties.remove (keyName);
  2749. propertyChanged();
  2750. }
  2751. }
  2752. }
  2753. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2754. {
  2755. setValue (keyName, String (value));
  2756. }
  2757. void PropertySet::setValue (const String& keyName, const int value) throw()
  2758. {
  2759. setValue (keyName, String (value));
  2760. }
  2761. void PropertySet::setValue (const String& keyName, const double value) throw()
  2762. {
  2763. setValue (keyName, String (value));
  2764. }
  2765. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2766. {
  2767. setValue (keyName, String ((value) ? T("1") : T("0")));
  2768. }
  2769. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2770. {
  2771. setValue (keyName, (xml == 0) ? String::empty
  2772. : xml->createDocument (String::empty, true));
  2773. }
  2774. bool PropertySet::containsKey (const String& keyName) const throw()
  2775. {
  2776. const ScopedLock sl (lock);
  2777. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2778. }
  2779. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2780. {
  2781. const ScopedLock sl (lock);
  2782. fallbackProperties = fallbackProperties_;
  2783. }
  2784. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2785. {
  2786. const ScopedLock sl (lock);
  2787. XmlElement* const xml = new XmlElement (nodeName);
  2788. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2789. {
  2790. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2791. e->setAttribute (T("name"), properties.getAllKeys()[i]);
  2792. e->setAttribute (T("val"), properties.getAllValues()[i]);
  2793. }
  2794. return xml;
  2795. }
  2796. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2797. {
  2798. const ScopedLock sl (lock);
  2799. clear();
  2800. forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
  2801. {
  2802. if (e->hasAttribute (T("name"))
  2803. && e->hasAttribute (T("val")))
  2804. {
  2805. properties.set (e->getStringAttribute (T("name")),
  2806. e->getStringAttribute (T("val")));
  2807. }
  2808. }
  2809. if (properties.size() > 0)
  2810. propertyChanged();
  2811. }
  2812. void PropertySet::propertyChanged()
  2813. {
  2814. }
  2815. END_JUCE_NAMESPACE
  2816. /*** End of inlined file: juce_PropertySet.cpp ***/
  2817. /*** Start of inlined file: juce_Variant.cpp ***/
  2818. BEGIN_JUCE_NAMESPACE
  2819. var::var() throw()
  2820. : type (voidType)
  2821. {
  2822. value.doubleValue = 0;
  2823. }
  2824. var::~var() throw()
  2825. {
  2826. if (type == stringType)
  2827. delete value.stringValue;
  2828. else if (type == objectType && value.objectValue != 0)
  2829. value.objectValue->decReferenceCount();
  2830. }
  2831. const var var::null;
  2832. var::var (const var& valueToCopy)
  2833. : type (valueToCopy.type),
  2834. value (valueToCopy.value)
  2835. {
  2836. if (type == stringType)
  2837. value.stringValue = new String (*(value.stringValue));
  2838. else if (type == objectType && value.objectValue != 0)
  2839. value.objectValue->incReferenceCount();
  2840. }
  2841. var::var (const int value_) throw()
  2842. : type (intType)
  2843. {
  2844. value.intValue = value_;
  2845. }
  2846. var::var (const bool value_) throw()
  2847. : type (boolType)
  2848. {
  2849. value.boolValue = value_;
  2850. }
  2851. var::var (const double value_) throw()
  2852. : type (doubleType)
  2853. {
  2854. value.doubleValue = value_;
  2855. }
  2856. var::var (const String& value_)
  2857. : type (stringType)
  2858. {
  2859. value.stringValue = new String (value_);
  2860. }
  2861. var::var (const char* const value_)
  2862. : type (stringType)
  2863. {
  2864. value.stringValue = new String (value_);
  2865. }
  2866. var::var (const juce_wchar* const value_)
  2867. : type (stringType)
  2868. {
  2869. value.stringValue = new String (value_);
  2870. }
  2871. var::var (DynamicObject* const object)
  2872. : type (objectType)
  2873. {
  2874. value.objectValue = object;
  2875. if (object != 0)
  2876. object->incReferenceCount();
  2877. }
  2878. var::var (MethodFunction method_) throw()
  2879. : type (methodType)
  2880. {
  2881. value.methodValue = method_;
  2882. }
  2883. void var::swapWith (var& other) throw()
  2884. {
  2885. swapVariables (type, other.type);
  2886. swapVariables (value, other.value);
  2887. }
  2888. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2889. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2890. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2891. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2892. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2893. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2894. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2895. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2896. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2897. var::operator int() const
  2898. {
  2899. switch (type)
  2900. {
  2901. case voidType: break;
  2902. case intType: return value.intValue;
  2903. case boolType: return value.boolValue ? 1 : 0;
  2904. case doubleType: return (int) value.doubleValue;
  2905. case stringType: return value.stringValue->getIntValue();
  2906. case objectType: break;
  2907. default: jassertfalse; break;
  2908. }
  2909. return 0;
  2910. }
  2911. var::operator bool() const
  2912. {
  2913. switch (type)
  2914. {
  2915. case voidType: break;
  2916. case intType: return value.intValue != 0;
  2917. case boolType: return value.boolValue;
  2918. case doubleType: return value.doubleValue != 0;
  2919. case stringType: return value.stringValue->getIntValue() != 0
  2920. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2921. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2922. case objectType: return value.objectValue != 0;
  2923. default: jassertfalse; break;
  2924. }
  2925. return false;
  2926. }
  2927. var::operator float() const
  2928. {
  2929. return (float) operator double();
  2930. }
  2931. var::operator double() const
  2932. {
  2933. switch (type)
  2934. {
  2935. case voidType: break;
  2936. case intType: return value.intValue;
  2937. case boolType: return value.boolValue ? 1.0 : 0.0;
  2938. case doubleType: return value.doubleValue;
  2939. case stringType: return value.stringValue->getDoubleValue();
  2940. case objectType: break;
  2941. default: jassertfalse; break;
  2942. }
  2943. return 0.0;
  2944. }
  2945. const String var::toString() const
  2946. {
  2947. switch (type)
  2948. {
  2949. case voidType: return String::empty;
  2950. case intType: return String (value.intValue);
  2951. case boolType: return value.boolValue ? T("1") : T("0");
  2952. case doubleType: return String (value.doubleValue);
  2953. case stringType: return *(value.stringValue);
  2954. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  2955. case methodType: return "Method";
  2956. default: jassertfalse; break;
  2957. }
  2958. return String::empty;
  2959. }
  2960. var::operator const String() const
  2961. {
  2962. return toString();
  2963. }
  2964. DynamicObject* var::getObject() const
  2965. {
  2966. return type == objectType ? value.objectValue : 0;
  2967. }
  2968. bool var::operator== (const var& other) const throw()
  2969. {
  2970. switch (type)
  2971. {
  2972. case voidType: return other.isVoid();
  2973. case intType: return value.intValue == (int) other;
  2974. case boolType: return value.boolValue == (bool) other;
  2975. case doubleType: return value.doubleValue == (double) other;
  2976. case stringType: return (*(value.stringValue)) == other.toString();
  2977. case objectType: return value.objectValue == other.getObject();
  2978. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  2979. default: jassertfalse; break;
  2980. }
  2981. return false;
  2982. }
  2983. bool var::operator!= (const var& other) const throw()
  2984. {
  2985. return ! operator== (other);
  2986. }
  2987. void var::writeToStream (OutputStream& output) const
  2988. {
  2989. switch (type)
  2990. {
  2991. case voidType: output.writeCompressedInt (0); break;
  2992. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  2993. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  2994. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  2995. case stringType:
  2996. {
  2997. const int len = value.stringValue->copyToUTF8 (0);
  2998. output.writeCompressedInt (len + 1);
  2999. output.writeByte (5);
  3000. HeapBlock <uint8> temp (len);
  3001. value.stringValue->copyToUTF8 (temp);
  3002. output.write (temp, len);
  3003. break;
  3004. }
  3005. case objectType:
  3006. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3007. default: jassertfalse; break; // Is this a corrupted object?
  3008. }
  3009. }
  3010. const var var::readFromStream (InputStream& input)
  3011. {
  3012. const int numBytes = input.readCompressedInt();
  3013. if (numBytes > 0)
  3014. {
  3015. switch (input.readByte())
  3016. {
  3017. case 1: return var (input.readInt());
  3018. case 2: return var (true);
  3019. case 3: return var (false);
  3020. case 4: return var (input.readDouble());
  3021. case 5:
  3022. {
  3023. MemoryBlock mb;
  3024. input.readIntoMemoryBlock (mb, numBytes - 1);
  3025. return var (String::fromUTF8 ((const uint8*) mb.getData(), (int) mb.getSize()));
  3026. }
  3027. default: input.skipNextBytes (numBytes - 1); break;
  3028. }
  3029. }
  3030. return var::null;
  3031. }
  3032. const var var::operator[] (const var::identifier& propertyName) const
  3033. {
  3034. if (type == objectType && value.objectValue != 0)
  3035. return value.objectValue->getProperty (propertyName);
  3036. return var::null;
  3037. }
  3038. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3039. {
  3040. if (type == objectType && value.objectValue != 0)
  3041. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3042. return var::null;
  3043. }
  3044. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3045. {
  3046. if (isMethod())
  3047. {
  3048. DynamicObject* const target = targetObject.getObject();
  3049. if (target != 0)
  3050. return (target->*(value.methodValue)) (arguments, numArguments);
  3051. }
  3052. return var::null;
  3053. }
  3054. const var var::call (const var::identifier& method) const
  3055. {
  3056. return invoke (method, 0, 0);
  3057. }
  3058. const var var::call (const var::identifier& method, const var& arg1) const
  3059. {
  3060. return invoke (method, &arg1, 1);
  3061. }
  3062. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3063. {
  3064. var args[] = { arg1, arg2 };
  3065. return invoke (method, args, 2);
  3066. }
  3067. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3068. {
  3069. var args[] = { arg1, arg2, arg3 };
  3070. return invoke (method, args, 3);
  3071. }
  3072. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3073. {
  3074. var args[] = { arg1, arg2, arg3, arg4 };
  3075. return invoke (method, args, 4);
  3076. }
  3077. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3078. {
  3079. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3080. return invoke (method, args, 5);
  3081. }
  3082. var::identifier::identifier() throw()
  3083. : hashCode (0)
  3084. {
  3085. }
  3086. var::identifier::identifier (const String& name_)
  3087. : name (name_),
  3088. hashCode (name_.hashCode())
  3089. {
  3090. /* An identifier string must be suitable for use as a script variable or XML
  3091. attribute, so it can only contain this limited set of characters.. */
  3092. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3093. }
  3094. var::identifier::identifier (const char* const name_)
  3095. : name (name_),
  3096. hashCode (name.hashCode())
  3097. {
  3098. /* An identifier string must be suitable for use as a script variable or XML
  3099. attribute, so it can only contain this limited set of characters.. */
  3100. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3101. }
  3102. var::identifier::~identifier()
  3103. {
  3104. }
  3105. END_JUCE_NAMESPACE
  3106. /*** End of inlined file: juce_Variant.cpp ***/
  3107. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3108. BEGIN_JUCE_NAMESPACE
  3109. NamedValueSet::NamedValue::NamedValue() throw()
  3110. {
  3111. }
  3112. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3113. : name (name_), value (value_)
  3114. {
  3115. }
  3116. NamedValueSet::NamedValueSet() throw()
  3117. {
  3118. }
  3119. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3120. : values (other.values)
  3121. {
  3122. }
  3123. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3124. {
  3125. values = other.values;
  3126. return *this;
  3127. }
  3128. NamedValueSet::~NamedValueSet()
  3129. {
  3130. }
  3131. int NamedValueSet::size() const throw()
  3132. {
  3133. return values.size();
  3134. }
  3135. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3136. {
  3137. for (int i = values.size(); --i >= 0;)
  3138. {
  3139. const NamedValue& v = values.getReference(i);
  3140. if (v.name == name)
  3141. return v.value;
  3142. }
  3143. return var::null;
  3144. }
  3145. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3146. {
  3147. const var* v = getItem (name);
  3148. return v != 0 ? *v : defaultReturnValue;
  3149. }
  3150. var* NamedValueSet::getItem (const var::identifier& name) const
  3151. {
  3152. for (int i = values.size(); --i >= 0;)
  3153. {
  3154. NamedValue& v = values.getReference(i);
  3155. if (v.name == name)
  3156. return &(v.value);
  3157. }
  3158. return 0;
  3159. }
  3160. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3161. {
  3162. for (int i = values.size(); --i >= 0;)
  3163. {
  3164. NamedValue& v = values.getReference(i);
  3165. if (v.name == name)
  3166. {
  3167. if (v.value == newValue)
  3168. return false;
  3169. v.value = newValue;
  3170. return true;
  3171. }
  3172. }
  3173. values.add (NamedValue (name, newValue));
  3174. return true;
  3175. }
  3176. bool NamedValueSet::contains (const var::identifier& name) const
  3177. {
  3178. return getItem (name) != 0;
  3179. }
  3180. bool NamedValueSet::remove (const var::identifier& name)
  3181. {
  3182. for (int i = values.size(); --i >= 0;)
  3183. {
  3184. if (values.getReference(i).name == name)
  3185. {
  3186. values.remove (i);
  3187. return true;
  3188. }
  3189. }
  3190. return false;
  3191. }
  3192. const var::identifier NamedValueSet::getName (int index) const
  3193. {
  3194. jassert (((unsigned int) index) < (unsigned int) values.size());
  3195. return values [index].name;
  3196. }
  3197. void NamedValueSet::clear()
  3198. {
  3199. values.clear();
  3200. }
  3201. END_JUCE_NAMESPACE
  3202. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3203. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3204. BEGIN_JUCE_NAMESPACE
  3205. DynamicObject::DynamicObject()
  3206. {
  3207. }
  3208. DynamicObject::~DynamicObject()
  3209. {
  3210. }
  3211. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3212. {
  3213. var* const v = properties.getItem (propertyName);
  3214. return v != 0 && ! v->isMethod();
  3215. }
  3216. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3217. {
  3218. return properties [propertyName];
  3219. }
  3220. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3221. {
  3222. properties.set (propertyName, newValue);
  3223. }
  3224. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3225. {
  3226. properties.remove (propertyName);
  3227. }
  3228. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3229. {
  3230. return getProperty (methodName).isMethod();
  3231. }
  3232. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3233. const var* parameters,
  3234. int numParameters)
  3235. {
  3236. return properties [methodName].invoke (var (this), parameters, numParameters);
  3237. }
  3238. void DynamicObject::setMethod (const var::identifier& name,
  3239. var::MethodFunction methodFunction)
  3240. {
  3241. properties.set (name, var (methodFunction));
  3242. }
  3243. void DynamicObject::clear()
  3244. {
  3245. properties.clear();
  3246. }
  3247. END_JUCE_NAMESPACE
  3248. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3249. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3250. BEGIN_JUCE_NAMESPACE
  3251. static const uint32 initialPValues [18] =
  3252. {
  3253. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
  3254. 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3255. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
  3256. 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3257. 0x9216d5d9, 0x8979fb1b
  3258. };
  3259. static const uint32 initialSValues [4 * 256] =
  3260. {
  3261. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
  3262. 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3263. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
  3264. 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3265. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
  3266. 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3267. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
  3268. 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3269. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
  3270. 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3271. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
  3272. 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3273. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
  3274. 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3275. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
  3276. 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3277. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
  3278. 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3279. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
  3280. 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3281. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
  3282. 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3283. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
  3284. 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3285. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
  3286. 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3287. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
  3288. 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3289. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
  3290. 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3291. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
  3292. 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3293. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
  3294. 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3295. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
  3296. 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3297. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
  3298. 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3299. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
  3300. 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3301. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
  3302. 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3303. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
  3304. 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3305. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
  3306. 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3307. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
  3308. 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3309. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
  3310. 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3311. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
  3312. 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3313. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
  3314. 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3315. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
  3316. 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3317. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
  3318. 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3319. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
  3320. 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3321. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
  3322. 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3323. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
  3324. 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3325. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
  3326. 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3327. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
  3328. 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3329. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
  3330. 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3331. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
  3332. 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3333. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
  3334. 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3335. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
  3336. 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3337. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
  3338. 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3339. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
  3340. 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3341. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
  3342. 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3343. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
  3344. 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3345. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
  3346. 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3347. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
  3348. 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3349. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
  3350. 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3351. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
  3352. 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3353. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
  3354. 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3355. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
  3356. 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3357. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
  3358. 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3359. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
  3360. 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3361. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
  3362. 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3363. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
  3364. 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3365. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
  3366. 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3367. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
  3368. 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3369. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
  3370. 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3371. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
  3372. 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3373. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
  3374. 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3375. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
  3376. 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3377. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
  3378. 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3379. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
  3380. 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3381. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
  3382. 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3383. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
  3384. 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3385. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
  3386. 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3387. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
  3388. 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3389. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
  3390. 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3391. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
  3392. 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3393. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
  3394. 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3395. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
  3396. 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3397. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
  3398. 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3399. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
  3400. 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3401. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
  3402. 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3403. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
  3404. 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3405. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
  3406. 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3407. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
  3408. 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3409. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
  3410. 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3411. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
  3412. 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3413. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
  3414. 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3415. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
  3416. 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3417. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
  3418. 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3419. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
  3420. 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3421. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
  3422. 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3423. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
  3424. 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3425. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
  3426. 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3427. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
  3428. 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3429. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
  3430. 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3431. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
  3432. 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3433. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
  3434. 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3435. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
  3436. 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3437. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
  3438. 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3439. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
  3440. 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3441. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
  3442. 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3443. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
  3444. 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3445. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
  3446. 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3447. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
  3448. 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3449. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
  3450. 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3451. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
  3452. 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3453. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
  3454. 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3455. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
  3456. 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3457. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
  3458. 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3459. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
  3460. 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3461. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
  3462. 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3463. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
  3464. 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3465. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
  3466. 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3467. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
  3468. 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3469. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
  3470. 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3471. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
  3472. 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3473. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
  3474. 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3475. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
  3476. 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3477. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
  3478. 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3479. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
  3480. 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3481. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
  3482. 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3483. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
  3484. 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3485. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
  3486. 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3487. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
  3488. 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3489. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
  3490. 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3491. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
  3492. 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3493. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
  3494. 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3495. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
  3496. 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3497. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
  3498. 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3499. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
  3500. 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3501. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
  3502. 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3503. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
  3504. 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3505. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
  3506. 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3507. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
  3508. 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3509. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
  3510. 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3511. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
  3512. 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3513. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
  3514. 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3515. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
  3516. 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3517. };
  3518. BlowFish::BlowFish (const uint8* keyData, int keyBytes)
  3519. {
  3520. memcpy (p, initialPValues, sizeof (p));
  3521. int i, j;
  3522. for (i = 4; --i >= 0;)
  3523. {
  3524. s[i].malloc (256);
  3525. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3526. }
  3527. j = 0;
  3528. for (i = 0; i < 18; ++i)
  3529. {
  3530. uint32 d = 0;
  3531. for (int k = 0; k < 4; ++k)
  3532. {
  3533. d = (d << 8) | keyData[j];
  3534. if (++j >= keyBytes)
  3535. j = 0;
  3536. }
  3537. p[i] = initialPValues[i] ^ d;
  3538. }
  3539. uint32 l = 0, r = 0;
  3540. for (i = 0; i < 18; i += 2)
  3541. {
  3542. encrypt (l, r);
  3543. p[i] = l;
  3544. p[i + 1] = r;
  3545. }
  3546. for (i = 0; i < 4; ++i)
  3547. {
  3548. for (j = 0; j < 256; j += 2)
  3549. {
  3550. encrypt (l, r);
  3551. s[i][j] = l;
  3552. s[i][j + 1] = r;
  3553. }
  3554. }
  3555. }
  3556. BlowFish::BlowFish (const BlowFish& other)
  3557. {
  3558. for (int i = 4; --i >= 0;)
  3559. s[i].malloc (256);
  3560. operator= (other);
  3561. }
  3562. const BlowFish& BlowFish::operator= (const BlowFish& other)
  3563. {
  3564. memcpy (p, other.p, sizeof (p));
  3565. for (int i = 4; --i >= 0;)
  3566. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3567. return *this;
  3568. }
  3569. BlowFish::~BlowFish()
  3570. {
  3571. }
  3572. uint32 BlowFish::F (uint32 x) const
  3573. {
  3574. uint16 a, b, c, d;
  3575. uint32 y;
  3576. d = (uint16) (x & 0xff);
  3577. x >>= 8;
  3578. c = (uint16) (x & 0xff);
  3579. x >>= 8;
  3580. b = (uint16) (x & 0xff);
  3581. x >>= 8;
  3582. a = (uint16) (x & 0xff);
  3583. y = s[0][a] + s[1][b];
  3584. y = y ^ s[2][c];
  3585. y = y + s[3][d];
  3586. return y;
  3587. }
  3588. void BlowFish::encrypt (uint32& data1,
  3589. uint32& data2) const
  3590. {
  3591. uint32 l = data1;
  3592. uint32 r = data2;
  3593. for (int i = 0; i < 16; ++i)
  3594. {
  3595. l = l ^ p[i];
  3596. r = F (l) ^ r;
  3597. const uint32 temp = l;
  3598. l = r;
  3599. r = temp;
  3600. }
  3601. const uint32 temp = l;
  3602. l = r;
  3603. r = temp;
  3604. r = r ^ p[16];
  3605. l = l ^ p[17];
  3606. data1 = l;
  3607. data2 = r;
  3608. }
  3609. void BlowFish::decrypt (uint32& data1,
  3610. uint32& data2) const
  3611. {
  3612. uint32 l = data1;
  3613. uint32 r = data2;
  3614. for (int i = 17; i > 1; --i)
  3615. {
  3616. l =l ^ p[i];
  3617. r = F (l) ^ r;
  3618. const uint32 temp = l;
  3619. l = r;
  3620. r = temp;
  3621. }
  3622. const uint32 temp = l;
  3623. l = r;
  3624. r = temp;
  3625. r = r ^ p[1];
  3626. l = l ^ p[0];
  3627. data1 = l;
  3628. data2 = r;
  3629. }
  3630. END_JUCE_NAMESPACE
  3631. /*** End of inlined file: juce_BlowFish.cpp ***/
  3632. /*** Start of inlined file: juce_MD5.cpp ***/
  3633. BEGIN_JUCE_NAMESPACE
  3634. MD5::MD5()
  3635. {
  3636. zeromem (result, sizeof (result));
  3637. }
  3638. MD5::MD5 (const MD5& other)
  3639. {
  3640. memcpy (result, other.result, sizeof (result));
  3641. }
  3642. const MD5& MD5::operator= (const MD5& other)
  3643. {
  3644. memcpy (result, other.result, sizeof (result));
  3645. return *this;
  3646. }
  3647. MD5::MD5 (const MemoryBlock& data)
  3648. {
  3649. ProcessContext context;
  3650. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3651. context.finish (result);
  3652. }
  3653. MD5::MD5 (const char* data, const size_t numBytes)
  3654. {
  3655. ProcessContext context;
  3656. context.processBlock ((const uint8*) data, numBytes);
  3657. context.finish (result);
  3658. }
  3659. MD5::MD5 (const String& text)
  3660. {
  3661. ProcessContext context;
  3662. const int len = text.length();
  3663. const juce_wchar* const t = text;
  3664. for (int i = 0; i < len; ++i)
  3665. {
  3666. // force the string into integer-sized unicode characters, to try to make it
  3667. // get the same results on all platforms + compilers.
  3668. uint32 unicodeChar = (uint32) t[i];
  3669. ByteOrder::swapIfBigEndian (unicodeChar);
  3670. context.processBlock ((const uint8*) &unicodeChar,
  3671. sizeof (unicodeChar));
  3672. }
  3673. context.finish (result);
  3674. }
  3675. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3676. {
  3677. ProcessContext context;
  3678. if (numBytesToRead < 0)
  3679. numBytesToRead = std::numeric_limits<int64>::max();
  3680. while (numBytesToRead > 0)
  3681. {
  3682. char tempBuffer [512];
  3683. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3684. if (bytesRead <= 0)
  3685. break;
  3686. numBytesToRead -= bytesRead;
  3687. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3688. }
  3689. context.finish (result);
  3690. }
  3691. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3692. {
  3693. processStream (input, numBytesToRead);
  3694. }
  3695. MD5::MD5 (const File& file)
  3696. {
  3697. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3698. if (fin != 0)
  3699. processStream (*fin, -1);
  3700. else
  3701. zeromem (result, sizeof (result));
  3702. }
  3703. MD5::~MD5()
  3704. {
  3705. }
  3706. MD5::ProcessContext::ProcessContext()
  3707. {
  3708. state[0] = 0x67452301;
  3709. state[1] = 0xefcdab89;
  3710. state[2] = 0x98badcfe;
  3711. state[3] = 0x10325476;
  3712. count[0] = 0;
  3713. count[1] = 0;
  3714. }
  3715. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3716. {
  3717. int bufferPos = ((count[0] >> 3) & 0x3F);
  3718. count[0] += (uint32) (dataSize << 3);
  3719. if (count[0] < ((uint32) dataSize << 3))
  3720. count[1]++;
  3721. count[1] += (uint32) (dataSize >> 29);
  3722. const size_t spaceLeft = 64 - bufferPos;
  3723. size_t i = 0;
  3724. if (dataSize >= spaceLeft)
  3725. {
  3726. memcpy (buffer + bufferPos, data, spaceLeft);
  3727. transform (buffer);
  3728. i = spaceLeft;
  3729. while (i + 64 <= dataSize)
  3730. {
  3731. transform (data + i);
  3732. i += 64;
  3733. }
  3734. bufferPos = 0;
  3735. }
  3736. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3737. }
  3738. static void encode (uint8* const output,
  3739. const uint32* const input,
  3740. const int numBytes)
  3741. {
  3742. uint32* const o = (uint32*) output;
  3743. for (int i = 0; i < (numBytes >> 2); ++i)
  3744. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3745. }
  3746. static void decode (uint32* const output,
  3747. const uint8* const input,
  3748. const int numBytes)
  3749. {
  3750. for (int i = 0; i < (numBytes >> 2); ++i)
  3751. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3752. }
  3753. void MD5::ProcessContext::finish (uint8* const result)
  3754. {
  3755. unsigned char encodedLength[8];
  3756. encode (encodedLength, count, 8);
  3757. // Pad out to 56 mod 64.
  3758. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3759. const int paddingLength = (index < 56) ? (56 - index)
  3760. : (120 - index);
  3761. uint8 paddingBuffer [64];
  3762. zeromem (paddingBuffer, paddingLength);
  3763. paddingBuffer [0] = 0x80;
  3764. processBlock (paddingBuffer, paddingLength);
  3765. processBlock (encodedLength, 8);
  3766. encode (result, state, 16);
  3767. zeromem (buffer, sizeof (buffer));
  3768. }
  3769. #define S11 7
  3770. #define S12 12
  3771. #define S13 17
  3772. #define S14 22
  3773. #define S21 5
  3774. #define S22 9
  3775. #define S23 14
  3776. #define S24 20
  3777. #define S31 4
  3778. #define S32 11
  3779. #define S33 16
  3780. #define S34 23
  3781. #define S41 6
  3782. #define S42 10
  3783. #define S43 15
  3784. #define S44 21
  3785. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) { return (x & y) | (~x & z); }
  3786. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) { return (x & z) | (y & ~z); }
  3787. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) { return x ^ y ^ z; }
  3788. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) { return y ^ (x | ~z); }
  3789. static inline uint32 rotateLeft (const uint32 x, const uint32 n) { return (x << n) | (x >> (32 - n)); }
  3790. static inline void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3791. {
  3792. a += F (b, c, d) + x + ac;
  3793. a = rotateLeft (a, s) + b;
  3794. }
  3795. static inline void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3796. {
  3797. a += G (b, c, d) + x + ac;
  3798. a = rotateLeft (a, s) + b;
  3799. }
  3800. static inline void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3801. {
  3802. a += H (b, c, d) + x + ac;
  3803. a = rotateLeft (a, s) + b;
  3804. }
  3805. static inline void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3806. {
  3807. a += I (b, c, d) + x + ac;
  3808. a = rotateLeft (a, s) + b;
  3809. }
  3810. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3811. {
  3812. uint32 a = state[0];
  3813. uint32 b = state[1];
  3814. uint32 c = state[2];
  3815. uint32 d = state[3];
  3816. uint32 x[16];
  3817. decode (x, bufferToTransform, 64);
  3818. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3819. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3820. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3821. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3822. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3823. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3824. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3825. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3826. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3827. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3828. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3829. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3830. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3831. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3832. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3833. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3834. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3835. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3836. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3837. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3838. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3839. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3840. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3841. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3842. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3843. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3844. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3845. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3846. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3847. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3848. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3849. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3850. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3851. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3852. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3853. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3854. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3855. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3856. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3857. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3858. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3859. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3860. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3861. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3862. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3863. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3864. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3865. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3866. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3867. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3868. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3869. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3870. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3871. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3872. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3873. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3874. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3875. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3876. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3877. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3878. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3879. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3880. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3881. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3882. state[0] += a;
  3883. state[1] += b;
  3884. state[2] += c;
  3885. state[3] += d;
  3886. zeromem (x, sizeof (x));
  3887. }
  3888. const MemoryBlock MD5::getRawChecksumData() const
  3889. {
  3890. return MemoryBlock (result, 16);
  3891. }
  3892. const String MD5::toHexString() const
  3893. {
  3894. return String::toHexString (result, 16, 0);
  3895. }
  3896. bool MD5::operator== (const MD5& other) const
  3897. {
  3898. return memcmp (result, other.result, 16) == 0;
  3899. }
  3900. bool MD5::operator!= (const MD5& other) const
  3901. {
  3902. return ! operator== (other);
  3903. }
  3904. END_JUCE_NAMESPACE
  3905. /*** End of inlined file: juce_MD5.cpp ***/
  3906. /*** Start of inlined file: juce_Primes.cpp ***/
  3907. BEGIN_JUCE_NAMESPACE
  3908. static void createSmallSieve (const int numBits, BitArray& result) throw()
  3909. {
  3910. result.setBit (numBits);
  3911. result.clearBit (numBits); // to enlarge the array
  3912. result.setBit (0);
  3913. int n = 2;
  3914. do
  3915. {
  3916. for (int i = n + n; i < numBits; i += n)
  3917. result.setBit (i);
  3918. n = result.findNextClearBit (n + 1);
  3919. }
  3920. while (n <= (numBits >> 1));
  3921. }
  3922. static void bigSieve (const BitArray& base,
  3923. const int numBits,
  3924. BitArray& result,
  3925. const BitArray& smallSieve,
  3926. const int smallSieveSize) throw()
  3927. {
  3928. jassert (! base[0]); // must be even!
  3929. result.setBit (numBits);
  3930. result.clearBit (numBits); // to enlarge the array
  3931. int index = smallSieve.findNextClearBit (0);
  3932. do
  3933. {
  3934. const int prime = (index << 1) + 1;
  3935. BitArray r (base);
  3936. BitArray remainder;
  3937. r.divideBy (prime, remainder);
  3938. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3939. if (r.isEmpty())
  3940. i += prime;
  3941. if ((i & 1) == 0)
  3942. i += prime;
  3943. i = (i - 1) >> 1;
  3944. while (i < numBits)
  3945. {
  3946. result.setBit (i);
  3947. i += prime;
  3948. }
  3949. index = smallSieve.findNextClearBit (index + 1);
  3950. }
  3951. while (index < smallSieveSize);
  3952. }
  3953. static bool findCandidate (const BitArray& base,
  3954. const BitArray& sieve,
  3955. const int numBits,
  3956. BitArray& result,
  3957. const int certainty) throw()
  3958. {
  3959. for (int i = 0; i < numBits; ++i)
  3960. {
  3961. if (! sieve[i])
  3962. {
  3963. result = base;
  3964. result.add (BitArray ((unsigned int) ((i << 1) + 1)));
  3965. if (Primes::isProbablyPrime (result, certainty))
  3966. return true;
  3967. }
  3968. }
  3969. return false;
  3970. }
  3971. const BitArray Primes::createProbablePrime (const int bitLength,
  3972. const int certainty,
  3973. const int* randomSeeds,
  3974. int numRandomSeeds) throw()
  3975. {
  3976. int defaultSeeds [16];
  3977. if (numRandomSeeds <= 0)
  3978. {
  3979. randomSeeds = defaultSeeds;
  3980. numRandomSeeds = numElementsInArray (defaultSeeds);
  3981. Random r (0);
  3982. for (int j = 10; --j >= 0;)
  3983. {
  3984. r.setSeedRandomly();
  3985. for (int i = numRandomSeeds; --i >= 0;)
  3986. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3987. }
  3988. }
  3989. BitArray smallSieve;
  3990. const int smallSieveSize = 15000;
  3991. createSmallSieve (smallSieveSize, smallSieve);
  3992. BitArray p;
  3993. for (int i = numRandomSeeds; --i >= 0;)
  3994. {
  3995. BitArray p2;
  3996. Random r (randomSeeds[i]);
  3997. r.fillBitsRandomly (p2, 0, bitLength);
  3998. p.xorWith (p2);
  3999. }
  4000. p.setBit (bitLength - 1);
  4001. p.clearBit (0);
  4002. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  4003. while (p.getHighestBit() < bitLength)
  4004. {
  4005. p.add (2 * searchLen);
  4006. BitArray sieve;
  4007. bigSieve (p, searchLen, sieve,
  4008. smallSieve, smallSieveSize);
  4009. BitArray candidate;
  4010. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  4011. return candidate;
  4012. }
  4013. jassertfalse
  4014. return BitArray();
  4015. }
  4016. static bool passesMillerRabin (const BitArray& n, int iterations) throw()
  4017. {
  4018. const BitArray one (1);
  4019. const BitArray two (2);
  4020. BitArray nMinusOne (n);
  4021. nMinusOne.subtract (one);
  4022. BitArray d (nMinusOne);
  4023. const int s = d.findNextSetBit (0);
  4024. d.shiftBits (-s);
  4025. BitArray smallPrimes;
  4026. int numBitsInSmallPrimes = 0;
  4027. for (;;)
  4028. {
  4029. numBitsInSmallPrimes += 256;
  4030. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  4031. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  4032. if (numPrimesFound > iterations + 1)
  4033. break;
  4034. }
  4035. int smallPrime = 2;
  4036. while (--iterations >= 0)
  4037. {
  4038. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  4039. BitArray r (smallPrime);
  4040. //r.createRandomNumber (nMinusOne);
  4041. r.exponentModulo (d, n);
  4042. if (! (r == one || r == nMinusOne))
  4043. {
  4044. for (int j = 0; j < s; ++j)
  4045. {
  4046. r.exponentModulo (two, n);
  4047. if (r == nMinusOne)
  4048. break;
  4049. }
  4050. if (r != nMinusOne)
  4051. return false;
  4052. }
  4053. }
  4054. return true;
  4055. }
  4056. bool Primes::isProbablyPrime (const BitArray& number,
  4057. const int certainty) throw()
  4058. {
  4059. if (! number[0])
  4060. return false;
  4061. if (number.getHighestBit() <= 10)
  4062. {
  4063. const int num = number.getBitRangeAsInt (0, 10);
  4064. for (int i = num / 2; --i > 1;)
  4065. if (num % i == 0)
  4066. return false;
  4067. return true;
  4068. }
  4069. else
  4070. {
  4071. const BitArray screen (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23);
  4072. if (number.findGreatestCommonDivisor (screen) != BitArray (1))
  4073. return false;
  4074. return passesMillerRabin (number, certainty);
  4075. }
  4076. }
  4077. END_JUCE_NAMESPACE
  4078. /*** End of inlined file: juce_Primes.cpp ***/
  4079. /*** Start of inlined file: juce_RSAKey.cpp ***/
  4080. BEGIN_JUCE_NAMESPACE
  4081. RSAKey::RSAKey() throw()
  4082. {
  4083. }
  4084. RSAKey::RSAKey (const String& s) throw()
  4085. {
  4086. if (s.containsChar (T(',')))
  4087. {
  4088. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  4089. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  4090. }
  4091. else
  4092. {
  4093. // the string needs to be two hex numbers, comma-separated..
  4094. jassertfalse;
  4095. }
  4096. }
  4097. RSAKey::~RSAKey() throw()
  4098. {
  4099. }
  4100. const String RSAKey::toString() const throw()
  4101. {
  4102. return part1.toString (16) + T(",") + part2.toString (16);
  4103. }
  4104. bool RSAKey::applyToValue (BitArray& value) const throw()
  4105. {
  4106. if (part1.isEmpty() || part2.isEmpty()
  4107. || value.compare (0) <= 0)
  4108. {
  4109. jassertfalse // using an uninitialised key
  4110. value.clear();
  4111. return false;
  4112. }
  4113. BitArray result;
  4114. while (! value.isEmpty())
  4115. {
  4116. result.multiplyBy (part2);
  4117. BitArray remainder;
  4118. value.divideBy (part2, remainder);
  4119. remainder.exponentModulo (part1, part2);
  4120. result.add (remainder);
  4121. }
  4122. value = result;
  4123. return true;
  4124. }
  4125. static const BitArray findBestCommonDivisor (const BitArray& p,
  4126. const BitArray& q) throw()
  4127. {
  4128. const BitArray one (1);
  4129. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  4130. // are fast to divide + multiply
  4131. for (int i = 2; i <= 65536; i *= 2)
  4132. {
  4133. const BitArray e (1 + i);
  4134. if (e.findGreatestCommonDivisor (p) == one
  4135. && e.findGreatestCommonDivisor (q) == one)
  4136. {
  4137. return e;
  4138. }
  4139. }
  4140. BitArray e (4);
  4141. while (! (e.findGreatestCommonDivisor (p) == one
  4142. && e.findGreatestCommonDivisor (q) == one))
  4143. {
  4144. e.add (one);
  4145. }
  4146. return e;
  4147. }
  4148. void RSAKey::createKeyPair (RSAKey& publicKey,
  4149. RSAKey& privateKey,
  4150. const int numBits,
  4151. const int* randomSeeds,
  4152. const int numRandomSeeds) throw()
  4153. {
  4154. jassert (numBits > 16); // not much point using less than this..
  4155. BitArray p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4156. BitArray q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4157. BitArray n (p);
  4158. n.multiplyBy (q); // n = pq
  4159. const BitArray one (1);
  4160. p.subtract (one);
  4161. q.subtract (one);
  4162. BitArray m (p);
  4163. m.multiplyBy (q); // m = (p - 1)(q - 1)
  4164. const BitArray e (findBestCommonDivisor (p, q));
  4165. BitArray d (e);
  4166. d.inverseModulo (m);
  4167. publicKey.part1 = e;
  4168. publicKey.part2 = n;
  4169. privateKey.part1 = d;
  4170. privateKey.part2 = n;
  4171. }
  4172. END_JUCE_NAMESPACE
  4173. /*** End of inlined file: juce_RSAKey.cpp ***/
  4174. /*** Start of inlined file: juce_InputStream.cpp ***/
  4175. BEGIN_JUCE_NAMESPACE
  4176. char InputStream::readByte()
  4177. {
  4178. char temp = 0;
  4179. read (&temp, 1);
  4180. return temp;
  4181. }
  4182. bool InputStream::readBool()
  4183. {
  4184. return readByte() != 0;
  4185. }
  4186. short InputStream::readShort()
  4187. {
  4188. char temp [2];
  4189. if (read (temp, 2) == 2)
  4190. return (short) ByteOrder::littleEndianShort (temp);
  4191. else
  4192. return 0;
  4193. }
  4194. short InputStream::readShortBigEndian()
  4195. {
  4196. char temp [2];
  4197. if (read (temp, 2) == 2)
  4198. return (short) ByteOrder::bigEndianShort (temp);
  4199. else
  4200. return 0;
  4201. }
  4202. int InputStream::readInt()
  4203. {
  4204. char temp [4];
  4205. if (read (temp, 4) == 4)
  4206. return (int) ByteOrder::littleEndianInt (temp);
  4207. else
  4208. return 0;
  4209. }
  4210. int InputStream::readIntBigEndian()
  4211. {
  4212. char temp [4];
  4213. if (read (temp, 4) == 4)
  4214. return (int) ByteOrder::bigEndianInt (temp);
  4215. else
  4216. return 0;
  4217. }
  4218. int InputStream::readCompressedInt()
  4219. {
  4220. const unsigned char sizeByte = readByte();
  4221. if (sizeByte == 0)
  4222. return 0;
  4223. const int numBytes = (sizeByte & 0x7f);
  4224. if (numBytes > 4)
  4225. {
  4226. jassertfalse // trying to read corrupt data - this method must only be used
  4227. // to read data that was written by OutputStream::writeCompressedInt()
  4228. return 0;
  4229. }
  4230. char bytes[4] = { 0, 0, 0, 0 };
  4231. if (read (bytes, numBytes) != numBytes)
  4232. return 0;
  4233. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4234. return (sizeByte >> 7) ? -num : num;
  4235. }
  4236. int64 InputStream::readInt64()
  4237. {
  4238. char temp [8];
  4239. if (read (temp, 8) == 8)
  4240. return (int64) ByteOrder::swapIfBigEndian (*(uint64*) temp);
  4241. else
  4242. return 0;
  4243. }
  4244. int64 InputStream::readInt64BigEndian()
  4245. {
  4246. char temp [8];
  4247. if (read (temp, 8) == 8)
  4248. return (int64) ByteOrder::swapIfLittleEndian (*(uint64*) temp);
  4249. else
  4250. return 0;
  4251. }
  4252. float InputStream::readFloat()
  4253. {
  4254. union { int asInt; float asFloat; } n;
  4255. n.asInt = readInt();
  4256. return n.asFloat;
  4257. }
  4258. float InputStream::readFloatBigEndian()
  4259. {
  4260. union { int asInt; float asFloat; } n;
  4261. n.asInt = readIntBigEndian();
  4262. return n.asFloat;
  4263. }
  4264. double InputStream::readDouble()
  4265. {
  4266. union { int64 asInt; double asDouble; } n;
  4267. n.asInt = readInt64();
  4268. return n.asDouble;
  4269. }
  4270. double InputStream::readDoubleBigEndian()
  4271. {
  4272. union { int64 asInt; double asDouble; } n;
  4273. n.asInt = readInt64BigEndian();
  4274. return n.asDouble;
  4275. }
  4276. const String InputStream::readString()
  4277. {
  4278. MemoryBlock buffer (256);
  4279. uint8* data = (uint8*) buffer.getData();
  4280. size_t i = 0;
  4281. while ((data[i] = readByte()) != 0)
  4282. {
  4283. if (++i >= buffer.getSize())
  4284. {
  4285. buffer.setSize (buffer.getSize() + 512);
  4286. data = (uint8*) buffer.getData();
  4287. }
  4288. }
  4289. return String::fromUTF8 (data, (int) i);
  4290. }
  4291. const String InputStream::readNextLine()
  4292. {
  4293. MemoryBlock buffer (256);
  4294. uint8* data = (uint8*) buffer.getData();
  4295. size_t i = 0;
  4296. while ((data[i] = readByte()) != 0)
  4297. {
  4298. if (data[i] == '\n')
  4299. break;
  4300. if (data[i] == '\r')
  4301. {
  4302. const int64 lastPos = getPosition();
  4303. if (readByte() != '\n')
  4304. setPosition (lastPos);
  4305. break;
  4306. }
  4307. if (++i >= buffer.getSize())
  4308. {
  4309. buffer.setSize (buffer.getSize() + 512);
  4310. data = (uint8*) buffer.getData();
  4311. }
  4312. }
  4313. return String::fromUTF8 (data, (int) i);
  4314. }
  4315. int InputStream::readIntoMemoryBlock (MemoryBlock& block,
  4316. int numBytes)
  4317. {
  4318. const int64 totalLength = getTotalLength();
  4319. if (totalLength >= 0)
  4320. {
  4321. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4322. totalLength - getPosition());
  4323. if (numBytes < 0)
  4324. numBytes = totalBytesRemaining;
  4325. else if (numBytes > 0)
  4326. numBytes = jmin (numBytes, totalBytesRemaining);
  4327. else
  4328. return 0;
  4329. }
  4330. const size_t originalBlockSize = block.getSize();
  4331. int totalBytesRead = 0;
  4332. if (numBytes > 0)
  4333. {
  4334. // know how many bytes we want, so we can resize the block first..
  4335. block.setSize (originalBlockSize + numBytes, false);
  4336. totalBytesRead = read (((char*) block.getData()) + originalBlockSize, numBytes);
  4337. }
  4338. else
  4339. {
  4340. // read until end of stram..
  4341. const int chunkSize = 32768;
  4342. for (;;)
  4343. {
  4344. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4345. const int bytesJustIn = read (((char*) block.getData())
  4346. + originalBlockSize
  4347. + totalBytesRead,
  4348. chunkSize);
  4349. if (bytesJustIn == 0)
  4350. break;
  4351. totalBytesRead += bytesJustIn;
  4352. }
  4353. }
  4354. // trim off any excess left at the end
  4355. block.setSize (originalBlockSize + totalBytesRead, false);
  4356. return totalBytesRead;
  4357. }
  4358. const String InputStream::readEntireStreamAsString()
  4359. {
  4360. MemoryBlock mb;
  4361. const int size = readIntoMemoryBlock (mb);
  4362. return String::createStringFromData ((const char*) mb.getData(), size);
  4363. }
  4364. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4365. {
  4366. if (numBytesToSkip > 0)
  4367. {
  4368. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4369. HeapBlock <char> temp (skipBufferSize);
  4370. while (numBytesToSkip > 0 && ! isExhausted())
  4371. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4372. }
  4373. }
  4374. END_JUCE_NAMESPACE
  4375. /*** End of inlined file: juce_InputStream.cpp ***/
  4376. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4377. BEGIN_JUCE_NAMESPACE
  4378. #if JUCE_DEBUG
  4379. static CriticalSection activeStreamLock;
  4380. static VoidArray activeStreams;
  4381. void juce_CheckForDanglingStreams()
  4382. {
  4383. /*
  4384. It's always a bad idea to leak any object, but if you're leaking output
  4385. streams, then there's a good chance that you're failing to flush a file
  4386. to disk properly, which could result in corrupted data and other similar
  4387. nastiness..
  4388. */
  4389. jassert (activeStreams.size() == 0);
  4390. };
  4391. #endif
  4392. OutputStream::OutputStream() throw()
  4393. {
  4394. #if JUCE_DEBUG
  4395. activeStreamLock.enter();
  4396. activeStreams.add (this);
  4397. activeStreamLock.exit();
  4398. #endif
  4399. }
  4400. OutputStream::~OutputStream()
  4401. {
  4402. #if JUCE_DEBUG
  4403. activeStreamLock.enter();
  4404. activeStreams.removeValue (this);
  4405. activeStreamLock.exit();
  4406. #endif
  4407. }
  4408. void OutputStream::writeBool (bool b)
  4409. {
  4410. writeByte ((b) ? (char) 1
  4411. : (char) 0);
  4412. }
  4413. void OutputStream::writeByte (char byte)
  4414. {
  4415. write (&byte, 1);
  4416. }
  4417. void OutputStream::writeShort (short value)
  4418. {
  4419. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4420. write (&v, 2);
  4421. }
  4422. void OutputStream::writeShortBigEndian (short value)
  4423. {
  4424. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4425. write (&v, 2);
  4426. }
  4427. void OutputStream::writeInt (int value)
  4428. {
  4429. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4430. write (&v, 4);
  4431. }
  4432. void OutputStream::writeIntBigEndian (int value)
  4433. {
  4434. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4435. write (&v, 4);
  4436. }
  4437. void OutputStream::writeCompressedInt (int value)
  4438. {
  4439. unsigned int un = (value < 0) ? (unsigned int) -value
  4440. : (unsigned int) value;
  4441. uint8 data[5];
  4442. int num = 0;
  4443. while (un > 0)
  4444. {
  4445. data[++num] = (uint8) un;
  4446. un >>= 8;
  4447. }
  4448. data[0] = (uint8) num;
  4449. if (value < 0)
  4450. data[0] |= 0x80;
  4451. write (data, num + 1);
  4452. }
  4453. void OutputStream::writeInt64 (int64 value)
  4454. {
  4455. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4456. write (&v, 8);
  4457. }
  4458. void OutputStream::writeInt64BigEndian (int64 value)
  4459. {
  4460. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4461. write (&v, 8);
  4462. }
  4463. void OutputStream::writeFloat (float value)
  4464. {
  4465. union { int asInt; float asFloat; } n;
  4466. n.asFloat = value;
  4467. writeInt (n.asInt);
  4468. }
  4469. void OutputStream::writeFloatBigEndian (float value)
  4470. {
  4471. union { int asInt; float asFloat; } n;
  4472. n.asFloat = value;
  4473. writeIntBigEndian (n.asInt);
  4474. }
  4475. void OutputStream::writeDouble (double value)
  4476. {
  4477. union { int64 asInt; double asDouble; } n;
  4478. n.asDouble = value;
  4479. writeInt64 (n.asInt);
  4480. }
  4481. void OutputStream::writeDoubleBigEndian (double value)
  4482. {
  4483. union { int64 asInt; double asDouble; } n;
  4484. n.asDouble = value;
  4485. writeInt64BigEndian (n.asInt);
  4486. }
  4487. void OutputStream::writeString (const String& text)
  4488. {
  4489. const int numBytes = text.copyToUTF8 (0);
  4490. HeapBlock <uint8> temp (numBytes);
  4491. text.copyToUTF8 (temp);
  4492. write (temp, numBytes); // (numBytes includes the terminating null).
  4493. }
  4494. void OutputStream::printf (const char* pf, ...)
  4495. {
  4496. unsigned int bufSize = 256;
  4497. HeapBlock <char> buf (bufSize);
  4498. for (;;)
  4499. {
  4500. va_list list;
  4501. va_start (list, pf);
  4502. const int num = CharacterFunctions::vprintf (buf, bufSize, pf, list);
  4503. va_end (list);
  4504. if (num > 0)
  4505. {
  4506. write (buf, num);
  4507. break;
  4508. }
  4509. else if (num == 0)
  4510. {
  4511. break;
  4512. }
  4513. bufSize += 256;
  4514. buf.malloc (bufSize);
  4515. }
  4516. }
  4517. OutputStream& OutputStream::operator<< (const int number)
  4518. {
  4519. const String s (number);
  4520. write ((const char*) s, s.length());
  4521. return *this;
  4522. }
  4523. OutputStream& OutputStream::operator<< (const double number)
  4524. {
  4525. const String s (number);
  4526. write ((const char*) s, s.length());
  4527. return *this;
  4528. }
  4529. OutputStream& OutputStream::operator<< (const char character)
  4530. {
  4531. writeByte (character);
  4532. return *this;
  4533. }
  4534. OutputStream& OutputStream::operator<< (const char* const text)
  4535. {
  4536. write (text, (int) strlen (text));
  4537. return *this;
  4538. }
  4539. OutputStream& OutputStream::operator<< (const juce_wchar* const text)
  4540. {
  4541. const String s (text);
  4542. write ((const char*) s, s.length());
  4543. return *this;
  4544. }
  4545. OutputStream& OutputStream::operator<< (const String& text)
  4546. {
  4547. write ((const char*) text,
  4548. text.length());
  4549. return *this;
  4550. }
  4551. void OutputStream::writeText (const String& text,
  4552. const bool asUnicode,
  4553. const bool writeUnicodeHeaderBytes)
  4554. {
  4555. if (asUnicode)
  4556. {
  4557. if (writeUnicodeHeaderBytes)
  4558. write ("\x0ff\x0fe", 2);
  4559. const juce_wchar* src = (const juce_wchar*) text;
  4560. bool lastCharWasReturn = false;
  4561. while (*src != 0)
  4562. {
  4563. if (*src == L'\n' && ! lastCharWasReturn)
  4564. writeShort ((short) L'\r');
  4565. lastCharWasReturn = (*src == L'\r');
  4566. writeShort ((short) *src++);
  4567. }
  4568. }
  4569. else
  4570. {
  4571. const char* src = (const char*) text;
  4572. const char* t = src;
  4573. for (;;)
  4574. {
  4575. if (*t == '\n')
  4576. {
  4577. if (t > src)
  4578. write (src, (int) (t - src));
  4579. write ("\r\n", 2);
  4580. src = t + 1;
  4581. }
  4582. else if (*t == '\r')
  4583. {
  4584. if (t[1] == '\n')
  4585. ++t;
  4586. }
  4587. else if (*t == 0)
  4588. {
  4589. if (t > src)
  4590. write (src, (int) (t - src));
  4591. break;
  4592. }
  4593. ++t;
  4594. }
  4595. }
  4596. }
  4597. int OutputStream::writeFromInputStream (InputStream& source,
  4598. int numBytesToWrite)
  4599. {
  4600. if (numBytesToWrite < 0)
  4601. numBytesToWrite = 0x7fffffff;
  4602. int numWritten = 0;
  4603. while (numBytesToWrite > 0 && ! source.isExhausted())
  4604. {
  4605. char buffer [8192];
  4606. const int num = source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4607. if (num == 0)
  4608. break;
  4609. write (buffer, num);
  4610. numBytesToWrite -= num;
  4611. numWritten += num;
  4612. }
  4613. return numWritten;
  4614. }
  4615. END_JUCE_NAMESPACE
  4616. /*** End of inlined file: juce_OutputStream.cpp ***/
  4617. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4618. BEGIN_JUCE_NAMESPACE
  4619. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4620. bool* isDirectory, bool* isHidden, int64* fileSize,
  4621. Time* modTime, Time* creationTime, bool* isReadOnly);
  4622. bool juce_findFileNext (void* handle, String& resultFile,
  4623. bool* isDirectory, bool* isHidden, int64* fileSize,
  4624. Time* modTime, Time* creationTime, bool* isReadOnly);
  4625. void juce_findFileClose (void* handle);
  4626. DirectoryIterator::DirectoryIterator (const File& directory,
  4627. bool isRecursive,
  4628. const String& wc,
  4629. const int whatToLookFor_)
  4630. : wildCard (wc),
  4631. index (-1),
  4632. whatToLookFor (whatToLookFor_)
  4633. {
  4634. // you have to specify the type of files you're looking for!
  4635. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4636. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4637. String path (directory.getFullPathName());
  4638. if (! path.endsWithChar (File::separator))
  4639. path += File::separator;
  4640. String filename;
  4641. bool isDirectory, isHidden;
  4642. void* const handle = juce_findFileStart (path,
  4643. isRecursive ? T("*") : wc,
  4644. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4645. if (handle != 0)
  4646. {
  4647. do
  4648. {
  4649. if (! filename.containsOnly (T(".")))
  4650. {
  4651. bool addToList = false;
  4652. if (isDirectory)
  4653. {
  4654. if (isRecursive
  4655. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4656. || ! isHidden))
  4657. {
  4658. dirsFound.add (File (path + filename, 0));
  4659. }
  4660. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4661. }
  4662. else
  4663. {
  4664. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4665. }
  4666. // if it's recursive, we're not relying on the OS iterator
  4667. // to do the wildcard match, so do it now..
  4668. if (isRecursive && addToList)
  4669. addToList = filename.matchesWildcard (wc, true);
  4670. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4671. addToList = ! isHidden;
  4672. if (addToList)
  4673. filesFound.add (File (path + filename, 0));
  4674. }
  4675. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4676. juce_findFileClose (handle);
  4677. }
  4678. }
  4679. DirectoryIterator::~DirectoryIterator()
  4680. {
  4681. }
  4682. bool DirectoryIterator::next()
  4683. {
  4684. if (subIterator != 0)
  4685. {
  4686. if (subIterator->next())
  4687. return true;
  4688. subIterator = 0;
  4689. }
  4690. if (index >= filesFound.size() + dirsFound.size() - 1)
  4691. return false;
  4692. ++index;
  4693. if (index >= filesFound.size())
  4694. {
  4695. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4696. true, wildCard, whatToLookFor);
  4697. return next();
  4698. }
  4699. return true;
  4700. }
  4701. const File DirectoryIterator::getFile() const
  4702. {
  4703. if (subIterator != 0)
  4704. return subIterator->getFile();
  4705. return filesFound [index];
  4706. }
  4707. float DirectoryIterator::getEstimatedProgress() const
  4708. {
  4709. if (filesFound.size() + dirsFound.size() == 0)
  4710. {
  4711. return 0.0f;
  4712. }
  4713. else
  4714. {
  4715. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4716. : (float) index;
  4717. return detailedIndex / (filesFound.size() + dirsFound.size());
  4718. }
  4719. }
  4720. END_JUCE_NAMESPACE
  4721. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4722. /*** Start of inlined file: juce_File.cpp ***/
  4723. #ifdef _MSC_VER
  4724. #pragma warning (disable: 4514)
  4725. #pragma warning (push)
  4726. #endif
  4727. #if ! JUCE_WINDOWS
  4728. #include <pwd.h>
  4729. #endif
  4730. BEGIN_JUCE_NAMESPACE
  4731. #ifdef _MSC_VER
  4732. #pragma warning (pop)
  4733. #endif
  4734. void* juce_fileOpen (const String& path, bool forWriting);
  4735. void juce_fileClose (void* handle);
  4736. int juce_fileWrite (void* handle, const void* buffer, int size);
  4737. int64 juce_fileGetPosition (void* handle);
  4738. int64 juce_fileSetPosition (void* handle, int64 pos);
  4739. void juce_fileFlush (void* handle);
  4740. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4741. bool juce_isDirectory (const String& fileName);
  4742. int64 juce_getFileSize (const String& fileName);
  4743. bool juce_canWriteToFile (const String& fileName);
  4744. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4745. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4746. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4747. bool juce_deleteFile (const String& fileName);
  4748. bool juce_copyFile (const String& source, const String& dest);
  4749. bool juce_moveFile (const String& source, const String& dest);
  4750. // this must also create all paths involved in the directory.
  4751. void juce_createDirectory (const String& fileName);
  4752. bool juce_launchFile (const String& fileName, const String& parameters);
  4753. const StringArray juce_getFileSystemRoots();
  4754. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4755. // starts a directory search operation with a wildcard, returning a handle for
  4756. // use in calls to juce_findFileNext.
  4757. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4758. // the other pointers, if non-null, are set based on the properties of the file.
  4759. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4760. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4761. Time* creationTime, bool* isReadOnly);
  4762. // returns false when no more files are found
  4763. bool juce_findFileNext (void* handle, String& resultFile,
  4764. bool* isDirectory, bool* isHidden, int64* fileSize,
  4765. Time* modTime, Time* creationTime, bool* isReadOnly);
  4766. void juce_findFileClose (void* handle);
  4767. static const String juce_addTrailingSeparator (const String& path)
  4768. {
  4769. return path.endsWithChar (File::separator) ? path
  4770. : path + File::separator;
  4771. }
  4772. static const String parseAbsolutePath (String path)
  4773. {
  4774. if (path.isEmpty())
  4775. return String::empty;
  4776. #if JUCE_WINDOWS
  4777. // Windows..
  4778. path = path.replaceCharacter (T('/'), T('\\'));
  4779. if (path.startsWithChar (File::separator))
  4780. {
  4781. if (path[1] != File::separator)
  4782. {
  4783. jassertfalse // using a filename that starts with a slash is a bit dodgy on
  4784. // Windows, because it needs a drive letter, which in this case
  4785. // we'll take from the CWD.. but this is a bit of an assumption that
  4786. // could be wrong..
  4787. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4788. }
  4789. }
  4790. else if (path.indexOfChar (T(':')) < 0)
  4791. {
  4792. if (path.isEmpty())
  4793. return String::empty;
  4794. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4795. // we don't know what directory to put it in.
  4796. // Here we'll assume it's in the CWD, but this might not be what was
  4797. // intended..
  4798. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4799. }
  4800. #else
  4801. // Mac or Linux..
  4802. path = path.replaceCharacter (T('\\'), T('/'));
  4803. if (path.startsWithChar (T('~')))
  4804. {
  4805. const char* homeDir = 0;
  4806. if (path[1] == File::separator || path[1] == 0)
  4807. {
  4808. // expand a name of the form "~/abc"
  4809. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4810. + path.substring (1);
  4811. }
  4812. else
  4813. {
  4814. // expand a name of type "~dave/abc"
  4815. const String userName (path.substring (1)
  4816. .upToFirstOccurrenceOf (T("/"), false, false));
  4817. struct passwd* const pw = getpwnam (userName);
  4818. if (pw != 0)
  4819. {
  4820. String home (homeDir);
  4821. if (home.endsWithChar (File::separator))
  4822. home [home.length() - 1] = 0;
  4823. path = String (pw->pw_dir)
  4824. + path.substring (userName.length());
  4825. }
  4826. }
  4827. }
  4828. else if (! path.startsWithChar (File::separator))
  4829. {
  4830. while (path.startsWith (T("./")))
  4831. path = path.substring (2);
  4832. if (path.isEmpty())
  4833. return String::empty;
  4834. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4835. // we don't know what directory to put it in.
  4836. // Here we'll assume it's in the CWD, but this might not be what was
  4837. // intended..
  4838. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4839. }
  4840. #endif
  4841. int len = path.length();
  4842. while (--len > 0 && path [len] == File::separator)
  4843. path [len] = 0;
  4844. return path;
  4845. }
  4846. const File File::nonexistent;
  4847. File::File (const String& fullPathName)
  4848. : fullPath (parseAbsolutePath (fullPathName))
  4849. {
  4850. }
  4851. File::File (const String& path, int)
  4852. : fullPath (path)
  4853. {
  4854. }
  4855. const File File::createFileWithoutCheckingPath (const String& path)
  4856. {
  4857. return File (path, 0);
  4858. }
  4859. File::File (const File& other)
  4860. : fullPath (other.fullPath)
  4861. {
  4862. }
  4863. const File& File::operator= (const String& newPath)
  4864. {
  4865. fullPath = parseAbsolutePath (newPath);
  4866. return *this;
  4867. }
  4868. const File& File::operator= (const File& other)
  4869. {
  4870. fullPath = other.fullPath;
  4871. return *this;
  4872. }
  4873. #if JUCE_LINUX
  4874. #define NAMES_ARE_CASE_SENSITIVE 1
  4875. #endif
  4876. bool File::areFileNamesCaseSensitive()
  4877. {
  4878. #if NAMES_ARE_CASE_SENSITIVE
  4879. return true;
  4880. #else
  4881. return false;
  4882. #endif
  4883. }
  4884. bool File::operator== (const File& other) const
  4885. {
  4886. // case-insensitive on Windows, but not on linux.
  4887. #if NAMES_ARE_CASE_SENSITIVE
  4888. return fullPath == other.fullPath;
  4889. #else
  4890. return fullPath.equalsIgnoreCase (other.fullPath);
  4891. #endif
  4892. }
  4893. bool File::operator!= (const File& other) const
  4894. {
  4895. return ! operator== (other);
  4896. }
  4897. bool File::exists() const
  4898. {
  4899. return juce_fileExists (fullPath, false);
  4900. }
  4901. bool File::existsAsFile() const
  4902. {
  4903. return juce_fileExists (fullPath, true);
  4904. }
  4905. bool File::isDirectory() const
  4906. {
  4907. return juce_isDirectory (fullPath);
  4908. }
  4909. bool File::hasWriteAccess() const
  4910. {
  4911. if (exists())
  4912. return juce_canWriteToFile (fullPath);
  4913. #if ! JUCE_WINDOWS
  4914. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4915. return getParentDirectory().hasWriteAccess();
  4916. else
  4917. return false;
  4918. #else
  4919. // on windows, it seems that even read-only directories can still be written into,
  4920. // so checking the parent directory's permissions would return the wrong result..
  4921. else
  4922. return true;
  4923. #endif
  4924. }
  4925. bool File::setReadOnly (const bool shouldBeReadOnly,
  4926. const bool applyRecursively) const
  4927. {
  4928. bool worked = true;
  4929. if (applyRecursively && isDirectory())
  4930. {
  4931. Array <File> subFiles;
  4932. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4933. for (int i = subFiles.size(); --i >= 0;)
  4934. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4935. }
  4936. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4937. }
  4938. bool File::deleteFile() const
  4939. {
  4940. return (! exists())
  4941. || juce_deleteFile (fullPath);
  4942. }
  4943. bool File::deleteRecursively() const
  4944. {
  4945. bool worked = true;
  4946. if (isDirectory())
  4947. {
  4948. Array<File> subFiles;
  4949. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4950. for (int i = subFiles.size(); --i >= 0;)
  4951. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4952. }
  4953. return deleteFile() && worked;
  4954. }
  4955. bool File::moveFileTo (const File& newFile) const
  4956. {
  4957. if (newFile.fullPath == fullPath)
  4958. return true;
  4959. #if ! NAMES_ARE_CASE_SENSITIVE
  4960. if (*this != newFile)
  4961. #endif
  4962. if (! newFile.deleteFile())
  4963. return false;
  4964. return juce_moveFile (fullPath, newFile.fullPath);
  4965. }
  4966. bool File::copyFileTo (const File& newFile) const
  4967. {
  4968. if (*this == newFile)
  4969. return true;
  4970. if (! newFile.deleteFile())
  4971. return false;
  4972. return juce_copyFile (fullPath, newFile.fullPath);
  4973. }
  4974. bool File::copyDirectoryTo (const File& newDirectory) const
  4975. {
  4976. if (isDirectory() && newDirectory.createDirectory())
  4977. {
  4978. Array<File> subFiles;
  4979. findChildFiles (subFiles, File::findFiles, false);
  4980. int i;
  4981. for (i = 0; i < subFiles.size(); ++i)
  4982. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4983. return false;
  4984. subFiles.clear();
  4985. findChildFiles (subFiles, File::findDirectories, false);
  4986. for (i = 0; i < subFiles.size(); ++i)
  4987. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4988. return false;
  4989. return true;
  4990. }
  4991. return false;
  4992. }
  4993. const String File::getPathUpToLastSlash() const
  4994. {
  4995. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4996. if (lastSlash > 0)
  4997. return fullPath.substring (0, lastSlash);
  4998. else if (lastSlash == 0)
  4999. return separatorString;
  5000. else
  5001. return fullPath;
  5002. }
  5003. const File File::getParentDirectory() const
  5004. {
  5005. return File (getPathUpToLastSlash());
  5006. }
  5007. const String File::getFileName() const
  5008. {
  5009. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  5010. }
  5011. int File::hashCode() const
  5012. {
  5013. return fullPath.hashCode();
  5014. }
  5015. int64 File::hashCode64() const
  5016. {
  5017. return fullPath.hashCode64();
  5018. }
  5019. const String File::getFileNameWithoutExtension() const
  5020. {
  5021. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  5022. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  5023. if (lastDot > lastSlash)
  5024. return fullPath.substring (lastSlash, lastDot);
  5025. else
  5026. return fullPath.substring (lastSlash);
  5027. }
  5028. bool File::isAChildOf (const File& potentialParent) const
  5029. {
  5030. if (potentialParent == File::nonexistent)
  5031. return false;
  5032. const String ourPath (getPathUpToLastSlash());
  5033. #if NAMES_ARE_CASE_SENSITIVE
  5034. if (potentialParent.fullPath == ourPath)
  5035. #else
  5036. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  5037. #endif
  5038. {
  5039. return true;
  5040. }
  5041. else if (potentialParent.fullPath.length() >= ourPath.length())
  5042. {
  5043. return false;
  5044. }
  5045. else
  5046. {
  5047. return getParentDirectory().isAChildOf (potentialParent);
  5048. }
  5049. }
  5050. bool File::isAbsolutePath (const String& path)
  5051. {
  5052. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  5053. #if JUCE_WINDOWS
  5054. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  5055. #else
  5056. || path.startsWithChar (T('~'));
  5057. #endif
  5058. }
  5059. const File File::getChildFile (String relativePath) const
  5060. {
  5061. if (isAbsolutePath (relativePath))
  5062. {
  5063. // the path is really absolute..
  5064. return File (relativePath);
  5065. }
  5066. else
  5067. {
  5068. // it's relative, so remove any ../ or ./ bits at the start.
  5069. String path (fullPath);
  5070. if (relativePath[0] == T('.'))
  5071. {
  5072. #if JUCE_WINDOWS
  5073. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  5074. #else
  5075. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  5076. #endif
  5077. while (relativePath[0] == T('.'))
  5078. {
  5079. if (relativePath[1] == T('.'))
  5080. {
  5081. if (relativePath [2] == 0 || relativePath[2] == separator)
  5082. {
  5083. const int lastSlash = path.lastIndexOfChar (separator);
  5084. if (lastSlash >= 0)
  5085. path = path.substring (0, lastSlash);
  5086. relativePath = relativePath.substring (3);
  5087. }
  5088. else
  5089. {
  5090. break;
  5091. }
  5092. }
  5093. else if (relativePath[1] == separator)
  5094. {
  5095. relativePath = relativePath.substring (2);
  5096. }
  5097. else
  5098. {
  5099. break;
  5100. }
  5101. }
  5102. }
  5103. return File (juce_addTrailingSeparator (path) + relativePath);
  5104. }
  5105. }
  5106. const File File::getSiblingFile (const String& fileName) const
  5107. {
  5108. return getParentDirectory().getChildFile (fileName);
  5109. }
  5110. int64 File::getSize() const
  5111. {
  5112. return juce_getFileSize (fullPath);
  5113. }
  5114. const String File::descriptionOfSizeInBytes (const int64 bytes)
  5115. {
  5116. if (bytes == 1)
  5117. {
  5118. return "1 byte";
  5119. }
  5120. else if (bytes < 1024)
  5121. {
  5122. return String ((int) bytes) + " bytes";
  5123. }
  5124. else if (bytes < 1024 * 1024)
  5125. {
  5126. return String (bytes / 1024.0, 1) + " KB";
  5127. }
  5128. else if (bytes < 1024 * 1024 * 1024)
  5129. {
  5130. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  5131. }
  5132. else
  5133. {
  5134. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  5135. }
  5136. }
  5137. bool File::create() const
  5138. {
  5139. if (! exists())
  5140. {
  5141. const File parentDir (getParentDirectory());
  5142. if (parentDir == *this || ! parentDir.createDirectory())
  5143. return false;
  5144. void* const fh = juce_fileOpen (fullPath, true);
  5145. if (fh == 0)
  5146. return false;
  5147. juce_fileClose (fh);
  5148. }
  5149. return true;
  5150. }
  5151. bool File::createDirectory() const
  5152. {
  5153. if (! isDirectory())
  5154. {
  5155. const File parentDir (getParentDirectory());
  5156. if (parentDir == *this || ! parentDir.createDirectory())
  5157. return false;
  5158. String dir (fullPath);
  5159. while (dir.endsWithChar (separator))
  5160. dir [dir.length() - 1] = 0;
  5161. juce_createDirectory (dir);
  5162. return isDirectory();
  5163. }
  5164. return true;
  5165. }
  5166. const Time File::getCreationTime() const
  5167. {
  5168. int64 m, a, c;
  5169. juce_getFileTimes (fullPath, m, a, c);
  5170. return Time (c);
  5171. }
  5172. bool File::setCreationTime (const Time& t) const
  5173. {
  5174. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  5175. }
  5176. const Time File::getLastModificationTime() const
  5177. {
  5178. int64 m, a, c;
  5179. juce_getFileTimes (fullPath, m, a, c);
  5180. return Time (m);
  5181. }
  5182. bool File::setLastModificationTime (const Time& t) const
  5183. {
  5184. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  5185. }
  5186. const Time File::getLastAccessTime() const
  5187. {
  5188. int64 m, a, c;
  5189. juce_getFileTimes (fullPath, m, a, c);
  5190. return Time (a);
  5191. }
  5192. bool File::setLastAccessTime (const Time& t) const
  5193. {
  5194. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5195. }
  5196. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5197. {
  5198. if (! existsAsFile())
  5199. return false;
  5200. FileInputStream in (*this);
  5201. return getSize() == in.readIntoMemoryBlock (destBlock);
  5202. }
  5203. const String File::loadFileAsString() const
  5204. {
  5205. if (! existsAsFile())
  5206. return String::empty;
  5207. FileInputStream in (*this);
  5208. return in.readEntireStreamAsString();
  5209. }
  5210. static inline bool fileTypeMatches (const int whatToLookFor,
  5211. const bool isDir,
  5212. const bool isHidden)
  5213. {
  5214. return (whatToLookFor & (isDir ? File::findDirectories
  5215. : File::findFiles)) != 0
  5216. && ((! isHidden)
  5217. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5218. }
  5219. int File::findChildFiles (Array<File>& results,
  5220. const int whatToLookFor,
  5221. const bool searchRecursively,
  5222. const String& wildCardPattern) const
  5223. {
  5224. // you have to specify the type of files you're looking for!
  5225. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5226. int total = 0;
  5227. // find child files or directories in this directory first..
  5228. if (isDirectory())
  5229. {
  5230. const String path (juce_addTrailingSeparator (fullPath));
  5231. String filename;
  5232. bool itemIsDirectory, itemIsHidden;
  5233. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5234. &itemIsDirectory, &itemIsHidden,
  5235. 0, 0, 0, 0);
  5236. if (handle != 0)
  5237. {
  5238. do
  5239. {
  5240. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5241. && ! filename.containsOnly (T(".")))
  5242. {
  5243. results.add (File (path + filename, 0));
  5244. ++total;
  5245. }
  5246. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5247. juce_findFileClose (handle);
  5248. }
  5249. }
  5250. else
  5251. {
  5252. // trying to search for files inside a non-directory?
  5253. //jassertfalse
  5254. }
  5255. // and recurse down if required.
  5256. if (searchRecursively)
  5257. {
  5258. Array<File> subDirectories;
  5259. findChildFiles (subDirectories, File::findDirectories, false);
  5260. for (int i = 0; i < subDirectories.size(); ++i)
  5261. {
  5262. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5263. true, wildCardPattern);
  5264. }
  5265. }
  5266. return total;
  5267. }
  5268. int File::getNumberOfChildFiles (const int whatToLookFor,
  5269. const String& wildCardPattern) const
  5270. {
  5271. // you have to specify the type of files you're looking for!
  5272. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5273. int count = 0;
  5274. if (isDirectory())
  5275. {
  5276. String filename;
  5277. bool itemIsDirectory, itemIsHidden;
  5278. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5279. &itemIsDirectory, &itemIsHidden,
  5280. 0, 0, 0, 0);
  5281. if (handle != 0)
  5282. {
  5283. do
  5284. {
  5285. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5286. && ! filename.containsOnly (T(".")))
  5287. {
  5288. ++count;
  5289. }
  5290. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5291. juce_findFileClose (handle);
  5292. }
  5293. }
  5294. else
  5295. {
  5296. // trying to search for files inside a non-directory?
  5297. jassertfalse
  5298. }
  5299. return count;
  5300. }
  5301. bool File::containsSubDirectories() const
  5302. {
  5303. bool result = false;
  5304. if (isDirectory())
  5305. {
  5306. String filename;
  5307. bool itemIsDirectory, itemIsHidden;
  5308. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5309. T("*"), filename,
  5310. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5311. if (handle != 0)
  5312. {
  5313. do
  5314. {
  5315. if (itemIsDirectory)
  5316. {
  5317. result = true;
  5318. break;
  5319. }
  5320. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5321. juce_findFileClose (handle);
  5322. }
  5323. }
  5324. return result;
  5325. }
  5326. const File File::getNonexistentChildFile (const String& prefix_,
  5327. const String& suffix,
  5328. bool putNumbersInBrackets) const
  5329. {
  5330. File f (getChildFile (prefix_ + suffix));
  5331. if (f.exists())
  5332. {
  5333. int num = 2;
  5334. String prefix (prefix_);
  5335. // remove any bracketed numbers that may already be on the end..
  5336. if (prefix.trim().endsWithChar (T(')')))
  5337. {
  5338. putNumbersInBrackets = true;
  5339. const int openBracks = prefix.lastIndexOfChar (T('('));
  5340. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5341. if (openBracks > 0
  5342. && closeBracks > openBracks
  5343. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5344. {
  5345. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5346. prefix = prefix.substring (0, openBracks);
  5347. }
  5348. }
  5349. // also use brackets if it ends in a digit.
  5350. putNumbersInBrackets = putNumbersInBrackets
  5351. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5352. do
  5353. {
  5354. if (putNumbersInBrackets)
  5355. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5356. else
  5357. f = getChildFile (prefix + String (num++) + suffix);
  5358. } while (f.exists());
  5359. }
  5360. return f;
  5361. }
  5362. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5363. {
  5364. if (exists())
  5365. {
  5366. return getParentDirectory()
  5367. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5368. getFileExtension(),
  5369. putNumbersInBrackets);
  5370. }
  5371. else
  5372. {
  5373. return *this;
  5374. }
  5375. }
  5376. const String File::getFileExtension() const
  5377. {
  5378. String ext;
  5379. if (! isDirectory())
  5380. {
  5381. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5382. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5383. ext = fullPath.substring (indexOfDot);
  5384. }
  5385. return ext;
  5386. }
  5387. bool File::hasFileExtension (const String& possibleSuffix) const
  5388. {
  5389. if (possibleSuffix.isEmpty())
  5390. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5391. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5392. if (semicolon >= 0)
  5393. {
  5394. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5395. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5396. }
  5397. else
  5398. {
  5399. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5400. {
  5401. if (possibleSuffix.startsWithChar (T('.')))
  5402. return true;
  5403. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5404. if (dotPos >= 0)
  5405. return fullPath [dotPos] == T('.');
  5406. }
  5407. }
  5408. return false;
  5409. }
  5410. const File File::withFileExtension (const String& newExtension) const
  5411. {
  5412. if (fullPath.isEmpty())
  5413. return File::nonexistent;
  5414. String filePart (getFileName());
  5415. int i = filePart.lastIndexOfChar (T('.'));
  5416. if (i < 0)
  5417. i = filePart.length();
  5418. String newExt (newExtension);
  5419. if (newExt.isNotEmpty() && ! newExt.startsWithChar (T('.')))
  5420. newExt = T(".") + newExt;
  5421. return getSiblingFile (filePart.substring (0, i) + newExt);
  5422. }
  5423. bool File::startAsProcess (const String& parameters) const
  5424. {
  5425. return exists()
  5426. && juce_launchFile (fullPath, parameters);
  5427. }
  5428. FileInputStream* File::createInputStream() const
  5429. {
  5430. if (existsAsFile())
  5431. return new FileInputStream (*this);
  5432. else
  5433. return 0;
  5434. }
  5435. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5436. {
  5437. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5438. if (out->failedToOpen())
  5439. return 0;
  5440. return out.release();
  5441. }
  5442. bool File::appendData (const void* const dataToAppend,
  5443. const int numberOfBytes) const
  5444. {
  5445. if (numberOfBytes > 0)
  5446. {
  5447. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5448. if (out == 0)
  5449. return false;
  5450. out->write (dataToAppend, numberOfBytes);
  5451. }
  5452. return true;
  5453. }
  5454. bool File::replaceWithData (const void* const dataToWrite,
  5455. const int numberOfBytes) const
  5456. {
  5457. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5458. if (numberOfBytes <= 0)
  5459. return deleteFile();
  5460. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5461. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5462. return tempFile.overwriteTargetFileWithTemporary();
  5463. }
  5464. bool File::appendText (const String& text,
  5465. const bool asUnicode,
  5466. const bool writeUnicodeHeaderBytes) const
  5467. {
  5468. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5469. if (out != 0)
  5470. {
  5471. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5472. return true;
  5473. }
  5474. return false;
  5475. }
  5476. bool File::replaceWithText (const String& textToWrite,
  5477. const bool asUnicode,
  5478. const bool writeUnicodeHeaderBytes) const
  5479. {
  5480. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5481. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5482. return tempFile.overwriteTargetFileWithTemporary();
  5483. }
  5484. const String File::createLegalPathName (const String& original)
  5485. {
  5486. String s (original);
  5487. String start;
  5488. if (s[1] == T(':'))
  5489. {
  5490. start = s.substring (0, 2);
  5491. s = s.substring (2);
  5492. }
  5493. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5494. .substring (0, 1024);
  5495. }
  5496. const String File::createLegalFileName (const String& original)
  5497. {
  5498. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5499. const int maxLength = 128; // only the length of the filename, not the whole path
  5500. const int len = s.length();
  5501. if (len > maxLength)
  5502. {
  5503. const int lastDot = s.lastIndexOfChar (T('.'));
  5504. if (lastDot > jmax (0, len - 12))
  5505. {
  5506. s = s.substring (0, maxLength - (len - lastDot))
  5507. + s.substring (lastDot);
  5508. }
  5509. else
  5510. {
  5511. s = s.substring (0, maxLength);
  5512. }
  5513. }
  5514. return s;
  5515. }
  5516. const String File::getRelativePathFrom (const File& dir) const
  5517. {
  5518. String thisPath (fullPath);
  5519. {
  5520. int len = thisPath.length();
  5521. while (--len >= 0 && thisPath [len] == File::separator)
  5522. thisPath [len] = 0;
  5523. }
  5524. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5525. : dir.fullPath));
  5526. const int len = jmin (thisPath.length(), dirPath.length());
  5527. int commonBitLength = 0;
  5528. for (int i = 0; i < len; ++i)
  5529. {
  5530. #if NAMES_ARE_CASE_SENSITIVE
  5531. if (thisPath[i] != dirPath[i])
  5532. #else
  5533. if (CharacterFunctions::toLowerCase (thisPath[i])
  5534. != CharacterFunctions::toLowerCase (dirPath[i]))
  5535. #endif
  5536. {
  5537. break;
  5538. }
  5539. ++commonBitLength;
  5540. }
  5541. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5542. --commonBitLength;
  5543. // if the only common bit is the root, then just return the full path..
  5544. if (commonBitLength <= 0
  5545. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5546. return fullPath;
  5547. thisPath = thisPath.substring (commonBitLength);
  5548. dirPath = dirPath.substring (commonBitLength);
  5549. while (dirPath.isNotEmpty())
  5550. {
  5551. #if JUCE_WINDOWS
  5552. thisPath = T("..\\") + thisPath;
  5553. #else
  5554. thisPath = T("../") + thisPath;
  5555. #endif
  5556. const int sep = dirPath.indexOfChar (separator);
  5557. if (sep >= 0)
  5558. dirPath = dirPath.substring (sep + 1);
  5559. else
  5560. dirPath = String::empty;
  5561. }
  5562. return thisPath;
  5563. }
  5564. void File::findFileSystemRoots (Array<File>& destArray)
  5565. {
  5566. const StringArray roots (juce_getFileSystemRoots());
  5567. for (int i = 0; i < roots.size(); ++i)
  5568. destArray.add (File (roots[i]));
  5569. }
  5570. const String File::getVolumeLabel() const
  5571. {
  5572. int serialNum;
  5573. return juce_getVolumeLabel (fullPath, serialNum);
  5574. }
  5575. int File::getVolumeSerialNumber() const
  5576. {
  5577. int serialNum;
  5578. juce_getVolumeLabel (fullPath, serialNum);
  5579. return serialNum;
  5580. }
  5581. const File File::createTempFile (const String& fileNameEnding)
  5582. {
  5583. const File tempFile (getSpecialLocation (tempDirectory)
  5584. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5585. .withFileExtension (fileNameEnding));
  5586. if (tempFile.exists())
  5587. return createTempFile (fileNameEnding);
  5588. else
  5589. return tempFile;
  5590. }
  5591. END_JUCE_NAMESPACE
  5592. /*** End of inlined file: juce_File.cpp ***/
  5593. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5594. BEGIN_JUCE_NAMESPACE
  5595. void* juce_fileOpen (const String& path, bool forWriting);
  5596. void juce_fileClose (void* handle);
  5597. int juce_fileRead (void* handle, void* buffer, int size);
  5598. int64 juce_fileSetPosition (void* handle, int64 pos);
  5599. FileInputStream::FileInputStream (const File& f)
  5600. : file (f),
  5601. currentPosition (0),
  5602. needToSeek (true)
  5603. {
  5604. totalSize = f.getSize();
  5605. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5606. }
  5607. FileInputStream::~FileInputStream()
  5608. {
  5609. juce_fileClose (fileHandle);
  5610. }
  5611. int64 FileInputStream::getTotalLength()
  5612. {
  5613. return totalSize;
  5614. }
  5615. int FileInputStream::read (void* buffer, int bytesToRead)
  5616. {
  5617. int num = 0;
  5618. if (needToSeek)
  5619. {
  5620. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5621. return 0;
  5622. needToSeek = false;
  5623. }
  5624. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5625. currentPosition += num;
  5626. return num;
  5627. }
  5628. bool FileInputStream::isExhausted()
  5629. {
  5630. return currentPosition >= totalSize;
  5631. }
  5632. int64 FileInputStream::getPosition()
  5633. {
  5634. return currentPosition;
  5635. }
  5636. bool FileInputStream::setPosition (int64 pos)
  5637. {
  5638. pos = jlimit ((int64) 0, totalSize, pos);
  5639. needToSeek |= (currentPosition != pos);
  5640. currentPosition = pos;
  5641. return true;
  5642. }
  5643. END_JUCE_NAMESPACE
  5644. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5645. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5646. BEGIN_JUCE_NAMESPACE
  5647. void* juce_fileOpen (const String& path, bool forWriting);
  5648. void juce_fileClose (void* handle);
  5649. int juce_fileWrite (void* handle, const void* buffer, int size);
  5650. void juce_fileFlush (void* handle);
  5651. int64 juce_fileGetPosition (void* handle);
  5652. int64 juce_fileSetPosition (void* handle, int64 pos);
  5653. FileOutputStream::FileOutputStream (const File& f,
  5654. const int bufferSize_)
  5655. : file (f),
  5656. bufferSize (bufferSize_),
  5657. bytesInBuffer (0)
  5658. {
  5659. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5660. if (fileHandle != 0)
  5661. {
  5662. currentPosition = juce_fileGetPosition (fileHandle);
  5663. if (currentPosition < 0)
  5664. {
  5665. jassertfalse
  5666. juce_fileClose (fileHandle);
  5667. fileHandle = 0;
  5668. }
  5669. }
  5670. buffer.malloc (jmax (bufferSize_, 16));
  5671. }
  5672. FileOutputStream::~FileOutputStream()
  5673. {
  5674. flush();
  5675. juce_fileClose (fileHandle);
  5676. }
  5677. int64 FileOutputStream::getPosition()
  5678. {
  5679. return currentPosition;
  5680. }
  5681. bool FileOutputStream::setPosition (int64 newPosition)
  5682. {
  5683. if (newPosition != currentPosition)
  5684. {
  5685. flush();
  5686. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5687. }
  5688. return newPosition == currentPosition;
  5689. }
  5690. void FileOutputStream::flush()
  5691. {
  5692. if (bytesInBuffer > 0)
  5693. {
  5694. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5695. bytesInBuffer = 0;
  5696. }
  5697. juce_fileFlush (fileHandle);
  5698. }
  5699. bool FileOutputStream::write (const void* const src, const int numBytes)
  5700. {
  5701. if (bytesInBuffer + numBytes < bufferSize)
  5702. {
  5703. memcpy (buffer + bytesInBuffer, src, numBytes);
  5704. bytesInBuffer += numBytes;
  5705. currentPosition += numBytes;
  5706. }
  5707. else
  5708. {
  5709. if (bytesInBuffer > 0)
  5710. {
  5711. // flush the reservoir
  5712. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5713. bytesInBuffer = 0;
  5714. if (! wroteOk)
  5715. return false;
  5716. }
  5717. if (numBytes < bufferSize)
  5718. {
  5719. memcpy (buffer + bytesInBuffer, src, numBytes);
  5720. bytesInBuffer += numBytes;
  5721. currentPosition += numBytes;
  5722. }
  5723. else
  5724. {
  5725. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5726. currentPosition += bytesWritten;
  5727. return bytesWritten == numBytes;
  5728. }
  5729. }
  5730. return true;
  5731. }
  5732. END_JUCE_NAMESPACE
  5733. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5734. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5735. BEGIN_JUCE_NAMESPACE
  5736. FileSearchPath::FileSearchPath()
  5737. {
  5738. }
  5739. FileSearchPath::FileSearchPath (const String& path)
  5740. {
  5741. init (path);
  5742. }
  5743. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5744. : directories (other.directories)
  5745. {
  5746. }
  5747. FileSearchPath::~FileSearchPath()
  5748. {
  5749. }
  5750. const FileSearchPath& FileSearchPath::operator= (const String& path)
  5751. {
  5752. init (path);
  5753. return *this;
  5754. }
  5755. void FileSearchPath::init (const String& path)
  5756. {
  5757. directories.clear();
  5758. directories.addTokens (path, T(";"), T("\""));
  5759. directories.trim();
  5760. directories.removeEmptyStrings();
  5761. for (int i = directories.size(); --i >= 0;)
  5762. directories.set (i, directories[i].unquoted());
  5763. }
  5764. int FileSearchPath::getNumPaths() const
  5765. {
  5766. return directories.size();
  5767. }
  5768. const File FileSearchPath::operator[] (const int index) const
  5769. {
  5770. return File (directories [index]);
  5771. }
  5772. const String FileSearchPath::toString() const
  5773. {
  5774. StringArray directories2 (directories);
  5775. for (int i = directories2.size(); --i >= 0;)
  5776. if (directories2[i].containsChar (T(';')))
  5777. directories2.set (i, directories2[i].quoted());
  5778. return directories2.joinIntoString (T(";"));
  5779. }
  5780. void FileSearchPath::add (const File& dir, const int insertIndex)
  5781. {
  5782. directories.insert (insertIndex, dir.getFullPathName());
  5783. }
  5784. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5785. {
  5786. for (int i = 0; i < directories.size(); ++i)
  5787. if (File (directories[i]) == dir)
  5788. return;
  5789. add (dir);
  5790. }
  5791. void FileSearchPath::remove (const int index)
  5792. {
  5793. directories.remove (index);
  5794. }
  5795. void FileSearchPath::addPath (const FileSearchPath& other)
  5796. {
  5797. for (int i = 0; i < other.getNumPaths(); ++i)
  5798. addIfNotAlreadyThere (other[i]);
  5799. }
  5800. void FileSearchPath::removeRedundantPaths()
  5801. {
  5802. for (int i = directories.size(); --i >= 0;)
  5803. {
  5804. const File d1 (directories[i]);
  5805. for (int j = directories.size(); --j >= 0;)
  5806. {
  5807. const File d2 (directories[j]);
  5808. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5809. {
  5810. directories.remove (i);
  5811. break;
  5812. }
  5813. }
  5814. }
  5815. }
  5816. void FileSearchPath::removeNonExistentPaths()
  5817. {
  5818. for (int i = directories.size(); --i >= 0;)
  5819. if (! File (directories[i]).isDirectory())
  5820. directories.remove (i);
  5821. }
  5822. int FileSearchPath::findChildFiles (Array<File>& results,
  5823. const int whatToLookFor,
  5824. const bool searchRecursively,
  5825. const String& wildCardPattern) const
  5826. {
  5827. int total = 0;
  5828. for (int i = 0; i < directories.size(); ++i)
  5829. total += operator[] (i).findChildFiles (results,
  5830. whatToLookFor,
  5831. searchRecursively,
  5832. wildCardPattern);
  5833. return total;
  5834. }
  5835. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5836. const bool checkRecursively) const
  5837. {
  5838. for (int i = directories.size(); --i >= 0;)
  5839. {
  5840. const File d (directories[i]);
  5841. if (checkRecursively)
  5842. {
  5843. if (fileToCheck.isAChildOf (d))
  5844. return true;
  5845. }
  5846. else
  5847. {
  5848. if (fileToCheck.getParentDirectory() == d)
  5849. return true;
  5850. }
  5851. }
  5852. return false;
  5853. }
  5854. END_JUCE_NAMESPACE
  5855. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5856. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5857. BEGIN_JUCE_NAMESPACE
  5858. NamedPipe::NamedPipe()
  5859. : internal (0)
  5860. {
  5861. }
  5862. NamedPipe::~NamedPipe()
  5863. {
  5864. close();
  5865. }
  5866. bool NamedPipe::openExisting (const String& pipeName)
  5867. {
  5868. currentPipeName = pipeName;
  5869. return openInternal (pipeName, false);
  5870. }
  5871. bool NamedPipe::createNewPipe (const String& pipeName)
  5872. {
  5873. currentPipeName = pipeName;
  5874. return openInternal (pipeName, true);
  5875. }
  5876. bool NamedPipe::isOpen() const
  5877. {
  5878. return internal != 0;
  5879. }
  5880. const String NamedPipe::getName() const
  5881. {
  5882. return currentPipeName;
  5883. }
  5884. // other methods for this class are implemented in the platform-specific files
  5885. END_JUCE_NAMESPACE
  5886. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5887. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5888. BEGIN_JUCE_NAMESPACE
  5889. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5890. {
  5891. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5892. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5893. suffix,
  5894. optionFlags);
  5895. }
  5896. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5897. : targetFile (targetFile_)
  5898. {
  5899. // If you use this constructor, you need to give it a valid target file!
  5900. jassert (targetFile != File::nonexistent);
  5901. createTempFile (targetFile.getParentDirectory(),
  5902. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5903. targetFile.getFileExtension(),
  5904. optionFlags);
  5905. }
  5906. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5907. const String& suffix, const int optionFlags)
  5908. {
  5909. if ((optionFlags & useHiddenFile) != 0)
  5910. name = T(".") + name;
  5911. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5912. }
  5913. TemporaryFile::~TemporaryFile()
  5914. {
  5915. // Have a few attempts at deleting the file before giving up..
  5916. for (int i = 5; --i >= 0;)
  5917. {
  5918. if (temporaryFile.deleteFile())
  5919. return;
  5920. Thread::sleep (50);
  5921. }
  5922. // Failed to delete our temporary file! Check that you've deleted all the
  5923. // file output streams that were using it!
  5924. jassertfalse;
  5925. }
  5926. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5927. {
  5928. // This method only works if you created this object with the constructor
  5929. // that takes a target file!
  5930. jassert (targetFile != File::nonexistent);
  5931. if (temporaryFile.exists())
  5932. {
  5933. // Have a few attempts at overwriting the file before giving up..
  5934. for (int i = 5; --i >= 0;)
  5935. {
  5936. if (temporaryFile.moveFileTo (targetFile))
  5937. return true;
  5938. Thread::sleep (100);
  5939. }
  5940. // Failed to overwrite the new file! Make sure you've not left any
  5941. // file streams hanging around when you call this method!
  5942. jassertfalse
  5943. }
  5944. else
  5945. {
  5946. // There's no temporary file to use. If your write failed, you should
  5947. // probably check, and not bother calling this method.
  5948. jassertfalse
  5949. }
  5950. return false;
  5951. }
  5952. END_JUCE_NAMESPACE
  5953. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5954. /*** Start of inlined file: juce_Socket.cpp ***/
  5955. #if JUCE_WINDOWS
  5956. #include <winsock2.h>
  5957. #ifdef _MSC_VER
  5958. #pragma warning (disable : 4127 4389 4018)
  5959. #endif
  5960. #else
  5961. #if JUCE_LINUX
  5962. #include <sys/types.h>
  5963. #include <sys/socket.h>
  5964. #include <sys/errno.h>
  5965. #include <unistd.h>
  5966. #include <netinet/in.h>
  5967. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5968. #include <CoreServices/CoreServices.h>
  5969. #endif
  5970. #include <fcntl.h>
  5971. #include <netdb.h>
  5972. #include <arpa/inet.h>
  5973. #include <netinet/tcp.h>
  5974. #endif
  5975. BEGIN_JUCE_NAMESPACE
  5976. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5977. typedef socklen_t juce_socklen_t;
  5978. #else
  5979. typedef int juce_socklen_t;
  5980. #endif
  5981. #if JUCE_WINDOWS
  5982. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5983. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5984. static void initWin32Sockets()
  5985. {
  5986. static CriticalSection lock;
  5987. const ScopedLock sl (lock);
  5988. if (juce_CloseWin32SocketLib == 0)
  5989. {
  5990. WSADATA wsaData;
  5991. const WORD wVersionRequested = MAKEWORD (1, 1);
  5992. WSAStartup (wVersionRequested, &wsaData);
  5993. juce_CloseWin32SocketLib = &WSACleanup;
  5994. }
  5995. }
  5996. #endif
  5997. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5998. {
  5999. const int sndBufSize = 65536;
  6000. const int rcvBufSize = 65536;
  6001. const int one = 1;
  6002. return handle > 0
  6003. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  6004. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  6005. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  6006. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  6007. }
  6008. static bool bindSocketToPort (const int handle, const int port) throw()
  6009. {
  6010. if (handle <= 0 || port <= 0)
  6011. return false;
  6012. struct sockaddr_in servTmpAddr;
  6013. zerostruct (servTmpAddr);
  6014. servTmpAddr.sin_family = PF_INET;
  6015. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6016. servTmpAddr.sin_port = htons ((uint16) port);
  6017. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  6018. }
  6019. static int readSocket (const int handle,
  6020. void* const destBuffer, const int maxBytesToRead,
  6021. bool volatile& connected,
  6022. const bool blockUntilSpecifiedAmountHasArrived) throw()
  6023. {
  6024. int bytesRead = 0;
  6025. while (bytesRead < maxBytesToRead)
  6026. {
  6027. int bytesThisTime;
  6028. #if JUCE_WINDOWS
  6029. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  6030. #else
  6031. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  6032. && errno == EINTR
  6033. && connected)
  6034. {
  6035. }
  6036. #endif
  6037. if (bytesThisTime <= 0 || ! connected)
  6038. {
  6039. if (bytesRead == 0)
  6040. bytesRead = -1;
  6041. break;
  6042. }
  6043. bytesRead += bytesThisTime;
  6044. if (! blockUntilSpecifiedAmountHasArrived)
  6045. break;
  6046. }
  6047. return bytesRead;
  6048. }
  6049. static int waitForReadiness (const int handle, const bool forReading,
  6050. const int timeoutMsecs) throw()
  6051. {
  6052. struct timeval timeout;
  6053. struct timeval* timeoutp;
  6054. if (timeoutMsecs >= 0)
  6055. {
  6056. timeout.tv_sec = timeoutMsecs / 1000;
  6057. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  6058. timeoutp = &timeout;
  6059. }
  6060. else
  6061. {
  6062. timeoutp = 0;
  6063. }
  6064. fd_set rset, wset;
  6065. FD_ZERO (&rset);
  6066. FD_SET (handle, &rset);
  6067. FD_ZERO (&wset);
  6068. FD_SET (handle, &wset);
  6069. fd_set* const prset = forReading ? &rset : 0;
  6070. fd_set* const pwset = forReading ? 0 : &wset;
  6071. #if JUCE_WINDOWS
  6072. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  6073. return -1;
  6074. #else
  6075. {
  6076. int result;
  6077. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  6078. && errno == EINTR)
  6079. {
  6080. }
  6081. if (result < 0)
  6082. return -1;
  6083. }
  6084. #endif
  6085. {
  6086. int opt;
  6087. juce_socklen_t len = sizeof (opt);
  6088. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  6089. || opt != 0)
  6090. return -1;
  6091. }
  6092. if ((forReading && FD_ISSET (handle, &rset))
  6093. || ((! forReading) && FD_ISSET (handle, &wset)))
  6094. return 1;
  6095. return 0;
  6096. }
  6097. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  6098. {
  6099. #if JUCE_WINDOWS
  6100. u_long nonBlocking = shouldBlock ? 0 : 1;
  6101. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  6102. return false;
  6103. #else
  6104. int socketFlags = fcntl (handle, F_GETFL, 0);
  6105. if (socketFlags == -1)
  6106. return false;
  6107. if (shouldBlock)
  6108. socketFlags &= ~O_NONBLOCK;
  6109. else
  6110. socketFlags |= O_NONBLOCK;
  6111. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  6112. return false;
  6113. #endif
  6114. return true;
  6115. }
  6116. static bool connectSocket (int volatile& handle,
  6117. const bool isDatagram,
  6118. void** serverAddress,
  6119. const String& hostName,
  6120. const int portNumber,
  6121. const int timeOutMillisecs) throw()
  6122. {
  6123. struct hostent* const hostEnt = gethostbyname (hostName);
  6124. if (hostEnt == 0)
  6125. return false;
  6126. struct in_addr targetAddress;
  6127. memcpy (&targetAddress.s_addr,
  6128. *(hostEnt->h_addr_list),
  6129. sizeof (targetAddress.s_addr));
  6130. struct sockaddr_in servTmpAddr;
  6131. zerostruct (servTmpAddr);
  6132. servTmpAddr.sin_family = PF_INET;
  6133. servTmpAddr.sin_addr = targetAddress;
  6134. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6135. if (handle < 0)
  6136. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  6137. if (handle < 0)
  6138. return false;
  6139. if (isDatagram)
  6140. {
  6141. *serverAddress = new struct sockaddr_in();
  6142. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  6143. return true;
  6144. }
  6145. setSocketBlockingState (handle, false);
  6146. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  6147. if (result < 0)
  6148. {
  6149. #if JUCE_WINDOWS
  6150. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  6151. #else
  6152. if (errno == EINPROGRESS)
  6153. #endif
  6154. {
  6155. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  6156. {
  6157. setSocketBlockingState (handle, true);
  6158. return false;
  6159. }
  6160. }
  6161. }
  6162. setSocketBlockingState (handle, true);
  6163. resetSocketOptions (handle, false, false);
  6164. return true;
  6165. }
  6166. StreamingSocket::StreamingSocket()
  6167. : portNumber (0),
  6168. handle (-1),
  6169. connected (false),
  6170. isListener (false)
  6171. {
  6172. #if JUCE_WINDOWS
  6173. initWin32Sockets();
  6174. #endif
  6175. }
  6176. StreamingSocket::StreamingSocket (const String& hostName_,
  6177. const int portNumber_,
  6178. const int handle_)
  6179. : hostName (hostName_),
  6180. portNumber (portNumber_),
  6181. handle (handle_),
  6182. connected (true),
  6183. isListener (false)
  6184. {
  6185. #if JUCE_WINDOWS
  6186. initWin32Sockets();
  6187. #endif
  6188. resetSocketOptions (handle_, false, false);
  6189. }
  6190. StreamingSocket::~StreamingSocket()
  6191. {
  6192. close();
  6193. }
  6194. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6195. {
  6196. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6197. : -1;
  6198. }
  6199. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6200. {
  6201. if (isListener || ! connected)
  6202. return -1;
  6203. #if JUCE_WINDOWS
  6204. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6205. #else
  6206. int result;
  6207. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6208. && errno == EINTR)
  6209. {
  6210. }
  6211. return result;
  6212. #endif
  6213. }
  6214. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6215. const int timeoutMsecs) const
  6216. {
  6217. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6218. : -1;
  6219. }
  6220. bool StreamingSocket::bindToPort (const int port)
  6221. {
  6222. return bindSocketToPort (handle, port);
  6223. }
  6224. bool StreamingSocket::connect (const String& remoteHostName,
  6225. const int remotePortNumber,
  6226. const int timeOutMillisecs)
  6227. {
  6228. if (isListener)
  6229. {
  6230. jassertfalse // a listener socket can't connect to another one!
  6231. return false;
  6232. }
  6233. if (connected)
  6234. close();
  6235. hostName = remoteHostName;
  6236. portNumber = remotePortNumber;
  6237. isListener = false;
  6238. connected = connectSocket (handle, false, 0, remoteHostName,
  6239. remotePortNumber, timeOutMillisecs);
  6240. if (! (connected && resetSocketOptions (handle, false, false)))
  6241. {
  6242. close();
  6243. return false;
  6244. }
  6245. return true;
  6246. }
  6247. void StreamingSocket::close()
  6248. {
  6249. #if JUCE_WINDOWS
  6250. closesocket (handle);
  6251. connected = false;
  6252. #else
  6253. if (connected)
  6254. {
  6255. connected = false;
  6256. if (isListener)
  6257. {
  6258. // need to do this to interrupt the accept() function..
  6259. StreamingSocket temp;
  6260. temp.connect ("localhost", portNumber, 1000);
  6261. }
  6262. }
  6263. ::close (handle);
  6264. #endif
  6265. hostName = String::empty;
  6266. portNumber = 0;
  6267. handle = -1;
  6268. isListener = false;
  6269. }
  6270. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6271. {
  6272. if (connected)
  6273. close();
  6274. hostName = "listener";
  6275. portNumber = newPortNumber;
  6276. isListener = true;
  6277. struct sockaddr_in servTmpAddr;
  6278. zerostruct (servTmpAddr);
  6279. servTmpAddr.sin_family = PF_INET;
  6280. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6281. if (localHostName.isNotEmpty())
  6282. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6283. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6284. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6285. if (handle < 0)
  6286. return false;
  6287. const int reuse = 1;
  6288. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6289. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6290. || listen (handle, SOMAXCONN) < 0)
  6291. {
  6292. close();
  6293. return false;
  6294. }
  6295. connected = true;
  6296. return true;
  6297. }
  6298. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6299. {
  6300. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6301. // prepare this socket as a listener.
  6302. if (connected && isListener)
  6303. {
  6304. struct sockaddr address;
  6305. juce_socklen_t len = sizeof (sockaddr);
  6306. const int newSocket = (int) accept (handle, &address, &len);
  6307. if (newSocket >= 0 && connected)
  6308. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6309. portNumber, newSocket);
  6310. }
  6311. return 0;
  6312. }
  6313. bool StreamingSocket::isLocal() const throw()
  6314. {
  6315. return hostName == T("127.0.0.1");
  6316. }
  6317. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6318. : portNumber (0),
  6319. handle (-1),
  6320. connected (true),
  6321. allowBroadcast (allowBroadcast_),
  6322. serverAddress (0)
  6323. {
  6324. #if JUCE_WINDOWS
  6325. initWin32Sockets();
  6326. #endif
  6327. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6328. bindToPort (localPortNumber);
  6329. }
  6330. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6331. const int handle_, const int localPortNumber)
  6332. : hostName (hostName_),
  6333. portNumber (portNumber_),
  6334. handle (handle_),
  6335. connected (true),
  6336. allowBroadcast (false),
  6337. serverAddress (0)
  6338. {
  6339. #if JUCE_WINDOWS
  6340. initWin32Sockets();
  6341. #endif
  6342. resetSocketOptions (handle_, true, allowBroadcast);
  6343. bindToPort (localPortNumber);
  6344. }
  6345. DatagramSocket::~DatagramSocket()
  6346. {
  6347. close();
  6348. delete ((struct sockaddr_in*) serverAddress);
  6349. serverAddress = 0;
  6350. }
  6351. void DatagramSocket::close()
  6352. {
  6353. #if JUCE_WINDOWS
  6354. closesocket (handle);
  6355. connected = false;
  6356. #else
  6357. connected = false;
  6358. ::close (handle);
  6359. #endif
  6360. hostName = String::empty;
  6361. portNumber = 0;
  6362. handle = -1;
  6363. }
  6364. bool DatagramSocket::bindToPort (const int port)
  6365. {
  6366. return bindSocketToPort (handle, port);
  6367. }
  6368. bool DatagramSocket::connect (const String& remoteHostName,
  6369. const int remotePortNumber,
  6370. const int timeOutMillisecs)
  6371. {
  6372. if (connected)
  6373. close();
  6374. hostName = remoteHostName;
  6375. portNumber = remotePortNumber;
  6376. connected = connectSocket (handle, true, &serverAddress,
  6377. remoteHostName, remotePortNumber,
  6378. timeOutMillisecs);
  6379. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6380. {
  6381. close();
  6382. return false;
  6383. }
  6384. return true;
  6385. }
  6386. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6387. {
  6388. struct sockaddr address;
  6389. juce_socklen_t len = sizeof (sockaddr);
  6390. while (waitUntilReady (true, -1) == 1)
  6391. {
  6392. char buf[1];
  6393. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6394. {
  6395. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6396. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6397. -1, -1);
  6398. }
  6399. }
  6400. return 0;
  6401. }
  6402. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6403. const int timeoutMsecs) const
  6404. {
  6405. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6406. : -1;
  6407. }
  6408. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6409. {
  6410. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6411. : -1;
  6412. }
  6413. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6414. {
  6415. // You need to call connect() first to set the server address..
  6416. jassert (serverAddress != 0 && connected);
  6417. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6418. numBytesToWrite, 0,
  6419. (const struct sockaddr*) serverAddress,
  6420. sizeof (struct sockaddr_in))
  6421. : -1;
  6422. }
  6423. bool DatagramSocket::isLocal() const throw()
  6424. {
  6425. return hostName == T("127.0.0.1");
  6426. }
  6427. END_JUCE_NAMESPACE
  6428. /*** End of inlined file: juce_Socket.cpp ***/
  6429. /*** Start of inlined file: juce_URL.cpp ***/
  6430. BEGIN_JUCE_NAMESPACE
  6431. URL::URL()
  6432. {
  6433. }
  6434. URL::URL (const String& url_)
  6435. : url (url_)
  6436. {
  6437. int i = url.indexOfChar (T('?'));
  6438. if (i >= 0)
  6439. {
  6440. do
  6441. {
  6442. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6443. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6444. if (equalsPos > i + 1)
  6445. {
  6446. if (nextAmp < 0)
  6447. {
  6448. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6449. removeEscapeChars (url.substring (equalsPos + 1)));
  6450. }
  6451. else if (nextAmp > 0 && equalsPos < nextAmp)
  6452. {
  6453. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6454. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6455. }
  6456. }
  6457. i = nextAmp;
  6458. }
  6459. while (i >= 0);
  6460. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6461. }
  6462. }
  6463. URL::URL (const URL& other)
  6464. : url (other.url),
  6465. postData (other.postData),
  6466. parameters (other.parameters),
  6467. filesToUpload (other.filesToUpload),
  6468. mimeTypes (other.mimeTypes)
  6469. {
  6470. }
  6471. const URL& URL::operator= (const URL& other)
  6472. {
  6473. url = other.url;
  6474. postData = other.postData;
  6475. parameters = other.parameters;
  6476. filesToUpload = other.filesToUpload;
  6477. mimeTypes = other.mimeTypes;
  6478. return *this;
  6479. }
  6480. URL::~URL()
  6481. {
  6482. }
  6483. static const String getMangledParameters (const StringPairArray& parameters)
  6484. {
  6485. String p;
  6486. for (int i = 0; i < parameters.size(); ++i)
  6487. {
  6488. if (i > 0)
  6489. p += T("&");
  6490. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6491. << T("=")
  6492. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6493. }
  6494. return p;
  6495. }
  6496. const String URL::toString (const bool includeGetParameters) const
  6497. {
  6498. if (includeGetParameters && parameters.size() > 0)
  6499. return url + T("?") + getMangledParameters (parameters);
  6500. else
  6501. return url;
  6502. }
  6503. bool URL::isWellFormed() const
  6504. {
  6505. //xxx TODO
  6506. return url.isNotEmpty();
  6507. }
  6508. static int findStartOfDomain (const String& url)
  6509. {
  6510. int i = 0;
  6511. while (CharacterFunctions::isLetterOrDigit (url[i])
  6512. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6513. ++i;
  6514. return url[i] == T(':') ? i + 1 : 0;
  6515. }
  6516. const String URL::getDomain() const
  6517. {
  6518. int start = findStartOfDomain (url);
  6519. while (url[start] == T('/'))
  6520. ++start;
  6521. const int end1 = url.indexOfChar (start, T('/'));
  6522. const int end2 = url.indexOfChar (start, T(':'));
  6523. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6524. : jmin (end1, end2);
  6525. return url.substring (start, end);
  6526. }
  6527. const String URL::getSubPath() const
  6528. {
  6529. int start = findStartOfDomain (url);
  6530. while (url[start] == T('/'))
  6531. ++start;
  6532. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6533. return startOfPath <= 0 ? String::empty
  6534. : url.substring (startOfPath);
  6535. }
  6536. const String URL::getScheme() const
  6537. {
  6538. return url.substring (0, findStartOfDomain (url) - 1);
  6539. }
  6540. const URL URL::withNewSubPath (const String& newPath) const
  6541. {
  6542. int start = findStartOfDomain (url);
  6543. while (url[start] == T('/'))
  6544. ++start;
  6545. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6546. URL u (*this);
  6547. if (startOfPath > 0)
  6548. u.url = url.substring (0, startOfPath);
  6549. if (! u.url.endsWithChar (T('/')))
  6550. u.url << '/';
  6551. if (newPath.startsWithChar (T('/')))
  6552. u.url << newPath.substring (1);
  6553. else
  6554. u.url << newPath;
  6555. return u;
  6556. }
  6557. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6558. {
  6559. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6560. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6561. return true;
  6562. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6563. || possibleURL.containsChar (T('@'))
  6564. || possibleURL.endsWithChar (T('.'))
  6565. || (! possibleURL.containsChar (T('.'))))
  6566. return false;
  6567. if (possibleURL.startsWithIgnoreCase (T("www."))
  6568. && possibleURL.substring (5).containsChar (T('.')))
  6569. return true;
  6570. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6571. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6572. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6573. return true;
  6574. return false;
  6575. }
  6576. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6577. {
  6578. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6579. return atSign > 0
  6580. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6581. && (! possibleEmailAddress.endsWithChar (T('.')));
  6582. }
  6583. void* juce_openInternetFile (const String& url,
  6584. const String& headers,
  6585. const MemoryBlock& optionalPostData,
  6586. const bool isPost,
  6587. URL::OpenStreamProgressCallback* callback,
  6588. void* callbackContext,
  6589. int timeOutMs);
  6590. void juce_closeInternetFile (void* handle);
  6591. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6592. int juce_seekInInternetFile (void* handle, int newPosition);
  6593. int64 juce_getInternetFileContentLength (void* handle);
  6594. class WebInputStream : public InputStream
  6595. {
  6596. public:
  6597. WebInputStream (const URL& url,
  6598. const bool isPost_,
  6599. URL::OpenStreamProgressCallback* const progressCallback_,
  6600. void* const progressCallbackContext_,
  6601. const String& extraHeaders,
  6602. int timeOutMs_)
  6603. : position (0),
  6604. finished (false),
  6605. isPost (isPost_),
  6606. progressCallback (progressCallback_),
  6607. progressCallbackContext (progressCallbackContext_),
  6608. timeOutMs (timeOutMs_)
  6609. {
  6610. server = url.toString (! isPost);
  6611. if (isPost_)
  6612. createHeadersAndPostData (url);
  6613. headers += extraHeaders;
  6614. if (! headers.endsWithChar (T('\n')))
  6615. headers << "\r\n";
  6616. handle = juce_openInternetFile (server, headers, postData, isPost,
  6617. progressCallback_, progressCallbackContext_,
  6618. timeOutMs);
  6619. }
  6620. ~WebInputStream()
  6621. {
  6622. juce_closeInternetFile (handle);
  6623. }
  6624. bool isError() const
  6625. {
  6626. return handle == 0;
  6627. }
  6628. int64 getTotalLength()
  6629. {
  6630. return juce_getInternetFileContentLength (handle);
  6631. }
  6632. bool isExhausted()
  6633. {
  6634. return finished;
  6635. }
  6636. int read (void* dest, int bytes)
  6637. {
  6638. if (finished || isError())
  6639. {
  6640. return 0;
  6641. }
  6642. else
  6643. {
  6644. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6645. position += bytesRead;
  6646. if (bytesRead == 0)
  6647. finished = true;
  6648. return bytesRead;
  6649. }
  6650. }
  6651. int64 getPosition()
  6652. {
  6653. return position;
  6654. }
  6655. bool setPosition (int64 wantedPos)
  6656. {
  6657. if (wantedPos != position)
  6658. {
  6659. finished = false;
  6660. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6661. if (actualPos == wantedPos)
  6662. {
  6663. position = wantedPos;
  6664. }
  6665. else
  6666. {
  6667. if (wantedPos < position)
  6668. {
  6669. juce_closeInternetFile (handle);
  6670. position = 0;
  6671. finished = false;
  6672. handle = juce_openInternetFile (server, headers, postData, isPost,
  6673. progressCallback, progressCallbackContext,
  6674. timeOutMs);
  6675. }
  6676. skipNextBytes (wantedPos - position);
  6677. }
  6678. }
  6679. return true;
  6680. }
  6681. juce_UseDebuggingNewOperator
  6682. private:
  6683. String server, headers;
  6684. MemoryBlock postData;
  6685. int64 position;
  6686. bool finished;
  6687. const bool isPost;
  6688. void* handle;
  6689. URL::OpenStreamProgressCallback* const progressCallback;
  6690. void* const progressCallbackContext;
  6691. const int timeOutMs;
  6692. void createHeadersAndPostData (const URL& url)
  6693. {
  6694. if (url.getFilesToUpload().size() > 0)
  6695. {
  6696. // need to upload some files, so do it as multi-part...
  6697. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6698. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6699. appendUTF8ToPostData ("--" + boundary);
  6700. int i;
  6701. for (i = 0; i < url.getParameters().size(); ++i)
  6702. {
  6703. String s;
  6704. s << "\r\nContent-Disposition: form-data; name=\""
  6705. << url.getParameters().getAllKeys() [i]
  6706. << "\"\r\n\r\n"
  6707. << url.getParameters().getAllValues() [i]
  6708. << "\r\n--"
  6709. << boundary;
  6710. appendUTF8ToPostData (s);
  6711. }
  6712. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6713. {
  6714. const File f (url.getFilesToUpload().getAllValues() [i]);
  6715. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6716. String s;
  6717. s << "\r\nContent-Disposition: form-data; name=\""
  6718. << paramName
  6719. << "\"; filename=\""
  6720. << f.getFileName()
  6721. << "\"\r\n";
  6722. const String mimeType (url.getMimeTypesOfUploadFiles()
  6723. .getValue (paramName, String::empty));
  6724. if (mimeType.isNotEmpty())
  6725. s << "Content-Type: " << mimeType << "\r\n";
  6726. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6727. appendUTF8ToPostData (s);
  6728. f.loadFileAsData (postData);
  6729. s = "\r\n--" + boundary;
  6730. appendUTF8ToPostData (s);
  6731. }
  6732. appendUTF8ToPostData ("--\r\n");
  6733. }
  6734. else
  6735. {
  6736. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6737. appendUTF8ToPostData (url.getPostData());
  6738. // just a short text attachment, so use simple url encoding..
  6739. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6740. + String ((unsigned int) postData.getSize())
  6741. + "\r\n";
  6742. }
  6743. }
  6744. void appendUTF8ToPostData (const String& text)
  6745. {
  6746. postData.append (text.toUTF8(),
  6747. (int) strlen (text.toUTF8()));
  6748. }
  6749. WebInputStream (const WebInputStream&);
  6750. const WebInputStream& operator= (const WebInputStream&);
  6751. };
  6752. InputStream* URL::createInputStream (const bool usePostCommand,
  6753. OpenStreamProgressCallback* const progressCallback,
  6754. void* const progressCallbackContext,
  6755. const String& extraHeaders,
  6756. const int timeOutMs) const
  6757. {
  6758. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6759. progressCallback, progressCallbackContext,
  6760. extraHeaders,
  6761. timeOutMs));
  6762. return wi->isError() ? 0 : wi.release();
  6763. }
  6764. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6765. const bool usePostCommand) const
  6766. {
  6767. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6768. if (in != 0)
  6769. {
  6770. in->readIntoMemoryBlock (destData, -1);
  6771. return true;
  6772. }
  6773. return false;
  6774. }
  6775. const String URL::readEntireTextStream (const bool usePostCommand) const
  6776. {
  6777. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6778. if (in != 0)
  6779. return in->readEntireStreamAsString();
  6780. return String::empty;
  6781. }
  6782. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6783. {
  6784. XmlDocument doc (readEntireTextStream (usePostCommand));
  6785. return doc.getDocumentElement();
  6786. }
  6787. const URL URL::withParameter (const String& parameterName,
  6788. const String& parameterValue) const
  6789. {
  6790. URL u (*this);
  6791. u.parameters.set (parameterName, parameterValue);
  6792. return u;
  6793. }
  6794. const URL URL::withFileToUpload (const String& parameterName,
  6795. const File& fileToUpload,
  6796. const String& mimeType) const
  6797. {
  6798. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6799. URL u (*this);
  6800. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6801. u.mimeTypes.set (parameterName, mimeType);
  6802. return u;
  6803. }
  6804. const URL URL::withPOSTData (const String& postData_) const
  6805. {
  6806. URL u (*this);
  6807. u.postData = postData_;
  6808. return u;
  6809. }
  6810. const StringPairArray& URL::getParameters() const
  6811. {
  6812. return parameters;
  6813. }
  6814. const StringPairArray& URL::getFilesToUpload() const
  6815. {
  6816. return filesToUpload;
  6817. }
  6818. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6819. {
  6820. return mimeTypes;
  6821. }
  6822. const String URL::removeEscapeChars (const String& s)
  6823. {
  6824. const int len = s.length();
  6825. HeapBlock <uint8> resultUTF8 (len * 4);
  6826. uint8* r = resultUTF8;
  6827. for (int i = 0; i < len; ++i)
  6828. {
  6829. char c = (char) s[i];
  6830. if (c == 0)
  6831. break;
  6832. if (c == '+')
  6833. {
  6834. c = ' ';
  6835. }
  6836. else if (c == '%')
  6837. {
  6838. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6839. i += 2;
  6840. }
  6841. *r++ = c;
  6842. }
  6843. return String::fromUTF8 (resultUTF8);
  6844. }
  6845. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6846. {
  6847. String result;
  6848. result.preallocateStorage (s.length() + 8);
  6849. const char* utf8 = s.toUTF8();
  6850. const char* legalChars = isParameter ? "_-.*!'()"
  6851. : "_-$.*!'(),";
  6852. while (*utf8 != 0)
  6853. {
  6854. const char c = *utf8++;
  6855. if (CharacterFunctions::isLetterOrDigit (c)
  6856. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6857. {
  6858. result << c;
  6859. }
  6860. else
  6861. {
  6862. const int v = (int) (uint8) c;
  6863. if (v < 0x10)
  6864. result << T("%0");
  6865. else
  6866. result << T('%');
  6867. result << String::toHexString (v);
  6868. }
  6869. }
  6870. return result;
  6871. }
  6872. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6873. bool URL::launchInDefaultBrowser() const
  6874. {
  6875. String u (toString (true));
  6876. if (u.contains (T("@")) && ! u.contains (T(":")))
  6877. u = "mailto:" + u;
  6878. return juce_launchFile (u, String::empty);
  6879. }
  6880. END_JUCE_NAMESPACE
  6881. /*** End of inlined file: juce_URL.cpp ***/
  6882. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6883. BEGIN_JUCE_NAMESPACE
  6884. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6885. const int bufferSize_,
  6886. const bool deleteSourceWhenDestroyed)
  6887. : source (source_),
  6888. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6889. bufferSize (jmax (256, bufferSize_)),
  6890. position (source_->getPosition()),
  6891. lastReadPos (0),
  6892. bufferOverlap (128)
  6893. {
  6894. const int sourceSize = (int) source_->getTotalLength();
  6895. if (sourceSize >= 0)
  6896. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6897. bufferStart = position;
  6898. buffer.malloc (bufferSize);
  6899. }
  6900. BufferedInputStream::~BufferedInputStream()
  6901. {
  6902. }
  6903. int64 BufferedInputStream::getTotalLength()
  6904. {
  6905. return source->getTotalLength();
  6906. }
  6907. int64 BufferedInputStream::getPosition()
  6908. {
  6909. return position;
  6910. }
  6911. bool BufferedInputStream::setPosition (int64 newPosition)
  6912. {
  6913. position = jmax ((int64) 0, newPosition);
  6914. return true;
  6915. }
  6916. bool BufferedInputStream::isExhausted()
  6917. {
  6918. return (position >= lastReadPos)
  6919. && source->isExhausted();
  6920. }
  6921. void BufferedInputStream::ensureBuffered()
  6922. {
  6923. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6924. if (position < bufferStart || position >= bufferEndOverlap)
  6925. {
  6926. int bytesRead;
  6927. if (position < lastReadPos
  6928. && position >= bufferEndOverlap
  6929. && position >= bufferStart)
  6930. {
  6931. const int bytesToKeep = (int) (lastReadPos - position);
  6932. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6933. bufferStart = position;
  6934. bytesRead = source->read (buffer + bytesToKeep,
  6935. bufferSize - bytesToKeep);
  6936. lastReadPos += bytesRead;
  6937. bytesRead += bytesToKeep;
  6938. }
  6939. else
  6940. {
  6941. bufferStart = position;
  6942. source->setPosition (bufferStart);
  6943. bytesRead = source->read (buffer, bufferSize);
  6944. lastReadPos = bufferStart + bytesRead;
  6945. }
  6946. while (bytesRead < bufferSize)
  6947. buffer [bytesRead++] = 0;
  6948. }
  6949. }
  6950. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6951. {
  6952. if (position >= bufferStart
  6953. && position + maxBytesToRead <= lastReadPos)
  6954. {
  6955. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6956. position += maxBytesToRead;
  6957. return maxBytesToRead;
  6958. }
  6959. else
  6960. {
  6961. if (position < bufferStart || position >= lastReadPos)
  6962. ensureBuffered();
  6963. int bytesRead = 0;
  6964. while (maxBytesToRead > 0)
  6965. {
  6966. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6967. if (bytesAvailable > 0)
  6968. {
  6969. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6970. maxBytesToRead -= bytesAvailable;
  6971. bytesRead += bytesAvailable;
  6972. position += bytesAvailable;
  6973. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6974. }
  6975. const int64 oldLastReadPos = lastReadPos;
  6976. ensureBuffered();
  6977. if (oldLastReadPos == lastReadPos)
  6978. break; // if ensureBuffered() failed to read any more data, bail out
  6979. if (isExhausted())
  6980. break;
  6981. }
  6982. return bytesRead;
  6983. }
  6984. }
  6985. const String BufferedInputStream::readString()
  6986. {
  6987. if (position >= bufferStart
  6988. && position < lastReadPos)
  6989. {
  6990. const int maxChars = (int) (lastReadPos - position);
  6991. const char* const src = buffer + (int) (position - bufferStart);
  6992. for (int i = 0; i < maxChars; ++i)
  6993. {
  6994. if (src[i] == 0)
  6995. {
  6996. position += i + 1;
  6997. return String::fromUTF8 ((const uint8*) src, i);
  6998. }
  6999. }
  7000. }
  7001. return InputStream::readString();
  7002. }
  7003. END_JUCE_NAMESPACE
  7004. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  7005. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  7006. BEGIN_JUCE_NAMESPACE
  7007. FileInputSource::FileInputSource (const File& file_)
  7008. : file (file_)
  7009. {
  7010. }
  7011. FileInputSource::~FileInputSource()
  7012. {
  7013. }
  7014. InputStream* FileInputSource::createInputStream()
  7015. {
  7016. return file.createInputStream();
  7017. }
  7018. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  7019. {
  7020. return file.getSiblingFile (relatedItemPath).createInputStream();
  7021. }
  7022. int64 FileInputSource::hashCode() const
  7023. {
  7024. return file.hashCode();
  7025. }
  7026. END_JUCE_NAMESPACE
  7027. /*** End of inlined file: juce_FileInputSource.cpp ***/
  7028. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  7029. BEGIN_JUCE_NAMESPACE
  7030. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  7031. const size_t sourceDataSize,
  7032. const bool keepInternalCopy)
  7033. : data ((const char*) sourceData),
  7034. dataSize (sourceDataSize),
  7035. position (0)
  7036. {
  7037. if (keepInternalCopy)
  7038. {
  7039. internalCopy.append (data, sourceDataSize);
  7040. data = (const char*) internalCopy.getData();
  7041. }
  7042. }
  7043. MemoryInputStream::~MemoryInputStream()
  7044. {
  7045. }
  7046. int64 MemoryInputStream::getTotalLength()
  7047. {
  7048. return dataSize;
  7049. }
  7050. int MemoryInputStream::read (void* buffer, int howMany)
  7051. {
  7052. jassert (howMany >= 0);
  7053. const int num = jmin (howMany, (int) (dataSize - position));
  7054. memcpy (buffer, data + position, num);
  7055. position += num;
  7056. return (int) num;
  7057. }
  7058. bool MemoryInputStream::isExhausted()
  7059. {
  7060. return (position >= dataSize);
  7061. }
  7062. bool MemoryInputStream::setPosition (int64 pos)
  7063. {
  7064. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  7065. return true;
  7066. }
  7067. int64 MemoryInputStream::getPosition()
  7068. {
  7069. return position;
  7070. }
  7071. END_JUCE_NAMESPACE
  7072. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  7073. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  7074. BEGIN_JUCE_NAMESPACE
  7075. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  7076. const size_t blockSizeToIncreaseBy,
  7077. MemoryBlock* const memoryBlockToWriteTo) throw()
  7078. : data (memoryBlockToWriteTo),
  7079. position (0),
  7080. size (0),
  7081. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  7082. {
  7083. if (data == 0)
  7084. dataToDelete = data = new MemoryBlock (initialSize);
  7085. else
  7086. data->setSize (initialSize, false);
  7087. }
  7088. MemoryOutputStream::~MemoryOutputStream() throw()
  7089. {
  7090. flush();
  7091. }
  7092. void MemoryOutputStream::flush()
  7093. {
  7094. if (dataToDelete == 0)
  7095. data->setSize (size, false);
  7096. }
  7097. void MemoryOutputStream::reset() throw()
  7098. {
  7099. position = 0;
  7100. size = 0;
  7101. }
  7102. bool MemoryOutputStream::write (const void* buffer, int howMany)
  7103. {
  7104. if (howMany > 0)
  7105. {
  7106. size_t storageNeeded = position + howMany;
  7107. if (storageNeeded >= data->getSize())
  7108. {
  7109. // if we need more space, increase the block by at least 10%..
  7110. storageNeeded += jmax (blockSize, storageNeeded / 10);
  7111. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  7112. data->ensureSize (storageNeeded);
  7113. }
  7114. data->copyFrom (buffer, (int) position, howMany);
  7115. position += howMany;
  7116. size = jmax (size, position);
  7117. }
  7118. return true;
  7119. }
  7120. const char* MemoryOutputStream::getData() const throw()
  7121. {
  7122. if (data->getSize() > size)
  7123. ((char*) data->getData()) [size] = 0;
  7124. return (const char*) data->getData();
  7125. }
  7126. size_t MemoryOutputStream::getDataSize() const throw()
  7127. {
  7128. return size;
  7129. }
  7130. int64 MemoryOutputStream::getPosition()
  7131. {
  7132. return position;
  7133. }
  7134. bool MemoryOutputStream::setPosition (int64 newPosition)
  7135. {
  7136. if (newPosition <= (int64) size)
  7137. {
  7138. // ok to seek backwards
  7139. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  7140. return true;
  7141. }
  7142. else
  7143. {
  7144. // trying to make it bigger isn't a good thing to do..
  7145. return false;
  7146. }
  7147. }
  7148. END_JUCE_NAMESPACE
  7149. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  7150. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  7151. BEGIN_JUCE_NAMESPACE
  7152. SubregionStream::SubregionStream (InputStream* const sourceStream,
  7153. const int64 startPositionInSourceStream_,
  7154. const int64 lengthOfSourceStream_,
  7155. const bool deleteSourceWhenDestroyed) throw()
  7156. : source (sourceStream),
  7157. startPositionInSourceStream (startPositionInSourceStream_),
  7158. lengthOfSourceStream (lengthOfSourceStream_)
  7159. {
  7160. if (deleteSourceWhenDestroyed)
  7161. sourceToDelete = source;
  7162. setPosition (0);
  7163. }
  7164. SubregionStream::~SubregionStream() throw()
  7165. {
  7166. }
  7167. int64 SubregionStream::getTotalLength()
  7168. {
  7169. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  7170. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  7171. : srcLen;
  7172. }
  7173. int64 SubregionStream::getPosition()
  7174. {
  7175. return source->getPosition() - startPositionInSourceStream;
  7176. }
  7177. bool SubregionStream::setPosition (int64 newPosition)
  7178. {
  7179. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7180. }
  7181. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7182. {
  7183. if (lengthOfSourceStream < 0)
  7184. {
  7185. return source->read (destBuffer, maxBytesToRead);
  7186. }
  7187. else
  7188. {
  7189. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7190. if (maxBytesToRead <= 0)
  7191. return 0;
  7192. return source->read (destBuffer, maxBytesToRead);
  7193. }
  7194. }
  7195. bool SubregionStream::isExhausted()
  7196. {
  7197. if (lengthOfSourceStream >= 0)
  7198. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7199. else
  7200. return source->isExhausted();
  7201. }
  7202. END_JUCE_NAMESPACE
  7203. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7204. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7205. BEGIN_JUCE_NAMESPACE
  7206. PerformanceCounter::PerformanceCounter (const String& name_,
  7207. int runsPerPrintout,
  7208. const File& loggingFile)
  7209. : name (name_),
  7210. numRuns (0),
  7211. runsPerPrint (runsPerPrintout),
  7212. totalTime (0),
  7213. outputFile (loggingFile)
  7214. {
  7215. if (outputFile != File::nonexistent)
  7216. {
  7217. String s ("**** Counter for \"");
  7218. s << name_ << "\" started at: "
  7219. << Time::getCurrentTime().toString (true, true)
  7220. << "\r\n";
  7221. outputFile.appendText (s, false, false);
  7222. }
  7223. }
  7224. PerformanceCounter::~PerformanceCounter()
  7225. {
  7226. printStatistics();
  7227. }
  7228. void PerformanceCounter::start()
  7229. {
  7230. started = Time::getHighResolutionTicks();
  7231. }
  7232. void PerformanceCounter::stop()
  7233. {
  7234. const int64 now = Time::getHighResolutionTicks();
  7235. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7236. if (++numRuns == runsPerPrint)
  7237. printStatistics();
  7238. }
  7239. void PerformanceCounter::printStatistics()
  7240. {
  7241. if (numRuns > 0)
  7242. {
  7243. String s ("Performance count for \"");
  7244. s << name << "\" - average over " << numRuns << " run(s) = ";
  7245. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7246. if (micros > 10000)
  7247. s << (micros/1000) << " millisecs";
  7248. else
  7249. s << micros << " microsecs";
  7250. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7251. Logger::outputDebugString (s);
  7252. s << "\r\n";
  7253. if (outputFile != File::nonexistent)
  7254. outputFile.appendText (s, false, false);
  7255. numRuns = 0;
  7256. totalTime = 0;
  7257. }
  7258. }
  7259. END_JUCE_NAMESPACE
  7260. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7261. /*** Start of inlined file: juce_Uuid.cpp ***/
  7262. BEGIN_JUCE_NAMESPACE
  7263. Uuid::Uuid()
  7264. {
  7265. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7266. // to make it very very unlikely that two UUIDs will ever be the same..
  7267. static int64 macAddresses[2];
  7268. static bool hasCheckedMacAddresses = false;
  7269. if (! hasCheckedMacAddresses)
  7270. {
  7271. hasCheckedMacAddresses = true;
  7272. SystemStats::getMACAddresses (macAddresses, 2);
  7273. }
  7274. value.asInt64[0] = macAddresses[0];
  7275. value.asInt64[1] = macAddresses[1];
  7276. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7277. // whose seed will carry over between calls to this method.
  7278. Random r (macAddresses[0] ^ macAddresses[1]
  7279. ^ Random::getSystemRandom().nextInt64());
  7280. for (int i = 4; --i >= 0;)
  7281. {
  7282. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7283. value.asInt[i] ^= r.nextInt();
  7284. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7285. }
  7286. }
  7287. Uuid::~Uuid() throw()
  7288. {
  7289. }
  7290. Uuid::Uuid (const Uuid& other)
  7291. : value (other.value)
  7292. {
  7293. }
  7294. Uuid& Uuid::operator= (const Uuid& other)
  7295. {
  7296. value = other.value;
  7297. return *this;
  7298. }
  7299. bool Uuid::operator== (const Uuid& other) const
  7300. {
  7301. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7302. }
  7303. bool Uuid::operator!= (const Uuid& other) const
  7304. {
  7305. return ! operator== (other);
  7306. }
  7307. bool Uuid::isNull() const throw()
  7308. {
  7309. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7310. }
  7311. const String Uuid::toString() const
  7312. {
  7313. return String::toHexString (value.asBytes, 16, 0);
  7314. }
  7315. Uuid::Uuid (const String& uuidString)
  7316. {
  7317. operator= (uuidString);
  7318. }
  7319. Uuid& Uuid::operator= (const String& uuidString)
  7320. {
  7321. int destIndex = 0;
  7322. int i = 0;
  7323. for (;;)
  7324. {
  7325. int byte = 0;
  7326. for (int loop = 2; --loop >= 0;)
  7327. {
  7328. byte <<= 4;
  7329. for (;;)
  7330. {
  7331. const tchar c = uuidString [i++];
  7332. if (c >= T('0') && c <= T('9'))
  7333. {
  7334. byte |= c - T('0');
  7335. break;
  7336. }
  7337. else if (c >= T('a') && c <= T('z'))
  7338. {
  7339. byte |= c - (T('a') - 10);
  7340. break;
  7341. }
  7342. else if (c >= T('A') && c <= T('Z'))
  7343. {
  7344. byte |= c - (T('A') - 10);
  7345. break;
  7346. }
  7347. else if (c == 0)
  7348. {
  7349. while (destIndex < 16)
  7350. value.asBytes [destIndex++] = 0;
  7351. return *this;
  7352. }
  7353. }
  7354. }
  7355. value.asBytes [destIndex++] = (uint8) byte;
  7356. }
  7357. }
  7358. Uuid::Uuid (const uint8* const rawData)
  7359. {
  7360. operator= (rawData);
  7361. }
  7362. Uuid& Uuid::operator= (const uint8* const rawData)
  7363. {
  7364. if (rawData != 0)
  7365. memcpy (value.asBytes, rawData, 16);
  7366. else
  7367. zeromem (value.asBytes, 16);
  7368. return *this;
  7369. }
  7370. END_JUCE_NAMESPACE
  7371. /*** End of inlined file: juce_Uuid.cpp ***/
  7372. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7373. BEGIN_JUCE_NAMESPACE
  7374. class ZipFile::ZipEntryInfo
  7375. {
  7376. public:
  7377. ZipFile::ZipEntry entry;
  7378. int streamOffset;
  7379. int compressedSize;
  7380. bool compressed;
  7381. };
  7382. class ZipFile::ZipInputStream : public InputStream
  7383. {
  7384. public:
  7385. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7386. : file (file_),
  7387. zipEntryInfo (zei),
  7388. pos (0),
  7389. headerSize (0),
  7390. inputStream (0)
  7391. {
  7392. inputStream = file_.inputStream;
  7393. if (file_.inputSource != 0)
  7394. {
  7395. inputStream = file.inputSource->createInputStream();
  7396. }
  7397. else
  7398. {
  7399. #ifdef JUCE_DEBUG
  7400. file_.numOpenStreams++;
  7401. #endif
  7402. }
  7403. char buffer [30];
  7404. if (inputStream != 0
  7405. && inputStream->setPosition (zei.streamOffset)
  7406. && inputStream->read (buffer, 30) == 30
  7407. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7408. {
  7409. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7410. + ByteOrder::littleEndianShort (buffer + 28);
  7411. }
  7412. }
  7413. ~ZipInputStream() throw()
  7414. {
  7415. #ifdef JUCE_DEBUG
  7416. if (inputStream != 0 && inputStream == file.inputStream)
  7417. file.numOpenStreams--;
  7418. #endif
  7419. if (inputStream != file.inputStream)
  7420. delete inputStream;
  7421. }
  7422. int64 getTotalLength() throw()
  7423. {
  7424. return zipEntryInfo.compressedSize;
  7425. }
  7426. int read (void* buffer, int howMany) throw()
  7427. {
  7428. if (headerSize <= 0)
  7429. return 0;
  7430. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7431. if (inputStream == 0)
  7432. return 0;
  7433. int num;
  7434. if (inputStream == file.inputStream)
  7435. {
  7436. const ScopedLock sl (file.lock);
  7437. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7438. num = inputStream->read (buffer, howMany);
  7439. }
  7440. else
  7441. {
  7442. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7443. num = inputStream->read (buffer, howMany);
  7444. }
  7445. pos += num;
  7446. return num;
  7447. }
  7448. bool isExhausted() throw()
  7449. {
  7450. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7451. }
  7452. int64 getPosition() throw()
  7453. {
  7454. return pos;
  7455. }
  7456. bool setPosition (int64 newPos) throw()
  7457. {
  7458. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7459. return true;
  7460. }
  7461. private:
  7462. ZipFile& file;
  7463. ZipEntryInfo zipEntryInfo;
  7464. int64 pos;
  7465. int headerSize;
  7466. InputStream* inputStream;
  7467. ZipInputStream (const ZipInputStream&);
  7468. const ZipInputStream& operator= (const ZipInputStream&);
  7469. };
  7470. ZipFile::ZipFile (InputStream* const source_,
  7471. const bool deleteStreamWhenDestroyed) throw()
  7472. : inputStream (source_)
  7473. #ifdef JUCE_DEBUG
  7474. , numOpenStreams (0)
  7475. #endif
  7476. {
  7477. if (deleteStreamWhenDestroyed)
  7478. streamToDelete = inputStream;
  7479. init();
  7480. }
  7481. ZipFile::ZipFile (const File& file)
  7482. : inputStream (0)
  7483. #ifdef JUCE_DEBUG
  7484. , numOpenStreams (0)
  7485. #endif
  7486. {
  7487. inputSource = new FileInputSource (file);
  7488. init();
  7489. }
  7490. ZipFile::ZipFile (InputSource* const inputSource_)
  7491. : inputStream (0),
  7492. inputSource (inputSource_)
  7493. #ifdef JUCE_DEBUG
  7494. , numOpenStreams (0)
  7495. #endif
  7496. {
  7497. init();
  7498. }
  7499. ZipFile::~ZipFile() throw()
  7500. {
  7501. #ifdef JUCE_DEBUG
  7502. entries.clear();
  7503. // If you hit this assertion, it means you've created a stream to read
  7504. // one of the items in the zipfile, but you've forgotten to delete that
  7505. // stream object before deleting the file.. Streams can't be kept open
  7506. // after the file is deleted because they need to share the input
  7507. // stream that the file uses to read itself.
  7508. jassert (numOpenStreams == 0);
  7509. #endif
  7510. }
  7511. int ZipFile::getNumEntries() const throw()
  7512. {
  7513. return entries.size();
  7514. }
  7515. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7516. {
  7517. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7518. return (zei != 0) ? &(zei->entry)
  7519. : 0;
  7520. }
  7521. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7522. {
  7523. for (int i = 0; i < entries.size(); ++i)
  7524. if (entries.getUnchecked (i)->entry.filename == fileName)
  7525. return i;
  7526. return -1;
  7527. }
  7528. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7529. {
  7530. return getEntry (getIndexOfFileName (fileName));
  7531. }
  7532. InputStream* ZipFile::createStreamForEntry (const int index)
  7533. {
  7534. ZipEntryInfo* const zei = entries[index];
  7535. InputStream* stream = 0;
  7536. if (zei != 0)
  7537. {
  7538. stream = new ZipInputStream (*this, *zei);
  7539. if (zei->compressed)
  7540. {
  7541. stream = new GZIPDecompressorInputStream (stream, true, true,
  7542. zei->entry.uncompressedSize);
  7543. // (much faster to unzip in big blocks using a buffer..)
  7544. stream = new BufferedInputStream (stream, 32768, true);
  7545. }
  7546. }
  7547. return stream;
  7548. }
  7549. class ZipFile::ZipFilenameComparator
  7550. {
  7551. public:
  7552. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7553. {
  7554. return first->entry.filename.compare (second->entry.filename);
  7555. }
  7556. };
  7557. void ZipFile::sortEntriesByFilename()
  7558. {
  7559. ZipFilenameComparator sorter;
  7560. entries.sort (sorter);
  7561. }
  7562. void ZipFile::init()
  7563. {
  7564. ScopedPointer <InputStream> toDelete;
  7565. InputStream* in = inputStream;
  7566. if (inputSource != 0)
  7567. {
  7568. in = inputSource->createInputStream();
  7569. toDelete = in;
  7570. }
  7571. if (in != 0)
  7572. {
  7573. int numEntries = 0;
  7574. int pos = findEndOfZipEntryTable (in, numEntries);
  7575. if (pos >= 0 && pos < in->getTotalLength())
  7576. {
  7577. const int size = (int) (in->getTotalLength() - pos);
  7578. in->setPosition (pos);
  7579. MemoryBlock headerData;
  7580. if (in->readIntoMemoryBlock (headerData, size) == size)
  7581. {
  7582. pos = 0;
  7583. for (int i = 0; i < numEntries; ++i)
  7584. {
  7585. if (pos + 46 > size)
  7586. break;
  7587. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7588. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7589. if (pos + 46 + fileNameLen > size)
  7590. break;
  7591. ZipEntryInfo* const zei = new ZipEntryInfo();
  7592. zei->entry.filename = String::fromUTF8 ((const uint8*) buffer + 46, fileNameLen);
  7593. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7594. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7595. const int year = 1980 + (date >> 9);
  7596. const int month = ((date >> 5) & 15) - 1;
  7597. const int day = date & 31;
  7598. const int hours = time >> 11;
  7599. const int minutes = (time >> 5) & 63;
  7600. const int seconds = (time & 31) << 1;
  7601. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7602. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7603. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7604. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7605. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7606. entries.add (zei);
  7607. pos += 46 + fileNameLen
  7608. + ByteOrder::littleEndianShort (buffer + 30)
  7609. + ByteOrder::littleEndianShort (buffer + 32);
  7610. }
  7611. }
  7612. }
  7613. }
  7614. }
  7615. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7616. {
  7617. BufferedInputStream in (input, 8192, false);
  7618. in.setPosition (in.getTotalLength());
  7619. int64 pos = in.getPosition();
  7620. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7621. char buffer [32];
  7622. zeromem (buffer, sizeof (buffer));
  7623. while (pos > lowestPos)
  7624. {
  7625. in.setPosition (pos - 22);
  7626. pos = in.getPosition();
  7627. memcpy (buffer + 22, buffer, 4);
  7628. if (in.read (buffer, 22) != 22)
  7629. return 0;
  7630. for (int i = 0; i < 22; ++i)
  7631. {
  7632. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7633. {
  7634. in.setPosition (pos + i);
  7635. in.read (buffer, 22);
  7636. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7637. return ByteOrder::littleEndianInt (buffer + 16);
  7638. }
  7639. }
  7640. }
  7641. return 0;
  7642. }
  7643. void ZipFile::uncompressTo (const File& targetDirectory,
  7644. const bool shouldOverwriteFiles)
  7645. {
  7646. for (int i = 0; i < entries.size(); ++i)
  7647. {
  7648. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7649. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7650. if (zei.filename.endsWithChar (T('/')))
  7651. {
  7652. targetFile.createDirectory(); // (entry is a directory, not a file)
  7653. }
  7654. else
  7655. {
  7656. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7657. if (in != 0)
  7658. {
  7659. if (shouldOverwriteFiles)
  7660. targetFile.deleteFile();
  7661. if ((! targetFile.exists())
  7662. && targetFile.getParentDirectory().createDirectory())
  7663. {
  7664. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7665. if (out != 0)
  7666. {
  7667. out->writeFromInputStream (*in, -1);
  7668. out = 0;
  7669. targetFile.setCreationTime (zei.fileTime);
  7670. targetFile.setLastModificationTime (zei.fileTime);
  7671. targetFile.setLastAccessTime (zei.fileTime);
  7672. }
  7673. }
  7674. }
  7675. }
  7676. }
  7677. }
  7678. END_JUCE_NAMESPACE
  7679. /*** End of inlined file: juce_ZipFile.cpp ***/
  7680. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7681. #ifdef _MSC_VER
  7682. #pragma warning (disable: 4514 4996)
  7683. #pragma warning (push)
  7684. #endif
  7685. #include <cwctype>
  7686. #include <cctype>
  7687. #include <ctime>
  7688. #ifdef _MSC_VER
  7689. #pragma warning (pop)
  7690. #endif
  7691. BEGIN_JUCE_NAMESPACE
  7692. int CharacterFunctions::length (const char* const s) throw()
  7693. {
  7694. return (int) strlen (s);
  7695. }
  7696. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7697. {
  7698. return (int) wcslen (s);
  7699. }
  7700. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7701. {
  7702. strncpy (dest, src, maxChars);
  7703. }
  7704. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7705. {
  7706. wcsncpy (dest, src, maxChars);
  7707. }
  7708. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7709. {
  7710. mbstowcs (dest, src, maxChars);
  7711. }
  7712. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7713. {
  7714. wcstombs (dest, src, maxChars);
  7715. }
  7716. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7717. {
  7718. return (int) wcstombs (0, src, 0);
  7719. }
  7720. void CharacterFunctions::append (char* dest, const char* src) throw()
  7721. {
  7722. strcat (dest, src);
  7723. }
  7724. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7725. {
  7726. wcscat (dest, src);
  7727. }
  7728. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7729. {
  7730. return strcmp (s1, s2);
  7731. }
  7732. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7733. {
  7734. jassert (s1 != 0 && s2 != 0);
  7735. return wcscmp (s1, s2);
  7736. }
  7737. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7738. {
  7739. jassert (s1 != 0 && s2 != 0);
  7740. return strncmp (s1, s2, maxChars);
  7741. }
  7742. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7743. {
  7744. jassert (s1 != 0 && s2 != 0);
  7745. return wcsncmp (s1, s2, maxChars);
  7746. }
  7747. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7748. {
  7749. jassert (s1 != 0 && s2 != 0);
  7750. #if JUCE_WIN32
  7751. return stricmp (s1, s2);
  7752. #else
  7753. return strcasecmp (s1, s2);
  7754. #endif
  7755. }
  7756. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7757. {
  7758. jassert (s1 != 0 && s2 != 0);
  7759. #if JUCE_WIN32
  7760. return _wcsicmp (s1, s2);
  7761. #else
  7762. for (;;)
  7763. {
  7764. if (*s1 != *s2)
  7765. {
  7766. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7767. if (diff != 0)
  7768. return diff < 0 ? -1 : 1;
  7769. }
  7770. else if (*s1 == 0)
  7771. break;
  7772. ++s1;
  7773. ++s2;
  7774. }
  7775. return 0;
  7776. #endif
  7777. }
  7778. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7779. {
  7780. jassert (s1 != 0 && s2 != 0);
  7781. #if JUCE_WIN32
  7782. return strnicmp (s1, s2, maxChars);
  7783. #else
  7784. return strncasecmp (s1, s2, maxChars);
  7785. #endif
  7786. }
  7787. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7788. {
  7789. jassert (s1 != 0 && s2 != 0);
  7790. #if JUCE_WIN32
  7791. return _wcsnicmp (s1, s2, maxChars);
  7792. #else
  7793. while (--maxChars >= 0)
  7794. {
  7795. if (*s1 != *s2)
  7796. {
  7797. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7798. if (diff != 0)
  7799. return diff < 0 ? -1 : 1;
  7800. }
  7801. else if (*s1 == 0)
  7802. break;
  7803. ++s1;
  7804. ++s2;
  7805. }
  7806. return 0;
  7807. #endif
  7808. }
  7809. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7810. {
  7811. return strstr (haystack, needle);
  7812. }
  7813. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7814. {
  7815. return wcsstr (haystack, needle);
  7816. }
  7817. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7818. {
  7819. if (haystack != 0)
  7820. {
  7821. int i = 0;
  7822. if (ignoreCase)
  7823. {
  7824. const char n1 = toLowerCase (needle);
  7825. const char n2 = toUpperCase (needle);
  7826. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7827. {
  7828. while (haystack[i] != 0)
  7829. {
  7830. if (haystack[i] == n1 || haystack[i] == n2)
  7831. return i;
  7832. ++i;
  7833. }
  7834. return -1;
  7835. }
  7836. jassert (n1 == needle);
  7837. }
  7838. while (haystack[i] != 0)
  7839. {
  7840. if (haystack[i] == needle)
  7841. return i;
  7842. ++i;
  7843. }
  7844. }
  7845. return -1;
  7846. }
  7847. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7848. {
  7849. if (haystack != 0)
  7850. {
  7851. int i = 0;
  7852. if (ignoreCase)
  7853. {
  7854. const juce_wchar n1 = toLowerCase (needle);
  7855. const juce_wchar n2 = toUpperCase (needle);
  7856. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7857. {
  7858. while (haystack[i] != 0)
  7859. {
  7860. if (haystack[i] == n1 || haystack[i] == n2)
  7861. return i;
  7862. ++i;
  7863. }
  7864. return -1;
  7865. }
  7866. jassert (n1 == needle);
  7867. }
  7868. while (haystack[i] != 0)
  7869. {
  7870. if (haystack[i] == needle)
  7871. return i;
  7872. ++i;
  7873. }
  7874. }
  7875. return -1;
  7876. }
  7877. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7878. {
  7879. jassert (haystack != 0);
  7880. int i = 0;
  7881. while (haystack[i] != 0)
  7882. {
  7883. if (haystack[i] == needle)
  7884. return i;
  7885. ++i;
  7886. }
  7887. return -1;
  7888. }
  7889. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7890. {
  7891. jassert (haystack != 0);
  7892. int i = 0;
  7893. while (haystack[i] != 0)
  7894. {
  7895. if (haystack[i] == needle)
  7896. return i;
  7897. ++i;
  7898. }
  7899. return -1;
  7900. }
  7901. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7902. {
  7903. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7904. }
  7905. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7906. {
  7907. if (allowedChars == 0)
  7908. return 0;
  7909. int i = 0;
  7910. for (;;)
  7911. {
  7912. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7913. break;
  7914. ++i;
  7915. }
  7916. return i;
  7917. }
  7918. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7919. {
  7920. return (int) strftime (dest, maxChars, format, tm);
  7921. }
  7922. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7923. {
  7924. return (int) wcsftime (dest, maxChars, format, tm);
  7925. }
  7926. int CharacterFunctions::getIntValue (const char* const s) throw()
  7927. {
  7928. return atoi (s);
  7929. }
  7930. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7931. {
  7932. #if JUCE_WIN32
  7933. return _wtoi (s);
  7934. #else
  7935. int v = 0;
  7936. while (isWhitespace (*s))
  7937. ++s;
  7938. const bool isNeg = *s == T('-');
  7939. if (isNeg)
  7940. ++s;
  7941. for (;;)
  7942. {
  7943. const wchar_t c = *s++;
  7944. if (c >= T('0') && c <= T('9'))
  7945. v = v * 10 + (int) (c - T('0'));
  7946. else
  7947. break;
  7948. }
  7949. return isNeg ? -v : v;
  7950. #endif
  7951. }
  7952. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7953. {
  7954. #if JUCE_LINUX
  7955. return atoll (s);
  7956. #elif defined (JUCE_WIN32)
  7957. return _atoi64 (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 char c = *s++;
  7968. if (c >= '0' && c <= '9')
  7969. v = v * 10 + (int64) (c - '0');
  7970. else
  7971. break;
  7972. }
  7973. return isNeg ? -v : v;
  7974. #endif
  7975. }
  7976. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7977. {
  7978. #if JUCE_WIN32
  7979. return _wtoi64 (s);
  7980. #else
  7981. int64 v = 0;
  7982. while (isWhitespace (*s))
  7983. ++s;
  7984. const bool isNeg = *s == T('-');
  7985. if (isNeg)
  7986. ++s;
  7987. for (;;)
  7988. {
  7989. const juce_wchar c = *s++;
  7990. if (c >= T('0') && c <= T('9'))
  7991. v = v * 10 + (int64) (c - T('0'));
  7992. else
  7993. break;
  7994. }
  7995. return isNeg ? -v : v;
  7996. #endif
  7997. }
  7998. static double juce_mulexp10 (const double value, int exponent) throw()
  7999. {
  8000. if (exponent == 0)
  8001. return value;
  8002. if (value == 0)
  8003. return 0;
  8004. const bool negative = (exponent < 0);
  8005. if (negative)
  8006. exponent = -exponent;
  8007. double result = 1.0, power = 10.0;
  8008. for (int bit = 1; exponent != 0; bit <<= 1)
  8009. {
  8010. if ((exponent & bit) != 0)
  8011. {
  8012. exponent ^= bit;
  8013. result *= power;
  8014. if (exponent == 0)
  8015. break;
  8016. }
  8017. power *= power;
  8018. }
  8019. return negative ? (value / result) : (value * result);
  8020. }
  8021. template <class CharType>
  8022. double juce_atof (const CharType* const original) throw()
  8023. {
  8024. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  8025. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  8026. int exponent = 0, decPointIndex = 0, digit = 0;
  8027. int lastDigit = 0, numSignificantDigits = 0;
  8028. bool isNegative = false, digitsFound = false;
  8029. const int maxSignificantDigits = 15 + 2;
  8030. const CharType* s = original;
  8031. while (CharacterFunctions::isWhitespace (*s))
  8032. ++s;
  8033. switch (*s)
  8034. {
  8035. case '-': isNegative = true; // fall-through..
  8036. case '+': ++s;
  8037. }
  8038. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  8039. return atof (String (original)); // Let the c library deal with NAN and INF
  8040. for (;;)
  8041. {
  8042. if (CharacterFunctions::isDigit (*s))
  8043. {
  8044. lastDigit = digit;
  8045. digit = *s++ - '0';
  8046. digitsFound = true;
  8047. if (decPointIndex != 0)
  8048. exponentAdjustment[1]++;
  8049. if (numSignificantDigits == 0 && digit == 0)
  8050. continue;
  8051. if (++numSignificantDigits > maxSignificantDigits)
  8052. {
  8053. if (digit > 5)
  8054. ++accumulator [decPointIndex];
  8055. else if (digit == 5 && (lastDigit & 1) != 0)
  8056. ++accumulator [decPointIndex];
  8057. if (decPointIndex > 0)
  8058. exponentAdjustment[1]--;
  8059. else
  8060. exponentAdjustment[0]++;
  8061. while (CharacterFunctions::isDigit (*s))
  8062. {
  8063. ++s;
  8064. if (decPointIndex == 0)
  8065. exponentAdjustment[0]++;
  8066. }
  8067. }
  8068. else
  8069. {
  8070. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  8071. if (accumulator [decPointIndex] > maxAccumulatorValue)
  8072. {
  8073. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  8074. + accumulator [decPointIndex];
  8075. accumulator [decPointIndex] = 0;
  8076. exponentAccumulator [decPointIndex] = 0;
  8077. }
  8078. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  8079. exponentAccumulator [decPointIndex]++;
  8080. }
  8081. }
  8082. else if (decPointIndex == 0 && *s == '.')
  8083. {
  8084. ++s;
  8085. decPointIndex = 1;
  8086. if (numSignificantDigits > maxSignificantDigits)
  8087. {
  8088. while (CharacterFunctions::isDigit (*s))
  8089. ++s;
  8090. break;
  8091. }
  8092. }
  8093. else
  8094. {
  8095. break;
  8096. }
  8097. }
  8098. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  8099. if (decPointIndex != 0)
  8100. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  8101. if ((*s == 'e' || *s == 'E') && digitsFound)
  8102. {
  8103. bool negativeExponent = false;
  8104. switch (*++s)
  8105. {
  8106. case '-': negativeExponent = true; // fall-through..
  8107. case '+': ++s;
  8108. }
  8109. while (CharacterFunctions::isDigit (*s))
  8110. exponent = (exponent * 10) + (*s++ - '0');
  8111. if (negativeExponent)
  8112. exponent = -exponent;
  8113. }
  8114. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  8115. if (decPointIndex != 0)
  8116. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  8117. return isNegative ? -r : r;
  8118. }
  8119. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  8120. {
  8121. return juce_atof <char> (s);
  8122. }
  8123. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  8124. {
  8125. return juce_atof <juce_wchar> (s);
  8126. }
  8127. char CharacterFunctions::toUpperCase (const char character) throw()
  8128. {
  8129. return (char) toupper (character);
  8130. }
  8131. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  8132. {
  8133. return towupper (character);
  8134. }
  8135. void CharacterFunctions::toUpperCase (char* s) throw()
  8136. {
  8137. #if JUCE_WIN32
  8138. strupr (s);
  8139. #else
  8140. while (*s != 0)
  8141. {
  8142. *s = toUpperCase (*s);
  8143. ++s;
  8144. }
  8145. #endif
  8146. }
  8147. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  8148. {
  8149. #if JUCE_WIN32
  8150. _wcsupr (s);
  8151. #else
  8152. while (*s != 0)
  8153. {
  8154. *s = toUpperCase (*s);
  8155. ++s;
  8156. }
  8157. #endif
  8158. }
  8159. bool CharacterFunctions::isUpperCase (const char character) throw()
  8160. {
  8161. return isupper (character) != 0;
  8162. }
  8163. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8164. {
  8165. #if JUCE_WIN32
  8166. return iswupper (character) != 0;
  8167. #else
  8168. return toLowerCase (character) != character;
  8169. #endif
  8170. }
  8171. char CharacterFunctions::toLowerCase (const char character) throw()
  8172. {
  8173. return (char) tolower (character);
  8174. }
  8175. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8176. {
  8177. return towlower (character);
  8178. }
  8179. void CharacterFunctions::toLowerCase (char* s) throw()
  8180. {
  8181. #if JUCE_WIN32
  8182. strlwr (s);
  8183. #else
  8184. while (*s != 0)
  8185. {
  8186. *s = toLowerCase (*s);
  8187. ++s;
  8188. }
  8189. #endif
  8190. }
  8191. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8192. {
  8193. #if JUCE_WIN32
  8194. _wcslwr (s);
  8195. #else
  8196. while (*s != 0)
  8197. {
  8198. *s = toLowerCase (*s);
  8199. ++s;
  8200. }
  8201. #endif
  8202. }
  8203. bool CharacterFunctions::isLowerCase (const char character) throw()
  8204. {
  8205. return islower (character) != 0;
  8206. }
  8207. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8208. {
  8209. #if JUCE_WIN32
  8210. return iswlower (character) != 0;
  8211. #else
  8212. return toUpperCase (character) != character;
  8213. #endif
  8214. }
  8215. bool CharacterFunctions::isWhitespace (const char character) throw()
  8216. {
  8217. return character == T(' ') || (character <= 13 && character >= 9);
  8218. }
  8219. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8220. {
  8221. return iswspace (character) != 0;
  8222. }
  8223. bool CharacterFunctions::isDigit (const char character) throw()
  8224. {
  8225. return (character >= '0' && character <= '9');
  8226. }
  8227. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8228. {
  8229. return iswdigit (character) != 0;
  8230. }
  8231. bool CharacterFunctions::isLetter (const char character) throw()
  8232. {
  8233. return (character >= 'a' && character <= 'z')
  8234. || (character >= 'A' && character <= 'Z');
  8235. }
  8236. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8237. {
  8238. return iswalpha (character) != 0;
  8239. }
  8240. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8241. {
  8242. return (character >= 'a' && character <= 'z')
  8243. || (character >= 'A' && character <= 'Z')
  8244. || (character >= '0' && character <= '9');
  8245. }
  8246. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8247. {
  8248. return iswalnum (character) != 0;
  8249. }
  8250. int CharacterFunctions::getHexDigitValue (const tchar digit) throw()
  8251. {
  8252. if (digit >= T('0') && digit <= T('9'))
  8253. return digit - T('0');
  8254. else if (digit >= T('a') && digit <= T('f'))
  8255. return digit - (T('a') - 10);
  8256. else if (digit >= T('A') && digit <= T('F'))
  8257. return digit - (T('A') - 10);
  8258. return -1;
  8259. }
  8260. int CharacterFunctions::printf (char* const dest, const int maxLength, const char* const format, ...) throw()
  8261. {
  8262. va_list list;
  8263. va_start (list, format);
  8264. return vprintf (dest, maxLength, format, list);
  8265. }
  8266. int CharacterFunctions::printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw()
  8267. {
  8268. va_list list;
  8269. va_start (list, format);
  8270. return vprintf (dest, maxLength, format, list);
  8271. }
  8272. int CharacterFunctions::vprintf (char* const dest, const int maxLength, const char* const format, va_list& args) throw()
  8273. {
  8274. #if JUCE_WIN32
  8275. return (int) _vsnprintf (dest, maxLength, format, args);
  8276. #else
  8277. return (int) vsnprintf (dest, maxLength, format, args);
  8278. #endif
  8279. }
  8280. int CharacterFunctions::vprintf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, va_list& args) throw()
  8281. {
  8282. #if defined (JUCE_WIN32)
  8283. return (int) _vsnwprintf (dest, maxLength, format, args);
  8284. #else
  8285. return (int) vswprintf (dest, maxLength, format, args);
  8286. #endif
  8287. }
  8288. END_JUCE_NAMESPACE
  8289. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8290. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8291. BEGIN_JUCE_NAMESPACE
  8292. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8293. {
  8294. loadFromText (fileContents);
  8295. }
  8296. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8297. {
  8298. loadFromText (fileToLoad.loadFileAsString());
  8299. }
  8300. LocalisedStrings::~LocalisedStrings()
  8301. {
  8302. }
  8303. const String LocalisedStrings::translate (const String& text) const
  8304. {
  8305. return translations.getValue (text, text);
  8306. }
  8307. static int findCloseQuote (const String& text, int startPos)
  8308. {
  8309. tchar lastChar = 0;
  8310. for (;;)
  8311. {
  8312. const tchar c = text [startPos];
  8313. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8314. break;
  8315. lastChar = c;
  8316. ++startPos;
  8317. }
  8318. return startPos;
  8319. }
  8320. static const String unescapeString (const String& s)
  8321. {
  8322. return s.replace (T("\\\""), T("\""))
  8323. .replace (T("\\\'"), T("\'"))
  8324. .replace (T("\\t"), T("\t"))
  8325. .replace (T("\\r"), T("\r"))
  8326. .replace (T("\\n"), T("\n"));
  8327. }
  8328. void LocalisedStrings::loadFromText (const String& fileContents)
  8329. {
  8330. StringArray lines;
  8331. lines.addLines (fileContents);
  8332. for (int i = 0; i < lines.size(); ++i)
  8333. {
  8334. String line (lines[i].trim());
  8335. if (line.startsWithChar (T('"')))
  8336. {
  8337. int closeQuote = findCloseQuote (line, 1);
  8338. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8339. if (originalText.isNotEmpty())
  8340. {
  8341. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8342. closeQuote = findCloseQuote (line, openingQuote + 1);
  8343. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8344. if (newText.isNotEmpty())
  8345. translations.set (originalText, newText);
  8346. }
  8347. }
  8348. else if (line.startsWithIgnoreCase (T("language:")))
  8349. {
  8350. languageName = line.substring (9).trim();
  8351. }
  8352. else if (line.startsWithIgnoreCase (T("countries:")))
  8353. {
  8354. countryCodes.addTokens (line.substring (10).trim(), true);
  8355. countryCodes.trim();
  8356. countryCodes.removeEmptyStrings();
  8357. }
  8358. }
  8359. }
  8360. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8361. {
  8362. translations.setIgnoresCase (shouldIgnoreCase);
  8363. }
  8364. static CriticalSection currentMappingsLock;
  8365. static LocalisedStrings* currentMappings = 0;
  8366. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8367. {
  8368. const ScopedLock sl (currentMappingsLock);
  8369. delete currentMappings;
  8370. currentMappings = newTranslations;
  8371. }
  8372. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8373. {
  8374. return currentMappings;
  8375. }
  8376. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8377. {
  8378. const ScopedLock sl (currentMappingsLock);
  8379. if (currentMappings != 0)
  8380. return currentMappings->translate (text);
  8381. return text;
  8382. }
  8383. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8384. {
  8385. return translateWithCurrentMappings (String (text));
  8386. }
  8387. END_JUCE_NAMESPACE
  8388. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8389. /*** Start of inlined file: juce_String.cpp ***/
  8390. #ifdef _MSC_VER
  8391. #pragma warning (disable: 4514)
  8392. #pragma warning (push)
  8393. #endif
  8394. #include <locale>
  8395. #if JUCE_MSVC
  8396. #include <float.h>
  8397. #endif
  8398. BEGIN_JUCE_NAMESPACE
  8399. #ifdef _MSC_VER
  8400. #pragma warning (pop)
  8401. #endif
  8402. static const char* const emptyCharString = "\0\0\0\0JUCE";
  8403. static const int safeEmptyStringRefCount = 0x3fffffff;
  8404. String::InternalRefCountedStringHolder String::emptyString = { safeEmptyStringRefCount, 0, { 0 } };
  8405. static tchar decimalPoint = T('.');
  8406. void juce_initialiseStrings()
  8407. {
  8408. decimalPoint = String::fromUTF8 ((const uint8*) localeconv()->decimal_point) [0];
  8409. }
  8410. void String::createInternal (const int numChars) throw()
  8411. {
  8412. jassert (numChars > 0);
  8413. text = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8414. + numChars * sizeof (tchar));
  8415. text->refCount = 1;
  8416. text->allocatedNumChars = numChars;
  8417. text->text[0] = 0;
  8418. }
  8419. void String::createInternal (const tchar* const t, const tchar* const textEnd) throw()
  8420. {
  8421. jassert (*(textEnd - 1) == 0); // must have a null terminator
  8422. const int numChars = (int) (textEnd - t);
  8423. createInternal (numChars - 1);
  8424. memcpy (text->text, t, numChars * sizeof (tchar));
  8425. }
  8426. void String::appendInternal (const tchar* const newText,
  8427. const int numExtraChars) throw()
  8428. {
  8429. if (numExtraChars > 0)
  8430. {
  8431. const int oldLen = CharacterFunctions::length (text->text);
  8432. const int newTotalLen = oldLen + numExtraChars;
  8433. if (text->refCount > 1)
  8434. {
  8435. // it's in use by other strings as well, so we need to make a private copy before messing with it..
  8436. InternalRefCountedStringHolder* const newTextHolder
  8437. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8438. + newTotalLen * sizeof (tchar));
  8439. newTextHolder->refCount = 1;
  8440. newTextHolder->allocatedNumChars = newTotalLen;
  8441. memcpy (newTextHolder->text, text->text, oldLen * sizeof (tchar));
  8442. memcpy (newTextHolder->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8443. InternalRefCountedStringHolder* const old = text;
  8444. text = newTextHolder;
  8445. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8446. juce_free (old);
  8447. }
  8448. else
  8449. {
  8450. // no other strings using it, so just expand it if needed..
  8451. if (newTotalLen > text->allocatedNumChars)
  8452. {
  8453. text = (InternalRefCountedStringHolder*)
  8454. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8455. + newTotalLen * sizeof (tchar));
  8456. text->allocatedNumChars = newTotalLen;
  8457. }
  8458. memcpy (text->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8459. }
  8460. text->text [newTotalLen] = 0;
  8461. }
  8462. }
  8463. void String::dupeInternalIfMultiplyReferenced() throw()
  8464. {
  8465. if (text->refCount > 1)
  8466. {
  8467. InternalRefCountedStringHolder* const old = text;
  8468. const int len = old->allocatedNumChars;
  8469. InternalRefCountedStringHolder* const newTextHolder
  8470. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8471. + len * sizeof (tchar));
  8472. newTextHolder->refCount = 1;
  8473. newTextHolder->allocatedNumChars = len;
  8474. memcpy (newTextHolder->text, old->text, (len + 1) * sizeof (tchar));
  8475. text = newTextHolder;
  8476. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8477. juce_free (old);
  8478. }
  8479. }
  8480. const String String::empty;
  8481. String::String() throw()
  8482. : text (&emptyString)
  8483. {
  8484. }
  8485. String::String (const String& other) throw()
  8486. : text (other.text)
  8487. {
  8488. Atomic::increment (text->refCount);
  8489. }
  8490. String::String (const int numChars,
  8491. const int /*dummyVariable*/) throw()
  8492. {
  8493. createInternal (numChars);
  8494. }
  8495. String::String (const char* const t) throw()
  8496. {
  8497. if (t != 0 && *t != 0)
  8498. {
  8499. const int len = CharacterFunctions::length (t);
  8500. createInternal (len);
  8501. #if JUCE_STRINGS_ARE_UNICODE
  8502. CharacterFunctions::copy (text->text, t, len + 1);
  8503. #else
  8504. memcpy (text->text, t, len + 1);
  8505. #endif
  8506. }
  8507. else
  8508. {
  8509. text = &emptyString;
  8510. emptyString.refCount = safeEmptyStringRefCount;
  8511. }
  8512. }
  8513. String::String (const juce_wchar* const t) throw()
  8514. {
  8515. if (t != 0 && *t != 0)
  8516. {
  8517. #if JUCE_STRINGS_ARE_UNICODE
  8518. const int len = CharacterFunctions::length (t);
  8519. createInternal (len);
  8520. memcpy (text->text, t, (len + 1) * sizeof (tchar));
  8521. #else
  8522. const int len = CharacterFunctions::bytesRequiredForCopy (t);
  8523. createInternal (len);
  8524. CharacterFunctions::copy (text->text, t, len + 1);
  8525. #endif
  8526. }
  8527. else
  8528. {
  8529. text = &emptyString;
  8530. emptyString.refCount = safeEmptyStringRefCount;
  8531. }
  8532. }
  8533. String::String (const char* const t,
  8534. const size_t maxChars) throw()
  8535. {
  8536. int i;
  8537. for (i = 0; (size_t) i < maxChars; ++i)
  8538. if (t[i] == 0)
  8539. break;
  8540. if (i > 0)
  8541. {
  8542. createInternal (i);
  8543. #if JUCE_STRINGS_ARE_UNICODE
  8544. CharacterFunctions::copy (text->text, t, i);
  8545. #else
  8546. memcpy (text->text, t, i);
  8547. #endif
  8548. text->text [i] = 0;
  8549. }
  8550. else
  8551. {
  8552. text = &emptyString;
  8553. emptyString.refCount = safeEmptyStringRefCount;
  8554. }
  8555. }
  8556. String::String (const juce_wchar* const t,
  8557. const size_t maxChars) throw()
  8558. {
  8559. int i;
  8560. for (i = 0; (size_t) i < maxChars; ++i)
  8561. if (t[i] == 0)
  8562. break;
  8563. if (i > 0)
  8564. {
  8565. createInternal (i);
  8566. #if JUCE_STRINGS_ARE_UNICODE
  8567. memcpy (text->text, t, i * sizeof (tchar));
  8568. #else
  8569. CharacterFunctions::copy (text->text, t, i);
  8570. #endif
  8571. text->text [i] = 0;
  8572. }
  8573. else
  8574. {
  8575. text = &emptyString;
  8576. emptyString.refCount = safeEmptyStringRefCount;
  8577. }
  8578. }
  8579. const String String::charToString (const tchar character) throw()
  8580. {
  8581. tchar temp[2];
  8582. temp[0] = character;
  8583. temp[1] = 0;
  8584. return String (temp);
  8585. }
  8586. // pass in a pointer to the END of a buffer..
  8587. static tchar* int64ToCharString (tchar* t, const int64 n) throw()
  8588. {
  8589. *--t = 0;
  8590. int64 v = (n >= 0) ? n : -n;
  8591. do
  8592. {
  8593. *--t = (tchar) (T('0') + (int) (v % 10));
  8594. v /= 10;
  8595. } while (v > 0);
  8596. if (n < 0)
  8597. *--t = T('-');
  8598. return t;
  8599. }
  8600. static tchar* intToCharString (tchar* t, const int n) throw()
  8601. {
  8602. if (n == (int) 0x80000000) // (would cause an overflow)
  8603. return int64ToCharString (t, n);
  8604. *--t = 0;
  8605. int v = abs (n);
  8606. do
  8607. {
  8608. *--t = (tchar) (T('0') + (v % 10));
  8609. v /= 10;
  8610. } while (v > 0);
  8611. if (n < 0)
  8612. *--t = T('-');
  8613. return t;
  8614. }
  8615. static tchar* uintToCharString (tchar* t, unsigned int v) throw()
  8616. {
  8617. *--t = 0;
  8618. do
  8619. {
  8620. *--t = (tchar) (T('0') + (v % 10));
  8621. v /= 10;
  8622. } while (v > 0);
  8623. return t;
  8624. }
  8625. String::String (const int number) throw()
  8626. {
  8627. tchar buffer [16];
  8628. tchar* const end = buffer + 16;
  8629. createInternal (intToCharString (end, number), end);
  8630. }
  8631. String::String (const unsigned int number) throw()
  8632. {
  8633. tchar buffer [16];
  8634. tchar* const end = buffer + 16;
  8635. createInternal (uintToCharString (end, number), end);
  8636. }
  8637. String::String (const short number) throw()
  8638. {
  8639. tchar buffer [16];
  8640. tchar* const end = buffer + 16;
  8641. createInternal (intToCharString (end, (int) number), end);
  8642. }
  8643. String::String (const unsigned short number) throw()
  8644. {
  8645. tchar buffer [16];
  8646. tchar* const end = buffer + 16;
  8647. createInternal (uintToCharString (end, (unsigned int) number), end);
  8648. }
  8649. String::String (const int64 number) throw()
  8650. {
  8651. tchar buffer [32];
  8652. tchar* const end = buffer + 32;
  8653. createInternal (int64ToCharString (end, number), end);
  8654. }
  8655. String::String (const uint64 number) throw()
  8656. {
  8657. tchar buffer [32];
  8658. tchar* const end = buffer + 32;
  8659. tchar* t = end;
  8660. *--t = 0;
  8661. int64 v = number;
  8662. do
  8663. {
  8664. *--t = (tchar) (T('0') + (int) (v % 10));
  8665. v /= 10;
  8666. } while (v > 0);
  8667. createInternal (t, end);
  8668. }
  8669. // a double-to-string routine that actually uses the number of dec. places you asked for
  8670. // without resorting to exponent notation if the number's too big or small (which is what printf does).
  8671. void String::doubleToStringWithDecPlaces (double n, int numDecPlaces) throw()
  8672. {
  8673. const int bufSize = 80;
  8674. tchar buffer [bufSize];
  8675. int len;
  8676. tchar* t;
  8677. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8678. {
  8679. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8680. t = buffer + bufSize;
  8681. *--t = (tchar) 0;
  8682. while (numDecPlaces >= 0 || v > 0)
  8683. {
  8684. if (numDecPlaces == 0)
  8685. *--t = decimalPoint;
  8686. *--t = (tchar) (T('0') + (v % 10));
  8687. v /= 10;
  8688. --numDecPlaces;
  8689. }
  8690. if (n < 0)
  8691. *--t = T('-');
  8692. len = (int) ((buffer + bufSize) - t);
  8693. }
  8694. else
  8695. {
  8696. len = CharacterFunctions::printf (buffer, bufSize, T("%.9g"), n) + 1;
  8697. t = buffer;
  8698. }
  8699. if (len > 1)
  8700. {
  8701. jassert (len < numElementsInArray (buffer));
  8702. createInternal (len - 1);
  8703. memcpy (text->text, t, len * sizeof (tchar));
  8704. }
  8705. else
  8706. {
  8707. jassert (*t == 0);
  8708. text = &emptyString;
  8709. emptyString.refCount = safeEmptyStringRefCount;
  8710. }
  8711. }
  8712. String::String (const float number,
  8713. const int numberOfDecimalPlaces) throw()
  8714. {
  8715. doubleToStringWithDecPlaces ((double) number,
  8716. numberOfDecimalPlaces);
  8717. }
  8718. String::String (const double number,
  8719. const int numberOfDecimalPlaces) throw()
  8720. {
  8721. doubleToStringWithDecPlaces (number,
  8722. numberOfDecimalPlaces);
  8723. }
  8724. String::~String() throw()
  8725. {
  8726. emptyString.refCount = safeEmptyStringRefCount;
  8727. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8728. juce_free (text);
  8729. }
  8730. void String::preallocateStorage (const size_t numChars) throw()
  8731. {
  8732. if (numChars > (size_t) text->allocatedNumChars)
  8733. {
  8734. dupeInternalIfMultiplyReferenced();
  8735. text = (InternalRefCountedStringHolder*) juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8736. + numChars * sizeof (tchar));
  8737. text->allocatedNumChars = (int) numChars;
  8738. }
  8739. }
  8740. #if JUCE_STRINGS_ARE_UNICODE
  8741. String::operator const char*() const throw()
  8742. {
  8743. if (isEmpty())
  8744. {
  8745. return (const char*) emptyCharString;
  8746. }
  8747. else
  8748. {
  8749. String* const mutableThis = const_cast <String*> (this);
  8750. mutableThis->dupeInternalIfMultiplyReferenced();
  8751. int len = CharacterFunctions::bytesRequiredForCopy (text->text) + 1;
  8752. mutableThis->text = (InternalRefCountedStringHolder*)
  8753. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8754. + (len * sizeof (juce_wchar) + len));
  8755. char* otherCopy = (char*) (text->text + len);
  8756. --len;
  8757. CharacterFunctions::copy (otherCopy, text->text, len);
  8758. otherCopy [len] = 0;
  8759. return otherCopy;
  8760. }
  8761. }
  8762. #else
  8763. String::operator const juce_wchar*() const throw()
  8764. {
  8765. if (isEmpty())
  8766. {
  8767. return (const juce_wchar*) emptyCharString;
  8768. }
  8769. else
  8770. {
  8771. String* const mutableThis = const_cast <String*> (this);
  8772. mutableThis->dupeInternalIfMultiplyReferenced();
  8773. int len = CharacterFunctions::length (text->text) + 1;
  8774. mutableThis->text = (InternalRefCountedStringHolder*)
  8775. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8776. + (len * sizeof (juce_wchar) + len));
  8777. juce_wchar* otherCopy = (juce_wchar*) (text->text + len);
  8778. --len;
  8779. CharacterFunctions::copy (otherCopy, text->text, len);
  8780. otherCopy [len] = 0;
  8781. return otherCopy;
  8782. }
  8783. }
  8784. #endif
  8785. void String::copyToBuffer (char* const destBuffer,
  8786. const int bufferSizeBytes) const throw()
  8787. {
  8788. #if JUCE_STRINGS_ARE_UNICODE
  8789. const int len = jmin (bufferSizeBytes, CharacterFunctions::bytesRequiredForCopy (text->text));
  8790. CharacterFunctions::copy (destBuffer, text->text, len);
  8791. #else
  8792. const int len = jmin (bufferSizeBytes, length());
  8793. memcpy (destBuffer, text->text, len * sizeof (tchar));
  8794. #endif
  8795. destBuffer [len] = 0;
  8796. }
  8797. void String::copyToBuffer (juce_wchar* const destBuffer,
  8798. const int maxCharsToCopy) const throw()
  8799. {
  8800. const int len = jmin (maxCharsToCopy, length());
  8801. #if JUCE_STRINGS_ARE_UNICODE
  8802. memcpy (destBuffer, text->text, len * sizeof (juce_wchar));
  8803. #else
  8804. CharacterFunctions::copy (destBuffer, text->text, len);
  8805. #endif
  8806. destBuffer [len] = 0;
  8807. }
  8808. int String::length() const throw()
  8809. {
  8810. return CharacterFunctions::length (text->text);
  8811. }
  8812. int String::hashCode() const throw()
  8813. {
  8814. const tchar* t = text->text;
  8815. int result = 0;
  8816. while (*t != (tchar) 0)
  8817. result = 31 * result + *t++;
  8818. return result;
  8819. }
  8820. int64 String::hashCode64() const throw()
  8821. {
  8822. const tchar* t = text->text;
  8823. int64 result = 0;
  8824. while (*t != (tchar) 0)
  8825. result = 101 * result + *t++;
  8826. return result;
  8827. }
  8828. const String& String::operator= (const tchar* const otherText) throw()
  8829. {
  8830. operator= (String (otherText));
  8831. return *this;
  8832. }
  8833. const String& String::operator= (const String& other) throw()
  8834. {
  8835. if (this != &other)
  8836. {
  8837. InternalRefCountedStringHolder* newText = other.text;
  8838. Atomic::increment (newText->refCount);
  8839. InternalRefCountedStringHolder* oldText
  8840. = (InternalRefCountedStringHolder*) Atomic::swapPointers ((void* volatile*) &text, newText);
  8841. if (Atomic::decrementAndReturn (oldText->refCount) == 0)
  8842. juce_free (oldText);
  8843. }
  8844. return *this;
  8845. }
  8846. bool String::operator== (const String& other) const throw()
  8847. {
  8848. return text == other.text
  8849. || CharacterFunctions::compare (text->text, other.text->text) == 0;
  8850. }
  8851. bool String::operator== (const tchar* const t) const throw()
  8852. {
  8853. return t != 0 ? CharacterFunctions::compare (text->text, t) == 0
  8854. : isEmpty();
  8855. }
  8856. bool String::equalsIgnoreCase (const tchar* t) const throw()
  8857. {
  8858. return t != 0 ? CharacterFunctions::compareIgnoreCase (text->text, t) == 0
  8859. : isEmpty();
  8860. }
  8861. bool String::equalsIgnoreCase (const String& other) const throw()
  8862. {
  8863. return text == other.text
  8864. || CharacterFunctions::compareIgnoreCase (text->text, other.text->text) == 0;
  8865. }
  8866. bool String::operator!= (const String& other) const throw()
  8867. {
  8868. return text != other.text
  8869. && CharacterFunctions::compare (text->text, other.text->text) != 0;
  8870. }
  8871. bool String::operator!= (const tchar* const t) const throw()
  8872. {
  8873. return t != 0 ? (CharacterFunctions::compare (text->text, t) != 0)
  8874. : isNotEmpty();
  8875. }
  8876. bool String::operator> (const String& other) const throw()
  8877. {
  8878. return compare (other) > 0;
  8879. }
  8880. bool String::operator< (const tchar* const other) const throw()
  8881. {
  8882. return compare (other) < 0;
  8883. }
  8884. bool String::operator>= (const String& other) const throw()
  8885. {
  8886. return compare (other) >= 0;
  8887. }
  8888. bool String::operator<= (const tchar* const other) const throw()
  8889. {
  8890. return compare (other) <= 0;
  8891. }
  8892. int String::compare (const tchar* const other) const throw()
  8893. {
  8894. return other != 0 ? CharacterFunctions::compare (text->text, other)
  8895. : isEmpty();
  8896. }
  8897. int String::compareIgnoreCase (const tchar* const other) const throw()
  8898. {
  8899. return other != 0 ? CharacterFunctions::compareIgnoreCase (text->text, other)
  8900. : isEmpty();
  8901. }
  8902. int String::compareLexicographically (const tchar* other) const throw()
  8903. {
  8904. if (other == 0)
  8905. return isEmpty();
  8906. const tchar* s1 = text->text;
  8907. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8908. ++s1;
  8909. while (*other != 0 && ! CharacterFunctions::isLetterOrDigit (*other))
  8910. ++other;
  8911. return CharacterFunctions::compareIgnoreCase (s1, other);
  8912. }
  8913. const String String::operator+ (const String& other) const throw()
  8914. {
  8915. if (*(other.text->text) == 0)
  8916. return *this;
  8917. if (isEmpty())
  8918. return other;
  8919. const int len = CharacterFunctions::length (text->text);
  8920. const int otherLen = CharacterFunctions::length (other.text->text);
  8921. String result (len + otherLen, (int) 0);
  8922. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8923. memcpy (result.text->text + len, other.text->text, otherLen * sizeof (tchar));
  8924. result.text->text [len + otherLen] = 0;
  8925. return result;
  8926. }
  8927. const String String::operator+ (const tchar* const textToAppend) const throw()
  8928. {
  8929. if (textToAppend == 0 || *textToAppend == 0)
  8930. return *this;
  8931. const int len = CharacterFunctions::length (text->text);
  8932. const int otherLen = CharacterFunctions::length (textToAppend);
  8933. String result (len + otherLen, (int) 0);
  8934. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8935. memcpy (result.text->text + len, textToAppend, otherLen * sizeof (tchar));
  8936. result.text->text [len + otherLen] = 0;
  8937. return result;
  8938. }
  8939. const String String::operator+ (const tchar characterToAppend) const throw()
  8940. {
  8941. if (characterToAppend == 0)
  8942. return *this;
  8943. const int len = CharacterFunctions::length (text->text);
  8944. String result ((int) (len + 1), (int) 0);
  8945. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8946. result.text->text[len] = characterToAppend;
  8947. result.text->text[len + 1] = 0;
  8948. return result;
  8949. }
  8950. const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1,
  8951. const String& string2) throw()
  8952. {
  8953. String s (string1);
  8954. s += string2;
  8955. return s;
  8956. }
  8957. const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1,
  8958. const String& string2) throw()
  8959. {
  8960. String s (string1);
  8961. s += string2;
  8962. return s;
  8963. }
  8964. const String& String::operator+= (const tchar* const t) throw()
  8965. {
  8966. if (t != 0)
  8967. appendInternal (t, CharacterFunctions::length (t));
  8968. return *this;
  8969. }
  8970. const String& String::operator+= (const String& other) throw()
  8971. {
  8972. if (isEmpty())
  8973. operator= (other);
  8974. else
  8975. appendInternal (other.text->text,
  8976. CharacterFunctions::length (other.text->text));
  8977. return *this;
  8978. }
  8979. const String& String::operator+= (const char ch) throw()
  8980. {
  8981. char asString[2];
  8982. asString[0] = ch;
  8983. asString[1] = 0;
  8984. #if JUCE_STRINGS_ARE_UNICODE
  8985. operator+= (String (asString));
  8986. #else
  8987. appendInternal (asString, 1);
  8988. #endif
  8989. return *this;
  8990. }
  8991. const String& String::operator+= (const juce_wchar ch) throw()
  8992. {
  8993. juce_wchar asString[2];
  8994. asString[0] = ch;
  8995. asString[1] = 0;
  8996. #if JUCE_STRINGS_ARE_UNICODE
  8997. appendInternal (asString, 1);
  8998. #else
  8999. operator+= (String (asString));
  9000. #endif
  9001. return *this;
  9002. }
  9003. void String::append (const tchar* const other,
  9004. const int howMany) throw()
  9005. {
  9006. if (howMany > 0)
  9007. {
  9008. int i;
  9009. for (i = 0; i < howMany; ++i)
  9010. if (other[i] == 0)
  9011. break;
  9012. appendInternal (other, i);
  9013. }
  9014. }
  9015. String& String::operator<< (const int number) throw()
  9016. {
  9017. tchar buffer [64];
  9018. tchar* const end = buffer + 64;
  9019. const tchar* const t = intToCharString (end, number);
  9020. appendInternal (t, (int) (end - t) - 1);
  9021. return *this;
  9022. }
  9023. String& String::operator<< (const unsigned int number) throw()
  9024. {
  9025. tchar buffer [64];
  9026. tchar* const end = buffer + 64;
  9027. const tchar* const t = uintToCharString (end, number);
  9028. appendInternal (t, (int) (end - t) - 1);
  9029. return *this;
  9030. }
  9031. String& String::operator<< (const short number) throw()
  9032. {
  9033. tchar buffer [64];
  9034. tchar* const end = buffer + 64;
  9035. const tchar* const t = intToCharString (end, (int) number);
  9036. appendInternal (t, (int) (end - t) - 1);
  9037. return *this;
  9038. }
  9039. String& String::operator<< (const long number) throw()
  9040. {
  9041. return operator<< ((int) number);
  9042. }
  9043. String& String::operator<< (const unsigned long number) throw()
  9044. {
  9045. return operator<< ((unsigned int) number);
  9046. }
  9047. String& String::operator<< (const double number) throw()
  9048. {
  9049. operator+= (String (number));
  9050. return *this;
  9051. }
  9052. String& String::operator<< (const float number) throw()
  9053. {
  9054. operator+= (String (number));
  9055. return *this;
  9056. }
  9057. String& String::operator<< (const char character) throw()
  9058. {
  9059. operator+= (character);
  9060. return *this;
  9061. }
  9062. String& String::operator<< (const juce_wchar character) throw()
  9063. {
  9064. operator+= (character);
  9065. return *this;
  9066. }
  9067. String& String::operator<< (const char* const t) throw()
  9068. {
  9069. #if JUCE_STRINGS_ARE_UNICODE
  9070. operator+= (String (t));
  9071. #else
  9072. operator+= (t);
  9073. #endif
  9074. return *this;
  9075. }
  9076. String& String::operator<< (const juce_wchar* const t) throw()
  9077. {
  9078. #if JUCE_STRINGS_ARE_UNICODE
  9079. operator+= (t);
  9080. #else
  9081. operator+= (String (t));
  9082. #endif
  9083. return *this;
  9084. }
  9085. String& String::operator<< (const String& t) throw()
  9086. {
  9087. operator+= (t);
  9088. return *this;
  9089. }
  9090. int String::indexOfChar (const tchar character) const throw()
  9091. {
  9092. const tchar* t = text->text;
  9093. for (;;)
  9094. {
  9095. if (*t == character)
  9096. return (int) (t - text->text);
  9097. if (*t++ == 0)
  9098. return -1;
  9099. }
  9100. }
  9101. int String::lastIndexOfChar (const tchar character) const throw()
  9102. {
  9103. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9104. if (text->text[i] == character)
  9105. return i;
  9106. return -1;
  9107. }
  9108. int String::indexOf (const tchar* const t) const throw()
  9109. {
  9110. const tchar* const r = CharacterFunctions::find (text->text, t);
  9111. return (r == 0) ? -1
  9112. : (int) (r - text->text);
  9113. }
  9114. int String::indexOfChar (const int startIndex,
  9115. const tchar character) const throw()
  9116. {
  9117. if (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text))
  9118. return -1;
  9119. const tchar* t = text->text + jmax (0, startIndex);
  9120. for (;;)
  9121. {
  9122. if (*t == character)
  9123. return (int) (t - text->text);
  9124. if (*t++ == 0)
  9125. return -1;
  9126. }
  9127. }
  9128. int String::indexOfAnyOf (const tchar* const charactersToLookFor,
  9129. const int startIndex,
  9130. const bool ignoreCase) const throw()
  9131. {
  9132. if (charactersToLookFor == 0
  9133. || (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text)))
  9134. return -1;
  9135. const tchar* t = text->text + jmax (0, startIndex);
  9136. while (*t != 0)
  9137. {
  9138. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  9139. return (int) (t - text->text);
  9140. ++t;
  9141. }
  9142. return -1;
  9143. }
  9144. int String::indexOf (const int startIndex,
  9145. const tchar* const other) const throw()
  9146. {
  9147. if (other == 0 || startIndex >= CharacterFunctions::length (text->text))
  9148. return -1;
  9149. const tchar* const found = CharacterFunctions::find (text->text + jmax (0, startIndex),
  9150. other);
  9151. return (found == 0) ? -1
  9152. : (int) (found - text->text);
  9153. }
  9154. int String::indexOfIgnoreCase (const tchar* const other) const throw()
  9155. {
  9156. if (other != 0 && *other != 0)
  9157. {
  9158. const int len = CharacterFunctions::length (other);
  9159. const int end = CharacterFunctions::length (text->text) - len;
  9160. for (int i = 0; i <= end; ++i)
  9161. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9162. return i;
  9163. }
  9164. return -1;
  9165. }
  9166. int String::indexOfIgnoreCase (const int startIndex,
  9167. const tchar* const other) const throw()
  9168. {
  9169. if (other != 0 && *other != 0)
  9170. {
  9171. const int len = CharacterFunctions::length (other);
  9172. const int end = length() - len;
  9173. for (int i = jmax (0, startIndex); i <= end; ++i)
  9174. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9175. return i;
  9176. }
  9177. return -1;
  9178. }
  9179. int String::lastIndexOf (const tchar* const other) const throw()
  9180. {
  9181. if (other != 0 && *other != 0)
  9182. {
  9183. const int len = CharacterFunctions::length (other);
  9184. int i = length() - len;
  9185. if (i >= 0)
  9186. {
  9187. const tchar* n = text->text + i;
  9188. while (i >= 0)
  9189. {
  9190. if (CharacterFunctions::compare (n--, other, len) == 0)
  9191. return i;
  9192. --i;
  9193. }
  9194. }
  9195. }
  9196. return -1;
  9197. }
  9198. int String::lastIndexOfIgnoreCase (const tchar* const other) const throw()
  9199. {
  9200. if (other != 0 && *other != 0)
  9201. {
  9202. const int len = CharacterFunctions::length (other);
  9203. int i = length() - len;
  9204. if (i >= 0)
  9205. {
  9206. const tchar* n = text->text + i;
  9207. while (i >= 0)
  9208. {
  9209. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  9210. return i;
  9211. --i;
  9212. }
  9213. }
  9214. }
  9215. return -1;
  9216. }
  9217. int String::lastIndexOfAnyOf (const tchar* const charactersToLookFor,
  9218. const bool ignoreCase) const throw()
  9219. {
  9220. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9221. if (CharacterFunctions::indexOfChar (charactersToLookFor, text->text [i], ignoreCase) >= 0)
  9222. return i;
  9223. return -1;
  9224. }
  9225. bool String::contains (const tchar* const other) const throw()
  9226. {
  9227. return indexOf (other) >= 0;
  9228. }
  9229. bool String::containsChar (const tchar character) const throw()
  9230. {
  9231. return indexOfChar (character) >= 0;
  9232. }
  9233. bool String::containsIgnoreCase (const tchar* const t) const throw()
  9234. {
  9235. return indexOfIgnoreCase (t) >= 0;
  9236. }
  9237. int String::indexOfWholeWord (const tchar* const word) const throw()
  9238. {
  9239. if (word != 0 && *word != 0)
  9240. {
  9241. const int wordLen = CharacterFunctions::length (word);
  9242. const int end = length() - wordLen;
  9243. const tchar* t = text->text;
  9244. for (int i = 0; i <= end; ++i)
  9245. {
  9246. if (CharacterFunctions::compare (t, word, wordLen) == 0
  9247. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9248. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9249. {
  9250. return i;
  9251. }
  9252. ++t;
  9253. }
  9254. }
  9255. return -1;
  9256. }
  9257. int String::indexOfWholeWordIgnoreCase (const tchar* const word) const throw()
  9258. {
  9259. if (word != 0 && *word != 0)
  9260. {
  9261. const int wordLen = CharacterFunctions::length (word);
  9262. const int end = length() - wordLen;
  9263. const tchar* t = text->text;
  9264. for (int i = 0; i <= end; ++i)
  9265. {
  9266. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  9267. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9268. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9269. {
  9270. return i;
  9271. }
  9272. ++t;
  9273. }
  9274. }
  9275. return -1;
  9276. }
  9277. bool String::containsWholeWord (const tchar* const wordToLookFor) const throw()
  9278. {
  9279. return indexOfWholeWord (wordToLookFor) >= 0;
  9280. }
  9281. bool String::containsWholeWordIgnoreCase (const tchar* const wordToLookFor) const throw()
  9282. {
  9283. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9284. }
  9285. static int indexOfMatch (const tchar* const wildcard,
  9286. const tchar* const test,
  9287. const bool ignoreCase) throw()
  9288. {
  9289. int start = 0;
  9290. while (test [start] != 0)
  9291. {
  9292. int i = 0;
  9293. for (;;)
  9294. {
  9295. const tchar wc = wildcard [i];
  9296. const tchar c = test [i + start];
  9297. if (wc == c
  9298. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9299. || (wc == T('?') && c != 0))
  9300. {
  9301. if (wc == 0)
  9302. return start;
  9303. ++i;
  9304. }
  9305. else
  9306. {
  9307. if (wc == T('*') && (wildcard [i + 1] == 0
  9308. || indexOfMatch (wildcard + i + 1,
  9309. test + start + i,
  9310. ignoreCase) >= 0))
  9311. {
  9312. return start;
  9313. }
  9314. break;
  9315. }
  9316. }
  9317. ++start;
  9318. }
  9319. return -1;
  9320. }
  9321. bool String::matchesWildcard (const tchar* wildcard, const bool ignoreCase) const throw()
  9322. {
  9323. int i = 0;
  9324. for (;;)
  9325. {
  9326. const tchar wc = wildcard [i];
  9327. const tchar c = text->text [i];
  9328. if (wc == c
  9329. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9330. || (wc == T('?') && c != 0))
  9331. {
  9332. if (wc == 0)
  9333. return true;
  9334. ++i;
  9335. }
  9336. else
  9337. {
  9338. return wc == T('*') && (wildcard [i + 1] == 0
  9339. || indexOfMatch (wildcard + i + 1,
  9340. text->text + i,
  9341. ignoreCase) >= 0);
  9342. }
  9343. }
  9344. }
  9345. void String::printf (const tchar* const pf, ...) throw()
  9346. {
  9347. va_list list;
  9348. va_start (list, pf);
  9349. vprintf (pf, list);
  9350. }
  9351. const String String::formatted (const tchar* const pf, ...) throw()
  9352. {
  9353. va_list list;
  9354. va_start (list, pf);
  9355. String result;
  9356. result.vprintf (pf, list);
  9357. return result;
  9358. }
  9359. void String::vprintf (const tchar* const pf, va_list& args) throw()
  9360. {
  9361. int bufferSize = 256;
  9362. String result (bufferSize, 0);
  9363. do
  9364. {
  9365. #if JUCE_LINUX && JUCE_64BIT
  9366. va_list tempArgs;
  9367. va_copy (tempArgs, args);
  9368. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, tempArgs);
  9369. va_end (tempArgs);
  9370. #else
  9371. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, args);
  9372. #endif
  9373. if (num > 0)
  9374. {
  9375. *this = result;
  9376. break;
  9377. }
  9378. else if (num == 0)
  9379. {
  9380. *this = String::empty;
  9381. break;
  9382. }
  9383. bufferSize += 256;
  9384. result.preallocateStorage (bufferSize);
  9385. }
  9386. while (bufferSize < 65536); // this is a sanity check to avoid situations where vprintf repeatedly
  9387. // returns -1 because of an error rather than because it needs more space.
  9388. }
  9389. const String String::repeatedString (const tchar* const stringToRepeat,
  9390. int numberOfTimesToRepeat) throw()
  9391. {
  9392. const int len = CharacterFunctions::length (stringToRepeat);
  9393. String result ((int) (len * numberOfTimesToRepeat + 1), (int) 0);
  9394. tchar* n = result.text->text;
  9395. n[0] = 0;
  9396. while (--numberOfTimesToRepeat >= 0)
  9397. {
  9398. CharacterFunctions::append (n, stringToRepeat);
  9399. n += len;
  9400. }
  9401. return result;
  9402. }
  9403. const String String::replaceSection (int index,
  9404. int numCharsToReplace,
  9405. const tchar* const stringToInsert) const throw()
  9406. {
  9407. if (index < 0)
  9408. {
  9409. // a negative index to replace from?
  9410. jassertfalse
  9411. index = 0;
  9412. }
  9413. if (numCharsToReplace < 0)
  9414. {
  9415. // replacing a negative number of characters?
  9416. numCharsToReplace = 0;
  9417. jassertfalse;
  9418. }
  9419. const int len = length();
  9420. if (index + numCharsToReplace > len)
  9421. {
  9422. if (index > len)
  9423. {
  9424. // replacing beyond the end of the string?
  9425. index = len;
  9426. jassertfalse
  9427. }
  9428. numCharsToReplace = len - index;
  9429. }
  9430. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9431. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9432. if (newTotalLen <= 0)
  9433. return String::empty;
  9434. String result (newTotalLen, (int) 0);
  9435. memcpy (result.text->text,
  9436. text->text,
  9437. index * sizeof (tchar));
  9438. if (newStringLen > 0)
  9439. memcpy (result.text->text + index,
  9440. stringToInsert,
  9441. newStringLen * sizeof (tchar));
  9442. const int endStringLen = newTotalLen - (index + newStringLen);
  9443. if (endStringLen > 0)
  9444. memcpy (result.text->text + (index + newStringLen),
  9445. text->text + (index + numCharsToReplace),
  9446. endStringLen * sizeof (tchar));
  9447. result.text->text [newTotalLen] = 0;
  9448. return result;
  9449. }
  9450. const String String::replace (const tchar* const stringToReplace,
  9451. const tchar* const stringToInsert,
  9452. const bool ignoreCase) const throw()
  9453. {
  9454. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9455. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9456. int i = 0;
  9457. String result (*this);
  9458. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9459. : result.indexOf (i, stringToReplace))) >= 0)
  9460. {
  9461. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9462. i += stringToInsertLen;
  9463. }
  9464. return result;
  9465. }
  9466. const String String::replaceCharacter (const tchar charToReplace,
  9467. const tchar charToInsert) const throw()
  9468. {
  9469. const int index = indexOfChar (charToReplace);
  9470. if (index < 0)
  9471. return *this;
  9472. String result (*this);
  9473. result.dupeInternalIfMultiplyReferenced();
  9474. tchar* t = result.text->text + index;
  9475. while (*t != 0)
  9476. {
  9477. if (*t == charToReplace)
  9478. *t = charToInsert;
  9479. ++t;
  9480. }
  9481. return result;
  9482. }
  9483. const String String::replaceCharacters (const String& charactersToReplace,
  9484. const tchar* const charactersToInsertInstead) const throw()
  9485. {
  9486. String result (*this);
  9487. result.dupeInternalIfMultiplyReferenced();
  9488. tchar* t = result.text->text;
  9489. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9490. // the two strings passed in are supposed to be the same length!
  9491. jassert (len2 == charactersToReplace.length());
  9492. while (*t != 0)
  9493. {
  9494. const int index = charactersToReplace.indexOfChar (*t);
  9495. if (((unsigned int) index) < (unsigned int) len2)
  9496. *t = charactersToInsertInstead [index];
  9497. ++t;
  9498. }
  9499. return result;
  9500. }
  9501. bool String::startsWith (const tchar* const other) const throw()
  9502. {
  9503. return other != 0
  9504. && CharacterFunctions::compare (text->text, other, CharacterFunctions::length (other)) == 0;
  9505. }
  9506. bool String::startsWithIgnoreCase (const tchar* const other) const throw()
  9507. {
  9508. return other != 0
  9509. && CharacterFunctions::compareIgnoreCase (text->text, other, CharacterFunctions::length (other)) == 0;
  9510. }
  9511. bool String::startsWithChar (const tchar character) const throw()
  9512. {
  9513. jassert (character != 0); // strings can't contain a null character!
  9514. return text->text[0] == character;
  9515. }
  9516. bool String::endsWithChar (const tchar character) const throw()
  9517. {
  9518. jassert (character != 0); // strings can't contain a null character!
  9519. return text->text[0] != 0
  9520. && text->text [length() - 1] == character;
  9521. }
  9522. bool String::endsWith (const tchar* const other) const throw()
  9523. {
  9524. if (other == 0)
  9525. return false;
  9526. const int thisLen = length();
  9527. const int otherLen = CharacterFunctions::length (other);
  9528. return thisLen >= otherLen
  9529. && CharacterFunctions::compare (text->text + thisLen - otherLen, other) == 0;
  9530. }
  9531. bool String::endsWithIgnoreCase (const tchar* const other) const throw()
  9532. {
  9533. if (other == 0)
  9534. return false;
  9535. const int thisLen = length();
  9536. const int otherLen = CharacterFunctions::length (other);
  9537. return thisLen >= otherLen
  9538. && CharacterFunctions::compareIgnoreCase (text->text + thisLen - otherLen, other) == 0;
  9539. }
  9540. const String String::toUpperCase() const throw()
  9541. {
  9542. String result (*this);
  9543. result.dupeInternalIfMultiplyReferenced();
  9544. CharacterFunctions::toUpperCase (result.text->text);
  9545. return result;
  9546. }
  9547. const String String::toLowerCase() const throw()
  9548. {
  9549. String result (*this);
  9550. result.dupeInternalIfMultiplyReferenced();
  9551. CharacterFunctions::toLowerCase (result.text->text);
  9552. return result;
  9553. }
  9554. tchar& String::operator[] (const int index) throw()
  9555. {
  9556. jassert (((unsigned int) index) <= (unsigned int) length());
  9557. dupeInternalIfMultiplyReferenced();
  9558. return text->text [index];
  9559. }
  9560. tchar String::getLastCharacter() const throw()
  9561. {
  9562. return (isEmpty()) ? ((tchar) 0)
  9563. : text->text [CharacterFunctions::length (text->text) - 1];
  9564. }
  9565. const String String::substring (int start, int end) const throw()
  9566. {
  9567. if (start < 0)
  9568. start = 0;
  9569. else if (end <= start)
  9570. return empty;
  9571. int len = 0;
  9572. const tchar* const t = text->text;
  9573. while (len <= end && t [len] != 0)
  9574. ++len;
  9575. if (end >= len)
  9576. {
  9577. if (start == 0)
  9578. return *this;
  9579. end = len;
  9580. }
  9581. return String (text->text + start,
  9582. end - start);
  9583. }
  9584. const String String::substring (const int start) const throw()
  9585. {
  9586. if (start <= 0)
  9587. return *this;
  9588. const int len = CharacterFunctions::length (text->text);
  9589. if (start >= len)
  9590. return empty;
  9591. else
  9592. return String (text->text + start,
  9593. len - start);
  9594. }
  9595. const String String::dropLastCharacters (const int numberToDrop) const throw()
  9596. {
  9597. return String (text->text,
  9598. jmax (0, CharacterFunctions::length (text->text) - numberToDrop));
  9599. }
  9600. const String String::getLastCharacters (const int numCharacters) const throw()
  9601. {
  9602. return String (text->text + jmax (0, CharacterFunctions::length (text->text) - jmax (0, numCharacters)));
  9603. }
  9604. const String String::fromFirstOccurrenceOf (const tchar* const sub,
  9605. const bool includeSubString,
  9606. const bool ignoreCase) const throw()
  9607. {
  9608. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9609. : indexOf (sub);
  9610. if (i < 0)
  9611. return empty;
  9612. else
  9613. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9614. }
  9615. const String String::fromLastOccurrenceOf (const tchar* const sub,
  9616. const bool includeSubString,
  9617. const bool ignoreCase) const throw()
  9618. {
  9619. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9620. : lastIndexOf (sub);
  9621. if (i < 0)
  9622. return *this;
  9623. else
  9624. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9625. }
  9626. const String String::upToFirstOccurrenceOf (const tchar* const sub,
  9627. const bool includeSubString,
  9628. const bool ignoreCase) const throw()
  9629. {
  9630. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9631. : indexOf (sub);
  9632. if (i < 0)
  9633. return *this;
  9634. else
  9635. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9636. }
  9637. const String String::upToLastOccurrenceOf (const tchar* const sub,
  9638. const bool includeSubString,
  9639. const bool ignoreCase) const throw()
  9640. {
  9641. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9642. : lastIndexOf (sub);
  9643. if (i < 0)
  9644. return *this;
  9645. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9646. }
  9647. bool String::isQuotedString() const throw()
  9648. {
  9649. const String trimmed (trimStart());
  9650. return trimmed[0] == T('"')
  9651. || trimmed[0] == T('\'');
  9652. }
  9653. const String String::unquoted() const throw()
  9654. {
  9655. String s (*this);
  9656. if (s[0] == T('"') || s[0] == T('\''))
  9657. s = s.substring (1);
  9658. const int lastCharIndex = s.length() - 1;
  9659. if (lastCharIndex >= 0
  9660. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9661. s [lastCharIndex] = 0;
  9662. return s;
  9663. }
  9664. const String String::quoted (const tchar quoteCharacter) const throw()
  9665. {
  9666. if (isEmpty())
  9667. return charToString (quoteCharacter) + quoteCharacter;
  9668. String t (*this);
  9669. if (! t.startsWithChar (quoteCharacter))
  9670. t = charToString (quoteCharacter) + t;
  9671. if (! t.endsWithChar (quoteCharacter))
  9672. t += quoteCharacter;
  9673. return t;
  9674. }
  9675. const String String::trim() const throw()
  9676. {
  9677. if (isEmpty())
  9678. return empty;
  9679. int start = 0;
  9680. while (CharacterFunctions::isWhitespace (text->text [start]))
  9681. ++start;
  9682. const int len = CharacterFunctions::length (text->text);
  9683. int end = len - 1;
  9684. while ((end >= start) && CharacterFunctions::isWhitespace (text->text [end]))
  9685. --end;
  9686. ++end;
  9687. if (end <= start)
  9688. return empty;
  9689. else if (start > 0 || end < len)
  9690. return String (text->text + start, end - start);
  9691. else
  9692. return *this;
  9693. }
  9694. const String String::trimStart() const throw()
  9695. {
  9696. if (isEmpty())
  9697. return empty;
  9698. const tchar* t = text->text;
  9699. while (CharacterFunctions::isWhitespace (*t))
  9700. ++t;
  9701. if (t == text->text)
  9702. return *this;
  9703. else
  9704. return String (t);
  9705. }
  9706. const String String::trimEnd() const throw()
  9707. {
  9708. if (isEmpty())
  9709. return empty;
  9710. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9711. while ((endT >= text->text) && CharacterFunctions::isWhitespace (*endT))
  9712. --endT;
  9713. return String (text->text, (int) (++endT - text->text));
  9714. }
  9715. const String String::trimCharactersAtStart (const tchar* charactersToTrim) const throw()
  9716. {
  9717. jassert (charactersToTrim != 0);
  9718. if (isEmpty())
  9719. return empty;
  9720. const tchar* t = text->text;
  9721. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9722. ++t;
  9723. if (t == text->text)
  9724. return *this;
  9725. else
  9726. return String (t);
  9727. }
  9728. const String String::trimCharactersAtEnd (const tchar* charactersToTrim) const throw()
  9729. {
  9730. jassert (charactersToTrim != 0);
  9731. if (isEmpty())
  9732. return empty;
  9733. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9734. while ((endT >= text->text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9735. --endT;
  9736. return String (text->text, (int) (++endT - text->text));
  9737. }
  9738. const String String::retainCharacters (const tchar* const charactersToRetain) const throw()
  9739. {
  9740. jassert (charactersToRetain != 0);
  9741. if (isEmpty())
  9742. return empty;
  9743. String result (text->allocatedNumChars, (int) 0);
  9744. tchar* dst = result.text->text;
  9745. const tchar* src = text->text;
  9746. while (*src != 0)
  9747. {
  9748. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9749. *dst++ = *src;
  9750. ++src;
  9751. }
  9752. *dst = 0;
  9753. return result;
  9754. }
  9755. const String String::removeCharacters (const tchar* const charactersToRemove) const throw()
  9756. {
  9757. jassert (charactersToRemove != 0);
  9758. if (isEmpty())
  9759. return empty;
  9760. String result (text->allocatedNumChars, (int) 0);
  9761. tchar* dst = result.text->text;
  9762. const tchar* src = text->text;
  9763. while (*src != 0)
  9764. {
  9765. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9766. *dst++ = *src;
  9767. ++src;
  9768. }
  9769. *dst = 0;
  9770. return result;
  9771. }
  9772. const String String::initialSectionContainingOnly (const tchar* const permittedCharacters) const throw()
  9773. {
  9774. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text->text, permittedCharacters));
  9775. }
  9776. const String String::initialSectionNotContaining (const tchar* const charactersToStopAt) const throw()
  9777. {
  9778. jassert (charactersToStopAt != 0);
  9779. const tchar* const t = text->text;
  9780. int i = 0;
  9781. while (t[i] != 0)
  9782. {
  9783. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9784. return String (text->text, i);
  9785. ++i;
  9786. }
  9787. return empty;
  9788. }
  9789. bool String::containsOnly (const tchar* const chars) const throw()
  9790. {
  9791. jassert (chars != 0);
  9792. const tchar* t = text->text;
  9793. while (*t != 0)
  9794. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9795. return false;
  9796. return true;
  9797. }
  9798. bool String::containsAnyOf (const tchar* const chars) const throw()
  9799. {
  9800. jassert (chars != 0);
  9801. const tchar* t = text->text;
  9802. while (*t != 0)
  9803. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9804. return true;
  9805. return false;
  9806. }
  9807. bool String::containsNonWhitespaceChars() const throw()
  9808. {
  9809. const tchar* t = text->text;
  9810. while (*t != 0)
  9811. if (! CharacterFunctions::isWhitespace (*t++))
  9812. return true;
  9813. return false;
  9814. }
  9815. int String::getIntValue() const throw()
  9816. {
  9817. return CharacterFunctions::getIntValue (text->text);
  9818. }
  9819. int String::getTrailingIntValue() const throw()
  9820. {
  9821. int n = 0;
  9822. int mult = 1;
  9823. const tchar* t = text->text + length();
  9824. while (--t >= text->text)
  9825. {
  9826. const tchar c = *t;
  9827. if (! CharacterFunctions::isDigit (c))
  9828. {
  9829. if (c == T('-'))
  9830. n = -n;
  9831. break;
  9832. }
  9833. n += mult * (c - T('0'));
  9834. mult *= 10;
  9835. }
  9836. return n;
  9837. }
  9838. int64 String::getLargeIntValue() const throw()
  9839. {
  9840. return CharacterFunctions::getInt64Value (text->text);
  9841. }
  9842. float String::getFloatValue() const throw()
  9843. {
  9844. return (float) CharacterFunctions::getDoubleValue (text->text);
  9845. }
  9846. double String::getDoubleValue() const throw()
  9847. {
  9848. return CharacterFunctions::getDoubleValue (text->text);
  9849. }
  9850. static const tchar* const hexDigits = T("0123456789abcdef");
  9851. const String String::toHexString (const int number) throw()
  9852. {
  9853. tchar buffer[32];
  9854. tchar* const end = buffer + 32;
  9855. tchar* t = end;
  9856. *--t = 0;
  9857. unsigned int v = (unsigned int) number;
  9858. do
  9859. {
  9860. *--t = hexDigits [v & 15];
  9861. v >>= 4;
  9862. } while (v != 0);
  9863. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9864. }
  9865. const String String::toHexString (const int64 number) throw()
  9866. {
  9867. tchar buffer[32];
  9868. tchar* const end = buffer + 32;
  9869. tchar* t = end;
  9870. *--t = 0;
  9871. uint64 v = (uint64) number;
  9872. do
  9873. {
  9874. *--t = hexDigits [(int) (v & 15)];
  9875. v >>= 4;
  9876. } while (v != 0);
  9877. return String (t, (int) (((char*) end) - (char*) t));
  9878. }
  9879. const String String::toHexString (const short number) throw()
  9880. {
  9881. return toHexString ((int) (unsigned short) number);
  9882. }
  9883. const String String::toHexString (const unsigned char* data,
  9884. const int size,
  9885. const int groupSize) throw()
  9886. {
  9887. if (size <= 0)
  9888. return empty;
  9889. int numChars = (size * 2) + 2;
  9890. if (groupSize > 0)
  9891. numChars += size / groupSize;
  9892. String s (numChars, (int) 0);
  9893. tchar* d = s.text->text;
  9894. for (int i = 0; i < size; ++i)
  9895. {
  9896. *d++ = hexDigits [(*data) >> 4];
  9897. *d++ = hexDigits [(*data) & 0xf];
  9898. ++data;
  9899. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9900. *d++ = T(' ');
  9901. }
  9902. *d = 0;
  9903. return s;
  9904. }
  9905. int String::getHexValue32() const throw()
  9906. {
  9907. int result = 0;
  9908. const tchar* c = text->text;
  9909. for (;;)
  9910. {
  9911. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9912. if (hexValue >= 0)
  9913. result = (result << 4) | hexValue;
  9914. else if (*c == 0)
  9915. break;
  9916. ++c;
  9917. }
  9918. return result;
  9919. }
  9920. int64 String::getHexValue64() const throw()
  9921. {
  9922. int64 result = 0;
  9923. const tchar* c = text->text;
  9924. for (;;)
  9925. {
  9926. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9927. if (hexValue >= 0)
  9928. result = (result << 4) | hexValue;
  9929. else if (*c == 0)
  9930. break;
  9931. ++c;
  9932. }
  9933. return result;
  9934. }
  9935. const String String::createStringFromData (const void* const data_,
  9936. const int size) throw()
  9937. {
  9938. const char* const data = (const char*) data_;
  9939. if (size <= 0 || data == 0)
  9940. {
  9941. return empty;
  9942. }
  9943. else if (size < 2)
  9944. {
  9945. return charToString (data[0]);
  9946. }
  9947. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9948. || (data[0] == (char)-1 && data[1] == (char)-2))
  9949. {
  9950. // assume it's 16-bit unicode
  9951. const bool bigEndian = (data[0] == (char)-2);
  9952. const int numChars = size / 2 - 1;
  9953. String result;
  9954. result.preallocateStorage (numChars + 2);
  9955. const uint16* const src = (const uint16*) (data + 2);
  9956. tchar* const dst = const_cast <tchar*> ((const tchar*) result);
  9957. if (bigEndian)
  9958. {
  9959. for (int i = 0; i < numChars; ++i)
  9960. dst[i] = (tchar) ByteOrder::swapIfLittleEndian (src[i]);
  9961. }
  9962. else
  9963. {
  9964. for (int i = 0; i < numChars; ++i)
  9965. dst[i] = (tchar) ByteOrder::swapIfBigEndian (src[i]);
  9966. }
  9967. dst [numChars] = 0;
  9968. return result;
  9969. }
  9970. else
  9971. {
  9972. return String::fromUTF8 ((const uint8*) data, size);
  9973. }
  9974. }
  9975. const char* String::toUTF8() const throw()
  9976. {
  9977. if (isEmpty())
  9978. {
  9979. return (const char*) emptyCharString;
  9980. }
  9981. else
  9982. {
  9983. String* const mutableThis = const_cast <String*> (this);
  9984. mutableThis->dupeInternalIfMultiplyReferenced();
  9985. const int currentLen = CharacterFunctions::length (text->text) + 1;
  9986. const int utf8BytesNeeded = copyToUTF8 (0);
  9987. mutableThis->text = (InternalRefCountedStringHolder*)
  9988. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  9989. + (currentLen * sizeof (juce_wchar) + utf8BytesNeeded));
  9990. char* const otherCopy = (char*) (text->text + currentLen);
  9991. copyToUTF8 ((uint8*) otherCopy);
  9992. return otherCopy;
  9993. }
  9994. }
  9995. int String::copyToUTF8 (uint8* const buffer, const int maxBufferSizeBytes) const throw()
  9996. {
  9997. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9998. #if JUCE_STRINGS_ARE_UNICODE
  9999. int num = 0, index = 0;
  10000. for (;;)
  10001. {
  10002. const uint32 c = (uint32) text->text [index++];
  10003. if (c >= 0x80)
  10004. {
  10005. int numExtraBytes = 1;
  10006. if (c >= 0x800)
  10007. {
  10008. ++numExtraBytes;
  10009. if (c >= 0x10000)
  10010. {
  10011. ++numExtraBytes;
  10012. if (c >= 0x200000)
  10013. {
  10014. ++numExtraBytes;
  10015. if (c >= 0x4000000)
  10016. ++numExtraBytes;
  10017. }
  10018. }
  10019. }
  10020. if (buffer != 0)
  10021. {
  10022. if (num + numExtraBytes >= maxBufferSizeBytes)
  10023. {
  10024. buffer [num++] = 0;
  10025. break;
  10026. }
  10027. else
  10028. {
  10029. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  10030. while (--numExtraBytes >= 0)
  10031. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  10032. }
  10033. }
  10034. else
  10035. {
  10036. num += numExtraBytes + 1;
  10037. }
  10038. }
  10039. else
  10040. {
  10041. if (buffer != 0)
  10042. {
  10043. if (num + 1 >= maxBufferSizeBytes)
  10044. {
  10045. buffer [num++] = 0;
  10046. break;
  10047. }
  10048. buffer [num] = (uint8) c;
  10049. }
  10050. ++num;
  10051. }
  10052. if (c == 0)
  10053. break;
  10054. }
  10055. return num;
  10056. #else
  10057. const int numBytes = jmin (maxBufferSizeBytes, length() + 1);
  10058. if (buffer != 0)
  10059. copyToBuffer ((char*) buffer, maxBufferSizeBytes);
  10060. return numBytes;
  10061. #endif
  10062. }
  10063. const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) throw()
  10064. {
  10065. if (buffer == 0)
  10066. return empty;
  10067. if (bufferSizeBytes < 0)
  10068. bufferSizeBytes = std::numeric_limits<int>::max();
  10069. size_t numBytes;
  10070. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  10071. if (buffer [numBytes] == 0)
  10072. break;
  10073. String result ((int) numBytes + 1, 0);
  10074. tchar* dest = result.text->text;
  10075. size_t i = 0;
  10076. while (i < numBytes)
  10077. {
  10078. const uint8 c = buffer [i++];
  10079. if ((c & 0x80) != 0)
  10080. {
  10081. int mask = 0x7f;
  10082. int bit = 0x40;
  10083. int numExtraValues = 0;
  10084. while (bit != 0 && (c & bit) != 0)
  10085. {
  10086. bit >>= 1;
  10087. mask >>= 1;
  10088. ++numExtraValues;
  10089. }
  10090. int n = (c & mask);
  10091. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  10092. {
  10093. const uint8 nextByte = buffer[i];
  10094. if ((nextByte & 0xc0) != 0x80)
  10095. break;
  10096. n <<= 6;
  10097. n |= (nextByte & 0x3f);
  10098. ++i;
  10099. }
  10100. *dest++ = (tchar) n;
  10101. }
  10102. else
  10103. {
  10104. *dest++ = (tchar) c;
  10105. }
  10106. }
  10107. *dest = 0;
  10108. return result;
  10109. }
  10110. String::Concatenator::Concatenator (String& stringToAppendTo)
  10111. : result (stringToAppendTo),
  10112. nextIndex (stringToAppendTo.length())
  10113. {
  10114. }
  10115. String::Concatenator::~Concatenator()
  10116. {
  10117. }
  10118. void String::Concatenator::append (const String& s)
  10119. {
  10120. const int len = s.length();
  10121. if (len > 0)
  10122. {
  10123. result.preallocateStorage (nextIndex + len);
  10124. s.copyToBuffer (const_cast <tchar*> ((const tchar*) result) + nextIndex, len);
  10125. nextIndex += len;
  10126. }
  10127. }
  10128. END_JUCE_NAMESPACE
  10129. /*** End of inlined file: juce_String.cpp ***/
  10130. /*** Start of inlined file: juce_StringArray.cpp ***/
  10131. BEGIN_JUCE_NAMESPACE
  10132. StringArray::StringArray() throw()
  10133. {
  10134. }
  10135. StringArray::StringArray (const StringArray& other)
  10136. : strings (other.strings)
  10137. {
  10138. }
  10139. StringArray::StringArray (const juce_wchar** const initialStrings,
  10140. const int numberOfStrings)
  10141. {
  10142. for (int i = 0; i < numberOfStrings; ++i)
  10143. add (initialStrings [i]);
  10144. }
  10145. StringArray::StringArray (const char** const initialStrings,
  10146. const int numberOfStrings)
  10147. {
  10148. for (int i = 0; i < numberOfStrings; ++i)
  10149. add (initialStrings [i]);
  10150. }
  10151. StringArray::StringArray (const juce_wchar** const initialStrings)
  10152. {
  10153. int i = 0;
  10154. while (initialStrings[i] != 0)
  10155. add (initialStrings [i++]);
  10156. }
  10157. StringArray::StringArray (const char** const initialStrings)
  10158. {
  10159. int i = 0;
  10160. while (initialStrings[i] != 0)
  10161. add (initialStrings [i++]);
  10162. }
  10163. const StringArray& StringArray::operator= (const StringArray& other)
  10164. {
  10165. strings = other.strings;
  10166. return *this;
  10167. }
  10168. StringArray::~StringArray()
  10169. {
  10170. }
  10171. bool StringArray::operator== (const StringArray& other) const
  10172. {
  10173. if (other.size() != size())
  10174. return false;
  10175. for (int i = size(); --i >= 0;)
  10176. if (other.strings.getReference(i) != strings.getReference(i))
  10177. return false;
  10178. return true;
  10179. }
  10180. bool StringArray::operator!= (const StringArray& other) const
  10181. {
  10182. return ! operator== (other);
  10183. }
  10184. void StringArray::clear()
  10185. {
  10186. strings.clear();
  10187. }
  10188. const String& StringArray::operator[] (const int index) const throw()
  10189. {
  10190. if (((unsigned int) index) < (unsigned int) strings.size())
  10191. return strings.getReference (index);
  10192. return String::empty;
  10193. }
  10194. void StringArray::add (const String& newString)
  10195. {
  10196. strings.add (newString);
  10197. }
  10198. void StringArray::insert (const int index, const String& newString)
  10199. {
  10200. strings.insert (index, newString);
  10201. }
  10202. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  10203. {
  10204. if (! contains (newString, ignoreCase))
  10205. add (newString);
  10206. }
  10207. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  10208. {
  10209. if (startIndex < 0)
  10210. {
  10211. jassertfalse
  10212. startIndex = 0;
  10213. }
  10214. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10215. numElementsToAdd = otherArray.size() - startIndex;
  10216. while (--numElementsToAdd >= 0)
  10217. strings.add (otherArray.strings.getReference (startIndex++));
  10218. }
  10219. void StringArray::set (const int index, const String& newString)
  10220. {
  10221. strings.set (index, newString);
  10222. }
  10223. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10224. {
  10225. if (ignoreCase)
  10226. {
  10227. for (int i = size(); --i >= 0;)
  10228. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10229. return true;
  10230. }
  10231. else
  10232. {
  10233. for (int i = size(); --i >= 0;)
  10234. if (stringToLookFor == strings.getReference(i))
  10235. return true;
  10236. }
  10237. return false;
  10238. }
  10239. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10240. {
  10241. if (i < 0)
  10242. i = 0;
  10243. const int numElements = size();
  10244. if (ignoreCase)
  10245. {
  10246. while (i < numElements)
  10247. {
  10248. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10249. return i;
  10250. ++i;
  10251. }
  10252. }
  10253. else
  10254. {
  10255. while (i < numElements)
  10256. {
  10257. if (stringToLookFor == strings.getReference (i))
  10258. return i;
  10259. ++i;
  10260. }
  10261. }
  10262. return -1;
  10263. }
  10264. void StringArray::remove (const int index)
  10265. {
  10266. strings.remove (index);
  10267. }
  10268. void StringArray::removeString (const String& stringToRemove,
  10269. const bool ignoreCase)
  10270. {
  10271. if (ignoreCase)
  10272. {
  10273. for (int i = size(); --i >= 0;)
  10274. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10275. strings.remove (i);
  10276. }
  10277. else
  10278. {
  10279. for (int i = size(); --i >= 0;)
  10280. if (stringToRemove == strings.getReference (i))
  10281. strings.remove (i);
  10282. }
  10283. }
  10284. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10285. {
  10286. if (removeWhitespaceStrings)
  10287. {
  10288. for (int i = size(); --i >= 0;)
  10289. if (! strings.getReference(i).containsNonWhitespaceChars())
  10290. strings.remove (i);
  10291. }
  10292. else
  10293. {
  10294. for (int i = size(); --i >= 0;)
  10295. if (strings.getReference(i).isEmpty())
  10296. strings.remove (i);
  10297. }
  10298. }
  10299. void StringArray::trim()
  10300. {
  10301. for (int i = size(); --i >= 0;)
  10302. {
  10303. String& s = strings.getReference(i);
  10304. s = s.trim();
  10305. }
  10306. }
  10307. class InternalStringArrayComparator_CaseSensitive
  10308. {
  10309. public:
  10310. static int compareElements (String& first, String& second) { return first.compare (second); }
  10311. };
  10312. class InternalStringArrayComparator_CaseInsensitive
  10313. {
  10314. public:
  10315. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10316. };
  10317. void StringArray::sort (const bool ignoreCase)
  10318. {
  10319. if (ignoreCase)
  10320. {
  10321. InternalStringArrayComparator_CaseInsensitive comp;
  10322. strings.sort (comp);
  10323. }
  10324. else
  10325. {
  10326. InternalStringArrayComparator_CaseSensitive comp;
  10327. strings.sort (comp);
  10328. }
  10329. }
  10330. void StringArray::move (const int currentIndex, int newIndex) throw()
  10331. {
  10332. strings.move (currentIndex, newIndex);
  10333. }
  10334. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10335. {
  10336. const int last = (numberToJoin < 0) ? size()
  10337. : jmin (size(), start + numberToJoin);
  10338. if (start < 0)
  10339. start = 0;
  10340. if (start >= last)
  10341. return String::empty;
  10342. if (start == last - 1)
  10343. return strings.getReference (start);
  10344. const int separatorLen = separator.length();
  10345. int charsNeeded = separatorLen * (last - start - 1);
  10346. for (int i = start; i < last; ++i)
  10347. charsNeeded += strings.getReference(i).length();
  10348. String result;
  10349. result.preallocateStorage (charsNeeded);
  10350. tchar* dest = (tchar*) (const tchar*) result;
  10351. while (start < last)
  10352. {
  10353. const String& s = strings.getReference (start);
  10354. const int len = s.length();
  10355. if (len > 0)
  10356. {
  10357. s.copyToBuffer (dest, len);
  10358. dest += len;
  10359. }
  10360. if (++start < last && separatorLen > 0)
  10361. {
  10362. separator.copyToBuffer (dest, separatorLen);
  10363. dest += separatorLen;
  10364. }
  10365. }
  10366. *dest = 0;
  10367. return result;
  10368. }
  10369. int StringArray::addTokens (const tchar* const text, const bool preserveQuotedStrings)
  10370. {
  10371. return addTokens (text,
  10372. T(" \n\r\t"),
  10373. preserveQuotedStrings ? T("\"") : 0);
  10374. }
  10375. int StringArray::addTokens (const tchar* const text, const tchar* breakCharacters, const tchar* quoteCharacters)
  10376. {
  10377. int num = 0;
  10378. if (text != 0 && *text != 0)
  10379. {
  10380. if (breakCharacters == 0)
  10381. breakCharacters = T("");
  10382. if (quoteCharacters == 0)
  10383. quoteCharacters = T("");
  10384. bool insideQuotes = false;
  10385. tchar currentQuoteChar = 0;
  10386. int i = 0;
  10387. int tokenStart = 0;
  10388. for (;;)
  10389. {
  10390. const tchar c = text[i];
  10391. bool isBreak = (c == 0);
  10392. if (! (insideQuotes || isBreak))
  10393. {
  10394. const tchar* b = breakCharacters;
  10395. while (*b != 0)
  10396. {
  10397. if (*b++ == c)
  10398. {
  10399. isBreak = true;
  10400. break;
  10401. }
  10402. }
  10403. }
  10404. if (! isBreak)
  10405. {
  10406. bool isQuote = false;
  10407. const tchar* q = quoteCharacters;
  10408. while (*q != 0)
  10409. {
  10410. if (*q++ == c)
  10411. {
  10412. isQuote = true;
  10413. break;
  10414. }
  10415. }
  10416. if (isQuote)
  10417. {
  10418. if (insideQuotes)
  10419. {
  10420. // only break out of quotes-mode if we find a matching quote to the
  10421. // one that we opened with..
  10422. if (currentQuoteChar == c)
  10423. insideQuotes = false;
  10424. }
  10425. else
  10426. {
  10427. insideQuotes = true;
  10428. currentQuoteChar = c;
  10429. }
  10430. }
  10431. }
  10432. else
  10433. {
  10434. add (String (text + tokenStart, i - tokenStart));
  10435. ++num;
  10436. tokenStart = i + 1;
  10437. }
  10438. if (c == 0)
  10439. break;
  10440. ++i;
  10441. }
  10442. }
  10443. return num;
  10444. }
  10445. int StringArray::addLines (const tchar* text)
  10446. {
  10447. int numLines = 0;
  10448. if (text != 0)
  10449. {
  10450. while (*text != 0)
  10451. {
  10452. const tchar* const startOfLine = text;
  10453. while (*text != 0)
  10454. {
  10455. if (*text == T('\r'))
  10456. {
  10457. ++text;
  10458. if (*text == T('\n'))
  10459. ++text;
  10460. break;
  10461. }
  10462. if (*text == T('\n'))
  10463. {
  10464. ++text;
  10465. break;
  10466. }
  10467. ++text;
  10468. }
  10469. const tchar* endOfLine = text;
  10470. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10471. --endOfLine;
  10472. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10473. --endOfLine;
  10474. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10475. ++numLines;
  10476. }
  10477. }
  10478. return numLines;
  10479. }
  10480. void StringArray::removeDuplicates (const bool ignoreCase)
  10481. {
  10482. for (int i = 0; i < size() - 1; ++i)
  10483. {
  10484. const String s (strings.getReference(i));
  10485. int nextIndex = i + 1;
  10486. for (;;)
  10487. {
  10488. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10489. if (nextIndex < 0)
  10490. break;
  10491. strings.remove (nextIndex);
  10492. }
  10493. }
  10494. }
  10495. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10496. const bool appendNumberToFirstInstance,
  10497. const tchar* const preNumberString,
  10498. const tchar* const postNumberString)
  10499. {
  10500. for (int i = 0; i < size() - 1; ++i)
  10501. {
  10502. String& s = strings.getReference(i);
  10503. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10504. if (nextIndex >= 0)
  10505. {
  10506. const String original (s);
  10507. int number = 0;
  10508. if (appendNumberToFirstInstance)
  10509. s = original + preNumberString + String (++number) + postNumberString;
  10510. else
  10511. ++number;
  10512. while (nextIndex >= 0)
  10513. {
  10514. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10515. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10516. }
  10517. }
  10518. }
  10519. }
  10520. void StringArray::minimiseStorageOverheads()
  10521. {
  10522. strings.minimiseStorageOverheads();
  10523. }
  10524. END_JUCE_NAMESPACE
  10525. /*** End of inlined file: juce_StringArray.cpp ***/
  10526. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10527. BEGIN_JUCE_NAMESPACE
  10528. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  10529. : ignoreCase (ignoreCase_)
  10530. {
  10531. }
  10532. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  10533. : keys (other.keys),
  10534. values (other.values),
  10535. ignoreCase (other.ignoreCase)
  10536. {
  10537. }
  10538. StringPairArray::~StringPairArray() throw()
  10539. {
  10540. }
  10541. const StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  10542. {
  10543. keys = other.keys;
  10544. values = other.values;
  10545. return *this;
  10546. }
  10547. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  10548. {
  10549. for (int i = keys.size(); --i >= 0;)
  10550. if (other [keys[i]] != values[i])
  10551. return false;
  10552. return true;
  10553. }
  10554. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  10555. {
  10556. return ! operator== (other);
  10557. }
  10558. const String& StringPairArray::operator[] (const String& key) const throw()
  10559. {
  10560. return values [keys.indexOf (key, ignoreCase)];
  10561. }
  10562. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10563. {
  10564. const int i = keys.indexOf (key, ignoreCase);
  10565. if (i >= 0)
  10566. return values[i];
  10567. return defaultReturnValue;
  10568. }
  10569. void StringPairArray::set (const String& key,
  10570. const String& value) throw()
  10571. {
  10572. const int i = keys.indexOf (key, ignoreCase);
  10573. if (i >= 0)
  10574. {
  10575. values.set (i, value);
  10576. }
  10577. else
  10578. {
  10579. keys.add (key);
  10580. values.add (value);
  10581. }
  10582. }
  10583. void StringPairArray::addArray (const StringPairArray& other)
  10584. {
  10585. for (int i = 0; i < other.size(); ++i)
  10586. set (other.keys[i], other.values[i]);
  10587. }
  10588. void StringPairArray::clear() throw()
  10589. {
  10590. keys.clear();
  10591. values.clear();
  10592. }
  10593. void StringPairArray::remove (const String& key) throw()
  10594. {
  10595. remove (keys.indexOf (key, ignoreCase));
  10596. }
  10597. void StringPairArray::remove (const int index) throw()
  10598. {
  10599. keys.remove (index);
  10600. values.remove (index);
  10601. }
  10602. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  10603. {
  10604. ignoreCase = shouldIgnoreCase;
  10605. }
  10606. const String StringPairArray::getDescription() const
  10607. {
  10608. String s;
  10609. for (int i = 0; i < keys.size(); ++i)
  10610. {
  10611. s << keys[i] << T(" = ") << values[i];
  10612. if (i < keys.size())
  10613. s << T(", ");
  10614. }
  10615. return s;
  10616. }
  10617. void StringPairArray::minimiseStorageOverheads() throw()
  10618. {
  10619. keys.minimiseStorageOverheads();
  10620. values.minimiseStorageOverheads();
  10621. }
  10622. END_JUCE_NAMESPACE
  10623. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10624. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10625. BEGIN_JUCE_NAMESPACE
  10626. XmlDocument::XmlDocument (const String& documentText) throw()
  10627. : originalText (documentText),
  10628. ignoreEmptyTextElements (true)
  10629. {
  10630. }
  10631. XmlDocument::XmlDocument (const File& file)
  10632. {
  10633. inputSource = new FileInputSource (file);
  10634. }
  10635. XmlDocument::~XmlDocument() throw()
  10636. {
  10637. }
  10638. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10639. {
  10640. inputSource = newSource;
  10641. }
  10642. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10643. {
  10644. ignoreEmptyTextElements = shouldBeIgnored;
  10645. }
  10646. bool XmlDocument::isXmlIdentifierCharSlow (const tchar c) throw()
  10647. {
  10648. return CharacterFunctions::isLetterOrDigit (c)
  10649. || c == T('_')
  10650. || c == T('-')
  10651. || c == T(':')
  10652. || c == T('.');
  10653. }
  10654. inline bool XmlDocument::isXmlIdentifierChar (const tchar c) const throw()
  10655. {
  10656. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10657. : isXmlIdentifierCharSlow (c);
  10658. }
  10659. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10660. {
  10661. String textToParse (originalText);
  10662. if (textToParse.isEmpty() && inputSource != 0)
  10663. {
  10664. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10665. if (in != 0)
  10666. {
  10667. MemoryBlock data;
  10668. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10669. if (data.getSize() >= 2
  10670. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10671. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10672. {
  10673. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10674. }
  10675. else
  10676. {
  10677. textToParse = String::fromUTF8 ((const uint8*) data.getData(), (int) data.getSize());
  10678. }
  10679. if (! onlyReadOuterDocumentElement)
  10680. originalText = textToParse;
  10681. }
  10682. }
  10683. input = textToParse;
  10684. lastError = String::empty;
  10685. errorOccurred = false;
  10686. outOfData = false;
  10687. needToLoadDTD = true;
  10688. for (int i = 0; i < 128; ++i)
  10689. identifierLookupTable[i] = isXmlIdentifierCharSlow ((tchar) i);
  10690. if (textToParse.isEmpty())
  10691. {
  10692. lastError = "not enough input";
  10693. }
  10694. else
  10695. {
  10696. skipHeader();
  10697. if (input != 0)
  10698. {
  10699. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10700. if (! errorOccurred)
  10701. return result.release();
  10702. }
  10703. else
  10704. {
  10705. lastError = "incorrect xml header";
  10706. }
  10707. }
  10708. return 0;
  10709. }
  10710. const String& XmlDocument::getLastParseError() const throw()
  10711. {
  10712. return lastError;
  10713. }
  10714. void XmlDocument::setLastError (const String& desc, const bool carryOn) throw()
  10715. {
  10716. lastError = desc;
  10717. errorOccurred = ! carryOn;
  10718. }
  10719. const String XmlDocument::getFileContents (const String& filename) const
  10720. {
  10721. if (inputSource != 0)
  10722. {
  10723. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10724. if (in != 0)
  10725. return in->readEntireStreamAsString();
  10726. }
  10727. return String::empty;
  10728. }
  10729. tchar XmlDocument::readNextChar() throw()
  10730. {
  10731. if (*input != 0)
  10732. {
  10733. return *input++;
  10734. }
  10735. else
  10736. {
  10737. outOfData = true;
  10738. return 0;
  10739. }
  10740. }
  10741. int XmlDocument::findNextTokenLength() throw()
  10742. {
  10743. int len = 0;
  10744. tchar c = *input;
  10745. while (isXmlIdentifierChar (c))
  10746. c = input [++len];
  10747. return len;
  10748. }
  10749. void XmlDocument::skipHeader() throw()
  10750. {
  10751. const tchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10752. if (found != 0)
  10753. {
  10754. input = found;
  10755. input = CharacterFunctions::find (input, T("?>"));
  10756. if (input == 0)
  10757. return;
  10758. input += 2;
  10759. }
  10760. skipNextWhiteSpace();
  10761. const tchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10762. if (docType == 0)
  10763. return;
  10764. input = docType + 9;
  10765. int n = 1;
  10766. while (n > 0)
  10767. {
  10768. const tchar c = readNextChar();
  10769. if (outOfData)
  10770. return;
  10771. if (c == T('<'))
  10772. ++n;
  10773. else if (c == T('>'))
  10774. --n;
  10775. }
  10776. docType += 9;
  10777. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10778. }
  10779. void XmlDocument::skipNextWhiteSpace() throw()
  10780. {
  10781. for (;;)
  10782. {
  10783. tchar c = *input;
  10784. while (CharacterFunctions::isWhitespace (c))
  10785. c = *++input;
  10786. if (c == 0)
  10787. {
  10788. outOfData = true;
  10789. break;
  10790. }
  10791. else if (c == T('<'))
  10792. {
  10793. if (input[1] == T('!')
  10794. && input[2] == T('-')
  10795. && input[3] == T('-'))
  10796. {
  10797. const tchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10798. if (closeComment == 0)
  10799. {
  10800. outOfData = true;
  10801. break;
  10802. }
  10803. input = closeComment + 3;
  10804. continue;
  10805. }
  10806. else if (input[1] == T('?'))
  10807. {
  10808. const tchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10809. if (closeBracket == 0)
  10810. {
  10811. outOfData = true;
  10812. break;
  10813. }
  10814. input = closeBracket + 2;
  10815. continue;
  10816. }
  10817. }
  10818. break;
  10819. }
  10820. }
  10821. void XmlDocument::readQuotedString (String& result) throw()
  10822. {
  10823. const tchar quote = readNextChar();
  10824. while (! outOfData)
  10825. {
  10826. const tchar c = readNextChar();
  10827. if (c == quote)
  10828. break;
  10829. if (c == T('&'))
  10830. {
  10831. --input;
  10832. readEntity (result);
  10833. }
  10834. else
  10835. {
  10836. --input;
  10837. const tchar* const start = input;
  10838. for (;;)
  10839. {
  10840. const tchar character = *input;
  10841. if (character == quote)
  10842. {
  10843. result.append (start, (int) (input - start));
  10844. ++input;
  10845. return;
  10846. }
  10847. else if (character == T('&'))
  10848. {
  10849. result.append (start, (int) (input - start));
  10850. break;
  10851. }
  10852. else if (character == 0)
  10853. {
  10854. outOfData = true;
  10855. setLastError ("unmatched quotes", false);
  10856. break;
  10857. }
  10858. ++input;
  10859. }
  10860. }
  10861. }
  10862. }
  10863. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw()
  10864. {
  10865. XmlElement* node = 0;
  10866. skipNextWhiteSpace();
  10867. if (outOfData)
  10868. return 0;
  10869. input = CharacterFunctions::find (input, T("<"));
  10870. if (input != 0)
  10871. {
  10872. ++input;
  10873. int tagLen = findNextTokenLength();
  10874. if (tagLen == 0)
  10875. {
  10876. // no tag name - but allow for a gap after the '<' before giving an error
  10877. skipNextWhiteSpace();
  10878. tagLen = findNextTokenLength();
  10879. if (tagLen == 0)
  10880. {
  10881. setLastError ("tag name missing", false);
  10882. return node;
  10883. }
  10884. }
  10885. node = new XmlElement (String (input, tagLen));
  10886. input += tagLen;
  10887. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10888. // look for attributes
  10889. for (;;)
  10890. {
  10891. skipNextWhiteSpace();
  10892. const tchar c = *input;
  10893. // empty tag..
  10894. if (c == T('/') && input[1] == T('>'))
  10895. {
  10896. input += 2;
  10897. break;
  10898. }
  10899. // parse the guts of the element..
  10900. if (c == T('>'))
  10901. {
  10902. ++input;
  10903. skipNextWhiteSpace();
  10904. if (alsoParseSubElements)
  10905. readChildElements (node);
  10906. break;
  10907. }
  10908. // get an attribute..
  10909. if (isXmlIdentifierChar (c))
  10910. {
  10911. const int attNameLen = findNextTokenLength();
  10912. if (attNameLen > 0)
  10913. {
  10914. const tchar* attNameStart = input;
  10915. input += attNameLen;
  10916. skipNextWhiteSpace();
  10917. if (readNextChar() == T('='))
  10918. {
  10919. skipNextWhiteSpace();
  10920. const tchar nextChar = *input;
  10921. if (nextChar == T('"') || nextChar == T('\''))
  10922. {
  10923. XmlElement::XmlAttributeNode* const newAtt
  10924. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10925. String::empty);
  10926. readQuotedString (newAtt->value);
  10927. if (lastAttribute == 0)
  10928. node->attributes = newAtt;
  10929. else
  10930. lastAttribute->next = newAtt;
  10931. lastAttribute = newAtt;
  10932. continue;
  10933. }
  10934. }
  10935. }
  10936. }
  10937. else
  10938. {
  10939. if (! outOfData)
  10940. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10941. }
  10942. break;
  10943. }
  10944. }
  10945. return node;
  10946. }
  10947. void XmlDocument::readChildElements (XmlElement* parent) throw()
  10948. {
  10949. XmlElement* lastChildNode = 0;
  10950. for (;;)
  10951. {
  10952. skipNextWhiteSpace();
  10953. if (outOfData)
  10954. {
  10955. setLastError ("unmatched tags", false);
  10956. break;
  10957. }
  10958. if (*input == T('<'))
  10959. {
  10960. if (input[1] == T('/'))
  10961. {
  10962. // our close tag..
  10963. input = CharacterFunctions::find (input, T(">"));
  10964. ++input;
  10965. break;
  10966. }
  10967. else if (input[1] == T('!')
  10968. && input[2] == T('[')
  10969. && input[3] == T('C')
  10970. && input[4] == T('D')
  10971. && input[5] == T('A')
  10972. && input[6] == T('T')
  10973. && input[7] == T('A')
  10974. && input[8] == T('['))
  10975. {
  10976. input += 9;
  10977. const tchar* const inputStart = input;
  10978. int len = 0;
  10979. for (;;)
  10980. {
  10981. if (*input == 0)
  10982. {
  10983. setLastError ("unterminated CDATA section", false);
  10984. outOfData = true;
  10985. break;
  10986. }
  10987. else if (input[0] == T(']')
  10988. && input[1] == T(']')
  10989. && input[2] == T('>'))
  10990. {
  10991. input += 3;
  10992. break;
  10993. }
  10994. ++input;
  10995. ++len;
  10996. }
  10997. XmlElement* const e = new XmlElement ((int) 0);
  10998. e->setText (String (inputStart, len));
  10999. if (lastChildNode != 0)
  11000. lastChildNode->nextElement = e;
  11001. else
  11002. parent->addChildElement (e);
  11003. lastChildNode = e;
  11004. }
  11005. else
  11006. {
  11007. // this is some other element, so parse and add it..
  11008. XmlElement* const n = readNextElement (true);
  11009. if (n != 0)
  11010. {
  11011. if (lastChildNode == 0)
  11012. parent->addChildElement (n);
  11013. else
  11014. lastChildNode->nextElement = n;
  11015. lastChildNode = n;
  11016. }
  11017. else
  11018. {
  11019. return;
  11020. }
  11021. }
  11022. }
  11023. else
  11024. {
  11025. // read character block..
  11026. XmlElement* const e = new XmlElement ((int)0);
  11027. if (lastChildNode != 0)
  11028. lastChildNode->nextElement = e;
  11029. else
  11030. parent->addChildElement (e);
  11031. lastChildNode = e;
  11032. String textElementContent;
  11033. for (;;)
  11034. {
  11035. const tchar c = *input;
  11036. if (c == T('<'))
  11037. break;
  11038. if (c == 0)
  11039. {
  11040. setLastError ("unmatched tags", false);
  11041. outOfData = true;
  11042. return;
  11043. }
  11044. if (c == T('&'))
  11045. {
  11046. String entity;
  11047. readEntity (entity);
  11048. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  11049. {
  11050. const tchar* const oldInput = input;
  11051. const bool oldOutOfData = outOfData;
  11052. input = (const tchar*) entity;
  11053. outOfData = false;
  11054. for (;;)
  11055. {
  11056. XmlElement* const n = readNextElement (true);
  11057. if (n == 0)
  11058. break;
  11059. if (lastChildNode == 0)
  11060. parent->addChildElement (n);
  11061. else
  11062. lastChildNode->nextElement = n;
  11063. lastChildNode = n;
  11064. }
  11065. input = oldInput;
  11066. outOfData = oldOutOfData;
  11067. }
  11068. else
  11069. {
  11070. textElementContent += entity;
  11071. }
  11072. }
  11073. else
  11074. {
  11075. const tchar* start = input;
  11076. int len = 0;
  11077. for (;;)
  11078. {
  11079. const tchar nextChar = *input;
  11080. if (nextChar == T('<') || nextChar == T('&'))
  11081. {
  11082. break;
  11083. }
  11084. else if (nextChar == 0)
  11085. {
  11086. setLastError ("unmatched tags", false);
  11087. outOfData = true;
  11088. return;
  11089. }
  11090. ++input;
  11091. ++len;
  11092. }
  11093. textElementContent.append (start, len);
  11094. }
  11095. }
  11096. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  11097. : textElementContent.isNotEmpty())
  11098. e->setText (textElementContent);
  11099. }
  11100. }
  11101. }
  11102. void XmlDocument::readEntity (String& result) throw()
  11103. {
  11104. // skip over the ampersand
  11105. ++input;
  11106. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  11107. {
  11108. input += 4;
  11109. result += T("&");
  11110. }
  11111. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  11112. {
  11113. input += 5;
  11114. result += T("\"");
  11115. }
  11116. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  11117. {
  11118. input += 5;
  11119. result += T("\'");
  11120. }
  11121. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  11122. {
  11123. input += 3;
  11124. result += T("<");
  11125. }
  11126. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  11127. {
  11128. input += 3;
  11129. result += T(">");
  11130. }
  11131. else if (*input == T('#'))
  11132. {
  11133. int charCode = 0;
  11134. ++input;
  11135. if (*input == T('x') || *input == T('X'))
  11136. {
  11137. ++input;
  11138. int numChars = 0;
  11139. while (input[0] != T(';'))
  11140. {
  11141. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  11142. if (hexValue < 0 || ++numChars > 8)
  11143. {
  11144. setLastError ("illegal escape sequence", true);
  11145. break;
  11146. }
  11147. charCode = (charCode << 4) | hexValue;
  11148. ++input;
  11149. }
  11150. ++input;
  11151. }
  11152. else if (input[0] >= T('0') && input[0] <= T('9'))
  11153. {
  11154. int numChars = 0;
  11155. while (input[0] != T(';'))
  11156. {
  11157. if (++numChars > 12)
  11158. {
  11159. setLastError ("illegal escape sequence", true);
  11160. break;
  11161. }
  11162. charCode = charCode * 10 + (input[0] - T('0'));
  11163. ++input;
  11164. }
  11165. ++input;
  11166. }
  11167. else
  11168. {
  11169. setLastError ("illegal escape sequence", true);
  11170. result += T("&");
  11171. return;
  11172. }
  11173. result << (tchar) charCode;
  11174. }
  11175. else
  11176. {
  11177. const tchar* const entityNameStart = input;
  11178. const tchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  11179. if (closingSemiColon == 0)
  11180. {
  11181. outOfData = true;
  11182. result += T("&");
  11183. }
  11184. else
  11185. {
  11186. input = closingSemiColon + 1;
  11187. result += expandExternalEntity (String (entityNameStart,
  11188. (int) (closingSemiColon - entityNameStart)));
  11189. }
  11190. }
  11191. }
  11192. const String XmlDocument::expandEntity (const String& ent)
  11193. {
  11194. if (ent.equalsIgnoreCase (T("amp")))
  11195. {
  11196. return T("&");
  11197. }
  11198. else if (ent.equalsIgnoreCase (T("quot")))
  11199. {
  11200. return T("\"");
  11201. }
  11202. else if (ent.equalsIgnoreCase (T("apos")))
  11203. {
  11204. return T("\'");
  11205. }
  11206. else if (ent.equalsIgnoreCase (T("lt")))
  11207. {
  11208. return T("<");
  11209. }
  11210. else if (ent.equalsIgnoreCase (T("gt")))
  11211. {
  11212. return T(">");
  11213. }
  11214. else if (ent[0] == T('#'))
  11215. {
  11216. if (ent[1] == T('x') || ent[1] == T('X'))
  11217. {
  11218. return String::charToString ((tchar) ent.substring (2).getHexValue32());
  11219. }
  11220. else if (ent[1] >= T('0') && ent[1] <= T('9'))
  11221. {
  11222. return String::charToString ((tchar) ent.substring (1).getIntValue());
  11223. }
  11224. setLastError ("illegal escape sequence", false);
  11225. return T("&");
  11226. }
  11227. else
  11228. {
  11229. return expandExternalEntity (ent);
  11230. }
  11231. }
  11232. const String XmlDocument::expandExternalEntity (const String& entity)
  11233. {
  11234. if (needToLoadDTD)
  11235. {
  11236. if (dtdText.isNotEmpty())
  11237. {
  11238. while (dtdText.endsWithChar (T('>')))
  11239. dtdText = dtdText.dropLastCharacters (1);
  11240. tokenisedDTD.addTokens (dtdText, true);
  11241. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  11242. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  11243. {
  11244. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  11245. tokenisedDTD.clear();
  11246. tokenisedDTD.addTokens (getFileContents (fn), true);
  11247. }
  11248. else
  11249. {
  11250. tokenisedDTD.clear();
  11251. const int openBracket = dtdText.indexOfChar (T('['));
  11252. if (openBracket > 0)
  11253. {
  11254. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  11255. if (closeBracket > openBracket)
  11256. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  11257. closeBracket), true);
  11258. }
  11259. }
  11260. for (int i = tokenisedDTD.size(); --i >= 0;)
  11261. {
  11262. if (tokenisedDTD[i].startsWithChar (T('%'))
  11263. && tokenisedDTD[i].endsWithChar (T(';')))
  11264. {
  11265. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11266. StringArray newToks;
  11267. newToks.addTokens (parsed, true);
  11268. tokenisedDTD.remove (i);
  11269. for (int j = newToks.size(); --j >= 0;)
  11270. tokenisedDTD.insert (i, newToks[j]);
  11271. }
  11272. }
  11273. }
  11274. needToLoadDTD = false;
  11275. }
  11276. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11277. {
  11278. if (tokenisedDTD[i] == entity)
  11279. {
  11280. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11281. {
  11282. String ent (tokenisedDTD [i + 1]);
  11283. while (ent.endsWithChar (T('>')))
  11284. ent = ent.dropLastCharacters (1);
  11285. ent = ent.trim().unquoted();
  11286. // check for sub-entities..
  11287. int ampersand = ent.indexOfChar (T('&'));
  11288. while (ampersand >= 0)
  11289. {
  11290. const int semiColon = ent.indexOf (i + 1, T(";"));
  11291. if (semiColon < 0)
  11292. {
  11293. setLastError ("entity without terminating semi-colon", false);
  11294. break;
  11295. }
  11296. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11297. ent = ent.substring (0, ampersand)
  11298. + resolved
  11299. + ent.substring (semiColon + 1);
  11300. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11301. }
  11302. return ent;
  11303. }
  11304. }
  11305. }
  11306. setLastError ("unknown entity", true);
  11307. return entity;
  11308. }
  11309. const String XmlDocument::getParameterEntity (const String& entity)
  11310. {
  11311. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11312. {
  11313. if (tokenisedDTD[i] == entity)
  11314. {
  11315. if (tokenisedDTD [i - 1] == T("%")
  11316. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11317. {
  11318. String ent (tokenisedDTD [i + 1]);
  11319. while (ent.endsWithChar (T('>')))
  11320. ent = ent.dropLastCharacters (1);
  11321. if (ent.equalsIgnoreCase (T("system")))
  11322. {
  11323. String filename (tokenisedDTD [i + 2]);
  11324. while (filename.endsWithChar (T('>')))
  11325. filename = filename.dropLastCharacters (1);
  11326. return getFileContents (filename);
  11327. }
  11328. else
  11329. {
  11330. return ent.trim().unquoted();
  11331. }
  11332. }
  11333. }
  11334. }
  11335. return entity;
  11336. }
  11337. END_JUCE_NAMESPACE
  11338. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11339. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11340. BEGIN_JUCE_NAMESPACE
  11341. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11342. : name (other.name),
  11343. value (other.value),
  11344. next (0)
  11345. {
  11346. }
  11347. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_,
  11348. const String& value_) throw()
  11349. : name (name_),
  11350. value (value_),
  11351. next (0)
  11352. {
  11353. }
  11354. XmlElement::XmlElement (const String& tagName_) throw()
  11355. : tagName (tagName_),
  11356. firstChildElement (0),
  11357. nextElement (0),
  11358. attributes (0)
  11359. {
  11360. // the tag name mustn't be empty, or it'll look like a text element!
  11361. jassert (tagName_.containsNonWhitespaceChars())
  11362. }
  11363. XmlElement::XmlElement (int /*dummy*/) throw()
  11364. : firstChildElement (0),
  11365. nextElement (0),
  11366. attributes (0)
  11367. {
  11368. }
  11369. XmlElement::XmlElement (const XmlElement& other) throw()
  11370. : tagName (other.tagName),
  11371. firstChildElement (0),
  11372. nextElement (0),
  11373. attributes (0)
  11374. {
  11375. copyChildrenAndAttributesFrom (other);
  11376. }
  11377. const XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11378. {
  11379. if (this != &other)
  11380. {
  11381. removeAllAttributes();
  11382. deleteAllChildElements();
  11383. tagName = other.tagName;
  11384. copyChildrenAndAttributesFrom (other);
  11385. }
  11386. return *this;
  11387. }
  11388. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11389. {
  11390. XmlElement* child = other.firstChildElement;
  11391. XmlElement* lastChild = 0;
  11392. while (child != 0)
  11393. {
  11394. XmlElement* const copiedChild = new XmlElement (*child);
  11395. if (lastChild != 0)
  11396. lastChild->nextElement = copiedChild;
  11397. else
  11398. firstChildElement = copiedChild;
  11399. lastChild = copiedChild;
  11400. child = child->nextElement;
  11401. }
  11402. const XmlAttributeNode* att = other.attributes;
  11403. XmlAttributeNode* lastAtt = 0;
  11404. while (att != 0)
  11405. {
  11406. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11407. if (lastAtt != 0)
  11408. lastAtt->next = newAtt;
  11409. else
  11410. attributes = newAtt;
  11411. lastAtt = newAtt;
  11412. att = att->next;
  11413. }
  11414. }
  11415. XmlElement::~XmlElement() throw()
  11416. {
  11417. XmlElement* child = firstChildElement;
  11418. while (child != 0)
  11419. {
  11420. XmlElement* const nextChild = child->nextElement;
  11421. delete child;
  11422. child = nextChild;
  11423. }
  11424. XmlAttributeNode* att = attributes;
  11425. while (att != 0)
  11426. {
  11427. XmlAttributeNode* const nextAtt = att->next;
  11428. delete att;
  11429. att = nextAtt;
  11430. }
  11431. }
  11432. static bool isLegalXmlChar (const juce_wchar character)
  11433. {
  11434. if ((character >= 'a' && character <= 'z')
  11435. || (character >= 'A' && character <= 'Z')
  11436. || (character >= '0' && character <= '9'))
  11437. return true;
  11438. const char* t = " .,;:-()_+=?!'#@[]/\\*%~{}";
  11439. do
  11440. {
  11441. if (((juce_wchar) (uint8) *t) == character)
  11442. return true;
  11443. }
  11444. while (*++t != 0);
  11445. return false;
  11446. }
  11447. static void escapeIllegalXmlChars (OutputStream& outputStream,
  11448. const String& text,
  11449. const bool changeNewLines) throw()
  11450. {
  11451. const juce_wchar* t = (const juce_wchar*) text;
  11452. for (;;)
  11453. {
  11454. const juce_wchar character = *t++;
  11455. if (character == 0)
  11456. {
  11457. break;
  11458. }
  11459. else if (isLegalXmlChar (character))
  11460. {
  11461. outputStream.writeByte ((char) character);
  11462. }
  11463. else
  11464. {
  11465. switch (character)
  11466. {
  11467. case '&':
  11468. outputStream.write ("&amp;", 5);
  11469. break;
  11470. case '"':
  11471. outputStream.write ("&quot;", 6);
  11472. break;
  11473. case '>':
  11474. outputStream.write ("&gt;", 4);
  11475. break;
  11476. case '<':
  11477. outputStream.write ("&lt;", 4);
  11478. break;
  11479. case '\n':
  11480. if (changeNewLines)
  11481. outputStream.write ("&#10;", 5);
  11482. else
  11483. outputStream.writeByte ((char) character);
  11484. break;
  11485. case '\r':
  11486. if (changeNewLines)
  11487. outputStream.write ("&#13;", 5);
  11488. else
  11489. outputStream.writeByte ((char) character);
  11490. break;
  11491. default:
  11492. {
  11493. String encoded (T("&#"));
  11494. encoded << String ((int) (unsigned int) character).trim()
  11495. << T(';');
  11496. outputStream.write ((const char*) encoded, encoded.length());
  11497. }
  11498. }
  11499. }
  11500. }
  11501. }
  11502. static void writeSpaces (OutputStream& out, int numSpaces) throw()
  11503. {
  11504. if (numSpaces > 0)
  11505. {
  11506. const char* const blanks = " ";
  11507. const int blankSize = (int) sizeof (blanks) - 1;
  11508. while (numSpaces > blankSize)
  11509. {
  11510. out.write (blanks, blankSize);
  11511. numSpaces -= blankSize;
  11512. }
  11513. out.write (blanks, numSpaces);
  11514. }
  11515. }
  11516. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11517. const int indentationLevel,
  11518. const int lineWrapLength) const throw()
  11519. {
  11520. writeSpaces (outputStream, indentationLevel);
  11521. if (! isTextElement())
  11522. {
  11523. outputStream.writeByte ('<');
  11524. const int nameLen = tagName.length();
  11525. outputStream.write ((const char*) tagName, nameLen);
  11526. const int attIndent = indentationLevel + nameLen + 1;
  11527. int lineLen = 0;
  11528. const XmlAttributeNode* att = attributes;
  11529. while (att != 0)
  11530. {
  11531. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11532. {
  11533. outputStream.write ("\r\n", 2);
  11534. writeSpaces (outputStream, attIndent);
  11535. lineLen = 0;
  11536. }
  11537. const int attNameLen = att->name.length();
  11538. outputStream.writeByte (' ');
  11539. outputStream.write ((const char*) (att->name), attNameLen);
  11540. outputStream.write ("=\"", 2);
  11541. escapeIllegalXmlChars (outputStream, att->value, true);
  11542. outputStream.writeByte ('"');
  11543. lineLen += 4 + attNameLen + att->value.length();
  11544. att = att->next;
  11545. }
  11546. if (firstChildElement != 0)
  11547. {
  11548. XmlElement* child = firstChildElement;
  11549. if (child->nextElement == 0 && child->isTextElement())
  11550. {
  11551. outputStream.writeByte ('>');
  11552. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11553. }
  11554. else
  11555. {
  11556. if (indentationLevel >= 0)
  11557. outputStream.write (">\r\n", 3);
  11558. else
  11559. outputStream.writeByte ('>');
  11560. bool lastWasTextNode = false;
  11561. while (child != 0)
  11562. {
  11563. if (child->isTextElement())
  11564. {
  11565. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11566. writeSpaces (outputStream, indentationLevel + 2);
  11567. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11568. lastWasTextNode = true;
  11569. }
  11570. else
  11571. {
  11572. if (indentationLevel >= 0)
  11573. {
  11574. if (lastWasTextNode)
  11575. outputStream.write ("\r\n", 2);
  11576. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11577. }
  11578. else
  11579. {
  11580. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11581. }
  11582. lastWasTextNode = false;
  11583. }
  11584. child = child->nextElement;
  11585. }
  11586. if (indentationLevel >= 0)
  11587. {
  11588. if (lastWasTextNode)
  11589. outputStream.write ("\r\n", 2);
  11590. writeSpaces (outputStream, indentationLevel);
  11591. }
  11592. }
  11593. outputStream.write ("</", 2);
  11594. outputStream.write ((const char*) tagName, nameLen);
  11595. if (indentationLevel >= 0)
  11596. outputStream.write (">\r\n", 3);
  11597. else
  11598. outputStream.writeByte ('>');
  11599. }
  11600. else
  11601. {
  11602. if (indentationLevel >= 0)
  11603. outputStream.write ("/>\r\n", 4);
  11604. else
  11605. outputStream.write ("/>", 2);
  11606. }
  11607. }
  11608. else
  11609. {
  11610. if (indentationLevel >= 0)
  11611. writeSpaces (outputStream, indentationLevel + 2);
  11612. escapeIllegalXmlChars (outputStream, getText(), false);
  11613. }
  11614. }
  11615. const String XmlElement::createDocument (const String& dtdToUse,
  11616. const bool allOnOneLine,
  11617. const bool includeXmlHeader,
  11618. const String& encodingType,
  11619. const int lineWrapLength) const throw()
  11620. {
  11621. MemoryOutputStream mem (2048, 4096);
  11622. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11623. return String (mem.getData(), mem.getDataSize());
  11624. }
  11625. void XmlElement::writeToStream (OutputStream& output,
  11626. const String& dtdToUse,
  11627. const bool allOnOneLine,
  11628. const bool includeXmlHeader,
  11629. const String& encodingType,
  11630. const int lineWrapLength) const throw()
  11631. {
  11632. if (includeXmlHeader)
  11633. {
  11634. output << "<?xml version=\"1.0\" encoding=\"" << encodingType;
  11635. if (allOnOneLine)
  11636. output << "\"?> ";
  11637. else
  11638. output << "\"?>\r\n\r\n";
  11639. }
  11640. if (dtdToUse.isNotEmpty())
  11641. {
  11642. output << dtdToUse;
  11643. if (allOnOneLine)
  11644. output << " ";
  11645. else
  11646. output << "\r\n";
  11647. }
  11648. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11649. }
  11650. bool XmlElement::writeToFile (const File& file,
  11651. const String& dtdToUse,
  11652. const String& encodingType,
  11653. const int lineWrapLength) const throw()
  11654. {
  11655. if (file.hasWriteAccess())
  11656. {
  11657. TemporaryFile tempFile (file);
  11658. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11659. if (out != 0)
  11660. {
  11661. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11662. out = 0;
  11663. return tempFile.overwriteTargetFileWithTemporary();
  11664. }
  11665. }
  11666. return false;
  11667. }
  11668. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11669. {
  11670. #ifdef JUCE_DEBUG
  11671. // if debugging, check that the case is actually the same, because
  11672. // valid xml is case-sensitive, and although this lets it pass, it's
  11673. // better not to..
  11674. if (tagName.equalsIgnoreCase (tagNameWanted))
  11675. {
  11676. jassert (tagName == tagNameWanted);
  11677. return true;
  11678. }
  11679. else
  11680. {
  11681. return false;
  11682. }
  11683. #else
  11684. return tagName.equalsIgnoreCase (tagNameWanted);
  11685. #endif
  11686. }
  11687. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11688. {
  11689. XmlElement* e = nextElement;
  11690. while (e != 0 && ! e->hasTagName (requiredTagName))
  11691. e = e->nextElement;
  11692. return e;
  11693. }
  11694. int XmlElement::getNumAttributes() const throw()
  11695. {
  11696. const XmlAttributeNode* att = attributes;
  11697. int count = 0;
  11698. while (att != 0)
  11699. {
  11700. att = att->next;
  11701. ++count;
  11702. }
  11703. return count;
  11704. }
  11705. const String& XmlElement::getAttributeName (const int index) const throw()
  11706. {
  11707. const XmlAttributeNode* att = attributes;
  11708. int count = 0;
  11709. while (att != 0)
  11710. {
  11711. if (count == index)
  11712. return att->name;
  11713. att = att->next;
  11714. ++count;
  11715. }
  11716. return String::empty;
  11717. }
  11718. const String& XmlElement::getAttributeValue (const int index) const throw()
  11719. {
  11720. const XmlAttributeNode* att = attributes;
  11721. int count = 0;
  11722. while (att != 0)
  11723. {
  11724. if (count == index)
  11725. return att->value;
  11726. att = att->next;
  11727. ++count;
  11728. }
  11729. return String::empty;
  11730. }
  11731. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11732. {
  11733. const XmlAttributeNode* att = attributes;
  11734. while (att != 0)
  11735. {
  11736. if (att->name.equalsIgnoreCase (attributeName))
  11737. return true;
  11738. att = att->next;
  11739. }
  11740. return false;
  11741. }
  11742. const String XmlElement::getStringAttribute (const String& attributeName,
  11743. const String& defaultReturnValue) const throw()
  11744. {
  11745. const XmlAttributeNode* att = attributes;
  11746. while (att != 0)
  11747. {
  11748. if (att->name.equalsIgnoreCase (attributeName))
  11749. return att->value;
  11750. att = att->next;
  11751. }
  11752. return defaultReturnValue;
  11753. }
  11754. int XmlElement::getIntAttribute (const String& attributeName,
  11755. const int defaultReturnValue) const throw()
  11756. {
  11757. const XmlAttributeNode* att = attributes;
  11758. while (att != 0)
  11759. {
  11760. if (att->name.equalsIgnoreCase (attributeName))
  11761. return att->value.getIntValue();
  11762. att = att->next;
  11763. }
  11764. return defaultReturnValue;
  11765. }
  11766. double XmlElement::getDoubleAttribute (const String& attributeName,
  11767. const double defaultReturnValue) const throw()
  11768. {
  11769. const XmlAttributeNode* att = attributes;
  11770. while (att != 0)
  11771. {
  11772. if (att->name.equalsIgnoreCase (attributeName))
  11773. return att->value.getDoubleValue();
  11774. att = att->next;
  11775. }
  11776. return defaultReturnValue;
  11777. }
  11778. bool XmlElement::getBoolAttribute (const String& attributeName,
  11779. const bool defaultReturnValue) const throw()
  11780. {
  11781. const XmlAttributeNode* att = attributes;
  11782. while (att != 0)
  11783. {
  11784. if (att->name.equalsIgnoreCase (attributeName))
  11785. {
  11786. tchar firstChar = att->value[0];
  11787. if (CharacterFunctions::isWhitespace (firstChar))
  11788. firstChar = att->value.trimStart() [0];
  11789. return firstChar == T('1')
  11790. || firstChar == T('t')
  11791. || firstChar == T('y')
  11792. || firstChar == T('T')
  11793. || firstChar == T('Y');
  11794. }
  11795. att = att->next;
  11796. }
  11797. return defaultReturnValue;
  11798. }
  11799. bool XmlElement::compareAttribute (const String& attributeName,
  11800. const String& stringToCompareAgainst,
  11801. const bool ignoreCase) const throw()
  11802. {
  11803. const XmlAttributeNode* att = attributes;
  11804. while (att != 0)
  11805. {
  11806. if (att->name.equalsIgnoreCase (attributeName))
  11807. {
  11808. if (ignoreCase)
  11809. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11810. else
  11811. return att->value == stringToCompareAgainst;
  11812. }
  11813. att = att->next;
  11814. }
  11815. return false;
  11816. }
  11817. void XmlElement::setAttribute (const String& attributeName,
  11818. const String& value) throw()
  11819. {
  11820. #ifdef JUCE_DEBUG
  11821. // check the identifier being passed in is legal..
  11822. const tchar* t = attributeName;
  11823. while (*t != 0)
  11824. {
  11825. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11826. || *t == T('_')
  11827. || *t == T('-')
  11828. || *t == T(':'));
  11829. ++t;
  11830. }
  11831. #endif
  11832. if (attributes == 0)
  11833. {
  11834. attributes = new XmlAttributeNode (attributeName, value);
  11835. }
  11836. else
  11837. {
  11838. XmlAttributeNode* att = attributes;
  11839. for (;;)
  11840. {
  11841. if (att->name.equalsIgnoreCase (attributeName))
  11842. {
  11843. att->value = value;
  11844. break;
  11845. }
  11846. else if (att->next == 0)
  11847. {
  11848. att->next = new XmlAttributeNode (attributeName, value);
  11849. break;
  11850. }
  11851. att = att->next;
  11852. }
  11853. }
  11854. }
  11855. void XmlElement::setAttribute (const String& attributeName,
  11856. const int number) throw()
  11857. {
  11858. setAttribute (attributeName, String (number));
  11859. }
  11860. void XmlElement::setAttribute (const String& attributeName,
  11861. const double number) throw()
  11862. {
  11863. setAttribute (attributeName, String (number));
  11864. }
  11865. void XmlElement::removeAttribute (const String& attributeName) throw()
  11866. {
  11867. XmlAttributeNode* att = attributes;
  11868. XmlAttributeNode* lastAtt = 0;
  11869. while (att != 0)
  11870. {
  11871. if (att->name.equalsIgnoreCase (attributeName))
  11872. {
  11873. if (lastAtt == 0)
  11874. attributes = att->next;
  11875. else
  11876. lastAtt->next = att->next;
  11877. delete att;
  11878. break;
  11879. }
  11880. lastAtt = att;
  11881. att = att->next;
  11882. }
  11883. }
  11884. void XmlElement::removeAllAttributes() throw()
  11885. {
  11886. while (attributes != 0)
  11887. {
  11888. XmlAttributeNode* const nextAtt = attributes->next;
  11889. delete attributes;
  11890. attributes = nextAtt;
  11891. }
  11892. }
  11893. int XmlElement::getNumChildElements() const throw()
  11894. {
  11895. int count = 0;
  11896. const XmlElement* child = firstChildElement;
  11897. while (child != 0)
  11898. {
  11899. ++count;
  11900. child = child->nextElement;
  11901. }
  11902. return count;
  11903. }
  11904. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11905. {
  11906. int count = 0;
  11907. XmlElement* child = firstChildElement;
  11908. while (child != 0 && count < index)
  11909. {
  11910. child = child->nextElement;
  11911. ++count;
  11912. }
  11913. return child;
  11914. }
  11915. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11916. {
  11917. XmlElement* child = firstChildElement;
  11918. while (child != 0)
  11919. {
  11920. if (child->hasTagName (childName))
  11921. break;
  11922. child = child->nextElement;
  11923. }
  11924. return child;
  11925. }
  11926. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11927. {
  11928. if (newNode != 0)
  11929. {
  11930. if (firstChildElement == 0)
  11931. {
  11932. firstChildElement = newNode;
  11933. }
  11934. else
  11935. {
  11936. XmlElement* child = firstChildElement;
  11937. while (child->nextElement != 0)
  11938. child = child->nextElement;
  11939. child->nextElement = newNode;
  11940. // if this is non-zero, then something's probably
  11941. // gone wrong..
  11942. jassert (newNode->nextElement == 0);
  11943. }
  11944. }
  11945. }
  11946. void XmlElement::insertChildElement (XmlElement* const newNode,
  11947. int indexToInsertAt) throw()
  11948. {
  11949. if (newNode != 0)
  11950. {
  11951. removeChildElement (newNode, false);
  11952. if (indexToInsertAt == 0)
  11953. {
  11954. newNode->nextElement = firstChildElement;
  11955. firstChildElement = newNode;
  11956. }
  11957. else
  11958. {
  11959. if (firstChildElement == 0)
  11960. {
  11961. firstChildElement = newNode;
  11962. }
  11963. else
  11964. {
  11965. if (indexToInsertAt < 0)
  11966. indexToInsertAt = std::numeric_limits<int>::max();
  11967. XmlElement* child = firstChildElement;
  11968. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11969. child = child->nextElement;
  11970. newNode->nextElement = child->nextElement;
  11971. child->nextElement = newNode;
  11972. }
  11973. }
  11974. }
  11975. }
  11976. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11977. {
  11978. XmlElement* const newElement = new XmlElement (tagName);
  11979. addChildElement (newElement);
  11980. return newElement;
  11981. }
  11982. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11983. XmlElement* const newNode) throw()
  11984. {
  11985. if (newNode != 0)
  11986. {
  11987. XmlElement* child = firstChildElement;
  11988. XmlElement* previousNode = 0;
  11989. while (child != 0)
  11990. {
  11991. if (child == currentChildElement)
  11992. {
  11993. if (child != newNode)
  11994. {
  11995. if (previousNode == 0)
  11996. firstChildElement = newNode;
  11997. else
  11998. previousNode->nextElement = newNode;
  11999. newNode->nextElement = child->nextElement;
  12000. delete child;
  12001. }
  12002. return true;
  12003. }
  12004. previousNode = child;
  12005. child = child->nextElement;
  12006. }
  12007. }
  12008. return false;
  12009. }
  12010. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  12011. const bool shouldDeleteTheChild) throw()
  12012. {
  12013. if (childToRemove != 0)
  12014. {
  12015. if (firstChildElement == childToRemove)
  12016. {
  12017. firstChildElement = childToRemove->nextElement;
  12018. childToRemove->nextElement = 0;
  12019. }
  12020. else
  12021. {
  12022. XmlElement* child = firstChildElement;
  12023. XmlElement* last = 0;
  12024. while (child != 0)
  12025. {
  12026. if (child == childToRemove)
  12027. {
  12028. if (last == 0)
  12029. firstChildElement = child->nextElement;
  12030. else
  12031. last->nextElement = child->nextElement;
  12032. childToRemove->nextElement = 0;
  12033. break;
  12034. }
  12035. last = child;
  12036. child = child->nextElement;
  12037. }
  12038. }
  12039. if (shouldDeleteTheChild)
  12040. delete childToRemove;
  12041. }
  12042. }
  12043. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  12044. const bool ignoreOrderOfAttributes) const throw()
  12045. {
  12046. if (this != other)
  12047. {
  12048. if (other == 0 || tagName != other->tagName)
  12049. {
  12050. return false;
  12051. }
  12052. if (ignoreOrderOfAttributes)
  12053. {
  12054. int totalAtts = 0;
  12055. const XmlAttributeNode* att = attributes;
  12056. while (att != 0)
  12057. {
  12058. if (! other->compareAttribute (att->name, att->value))
  12059. return false;
  12060. att = att->next;
  12061. ++totalAtts;
  12062. }
  12063. if (totalAtts != other->getNumAttributes())
  12064. return false;
  12065. }
  12066. else
  12067. {
  12068. const XmlAttributeNode* thisAtt = attributes;
  12069. const XmlAttributeNode* otherAtt = other->attributes;
  12070. for (;;)
  12071. {
  12072. if (thisAtt == 0 || otherAtt == 0)
  12073. {
  12074. if (thisAtt == otherAtt) // both 0, so it's a match
  12075. break;
  12076. return false;
  12077. }
  12078. if (thisAtt->name != otherAtt->name
  12079. || thisAtt->value != otherAtt->value)
  12080. {
  12081. return false;
  12082. }
  12083. thisAtt = thisAtt->next;
  12084. otherAtt = otherAtt->next;
  12085. }
  12086. }
  12087. const XmlElement* thisChild = firstChildElement;
  12088. const XmlElement* otherChild = other->firstChildElement;
  12089. for (;;)
  12090. {
  12091. if (thisChild == 0 || otherChild == 0)
  12092. {
  12093. if (thisChild == otherChild) // both 0, so it's a match
  12094. break;
  12095. return false;
  12096. }
  12097. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  12098. return false;
  12099. thisChild = thisChild->nextElement;
  12100. otherChild = otherChild->nextElement;
  12101. }
  12102. }
  12103. return true;
  12104. }
  12105. void XmlElement::deleteAllChildElements() throw()
  12106. {
  12107. while (firstChildElement != 0)
  12108. {
  12109. XmlElement* const nextChild = firstChildElement->nextElement;
  12110. delete firstChildElement;
  12111. firstChildElement = nextChild;
  12112. }
  12113. }
  12114. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  12115. {
  12116. XmlElement* child = firstChildElement;
  12117. while (child != 0)
  12118. {
  12119. if (child->hasTagName (name))
  12120. {
  12121. XmlElement* const nextChild = child->nextElement;
  12122. removeChildElement (child, true);
  12123. child = nextChild;
  12124. }
  12125. else
  12126. {
  12127. child = child->nextElement;
  12128. }
  12129. }
  12130. }
  12131. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  12132. {
  12133. const XmlElement* child = firstChildElement;
  12134. while (child != 0)
  12135. {
  12136. if (child == possibleChild)
  12137. return true;
  12138. child = child->nextElement;
  12139. }
  12140. return false;
  12141. }
  12142. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  12143. {
  12144. if (this == elementToLookFor || elementToLookFor == 0)
  12145. return 0;
  12146. XmlElement* child = firstChildElement;
  12147. while (child != 0)
  12148. {
  12149. if (elementToLookFor == child)
  12150. return this;
  12151. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  12152. if (found != 0)
  12153. return found;
  12154. child = child->nextElement;
  12155. }
  12156. return 0;
  12157. }
  12158. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  12159. {
  12160. XmlElement* e = firstChildElement;
  12161. while (e != 0)
  12162. {
  12163. *elems++ = e;
  12164. e = e->nextElement;
  12165. }
  12166. }
  12167. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  12168. {
  12169. XmlElement* e = firstChildElement = elems[0];
  12170. for (int i = 1; i < num; ++i)
  12171. {
  12172. e->nextElement = elems[i];
  12173. e = e->nextElement;
  12174. }
  12175. e->nextElement = 0;
  12176. }
  12177. bool XmlElement::isTextElement() const throw()
  12178. {
  12179. return tagName.isEmpty();
  12180. }
  12181. static const tchar* const juce_xmltextContentAttributeName = T("text");
  12182. const String XmlElement::getText() const throw()
  12183. {
  12184. jassert (isTextElement()); // you're trying to get the text from an element that
  12185. // isn't actually a text element.. If this contains text sub-nodes, you
  12186. // probably want to use getAllSubText instead.
  12187. return getStringAttribute (juce_xmltextContentAttributeName);
  12188. }
  12189. void XmlElement::setText (const String& newText) throw()
  12190. {
  12191. if (isTextElement())
  12192. {
  12193. setAttribute (juce_xmltextContentAttributeName, newText);
  12194. }
  12195. else
  12196. {
  12197. jassertfalse // you can only change the text in a text element, not a normal one.
  12198. }
  12199. }
  12200. const String XmlElement::getAllSubText() const throw()
  12201. {
  12202. String result;
  12203. String::Concatenator concatenator (result);
  12204. const XmlElement* child = firstChildElement;
  12205. while (child != 0)
  12206. {
  12207. if (child->isTextElement())
  12208. concatenator.append (child->getText());
  12209. child = child->nextElement;
  12210. }
  12211. return result;
  12212. }
  12213. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  12214. const String& defaultReturnValue) const throw()
  12215. {
  12216. const XmlElement* const child = getChildByName (childTagName);
  12217. if (child != 0)
  12218. return child->getAllSubText();
  12219. return defaultReturnValue;
  12220. }
  12221. XmlElement* XmlElement::createTextElement (const String& text) throw()
  12222. {
  12223. XmlElement* const e = new XmlElement ((int) 0);
  12224. e->setAttribute (juce_xmltextContentAttributeName, text);
  12225. return e;
  12226. }
  12227. void XmlElement::addTextElement (const String& text) throw()
  12228. {
  12229. addChildElement (createTextElement (text));
  12230. }
  12231. void XmlElement::deleteAllTextElements() throw()
  12232. {
  12233. XmlElement* child = firstChildElement;
  12234. while (child != 0)
  12235. {
  12236. XmlElement* const next = child->nextElement;
  12237. if (child->isTextElement())
  12238. removeChildElement (child, true);
  12239. child = next;
  12240. }
  12241. }
  12242. END_JUCE_NAMESPACE
  12243. /*** End of inlined file: juce_XmlElement.cpp ***/
  12244. /*** Start of inlined file: juce_InterProcessLock.cpp ***/
  12245. BEGIN_JUCE_NAMESPACE
  12246. // (implemented in the platform-specific code files)
  12247. END_JUCE_NAMESPACE
  12248. /*** End of inlined file: juce_InterProcessLock.cpp ***/
  12249. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  12250. BEGIN_JUCE_NAMESPACE
  12251. ReadWriteLock::ReadWriteLock() throw()
  12252. : numWaitingWriters (0),
  12253. numWriters (0),
  12254. writerThreadId (0)
  12255. {
  12256. }
  12257. ReadWriteLock::~ReadWriteLock() throw()
  12258. {
  12259. jassert (readerThreads.size() == 0);
  12260. jassert (numWriters == 0);
  12261. }
  12262. void ReadWriteLock::enterRead() const throw()
  12263. {
  12264. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12265. const ScopedLock sl (accessLock);
  12266. for (;;)
  12267. {
  12268. jassert (readerThreads.size() % 2 == 0);
  12269. int i;
  12270. for (i = 0; i < readerThreads.size(); i += 2)
  12271. if (readerThreads.getUnchecked(i) == threadId)
  12272. break;
  12273. if (i < readerThreads.size()
  12274. || numWriters + numWaitingWriters == 0
  12275. || (threadId == writerThreadId && numWriters > 0))
  12276. {
  12277. if (i < readerThreads.size())
  12278. {
  12279. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  12280. }
  12281. else
  12282. {
  12283. readerThreads.add (threadId);
  12284. readerThreads.add ((Thread::ThreadID) 1);
  12285. }
  12286. return;
  12287. }
  12288. const ScopedUnlock ul (accessLock);
  12289. waitEvent.wait (100);
  12290. }
  12291. }
  12292. void ReadWriteLock::exitRead() const throw()
  12293. {
  12294. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12295. const ScopedLock sl (accessLock);
  12296. for (int i = 0; i < readerThreads.size(); i += 2)
  12297. {
  12298. if (readerThreads.getUnchecked(i) == threadId)
  12299. {
  12300. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12301. if (newCount == 0)
  12302. {
  12303. readerThreads.removeRange (i, 2);
  12304. waitEvent.signal();
  12305. }
  12306. else
  12307. {
  12308. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12309. }
  12310. return;
  12311. }
  12312. }
  12313. jassertfalse // unlocking a lock that wasn't locked..
  12314. }
  12315. void ReadWriteLock::enterWrite() const throw()
  12316. {
  12317. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12318. const ScopedLock sl (accessLock);
  12319. for (;;)
  12320. {
  12321. if (readerThreads.size() + numWriters == 0
  12322. || threadId == writerThreadId
  12323. || (readerThreads.size() == 2
  12324. && readerThreads.getUnchecked(0) == threadId))
  12325. {
  12326. writerThreadId = threadId;
  12327. ++numWriters;
  12328. break;
  12329. }
  12330. ++numWaitingWriters;
  12331. accessLock.exit();
  12332. waitEvent.wait (100);
  12333. accessLock.enter();
  12334. --numWaitingWriters;
  12335. }
  12336. }
  12337. bool ReadWriteLock::tryEnterWrite() const throw()
  12338. {
  12339. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12340. const ScopedLock sl (accessLock);
  12341. if (readerThreads.size() + numWriters == 0
  12342. || threadId == writerThreadId
  12343. || (readerThreads.size() == 2
  12344. && readerThreads.getUnchecked(0) == threadId))
  12345. {
  12346. writerThreadId = threadId;
  12347. ++numWriters;
  12348. return true;
  12349. }
  12350. return false;
  12351. }
  12352. void ReadWriteLock::exitWrite() const throw()
  12353. {
  12354. const ScopedLock sl (accessLock);
  12355. // check this thread actually had the lock..
  12356. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12357. if (--numWriters == 0)
  12358. {
  12359. writerThreadId = 0;
  12360. waitEvent.signal();
  12361. }
  12362. }
  12363. END_JUCE_NAMESPACE
  12364. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12365. /*** Start of inlined file: juce_Thread.cpp ***/
  12366. BEGIN_JUCE_NAMESPACE
  12367. // these functions are implemented in the platform-specific code.
  12368. void* juce_createThread (void* userData);
  12369. void juce_killThread (void* handle);
  12370. bool juce_setThreadPriority (void* handle, int priority);
  12371. void juce_setCurrentThreadName (const String& name);
  12372. #if JUCE_WIN32
  12373. void juce_CloseThreadHandle (void* handle);
  12374. #endif
  12375. static VoidArray runningThreads;
  12376. static CriticalSection runningThreadsLock;
  12377. void Thread::threadEntryPoint (Thread* const thread)
  12378. {
  12379. {
  12380. const ScopedLock sl (runningThreadsLock);
  12381. runningThreads.add (thread);
  12382. }
  12383. JUCE_TRY
  12384. {
  12385. thread->threadId_ = Thread::getCurrentThreadId();
  12386. if (thread->threadName_.isNotEmpty())
  12387. juce_setCurrentThreadName (thread->threadName_);
  12388. if (thread->startSuspensionEvent_.wait (10000))
  12389. {
  12390. if (thread->affinityMask_ != 0)
  12391. setCurrentThreadAffinityMask (thread->affinityMask_);
  12392. thread->run();
  12393. }
  12394. }
  12395. JUCE_CATCH_ALL_ASSERT
  12396. {
  12397. const ScopedLock sl (runningThreadsLock);
  12398. jassert (runningThreads.contains (thread));
  12399. runningThreads.removeValue (thread);
  12400. }
  12401. #if JUCE_WIN32
  12402. juce_CloseThreadHandle (thread->threadHandle_);
  12403. #endif
  12404. thread->threadHandle_ = 0;
  12405. thread->threadId_ = 0;
  12406. }
  12407. // used to wrap the incoming call from the platform-specific code
  12408. void JUCE_API juce_threadEntryPoint (void* userData)
  12409. {
  12410. Thread::threadEntryPoint ((Thread*) userData);
  12411. }
  12412. Thread::Thread (const String& threadName)
  12413. : threadName_ (threadName),
  12414. threadHandle_ (0),
  12415. threadPriority_ (5),
  12416. threadId_ (0),
  12417. affinityMask_ (0),
  12418. threadShouldExit_ (false)
  12419. {
  12420. }
  12421. Thread::~Thread()
  12422. {
  12423. stopThread (100);
  12424. }
  12425. void Thread::startThread()
  12426. {
  12427. const ScopedLock sl (startStopLock);
  12428. threadShouldExit_ = false;
  12429. if (threadHandle_ == 0)
  12430. {
  12431. threadHandle_ = juce_createThread ((void*) this);
  12432. juce_setThreadPriority (threadHandle_, threadPriority_);
  12433. startSuspensionEvent_.signal();
  12434. }
  12435. }
  12436. void Thread::startThread (const int priority)
  12437. {
  12438. const ScopedLock sl (startStopLock);
  12439. if (threadHandle_ == 0)
  12440. {
  12441. threadPriority_ = priority;
  12442. startThread();
  12443. }
  12444. else
  12445. {
  12446. setPriority (priority);
  12447. }
  12448. }
  12449. bool Thread::isThreadRunning() const
  12450. {
  12451. return threadHandle_ != 0;
  12452. }
  12453. void Thread::signalThreadShouldExit()
  12454. {
  12455. threadShouldExit_ = true;
  12456. }
  12457. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12458. {
  12459. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12460. jassert (getThreadId() != getCurrentThreadId());
  12461. const int sleepMsPerIteration = 5;
  12462. int count = timeOutMilliseconds / sleepMsPerIteration;
  12463. while (isThreadRunning())
  12464. {
  12465. if (timeOutMilliseconds > 0 && --count < 0)
  12466. return false;
  12467. sleep (sleepMsPerIteration);
  12468. }
  12469. return true;
  12470. }
  12471. void Thread::stopThread (const int timeOutMilliseconds)
  12472. {
  12473. // agh! You can't stop the thread that's calling this method! How on earth
  12474. // would that work??
  12475. jassert (getCurrentThreadId() != getThreadId());
  12476. const ScopedLock sl (startStopLock);
  12477. if (isThreadRunning())
  12478. {
  12479. signalThreadShouldExit();
  12480. notify();
  12481. if (timeOutMilliseconds != 0)
  12482. waitForThreadToExit (timeOutMilliseconds);
  12483. if (isThreadRunning())
  12484. {
  12485. // very bad karma if this point is reached, as
  12486. // there are bound to be locks and events left in
  12487. // silly states when a thread is killed by force..
  12488. jassertfalse
  12489. Logger::writeToLog ("!! killing thread by force !!");
  12490. juce_killThread (threadHandle_);
  12491. threadHandle_ = 0;
  12492. threadId_ = 0;
  12493. const ScopedLock sl2 (runningThreadsLock);
  12494. runningThreads.removeValue (this);
  12495. }
  12496. }
  12497. }
  12498. bool Thread::setPriority (const int priority)
  12499. {
  12500. const ScopedLock sl (startStopLock);
  12501. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12502. if (worked)
  12503. threadPriority_ = priority;
  12504. return worked;
  12505. }
  12506. bool Thread::setCurrentThreadPriority (const int priority)
  12507. {
  12508. return juce_setThreadPriority (0, priority);
  12509. }
  12510. void Thread::setAffinityMask (const uint32 affinityMask)
  12511. {
  12512. affinityMask_ = affinityMask;
  12513. }
  12514. bool Thread::wait (const int timeOutMilliseconds) const
  12515. {
  12516. return defaultEvent_.wait (timeOutMilliseconds);
  12517. }
  12518. void Thread::notify() const
  12519. {
  12520. defaultEvent_.signal();
  12521. }
  12522. int Thread::getNumRunningThreads()
  12523. {
  12524. return runningThreads.size();
  12525. }
  12526. Thread* Thread::getCurrentThread()
  12527. {
  12528. const ThreadID thisId = getCurrentThreadId();
  12529. const ScopedLock sl (runningThreadsLock);
  12530. for (int i = runningThreads.size(); --i >= 0;)
  12531. {
  12532. Thread* const t = (Thread*) runningThreads.getUnchecked(i);
  12533. if (t->threadId_ == thisId)
  12534. return t;
  12535. }
  12536. return 0;
  12537. }
  12538. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12539. {
  12540. {
  12541. const ScopedLock sl (runningThreadsLock);
  12542. for (int i = runningThreads.size(); --i >= 0;)
  12543. ((Thread*) runningThreads.getUnchecked(i))->signalThreadShouldExit();
  12544. }
  12545. for (;;)
  12546. {
  12547. runningThreadsLock.enter();
  12548. Thread* const t = (Thread*) runningThreads[0];
  12549. runningThreadsLock.exit();
  12550. if (t == 0)
  12551. break;
  12552. t->stopThread (timeOutMilliseconds);
  12553. }
  12554. }
  12555. END_JUCE_NAMESPACE
  12556. /*** End of inlined file: juce_Thread.cpp ***/
  12557. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12558. BEGIN_JUCE_NAMESPACE
  12559. ThreadPoolJob::ThreadPoolJob (const String& name)
  12560. : jobName (name),
  12561. pool (0),
  12562. shouldStop (false),
  12563. isActive (false),
  12564. shouldBeDeleted (false)
  12565. {
  12566. }
  12567. ThreadPoolJob::~ThreadPoolJob()
  12568. {
  12569. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12570. // to remove it first!
  12571. jassert (pool == 0 || ! pool->contains (this));
  12572. }
  12573. const String ThreadPoolJob::getJobName() const
  12574. {
  12575. return jobName;
  12576. }
  12577. void ThreadPoolJob::setJobName (const String& newName)
  12578. {
  12579. jobName = newName;
  12580. }
  12581. void ThreadPoolJob::signalJobShouldExit()
  12582. {
  12583. shouldStop = true;
  12584. }
  12585. class ThreadPool::ThreadPoolThread : public Thread
  12586. {
  12587. public:
  12588. ThreadPoolThread (ThreadPool& pool_)
  12589. : Thread (T("Pool")),
  12590. pool (pool_),
  12591. busy (false)
  12592. {
  12593. }
  12594. ~ThreadPoolThread()
  12595. {
  12596. }
  12597. void run()
  12598. {
  12599. while (! threadShouldExit())
  12600. {
  12601. if (! pool.runNextJob())
  12602. wait (500);
  12603. }
  12604. }
  12605. private:
  12606. ThreadPool& pool;
  12607. bool volatile busy;
  12608. ThreadPoolThread (const ThreadPoolThread&);
  12609. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12610. };
  12611. ThreadPool::ThreadPool (const int numThreads,
  12612. const bool startThreadsOnlyWhenNeeded,
  12613. const int stopThreadsWhenNotUsedTimeoutMs)
  12614. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12615. priority (5)
  12616. {
  12617. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12618. for (int i = jmax (1, numThreads); --i >= 0;)
  12619. threads.add (new ThreadPoolThread (*this));
  12620. if (! startThreadsOnlyWhenNeeded)
  12621. for (int i = threads.size(); --i >= 0;)
  12622. threads.getUnchecked(i)->startThread (priority);
  12623. }
  12624. ThreadPool::~ThreadPool()
  12625. {
  12626. removeAllJobs (true, 4000);
  12627. int i;
  12628. for (i = threads.size(); --i >= 0;)
  12629. threads.getUnchecked(i)->signalThreadShouldExit();
  12630. for (i = threads.size(); --i >= 0;)
  12631. threads.getUnchecked(i)->stopThread (500);
  12632. }
  12633. void ThreadPool::addJob (ThreadPoolJob* const job)
  12634. {
  12635. jassert (job != 0);
  12636. jassert (job->pool == 0);
  12637. if (job->pool == 0)
  12638. {
  12639. job->pool = this;
  12640. job->shouldStop = false;
  12641. job->isActive = false;
  12642. {
  12643. const ScopedLock sl (lock);
  12644. jobs.add (job);
  12645. int numRunning = 0;
  12646. for (int i = threads.size(); --i >= 0;)
  12647. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12648. ++numRunning;
  12649. if (numRunning < threads.size())
  12650. {
  12651. bool startedOne = false;
  12652. int n = 1000;
  12653. while (--n >= 0 && ! startedOne)
  12654. {
  12655. for (int i = threads.size(); --i >= 0;)
  12656. {
  12657. if (! threads.getUnchecked(i)->isThreadRunning())
  12658. {
  12659. threads.getUnchecked(i)->startThread (priority);
  12660. startedOne = true;
  12661. break;
  12662. }
  12663. }
  12664. if (! startedOne)
  12665. Thread::sleep (2);
  12666. }
  12667. }
  12668. }
  12669. for (int i = threads.size(); --i >= 0;)
  12670. threads.getUnchecked(i)->notify();
  12671. }
  12672. }
  12673. int ThreadPool::getNumJobs() const
  12674. {
  12675. return jobs.size();
  12676. }
  12677. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12678. {
  12679. const ScopedLock sl (lock);
  12680. return (ThreadPoolJob*) jobs [index];
  12681. }
  12682. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12683. {
  12684. const ScopedLock sl (lock);
  12685. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12686. }
  12687. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12688. {
  12689. const ScopedLock sl (lock);
  12690. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12691. }
  12692. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12693. const int timeOutMs) const
  12694. {
  12695. if (job != 0)
  12696. {
  12697. const uint32 start = Time::getMillisecondCounter();
  12698. while (contains (job))
  12699. {
  12700. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12701. return false;
  12702. jobFinishedSignal.wait (2);
  12703. }
  12704. }
  12705. return true;
  12706. }
  12707. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12708. const bool interruptIfRunning,
  12709. const int timeOutMs)
  12710. {
  12711. if (job != 0)
  12712. {
  12713. lock.enter();
  12714. if (jobs.contains (job))
  12715. {
  12716. if (job->isActive)
  12717. {
  12718. if (interruptIfRunning)
  12719. job->signalJobShouldExit();
  12720. lock.exit();
  12721. return waitForJobToFinish (job, timeOutMs);
  12722. }
  12723. else
  12724. {
  12725. jobs.removeValue (job);
  12726. }
  12727. }
  12728. lock.exit();
  12729. }
  12730. return true;
  12731. }
  12732. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12733. const int timeOutMs,
  12734. const bool deleteInactiveJobs,
  12735. ThreadPool::JobSelector* selectedJobsToRemove)
  12736. {
  12737. Array <ThreadPoolJob*> jobsToWaitFor;
  12738. {
  12739. const ScopedLock sl (lock);
  12740. for (int i = jobs.size(); --i >= 0;)
  12741. {
  12742. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12743. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12744. {
  12745. if (job->isActive)
  12746. {
  12747. jobsToWaitFor.add (job);
  12748. if (interruptRunningJobs)
  12749. job->signalJobShouldExit();
  12750. }
  12751. else
  12752. {
  12753. jobs.remove (i);
  12754. if (deleteInactiveJobs)
  12755. delete job;
  12756. }
  12757. }
  12758. }
  12759. }
  12760. const uint32 start = Time::getMillisecondCounter();
  12761. for (;;)
  12762. {
  12763. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12764. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12765. jobsToWaitFor.remove (i);
  12766. if (jobsToWaitFor.size() == 0)
  12767. break;
  12768. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12769. return false;
  12770. jobFinishedSignal.wait (20);
  12771. }
  12772. return true;
  12773. }
  12774. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12775. {
  12776. StringArray s;
  12777. const ScopedLock sl (lock);
  12778. for (int i = 0; i < jobs.size(); ++i)
  12779. {
  12780. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12781. if (job->isActive || ! onlyReturnActiveJobs)
  12782. s.add (job->getJobName());
  12783. }
  12784. return s;
  12785. }
  12786. bool ThreadPool::setThreadPriorities (const int newPriority)
  12787. {
  12788. bool ok = true;
  12789. if (priority != newPriority)
  12790. {
  12791. priority = newPriority;
  12792. for (int i = threads.size(); --i >= 0;)
  12793. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12794. ok = false;
  12795. }
  12796. return ok;
  12797. }
  12798. bool ThreadPool::runNextJob()
  12799. {
  12800. ThreadPoolJob* job = 0;
  12801. {
  12802. const ScopedLock sl (lock);
  12803. for (int i = 0; i < jobs.size(); ++i)
  12804. {
  12805. job = jobs[i];
  12806. if (job != 0 && ! (job->isActive || job->shouldStop))
  12807. break;
  12808. job = 0;
  12809. }
  12810. if (job != 0)
  12811. job->isActive = true;
  12812. }
  12813. if (job != 0)
  12814. {
  12815. JUCE_TRY
  12816. {
  12817. ThreadPoolJob::JobStatus result = job->runJob();
  12818. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12819. const ScopedLock sl (lock);
  12820. if (jobs.contains (job))
  12821. {
  12822. job->isActive = false;
  12823. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12824. {
  12825. job->pool = 0;
  12826. job->shouldStop = true;
  12827. jobs.removeValue (job);
  12828. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12829. delete job;
  12830. jobFinishedSignal.signal();
  12831. }
  12832. else
  12833. {
  12834. // move the job to the end of the queue if it wants another go
  12835. jobs.move (jobs.indexOf (job), -1);
  12836. }
  12837. }
  12838. }
  12839. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12840. catch (...)
  12841. {
  12842. const ScopedLock sl (lock);
  12843. jobs.removeValue (job);
  12844. }
  12845. #endif
  12846. }
  12847. else
  12848. {
  12849. if (threadStopTimeout > 0
  12850. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12851. {
  12852. const ScopedLock sl (lock);
  12853. if (jobs.size() == 0)
  12854. for (int i = threads.size(); --i >= 0;)
  12855. threads.getUnchecked(i)->signalThreadShouldExit();
  12856. }
  12857. else
  12858. {
  12859. return false;
  12860. }
  12861. }
  12862. return true;
  12863. }
  12864. END_JUCE_NAMESPACE
  12865. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12866. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12867. BEGIN_JUCE_NAMESPACE
  12868. TimeSliceThread::TimeSliceThread (const String& threadName)
  12869. : Thread (threadName),
  12870. index (0),
  12871. clientBeingCalled (0),
  12872. clientsChanged (false)
  12873. {
  12874. }
  12875. TimeSliceThread::~TimeSliceThread()
  12876. {
  12877. stopThread (2000);
  12878. }
  12879. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12880. {
  12881. const ScopedLock sl (listLock);
  12882. clients.addIfNotAlreadyThere (client);
  12883. clientsChanged = true;
  12884. notify();
  12885. }
  12886. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12887. {
  12888. const ScopedLock sl1 (listLock);
  12889. clientsChanged = true;
  12890. // if there's a chance we're in the middle of calling this client, we need to
  12891. // also lock the outer lock..
  12892. if (clientBeingCalled == client)
  12893. {
  12894. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12895. const ScopedLock sl2 (callbackLock);
  12896. const ScopedLock sl3 (listLock);
  12897. clients.removeValue (client);
  12898. }
  12899. else
  12900. {
  12901. clients.removeValue (client);
  12902. }
  12903. }
  12904. int TimeSliceThread::getNumClients() const
  12905. {
  12906. return clients.size();
  12907. }
  12908. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12909. {
  12910. const ScopedLock sl (listLock);
  12911. return clients [i];
  12912. }
  12913. void TimeSliceThread::run()
  12914. {
  12915. int numCallsSinceBusy = 0;
  12916. while (! threadShouldExit())
  12917. {
  12918. int timeToWait = 500;
  12919. {
  12920. const ScopedLock sl (callbackLock);
  12921. {
  12922. const ScopedLock sl2 (listLock);
  12923. if (clients.size() > 0)
  12924. {
  12925. index = (index + 1) % clients.size();
  12926. clientBeingCalled = clients [index];
  12927. }
  12928. else
  12929. {
  12930. index = 0;
  12931. clientBeingCalled = 0;
  12932. }
  12933. if (clientsChanged)
  12934. {
  12935. clientsChanged = false;
  12936. numCallsSinceBusy = 0;
  12937. }
  12938. }
  12939. if (clientBeingCalled != 0)
  12940. {
  12941. if (clientBeingCalled->useTimeSlice())
  12942. numCallsSinceBusy = 0;
  12943. else
  12944. ++numCallsSinceBusy;
  12945. if (numCallsSinceBusy >= clients.size())
  12946. timeToWait = 500;
  12947. else if (index == 0)
  12948. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12949. else
  12950. timeToWait = 0;
  12951. }
  12952. }
  12953. if (timeToWait > 0)
  12954. wait (timeToWait);
  12955. }
  12956. }
  12957. END_JUCE_NAMESPACE
  12958. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12959. #endif
  12960. #if JUCE_BUILD_MISC
  12961. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12962. BEGIN_JUCE_NAMESPACE
  12963. class ValueTreeSetPropertyAction : public UndoableAction
  12964. {
  12965. public:
  12966. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12967. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12968. : target (target_), name (name_), newValue (newValue_),
  12969. isAddingNewProperty (isAddingNewProperty_),
  12970. isDeletingProperty (isDeletingProperty_)
  12971. {
  12972. if (! isAddingNewProperty)
  12973. oldValue = target_->getProperty (name_);
  12974. }
  12975. ~ValueTreeSetPropertyAction() {}
  12976. bool perform()
  12977. {
  12978. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12979. if (isDeletingProperty)
  12980. target->removeProperty (name, 0);
  12981. else
  12982. target->setProperty (name, newValue, 0);
  12983. return true;
  12984. }
  12985. bool undo()
  12986. {
  12987. if (isAddingNewProperty)
  12988. target->removeProperty (name, 0);
  12989. else
  12990. target->setProperty (name, oldValue, 0);
  12991. return true;
  12992. }
  12993. int getSizeInUnits()
  12994. {
  12995. return (int) sizeof (*this); //xxx should be more accurate
  12996. }
  12997. private:
  12998. const ValueTree::SharedObjectPtr target;
  12999. const var::identifier name;
  13000. const var newValue;
  13001. var oldValue;
  13002. const bool isAddingNewProperty, isDeletingProperty;
  13003. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  13004. const ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  13005. };
  13006. class ValueTreeChildChangeAction : public UndoableAction
  13007. {
  13008. public:
  13009. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  13010. const ValueTree::SharedObjectPtr& newChild_)
  13011. : target (target_),
  13012. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  13013. childIndex (childIndex_),
  13014. isDeleting (newChild_ == 0)
  13015. {
  13016. jassert (child != 0);
  13017. }
  13018. ~ValueTreeChildChangeAction() {}
  13019. bool perform()
  13020. {
  13021. if (isDeleting)
  13022. target->removeChild (childIndex, 0);
  13023. else
  13024. target->addChild (child, childIndex, 0);
  13025. return true;
  13026. }
  13027. bool undo()
  13028. {
  13029. if (isDeleting)
  13030. target->addChild (child, childIndex, 0);
  13031. else
  13032. target->removeChild (childIndex, 0);
  13033. return true;
  13034. }
  13035. int getSizeInUnits()
  13036. {
  13037. return (int) sizeof (*this); //xxx should be more accurate
  13038. }
  13039. private:
  13040. const ValueTree::SharedObjectPtr target, child;
  13041. const int childIndex;
  13042. const bool isDeleting;
  13043. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  13044. const ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  13045. };
  13046. ValueTree::SharedObject::SharedObject (const String& type_)
  13047. : type (type_), parent (0)
  13048. {
  13049. }
  13050. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  13051. : type (other.type), properties (other.properties), parent (0)
  13052. {
  13053. for (int i = 0; i < other.children.size(); ++i)
  13054. children.add (new SharedObject (*other.children.getUnchecked(i)));
  13055. }
  13056. ValueTree::SharedObject::~SharedObject()
  13057. {
  13058. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  13059. for (int i = children.size(); --i >= 0;)
  13060. {
  13061. const SharedObjectPtr c (children.getUnchecked(i));
  13062. c->parent = 0;
  13063. children.remove (i);
  13064. c->sendParentChangeMessage();
  13065. }
  13066. }
  13067. void ValueTree::deliverPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  13068. {
  13069. for (int i = listeners.size(); --i >= 0;)
  13070. {
  13071. ValueTree::Listener* const l = listeners[i];
  13072. if (l != 0)
  13073. l->valueTreePropertyChanged (tree, property);
  13074. }
  13075. }
  13076. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  13077. {
  13078. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13079. {
  13080. ValueTree* const v = valueTreesWithListeners[i];
  13081. if (v != 0)
  13082. v->deliverPropertyChangeMessage (tree, property);
  13083. }
  13084. }
  13085. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  13086. {
  13087. ValueTree tree (this);
  13088. ValueTree::SharedObject* t = this;
  13089. while (t != 0)
  13090. {
  13091. t->sendPropertyChangeMessage (tree, property);
  13092. t = t->parent;
  13093. }
  13094. }
  13095. void ValueTree::deliverChildChangeMessage (ValueTree& tree)
  13096. {
  13097. for (int i = listeners.size(); --i >= 0;)
  13098. {
  13099. ValueTree::Listener* const l = listeners[i];
  13100. if (l != 0)
  13101. l->valueTreeChildrenChanged (tree);
  13102. }
  13103. }
  13104. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  13105. {
  13106. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13107. {
  13108. ValueTree* const v = valueTreesWithListeners[i];
  13109. if (v != 0)
  13110. v->deliverChildChangeMessage (tree);
  13111. }
  13112. }
  13113. void ValueTree::SharedObject::sendChildChangeMessage()
  13114. {
  13115. ValueTree tree (this);
  13116. ValueTree::SharedObject* t = this;
  13117. while (t != 0)
  13118. {
  13119. t->sendChildChangeMessage (tree);
  13120. t = t->parent;
  13121. }
  13122. }
  13123. void ValueTree::deliverParentChangeMessage (ValueTree& tree)
  13124. {
  13125. for (int i = listeners.size(); --i >= 0;)
  13126. {
  13127. ValueTree::Listener* const l = listeners[i];
  13128. if (l != 0)
  13129. l->valueTreeParentChanged (tree);
  13130. }
  13131. }
  13132. void ValueTree::SharedObject::sendParentChangeMessage()
  13133. {
  13134. ValueTree tree (this);
  13135. int i;
  13136. for (i = children.size(); --i >= 0;)
  13137. {
  13138. SharedObject* const t = children[i];
  13139. if (t != 0)
  13140. t->sendParentChangeMessage();
  13141. }
  13142. for (i = valueTreesWithListeners.size(); --i >= 0;)
  13143. {
  13144. ValueTree* const v = valueTreesWithListeners[i];
  13145. if (v != 0)
  13146. v->deliverParentChangeMessage (tree);
  13147. }
  13148. }
  13149. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  13150. {
  13151. return properties [name];
  13152. }
  13153. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13154. {
  13155. if (undoManager == 0)
  13156. {
  13157. if (properties.set (name, newValue))
  13158. sendPropertyChangeMessage (name);
  13159. }
  13160. else
  13161. {
  13162. var* const existingValue = properties.getItem (name);
  13163. if (existingValue != 0)
  13164. {
  13165. if (*existingValue != newValue)
  13166. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  13167. }
  13168. else
  13169. {
  13170. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  13171. }
  13172. }
  13173. }
  13174. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  13175. {
  13176. return properties.contains (name);
  13177. }
  13178. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13179. {
  13180. if (undoManager == 0)
  13181. {
  13182. if (properties.remove (name))
  13183. sendPropertyChangeMessage (name);
  13184. }
  13185. else
  13186. {
  13187. if (properties.contains (name))
  13188. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  13189. }
  13190. }
  13191. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  13192. {
  13193. if (undoManager == 0)
  13194. {
  13195. while (properties.size() > 0)
  13196. {
  13197. const var::identifier name (properties.getName (properties.size() - 1));
  13198. properties.remove (name);
  13199. sendPropertyChangeMessage (name);
  13200. }
  13201. }
  13202. else
  13203. {
  13204. for (int i = properties.size(); --i >= 0;)
  13205. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  13206. }
  13207. }
  13208. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  13209. {
  13210. for (int i = 0; i < children.size(); ++i)
  13211. if (children.getUnchecked(i)->type == typeToMatch)
  13212. return (SharedObject*) children.getUnchecked(i);
  13213. return (SharedObject*) 0;
  13214. }
  13215. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13216. {
  13217. for (int i = 0; i < children.size(); ++i)
  13218. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  13219. return (SharedObject*) children.getUnchecked(i);
  13220. return (SharedObject*) 0;
  13221. }
  13222. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  13223. {
  13224. const SharedObject* p = parent;
  13225. while (p != 0)
  13226. {
  13227. if (p == possibleParent)
  13228. return true;
  13229. p = p->parent;
  13230. }
  13231. return false;
  13232. }
  13233. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  13234. {
  13235. if (child != 0 && child->parent != this)
  13236. {
  13237. if (child != this && ! isAChildOf (child))
  13238. {
  13239. // You should always make sure that a child is removed from its previous parent before
  13240. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  13241. // undomanager should be used when removing it from its current parent..
  13242. jassert (child->parent == 0);
  13243. if (child->parent != 0)
  13244. {
  13245. jassert (child->parent->children.indexOf (child) >= 0);
  13246. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  13247. }
  13248. if (undoManager == 0)
  13249. {
  13250. children.insert (index, child);
  13251. child->parent = this;
  13252. sendChildChangeMessage();
  13253. child->sendParentChangeMessage();
  13254. }
  13255. else
  13256. {
  13257. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  13258. }
  13259. }
  13260. else
  13261. {
  13262. // You're attempting to create a recursive loop! A node
  13263. // can't be a child of one of its own children!
  13264. jassertfalse
  13265. }
  13266. }
  13267. }
  13268. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  13269. {
  13270. const SharedObjectPtr child (children [childIndex]);
  13271. if (child != 0)
  13272. {
  13273. if (undoManager == 0)
  13274. {
  13275. children.remove (childIndex);
  13276. child->parent = 0;
  13277. sendChildChangeMessage();
  13278. child->sendParentChangeMessage();
  13279. }
  13280. else
  13281. {
  13282. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  13283. }
  13284. }
  13285. }
  13286. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  13287. {
  13288. while (children.size() > 0)
  13289. removeChild (children.size() - 1, undoManager);
  13290. }
  13291. ValueTree::ValueTree (const String& type_)
  13292. : object (new ValueTree::SharedObject (type_))
  13293. {
  13294. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  13295. }
  13296. ValueTree::ValueTree (SharedObject* const object_)
  13297. : object (object_)
  13298. {
  13299. }
  13300. ValueTree::ValueTree (const ValueTree& other)
  13301. : object (other.object)
  13302. {
  13303. }
  13304. const ValueTree& ValueTree::operator= (const ValueTree& other)
  13305. {
  13306. if (listeners.size() > 0)
  13307. {
  13308. if (object != 0)
  13309. object->valueTreesWithListeners.removeValue (this);
  13310. if (other.object != 0)
  13311. other.object->valueTreesWithListeners.add (this);
  13312. }
  13313. object = other.object;
  13314. return *this;
  13315. }
  13316. ValueTree::~ValueTree()
  13317. {
  13318. if (listeners.size() > 0 && object != 0)
  13319. object->valueTreesWithListeners.removeValue (this);
  13320. }
  13321. bool ValueTree::operator== (const ValueTree& other) const
  13322. {
  13323. return object == other.object;
  13324. }
  13325. bool ValueTree::operator!= (const ValueTree& other) const
  13326. {
  13327. return object != other.object;
  13328. }
  13329. ValueTree ValueTree::createCopy() const
  13330. {
  13331. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13332. }
  13333. bool ValueTree::hasType (const String& typeName) const
  13334. {
  13335. return object != 0 && object->type == typeName;
  13336. }
  13337. const String ValueTree::getType() const
  13338. {
  13339. return object != 0 ? object->type : String::empty;
  13340. }
  13341. ValueTree ValueTree::getParent() const
  13342. {
  13343. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13344. }
  13345. const var& ValueTree::operator[] (const var::identifier& name) const
  13346. {
  13347. return object == 0 ? var::null : object->getProperty (name);
  13348. }
  13349. const var& ValueTree::getProperty (const var::identifier& name) const
  13350. {
  13351. return object == 0 ? var::null : object->getProperty (name);
  13352. }
  13353. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13354. {
  13355. jassert (name.name.isNotEmpty());
  13356. if (object != 0 && name.name.isNotEmpty())
  13357. object->setProperty (name, newValue, undoManager);
  13358. }
  13359. bool ValueTree::hasProperty (const var::identifier& name) const
  13360. {
  13361. return object != 0 && object->hasProperty (name);
  13362. }
  13363. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13364. {
  13365. if (object != 0)
  13366. object->removeProperty (name, undoManager);
  13367. }
  13368. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13369. {
  13370. if (object != 0)
  13371. object->removeAllProperties (undoManager);
  13372. }
  13373. int ValueTree::getNumProperties() const
  13374. {
  13375. return object == 0 ? 0 : object->properties.size();
  13376. }
  13377. const var::identifier ValueTree::getPropertyName (int index) const
  13378. {
  13379. return (object == 0) ? var::identifier()
  13380. : object->properties.getName (index);
  13381. }
  13382. class ValueTreePropertyValueSource : public Value::ValueSource,
  13383. public ValueTree::Listener
  13384. {
  13385. public:
  13386. ValueTreePropertyValueSource (const ValueTree& tree_,
  13387. const var::identifier& property_,
  13388. UndoManager* const undoManager_)
  13389. : tree (tree_),
  13390. property (property_),
  13391. undoManager (undoManager_)
  13392. {
  13393. tree.addListener (this);
  13394. }
  13395. ~ValueTreePropertyValueSource()
  13396. {
  13397. tree.removeListener (this);
  13398. }
  13399. const var getValue() const
  13400. {
  13401. return tree [property];
  13402. }
  13403. void setValue (const var& newValue)
  13404. {
  13405. tree.setProperty (property, newValue, undoManager);
  13406. }
  13407. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13408. {
  13409. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13410. sendChangeMessage (false);
  13411. }
  13412. void valueTreeChildrenChanged (ValueTree&) {}
  13413. void valueTreeParentChanged (ValueTree&) {}
  13414. private:
  13415. ValueTree tree;
  13416. const var::identifier property;
  13417. UndoManager* const undoManager;
  13418. const ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13419. };
  13420. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13421. {
  13422. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13423. }
  13424. int ValueTree::getNumChildren() const
  13425. {
  13426. return object == 0 ? 0 : object->children.size();
  13427. }
  13428. ValueTree ValueTree::getChild (int index) const
  13429. {
  13430. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13431. }
  13432. ValueTree ValueTree::getChildWithName (const String& type) const
  13433. {
  13434. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13435. }
  13436. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13437. {
  13438. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13439. }
  13440. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13441. {
  13442. return object != 0 && object->isAChildOf (possibleParent.object);
  13443. }
  13444. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13445. {
  13446. if (object != 0)
  13447. object->addChild (child.object, index, undoManager);
  13448. }
  13449. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13450. {
  13451. if (object != 0)
  13452. object->removeChild (childIndex, undoManager);
  13453. }
  13454. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13455. {
  13456. if (object != 0)
  13457. object->removeChild (object->children.indexOf (child.object), undoManager);
  13458. }
  13459. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13460. {
  13461. if (object != 0)
  13462. object->removeAllChildren (undoManager);
  13463. }
  13464. void ValueTree::addListener (Listener* listener)
  13465. {
  13466. if (listener != 0)
  13467. {
  13468. if (listeners.size() == 0 && object != 0)
  13469. object->valueTreesWithListeners.add (this);
  13470. listeners.add (listener);
  13471. }
  13472. }
  13473. void ValueTree::removeListener (Listener* listener)
  13474. {
  13475. listeners.removeValue (listener);
  13476. if (listeners.size() == 0 && object != 0)
  13477. object->valueTreesWithListeners.removeValue (this);
  13478. }
  13479. XmlElement* ValueTree::SharedObject::createXml() const
  13480. {
  13481. XmlElement* xml = new XmlElement (type);
  13482. int i;
  13483. for (i = 0; i < properties.size(); ++i)
  13484. {
  13485. var::identifier name (properties.getName(i));
  13486. const var& v = properties [name];
  13487. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13488. xml->setAttribute (name.name, v.toString());
  13489. }
  13490. for (i = 0; i < children.size(); ++i)
  13491. xml->addChildElement (children.getUnchecked(i)->createXml());
  13492. return xml;
  13493. }
  13494. XmlElement* ValueTree::createXml() const
  13495. {
  13496. return object != 0 ? object->createXml() : 0;
  13497. }
  13498. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13499. {
  13500. ValueTree v (xml.getTagName());
  13501. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13502. for (int i = 0; i < numAtts; ++i)
  13503. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13504. forEachXmlChildElement (xml, e)
  13505. {
  13506. v.addChild (fromXml (*e), -1, 0);
  13507. }
  13508. return v;
  13509. }
  13510. void ValueTree::writeToStream (OutputStream& output)
  13511. {
  13512. output.writeString (getType());
  13513. const int numProps = getNumProperties();
  13514. output.writeCompressedInt (numProps);
  13515. int i;
  13516. for (i = 0; i < numProps; ++i)
  13517. {
  13518. const var::identifier name (getPropertyName(i));
  13519. output.writeString (name.name);
  13520. getProperty(name).writeToStream (output);
  13521. }
  13522. const int numChildren = getNumChildren();
  13523. output.writeCompressedInt (numChildren);
  13524. for (i = 0; i < numChildren; ++i)
  13525. getChild (i).writeToStream (output);
  13526. }
  13527. ValueTree ValueTree::readFromStream (InputStream& input)
  13528. {
  13529. String type (input.readString());
  13530. if (type.isEmpty())
  13531. return ValueTree ((SharedObject*) 0);
  13532. ValueTree v (type);
  13533. const int numProps = input.readCompressedInt();
  13534. if (numProps < 0)
  13535. {
  13536. jassertfalse // trying to read corrupted data!
  13537. return v;
  13538. }
  13539. int i;
  13540. for (i = 0; i < numProps; ++i)
  13541. {
  13542. const String name (input.readString());
  13543. jassert (name.isNotEmpty());
  13544. const var value (var::readFromStream (input));
  13545. v.setProperty (name, value, 0);
  13546. }
  13547. const int numChildren = input.readCompressedInt();
  13548. for (i = 0; i < numChildren; ++i)
  13549. v.addChild (readFromStream (input), -1, 0);
  13550. return v;
  13551. }
  13552. END_JUCE_NAMESPACE
  13553. /*** End of inlined file: juce_ValueTree.cpp ***/
  13554. /*** Start of inlined file: juce_Value.cpp ***/
  13555. BEGIN_JUCE_NAMESPACE
  13556. Value::ValueSource::ValueSource()
  13557. {
  13558. }
  13559. Value::ValueSource::~ValueSource()
  13560. {
  13561. }
  13562. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13563. {
  13564. if (synchronous)
  13565. {
  13566. for (int i = valuesWithListeners.size(); --i >= 0;)
  13567. {
  13568. Value* const v = valuesWithListeners[i];
  13569. if (v != 0)
  13570. v->callListeners();
  13571. }
  13572. }
  13573. else
  13574. {
  13575. triggerAsyncUpdate();
  13576. }
  13577. }
  13578. void Value::ValueSource::handleAsyncUpdate()
  13579. {
  13580. sendChangeMessage (true);
  13581. }
  13582. class SimpleValueSource : public Value::ValueSource
  13583. {
  13584. public:
  13585. SimpleValueSource()
  13586. {
  13587. }
  13588. SimpleValueSource (const var& initialValue)
  13589. : value (initialValue)
  13590. {
  13591. }
  13592. ~SimpleValueSource()
  13593. {
  13594. }
  13595. const var getValue() const
  13596. {
  13597. return value;
  13598. }
  13599. void setValue (const var& newValue)
  13600. {
  13601. if (newValue != value)
  13602. {
  13603. value = newValue;
  13604. sendChangeMessage (false);
  13605. }
  13606. }
  13607. private:
  13608. var value;
  13609. SimpleValueSource (const SimpleValueSource&);
  13610. const SimpleValueSource& operator= (const SimpleValueSource&);
  13611. };
  13612. Value::Value()
  13613. : value (new SimpleValueSource())
  13614. {
  13615. }
  13616. Value::Value (ValueSource* const value_)
  13617. : value (value_)
  13618. {
  13619. jassert (value_ != 0);
  13620. }
  13621. Value::Value (const var& initialValue)
  13622. : value (new SimpleValueSource (initialValue))
  13623. {
  13624. }
  13625. Value::Value (const Value& other)
  13626. : value (other.value)
  13627. {
  13628. }
  13629. const Value& Value::operator= (const Value& other)
  13630. {
  13631. value = other.value;
  13632. return *this;
  13633. }
  13634. Value::~Value()
  13635. {
  13636. if (listeners.size() > 0)
  13637. value->valuesWithListeners.removeValue (this);
  13638. }
  13639. const var Value::getValue() const
  13640. {
  13641. return value->getValue();
  13642. }
  13643. void Value::setValue (const var& newValue)
  13644. {
  13645. value->setValue (newValue);
  13646. }
  13647. const String Value::toString() const
  13648. {
  13649. return value->getValue().toString();
  13650. }
  13651. const Value& Value::operator= (const var& newValue)
  13652. {
  13653. value->setValue (newValue);
  13654. return *this;
  13655. }
  13656. void Value::referTo (const Value& valueToReferTo)
  13657. {
  13658. if (valueToReferTo.value != value)
  13659. {
  13660. if (listeners.size() > 0)
  13661. {
  13662. value->valuesWithListeners.removeValue (this);
  13663. valueToReferTo.value->valuesWithListeners.add (this);
  13664. }
  13665. value = valueToReferTo.value;
  13666. callListeners();
  13667. }
  13668. }
  13669. bool Value::refersToSameSourceAs (const Value& other) const
  13670. {
  13671. return value == other.value;
  13672. }
  13673. bool Value::operator== (const Value& other) const
  13674. {
  13675. return value == other.value || value->getValue() == other.getValue();
  13676. }
  13677. bool Value::operator!= (const Value& other) const
  13678. {
  13679. return value != other.value && value->getValue() != other.getValue();
  13680. }
  13681. void Value::addListener (Listener* const listener)
  13682. {
  13683. if (listener != 0)
  13684. {
  13685. if (listeners.size() == 0)
  13686. value->valuesWithListeners.add (this);
  13687. listeners.add (listener);
  13688. }
  13689. }
  13690. void Value::removeListener (Listener* const listener)
  13691. {
  13692. listeners.removeValue (listener);
  13693. if (listeners.size() == 0)
  13694. value->valuesWithListeners.removeValue (this);
  13695. }
  13696. void Value::callListeners()
  13697. {
  13698. Value valueCopy (*this); // Use a copy in case this object gets deleted by a callback
  13699. for (int i = listeners.size(); --i >= 0;)
  13700. {
  13701. Listener* const l = listeners[i];
  13702. if (l != 0)
  13703. l->valueChanged (valueCopy);
  13704. }
  13705. }
  13706. END_JUCE_NAMESPACE
  13707. /*** End of inlined file: juce_Value.cpp ***/
  13708. /*** Start of inlined file: juce_Application.cpp ***/
  13709. #if JUCE_MSVC
  13710. #pragma warning (push)
  13711. #pragma warning (disable: 4245 4514 4100)
  13712. #include <crtdbg.h>
  13713. #pragma warning (pop)
  13714. #endif
  13715. BEGIN_JUCE_NAMESPACE
  13716. void juce_setCurrentThreadName (const String& name);
  13717. static JUCEApplication* appInstance = 0;
  13718. JUCEApplication::JUCEApplication()
  13719. : appReturnValue (0),
  13720. stillInitialising (true),
  13721. appLock (0)
  13722. {
  13723. }
  13724. JUCEApplication::~JUCEApplication()
  13725. {
  13726. if (appLock != 0)
  13727. {
  13728. appLock->exit();
  13729. delete appLock;
  13730. }
  13731. }
  13732. JUCEApplication* JUCEApplication::getInstance() throw()
  13733. {
  13734. return appInstance;
  13735. }
  13736. bool JUCEApplication::isInitialising() const throw()
  13737. {
  13738. return stillInitialising;
  13739. }
  13740. const String JUCEApplication::getApplicationVersion()
  13741. {
  13742. return String::empty;
  13743. }
  13744. bool JUCEApplication::moreThanOneInstanceAllowed()
  13745. {
  13746. return true;
  13747. }
  13748. void JUCEApplication::anotherInstanceStarted (const String&)
  13749. {
  13750. }
  13751. void JUCEApplication::systemRequestedQuit()
  13752. {
  13753. quit();
  13754. }
  13755. void JUCEApplication::quit()
  13756. {
  13757. MessageManager::getInstance()->stopDispatchLoop();
  13758. }
  13759. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13760. {
  13761. appReturnValue = newReturnValue;
  13762. }
  13763. void JUCEApplication::unhandledException (const std::exception*,
  13764. const String&,
  13765. const int)
  13766. {
  13767. jassertfalse
  13768. }
  13769. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13770. const char* const sourceFile,
  13771. const int lineNumber)
  13772. {
  13773. if (appInstance != 0)
  13774. appInstance->unhandledException (e, sourceFile, lineNumber);
  13775. }
  13776. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13777. {
  13778. return 0;
  13779. }
  13780. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13781. {
  13782. commands.add (StandardApplicationCommandIDs::quit);
  13783. }
  13784. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13785. {
  13786. if (commandID == StandardApplicationCommandIDs::quit)
  13787. {
  13788. result.setInfo (TRANS("Quit"),
  13789. TRANS("Quits the application"),
  13790. "Application",
  13791. 0);
  13792. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13793. }
  13794. }
  13795. bool JUCEApplication::perform (const InvocationInfo& info)
  13796. {
  13797. if (info.commandID == StandardApplicationCommandIDs::quit)
  13798. {
  13799. systemRequestedQuit();
  13800. return true;
  13801. }
  13802. return false;
  13803. }
  13804. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13805. {
  13806. if (! app->initialiseApp (commandLine))
  13807. return 0;
  13808. // now loop until a quit message is received..
  13809. JUCE_TRY
  13810. {
  13811. MessageManager::getInstance()->runDispatchLoop();
  13812. }
  13813. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13814. catch (const std::exception& e)
  13815. {
  13816. app->unhandledException (&e, __FILE__, __LINE__);
  13817. }
  13818. catch (...)
  13819. {
  13820. app->unhandledException (0, __FILE__, __LINE__);
  13821. }
  13822. #endif
  13823. return shutdownAppAndClearUp();
  13824. }
  13825. bool JUCEApplication::initialiseApp (String& commandLine)
  13826. {
  13827. jassert (appInstance == 0);
  13828. appInstance = this;
  13829. commandLineParameters = commandLine.trim();
  13830. commandLine = String::empty;
  13831. initialiseJuce_GUI();
  13832. #if ! JUCE_IPHONE
  13833. jassert (appLock == 0); // initialiseApp must only be called once!
  13834. if (! moreThanOneInstanceAllowed())
  13835. {
  13836. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13837. if (! appLock->enter(0))
  13838. {
  13839. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13840. delete appInstance;
  13841. appInstance = 0;
  13842. DBG ("Another instance is running - quitting...");
  13843. return false;
  13844. }
  13845. }
  13846. #endif
  13847. // let the app do its setting-up..
  13848. initialise (commandLineParameters);
  13849. // register for broadcast new app messages
  13850. MessageManager::getInstance()->registerBroadcastListener (this);
  13851. stillInitialising = false;
  13852. return true;
  13853. }
  13854. int JUCEApplication::shutdownAppAndClearUp()
  13855. {
  13856. jassert (appInstance != 0);
  13857. JUCEApplication* const app = appInstance;
  13858. int returnValue = 0;
  13859. MessageManager::getInstance()->deregisterBroadcastListener (app);
  13860. static bool reentrancyCheck = false;
  13861. if (! reentrancyCheck)
  13862. {
  13863. reentrancyCheck = true;
  13864. JUCE_TRY
  13865. {
  13866. // give the app a chance to clean up..
  13867. app->shutdown();
  13868. }
  13869. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13870. catch (const std::exception& e)
  13871. {
  13872. app->unhandledException (&e, __FILE__, __LINE__);
  13873. }
  13874. catch (...)
  13875. {
  13876. app->unhandledException (0, __FILE__, __LINE__);
  13877. }
  13878. #endif
  13879. JUCE_TRY
  13880. {
  13881. shutdownJuce_GUI();
  13882. returnValue = app->getApplicationReturnValue();
  13883. appInstance = 0;
  13884. delete app;
  13885. }
  13886. JUCE_CATCH_ALL_ASSERT
  13887. reentrancyCheck = false;
  13888. }
  13889. return returnValue;
  13890. }
  13891. #if JUCE_IPHONE
  13892. extern int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app);
  13893. #endif
  13894. #if ! JUCE_WINDOWS
  13895. extern const char* juce_Argv0;
  13896. #endif
  13897. int JUCEApplication::main (int argc, char* argv[],
  13898. JUCEApplication* const newApp)
  13899. {
  13900. #if ! JUCE_WINDOWS
  13901. juce_Argv0 = argv[0];
  13902. #endif
  13903. #if JUCE_IPHONE
  13904. const ScopedAutoReleasePool pool;
  13905. return juce_IPhoneMain (argc, argv, newApp);
  13906. #else
  13907. #if JUCE_MAC
  13908. const ScopedAutoReleasePool pool;
  13909. #endif
  13910. String cmd;
  13911. for (int i = 1; i < argc; ++i)
  13912. cmd << String::fromUTF8 ((const uint8*) argv[i]) << T(' ');
  13913. return JUCEApplication::main (cmd, newApp);
  13914. #endif
  13915. }
  13916. void JUCEApplication::actionListenerCallback (const String& message)
  13917. {
  13918. if (message.startsWith (getApplicationName() + "/"))
  13919. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13920. }
  13921. static bool juceInitialisedGUI = false;
  13922. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13923. {
  13924. if (! juceInitialisedGUI)
  13925. {
  13926. #if JUCE_MAC || JUCE_IPHONE
  13927. const ScopedAutoReleasePool pool;
  13928. #endif
  13929. juceInitialisedGUI = true;
  13930. initialiseJuce_NonGUI();
  13931. MessageManager::getInstance();
  13932. LookAndFeel::setDefaultLookAndFeel (0);
  13933. juce_setCurrentThreadName ("Juce Message Thread");
  13934. #if JUCE_WINDOWS && JUCE_DEBUG
  13935. // This section is just for catching people who mess up their project settings and
  13936. // turn RTTI off..
  13937. try
  13938. {
  13939. TextButton tb (String::empty);
  13940. Component* c = &tb;
  13941. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13942. c = dynamic_cast <Button*> (c);
  13943. }
  13944. catch (...)
  13945. {
  13946. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13947. // got as far as this catch statement, then why haven't you got exception catching
  13948. // turned on in the debugger???
  13949. jassertfalse
  13950. }
  13951. #endif
  13952. }
  13953. }
  13954. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13955. {
  13956. if (juceInitialisedGUI)
  13957. {
  13958. #if JUCE_MAC
  13959. const ScopedAutoReleasePool pool;
  13960. #endif
  13961. {
  13962. DeletedAtShutdown::deleteAll();
  13963. LookAndFeel::clearDefaultLookAndFeel();
  13964. }
  13965. delete MessageManager::getInstance();
  13966. shutdownJuce_NonGUI();
  13967. juceInitialisedGUI = false;
  13968. }
  13969. }
  13970. END_JUCE_NAMESPACE
  13971. /*** End of inlined file: juce_Application.cpp ***/
  13972. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13973. BEGIN_JUCE_NAMESPACE
  13974. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13975. : commandID (commandID_),
  13976. flags (0)
  13977. {
  13978. }
  13979. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13980. const String& description_,
  13981. const String& categoryName_,
  13982. const int flags_) throw()
  13983. {
  13984. shortName = shortName_;
  13985. description = description_;
  13986. categoryName = categoryName_;
  13987. flags = flags_;
  13988. }
  13989. void ApplicationCommandInfo::setActive (const bool b) throw()
  13990. {
  13991. if (b)
  13992. flags &= ~isDisabled;
  13993. else
  13994. flags |= isDisabled;
  13995. }
  13996. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13997. {
  13998. if (b)
  13999. flags |= isTicked;
  14000. else
  14001. flags &= ~isTicked;
  14002. }
  14003. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  14004. {
  14005. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  14006. }
  14007. END_JUCE_NAMESPACE
  14008. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  14009. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  14010. BEGIN_JUCE_NAMESPACE
  14011. ApplicationCommandManager::ApplicationCommandManager()
  14012. : firstTarget (0)
  14013. {
  14014. keyMappings = new KeyPressMappingSet (this);
  14015. Desktop::getInstance().addFocusChangeListener (this);
  14016. }
  14017. ApplicationCommandManager::~ApplicationCommandManager()
  14018. {
  14019. Desktop::getInstance().removeFocusChangeListener (this);
  14020. keyMappings = 0;
  14021. }
  14022. void ApplicationCommandManager::clearCommands()
  14023. {
  14024. commands.clear();
  14025. keyMappings->clearAllKeyPresses();
  14026. triggerAsyncUpdate();
  14027. }
  14028. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  14029. {
  14030. // zero isn't a valid command ID!
  14031. jassert (newCommand.commandID != 0);
  14032. // the name isn't optional!
  14033. jassert (newCommand.shortName.isNotEmpty());
  14034. if (getCommandForID (newCommand.commandID) == 0)
  14035. {
  14036. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  14037. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  14038. commands.add (newInfo);
  14039. keyMappings->resetToDefaultMapping (newCommand.commandID);
  14040. triggerAsyncUpdate();
  14041. }
  14042. else
  14043. {
  14044. // trying to re-register the same command with different parameters?
  14045. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  14046. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  14047. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  14048. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  14049. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  14050. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  14051. }
  14052. }
  14053. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  14054. {
  14055. if (target != 0)
  14056. {
  14057. Array <CommandID> commandIDs;
  14058. target->getAllCommands (commandIDs);
  14059. for (int i = 0; i < commandIDs.size(); ++i)
  14060. {
  14061. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  14062. target->getCommandInfo (info.commandID, info);
  14063. registerCommand (info);
  14064. }
  14065. }
  14066. }
  14067. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  14068. {
  14069. for (int i = commands.size(); --i >= 0;)
  14070. {
  14071. if (commands.getUnchecked (i)->commandID == commandID)
  14072. {
  14073. commands.remove (i);
  14074. triggerAsyncUpdate();
  14075. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  14076. for (int j = keys.size(); --j >= 0;)
  14077. keyMappings->removeKeyPress (keys.getReference (j));
  14078. }
  14079. }
  14080. }
  14081. void ApplicationCommandManager::commandStatusChanged()
  14082. {
  14083. triggerAsyncUpdate();
  14084. }
  14085. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  14086. {
  14087. for (int i = commands.size(); --i >= 0;)
  14088. if (commands.getUnchecked(i)->commandID == commandID)
  14089. return commands.getUnchecked(i);
  14090. return 0;
  14091. }
  14092. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  14093. {
  14094. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14095. return (ci != 0) ? ci->shortName : String::empty;
  14096. }
  14097. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  14098. {
  14099. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14100. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  14101. : String::empty;
  14102. }
  14103. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  14104. {
  14105. StringArray s;
  14106. for (int i = 0; i < commands.size(); ++i)
  14107. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  14108. return s;
  14109. }
  14110. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  14111. {
  14112. Array <CommandID> results;
  14113. for (int i = 0; i < commands.size(); ++i)
  14114. if (commands.getUnchecked(i)->categoryName == categoryName)
  14115. results.add (commands.getUnchecked(i)->commandID);
  14116. return results;
  14117. }
  14118. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14119. {
  14120. ApplicationCommandTarget::InvocationInfo info (commandID);
  14121. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14122. return invoke (info, asynchronously);
  14123. }
  14124. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  14125. {
  14126. // This call isn't thread-safe for use from a non-UI thread without locking the message
  14127. // manager first..
  14128. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  14129. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  14130. if (target == 0)
  14131. return false;
  14132. ApplicationCommandInfo commandInfo (0);
  14133. target->getCommandInfo (info_.commandID, commandInfo);
  14134. ApplicationCommandTarget::InvocationInfo info (info_);
  14135. info.commandFlags = commandInfo.flags;
  14136. sendListenerInvokeCallback (info);
  14137. const bool ok = target->invoke (info, asynchronously);
  14138. commandStatusChanged();
  14139. return ok;
  14140. }
  14141. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  14142. {
  14143. return firstTarget != 0 ? firstTarget
  14144. : findDefaultComponentTarget();
  14145. }
  14146. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  14147. {
  14148. firstTarget = newTarget;
  14149. }
  14150. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  14151. ApplicationCommandInfo& upToDateInfo)
  14152. {
  14153. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  14154. if (target == 0)
  14155. target = JUCEApplication::getInstance();
  14156. if (target != 0)
  14157. target = target->getTargetForCommand (commandID);
  14158. if (target != 0)
  14159. target->getCommandInfo (commandID, upToDateInfo);
  14160. return target;
  14161. }
  14162. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  14163. {
  14164. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  14165. if (target == 0 && c != 0)
  14166. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14167. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14168. return target;
  14169. }
  14170. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  14171. {
  14172. Component* c = Component::getCurrentlyFocusedComponent();
  14173. if (c == 0)
  14174. {
  14175. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  14176. if (activeWindow != 0)
  14177. {
  14178. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  14179. if (c == 0)
  14180. c = activeWindow;
  14181. }
  14182. }
  14183. if (c == 0 && Process::isForegroundProcess())
  14184. {
  14185. // getting a bit desperate now - try all desktop comps..
  14186. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  14187. {
  14188. ApplicationCommandTarget* const target
  14189. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  14190. ->getPeer()->getLastFocusedSubcomponent());
  14191. if (target != 0)
  14192. return target;
  14193. }
  14194. }
  14195. if (c != 0)
  14196. {
  14197. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  14198. // if we're focused on a ResizableWindow, chances are that it's the content
  14199. // component that really should get the event. And if not, the event will
  14200. // still be passed up to the top level window anyway, so let's send it to the
  14201. // content comp.
  14202. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  14203. c = resizableWindow->getContentComponent();
  14204. ApplicationCommandTarget* const target = findTargetForComponent (c);
  14205. if (target != 0)
  14206. return target;
  14207. }
  14208. return JUCEApplication::getInstance();
  14209. }
  14210. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  14211. {
  14212. jassert (listener != 0);
  14213. if (listener != 0)
  14214. listeners.add (listener);
  14215. }
  14216. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  14217. {
  14218. listeners.removeValue (listener);
  14219. }
  14220. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) const
  14221. {
  14222. for (int i = listeners.size(); --i >= 0;)
  14223. {
  14224. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandInvoked (info);
  14225. i = jmin (i, listeners.size());
  14226. }
  14227. }
  14228. void ApplicationCommandManager::handleAsyncUpdate()
  14229. {
  14230. for (int i = listeners.size(); --i >= 0;)
  14231. {
  14232. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandListChanged();
  14233. i = jmin (i, listeners.size());
  14234. }
  14235. }
  14236. void ApplicationCommandManager::globalFocusChanged (Component*)
  14237. {
  14238. commandStatusChanged();
  14239. }
  14240. END_JUCE_NAMESPACE
  14241. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  14242. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14243. BEGIN_JUCE_NAMESPACE
  14244. ApplicationCommandTarget::ApplicationCommandTarget()
  14245. {
  14246. }
  14247. ApplicationCommandTarget::~ApplicationCommandTarget()
  14248. {
  14249. messageInvoker = 0;
  14250. }
  14251. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  14252. {
  14253. if (isCommandActive (info.commandID))
  14254. {
  14255. if (async)
  14256. {
  14257. if (messageInvoker == 0)
  14258. messageInvoker = new CommandTargetMessageInvoker (this);
  14259. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  14260. return true;
  14261. }
  14262. else
  14263. {
  14264. const bool success = perform (info);
  14265. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  14266. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  14267. // returns the command's info.
  14268. return success;
  14269. }
  14270. }
  14271. return false;
  14272. }
  14273. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  14274. {
  14275. Component* c = dynamic_cast <Component*> (this);
  14276. if (c != 0)
  14277. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14278. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14279. return 0;
  14280. }
  14281. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  14282. {
  14283. ApplicationCommandTarget* target = this;
  14284. int depth = 0;
  14285. while (target != 0)
  14286. {
  14287. Array <CommandID> commandIDs;
  14288. target->getAllCommands (commandIDs);
  14289. if (commandIDs.contains (commandID))
  14290. return target;
  14291. target = target->getNextCommandTarget();
  14292. ++depth;
  14293. jassert (depth < 100); // could be a recursive command chain??
  14294. jassert (target != this); // definitely a recursive command chain!
  14295. if (depth > 100 || target == this)
  14296. break;
  14297. }
  14298. if (target == 0)
  14299. {
  14300. target = JUCEApplication::getInstance();
  14301. if (target != 0)
  14302. {
  14303. Array <CommandID> commandIDs;
  14304. target->getAllCommands (commandIDs);
  14305. if (commandIDs.contains (commandID))
  14306. return target;
  14307. }
  14308. }
  14309. return 0;
  14310. }
  14311. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  14312. {
  14313. ApplicationCommandInfo info (commandID);
  14314. info.flags = ApplicationCommandInfo::isDisabled;
  14315. getCommandInfo (commandID, info);
  14316. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  14317. }
  14318. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  14319. {
  14320. ApplicationCommandTarget* target = this;
  14321. int depth = 0;
  14322. while (target != 0)
  14323. {
  14324. if (target->tryToInvoke (info, async))
  14325. return true;
  14326. target = target->getNextCommandTarget();
  14327. ++depth;
  14328. jassert (depth < 100); // could be a recursive command chain??
  14329. jassert (target != this); // definitely a recursive command chain!
  14330. if (depth > 100 || target == this)
  14331. break;
  14332. }
  14333. if (target == 0)
  14334. {
  14335. target = JUCEApplication::getInstance();
  14336. if (target != 0)
  14337. return target->tryToInvoke (info, async);
  14338. }
  14339. return false;
  14340. }
  14341. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14342. {
  14343. ApplicationCommandTarget::InvocationInfo info (commandID);
  14344. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14345. return invoke (info, asynchronously);
  14346. }
  14347. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14348. : commandID (commandID_),
  14349. commandFlags (0),
  14350. invocationMethod (direct),
  14351. originatingComponent (0),
  14352. isKeyDown (false),
  14353. millisecsSinceKeyPressed (0)
  14354. {
  14355. }
  14356. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14357. : owner (owner_)
  14358. {
  14359. }
  14360. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14361. {
  14362. }
  14363. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14364. {
  14365. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14366. owner->tryToInvoke (*info, false);
  14367. }
  14368. END_JUCE_NAMESPACE
  14369. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14370. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14371. BEGIN_JUCE_NAMESPACE
  14372. juce_ImplementSingleton (ApplicationProperties)
  14373. ApplicationProperties::ApplicationProperties() throw()
  14374. : msBeforeSaving (3000),
  14375. options (PropertiesFile::storeAsBinary),
  14376. commonSettingsAreReadOnly (0)
  14377. {
  14378. }
  14379. ApplicationProperties::~ApplicationProperties()
  14380. {
  14381. closeFiles();
  14382. clearSingletonInstance();
  14383. }
  14384. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14385. const String& fileNameSuffix,
  14386. const String& folderName_,
  14387. const int millisecondsBeforeSaving,
  14388. const int propertiesFileOptions) throw()
  14389. {
  14390. appName = applicationName;
  14391. fileSuffix = fileNameSuffix;
  14392. folderName = folderName_;
  14393. msBeforeSaving = millisecondsBeforeSaving;
  14394. options = propertiesFileOptions;
  14395. }
  14396. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14397. const bool testCommonSettings,
  14398. const bool showWarningDialogOnFailure)
  14399. {
  14400. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14401. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14402. if (! (userOk && commonOk))
  14403. {
  14404. if (showWarningDialogOnFailure)
  14405. {
  14406. String filenames;
  14407. if (userProps != 0 && ! userOk)
  14408. filenames << '\n' << userProps->getFile().getFullPathName();
  14409. if (commonProps != 0 && ! commonOk)
  14410. filenames << '\n' << commonProps->getFile().getFullPathName();
  14411. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14412. appName + TRANS(" - Unable to save settings"),
  14413. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14414. + appName + TRANS(" needs to be able to write to the following files:\n")
  14415. + filenames
  14416. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14417. }
  14418. return false;
  14419. }
  14420. return true;
  14421. }
  14422. void ApplicationProperties::openFiles() throw()
  14423. {
  14424. // You need to call setStorageParameters() before trying to get hold of the
  14425. // properties!
  14426. jassert (appName.isNotEmpty());
  14427. if (appName.isNotEmpty())
  14428. {
  14429. if (userProps == 0)
  14430. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14431. false, msBeforeSaving, options);
  14432. if (commonProps == 0)
  14433. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14434. true, msBeforeSaving, options);
  14435. userProps->setFallbackPropertySet (commonProps);
  14436. }
  14437. }
  14438. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14439. {
  14440. if (userProps == 0)
  14441. openFiles();
  14442. return userProps;
  14443. }
  14444. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14445. {
  14446. if (commonProps == 0)
  14447. openFiles();
  14448. if (returnUserPropsIfReadOnly)
  14449. {
  14450. if (commonSettingsAreReadOnly == 0)
  14451. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14452. if (commonSettingsAreReadOnly > 0)
  14453. return userProps;
  14454. }
  14455. return commonProps;
  14456. }
  14457. bool ApplicationProperties::saveIfNeeded()
  14458. {
  14459. return (userProps == 0 || userProps->saveIfNeeded())
  14460. && (commonProps == 0 || commonProps->saveIfNeeded());
  14461. }
  14462. void ApplicationProperties::closeFiles()
  14463. {
  14464. userProps = 0;
  14465. commonProps = 0;
  14466. }
  14467. END_JUCE_NAMESPACE
  14468. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14469. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14470. BEGIN_JUCE_NAMESPACE
  14471. static VoidArray objectsToDelete;
  14472. static CriticalSection lock;
  14473. DeletedAtShutdown::DeletedAtShutdown()
  14474. {
  14475. const ScopedLock sl (lock);
  14476. objectsToDelete.add (this);
  14477. }
  14478. DeletedAtShutdown::~DeletedAtShutdown()
  14479. {
  14480. const ScopedLock sl (lock);
  14481. objectsToDelete.removeValue (this);
  14482. }
  14483. void DeletedAtShutdown::deleteAll()
  14484. {
  14485. // make a local copy of the array, so it can't get into a loop if something
  14486. // creates another DeletedAtShutdown object during its destructor.
  14487. lock.enter();
  14488. const VoidArray localCopy (objectsToDelete);
  14489. lock.exit();
  14490. for (int i = localCopy.size(); --i >= 0;)
  14491. {
  14492. JUCE_TRY
  14493. {
  14494. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14495. // double-check that it's not already been deleted during another object's destructor.
  14496. {
  14497. const ScopedLock sl (lock);
  14498. if (! objectsToDelete.contains (deletee))
  14499. deletee = 0;
  14500. }
  14501. delete deletee;
  14502. }
  14503. JUCE_CATCH_EXCEPTION
  14504. }
  14505. // if no objects got re-created during shutdown, this should have been emptied by their
  14506. // destructors
  14507. jassert (objectsToDelete.size() == 0);
  14508. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14509. }
  14510. END_JUCE_NAMESPACE
  14511. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14512. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14513. BEGIN_JUCE_NAMESPACE
  14514. static const int propFileMagicNumber = ((int) ByteOrder::littleEndianInt ("PROP"));
  14515. static const int propFileMagicNumberCompressed = ((int) ByteOrder::littleEndianInt ("CPRP"));
  14516. static const tchar* const propertyFileXmlTag = T("PROPERTIES");
  14517. static const tchar* const propertyTagName = T("VALUE");
  14518. PropertiesFile::PropertiesFile (const File& f,
  14519. const int millisecondsBeforeSaving,
  14520. const int options_)
  14521. : PropertySet (ignoreCaseOfKeyNames),
  14522. file (f),
  14523. timerInterval (millisecondsBeforeSaving),
  14524. options (options_),
  14525. needsWriting (false)
  14526. {
  14527. // You need to correctly specify just one storage format for the file
  14528. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14529. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14530. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14531. ScopedPointer <InputStream> fileStream (f.createInputStream());
  14532. if (fileStream != 0)
  14533. {
  14534. int magicNumber = fileStream->readInt();
  14535. if (magicNumber == propFileMagicNumberCompressed)
  14536. {
  14537. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true),
  14538. true);
  14539. magicNumber = propFileMagicNumber;
  14540. }
  14541. if (magicNumber == propFileMagicNumber)
  14542. {
  14543. BufferedInputStream in (fileStream.release(), 2048, true);
  14544. int numValues = in.readInt();
  14545. while (--numValues >= 0 && ! in.isExhausted())
  14546. {
  14547. const String key (in.readString());
  14548. const String value (in.readString());
  14549. jassert (key.isNotEmpty());
  14550. if (key.isNotEmpty())
  14551. getAllProperties().set (key, value);
  14552. }
  14553. }
  14554. else
  14555. {
  14556. // Not a binary props file - let's see if it's XML..
  14557. fileStream = 0;
  14558. XmlDocument parser (f);
  14559. ScopedPointer <XmlElement> doc (parser.getDocumentElement (true));
  14560. if (doc != 0 && doc->hasTagName (propertyFileXmlTag))
  14561. {
  14562. doc = parser.getDocumentElement();
  14563. if (doc != 0)
  14564. {
  14565. forEachXmlChildElementWithTagName (*doc, e, propertyTagName)
  14566. {
  14567. const String name (e->getStringAttribute (T("name")));
  14568. if (name.isNotEmpty())
  14569. {
  14570. getAllProperties().set (name,
  14571. e->getFirstChildElement() != 0
  14572. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14573. : e->getStringAttribute (T("val")));
  14574. }
  14575. }
  14576. }
  14577. else
  14578. {
  14579. // must be a pretty broken XML file we're trying to parse here!
  14580. jassertfalse
  14581. }
  14582. }
  14583. }
  14584. }
  14585. }
  14586. PropertiesFile::~PropertiesFile()
  14587. {
  14588. saveIfNeeded();
  14589. }
  14590. bool PropertiesFile::saveIfNeeded()
  14591. {
  14592. const ScopedLock sl (getLock());
  14593. return (! needsWriting) || save();
  14594. }
  14595. bool PropertiesFile::needsToBeSaved() const
  14596. {
  14597. const ScopedLock sl (getLock());
  14598. return needsWriting;
  14599. }
  14600. bool PropertiesFile::save()
  14601. {
  14602. const ScopedLock sl (getLock());
  14603. stopTimer();
  14604. if (file == File::nonexistent
  14605. || file.isDirectory()
  14606. || ! file.getParentDirectory().createDirectory())
  14607. return false;
  14608. if ((options & storeAsXML) != 0)
  14609. {
  14610. XmlElement doc (propertyFileXmlTag);
  14611. for (int i = 0; i < getAllProperties().size(); ++i)
  14612. {
  14613. XmlElement* const e = doc.createNewChildElement (propertyTagName);
  14614. e->setAttribute (T("name"), getAllProperties().getAllKeys() [i]);
  14615. // if the value seems to contain xml, store it as such..
  14616. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14617. XmlElement* const childElement = xmlContent.getDocumentElement();
  14618. if (childElement != 0)
  14619. e->addChildElement (childElement);
  14620. else
  14621. e->setAttribute (T("val"), getAllProperties().getAllValues() [i]);
  14622. }
  14623. return doc.writeToFile (file, String::empty);
  14624. }
  14625. else
  14626. {
  14627. TemporaryFile tempFile (file);
  14628. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14629. if (out != 0)
  14630. {
  14631. if ((options & storeAsCompressedBinary) != 0)
  14632. {
  14633. out->writeInt (propFileMagicNumberCompressed);
  14634. out->flush();
  14635. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14636. }
  14637. else
  14638. {
  14639. // have you set up the storage option flags correctly?
  14640. jassert ((options & storeAsBinary) != 0);
  14641. out->writeInt (propFileMagicNumber);
  14642. }
  14643. const int numProperties = getAllProperties().size();
  14644. out->writeInt (numProperties);
  14645. for (int i = 0; i < numProperties; ++i)
  14646. {
  14647. out->writeString (getAllProperties().getAllKeys() [i]);
  14648. out->writeString (getAllProperties().getAllValues() [i]);
  14649. }
  14650. out = 0;
  14651. if (tempFile.overwriteTargetFileWithTemporary())
  14652. {
  14653. needsWriting = false;
  14654. return true;
  14655. }
  14656. }
  14657. }
  14658. return false;
  14659. }
  14660. void PropertiesFile::timerCallback()
  14661. {
  14662. saveIfNeeded();
  14663. }
  14664. void PropertiesFile::propertyChanged()
  14665. {
  14666. sendChangeMessage (this);
  14667. needsWriting = true;
  14668. if (timerInterval > 0)
  14669. startTimer (timerInterval);
  14670. else if (timerInterval == 0)
  14671. saveIfNeeded();
  14672. }
  14673. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14674. const String& fileNameSuffix,
  14675. const String& folderName,
  14676. const bool commonToAllUsers)
  14677. {
  14678. // mustn't have illegal characters in this name..
  14679. jassert (applicationName == File::createLegalFileName (applicationName));
  14680. #if JUCE_MAC || JUCE_IPHONE
  14681. File dir (commonToAllUsers ? "/Library/Preferences"
  14682. : "~/Library/Preferences");
  14683. if (folderName.isNotEmpty())
  14684. dir = dir.getChildFile (folderName);
  14685. #endif
  14686. #ifdef JUCE_LINUX
  14687. const File dir ((commonToAllUsers ? T("/var/") : T("~/"))
  14688. + (folderName.isNotEmpty() ? folderName
  14689. : (T(".") + applicationName)));
  14690. #endif
  14691. #if JUCE_WIN32
  14692. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14693. : File::userApplicationDataDirectory));
  14694. if (dir == File::nonexistent)
  14695. return File::nonexistent;
  14696. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14697. : applicationName);
  14698. #endif
  14699. return dir.getChildFile (applicationName)
  14700. .withFileExtension (fileNameSuffix);
  14701. }
  14702. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14703. const String& fileNameSuffix,
  14704. const String& folderName,
  14705. const bool commonToAllUsers,
  14706. const int millisecondsBeforeSaving,
  14707. const int propertiesFileOptions)
  14708. {
  14709. const File file (getDefaultAppSettingsFile (applicationName,
  14710. fileNameSuffix,
  14711. folderName,
  14712. commonToAllUsers));
  14713. jassert (file != File::nonexistent);
  14714. if (file == File::nonexistent)
  14715. return 0;
  14716. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14717. }
  14718. END_JUCE_NAMESPACE
  14719. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14720. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14721. BEGIN_JUCE_NAMESPACE
  14722. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14723. const String& fileWildcard_,
  14724. const String& openFileDialogTitle_,
  14725. const String& saveFileDialogTitle_)
  14726. : changedSinceSave (false),
  14727. fileExtension (fileExtension_),
  14728. fileWildcard (fileWildcard_),
  14729. openFileDialogTitle (openFileDialogTitle_),
  14730. saveFileDialogTitle (saveFileDialogTitle_)
  14731. {
  14732. }
  14733. FileBasedDocument::~FileBasedDocument()
  14734. {
  14735. }
  14736. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14737. {
  14738. changedSinceSave = hasChanged;
  14739. }
  14740. void FileBasedDocument::changed()
  14741. {
  14742. changedSinceSave = true;
  14743. sendChangeMessage (this);
  14744. }
  14745. void FileBasedDocument::setFile (const File& newFile)
  14746. {
  14747. if (documentFile != newFile)
  14748. {
  14749. documentFile = newFile;
  14750. changedSinceSave = true;
  14751. }
  14752. }
  14753. bool FileBasedDocument::loadFrom (const File& newFile,
  14754. const bool showMessageOnFailure)
  14755. {
  14756. MouseCursor::showWaitCursor();
  14757. const File oldFile (documentFile);
  14758. documentFile = newFile;
  14759. String error;
  14760. if (newFile.existsAsFile())
  14761. {
  14762. error = loadDocument (newFile);
  14763. if (error.isEmpty())
  14764. {
  14765. setChangedFlag (false);
  14766. MouseCursor::hideWaitCursor();
  14767. setLastDocumentOpened (newFile);
  14768. return true;
  14769. }
  14770. }
  14771. else
  14772. {
  14773. error = "The file doesn't exist";
  14774. }
  14775. documentFile = oldFile;
  14776. MouseCursor::hideWaitCursor();
  14777. if (showMessageOnFailure)
  14778. {
  14779. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14780. TRANS("Failed to open file..."),
  14781. TRANS("There was an error while trying to load the file:\n\n")
  14782. + newFile.getFullPathName()
  14783. + T("\n\n")
  14784. + error);
  14785. }
  14786. return false;
  14787. }
  14788. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14789. {
  14790. FileChooser fc (openFileDialogTitle,
  14791. getLastDocumentOpened(),
  14792. fileWildcard);
  14793. if (fc.browseForFileToOpen())
  14794. return loadFrom (fc.getResult(), showMessageOnFailure);
  14795. return false;
  14796. }
  14797. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14798. const bool showMessageOnFailure)
  14799. {
  14800. return saveAs (documentFile,
  14801. false,
  14802. askUserForFileIfNotSpecified,
  14803. showMessageOnFailure);
  14804. }
  14805. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14806. const bool warnAboutOverwritingExistingFiles,
  14807. const bool askUserForFileIfNotSpecified,
  14808. const bool showMessageOnFailure)
  14809. {
  14810. if (newFile == File::nonexistent)
  14811. {
  14812. if (askUserForFileIfNotSpecified)
  14813. {
  14814. return saveAsInteractive (true);
  14815. }
  14816. else
  14817. {
  14818. // can't save to an unspecified file
  14819. jassertfalse
  14820. return failedToWriteToFile;
  14821. }
  14822. }
  14823. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14824. {
  14825. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14826. TRANS("File already exists"),
  14827. TRANS("There's already a file called:\n\n")
  14828. + newFile.getFullPathName()
  14829. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14830. TRANS("overwrite"),
  14831. TRANS("cancel")))
  14832. {
  14833. return userCancelledSave;
  14834. }
  14835. }
  14836. MouseCursor::showWaitCursor();
  14837. const File oldFile (documentFile);
  14838. documentFile = newFile;
  14839. String error (saveDocument (newFile));
  14840. if (error.isEmpty())
  14841. {
  14842. setChangedFlag (false);
  14843. MouseCursor::hideWaitCursor();
  14844. return savedOk;
  14845. }
  14846. documentFile = oldFile;
  14847. MouseCursor::hideWaitCursor();
  14848. if (showMessageOnFailure)
  14849. {
  14850. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14851. TRANS("Error writing to file..."),
  14852. TRANS("An error occurred while trying to save \"")
  14853. + getDocumentTitle()
  14854. + TRANS("\" to the file:\n\n")
  14855. + newFile.getFullPathName()
  14856. + T("\n\n")
  14857. + error);
  14858. }
  14859. return failedToWriteToFile;
  14860. }
  14861. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14862. {
  14863. if (! hasChangedSinceSaved())
  14864. return savedOk;
  14865. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14866. TRANS("Closing document..."),
  14867. TRANS("Do you want to save the changes to \"")
  14868. + getDocumentTitle() + T("\"?"),
  14869. TRANS("save"),
  14870. TRANS("discard changes"),
  14871. TRANS("cancel"));
  14872. if (r == 1)
  14873. {
  14874. // save changes
  14875. return save (true, true);
  14876. }
  14877. else if (r == 2)
  14878. {
  14879. // discard changes
  14880. return savedOk;
  14881. }
  14882. return userCancelledSave;
  14883. }
  14884. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14885. {
  14886. File f;
  14887. if (documentFile.existsAsFile())
  14888. f = documentFile;
  14889. else
  14890. f = getLastDocumentOpened();
  14891. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14892. if (legalFilename.isEmpty())
  14893. legalFilename = "unnamed";
  14894. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14895. f = f.getSiblingFile (legalFilename);
  14896. else
  14897. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14898. f = f.withFileExtension (fileExtension)
  14899. .getNonexistentSibling (true);
  14900. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14901. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14902. {
  14903. setLastDocumentOpened (fc.getResult());
  14904. File chosen (fc.getResult());
  14905. if (chosen.getFileExtension().isEmpty())
  14906. {
  14907. chosen = chosen.withFileExtension (fileExtension);
  14908. if (chosen.exists())
  14909. {
  14910. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14911. TRANS("File already exists"),
  14912. TRANS("There's already a file called:\n\n")
  14913. + chosen.getFullPathName()
  14914. + T("\n\nAre you sure you want to overwrite it?"),
  14915. TRANS("overwrite"),
  14916. TRANS("cancel")))
  14917. {
  14918. return userCancelledSave;
  14919. }
  14920. }
  14921. }
  14922. return saveAs (chosen, false, false, true);
  14923. }
  14924. return userCancelledSave;
  14925. }
  14926. END_JUCE_NAMESPACE
  14927. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14928. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14929. BEGIN_JUCE_NAMESPACE
  14930. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14931. : maxNumberOfItems (10)
  14932. {
  14933. }
  14934. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14935. {
  14936. }
  14937. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14938. {
  14939. maxNumberOfItems = jmax (1, newMaxNumber);
  14940. while (getNumFiles() > maxNumberOfItems)
  14941. files.remove (getNumFiles() - 1);
  14942. }
  14943. int RecentlyOpenedFilesList::getNumFiles() const
  14944. {
  14945. return files.size();
  14946. }
  14947. const File RecentlyOpenedFilesList::getFile (const int index) const
  14948. {
  14949. return File (files [index]);
  14950. }
  14951. void RecentlyOpenedFilesList::clear()
  14952. {
  14953. files.clear();
  14954. }
  14955. void RecentlyOpenedFilesList::addFile (const File& file)
  14956. {
  14957. const String path (file.getFullPathName());
  14958. files.removeString (path, true);
  14959. files.insert (0, path);
  14960. setMaxNumberOfItems (maxNumberOfItems);
  14961. }
  14962. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14963. {
  14964. for (int i = getNumFiles(); --i >= 0;)
  14965. if (! getFile(i).exists())
  14966. files.remove (i);
  14967. }
  14968. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14969. const int baseItemId,
  14970. const bool showFullPaths,
  14971. const bool dontAddNonExistentFiles,
  14972. const File** filesToAvoid)
  14973. {
  14974. int num = 0;
  14975. for (int i = 0; i < getNumFiles(); ++i)
  14976. {
  14977. const File f (getFile(i));
  14978. if ((! dontAddNonExistentFiles) || f.exists())
  14979. {
  14980. bool needsAvoiding = false;
  14981. if (filesToAvoid != 0)
  14982. {
  14983. const File** avoid = filesToAvoid;
  14984. while (*avoid != 0)
  14985. {
  14986. if (f == **avoid)
  14987. {
  14988. needsAvoiding = true;
  14989. break;
  14990. }
  14991. ++avoid;
  14992. }
  14993. }
  14994. if (! needsAvoiding)
  14995. {
  14996. menuToAddTo.addItem (baseItemId + i,
  14997. showFullPaths ? f.getFullPathName()
  14998. : f.getFileName());
  14999. ++num;
  15000. }
  15001. }
  15002. }
  15003. return num;
  15004. }
  15005. const String RecentlyOpenedFilesList::toString() const
  15006. {
  15007. return files.joinIntoString (T("\n"));
  15008. }
  15009. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  15010. {
  15011. clear();
  15012. files.addLines (stringifiedVersion);
  15013. setMaxNumberOfItems (maxNumberOfItems);
  15014. }
  15015. END_JUCE_NAMESPACE
  15016. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  15017. /*** Start of inlined file: juce_UndoManager.cpp ***/
  15018. BEGIN_JUCE_NAMESPACE
  15019. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  15020. const int minimumTransactions)
  15021. : totalUnitsStored (0),
  15022. nextIndex (0),
  15023. newTransaction (true),
  15024. reentrancyCheck (false)
  15025. {
  15026. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  15027. minimumTransactions);
  15028. }
  15029. UndoManager::~UndoManager()
  15030. {
  15031. clearUndoHistory();
  15032. }
  15033. void UndoManager::clearUndoHistory()
  15034. {
  15035. transactions.clear();
  15036. transactionNames.clear();
  15037. totalUnitsStored = 0;
  15038. nextIndex = 0;
  15039. sendChangeMessage (this);
  15040. }
  15041. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  15042. {
  15043. return totalUnitsStored;
  15044. }
  15045. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  15046. const int minimumTransactions)
  15047. {
  15048. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  15049. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  15050. }
  15051. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  15052. {
  15053. if (command != 0)
  15054. {
  15055. if (actionName.isNotEmpty())
  15056. currentTransactionName = actionName;
  15057. if (reentrancyCheck)
  15058. {
  15059. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  15060. // undo() methods, or else these actions won't actually get done.
  15061. return false;
  15062. }
  15063. else
  15064. {
  15065. bool success = false;
  15066. JUCE_TRY
  15067. {
  15068. success = command->perform();
  15069. }
  15070. JUCE_CATCH_EXCEPTION
  15071. jassert (success);
  15072. if (success)
  15073. {
  15074. if (nextIndex > 0 && ! newTransaction)
  15075. {
  15076. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  15077. jassert (commandSet != 0);
  15078. if (commandSet == 0)
  15079. return false;
  15080. commandSet->add (command);
  15081. }
  15082. else
  15083. {
  15084. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  15085. commandSet->add (command);
  15086. transactions.insert (nextIndex, commandSet);
  15087. transactionNames.insert (nextIndex, currentTransactionName);
  15088. ++nextIndex;
  15089. }
  15090. totalUnitsStored += command->getSizeInUnits();
  15091. newTransaction = false;
  15092. }
  15093. while (nextIndex < transactions.size())
  15094. {
  15095. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  15096. for (int i = lastSet->size(); --i >= 0;)
  15097. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  15098. transactions.removeLast();
  15099. transactionNames.remove (transactionNames.size() - 1);
  15100. }
  15101. while (nextIndex > 0
  15102. && totalUnitsStored > maxNumUnitsToKeep
  15103. && transactions.size() > minimumTransactionsToKeep)
  15104. {
  15105. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  15106. for (int i = firstSet->size(); --i >= 0;)
  15107. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  15108. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  15109. transactions.remove (0);
  15110. transactionNames.remove (0);
  15111. --nextIndex;
  15112. }
  15113. sendChangeMessage (this);
  15114. return success;
  15115. }
  15116. }
  15117. return false;
  15118. }
  15119. void UndoManager::beginNewTransaction (const String& actionName)
  15120. {
  15121. newTransaction = true;
  15122. currentTransactionName = actionName;
  15123. }
  15124. void UndoManager::setCurrentTransactionName (const String& newName)
  15125. {
  15126. currentTransactionName = newName;
  15127. }
  15128. bool UndoManager::canUndo() const
  15129. {
  15130. return nextIndex > 0;
  15131. }
  15132. bool UndoManager::canRedo() const
  15133. {
  15134. return nextIndex < transactions.size();
  15135. }
  15136. const String UndoManager::getUndoDescription() const
  15137. {
  15138. return transactionNames [nextIndex - 1];
  15139. }
  15140. const String UndoManager::getRedoDescription() const
  15141. {
  15142. return transactionNames [nextIndex];
  15143. }
  15144. bool UndoManager::undo()
  15145. {
  15146. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15147. if (commandSet == 0)
  15148. return false;
  15149. reentrancyCheck = true;
  15150. bool failed = false;
  15151. for (int i = commandSet->size(); --i >= 0;)
  15152. {
  15153. if (! commandSet->getUnchecked(i)->undo())
  15154. {
  15155. jassertfalse
  15156. failed = true;
  15157. break;
  15158. }
  15159. }
  15160. reentrancyCheck = false;
  15161. if (failed)
  15162. {
  15163. clearUndoHistory();
  15164. }
  15165. else
  15166. {
  15167. --nextIndex;
  15168. }
  15169. beginNewTransaction();
  15170. sendChangeMessage (this);
  15171. return true;
  15172. }
  15173. bool UndoManager::redo()
  15174. {
  15175. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  15176. if (commandSet == 0)
  15177. return false;
  15178. reentrancyCheck = true;
  15179. bool failed = false;
  15180. for (int i = 0; i < commandSet->size(); ++i)
  15181. {
  15182. if (! commandSet->getUnchecked(i)->perform())
  15183. {
  15184. jassertfalse
  15185. failed = true;
  15186. break;
  15187. }
  15188. }
  15189. reentrancyCheck = false;
  15190. if (failed)
  15191. {
  15192. clearUndoHistory();
  15193. }
  15194. else
  15195. {
  15196. ++nextIndex;
  15197. }
  15198. beginNewTransaction();
  15199. sendChangeMessage (this);
  15200. return true;
  15201. }
  15202. bool UndoManager::undoCurrentTransactionOnly()
  15203. {
  15204. return newTransaction ? false
  15205. : undo();
  15206. }
  15207. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  15208. {
  15209. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15210. if (commandSet != 0 && ! newTransaction)
  15211. {
  15212. for (int i = 0; i < commandSet->size(); ++i)
  15213. actionsFound.add (commandSet->getUnchecked(i));
  15214. }
  15215. }
  15216. int UndoManager::getNumActionsInCurrentTransaction() const
  15217. {
  15218. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15219. if (commandSet != 0 && ! newTransaction)
  15220. return commandSet->size();
  15221. return 0;
  15222. }
  15223. END_JUCE_NAMESPACE
  15224. /*** End of inlined file: juce_UndoManager.cpp ***/
  15225. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  15226. BEGIN_JUCE_NAMESPACE
  15227. static const char* const aiffFormatName = "AIFF file";
  15228. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  15229. class AiffAudioFormatReader : public AudioFormatReader
  15230. {
  15231. public:
  15232. int bytesPerFrame;
  15233. int64 dataChunkStart;
  15234. bool littleEndian;
  15235. AiffAudioFormatReader (InputStream* in)
  15236. : AudioFormatReader (in, TRANS (aiffFormatName))
  15237. {
  15238. if (input->readInt() == chunkName ("FORM"))
  15239. {
  15240. const int len = input->readIntBigEndian();
  15241. const int64 end = input->getPosition() + len;
  15242. const int nextType = input->readInt();
  15243. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  15244. {
  15245. bool hasGotVer = false;
  15246. bool hasGotData = false;
  15247. bool hasGotType = false;
  15248. while (input->getPosition() < end)
  15249. {
  15250. const int type = input->readInt();
  15251. const uint32 length = (uint32) input->readIntBigEndian();
  15252. const int64 chunkEnd = input->getPosition() + length;
  15253. if (type == chunkName ("FVER"))
  15254. {
  15255. hasGotVer = true;
  15256. const int ver = input->readIntBigEndian();
  15257. if (ver != 0 && ver != (int)0xa2805140)
  15258. break;
  15259. }
  15260. else if (type == chunkName ("COMM"))
  15261. {
  15262. hasGotType = true;
  15263. numChannels = (unsigned int)input->readShortBigEndian();
  15264. lengthInSamples = input->readIntBigEndian();
  15265. bitsPerSample = input->readShortBigEndian();
  15266. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  15267. unsigned char sampleRateBytes[10];
  15268. input->read (sampleRateBytes, 10);
  15269. const int byte0 = sampleRateBytes[0];
  15270. if ((byte0 & 0x80) != 0
  15271. || byte0 <= 0x3F || byte0 > 0x40
  15272. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  15273. break;
  15274. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  15275. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  15276. sampleRate = (int) sampRate;
  15277. if (length <= 18)
  15278. {
  15279. // some types don't have a chunk large enough to include a compression
  15280. // type, so assume it's just big-endian pcm
  15281. littleEndian = false;
  15282. }
  15283. else
  15284. {
  15285. const int compType = input->readInt();
  15286. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15287. {
  15288. littleEndian = false;
  15289. }
  15290. else if (compType == chunkName ("sowt"))
  15291. {
  15292. littleEndian = true;
  15293. }
  15294. else
  15295. {
  15296. sampleRate = 0;
  15297. break;
  15298. }
  15299. }
  15300. }
  15301. else if (type == chunkName ("SSND"))
  15302. {
  15303. hasGotData = true;
  15304. const int offset = input->readIntBigEndian();
  15305. dataChunkStart = input->getPosition() + 4 + offset;
  15306. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15307. }
  15308. else if ((hasGotVer && hasGotData && hasGotType)
  15309. || chunkEnd < input->getPosition()
  15310. || input->isExhausted())
  15311. {
  15312. break;
  15313. }
  15314. input->setPosition (chunkEnd);
  15315. }
  15316. }
  15317. }
  15318. }
  15319. ~AiffAudioFormatReader()
  15320. {
  15321. }
  15322. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15323. int64 startSampleInFile, int numSamples)
  15324. {
  15325. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15326. if (samplesAvailable < numSamples)
  15327. {
  15328. for (int i = numDestChannels; --i >= 0;)
  15329. if (destSamples[i] != 0)
  15330. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15331. numSamples = (int) samplesAvailable;
  15332. }
  15333. if (numSamples <= 0)
  15334. return true;
  15335. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15336. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15337. char tempBuffer [tempBufSize];
  15338. while (numSamples > 0)
  15339. {
  15340. int* left = destSamples[0];
  15341. if (left != 0)
  15342. left += startOffsetInDestBuffer;
  15343. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15344. if (right != 0)
  15345. right += startOffsetInDestBuffer;
  15346. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15347. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15348. if (bytesRead < numThisTime * bytesPerFrame)
  15349. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15350. if (bitsPerSample == 16)
  15351. {
  15352. if (littleEndian)
  15353. {
  15354. const short* src = (const short*) tempBuffer;
  15355. if (numChannels > 1)
  15356. {
  15357. if (left == 0)
  15358. {
  15359. for (int i = numThisTime; --i >= 0;)
  15360. {
  15361. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15362. ++src;
  15363. }
  15364. }
  15365. else if (right == 0)
  15366. {
  15367. for (int i = numThisTime; --i >= 0;)
  15368. {
  15369. ++src;
  15370. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15371. }
  15372. }
  15373. else
  15374. {
  15375. for (int i = numThisTime; --i >= 0;)
  15376. {
  15377. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15378. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15379. }
  15380. }
  15381. }
  15382. else
  15383. {
  15384. for (int i = numThisTime; --i >= 0;)
  15385. {
  15386. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15387. }
  15388. }
  15389. }
  15390. else
  15391. {
  15392. const char* src = (const char*) tempBuffer;
  15393. if (numChannels > 1)
  15394. {
  15395. if (left == 0)
  15396. {
  15397. for (int i = numThisTime; --i >= 0;)
  15398. {
  15399. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15400. src += 4;
  15401. }
  15402. }
  15403. else if (right == 0)
  15404. {
  15405. for (int i = numThisTime; --i >= 0;)
  15406. {
  15407. src += 2;
  15408. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15409. src += 2;
  15410. }
  15411. }
  15412. else
  15413. {
  15414. for (int i = numThisTime; --i >= 0;)
  15415. {
  15416. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15417. src += 2;
  15418. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15419. src += 2;
  15420. }
  15421. }
  15422. }
  15423. else
  15424. {
  15425. for (int i = numThisTime; --i >= 0;)
  15426. {
  15427. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15428. src += 2;
  15429. }
  15430. }
  15431. }
  15432. }
  15433. else if (bitsPerSample == 24)
  15434. {
  15435. const char* src = (const char*)tempBuffer;
  15436. if (littleEndian)
  15437. {
  15438. if (numChannels > 1)
  15439. {
  15440. if (left == 0)
  15441. {
  15442. for (int i = numThisTime; --i >= 0;)
  15443. {
  15444. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15445. src += 6;
  15446. }
  15447. }
  15448. else if (right == 0)
  15449. {
  15450. for (int i = numThisTime; --i >= 0;)
  15451. {
  15452. src += 3;
  15453. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15454. src += 3;
  15455. }
  15456. }
  15457. else
  15458. {
  15459. for (int i = numThisTime; --i >= 0;)
  15460. {
  15461. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15462. src += 3;
  15463. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15464. src += 3;
  15465. }
  15466. }
  15467. }
  15468. else
  15469. {
  15470. for (int i = numThisTime; --i >= 0;)
  15471. {
  15472. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15473. src += 3;
  15474. }
  15475. }
  15476. }
  15477. else
  15478. {
  15479. if (numChannels > 1)
  15480. {
  15481. if (left == 0)
  15482. {
  15483. for (int i = numThisTime; --i >= 0;)
  15484. {
  15485. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15486. src += 6;
  15487. }
  15488. }
  15489. else if (right == 0)
  15490. {
  15491. for (int i = numThisTime; --i >= 0;)
  15492. {
  15493. src += 3;
  15494. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15495. src += 3;
  15496. }
  15497. }
  15498. else
  15499. {
  15500. for (int i = numThisTime; --i >= 0;)
  15501. {
  15502. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15503. src += 3;
  15504. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15505. src += 3;
  15506. }
  15507. }
  15508. }
  15509. else
  15510. {
  15511. for (int i = numThisTime; --i >= 0;)
  15512. {
  15513. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15514. src += 3;
  15515. }
  15516. }
  15517. }
  15518. }
  15519. else if (bitsPerSample == 32)
  15520. {
  15521. const unsigned int* src = (const unsigned int*) tempBuffer;
  15522. unsigned int* l = (unsigned int*) left;
  15523. unsigned int* r = (unsigned int*) right;
  15524. if (littleEndian)
  15525. {
  15526. if (numChannels > 1)
  15527. {
  15528. if (l == 0)
  15529. {
  15530. for (int i = numThisTime; --i >= 0;)
  15531. {
  15532. ++src;
  15533. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15534. }
  15535. }
  15536. else if (r == 0)
  15537. {
  15538. for (int i = numThisTime; --i >= 0;)
  15539. {
  15540. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15541. ++src;
  15542. }
  15543. }
  15544. else
  15545. {
  15546. for (int i = numThisTime; --i >= 0;)
  15547. {
  15548. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15549. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15550. }
  15551. }
  15552. }
  15553. else
  15554. {
  15555. for (int i = numThisTime; --i >= 0;)
  15556. {
  15557. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15558. }
  15559. }
  15560. }
  15561. else
  15562. {
  15563. if (numChannels > 1)
  15564. {
  15565. if (l == 0)
  15566. {
  15567. for (int i = numThisTime; --i >= 0;)
  15568. {
  15569. ++src;
  15570. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15571. }
  15572. }
  15573. else if (r == 0)
  15574. {
  15575. for (int i = numThisTime; --i >= 0;)
  15576. {
  15577. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15578. ++src;
  15579. }
  15580. }
  15581. else
  15582. {
  15583. for (int i = numThisTime; --i >= 0;)
  15584. {
  15585. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15586. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15587. }
  15588. }
  15589. }
  15590. else
  15591. {
  15592. for (int i = numThisTime; --i >= 0;)
  15593. {
  15594. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15595. }
  15596. }
  15597. }
  15598. left = (int*) l;
  15599. right = (int*) r;
  15600. }
  15601. else if (bitsPerSample == 8)
  15602. {
  15603. const char* src = (const char*) tempBuffer;
  15604. if (numChannels > 1)
  15605. {
  15606. if (left == 0)
  15607. {
  15608. for (int i = numThisTime; --i >= 0;)
  15609. {
  15610. *right++ = ((int) *src++) << 24;
  15611. ++src;
  15612. }
  15613. }
  15614. else if (right == 0)
  15615. {
  15616. for (int i = numThisTime; --i >= 0;)
  15617. {
  15618. ++src;
  15619. *left++ = ((int) *src++) << 24;
  15620. }
  15621. }
  15622. else
  15623. {
  15624. for (int i = numThisTime; --i >= 0;)
  15625. {
  15626. *left++ = ((int) *src++) << 24;
  15627. *right++ = ((int) *src++) << 24;
  15628. }
  15629. }
  15630. }
  15631. else
  15632. {
  15633. for (int i = numThisTime; --i >= 0;)
  15634. {
  15635. *left++ = ((int) *src++) << 24;
  15636. }
  15637. }
  15638. }
  15639. startOffsetInDestBuffer += numThisTime;
  15640. numSamples -= numThisTime;
  15641. }
  15642. if (numSamples > 0)
  15643. {
  15644. for (int i = numDestChannels; --i >= 0;)
  15645. if (destSamples[i] != 0)
  15646. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15647. sizeof (int) * numSamples);
  15648. }
  15649. return true;
  15650. }
  15651. juce_UseDebuggingNewOperator
  15652. private:
  15653. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15654. const AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15655. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15656. };
  15657. class AiffAudioFormatWriter : public AudioFormatWriter
  15658. {
  15659. MemoryBlock tempBlock;
  15660. uint32 lengthInSamples, bytesWritten;
  15661. int64 headerPosition;
  15662. bool writeFailed;
  15663. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15664. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15665. const AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15666. void writeHeader()
  15667. {
  15668. const bool couldSeekOk = output->setPosition (headerPosition);
  15669. (void) couldSeekOk;
  15670. // if this fails, you've given it an output stream that can't seek! It needs
  15671. // to be able to seek back to write the header
  15672. jassert (couldSeekOk);
  15673. const int headerLen = 54;
  15674. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15675. audioBytes += (audioBytes & 1);
  15676. output->writeInt (chunkName ("FORM"));
  15677. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15678. output->writeInt (chunkName ("AIFF"));
  15679. output->writeInt (chunkName ("COMM"));
  15680. output->writeIntBigEndian (18);
  15681. output->writeShortBigEndian ((short) numChannels);
  15682. output->writeIntBigEndian (lengthInSamples);
  15683. output->writeShortBigEndian ((short) bitsPerSample);
  15684. uint8 sampleRateBytes[10];
  15685. zeromem (sampleRateBytes, 10);
  15686. if (sampleRate <= 1)
  15687. {
  15688. sampleRateBytes[0] = 0x3f;
  15689. sampleRateBytes[1] = 0xff;
  15690. sampleRateBytes[2] = 0x80;
  15691. }
  15692. else
  15693. {
  15694. int mask = 0x40000000;
  15695. sampleRateBytes[0] = 0x40;
  15696. if (sampleRate >= mask)
  15697. {
  15698. jassertfalse
  15699. sampleRateBytes[1] = 0x1d;
  15700. }
  15701. else
  15702. {
  15703. int n = (int) sampleRate;
  15704. int i;
  15705. for (i = 0; i <= 32 ; ++i)
  15706. {
  15707. if ((n & mask) != 0)
  15708. break;
  15709. mask >>= 1;
  15710. }
  15711. n = n << (i + 1);
  15712. sampleRateBytes[1] = (uint8) (29 - i);
  15713. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15714. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15715. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15716. sampleRateBytes[5] = (uint8) (n & 0xff);
  15717. }
  15718. }
  15719. output->write (sampleRateBytes, 10);
  15720. output->writeInt (chunkName ("SSND"));
  15721. output->writeIntBigEndian (audioBytes + 8);
  15722. output->writeInt (0);
  15723. output->writeInt (0);
  15724. jassert (output->getPosition() == headerLen);
  15725. }
  15726. public:
  15727. AiffAudioFormatWriter (OutputStream* out,
  15728. const double sampleRate_,
  15729. const unsigned int chans,
  15730. const int bits)
  15731. : AudioFormatWriter (out,
  15732. TRANS (aiffFormatName),
  15733. sampleRate_,
  15734. chans,
  15735. bits),
  15736. lengthInSamples (0),
  15737. bytesWritten (0),
  15738. writeFailed (false)
  15739. {
  15740. headerPosition = out->getPosition();
  15741. writeHeader();
  15742. }
  15743. ~AiffAudioFormatWriter()
  15744. {
  15745. if ((bytesWritten & 1) != 0)
  15746. output->writeByte (0);
  15747. writeHeader();
  15748. }
  15749. bool write (const int** data, int numSamples)
  15750. {
  15751. if (writeFailed)
  15752. return false;
  15753. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15754. tempBlock.ensureSize (bytes, false);
  15755. char* buffer = (char*) tempBlock.getData();
  15756. const int* left = data[0];
  15757. const int* right = data[1];
  15758. if (right == 0)
  15759. right = left;
  15760. if (bitsPerSample == 16)
  15761. {
  15762. short* b = (short*) buffer;
  15763. if (numChannels > 1)
  15764. {
  15765. for (int i = numSamples; --i >= 0;)
  15766. {
  15767. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15768. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15769. }
  15770. }
  15771. else
  15772. {
  15773. for (int i = numSamples; --i >= 0;)
  15774. {
  15775. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15776. }
  15777. }
  15778. }
  15779. else if (bitsPerSample == 24)
  15780. {
  15781. char* b = (char*) buffer;
  15782. if (numChannels > 1)
  15783. {
  15784. for (int i = numSamples; --i >= 0;)
  15785. {
  15786. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15787. b += 3;
  15788. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15789. b += 3;
  15790. }
  15791. }
  15792. else
  15793. {
  15794. for (int i = numSamples; --i >= 0;)
  15795. {
  15796. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15797. b += 3;
  15798. }
  15799. }
  15800. }
  15801. else if (bitsPerSample == 32)
  15802. {
  15803. uint32* b = (uint32*) buffer;
  15804. if (numChannels > 1)
  15805. {
  15806. for (int i = numSamples; --i >= 0;)
  15807. {
  15808. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15809. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15810. }
  15811. }
  15812. else
  15813. {
  15814. for (int i = numSamples; --i >= 0;)
  15815. {
  15816. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15817. }
  15818. }
  15819. }
  15820. else if (bitsPerSample == 8)
  15821. {
  15822. char* b = (char*) buffer;
  15823. if (numChannels > 1)
  15824. {
  15825. for (int i = numSamples; --i >= 0;)
  15826. {
  15827. *b++ = (char) (*left++ >> 24);
  15828. *b++ = (char) (*right++ >> 24);
  15829. }
  15830. }
  15831. else
  15832. {
  15833. for (int i = numSamples; --i >= 0;)
  15834. {
  15835. *b++ = (char) (*left++ >> 24);
  15836. }
  15837. }
  15838. }
  15839. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15840. || ! output->write (buffer, bytes))
  15841. {
  15842. // failed to write to disk, so let's try writing the header.
  15843. // If it's just run out of disk space, then if it does manage
  15844. // to write the header, we'll still have a useable file..
  15845. writeHeader();
  15846. writeFailed = true;
  15847. return false;
  15848. }
  15849. else
  15850. {
  15851. bytesWritten += bytes;
  15852. lengthInSamples += numSamples;
  15853. return true;
  15854. }
  15855. }
  15856. juce_UseDebuggingNewOperator
  15857. };
  15858. AiffAudioFormat::AiffAudioFormat()
  15859. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15860. {
  15861. }
  15862. AiffAudioFormat::~AiffAudioFormat()
  15863. {
  15864. }
  15865. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15866. {
  15867. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15868. return Array <int> (rates);
  15869. }
  15870. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15871. {
  15872. const int depths[] = { 8, 16, 24, 0 };
  15873. return Array <int> (depths);
  15874. }
  15875. bool AiffAudioFormat::canDoStereo()
  15876. {
  15877. return true;
  15878. }
  15879. bool AiffAudioFormat::canDoMono()
  15880. {
  15881. return true;
  15882. }
  15883. #if JUCE_MAC
  15884. bool AiffAudioFormat::canHandleFile (const File& f)
  15885. {
  15886. if (AudioFormat::canHandleFile (f))
  15887. return true;
  15888. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15889. return type == 'AIFF' || type == 'AIFC'
  15890. || type == 'aiff' || type == 'aifc';
  15891. }
  15892. #endif
  15893. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15894. const bool deleteStreamIfOpeningFails)
  15895. {
  15896. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15897. if (w->sampleRate != 0)
  15898. return w.release();
  15899. if (! deleteStreamIfOpeningFails)
  15900. w->input = 0;
  15901. return 0;
  15902. }
  15903. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15904. double sampleRate,
  15905. unsigned int chans,
  15906. int bitsPerSample,
  15907. const StringPairArray& /*metadataValues*/,
  15908. int /*qualityOptionIndex*/)
  15909. {
  15910. if (getPossibleBitDepths().contains (bitsPerSample))
  15911. {
  15912. return new AiffAudioFormatWriter (out,
  15913. sampleRate,
  15914. chans,
  15915. bitsPerSample);
  15916. }
  15917. return 0;
  15918. }
  15919. END_JUCE_NAMESPACE
  15920. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15921. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15922. BEGIN_JUCE_NAMESPACE
  15923. #if JUCE_MAC && JUCE_USE_CDREADER
  15924. // Mac version doesn't need any native code because it's all done with files..
  15925. // Windows + Linux versions are in the platform-dependent code sections.
  15926. static void findCDs (Array<File>& cds)
  15927. {
  15928. File volumes ("/Volumes");
  15929. volumes.findChildFiles (cds, File::findDirectories, false);
  15930. for (int i = cds.size(); --i >= 0;)
  15931. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15932. cds.remove (i);
  15933. }
  15934. const StringArray AudioCDReader::getAvailableCDNames()
  15935. {
  15936. Array<File> cds;
  15937. findCDs (cds);
  15938. StringArray names;
  15939. for (int i = 0; i < cds.size(); ++i)
  15940. names.add (cds.getReference(i).getFileName());
  15941. return names;
  15942. }
  15943. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15944. {
  15945. Array<File> cds;
  15946. findCDs (cds);
  15947. if (cds[index] != File::nonexistent)
  15948. return new AudioCDReader (cds[index]);
  15949. else
  15950. return 0;
  15951. }
  15952. AudioCDReader::AudioCDReader (const File& volume)
  15953. : AudioFormatReader (0, "CD Audio"),
  15954. volumeDir (volume),
  15955. currentReaderTrack (-1),
  15956. reader (0)
  15957. {
  15958. sampleRate = 44100.0;
  15959. bitsPerSample = 16;
  15960. numChannels = 2;
  15961. usesFloatingPointData = false;
  15962. refreshTrackLengths();
  15963. }
  15964. AudioCDReader::~AudioCDReader()
  15965. {
  15966. }
  15967. static int getTrackNumber (const File& file)
  15968. {
  15969. return file.getFileName()
  15970. .initialSectionContainingOnly (T("0123456789"))
  15971. .getIntValue();
  15972. }
  15973. int AudioCDReader::compareElements (const File& first, const File& second)
  15974. {
  15975. const int firstTrack = getTrackNumber (first);
  15976. const int secondTrack = getTrackNumber (second);
  15977. jassert (firstTrack > 0 && secondTrack > 0);
  15978. return firstTrack - secondTrack;
  15979. }
  15980. void AudioCDReader::refreshTrackLengths()
  15981. {
  15982. tracks.clear();
  15983. trackStartSamples.clear();
  15984. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15985. tracks.sort (*this);
  15986. AiffAudioFormat format;
  15987. int sample = 0;
  15988. for (int i = 0; i < tracks.size(); ++i)
  15989. {
  15990. trackStartSamples.add (sample);
  15991. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15992. if (in != 0)
  15993. {
  15994. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15995. if (r != 0)
  15996. sample += (int) r->lengthInSamples;
  15997. }
  15998. }
  15999. trackStartSamples.add (sample);
  16000. lengthInSamples = sample;
  16001. }
  16002. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16003. int64 startSampleInFile, int numSamples)
  16004. {
  16005. while (numSamples > 0)
  16006. {
  16007. int track = -1;
  16008. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  16009. {
  16010. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  16011. {
  16012. track = i;
  16013. break;
  16014. }
  16015. }
  16016. if (track < 0)
  16017. return false;
  16018. if (track != currentReaderTrack)
  16019. {
  16020. reader = 0;
  16021. FileInputStream* const in = tracks [track].createInputStream();
  16022. if (in != 0)
  16023. {
  16024. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  16025. AiffAudioFormat format;
  16026. reader = format.createReaderFor (bin, true);
  16027. if (reader == 0)
  16028. currentReaderTrack = -1;
  16029. else
  16030. currentReaderTrack = track;
  16031. }
  16032. }
  16033. if (reader == 0)
  16034. return false;
  16035. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  16036. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  16037. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  16038. numSamples -= numAvailable;
  16039. startSampleInFile += numAvailable;
  16040. }
  16041. return true;
  16042. }
  16043. bool AudioCDReader::isCDStillPresent() const
  16044. {
  16045. return volumeDir.exists();
  16046. }
  16047. int AudioCDReader::getNumTracks() const
  16048. {
  16049. return tracks.size();
  16050. }
  16051. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  16052. {
  16053. return trackStartSamples [trackNum];
  16054. }
  16055. bool AudioCDReader::isTrackAudio (int trackNum) const
  16056. {
  16057. return tracks [trackNum] != File::nonexistent;
  16058. }
  16059. void AudioCDReader::enableIndexScanning (bool b)
  16060. {
  16061. // any way to do this on a Mac??
  16062. }
  16063. int AudioCDReader::getLastIndex() const
  16064. {
  16065. return 0;
  16066. }
  16067. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  16068. {
  16069. return Array <int>();
  16070. }
  16071. int AudioCDReader::getCDDBId()
  16072. {
  16073. return 0; //xxx
  16074. }
  16075. #endif
  16076. END_JUCE_NAMESPACE
  16077. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  16078. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  16079. BEGIN_JUCE_NAMESPACE
  16080. AudioFormatReader::AudioFormatReader (InputStream* const in,
  16081. const String& formatName_)
  16082. : sampleRate (0),
  16083. bitsPerSample (0),
  16084. lengthInSamples (0),
  16085. numChannels (0),
  16086. usesFloatingPointData (false),
  16087. input (in),
  16088. formatName (formatName_)
  16089. {
  16090. }
  16091. AudioFormatReader::~AudioFormatReader()
  16092. {
  16093. delete input;
  16094. }
  16095. bool AudioFormatReader::read (int** destSamples,
  16096. int numDestChannels,
  16097. int64 startSampleInSource,
  16098. int numSamplesToRead,
  16099. const bool fillLeftoverChannelsWithCopies)
  16100. {
  16101. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  16102. int startOffsetInDestBuffer = 0;
  16103. if (startSampleInSource < 0)
  16104. {
  16105. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  16106. for (int i = numDestChannels; --i >= 0;)
  16107. if (destSamples[i] != 0)
  16108. zeromem (destSamples[i], sizeof (int) * silence);
  16109. startOffsetInDestBuffer += silence;
  16110. numSamplesToRead -= silence;
  16111. startSampleInSource = 0;
  16112. }
  16113. if (numSamplesToRead <= 0)
  16114. return true;
  16115. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  16116. startSampleInSource, numSamplesToRead))
  16117. return false;
  16118. if (numDestChannels > (int) numChannels)
  16119. {
  16120. if (fillLeftoverChannelsWithCopies)
  16121. {
  16122. int* lastFullChannel = destSamples[0];
  16123. for (int i = numDestChannels; --i > 0;)
  16124. {
  16125. if (destSamples[i] != 0)
  16126. {
  16127. lastFullChannel = destSamples[i];
  16128. break;
  16129. }
  16130. }
  16131. if (lastFullChannel != 0)
  16132. for (int i = numChannels; i < numDestChannels; ++i)
  16133. if (destSamples[i] != 0)
  16134. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  16135. }
  16136. else
  16137. {
  16138. for (int i = numChannels; i < numDestChannels; ++i)
  16139. if (destSamples[i] != 0)
  16140. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  16141. }
  16142. }
  16143. return true;
  16144. }
  16145. static void findMaxMin (const float* src, const int num,
  16146. float& maxVal, float& minVal)
  16147. {
  16148. float mn = src[0];
  16149. float mx = mn;
  16150. for (int i = 1; i < num; ++i)
  16151. {
  16152. const float s = src[i];
  16153. if (s > mx)
  16154. mx = s;
  16155. if (s < mn)
  16156. mn = s;
  16157. }
  16158. maxVal = mx;
  16159. minVal = mn;
  16160. }
  16161. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  16162. int64 numSamples,
  16163. float& lowestLeft, float& highestLeft,
  16164. float& lowestRight, float& highestRight)
  16165. {
  16166. if (numSamples <= 0)
  16167. {
  16168. lowestLeft = 0;
  16169. lowestRight = 0;
  16170. highestLeft = 0;
  16171. highestRight = 0;
  16172. return;
  16173. }
  16174. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  16175. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16176. int* tempBuffer[3];
  16177. tempBuffer[0] = (int*) tempSpace.getData();
  16178. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16179. tempBuffer[2] = 0;
  16180. if (usesFloatingPointData)
  16181. {
  16182. float lmin = 1.0e6f;
  16183. float lmax = -lmin;
  16184. float rmin = lmin;
  16185. float rmax = lmax;
  16186. while (numSamples > 0)
  16187. {
  16188. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16189. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16190. numSamples -= numToDo;
  16191. startSampleInFile += numToDo;
  16192. float bufmin, bufmax;
  16193. findMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  16194. lmin = jmin (lmin, bufmin);
  16195. lmax = jmax (lmax, bufmax);
  16196. if (numChannels > 1)
  16197. {
  16198. findMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  16199. rmin = jmin (rmin, bufmin);
  16200. rmax = jmax (rmax, bufmax);
  16201. }
  16202. }
  16203. if (numChannels <= 1)
  16204. {
  16205. rmax = lmax;
  16206. rmin = lmin;
  16207. }
  16208. lowestLeft = lmin;
  16209. highestLeft = lmax;
  16210. lowestRight = rmin;
  16211. highestRight = rmax;
  16212. }
  16213. else
  16214. {
  16215. int lmax = std::numeric_limits<int>::min();
  16216. int lmin = std::numeric_limits<int>::max();
  16217. int rmax = std::numeric_limits<int>::min();
  16218. int rmin = std::numeric_limits<int>::max();
  16219. while (numSamples > 0)
  16220. {
  16221. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16222. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16223. numSamples -= numToDo;
  16224. startSampleInFile += numToDo;
  16225. for (int j = numChannels; --j >= 0;)
  16226. {
  16227. int bufMax = std::numeric_limits<int>::min();
  16228. int bufMin = std::numeric_limits<int>::max();
  16229. const int* const b = tempBuffer[j];
  16230. for (int i = 0; i < numToDo; ++i)
  16231. {
  16232. const int samp = b[i];
  16233. if (samp < bufMin)
  16234. bufMin = samp;
  16235. if (samp > bufMax)
  16236. bufMax = samp;
  16237. }
  16238. if (j == 0)
  16239. {
  16240. lmax = jmax (lmax, bufMax);
  16241. lmin = jmin (lmin, bufMin);
  16242. }
  16243. else
  16244. {
  16245. rmax = jmax (rmax, bufMax);
  16246. rmin = jmin (rmin, bufMin);
  16247. }
  16248. }
  16249. }
  16250. if (numChannels <= 1)
  16251. {
  16252. rmax = lmax;
  16253. rmin = lmin;
  16254. }
  16255. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  16256. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  16257. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  16258. highestRight = rmax / (float) std::numeric_limits<int>::max();
  16259. }
  16260. }
  16261. int64 AudioFormatReader::searchForLevel (int64 startSample,
  16262. int64 numSamplesToSearch,
  16263. const double magnitudeRangeMinimum,
  16264. const double magnitudeRangeMaximum,
  16265. const int minimumConsecutiveSamples)
  16266. {
  16267. if (numSamplesToSearch == 0)
  16268. return -1;
  16269. const int bufferSize = 4096;
  16270. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16271. int* tempBuffer[3];
  16272. tempBuffer[0] = (int*) tempSpace.getData();
  16273. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16274. tempBuffer[2] = 0;
  16275. int consecutive = 0;
  16276. int64 firstMatchPos = -1;
  16277. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  16278. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  16279. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  16280. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16281. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16282. while (numSamplesToSearch != 0)
  16283. {
  16284. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16285. int64 bufferStart = startSample;
  16286. if (numSamplesToSearch < 0)
  16287. bufferStart -= numThisTime;
  16288. if (bufferStart >= (int) lengthInSamples)
  16289. break;
  16290. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16291. int num = numThisTime;
  16292. while (--num >= 0)
  16293. {
  16294. if (numSamplesToSearch < 0)
  16295. --startSample;
  16296. bool matches = false;
  16297. const int index = (int) (startSample - bufferStart);
  16298. if (usesFloatingPointData)
  16299. {
  16300. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16301. if (sample1 >= magnitudeRangeMinimum
  16302. && sample1 <= magnitudeRangeMaximum)
  16303. {
  16304. matches = true;
  16305. }
  16306. else if (numChannels > 1)
  16307. {
  16308. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16309. matches = (sample2 >= magnitudeRangeMinimum
  16310. && sample2 <= magnitudeRangeMaximum);
  16311. }
  16312. }
  16313. else
  16314. {
  16315. const int sample1 = abs (tempBuffer[0] [index]);
  16316. if (sample1 >= intMagnitudeRangeMinimum
  16317. && sample1 <= intMagnitudeRangeMaximum)
  16318. {
  16319. matches = true;
  16320. }
  16321. else if (numChannels > 1)
  16322. {
  16323. const int sample2 = abs (tempBuffer[1][index]);
  16324. matches = (sample2 >= intMagnitudeRangeMinimum
  16325. && sample2 <= intMagnitudeRangeMaximum);
  16326. }
  16327. }
  16328. if (matches)
  16329. {
  16330. if (firstMatchPos < 0)
  16331. firstMatchPos = startSample;
  16332. if (++consecutive >= minimumConsecutiveSamples)
  16333. {
  16334. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16335. return -1;
  16336. return firstMatchPos;
  16337. }
  16338. }
  16339. else
  16340. {
  16341. consecutive = 0;
  16342. firstMatchPos = -1;
  16343. }
  16344. if (numSamplesToSearch > 0)
  16345. ++startSample;
  16346. }
  16347. if (numSamplesToSearch > 0)
  16348. numSamplesToSearch -= numThisTime;
  16349. else
  16350. numSamplesToSearch += numThisTime;
  16351. }
  16352. return -1;
  16353. }
  16354. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16355. const String& formatName_,
  16356. const double rate,
  16357. const unsigned int numChannels_,
  16358. const unsigned int bitsPerSample_)
  16359. : sampleRate (rate),
  16360. numChannels (numChannels_),
  16361. bitsPerSample (bitsPerSample_),
  16362. usesFloatingPointData (false),
  16363. output (out),
  16364. formatName (formatName_)
  16365. {
  16366. }
  16367. AudioFormatWriter::~AudioFormatWriter()
  16368. {
  16369. delete output;
  16370. }
  16371. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16372. int64 startSample,
  16373. int64 numSamplesToRead)
  16374. {
  16375. const int bufferSize = 16384;
  16376. const int maxChans = 128;
  16377. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16378. int* buffers [maxChans];
  16379. for (int i = maxChans; --i >= 0;)
  16380. buffers[i] = 0;
  16381. if (numSamplesToRead < 0)
  16382. numSamplesToRead = reader.lengthInSamples;
  16383. while (numSamplesToRead > 0)
  16384. {
  16385. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16386. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16387. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16388. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16389. return false;
  16390. if (reader.usesFloatingPointData != isFloatingPoint())
  16391. {
  16392. int** bufferChan = buffers;
  16393. while (*bufferChan != 0)
  16394. {
  16395. int* b = *bufferChan++;
  16396. if (isFloatingPoint())
  16397. {
  16398. // int -> float
  16399. const double factor = 1.0 / std::numeric_limits<int>::max();
  16400. for (int i = 0; i < numToDo; ++i)
  16401. ((float*) b)[i] = (float) (factor * b[i]);
  16402. }
  16403. else
  16404. {
  16405. // float -> int
  16406. for (int i = 0; i < numToDo; ++i)
  16407. {
  16408. const double samp = *(const float*) b;
  16409. if (samp <= -1.0)
  16410. *b++ = std::numeric_limits<int>::min();
  16411. else if (samp >= 1.0)
  16412. *b++ = std::numeric_limits<int>::max();
  16413. else
  16414. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16415. }
  16416. }
  16417. }
  16418. }
  16419. if (! write ((const int**) buffers, numToDo))
  16420. return false;
  16421. numSamplesToRead -= numToDo;
  16422. startSample += numToDo;
  16423. }
  16424. return true;
  16425. }
  16426. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16427. int numSamplesToRead,
  16428. const int samplesPerBlock)
  16429. {
  16430. const int maxChans = 128;
  16431. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16432. int* buffers [maxChans];
  16433. while (numSamplesToRead > 0)
  16434. {
  16435. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16436. AudioSourceChannelInfo info;
  16437. info.buffer = &tempBuffer;
  16438. info.startSample = 0;
  16439. info.numSamples = numToDo;
  16440. info.clearActiveBufferRegion();
  16441. source.getNextAudioBlock (info);
  16442. int i;
  16443. for (i = maxChans; --i >= 0;)
  16444. buffers[i] = 0;
  16445. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16446. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16447. if (! isFloatingPoint())
  16448. {
  16449. int** bufferChan = buffers;
  16450. while (*bufferChan != 0)
  16451. {
  16452. int* b = *bufferChan++;
  16453. // float -> int
  16454. for (int j = numToDo; --j >= 0;)
  16455. {
  16456. const double samp = *(const float*) b;
  16457. if (samp <= -1.0)
  16458. *b++ = std::numeric_limits<int>::min();
  16459. else if (samp >= 1.0)
  16460. *b++ = std::numeric_limits<int>::max();
  16461. else
  16462. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16463. }
  16464. }
  16465. }
  16466. if (! write ((const int**) buffers, numToDo))
  16467. return false;
  16468. numSamplesToRead -= numToDo;
  16469. }
  16470. return true;
  16471. }
  16472. AudioFormat::AudioFormat (const String& name,
  16473. const tchar** const extensions)
  16474. : formatName (name),
  16475. fileExtensions (extensions)
  16476. {
  16477. }
  16478. AudioFormat::~AudioFormat()
  16479. {
  16480. }
  16481. const String& AudioFormat::getFormatName() const
  16482. {
  16483. return formatName;
  16484. }
  16485. const StringArray& AudioFormat::getFileExtensions() const
  16486. {
  16487. return fileExtensions;
  16488. }
  16489. bool AudioFormat::canHandleFile (const File& f)
  16490. {
  16491. for (int i = 0; i < fileExtensions.size(); ++i)
  16492. if (f.hasFileExtension (fileExtensions[i]))
  16493. return true;
  16494. return false;
  16495. }
  16496. bool AudioFormat::isCompressed()
  16497. {
  16498. return false;
  16499. }
  16500. const StringArray AudioFormat::getQualityOptions()
  16501. {
  16502. return StringArray();
  16503. }
  16504. END_JUCE_NAMESPACE
  16505. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16506. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16507. BEGIN_JUCE_NAMESPACE
  16508. AudioFormatManager::AudioFormatManager()
  16509. : defaultFormatIndex (0)
  16510. {
  16511. }
  16512. AudioFormatManager::~AudioFormatManager()
  16513. {
  16514. clearFormats();
  16515. clearSingletonInstance();
  16516. }
  16517. juce_ImplementSingleton (AudioFormatManager);
  16518. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16519. const bool makeThisTheDefaultFormat)
  16520. {
  16521. jassert (newFormat != 0);
  16522. if (newFormat != 0)
  16523. {
  16524. #ifdef JUCE_DEBUG
  16525. for (int i = getNumKnownFormats(); --i >= 0;)
  16526. {
  16527. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16528. {
  16529. jassertfalse // trying to add the same format twice!
  16530. }
  16531. }
  16532. #endif
  16533. if (makeThisTheDefaultFormat)
  16534. defaultFormatIndex = knownFormats.size();
  16535. knownFormats.add (newFormat);
  16536. }
  16537. }
  16538. void AudioFormatManager::registerBasicFormats()
  16539. {
  16540. #if JUCE_MAC
  16541. registerFormat (new AiffAudioFormat(), true);
  16542. registerFormat (new WavAudioFormat(), false);
  16543. #else
  16544. registerFormat (new WavAudioFormat(), true);
  16545. registerFormat (new AiffAudioFormat(), false);
  16546. #endif
  16547. #if JUCE_USE_FLAC
  16548. registerFormat (new FlacAudioFormat(), false);
  16549. #endif
  16550. #if JUCE_USE_OGGVORBIS
  16551. registerFormat (new OggVorbisAudioFormat(), false);
  16552. #endif
  16553. }
  16554. void AudioFormatManager::clearFormats()
  16555. {
  16556. for (int i = getNumKnownFormats(); --i >= 0;)
  16557. delete getKnownFormat(i);
  16558. knownFormats.clear();
  16559. defaultFormatIndex = 0;
  16560. }
  16561. int AudioFormatManager::getNumKnownFormats() const
  16562. {
  16563. return knownFormats.size();
  16564. }
  16565. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16566. {
  16567. return (AudioFormat*) knownFormats [index];
  16568. }
  16569. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16570. {
  16571. return getKnownFormat (defaultFormatIndex);
  16572. }
  16573. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16574. {
  16575. String e (fileExtension);
  16576. if (! e.startsWithChar (T('.')))
  16577. e = T(".") + e;
  16578. for (int i = 0; i < getNumKnownFormats(); ++i)
  16579. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16580. return getKnownFormat(i);
  16581. return 0;
  16582. }
  16583. const String AudioFormatManager::getWildcardForAllFormats() const
  16584. {
  16585. StringArray allExtensions;
  16586. int i;
  16587. for (i = 0; i < getNumKnownFormats(); ++i)
  16588. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16589. allExtensions.trim();
  16590. allExtensions.removeEmptyStrings();
  16591. String s;
  16592. for (i = 0; i < allExtensions.size(); ++i)
  16593. {
  16594. s << T('*');
  16595. if (! allExtensions[i].startsWithChar (T('.')))
  16596. s << T('.');
  16597. s << allExtensions[i];
  16598. if (i < allExtensions.size() - 1)
  16599. s << T(';');
  16600. }
  16601. return s;
  16602. }
  16603. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16604. {
  16605. // you need to actually register some formats before the manager can
  16606. // use them to open a file!
  16607. jassert (knownFormats.size() > 0);
  16608. for (int i = 0; i < getNumKnownFormats(); ++i)
  16609. {
  16610. AudioFormat* const af = getKnownFormat(i);
  16611. if (af->canHandleFile (file))
  16612. {
  16613. InputStream* const in = file.createInputStream();
  16614. if (in != 0)
  16615. {
  16616. AudioFormatReader* const r = af->createReaderFor (in, true);
  16617. if (r != 0)
  16618. return r;
  16619. }
  16620. }
  16621. }
  16622. return 0;
  16623. }
  16624. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16625. {
  16626. // you need to actually register some formats before the manager can
  16627. // use them to open a file!
  16628. jassert (knownFormats.size() > 0);
  16629. ScopedPointer <InputStream> in (audioFileStream);
  16630. if (in != 0)
  16631. {
  16632. const int64 originalStreamPos = in->getPosition();
  16633. for (int i = 0; i < getNumKnownFormats(); ++i)
  16634. {
  16635. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16636. if (r != 0)
  16637. {
  16638. in.release();
  16639. return r;
  16640. }
  16641. in->setPosition (originalStreamPos);
  16642. // the stream that is passed-in must be capable of being repositioned so
  16643. // that all the formats can have a go at opening it.
  16644. jassert (in->getPosition() == originalStreamPos);
  16645. }
  16646. }
  16647. return 0;
  16648. }
  16649. END_JUCE_NAMESPACE
  16650. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16651. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16652. BEGIN_JUCE_NAMESPACE
  16653. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16654. const int64 startSample_,
  16655. const int64 length_,
  16656. const bool deleteSourceWhenDeleted_)
  16657. : AudioFormatReader (0, source_->getFormatName()),
  16658. source (source_),
  16659. startSample (startSample_),
  16660. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16661. {
  16662. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16663. sampleRate = source->sampleRate;
  16664. bitsPerSample = source->bitsPerSample;
  16665. lengthInSamples = length;
  16666. numChannels = source->numChannels;
  16667. usesFloatingPointData = source->usesFloatingPointData;
  16668. }
  16669. AudioSubsectionReader::~AudioSubsectionReader()
  16670. {
  16671. if (deleteSourceWhenDeleted)
  16672. delete source;
  16673. }
  16674. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16675. int64 startSampleInFile, int numSamples)
  16676. {
  16677. if (startSampleInFile + numSamples > length)
  16678. {
  16679. for (int i = numDestChannels; --i >= 0;)
  16680. if (destSamples[i] != 0)
  16681. zeromem (destSamples[i], sizeof (int) * numSamples);
  16682. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16683. if (numSamples <= 0)
  16684. return true;
  16685. }
  16686. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16687. startSampleInFile + startSample, numSamples);
  16688. }
  16689. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16690. int64 numSamples,
  16691. float& lowestLeft,
  16692. float& highestLeft,
  16693. float& lowestRight,
  16694. float& highestRight)
  16695. {
  16696. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16697. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16698. source->readMaxLevels (startSampleInFile + startSample,
  16699. numSamples,
  16700. lowestLeft,
  16701. highestLeft,
  16702. lowestRight,
  16703. highestRight);
  16704. }
  16705. END_JUCE_NAMESPACE
  16706. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16707. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16708. BEGIN_JUCE_NAMESPACE
  16709. const int timeBeforeDeletingReader = 2000;
  16710. struct AudioThumbnailDataFormat
  16711. {
  16712. char thumbnailMagic[4];
  16713. int samplesPerThumbSample;
  16714. int64 totalSamples; // source samples
  16715. int64 numFinishedSamples; // source samples
  16716. int numThumbnailSamples;
  16717. int numChannels;
  16718. int sampleRate;
  16719. char future[16];
  16720. char data[1];
  16721. };
  16722. #if JUCE_BIG_ENDIAN
  16723. static void swap (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16724. static void swap (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16725. #endif
  16726. static void swapEndiannessIfNeeded (AudioThumbnailDataFormat* const d)
  16727. {
  16728. (void) d;
  16729. #if JUCE_BIG_ENDIAN
  16730. swap (d->samplesPerThumbSample);
  16731. swap (d->totalSamples);
  16732. swap (d->numFinishedSamples);
  16733. swap (d->numThumbnailSamples);
  16734. swap (d->numChannels);
  16735. swap (d->sampleRate);
  16736. #endif
  16737. }
  16738. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16739. AudioFormatManager& formatManagerToUse_,
  16740. AudioThumbnailCache& cacheToUse)
  16741. : formatManagerToUse (formatManagerToUse_),
  16742. cache (cacheToUse),
  16743. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16744. {
  16745. clear();
  16746. }
  16747. AudioThumbnail::~AudioThumbnail()
  16748. {
  16749. cache.removeThumbnail (this);
  16750. const ScopedLock sl (readerLock);
  16751. reader = 0;
  16752. }
  16753. void AudioThumbnail::setSource (InputSource* const newSource)
  16754. {
  16755. cache.removeThumbnail (this);
  16756. timerCallback(); // stops the timer and deletes the reader
  16757. source = newSource;
  16758. clear();
  16759. if (newSource != 0
  16760. && ! (cache.loadThumb (*this, newSource->hashCode())
  16761. && isFullyLoaded()))
  16762. {
  16763. {
  16764. const ScopedLock sl (readerLock);
  16765. reader = createReader();
  16766. }
  16767. if (reader != 0)
  16768. {
  16769. initialiseFromAudioFile (*reader);
  16770. cache.addThumbnail (this);
  16771. }
  16772. }
  16773. sendChangeMessage (this);
  16774. }
  16775. bool AudioThumbnail::useTimeSlice()
  16776. {
  16777. const ScopedLock sl (readerLock);
  16778. if (isFullyLoaded())
  16779. {
  16780. if (reader != 0)
  16781. startTimer (timeBeforeDeletingReader);
  16782. cache.removeThumbnail (this);
  16783. return false;
  16784. }
  16785. if (reader == 0)
  16786. reader = createReader();
  16787. if (reader != 0)
  16788. {
  16789. readNextBlockFromAudioFile (*reader);
  16790. stopTimer();
  16791. sendChangeMessage (this);
  16792. const bool justFinished = isFullyLoaded();
  16793. if (justFinished)
  16794. cache.storeThumb (*this, source->hashCode());
  16795. return ! justFinished;
  16796. }
  16797. return false;
  16798. }
  16799. AudioFormatReader* AudioThumbnail::createReader() const
  16800. {
  16801. if (source != 0)
  16802. {
  16803. InputStream* const audioFileStream = source->createInputStream();
  16804. if (audioFileStream != 0)
  16805. return formatManagerToUse.createReaderFor (audioFileStream);
  16806. }
  16807. return 0;
  16808. }
  16809. void AudioThumbnail::timerCallback()
  16810. {
  16811. stopTimer();
  16812. const ScopedLock sl (readerLock);
  16813. reader = 0;
  16814. }
  16815. void AudioThumbnail::clear()
  16816. {
  16817. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16818. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16819. d->thumbnailMagic[0] = 'j';
  16820. d->thumbnailMagic[1] = 'a';
  16821. d->thumbnailMagic[2] = 't';
  16822. d->thumbnailMagic[3] = 'm';
  16823. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16824. d->totalSamples = 0;
  16825. d->numFinishedSamples = 0;
  16826. d->numThumbnailSamples = 0;
  16827. d->numChannels = 0;
  16828. d->sampleRate = 0;
  16829. numSamplesCached = 0;
  16830. cacheNeedsRefilling = true;
  16831. }
  16832. void AudioThumbnail::loadFrom (InputStream& input)
  16833. {
  16834. const ScopedLock sl (readerLock);
  16835. data.setSize (0);
  16836. input.readIntoMemoryBlock (data);
  16837. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16838. swapEndiannessIfNeeded (d);
  16839. if (! (d->thumbnailMagic[0] == 'j'
  16840. && d->thumbnailMagic[1] == 'a'
  16841. && d->thumbnailMagic[2] == 't'
  16842. && d->thumbnailMagic[3] == 'm'))
  16843. {
  16844. clear();
  16845. }
  16846. numSamplesCached = 0;
  16847. cacheNeedsRefilling = true;
  16848. }
  16849. void AudioThumbnail::saveTo (OutputStream& output) const
  16850. {
  16851. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16852. swapEndiannessIfNeeded (d);
  16853. output.write (data.getData(), (int) data.getSize());
  16854. swapEndiannessIfNeeded (d);
  16855. }
  16856. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16857. {
  16858. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16859. d->totalSamples = fileReader.lengthInSamples;
  16860. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16861. d->numFinishedSamples = 0;
  16862. d->sampleRate = roundToInt (fileReader.sampleRate);
  16863. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16864. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16865. d = (AudioThumbnailDataFormat*) data.getData();
  16866. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16867. return d->totalSamples > 0;
  16868. }
  16869. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16870. {
  16871. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16872. if (d->numFinishedSamples < d->totalSamples)
  16873. {
  16874. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16875. generateSection (fileReader,
  16876. d->numFinishedSamples,
  16877. numToDo);
  16878. d->numFinishedSamples += numToDo;
  16879. }
  16880. cacheNeedsRefilling = true;
  16881. return (d->numFinishedSamples < d->totalSamples);
  16882. }
  16883. int AudioThumbnail::getNumChannels() const throw()
  16884. {
  16885. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16886. jassert (d != 0);
  16887. return d->numChannels;
  16888. }
  16889. double AudioThumbnail::getTotalLength() const throw()
  16890. {
  16891. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16892. jassert (d != 0);
  16893. if (d->sampleRate > 0)
  16894. return d->totalSamples / (double)d->sampleRate;
  16895. else
  16896. return 0.0;
  16897. }
  16898. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16899. int64 startSample,
  16900. int numSamples)
  16901. {
  16902. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16903. jassert (d != 0);
  16904. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16905. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16906. char* l = getChannelData (0);
  16907. char* r = getChannelData (1);
  16908. for (int i = firstDataPos; i < lastDataPos; ++i)
  16909. {
  16910. const int sourceStart = i * d->samplesPerThumbSample;
  16911. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16912. float lowestLeft, highestLeft, lowestRight, highestRight;
  16913. fileReader.readMaxLevels (sourceStart,
  16914. sourceEnd - sourceStart,
  16915. lowestLeft,
  16916. highestLeft,
  16917. lowestRight,
  16918. highestRight);
  16919. int n = i * 2;
  16920. if (r != 0)
  16921. {
  16922. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16923. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16924. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16925. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16926. }
  16927. else
  16928. {
  16929. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16930. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16931. }
  16932. }
  16933. }
  16934. char* AudioThumbnail::getChannelData (int channel) const
  16935. {
  16936. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16937. jassert (d != 0);
  16938. if (channel >= 0 && channel < d->numChannels)
  16939. return d->data + (channel * 2 * d->numThumbnailSamples);
  16940. return 0;
  16941. }
  16942. bool AudioThumbnail::isFullyLoaded() const throw()
  16943. {
  16944. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16945. jassert (d != 0);
  16946. return d->numFinishedSamples >= d->totalSamples;
  16947. }
  16948. void AudioThumbnail::refillCache (const int numSamples,
  16949. double startTime,
  16950. const double timePerPixel)
  16951. {
  16952. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16953. jassert (d != 0);
  16954. if (numSamples <= 0
  16955. || timePerPixel <= 0.0
  16956. || d->sampleRate <= 0)
  16957. {
  16958. numSamplesCached = 0;
  16959. cacheNeedsRefilling = true;
  16960. return;
  16961. }
  16962. if (numSamples == numSamplesCached
  16963. && numChannelsCached == d->numChannels
  16964. && startTime == cachedStart
  16965. && timePerPixel == cachedTimePerPixel
  16966. && ! cacheNeedsRefilling)
  16967. {
  16968. return;
  16969. }
  16970. numSamplesCached = numSamples;
  16971. numChannelsCached = d->numChannels;
  16972. cachedStart = startTime;
  16973. cachedTimePerPixel = timePerPixel;
  16974. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16975. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16976. const ScopedLock sl (readerLock);
  16977. cacheNeedsRefilling = false;
  16978. if (needExtraDetail && reader == 0)
  16979. reader = createReader();
  16980. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16981. {
  16982. startTimer (timeBeforeDeletingReader);
  16983. char* cacheData = (char*) cachedLevels.getData();
  16984. int sample = roundToInt (startTime * d->sampleRate);
  16985. for (int i = numSamples; --i >= 0;)
  16986. {
  16987. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16988. if (sample >= 0)
  16989. {
  16990. if (sample >= reader->lengthInSamples)
  16991. break;
  16992. float lmin, lmax, rmin, rmax;
  16993. reader->readMaxLevels (sample,
  16994. jmax (1, nextSample - sample),
  16995. lmin, lmax, rmin, rmax);
  16996. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16997. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16998. if (numChannelsCached > 1)
  16999. {
  17000. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  17001. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  17002. }
  17003. cacheData += 2 * numChannelsCached;
  17004. }
  17005. startTime += timePerPixel;
  17006. sample = nextSample;
  17007. }
  17008. }
  17009. else
  17010. {
  17011. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  17012. {
  17013. char* const channelData = getChannelData (channelNum);
  17014. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  17015. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  17016. startTime = cachedStart;
  17017. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  17018. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  17019. for (int i = numSamples; --i >= 0;)
  17020. {
  17021. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  17022. if (sample >= 0 && channelData != 0)
  17023. {
  17024. char mx = -128;
  17025. char mn = 127;
  17026. while (sample <= nextSample)
  17027. {
  17028. if (sample >= numFinished)
  17029. break;
  17030. const int n = sample << 1;
  17031. const char sampMin = channelData [n];
  17032. const char sampMax = channelData [n + 1];
  17033. if (sampMin < mn)
  17034. mn = sampMin;
  17035. if (sampMax > mx)
  17036. mx = sampMax;
  17037. ++sample;
  17038. }
  17039. if (mn <= mx)
  17040. {
  17041. cacheData[0] = mn;
  17042. cacheData[1] = mx;
  17043. }
  17044. else
  17045. {
  17046. cacheData[0] = 1;
  17047. cacheData[1] = 0;
  17048. }
  17049. }
  17050. else
  17051. {
  17052. cacheData[0] = 1;
  17053. cacheData[1] = 0;
  17054. }
  17055. cacheData += numChannelsCached * 2;
  17056. startTime += timePerPixel;
  17057. sample = nextSample;
  17058. }
  17059. }
  17060. }
  17061. }
  17062. void AudioThumbnail::drawChannel (Graphics& g,
  17063. int x, int y, int w, int h,
  17064. double startTime,
  17065. double endTime,
  17066. int channelNum,
  17067. const float verticalZoomFactor)
  17068. {
  17069. refillCache (w, startTime, (endTime - startTime) / w);
  17070. if (numSamplesCached >= w
  17071. && channelNum >= 0
  17072. && channelNum < numChannelsCached)
  17073. {
  17074. const float topY = (float) y;
  17075. const float bottomY = topY + h;
  17076. const float midY = topY + h * 0.5f;
  17077. const float vscale = verticalZoomFactor * h / 256.0f;
  17078. const Rectangle<int> clip (g.getClipBounds());
  17079. const int skipLeft = jlimit (0, w, clip.getX() - x);
  17080. w -= skipLeft;
  17081. x += skipLeft;
  17082. const char* cacheData = ((const char*) cachedLevels.getData())
  17083. + (channelNum << 1)
  17084. + skipLeft * (numChannelsCached << 1);
  17085. while (--w >= 0)
  17086. {
  17087. const char mn = cacheData[0];
  17088. const char mx = cacheData[1];
  17089. cacheData += numChannelsCached << 1;
  17090. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  17091. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  17092. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  17093. ++x;
  17094. if (x >= clip.getRight())
  17095. break;
  17096. }
  17097. }
  17098. }
  17099. END_JUCE_NAMESPACE
  17100. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  17101. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  17102. BEGIN_JUCE_NAMESPACE
  17103. struct ThumbnailCacheEntry
  17104. {
  17105. int64 hash;
  17106. uint32 lastUsed;
  17107. MemoryBlock data;
  17108. juce_UseDebuggingNewOperator
  17109. };
  17110. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  17111. : TimeSliceThread (T("thumb cache")),
  17112. maxNumThumbsToStore (maxNumThumbsToStore_)
  17113. {
  17114. startThread (2);
  17115. }
  17116. AudioThumbnailCache::~AudioThumbnailCache()
  17117. {
  17118. }
  17119. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  17120. {
  17121. for (int i = thumbs.size(); --i >= 0;)
  17122. {
  17123. if (thumbs[i]->hash == hashCode)
  17124. {
  17125. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  17126. thumbs[i]->data.getSize(),
  17127. false);
  17128. thumb.loadFrom (in);
  17129. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  17130. return true;
  17131. }
  17132. }
  17133. return false;
  17134. }
  17135. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  17136. const int64 hashCode)
  17137. {
  17138. MemoryOutputStream out;
  17139. thumb.saveTo (out);
  17140. ThumbnailCacheEntry* te = 0;
  17141. for (int i = thumbs.size(); --i >= 0;)
  17142. {
  17143. if (thumbs[i]->hash == hashCode)
  17144. {
  17145. te = thumbs[i];
  17146. break;
  17147. }
  17148. }
  17149. if (te == 0)
  17150. {
  17151. te = new ThumbnailCacheEntry();
  17152. te->hash = hashCode;
  17153. if (thumbs.size() < maxNumThumbsToStore)
  17154. {
  17155. thumbs.add (te);
  17156. }
  17157. else
  17158. {
  17159. int oldest = 0;
  17160. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  17161. int i;
  17162. for (i = thumbs.size(); --i >= 0;)
  17163. if (thumbs[i]->lastUsed < oldestTime)
  17164. oldest = i;
  17165. thumbs.set (i, te);
  17166. }
  17167. }
  17168. te->lastUsed = Time::getMillisecondCounter();
  17169. te->data.setSize (0);
  17170. te->data.append (out.getData(), out.getDataSize());
  17171. }
  17172. void AudioThumbnailCache::clear()
  17173. {
  17174. thumbs.clear();
  17175. }
  17176. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  17177. {
  17178. addTimeSliceClient (thumb);
  17179. }
  17180. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  17181. {
  17182. removeTimeSliceClient (thumb);
  17183. }
  17184. END_JUCE_NAMESPACE
  17185. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  17186. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17187. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  17188. #if ! JUCE_WINDOWS
  17189. #include <QuickTime/Movies.h>
  17190. #include <QuickTime/QTML.h>
  17191. #include <QuickTime/QuickTimeComponents.h>
  17192. #include <QuickTime/MediaHandlers.h>
  17193. #include <QuickTime/ImageCodec.h>
  17194. #else
  17195. #if JUCE_MSVC
  17196. #pragma warning (push)
  17197. #pragma warning (disable : 4100)
  17198. #endif
  17199. #include <Movies.h>
  17200. #include <QTML.h>
  17201. #include <QuickTimeComponents.h>
  17202. #include <MediaHandlers.h>
  17203. #include <ImageCodec.h>
  17204. #if JUCE_MSVC
  17205. #pragma warning (pop)
  17206. #endif
  17207. #endif
  17208. BEGIN_JUCE_NAMESPACE
  17209. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  17210. static const char* const quickTimeFormatName = "QuickTime file";
  17211. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  17212. class QTAudioReader : public AudioFormatReader
  17213. {
  17214. public:
  17215. QTAudioReader (InputStream* const input_, const int trackNum_)
  17216. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  17217. ok (false),
  17218. movie (0),
  17219. trackNum (trackNum_),
  17220. lastSampleRead (0),
  17221. lastThreadId (0),
  17222. extractor (0),
  17223. dataHandle (0)
  17224. {
  17225. bufferList.calloc (256, 1);
  17226. #ifdef WIN32
  17227. if (InitializeQTML (0) != noErr)
  17228. return;
  17229. #endif
  17230. if (EnterMovies() != noErr)
  17231. return;
  17232. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  17233. if (! opened)
  17234. return;
  17235. {
  17236. const int numTracks = GetMovieTrackCount (movie);
  17237. int trackCount = 0;
  17238. for (int i = 1; i <= numTracks; ++i)
  17239. {
  17240. track = GetMovieIndTrack (movie, i);
  17241. media = GetTrackMedia (track);
  17242. OSType mediaType;
  17243. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  17244. if (mediaType == SoundMediaType
  17245. && trackCount++ == trackNum_)
  17246. {
  17247. ok = true;
  17248. break;
  17249. }
  17250. }
  17251. }
  17252. if (! ok)
  17253. return;
  17254. ok = false;
  17255. lengthInSamples = GetMediaDecodeDuration (media);
  17256. usesFloatingPointData = false;
  17257. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  17258. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  17259. / GetMediaTimeScale (media);
  17260. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  17261. unsigned long output_layout_size;
  17262. err = MovieAudioExtractionGetPropertyInfo (extractor,
  17263. kQTPropertyClass_MovieAudioExtraction_Audio,
  17264. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17265. 0, &output_layout_size, 0);
  17266. if (err != noErr)
  17267. return;
  17268. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  17269. qt_audio_channel_layout.calloc (output_layout_size, 1);
  17270. err = MovieAudioExtractionGetProperty (extractor,
  17271. kQTPropertyClass_MovieAudioExtraction_Audio,
  17272. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17273. output_layout_size, qt_audio_channel_layout, 0);
  17274. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  17275. err = MovieAudioExtractionSetProperty (extractor,
  17276. kQTPropertyClass_MovieAudioExtraction_Audio,
  17277. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17278. output_layout_size,
  17279. qt_audio_channel_layout);
  17280. err = MovieAudioExtractionGetProperty (extractor,
  17281. kQTPropertyClass_MovieAudioExtraction_Audio,
  17282. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17283. sizeof (inputStreamDesc),
  17284. &inputStreamDesc, 0);
  17285. if (err != noErr)
  17286. return;
  17287. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17288. | kAudioFormatFlagIsPacked
  17289. | kAudioFormatFlagsNativeEndian;
  17290. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17291. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17292. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17293. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17294. err = MovieAudioExtractionSetProperty (extractor,
  17295. kQTPropertyClass_MovieAudioExtraction_Audio,
  17296. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17297. sizeof (inputStreamDesc),
  17298. &inputStreamDesc);
  17299. if (err != noErr)
  17300. return;
  17301. Boolean allChannelsDiscrete = false;
  17302. err = MovieAudioExtractionSetProperty (extractor,
  17303. kQTPropertyClass_MovieAudioExtraction_Movie,
  17304. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17305. sizeof (allChannelsDiscrete),
  17306. &allChannelsDiscrete);
  17307. if (err != noErr)
  17308. return;
  17309. bufferList->mNumberBuffers = 1;
  17310. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17311. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17312. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17313. sampleRate = inputStreamDesc.mSampleRate;
  17314. bitsPerSample = 16;
  17315. numChannels = inputStreamDesc.mChannelsPerFrame;
  17316. detachThread();
  17317. ok = true;
  17318. }
  17319. ~QTAudioReader()
  17320. {
  17321. if (dataHandle != 0)
  17322. DisposeHandle (dataHandle);
  17323. if (extractor != 0)
  17324. {
  17325. MovieAudioExtractionEnd (extractor);
  17326. extractor = 0;
  17327. }
  17328. checkThreadIsAttached();
  17329. DisposeMovie (movie);
  17330. juce_free (bufferList->mBuffers[0].mData);
  17331. #if JUCE_MAC
  17332. ExitMoviesOnThread ();
  17333. #endif
  17334. }
  17335. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17336. int64 startSampleInFile, int numSamples)
  17337. {
  17338. checkThreadIsAttached();
  17339. while (numSamples > 0)
  17340. {
  17341. if (! loadFrame ((int) startSampleInFile))
  17342. return false;
  17343. const int numToDo = jmin (numSamples, samplesPerFrame);
  17344. for (int j = numDestChannels; --j >= 0;)
  17345. {
  17346. if (destSamples[j] != 0)
  17347. {
  17348. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17349. for (int i = 0; i < numToDo; ++i)
  17350. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17351. }
  17352. }
  17353. startOffsetInDestBuffer += numToDo;
  17354. startSampleInFile += numToDo;
  17355. numSamples -= numToDo;
  17356. }
  17357. detachThread();
  17358. return true;
  17359. }
  17360. bool loadFrame (const int sampleNum)
  17361. {
  17362. if (lastSampleRead != sampleNum)
  17363. {
  17364. TimeRecord time;
  17365. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17366. time.base = 0;
  17367. time.value.hi = 0;
  17368. time.value.lo = (UInt32) sampleNum;
  17369. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17370. kQTPropertyClass_MovieAudioExtraction_Movie,
  17371. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17372. sizeof (time), &time);
  17373. if (err != noErr)
  17374. return false;
  17375. }
  17376. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17377. UInt32 outFlags = 0;
  17378. UInt32 actualNumSamples = samplesPerFrame;
  17379. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17380. bufferList, &outFlags);
  17381. lastSampleRead = sampleNum + samplesPerFrame;
  17382. return err == noErr;
  17383. }
  17384. juce_UseDebuggingNewOperator
  17385. bool ok;
  17386. private:
  17387. Movie movie;
  17388. Media media;
  17389. Track track;
  17390. const int trackNum;
  17391. double trackUnitsPerFrame;
  17392. int samplesPerFrame;
  17393. int lastSampleRead;
  17394. Thread::ThreadID lastThreadId;
  17395. MovieAudioExtractionRef extractor;
  17396. AudioStreamBasicDescription inputStreamDesc;
  17397. HeapBlock <AudioBufferList> bufferList;
  17398. Handle dataHandle;
  17399. void checkThreadIsAttached()
  17400. {
  17401. #if JUCE_MAC
  17402. if (Thread::getCurrentThreadId() != lastThreadId)
  17403. EnterMoviesOnThread (0);
  17404. AttachMovieToCurrentThread (movie);
  17405. #endif
  17406. }
  17407. void detachThread()
  17408. {
  17409. #if JUCE_MAC
  17410. DetachMovieFromCurrentThread (movie);
  17411. #endif
  17412. }
  17413. };
  17414. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17415. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17416. {
  17417. }
  17418. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17419. {
  17420. }
  17421. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17422. {
  17423. return Array<int>();
  17424. }
  17425. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17426. {
  17427. return Array<int>();
  17428. }
  17429. bool QuickTimeAudioFormat::canDoStereo()
  17430. {
  17431. return true;
  17432. }
  17433. bool QuickTimeAudioFormat::canDoMono()
  17434. {
  17435. return true;
  17436. }
  17437. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17438. const bool deleteStreamIfOpeningFails)
  17439. {
  17440. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17441. if (r->ok)
  17442. return r.release();
  17443. if (! deleteStreamIfOpeningFails)
  17444. r->input = 0;
  17445. return 0;
  17446. }
  17447. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17448. double /*sampleRateToUse*/,
  17449. unsigned int /*numberOfChannels*/,
  17450. int /*bitsPerSample*/,
  17451. const StringPairArray& /*metadataValues*/,
  17452. int /*qualityOptionIndex*/)
  17453. {
  17454. jassertfalse // not yet implemented!
  17455. return 0;
  17456. }
  17457. END_JUCE_NAMESPACE
  17458. #endif
  17459. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17460. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17461. BEGIN_JUCE_NAMESPACE
  17462. static const char* const wavFormatName = "WAV file";
  17463. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17464. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17465. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17466. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17467. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17468. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17469. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17470. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17471. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17472. const String& originator,
  17473. const String& originatorRef,
  17474. const Time& date,
  17475. const int64 timeReferenceSamples,
  17476. const String& codingHistory)
  17477. {
  17478. StringPairArray m;
  17479. m.set (bwavDescription, description);
  17480. m.set (bwavOriginator, originator);
  17481. m.set (bwavOriginatorRef, originatorRef);
  17482. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17483. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17484. m.set (bwavTimeReference, String (timeReferenceSamples));
  17485. m.set (bwavCodingHistory, codingHistory);
  17486. return m;
  17487. }
  17488. #if JUCE_MSVC
  17489. #pragma pack (push, 1)
  17490. #define PACKED
  17491. #elif JUCE_GCC
  17492. #define PACKED __attribute__((packed))
  17493. #else
  17494. #define PACKED
  17495. #endif
  17496. struct BWAVChunk
  17497. {
  17498. uint8 description [256];
  17499. uint8 originator [32];
  17500. uint8 originatorRef [32];
  17501. uint8 originationDate [10];
  17502. uint8 originationTime [8];
  17503. uint32 timeRefLow;
  17504. uint32 timeRefHigh;
  17505. uint16 version;
  17506. uint8 umid[64];
  17507. uint8 reserved[190];
  17508. uint8 codingHistory[1];
  17509. void copyTo (StringPairArray& values) const
  17510. {
  17511. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17512. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17513. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17514. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17515. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17516. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17517. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17518. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17519. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17520. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17521. }
  17522. static MemoryBlock createFrom (const StringPairArray& values)
  17523. {
  17524. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (0) - 1;
  17525. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17526. data.fillWith (0);
  17527. BWAVChunk* b = (BWAVChunk*) data.getData();
  17528. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17529. // as they get called in the right order..
  17530. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17531. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17532. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17533. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17534. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17535. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17536. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17537. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17538. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory);
  17539. if (b->description[0] != 0
  17540. || b->originator[0] != 0
  17541. || b->originationDate[0] != 0
  17542. || b->originationTime[0] != 0
  17543. || b->codingHistory[0] != 0
  17544. || time != 0)
  17545. {
  17546. return data;
  17547. }
  17548. return MemoryBlock();
  17549. }
  17550. } PACKED;
  17551. struct SMPLChunk
  17552. {
  17553. struct SampleLoop
  17554. {
  17555. uint32 identifier;
  17556. uint32 type;
  17557. uint32 start;
  17558. uint32 end;
  17559. uint32 fraction;
  17560. uint32 playCount;
  17561. } PACKED;
  17562. uint32 manufacturer;
  17563. uint32 product;
  17564. uint32 samplePeriod;
  17565. uint32 midiUnityNote;
  17566. uint32 midiPitchFraction;
  17567. uint32 smpteFormat;
  17568. uint32 smpteOffset;
  17569. uint32 numSampleLoops;
  17570. uint32 samplerData;
  17571. SampleLoop loops[1];
  17572. void copyTo (StringPairArray& values, const int totalSize) const
  17573. {
  17574. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17575. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17576. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17577. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17578. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17579. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17580. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17581. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17582. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17583. for (uint32 i = 0; i < numSampleLoops; ++i)
  17584. {
  17585. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17586. break;
  17587. const String prefix ("Loop" + String(i));
  17588. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17589. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17590. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17591. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17592. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17593. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17594. }
  17595. }
  17596. static MemoryBlock createFrom (const StringPairArray& values)
  17597. {
  17598. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17599. if (numLoops <= 0)
  17600. return MemoryBlock();
  17601. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17602. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17603. data.fillWith (0);
  17604. SMPLChunk* s = (SMPLChunk*) data.getData();
  17605. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17606. // as they get called in the right order..
  17607. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17608. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17609. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17610. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17611. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17612. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17613. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17614. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17615. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17616. for (int i = 0; i < numLoops; ++i)
  17617. {
  17618. const String prefix ("Loop" + String(i));
  17619. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17620. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17621. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17622. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17623. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17624. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17625. }
  17626. return data;
  17627. }
  17628. } PACKED;
  17629. #if JUCE_MSVC
  17630. #pragma pack (pop)
  17631. #endif
  17632. #undef PACKED
  17633. class WavAudioFormatReader : public AudioFormatReader
  17634. {
  17635. int bytesPerFrame;
  17636. int64 dataChunkStart, dataLength;
  17637. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17638. WavAudioFormatReader (const WavAudioFormatReader&);
  17639. const WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17640. public:
  17641. int64 bwavChunkStart, bwavSize;
  17642. WavAudioFormatReader (InputStream* const in)
  17643. : AudioFormatReader (in, TRANS (wavFormatName)),
  17644. dataLength (0),
  17645. bwavChunkStart (0),
  17646. bwavSize (0)
  17647. {
  17648. if (input->readInt() == chunkName ("RIFF"))
  17649. {
  17650. const uint32 len = (uint32) input->readInt();
  17651. const int64 end = input->getPosition() + len;
  17652. bool hasGotType = false;
  17653. bool hasGotData = false;
  17654. if (input->readInt() == chunkName ("WAVE"))
  17655. {
  17656. while (input->getPosition() < end
  17657. && ! input->isExhausted())
  17658. {
  17659. const int chunkType = input->readInt();
  17660. uint32 length = (uint32) input->readInt();
  17661. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17662. if (chunkType == chunkName ("fmt "))
  17663. {
  17664. // read the format chunk
  17665. const short format = input->readShort();
  17666. const short numChans = input->readShort();
  17667. sampleRate = input->readInt();
  17668. const int bytesPerSec = input->readInt();
  17669. numChannels = numChans;
  17670. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17671. bitsPerSample = 8 * bytesPerFrame / numChans;
  17672. if (format == 3)
  17673. usesFloatingPointData = true;
  17674. else if (format != 1)
  17675. bytesPerFrame = 0;
  17676. hasGotType = true;
  17677. }
  17678. else if (chunkType == chunkName ("data"))
  17679. {
  17680. // get the data chunk's position
  17681. dataLength = length;
  17682. dataChunkStart = input->getPosition();
  17683. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17684. hasGotData = true;
  17685. }
  17686. else if (chunkType == chunkName ("bext"))
  17687. {
  17688. bwavChunkStart = input->getPosition();
  17689. bwavSize = length;
  17690. // Broadcast-wav extension chunk..
  17691. HeapBlock <BWAVChunk> bwav;
  17692. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17693. input->read (bwav, length);
  17694. bwav->copyTo (metadataValues);
  17695. }
  17696. else if (chunkType == chunkName ("smpl"))
  17697. {
  17698. HeapBlock <SMPLChunk> smpl;
  17699. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17700. input->read (smpl, length);
  17701. smpl->copyTo (metadataValues, length);
  17702. }
  17703. else if (chunkEnd <= input->getPosition())
  17704. {
  17705. break;
  17706. }
  17707. input->setPosition (chunkEnd);
  17708. }
  17709. }
  17710. }
  17711. }
  17712. ~WavAudioFormatReader()
  17713. {
  17714. }
  17715. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17716. int64 startSampleInFile, int numSamples)
  17717. {
  17718. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17719. if (samplesAvailable < numSamples)
  17720. {
  17721. for (int i = numDestChannels; --i >= 0;)
  17722. if (destSamples[i] != 0)
  17723. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17724. numSamples = (int) samplesAvailable;
  17725. }
  17726. if (numSamples <= 0)
  17727. return true;
  17728. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17729. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17730. char tempBuffer [tempBufSize];
  17731. while (numSamples > 0)
  17732. {
  17733. int* left = destSamples[0];
  17734. if (left != 0)
  17735. left += startOffsetInDestBuffer;
  17736. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17737. if (right != 0)
  17738. right += startOffsetInDestBuffer;
  17739. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17740. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17741. if (bytesRead < numThisTime * bytesPerFrame)
  17742. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17743. if (bitsPerSample == 16)
  17744. {
  17745. const short* src = (const short*) tempBuffer;
  17746. if (numChannels > 1)
  17747. {
  17748. if (left == 0)
  17749. {
  17750. for (int i = numThisTime; --i >= 0;)
  17751. {
  17752. ++src;
  17753. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17754. }
  17755. }
  17756. else if (right == 0)
  17757. {
  17758. for (int i = numThisTime; --i >= 0;)
  17759. {
  17760. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17761. ++src;
  17762. }
  17763. }
  17764. else
  17765. {
  17766. for (int i = numThisTime; --i >= 0;)
  17767. {
  17768. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17769. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17770. }
  17771. }
  17772. }
  17773. else
  17774. {
  17775. for (int i = numThisTime; --i >= 0;)
  17776. {
  17777. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17778. }
  17779. }
  17780. }
  17781. else if (bitsPerSample == 24)
  17782. {
  17783. const char* src = (const char*) tempBuffer;
  17784. if (numChannels > 1)
  17785. {
  17786. if (left == 0)
  17787. {
  17788. for (int i = numThisTime; --i >= 0;)
  17789. {
  17790. src += 3;
  17791. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17792. src += 3;
  17793. }
  17794. }
  17795. else if (right == 0)
  17796. {
  17797. for (int i = numThisTime; --i >= 0;)
  17798. {
  17799. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17800. src += 6;
  17801. }
  17802. }
  17803. else
  17804. {
  17805. for (int i = 0; i < numThisTime; ++i)
  17806. {
  17807. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17808. src += 3;
  17809. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17810. src += 3;
  17811. }
  17812. }
  17813. }
  17814. else
  17815. {
  17816. for (int i = 0; i < numThisTime; ++i)
  17817. {
  17818. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17819. src += 3;
  17820. }
  17821. }
  17822. }
  17823. else if (bitsPerSample == 32)
  17824. {
  17825. const unsigned int* src = (const unsigned int*) tempBuffer;
  17826. unsigned int* l = (unsigned int*) left;
  17827. unsigned int* r = (unsigned int*) right;
  17828. if (numChannels > 1)
  17829. {
  17830. if (l == 0)
  17831. {
  17832. for (int i = numThisTime; --i >= 0;)
  17833. {
  17834. ++src;
  17835. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17836. }
  17837. }
  17838. else if (r == 0)
  17839. {
  17840. for (int i = numThisTime; --i >= 0;)
  17841. {
  17842. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17843. ++src;
  17844. }
  17845. }
  17846. else
  17847. {
  17848. for (int i = numThisTime; --i >= 0;)
  17849. {
  17850. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17851. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17852. }
  17853. }
  17854. }
  17855. else
  17856. {
  17857. for (int i = numThisTime; --i >= 0;)
  17858. {
  17859. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17860. }
  17861. }
  17862. left = (int*)l;
  17863. right = (int*)r;
  17864. }
  17865. else if (bitsPerSample == 8)
  17866. {
  17867. const unsigned char* src = (const unsigned char*) tempBuffer;
  17868. if (numChannels > 1)
  17869. {
  17870. if (left == 0)
  17871. {
  17872. for (int i = numThisTime; --i >= 0;)
  17873. {
  17874. ++src;
  17875. *right++ = ((int) *src++ - 128) << 24;
  17876. }
  17877. }
  17878. else if (right == 0)
  17879. {
  17880. for (int i = numThisTime; --i >= 0;)
  17881. {
  17882. *left++ = ((int) *src++ - 128) << 24;
  17883. ++src;
  17884. }
  17885. }
  17886. else
  17887. {
  17888. for (int i = numThisTime; --i >= 0;)
  17889. {
  17890. *left++ = ((int) *src++ - 128) << 24;
  17891. *right++ = ((int) *src++ - 128) << 24;
  17892. }
  17893. }
  17894. }
  17895. else
  17896. {
  17897. for (int i = numThisTime; --i >= 0;)
  17898. {
  17899. *left++ = ((int)*src++ - 128) << 24;
  17900. }
  17901. }
  17902. }
  17903. startOffsetInDestBuffer += numThisTime;
  17904. numSamples -= numThisTime;
  17905. }
  17906. if (numSamples > 0)
  17907. {
  17908. for (int i = numDestChannels; --i >= 0;)
  17909. if (destSamples[i] != 0)
  17910. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17911. sizeof (int) * numSamples);
  17912. }
  17913. return true;
  17914. }
  17915. juce_UseDebuggingNewOperator
  17916. };
  17917. class WavAudioFormatWriter : public AudioFormatWriter
  17918. {
  17919. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17920. uint32 lengthInSamples, bytesWritten;
  17921. int64 headerPosition;
  17922. bool writeFailed;
  17923. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17924. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17925. const WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17926. void writeHeader()
  17927. {
  17928. const bool seekedOk = output->setPosition (headerPosition);
  17929. (void) seekedOk;
  17930. // if this fails, you've given it an output stream that can't seek! It needs
  17931. // to be able to seek back to write the header
  17932. jassert (seekedOk);
  17933. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17934. output->writeInt (chunkName ("RIFF"));
  17935. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17936. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17937. output->writeInt (chunkName ("WAVE"));
  17938. output->writeInt (chunkName ("fmt "));
  17939. output->writeInt (16);
  17940. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17941. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17942. output->writeShort ((short) numChannels);
  17943. output->writeInt ((int) sampleRate);
  17944. output->writeInt (bytesPerFrame * (int) sampleRate);
  17945. output->writeShort ((short) bytesPerFrame);
  17946. output->writeShort ((short) bitsPerSample);
  17947. if (bwavChunk.getSize() > 0)
  17948. {
  17949. output->writeInt (chunkName ("bext"));
  17950. output->writeInt ((int) bwavChunk.getSize());
  17951. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17952. }
  17953. if (smplChunk.getSize() > 0)
  17954. {
  17955. output->writeInt (chunkName ("smpl"));
  17956. output->writeInt (smplChunk.getSize());
  17957. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17958. }
  17959. output->writeInt (chunkName ("data"));
  17960. output->writeInt (lengthInSamples * bytesPerFrame);
  17961. usesFloatingPointData = (bitsPerSample == 32);
  17962. }
  17963. public:
  17964. WavAudioFormatWriter (OutputStream* const out,
  17965. const double sampleRate_,
  17966. const unsigned int numChannels_,
  17967. const int bits,
  17968. const StringPairArray& metadataValues)
  17969. : AudioFormatWriter (out,
  17970. TRANS (wavFormatName),
  17971. sampleRate_,
  17972. numChannels_,
  17973. bits),
  17974. lengthInSamples (0),
  17975. bytesWritten (0),
  17976. writeFailed (false)
  17977. {
  17978. if (metadataValues.size() > 0)
  17979. {
  17980. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17981. smplChunk = SMPLChunk::createFrom (metadataValues);
  17982. }
  17983. headerPosition = out->getPosition();
  17984. writeHeader();
  17985. }
  17986. ~WavAudioFormatWriter()
  17987. {
  17988. writeHeader();
  17989. }
  17990. bool write (const int** data, int numSamples)
  17991. {
  17992. if (writeFailed)
  17993. return false;
  17994. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17995. tempBlock.ensureSize (bytes, false);
  17996. char* buffer = (char*) tempBlock.getData();
  17997. const int* left = data[0];
  17998. const int* right = data[1];
  17999. if (right == 0)
  18000. right = left;
  18001. if (bitsPerSample == 16)
  18002. {
  18003. short* b = (short*) buffer;
  18004. if (numChannels > 1)
  18005. {
  18006. for (int i = numSamples; --i >= 0;)
  18007. {
  18008. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  18009. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  18010. }
  18011. }
  18012. else
  18013. {
  18014. for (int i = numSamples; --i >= 0;)
  18015. {
  18016. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  18017. }
  18018. }
  18019. }
  18020. else if (bitsPerSample == 24)
  18021. {
  18022. char* b = (char*) buffer;
  18023. if (numChannels > 1)
  18024. {
  18025. for (int i = numSamples; --i >= 0;)
  18026. {
  18027. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  18028. b += 3;
  18029. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  18030. b += 3;
  18031. }
  18032. }
  18033. else
  18034. {
  18035. for (int i = numSamples; --i >= 0;)
  18036. {
  18037. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  18038. b += 3;
  18039. }
  18040. }
  18041. }
  18042. else if (bitsPerSample == 32)
  18043. {
  18044. unsigned int* b = (unsigned int*) buffer;
  18045. if (numChannels > 1)
  18046. {
  18047. for (int i = numSamples; --i >= 0;)
  18048. {
  18049. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18050. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  18051. }
  18052. }
  18053. else
  18054. {
  18055. for (int i = numSamples; --i >= 0;)
  18056. {
  18057. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18058. }
  18059. }
  18060. }
  18061. else if (bitsPerSample == 8)
  18062. {
  18063. unsigned char* b = (unsigned char*) buffer;
  18064. if (numChannels > 1)
  18065. {
  18066. for (int i = numSamples; --i >= 0;)
  18067. {
  18068. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18069. *b++ = (unsigned char) (128 + (*right++ >> 24));
  18070. }
  18071. }
  18072. else
  18073. {
  18074. for (int i = numSamples; --i >= 0;)
  18075. {
  18076. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18077. }
  18078. }
  18079. }
  18080. if (bytesWritten + bytes >= (uint32) 0xfff00000
  18081. || ! output->write (buffer, bytes))
  18082. {
  18083. // failed to write to disk, so let's try writing the header.
  18084. // If it's just run out of disk space, then if it does manage
  18085. // to write the header, we'll still have a useable file..
  18086. writeHeader();
  18087. writeFailed = true;
  18088. return false;
  18089. }
  18090. else
  18091. {
  18092. bytesWritten += bytes;
  18093. lengthInSamples += numSamples;
  18094. return true;
  18095. }
  18096. }
  18097. juce_UseDebuggingNewOperator
  18098. };
  18099. WavAudioFormat::WavAudioFormat()
  18100. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  18101. {
  18102. }
  18103. WavAudioFormat::~WavAudioFormat()
  18104. {
  18105. }
  18106. const Array <int> WavAudioFormat::getPossibleSampleRates()
  18107. {
  18108. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  18109. return Array <int> (rates);
  18110. }
  18111. const Array <int> WavAudioFormat::getPossibleBitDepths()
  18112. {
  18113. const int depths[] = { 8, 16, 24, 32, 0 };
  18114. return Array <int> (depths);
  18115. }
  18116. bool WavAudioFormat::canDoStereo()
  18117. {
  18118. return true;
  18119. }
  18120. bool WavAudioFormat::canDoMono()
  18121. {
  18122. return true;
  18123. }
  18124. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  18125. const bool deleteStreamIfOpeningFails)
  18126. {
  18127. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  18128. if (r->sampleRate != 0)
  18129. return r.release();
  18130. if (! deleteStreamIfOpeningFails)
  18131. r->input = 0;
  18132. return 0;
  18133. }
  18134. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  18135. double sampleRate,
  18136. unsigned int numChannels,
  18137. int bitsPerSample,
  18138. const StringPairArray& metadataValues,
  18139. int /*qualityOptionIndex*/)
  18140. {
  18141. if (getPossibleBitDepths().contains (bitsPerSample))
  18142. {
  18143. return new WavAudioFormatWriter (out,
  18144. sampleRate,
  18145. numChannels,
  18146. bitsPerSample,
  18147. metadataValues);
  18148. }
  18149. return 0;
  18150. }
  18151. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  18152. {
  18153. TemporaryFile tempFile (file);
  18154. WavAudioFormat wav;
  18155. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  18156. if (reader != 0)
  18157. {
  18158. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  18159. if (outStream != 0)
  18160. {
  18161. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  18162. reader->numChannels, reader->bitsPerSample,
  18163. metadata, 0));
  18164. if (writer != 0)
  18165. {
  18166. outStream.release();
  18167. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  18168. writer = 0;
  18169. reader = 0;
  18170. return ok && tempFile.overwriteTargetFileWithTemporary();
  18171. }
  18172. }
  18173. }
  18174. return false;
  18175. }
  18176. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  18177. {
  18178. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  18179. if (reader != 0)
  18180. {
  18181. const int64 bwavPos = reader->bwavChunkStart;
  18182. const int64 bwavSize = reader->bwavSize;
  18183. reader = 0;
  18184. if (bwavSize > 0)
  18185. {
  18186. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  18187. if (chunk.getSize() <= (size_t) bwavSize)
  18188. {
  18189. // the new one will fit in the space available, so write it directly..
  18190. const int64 oldSize = wavFile.getSize();
  18191. {
  18192. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  18193. out->setPosition (bwavPos);
  18194. out->write (chunk.getData(), (int) chunk.getSize());
  18195. out->setPosition (oldSize);
  18196. }
  18197. jassert (wavFile.getSize() == oldSize);
  18198. return true;
  18199. }
  18200. }
  18201. }
  18202. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  18203. }
  18204. END_JUCE_NAMESPACE
  18205. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  18206. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18207. BEGIN_JUCE_NAMESPACE
  18208. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  18209. const bool deleteReaderWhenThisIsDeleted)
  18210. : reader (reader_),
  18211. deleteReader (deleteReaderWhenThisIsDeleted),
  18212. nextPlayPos (0),
  18213. looping (false)
  18214. {
  18215. jassert (reader != 0);
  18216. }
  18217. AudioFormatReaderSource::~AudioFormatReaderSource()
  18218. {
  18219. releaseResources();
  18220. if (deleteReader)
  18221. delete reader;
  18222. }
  18223. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  18224. {
  18225. nextPlayPos = newPosition;
  18226. }
  18227. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  18228. {
  18229. looping = shouldLoop;
  18230. }
  18231. int AudioFormatReaderSource::getNextReadPosition() const
  18232. {
  18233. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18234. : nextPlayPos;
  18235. }
  18236. int AudioFormatReaderSource::getTotalLength() const
  18237. {
  18238. return (int) reader->lengthInSamples;
  18239. }
  18240. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18241. double /*sampleRate*/)
  18242. {
  18243. }
  18244. void AudioFormatReaderSource::releaseResources()
  18245. {
  18246. }
  18247. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18248. {
  18249. if (info.numSamples > 0)
  18250. {
  18251. const int start = nextPlayPos;
  18252. if (looping)
  18253. {
  18254. const int newStart = start % (int) reader->lengthInSamples;
  18255. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18256. if (newEnd > newStart)
  18257. {
  18258. info.buffer->readFromAudioReader (reader,
  18259. info.startSample,
  18260. newEnd - newStart,
  18261. newStart,
  18262. true, true);
  18263. }
  18264. else
  18265. {
  18266. const int endSamps = (int) reader->lengthInSamples - newStart;
  18267. info.buffer->readFromAudioReader (reader,
  18268. info.startSample,
  18269. endSamps,
  18270. newStart,
  18271. true, true);
  18272. info.buffer->readFromAudioReader (reader,
  18273. info.startSample + endSamps,
  18274. newEnd,
  18275. 0,
  18276. true, true);
  18277. }
  18278. nextPlayPos = newEnd;
  18279. }
  18280. else
  18281. {
  18282. info.buffer->readFromAudioReader (reader,
  18283. info.startSample,
  18284. info.numSamples,
  18285. start,
  18286. true, true);
  18287. nextPlayPos += info.numSamples;
  18288. }
  18289. }
  18290. }
  18291. END_JUCE_NAMESPACE
  18292. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18293. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18294. BEGIN_JUCE_NAMESPACE
  18295. AudioSourcePlayer::AudioSourcePlayer()
  18296. : source (0),
  18297. sampleRate (0),
  18298. bufferSize (0),
  18299. tempBuffer (2, 8),
  18300. lastGain (1.0f),
  18301. gain (1.0f)
  18302. {
  18303. }
  18304. AudioSourcePlayer::~AudioSourcePlayer()
  18305. {
  18306. setSource (0);
  18307. }
  18308. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18309. {
  18310. if (source != newSource)
  18311. {
  18312. AudioSource* const oldSource = source;
  18313. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18314. newSource->prepareToPlay (bufferSize, sampleRate);
  18315. {
  18316. const ScopedLock sl (readLock);
  18317. source = newSource;
  18318. }
  18319. if (oldSource != 0)
  18320. oldSource->releaseResources();
  18321. }
  18322. }
  18323. void AudioSourcePlayer::setGain (const float newGain) throw()
  18324. {
  18325. gain = newGain;
  18326. }
  18327. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18328. int totalNumInputChannels,
  18329. float** outputChannelData,
  18330. int totalNumOutputChannels,
  18331. int numSamples)
  18332. {
  18333. // these should have been prepared by audioDeviceAboutToStart()...
  18334. jassert (sampleRate > 0 && bufferSize > 0);
  18335. const ScopedLock sl (readLock);
  18336. if (source != 0)
  18337. {
  18338. AudioSourceChannelInfo info;
  18339. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18340. // messy stuff needed to compact the channels down into an array
  18341. // of non-zero pointers..
  18342. for (i = 0; i < totalNumInputChannels; ++i)
  18343. {
  18344. if (inputChannelData[i] != 0)
  18345. {
  18346. inputChans [numInputs++] = inputChannelData[i];
  18347. if (numInputs >= numElementsInArray (inputChans))
  18348. break;
  18349. }
  18350. }
  18351. for (i = 0; i < totalNumOutputChannels; ++i)
  18352. {
  18353. if (outputChannelData[i] != 0)
  18354. {
  18355. outputChans [numOutputs++] = outputChannelData[i];
  18356. if (numOutputs >= numElementsInArray (outputChans))
  18357. break;
  18358. }
  18359. }
  18360. if (numInputs > numOutputs)
  18361. {
  18362. // if there aren't enough output channels for the number of
  18363. // inputs, we need to create some temporary extra ones (can't
  18364. // use the input data in case it gets written to)
  18365. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18366. false, false, true);
  18367. for (i = 0; i < numOutputs; ++i)
  18368. {
  18369. channels[numActiveChans] = outputChans[i];
  18370. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18371. ++numActiveChans;
  18372. }
  18373. for (i = numOutputs; i < numInputs; ++i)
  18374. {
  18375. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18376. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18377. ++numActiveChans;
  18378. }
  18379. }
  18380. else
  18381. {
  18382. for (i = 0; i < numInputs; ++i)
  18383. {
  18384. channels[numActiveChans] = outputChans[i];
  18385. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18386. ++numActiveChans;
  18387. }
  18388. for (i = numInputs; i < numOutputs; ++i)
  18389. {
  18390. channels[numActiveChans] = outputChans[i];
  18391. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18392. ++numActiveChans;
  18393. }
  18394. }
  18395. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18396. info.buffer = &buffer;
  18397. info.startSample = 0;
  18398. info.numSamples = numSamples;
  18399. source->getNextAudioBlock (info);
  18400. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18401. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18402. lastGain = gain;
  18403. }
  18404. else
  18405. {
  18406. for (int i = 0; i < totalNumOutputChannels; ++i)
  18407. if (outputChannelData[i] != 0)
  18408. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18409. }
  18410. }
  18411. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18412. {
  18413. sampleRate = device->getCurrentSampleRate();
  18414. bufferSize = device->getCurrentBufferSizeSamples();
  18415. zeromem (channels, sizeof (channels));
  18416. if (source != 0)
  18417. source->prepareToPlay (bufferSize, sampleRate);
  18418. }
  18419. void AudioSourcePlayer::audioDeviceStopped()
  18420. {
  18421. if (source != 0)
  18422. source->releaseResources();
  18423. sampleRate = 0.0;
  18424. bufferSize = 0;
  18425. tempBuffer.setSize (2, 8);
  18426. }
  18427. END_JUCE_NAMESPACE
  18428. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18429. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18430. BEGIN_JUCE_NAMESPACE
  18431. AudioTransportSource::AudioTransportSource()
  18432. : source (0),
  18433. resamplerSource (0),
  18434. bufferingSource (0),
  18435. positionableSource (0),
  18436. masterSource (0),
  18437. gain (1.0f),
  18438. lastGain (1.0f),
  18439. playing (false),
  18440. stopped (true),
  18441. sampleRate (44100.0),
  18442. sourceSampleRate (0.0),
  18443. blockSize (128),
  18444. readAheadBufferSize (0),
  18445. isPrepared (false),
  18446. inputStreamEOF (false)
  18447. {
  18448. }
  18449. AudioTransportSource::~AudioTransportSource()
  18450. {
  18451. setSource (0);
  18452. releaseResources();
  18453. }
  18454. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18455. int readAheadBufferSize_,
  18456. double sourceSampleRateToCorrectFor)
  18457. {
  18458. if (source == newSource)
  18459. {
  18460. if (source == 0)
  18461. return;
  18462. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18463. }
  18464. readAheadBufferSize = readAheadBufferSize_;
  18465. sourceSampleRate = sourceSampleRateToCorrectFor;
  18466. ResamplingAudioSource* newResamplerSource = 0;
  18467. BufferingAudioSource* newBufferingSource = 0;
  18468. PositionableAudioSource* newPositionableSource = 0;
  18469. AudioSource* newMasterSource = 0;
  18470. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18471. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18472. AudioSource* oldMasterSource = masterSource;
  18473. if (newSource != 0)
  18474. {
  18475. newPositionableSource = newSource;
  18476. if (readAheadBufferSize_ > 0)
  18477. newPositionableSource = newBufferingSource
  18478. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18479. newPositionableSource->setNextReadPosition (0);
  18480. if (sourceSampleRateToCorrectFor != 0)
  18481. newMasterSource = newResamplerSource
  18482. = new ResamplingAudioSource (newPositionableSource, false);
  18483. else
  18484. newMasterSource = newPositionableSource;
  18485. if (isPrepared)
  18486. {
  18487. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18488. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18489. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18490. }
  18491. }
  18492. {
  18493. const ScopedLock sl (callbackLock);
  18494. source = newSource;
  18495. resamplerSource = newResamplerSource;
  18496. bufferingSource = newBufferingSource;
  18497. masterSource = newMasterSource;
  18498. positionableSource = newPositionableSource;
  18499. playing = false;
  18500. }
  18501. if (oldMasterSource != 0)
  18502. oldMasterSource->releaseResources();
  18503. }
  18504. void AudioTransportSource::start()
  18505. {
  18506. if ((! playing) && masterSource != 0)
  18507. {
  18508. callbackLock.enter();
  18509. playing = true;
  18510. stopped = false;
  18511. inputStreamEOF = false;
  18512. callbackLock.exit();
  18513. sendChangeMessage (this);
  18514. }
  18515. }
  18516. void AudioTransportSource::stop()
  18517. {
  18518. if (playing)
  18519. {
  18520. callbackLock.enter();
  18521. playing = false;
  18522. callbackLock.exit();
  18523. int n = 500;
  18524. while (--n >= 0 && ! stopped)
  18525. Thread::sleep (2);
  18526. sendChangeMessage (this);
  18527. }
  18528. }
  18529. void AudioTransportSource::setPosition (double newPosition)
  18530. {
  18531. if (sampleRate > 0.0)
  18532. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18533. }
  18534. double AudioTransportSource::getCurrentPosition() const
  18535. {
  18536. if (sampleRate > 0.0)
  18537. return getNextReadPosition() / sampleRate;
  18538. else
  18539. return 0.0;
  18540. }
  18541. void AudioTransportSource::setNextReadPosition (int newPosition)
  18542. {
  18543. if (positionableSource != 0)
  18544. {
  18545. if (sampleRate > 0 && sourceSampleRate > 0)
  18546. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18547. positionableSource->setNextReadPosition (newPosition);
  18548. }
  18549. }
  18550. int AudioTransportSource::getNextReadPosition() const
  18551. {
  18552. if (positionableSource != 0)
  18553. {
  18554. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18555. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18556. }
  18557. return 0;
  18558. }
  18559. int AudioTransportSource::getTotalLength() const
  18560. {
  18561. const ScopedLock sl (callbackLock);
  18562. if (positionableSource != 0)
  18563. {
  18564. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18565. return roundToInt (positionableSource->getTotalLength() * ratio);
  18566. }
  18567. return 0;
  18568. }
  18569. bool AudioTransportSource::isLooping() const
  18570. {
  18571. const ScopedLock sl (callbackLock);
  18572. return positionableSource != 0
  18573. && positionableSource->isLooping();
  18574. }
  18575. void AudioTransportSource::setGain (const float newGain) throw()
  18576. {
  18577. gain = newGain;
  18578. }
  18579. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18580. double sampleRate_)
  18581. {
  18582. const ScopedLock sl (callbackLock);
  18583. sampleRate = sampleRate_;
  18584. blockSize = samplesPerBlockExpected;
  18585. if (masterSource != 0)
  18586. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18587. if (resamplerSource != 0 && sourceSampleRate != 0)
  18588. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18589. isPrepared = true;
  18590. }
  18591. void AudioTransportSource::releaseResources()
  18592. {
  18593. const ScopedLock sl (callbackLock);
  18594. if (masterSource != 0)
  18595. masterSource->releaseResources();
  18596. isPrepared = false;
  18597. }
  18598. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18599. {
  18600. const ScopedLock sl (callbackLock);
  18601. inputStreamEOF = false;
  18602. if (masterSource != 0 && ! stopped)
  18603. {
  18604. masterSource->getNextAudioBlock (info);
  18605. if (! playing)
  18606. {
  18607. // just stopped playing, so fade out the last block..
  18608. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18609. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18610. if (info.numSamples > 256)
  18611. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18612. }
  18613. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18614. && ! positionableSource->isLooping())
  18615. {
  18616. playing = false;
  18617. inputStreamEOF = true;
  18618. sendChangeMessage (this);
  18619. }
  18620. stopped = ! playing;
  18621. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18622. {
  18623. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18624. lastGain, gain);
  18625. }
  18626. }
  18627. else
  18628. {
  18629. info.clearActiveBufferRegion();
  18630. stopped = true;
  18631. }
  18632. lastGain = gain;
  18633. }
  18634. END_JUCE_NAMESPACE
  18635. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18636. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18637. BEGIN_JUCE_NAMESPACE
  18638. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18639. public Thread,
  18640. private Timer
  18641. {
  18642. public:
  18643. SharedBufferingAudioSourceThread()
  18644. : Thread ("Audio Buffer")
  18645. {
  18646. }
  18647. ~SharedBufferingAudioSourceThread()
  18648. {
  18649. stopThread (10000);
  18650. clearSingletonInstance();
  18651. }
  18652. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18653. void addSource (BufferingAudioSource* source)
  18654. {
  18655. const ScopedLock sl (lock);
  18656. if (! sources.contains ((void*) source))
  18657. {
  18658. sources.add ((void*) source);
  18659. startThread();
  18660. stopTimer();
  18661. }
  18662. notify();
  18663. }
  18664. void removeSource (BufferingAudioSource* source)
  18665. {
  18666. const ScopedLock sl (lock);
  18667. sources.removeValue ((void*) source);
  18668. if (sources.size() == 0)
  18669. startTimer (5000);
  18670. }
  18671. private:
  18672. VoidArray sources;
  18673. CriticalSection lock;
  18674. void run()
  18675. {
  18676. while (! threadShouldExit())
  18677. {
  18678. bool busy = false;
  18679. for (int i = sources.size(); --i >= 0;)
  18680. {
  18681. if (threadShouldExit())
  18682. return;
  18683. const ScopedLock sl (lock);
  18684. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18685. if (b != 0 && b->readNextBufferChunk())
  18686. busy = true;
  18687. }
  18688. if (! busy)
  18689. wait (500);
  18690. }
  18691. }
  18692. void timerCallback()
  18693. {
  18694. stopTimer();
  18695. if (sources.size() == 0)
  18696. deleteInstance();
  18697. }
  18698. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18699. const SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18700. };
  18701. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18702. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18703. const bool deleteSourceWhenDeleted_,
  18704. int numberOfSamplesToBuffer_)
  18705. : source (source_),
  18706. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18707. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18708. buffer (2, 0),
  18709. bufferValidStart (0),
  18710. bufferValidEnd (0),
  18711. nextPlayPos (0),
  18712. wasSourceLooping (false)
  18713. {
  18714. jassert (source_ != 0);
  18715. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18716. // not using a larger buffer..
  18717. }
  18718. BufferingAudioSource::~BufferingAudioSource()
  18719. {
  18720. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18721. if (thread != 0)
  18722. thread->removeSource (this);
  18723. if (deleteSourceWhenDeleted)
  18724. delete source;
  18725. }
  18726. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18727. {
  18728. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18729. sampleRate = sampleRate_;
  18730. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18731. buffer.clear();
  18732. bufferValidStart = 0;
  18733. bufferValidEnd = 0;
  18734. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18735. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18736. buffer.getNumSamples() / 2))
  18737. {
  18738. SharedBufferingAudioSourceThread::getInstance()->notify();
  18739. Thread::sleep (5);
  18740. }
  18741. }
  18742. void BufferingAudioSource::releaseResources()
  18743. {
  18744. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18745. if (thread != 0)
  18746. thread->removeSource (this);
  18747. buffer.setSize (2, 0);
  18748. source->releaseResources();
  18749. }
  18750. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18751. {
  18752. const ScopedLock sl (bufferStartPosLock);
  18753. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18754. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18755. if (validStart == validEnd)
  18756. {
  18757. // total cache miss
  18758. info.clearActiveBufferRegion();
  18759. }
  18760. else
  18761. {
  18762. if (validStart > 0)
  18763. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18764. if (validEnd < info.numSamples)
  18765. info.buffer->clear (info.startSample + validEnd,
  18766. info.numSamples - validEnd); // partial cache miss at end
  18767. if (validStart < validEnd)
  18768. {
  18769. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18770. {
  18771. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18772. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18773. if (startBufferIndex < endBufferIndex)
  18774. {
  18775. info.buffer->copyFrom (chan, info.startSample + validStart,
  18776. buffer,
  18777. chan, startBufferIndex,
  18778. validEnd - validStart);
  18779. }
  18780. else
  18781. {
  18782. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18783. info.buffer->copyFrom (chan, info.startSample + validStart,
  18784. buffer,
  18785. chan, startBufferIndex,
  18786. initialSize);
  18787. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18788. buffer,
  18789. chan, 0,
  18790. (validEnd - validStart) - initialSize);
  18791. }
  18792. }
  18793. }
  18794. nextPlayPos += info.numSamples;
  18795. if (source->isLooping() && nextPlayPos > 0)
  18796. nextPlayPos %= source->getTotalLength();
  18797. }
  18798. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18799. if (thread != 0)
  18800. thread->notify();
  18801. }
  18802. int BufferingAudioSource::getNextReadPosition() const
  18803. {
  18804. return (source->isLooping() && nextPlayPos > 0)
  18805. ? nextPlayPos % source->getTotalLength()
  18806. : nextPlayPos;
  18807. }
  18808. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18809. {
  18810. const ScopedLock sl (bufferStartPosLock);
  18811. nextPlayPos = newPosition;
  18812. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18813. if (thread != 0)
  18814. thread->notify();
  18815. }
  18816. bool BufferingAudioSource::readNextBufferChunk()
  18817. {
  18818. bufferStartPosLock.enter();
  18819. if (wasSourceLooping != isLooping())
  18820. {
  18821. wasSourceLooping = isLooping();
  18822. bufferValidStart = 0;
  18823. bufferValidEnd = 0;
  18824. }
  18825. int newBVS = jmax (0, nextPlayPos);
  18826. int newBVE = newBVS + buffer.getNumSamples() - 4;
  18827. int sectionToReadStart = 0;
  18828. int sectionToReadEnd = 0;
  18829. const int maxChunkSize = 2048;
  18830. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18831. {
  18832. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18833. sectionToReadStart = newBVS;
  18834. sectionToReadEnd = newBVE;
  18835. bufferValidStart = 0;
  18836. bufferValidEnd = 0;
  18837. }
  18838. else if (abs (newBVS - bufferValidStart) > 512
  18839. || abs (newBVE - bufferValidEnd) > 512)
  18840. {
  18841. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18842. sectionToReadStart = bufferValidEnd;
  18843. sectionToReadEnd = newBVE;
  18844. bufferValidStart = newBVS;
  18845. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18846. }
  18847. bufferStartPosLock.exit();
  18848. if (sectionToReadStart != sectionToReadEnd)
  18849. {
  18850. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18851. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18852. if (bufferIndexStart < bufferIndexEnd)
  18853. {
  18854. readBufferSection (sectionToReadStart,
  18855. sectionToReadEnd - sectionToReadStart,
  18856. bufferIndexStart);
  18857. }
  18858. else
  18859. {
  18860. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18861. readBufferSection (sectionToReadStart,
  18862. initialSize,
  18863. bufferIndexStart);
  18864. readBufferSection (sectionToReadStart + initialSize,
  18865. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18866. 0);
  18867. }
  18868. const ScopedLock sl2 (bufferStartPosLock);
  18869. bufferValidStart = newBVS;
  18870. bufferValidEnd = newBVE;
  18871. return true;
  18872. }
  18873. else
  18874. {
  18875. return false;
  18876. }
  18877. }
  18878. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18879. {
  18880. if (source->getNextReadPosition() != start)
  18881. source->setNextReadPosition (start);
  18882. AudioSourceChannelInfo info;
  18883. info.buffer = &buffer;
  18884. info.startSample = bufferOffset;
  18885. info.numSamples = length;
  18886. source->getNextAudioBlock (info);
  18887. }
  18888. END_JUCE_NAMESPACE
  18889. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18890. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18891. BEGIN_JUCE_NAMESPACE
  18892. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18893. const bool deleteSourceWhenDeleted_)
  18894. : requiredNumberOfChannels (2),
  18895. source (source_),
  18896. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18897. buffer (2, 16)
  18898. {
  18899. remappedInfo.buffer = &buffer;
  18900. remappedInfo.startSample = 0;
  18901. }
  18902. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18903. {
  18904. if (deleteSourceWhenDeleted)
  18905. delete source;
  18906. }
  18907. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18908. {
  18909. const ScopedLock sl (lock);
  18910. requiredNumberOfChannels = requiredNumberOfChannels_;
  18911. }
  18912. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18913. {
  18914. const ScopedLock sl (lock);
  18915. remappedInputs.clear();
  18916. remappedOutputs.clear();
  18917. }
  18918. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18919. {
  18920. const ScopedLock sl (lock);
  18921. while (remappedInputs.size() < destIndex)
  18922. remappedInputs.add (-1);
  18923. remappedInputs.set (destIndex, sourceIndex);
  18924. }
  18925. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18926. {
  18927. const ScopedLock sl (lock);
  18928. while (remappedOutputs.size() < sourceIndex)
  18929. remappedOutputs.add (-1);
  18930. remappedOutputs.set (sourceIndex, destIndex);
  18931. }
  18932. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18933. {
  18934. const ScopedLock sl (lock);
  18935. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18936. return remappedInputs.getUnchecked (inputChannelIndex);
  18937. return -1;
  18938. }
  18939. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18940. {
  18941. const ScopedLock sl (lock);
  18942. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18943. return remappedOutputs .getUnchecked (outputChannelIndex);
  18944. return -1;
  18945. }
  18946. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18947. {
  18948. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18949. }
  18950. void ChannelRemappingAudioSource::releaseResources()
  18951. {
  18952. source->releaseResources();
  18953. }
  18954. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18955. {
  18956. const ScopedLock sl (lock);
  18957. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18958. const int numChans = bufferToFill.buffer->getNumChannels();
  18959. int i;
  18960. for (i = 0; i < buffer.getNumChannels(); ++i)
  18961. {
  18962. const int remappedChan = getRemappedInputChannel (i);
  18963. if (remappedChan >= 0 && remappedChan < numChans)
  18964. {
  18965. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18966. remappedChan,
  18967. bufferToFill.startSample,
  18968. bufferToFill.numSamples);
  18969. }
  18970. else
  18971. {
  18972. buffer.clear (i, 0, bufferToFill.numSamples);
  18973. }
  18974. }
  18975. remappedInfo.numSamples = bufferToFill.numSamples;
  18976. source->getNextAudioBlock (remappedInfo);
  18977. bufferToFill.clearActiveBufferRegion();
  18978. for (i = 0; i < requiredNumberOfChannels; ++i)
  18979. {
  18980. const int remappedChan = getRemappedOutputChannel (i);
  18981. if (remappedChan >= 0 && remappedChan < numChans)
  18982. {
  18983. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18984. buffer, i, 0, bufferToFill.numSamples);
  18985. }
  18986. }
  18987. }
  18988. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18989. {
  18990. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18991. String ins, outs;
  18992. int i;
  18993. const ScopedLock sl (lock);
  18994. for (i = 0; i < remappedInputs.size(); ++i)
  18995. ins << remappedInputs.getUnchecked(i) << T(' ');
  18996. for (i = 0; i < remappedOutputs.size(); ++i)
  18997. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18998. e->setAttribute (T("inputs"), ins.trimEnd());
  18999. e->setAttribute (T("outputs"), outs.trimEnd());
  19000. return e;
  19001. }
  19002. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  19003. {
  19004. if (e.hasTagName (T("MAPPINGS")))
  19005. {
  19006. const ScopedLock sl (lock);
  19007. clearAllMappings();
  19008. StringArray ins, outs;
  19009. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  19010. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  19011. int i;
  19012. for (i = 0; i < ins.size(); ++i)
  19013. remappedInputs.add (ins[i].getIntValue());
  19014. for (i = 0; i < outs.size(); ++i)
  19015. remappedOutputs.add (outs[i].getIntValue());
  19016. }
  19017. }
  19018. END_JUCE_NAMESPACE
  19019. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  19020. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  19021. BEGIN_JUCE_NAMESPACE
  19022. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  19023. const bool deleteInputWhenDeleted_)
  19024. : input (inputSource),
  19025. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  19026. {
  19027. jassert (inputSource != 0);
  19028. for (int i = 2; --i >= 0;)
  19029. iirFilters.add (new IIRFilter());
  19030. }
  19031. IIRFilterAudioSource::~IIRFilterAudioSource()
  19032. {
  19033. if (deleteInputWhenDeleted)
  19034. delete input;
  19035. }
  19036. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  19037. {
  19038. for (int i = iirFilters.size(); --i >= 0;)
  19039. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  19040. }
  19041. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19042. {
  19043. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19044. for (int i = iirFilters.size(); --i >= 0;)
  19045. iirFilters.getUnchecked(i)->reset();
  19046. }
  19047. void IIRFilterAudioSource::releaseResources()
  19048. {
  19049. input->releaseResources();
  19050. }
  19051. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  19052. {
  19053. input->getNextAudioBlock (bufferToFill);
  19054. const int numChannels = bufferToFill.buffer->getNumChannels();
  19055. while (numChannels > iirFilters.size())
  19056. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  19057. for (int i = 0; i < numChannels; ++i)
  19058. iirFilters.getUnchecked(i)
  19059. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  19060. bufferToFill.numSamples);
  19061. }
  19062. END_JUCE_NAMESPACE
  19063. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  19064. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  19065. BEGIN_JUCE_NAMESPACE
  19066. MixerAudioSource::MixerAudioSource()
  19067. : tempBuffer (2, 0),
  19068. currentSampleRate (0.0),
  19069. bufferSizeExpected (0)
  19070. {
  19071. }
  19072. MixerAudioSource::~MixerAudioSource()
  19073. {
  19074. removeAllInputs();
  19075. }
  19076. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  19077. {
  19078. if (input != 0 && ! inputs.contains (input))
  19079. {
  19080. lock.enter();
  19081. double localRate = currentSampleRate;
  19082. int localBufferSize = bufferSizeExpected;
  19083. lock.exit();
  19084. if (localRate != 0.0)
  19085. input->prepareToPlay (localBufferSize, localRate);
  19086. const ScopedLock sl (lock);
  19087. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  19088. inputs.add (input);
  19089. }
  19090. }
  19091. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  19092. {
  19093. if (input != 0)
  19094. {
  19095. lock.enter();
  19096. const int index = inputs.indexOf ((void*) input);
  19097. if (index >= 0)
  19098. {
  19099. inputsToDelete.shiftBits (index, 1);
  19100. inputs.remove (index);
  19101. }
  19102. lock.exit();
  19103. if (index >= 0)
  19104. {
  19105. input->releaseResources();
  19106. if (deleteInput)
  19107. delete input;
  19108. }
  19109. }
  19110. }
  19111. void MixerAudioSource::removeAllInputs()
  19112. {
  19113. lock.enter();
  19114. VoidArray inputsCopy (inputs);
  19115. BitArray inputsToDeleteCopy (inputsToDelete);
  19116. inputs.clear();
  19117. lock.exit();
  19118. for (int i = inputsCopy.size(); --i >= 0;)
  19119. if (inputsToDeleteCopy[i])
  19120. delete (AudioSource*) inputsCopy[i];
  19121. }
  19122. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19123. {
  19124. tempBuffer.setSize (2, samplesPerBlockExpected);
  19125. const ScopedLock sl (lock);
  19126. currentSampleRate = sampleRate;
  19127. bufferSizeExpected = samplesPerBlockExpected;
  19128. for (int i = inputs.size(); --i >= 0;)
  19129. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  19130. sampleRate);
  19131. }
  19132. void MixerAudioSource::releaseResources()
  19133. {
  19134. const ScopedLock sl (lock);
  19135. for (int i = inputs.size(); --i >= 0;)
  19136. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  19137. tempBuffer.setSize (2, 0);
  19138. currentSampleRate = 0;
  19139. bufferSizeExpected = 0;
  19140. }
  19141. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19142. {
  19143. const ScopedLock sl (lock);
  19144. if (inputs.size() > 0)
  19145. {
  19146. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  19147. if (inputs.size() > 1)
  19148. {
  19149. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  19150. info.buffer->getNumSamples());
  19151. AudioSourceChannelInfo info2;
  19152. info2.buffer = &tempBuffer;
  19153. info2.numSamples = info.numSamples;
  19154. info2.startSample = 0;
  19155. for (int i = 1; i < inputs.size(); ++i)
  19156. {
  19157. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  19158. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  19159. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  19160. }
  19161. }
  19162. }
  19163. else
  19164. {
  19165. info.clearActiveBufferRegion();
  19166. }
  19167. }
  19168. END_JUCE_NAMESPACE
  19169. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  19170. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  19171. BEGIN_JUCE_NAMESPACE
  19172. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  19173. const bool deleteInputWhenDeleted_)
  19174. : input (inputSource),
  19175. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  19176. ratio (1.0),
  19177. lastRatio (1.0),
  19178. buffer (2, 0),
  19179. sampsInBuffer (0)
  19180. {
  19181. jassert (input != 0);
  19182. }
  19183. ResamplingAudioSource::~ResamplingAudioSource()
  19184. {
  19185. if (deleteInputWhenDeleted)
  19186. delete input;
  19187. }
  19188. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  19189. {
  19190. jassert (samplesInPerOutputSample > 0);
  19191. const ScopedLock sl (ratioLock);
  19192. ratio = jmax (0.0, samplesInPerOutputSample);
  19193. }
  19194. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  19195. double sampleRate)
  19196. {
  19197. const ScopedLock sl (ratioLock);
  19198. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19199. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  19200. buffer.clear();
  19201. sampsInBuffer = 0;
  19202. bufferPos = 0;
  19203. subSampleOffset = 0.0;
  19204. createLowPass (ratio);
  19205. resetFilters();
  19206. }
  19207. void ResamplingAudioSource::releaseResources()
  19208. {
  19209. input->releaseResources();
  19210. buffer.setSize (2, 0);
  19211. }
  19212. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19213. {
  19214. const ScopedLock sl (ratioLock);
  19215. if (lastRatio != ratio)
  19216. {
  19217. createLowPass (ratio);
  19218. lastRatio = ratio;
  19219. }
  19220. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19221. int bufferSize = buffer.getNumSamples();
  19222. if (bufferSize < sampsNeeded + 8)
  19223. {
  19224. bufferPos %= bufferSize;
  19225. bufferSize = sampsNeeded + 32;
  19226. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19227. }
  19228. bufferPos %= bufferSize;
  19229. int endOfBufferPos = bufferPos + sampsInBuffer;
  19230. while (sampsNeeded > sampsInBuffer)
  19231. {
  19232. endOfBufferPos %= bufferSize;
  19233. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19234. bufferSize - endOfBufferPos);
  19235. AudioSourceChannelInfo readInfo;
  19236. readInfo.buffer = &buffer;
  19237. readInfo.numSamples = numToDo;
  19238. readInfo.startSample = endOfBufferPos;
  19239. input->getNextAudioBlock (readInfo);
  19240. if (ratio > 1.0001)
  19241. {
  19242. // for down-sampling, pre-apply the filter..
  19243. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19244. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19245. }
  19246. sampsInBuffer += numToDo;
  19247. endOfBufferPos += numToDo;
  19248. }
  19249. float* dl = info.buffer->getSampleData (0, info.startSample);
  19250. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19251. const float* const bl = buffer.getSampleData (0, 0);
  19252. const float* const br = buffer.getSampleData (1, 0);
  19253. int nextPos = (bufferPos + 1) % bufferSize;
  19254. for (int m = info.numSamples; --m >= 0;)
  19255. {
  19256. const float alpha = (float) subSampleOffset;
  19257. const float invAlpha = 1.0f - alpha;
  19258. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19259. if (dr != 0)
  19260. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19261. subSampleOffset += ratio;
  19262. jassert (sampsInBuffer > 0);
  19263. while (subSampleOffset >= 1.0)
  19264. {
  19265. if (++bufferPos >= bufferSize)
  19266. bufferPos = 0;
  19267. --sampsInBuffer;
  19268. nextPos = (bufferPos + 1) % bufferSize;
  19269. subSampleOffset -= 1.0;
  19270. }
  19271. }
  19272. if (ratio < 0.9999)
  19273. {
  19274. // for up-sampling, apply the filter after transposing..
  19275. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19276. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19277. }
  19278. else if (ratio <= 1.0001)
  19279. {
  19280. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19281. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19282. {
  19283. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19284. FilterState& fs = filterStates[i];
  19285. if (info.numSamples > 1)
  19286. {
  19287. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19288. }
  19289. else
  19290. {
  19291. fs.y2 = fs.y1;
  19292. fs.x2 = fs.x1;
  19293. }
  19294. fs.y1 = fs.x1 = *endOfBuffer;
  19295. }
  19296. }
  19297. jassert (sampsInBuffer >= 0);
  19298. }
  19299. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19300. {
  19301. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19302. : 0.5 * frequencyRatio;
  19303. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19304. const double nSquared = n * n;
  19305. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19306. setFilterCoefficients (c1,
  19307. c1 * 2.0f,
  19308. c1,
  19309. 1.0,
  19310. c1 * 2.0 * (1.0 - nSquared),
  19311. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19312. }
  19313. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19314. {
  19315. const double a = 1.0 / c4;
  19316. c1 *= a;
  19317. c2 *= a;
  19318. c3 *= a;
  19319. c5 *= a;
  19320. c6 *= a;
  19321. coefficients[0] = c1;
  19322. coefficients[1] = c2;
  19323. coefficients[2] = c3;
  19324. coefficients[3] = c4;
  19325. coefficients[4] = c5;
  19326. coefficients[5] = c6;
  19327. }
  19328. void ResamplingAudioSource::resetFilters()
  19329. {
  19330. zeromem (filterStates, sizeof (filterStates));
  19331. }
  19332. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19333. {
  19334. while (--num >= 0)
  19335. {
  19336. const double in = *samples;
  19337. double out = coefficients[0] * in
  19338. + coefficients[1] * fs.x1
  19339. + coefficients[2] * fs.x2
  19340. - coefficients[4] * fs.y1
  19341. - coefficients[5] * fs.y2;
  19342. #if JUCE_INTEL
  19343. if (! (out < -1.0e-8 || out > 1.0e-8))
  19344. out = 0;
  19345. #endif
  19346. fs.x2 = fs.x1;
  19347. fs.x1 = in;
  19348. fs.y2 = fs.y1;
  19349. fs.y1 = out;
  19350. *samples++ = (float) out;
  19351. }
  19352. }
  19353. END_JUCE_NAMESPACE
  19354. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19355. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19356. BEGIN_JUCE_NAMESPACE
  19357. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19358. : frequency (1000.0),
  19359. sampleRate (44100.0),
  19360. currentPhase (0.0),
  19361. phasePerSample (0.0),
  19362. amplitude (0.5f)
  19363. {
  19364. }
  19365. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19366. {
  19367. }
  19368. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19369. {
  19370. amplitude = newAmplitude;
  19371. }
  19372. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19373. {
  19374. frequency = newFrequencyHz;
  19375. phasePerSample = 0.0;
  19376. }
  19377. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19378. double sampleRate_)
  19379. {
  19380. currentPhase = 0.0;
  19381. phasePerSample = 0.0;
  19382. sampleRate = sampleRate_;
  19383. }
  19384. void ToneGeneratorAudioSource::releaseResources()
  19385. {
  19386. }
  19387. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19388. {
  19389. if (phasePerSample == 0.0)
  19390. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19391. for (int i = 0; i < info.numSamples; ++i)
  19392. {
  19393. const float sample = amplitude * (float) sin (currentPhase);
  19394. currentPhase += phasePerSample;
  19395. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19396. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19397. }
  19398. }
  19399. END_JUCE_NAMESPACE
  19400. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19401. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19402. BEGIN_JUCE_NAMESPACE
  19403. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19404. : sampleRate (0),
  19405. bufferSize (0),
  19406. useDefaultInputChannels (true),
  19407. useDefaultOutputChannels (true)
  19408. {
  19409. }
  19410. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19411. {
  19412. return outputDeviceName == other.outputDeviceName
  19413. && inputDeviceName == other.inputDeviceName
  19414. && sampleRate == other.sampleRate
  19415. && bufferSize == other.bufferSize
  19416. && inputChannels == other.inputChannels
  19417. && useDefaultInputChannels == other.useDefaultInputChannels
  19418. && outputChannels == other.outputChannels
  19419. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19420. }
  19421. AudioDeviceManager::AudioDeviceManager()
  19422. : currentAudioDevice (0),
  19423. numInputChansNeeded (0),
  19424. numOutputChansNeeded (2),
  19425. listNeedsScanning (true),
  19426. useInputNames (false),
  19427. inputLevelMeasurementEnabledCount (0),
  19428. inputLevel (0),
  19429. tempBuffer (2, 2),
  19430. defaultMidiOutput (0),
  19431. cpuUsageMs (0),
  19432. timeToCpuScale (0)
  19433. {
  19434. callbackHandler.owner = this;
  19435. }
  19436. AudioDeviceManager::~AudioDeviceManager()
  19437. {
  19438. currentAudioDevice = 0;
  19439. defaultMidiOutput = 0;
  19440. }
  19441. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19442. {
  19443. if (availableDeviceTypes.size() == 0)
  19444. {
  19445. createAudioDeviceTypes (availableDeviceTypes);
  19446. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19447. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19448. if (availableDeviceTypes.size() > 0)
  19449. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19450. }
  19451. }
  19452. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19453. {
  19454. scanDevicesIfNeeded();
  19455. return availableDeviceTypes;
  19456. }
  19457. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19458. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19459. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19460. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19461. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19462. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19463. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19464. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19465. {
  19466. #if JUCE_WINDOWS
  19467. #if JUCE_WASAPI
  19468. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19469. list.add (juce_createAudioIODeviceType_WASAPI());
  19470. #endif
  19471. #if JUCE_DIRECTSOUND
  19472. list.add (juce_createAudioIODeviceType_DirectSound());
  19473. #endif
  19474. #if JUCE_ASIO
  19475. list.add (juce_createAudioIODeviceType_ASIO());
  19476. #endif
  19477. #endif
  19478. #if JUCE_MAC
  19479. list.add (juce_createAudioIODeviceType_CoreAudio());
  19480. #endif
  19481. #if JUCE_IPHONE
  19482. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19483. #endif
  19484. #if JUCE_LINUX && JUCE_ALSA
  19485. list.add (juce_createAudioIODeviceType_ALSA());
  19486. #endif
  19487. #if JUCE_LINUX && JUCE_JACK
  19488. list.add (juce_createAudioIODeviceType_JACK());
  19489. #endif
  19490. }
  19491. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19492. const int numOutputChannelsNeeded,
  19493. const XmlElement* const e,
  19494. const bool selectDefaultDeviceOnFailure,
  19495. const String& preferredDefaultDeviceName,
  19496. const AudioDeviceSetup* preferredSetupOptions)
  19497. {
  19498. scanDevicesIfNeeded();
  19499. numInputChansNeeded = numInputChannelsNeeded;
  19500. numOutputChansNeeded = numOutputChannelsNeeded;
  19501. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19502. {
  19503. lastExplicitSettings = new XmlElement (*e);
  19504. String error;
  19505. AudioDeviceSetup setup;
  19506. if (preferredSetupOptions != 0)
  19507. setup = *preferredSetupOptions;
  19508. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19509. {
  19510. setup.inputDeviceName = setup.outputDeviceName
  19511. = e->getStringAttribute (T("audioDeviceName"));
  19512. }
  19513. else
  19514. {
  19515. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19516. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19517. }
  19518. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19519. if (currentDeviceType.isEmpty())
  19520. {
  19521. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19522. if (type != 0)
  19523. currentDeviceType = type->getTypeName();
  19524. else if (availableDeviceTypes.size() > 0)
  19525. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19526. }
  19527. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19528. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19529. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19530. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19531. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19532. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19533. error = setAudioDeviceSetup (setup, true);
  19534. midiInsFromXml.clear();
  19535. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19536. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19537. const StringArray allMidiIns (MidiInput::getDevices());
  19538. for (int i = allMidiIns.size(); --i >= 0;)
  19539. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19540. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19541. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19542. false, preferredDefaultDeviceName);
  19543. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19544. return error;
  19545. }
  19546. else
  19547. {
  19548. AudioDeviceSetup setup;
  19549. if (preferredSetupOptions != 0)
  19550. {
  19551. setup = *preferredSetupOptions;
  19552. }
  19553. else if (preferredDefaultDeviceName.isNotEmpty())
  19554. {
  19555. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19556. {
  19557. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19558. StringArray outs (type->getDeviceNames (false));
  19559. int i;
  19560. for (i = 0; i < outs.size(); ++i)
  19561. {
  19562. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19563. {
  19564. setup.outputDeviceName = outs[i];
  19565. break;
  19566. }
  19567. }
  19568. StringArray ins (type->getDeviceNames (true));
  19569. for (i = 0; i < ins.size(); ++i)
  19570. {
  19571. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19572. {
  19573. setup.inputDeviceName = ins[i];
  19574. break;
  19575. }
  19576. }
  19577. }
  19578. }
  19579. insertDefaultDeviceNames (setup);
  19580. return setAudioDeviceSetup (setup, false);
  19581. }
  19582. }
  19583. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19584. {
  19585. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19586. if (type != 0)
  19587. {
  19588. if (setup.outputDeviceName.isEmpty())
  19589. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19590. if (setup.inputDeviceName.isEmpty())
  19591. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19592. }
  19593. }
  19594. XmlElement* AudioDeviceManager::createStateXml() const
  19595. {
  19596. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19597. }
  19598. void AudioDeviceManager::scanDevicesIfNeeded()
  19599. {
  19600. if (listNeedsScanning)
  19601. {
  19602. listNeedsScanning = false;
  19603. createDeviceTypesIfNeeded();
  19604. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19605. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19606. }
  19607. }
  19608. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19609. {
  19610. scanDevicesIfNeeded();
  19611. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19612. {
  19613. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19614. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19615. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19616. {
  19617. return type;
  19618. }
  19619. }
  19620. return 0;
  19621. }
  19622. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19623. {
  19624. setup = currentSetup;
  19625. }
  19626. void AudioDeviceManager::deleteCurrentDevice()
  19627. {
  19628. currentAudioDevice = 0;
  19629. currentSetup.inputDeviceName = String::empty;
  19630. currentSetup.outputDeviceName = String::empty;
  19631. }
  19632. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19633. const bool treatAsChosenDevice)
  19634. {
  19635. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19636. {
  19637. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19638. && currentDeviceType != type)
  19639. {
  19640. currentDeviceType = type;
  19641. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19642. insertDefaultDeviceNames (s);
  19643. setAudioDeviceSetup (s, treatAsChosenDevice);
  19644. sendChangeMessage (this);
  19645. break;
  19646. }
  19647. }
  19648. }
  19649. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19650. {
  19651. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19652. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19653. return availableDeviceTypes[i];
  19654. return availableDeviceTypes[0];
  19655. }
  19656. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19657. const bool treatAsChosenDevice)
  19658. {
  19659. jassert (&newSetup != &currentSetup); // this will have no effect
  19660. if (newSetup == currentSetup && currentAudioDevice != 0)
  19661. return String::empty;
  19662. if (! (newSetup == currentSetup))
  19663. sendChangeMessage (this);
  19664. stopDevice();
  19665. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19666. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19667. String error;
  19668. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19669. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19670. {
  19671. deleteCurrentDevice();
  19672. if (treatAsChosenDevice)
  19673. updateXml();
  19674. return String::empty;
  19675. }
  19676. if (currentSetup.inputDeviceName != newInputDeviceName
  19677. || currentSetup.outputDeviceName != newOutputDeviceName
  19678. || currentAudioDevice == 0)
  19679. {
  19680. deleteCurrentDevice();
  19681. scanDevicesIfNeeded();
  19682. if (newOutputDeviceName.isNotEmpty()
  19683. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19684. {
  19685. return "No such device: " + newOutputDeviceName;
  19686. }
  19687. if (newInputDeviceName.isNotEmpty()
  19688. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19689. {
  19690. return "No such device: " + newInputDeviceName;
  19691. }
  19692. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19693. if (currentAudioDevice == 0)
  19694. 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!";
  19695. else
  19696. error = currentAudioDevice->getLastError();
  19697. if (error.isNotEmpty())
  19698. {
  19699. deleteCurrentDevice();
  19700. return error;
  19701. }
  19702. if (newSetup.useDefaultInputChannels)
  19703. {
  19704. inputChannels.clear();
  19705. inputChannels.setRange (0, numInputChansNeeded, true);
  19706. }
  19707. if (newSetup.useDefaultOutputChannels)
  19708. {
  19709. outputChannels.clear();
  19710. outputChannels.setRange (0, numOutputChansNeeded, true);
  19711. }
  19712. if (newInputDeviceName.isEmpty())
  19713. inputChannels.clear();
  19714. if (newOutputDeviceName.isEmpty())
  19715. outputChannels.clear();
  19716. }
  19717. if (! newSetup.useDefaultInputChannels)
  19718. inputChannels = newSetup.inputChannels;
  19719. if (! newSetup.useDefaultOutputChannels)
  19720. outputChannels = newSetup.outputChannels;
  19721. currentSetup = newSetup;
  19722. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19723. error = currentAudioDevice->open (inputChannels,
  19724. outputChannels,
  19725. currentSetup.sampleRate,
  19726. currentSetup.bufferSize);
  19727. if (error.isEmpty())
  19728. {
  19729. currentDeviceType = currentAudioDevice->getTypeName();
  19730. currentAudioDevice->start (&callbackHandler);
  19731. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19732. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19733. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19734. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19735. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19736. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19737. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19738. if (treatAsChosenDevice)
  19739. updateXml();
  19740. }
  19741. else
  19742. {
  19743. deleteCurrentDevice();
  19744. }
  19745. return error;
  19746. }
  19747. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19748. {
  19749. jassert (currentAudioDevice != 0);
  19750. if (rate > 0)
  19751. {
  19752. bool ok = false;
  19753. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19754. {
  19755. const double sr = currentAudioDevice->getSampleRate (i);
  19756. if (sr == rate)
  19757. ok = true;
  19758. }
  19759. if (! ok)
  19760. rate = 0;
  19761. }
  19762. if (rate == 0)
  19763. {
  19764. double lowestAbove44 = 0.0;
  19765. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19766. {
  19767. const double sr = currentAudioDevice->getSampleRate (i);
  19768. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19769. lowestAbove44 = sr;
  19770. }
  19771. if (lowestAbove44 == 0.0)
  19772. rate = currentAudioDevice->getSampleRate (0);
  19773. else
  19774. rate = lowestAbove44;
  19775. }
  19776. return rate;
  19777. }
  19778. void AudioDeviceManager::stopDevice()
  19779. {
  19780. if (currentAudioDevice != 0)
  19781. currentAudioDevice->stop();
  19782. testSound = 0;
  19783. }
  19784. void AudioDeviceManager::closeAudioDevice()
  19785. {
  19786. stopDevice();
  19787. currentAudioDevice = 0;
  19788. }
  19789. void AudioDeviceManager::restartLastAudioDevice()
  19790. {
  19791. if (currentAudioDevice == 0)
  19792. {
  19793. if (currentSetup.inputDeviceName.isEmpty()
  19794. && currentSetup.outputDeviceName.isEmpty())
  19795. {
  19796. // This method will only reload the last device that was running
  19797. // before closeAudioDevice() was called - you need to actually open
  19798. // one first, with setAudioDevice().
  19799. jassertfalse
  19800. return;
  19801. }
  19802. AudioDeviceSetup s (currentSetup);
  19803. setAudioDeviceSetup (s, false);
  19804. }
  19805. }
  19806. void AudioDeviceManager::updateXml()
  19807. {
  19808. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19809. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19810. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19811. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19812. if (currentAudioDevice != 0)
  19813. {
  19814. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19815. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19816. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19817. if (! currentSetup.useDefaultInputChannels)
  19818. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19819. if (! currentSetup.useDefaultOutputChannels)
  19820. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19821. }
  19822. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19823. {
  19824. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19825. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19826. }
  19827. if (midiInsFromXml.size() > 0)
  19828. {
  19829. // Add any midi devices that have been enabled before, but which aren't currently
  19830. // open because the device has been disconnected.
  19831. const StringArray availableMidiDevices (MidiInput::getDevices());
  19832. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19833. {
  19834. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19835. {
  19836. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19837. m->setAttribute ("name", midiInsFromXml[i]);
  19838. }
  19839. }
  19840. }
  19841. if (defaultMidiOutputName.isNotEmpty())
  19842. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19843. }
  19844. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19845. {
  19846. {
  19847. const ScopedLock sl (audioCallbackLock);
  19848. if (callbacks.contains (newCallback))
  19849. return;
  19850. }
  19851. if (currentAudioDevice != 0 && newCallback != 0)
  19852. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19853. const ScopedLock sl (audioCallbackLock);
  19854. callbacks.add (newCallback);
  19855. }
  19856. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19857. {
  19858. if (callback != 0)
  19859. {
  19860. bool needsDeinitialising = currentAudioDevice != 0;
  19861. {
  19862. const ScopedLock sl (audioCallbackLock);
  19863. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19864. callbacks.removeValue (callback);
  19865. }
  19866. if (needsDeinitialising)
  19867. callback->audioDeviceStopped();
  19868. }
  19869. }
  19870. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19871. int numInputChannels,
  19872. float** outputChannelData,
  19873. int numOutputChannels,
  19874. int numSamples)
  19875. {
  19876. const ScopedLock sl (audioCallbackLock);
  19877. if (inputLevelMeasurementEnabledCount > 0)
  19878. {
  19879. for (int j = 0; j < numSamples; ++j)
  19880. {
  19881. float s = 0;
  19882. for (int i = 0; i < numInputChannels; ++i)
  19883. s += fabsf (inputChannelData[i][j]);
  19884. s /= numInputChannels;
  19885. const double decayFactor = 0.99992;
  19886. if (s > inputLevel)
  19887. inputLevel = s;
  19888. else if (inputLevel > 0.001f)
  19889. inputLevel *= decayFactor;
  19890. else
  19891. inputLevel = 0;
  19892. }
  19893. }
  19894. if (callbacks.size() > 0)
  19895. {
  19896. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19897. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19898. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19899. outputChannelData, numOutputChannels, numSamples);
  19900. float** const tempChans = tempBuffer.getArrayOfChannels();
  19901. for (int i = callbacks.size(); --i > 0;)
  19902. {
  19903. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19904. tempChans, numOutputChannels, numSamples);
  19905. for (int chan = 0; chan < numOutputChannels; ++chan)
  19906. {
  19907. const float* const src = tempChans [chan];
  19908. float* const dst = outputChannelData [chan];
  19909. if (src != 0 && dst != 0)
  19910. for (int j = 0; j < numSamples; ++j)
  19911. dst[j] += src[j];
  19912. }
  19913. }
  19914. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19915. const double filterAmount = 0.2;
  19916. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19917. }
  19918. else
  19919. {
  19920. for (int i = 0; i < numOutputChannels; ++i)
  19921. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19922. }
  19923. if (testSound != 0)
  19924. {
  19925. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19926. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19927. for (int i = 0; i < numOutputChannels; ++i)
  19928. for (int j = 0; j < numSamps; ++j)
  19929. outputChannelData [i][j] += src[j];
  19930. testSoundPosition += numSamps;
  19931. if (testSoundPosition >= testSound->getNumSamples())
  19932. testSound = 0;
  19933. }
  19934. }
  19935. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19936. {
  19937. cpuUsageMs = 0;
  19938. const double sampleRate = device->getCurrentSampleRate();
  19939. const int blockSize = device->getCurrentBufferSizeSamples();
  19940. if (sampleRate > 0.0 && blockSize > 0)
  19941. {
  19942. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19943. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19944. }
  19945. {
  19946. const ScopedLock sl (audioCallbackLock);
  19947. for (int i = callbacks.size(); --i >= 0;)
  19948. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19949. }
  19950. sendChangeMessage (this);
  19951. }
  19952. void AudioDeviceManager::audioDeviceStoppedInt()
  19953. {
  19954. cpuUsageMs = 0;
  19955. timeToCpuScale = 0;
  19956. sendChangeMessage (this);
  19957. const ScopedLock sl (audioCallbackLock);
  19958. for (int i = callbacks.size(); --i >= 0;)
  19959. callbacks.getUnchecked(i)->audioDeviceStopped();
  19960. }
  19961. double AudioDeviceManager::getCpuUsage() const
  19962. {
  19963. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19964. }
  19965. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19966. const bool enabled)
  19967. {
  19968. if (enabled != isMidiInputEnabled (name))
  19969. {
  19970. if (enabled)
  19971. {
  19972. const int index = MidiInput::getDevices().indexOf (name);
  19973. if (index >= 0)
  19974. {
  19975. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19976. if (min != 0)
  19977. {
  19978. enabledMidiInputs.add (min);
  19979. min->start();
  19980. }
  19981. }
  19982. }
  19983. else
  19984. {
  19985. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19986. if (enabledMidiInputs[i]->getName() == name)
  19987. enabledMidiInputs.remove (i);
  19988. }
  19989. updateXml();
  19990. sendChangeMessage (this);
  19991. }
  19992. }
  19993. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19994. {
  19995. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19996. if (enabledMidiInputs[i]->getName() == name)
  19997. return true;
  19998. return false;
  19999. }
  20000. void AudioDeviceManager::addMidiInputCallback (const String& name,
  20001. MidiInputCallback* callback)
  20002. {
  20003. removeMidiInputCallback (name, callback);
  20004. if (name.isEmpty())
  20005. {
  20006. midiCallbacks.add (callback);
  20007. midiCallbackDevices.add (0);
  20008. }
  20009. else
  20010. {
  20011. for (int i = enabledMidiInputs.size(); --i >= 0;)
  20012. {
  20013. if (enabledMidiInputs[i]->getName() == name)
  20014. {
  20015. const ScopedLock sl (midiCallbackLock);
  20016. midiCallbacks.add (callback);
  20017. midiCallbackDevices.add (enabledMidiInputs[i]);
  20018. break;
  20019. }
  20020. }
  20021. }
  20022. }
  20023. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  20024. MidiInputCallback* /*callback*/)
  20025. {
  20026. const ScopedLock sl (midiCallbackLock);
  20027. for (int i = midiCallbacks.size(); --i >= 0;)
  20028. {
  20029. String devName;
  20030. if (midiCallbackDevices.getUnchecked(i) != 0)
  20031. devName = midiCallbackDevices.getUnchecked(i)->getName();
  20032. if (devName == name)
  20033. {
  20034. midiCallbacks.remove (i);
  20035. midiCallbackDevices.remove (i);
  20036. }
  20037. }
  20038. }
  20039. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  20040. const MidiMessage& message)
  20041. {
  20042. if (! message.isActiveSense())
  20043. {
  20044. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  20045. const ScopedLock sl (midiCallbackLock);
  20046. for (int i = midiCallbackDevices.size(); --i >= 0;)
  20047. {
  20048. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  20049. if (md == source || (md == 0 && isDefaultSource))
  20050. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  20051. }
  20052. }
  20053. }
  20054. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  20055. {
  20056. if (defaultMidiOutputName != deviceName)
  20057. {
  20058. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  20059. {
  20060. const ScopedLock sl (audioCallbackLock);
  20061. oldCallbacks = callbacks;
  20062. callbacks.clear();
  20063. }
  20064. if (currentAudioDevice != 0)
  20065. for (int i = oldCallbacks.size(); --i >= 0;)
  20066. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  20067. defaultMidiOutput = 0;
  20068. defaultMidiOutputName = deviceName;
  20069. if (deviceName.isNotEmpty())
  20070. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  20071. if (currentAudioDevice != 0)
  20072. for (int i = oldCallbacks.size(); --i >= 0;)
  20073. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  20074. {
  20075. const ScopedLock sl (audioCallbackLock);
  20076. callbacks = oldCallbacks;
  20077. }
  20078. updateXml();
  20079. sendChangeMessage (this);
  20080. }
  20081. }
  20082. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  20083. int numInputChannels,
  20084. float** outputChannelData,
  20085. int numOutputChannels,
  20086. int numSamples)
  20087. {
  20088. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  20089. }
  20090. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  20091. {
  20092. owner->audioDeviceAboutToStartInt (device);
  20093. }
  20094. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  20095. {
  20096. owner->audioDeviceStoppedInt();
  20097. }
  20098. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  20099. {
  20100. owner->handleIncomingMidiMessageInt (source, message);
  20101. }
  20102. void AudioDeviceManager::playTestSound()
  20103. {
  20104. {
  20105. audioCallbackLock.enter();
  20106. ScopedPointer <AudioSampleBuffer> oldSound (testSound);
  20107. audioCallbackLock.exit();
  20108. }
  20109. testSoundPosition = 0;
  20110. if (currentAudioDevice != 0)
  20111. {
  20112. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  20113. const int soundLength = (int) sampleRate;
  20114. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  20115. float* samples = newSound->getSampleData (0);
  20116. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  20117. const float amplitude = 0.5f;
  20118. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  20119. for (int i = 0; i < soundLength; ++i)
  20120. samples[i] = amplitude * (float) sin (i * phasePerSample);
  20121. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  20122. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  20123. const ScopedLock sl (audioCallbackLock);
  20124. testSound = newSound;
  20125. }
  20126. }
  20127. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  20128. {
  20129. const ScopedLock sl (audioCallbackLock);
  20130. if (enableMeasurement)
  20131. ++inputLevelMeasurementEnabledCount;
  20132. else
  20133. --inputLevelMeasurementEnabledCount;
  20134. inputLevel = 0;
  20135. }
  20136. double AudioDeviceManager::getCurrentInputLevel() const
  20137. {
  20138. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  20139. return inputLevel;
  20140. }
  20141. END_JUCE_NAMESPACE
  20142. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  20143. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  20144. BEGIN_JUCE_NAMESPACE
  20145. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  20146. : name (deviceName),
  20147. typeName (typeName_)
  20148. {
  20149. }
  20150. AudioIODevice::~AudioIODevice()
  20151. {
  20152. }
  20153. bool AudioIODevice::hasControlPanel() const
  20154. {
  20155. return false;
  20156. }
  20157. bool AudioIODevice::showControlPanel()
  20158. {
  20159. jassertfalse // this should only be called for devices which return true from
  20160. // their hasControlPanel() method.
  20161. return false;
  20162. }
  20163. END_JUCE_NAMESPACE
  20164. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  20165. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  20166. BEGIN_JUCE_NAMESPACE
  20167. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  20168. : typeName (name)
  20169. {
  20170. }
  20171. AudioIODeviceType::~AudioIODeviceType()
  20172. {
  20173. }
  20174. END_JUCE_NAMESPACE
  20175. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  20176. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  20177. BEGIN_JUCE_NAMESPACE
  20178. MidiOutput::MidiOutput() throw()
  20179. : Thread ("midi out"),
  20180. internal (0),
  20181. firstMessage (0)
  20182. {
  20183. }
  20184. MidiOutput::PendingMessage::PendingMessage (const uint8* const data,
  20185. const int len,
  20186. const double sampleNumber) throw()
  20187. : message (data, len, sampleNumber)
  20188. {
  20189. }
  20190. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  20191. const double millisecondCounterToStartAt,
  20192. double samplesPerSecondForBuffer) throw()
  20193. {
  20194. // You've got to call startBackgroundThread() for this to actually work..
  20195. jassert (isThreadRunning());
  20196. // this needs to be a value in the future - RTFM for this method!
  20197. jassert (millisecondCounterToStartAt > 0);
  20198. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  20199. MidiBuffer::Iterator i (buffer);
  20200. const uint8* data;
  20201. int len, time;
  20202. while (i.getNextEvent (data, len, time))
  20203. {
  20204. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  20205. PendingMessage* const m
  20206. = new PendingMessage (data, len, eventTime);
  20207. const ScopedLock sl (lock);
  20208. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  20209. {
  20210. m->next = firstMessage;
  20211. firstMessage = m;
  20212. }
  20213. else
  20214. {
  20215. PendingMessage* mm = firstMessage;
  20216. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  20217. mm = mm->next;
  20218. m->next = mm->next;
  20219. mm->next = m;
  20220. }
  20221. }
  20222. notify();
  20223. }
  20224. void MidiOutput::clearAllPendingMessages() throw()
  20225. {
  20226. const ScopedLock sl (lock);
  20227. while (firstMessage != 0)
  20228. {
  20229. PendingMessage* const m = firstMessage;
  20230. firstMessage = firstMessage->next;
  20231. delete m;
  20232. }
  20233. }
  20234. void MidiOutput::startBackgroundThread() throw()
  20235. {
  20236. startThread (9);
  20237. }
  20238. void MidiOutput::stopBackgroundThread() throw()
  20239. {
  20240. stopThread (5000);
  20241. }
  20242. void MidiOutput::run()
  20243. {
  20244. while (! threadShouldExit())
  20245. {
  20246. uint32 now = Time::getMillisecondCounter();
  20247. uint32 eventTime = 0;
  20248. uint32 timeToWait = 500;
  20249. lock.enter();
  20250. PendingMessage* message = firstMessage;
  20251. if (message != 0)
  20252. {
  20253. eventTime = roundToInt (message->message.getTimeStamp());
  20254. if (eventTime > now + 20)
  20255. {
  20256. timeToWait = eventTime - (now + 20);
  20257. message = 0;
  20258. }
  20259. else
  20260. {
  20261. firstMessage = message->next;
  20262. }
  20263. }
  20264. lock.exit();
  20265. if (message != 0)
  20266. {
  20267. if (eventTime > now)
  20268. {
  20269. Time::waitForMillisecondCounter (eventTime);
  20270. if (threadShouldExit())
  20271. break;
  20272. }
  20273. if (eventTime > now - 200)
  20274. sendMessageNow (message->message);
  20275. delete message;
  20276. }
  20277. else
  20278. {
  20279. jassert (timeToWait < 1000 * 30);
  20280. wait (timeToWait);
  20281. }
  20282. }
  20283. clearAllPendingMessages();
  20284. }
  20285. END_JUCE_NAMESPACE
  20286. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20287. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20288. BEGIN_JUCE_NAMESPACE
  20289. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20290. {
  20291. const double maxVal = (double) 0x7fff;
  20292. char* intData = (char*) dest;
  20293. if (dest != (void*) source || destBytesPerSample <= 4)
  20294. {
  20295. for (int i = 0; i < numSamples; ++i)
  20296. {
  20297. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20298. intData += destBytesPerSample;
  20299. }
  20300. }
  20301. else
  20302. {
  20303. intData += destBytesPerSample * numSamples;
  20304. for (int i = numSamples; --i >= 0;)
  20305. {
  20306. intData -= destBytesPerSample;
  20307. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20308. }
  20309. }
  20310. }
  20311. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20312. {
  20313. const double maxVal = (double) 0x7fff;
  20314. char* intData = (char*) dest;
  20315. if (dest != (void*) source || destBytesPerSample <= 4)
  20316. {
  20317. for (int i = 0; i < numSamples; ++i)
  20318. {
  20319. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20320. intData += destBytesPerSample;
  20321. }
  20322. }
  20323. else
  20324. {
  20325. intData += destBytesPerSample * numSamples;
  20326. for (int i = numSamples; --i >= 0;)
  20327. {
  20328. intData -= destBytesPerSample;
  20329. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20330. }
  20331. }
  20332. }
  20333. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20334. {
  20335. const double maxVal = (double) 0x7fffff;
  20336. char* intData = (char*) dest;
  20337. if (dest != (void*) source || destBytesPerSample <= 4)
  20338. {
  20339. for (int i = 0; i < numSamples; ++i)
  20340. {
  20341. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20342. intData += destBytesPerSample;
  20343. }
  20344. }
  20345. else
  20346. {
  20347. intData += destBytesPerSample * numSamples;
  20348. for (int i = numSamples; --i >= 0;)
  20349. {
  20350. intData -= destBytesPerSample;
  20351. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20352. }
  20353. }
  20354. }
  20355. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20356. {
  20357. const double maxVal = (double) 0x7fffff;
  20358. char* intData = (char*) dest;
  20359. if (dest != (void*) source || destBytesPerSample <= 4)
  20360. {
  20361. for (int i = 0; i < numSamples; ++i)
  20362. {
  20363. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20364. intData += destBytesPerSample;
  20365. }
  20366. }
  20367. else
  20368. {
  20369. intData += destBytesPerSample * numSamples;
  20370. for (int i = numSamples; --i >= 0;)
  20371. {
  20372. intData -= destBytesPerSample;
  20373. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20374. }
  20375. }
  20376. }
  20377. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20378. {
  20379. const double maxVal = (double) 0x7fffffff;
  20380. char* intData = (char*) dest;
  20381. if (dest != (void*) source || destBytesPerSample <= 4)
  20382. {
  20383. for (int i = 0; i < numSamples; ++i)
  20384. {
  20385. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20386. intData += destBytesPerSample;
  20387. }
  20388. }
  20389. else
  20390. {
  20391. intData += destBytesPerSample * numSamples;
  20392. for (int i = numSamples; --i >= 0;)
  20393. {
  20394. intData -= destBytesPerSample;
  20395. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20396. }
  20397. }
  20398. }
  20399. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20400. {
  20401. const double maxVal = (double) 0x7fffffff;
  20402. char* intData = (char*) dest;
  20403. if (dest != (void*) source || destBytesPerSample <= 4)
  20404. {
  20405. for (int i = 0; i < numSamples; ++i)
  20406. {
  20407. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20408. intData += destBytesPerSample;
  20409. }
  20410. }
  20411. else
  20412. {
  20413. intData += destBytesPerSample * numSamples;
  20414. for (int i = numSamples; --i >= 0;)
  20415. {
  20416. intData -= destBytesPerSample;
  20417. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20418. }
  20419. }
  20420. }
  20421. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20422. {
  20423. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20424. char* d = (char*) dest;
  20425. for (int i = 0; i < numSamples; ++i)
  20426. {
  20427. *(float*) d = source[i];
  20428. #if JUCE_BIG_ENDIAN
  20429. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20430. #endif
  20431. d += destBytesPerSample;
  20432. }
  20433. }
  20434. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20435. {
  20436. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20437. char* d = (char*) dest;
  20438. for (int i = 0; i < numSamples; ++i)
  20439. {
  20440. *(float*) d = source[i];
  20441. #if JUCE_LITTLE_ENDIAN
  20442. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20443. #endif
  20444. d += destBytesPerSample;
  20445. }
  20446. }
  20447. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20448. {
  20449. const float scale = 1.0f / 0x7fff;
  20450. const char* intData = (const char*) source;
  20451. if (source != (void*) dest || srcBytesPerSample >= 4)
  20452. {
  20453. for (int i = 0; i < numSamples; ++i)
  20454. {
  20455. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20456. intData += srcBytesPerSample;
  20457. }
  20458. }
  20459. else
  20460. {
  20461. intData += srcBytesPerSample * numSamples;
  20462. for (int i = numSamples; --i >= 0;)
  20463. {
  20464. intData -= srcBytesPerSample;
  20465. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20466. }
  20467. }
  20468. }
  20469. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20470. {
  20471. const float scale = 1.0f / 0x7fff;
  20472. const char* intData = (const char*) source;
  20473. if (source != (void*) dest || srcBytesPerSample >= 4)
  20474. {
  20475. for (int i = 0; i < numSamples; ++i)
  20476. {
  20477. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20478. intData += srcBytesPerSample;
  20479. }
  20480. }
  20481. else
  20482. {
  20483. intData += srcBytesPerSample * numSamples;
  20484. for (int i = numSamples; --i >= 0;)
  20485. {
  20486. intData -= srcBytesPerSample;
  20487. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20488. }
  20489. }
  20490. }
  20491. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20492. {
  20493. const float scale = 1.0f / 0x7fffff;
  20494. const char* intData = (const char*) source;
  20495. if (source != (void*) dest || srcBytesPerSample >= 4)
  20496. {
  20497. for (int i = 0; i < numSamples; ++i)
  20498. {
  20499. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20500. intData += srcBytesPerSample;
  20501. }
  20502. }
  20503. else
  20504. {
  20505. intData += srcBytesPerSample * numSamples;
  20506. for (int i = numSamples; --i >= 0;)
  20507. {
  20508. intData -= srcBytesPerSample;
  20509. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20510. }
  20511. }
  20512. }
  20513. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20514. {
  20515. const float scale = 1.0f / 0x7fffff;
  20516. const char* intData = (const char*) source;
  20517. if (source != (void*) dest || srcBytesPerSample >= 4)
  20518. {
  20519. for (int i = 0; i < numSamples; ++i)
  20520. {
  20521. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20522. intData += srcBytesPerSample;
  20523. }
  20524. }
  20525. else
  20526. {
  20527. intData += srcBytesPerSample * numSamples;
  20528. for (int i = numSamples; --i >= 0;)
  20529. {
  20530. intData -= srcBytesPerSample;
  20531. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20532. }
  20533. }
  20534. }
  20535. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20536. {
  20537. const float scale = 1.0f / 0x7fffffff;
  20538. const char* intData = (const char*) source;
  20539. if (source != (void*) dest || srcBytesPerSample >= 4)
  20540. {
  20541. for (int i = 0; i < numSamples; ++i)
  20542. {
  20543. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20544. intData += srcBytesPerSample;
  20545. }
  20546. }
  20547. else
  20548. {
  20549. intData += srcBytesPerSample * numSamples;
  20550. for (int i = numSamples; --i >= 0;)
  20551. {
  20552. intData -= srcBytesPerSample;
  20553. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20554. }
  20555. }
  20556. }
  20557. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20558. {
  20559. const float scale = 1.0f / 0x7fffffff;
  20560. const char* intData = (const char*) source;
  20561. if (source != (void*) dest || srcBytesPerSample >= 4)
  20562. {
  20563. for (int i = 0; i < numSamples; ++i)
  20564. {
  20565. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20566. intData += srcBytesPerSample;
  20567. }
  20568. }
  20569. else
  20570. {
  20571. intData += srcBytesPerSample * numSamples;
  20572. for (int i = numSamples; --i >= 0;)
  20573. {
  20574. intData -= srcBytesPerSample;
  20575. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20576. }
  20577. }
  20578. }
  20579. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20580. {
  20581. const char* s = (const char*) source;
  20582. for (int i = 0; i < numSamples; ++i)
  20583. {
  20584. dest[i] = *(float*)s;
  20585. #if JUCE_BIG_ENDIAN
  20586. uint32* const d = (uint32*) (dest + i);
  20587. *d = ByteOrder::swap (*d);
  20588. #endif
  20589. s += srcBytesPerSample;
  20590. }
  20591. }
  20592. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20593. {
  20594. const char* s = (const char*) source;
  20595. for (int i = 0; i < numSamples; ++i)
  20596. {
  20597. dest[i] = *(float*)s;
  20598. #if JUCE_LITTLE_ENDIAN
  20599. uint32* const d = (uint32*) (dest + i);
  20600. *d = ByteOrder::swap (*d);
  20601. #endif
  20602. s += srcBytesPerSample;
  20603. }
  20604. }
  20605. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20606. const float* const source,
  20607. void* const dest,
  20608. const int numSamples)
  20609. {
  20610. switch (destFormat)
  20611. {
  20612. case int16LE:
  20613. convertFloatToInt16LE (source, dest, numSamples);
  20614. break;
  20615. case int16BE:
  20616. convertFloatToInt16BE (source, dest, numSamples);
  20617. break;
  20618. case int24LE:
  20619. convertFloatToInt24LE (source, dest, numSamples);
  20620. break;
  20621. case int24BE:
  20622. convertFloatToInt24BE (source, dest, numSamples);
  20623. break;
  20624. case int32LE:
  20625. convertFloatToInt32LE (source, dest, numSamples);
  20626. break;
  20627. case int32BE:
  20628. convertFloatToInt32BE (source, dest, numSamples);
  20629. break;
  20630. case float32LE:
  20631. convertFloatToFloat32LE (source, dest, numSamples);
  20632. break;
  20633. case float32BE:
  20634. convertFloatToFloat32BE (source, dest, numSamples);
  20635. break;
  20636. default:
  20637. jassertfalse
  20638. break;
  20639. }
  20640. }
  20641. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20642. const void* const source,
  20643. float* const dest,
  20644. const int numSamples)
  20645. {
  20646. switch (sourceFormat)
  20647. {
  20648. case int16LE:
  20649. convertInt16LEToFloat (source, dest, numSamples);
  20650. break;
  20651. case int16BE:
  20652. convertInt16BEToFloat (source, dest, numSamples);
  20653. break;
  20654. case int24LE:
  20655. convertInt24LEToFloat (source, dest, numSamples);
  20656. break;
  20657. case int24BE:
  20658. convertInt24BEToFloat (source, dest, numSamples);
  20659. break;
  20660. case int32LE:
  20661. convertInt32LEToFloat (source, dest, numSamples);
  20662. break;
  20663. case int32BE:
  20664. convertInt32BEToFloat (source, dest, numSamples);
  20665. break;
  20666. case float32LE:
  20667. convertFloat32LEToFloat (source, dest, numSamples);
  20668. break;
  20669. case float32BE:
  20670. convertFloat32BEToFloat (source, dest, numSamples);
  20671. break;
  20672. default:
  20673. jassertfalse
  20674. break;
  20675. }
  20676. }
  20677. void AudioDataConverters::interleaveSamples (const float** const source,
  20678. float* const dest,
  20679. const int numSamples,
  20680. const int numChannels)
  20681. {
  20682. for (int chan = 0; chan < numChannels; ++chan)
  20683. {
  20684. int i = chan;
  20685. const float* src = source [chan];
  20686. for (int j = 0; j < numSamples; ++j)
  20687. {
  20688. dest [i] = src [j];
  20689. i += numChannels;
  20690. }
  20691. }
  20692. }
  20693. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20694. float** const dest,
  20695. const int numSamples,
  20696. const int numChannels)
  20697. {
  20698. for (int chan = 0; chan < numChannels; ++chan)
  20699. {
  20700. int i = chan;
  20701. float* dst = dest [chan];
  20702. for (int j = 0; j < numSamples; ++j)
  20703. {
  20704. dst [j] = source [i];
  20705. i += numChannels;
  20706. }
  20707. }
  20708. }
  20709. END_JUCE_NAMESPACE
  20710. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20711. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20712. BEGIN_JUCE_NAMESPACE
  20713. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20714. const int numSamples) throw()
  20715. : numChannels (numChannels_),
  20716. size (numSamples)
  20717. {
  20718. jassert (numSamples >= 0);
  20719. jassert (numChannels_ > 0);
  20720. allocateData();
  20721. }
  20722. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20723. : numChannels (other.numChannels),
  20724. size (other.size)
  20725. {
  20726. allocateData();
  20727. const size_t numBytes = size * sizeof (float);
  20728. for (int i = 0; i < numChannels; ++i)
  20729. memcpy (channels[i], other.channels[i], numBytes);
  20730. }
  20731. void AudioSampleBuffer::allocateData()
  20732. {
  20733. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20734. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20735. allocatedData.malloc (allocatedBytes);
  20736. channels = (float**) allocatedData;
  20737. float* chan = (float*) (allocatedData + channelListSize);
  20738. for (int i = 0; i < numChannels; ++i)
  20739. {
  20740. channels[i] = chan;
  20741. chan += size;
  20742. }
  20743. channels [numChannels] = 0;
  20744. }
  20745. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20746. const int numChannels_,
  20747. const int numSamples) throw()
  20748. : numChannels (numChannels_),
  20749. size (numSamples),
  20750. allocatedBytes (0)
  20751. {
  20752. jassert (numChannels_ > 0);
  20753. allocateChannels (dataToReferTo);
  20754. }
  20755. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20756. const int newNumChannels,
  20757. const int newNumSamples) throw()
  20758. {
  20759. jassert (newNumChannels > 0);
  20760. allocatedBytes = 0;
  20761. allocatedData.free();
  20762. numChannels = newNumChannels;
  20763. size = newNumSamples;
  20764. allocateChannels (dataToReferTo);
  20765. }
  20766. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20767. {
  20768. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20769. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20770. {
  20771. channels = (float**) preallocatedChannelSpace;
  20772. }
  20773. else
  20774. {
  20775. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20776. channels = (float**) allocatedData;
  20777. }
  20778. for (int i = 0; i < numChannels; ++i)
  20779. {
  20780. // you have to pass in the same number of valid pointers as numChannels
  20781. jassert (dataToReferTo[i] != 0);
  20782. channels[i] = dataToReferTo[i];
  20783. }
  20784. channels [numChannels] = 0;
  20785. }
  20786. const AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20787. {
  20788. if (this != &other)
  20789. {
  20790. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20791. const size_t numBytes = size * sizeof (float);
  20792. for (int i = 0; i < numChannels; ++i)
  20793. memcpy (channels[i], other.channels[i], numBytes);
  20794. }
  20795. return *this;
  20796. }
  20797. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20798. {
  20799. }
  20800. void AudioSampleBuffer::setSize (const int newNumChannels,
  20801. const int newNumSamples,
  20802. const bool keepExistingContent,
  20803. const bool clearExtraSpace,
  20804. const bool avoidReallocating) throw()
  20805. {
  20806. jassert (newNumChannels > 0);
  20807. if (newNumSamples != size || newNumChannels != numChannels)
  20808. {
  20809. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20810. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20811. if (keepExistingContent)
  20812. {
  20813. HeapBlock <char> newData;
  20814. newData.allocate (newTotalBytes, clearExtraSpace);
  20815. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20816. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20817. float** const newChannels = (float**) newData;
  20818. float* newChan = (float*) (newData + channelListSize);
  20819. for (int i = 0; i < numChansToCopy; ++i)
  20820. {
  20821. memcpy (newChan, channels[i], numBytesToCopy);
  20822. newChannels[i] = newChan;
  20823. newChan += newNumSamples;
  20824. }
  20825. allocatedData.swapWith (newData);
  20826. allocatedBytes = (int) newTotalBytes;
  20827. channels = (float**) allocatedData;
  20828. }
  20829. else
  20830. {
  20831. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20832. {
  20833. if (clearExtraSpace)
  20834. zeromem (allocatedData, newTotalBytes);
  20835. }
  20836. else
  20837. {
  20838. allocatedBytes = newTotalBytes;
  20839. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20840. channels = (float**) allocatedData;
  20841. }
  20842. float* chan = (float*) (allocatedData + channelListSize);
  20843. for (int i = 0; i < newNumChannels; ++i)
  20844. {
  20845. channels[i] = chan;
  20846. chan += newNumSamples;
  20847. }
  20848. }
  20849. channels [newNumChannels] = 0;
  20850. size = newNumSamples;
  20851. numChannels = newNumChannels;
  20852. }
  20853. }
  20854. void AudioSampleBuffer::clear() throw()
  20855. {
  20856. for (int i = 0; i < numChannels; ++i)
  20857. zeromem (channels[i], size * sizeof (float));
  20858. }
  20859. void AudioSampleBuffer::clear (const int startSample,
  20860. const int numSamples) throw()
  20861. {
  20862. jassert (startSample >= 0 && startSample + numSamples <= size);
  20863. for (int i = 0; i < numChannels; ++i)
  20864. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20865. }
  20866. void AudioSampleBuffer::clear (const int channel,
  20867. const int startSample,
  20868. const int numSamples) throw()
  20869. {
  20870. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20871. jassert (startSample >= 0 && startSample + numSamples <= size);
  20872. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20873. }
  20874. void AudioSampleBuffer::applyGain (const int channel,
  20875. const int startSample,
  20876. int numSamples,
  20877. const float gain) throw()
  20878. {
  20879. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20880. jassert (startSample >= 0 && startSample + numSamples <= size);
  20881. if (gain != 1.0f)
  20882. {
  20883. float* d = channels [channel] + startSample;
  20884. if (gain == 0.0f)
  20885. {
  20886. zeromem (d, sizeof (float) * numSamples);
  20887. }
  20888. else
  20889. {
  20890. while (--numSamples >= 0)
  20891. *d++ *= gain;
  20892. }
  20893. }
  20894. }
  20895. void AudioSampleBuffer::applyGainRamp (const int channel,
  20896. const int startSample,
  20897. int numSamples,
  20898. float startGain,
  20899. float endGain) throw()
  20900. {
  20901. if (startGain == endGain)
  20902. {
  20903. applyGain (channel, startSample, numSamples, startGain);
  20904. }
  20905. else
  20906. {
  20907. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20908. jassert (startSample >= 0 && startSample + numSamples <= size);
  20909. const float increment = (endGain - startGain) / numSamples;
  20910. float* d = channels [channel] + startSample;
  20911. while (--numSamples >= 0)
  20912. {
  20913. *d++ *= startGain;
  20914. startGain += increment;
  20915. }
  20916. }
  20917. }
  20918. void AudioSampleBuffer::applyGain (const int startSample,
  20919. const int numSamples,
  20920. const float gain) throw()
  20921. {
  20922. for (int i = 0; i < numChannels; ++i)
  20923. applyGain (i, startSample, numSamples, gain);
  20924. }
  20925. void AudioSampleBuffer::addFrom (const int destChannel,
  20926. const int destStartSample,
  20927. const AudioSampleBuffer& source,
  20928. const int sourceChannel,
  20929. const int sourceStartSample,
  20930. int numSamples,
  20931. const float gain) throw()
  20932. {
  20933. jassert (&source != this || sourceChannel != destChannel);
  20934. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20935. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20936. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20937. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20938. if (gain != 0.0f && numSamples > 0)
  20939. {
  20940. float* d = channels [destChannel] + destStartSample;
  20941. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20942. if (gain != 1.0f)
  20943. {
  20944. while (--numSamples >= 0)
  20945. *d++ += gain * *s++;
  20946. }
  20947. else
  20948. {
  20949. while (--numSamples >= 0)
  20950. *d++ += *s++;
  20951. }
  20952. }
  20953. }
  20954. void AudioSampleBuffer::addFrom (const int destChannel,
  20955. const int destStartSample,
  20956. const float* source,
  20957. int numSamples,
  20958. const float gain) throw()
  20959. {
  20960. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20961. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20962. jassert (source != 0);
  20963. if (gain != 0.0f && numSamples > 0)
  20964. {
  20965. float* d = channels [destChannel] + destStartSample;
  20966. if (gain != 1.0f)
  20967. {
  20968. while (--numSamples >= 0)
  20969. *d++ += gain * *source++;
  20970. }
  20971. else
  20972. {
  20973. while (--numSamples >= 0)
  20974. *d++ += *source++;
  20975. }
  20976. }
  20977. }
  20978. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20979. const int destStartSample,
  20980. const float* source,
  20981. int numSamples,
  20982. float startGain,
  20983. const float endGain) throw()
  20984. {
  20985. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20986. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20987. jassert (source != 0);
  20988. if (startGain == endGain)
  20989. {
  20990. addFrom (destChannel,
  20991. destStartSample,
  20992. source,
  20993. numSamples,
  20994. startGain);
  20995. }
  20996. else
  20997. {
  20998. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20999. {
  21000. const float increment = (endGain - startGain) / numSamples;
  21001. float* d = channels [destChannel] + destStartSample;
  21002. while (--numSamples >= 0)
  21003. {
  21004. *d++ += startGain * *source++;
  21005. startGain += increment;
  21006. }
  21007. }
  21008. }
  21009. }
  21010. void AudioSampleBuffer::copyFrom (const int destChannel,
  21011. const int destStartSample,
  21012. const AudioSampleBuffer& source,
  21013. const int sourceChannel,
  21014. const int sourceStartSample,
  21015. int numSamples) throw()
  21016. {
  21017. jassert (&source != this || sourceChannel != destChannel);
  21018. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21019. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21020. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  21021. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  21022. if (numSamples > 0)
  21023. {
  21024. memcpy (channels [destChannel] + destStartSample,
  21025. source.channels [sourceChannel] + sourceStartSample,
  21026. sizeof (float) * numSamples);
  21027. }
  21028. }
  21029. void AudioSampleBuffer::copyFrom (const int destChannel,
  21030. const int destStartSample,
  21031. const float* source,
  21032. int numSamples) throw()
  21033. {
  21034. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21035. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21036. jassert (source != 0);
  21037. if (numSamples > 0)
  21038. {
  21039. memcpy (channels [destChannel] + destStartSample,
  21040. source,
  21041. sizeof (float) * numSamples);
  21042. }
  21043. }
  21044. void AudioSampleBuffer::copyFrom (const int destChannel,
  21045. const int destStartSample,
  21046. const float* source,
  21047. int numSamples,
  21048. const float gain) throw()
  21049. {
  21050. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21051. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21052. jassert (source != 0);
  21053. if (numSamples > 0)
  21054. {
  21055. float* d = channels [destChannel] + destStartSample;
  21056. if (gain != 1.0f)
  21057. {
  21058. if (gain == 0)
  21059. {
  21060. zeromem (d, sizeof (float) * numSamples);
  21061. }
  21062. else
  21063. {
  21064. while (--numSamples >= 0)
  21065. *d++ = gain * *source++;
  21066. }
  21067. }
  21068. else
  21069. {
  21070. memcpy (d, source, sizeof (float) * numSamples);
  21071. }
  21072. }
  21073. }
  21074. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  21075. const int destStartSample,
  21076. const float* source,
  21077. int numSamples,
  21078. float startGain,
  21079. float endGain) throw()
  21080. {
  21081. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21082. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21083. jassert (source != 0);
  21084. if (startGain == endGain)
  21085. {
  21086. copyFrom (destChannel,
  21087. destStartSample,
  21088. source,
  21089. numSamples,
  21090. startGain);
  21091. }
  21092. else
  21093. {
  21094. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  21095. {
  21096. const float increment = (endGain - startGain) / numSamples;
  21097. float* d = channels [destChannel] + destStartSample;
  21098. while (--numSamples >= 0)
  21099. {
  21100. *d++ = startGain * *source++;
  21101. startGain += increment;
  21102. }
  21103. }
  21104. }
  21105. }
  21106. void AudioSampleBuffer::findMinMax (const int channel,
  21107. const int startSample,
  21108. int numSamples,
  21109. float& minVal,
  21110. float& maxVal) const throw()
  21111. {
  21112. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21113. jassert (startSample >= 0 && startSample + numSamples <= size);
  21114. if (numSamples <= 0)
  21115. {
  21116. minVal = 0.0f;
  21117. maxVal = 0.0f;
  21118. }
  21119. else
  21120. {
  21121. const float* d = channels [channel] + startSample;
  21122. float mn = *d++;
  21123. float mx = mn;
  21124. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  21125. {
  21126. const float samp = *d++;
  21127. if (samp > mx)
  21128. mx = samp;
  21129. if (samp < mn)
  21130. mn = samp;
  21131. }
  21132. maxVal = mx;
  21133. minVal = mn;
  21134. }
  21135. }
  21136. float AudioSampleBuffer::getMagnitude (const int channel,
  21137. const int startSample,
  21138. const int numSamples) const throw()
  21139. {
  21140. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21141. jassert (startSample >= 0 && startSample + numSamples <= size);
  21142. float mn, mx;
  21143. findMinMax (channel, startSample, numSamples, mn, mx);
  21144. return jmax (mn, -mn, mx, -mx);
  21145. }
  21146. float AudioSampleBuffer::getMagnitude (const int startSample,
  21147. const int numSamples) const throw()
  21148. {
  21149. float mag = 0.0f;
  21150. for (int i = 0; i < numChannels; ++i)
  21151. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  21152. return mag;
  21153. }
  21154. float AudioSampleBuffer::getRMSLevel (const int channel,
  21155. const int startSample,
  21156. const int numSamples) const throw()
  21157. {
  21158. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21159. jassert (startSample >= 0 && startSample + numSamples <= size);
  21160. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  21161. return 0.0f;
  21162. const float* const data = channels [channel] + startSample;
  21163. double sum = 0.0;
  21164. for (int i = 0; i < numSamples; ++i)
  21165. {
  21166. const float sample = data [i];
  21167. sum += sample * sample;
  21168. }
  21169. return (float) sqrt (sum / numSamples);
  21170. }
  21171. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  21172. const int startSample,
  21173. const int numSamples,
  21174. const int readerStartSample,
  21175. const bool useLeftChan,
  21176. const bool useRightChan) throw()
  21177. {
  21178. jassert (reader != 0);
  21179. jassert (startSample >= 0 && startSample + numSamples <= size);
  21180. if (numSamples > 0)
  21181. {
  21182. int* chans[3];
  21183. if (useLeftChan == useRightChan)
  21184. {
  21185. chans[0] = (int*) getSampleData (0, startSample);
  21186. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  21187. }
  21188. else if (useLeftChan || (reader->numChannels == 1))
  21189. {
  21190. chans[0] = (int*) getSampleData (0, startSample);
  21191. chans[1] = 0;
  21192. }
  21193. else if (useRightChan)
  21194. {
  21195. chans[0] = 0;
  21196. chans[1] = (int*) getSampleData (0, startSample);
  21197. }
  21198. chans[2] = 0;
  21199. reader->read (chans, 2, readerStartSample, numSamples, true);
  21200. if (! reader->usesFloatingPointData)
  21201. {
  21202. for (int j = 0; j < 2; ++j)
  21203. {
  21204. float* const d = (float*) (chans[j]);
  21205. if (d != 0)
  21206. {
  21207. const float multiplier = 1.0f / 0x7fffffff;
  21208. for (int i = 0; i < numSamples; ++i)
  21209. d[i] = *(int*)(d + i) * multiplier;
  21210. }
  21211. }
  21212. }
  21213. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  21214. {
  21215. // if this is a stereo buffer and the source was mono, dupe the first channel..
  21216. memcpy (getSampleData (1, startSample),
  21217. getSampleData (0, startSample),
  21218. sizeof (float) * numSamples);
  21219. }
  21220. }
  21221. }
  21222. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21223. const int startSample,
  21224. const int numSamples) const throw()
  21225. {
  21226. jassert (startSample >= 0 && startSample + numSamples <= size);
  21227. if (numSamples > 0)
  21228. {
  21229. int* chans [3];
  21230. if (writer->isFloatingPoint())
  21231. {
  21232. chans[0] = (int*) getSampleData (0, startSample);
  21233. if (numChannels > 1)
  21234. chans[1] = (int*) getSampleData (1, startSample);
  21235. else
  21236. chans[1] = 0;
  21237. chans[2] = 0;
  21238. writer->write ((const int**) chans, numSamples);
  21239. }
  21240. else
  21241. {
  21242. HeapBlock <int> tempBuffer (numSamples * 2);
  21243. chans[0] = tempBuffer;
  21244. if (numChannels > 1)
  21245. chans[1] = chans[0] + numSamples;
  21246. else
  21247. chans[1] = 0;
  21248. chans[2] = 0;
  21249. for (int j = 0; j < 2; ++j)
  21250. {
  21251. int* const dest = chans[j];
  21252. if (dest != 0)
  21253. {
  21254. const float* const src = channels [j] + startSample;
  21255. for (int i = 0; i < numSamples; ++i)
  21256. {
  21257. const double samp = src[i];
  21258. if (samp <= -1.0)
  21259. dest[i] = std::numeric_limits<int>::min();
  21260. else if (samp >= 1.0)
  21261. dest[i] = std::numeric_limits<int>::max();
  21262. else
  21263. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21264. }
  21265. }
  21266. }
  21267. writer->write ((const int**) chans, numSamples);
  21268. }
  21269. }
  21270. }
  21271. END_JUCE_NAMESPACE
  21272. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21273. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21274. BEGIN_JUCE_NAMESPACE
  21275. IIRFilter::IIRFilter() throw()
  21276. : active (false)
  21277. {
  21278. reset();
  21279. }
  21280. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21281. : active (other.active)
  21282. {
  21283. const ScopedLock sl (other.processLock);
  21284. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21285. reset();
  21286. }
  21287. IIRFilter::~IIRFilter() throw()
  21288. {
  21289. }
  21290. void IIRFilter::reset() throw()
  21291. {
  21292. const ScopedLock sl (processLock);
  21293. x1 = 0;
  21294. x2 = 0;
  21295. y1 = 0;
  21296. y2 = 0;
  21297. }
  21298. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21299. {
  21300. float out = coefficients[0] * in
  21301. + coefficients[1] * x1
  21302. + coefficients[2] * x2
  21303. - coefficients[4] * y1
  21304. - coefficients[5] * y2;
  21305. #if JUCE_INTEL
  21306. if (! (out < -1.0e-8 || out > 1.0e-8))
  21307. out = 0;
  21308. #endif
  21309. x2 = x1;
  21310. x1 = in;
  21311. y2 = y1;
  21312. y1 = out;
  21313. return out;
  21314. }
  21315. void IIRFilter::processSamples (float* const samples,
  21316. const int numSamples) throw()
  21317. {
  21318. const ScopedLock sl (processLock);
  21319. if (active)
  21320. {
  21321. for (int i = 0; i < numSamples; ++i)
  21322. {
  21323. const float in = samples[i];
  21324. float out = coefficients[0] * in
  21325. + coefficients[1] * x1
  21326. + coefficients[2] * x2
  21327. - coefficients[4] * y1
  21328. - coefficients[5] * y2;
  21329. #if JUCE_INTEL
  21330. if (! (out < -1.0e-8 || out > 1.0e-8))
  21331. out = 0;
  21332. #endif
  21333. x2 = x1;
  21334. x1 = in;
  21335. y2 = y1;
  21336. y1 = out;
  21337. samples[i] = out;
  21338. }
  21339. }
  21340. }
  21341. void IIRFilter::makeLowPass (const double sampleRate,
  21342. const double frequency) throw()
  21343. {
  21344. jassert (sampleRate > 0);
  21345. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21346. const double nSquared = n * n;
  21347. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21348. setCoefficients (c1,
  21349. c1 * 2.0f,
  21350. c1,
  21351. 1.0,
  21352. c1 * 2.0 * (1.0 - nSquared),
  21353. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21354. }
  21355. void IIRFilter::makeHighPass (const double sampleRate,
  21356. const double frequency) throw()
  21357. {
  21358. const double n = tan (double_Pi * frequency / sampleRate);
  21359. const double nSquared = n * n;
  21360. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21361. setCoefficients (c1,
  21362. c1 * -2.0f,
  21363. c1,
  21364. 1.0,
  21365. c1 * 2.0 * (nSquared - 1.0),
  21366. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21367. }
  21368. void IIRFilter::makeLowShelf (const double sampleRate,
  21369. const double cutOffFrequency,
  21370. const double Q,
  21371. const float gainFactor) throw()
  21372. {
  21373. jassert (sampleRate > 0);
  21374. jassert (Q > 0);
  21375. const double A = jmax (0.0f, gainFactor);
  21376. const double aminus1 = A - 1.0;
  21377. const double aplus1 = A + 1.0;
  21378. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21379. const double coso = cos (omega);
  21380. const double beta = sin (omega) * sqrt (A) / Q;
  21381. const double aminus1TimesCoso = aminus1 * coso;
  21382. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21383. A * 2.0 * (aminus1 - aplus1 * coso),
  21384. A * (aplus1 - aminus1TimesCoso - beta),
  21385. aplus1 + aminus1TimesCoso + beta,
  21386. -2.0 * (aminus1 + aplus1 * coso),
  21387. aplus1 + aminus1TimesCoso - beta);
  21388. }
  21389. void IIRFilter::makeHighShelf (const double sampleRate,
  21390. const double cutOffFrequency,
  21391. const double Q,
  21392. const float gainFactor) throw()
  21393. {
  21394. jassert (sampleRate > 0);
  21395. jassert (Q > 0);
  21396. const double A = jmax (0.0f, gainFactor);
  21397. const double aminus1 = A - 1.0;
  21398. const double aplus1 = A + 1.0;
  21399. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21400. const double coso = cos (omega);
  21401. const double beta = sin (omega) * sqrt (A) / Q;
  21402. const double aminus1TimesCoso = aminus1 * coso;
  21403. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21404. A * -2.0 * (aminus1 + aplus1 * coso),
  21405. A * (aplus1 + aminus1TimesCoso - beta),
  21406. aplus1 - aminus1TimesCoso + beta,
  21407. 2.0 * (aminus1 - aplus1 * coso),
  21408. aplus1 - aminus1TimesCoso - beta);
  21409. }
  21410. void IIRFilter::makeBandPass (const double sampleRate,
  21411. const double centreFrequency,
  21412. const double Q,
  21413. const float gainFactor) throw()
  21414. {
  21415. jassert (sampleRate > 0);
  21416. jassert (Q > 0);
  21417. const double A = jmax (0.0f, gainFactor);
  21418. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21419. const double alpha = 0.5 * sin (omega) / Q;
  21420. const double c2 = -2.0 * cos (omega);
  21421. const double alphaTimesA = alpha * A;
  21422. const double alphaOverA = alpha / A;
  21423. setCoefficients (1.0 + alphaTimesA,
  21424. c2,
  21425. 1.0 - alphaTimesA,
  21426. 1.0 + alphaOverA,
  21427. c2,
  21428. 1.0 - alphaOverA);
  21429. }
  21430. void IIRFilter::makeInactive() throw()
  21431. {
  21432. const ScopedLock sl (processLock);
  21433. active = false;
  21434. }
  21435. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21436. {
  21437. const ScopedLock sl (processLock);
  21438. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21439. active = other.active;
  21440. }
  21441. void IIRFilter::setCoefficients (double c1,
  21442. double c2,
  21443. double c3,
  21444. double c4,
  21445. double c5,
  21446. double c6) throw()
  21447. {
  21448. const double a = 1.0 / c4;
  21449. c1 *= a;
  21450. c2 *= a;
  21451. c3 *= a;
  21452. c5 *= a;
  21453. c6 *= a;
  21454. const ScopedLock sl (processLock);
  21455. coefficients[0] = (float) c1;
  21456. coefficients[1] = (float) c2;
  21457. coefficients[2] = (float) c3;
  21458. coefficients[3] = (float) c4;
  21459. coefficients[4] = (float) c5;
  21460. coefficients[5] = (float) c6;
  21461. active = true;
  21462. }
  21463. END_JUCE_NAMESPACE
  21464. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21465. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21466. BEGIN_JUCE_NAMESPACE
  21467. MidiBuffer::MidiBuffer() throw()
  21468. : bytesUsed (0)
  21469. {
  21470. }
  21471. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21472. : bytesUsed (0)
  21473. {
  21474. addEvent (message, 0);
  21475. }
  21476. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21477. : data (other.data),
  21478. bytesUsed (other.bytesUsed)
  21479. {
  21480. }
  21481. const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21482. {
  21483. bytesUsed = other.bytesUsed;
  21484. data = other.data;
  21485. return *this;
  21486. }
  21487. void MidiBuffer::swap (MidiBuffer& other)
  21488. {
  21489. data.swapWith (other.data);
  21490. swapVariables <int> (bytesUsed, other.bytesUsed);
  21491. }
  21492. MidiBuffer::~MidiBuffer() throw()
  21493. {
  21494. }
  21495. void MidiBuffer::clear() throw()
  21496. {
  21497. bytesUsed = 0;
  21498. }
  21499. void MidiBuffer::clear (const int startSample,
  21500. const int numSamples) throw()
  21501. {
  21502. uint8* const start = findEventAfter (data, startSample - 1);
  21503. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21504. if (end > start)
  21505. {
  21506. const size_t bytesToMove = (size_t) (bytesUsed - (end - (uint8*) data.getData()));
  21507. if (bytesToMove > 0)
  21508. memmove (start, end, bytesToMove);
  21509. bytesUsed -= (int) (end - start);
  21510. }
  21511. }
  21512. void MidiBuffer::addEvent (const MidiMessage& m,
  21513. const int sampleNumber) throw()
  21514. {
  21515. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21516. }
  21517. static int findActualEventLength (const uint8* const data,
  21518. const int maxBytes) throw()
  21519. {
  21520. unsigned int byte = (unsigned int) *data;
  21521. int size = 0;
  21522. if (byte == 0xf0 || byte == 0xf7)
  21523. {
  21524. const uint8* d = data + 1;
  21525. while (d < data + maxBytes)
  21526. if (*d++ == 0xf7)
  21527. break;
  21528. size = (int) (d - data);
  21529. }
  21530. else if (byte == 0xff)
  21531. {
  21532. int n;
  21533. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21534. size = jmin (maxBytes, n + 2 + bytesLeft);
  21535. }
  21536. else if (byte >= 0x80)
  21537. {
  21538. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21539. }
  21540. return size;
  21541. }
  21542. void MidiBuffer::addEvent (const uint8* const newData,
  21543. const int maxBytes,
  21544. const int sampleNumber) throw()
  21545. {
  21546. const int numBytes = findActualEventLength (newData, maxBytes);
  21547. if (numBytes > 0)
  21548. {
  21549. int spaceNeeded = bytesUsed + numBytes + 6;
  21550. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21551. uint8* d = findEventAfter ((uint8*) data.getData(), sampleNumber);
  21552. const size_t bytesToMove = (size_t) (bytesUsed - (d - (uint8*) data.getData()));
  21553. if (bytesToMove > 0)
  21554. memmove (d + numBytes + 6,
  21555. d,
  21556. bytesToMove);
  21557. *(int*) d = sampleNumber;
  21558. d += 4;
  21559. *(uint16*) d = (uint16) numBytes;
  21560. d += 2;
  21561. memcpy (d, newData, numBytes);
  21562. bytesUsed += numBytes + 6;
  21563. }
  21564. }
  21565. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21566. const int startSample,
  21567. const int numSamples,
  21568. const int sampleDeltaToAdd) throw()
  21569. {
  21570. Iterator i (otherBuffer);
  21571. i.setNextSamplePosition (startSample);
  21572. const uint8* eventData;
  21573. int eventSize, position;
  21574. while (i.getNextEvent (eventData, eventSize, position)
  21575. && (position < startSample + numSamples || numSamples < 0))
  21576. {
  21577. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21578. }
  21579. }
  21580. bool MidiBuffer::isEmpty() const throw()
  21581. {
  21582. return bytesUsed == 0;
  21583. }
  21584. int MidiBuffer::getNumEvents() const throw()
  21585. {
  21586. int n = 0;
  21587. const uint8* d = (uint8*) data.getData();
  21588. const uint8* const end = d + bytesUsed;
  21589. while (d < end)
  21590. {
  21591. d += 4;
  21592. d += 2 + *(const uint16*) d;
  21593. ++n;
  21594. }
  21595. return n;
  21596. }
  21597. int MidiBuffer::getFirstEventTime() const throw()
  21598. {
  21599. return (bytesUsed > 0) ? *(const int*) data.getData() : 0;
  21600. }
  21601. int MidiBuffer::getLastEventTime() const throw()
  21602. {
  21603. if (bytesUsed == 0)
  21604. return 0;
  21605. const uint8* d = (uint8*) data.getData();
  21606. const uint8* const endData = d + bytesUsed;
  21607. for (;;)
  21608. {
  21609. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21610. if (nextOne >= endData)
  21611. return *(const int*) d;
  21612. d = nextOne;
  21613. }
  21614. }
  21615. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21616. {
  21617. const uint8* const endData = ((uint8*) data.getData()) + bytesUsed;
  21618. while (d < endData && *(int*) d <= samplePosition)
  21619. {
  21620. d += 4;
  21621. d += 2 + *(uint16*) d;
  21622. }
  21623. return d;
  21624. }
  21625. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21626. : buffer (buffer_),
  21627. data ((uint8*) buffer_.data.getData())
  21628. {
  21629. }
  21630. MidiBuffer::Iterator::~Iterator() throw()
  21631. {
  21632. }
  21633. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21634. {
  21635. data = buffer.data;
  21636. const uint8* dataEnd = ((uint8*) buffer.data.getData()) + buffer.bytesUsed;
  21637. while (data < dataEnd && *(int*) data < samplePosition)
  21638. {
  21639. data += 4;
  21640. data += 2 + *(uint16*) data;
  21641. }
  21642. }
  21643. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21644. int& numBytes,
  21645. int& samplePosition) throw()
  21646. {
  21647. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21648. return false;
  21649. samplePosition = *(int*) data;
  21650. data += 4;
  21651. numBytes = *(uint16*) data;
  21652. data += 2;
  21653. midiData = data;
  21654. data += numBytes;
  21655. return true;
  21656. }
  21657. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21658. int& samplePosition) throw()
  21659. {
  21660. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21661. return false;
  21662. samplePosition = *(int*) data;
  21663. data += 4;
  21664. const int numBytes = *(uint16*) data;
  21665. data += 2;
  21666. result = MidiMessage (data, numBytes, samplePosition);
  21667. data += numBytes;
  21668. return true;
  21669. }
  21670. END_JUCE_NAMESPACE
  21671. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21672. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21673. BEGIN_JUCE_NAMESPACE
  21674. struct TempoInfo
  21675. {
  21676. double bpm, timestamp;
  21677. };
  21678. struct TimeSigInfo
  21679. {
  21680. int numerator, denominator;
  21681. double timestamp;
  21682. };
  21683. MidiFile::MidiFile() throw()
  21684. : timeFormat ((short) (unsigned short) 0xe728)
  21685. {
  21686. }
  21687. MidiFile::~MidiFile() throw()
  21688. {
  21689. clear();
  21690. }
  21691. void MidiFile::clear() throw()
  21692. {
  21693. tracks.clear();
  21694. }
  21695. int MidiFile::getNumTracks() const throw()
  21696. {
  21697. return tracks.size();
  21698. }
  21699. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21700. {
  21701. return tracks [index];
  21702. }
  21703. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21704. {
  21705. tracks.add (new MidiMessageSequence (trackSequence));
  21706. }
  21707. short MidiFile::getTimeFormat() const throw()
  21708. {
  21709. return timeFormat;
  21710. }
  21711. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21712. {
  21713. timeFormat = (short)ticks;
  21714. }
  21715. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21716. const int subframeResolution) throw()
  21717. {
  21718. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21719. }
  21720. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21721. {
  21722. for (int i = tracks.size(); --i >= 0;)
  21723. {
  21724. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21725. for (int j = 0; j < numEvents; ++j)
  21726. {
  21727. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21728. if (m.isTempoMetaEvent())
  21729. tempoChangeEvents.addEvent (m);
  21730. }
  21731. }
  21732. }
  21733. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21734. {
  21735. for (int i = tracks.size(); --i >= 0;)
  21736. {
  21737. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21738. for (int j = 0; j < numEvents; ++j)
  21739. {
  21740. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21741. if (m.isTimeSignatureMetaEvent())
  21742. timeSigEvents.addEvent (m);
  21743. }
  21744. }
  21745. }
  21746. double MidiFile::getLastTimestamp() const
  21747. {
  21748. double t = 0.0;
  21749. for (int i = tracks.size(); --i >= 0;)
  21750. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21751. return t;
  21752. }
  21753. static bool parseMidiHeader (const char* &data,
  21754. short& timeFormat,
  21755. short& fileType,
  21756. short& numberOfTracks)
  21757. {
  21758. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21759. data += 4;
  21760. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21761. {
  21762. bool ok = false;
  21763. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21764. {
  21765. for (int i = 0; i < 8; ++i)
  21766. {
  21767. ch = ByteOrder::bigEndianInt (data);
  21768. data += 4;
  21769. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21770. {
  21771. ok = true;
  21772. break;
  21773. }
  21774. }
  21775. }
  21776. if (! ok)
  21777. return false;
  21778. }
  21779. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21780. data += 4;
  21781. fileType = (short) ByteOrder::bigEndianShort (data);
  21782. data += 2;
  21783. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21784. data += 2;
  21785. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21786. data += 2;
  21787. bytesRemaining -= 6;
  21788. data += bytesRemaining;
  21789. return true;
  21790. }
  21791. bool MidiFile::readFrom (InputStream& sourceStream)
  21792. {
  21793. clear();
  21794. MemoryBlock data;
  21795. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21796. // (put a sanity-check on the file size, as midi files are generally small)
  21797. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21798. {
  21799. size_t size = data.getSize();
  21800. const char* d = (char*) data.getData();
  21801. short fileType, expectedTracks;
  21802. if (size > 16 && parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21803. {
  21804. size -= (int) (d - (char*) data.getData());
  21805. int track = 0;
  21806. while (size > 0 && track < expectedTracks)
  21807. {
  21808. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21809. d += 4;
  21810. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21811. d += 4;
  21812. if (chunkSize <= 0)
  21813. break;
  21814. if (size < 0)
  21815. return false;
  21816. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21817. {
  21818. readNextTrack (d, chunkSize);
  21819. }
  21820. size -= chunkSize + 8;
  21821. d += chunkSize;
  21822. ++track;
  21823. }
  21824. return true;
  21825. }
  21826. }
  21827. return false;
  21828. }
  21829. // a comparator that puts all the note-offs before note-ons that have the same time
  21830. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21831. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21832. {
  21833. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21834. if (diff == 0)
  21835. {
  21836. if (first->message.isNoteOff() && second->message.isNoteOn())
  21837. return -1;
  21838. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21839. return 1;
  21840. else
  21841. return 0;
  21842. }
  21843. else
  21844. {
  21845. return (diff > 0) ? 1 : -1;
  21846. }
  21847. }
  21848. void MidiFile::readNextTrack (const char* data, int size)
  21849. {
  21850. double time = 0;
  21851. char lastStatusByte = 0;
  21852. MidiMessageSequence result;
  21853. while (size > 0)
  21854. {
  21855. int bytesUsed;
  21856. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21857. data += bytesUsed;
  21858. size -= bytesUsed;
  21859. time += delay;
  21860. int messSize = 0;
  21861. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21862. if (messSize <= 0)
  21863. break;
  21864. size -= messSize;
  21865. data += messSize;
  21866. result.addEvent (mm);
  21867. const char firstByte = *(mm.getRawData());
  21868. if ((firstByte & 0xf0) != 0xf0)
  21869. lastStatusByte = firstByte;
  21870. }
  21871. // use a sort that puts all the note-offs before note-ons that have the same time
  21872. result.list.sort (*this, true);
  21873. result.updateMatchedPairs();
  21874. addTrack (result);
  21875. }
  21876. static double convertTicksToSeconds (const double time,
  21877. const MidiMessageSequence& tempoEvents,
  21878. const int timeFormat)
  21879. {
  21880. if (timeFormat > 0)
  21881. {
  21882. int numer = 4, denom = 4;
  21883. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21884. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21885. double secsPerTick = 0.5 * tickLen;
  21886. const int numEvents = tempoEvents.getNumEvents();
  21887. for (int i = 0; i < numEvents; ++i)
  21888. {
  21889. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21890. if (time <= m.getTimeStamp())
  21891. break;
  21892. if (timeFormat > 0)
  21893. {
  21894. correctedTempoTime = correctedTempoTime
  21895. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21896. }
  21897. else
  21898. {
  21899. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21900. }
  21901. tempoTime = m.getTimeStamp();
  21902. if (m.isTempoMetaEvent())
  21903. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21904. else if (m.isTimeSignatureMetaEvent())
  21905. m.getTimeSignatureInfo (numer, denom);
  21906. while (i + 1 < numEvents)
  21907. {
  21908. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21909. if (m2.getTimeStamp() == tempoTime)
  21910. {
  21911. ++i;
  21912. if (m2.isTempoMetaEvent())
  21913. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21914. else if (m2.isTimeSignatureMetaEvent())
  21915. m2.getTimeSignatureInfo (numer, denom);
  21916. }
  21917. else
  21918. {
  21919. break;
  21920. }
  21921. }
  21922. }
  21923. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21924. }
  21925. else
  21926. {
  21927. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21928. }
  21929. }
  21930. void MidiFile::convertTimestampTicksToSeconds()
  21931. {
  21932. MidiMessageSequence tempoEvents;
  21933. findAllTempoEvents (tempoEvents);
  21934. findAllTimeSigEvents (tempoEvents);
  21935. for (int i = 0; i < tracks.size(); ++i)
  21936. {
  21937. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21938. for (int j = ms.getNumEvents(); --j >= 0;)
  21939. {
  21940. MidiMessage& m = ms.getEventPointer(j)->message;
  21941. m.setTimeStamp (convertTicksToSeconds (m.getTimeStamp(),
  21942. tempoEvents,
  21943. timeFormat));
  21944. }
  21945. }
  21946. }
  21947. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21948. {
  21949. unsigned int buffer = v & 0x7F;
  21950. while ((v >>= 7) != 0)
  21951. {
  21952. buffer <<= 8;
  21953. buffer |= ((v & 0x7F) | 0x80);
  21954. }
  21955. for (;;)
  21956. {
  21957. out.writeByte ((char) buffer);
  21958. if (buffer & 0x80)
  21959. buffer >>= 8;
  21960. else
  21961. break;
  21962. }
  21963. }
  21964. bool MidiFile::writeTo (OutputStream& out)
  21965. {
  21966. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21967. out.writeIntBigEndian (6);
  21968. out.writeShortBigEndian (1); // type
  21969. out.writeShortBigEndian ((short) tracks.size());
  21970. out.writeShortBigEndian (timeFormat);
  21971. for (int i = 0; i < tracks.size(); ++i)
  21972. writeTrack (out, i);
  21973. out.flush();
  21974. return true;
  21975. }
  21976. void MidiFile::writeTrack (OutputStream& mainOut,
  21977. const int trackNum)
  21978. {
  21979. MemoryOutputStream out;
  21980. const MidiMessageSequence& ms = *tracks[trackNum];
  21981. int lastTick = 0;
  21982. char lastStatusByte = 0;
  21983. for (int i = 0; i < ms.getNumEvents(); ++i)
  21984. {
  21985. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21986. const int tick = roundToInt (mm.getTimeStamp());
  21987. const int delta = jmax (0, tick - lastTick);
  21988. writeVariableLengthInt (out, delta);
  21989. lastTick = tick;
  21990. const char statusByte = *(mm.getRawData());
  21991. if ((statusByte == lastStatusByte)
  21992. && ((statusByte & 0xf0) != 0xf0)
  21993. && i > 0
  21994. && mm.getRawDataSize() > 1)
  21995. {
  21996. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21997. }
  21998. else
  21999. {
  22000. out.write (mm.getRawData(), mm.getRawDataSize());
  22001. }
  22002. lastStatusByte = statusByte;
  22003. }
  22004. out.writeByte (0);
  22005. const MidiMessage m (MidiMessage::endOfTrack());
  22006. out.write (m.getRawData(),
  22007. m.getRawDataSize());
  22008. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  22009. mainOut.writeIntBigEndian ((int) out.getDataSize());
  22010. mainOut.write (out.getData(), (int) out.getDataSize());
  22011. }
  22012. END_JUCE_NAMESPACE
  22013. /*** End of inlined file: juce_MidiFile.cpp ***/
  22014. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  22015. BEGIN_JUCE_NAMESPACE
  22016. MidiKeyboardState::MidiKeyboardState()
  22017. {
  22018. zeromem (noteStates, sizeof (noteStates));
  22019. }
  22020. MidiKeyboardState::~MidiKeyboardState()
  22021. {
  22022. }
  22023. void MidiKeyboardState::reset()
  22024. {
  22025. const ScopedLock sl (lock);
  22026. zeromem (noteStates, sizeof (noteStates));
  22027. eventsToAdd.clear();
  22028. }
  22029. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  22030. {
  22031. jassert (midiChannel >= 0 && midiChannel <= 16);
  22032. return ((unsigned int) n) < 128
  22033. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  22034. }
  22035. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  22036. {
  22037. return ((unsigned int) n) < 128
  22038. && (noteStates[n] & midiChannelMask) != 0;
  22039. }
  22040. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  22041. {
  22042. jassert (midiChannel >= 0 && midiChannel <= 16);
  22043. jassert (((unsigned int) midiNoteNumber) < 128);
  22044. const ScopedLock sl (lock);
  22045. if (((unsigned int) midiNoteNumber) < 128)
  22046. {
  22047. const int timeNow = (int) Time::getMillisecondCounter();
  22048. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  22049. eventsToAdd.clear (0, timeNow - 500);
  22050. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  22051. }
  22052. }
  22053. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  22054. {
  22055. if (((unsigned int) midiNoteNumber) < 128)
  22056. {
  22057. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  22058. for (int i = listeners.size(); --i >= 0;)
  22059. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22060. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  22061. }
  22062. }
  22063. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  22064. {
  22065. const ScopedLock sl (lock);
  22066. if (isNoteOn (midiChannel, midiNoteNumber))
  22067. {
  22068. const int timeNow = (int) Time::getMillisecondCounter();
  22069. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  22070. eventsToAdd.clear (0, timeNow - 500);
  22071. noteOffInternal (midiChannel, midiNoteNumber);
  22072. }
  22073. }
  22074. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  22075. {
  22076. if (isNoteOn (midiChannel, midiNoteNumber))
  22077. {
  22078. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  22079. for (int i = listeners.size(); --i >= 0;)
  22080. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22081. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  22082. }
  22083. }
  22084. void MidiKeyboardState::allNotesOff (const int midiChannel)
  22085. {
  22086. const ScopedLock sl (lock);
  22087. if (midiChannel <= 0)
  22088. {
  22089. for (int i = 1; i <= 16; ++i)
  22090. allNotesOff (i);
  22091. }
  22092. else
  22093. {
  22094. for (int i = 0; i < 128; ++i)
  22095. noteOff (midiChannel, i);
  22096. }
  22097. }
  22098. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  22099. {
  22100. if (message.isNoteOn())
  22101. {
  22102. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  22103. }
  22104. else if (message.isNoteOff())
  22105. {
  22106. noteOffInternal (message.getChannel(), message.getNoteNumber());
  22107. }
  22108. else if (message.isAllNotesOff())
  22109. {
  22110. for (int i = 0; i < 128; ++i)
  22111. noteOffInternal (message.getChannel(), i);
  22112. }
  22113. }
  22114. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  22115. const int startSample,
  22116. const int numSamples,
  22117. const bool injectIndirectEvents)
  22118. {
  22119. MidiBuffer::Iterator i (buffer);
  22120. MidiMessage message (0xf4, 0.0);
  22121. int time;
  22122. const ScopedLock sl (lock);
  22123. while (i.getNextEvent (message, time))
  22124. processNextMidiEvent (message);
  22125. if (injectIndirectEvents)
  22126. {
  22127. MidiBuffer::Iterator i2 (eventsToAdd);
  22128. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  22129. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  22130. while (i2.getNextEvent (message, time))
  22131. {
  22132. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  22133. buffer.addEvent (message, startSample + pos);
  22134. }
  22135. }
  22136. eventsToAdd.clear();
  22137. }
  22138. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  22139. {
  22140. const ScopedLock sl (lock);
  22141. listeners.addIfNotAlreadyThere (listener);
  22142. }
  22143. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  22144. {
  22145. const ScopedLock sl (lock);
  22146. listeners.removeValue (listener);
  22147. }
  22148. END_JUCE_NAMESPACE
  22149. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  22150. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  22151. BEGIN_JUCE_NAMESPACE
  22152. int MidiMessage::readVariableLengthVal (const uint8* data,
  22153. int& numBytesUsed) throw()
  22154. {
  22155. numBytesUsed = 0;
  22156. int v = 0;
  22157. int i;
  22158. do
  22159. {
  22160. i = (int) *data++;
  22161. if (++numBytesUsed > 6)
  22162. break;
  22163. v = (v << 7) + (i & 0x7f);
  22164. } while (i & 0x80);
  22165. return v;
  22166. }
  22167. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  22168. {
  22169. // this method only works for valid starting bytes of a short midi message
  22170. jassert (firstByte >= 0x80
  22171. && firstByte != 0xf0
  22172. && firstByte != 0xf7);
  22173. static const char messageLengths[] =
  22174. {
  22175. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22176. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22177. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22178. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22179. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22180. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22181. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22182. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  22183. };
  22184. return messageLengths [firstByte & 0x7f];
  22185. }
  22186. MidiMessage::MidiMessage (const uint8* const d,
  22187. const int dataSize,
  22188. const double t) throw()
  22189. : timeStamp (t),
  22190. message (0),
  22191. size (dataSize)
  22192. {
  22193. jassert (dataSize > 0);
  22194. if (dataSize <= 4)
  22195. data = (uint8*) &message;
  22196. else
  22197. data = (uint8*) juce_malloc (dataSize);
  22198. memcpy (data, d, dataSize);
  22199. // check that the length matches the data..
  22200. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  22201. }
  22202. MidiMessage::MidiMessage (const int byte1,
  22203. const double t) throw()
  22204. : timeStamp (t),
  22205. data ((uint8*) &message),
  22206. size (1)
  22207. {
  22208. data[0] = (uint8) byte1;
  22209. // check that the length matches the data..
  22210. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  22211. }
  22212. MidiMessage::MidiMessage (const int byte1,
  22213. const int byte2,
  22214. const double t) throw()
  22215. : timeStamp (t),
  22216. data ((uint8*) &message),
  22217. size (2)
  22218. {
  22219. data[0] = (uint8) byte1;
  22220. data[1] = (uint8) byte2;
  22221. // check that the length matches the data..
  22222. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  22223. }
  22224. MidiMessage::MidiMessage (const int byte1,
  22225. const int byte2,
  22226. const int byte3,
  22227. const double t) throw()
  22228. : timeStamp (t),
  22229. data ((uint8*) &message),
  22230. size (3)
  22231. {
  22232. data[0] = (uint8) byte1;
  22233. data[1] = (uint8) byte2;
  22234. data[2] = (uint8) byte3;
  22235. // check that the length matches the data..
  22236. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22237. }
  22238. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22239. : timeStamp (other.timeStamp),
  22240. message (other.message),
  22241. size (other.size)
  22242. {
  22243. if (other.data != (uint8*) &other.message)
  22244. {
  22245. data = (uint8*) juce_malloc (size);
  22246. memcpy (data, other.data, size);
  22247. }
  22248. else
  22249. {
  22250. data = (uint8*) &message;
  22251. }
  22252. }
  22253. MidiMessage::MidiMessage (const MidiMessage& other,
  22254. const double newTimeStamp) throw()
  22255. : timeStamp (newTimeStamp),
  22256. message (other.message),
  22257. size (other.size)
  22258. {
  22259. if (other.data != (uint8*) &other.message)
  22260. {
  22261. data = (uint8*) juce_malloc (size);
  22262. memcpy (data, other.data, size);
  22263. }
  22264. else
  22265. {
  22266. data = (uint8*) &message;
  22267. }
  22268. }
  22269. MidiMessage::MidiMessage (const uint8* src,
  22270. int sz,
  22271. int& numBytesUsed,
  22272. const uint8 lastStatusByte,
  22273. double t) throw()
  22274. : timeStamp (t),
  22275. data ((uint8*) &message),
  22276. message (0)
  22277. {
  22278. unsigned int byte = (unsigned int) *src;
  22279. if (byte < 0x80)
  22280. {
  22281. byte = (unsigned int) (uint8) lastStatusByte;
  22282. numBytesUsed = -1;
  22283. }
  22284. else
  22285. {
  22286. numBytesUsed = 0;
  22287. --sz;
  22288. ++src;
  22289. }
  22290. if (byte >= 0x80)
  22291. {
  22292. if (byte == 0xf0)
  22293. {
  22294. const uint8* d = (const uint8*) src;
  22295. while (d < src + sz)
  22296. {
  22297. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22298. {
  22299. if (*d == 0xf7) // include an 0xf7 if we hit one
  22300. ++d;
  22301. break;
  22302. }
  22303. ++d;
  22304. }
  22305. size = 1 + (int) (d - src);
  22306. data = (uint8*) juce_malloc (size);
  22307. *data = (uint8) byte;
  22308. memcpy (data + 1, src, size - 1);
  22309. }
  22310. else if (byte == 0xff)
  22311. {
  22312. int n;
  22313. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22314. size = jmin (sz + 1, n + 2 + bytesLeft);
  22315. data = (uint8*) juce_malloc (size);
  22316. *data = (uint8) byte;
  22317. memcpy (data + 1, src, size - 1);
  22318. }
  22319. else
  22320. {
  22321. size = getMessageLengthFromFirstByte ((uint8) byte);
  22322. *data = (uint8) byte;
  22323. if (size > 1)
  22324. {
  22325. data[1] = src[0];
  22326. if (size > 2)
  22327. data[2] = src[1];
  22328. }
  22329. }
  22330. numBytesUsed += size;
  22331. }
  22332. else
  22333. {
  22334. message = 0;
  22335. size = 0;
  22336. }
  22337. }
  22338. const MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22339. {
  22340. if (this != &other)
  22341. {
  22342. timeStamp = other.timeStamp;
  22343. size = other.size;
  22344. message = other.message;
  22345. if (data != (uint8*) &message)
  22346. juce_free (data);
  22347. if (other.data != (uint8*) &other.message)
  22348. {
  22349. data = (uint8*) juce_malloc (size);
  22350. memcpy (data, other.data, size);
  22351. }
  22352. else
  22353. {
  22354. data = (uint8*) &message;
  22355. }
  22356. }
  22357. return *this;
  22358. }
  22359. MidiMessage::~MidiMessage() throw()
  22360. {
  22361. if (data != (uint8*) &message)
  22362. juce_free (data);
  22363. }
  22364. int MidiMessage::getChannel() const throw()
  22365. {
  22366. if ((data[0] & 0xf0) != 0xf0)
  22367. return (data[0] & 0xf) + 1;
  22368. else
  22369. return 0;
  22370. }
  22371. bool MidiMessage::isForChannel (const int channel) const throw()
  22372. {
  22373. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22374. return ((data[0] & 0xf) == channel - 1)
  22375. && ((data[0] & 0xf0) != 0xf0);
  22376. }
  22377. void MidiMessage::setChannel (const int channel) throw()
  22378. {
  22379. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22380. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22381. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22382. | (uint8)(channel - 1));
  22383. }
  22384. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22385. {
  22386. return ((data[0] & 0xf0) == 0x90)
  22387. && (returnTrueForVelocity0 || data[2] != 0);
  22388. }
  22389. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22390. {
  22391. return ((data[0] & 0xf0) == 0x80)
  22392. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22393. }
  22394. bool MidiMessage::isNoteOnOrOff() const throw()
  22395. {
  22396. const int d = data[0] & 0xf0;
  22397. return (d == 0x90) || (d == 0x80);
  22398. }
  22399. int MidiMessage::getNoteNumber() const throw()
  22400. {
  22401. return data[1];
  22402. }
  22403. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22404. {
  22405. if (isNoteOnOrOff())
  22406. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22407. }
  22408. uint8 MidiMessage::getVelocity() const throw()
  22409. {
  22410. if (isNoteOnOrOff())
  22411. return data[2];
  22412. else
  22413. return 0;
  22414. }
  22415. float MidiMessage::getFloatVelocity() const throw()
  22416. {
  22417. return getVelocity() * (1.0f / 127.0f);
  22418. }
  22419. void MidiMessage::setVelocity (const float newVelocity) throw()
  22420. {
  22421. if (isNoteOnOrOff())
  22422. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22423. }
  22424. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22425. {
  22426. if (isNoteOnOrOff())
  22427. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22428. }
  22429. bool MidiMessage::isAftertouch() const throw()
  22430. {
  22431. return (data[0] & 0xf0) == 0xa0;
  22432. }
  22433. int MidiMessage::getAfterTouchValue() const throw()
  22434. {
  22435. return data[2];
  22436. }
  22437. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22438. const int noteNum,
  22439. const int aftertouchValue) throw()
  22440. {
  22441. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22442. jassert (((unsigned int) noteNum) <= 127);
  22443. jassert (((unsigned int) aftertouchValue) <= 127);
  22444. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22445. noteNum & 0x7f,
  22446. aftertouchValue & 0x7f);
  22447. }
  22448. bool MidiMessage::isChannelPressure() const throw()
  22449. {
  22450. return (data[0] & 0xf0) == 0xd0;
  22451. }
  22452. int MidiMessage::getChannelPressureValue() const throw()
  22453. {
  22454. jassert (isChannelPressure());
  22455. return data[1];
  22456. }
  22457. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22458. const int pressure) throw()
  22459. {
  22460. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22461. jassert (((unsigned int) pressure) <= 127);
  22462. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22463. pressure & 0x7f);
  22464. }
  22465. bool MidiMessage::isProgramChange() const throw()
  22466. {
  22467. return (data[0] & 0xf0) == 0xc0;
  22468. }
  22469. int MidiMessage::getProgramChangeNumber() const throw()
  22470. {
  22471. return data[1];
  22472. }
  22473. const MidiMessage MidiMessage::programChange (const int channel,
  22474. const int programNumber) throw()
  22475. {
  22476. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22477. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22478. programNumber & 0x7f);
  22479. }
  22480. bool MidiMessage::isPitchWheel() const throw()
  22481. {
  22482. return (data[0] & 0xf0) == 0xe0;
  22483. }
  22484. int MidiMessage::getPitchWheelValue() const throw()
  22485. {
  22486. return data[1] | (data[2] << 7);
  22487. }
  22488. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22489. const int position) throw()
  22490. {
  22491. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22492. jassert (((unsigned int) position) <= 0x3fff);
  22493. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22494. position & 127,
  22495. (position >> 7) & 127);
  22496. }
  22497. bool MidiMessage::isController() const throw()
  22498. {
  22499. return (data[0] & 0xf0) == 0xb0;
  22500. }
  22501. int MidiMessage::getControllerNumber() const throw()
  22502. {
  22503. jassert (isController());
  22504. return data[1];
  22505. }
  22506. int MidiMessage::getControllerValue() const throw()
  22507. {
  22508. jassert (isController());
  22509. return data[2];
  22510. }
  22511. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22512. const int controllerType,
  22513. const int value) throw()
  22514. {
  22515. // the channel must be between 1 and 16 inclusive
  22516. jassert (channel > 0 && channel <= 16);
  22517. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22518. controllerType & 127,
  22519. value & 127);
  22520. }
  22521. const MidiMessage MidiMessage::noteOn (const int channel,
  22522. const int noteNumber,
  22523. const float velocity) throw()
  22524. {
  22525. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22526. }
  22527. const MidiMessage MidiMessage::noteOn (const int channel,
  22528. const int noteNumber,
  22529. const uint8 velocity) throw()
  22530. {
  22531. jassert (channel > 0 && channel <= 16);
  22532. jassert (((unsigned int) noteNumber) <= 127);
  22533. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22534. noteNumber & 127,
  22535. jlimit (0, 127, roundToInt (velocity)));
  22536. }
  22537. const MidiMessage MidiMessage::noteOff (const int channel,
  22538. const int noteNumber) throw()
  22539. {
  22540. jassert (channel > 0 && channel <= 16);
  22541. jassert (((unsigned int) noteNumber) <= 127);
  22542. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22543. }
  22544. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22545. {
  22546. jassert (channel > 0 && channel <= 16);
  22547. return controllerEvent (channel, 123, 0);
  22548. }
  22549. bool MidiMessage::isAllNotesOff() const throw()
  22550. {
  22551. return (data[0] & 0xf0) == 0xb0
  22552. && data[1] == 123;
  22553. }
  22554. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22555. {
  22556. return controllerEvent (channel, 120, 0);
  22557. }
  22558. bool MidiMessage::isAllSoundOff() const throw()
  22559. {
  22560. return (data[0] & 0xf0) == 0xb0
  22561. && data[1] == 120;
  22562. }
  22563. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22564. {
  22565. return controllerEvent (channel, 121, 0);
  22566. }
  22567. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22568. {
  22569. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22570. uint8 buf[8];
  22571. buf[0] = 0xf0;
  22572. buf[1] = 0x7f;
  22573. buf[2] = 0x7f;
  22574. buf[3] = 0x04;
  22575. buf[4] = 0x01;
  22576. buf[5] = (uint8) (vol & 0x7f);
  22577. buf[6] = (uint8) (vol >> 7);
  22578. buf[7] = 0xf7;
  22579. return MidiMessage (buf, 8);
  22580. }
  22581. bool MidiMessage::isSysEx() const throw()
  22582. {
  22583. return *data == 0xf0;
  22584. }
  22585. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22586. const int dataSize) throw()
  22587. {
  22588. MemoryBlock mm (dataSize + 2);
  22589. uint8* const m = (uint8*) mm.getData();
  22590. m[0] = 0xf0;
  22591. memcpy (m + 1, sysexData, dataSize);
  22592. m[dataSize + 1] = 0xf7;
  22593. return MidiMessage (m, dataSize + 2);
  22594. }
  22595. const uint8* MidiMessage::getSysExData() const throw()
  22596. {
  22597. return (isSysEx()) ? getRawData() + 1
  22598. : 0;
  22599. }
  22600. int MidiMessage::getSysExDataSize() const throw()
  22601. {
  22602. return (isSysEx()) ? size - 2
  22603. : 0;
  22604. }
  22605. bool MidiMessage::isMetaEvent() const throw()
  22606. {
  22607. return *data == 0xff;
  22608. }
  22609. bool MidiMessage::isActiveSense() const throw()
  22610. {
  22611. return *data == 0xfe;
  22612. }
  22613. int MidiMessage::getMetaEventType() const throw()
  22614. {
  22615. if (*data != 0xff)
  22616. return -1;
  22617. else
  22618. return data[1];
  22619. }
  22620. int MidiMessage::getMetaEventLength() const throw()
  22621. {
  22622. if (*data == 0xff)
  22623. {
  22624. int n;
  22625. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22626. }
  22627. return 0;
  22628. }
  22629. const uint8* MidiMessage::getMetaEventData() const throw()
  22630. {
  22631. int n;
  22632. const uint8* d = data + 2;
  22633. readVariableLengthVal (d, n);
  22634. return d + n;
  22635. }
  22636. bool MidiMessage::isTrackMetaEvent() const throw()
  22637. {
  22638. return getMetaEventType() == 0;
  22639. }
  22640. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22641. {
  22642. return getMetaEventType() == 47;
  22643. }
  22644. bool MidiMessage::isTextMetaEvent() const throw()
  22645. {
  22646. const int t = getMetaEventType();
  22647. return t > 0 && t < 16;
  22648. }
  22649. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22650. {
  22651. return String ((const char*) getMetaEventData(),
  22652. getMetaEventLength());
  22653. }
  22654. bool MidiMessage::isTrackNameEvent() const throw()
  22655. {
  22656. return (data[1] == 3)
  22657. && (*data == 0xff);
  22658. }
  22659. bool MidiMessage::isTempoMetaEvent() const throw()
  22660. {
  22661. return (data[1] == 81)
  22662. && (*data == 0xff);
  22663. }
  22664. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22665. {
  22666. return (data[1] == 0x20)
  22667. && (*data == 0xff)
  22668. && (data[2] == 1);
  22669. }
  22670. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22671. {
  22672. return data[3] + 1;
  22673. }
  22674. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22675. {
  22676. if (! isTempoMetaEvent())
  22677. return 0.0;
  22678. const uint8* const d = getMetaEventData();
  22679. return (((unsigned int) d[0] << 16)
  22680. | ((unsigned int) d[1] << 8)
  22681. | d[2])
  22682. / 1000000.0;
  22683. }
  22684. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22685. {
  22686. if (timeFormat > 0)
  22687. {
  22688. if (! isTempoMetaEvent())
  22689. return 0.5 / timeFormat;
  22690. return getTempoSecondsPerQuarterNote() / timeFormat;
  22691. }
  22692. else
  22693. {
  22694. const int frameCode = (-timeFormat) >> 8;
  22695. double framesPerSecond;
  22696. switch (frameCode)
  22697. {
  22698. case 24: framesPerSecond = 24.0; break;
  22699. case 25: framesPerSecond = 25.0; break;
  22700. case 29: framesPerSecond = 29.97; break;
  22701. case 30: framesPerSecond = 30.0; break;
  22702. default: framesPerSecond = 30.0; break;
  22703. }
  22704. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22705. }
  22706. }
  22707. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22708. {
  22709. uint8 d[8];
  22710. d[0] = 0xff;
  22711. d[1] = 81;
  22712. d[2] = 3;
  22713. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22714. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22715. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22716. return MidiMessage (d, 6, 0.0);
  22717. }
  22718. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22719. {
  22720. return (data[1] == 0x58)
  22721. && (*data == (uint8) 0xff);
  22722. }
  22723. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22724. int& denominator) const throw()
  22725. {
  22726. if (isTimeSignatureMetaEvent())
  22727. {
  22728. const uint8* const d = getMetaEventData();
  22729. numerator = d[0];
  22730. denominator = 1 << d[1];
  22731. }
  22732. else
  22733. {
  22734. numerator = 4;
  22735. denominator = 4;
  22736. }
  22737. }
  22738. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22739. const int denominator) throw()
  22740. {
  22741. uint8 d[8];
  22742. d[0] = 0xff;
  22743. d[1] = 0x58;
  22744. d[2] = 0x04;
  22745. d[3] = (uint8) numerator;
  22746. int n = 1;
  22747. int powerOfTwo = 0;
  22748. while (n < denominator)
  22749. {
  22750. n <<= 1;
  22751. ++powerOfTwo;
  22752. }
  22753. d[4] = (uint8) powerOfTwo;
  22754. d[5] = 0x01;
  22755. d[6] = 96;
  22756. return MidiMessage (d, 7, 0.0);
  22757. }
  22758. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22759. {
  22760. uint8 d[8];
  22761. d[0] = 0xff;
  22762. d[1] = 0x20;
  22763. d[2] = 0x01;
  22764. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22765. return MidiMessage (d, 4, 0.0);
  22766. }
  22767. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22768. {
  22769. return getMetaEventType() == 89;
  22770. }
  22771. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22772. {
  22773. return (int) *getMetaEventData();
  22774. }
  22775. const MidiMessage MidiMessage::endOfTrack() throw()
  22776. {
  22777. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22778. }
  22779. bool MidiMessage::isSongPositionPointer() const throw()
  22780. {
  22781. return *data == 0xf2;
  22782. }
  22783. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22784. {
  22785. return data[1] | (data[2] << 7);
  22786. }
  22787. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22788. {
  22789. return MidiMessage (0xf2,
  22790. positionInMidiBeats & 127,
  22791. (positionInMidiBeats >> 7) & 127);
  22792. }
  22793. bool MidiMessage::isMidiStart() const throw()
  22794. {
  22795. return *data == 0xfa;
  22796. }
  22797. const MidiMessage MidiMessage::midiStart() throw()
  22798. {
  22799. return MidiMessage (0xfa);
  22800. }
  22801. bool MidiMessage::isMidiContinue() const throw()
  22802. {
  22803. return *data == 0xfb;
  22804. }
  22805. const MidiMessage MidiMessage::midiContinue() throw()
  22806. {
  22807. return MidiMessage (0xfb);
  22808. }
  22809. bool MidiMessage::isMidiStop() const throw()
  22810. {
  22811. return *data == 0xfc;
  22812. }
  22813. const MidiMessage MidiMessage::midiStop() throw()
  22814. {
  22815. return MidiMessage (0xfc);
  22816. }
  22817. bool MidiMessage::isMidiClock() const throw()
  22818. {
  22819. return *data == 0xf8;
  22820. }
  22821. const MidiMessage MidiMessage::midiClock() throw()
  22822. {
  22823. return MidiMessage (0xf8);
  22824. }
  22825. bool MidiMessage::isQuarterFrame() const throw()
  22826. {
  22827. return *data == 0xf1;
  22828. }
  22829. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22830. {
  22831. return ((int) data[1]) >> 4;
  22832. }
  22833. int MidiMessage::getQuarterFrameValue() const throw()
  22834. {
  22835. return ((int) data[1]) & 0x0f;
  22836. }
  22837. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22838. const int value) throw()
  22839. {
  22840. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22841. }
  22842. bool MidiMessage::isFullFrame() const throw()
  22843. {
  22844. return data[0] == 0xf0
  22845. && data[1] == 0x7f
  22846. && size >= 10
  22847. && data[3] == 0x01
  22848. && data[4] == 0x01;
  22849. }
  22850. void MidiMessage::getFullFrameParameters (int& hours,
  22851. int& minutes,
  22852. int& seconds,
  22853. int& frames,
  22854. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22855. {
  22856. jassert (isFullFrame());
  22857. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22858. hours = data[5] & 0x1f;
  22859. minutes = data[6];
  22860. seconds = data[7];
  22861. frames = data[8];
  22862. }
  22863. const MidiMessage MidiMessage::fullFrame (const int hours,
  22864. const int minutes,
  22865. const int seconds,
  22866. const int frames,
  22867. MidiMessage::SmpteTimecodeType timecodeType)
  22868. {
  22869. uint8 d[10];
  22870. d[0] = 0xf0;
  22871. d[1] = 0x7f;
  22872. d[2] = 0x7f;
  22873. d[3] = 0x01;
  22874. d[4] = 0x01;
  22875. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22876. d[6] = (uint8) minutes;
  22877. d[7] = (uint8) seconds;
  22878. d[8] = (uint8) frames;
  22879. d[9] = 0xf7;
  22880. return MidiMessage (d, 10, 0.0);
  22881. }
  22882. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22883. {
  22884. return data[0] == 0xf0
  22885. && data[1] == 0x7f
  22886. && data[3] == 0x06
  22887. && size > 5;
  22888. }
  22889. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22890. {
  22891. jassert (isMidiMachineControlMessage());
  22892. return (MidiMachineControlCommand) data[4];
  22893. }
  22894. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22895. {
  22896. uint8 d[6];
  22897. d[0] = 0xf0;
  22898. d[1] = 0x7f;
  22899. d[2] = 0x00;
  22900. d[3] = 0x06;
  22901. d[4] = (uint8) command;
  22902. d[5] = 0xf7;
  22903. return MidiMessage (d, 6, 0.0);
  22904. }
  22905. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22906. int& minutes,
  22907. int& seconds,
  22908. int& frames) const throw()
  22909. {
  22910. if (size >= 12
  22911. && data[0] == 0xf0
  22912. && data[1] == 0x7f
  22913. && data[3] == 0x06
  22914. && data[4] == 0x44
  22915. && data[5] == 0x06
  22916. && data[6] == 0x01)
  22917. {
  22918. hours = data[7] % 24; // (that some machines send out hours > 24)
  22919. minutes = data[8];
  22920. seconds = data[9];
  22921. frames = data[10];
  22922. return true;
  22923. }
  22924. return false;
  22925. }
  22926. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22927. int minutes,
  22928. int seconds,
  22929. int frames)
  22930. {
  22931. uint8 d[12];
  22932. d[0] = 0xf0;
  22933. d[1] = 0x7f;
  22934. d[2] = 0x00;
  22935. d[3] = 0x06;
  22936. d[4] = 0x44;
  22937. d[5] = 0x06;
  22938. d[6] = 0x01;
  22939. d[7] = (uint8) hours;
  22940. d[8] = (uint8) minutes;
  22941. d[9] = (uint8) seconds;
  22942. d[10] = (uint8) frames;
  22943. d[11] = 0xf7;
  22944. return MidiMessage (d, 12, 0.0);
  22945. }
  22946. const String MidiMessage::getMidiNoteName (int note,
  22947. bool useSharps,
  22948. bool includeOctaveNumber,
  22949. int octaveNumForMiddleC) throw()
  22950. {
  22951. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22952. "F", "F#", "G", "G#", "A",
  22953. "A#", "B" };
  22954. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22955. "F", "Gb", "G", "Ab", "A",
  22956. "Bb", "B" };
  22957. if (((unsigned int) note) < 128)
  22958. {
  22959. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22960. : flatNoteNames [note % 12]);
  22961. if (includeOctaveNumber)
  22962. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22963. else
  22964. return s;
  22965. }
  22966. return String::empty;
  22967. }
  22968. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22969. {
  22970. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22971. return 440.0 * pow (2.0, noteNumber / 12.0);
  22972. }
  22973. const String MidiMessage::getGMInstrumentName (int n) throw()
  22974. {
  22975. const char *names[] =
  22976. {
  22977. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22978. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22979. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22980. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22981. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22982. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22983. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22984. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22985. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22986. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22987. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22988. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22989. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22990. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22991. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22992. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22993. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22994. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22995. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22996. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22997. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22998. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22999. "Applause", "Gunshot"
  23000. };
  23001. return (((unsigned int) n) < 128) ? names[n]
  23002. : (const char*)0;
  23003. }
  23004. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  23005. {
  23006. const char* names[] =
  23007. {
  23008. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  23009. "Bass", "Strings", "Ensemble", "Brass",
  23010. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  23011. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  23012. };
  23013. return (((unsigned int) n) <= 15) ? names[n]
  23014. : (const char*)0;
  23015. }
  23016. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  23017. {
  23018. const char* names[] =
  23019. {
  23020. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  23021. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  23022. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  23023. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  23024. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  23025. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  23026. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  23027. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  23028. "Mute Triangle", "Open Triangle"
  23029. };
  23030. return (n >= 35 && n <= 81) ? names [n - 35]
  23031. : (const char*)0;
  23032. }
  23033. const String MidiMessage::getControllerName (int n) throw()
  23034. {
  23035. const char* names[] =
  23036. {
  23037. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  23038. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  23039. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  23040. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  23041. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  23042. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  23043. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  23044. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  23045. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  23046. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  23047. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  23048. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  23049. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  23050. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  23051. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  23052. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  23053. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  23054. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  23055. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  23056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  23057. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  23058. "Poly Operation"
  23059. };
  23060. return (((unsigned int) n) < 128) ? names[n]
  23061. : (const char*)0;
  23062. }
  23063. END_JUCE_NAMESPACE
  23064. /*** End of inlined file: juce_MidiMessage.cpp ***/
  23065. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  23066. BEGIN_JUCE_NAMESPACE
  23067. MidiMessageCollector::MidiMessageCollector()
  23068. : lastCallbackTime (0),
  23069. sampleRate (44100.0001)
  23070. {
  23071. }
  23072. MidiMessageCollector::~MidiMessageCollector()
  23073. {
  23074. }
  23075. void MidiMessageCollector::reset (const double sampleRate_)
  23076. {
  23077. jassert (sampleRate_ > 0);
  23078. const ScopedLock sl (midiCallbackLock);
  23079. sampleRate = sampleRate_;
  23080. incomingMessages.clear();
  23081. lastCallbackTime = Time::getMillisecondCounterHiRes();
  23082. }
  23083. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  23084. {
  23085. // you need to call reset() to set the correct sample rate before using this object
  23086. jassert (sampleRate != 44100.0001);
  23087. // the messages that come in here need to be time-stamped correctly - see MidiInput
  23088. // for details of what the number should be.
  23089. jassert (message.getTimeStamp() != 0);
  23090. const ScopedLock sl (midiCallbackLock);
  23091. const int sampleNumber
  23092. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  23093. incomingMessages.addEvent (message, sampleNumber);
  23094. // if the messages don't get used for over a second, we'd better
  23095. // get rid of any old ones to avoid the queue getting too big
  23096. if (sampleNumber > sampleRate)
  23097. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  23098. }
  23099. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  23100. const int numSamples)
  23101. {
  23102. // you need to call reset() to set the correct sample rate before using this object
  23103. jassert (sampleRate != 44100.0001);
  23104. const double timeNow = Time::getMillisecondCounterHiRes();
  23105. const double msElapsed = timeNow - lastCallbackTime;
  23106. const ScopedLock sl (midiCallbackLock);
  23107. lastCallbackTime = timeNow;
  23108. if (! incomingMessages.isEmpty())
  23109. {
  23110. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  23111. int startSample = 0;
  23112. int scale = 1 << 16;
  23113. const uint8* midiData;
  23114. int numBytes, samplePosition;
  23115. MidiBuffer::Iterator iter (incomingMessages);
  23116. if (numSourceSamples > numSamples)
  23117. {
  23118. // if our list of events is longer than the buffer we're being
  23119. // asked for, scale them down to squeeze them all in..
  23120. const int maxBlockLengthToUse = numSamples << 5;
  23121. if (numSourceSamples > maxBlockLengthToUse)
  23122. {
  23123. startSample = numSourceSamples - maxBlockLengthToUse;
  23124. numSourceSamples = maxBlockLengthToUse;
  23125. iter.setNextSamplePosition (startSample);
  23126. }
  23127. scale = (numSamples << 10) / numSourceSamples;
  23128. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23129. {
  23130. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  23131. destBuffer.addEvent (midiData, numBytes,
  23132. jlimit (0, numSamples - 1, samplePosition));
  23133. }
  23134. }
  23135. else
  23136. {
  23137. // if our event list is shorter than the number we need, put them
  23138. // towards the end of the buffer
  23139. startSample = numSamples - numSourceSamples;
  23140. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23141. {
  23142. destBuffer.addEvent (midiData, numBytes,
  23143. jlimit (0, numSamples - 1, samplePosition + startSample));
  23144. }
  23145. }
  23146. incomingMessages.clear();
  23147. }
  23148. }
  23149. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  23150. {
  23151. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  23152. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23153. addMessageToQueue (m);
  23154. }
  23155. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  23156. {
  23157. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  23158. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23159. addMessageToQueue (m);
  23160. }
  23161. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  23162. {
  23163. addMessageToQueue (message);
  23164. }
  23165. END_JUCE_NAMESPACE
  23166. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  23167. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  23168. BEGIN_JUCE_NAMESPACE
  23169. MidiMessageSequence::MidiMessageSequence()
  23170. {
  23171. }
  23172. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  23173. {
  23174. list.ensureStorageAllocated (other.list.size());
  23175. for (int i = 0; i < other.list.size(); ++i)
  23176. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  23177. }
  23178. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  23179. {
  23180. MidiMessageSequence otherCopy (other);
  23181. swapWith (otherCopy);
  23182. return *this;
  23183. }
  23184. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  23185. {
  23186. list.swapWithArray (other.list);
  23187. }
  23188. MidiMessageSequence::~MidiMessageSequence()
  23189. {
  23190. }
  23191. void MidiMessageSequence::clear()
  23192. {
  23193. list.clear();
  23194. }
  23195. int MidiMessageSequence::getNumEvents() const
  23196. {
  23197. return list.size();
  23198. }
  23199. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  23200. {
  23201. return list [index];
  23202. }
  23203. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  23204. {
  23205. const MidiEventHolder* const meh = list [index];
  23206. if (meh != 0 && meh->noteOffObject != 0)
  23207. return meh->noteOffObject->message.getTimeStamp();
  23208. else
  23209. return 0.0;
  23210. }
  23211. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  23212. {
  23213. const MidiEventHolder* const meh = list [index];
  23214. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  23215. }
  23216. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  23217. {
  23218. return list.indexOf (event);
  23219. }
  23220. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  23221. {
  23222. const int numEvents = list.size();
  23223. int i;
  23224. for (i = 0; i < numEvents; ++i)
  23225. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23226. break;
  23227. return i;
  23228. }
  23229. double MidiMessageSequence::getStartTime() const
  23230. {
  23231. if (list.size() > 0)
  23232. return list.getUnchecked(0)->message.getTimeStamp();
  23233. else
  23234. return 0;
  23235. }
  23236. double MidiMessageSequence::getEndTime() const
  23237. {
  23238. if (list.size() > 0)
  23239. return list.getLast()->message.getTimeStamp();
  23240. else
  23241. return 0;
  23242. }
  23243. double MidiMessageSequence::getEventTime (const int index) const
  23244. {
  23245. if (((unsigned int) index) < (unsigned int) list.size())
  23246. return list.getUnchecked (index)->message.getTimeStamp();
  23247. return 0.0;
  23248. }
  23249. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23250. double timeAdjustment)
  23251. {
  23252. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23253. timeAdjustment += newMessage.getTimeStamp();
  23254. newOne->message.setTimeStamp (timeAdjustment);
  23255. int i;
  23256. for (i = list.size(); --i >= 0;)
  23257. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23258. break;
  23259. list.insert (i + 1, newOne);
  23260. }
  23261. void MidiMessageSequence::deleteEvent (const int index,
  23262. const bool deleteMatchingNoteUp)
  23263. {
  23264. if (((unsigned int) index) < (unsigned int) list.size())
  23265. {
  23266. if (deleteMatchingNoteUp)
  23267. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23268. list.remove (index);
  23269. }
  23270. }
  23271. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23272. double timeAdjustment,
  23273. double firstAllowableTime,
  23274. double endOfAllowableDestTimes)
  23275. {
  23276. firstAllowableTime -= timeAdjustment;
  23277. endOfAllowableDestTimes -= timeAdjustment;
  23278. for (int i = 0; i < other.list.size(); ++i)
  23279. {
  23280. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23281. const double t = m.getTimeStamp();
  23282. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23283. {
  23284. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23285. newOne->message.setTimeStamp (timeAdjustment + t);
  23286. list.add (newOne);
  23287. }
  23288. }
  23289. sort();
  23290. }
  23291. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23292. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23293. {
  23294. const double diff = first->message.getTimeStamp()
  23295. - second->message.getTimeStamp();
  23296. return (diff > 0) - (diff < 0);
  23297. }
  23298. void MidiMessageSequence::sort()
  23299. {
  23300. list.sort (*this, true);
  23301. }
  23302. void MidiMessageSequence::updateMatchedPairs()
  23303. {
  23304. for (int i = 0; i < list.size(); ++i)
  23305. {
  23306. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23307. if (m1.isNoteOn())
  23308. {
  23309. list.getUnchecked(i)->noteOffObject = 0;
  23310. const int note = m1.getNoteNumber();
  23311. const int chan = m1.getChannel();
  23312. const int len = list.size();
  23313. for (int j = i + 1; j < len; ++j)
  23314. {
  23315. const MidiMessage& m = list.getUnchecked(j)->message;
  23316. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23317. {
  23318. if (m.isNoteOff())
  23319. {
  23320. list.getUnchecked(i)->noteOffObject = list[j];
  23321. break;
  23322. }
  23323. else if (m.isNoteOn())
  23324. {
  23325. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23326. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23327. list.getUnchecked(i)->noteOffObject = list[j];
  23328. break;
  23329. }
  23330. }
  23331. }
  23332. }
  23333. }
  23334. }
  23335. void MidiMessageSequence::addTimeToMessages (const double delta)
  23336. {
  23337. for (int i = list.size(); --i >= 0;)
  23338. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23339. + delta);
  23340. }
  23341. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23342. MidiMessageSequence& destSequence,
  23343. const bool alsoIncludeMetaEvents) const
  23344. {
  23345. for (int i = 0; i < list.size(); ++i)
  23346. {
  23347. const MidiMessage& mm = list.getUnchecked(i)->message;
  23348. if (mm.isForChannel (channelNumberToExtract)
  23349. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23350. {
  23351. destSequence.addEvent (mm);
  23352. }
  23353. }
  23354. }
  23355. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23356. {
  23357. for (int i = 0; i < list.size(); ++i)
  23358. {
  23359. const MidiMessage& mm = list.getUnchecked(i)->message;
  23360. if (mm.isSysEx())
  23361. destSequence.addEvent (mm);
  23362. }
  23363. }
  23364. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23365. {
  23366. for (int i = list.size(); --i >= 0;)
  23367. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23368. list.remove(i);
  23369. }
  23370. void MidiMessageSequence::deleteSysExMessages()
  23371. {
  23372. for (int i = list.size(); --i >= 0;)
  23373. if (list.getUnchecked(i)->message.isSysEx())
  23374. list.remove(i);
  23375. }
  23376. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23377. const double time,
  23378. OwnedArray<MidiMessage>& dest)
  23379. {
  23380. bool doneProg = false;
  23381. bool donePitchWheel = false;
  23382. Array <int> doneControllers;
  23383. doneControllers.ensureStorageAllocated (32);
  23384. for (int i = list.size(); --i >= 0;)
  23385. {
  23386. const MidiMessage& mm = list.getUnchecked(i)->message;
  23387. if (mm.isForChannel (channelNumber)
  23388. && mm.getTimeStamp() <= time)
  23389. {
  23390. if (mm.isProgramChange())
  23391. {
  23392. if (! doneProg)
  23393. {
  23394. dest.add (new MidiMessage (mm, 0.0));
  23395. doneProg = true;
  23396. }
  23397. }
  23398. else if (mm.isController())
  23399. {
  23400. if (! doneControllers.contains (mm.getControllerNumber()))
  23401. {
  23402. dest.add (new MidiMessage (mm, 0.0));
  23403. doneControllers.add (mm.getControllerNumber());
  23404. }
  23405. }
  23406. else if (mm.isPitchWheel())
  23407. {
  23408. if (! donePitchWheel)
  23409. {
  23410. dest.add (new MidiMessage (mm, 0.0));
  23411. donePitchWheel = true;
  23412. }
  23413. }
  23414. }
  23415. }
  23416. }
  23417. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23418. : message (message_),
  23419. noteOffObject (0)
  23420. {
  23421. }
  23422. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23423. {
  23424. }
  23425. END_JUCE_NAMESPACE
  23426. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23427. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23428. BEGIN_JUCE_NAMESPACE
  23429. AudioPluginFormat::AudioPluginFormat() throw()
  23430. {
  23431. }
  23432. AudioPluginFormat::~AudioPluginFormat()
  23433. {
  23434. }
  23435. END_JUCE_NAMESPACE
  23436. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23437. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23438. BEGIN_JUCE_NAMESPACE
  23439. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23440. {
  23441. }
  23442. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23443. {
  23444. clearSingletonInstance();
  23445. }
  23446. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23447. void AudioPluginFormatManager::addDefaultFormats()
  23448. {
  23449. #ifdef JUCE_DEBUG
  23450. // you should only call this method once!
  23451. for (int i = formats.size(); --i >= 0;)
  23452. {
  23453. #if JUCE_PLUGINHOST_VST
  23454. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23455. #endif
  23456. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23457. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23458. #endif
  23459. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23460. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23461. #endif
  23462. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23463. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23464. #endif
  23465. }
  23466. #endif
  23467. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23468. formats.add (new AudioUnitPluginFormat());
  23469. #endif
  23470. #if JUCE_PLUGINHOST_VST
  23471. formats.add (new VSTPluginFormat());
  23472. #endif
  23473. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23474. formats.add (new DirectXPluginFormat());
  23475. #endif
  23476. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23477. formats.add (new LADSPAPluginFormat());
  23478. #endif
  23479. }
  23480. int AudioPluginFormatManager::getNumFormats() throw()
  23481. {
  23482. return formats.size();
  23483. }
  23484. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23485. {
  23486. return formats [index];
  23487. }
  23488. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23489. {
  23490. formats.add (format);
  23491. }
  23492. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23493. String& errorMessage) const
  23494. {
  23495. AudioPluginInstance* result = 0;
  23496. for (int i = 0; i < formats.size(); ++i)
  23497. {
  23498. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23499. if (result != 0)
  23500. break;
  23501. }
  23502. if (result == 0)
  23503. {
  23504. if (! doesPluginStillExist (description))
  23505. errorMessage = TRANS ("This plug-in file no longer exists");
  23506. else
  23507. errorMessage = TRANS ("This plug-in failed to load correctly");
  23508. }
  23509. return result;
  23510. }
  23511. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23512. {
  23513. for (int i = 0; i < formats.size(); ++i)
  23514. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23515. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23516. return false;
  23517. }
  23518. END_JUCE_NAMESPACE
  23519. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23520. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23521. #define JUCE_PLUGIN_HOST 1
  23522. BEGIN_JUCE_NAMESPACE
  23523. AudioPluginInstance::AudioPluginInstance()
  23524. {
  23525. }
  23526. AudioPluginInstance::~AudioPluginInstance()
  23527. {
  23528. }
  23529. END_JUCE_NAMESPACE
  23530. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23531. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23532. BEGIN_JUCE_NAMESPACE
  23533. KnownPluginList::KnownPluginList()
  23534. {
  23535. }
  23536. KnownPluginList::~KnownPluginList()
  23537. {
  23538. }
  23539. void KnownPluginList::clear()
  23540. {
  23541. if (types.size() > 0)
  23542. {
  23543. types.clear();
  23544. sendChangeMessage (this);
  23545. }
  23546. }
  23547. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23548. {
  23549. for (int i = 0; i < types.size(); ++i)
  23550. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23551. return types.getUnchecked(i);
  23552. return 0;
  23553. }
  23554. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23555. {
  23556. for (int i = 0; i < types.size(); ++i)
  23557. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23558. return types.getUnchecked(i);
  23559. return 0;
  23560. }
  23561. bool KnownPluginList::addType (const PluginDescription& type)
  23562. {
  23563. for (int i = types.size(); --i >= 0;)
  23564. {
  23565. if (types.getUnchecked(i)->isDuplicateOf (type))
  23566. {
  23567. // strange - found a duplicate plugin with different info..
  23568. jassert (types.getUnchecked(i)->name == type.name);
  23569. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23570. *types.getUnchecked(i) = type;
  23571. return false;
  23572. }
  23573. }
  23574. types.add (new PluginDescription (type));
  23575. sendChangeMessage (this);
  23576. return true;
  23577. }
  23578. void KnownPluginList::removeType (const int index) throw()
  23579. {
  23580. types.remove (index);
  23581. sendChangeMessage (this);
  23582. }
  23583. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23584. {
  23585. if (fileOrIdentifier.startsWithChar (T('/'))
  23586. || fileOrIdentifier[1] == T(':'))
  23587. {
  23588. return File (fileOrIdentifier).getLastModificationTime();
  23589. }
  23590. return Time (0);
  23591. }
  23592. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23593. {
  23594. return t1 != t2 || t1 == Time (0);
  23595. }
  23596. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23597. {
  23598. if (getTypeForFile (fileOrIdentifier) == 0)
  23599. return false;
  23600. for (int i = types.size(); --i >= 0;)
  23601. {
  23602. const PluginDescription* const d = types.getUnchecked(i);
  23603. if (d->fileOrIdentifier == fileOrIdentifier
  23604. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23605. {
  23606. return false;
  23607. }
  23608. }
  23609. return true;
  23610. }
  23611. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23612. const bool dontRescanIfAlreadyInList,
  23613. OwnedArray <PluginDescription>& typesFound,
  23614. AudioPluginFormat& format)
  23615. {
  23616. bool addedOne = false;
  23617. if (dontRescanIfAlreadyInList
  23618. && getTypeForFile (fileOrIdentifier) != 0)
  23619. {
  23620. bool needsRescanning = false;
  23621. for (int i = types.size(); --i >= 0;)
  23622. {
  23623. const PluginDescription* const d = types.getUnchecked(i);
  23624. if (d->fileOrIdentifier == fileOrIdentifier)
  23625. {
  23626. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23627. needsRescanning = true;
  23628. else
  23629. typesFound.add (new PluginDescription (*d));
  23630. }
  23631. }
  23632. if (! needsRescanning)
  23633. return false;
  23634. }
  23635. OwnedArray <PluginDescription> found;
  23636. format.findAllTypesForFile (found, fileOrIdentifier);
  23637. for (int i = 0; i < found.size(); ++i)
  23638. {
  23639. PluginDescription* const desc = found.getUnchecked(i);
  23640. jassert (desc != 0);
  23641. if (addType (*desc))
  23642. addedOne = true;
  23643. typesFound.add (new PluginDescription (*desc));
  23644. }
  23645. return addedOne;
  23646. }
  23647. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23648. OwnedArray <PluginDescription>& typesFound)
  23649. {
  23650. for (int i = 0; i < files.size(); ++i)
  23651. {
  23652. bool loaded = false;
  23653. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23654. {
  23655. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23656. if (scanAndAddFile (files[i], true, typesFound, *format))
  23657. loaded = true;
  23658. }
  23659. if (! loaded)
  23660. {
  23661. const File f (files[i]);
  23662. if (f.isDirectory())
  23663. {
  23664. StringArray s;
  23665. {
  23666. Array<File> subFiles;
  23667. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23668. for (int j = 0; j < subFiles.size(); ++j)
  23669. s.add (subFiles.getReference(j).getFullPathName());
  23670. }
  23671. scanAndAddDragAndDroppedFiles (s, typesFound);
  23672. }
  23673. }
  23674. }
  23675. }
  23676. class PluginSorter
  23677. {
  23678. public:
  23679. KnownPluginList::SortMethod method;
  23680. PluginSorter() throw() {}
  23681. int compareElements (const PluginDescription* const first,
  23682. const PluginDescription* const second) const throw()
  23683. {
  23684. int diff = 0;
  23685. if (method == KnownPluginList::sortByCategory)
  23686. diff = first->category.compareLexicographically (second->category);
  23687. else if (method == KnownPluginList::sortByManufacturer)
  23688. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23689. else if (method == KnownPluginList::sortByFileSystemLocation)
  23690. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23691. .upToLastOccurrenceOf (T("/"), false, false)
  23692. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23693. .upToLastOccurrenceOf (T("/"), false, false));
  23694. if (diff == 0)
  23695. diff = first->name.compareLexicographically (second->name);
  23696. return diff;
  23697. }
  23698. };
  23699. void KnownPluginList::sort (const SortMethod method)
  23700. {
  23701. if (method != defaultOrder)
  23702. {
  23703. PluginSorter sorter;
  23704. sorter.method = method;
  23705. types.sort (sorter, true);
  23706. sendChangeMessage (this);
  23707. }
  23708. }
  23709. XmlElement* KnownPluginList::createXml() const
  23710. {
  23711. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23712. for (int i = 0; i < types.size(); ++i)
  23713. e->addChildElement (types.getUnchecked(i)->createXml());
  23714. return e;
  23715. }
  23716. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23717. {
  23718. clear();
  23719. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23720. {
  23721. forEachXmlChildElement (xml, e)
  23722. {
  23723. PluginDescription info;
  23724. if (info.loadFromXml (*e))
  23725. addType (info);
  23726. }
  23727. }
  23728. }
  23729. const int menuIdBase = 0x324503f4;
  23730. // This is used to turn a bunch of paths into a nested menu structure.
  23731. struct PluginFilesystemTree
  23732. {
  23733. private:
  23734. String folder;
  23735. OwnedArray <PluginFilesystemTree> subFolders;
  23736. Array <PluginDescription*> plugins;
  23737. void addPlugin (PluginDescription* const pd, const String& path)
  23738. {
  23739. if (path.isEmpty())
  23740. {
  23741. plugins.add (pd);
  23742. }
  23743. else
  23744. {
  23745. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23746. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23747. for (int i = subFolders.size(); --i >= 0;)
  23748. {
  23749. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23750. {
  23751. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23752. return;
  23753. }
  23754. }
  23755. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23756. newFolder->folder = firstSubFolder;
  23757. subFolders.add (newFolder);
  23758. newFolder->addPlugin (pd, remainingPath);
  23759. }
  23760. }
  23761. // removes any deeply nested folders that don't contain any actual plugins
  23762. void optimise()
  23763. {
  23764. for (int i = subFolders.size(); --i >= 0;)
  23765. {
  23766. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23767. sub->optimise();
  23768. if (sub->plugins.size() == 0)
  23769. {
  23770. for (int j = 0; j < sub->subFolders.size(); ++j)
  23771. subFolders.add (sub->subFolders.getUnchecked(j));
  23772. sub->subFolders.clear (false);
  23773. subFolders.remove (i);
  23774. }
  23775. }
  23776. }
  23777. public:
  23778. void buildTree (const Array <PluginDescription*>& allPlugins)
  23779. {
  23780. for (int i = 0; i < allPlugins.size(); ++i)
  23781. {
  23782. String path (allPlugins.getUnchecked(i)
  23783. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23784. .upToLastOccurrenceOf (T("/"), false, false));
  23785. if (path.substring (1, 2) == T(":"))
  23786. path = path.substring (2);
  23787. addPlugin (allPlugins.getUnchecked(i), path);
  23788. }
  23789. optimise();
  23790. }
  23791. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23792. {
  23793. int i;
  23794. for (i = 0; i < subFolders.size(); ++i)
  23795. {
  23796. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23797. PopupMenu subMenu;
  23798. sub->addToMenu (subMenu, allPlugins);
  23799. #if JUCE_MAC
  23800. // avoid the special AU formatting nonsense on Mac..
  23801. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23802. #else
  23803. m.addSubMenu (sub->folder, subMenu);
  23804. #endif
  23805. }
  23806. for (i = 0; i < plugins.size(); ++i)
  23807. {
  23808. PluginDescription* const plugin = plugins.getUnchecked(i);
  23809. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23810. plugin->name, true, false);
  23811. }
  23812. }
  23813. };
  23814. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23815. {
  23816. Array <PluginDescription*> sorted;
  23817. {
  23818. PluginSorter sorter;
  23819. sorter.method = sortMethod;
  23820. for (int i = 0; i < types.size(); ++i)
  23821. sorted.addSorted (sorter, types.getUnchecked(i));
  23822. }
  23823. if (sortMethod == sortByCategory
  23824. || sortMethod == sortByManufacturer)
  23825. {
  23826. String lastSubMenuName;
  23827. PopupMenu sub;
  23828. for (int i = 0; i < sorted.size(); ++i)
  23829. {
  23830. const PluginDescription* const pd = sorted.getUnchecked(i);
  23831. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23832. : pd->manufacturerName);
  23833. if (! thisSubMenuName.containsNonWhitespaceChars())
  23834. thisSubMenuName = T("Other");
  23835. if (thisSubMenuName != lastSubMenuName)
  23836. {
  23837. if (sub.getNumItems() > 0)
  23838. {
  23839. menu.addSubMenu (lastSubMenuName, sub);
  23840. sub.clear();
  23841. }
  23842. lastSubMenuName = thisSubMenuName;
  23843. }
  23844. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23845. }
  23846. if (sub.getNumItems() > 0)
  23847. menu.addSubMenu (lastSubMenuName, sub);
  23848. }
  23849. else if (sortMethod == sortByFileSystemLocation)
  23850. {
  23851. PluginFilesystemTree root;
  23852. root.buildTree (sorted);
  23853. root.addToMenu (menu, types);
  23854. }
  23855. else
  23856. {
  23857. for (int i = 0; i < sorted.size(); ++i)
  23858. {
  23859. const PluginDescription* const pd = sorted.getUnchecked(i);
  23860. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23861. }
  23862. }
  23863. }
  23864. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23865. {
  23866. const int i = menuResultCode - menuIdBase;
  23867. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23868. }
  23869. END_JUCE_NAMESPACE
  23870. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23871. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23872. BEGIN_JUCE_NAMESPACE
  23873. PluginDescription::PluginDescription() throw()
  23874. : uid (0),
  23875. isInstrument (false),
  23876. numInputChannels (0),
  23877. numOutputChannels (0)
  23878. {
  23879. }
  23880. PluginDescription::~PluginDescription() throw()
  23881. {
  23882. }
  23883. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23884. : name (other.name),
  23885. pluginFormatName (other.pluginFormatName),
  23886. category (other.category),
  23887. manufacturerName (other.manufacturerName),
  23888. version (other.version),
  23889. fileOrIdentifier (other.fileOrIdentifier),
  23890. lastFileModTime (other.lastFileModTime),
  23891. uid (other.uid),
  23892. isInstrument (other.isInstrument),
  23893. numInputChannels (other.numInputChannels),
  23894. numOutputChannels (other.numOutputChannels)
  23895. {
  23896. }
  23897. const PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23898. {
  23899. name = other.name;
  23900. pluginFormatName = other.pluginFormatName;
  23901. category = other.category;
  23902. manufacturerName = other.manufacturerName;
  23903. version = other.version;
  23904. fileOrIdentifier = other.fileOrIdentifier;
  23905. uid = other.uid;
  23906. isInstrument = other.isInstrument;
  23907. lastFileModTime = other.lastFileModTime;
  23908. numInputChannels = other.numInputChannels;
  23909. numOutputChannels = other.numOutputChannels;
  23910. return *this;
  23911. }
  23912. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23913. {
  23914. return fileOrIdentifier == other.fileOrIdentifier
  23915. && uid == other.uid;
  23916. }
  23917. const String PluginDescription::createIdentifierString() const throw()
  23918. {
  23919. return pluginFormatName
  23920. + T("-") + name
  23921. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23922. + T("-") + String::toHexString (uid);
  23923. }
  23924. XmlElement* PluginDescription::createXml() const
  23925. {
  23926. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23927. e->setAttribute (T("name"), name);
  23928. e->setAttribute (T("format"), pluginFormatName);
  23929. e->setAttribute (T("category"), category);
  23930. e->setAttribute (T("manufacturer"), manufacturerName);
  23931. e->setAttribute (T("version"), version);
  23932. e->setAttribute (T("file"), fileOrIdentifier);
  23933. e->setAttribute (T("uid"), String::toHexString (uid));
  23934. e->setAttribute (T("isInstrument"), isInstrument);
  23935. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23936. e->setAttribute (T("numInputs"), numInputChannels);
  23937. e->setAttribute (T("numOutputs"), numOutputChannels);
  23938. return e;
  23939. }
  23940. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23941. {
  23942. if (xml.hasTagName (T("PLUGIN")))
  23943. {
  23944. name = xml.getStringAttribute (T("name"));
  23945. pluginFormatName = xml.getStringAttribute (T("format"));
  23946. category = xml.getStringAttribute (T("category"));
  23947. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23948. version = xml.getStringAttribute (T("version"));
  23949. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23950. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23951. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23952. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23953. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23954. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23955. return true;
  23956. }
  23957. return false;
  23958. }
  23959. END_JUCE_NAMESPACE
  23960. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23961. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23962. BEGIN_JUCE_NAMESPACE
  23963. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23964. AudioPluginFormat& formatToLookFor,
  23965. FileSearchPath directoriesToSearch,
  23966. const bool recursive,
  23967. const File& deadMansPedalFile_)
  23968. : list (listToAddTo),
  23969. format (formatToLookFor),
  23970. deadMansPedalFile (deadMansPedalFile_),
  23971. nextIndex (0),
  23972. progress (0)
  23973. {
  23974. directoriesToSearch.removeRedundantPaths();
  23975. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23976. // If any plugins have crashed recently when being loaded, move them to the
  23977. // end of the list to give the others a chance to load correctly..
  23978. const StringArray crashedPlugins (getDeadMansPedalFile());
  23979. for (int i = 0; i < crashedPlugins.size(); ++i)
  23980. {
  23981. const String f = crashedPlugins[i];
  23982. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23983. if (f == filesOrIdentifiersToScan[j])
  23984. filesOrIdentifiersToScan.move (j, -1);
  23985. }
  23986. }
  23987. PluginDirectoryScanner::~PluginDirectoryScanner()
  23988. {
  23989. }
  23990. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23991. {
  23992. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23993. }
  23994. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23995. {
  23996. String file (filesOrIdentifiersToScan [nextIndex]);
  23997. if (file.isNotEmpty())
  23998. {
  23999. if (! list.isListingUpToDate (file))
  24000. {
  24001. OwnedArray <PluginDescription> typesFound;
  24002. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  24003. StringArray crashedPlugins (getDeadMansPedalFile());
  24004. crashedPlugins.removeString (file);
  24005. crashedPlugins.add (file);
  24006. setDeadMansPedalFile (crashedPlugins);
  24007. list.scanAndAddFile (file,
  24008. dontRescanIfAlreadyInList,
  24009. typesFound,
  24010. format);
  24011. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  24012. crashedPlugins.removeString (file);
  24013. setDeadMansPedalFile (crashedPlugins);
  24014. if (typesFound.size() == 0)
  24015. failedFiles.add (file);
  24016. }
  24017. ++nextIndex;
  24018. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  24019. }
  24020. return nextIndex < filesOrIdentifiersToScan.size();
  24021. }
  24022. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  24023. {
  24024. StringArray lines;
  24025. if (deadMansPedalFile != File::nonexistent)
  24026. {
  24027. lines.addLines (deadMansPedalFile.loadFileAsString());
  24028. lines.removeEmptyStrings();
  24029. }
  24030. return lines;
  24031. }
  24032. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  24033. {
  24034. if (deadMansPedalFile != File::nonexistent)
  24035. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  24036. }
  24037. END_JUCE_NAMESPACE
  24038. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  24039. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  24040. BEGIN_JUCE_NAMESPACE
  24041. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  24042. const File& deadMansPedalFile_,
  24043. PropertiesFile* const propertiesToUse_)
  24044. : list (listToEdit),
  24045. deadMansPedalFile (deadMansPedalFile_),
  24046. propertiesToUse (propertiesToUse_)
  24047. {
  24048. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  24049. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  24050. optionsButton->addButtonListener (this);
  24051. optionsButton->setTriggeredOnMouseDown (true);
  24052. setSize (400, 600);
  24053. list.addChangeListener (this);
  24054. }
  24055. PluginListComponent::~PluginListComponent()
  24056. {
  24057. list.removeChangeListener (this);
  24058. deleteAllChildren();
  24059. }
  24060. void PluginListComponent::resized()
  24061. {
  24062. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  24063. optionsButton->changeWidthToFitText (24);
  24064. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  24065. }
  24066. void PluginListComponent::changeListenerCallback (void*)
  24067. {
  24068. listBox->updateContent();
  24069. listBox->repaint();
  24070. }
  24071. int PluginListComponent::getNumRows()
  24072. {
  24073. return list.getNumTypes();
  24074. }
  24075. void PluginListComponent::paintListBoxItem (int row,
  24076. Graphics& g,
  24077. int width, int height,
  24078. bool rowIsSelected)
  24079. {
  24080. if (rowIsSelected)
  24081. g.fillAll (findColour (TextEditor::highlightColourId));
  24082. const PluginDescription* const pd = list.getType (row);
  24083. if (pd != 0)
  24084. {
  24085. GlyphArrangement ga;
  24086. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  24087. g.setColour (Colours::black);
  24088. ga.draw (g);
  24089. float x, y, r, b;
  24090. ga.getBoundingBox (0, -1, x, y, r, b, false);
  24091. String desc;
  24092. desc << pd->pluginFormatName
  24093. << (pd->isInstrument ? " instrument" : " effect")
  24094. << " - "
  24095. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  24096. << " / "
  24097. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  24098. if (pd->manufacturerName.isNotEmpty())
  24099. desc << " - " << pd->manufacturerName;
  24100. if (pd->version.isNotEmpty())
  24101. desc << " - " << pd->version;
  24102. if (pd->category.isNotEmpty())
  24103. desc << " - category: '" << pd->category << '\'';
  24104. g.setColour (Colours::grey);
  24105. ga.clear();
  24106. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  24107. ga.draw (g);
  24108. }
  24109. }
  24110. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  24111. {
  24112. list.removeType (lastRowSelected);
  24113. }
  24114. void PluginListComponent::buttonClicked (Button* b)
  24115. {
  24116. if (optionsButton == b)
  24117. {
  24118. PopupMenu menu;
  24119. menu.addItem (1, TRANS("Clear list"));
  24120. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  24121. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  24122. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  24123. menu.addSeparator();
  24124. menu.addItem (2, TRANS("Sort alphabetically"));
  24125. menu.addItem (3, TRANS("Sort by category"));
  24126. menu.addItem (4, TRANS("Sort by manufacturer"));
  24127. menu.addSeparator();
  24128. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  24129. {
  24130. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  24131. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  24132. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  24133. }
  24134. const int r = menu.showAt (optionsButton);
  24135. if (r == 1)
  24136. {
  24137. list.clear();
  24138. }
  24139. else if (r == 2)
  24140. {
  24141. list.sort (KnownPluginList::sortAlphabetically);
  24142. }
  24143. else if (r == 3)
  24144. {
  24145. list.sort (KnownPluginList::sortByCategory);
  24146. }
  24147. else if (r == 4)
  24148. {
  24149. list.sort (KnownPluginList::sortByManufacturer);
  24150. }
  24151. else if (r == 5)
  24152. {
  24153. const SparseSet <int> selected (listBox->getSelectedRows());
  24154. for (int i = list.getNumTypes(); --i >= 0;)
  24155. if (selected.contains (i))
  24156. list.removeType (i);
  24157. }
  24158. else if (r == 6)
  24159. {
  24160. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  24161. if (desc != 0)
  24162. {
  24163. if (File (desc->fileOrIdentifier).existsAsFile())
  24164. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  24165. }
  24166. }
  24167. else if (r == 7)
  24168. {
  24169. for (int i = list.getNumTypes(); --i >= 0;)
  24170. {
  24171. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  24172. {
  24173. list.removeType (i);
  24174. }
  24175. }
  24176. }
  24177. else if (r != 0)
  24178. {
  24179. typeToScan = r - 10;
  24180. startTimer (1);
  24181. }
  24182. }
  24183. }
  24184. void PluginListComponent::timerCallback()
  24185. {
  24186. stopTimer();
  24187. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  24188. }
  24189. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  24190. {
  24191. return true;
  24192. }
  24193. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  24194. {
  24195. OwnedArray <PluginDescription> typesFound;
  24196. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  24197. }
  24198. void PluginListComponent::scanFor (AudioPluginFormat* format)
  24199. {
  24200. if (format == 0)
  24201. return;
  24202. FileSearchPath path (format->getDefaultLocationsToSearch());
  24203. if (propertiesToUse != 0)
  24204. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24205. {
  24206. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  24207. FileSearchPathListComponent pathList;
  24208. pathList.setSize (500, 300);
  24209. pathList.setPath (path);
  24210. aw.addCustomComponent (&pathList);
  24211. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  24212. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24213. if (aw.runModalLoop() == 0)
  24214. return;
  24215. path = pathList.getPath();
  24216. }
  24217. if (propertiesToUse != 0)
  24218. {
  24219. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24220. propertiesToUse->saveIfNeeded();
  24221. }
  24222. double progress = 0.0;
  24223. AlertWindow aw (TRANS("Scanning for plugins..."),
  24224. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  24225. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24226. aw.addProgressBarComponent (progress);
  24227. aw.enterModalState();
  24228. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24229. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24230. for (;;)
  24231. {
  24232. aw.setMessage (TRANS("Testing:\n\n")
  24233. + scanner.getNextPluginFileThatWillBeScanned());
  24234. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24235. if (! scanner.scanNextFile (true))
  24236. break;
  24237. if (! aw.isCurrentlyModal())
  24238. break;
  24239. progress = scanner.getProgress();
  24240. }
  24241. if (scanner.getFailedFiles().size() > 0)
  24242. {
  24243. StringArray shortNames;
  24244. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24245. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24246. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24247. TRANS("Scan complete"),
  24248. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24249. + shortNames.joinIntoString (", "));
  24250. }
  24251. }
  24252. END_JUCE_NAMESPACE
  24253. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  24254. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24255. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24256. #include <AudioUnit/AudioUnit.h>
  24257. #include <AudioUnit/AUCocoaUIView.h>
  24258. #include <CoreAudioKit/AUGenericView.h>
  24259. #if JUCE_SUPPORT_CARBON
  24260. #include <AudioToolbox/AudioUnitUtilities.h>
  24261. #include <AudioUnit/AudioUnitCarbonView.h>
  24262. #endif
  24263. BEGIN_JUCE_NAMESPACE
  24264. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24265. #endif
  24266. #if JUCE_MAC
  24267. // Change this to disable logging of various activities
  24268. #ifndef AU_LOGGING
  24269. #define AU_LOGGING 1
  24270. #endif
  24271. #if AU_LOGGING
  24272. #define log(a) Logger::writeToLog(a);
  24273. #else
  24274. #define log(a)
  24275. #endif
  24276. static int insideCallback = 0;
  24277. static const String osTypeToString (OSType type) throw()
  24278. {
  24279. char s[4];
  24280. s[0] = (char) (((uint32) type) >> 24);
  24281. s[1] = (char) (((uint32) type) >> 16);
  24282. s[2] = (char) (((uint32) type) >> 8);
  24283. s[3] = (char) ((uint32) type);
  24284. return String (s, 4);
  24285. }
  24286. static OSType stringToOSType (const String& s1) throw()
  24287. {
  24288. const String s (s1 + " ");
  24289. return (((OSType) (unsigned char) s[0]) << 24)
  24290. | (((OSType) (unsigned char) s[1]) << 16)
  24291. | (((OSType) (unsigned char) s[2]) << 8)
  24292. | ((OSType) (unsigned char) s[3]);
  24293. }
  24294. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24295. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24296. {
  24297. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24298. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24299. String s (auIdentifierPrefix);
  24300. if (desc.componentType == kAudioUnitType_MusicDevice)
  24301. s << "Synths/";
  24302. else if (desc.componentType == kAudioUnitType_MusicEffect
  24303. || desc.componentType == kAudioUnitType_Effect)
  24304. s << "Effects/";
  24305. else if (desc.componentType == kAudioUnitType_Generator)
  24306. s << "Generators/";
  24307. else if (desc.componentType == kAudioUnitType_Panner)
  24308. s << "Panners/";
  24309. s << osTypeToString (desc.componentType)
  24310. << T(",")
  24311. << osTypeToString (desc.componentSubType)
  24312. << T(",")
  24313. << osTypeToString (desc.componentManufacturer);
  24314. return s;
  24315. }
  24316. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24317. {
  24318. Handle componentNameHandle = NewHandle (sizeof (void*));
  24319. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24320. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24321. {
  24322. ComponentDescription desc;
  24323. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24324. {
  24325. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24326. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24327. if (nameString != 0 && nameString[0] != 0)
  24328. {
  24329. const String all ((const char*) nameString + 1, nameString[0]);
  24330. DBG ("name: "+ all);
  24331. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24332. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24333. }
  24334. if (infoString != 0 && infoString[0] != 0)
  24335. {
  24336. const String all ((const char*) infoString + 1, infoString[0]);
  24337. DBG ("info: " + all);
  24338. }
  24339. if (name.isEmpty())
  24340. name = "<Unknown>";
  24341. }
  24342. DisposeHandle (componentNameHandle);
  24343. DisposeHandle (componentInfoHandle);
  24344. }
  24345. }
  24346. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24347. String& name, String& version, String& manufacturer)
  24348. {
  24349. zerostruct (desc);
  24350. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24351. {
  24352. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24353. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24354. StringArray tokens;
  24355. tokens.addTokens (s, T(","), 0);
  24356. tokens.trim();
  24357. tokens.removeEmptyStrings();
  24358. if (tokens.size() == 3)
  24359. {
  24360. desc.componentType = stringToOSType (tokens[0]);
  24361. desc.componentSubType = stringToOSType (tokens[1]);
  24362. desc.componentManufacturer = stringToOSType (tokens[2]);
  24363. ComponentRecord* comp = FindNextComponent (0, &desc);
  24364. if (comp != 0)
  24365. {
  24366. getAUDetails (comp, name, manufacturer);
  24367. return true;
  24368. }
  24369. }
  24370. }
  24371. return false;
  24372. }
  24373. class AudioUnitPluginWindowCarbon;
  24374. class AudioUnitPluginWindowCocoa;
  24375. class AudioUnitPluginInstance : public AudioPluginInstance
  24376. {
  24377. public:
  24378. ~AudioUnitPluginInstance();
  24379. // AudioPluginInstance methods:
  24380. void fillInPluginDescription (PluginDescription& desc) const
  24381. {
  24382. desc.name = pluginName;
  24383. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24384. desc.uid = ((int) componentDesc.componentType)
  24385. ^ ((int) componentDesc.componentSubType)
  24386. ^ ((int) componentDesc.componentManufacturer);
  24387. desc.lastFileModTime = 0;
  24388. desc.pluginFormatName = "AudioUnit";
  24389. desc.category = getCategory();
  24390. desc.manufacturerName = manufacturer;
  24391. desc.version = version;
  24392. desc.numInputChannels = getNumInputChannels();
  24393. desc.numOutputChannels = getNumOutputChannels();
  24394. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24395. }
  24396. const String getName() const { return pluginName; }
  24397. bool acceptsMidi() const { return wantsMidiMessages; }
  24398. bool producesMidi() const { return false; }
  24399. // AudioProcessor methods:
  24400. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24401. void releaseResources();
  24402. void processBlock (AudioSampleBuffer& buffer,
  24403. MidiBuffer& midiMessages);
  24404. AudioProcessorEditor* createEditor();
  24405. const String getInputChannelName (const int index) const;
  24406. bool isInputChannelStereoPair (int index) const;
  24407. const String getOutputChannelName (const int index) const;
  24408. bool isOutputChannelStereoPair (int index) const;
  24409. int getNumParameters();
  24410. float getParameter (int index);
  24411. void setParameter (int index, float newValue);
  24412. const String getParameterName (int index);
  24413. const String getParameterText (int index);
  24414. bool isParameterAutomatable (int index) const;
  24415. int getNumPrograms();
  24416. int getCurrentProgram();
  24417. void setCurrentProgram (int index);
  24418. const String getProgramName (int index);
  24419. void changeProgramName (int index, const String& newName);
  24420. void getStateInformation (MemoryBlock& destData);
  24421. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24422. void setStateInformation (const void* data, int sizeInBytes);
  24423. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24424. juce_UseDebuggingNewOperator
  24425. private:
  24426. friend class AudioUnitPluginWindowCarbon;
  24427. friend class AudioUnitPluginWindowCocoa;
  24428. friend class AudioUnitPluginFormat;
  24429. ComponentDescription componentDesc;
  24430. String pluginName, manufacturer, version;
  24431. String fileOrIdentifier;
  24432. CriticalSection lock;
  24433. bool initialised, wantsMidiMessages, wasPlaying;
  24434. HeapBlock <AudioBufferList> outputBufferList;
  24435. AudioTimeStamp timeStamp;
  24436. AudioSampleBuffer* currentBuffer;
  24437. AudioUnit audioUnit;
  24438. Array <int> parameterIds;
  24439. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24440. void initialise();
  24441. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24442. const AudioTimeStamp* inTimeStamp,
  24443. UInt32 inBusNumber,
  24444. UInt32 inNumberFrames,
  24445. AudioBufferList* ioData) const;
  24446. static OSStatus renderGetInputCallback (void* inRefCon,
  24447. AudioUnitRenderActionFlags* ioActionFlags,
  24448. const AudioTimeStamp* inTimeStamp,
  24449. UInt32 inBusNumber,
  24450. UInt32 inNumberFrames,
  24451. AudioBufferList* ioData)
  24452. {
  24453. return ((AudioUnitPluginInstance*) inRefCon)
  24454. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24455. }
  24456. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24457. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24458. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24459. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24460. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24461. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24462. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24463. {
  24464. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24465. }
  24466. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24467. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24468. Float64* outCurrentMeasureDownBeat)
  24469. {
  24470. return ((AudioUnitPluginInstance*) inHostUserData)
  24471. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24472. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24473. }
  24474. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24475. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24476. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24477. {
  24478. return ((AudioUnitPluginInstance*) inHostUserData)
  24479. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24480. outCurrentSampleInTimeLine, outIsCycling,
  24481. outCycleStartBeat, outCycleEndBeat);
  24482. }
  24483. void getNumChannels (int& numIns, int& numOuts)
  24484. {
  24485. numIns = 0;
  24486. numOuts = 0;
  24487. AUChannelInfo supportedChannels [128];
  24488. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24489. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24490. 0, supportedChannels, &supportedChannelsSize) == noErr
  24491. && supportedChannelsSize > 0)
  24492. {
  24493. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24494. {
  24495. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24496. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24497. }
  24498. }
  24499. else
  24500. {
  24501. // (this really means the plugin will take any number of ins/outs as long
  24502. // as they are the same)
  24503. numIns = numOuts = 2;
  24504. }
  24505. }
  24506. const String getCategory() const;
  24507. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24508. };
  24509. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24510. : fileOrIdentifier (fileOrIdentifier),
  24511. initialised (false),
  24512. wantsMidiMessages (false),
  24513. audioUnit (0),
  24514. currentBuffer (0)
  24515. {
  24516. try
  24517. {
  24518. ++insideCallback;
  24519. log (T("Opening AU: ") + fileOrIdentifier);
  24520. if (getComponentDescFromFile (fileOrIdentifier))
  24521. {
  24522. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24523. if (comp != 0)
  24524. {
  24525. audioUnit = (AudioUnit) OpenComponent (comp);
  24526. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24527. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24528. }
  24529. }
  24530. --insideCallback;
  24531. }
  24532. catch (...)
  24533. {
  24534. --insideCallback;
  24535. }
  24536. }
  24537. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24538. {
  24539. {
  24540. const ScopedLock sl (lock);
  24541. jassert (insideCallback == 0);
  24542. if (audioUnit != 0)
  24543. {
  24544. AudioUnitUninitialize (audioUnit);
  24545. CloseComponent (audioUnit);
  24546. audioUnit = 0;
  24547. }
  24548. }
  24549. }
  24550. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24551. {
  24552. zerostruct (componentDesc);
  24553. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24554. return true;
  24555. const File file (fileOrIdentifier);
  24556. if (! file.hasFileExtension (T(".component")))
  24557. return false;
  24558. const char* const utf8 = fileOrIdentifier.toUTF8();
  24559. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24560. strlen (utf8), file.isDirectory());
  24561. if (url != 0)
  24562. {
  24563. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24564. CFRelease (url);
  24565. if (bundleRef != 0)
  24566. {
  24567. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24568. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24569. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24570. if (pluginName.isEmpty())
  24571. pluginName = file.getFileNameWithoutExtension();
  24572. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24573. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24574. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24575. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24576. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24577. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24578. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24579. UseResFile (resFileId);
  24580. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24581. {
  24582. Handle h = Get1IndResource ('thng', i);
  24583. if (h != 0)
  24584. {
  24585. HLock (h);
  24586. const uint32* const types = (const uint32*) *h;
  24587. if (types[0] == kAudioUnitType_MusicDevice
  24588. || types[0] == kAudioUnitType_MusicEffect
  24589. || types[0] == kAudioUnitType_Effect
  24590. || types[0] == kAudioUnitType_Generator
  24591. || types[0] == kAudioUnitType_Panner)
  24592. {
  24593. componentDesc.componentType = types[0];
  24594. componentDesc.componentSubType = types[1];
  24595. componentDesc.componentManufacturer = types[2];
  24596. break;
  24597. }
  24598. HUnlock (h);
  24599. ReleaseResource (h);
  24600. }
  24601. }
  24602. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24603. CFRelease (bundleRef);
  24604. }
  24605. }
  24606. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24607. }
  24608. void AudioUnitPluginInstance::initialise()
  24609. {
  24610. if (initialised || audioUnit == 0)
  24611. return;
  24612. log (T("Initialising AU: ") + pluginName);
  24613. parameterIds.clear();
  24614. {
  24615. UInt32 paramListSize = 0;
  24616. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24617. 0, 0, &paramListSize);
  24618. if (paramListSize > 0)
  24619. {
  24620. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24621. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24622. 0, &parameterIds.getReference(0), &paramListSize);
  24623. }
  24624. }
  24625. {
  24626. AURenderCallbackStruct info;
  24627. zerostruct (info);
  24628. info.inputProcRefCon = this;
  24629. info.inputProc = renderGetInputCallback;
  24630. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24631. 0, &info, sizeof (info));
  24632. }
  24633. {
  24634. HostCallbackInfo info;
  24635. zerostruct (info);
  24636. info.hostUserData = this;
  24637. info.beatAndTempoProc = getBeatAndTempoCallback;
  24638. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24639. info.transportStateProc = getTransportStateCallback;
  24640. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24641. 0, &info, sizeof (info));
  24642. }
  24643. int numIns, numOuts;
  24644. getNumChannels (numIns, numOuts);
  24645. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24646. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24647. setLatencySamples (0);
  24648. }
  24649. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24650. int samplesPerBlockExpected)
  24651. {
  24652. initialise();
  24653. if (initialised)
  24654. {
  24655. int numIns, numOuts;
  24656. getNumChannels (numIns, numOuts);
  24657. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24658. Float64 latencySecs = 0.0;
  24659. UInt32 latencySize = sizeof (latencySecs);
  24660. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24661. 0, &latencySecs, &latencySize);
  24662. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24663. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24664. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24665. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24666. AudioStreamBasicDescription stream;
  24667. zerostruct (stream);
  24668. stream.mSampleRate = sampleRate_;
  24669. stream.mFormatID = kAudioFormatLinearPCM;
  24670. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24671. stream.mFramesPerPacket = 1;
  24672. stream.mBytesPerPacket = 4;
  24673. stream.mBytesPerFrame = 4;
  24674. stream.mBitsPerChannel = 32;
  24675. stream.mChannelsPerFrame = numIns;
  24676. OSStatus err = AudioUnitSetProperty (audioUnit,
  24677. kAudioUnitProperty_StreamFormat,
  24678. kAudioUnitScope_Input,
  24679. 0, &stream, sizeof (stream));
  24680. stream.mChannelsPerFrame = numOuts;
  24681. err = AudioUnitSetProperty (audioUnit,
  24682. kAudioUnitProperty_StreamFormat,
  24683. kAudioUnitScope_Output,
  24684. 0, &stream, sizeof (stream));
  24685. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24686. outputBufferList->mNumberBuffers = numOuts;
  24687. for (int i = numOuts; --i >= 0;)
  24688. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24689. zerostruct (timeStamp);
  24690. timeStamp.mSampleTime = 0;
  24691. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24692. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24693. currentBuffer = 0;
  24694. wasPlaying = false;
  24695. }
  24696. }
  24697. void AudioUnitPluginInstance::releaseResources()
  24698. {
  24699. if (initialised)
  24700. {
  24701. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24702. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24703. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24704. outputBufferList.free();
  24705. currentBuffer = 0;
  24706. }
  24707. }
  24708. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24709. const AudioTimeStamp* inTimeStamp,
  24710. UInt32 inBusNumber,
  24711. UInt32 inNumberFrames,
  24712. AudioBufferList* ioData) const
  24713. {
  24714. if (inBusNumber == 0
  24715. && currentBuffer != 0)
  24716. {
  24717. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24718. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24719. {
  24720. if (i < currentBuffer->getNumChannels())
  24721. {
  24722. memcpy (ioData->mBuffers[i].mData,
  24723. currentBuffer->getSampleData (i, 0),
  24724. sizeof (float) * inNumberFrames);
  24725. }
  24726. else
  24727. {
  24728. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24729. }
  24730. }
  24731. }
  24732. return noErr;
  24733. }
  24734. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24735. MidiBuffer& midiMessages)
  24736. {
  24737. const int numSamples = buffer.getNumSamples();
  24738. if (initialised)
  24739. {
  24740. AudioUnitRenderActionFlags flags = 0;
  24741. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24742. for (int i = getNumOutputChannels(); --i >= 0;)
  24743. {
  24744. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24745. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24746. }
  24747. currentBuffer = &buffer;
  24748. if (wantsMidiMessages)
  24749. {
  24750. const uint8* midiEventData;
  24751. int midiEventSize, midiEventPosition;
  24752. MidiBuffer::Iterator i (midiMessages);
  24753. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24754. {
  24755. if (midiEventSize <= 3)
  24756. MusicDeviceMIDIEvent (audioUnit,
  24757. midiEventData[0], midiEventData[1], midiEventData[2],
  24758. midiEventPosition);
  24759. else
  24760. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24761. }
  24762. midiMessages.clear();
  24763. }
  24764. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24765. 0, numSamples, outputBufferList);
  24766. timeStamp.mSampleTime += numSamples;
  24767. }
  24768. else
  24769. {
  24770. // Not initialised, so just bypass..
  24771. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24772. buffer.clear (i, 0, buffer.getNumSamples());
  24773. }
  24774. }
  24775. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24776. {
  24777. AudioPlayHead* const ph = getPlayHead();
  24778. AudioPlayHead::CurrentPositionInfo result;
  24779. if (ph != 0 && ph->getCurrentPosition (result))
  24780. {
  24781. if (outCurrentBeat != 0)
  24782. *outCurrentBeat = result.ppqPosition;
  24783. if (outCurrentTempo != 0)
  24784. *outCurrentTempo = result.bpm;
  24785. }
  24786. else
  24787. {
  24788. if (outCurrentBeat != 0)
  24789. *outCurrentBeat = 0;
  24790. if (outCurrentTempo != 0)
  24791. *outCurrentTempo = 120.0;
  24792. }
  24793. return noErr;
  24794. }
  24795. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24796. Float32* outTimeSig_Numerator,
  24797. UInt32* outTimeSig_Denominator,
  24798. Float64* outCurrentMeasureDownBeat) const
  24799. {
  24800. AudioPlayHead* const ph = getPlayHead();
  24801. AudioPlayHead::CurrentPositionInfo result;
  24802. if (ph != 0 && ph->getCurrentPosition (result))
  24803. {
  24804. if (outTimeSig_Numerator != 0)
  24805. *outTimeSig_Numerator = result.timeSigNumerator;
  24806. if (outTimeSig_Denominator != 0)
  24807. *outTimeSig_Denominator = result.timeSigDenominator;
  24808. if (outDeltaSampleOffsetToNextBeat != 0)
  24809. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24810. if (outCurrentMeasureDownBeat != 0)
  24811. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24812. }
  24813. else
  24814. {
  24815. if (outDeltaSampleOffsetToNextBeat != 0)
  24816. *outDeltaSampleOffsetToNextBeat = 0;
  24817. if (outTimeSig_Numerator != 0)
  24818. *outTimeSig_Numerator = 4;
  24819. if (outTimeSig_Denominator != 0)
  24820. *outTimeSig_Denominator = 4;
  24821. if (outCurrentMeasureDownBeat != 0)
  24822. *outCurrentMeasureDownBeat = 0;
  24823. }
  24824. return noErr;
  24825. }
  24826. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24827. Boolean* outTransportStateChanged,
  24828. Float64* outCurrentSampleInTimeLine,
  24829. Boolean* outIsCycling,
  24830. Float64* outCycleStartBeat,
  24831. Float64* outCycleEndBeat)
  24832. {
  24833. AudioPlayHead* const ph = getPlayHead();
  24834. AudioPlayHead::CurrentPositionInfo result;
  24835. if (ph != 0 && ph->getCurrentPosition (result))
  24836. {
  24837. if (outIsPlaying != 0)
  24838. *outIsPlaying = result.isPlaying;
  24839. if (outTransportStateChanged != 0)
  24840. {
  24841. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24842. wasPlaying = result.isPlaying;
  24843. }
  24844. if (outCurrentSampleInTimeLine != 0)
  24845. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24846. if (outIsCycling != 0)
  24847. *outIsCycling = false;
  24848. if (outCycleStartBeat != 0)
  24849. *outCycleStartBeat = 0;
  24850. if (outCycleEndBeat != 0)
  24851. *outCycleEndBeat = 0;
  24852. }
  24853. else
  24854. {
  24855. if (outIsPlaying != 0)
  24856. *outIsPlaying = false;
  24857. if (outTransportStateChanged != 0)
  24858. *outTransportStateChanged = false;
  24859. if (outCurrentSampleInTimeLine != 0)
  24860. *outCurrentSampleInTimeLine = 0;
  24861. if (outIsCycling != 0)
  24862. *outIsCycling = false;
  24863. if (outCycleStartBeat != 0)
  24864. *outCycleStartBeat = 0;
  24865. if (outCycleEndBeat != 0)
  24866. *outCycleEndBeat = 0;
  24867. }
  24868. return noErr;
  24869. }
  24870. static VoidArray activeWindows;
  24871. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24872. {
  24873. public:
  24874. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24875. : AudioProcessorEditor (&plugin_),
  24876. plugin (plugin_),
  24877. wrapper (0)
  24878. {
  24879. addAndMakeVisible (wrapper = new NSViewComponent());
  24880. activeWindows.add (this);
  24881. setOpaque (true);
  24882. setVisible (true);
  24883. setSize (100, 100);
  24884. createView (createGenericViewIfNeeded);
  24885. }
  24886. ~AudioUnitPluginWindowCocoa()
  24887. {
  24888. const bool wasValid = isValid();
  24889. wrapper->setView (0);
  24890. activeWindows.removeValue (this);
  24891. if (wasValid)
  24892. plugin.editorBeingDeleted (this);
  24893. delete wrapper;
  24894. }
  24895. bool isValid() const { return wrapper->getView() != 0; }
  24896. void paint (Graphics& g)
  24897. {
  24898. g.fillAll (Colours::white);
  24899. }
  24900. void resized()
  24901. {
  24902. wrapper->setSize (getWidth(), getHeight());
  24903. }
  24904. private:
  24905. AudioUnitPluginInstance& plugin;
  24906. NSViewComponent* wrapper;
  24907. bool createView (const bool createGenericViewIfNeeded)
  24908. {
  24909. NSView* pluginView = 0;
  24910. UInt32 dataSize = 0;
  24911. Boolean isWritable = false;
  24912. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24913. 0, &dataSize, &isWritable) == noErr
  24914. && dataSize != 0
  24915. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24916. 0, &dataSize, &isWritable) == noErr)
  24917. {
  24918. HeapBlock <AudioUnitCocoaViewInfo> info;
  24919. info.calloc (dataSize, 1);
  24920. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24921. 0, info, &dataSize) == noErr)
  24922. {
  24923. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24924. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24925. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24926. Class viewClass = [viewBundle classNamed: viewClassName];
  24927. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24928. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24929. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24930. {
  24931. id factory = [[[viewClass alloc] init] autorelease];
  24932. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24933. withSize: NSMakeSize (getWidth(), getHeight())];
  24934. }
  24935. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24936. {
  24937. CFRelease (info->mCocoaAUViewClass[i]);
  24938. CFRelease (info->mCocoaAUViewBundleLocation);
  24939. }
  24940. }
  24941. }
  24942. if (createGenericViewIfNeeded && (pluginView == 0))
  24943. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24944. wrapper->setView (pluginView);
  24945. if (pluginView != 0)
  24946. setSize ([pluginView frame].size.width,
  24947. [pluginView frame].size.height);
  24948. return pluginView != 0;
  24949. }
  24950. };
  24951. #if JUCE_SUPPORT_CARBON
  24952. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24953. {
  24954. public:
  24955. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24956. : AudioProcessorEditor (&plugin_),
  24957. plugin (plugin_),
  24958. viewComponent (0)
  24959. {
  24960. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24961. activeWindows.add (this);
  24962. setOpaque (true);
  24963. setVisible (true);
  24964. setSize (400, 300);
  24965. ComponentDescription viewList [16];
  24966. UInt32 viewListSize = sizeof (viewList);
  24967. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24968. 0, &viewList, &viewListSize);
  24969. componentRecord = FindNextComponent (0, &viewList[0]);
  24970. }
  24971. ~AudioUnitPluginWindowCarbon()
  24972. {
  24973. deleteAndZero (innerWrapper);
  24974. activeWindows.removeValue (this);
  24975. if (isValid())
  24976. plugin.editorBeingDeleted (this);
  24977. }
  24978. bool isValid() const throw() { return componentRecord != 0; }
  24979. void paint (Graphics& g)
  24980. {
  24981. g.fillAll (Colours::black);
  24982. }
  24983. void resized()
  24984. {
  24985. innerWrapper->setSize (getWidth(), getHeight());
  24986. }
  24987. bool keyStateChanged (const bool)
  24988. {
  24989. return false;
  24990. }
  24991. bool keyPressed (const KeyPress&)
  24992. {
  24993. return false;
  24994. }
  24995. void broughtToFront()
  24996. {
  24997. activeWindows.removeValue (this);
  24998. activeWindows.add (this);
  24999. }
  25000. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  25001. AudioUnitCarbonView getViewComponent()
  25002. {
  25003. if (viewComponent == 0 && componentRecord != 0)
  25004. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  25005. return viewComponent;
  25006. }
  25007. void closeViewComponent()
  25008. {
  25009. if (viewComponent != 0)
  25010. {
  25011. CloseComponent (viewComponent);
  25012. viewComponent = 0;
  25013. }
  25014. }
  25015. juce_UseDebuggingNewOperator
  25016. private:
  25017. AudioUnitPluginInstance& plugin;
  25018. ComponentRecord* componentRecord;
  25019. AudioUnitCarbonView viewComponent;
  25020. class InnerWrapperComponent : public CarbonViewWrapperComponent
  25021. {
  25022. public:
  25023. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  25024. : owner (owner_)
  25025. {
  25026. }
  25027. ~InnerWrapperComponent()
  25028. {
  25029. deleteWindow();
  25030. }
  25031. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  25032. {
  25033. log (T("Opening AU GUI: ") + owner->plugin.getName());
  25034. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  25035. if (viewComponent == 0)
  25036. return 0;
  25037. Float32Point pos = { 0, 0 };
  25038. Float32Point size = { 250, 200 };
  25039. HIViewRef pluginView = 0;
  25040. AudioUnitCarbonViewCreate (viewComponent,
  25041. owner->getAudioUnit(),
  25042. windowRef,
  25043. rootView,
  25044. &pos,
  25045. &size,
  25046. (ControlRef*) &pluginView);
  25047. return pluginView;
  25048. }
  25049. void removeView (HIViewRef)
  25050. {
  25051. log (T("Closing AU GUI: ") + owner->plugin.getName());
  25052. owner->closeViewComponent();
  25053. }
  25054. private:
  25055. AudioUnitPluginWindowCarbon* const owner;
  25056. };
  25057. friend class InnerWrapperComponent;
  25058. InnerWrapperComponent* innerWrapper;
  25059. };
  25060. #endif
  25061. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  25062. {
  25063. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  25064. if (! ((AudioUnitPluginWindowCocoa*) w)->isValid())
  25065. w = 0;
  25066. #if JUCE_SUPPORT_CARBON
  25067. if (w == 0)
  25068. {
  25069. w = new AudioUnitPluginWindowCarbon (*this);
  25070. if (! ((AudioUnitPluginWindowCarbon*) w)->isValid())
  25071. w = 0;
  25072. }
  25073. #endif
  25074. if (w == 0)
  25075. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  25076. return w.release();
  25077. }
  25078. const String AudioUnitPluginInstance::getCategory() const
  25079. {
  25080. const char* result = 0;
  25081. switch (componentDesc.componentType)
  25082. {
  25083. case kAudioUnitType_Effect:
  25084. case kAudioUnitType_MusicEffect:
  25085. result = "Effect";
  25086. break;
  25087. case kAudioUnitType_MusicDevice:
  25088. result = "Synth";
  25089. break;
  25090. case kAudioUnitType_Generator:
  25091. result = "Generator";
  25092. break;
  25093. case kAudioUnitType_Panner:
  25094. result = "Panner";
  25095. break;
  25096. default:
  25097. break;
  25098. }
  25099. return result;
  25100. }
  25101. int AudioUnitPluginInstance::getNumParameters()
  25102. {
  25103. return parameterIds.size();
  25104. }
  25105. float AudioUnitPluginInstance::getParameter (int index)
  25106. {
  25107. const ScopedLock sl (lock);
  25108. Float32 value = 0.0f;
  25109. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25110. {
  25111. AudioUnitGetParameter (audioUnit,
  25112. (UInt32) parameterIds.getUnchecked (index),
  25113. kAudioUnitScope_Global, 0,
  25114. &value);
  25115. }
  25116. return value;
  25117. }
  25118. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  25119. {
  25120. const ScopedLock sl (lock);
  25121. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25122. {
  25123. AudioUnitSetParameter (audioUnit,
  25124. (UInt32) parameterIds.getUnchecked (index),
  25125. kAudioUnitScope_Global, 0,
  25126. newValue, 0);
  25127. }
  25128. }
  25129. const String AudioUnitPluginInstance::getParameterName (int index)
  25130. {
  25131. AudioUnitParameterInfo info;
  25132. zerostruct (info);
  25133. UInt32 sz = sizeof (info);
  25134. String name;
  25135. if (AudioUnitGetProperty (audioUnit,
  25136. kAudioUnitProperty_ParameterInfo,
  25137. kAudioUnitScope_Global,
  25138. parameterIds [index], &info, &sz) == noErr)
  25139. {
  25140. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  25141. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  25142. else
  25143. name = String (info.name, sizeof (info.name));
  25144. }
  25145. return name;
  25146. }
  25147. const String AudioUnitPluginInstance::getParameterText (int index)
  25148. {
  25149. return String (getParameter (index));
  25150. }
  25151. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  25152. {
  25153. AudioUnitParameterInfo info;
  25154. UInt32 sz = sizeof (info);
  25155. if (AudioUnitGetProperty (audioUnit,
  25156. kAudioUnitProperty_ParameterInfo,
  25157. kAudioUnitScope_Global,
  25158. parameterIds [index], &info, &sz) == noErr)
  25159. {
  25160. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  25161. }
  25162. return true;
  25163. }
  25164. int AudioUnitPluginInstance::getNumPrograms()
  25165. {
  25166. CFArrayRef presets;
  25167. UInt32 sz = sizeof (CFArrayRef);
  25168. int num = 0;
  25169. if (AudioUnitGetProperty (audioUnit,
  25170. kAudioUnitProperty_FactoryPresets,
  25171. kAudioUnitScope_Global,
  25172. 0, &presets, &sz) == noErr)
  25173. {
  25174. num = (int) CFArrayGetCount (presets);
  25175. CFRelease (presets);
  25176. }
  25177. return num;
  25178. }
  25179. int AudioUnitPluginInstance::getCurrentProgram()
  25180. {
  25181. AUPreset current;
  25182. current.presetNumber = 0;
  25183. UInt32 sz = sizeof (AUPreset);
  25184. AudioUnitGetProperty (audioUnit,
  25185. kAudioUnitProperty_FactoryPresets,
  25186. kAudioUnitScope_Global,
  25187. 0, &current, &sz);
  25188. return current.presetNumber;
  25189. }
  25190. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  25191. {
  25192. AUPreset current;
  25193. current.presetNumber = newIndex;
  25194. current.presetName = 0;
  25195. AudioUnitSetProperty (audioUnit,
  25196. kAudioUnitProperty_FactoryPresets,
  25197. kAudioUnitScope_Global,
  25198. 0, &current, sizeof (AUPreset));
  25199. }
  25200. const String AudioUnitPluginInstance::getProgramName (int index)
  25201. {
  25202. String s;
  25203. CFArrayRef presets;
  25204. UInt32 sz = sizeof (CFArrayRef);
  25205. if (AudioUnitGetProperty (audioUnit,
  25206. kAudioUnitProperty_FactoryPresets,
  25207. kAudioUnitScope_Global,
  25208. 0, &presets, &sz) == noErr)
  25209. {
  25210. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  25211. {
  25212. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  25213. if (p != 0 && p->presetNumber == index)
  25214. {
  25215. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  25216. break;
  25217. }
  25218. }
  25219. CFRelease (presets);
  25220. }
  25221. return s;
  25222. }
  25223. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  25224. {
  25225. jassertfalse // xxx not implemented!
  25226. }
  25227. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  25228. {
  25229. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  25230. return T("Input ") + String (index + 1);
  25231. return String::empty;
  25232. }
  25233. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25234. {
  25235. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25236. return false;
  25237. return true;
  25238. }
  25239. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25240. {
  25241. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25242. return T("Output ") + String (index + 1);
  25243. return String::empty;
  25244. }
  25245. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25246. {
  25247. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25248. return false;
  25249. return true;
  25250. }
  25251. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25252. {
  25253. getCurrentProgramStateInformation (destData);
  25254. }
  25255. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25256. {
  25257. CFPropertyListRef propertyList = 0;
  25258. UInt32 sz = sizeof (CFPropertyListRef);
  25259. if (AudioUnitGetProperty (audioUnit,
  25260. kAudioUnitProperty_ClassInfo,
  25261. kAudioUnitScope_Global,
  25262. 0, &propertyList, &sz) == noErr)
  25263. {
  25264. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25265. CFWriteStreamOpen (stream);
  25266. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25267. CFWriteStreamClose (stream);
  25268. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25269. destData.setSize (bytesWritten);
  25270. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25271. CFRelease (data);
  25272. CFRelease (stream);
  25273. CFRelease (propertyList);
  25274. }
  25275. }
  25276. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25277. {
  25278. setCurrentProgramStateInformation (data, sizeInBytes);
  25279. }
  25280. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25281. {
  25282. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25283. (const UInt8*) data,
  25284. sizeInBytes,
  25285. kCFAllocatorNull);
  25286. CFReadStreamOpen (stream);
  25287. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25288. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25289. stream,
  25290. 0,
  25291. kCFPropertyListImmutable,
  25292. &format,
  25293. 0);
  25294. CFRelease (stream);
  25295. if (propertyList != 0)
  25296. AudioUnitSetProperty (audioUnit,
  25297. kAudioUnitProperty_ClassInfo,
  25298. kAudioUnitScope_Global,
  25299. 0, &propertyList, sizeof (propertyList));
  25300. }
  25301. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25302. {
  25303. }
  25304. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25305. {
  25306. }
  25307. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25308. const String& fileOrIdentifier)
  25309. {
  25310. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25311. return;
  25312. PluginDescription desc;
  25313. desc.fileOrIdentifier = fileOrIdentifier;
  25314. desc.uid = 0;
  25315. try
  25316. {
  25317. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25318. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25319. if (auInstance != 0)
  25320. {
  25321. auInstance->fillInPluginDescription (desc);
  25322. results.add (new PluginDescription (desc));
  25323. }
  25324. }
  25325. catch (...)
  25326. {
  25327. // crashed while loading...
  25328. }
  25329. }
  25330. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25331. {
  25332. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25333. {
  25334. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25335. if (result->audioUnit != 0)
  25336. {
  25337. result->initialise();
  25338. return result.release();
  25339. }
  25340. }
  25341. return 0;
  25342. }
  25343. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25344. const bool /*recursive*/)
  25345. {
  25346. StringArray result;
  25347. ComponentRecord* comp = 0;
  25348. ComponentDescription desc;
  25349. zerostruct (desc);
  25350. for (;;)
  25351. {
  25352. zerostruct (desc);
  25353. comp = FindNextComponent (comp, &desc);
  25354. if (comp == 0)
  25355. break;
  25356. GetComponentInfo (comp, &desc, 0, 0, 0);
  25357. if (desc.componentType == kAudioUnitType_MusicDevice
  25358. || desc.componentType == kAudioUnitType_MusicEffect
  25359. || desc.componentType == kAudioUnitType_Effect
  25360. || desc.componentType == kAudioUnitType_Generator
  25361. || desc.componentType == kAudioUnitType_Panner)
  25362. {
  25363. const String s (createAUPluginIdentifier (desc));
  25364. DBG (s);
  25365. result.add (s);
  25366. }
  25367. }
  25368. return result;
  25369. }
  25370. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25371. {
  25372. ComponentDescription desc;
  25373. String name, version, manufacturer;
  25374. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25375. return FindNextComponent (0, &desc) != 0;
  25376. const File f (fileOrIdentifier);
  25377. return f.hasFileExtension (T(".component"))
  25378. && f.isDirectory();
  25379. }
  25380. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25381. {
  25382. ComponentDescription desc;
  25383. String name, version, manufacturer;
  25384. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25385. if (name.isEmpty())
  25386. name = fileOrIdentifier;
  25387. return name;
  25388. }
  25389. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25390. {
  25391. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25392. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25393. else
  25394. return File (desc.fileOrIdentifier).exists();
  25395. }
  25396. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25397. {
  25398. return FileSearchPath ("/(Default AudioUnit locations)");
  25399. }
  25400. #endif
  25401. END_JUCE_NAMESPACE
  25402. #undef log
  25403. #endif
  25404. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25405. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25406. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25407. #define JUCE_MAC_VST_INCLUDED 1
  25408. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25409. #if JUCE_PLUGINHOST_VST
  25410. #if (defined (_WIN32) || defined (_WIN64))
  25411. #undef _WIN32_WINNT
  25412. #define _WIN32_WINNT 0x500
  25413. #undef STRICT
  25414. #define STRICT
  25415. #include <windows.h>
  25416. #include <float.h>
  25417. #pragma warning (disable : 4312 4355)
  25418. #elif defined (LINUX) || defined (__linux__)
  25419. #include <float.h>
  25420. #include <sys/time.h>
  25421. #include <X11/Xlib.h>
  25422. #include <X11/Xutil.h>
  25423. #include <X11/Xatom.h>
  25424. #undef Font
  25425. #undef KeyPress
  25426. #undef Drawable
  25427. #undef Time
  25428. #else
  25429. #ifndef JUCE_MAC_VST_INCLUDED
  25430. // On the mac, this file needs to be compiled indirectly, by using
  25431. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25432. #error
  25433. #endif
  25434. #include <Cocoa/Cocoa.h>
  25435. #include <Carbon/Carbon.h>
  25436. #endif
  25437. #if ! (JUCE_MAC && JUCE_64BIT)
  25438. BEGIN_JUCE_NAMESPACE
  25439. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25440. #endif
  25441. #undef PRAGMA_ALIGN_SUPPORTED
  25442. #define VST_FORCE_DEPRECATED 0
  25443. #ifdef _MSC_VER
  25444. #pragma warning (push)
  25445. #pragma warning (disable: 4996)
  25446. #endif
  25447. #include "pluginterfaces/vst2.x/aeffectx.h"
  25448. #ifdef _MSC_VER
  25449. #pragma warning (pop)
  25450. #endif
  25451. #if JUCE_LINUX
  25452. #define Font JUCE_NAMESPACE::Font
  25453. #define KeyPress JUCE_NAMESPACE::KeyPress
  25454. #define Drawable JUCE_NAMESPACE::Drawable
  25455. #define Time JUCE_NAMESPACE::Time
  25456. #endif
  25457. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25458. #ifdef __aeffect__
  25459. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25460. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25461. class VSTMidiEventList
  25462. {
  25463. public:
  25464. VSTMidiEventList()
  25465. : numEventsUsed (0), numEventsAllocated (0)
  25466. {
  25467. }
  25468. ~VSTMidiEventList()
  25469. {
  25470. freeEvents();
  25471. }
  25472. void clear()
  25473. {
  25474. numEventsUsed = 0;
  25475. if (events != 0)
  25476. events->numEvents = 0;
  25477. }
  25478. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25479. {
  25480. ensureSize (numEventsUsed + 1);
  25481. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25482. events->numEvents = ++numEventsUsed;
  25483. if (numBytes <= 4)
  25484. {
  25485. if (e->type == kVstSysExType)
  25486. {
  25487. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25488. e->type = kVstMidiType;
  25489. e->byteSize = sizeof (VstMidiEvent);
  25490. e->noteLength = 0;
  25491. e->noteOffset = 0;
  25492. e->detune = 0;
  25493. e->noteOffVelocity = 0;
  25494. }
  25495. e->deltaFrames = frameOffset;
  25496. memcpy (e->midiData, midiData, numBytes);
  25497. }
  25498. else
  25499. {
  25500. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25501. if (se->type == kVstSysExType)
  25502. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25503. else
  25504. se->sysexDump = (char*) juce_malloc (numBytes);
  25505. memcpy (se->sysexDump, midiData, numBytes);
  25506. se->type = kVstSysExType;
  25507. se->byteSize = sizeof (VstMidiSysexEvent);
  25508. se->deltaFrames = frameOffset;
  25509. se->flags = 0;
  25510. se->dumpBytes = numBytes;
  25511. se->resvd1 = 0;
  25512. se->resvd2 = 0;
  25513. }
  25514. }
  25515. // Handy method to pull the events out of an event buffer supplied by the host
  25516. // or plugin.
  25517. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25518. {
  25519. for (int i = 0; i < events->numEvents; ++i)
  25520. {
  25521. const VstEvent* const e = events->events[i];
  25522. if (e != 0)
  25523. {
  25524. if (e->type == kVstMidiType)
  25525. {
  25526. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25527. 4, e->deltaFrames);
  25528. }
  25529. else if (e->type == kVstSysExType)
  25530. {
  25531. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25532. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25533. e->deltaFrames);
  25534. }
  25535. }
  25536. }
  25537. }
  25538. void ensureSize (int numEventsNeeded)
  25539. {
  25540. if (numEventsNeeded > numEventsAllocated)
  25541. {
  25542. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25543. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25544. if (events == 0)
  25545. events.calloc (size, 1);
  25546. else
  25547. events.realloc (size, 1);
  25548. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25549. {
  25550. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25551. (int) sizeof (VstMidiSysexEvent)));
  25552. e->type = kVstMidiType;
  25553. e->byteSize = sizeof (VstMidiEvent);
  25554. events->events[i] = (VstEvent*) e;
  25555. }
  25556. numEventsAllocated = numEventsNeeded;
  25557. }
  25558. }
  25559. void freeEvents()
  25560. {
  25561. if (events != 0)
  25562. {
  25563. for (int i = numEventsAllocated; --i >= 0;)
  25564. {
  25565. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25566. if (e->type == kVstSysExType)
  25567. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25568. juce_free (e);
  25569. }
  25570. events.free();
  25571. numEventsUsed = 0;
  25572. numEventsAllocated = 0;
  25573. }
  25574. }
  25575. HeapBlock <VstEvents> events;
  25576. private:
  25577. int numEventsUsed, numEventsAllocated;
  25578. };
  25579. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25580. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25581. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25582. #if ! JUCE_WIN32
  25583. #define _fpreset()
  25584. #define _clearfp()
  25585. #endif
  25586. extern void juce_callAnyTimersSynchronously();
  25587. const int fxbVersionNum = 1;
  25588. struct fxProgram
  25589. {
  25590. long chunkMagic; // 'CcnK'
  25591. long byteSize; // of this chunk, excl. magic + byteSize
  25592. long fxMagic; // 'FxCk'
  25593. long version;
  25594. long fxID; // fx unique id
  25595. long fxVersion;
  25596. long numParams;
  25597. char prgName[28];
  25598. float params[1]; // variable no. of parameters
  25599. };
  25600. struct fxSet
  25601. {
  25602. long chunkMagic; // 'CcnK'
  25603. long byteSize; // of this chunk, excl. magic + byteSize
  25604. long fxMagic; // 'FxBk'
  25605. long version;
  25606. long fxID; // fx unique id
  25607. long fxVersion;
  25608. long numPrograms;
  25609. char future[128];
  25610. fxProgram programs[1]; // variable no. of programs
  25611. };
  25612. struct fxChunkSet
  25613. {
  25614. long chunkMagic; // 'CcnK'
  25615. long byteSize; // of this chunk, excl. magic + byteSize
  25616. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25617. long version;
  25618. long fxID; // fx unique id
  25619. long fxVersion;
  25620. long numPrograms;
  25621. char future[128];
  25622. long chunkSize;
  25623. char chunk[8]; // variable
  25624. };
  25625. struct fxProgramSet
  25626. {
  25627. long chunkMagic; // 'CcnK'
  25628. long byteSize; // of this chunk, excl. magic + byteSize
  25629. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25630. long version;
  25631. long fxID; // fx unique id
  25632. long fxVersion;
  25633. long numPrograms;
  25634. char name[28];
  25635. long chunkSize;
  25636. char chunk[8]; // variable
  25637. };
  25638. static long vst_swap (const long x) throw()
  25639. {
  25640. #ifdef JUCE_LITTLE_ENDIAN
  25641. return (long) ByteOrder::swap ((uint32) x);
  25642. #else
  25643. return x;
  25644. #endif
  25645. }
  25646. static float vst_swapFloat (const float x) throw()
  25647. {
  25648. #ifdef JUCE_LITTLE_ENDIAN
  25649. union { uint32 asInt; float asFloat; } n;
  25650. n.asFloat = x;
  25651. n.asInt = ByteOrder::swap (n.asInt);
  25652. return n.asFloat;
  25653. #else
  25654. return x;
  25655. #endif
  25656. }
  25657. typedef AEffect* (*MainCall) (audioMasterCallback);
  25658. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25659. static int shellUIDToCreate = 0;
  25660. static int insideVSTCallback = 0;
  25661. class VSTPluginWindow;
  25662. // Change this to disable logging of various VST activities
  25663. #ifndef VST_LOGGING
  25664. #define VST_LOGGING 1
  25665. #endif
  25666. #if VST_LOGGING
  25667. #define log(a) Logger::writeToLog(a);
  25668. #else
  25669. #define log(a)
  25670. #endif
  25671. #if JUCE_MAC && JUCE_PPC
  25672. static void* NewCFMFromMachO (void* const machofp) throw()
  25673. {
  25674. void* result = juce_malloc (8);
  25675. ((void**) result)[0] = machofp;
  25676. ((void**) result)[1] = result;
  25677. return result;
  25678. }
  25679. #endif
  25680. #if JUCE_LINUX
  25681. extern Display* display;
  25682. extern XContext improbableNumber;
  25683. typedef void (*EventProcPtr) (XEvent* ev);
  25684. static bool xErrorTriggered;
  25685. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25686. {
  25687. xErrorTriggered = true;
  25688. return 0;
  25689. }
  25690. static int getPropertyFromXWindow (Window handle, Atom atom)
  25691. {
  25692. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25693. xErrorTriggered = false;
  25694. int userSize;
  25695. unsigned long bytes, userCount;
  25696. unsigned char* data;
  25697. Atom userType;
  25698. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25699. &userType, &userSize, &userCount, &bytes, &data);
  25700. XSetErrorHandler (oldErrorHandler);
  25701. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25702. : 0;
  25703. }
  25704. static Window getChildWindow (Window windowToCheck)
  25705. {
  25706. Window rootWindow, parentWindow;
  25707. Window* childWindows;
  25708. unsigned int numChildren;
  25709. XQueryTree (display,
  25710. windowToCheck,
  25711. &rootWindow,
  25712. &parentWindow,
  25713. &childWindows,
  25714. &numChildren);
  25715. if (numChildren > 0)
  25716. return childWindows [0];
  25717. return 0;
  25718. }
  25719. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25720. {
  25721. if (e.mods.isLeftButtonDown())
  25722. {
  25723. ev.xbutton.button = Button1;
  25724. ev.xbutton.state |= Button1Mask;
  25725. }
  25726. else if (e.mods.isRightButtonDown())
  25727. {
  25728. ev.xbutton.button = Button3;
  25729. ev.xbutton.state |= Button3Mask;
  25730. }
  25731. else if (e.mods.isMiddleButtonDown())
  25732. {
  25733. ev.xbutton.button = Button2;
  25734. ev.xbutton.state |= Button2Mask;
  25735. }
  25736. }
  25737. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25738. {
  25739. if (e.mods.isLeftButtonDown())
  25740. ev.xmotion.state |= Button1Mask;
  25741. else if (e.mods.isRightButtonDown())
  25742. ev.xmotion.state |= Button3Mask;
  25743. else if (e.mods.isMiddleButtonDown())
  25744. ev.xmotion.state |= Button2Mask;
  25745. }
  25746. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25747. {
  25748. if (e.mods.isLeftButtonDown())
  25749. ev.xcrossing.state |= Button1Mask;
  25750. else if (e.mods.isRightButtonDown())
  25751. ev.xcrossing.state |= Button3Mask;
  25752. else if (e.mods.isMiddleButtonDown())
  25753. ev.xcrossing.state |= Button2Mask;
  25754. }
  25755. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25756. {
  25757. if (increment < 0)
  25758. {
  25759. ev.xbutton.button = Button5;
  25760. ev.xbutton.state |= Button5Mask;
  25761. }
  25762. else if (increment > 0)
  25763. {
  25764. ev.xbutton.button = Button4;
  25765. ev.xbutton.state |= Button4Mask;
  25766. }
  25767. }
  25768. #endif
  25769. static VoidArray activeModules;
  25770. class ModuleHandle : public ReferenceCountedObject
  25771. {
  25772. public:
  25773. File file;
  25774. MainCall moduleMain;
  25775. String pluginName;
  25776. static ModuleHandle* findOrCreateModule (const File& file)
  25777. {
  25778. for (int i = activeModules.size(); --i >= 0;)
  25779. {
  25780. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25781. if (module->file == file)
  25782. return module;
  25783. }
  25784. _fpreset(); // (doesn't do any harm)
  25785. ++insideVSTCallback;
  25786. shellUIDToCreate = 0;
  25787. log ("Attempting to load VST: " + file.getFullPathName());
  25788. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25789. if (! m->open())
  25790. m = 0;
  25791. --insideVSTCallback;
  25792. _fpreset(); // (doesn't do any harm)
  25793. return m.release();
  25794. }
  25795. ModuleHandle (const File& file_)
  25796. : file (file_),
  25797. moduleMain (0),
  25798. #if JUCE_WIN32 || JUCE_LINUX
  25799. hModule (0)
  25800. #elif JUCE_MAC
  25801. fragId (0),
  25802. resHandle (0),
  25803. bundleRef (0),
  25804. resFileId (0)
  25805. #endif
  25806. {
  25807. activeModules.add (this);
  25808. #if JUCE_WIN32 || JUCE_LINUX
  25809. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25810. #elif JUCE_MAC
  25811. FSRef ref;
  25812. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25813. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25814. #endif
  25815. }
  25816. ~ModuleHandle()
  25817. {
  25818. activeModules.removeValue (this);
  25819. close();
  25820. }
  25821. juce_UseDebuggingNewOperator
  25822. #if JUCE_WIN32 || JUCE_LINUX
  25823. void* hModule;
  25824. String fullParentDirectoryPathName;
  25825. bool open()
  25826. {
  25827. #if JUCE_WIN32
  25828. static bool timePeriodSet = false;
  25829. if (! timePeriodSet)
  25830. {
  25831. timePeriodSet = true;
  25832. timeBeginPeriod (2);
  25833. }
  25834. #endif
  25835. pluginName = file.getFileNameWithoutExtension();
  25836. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25837. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25838. if (moduleMain == 0)
  25839. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25840. return moduleMain != 0;
  25841. }
  25842. void close()
  25843. {
  25844. _fpreset(); // (doesn't do any harm)
  25845. PlatformUtilities::freeDynamicLibrary (hModule);
  25846. }
  25847. void closeEffect (AEffect* eff)
  25848. {
  25849. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25850. }
  25851. #else
  25852. CFragConnectionID fragId;
  25853. Handle resHandle;
  25854. CFBundleRef bundleRef;
  25855. FSSpec parentDirFSSpec;
  25856. short resFileId;
  25857. bool open()
  25858. {
  25859. bool ok = false;
  25860. const String filename (file.getFullPathName());
  25861. if (file.hasFileExtension (T(".vst")))
  25862. {
  25863. const char* const utf8 = filename.toUTF8();
  25864. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25865. strlen (utf8), file.isDirectory());
  25866. if (url != 0)
  25867. {
  25868. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25869. CFRelease (url);
  25870. if (bundleRef != 0)
  25871. {
  25872. if (CFBundleLoadExecutable (bundleRef))
  25873. {
  25874. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25875. if (moduleMain == 0)
  25876. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25877. if (moduleMain != 0)
  25878. {
  25879. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25880. if (name != 0)
  25881. {
  25882. if (CFGetTypeID (name) == CFStringGetTypeID())
  25883. {
  25884. char buffer[1024];
  25885. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25886. pluginName = buffer;
  25887. }
  25888. }
  25889. if (pluginName.isEmpty())
  25890. pluginName = file.getFileNameWithoutExtension();
  25891. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25892. ok = true;
  25893. }
  25894. }
  25895. if (! ok)
  25896. {
  25897. CFBundleUnloadExecutable (bundleRef);
  25898. CFRelease (bundleRef);
  25899. bundleRef = 0;
  25900. }
  25901. }
  25902. }
  25903. }
  25904. #if JUCE_PPC
  25905. else
  25906. {
  25907. FSRef fn;
  25908. if (FSPathMakeRef ((UInt8*) (const char*) filename, &fn, 0) == noErr)
  25909. {
  25910. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25911. if (resFileId != -1)
  25912. {
  25913. const int numEffs = Count1Resources ('aEff');
  25914. for (int i = 0; i < numEffs; ++i)
  25915. {
  25916. resHandle = Get1IndResource ('aEff', i + 1);
  25917. if (resHandle != 0)
  25918. {
  25919. OSType type;
  25920. Str255 name;
  25921. SInt16 id;
  25922. GetResInfo (resHandle, &id, &type, name);
  25923. pluginName = String ((const char*) name + 1, name[0]);
  25924. DetachResource (resHandle);
  25925. HLock (resHandle);
  25926. Ptr ptr;
  25927. Str255 errorText;
  25928. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25929. name, kPrivateCFragCopy,
  25930. &fragId, &ptr, errorText);
  25931. if (err == noErr)
  25932. {
  25933. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25934. ok = true;
  25935. }
  25936. else
  25937. {
  25938. HUnlock (resHandle);
  25939. }
  25940. break;
  25941. }
  25942. }
  25943. if (! ok)
  25944. CloseResFile (resFileId);
  25945. }
  25946. }
  25947. }
  25948. #endif
  25949. return ok;
  25950. }
  25951. void close()
  25952. {
  25953. #if JUCE_PPC
  25954. if (fragId != 0)
  25955. {
  25956. if (moduleMain != 0)
  25957. disposeMachOFromCFM ((void*) moduleMain);
  25958. CloseConnection (&fragId);
  25959. HUnlock (resHandle);
  25960. if (resFileId != 0)
  25961. CloseResFile (resFileId);
  25962. }
  25963. else
  25964. #endif
  25965. if (bundleRef != 0)
  25966. {
  25967. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25968. if (CFGetRetainCount (bundleRef) == 1)
  25969. CFBundleUnloadExecutable (bundleRef);
  25970. if (CFGetRetainCount (bundleRef) > 0)
  25971. CFRelease (bundleRef);
  25972. }
  25973. }
  25974. void closeEffect (AEffect* eff)
  25975. {
  25976. #if JUCE_PPC
  25977. if (fragId != 0)
  25978. {
  25979. VoidArray thingsToDelete;
  25980. thingsToDelete.add ((void*) eff->dispatcher);
  25981. thingsToDelete.add ((void*) eff->process);
  25982. thingsToDelete.add ((void*) eff->setParameter);
  25983. thingsToDelete.add ((void*) eff->getParameter);
  25984. thingsToDelete.add ((void*) eff->processReplacing);
  25985. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25986. for (int i = thingsToDelete.size(); --i >= 0;)
  25987. disposeMachOFromCFM (thingsToDelete[i]);
  25988. }
  25989. else
  25990. #endif
  25991. {
  25992. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25993. }
  25994. }
  25995. #if JUCE_PPC
  25996. static void* newMachOFromCFM (void* cfmfp)
  25997. {
  25998. if (cfmfp == 0)
  25999. return 0;
  26000. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  26001. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  26002. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  26003. mfp[2] = 0x800c0000;
  26004. mfp[3] = 0x804c0004;
  26005. mfp[4] = 0x7c0903a6;
  26006. mfp[5] = 0x4e800420;
  26007. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  26008. return mfp;
  26009. }
  26010. static void disposeMachOFromCFM (void* ptr)
  26011. {
  26012. juce_free (ptr);
  26013. }
  26014. void coerceAEffectFunctionCalls (AEffect* eff)
  26015. {
  26016. if (fragId != 0)
  26017. {
  26018. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  26019. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  26020. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  26021. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  26022. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  26023. }
  26024. }
  26025. #endif
  26026. #endif
  26027. };
  26028. class VSTPluginInstance : public AudioPluginInstance,
  26029. private Timer,
  26030. private AsyncUpdater
  26031. {
  26032. public:
  26033. ~VSTPluginInstance();
  26034. // AudioPluginInstance methods:
  26035. void fillInPluginDescription (PluginDescription& desc) const
  26036. {
  26037. desc.name = name;
  26038. desc.fileOrIdentifier = module->file.getFullPathName();
  26039. desc.uid = getUID();
  26040. desc.lastFileModTime = module->file.getLastModificationTime();
  26041. desc.pluginFormatName = "VST";
  26042. desc.category = getCategory();
  26043. {
  26044. char buffer [kVstMaxVendorStrLen + 8];
  26045. zerostruct (buffer);
  26046. dispatch (effGetVendorString, 0, 0, buffer, 0);
  26047. desc.manufacturerName = buffer;
  26048. }
  26049. desc.version = getVersion();
  26050. desc.numInputChannels = getNumInputChannels();
  26051. desc.numOutputChannels = getNumOutputChannels();
  26052. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  26053. }
  26054. const String getName() const { return name; }
  26055. int getUID() const throw();
  26056. bool acceptsMidi() const { return wantsMidiMessages; }
  26057. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  26058. // AudioProcessor methods:
  26059. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  26060. void releaseResources();
  26061. void processBlock (AudioSampleBuffer& buffer,
  26062. MidiBuffer& midiMessages);
  26063. AudioProcessorEditor* createEditor();
  26064. const String getInputChannelName (const int index) const;
  26065. bool isInputChannelStereoPair (int index) const;
  26066. const String getOutputChannelName (const int index) const;
  26067. bool isOutputChannelStereoPair (int index) const;
  26068. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  26069. float getParameter (int index);
  26070. void setParameter (int index, float newValue);
  26071. const String getParameterName (int index);
  26072. const String getParameterText (int index);
  26073. bool isParameterAutomatable (int index) const;
  26074. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  26075. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  26076. void setCurrentProgram (int index);
  26077. const String getProgramName (int index);
  26078. void changeProgramName (int index, const String& newName);
  26079. void getStateInformation (MemoryBlock& destData);
  26080. void getCurrentProgramStateInformation (MemoryBlock& destData);
  26081. void setStateInformation (const void* data, int sizeInBytes);
  26082. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  26083. void timerCallback();
  26084. void handleAsyncUpdate();
  26085. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  26086. juce_UseDebuggingNewOperator
  26087. private:
  26088. friend class VSTPluginWindow;
  26089. friend class VSTPluginFormat;
  26090. AEffect* effect;
  26091. String name;
  26092. CriticalSection lock;
  26093. bool wantsMidiMessages, initialised, isPowerOn;
  26094. mutable StringArray programNames;
  26095. AudioSampleBuffer tempBuffer;
  26096. CriticalSection midiInLock;
  26097. MidiBuffer incomingMidi;
  26098. VSTMidiEventList midiEventsToSend;
  26099. VstTimeInfo vstHostTime;
  26100. HeapBlock <float*> channels;
  26101. ReferenceCountedObjectPtr <ModuleHandle> module;
  26102. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  26103. bool restoreProgramSettings (const fxProgram* const prog);
  26104. const String getCurrentProgramName();
  26105. void setParamsInProgramBlock (fxProgram* const prog) throw();
  26106. void updateStoredProgramNames();
  26107. void initialise();
  26108. void handleMidiFromPlugin (const VstEvents* const events);
  26109. void createTempParameterStore (MemoryBlock& dest);
  26110. void restoreFromTempParameterStore (const MemoryBlock& mb);
  26111. const String getParameterLabel (int index) const;
  26112. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  26113. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  26114. void setChunkData (const char* data, int size, bool isPreset);
  26115. bool loadFromFXBFile (const void* data, int numBytes);
  26116. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  26117. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  26118. const String getVersion() const throw();
  26119. const String getCategory() const throw();
  26120. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  26121. void setPower (const bool on);
  26122. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  26123. };
  26124. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  26125. : effect (0),
  26126. wantsMidiMessages (false),
  26127. initialised (false),
  26128. isPowerOn (false),
  26129. tempBuffer (1, 1),
  26130. module (module_)
  26131. {
  26132. try
  26133. {
  26134. _fpreset();
  26135. ++insideVSTCallback;
  26136. name = module->pluginName;
  26137. log (T("Creating VST instance: ") + name);
  26138. #if JUCE_MAC
  26139. if (module->resFileId != 0)
  26140. UseResFile (module->resFileId);
  26141. #if JUCE_PPC
  26142. if (module->fragId != 0)
  26143. {
  26144. static void* audioMasterCoerced = 0;
  26145. if (audioMasterCoerced == 0)
  26146. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  26147. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  26148. }
  26149. else
  26150. #endif
  26151. #endif
  26152. {
  26153. effect = module->moduleMain (&audioMaster);
  26154. }
  26155. --insideVSTCallback;
  26156. if (effect != 0 && effect->magic == kEffectMagic)
  26157. {
  26158. #if JUCE_PPC
  26159. module->coerceAEffectFunctionCalls (effect);
  26160. #endif
  26161. jassert (effect->resvd2 == 0);
  26162. jassert (effect->object != 0);
  26163. _fpreset(); // some dodgy plugs fuck around with this
  26164. }
  26165. else
  26166. {
  26167. effect = 0;
  26168. }
  26169. }
  26170. catch (...)
  26171. {
  26172. --insideVSTCallback;
  26173. }
  26174. }
  26175. VSTPluginInstance::~VSTPluginInstance()
  26176. {
  26177. {
  26178. const ScopedLock sl (lock);
  26179. jassert (insideVSTCallback == 0);
  26180. if (effect != 0 && effect->magic == kEffectMagic)
  26181. {
  26182. try
  26183. {
  26184. #if JUCE_MAC
  26185. if (module->resFileId != 0)
  26186. UseResFile (module->resFileId);
  26187. #endif
  26188. // Must delete any editors before deleting the plugin instance!
  26189. jassert (getActiveEditor() == 0);
  26190. _fpreset(); // some dodgy plugs fuck around with this
  26191. module->closeEffect (effect);
  26192. }
  26193. catch (...)
  26194. {}
  26195. }
  26196. module = 0;
  26197. effect = 0;
  26198. }
  26199. }
  26200. void VSTPluginInstance::initialise()
  26201. {
  26202. if (initialised || effect == 0)
  26203. return;
  26204. log (T("Initialising VST: ") + module->pluginName);
  26205. initialised = true;
  26206. dispatch (effIdentify, 0, 0, 0, 0);
  26207. // this code would ask the plugin for its name, but so few plugins
  26208. // actually bother implementing this correctly, that it's better to
  26209. // just ignore it and use the file name instead.
  26210. if (getSampleRate() > 0)
  26211. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  26212. if (getBlockSize() > 0)
  26213. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  26214. dispatch (effOpen, 0, 0, 0, 0);
  26215. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26216. getSampleRate(), getBlockSize());
  26217. if (getNumPrograms() > 1)
  26218. setCurrentProgram (0);
  26219. else
  26220. dispatch (effSetProgram, 0, 0, 0, 0);
  26221. int i;
  26222. for (i = effect->numInputs; --i >= 0;)
  26223. dispatch (effConnectInput, i, 1, 0, 0);
  26224. for (i = effect->numOutputs; --i >= 0;)
  26225. dispatch (effConnectOutput, i, 1, 0, 0);
  26226. updateStoredProgramNames();
  26227. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  26228. setLatencySamples (effect->initialDelay);
  26229. }
  26230. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26231. int samplesPerBlockExpected)
  26232. {
  26233. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26234. sampleRate_, samplesPerBlockExpected);
  26235. setLatencySamples (effect->initialDelay);
  26236. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26237. vstHostTime.tempo = 120.0;
  26238. vstHostTime.timeSigNumerator = 4;
  26239. vstHostTime.timeSigDenominator = 4;
  26240. vstHostTime.sampleRate = sampleRate_;
  26241. vstHostTime.samplePos = 0;
  26242. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26243. initialise();
  26244. if (initialised)
  26245. {
  26246. wantsMidiMessages = wantsMidiMessages
  26247. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26248. if (wantsMidiMessages)
  26249. midiEventsToSend.ensureSize (256);
  26250. else
  26251. midiEventsToSend.freeEvents();
  26252. incomingMidi.clear();
  26253. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26254. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26255. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26256. if (! isPowerOn)
  26257. setPower (true);
  26258. // dodgy hack to force some plugins to initialise the sample rate..
  26259. if ((! hasEditor()) && getNumParameters() > 0)
  26260. {
  26261. const float old = getParameter (0);
  26262. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26263. setParameter (0, old);
  26264. }
  26265. dispatch (effStartProcess, 0, 0, 0, 0);
  26266. }
  26267. }
  26268. void VSTPluginInstance::releaseResources()
  26269. {
  26270. if (initialised)
  26271. {
  26272. dispatch (effStopProcess, 0, 0, 0, 0);
  26273. setPower (false);
  26274. }
  26275. tempBuffer.setSize (1, 1);
  26276. incomingMidi.clear();
  26277. midiEventsToSend.freeEvents();
  26278. channels.free();
  26279. }
  26280. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26281. MidiBuffer& midiMessages)
  26282. {
  26283. const int numSamples = buffer.getNumSamples();
  26284. if (initialised)
  26285. {
  26286. AudioPlayHead* playHead = getPlayHead();
  26287. if (playHead != 0)
  26288. {
  26289. AudioPlayHead::CurrentPositionInfo position;
  26290. playHead->getCurrentPosition (position);
  26291. vstHostTime.tempo = position.bpm;
  26292. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26293. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26294. vstHostTime.ppqPos = position.ppqPosition;
  26295. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26296. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26297. if (position.isPlaying)
  26298. vstHostTime.flags |= kVstTransportPlaying;
  26299. else
  26300. vstHostTime.flags &= ~kVstTransportPlaying;
  26301. }
  26302. #if JUCE_WIN32
  26303. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26304. #elif JUCE_LINUX
  26305. timeval micro;
  26306. gettimeofday (&micro, 0);
  26307. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26308. #elif JUCE_MAC
  26309. UnsignedWide micro;
  26310. Microseconds (&micro);
  26311. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26312. #endif
  26313. if (wantsMidiMessages)
  26314. {
  26315. midiEventsToSend.clear();
  26316. midiEventsToSend.ensureSize (1);
  26317. MidiBuffer::Iterator iter (midiMessages);
  26318. const uint8* midiData;
  26319. int numBytesOfMidiData, samplePosition;
  26320. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26321. {
  26322. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26323. jlimit (0, numSamples - 1, samplePosition));
  26324. }
  26325. try
  26326. {
  26327. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26328. }
  26329. catch (...)
  26330. {}
  26331. }
  26332. int i;
  26333. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26334. for (i = 0; i < maxChans; ++i)
  26335. channels[i] = buffer.getSampleData (i);
  26336. channels [maxChans] = 0;
  26337. _clearfp();
  26338. if ((effect->flags & effFlagsCanReplacing) != 0)
  26339. {
  26340. try
  26341. {
  26342. effect->processReplacing (effect, channels, channels, numSamples);
  26343. }
  26344. catch (...)
  26345. {}
  26346. }
  26347. else
  26348. {
  26349. tempBuffer.setSize (effect->numOutputs, numSamples);
  26350. tempBuffer.clear();
  26351. float* outs [64];
  26352. for (i = effect->numOutputs; --i >= 0;)
  26353. outs[i] = tempBuffer.getSampleData (i);
  26354. outs [effect->numOutputs] = 0;
  26355. try
  26356. {
  26357. effect->process (effect, channels, outs, numSamples);
  26358. }
  26359. catch (...)
  26360. {}
  26361. for (i = effect->numOutputs; --i >= 0;)
  26362. buffer.copyFrom (i, 0, outs[i], numSamples);
  26363. }
  26364. }
  26365. else
  26366. {
  26367. // Not initialised, so just bypass..
  26368. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26369. buffer.clear (i, 0, buffer.getNumSamples());
  26370. }
  26371. {
  26372. // copy any incoming midi..
  26373. const ScopedLock sl (midiInLock);
  26374. midiMessages = incomingMidi;
  26375. incomingMidi.clear();
  26376. }
  26377. }
  26378. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26379. {
  26380. if (events != 0)
  26381. {
  26382. const ScopedLock sl (midiInLock);
  26383. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26384. }
  26385. }
  26386. static Array <VSTPluginWindow*> activeVSTWindows;
  26387. class VSTPluginWindow : public AudioProcessorEditor,
  26388. #if ! JUCE_MAC
  26389. public ComponentMovementWatcher,
  26390. #endif
  26391. public Timer
  26392. {
  26393. public:
  26394. VSTPluginWindow (VSTPluginInstance& plugin_)
  26395. : AudioProcessorEditor (&plugin_),
  26396. #if ! JUCE_MAC
  26397. ComponentMovementWatcher (this),
  26398. #endif
  26399. plugin (plugin_),
  26400. isOpen (false),
  26401. wasShowing (false),
  26402. pluginRefusesToResize (false),
  26403. pluginWantsKeys (false),
  26404. alreadyInside (false),
  26405. recursiveResize (false)
  26406. {
  26407. #if JUCE_WIN32
  26408. sizeCheckCount = 0;
  26409. pluginHWND = 0;
  26410. #elif JUCE_LINUX
  26411. pluginWindow = None;
  26412. pluginProc = None;
  26413. #else
  26414. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26415. #endif
  26416. activeVSTWindows.add (this);
  26417. setSize (1, 1);
  26418. setOpaque (true);
  26419. setVisible (true);
  26420. }
  26421. ~VSTPluginWindow()
  26422. {
  26423. #if JUCE_MAC
  26424. innerWrapper = 0;
  26425. #else
  26426. closePluginWindow();
  26427. #endif
  26428. activeVSTWindows.removeValue (this);
  26429. plugin.editorBeingDeleted (this);
  26430. }
  26431. #if ! JUCE_MAC
  26432. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26433. {
  26434. if (recursiveResize)
  26435. return;
  26436. Component* const topComp = getTopLevelComponent();
  26437. if (topComp->getPeer() != 0)
  26438. {
  26439. int x = 0, y = 0;
  26440. relativePositionToOtherComponent (topComp, x, y);
  26441. recursiveResize = true;
  26442. #if JUCE_WIN32
  26443. if (pluginHWND != 0)
  26444. MoveWindow (pluginHWND, x, y, getWidth(), getHeight(), TRUE);
  26445. #elif JUCE_LINUX
  26446. if (pluginWindow != 0)
  26447. {
  26448. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26449. XMoveWindow (display, pluginWindow, x, y);
  26450. XMapRaised (display, pluginWindow);
  26451. }
  26452. #endif
  26453. recursiveResize = false;
  26454. }
  26455. }
  26456. void componentVisibilityChanged (Component&)
  26457. {
  26458. const bool isShowingNow = isShowing();
  26459. if (wasShowing != isShowingNow)
  26460. {
  26461. wasShowing = isShowingNow;
  26462. if (isShowingNow)
  26463. openPluginWindow();
  26464. else
  26465. closePluginWindow();
  26466. }
  26467. componentMovedOrResized (true, true);
  26468. }
  26469. void componentPeerChanged()
  26470. {
  26471. closePluginWindow();
  26472. openPluginWindow();
  26473. }
  26474. #endif
  26475. bool keyStateChanged (const bool)
  26476. {
  26477. return pluginWantsKeys;
  26478. }
  26479. bool keyPressed (const KeyPress&)
  26480. {
  26481. return pluginWantsKeys;
  26482. }
  26483. #if JUCE_MAC
  26484. void paint (Graphics& g)
  26485. {
  26486. g.fillAll (Colours::black);
  26487. }
  26488. #else
  26489. void paint (Graphics& g)
  26490. {
  26491. if (isOpen)
  26492. {
  26493. ComponentPeer* const peer = getPeer();
  26494. if (peer != 0)
  26495. {
  26496. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  26497. getScreenY() - peer->getScreenY(),
  26498. getWidth(), getHeight());
  26499. #if JUCE_LINUX
  26500. if (pluginWindow != 0)
  26501. {
  26502. const Rectangle<int> clip (g.getClipBounds());
  26503. XEvent ev;
  26504. zerostruct (ev);
  26505. ev.xexpose.type = Expose;
  26506. ev.xexpose.display = display;
  26507. ev.xexpose.window = pluginWindow;
  26508. ev.xexpose.x = clip.getX();
  26509. ev.xexpose.y = clip.getY();
  26510. ev.xexpose.width = clip.getWidth();
  26511. ev.xexpose.height = clip.getHeight();
  26512. sendEventToChild (&ev);
  26513. }
  26514. #endif
  26515. }
  26516. }
  26517. else
  26518. {
  26519. g.fillAll (Colours::black);
  26520. }
  26521. }
  26522. #endif
  26523. void timerCallback()
  26524. {
  26525. #if JUCE_WIN32
  26526. if (--sizeCheckCount <= 0)
  26527. {
  26528. sizeCheckCount = 10;
  26529. checkPluginWindowSize();
  26530. }
  26531. #endif
  26532. try
  26533. {
  26534. static bool reentrant = false;
  26535. if (! reentrant)
  26536. {
  26537. reentrant = true;
  26538. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26539. reentrant = false;
  26540. }
  26541. }
  26542. catch (...)
  26543. {}
  26544. }
  26545. void mouseDown (const MouseEvent& e)
  26546. {
  26547. #if JUCE_LINUX
  26548. if (pluginWindow == 0)
  26549. return;
  26550. toFront (true);
  26551. XEvent ev;
  26552. zerostruct (ev);
  26553. ev.xbutton.display = display;
  26554. ev.xbutton.type = ButtonPress;
  26555. ev.xbutton.window = pluginWindow;
  26556. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26557. ev.xbutton.time = CurrentTime;
  26558. ev.xbutton.x = e.x;
  26559. ev.xbutton.y = e.y;
  26560. ev.xbutton.x_root = e.getScreenX();
  26561. ev.xbutton.y_root = e.getScreenY();
  26562. translateJuceToXButtonModifiers (e, ev);
  26563. sendEventToChild (&ev);
  26564. #elif JUCE_WIN32
  26565. (void) e;
  26566. toFront (true);
  26567. #endif
  26568. }
  26569. void broughtToFront()
  26570. {
  26571. activeVSTWindows.removeValue (this);
  26572. activeVSTWindows.add (this);
  26573. #if JUCE_MAC
  26574. dispatch (effEditTop, 0, 0, 0, 0);
  26575. #endif
  26576. }
  26577. juce_UseDebuggingNewOperator
  26578. private:
  26579. VSTPluginInstance& plugin;
  26580. bool isOpen, wasShowing, recursiveResize;
  26581. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26582. #if JUCE_WIN32
  26583. HWND pluginHWND;
  26584. void* originalWndProc;
  26585. int sizeCheckCount;
  26586. #elif JUCE_LINUX
  26587. Window pluginWindow;
  26588. EventProcPtr pluginProc;
  26589. #endif
  26590. #if JUCE_MAC
  26591. void openPluginWindow (WindowRef parentWindow)
  26592. {
  26593. if (isOpen || parentWindow == 0)
  26594. return;
  26595. isOpen = true;
  26596. ERect* rect = 0;
  26597. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26598. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26599. // do this before and after like in the steinberg example
  26600. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26601. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26602. // Install keyboard hooks
  26603. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26604. // double-check it's not too tiny
  26605. int w = 250, h = 150;
  26606. if (rect != 0)
  26607. {
  26608. w = rect->right - rect->left;
  26609. h = rect->bottom - rect->top;
  26610. if (w == 0 || h == 0)
  26611. {
  26612. w = 250;
  26613. h = 150;
  26614. }
  26615. }
  26616. w = jmax (w, 32);
  26617. h = jmax (h, 32);
  26618. setSize (w, h);
  26619. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26620. repaint();
  26621. }
  26622. #else
  26623. void openPluginWindow()
  26624. {
  26625. if (isOpen || getWindowHandle() == 0)
  26626. return;
  26627. log (T("Opening VST UI: ") + plugin.name);
  26628. isOpen = true;
  26629. ERect* rect = 0;
  26630. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26631. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26632. // do this before and after like in the steinberg example
  26633. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26634. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26635. // Install keyboard hooks
  26636. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26637. #if JUCE_WIN32
  26638. originalWndProc = 0;
  26639. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26640. if (pluginHWND == 0)
  26641. {
  26642. isOpen = false;
  26643. setSize (300, 150);
  26644. return;
  26645. }
  26646. #pragma warning (push)
  26647. #pragma warning (disable: 4244)
  26648. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26649. if (! pluginWantsKeys)
  26650. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26651. #pragma warning (pop)
  26652. int w, h;
  26653. RECT r;
  26654. GetWindowRect (pluginHWND, &r);
  26655. w = r.right - r.left;
  26656. h = r.bottom - r.top;
  26657. if (rect != 0)
  26658. {
  26659. const int rw = rect->right - rect->left;
  26660. const int rh = rect->bottom - rect->top;
  26661. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26662. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26663. {
  26664. // very dodgy logic to decide which size is right.
  26665. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26666. {
  26667. SetWindowPos (pluginHWND, 0,
  26668. 0, 0, rw, rh,
  26669. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26670. GetWindowRect (pluginHWND, &r);
  26671. w = r.right - r.left;
  26672. h = r.bottom - r.top;
  26673. pluginRefusesToResize = (w != rw) || (h != rh);
  26674. w = rw;
  26675. h = rh;
  26676. }
  26677. }
  26678. }
  26679. #elif JUCE_LINUX
  26680. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26681. if (pluginWindow != 0)
  26682. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26683. XInternAtom (display, "_XEventProc", False));
  26684. int w = 250, h = 150;
  26685. if (rect != 0)
  26686. {
  26687. w = rect->right - rect->left;
  26688. h = rect->bottom - rect->top;
  26689. if (w == 0 || h == 0)
  26690. {
  26691. w = 250;
  26692. h = 150;
  26693. }
  26694. }
  26695. if (pluginWindow != 0)
  26696. XMapRaised (display, pluginWindow);
  26697. #endif
  26698. // double-check it's not too tiny
  26699. w = jmax (w, 32);
  26700. h = jmax (h, 32);
  26701. setSize (w, h);
  26702. #if JUCE_WIN32
  26703. checkPluginWindowSize();
  26704. #endif
  26705. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26706. repaint();
  26707. }
  26708. #endif
  26709. #if ! JUCE_MAC
  26710. void closePluginWindow()
  26711. {
  26712. if (isOpen)
  26713. {
  26714. log (T("Closing VST UI: ") + plugin.getName());
  26715. isOpen = false;
  26716. dispatch (effEditClose, 0, 0, 0, 0);
  26717. #if JUCE_WIN32
  26718. #pragma warning (push)
  26719. #pragma warning (disable: 4244)
  26720. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26721. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26722. #pragma warning (pop)
  26723. stopTimer();
  26724. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26725. DestroyWindow (pluginHWND);
  26726. pluginHWND = 0;
  26727. #elif JUCE_LINUX
  26728. stopTimer();
  26729. pluginWindow = 0;
  26730. pluginProc = 0;
  26731. #endif
  26732. }
  26733. }
  26734. #endif
  26735. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26736. {
  26737. return plugin.dispatch (opcode, index, value, ptr, opt);
  26738. }
  26739. #if JUCE_WIN32
  26740. void checkPluginWindowSize() throw()
  26741. {
  26742. RECT r;
  26743. GetWindowRect (pluginHWND, &r);
  26744. const int w = r.right - r.left;
  26745. const int h = r.bottom - r.top;
  26746. if (isShowing() && w > 0 && h > 0
  26747. && (w != getWidth() || h != getHeight())
  26748. && ! pluginRefusesToResize)
  26749. {
  26750. setSize (w, h);
  26751. sizeCheckCount = 0;
  26752. }
  26753. }
  26754. // hooks to get keyboard events from VST windows..
  26755. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26756. {
  26757. for (int i = activeVSTWindows.size(); --i >= 0;)
  26758. {
  26759. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26760. if (w->pluginHWND == hW)
  26761. {
  26762. if (message == WM_CHAR
  26763. || message == WM_KEYDOWN
  26764. || message == WM_SYSKEYDOWN
  26765. || message == WM_KEYUP
  26766. || message == WM_SYSKEYUP
  26767. || message == WM_APPCOMMAND)
  26768. {
  26769. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26770. message, wParam, lParam);
  26771. }
  26772. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26773. (HWND) w->pluginHWND,
  26774. message,
  26775. wParam,
  26776. lParam);
  26777. }
  26778. }
  26779. return DefWindowProc (hW, message, wParam, lParam);
  26780. }
  26781. #endif
  26782. #if JUCE_LINUX
  26783. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26784. void sendEventToChild (XEvent* event)
  26785. {
  26786. if (pluginProc != 0)
  26787. {
  26788. // if the plugin publishes an event procedure, pass the event directly..
  26789. pluginProc (event);
  26790. }
  26791. else if (pluginWindow != 0)
  26792. {
  26793. // if the plugin has a window, then send the event to the window so that
  26794. // its message thread will pick it up..
  26795. XSendEvent (display, pluginWindow, False, 0L, event);
  26796. XFlush (display);
  26797. }
  26798. }
  26799. void mouseEnter (const MouseEvent& e)
  26800. {
  26801. if (pluginWindow != 0)
  26802. {
  26803. XEvent ev;
  26804. zerostruct (ev);
  26805. ev.xcrossing.display = display;
  26806. ev.xcrossing.type = EnterNotify;
  26807. ev.xcrossing.window = pluginWindow;
  26808. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26809. ev.xcrossing.time = CurrentTime;
  26810. ev.xcrossing.x = e.x;
  26811. ev.xcrossing.y = e.y;
  26812. ev.xcrossing.x_root = e.getScreenX();
  26813. ev.xcrossing.y_root = e.getScreenY();
  26814. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26815. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26816. translateJuceToXCrossingModifiers (e, ev);
  26817. sendEventToChild (&ev);
  26818. }
  26819. }
  26820. void mouseExit (const MouseEvent& e)
  26821. {
  26822. if (pluginWindow != 0)
  26823. {
  26824. XEvent ev;
  26825. zerostruct (ev);
  26826. ev.xcrossing.display = display;
  26827. ev.xcrossing.type = LeaveNotify;
  26828. ev.xcrossing.window = pluginWindow;
  26829. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26830. ev.xcrossing.time = CurrentTime;
  26831. ev.xcrossing.x = e.x;
  26832. ev.xcrossing.y = e.y;
  26833. ev.xcrossing.x_root = e.getScreenX();
  26834. ev.xcrossing.y_root = e.getScreenY();
  26835. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26836. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26837. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26838. translateJuceToXCrossingModifiers (e, ev);
  26839. sendEventToChild (&ev);
  26840. }
  26841. }
  26842. void mouseMove (const MouseEvent& e)
  26843. {
  26844. if (pluginWindow != 0)
  26845. {
  26846. XEvent ev;
  26847. zerostruct (ev);
  26848. ev.xmotion.display = display;
  26849. ev.xmotion.type = MotionNotify;
  26850. ev.xmotion.window = pluginWindow;
  26851. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26852. ev.xmotion.time = CurrentTime;
  26853. ev.xmotion.is_hint = NotifyNormal;
  26854. ev.xmotion.x = e.x;
  26855. ev.xmotion.y = e.y;
  26856. ev.xmotion.x_root = e.getScreenX();
  26857. ev.xmotion.y_root = e.getScreenY();
  26858. sendEventToChild (&ev);
  26859. }
  26860. }
  26861. void mouseDrag (const MouseEvent& e)
  26862. {
  26863. if (pluginWindow != 0)
  26864. {
  26865. XEvent ev;
  26866. zerostruct (ev);
  26867. ev.xmotion.display = display;
  26868. ev.xmotion.type = MotionNotify;
  26869. ev.xmotion.window = pluginWindow;
  26870. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26871. ev.xmotion.time = CurrentTime;
  26872. ev.xmotion.x = e.x ;
  26873. ev.xmotion.y = e.y;
  26874. ev.xmotion.x_root = e.getScreenX();
  26875. ev.xmotion.y_root = e.getScreenY();
  26876. ev.xmotion.is_hint = NotifyNormal;
  26877. translateJuceToXMotionModifiers (e, ev);
  26878. sendEventToChild (&ev);
  26879. }
  26880. }
  26881. void mouseUp (const MouseEvent& e)
  26882. {
  26883. if (pluginWindow != 0)
  26884. {
  26885. XEvent ev;
  26886. zerostruct (ev);
  26887. ev.xbutton.display = display;
  26888. ev.xbutton.type = ButtonRelease;
  26889. ev.xbutton.window = pluginWindow;
  26890. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26891. ev.xbutton.time = CurrentTime;
  26892. ev.xbutton.x = e.x;
  26893. ev.xbutton.y = e.y;
  26894. ev.xbutton.x_root = e.getScreenX();
  26895. ev.xbutton.y_root = e.getScreenY();
  26896. translateJuceToXButtonModifiers (e, ev);
  26897. sendEventToChild (&ev);
  26898. }
  26899. }
  26900. void mouseWheelMove (const MouseEvent& e,
  26901. float incrementX,
  26902. float incrementY)
  26903. {
  26904. if (pluginWindow != 0)
  26905. {
  26906. XEvent ev;
  26907. zerostruct (ev);
  26908. ev.xbutton.display = display;
  26909. ev.xbutton.type = ButtonPress;
  26910. ev.xbutton.window = pluginWindow;
  26911. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26912. ev.xbutton.time = CurrentTime;
  26913. ev.xbutton.x = e.x;
  26914. ev.xbutton.y = e.y;
  26915. ev.xbutton.x_root = e.getScreenX();
  26916. ev.xbutton.y_root = e.getScreenY();
  26917. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26918. sendEventToChild (&ev);
  26919. // TODO - put a usleep here ?
  26920. ev.xbutton.type = ButtonRelease;
  26921. sendEventToChild (&ev);
  26922. }
  26923. }
  26924. #endif
  26925. #if JUCE_MAC
  26926. #if ! JUCE_SUPPORT_CARBON
  26927. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26928. #endif
  26929. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26930. {
  26931. public:
  26932. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26933. : owner (owner_),
  26934. alreadyInside (false)
  26935. {
  26936. }
  26937. ~InnerWrapperComponent()
  26938. {
  26939. deleteWindow();
  26940. }
  26941. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26942. {
  26943. owner->openPluginWindow (windowRef);
  26944. return 0;
  26945. }
  26946. void removeView (HIViewRef)
  26947. {
  26948. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26949. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26950. }
  26951. bool getEmbeddedViewSize (int& w, int& h)
  26952. {
  26953. ERect* rect = 0;
  26954. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26955. w = rect->right - rect->left;
  26956. h = rect->bottom - rect->top;
  26957. return true;
  26958. }
  26959. void mouseDown (int x, int y)
  26960. {
  26961. if (! alreadyInside)
  26962. {
  26963. alreadyInside = true;
  26964. getTopLevelComponent()->toFront (true);
  26965. owner->dispatch (effEditMouse, x, y, 0, 0);
  26966. alreadyInside = false;
  26967. }
  26968. else
  26969. {
  26970. PostEvent (::mouseDown, 0);
  26971. }
  26972. }
  26973. void paint()
  26974. {
  26975. ComponentPeer* const peer = getPeer();
  26976. if (peer != 0)
  26977. {
  26978. ERect r;
  26979. r.left = getScreenX() - peer->getScreenX();
  26980. r.right = r.left + getWidth();
  26981. r.top = getScreenY() - peer->getScreenY();
  26982. r.bottom = r.top + getHeight();
  26983. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26984. }
  26985. }
  26986. private:
  26987. VSTPluginWindow* const owner;
  26988. bool alreadyInside;
  26989. };
  26990. friend class InnerWrapperComponent;
  26991. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26992. void resized()
  26993. {
  26994. innerWrapper->setSize (getWidth(), getHeight());
  26995. }
  26996. #endif
  26997. };
  26998. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26999. {
  27000. if (hasEditor())
  27001. return new VSTPluginWindow (*this);
  27002. return 0;
  27003. }
  27004. void VSTPluginInstance::handleAsyncUpdate()
  27005. {
  27006. // indicates that something about the plugin has changed..
  27007. updateHostDisplay();
  27008. }
  27009. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  27010. {
  27011. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  27012. {
  27013. changeProgramName (getCurrentProgram(), prog->prgName);
  27014. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  27015. setParameter (i, vst_swapFloat (prog->params[i]));
  27016. return true;
  27017. }
  27018. return false;
  27019. }
  27020. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  27021. const int dataSize)
  27022. {
  27023. if (dataSize < 28)
  27024. return false;
  27025. const fxSet* const set = (const fxSet*) data;
  27026. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  27027. || vst_swap (set->version) > fxbVersionNum)
  27028. return false;
  27029. if (vst_swap (set->fxMagic) == 'FxBk')
  27030. {
  27031. // bank of programs
  27032. if (vst_swap (set->numPrograms) >= 0)
  27033. {
  27034. const int oldProg = getCurrentProgram();
  27035. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  27036. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27037. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  27038. {
  27039. if (i != oldProg)
  27040. {
  27041. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  27042. if (((const char*) prog) - ((const char*) set) >= dataSize)
  27043. return false;
  27044. if (vst_swap (set->numPrograms) > 0)
  27045. setCurrentProgram (i);
  27046. if (! restoreProgramSettings (prog))
  27047. return false;
  27048. }
  27049. }
  27050. if (vst_swap (set->numPrograms) > 0)
  27051. setCurrentProgram (oldProg);
  27052. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  27053. if (((const char*) prog) - ((const char*) set) >= dataSize)
  27054. return false;
  27055. if (! restoreProgramSettings (prog))
  27056. return false;
  27057. }
  27058. }
  27059. else if (vst_swap (set->fxMagic) == 'FxCk')
  27060. {
  27061. // single program
  27062. const fxProgram* const prog = (const fxProgram*) data;
  27063. if (vst_swap (prog->chunkMagic) != 'CcnK')
  27064. return false;
  27065. changeProgramName (getCurrentProgram(), prog->prgName);
  27066. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  27067. setParameter (i, vst_swapFloat (prog->params[i]));
  27068. }
  27069. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  27070. {
  27071. // non-preset chunk
  27072. const fxChunkSet* const cset = (const fxChunkSet*) data;
  27073. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  27074. return false;
  27075. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  27076. }
  27077. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  27078. {
  27079. // preset chunk
  27080. const fxProgramSet* const cset = (const fxProgramSet*) data;
  27081. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  27082. return false;
  27083. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  27084. changeProgramName (getCurrentProgram(), cset->name);
  27085. }
  27086. else
  27087. {
  27088. return false;
  27089. }
  27090. return true;
  27091. }
  27092. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  27093. {
  27094. const int numParams = getNumParameters();
  27095. prog->chunkMagic = vst_swap ('CcnK');
  27096. prog->byteSize = 0;
  27097. prog->fxMagic = vst_swap ('FxCk');
  27098. prog->version = vst_swap (fxbVersionNum);
  27099. prog->fxID = vst_swap (getUID());
  27100. prog->fxVersion = vst_swap (getVersionNumber());
  27101. prog->numParams = vst_swap (numParams);
  27102. getCurrentProgramName().copyToBuffer (prog->prgName, sizeof (prog->prgName) - 1);
  27103. for (int i = 0; i < numParams; ++i)
  27104. prog->params[i] = vst_swapFloat (getParameter (i));
  27105. }
  27106. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  27107. {
  27108. const int numPrograms = getNumPrograms();
  27109. const int numParams = getNumParameters();
  27110. if (usesChunks())
  27111. {
  27112. if (isFXB)
  27113. {
  27114. MemoryBlock chunk;
  27115. getChunkData (chunk, false, maxSizeMB);
  27116. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  27117. dest.setSize (totalLen, true);
  27118. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  27119. set->chunkMagic = vst_swap ('CcnK');
  27120. set->byteSize = 0;
  27121. set->fxMagic = vst_swap ('FBCh');
  27122. set->version = vst_swap (fxbVersionNum);
  27123. set->fxID = vst_swap (getUID());
  27124. set->fxVersion = vst_swap (getVersionNumber());
  27125. set->numPrograms = vst_swap (numPrograms);
  27126. set->chunkSize = vst_swap ((long) chunk.getSize());
  27127. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27128. }
  27129. else
  27130. {
  27131. MemoryBlock chunk;
  27132. getChunkData (chunk, true, maxSizeMB);
  27133. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  27134. dest.setSize (totalLen, true);
  27135. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  27136. set->chunkMagic = vst_swap ('CcnK');
  27137. set->byteSize = 0;
  27138. set->fxMagic = vst_swap ('FPCh');
  27139. set->version = vst_swap (fxbVersionNum);
  27140. set->fxID = vst_swap (getUID());
  27141. set->fxVersion = vst_swap (getVersionNumber());
  27142. set->numPrograms = vst_swap (numPrograms);
  27143. set->chunkSize = vst_swap ((long) chunk.getSize());
  27144. getCurrentProgramName().copyToBuffer (set->name, sizeof (set->name) - 1);
  27145. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27146. }
  27147. }
  27148. else
  27149. {
  27150. if (isFXB)
  27151. {
  27152. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27153. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  27154. dest.setSize (len, true);
  27155. fxSet* const set = (fxSet*) dest.getData();
  27156. set->chunkMagic = vst_swap ('CcnK');
  27157. set->byteSize = 0;
  27158. set->fxMagic = vst_swap ('FxBk');
  27159. set->version = vst_swap (fxbVersionNum);
  27160. set->fxID = vst_swap (getUID());
  27161. set->fxVersion = vst_swap (getVersionNumber());
  27162. set->numPrograms = vst_swap (numPrograms);
  27163. const int oldProgram = getCurrentProgram();
  27164. MemoryBlock oldSettings;
  27165. createTempParameterStore (oldSettings);
  27166. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  27167. for (int i = 0; i < numPrograms; ++i)
  27168. {
  27169. if (i != oldProgram)
  27170. {
  27171. setCurrentProgram (i);
  27172. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  27173. }
  27174. }
  27175. setCurrentProgram (oldProgram);
  27176. restoreFromTempParameterStore (oldSettings);
  27177. }
  27178. else
  27179. {
  27180. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27181. dest.setSize (totalLen, true);
  27182. setParamsInProgramBlock ((fxProgram*) dest.getData());
  27183. }
  27184. }
  27185. return true;
  27186. }
  27187. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  27188. {
  27189. if (usesChunks())
  27190. {
  27191. void* data = 0;
  27192. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  27193. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  27194. {
  27195. mb.setSize (bytes);
  27196. mb.copyFrom (data, 0, bytes);
  27197. }
  27198. }
  27199. }
  27200. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  27201. {
  27202. if (size > 0 && usesChunks())
  27203. {
  27204. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  27205. if (! isPreset)
  27206. updateStoredProgramNames();
  27207. }
  27208. }
  27209. void VSTPluginInstance::timerCallback()
  27210. {
  27211. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  27212. stopTimer();
  27213. }
  27214. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  27215. {
  27216. const ScopedLock sl (lock);
  27217. ++insideVSTCallback;
  27218. int result = 0;
  27219. try
  27220. {
  27221. if (effect != 0)
  27222. {
  27223. #if JUCE_MAC
  27224. if (module->resFileId != 0)
  27225. UseResFile (module->resFileId);
  27226. CGrafPtr oldPort;
  27227. if (getActiveEditor() != 0)
  27228. {
  27229. int x = 0, y = 0;
  27230. getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), x, y);
  27231. GetPort (&oldPort);
  27232. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27233. SetOrigin (-x, -y);
  27234. }
  27235. #endif
  27236. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27237. #if JUCE_MAC
  27238. if (getActiveEditor() != 0)
  27239. SetPort (oldPort);
  27240. module->resFileId = CurResFile();
  27241. #endif
  27242. --insideVSTCallback;
  27243. return result;
  27244. }
  27245. }
  27246. catch (...)
  27247. {
  27248. //char s[512];
  27249. //sprintf (s, "dispatcher (%d, %d, %d, %x, %f)", opcode, index, value, (int)ptr, opt);
  27250. }
  27251. --insideVSTCallback;
  27252. return result;
  27253. }
  27254. // handles non plugin-specific callbacks..
  27255. static const int defaultVSTSampleRateValue = 16384;
  27256. static const int defaultVSTBlockSizeValue = 512;
  27257. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27258. {
  27259. (void) index;
  27260. (void) value;
  27261. (void) opt;
  27262. switch (opcode)
  27263. {
  27264. case audioMasterCanDo:
  27265. {
  27266. static const char* canDos[] = { "supplyIdle",
  27267. "sendVstEvents",
  27268. "sendVstMidiEvent",
  27269. "sendVstTimeInfo",
  27270. "receiveVstEvents",
  27271. "receiveVstMidiEvent",
  27272. "supportShell",
  27273. "shellCategory" };
  27274. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27275. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27276. return 1;
  27277. return 0;
  27278. }
  27279. case audioMasterVersion:
  27280. return 0x2400;
  27281. case audioMasterCurrentId:
  27282. return shellUIDToCreate;
  27283. case audioMasterGetNumAutomatableParameters:
  27284. return 0;
  27285. case audioMasterGetAutomationState:
  27286. return 1;
  27287. case audioMasterGetVendorVersion:
  27288. return 0x0101;
  27289. case audioMasterGetVendorString:
  27290. case audioMasterGetProductString:
  27291. {
  27292. String hostName ("Juce VST Host");
  27293. if (JUCEApplication::getInstance() != 0)
  27294. hostName = JUCEApplication::getInstance()->getApplicationName();
  27295. hostName.copyToBuffer ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27296. }
  27297. break;
  27298. case audioMasterGetSampleRate:
  27299. return (VstIntPtr) defaultVSTSampleRateValue;
  27300. case audioMasterGetBlockSize:
  27301. return (VstIntPtr) defaultVSTBlockSizeValue;
  27302. case audioMasterSetOutputSampleRate:
  27303. return 0;
  27304. default:
  27305. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27306. break;
  27307. }
  27308. return 0;
  27309. }
  27310. // handles callbacks for a specific plugin
  27311. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27312. {
  27313. switch (opcode)
  27314. {
  27315. case audioMasterAutomate:
  27316. sendParamChangeMessageToListeners (index, opt);
  27317. break;
  27318. case audioMasterProcessEvents:
  27319. handleMidiFromPlugin ((const VstEvents*) ptr);
  27320. break;
  27321. case audioMasterGetTime:
  27322. #ifdef _MSC_VER
  27323. #pragma warning (push)
  27324. #pragma warning (disable: 4311)
  27325. #endif
  27326. return (VstIntPtr) &vstHostTime;
  27327. #ifdef _MSC_VER
  27328. #pragma warning (pop)
  27329. #endif
  27330. break;
  27331. case audioMasterIdle:
  27332. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27333. {
  27334. ++insideVSTCallback;
  27335. #if JUCE_MAC
  27336. if (getActiveEditor() != 0)
  27337. dispatch (effEditIdle, 0, 0, 0, 0);
  27338. #endif
  27339. juce_callAnyTimersSynchronously();
  27340. handleUpdateNowIfNeeded();
  27341. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27342. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27343. --insideVSTCallback;
  27344. }
  27345. break;
  27346. case audioMasterUpdateDisplay:
  27347. triggerAsyncUpdate();
  27348. break;
  27349. case audioMasterTempoAt:
  27350. // returns (10000 * bpm)
  27351. break;
  27352. case audioMasterNeedIdle:
  27353. startTimer (50);
  27354. break;
  27355. case audioMasterSizeWindow:
  27356. if (getActiveEditor() != 0)
  27357. getActiveEditor()->setSize (index, value);
  27358. return 1;
  27359. case audioMasterGetSampleRate:
  27360. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27361. case audioMasterGetBlockSize:
  27362. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27363. case audioMasterWantMidi:
  27364. wantsMidiMessages = true;
  27365. break;
  27366. case audioMasterGetDirectory:
  27367. #if JUCE_MAC
  27368. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27369. #else
  27370. return (VstIntPtr) (pointer_sized_uint) (const char*) module->fullParentDirectoryPathName;
  27371. #endif
  27372. case audioMasterGetAutomationState:
  27373. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27374. break;
  27375. // none of these are handled (yet)..
  27376. case audioMasterBeginEdit:
  27377. case audioMasterEndEdit:
  27378. case audioMasterSetTime:
  27379. case audioMasterPinConnected:
  27380. case audioMasterGetParameterQuantization:
  27381. case audioMasterIOChanged:
  27382. case audioMasterGetInputLatency:
  27383. case audioMasterGetOutputLatency:
  27384. case audioMasterGetPreviousPlug:
  27385. case audioMasterGetNextPlug:
  27386. case audioMasterWillReplaceOrAccumulate:
  27387. case audioMasterGetCurrentProcessLevel:
  27388. case audioMasterOfflineStart:
  27389. case audioMasterOfflineRead:
  27390. case audioMasterOfflineWrite:
  27391. case audioMasterOfflineGetCurrentPass:
  27392. case audioMasterOfflineGetCurrentMetaPass:
  27393. case audioMasterVendorSpecific:
  27394. case audioMasterSetIcon:
  27395. case audioMasterGetLanguage:
  27396. case audioMasterOpenWindow:
  27397. case audioMasterCloseWindow:
  27398. break;
  27399. default:
  27400. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27401. }
  27402. return 0;
  27403. }
  27404. // entry point for all callbacks from the plugin
  27405. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27406. {
  27407. try
  27408. {
  27409. if (effect != 0 && effect->resvd2 != 0)
  27410. {
  27411. return ((VSTPluginInstance*)(effect->resvd2))
  27412. ->handleCallback (opcode, index, value, ptr, opt);
  27413. }
  27414. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27415. }
  27416. catch (...)
  27417. {
  27418. return 0;
  27419. }
  27420. }
  27421. const String VSTPluginInstance::getVersion() const throw()
  27422. {
  27423. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27424. String s;
  27425. if (v == 0 || v == -1)
  27426. v = getVersionNumber();
  27427. if (v != 0)
  27428. {
  27429. int versionBits[4];
  27430. int n = 0;
  27431. while (v != 0)
  27432. {
  27433. versionBits [n++] = (v & 0xff);
  27434. v >>= 8;
  27435. }
  27436. s << 'V';
  27437. while (n > 0)
  27438. {
  27439. s << versionBits [--n];
  27440. if (n > 0)
  27441. s << '.';
  27442. }
  27443. }
  27444. return s;
  27445. }
  27446. int VSTPluginInstance::getUID() const throw()
  27447. {
  27448. int uid = effect != 0 ? effect->uniqueID : 0;
  27449. if (uid == 0)
  27450. uid = module->file.hashCode();
  27451. return uid;
  27452. }
  27453. const String VSTPluginInstance::getCategory() const throw()
  27454. {
  27455. const char* result = 0;
  27456. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27457. {
  27458. case kPlugCategEffect:
  27459. result = "Effect";
  27460. break;
  27461. case kPlugCategSynth:
  27462. result = "Synth";
  27463. break;
  27464. case kPlugCategAnalysis:
  27465. result = "Anaylsis";
  27466. break;
  27467. case kPlugCategMastering:
  27468. result = "Mastering";
  27469. break;
  27470. case kPlugCategSpacializer:
  27471. result = "Spacial";
  27472. break;
  27473. case kPlugCategRoomFx:
  27474. result = "Reverb";
  27475. break;
  27476. case kPlugSurroundFx:
  27477. result = "Surround";
  27478. break;
  27479. case kPlugCategRestoration:
  27480. result = "Restoration";
  27481. break;
  27482. case kPlugCategGenerator:
  27483. result = "Tone generation";
  27484. break;
  27485. default:
  27486. break;
  27487. }
  27488. return result;
  27489. }
  27490. float VSTPluginInstance::getParameter (int index)
  27491. {
  27492. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27493. {
  27494. try
  27495. {
  27496. const ScopedLock sl (lock);
  27497. return effect->getParameter (effect, index);
  27498. }
  27499. catch (...)
  27500. {
  27501. }
  27502. }
  27503. return 0.0f;
  27504. }
  27505. void VSTPluginInstance::setParameter (int index, float newValue)
  27506. {
  27507. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27508. {
  27509. try
  27510. {
  27511. const ScopedLock sl (lock);
  27512. if (effect->getParameter (effect, index) != newValue)
  27513. effect->setParameter (effect, index, newValue);
  27514. }
  27515. catch (...)
  27516. {
  27517. }
  27518. }
  27519. }
  27520. const String VSTPluginInstance::getParameterName (int index)
  27521. {
  27522. if (effect != 0)
  27523. {
  27524. jassert (index >= 0 && index < effect->numParams);
  27525. char nm [256];
  27526. zerostruct (nm);
  27527. dispatch (effGetParamName, index, 0, nm, 0);
  27528. return String (nm).trim();
  27529. }
  27530. return String::empty;
  27531. }
  27532. const String VSTPluginInstance::getParameterLabel (int index) const
  27533. {
  27534. if (effect != 0)
  27535. {
  27536. jassert (index >= 0 && index < effect->numParams);
  27537. char nm [256];
  27538. zerostruct (nm);
  27539. dispatch (effGetParamLabel, index, 0, nm, 0);
  27540. return String (nm).trim();
  27541. }
  27542. return String::empty;
  27543. }
  27544. const String VSTPluginInstance::getParameterText (int index)
  27545. {
  27546. if (effect != 0)
  27547. {
  27548. jassert (index >= 0 && index < effect->numParams);
  27549. char nm [256];
  27550. zerostruct (nm);
  27551. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27552. return String (nm).trim();
  27553. }
  27554. return String::empty;
  27555. }
  27556. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27557. {
  27558. if (effect != 0)
  27559. {
  27560. jassert (index >= 0 && index < effect->numParams);
  27561. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27562. }
  27563. return false;
  27564. }
  27565. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27566. {
  27567. dest.setSize (64 + 4 * getNumParameters());
  27568. dest.fillWith (0);
  27569. getCurrentProgramName().copyToBuffer ((char*) dest.getData(), 63);
  27570. float* const p = (float*) (((char*) dest.getData()) + 64);
  27571. for (int i = 0; i < getNumParameters(); ++i)
  27572. p[i] = getParameter(i);
  27573. }
  27574. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27575. {
  27576. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27577. float* p = (float*) (((char*) m.getData()) + 64);
  27578. for (int i = 0; i < getNumParameters(); ++i)
  27579. setParameter (i, p[i]);
  27580. }
  27581. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27582. {
  27583. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27584. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27585. }
  27586. const String VSTPluginInstance::getProgramName (int index)
  27587. {
  27588. if (index == getCurrentProgram())
  27589. {
  27590. return getCurrentProgramName();
  27591. }
  27592. else if (effect != 0)
  27593. {
  27594. char nm [256];
  27595. zerostruct (nm);
  27596. if (dispatch (effGetProgramNameIndexed,
  27597. jlimit (0, getNumPrograms(), index),
  27598. -1, nm, 0) != 0)
  27599. {
  27600. return String (nm).trim();
  27601. }
  27602. }
  27603. return programNames [index];
  27604. }
  27605. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27606. {
  27607. if (index == getCurrentProgram())
  27608. {
  27609. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27610. dispatch (effSetProgramName, 0, 0, (void*) (const char*) newName.substring (0, 24), 0.0f);
  27611. }
  27612. else
  27613. {
  27614. jassertfalse // xxx not implemented!
  27615. }
  27616. }
  27617. void VSTPluginInstance::updateStoredProgramNames()
  27618. {
  27619. if (effect != 0 && getNumPrograms() > 0)
  27620. {
  27621. char nm [256];
  27622. zerostruct (nm);
  27623. // only do this if the plugin can't use indexed names..
  27624. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27625. {
  27626. const int oldProgram = getCurrentProgram();
  27627. MemoryBlock oldSettings;
  27628. createTempParameterStore (oldSettings);
  27629. for (int i = 0; i < getNumPrograms(); ++i)
  27630. {
  27631. setCurrentProgram (i);
  27632. getCurrentProgramName(); // (this updates the list)
  27633. }
  27634. setCurrentProgram (oldProgram);
  27635. restoreFromTempParameterStore (oldSettings);
  27636. }
  27637. }
  27638. }
  27639. const String VSTPluginInstance::getCurrentProgramName()
  27640. {
  27641. if (effect != 0)
  27642. {
  27643. char nm [256];
  27644. zerostruct (nm);
  27645. dispatch (effGetProgramName, 0, 0, nm, 0);
  27646. const int index = getCurrentProgram();
  27647. if (programNames[index].isEmpty())
  27648. {
  27649. while (programNames.size() < index)
  27650. programNames.add (String::empty);
  27651. programNames.set (index, String (nm).trim());
  27652. }
  27653. return String (nm).trim();
  27654. }
  27655. return String::empty;
  27656. }
  27657. const String VSTPluginInstance::getInputChannelName (const int index) const
  27658. {
  27659. if (index >= 0 && index < getNumInputChannels())
  27660. {
  27661. VstPinProperties pinProps;
  27662. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27663. return String (pinProps.label, sizeof (pinProps.label));
  27664. }
  27665. return String::empty;
  27666. }
  27667. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27668. {
  27669. if (index < 0 || index >= getNumInputChannels())
  27670. return false;
  27671. VstPinProperties pinProps;
  27672. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27673. return (pinProps.flags & kVstPinIsStereo) != 0;
  27674. return true;
  27675. }
  27676. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27677. {
  27678. if (index >= 0 && index < getNumOutputChannels())
  27679. {
  27680. VstPinProperties pinProps;
  27681. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27682. return String (pinProps.label, sizeof (pinProps.label));
  27683. }
  27684. return String::empty;
  27685. }
  27686. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27687. {
  27688. if (index < 0 || index >= getNumOutputChannels())
  27689. return false;
  27690. VstPinProperties pinProps;
  27691. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27692. return (pinProps.flags & kVstPinIsStereo) != 0;
  27693. return true;
  27694. }
  27695. void VSTPluginInstance::setPower (const bool on)
  27696. {
  27697. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27698. isPowerOn = on;
  27699. }
  27700. const int defaultMaxSizeMB = 64;
  27701. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27702. {
  27703. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27704. }
  27705. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27706. {
  27707. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27708. }
  27709. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27710. {
  27711. loadFromFXBFile (data, sizeInBytes);
  27712. }
  27713. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27714. {
  27715. loadFromFXBFile (data, sizeInBytes);
  27716. }
  27717. VSTPluginFormat::VSTPluginFormat()
  27718. {
  27719. }
  27720. VSTPluginFormat::~VSTPluginFormat()
  27721. {
  27722. }
  27723. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27724. const String& fileOrIdentifier)
  27725. {
  27726. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27727. return;
  27728. PluginDescription desc;
  27729. desc.fileOrIdentifier = fileOrIdentifier;
  27730. desc.uid = 0;
  27731. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27732. if (instance == 0)
  27733. return;
  27734. try
  27735. {
  27736. #if JUCE_MAC
  27737. if (instance->module->resFileId != 0)
  27738. UseResFile (instance->module->resFileId);
  27739. #endif
  27740. instance->fillInPluginDescription (desc);
  27741. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27742. if (category != kPlugCategShell)
  27743. {
  27744. // Normal plugin...
  27745. results.add (new PluginDescription (desc));
  27746. ++insideVSTCallback;
  27747. instance->dispatch (effOpen, 0, 0, 0, 0);
  27748. --insideVSTCallback;
  27749. }
  27750. else
  27751. {
  27752. // It's a shell plugin, so iterate all the subtypes...
  27753. char shellEffectName [64];
  27754. for (;;)
  27755. {
  27756. zerostruct (shellEffectName);
  27757. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27758. if (uid == 0)
  27759. {
  27760. break;
  27761. }
  27762. else
  27763. {
  27764. desc.uid = uid;
  27765. desc.name = shellEffectName;
  27766. bool alreadyThere = false;
  27767. for (int i = results.size(); --i >= 0;)
  27768. {
  27769. PluginDescription* const d = results.getUnchecked(i);
  27770. if (d->isDuplicateOf (desc))
  27771. {
  27772. alreadyThere = true;
  27773. break;
  27774. }
  27775. }
  27776. if (! alreadyThere)
  27777. results.add (new PluginDescription (desc));
  27778. }
  27779. }
  27780. }
  27781. }
  27782. catch (...)
  27783. {
  27784. // crashed while loading...
  27785. }
  27786. }
  27787. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27788. {
  27789. ScopedPointer <VSTPluginInstance> result;
  27790. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27791. {
  27792. File file (desc.fileOrIdentifier);
  27793. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27794. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27795. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27796. if (module != 0)
  27797. {
  27798. shellUIDToCreate = desc.uid;
  27799. result = new VSTPluginInstance (module);
  27800. if (result->effect != 0)
  27801. {
  27802. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27803. result->initialise();
  27804. }
  27805. else
  27806. {
  27807. result = 0;
  27808. }
  27809. }
  27810. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27811. }
  27812. return result.release();
  27813. }
  27814. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27815. {
  27816. const File f (fileOrIdentifier);
  27817. #if JUCE_MAC
  27818. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27819. return true;
  27820. #if JUCE_PPC
  27821. FSRef fileRef;
  27822. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27823. {
  27824. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27825. if (resFileId != -1)
  27826. {
  27827. const int numEffects = Count1Resources ('aEff');
  27828. CloseResFile (resFileId);
  27829. if (numEffects > 0)
  27830. return true;
  27831. }
  27832. }
  27833. #endif
  27834. return false;
  27835. #elif JUCE_WIN32
  27836. return f.existsAsFile()
  27837. && f.hasFileExtension (T(".dll"));
  27838. #elif JUCE_LINUX
  27839. return f.existsAsFile()
  27840. && f.hasFileExtension (T(".so"));
  27841. #endif
  27842. }
  27843. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27844. {
  27845. return fileOrIdentifier;
  27846. }
  27847. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27848. {
  27849. return File (desc.fileOrIdentifier).exists();
  27850. }
  27851. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27852. {
  27853. StringArray results;
  27854. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27855. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27856. return results;
  27857. }
  27858. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27859. {
  27860. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27861. // .component or .vst directories.
  27862. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27863. while (iter.next())
  27864. {
  27865. const File f (iter.getFile());
  27866. bool isPlugin = false;
  27867. if (fileMightContainThisPluginType (f.getFullPathName()))
  27868. {
  27869. isPlugin = true;
  27870. results.add (f.getFullPathName());
  27871. }
  27872. if (recursive && (! isPlugin) && f.isDirectory())
  27873. recursiveFileSearch (results, f, true);
  27874. }
  27875. }
  27876. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27877. {
  27878. #if JUCE_MAC
  27879. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27880. #elif JUCE_WIN32
  27881. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27882. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27883. #elif JUCE_LINUX
  27884. return FileSearchPath ("/usr/lib/vst");
  27885. #endif
  27886. }
  27887. END_JUCE_NAMESPACE
  27888. #endif
  27889. #undef log
  27890. #endif
  27891. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27892. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27893. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27894. BEGIN_JUCE_NAMESPACE
  27895. AudioProcessor::AudioProcessor()
  27896. : playHead (0),
  27897. activeEditor (0),
  27898. sampleRate (0),
  27899. blockSize (0),
  27900. numInputChannels (0),
  27901. numOutputChannels (0),
  27902. latencySamples (0),
  27903. suspended (false),
  27904. nonRealtime (false)
  27905. {
  27906. }
  27907. AudioProcessor::~AudioProcessor()
  27908. {
  27909. // ooh, nasty - the editor should have been deleted before the filter
  27910. // that it refers to is deleted..
  27911. jassert (activeEditor == 0);
  27912. #ifdef JUCE_DEBUG
  27913. // This will fail if you've called beginParameterChangeGesture() for one
  27914. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27915. jassert (changingParams.countNumberOfSetBits() == 0);
  27916. #endif
  27917. }
  27918. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27919. {
  27920. playHead = newPlayHead;
  27921. }
  27922. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27923. {
  27924. const ScopedLock sl (listenerLock);
  27925. listeners.addIfNotAlreadyThere (newListener);
  27926. }
  27927. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27928. {
  27929. const ScopedLock sl (listenerLock);
  27930. listeners.removeValue (listenerToRemove);
  27931. }
  27932. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27933. const int numOuts,
  27934. const double sampleRate_,
  27935. const int blockSize_) throw()
  27936. {
  27937. numInputChannels = numIns;
  27938. numOutputChannels = numOuts;
  27939. sampleRate = sampleRate_;
  27940. blockSize = blockSize_;
  27941. }
  27942. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27943. {
  27944. nonRealtime = nonRealtime_;
  27945. }
  27946. void AudioProcessor::setLatencySamples (const int newLatency)
  27947. {
  27948. if (latencySamples != newLatency)
  27949. {
  27950. latencySamples = newLatency;
  27951. updateHostDisplay();
  27952. }
  27953. }
  27954. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27955. const float newValue)
  27956. {
  27957. setParameter (parameterIndex, newValue);
  27958. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27959. }
  27960. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27961. {
  27962. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27963. for (int i = listeners.size(); --i >= 0;)
  27964. {
  27965. listenerLock.enter();
  27966. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27967. listenerLock.exit();
  27968. if (l != 0)
  27969. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27970. }
  27971. }
  27972. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27973. {
  27974. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27975. #ifdef JUCE_DEBUG
  27976. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27977. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27978. jassert (! changingParams [parameterIndex]);
  27979. changingParams.setBit (parameterIndex);
  27980. #endif
  27981. for (int i = listeners.size(); --i >= 0;)
  27982. {
  27983. listenerLock.enter();
  27984. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27985. listenerLock.exit();
  27986. if (l != 0)
  27987. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27988. }
  27989. }
  27990. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27991. {
  27992. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27993. #ifdef JUCE_DEBUG
  27994. // This means you've called endParameterChangeGesture without having previously called
  27995. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27996. // calls matched correctly.
  27997. jassert (changingParams [parameterIndex]);
  27998. changingParams.clearBit (parameterIndex);
  27999. #endif
  28000. for (int i = listeners.size(); --i >= 0;)
  28001. {
  28002. listenerLock.enter();
  28003. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  28004. listenerLock.exit();
  28005. if (l != 0)
  28006. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  28007. }
  28008. }
  28009. void AudioProcessor::updateHostDisplay()
  28010. {
  28011. for (int i = listeners.size(); --i >= 0;)
  28012. {
  28013. listenerLock.enter();
  28014. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  28015. listenerLock.exit();
  28016. if (l != 0)
  28017. l->audioProcessorChanged (this);
  28018. }
  28019. }
  28020. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  28021. {
  28022. return true;
  28023. }
  28024. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  28025. {
  28026. return false;
  28027. }
  28028. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  28029. {
  28030. const ScopedLock sl (callbackLock);
  28031. suspended = shouldBeSuspended;
  28032. }
  28033. void AudioProcessor::reset()
  28034. {
  28035. }
  28036. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  28037. {
  28038. const ScopedLock sl (callbackLock);
  28039. jassert (activeEditor == editor);
  28040. if (activeEditor == editor)
  28041. activeEditor = 0;
  28042. }
  28043. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  28044. {
  28045. if (activeEditor != 0)
  28046. return activeEditor;
  28047. AudioProcessorEditor* const ed = createEditor();
  28048. if (ed != 0)
  28049. {
  28050. // you must give your editor comp a size before returning it..
  28051. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  28052. const ScopedLock sl (callbackLock);
  28053. activeEditor = ed;
  28054. }
  28055. return ed;
  28056. }
  28057. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  28058. {
  28059. getStateInformation (destData);
  28060. }
  28061. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  28062. {
  28063. setStateInformation (data, sizeInBytes);
  28064. }
  28065. // magic number to identify memory blocks that we've stored as XML
  28066. const uint32 magicXmlNumber = 0x21324356;
  28067. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  28068. JUCE_NAMESPACE::MemoryBlock& destData)
  28069. {
  28070. const String xmlString (xml.createDocument (String::empty, true, false));
  28071. const int stringLength = xmlString.length();
  28072. destData.setSize (stringLength + 10);
  28073. char* const d = (char*) destData.getData();
  28074. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  28075. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  28076. xmlString.copyToBuffer (d + 8, stringLength);
  28077. }
  28078. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  28079. const int sizeInBytes)
  28080. {
  28081. if (sizeInBytes > 8
  28082. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  28083. {
  28084. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  28085. if (stringLength > 0)
  28086. {
  28087. XmlDocument doc (String (((const char*) data) + 8,
  28088. jmin ((sizeInBytes - 8), stringLength)));
  28089. return doc.getDocumentElement();
  28090. }
  28091. }
  28092. return 0;
  28093. }
  28094. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  28095. {
  28096. }
  28097. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  28098. {
  28099. }
  28100. END_JUCE_NAMESPACE
  28101. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  28102. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  28103. BEGIN_JUCE_NAMESPACE
  28104. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  28105. : owner (owner_)
  28106. {
  28107. // the filter must be valid..
  28108. jassert (owner != 0);
  28109. }
  28110. AudioProcessorEditor::~AudioProcessorEditor()
  28111. {
  28112. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  28113. // filter for some reason..
  28114. jassert (owner->getActiveEditor() != this);
  28115. }
  28116. END_JUCE_NAMESPACE
  28117. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  28118. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  28119. BEGIN_JUCE_NAMESPACE
  28120. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  28121. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  28122. : id (id_),
  28123. processor (processor_),
  28124. isPrepared (false)
  28125. {
  28126. jassert (processor_ != 0);
  28127. }
  28128. AudioProcessorGraph::Node::~Node()
  28129. {
  28130. delete processor;
  28131. }
  28132. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  28133. AudioProcessorGraph* const graph)
  28134. {
  28135. if (! isPrepared)
  28136. {
  28137. isPrepared = true;
  28138. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28139. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  28140. if (ioProc != 0)
  28141. ioProc->setParentGraph (graph);
  28142. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  28143. processor->getNumOutputChannels(),
  28144. sampleRate, blockSize);
  28145. processor->prepareToPlay (sampleRate, blockSize);
  28146. }
  28147. }
  28148. void AudioProcessorGraph::Node::unprepare()
  28149. {
  28150. if (isPrepared)
  28151. {
  28152. isPrepared = false;
  28153. processor->releaseResources();
  28154. }
  28155. }
  28156. AudioProcessorGraph::AudioProcessorGraph()
  28157. : lastNodeId (0),
  28158. renderingBuffers (1, 1),
  28159. currentAudioOutputBuffer (1, 1)
  28160. {
  28161. }
  28162. AudioProcessorGraph::~AudioProcessorGraph()
  28163. {
  28164. clearRenderingSequence();
  28165. clear();
  28166. }
  28167. const String AudioProcessorGraph::getName() const
  28168. {
  28169. return "Audio Graph";
  28170. }
  28171. void AudioProcessorGraph::clear()
  28172. {
  28173. nodes.clear();
  28174. connections.clear();
  28175. triggerAsyncUpdate();
  28176. }
  28177. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  28178. {
  28179. for (int i = nodes.size(); --i >= 0;)
  28180. if (nodes.getUnchecked(i)->id == nodeId)
  28181. return nodes.getUnchecked(i);
  28182. return 0;
  28183. }
  28184. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  28185. uint32 nodeId)
  28186. {
  28187. if (newProcessor == 0)
  28188. {
  28189. jassertfalse
  28190. return 0;
  28191. }
  28192. if (nodeId == 0)
  28193. {
  28194. nodeId = ++lastNodeId;
  28195. }
  28196. else
  28197. {
  28198. // you can't add a node with an id that already exists in the graph..
  28199. jassert (getNodeForId (nodeId) == 0);
  28200. removeNode (nodeId);
  28201. }
  28202. lastNodeId = nodeId;
  28203. Node* const n = new Node (nodeId, newProcessor);
  28204. nodes.add (n);
  28205. triggerAsyncUpdate();
  28206. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28207. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  28208. if (ioProc != 0)
  28209. ioProc->setParentGraph (this);
  28210. return n;
  28211. }
  28212. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  28213. {
  28214. disconnectNode (nodeId);
  28215. for (int i = nodes.size(); --i >= 0;)
  28216. {
  28217. if (nodes.getUnchecked(i)->id == nodeId)
  28218. {
  28219. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28220. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  28221. if (ioProc != 0)
  28222. ioProc->setParentGraph (0);
  28223. nodes.remove (i);
  28224. triggerAsyncUpdate();
  28225. return true;
  28226. }
  28227. }
  28228. return false;
  28229. }
  28230. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28231. const int sourceChannelIndex,
  28232. const uint32 destNodeId,
  28233. const int destChannelIndex) const
  28234. {
  28235. for (int i = connections.size(); --i >= 0;)
  28236. {
  28237. const Connection* const c = connections.getUnchecked(i);
  28238. if (c->sourceNodeId == sourceNodeId
  28239. && c->destNodeId == destNodeId
  28240. && c->sourceChannelIndex == sourceChannelIndex
  28241. && c->destChannelIndex == destChannelIndex)
  28242. {
  28243. return c;
  28244. }
  28245. }
  28246. return 0;
  28247. }
  28248. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28249. const uint32 possibleDestNodeId) const
  28250. {
  28251. for (int i = connections.size(); --i >= 0;)
  28252. {
  28253. const Connection* const c = connections.getUnchecked(i);
  28254. if (c->sourceNodeId == possibleSourceNodeId
  28255. && c->destNodeId == possibleDestNodeId)
  28256. {
  28257. return true;
  28258. }
  28259. }
  28260. return false;
  28261. }
  28262. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28263. const int sourceChannelIndex,
  28264. const uint32 destNodeId,
  28265. const int destChannelIndex) const
  28266. {
  28267. if (sourceChannelIndex < 0
  28268. || destChannelIndex < 0
  28269. || sourceNodeId == destNodeId
  28270. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28271. return false;
  28272. const Node* const source = getNodeForId (sourceNodeId);
  28273. if (source == 0
  28274. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28275. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28276. return false;
  28277. const Node* const dest = getNodeForId (destNodeId);
  28278. if (dest == 0
  28279. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28280. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28281. return false;
  28282. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28283. destNodeId, destChannelIndex) == 0;
  28284. }
  28285. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28286. const int sourceChannelIndex,
  28287. const uint32 destNodeId,
  28288. const int destChannelIndex)
  28289. {
  28290. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28291. return false;
  28292. Connection* const c = new Connection();
  28293. c->sourceNodeId = sourceNodeId;
  28294. c->sourceChannelIndex = sourceChannelIndex;
  28295. c->destNodeId = destNodeId;
  28296. c->destChannelIndex = destChannelIndex;
  28297. connections.add (c);
  28298. triggerAsyncUpdate();
  28299. return true;
  28300. }
  28301. void AudioProcessorGraph::removeConnection (const int index)
  28302. {
  28303. connections.remove (index);
  28304. triggerAsyncUpdate();
  28305. }
  28306. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28307. const uint32 destNodeId, const int destChannelIndex)
  28308. {
  28309. bool doneAnything = false;
  28310. for (int i = connections.size(); --i >= 0;)
  28311. {
  28312. const Connection* const c = connections.getUnchecked(i);
  28313. if (c->sourceNodeId == sourceNodeId
  28314. && c->destNodeId == destNodeId
  28315. && c->sourceChannelIndex == sourceChannelIndex
  28316. && c->destChannelIndex == destChannelIndex)
  28317. {
  28318. removeConnection (i);
  28319. doneAnything = true;
  28320. triggerAsyncUpdate();
  28321. }
  28322. }
  28323. return doneAnything;
  28324. }
  28325. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28326. {
  28327. bool doneAnything = false;
  28328. for (int i = connections.size(); --i >= 0;)
  28329. {
  28330. const Connection* const c = connections.getUnchecked(i);
  28331. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28332. {
  28333. removeConnection (i);
  28334. doneAnything = true;
  28335. triggerAsyncUpdate();
  28336. }
  28337. }
  28338. return doneAnything;
  28339. }
  28340. bool AudioProcessorGraph::removeIllegalConnections()
  28341. {
  28342. bool doneAnything = false;
  28343. for (int i = connections.size(); --i >= 0;)
  28344. {
  28345. const Connection* const c = connections.getUnchecked(i);
  28346. const Node* const source = getNodeForId (c->sourceNodeId);
  28347. const Node* const dest = getNodeForId (c->destNodeId);
  28348. if (source == 0 || dest == 0
  28349. || (c->sourceChannelIndex != midiChannelIndex
  28350. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28351. || (c->sourceChannelIndex == midiChannelIndex
  28352. && ! source->processor->producesMidi())
  28353. || (c->destChannelIndex != midiChannelIndex
  28354. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28355. || (c->destChannelIndex == midiChannelIndex
  28356. && ! dest->processor->acceptsMidi()))
  28357. {
  28358. removeConnection (i);
  28359. doneAnything = true;
  28360. triggerAsyncUpdate();
  28361. }
  28362. }
  28363. return doneAnything;
  28364. }
  28365. namespace GraphRenderingOps
  28366. {
  28367. class AudioGraphRenderingOp
  28368. {
  28369. public:
  28370. AudioGraphRenderingOp() {}
  28371. virtual ~AudioGraphRenderingOp() {}
  28372. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28373. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28374. const int numSamples) = 0;
  28375. juce_UseDebuggingNewOperator
  28376. };
  28377. class ClearChannelOp : public AudioGraphRenderingOp
  28378. {
  28379. public:
  28380. ClearChannelOp (const int channelNum_)
  28381. : channelNum (channelNum_)
  28382. {}
  28383. ~ClearChannelOp() {}
  28384. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28385. {
  28386. sharedBufferChans.clear (channelNum, 0, numSamples);
  28387. }
  28388. private:
  28389. const int channelNum;
  28390. ClearChannelOp (const ClearChannelOp&);
  28391. const ClearChannelOp& operator= (const ClearChannelOp&);
  28392. };
  28393. class CopyChannelOp : public AudioGraphRenderingOp
  28394. {
  28395. public:
  28396. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28397. : srcChannelNum (srcChannelNum_),
  28398. dstChannelNum (dstChannelNum_)
  28399. {}
  28400. ~CopyChannelOp() {}
  28401. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28402. {
  28403. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28404. }
  28405. private:
  28406. const int srcChannelNum, dstChannelNum;
  28407. CopyChannelOp (const CopyChannelOp&);
  28408. const CopyChannelOp& operator= (const CopyChannelOp&);
  28409. };
  28410. class AddChannelOp : public AudioGraphRenderingOp
  28411. {
  28412. public:
  28413. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28414. : srcChannelNum (srcChannelNum_),
  28415. dstChannelNum (dstChannelNum_)
  28416. {}
  28417. ~AddChannelOp() {}
  28418. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28419. {
  28420. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28421. }
  28422. private:
  28423. const int srcChannelNum, dstChannelNum;
  28424. AddChannelOp (const AddChannelOp&);
  28425. const AddChannelOp& operator= (const AddChannelOp&);
  28426. };
  28427. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28428. {
  28429. public:
  28430. ClearMidiBufferOp (const int bufferNum_)
  28431. : bufferNum (bufferNum_)
  28432. {}
  28433. ~ClearMidiBufferOp() {}
  28434. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28435. {
  28436. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28437. }
  28438. private:
  28439. const int bufferNum;
  28440. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28441. const ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28442. };
  28443. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28444. {
  28445. public:
  28446. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28447. : srcBufferNum (srcBufferNum_),
  28448. dstBufferNum (dstBufferNum_)
  28449. {}
  28450. ~CopyMidiBufferOp() {}
  28451. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28452. {
  28453. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28454. }
  28455. private:
  28456. const int srcBufferNum, dstBufferNum;
  28457. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28458. const CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28459. };
  28460. class AddMidiBufferOp : public AudioGraphRenderingOp
  28461. {
  28462. public:
  28463. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28464. : srcBufferNum (srcBufferNum_),
  28465. dstBufferNum (dstBufferNum_)
  28466. {}
  28467. ~AddMidiBufferOp() {}
  28468. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28469. {
  28470. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28471. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28472. }
  28473. private:
  28474. const int srcBufferNum, dstBufferNum;
  28475. AddMidiBufferOp (const AddMidiBufferOp&);
  28476. const AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28477. };
  28478. class ProcessBufferOp : public AudioGraphRenderingOp
  28479. {
  28480. public:
  28481. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28482. const Array <int>& audioChannelsToUse_,
  28483. const int totalChans_,
  28484. const int midiBufferToUse_)
  28485. : node (node_),
  28486. processor (node_->processor),
  28487. audioChannelsToUse (audioChannelsToUse_),
  28488. totalChans (jmax (1, totalChans_)),
  28489. midiBufferToUse (midiBufferToUse_)
  28490. {
  28491. channels.calloc (totalChans);
  28492. while (audioChannelsToUse.size() < totalChans)
  28493. audioChannelsToUse.add (0);
  28494. }
  28495. ~ProcessBufferOp()
  28496. {
  28497. }
  28498. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28499. {
  28500. for (int i = totalChans; --i >= 0;)
  28501. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28502. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28503. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28504. }
  28505. const AudioProcessorGraph::Node::Ptr node;
  28506. AudioProcessor* const processor;
  28507. private:
  28508. Array <int> audioChannelsToUse;
  28509. HeapBlock <float*> channels;
  28510. int totalChans;
  28511. int midiBufferToUse;
  28512. ProcessBufferOp (const ProcessBufferOp&);
  28513. const ProcessBufferOp& operator= (const ProcessBufferOp&);
  28514. };
  28515. class RenderingOpSequenceCalculator
  28516. {
  28517. public:
  28518. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28519. const VoidArray& orderedNodes_,
  28520. VoidArray& renderingOps)
  28521. : graph (graph_),
  28522. orderedNodes (orderedNodes_)
  28523. {
  28524. nodeIds.add (-2); // first buffer is read-only zeros
  28525. channels.add (0);
  28526. midiNodeIds.add (-2);
  28527. for (int i = 0; i < orderedNodes.size(); ++i)
  28528. {
  28529. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28530. renderingOps, i);
  28531. markAnyUnusedBuffersAsFree (i);
  28532. }
  28533. }
  28534. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28535. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28536. juce_UseDebuggingNewOperator
  28537. private:
  28538. AudioProcessorGraph& graph;
  28539. const VoidArray& orderedNodes;
  28540. Array <int> nodeIds, channels, midiNodeIds;
  28541. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28542. VoidArray& renderingOps,
  28543. const int ourRenderingIndex)
  28544. {
  28545. const int numIns = node->processor->getNumInputChannels();
  28546. const int numOuts = node->processor->getNumOutputChannels();
  28547. const int totalChans = jmax (numIns, numOuts);
  28548. Array <int> audioChannelsToUse;
  28549. int midiBufferToUse = -1;
  28550. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28551. {
  28552. // get a list of all the inputs to this node
  28553. Array <int> sourceNodes, sourceOutputChans;
  28554. for (int i = graph.getNumConnections(); --i >= 0;)
  28555. {
  28556. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28557. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28558. {
  28559. sourceNodes.add (c->sourceNodeId);
  28560. sourceOutputChans.add (c->sourceChannelIndex);
  28561. }
  28562. }
  28563. int bufIndex = -1;
  28564. if (sourceNodes.size() == 0)
  28565. {
  28566. // unconnected input channel
  28567. if (inputChan >= numOuts)
  28568. {
  28569. bufIndex = getReadOnlyEmptyBuffer();
  28570. jassert (bufIndex >= 0);
  28571. }
  28572. else
  28573. {
  28574. bufIndex = getFreeBuffer (false);
  28575. renderingOps.add (new ClearChannelOp (bufIndex));
  28576. }
  28577. }
  28578. else if (sourceNodes.size() == 1)
  28579. {
  28580. // channel with a straightforward single input..
  28581. const int srcNode = sourceNodes.getUnchecked(0);
  28582. const int srcChan = sourceOutputChans.getUnchecked(0);
  28583. bufIndex = getBufferContaining (srcNode, srcChan);
  28584. if (bufIndex < 0)
  28585. {
  28586. // if not found, this is probably a feedback loop
  28587. bufIndex = getReadOnlyEmptyBuffer();
  28588. jassert (bufIndex >= 0);
  28589. }
  28590. if (inputChan < numOuts
  28591. && isBufferNeededLater (ourRenderingIndex,
  28592. inputChan,
  28593. srcNode, srcChan))
  28594. {
  28595. // can't mess up this channel because it's needed later by another node, so we
  28596. // need to use a copy of it..
  28597. const int newFreeBuffer = getFreeBuffer (false);
  28598. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28599. bufIndex = newFreeBuffer;
  28600. }
  28601. }
  28602. else
  28603. {
  28604. // channel with a mix of several inputs..
  28605. // try to find a re-usable channel from our inputs..
  28606. int reusableInputIndex = -1;
  28607. for (int i = 0; i < sourceNodes.size(); ++i)
  28608. {
  28609. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28610. sourceOutputChans.getUnchecked(i));
  28611. if (sourceBufIndex >= 0
  28612. && ! isBufferNeededLater (ourRenderingIndex,
  28613. inputChan,
  28614. sourceNodes.getUnchecked(i),
  28615. sourceOutputChans.getUnchecked(i)))
  28616. {
  28617. // we've found one of our input chans that can be re-used..
  28618. reusableInputIndex = i;
  28619. bufIndex = sourceBufIndex;
  28620. break;
  28621. }
  28622. }
  28623. if (reusableInputIndex < 0)
  28624. {
  28625. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28626. bufIndex = getFreeBuffer (false);
  28627. jassert (bufIndex != 0);
  28628. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28629. sourceOutputChans.getUnchecked (0));
  28630. if (srcIndex < 0)
  28631. {
  28632. // if not found, this is probably a feedback loop
  28633. renderingOps.add (new ClearChannelOp (bufIndex));
  28634. }
  28635. else
  28636. {
  28637. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28638. }
  28639. reusableInputIndex = 0;
  28640. }
  28641. for (int j = 0; j < sourceNodes.size(); ++j)
  28642. {
  28643. if (j != reusableInputIndex)
  28644. {
  28645. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28646. sourceOutputChans.getUnchecked(j));
  28647. if (srcIndex >= 0)
  28648. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28649. }
  28650. }
  28651. }
  28652. jassert (bufIndex >= 0);
  28653. audioChannelsToUse.add (bufIndex);
  28654. if (inputChan < numOuts)
  28655. markBufferAsContaining (bufIndex, node->id, inputChan);
  28656. }
  28657. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28658. {
  28659. const int bufIndex = getFreeBuffer (false);
  28660. jassert (bufIndex != 0);
  28661. audioChannelsToUse.add (bufIndex);
  28662. markBufferAsContaining (bufIndex, node->id, outputChan);
  28663. }
  28664. // Now the same thing for midi..
  28665. Array <int> midiSourceNodes;
  28666. for (int i = graph.getNumConnections(); --i >= 0;)
  28667. {
  28668. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28669. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28670. midiSourceNodes.add (c->sourceNodeId);
  28671. }
  28672. if (midiSourceNodes.size() == 0)
  28673. {
  28674. // No midi inputs..
  28675. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28676. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28677. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28678. }
  28679. else if (midiSourceNodes.size() == 1)
  28680. {
  28681. // One midi input..
  28682. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28683. AudioProcessorGraph::midiChannelIndex);
  28684. if (midiBufferToUse >= 0)
  28685. {
  28686. if (isBufferNeededLater (ourRenderingIndex,
  28687. AudioProcessorGraph::midiChannelIndex,
  28688. midiSourceNodes.getUnchecked(0),
  28689. AudioProcessorGraph::midiChannelIndex))
  28690. {
  28691. // can't mess up this channel because it's needed later by another node, so we
  28692. // need to use a copy of it..
  28693. const int newFreeBuffer = getFreeBuffer (true);
  28694. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28695. midiBufferToUse = newFreeBuffer;
  28696. }
  28697. }
  28698. else
  28699. {
  28700. // probably a feedback loop, so just use an empty one..
  28701. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28702. }
  28703. }
  28704. else
  28705. {
  28706. // More than one midi input being mixed..
  28707. int reusableInputIndex = -1;
  28708. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28709. {
  28710. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28711. AudioProcessorGraph::midiChannelIndex);
  28712. if (sourceBufIndex >= 0
  28713. && ! isBufferNeededLater (ourRenderingIndex,
  28714. AudioProcessorGraph::midiChannelIndex,
  28715. midiSourceNodes.getUnchecked(i),
  28716. AudioProcessorGraph::midiChannelIndex))
  28717. {
  28718. // we've found one of our input buffers that can be re-used..
  28719. reusableInputIndex = i;
  28720. midiBufferToUse = sourceBufIndex;
  28721. break;
  28722. }
  28723. }
  28724. if (reusableInputIndex < 0)
  28725. {
  28726. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28727. midiBufferToUse = getFreeBuffer (true);
  28728. jassert (midiBufferToUse >= 0);
  28729. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28730. AudioProcessorGraph::midiChannelIndex);
  28731. if (srcIndex >= 0)
  28732. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28733. else
  28734. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28735. reusableInputIndex = 0;
  28736. }
  28737. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28738. {
  28739. if (j != reusableInputIndex)
  28740. {
  28741. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28742. AudioProcessorGraph::midiChannelIndex);
  28743. if (srcIndex >= 0)
  28744. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28745. }
  28746. }
  28747. }
  28748. if (node->processor->producesMidi())
  28749. markBufferAsContaining (midiBufferToUse, node->id,
  28750. AudioProcessorGraph::midiChannelIndex);
  28751. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28752. totalChans, midiBufferToUse));
  28753. }
  28754. int getFreeBuffer (const bool forMidi)
  28755. {
  28756. if (forMidi)
  28757. {
  28758. for (int i = 1; i < midiNodeIds.size(); ++i)
  28759. if (midiNodeIds.getUnchecked(i) < 0)
  28760. return i;
  28761. midiNodeIds.add (-1);
  28762. return midiNodeIds.size() - 1;
  28763. }
  28764. else
  28765. {
  28766. for (int i = 1; i < nodeIds.size(); ++i)
  28767. if (nodeIds.getUnchecked(i) < 0)
  28768. return i;
  28769. nodeIds.add (-1);
  28770. channels.add (0);
  28771. return nodeIds.size() - 1;
  28772. }
  28773. }
  28774. int getReadOnlyEmptyBuffer() const
  28775. {
  28776. return 0;
  28777. }
  28778. int getBufferContaining (const int nodeId, const int outputChannel) const
  28779. {
  28780. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28781. {
  28782. for (int i = midiNodeIds.size(); --i >= 0;)
  28783. if (midiNodeIds.getUnchecked(i) == nodeId)
  28784. return i;
  28785. }
  28786. else
  28787. {
  28788. for (int i = nodeIds.size(); --i >= 0;)
  28789. if (nodeIds.getUnchecked(i) == nodeId
  28790. && channels.getUnchecked(i) == outputChannel)
  28791. return i;
  28792. }
  28793. return -1;
  28794. }
  28795. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28796. {
  28797. int i;
  28798. for (i = 0; i < nodeIds.size(); ++i)
  28799. {
  28800. if (nodeIds.getUnchecked(i) >= 0
  28801. && ! isBufferNeededLater (stepIndex, -1,
  28802. nodeIds.getUnchecked(i),
  28803. channels.getUnchecked(i)))
  28804. {
  28805. nodeIds.set (i, -1);
  28806. }
  28807. }
  28808. for (i = 0; i < midiNodeIds.size(); ++i)
  28809. {
  28810. if (midiNodeIds.getUnchecked(i) >= 0
  28811. && ! isBufferNeededLater (stepIndex, -1,
  28812. midiNodeIds.getUnchecked(i),
  28813. AudioProcessorGraph::midiChannelIndex))
  28814. {
  28815. midiNodeIds.set (i, -1);
  28816. }
  28817. }
  28818. }
  28819. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28820. int inputChannelOfIndexToIgnore,
  28821. const int nodeId,
  28822. const int outputChanIndex) const
  28823. {
  28824. while (stepIndexToSearchFrom < orderedNodes.size())
  28825. {
  28826. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28827. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28828. {
  28829. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28830. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28831. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28832. return true;
  28833. }
  28834. else
  28835. {
  28836. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28837. if (i != inputChannelOfIndexToIgnore
  28838. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28839. node->id, i) != 0)
  28840. return true;
  28841. }
  28842. inputChannelOfIndexToIgnore = -1;
  28843. ++stepIndexToSearchFrom;
  28844. }
  28845. return false;
  28846. }
  28847. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28848. {
  28849. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28850. {
  28851. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28852. midiNodeIds.set (bufferNum, nodeId);
  28853. }
  28854. else
  28855. {
  28856. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28857. nodeIds.set (bufferNum, nodeId);
  28858. channels.set (bufferNum, outputIndex);
  28859. }
  28860. }
  28861. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28862. const RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28863. };
  28864. }
  28865. void AudioProcessorGraph::clearRenderingSequence()
  28866. {
  28867. const ScopedLock sl (renderLock);
  28868. for (int i = renderingOps.size(); --i >= 0;)
  28869. {
  28870. GraphRenderingOps::AudioGraphRenderingOp* const r
  28871. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28872. renderingOps.remove (i);
  28873. delete r;
  28874. }
  28875. }
  28876. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28877. const uint32 possibleDestinationId,
  28878. const int recursionCheck) const
  28879. {
  28880. if (recursionCheck > 0)
  28881. {
  28882. for (int i = connections.size(); --i >= 0;)
  28883. {
  28884. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28885. if (c->destNodeId == possibleDestinationId
  28886. && (c->sourceNodeId == possibleInputId
  28887. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28888. return true;
  28889. }
  28890. }
  28891. return false;
  28892. }
  28893. void AudioProcessorGraph::buildRenderingSequence()
  28894. {
  28895. VoidArray newRenderingOps;
  28896. int numRenderingBuffersNeeded = 2;
  28897. int numMidiBuffersNeeded = 1;
  28898. {
  28899. MessageManagerLock mml;
  28900. VoidArray orderedNodes;
  28901. int i;
  28902. for (i = 0; i < nodes.size(); ++i)
  28903. {
  28904. Node* const node = nodes.getUnchecked(i);
  28905. node->prepare (getSampleRate(), getBlockSize(), this);
  28906. int j = 0;
  28907. for (; j < orderedNodes.size(); ++j)
  28908. if (isAnInputTo (node->id,
  28909. ((Node*) orderedNodes.getUnchecked (j))->id,
  28910. nodes.size() + 1))
  28911. break;
  28912. orderedNodes.insert (j, node);
  28913. }
  28914. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28915. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28916. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28917. }
  28918. VoidArray oldRenderingOps (renderingOps);
  28919. {
  28920. // swap over to the new rendering sequence..
  28921. const ScopedLock sl (renderLock);
  28922. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28923. renderingBuffers.clear();
  28924. for (int i = midiBuffers.size(); --i >= 0;)
  28925. midiBuffers.getUnchecked(i)->clear();
  28926. while (midiBuffers.size() < numMidiBuffersNeeded)
  28927. midiBuffers.add (new MidiBuffer());
  28928. renderingOps = newRenderingOps;
  28929. }
  28930. for (int i = oldRenderingOps.size(); --i >= 0;)
  28931. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28932. }
  28933. void AudioProcessorGraph::handleAsyncUpdate()
  28934. {
  28935. buildRenderingSequence();
  28936. }
  28937. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28938. {
  28939. currentAudioInputBuffer = 0;
  28940. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28941. currentMidiInputBuffer = 0;
  28942. currentMidiOutputBuffer.clear();
  28943. clearRenderingSequence();
  28944. buildRenderingSequence();
  28945. }
  28946. void AudioProcessorGraph::releaseResources()
  28947. {
  28948. for (int i = 0; i < nodes.size(); ++i)
  28949. nodes.getUnchecked(i)->unprepare();
  28950. renderingBuffers.setSize (1, 1);
  28951. midiBuffers.clear();
  28952. currentAudioInputBuffer = 0;
  28953. currentAudioOutputBuffer.setSize (1, 1);
  28954. currentMidiInputBuffer = 0;
  28955. currentMidiOutputBuffer.clear();
  28956. }
  28957. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28958. {
  28959. const int numSamples = buffer.getNumSamples();
  28960. const ScopedLock sl (renderLock);
  28961. currentAudioInputBuffer = &buffer;
  28962. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28963. currentAudioOutputBuffer.clear();
  28964. currentMidiInputBuffer = &midiMessages;
  28965. currentMidiOutputBuffer.clear();
  28966. int i;
  28967. for (i = 0; i < renderingOps.size(); ++i)
  28968. {
  28969. GraphRenderingOps::AudioGraphRenderingOp* const op
  28970. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28971. op->perform (renderingBuffers, midiBuffers, numSamples);
  28972. }
  28973. for (i = 0; i < buffer.getNumChannels(); ++i)
  28974. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28975. midiMessages.clear();
  28976. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28977. }
  28978. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28979. {
  28980. return "Input " + String (channelIndex + 1);
  28981. }
  28982. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28983. {
  28984. return "Output " + String (channelIndex + 1);
  28985. }
  28986. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28987. {
  28988. return true;
  28989. }
  28990. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28991. {
  28992. return true;
  28993. }
  28994. bool AudioProcessorGraph::acceptsMidi() const
  28995. {
  28996. return true;
  28997. }
  28998. bool AudioProcessorGraph::producesMidi() const
  28999. {
  29000. return true;
  29001. }
  29002. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  29003. {
  29004. }
  29005. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  29006. {
  29007. }
  29008. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  29009. : type (type_),
  29010. graph (0)
  29011. {
  29012. }
  29013. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  29014. {
  29015. }
  29016. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  29017. {
  29018. switch (type)
  29019. {
  29020. case audioOutputNode:
  29021. return "Audio Output";
  29022. case audioInputNode:
  29023. return "Audio Input";
  29024. case midiOutputNode:
  29025. return "Midi Output";
  29026. case midiInputNode:
  29027. return "Midi Input";
  29028. default:
  29029. break;
  29030. }
  29031. return String::empty;
  29032. }
  29033. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  29034. {
  29035. d.name = getName();
  29036. d.uid = d.name.hashCode();
  29037. d.category = "I/O devices";
  29038. d.pluginFormatName = "Internal";
  29039. d.manufacturerName = "Raw Material Software";
  29040. d.version = "1.0";
  29041. d.isInstrument = false;
  29042. d.numInputChannels = getNumInputChannels();
  29043. if (type == audioOutputNode && graph != 0)
  29044. d.numInputChannels = graph->getNumInputChannels();
  29045. d.numOutputChannels = getNumOutputChannels();
  29046. if (type == audioInputNode && graph != 0)
  29047. d.numOutputChannels = graph->getNumOutputChannels();
  29048. }
  29049. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  29050. {
  29051. jassert (graph != 0);
  29052. }
  29053. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  29054. {
  29055. }
  29056. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  29057. MidiBuffer& midiMessages)
  29058. {
  29059. jassert (graph != 0);
  29060. switch (type)
  29061. {
  29062. case audioOutputNode:
  29063. {
  29064. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  29065. buffer.getNumChannels()); --i >= 0;)
  29066. {
  29067. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  29068. }
  29069. break;
  29070. }
  29071. case audioInputNode:
  29072. {
  29073. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  29074. buffer.getNumChannels()); --i >= 0;)
  29075. {
  29076. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  29077. }
  29078. break;
  29079. }
  29080. case midiOutputNode:
  29081. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  29082. break;
  29083. case midiInputNode:
  29084. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  29085. break;
  29086. default:
  29087. break;
  29088. }
  29089. }
  29090. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  29091. {
  29092. return type == midiOutputNode;
  29093. }
  29094. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  29095. {
  29096. return type == midiInputNode;
  29097. }
  29098. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  29099. {
  29100. switch (type)
  29101. {
  29102. case audioOutputNode:
  29103. return "Output " + String (channelIndex + 1);
  29104. case midiOutputNode:
  29105. return "Midi Output";
  29106. default:
  29107. break;
  29108. }
  29109. return String::empty;
  29110. }
  29111. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  29112. {
  29113. switch (type)
  29114. {
  29115. case audioInputNode:
  29116. return "Input " + String (channelIndex + 1);
  29117. case midiInputNode:
  29118. return "Midi Input";
  29119. default:
  29120. break;
  29121. }
  29122. return String::empty;
  29123. }
  29124. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  29125. {
  29126. return type == audioInputNode || type == audioOutputNode;
  29127. }
  29128. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  29129. {
  29130. return isInputChannelStereoPair (index);
  29131. }
  29132. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  29133. {
  29134. return type == audioInputNode || type == midiInputNode;
  29135. }
  29136. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  29137. {
  29138. return type == audioOutputNode || type == midiOutputNode;
  29139. }
  29140. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  29141. {
  29142. return 0;
  29143. }
  29144. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  29145. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  29146. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  29147. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  29148. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  29149. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  29150. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  29151. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  29152. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  29153. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  29154. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  29155. {
  29156. }
  29157. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  29158. {
  29159. }
  29160. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  29161. {
  29162. graph = newGraph;
  29163. if (graph != 0)
  29164. {
  29165. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  29166. type == audioInputNode ? graph->getNumInputChannels() : 0,
  29167. getSampleRate(),
  29168. getBlockSize());
  29169. updateHostDisplay();
  29170. }
  29171. }
  29172. END_JUCE_NAMESPACE
  29173. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  29174. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29175. BEGIN_JUCE_NAMESPACE
  29176. AudioProcessorPlayer::AudioProcessorPlayer()
  29177. : processor (0),
  29178. sampleRate (0),
  29179. blockSize (0),
  29180. isPrepared (false),
  29181. numInputChans (0),
  29182. numOutputChans (0),
  29183. tempBuffer (1, 1)
  29184. {
  29185. }
  29186. AudioProcessorPlayer::~AudioProcessorPlayer()
  29187. {
  29188. setProcessor (0);
  29189. }
  29190. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  29191. {
  29192. if (processor != processorToPlay)
  29193. {
  29194. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  29195. {
  29196. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  29197. sampleRate, blockSize);
  29198. processorToPlay->prepareToPlay (sampleRate, blockSize);
  29199. }
  29200. lock.enter();
  29201. AudioProcessor* const oldOne = isPrepared ? processor : 0;
  29202. processor = processorToPlay;
  29203. isPrepared = true;
  29204. lock.exit();
  29205. if (oldOne != 0)
  29206. oldOne->releaseResources();
  29207. }
  29208. }
  29209. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  29210. int numInputChannels,
  29211. float** outputChannelData,
  29212. int numOutputChannels,
  29213. int numSamples)
  29214. {
  29215. // these should have been prepared by audioDeviceAboutToStart()...
  29216. jassert (sampleRate > 0 && blockSize > 0);
  29217. incomingMidi.clear();
  29218. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  29219. int i, totalNumChans = 0;
  29220. if (numInputChannels > numOutputChannels)
  29221. {
  29222. // if there aren't enough output channels for the number of
  29223. // inputs, we need to create some temporary extra ones (can't
  29224. // use the input data in case it gets written to)
  29225. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29226. false, false, true);
  29227. for (i = 0; i < numOutputChannels; ++i)
  29228. {
  29229. channels[totalNumChans] = outputChannelData[i];
  29230. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29231. ++totalNumChans;
  29232. }
  29233. for (i = numOutputChannels; i < numInputChannels; ++i)
  29234. {
  29235. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29236. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29237. ++totalNumChans;
  29238. }
  29239. }
  29240. else
  29241. {
  29242. for (i = 0; i < numInputChannels; ++i)
  29243. {
  29244. channels[totalNumChans] = outputChannelData[i];
  29245. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29246. ++totalNumChans;
  29247. }
  29248. for (i = numInputChannels; i < numOutputChannels; ++i)
  29249. {
  29250. channels[totalNumChans] = outputChannelData[i];
  29251. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29252. ++totalNumChans;
  29253. }
  29254. }
  29255. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29256. const ScopedLock sl (lock);
  29257. if (processor != 0)
  29258. processor->processBlock (buffer, incomingMidi);
  29259. }
  29260. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29261. {
  29262. const ScopedLock sl (lock);
  29263. sampleRate = device->getCurrentSampleRate();
  29264. blockSize = device->getCurrentBufferSizeSamples();
  29265. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29266. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29267. messageCollector.reset (sampleRate);
  29268. zeromem (channels, sizeof (channels));
  29269. if (processor != 0)
  29270. {
  29271. if (isPrepared)
  29272. processor->releaseResources();
  29273. AudioProcessor* const oldProcessor = processor;
  29274. setProcessor (0);
  29275. setProcessor (oldProcessor);
  29276. }
  29277. }
  29278. void AudioProcessorPlayer::audioDeviceStopped()
  29279. {
  29280. const ScopedLock sl (lock);
  29281. if (processor != 0 && isPrepared)
  29282. processor->releaseResources();
  29283. sampleRate = 0.0;
  29284. blockSize = 0;
  29285. isPrepared = false;
  29286. tempBuffer.setSize (1, 1);
  29287. }
  29288. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29289. {
  29290. messageCollector.addMessageToQueue (message);
  29291. }
  29292. END_JUCE_NAMESPACE
  29293. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29294. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29295. BEGIN_JUCE_NAMESPACE
  29296. class ProcessorParameterPropertyComp : public PropertyComponent,
  29297. public AudioProcessorListener,
  29298. public AsyncUpdater
  29299. {
  29300. public:
  29301. ProcessorParameterPropertyComp (const String& name,
  29302. AudioProcessor* const owner_,
  29303. const int index_)
  29304. : PropertyComponent (name),
  29305. owner (owner_),
  29306. index (index_)
  29307. {
  29308. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29309. owner_->addListener (this);
  29310. }
  29311. ~ProcessorParameterPropertyComp()
  29312. {
  29313. owner->removeListener (this);
  29314. deleteAllChildren();
  29315. }
  29316. void refresh()
  29317. {
  29318. slider->setValue (owner->getParameter (index), false);
  29319. }
  29320. void audioProcessorChanged (AudioProcessor*) {}
  29321. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29322. {
  29323. if (parameterIndex == index)
  29324. triggerAsyncUpdate();
  29325. }
  29326. void handleAsyncUpdate()
  29327. {
  29328. refresh();
  29329. }
  29330. juce_UseDebuggingNewOperator
  29331. private:
  29332. AudioProcessor* const owner;
  29333. const int index;
  29334. Slider* slider;
  29335. class ParamSlider : public Slider
  29336. {
  29337. public:
  29338. ParamSlider (AudioProcessor* const owner_, const int index_)
  29339. : Slider (String::empty),
  29340. owner (owner_),
  29341. index (index_)
  29342. {
  29343. setRange (0.0, 1.0, 0.0);
  29344. setSliderStyle (Slider::LinearBar);
  29345. setTextBoxIsEditable (false);
  29346. setScrollWheelEnabled (false);
  29347. }
  29348. ~ParamSlider()
  29349. {
  29350. }
  29351. void valueChanged()
  29352. {
  29353. const float newVal = (float) getValue();
  29354. if (owner->getParameter (index) != newVal)
  29355. owner->setParameter (index, newVal);
  29356. }
  29357. const String getTextFromValue (double /*value*/)
  29358. {
  29359. return owner->getParameterText (index);
  29360. }
  29361. juce_UseDebuggingNewOperator
  29362. private:
  29363. AudioProcessor* const owner;
  29364. const int index;
  29365. ParamSlider (const ParamSlider&);
  29366. const ParamSlider& operator= (const ParamSlider&);
  29367. };
  29368. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29369. const ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29370. };
  29371. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29372. : AudioProcessorEditor (owner_)
  29373. {
  29374. setOpaque (true);
  29375. addAndMakeVisible (panel = new PropertyPanel());
  29376. Array <PropertyComponent*> params;
  29377. const int numParams = owner_->getNumParameters();
  29378. int totalHeight = 0;
  29379. for (int i = 0; i < numParams; ++i)
  29380. {
  29381. String name (owner_->getParameterName (i));
  29382. if (name.trim().isEmpty())
  29383. name = "Unnamed";
  29384. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29385. params.add (pc);
  29386. totalHeight += pc->getPreferredHeight();
  29387. }
  29388. panel->addProperties (params);
  29389. setSize (400, jlimit (25, 400, totalHeight));
  29390. }
  29391. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29392. {
  29393. deleteAllChildren();
  29394. }
  29395. void GenericAudioProcessorEditor::paint (Graphics& g)
  29396. {
  29397. g.fillAll (Colours::white);
  29398. }
  29399. void GenericAudioProcessorEditor::resized()
  29400. {
  29401. panel->setSize (getWidth(), getHeight());
  29402. }
  29403. END_JUCE_NAMESPACE
  29404. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29405. /*** Start of inlined file: juce_Sampler.cpp ***/
  29406. BEGIN_JUCE_NAMESPACE
  29407. SamplerSound::SamplerSound (const String& name_,
  29408. AudioFormatReader& source,
  29409. const BitArray& midiNotes_,
  29410. const int midiNoteForNormalPitch,
  29411. const double attackTimeSecs,
  29412. const double releaseTimeSecs,
  29413. const double maxSampleLengthSeconds)
  29414. : name (name_),
  29415. midiNotes (midiNotes_),
  29416. midiRootNote (midiNoteForNormalPitch)
  29417. {
  29418. sourceSampleRate = source.sampleRate;
  29419. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29420. {
  29421. length = 0;
  29422. attackSamples = 0;
  29423. releaseSamples = 0;
  29424. }
  29425. else
  29426. {
  29427. length = jmin ((int) source.lengthInSamples,
  29428. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29429. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29430. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29431. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29432. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29433. }
  29434. }
  29435. SamplerSound::~SamplerSound()
  29436. {
  29437. }
  29438. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29439. {
  29440. return midiNotes [midiNoteNumber];
  29441. }
  29442. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29443. {
  29444. return true;
  29445. }
  29446. SamplerVoice::SamplerVoice()
  29447. : pitchRatio (0.0),
  29448. sourceSamplePosition (0.0),
  29449. lgain (0.0f),
  29450. rgain (0.0f),
  29451. isInAttack (false),
  29452. isInRelease (false)
  29453. {
  29454. }
  29455. SamplerVoice::~SamplerVoice()
  29456. {
  29457. }
  29458. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29459. {
  29460. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29461. }
  29462. void SamplerVoice::startNote (const int midiNoteNumber,
  29463. const float velocity,
  29464. SynthesiserSound* s,
  29465. const int /*currentPitchWheelPosition*/)
  29466. {
  29467. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29468. jassert (sound != 0); // this object can only play SamplerSounds!
  29469. if (sound != 0)
  29470. {
  29471. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29472. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29473. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29474. sourceSamplePosition = 0.0;
  29475. lgain = velocity;
  29476. rgain = velocity;
  29477. isInAttack = (sound->attackSamples > 0);
  29478. isInRelease = false;
  29479. if (isInAttack)
  29480. {
  29481. attackReleaseLevel = 0.0f;
  29482. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29483. }
  29484. else
  29485. {
  29486. attackReleaseLevel = 1.0f;
  29487. attackDelta = 0.0f;
  29488. }
  29489. if (sound->releaseSamples > 0)
  29490. {
  29491. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29492. }
  29493. else
  29494. {
  29495. releaseDelta = 0.0f;
  29496. }
  29497. }
  29498. }
  29499. void SamplerVoice::stopNote (const bool allowTailOff)
  29500. {
  29501. if (allowTailOff)
  29502. {
  29503. isInAttack = false;
  29504. isInRelease = true;
  29505. }
  29506. else
  29507. {
  29508. clearCurrentNote();
  29509. }
  29510. }
  29511. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29512. {
  29513. }
  29514. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29515. const int /*newValue*/)
  29516. {
  29517. }
  29518. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29519. {
  29520. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29521. if (playingSound != 0)
  29522. {
  29523. const float* const inL = playingSound->data->getSampleData (0, 0);
  29524. const float* const inR = playingSound->data->getNumChannels() > 1
  29525. ? playingSound->data->getSampleData (1, 0) : 0;
  29526. float* outL = outputBuffer.getSampleData (0, startSample);
  29527. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29528. while (--numSamples >= 0)
  29529. {
  29530. const int pos = (int) sourceSamplePosition;
  29531. const float alpha = (float) (sourceSamplePosition - pos);
  29532. const float invAlpha = 1.0f - alpha;
  29533. // just using a very simple linear interpolation here..
  29534. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29535. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29536. : l;
  29537. l *= lgain;
  29538. r *= rgain;
  29539. if (isInAttack)
  29540. {
  29541. l *= attackReleaseLevel;
  29542. r *= attackReleaseLevel;
  29543. attackReleaseLevel += attackDelta;
  29544. if (attackReleaseLevel >= 1.0f)
  29545. {
  29546. attackReleaseLevel = 1.0f;
  29547. isInAttack = false;
  29548. }
  29549. }
  29550. else if (isInRelease)
  29551. {
  29552. l *= attackReleaseLevel;
  29553. r *= attackReleaseLevel;
  29554. attackReleaseLevel += releaseDelta;
  29555. if (attackReleaseLevel <= 0.0f)
  29556. {
  29557. stopNote (false);
  29558. break;
  29559. }
  29560. }
  29561. if (outR != 0)
  29562. {
  29563. *outL++ += l;
  29564. *outR++ += r;
  29565. }
  29566. else
  29567. {
  29568. *outL++ += (l + r) * 0.5f;
  29569. }
  29570. sourceSamplePosition += pitchRatio;
  29571. if (sourceSamplePosition > playingSound->length)
  29572. {
  29573. stopNote (false);
  29574. break;
  29575. }
  29576. }
  29577. }
  29578. }
  29579. END_JUCE_NAMESPACE
  29580. /*** End of inlined file: juce_Sampler.cpp ***/
  29581. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29582. BEGIN_JUCE_NAMESPACE
  29583. SynthesiserSound::SynthesiserSound()
  29584. {
  29585. }
  29586. SynthesiserSound::~SynthesiserSound()
  29587. {
  29588. }
  29589. SynthesiserVoice::SynthesiserVoice()
  29590. : currentSampleRate (44100.0),
  29591. currentlyPlayingNote (-1),
  29592. noteOnTime (0),
  29593. currentlyPlayingSound (0)
  29594. {
  29595. }
  29596. SynthesiserVoice::~SynthesiserVoice()
  29597. {
  29598. }
  29599. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29600. {
  29601. return currentlyPlayingSound != 0
  29602. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29603. }
  29604. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29605. {
  29606. currentSampleRate = newRate;
  29607. }
  29608. void SynthesiserVoice::clearCurrentNote()
  29609. {
  29610. currentlyPlayingNote = -1;
  29611. currentlyPlayingSound = 0;
  29612. }
  29613. Synthesiser::Synthesiser()
  29614. : sampleRate (0),
  29615. lastNoteOnCounter (0),
  29616. shouldStealNotes (true)
  29617. {
  29618. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29619. lastPitchWheelValues[i] = 0x2000;
  29620. }
  29621. Synthesiser::~Synthesiser()
  29622. {
  29623. }
  29624. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29625. {
  29626. const ScopedLock sl (lock);
  29627. return voices [index];
  29628. }
  29629. void Synthesiser::clearVoices()
  29630. {
  29631. const ScopedLock sl (lock);
  29632. voices.clear();
  29633. }
  29634. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29635. {
  29636. const ScopedLock sl (lock);
  29637. voices.add (newVoice);
  29638. }
  29639. void Synthesiser::removeVoice (const int index)
  29640. {
  29641. const ScopedLock sl (lock);
  29642. voices.remove (index);
  29643. }
  29644. void Synthesiser::clearSounds()
  29645. {
  29646. const ScopedLock sl (lock);
  29647. sounds.clear();
  29648. }
  29649. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29650. {
  29651. const ScopedLock sl (lock);
  29652. sounds.add (newSound);
  29653. }
  29654. void Synthesiser::removeSound (const int index)
  29655. {
  29656. const ScopedLock sl (lock);
  29657. sounds.remove (index);
  29658. }
  29659. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29660. {
  29661. shouldStealNotes = shouldStealNotes_;
  29662. }
  29663. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29664. {
  29665. if (sampleRate != newRate)
  29666. {
  29667. const ScopedLock sl (lock);
  29668. allNotesOff (0, false);
  29669. sampleRate = newRate;
  29670. for (int i = voices.size(); --i >= 0;)
  29671. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29672. }
  29673. }
  29674. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29675. const MidiBuffer& midiData,
  29676. int startSample,
  29677. int numSamples)
  29678. {
  29679. // must set the sample rate before using this!
  29680. jassert (sampleRate != 0);
  29681. const ScopedLock sl (lock);
  29682. MidiBuffer::Iterator midiIterator (midiData);
  29683. midiIterator.setNextSamplePosition (startSample);
  29684. MidiMessage m (0xf4, 0.0);
  29685. while (numSamples > 0)
  29686. {
  29687. int midiEventPos;
  29688. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29689. && midiEventPos < startSample + numSamples;
  29690. const int numThisTime = useEvent ? midiEventPos - startSample
  29691. : numSamples;
  29692. if (numThisTime > 0)
  29693. {
  29694. for (int i = voices.size(); --i >= 0;)
  29695. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29696. }
  29697. if (useEvent)
  29698. {
  29699. if (m.isNoteOn())
  29700. {
  29701. const int channel = m.getChannel();
  29702. noteOn (channel,
  29703. m.getNoteNumber(),
  29704. m.getFloatVelocity());
  29705. }
  29706. else if (m.isNoteOff())
  29707. {
  29708. noteOff (m.getChannel(),
  29709. m.getNoteNumber(),
  29710. true);
  29711. }
  29712. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29713. {
  29714. allNotesOff (m.getChannel(), true);
  29715. }
  29716. else if (m.isPitchWheel())
  29717. {
  29718. const int channel = m.getChannel();
  29719. const int wheelPos = m.getPitchWheelValue();
  29720. lastPitchWheelValues [channel - 1] = wheelPos;
  29721. handlePitchWheel (channel, wheelPos);
  29722. }
  29723. else if (m.isController())
  29724. {
  29725. handleController (m.getChannel(),
  29726. m.getControllerNumber(),
  29727. m.getControllerValue());
  29728. }
  29729. }
  29730. startSample += numThisTime;
  29731. numSamples -= numThisTime;
  29732. }
  29733. }
  29734. void Synthesiser::noteOn (const int midiChannel,
  29735. const int midiNoteNumber,
  29736. const float velocity)
  29737. {
  29738. const ScopedLock sl (lock);
  29739. for (int i = sounds.size(); --i >= 0;)
  29740. {
  29741. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29742. if (sound->appliesToNote (midiNoteNumber)
  29743. && sound->appliesToChannel (midiChannel))
  29744. {
  29745. startVoice (findFreeVoice (sound, shouldStealNotes),
  29746. sound, midiChannel, midiNoteNumber, velocity);
  29747. }
  29748. }
  29749. }
  29750. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29751. SynthesiserSound* const sound,
  29752. const int midiChannel,
  29753. const int midiNoteNumber,
  29754. const float velocity)
  29755. {
  29756. if (voice != 0 && sound != 0)
  29757. {
  29758. if (voice->currentlyPlayingSound != 0)
  29759. voice->stopNote (false);
  29760. voice->startNote (midiNoteNumber,
  29761. velocity,
  29762. sound,
  29763. lastPitchWheelValues [midiChannel - 1]);
  29764. voice->currentlyPlayingNote = midiNoteNumber;
  29765. voice->noteOnTime = ++lastNoteOnCounter;
  29766. voice->currentlyPlayingSound = sound;
  29767. }
  29768. }
  29769. void Synthesiser::noteOff (const int midiChannel,
  29770. const int midiNoteNumber,
  29771. const bool allowTailOff)
  29772. {
  29773. const ScopedLock sl (lock);
  29774. for (int i = voices.size(); --i >= 0;)
  29775. {
  29776. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29777. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29778. {
  29779. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29780. if (sound != 0
  29781. && sound->appliesToNote (midiNoteNumber)
  29782. && sound->appliesToChannel (midiChannel))
  29783. {
  29784. voice->stopNote (allowTailOff);
  29785. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29786. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29787. }
  29788. }
  29789. }
  29790. }
  29791. void Synthesiser::allNotesOff (const int midiChannel,
  29792. const bool allowTailOff)
  29793. {
  29794. const ScopedLock sl (lock);
  29795. for (int i = voices.size(); --i >= 0;)
  29796. {
  29797. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29798. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29799. voice->stopNote (allowTailOff);
  29800. }
  29801. }
  29802. void Synthesiser::handlePitchWheel (const int midiChannel,
  29803. const int wheelValue)
  29804. {
  29805. const ScopedLock sl (lock);
  29806. for (int i = voices.size(); --i >= 0;)
  29807. {
  29808. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29809. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29810. {
  29811. voice->pitchWheelMoved (wheelValue);
  29812. }
  29813. }
  29814. }
  29815. void Synthesiser::handleController (const int midiChannel,
  29816. const int controllerNumber,
  29817. const int controllerValue)
  29818. {
  29819. const ScopedLock sl (lock);
  29820. for (int i = voices.size(); --i >= 0;)
  29821. {
  29822. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29823. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29824. voice->controllerMoved (controllerNumber, controllerValue);
  29825. }
  29826. }
  29827. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29828. const bool stealIfNoneAvailable) const
  29829. {
  29830. const ScopedLock sl (lock);
  29831. for (int i = voices.size(); --i >= 0;)
  29832. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29833. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29834. return voices.getUnchecked (i);
  29835. if (stealIfNoneAvailable)
  29836. {
  29837. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29838. SynthesiserVoice* oldest = 0;
  29839. for (int i = voices.size(); --i >= 0;)
  29840. {
  29841. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29842. if (voice->canPlaySound (soundToPlay)
  29843. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29844. oldest = voice;
  29845. }
  29846. jassert (oldest != 0);
  29847. return oldest;
  29848. }
  29849. return 0;
  29850. }
  29851. END_JUCE_NAMESPACE
  29852. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29853. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29854. BEGIN_JUCE_NAMESPACE
  29855. ActionBroadcaster::ActionBroadcaster() throw()
  29856. {
  29857. // are you trying to create this object before or after juce has been intialised??
  29858. jassert (MessageManager::instance != 0);
  29859. }
  29860. ActionBroadcaster::~ActionBroadcaster()
  29861. {
  29862. // all event-based objects must be deleted BEFORE juce is shut down!
  29863. jassert (MessageManager::instance != 0);
  29864. }
  29865. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29866. {
  29867. actionListenerList.addActionListener (listener);
  29868. }
  29869. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29870. {
  29871. jassert (actionListenerList.isValidMessageListener());
  29872. if (actionListenerList.isValidMessageListener())
  29873. actionListenerList.removeActionListener (listener);
  29874. }
  29875. void ActionBroadcaster::removeAllActionListeners()
  29876. {
  29877. actionListenerList.removeAllActionListeners();
  29878. }
  29879. void ActionBroadcaster::sendActionMessage (const String& message) const
  29880. {
  29881. actionListenerList.sendActionMessage (message);
  29882. }
  29883. END_JUCE_NAMESPACE
  29884. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29885. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29886. BEGIN_JUCE_NAMESPACE
  29887. // special message of our own with a string in it
  29888. class ActionMessage : public Message
  29889. {
  29890. public:
  29891. const String message;
  29892. ActionMessage (const String& messageText,
  29893. void* const listener_) throw()
  29894. : message (messageText)
  29895. {
  29896. pointerParameter = listener_;
  29897. }
  29898. ~ActionMessage() throw()
  29899. {
  29900. }
  29901. private:
  29902. ActionMessage (const ActionMessage&);
  29903. const ActionMessage& operator= (const ActionMessage&);
  29904. };
  29905. ActionListenerList::ActionListenerList() throw()
  29906. {
  29907. }
  29908. ActionListenerList::~ActionListenerList() throw()
  29909. {
  29910. }
  29911. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29912. {
  29913. const ScopedLock sl (actionListenerLock_);
  29914. jassert (listener != 0);
  29915. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29916. if (listener != 0)
  29917. actionListeners_.add (listener);
  29918. }
  29919. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29920. {
  29921. const ScopedLock sl (actionListenerLock_);
  29922. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29923. actionListeners_.removeValue (listener);
  29924. }
  29925. void ActionListenerList::removeAllActionListeners() throw()
  29926. {
  29927. const ScopedLock sl (actionListenerLock_);
  29928. actionListeners_.clear();
  29929. }
  29930. void ActionListenerList::sendActionMessage (const String& message) const
  29931. {
  29932. const ScopedLock sl (actionListenerLock_);
  29933. for (int i = actionListeners_.size(); --i >= 0;)
  29934. {
  29935. postMessage (new ActionMessage (message,
  29936. (ActionListener*) actionListeners_.getUnchecked(i)));
  29937. }
  29938. }
  29939. void ActionListenerList::handleMessage (const Message& message)
  29940. {
  29941. const ActionMessage& am = (const ActionMessage&) message;
  29942. if (actionListeners_.contains (am.pointerParameter))
  29943. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29944. }
  29945. END_JUCE_NAMESPACE
  29946. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29947. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29948. BEGIN_JUCE_NAMESPACE
  29949. AsyncUpdater::AsyncUpdater() throw()
  29950. : asyncMessagePending (false)
  29951. {
  29952. internalAsyncHandler.owner = this;
  29953. }
  29954. AsyncUpdater::~AsyncUpdater()
  29955. {
  29956. }
  29957. void AsyncUpdater::triggerAsyncUpdate() throw()
  29958. {
  29959. if (! asyncMessagePending)
  29960. {
  29961. asyncMessagePending = true;
  29962. internalAsyncHandler.postMessage (new Message());
  29963. }
  29964. }
  29965. void AsyncUpdater::cancelPendingUpdate() throw()
  29966. {
  29967. asyncMessagePending = false;
  29968. }
  29969. void AsyncUpdater::handleUpdateNowIfNeeded()
  29970. {
  29971. if (asyncMessagePending)
  29972. {
  29973. asyncMessagePending = false;
  29974. handleAsyncUpdate();
  29975. }
  29976. }
  29977. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29978. {
  29979. owner->handleUpdateNowIfNeeded();
  29980. }
  29981. END_JUCE_NAMESPACE
  29982. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29983. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29984. BEGIN_JUCE_NAMESPACE
  29985. ChangeBroadcaster::ChangeBroadcaster() throw()
  29986. {
  29987. // are you trying to create this object before or after juce has been intialised??
  29988. jassert (MessageManager::instance != 0);
  29989. }
  29990. ChangeBroadcaster::~ChangeBroadcaster()
  29991. {
  29992. // all event-based objects must be deleted BEFORE juce is shut down!
  29993. jassert (MessageManager::instance != 0);
  29994. }
  29995. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29996. {
  29997. changeListenerList.addChangeListener (listener);
  29998. }
  29999. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  30000. {
  30001. jassert (changeListenerList.isValidMessageListener());
  30002. if (changeListenerList.isValidMessageListener())
  30003. changeListenerList.removeChangeListener (listener);
  30004. }
  30005. void ChangeBroadcaster::removeAllChangeListeners() throw()
  30006. {
  30007. changeListenerList.removeAllChangeListeners();
  30008. }
  30009. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  30010. {
  30011. changeListenerList.sendChangeMessage (objectThatHasChanged);
  30012. }
  30013. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  30014. {
  30015. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  30016. }
  30017. void ChangeBroadcaster::dispatchPendingMessages()
  30018. {
  30019. changeListenerList.dispatchPendingMessages();
  30020. }
  30021. END_JUCE_NAMESPACE
  30022. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  30023. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  30024. BEGIN_JUCE_NAMESPACE
  30025. ChangeListenerList::ChangeListenerList() throw()
  30026. : lastChangedObject (0),
  30027. messagePending (false)
  30028. {
  30029. }
  30030. ChangeListenerList::~ChangeListenerList() throw()
  30031. {
  30032. }
  30033. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  30034. {
  30035. const ScopedLock sl (lock);
  30036. jassert (listener != 0);
  30037. if (listener != 0)
  30038. listeners.add (listener);
  30039. }
  30040. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  30041. {
  30042. const ScopedLock sl (lock);
  30043. listeners.removeValue (listener);
  30044. }
  30045. void ChangeListenerList::removeAllChangeListeners() throw()
  30046. {
  30047. const ScopedLock sl (lock);
  30048. listeners.clear();
  30049. }
  30050. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  30051. {
  30052. const ScopedLock sl (lock);
  30053. if ((! messagePending) && (listeners.size() > 0))
  30054. {
  30055. lastChangedObject = objectThatHasChanged;
  30056. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  30057. messagePending = true;
  30058. }
  30059. }
  30060. void ChangeListenerList::handleMessage (const Message& message)
  30061. {
  30062. sendSynchronousChangeMessage (message.pointerParameter);
  30063. }
  30064. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  30065. {
  30066. const ScopedLock sl (lock);
  30067. messagePending = false;
  30068. for (int i = listeners.size(); --i >= 0;)
  30069. {
  30070. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  30071. {
  30072. const ScopedUnlock tempUnlocker (lock);
  30073. l->changeListenerCallback (objectThatHasChanged);
  30074. }
  30075. i = jmin (i, listeners.size());
  30076. }
  30077. }
  30078. void ChangeListenerList::dispatchPendingMessages()
  30079. {
  30080. if (messagePending)
  30081. sendSynchronousChangeMessage (lastChangedObject);
  30082. }
  30083. END_JUCE_NAMESPACE
  30084. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  30085. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  30086. BEGIN_JUCE_NAMESPACE
  30087. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  30088. const uint32 magicMessageHeaderNumber)
  30089. : Thread ("Juce IPC connection"),
  30090. callbackConnectionState (false),
  30091. useMessageThread (callbacksOnMessageThread),
  30092. magicMessageHeader (magicMessageHeaderNumber),
  30093. pipeReceiveMessageTimeout (-1)
  30094. {
  30095. }
  30096. InterprocessConnection::~InterprocessConnection()
  30097. {
  30098. callbackConnectionState = false;
  30099. disconnect();
  30100. }
  30101. bool InterprocessConnection::connectToSocket (const String& hostName,
  30102. const int portNumber,
  30103. const int timeOutMillisecs)
  30104. {
  30105. disconnect();
  30106. const ScopedLock sl (pipeAndSocketLock);
  30107. socket = new StreamingSocket();
  30108. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  30109. {
  30110. connectionMadeInt();
  30111. startThread();
  30112. return true;
  30113. }
  30114. else
  30115. {
  30116. socket = 0;
  30117. return false;
  30118. }
  30119. }
  30120. bool InterprocessConnection::connectToPipe (const String& pipeName,
  30121. const int pipeReceiveMessageTimeoutMs)
  30122. {
  30123. disconnect();
  30124. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30125. if (newPipe->openExisting (pipeName))
  30126. {
  30127. const ScopedLock sl (pipeAndSocketLock);
  30128. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30129. initialiseWithPipe (newPipe.release());
  30130. return true;
  30131. }
  30132. return false;
  30133. }
  30134. bool InterprocessConnection::createPipe (const String& pipeName,
  30135. const int pipeReceiveMessageTimeoutMs)
  30136. {
  30137. disconnect();
  30138. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30139. if (newPipe->createNewPipe (pipeName))
  30140. {
  30141. const ScopedLock sl (pipeAndSocketLock);
  30142. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30143. initialiseWithPipe (newPipe.release());
  30144. return true;
  30145. }
  30146. return false;
  30147. }
  30148. void InterprocessConnection::disconnect()
  30149. {
  30150. if (socket != 0)
  30151. socket->close();
  30152. if (pipe != 0)
  30153. {
  30154. pipe->cancelPendingReads();
  30155. pipe->close();
  30156. }
  30157. stopThread (4000);
  30158. {
  30159. const ScopedLock sl (pipeAndSocketLock);
  30160. socket = 0;
  30161. pipe = 0;
  30162. }
  30163. connectionLostInt();
  30164. }
  30165. bool InterprocessConnection::isConnected() const
  30166. {
  30167. const ScopedLock sl (pipeAndSocketLock);
  30168. return ((socket != 0 && socket->isConnected())
  30169. || (pipe != 0 && pipe->isOpen()))
  30170. && isThreadRunning();
  30171. }
  30172. const String InterprocessConnection::getConnectedHostName() const
  30173. {
  30174. if (pipe != 0)
  30175. {
  30176. return "localhost";
  30177. }
  30178. else if (socket != 0)
  30179. {
  30180. if (! socket->isLocal())
  30181. return socket->getHostName();
  30182. return "localhost";
  30183. }
  30184. return String::empty;
  30185. }
  30186. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  30187. {
  30188. uint32 messageHeader[2];
  30189. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  30190. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  30191. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  30192. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  30193. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  30194. size_t bytesWritten = 0;
  30195. const ScopedLock sl (pipeAndSocketLock);
  30196. if (socket != 0)
  30197. {
  30198. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  30199. }
  30200. else if (pipe != 0)
  30201. {
  30202. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  30203. }
  30204. if (bytesWritten < 0)
  30205. {
  30206. // error..
  30207. return false;
  30208. }
  30209. return (bytesWritten == messageData.getSize());
  30210. }
  30211. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  30212. {
  30213. jassert (socket == 0);
  30214. socket = socket_;
  30215. connectionMadeInt();
  30216. startThread();
  30217. }
  30218. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  30219. {
  30220. jassert (pipe == 0);
  30221. pipe = pipe_;
  30222. connectionMadeInt();
  30223. startThread();
  30224. }
  30225. const int messageMagicNumber = 0xb734128b;
  30226. void InterprocessConnection::handleMessage (const Message& message)
  30227. {
  30228. if (message.intParameter1 == messageMagicNumber)
  30229. {
  30230. switch (message.intParameter2)
  30231. {
  30232. case 0:
  30233. {
  30234. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30235. messageReceived (*data);
  30236. break;
  30237. }
  30238. case 1:
  30239. connectionMade();
  30240. break;
  30241. case 2:
  30242. connectionLost();
  30243. break;
  30244. }
  30245. }
  30246. }
  30247. void InterprocessConnection::connectionMadeInt()
  30248. {
  30249. if (! callbackConnectionState)
  30250. {
  30251. callbackConnectionState = true;
  30252. if (useMessageThread)
  30253. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30254. else
  30255. connectionMade();
  30256. }
  30257. }
  30258. void InterprocessConnection::connectionLostInt()
  30259. {
  30260. if (callbackConnectionState)
  30261. {
  30262. callbackConnectionState = false;
  30263. if (useMessageThread)
  30264. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30265. else
  30266. connectionLost();
  30267. }
  30268. }
  30269. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30270. {
  30271. jassert (callbackConnectionState);
  30272. if (useMessageThread)
  30273. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30274. else
  30275. messageReceived (data);
  30276. }
  30277. bool InterprocessConnection::readNextMessageInt()
  30278. {
  30279. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30280. uint32 messageHeader[2];
  30281. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30282. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30283. if (bytes == sizeof (messageHeader)
  30284. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30285. {
  30286. const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30287. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30288. {
  30289. MemoryBlock messageData (bytesInMessage, true);
  30290. int bytesRead = 0;
  30291. while (bytesRead < bytesInMessage)
  30292. {
  30293. if (threadShouldExit())
  30294. return false;
  30295. const int numThisTime = jmin (bytesInMessage, 65536);
  30296. const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true)
  30297. : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime,
  30298. pipeReceiveMessageTimeout);
  30299. if (bytesIn <= 0)
  30300. break;
  30301. bytesRead += bytesIn;
  30302. }
  30303. if (bytesRead >= 0)
  30304. deliverDataInt (messageData);
  30305. }
  30306. }
  30307. else if (bytes < 0)
  30308. {
  30309. {
  30310. const ScopedLock sl (pipeAndSocketLock);
  30311. socket = 0;
  30312. }
  30313. connectionLostInt();
  30314. return false;
  30315. }
  30316. return true;
  30317. }
  30318. void InterprocessConnection::run()
  30319. {
  30320. while (! threadShouldExit())
  30321. {
  30322. if (socket != 0)
  30323. {
  30324. const int ready = socket->waitUntilReady (true, 0);
  30325. if (ready < 0)
  30326. {
  30327. {
  30328. const ScopedLock sl (pipeAndSocketLock);
  30329. socket = 0;
  30330. }
  30331. connectionLostInt();
  30332. break;
  30333. }
  30334. else if (ready > 0)
  30335. {
  30336. if (! readNextMessageInt())
  30337. break;
  30338. }
  30339. else
  30340. {
  30341. Thread::sleep (2);
  30342. }
  30343. }
  30344. else if (pipe != 0)
  30345. {
  30346. if (! pipe->isOpen())
  30347. {
  30348. {
  30349. const ScopedLock sl (pipeAndSocketLock);
  30350. pipe = 0;
  30351. }
  30352. connectionLostInt();
  30353. break;
  30354. }
  30355. else
  30356. {
  30357. if (! readNextMessageInt())
  30358. break;
  30359. }
  30360. }
  30361. else
  30362. {
  30363. break;
  30364. }
  30365. }
  30366. }
  30367. END_JUCE_NAMESPACE
  30368. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30369. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30370. BEGIN_JUCE_NAMESPACE
  30371. InterprocessConnectionServer::InterprocessConnectionServer()
  30372. : Thread ("Juce IPC server")
  30373. {
  30374. }
  30375. InterprocessConnectionServer::~InterprocessConnectionServer()
  30376. {
  30377. stop();
  30378. }
  30379. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30380. {
  30381. stop();
  30382. socket = new StreamingSocket();
  30383. if (socket->createListener (portNumber))
  30384. {
  30385. startThread();
  30386. return true;
  30387. }
  30388. socket = 0;
  30389. return false;
  30390. }
  30391. void InterprocessConnectionServer::stop()
  30392. {
  30393. signalThreadShouldExit();
  30394. if (socket != 0)
  30395. socket->close();
  30396. stopThread (4000);
  30397. socket = 0;
  30398. }
  30399. void InterprocessConnectionServer::run()
  30400. {
  30401. while ((! threadShouldExit()) && socket != 0)
  30402. {
  30403. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30404. if (clientSocket != 0)
  30405. {
  30406. InterprocessConnection* newConnection = createConnectionObject();
  30407. if (newConnection != 0)
  30408. newConnection->initialiseWithSocket (clientSocket.release());
  30409. }
  30410. }
  30411. }
  30412. END_JUCE_NAMESPACE
  30413. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30414. /*** Start of inlined file: juce_Message.cpp ***/
  30415. BEGIN_JUCE_NAMESPACE
  30416. Message::Message() throw()
  30417. {
  30418. }
  30419. Message::~Message() throw()
  30420. {
  30421. }
  30422. Message::Message (const int intParameter1_,
  30423. const int intParameter2_,
  30424. const int intParameter3_,
  30425. void* const pointerParameter_) throw()
  30426. : intParameter1 (intParameter1_),
  30427. intParameter2 (intParameter2_),
  30428. intParameter3 (intParameter3_),
  30429. pointerParameter (pointerParameter_)
  30430. {
  30431. }
  30432. END_JUCE_NAMESPACE
  30433. /*** End of inlined file: juce_Message.cpp ***/
  30434. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30435. BEGIN_JUCE_NAMESPACE
  30436. MessageListener::MessageListener() throw()
  30437. {
  30438. // are you trying to create a messagelistener before or after juce has been intialised??
  30439. jassert (MessageManager::instance != 0);
  30440. if (MessageManager::instance != 0)
  30441. MessageManager::instance->messageListeners.add (this);
  30442. }
  30443. MessageListener::~MessageListener()
  30444. {
  30445. if (MessageManager::instance != 0)
  30446. MessageManager::instance->messageListeners.removeValue (this);
  30447. }
  30448. void MessageListener::postMessage (Message* const message) const throw()
  30449. {
  30450. message->messageRecipient = const_cast <MessageListener*> (this);
  30451. if (MessageManager::instance == 0)
  30452. MessageManager::getInstance();
  30453. MessageManager::instance->postMessageToQueue (message);
  30454. }
  30455. bool MessageListener::isValidMessageListener() const throw()
  30456. {
  30457. return (MessageManager::instance != 0)
  30458. && MessageManager::instance->messageListeners.contains (this);
  30459. }
  30460. END_JUCE_NAMESPACE
  30461. /*** End of inlined file: juce_MessageListener.cpp ***/
  30462. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30463. BEGIN_JUCE_NAMESPACE
  30464. // platform-specific functions..
  30465. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30466. bool juce_postMessageToSystemQueue (void* message);
  30467. MessageManager* MessageManager::instance = 0;
  30468. static const int quitMessageId = 0xfffff321;
  30469. MessageManager::MessageManager() throw()
  30470. : quitMessagePosted (false),
  30471. quitMessageReceived (false),
  30472. threadWithLock (0)
  30473. {
  30474. messageThreadId = Thread::getCurrentThreadId();
  30475. }
  30476. MessageManager::~MessageManager() throw()
  30477. {
  30478. broadcastListeners = 0;
  30479. doPlatformSpecificShutdown();
  30480. jassert (instance == this);
  30481. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30482. }
  30483. MessageManager* MessageManager::getInstance() throw()
  30484. {
  30485. if (instance == 0)
  30486. {
  30487. instance = new MessageManager();
  30488. doPlatformSpecificInitialisation();
  30489. }
  30490. return instance;
  30491. }
  30492. void MessageManager::postMessageToQueue (Message* const message)
  30493. {
  30494. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30495. delete message;
  30496. }
  30497. CallbackMessage::CallbackMessage() throw() {}
  30498. CallbackMessage::~CallbackMessage() throw() {}
  30499. void CallbackMessage::post()
  30500. {
  30501. if (MessageManager::instance != 0)
  30502. MessageManager::instance->postCallbackMessage (this);
  30503. }
  30504. void MessageManager::postCallbackMessage (Message* const message)
  30505. {
  30506. message->messageRecipient = 0;
  30507. postMessageToQueue (message);
  30508. }
  30509. // not for public use..
  30510. void MessageManager::deliverMessage (void* message)
  30511. {
  30512. const ScopedPointer <Message> m ((Message*) message);
  30513. MessageListener* const recipient = m->messageRecipient;
  30514. JUCE_TRY
  30515. {
  30516. if (messageListeners.contains (recipient))
  30517. {
  30518. recipient->handleMessage (*m);
  30519. }
  30520. else if (recipient == 0)
  30521. {
  30522. if (m->intParameter1 == quitMessageId)
  30523. {
  30524. quitMessageReceived = true;
  30525. }
  30526. else
  30527. {
  30528. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30529. if (cm != 0)
  30530. cm->messageCallback();
  30531. }
  30532. }
  30533. }
  30534. JUCE_CATCH_EXCEPTION
  30535. }
  30536. #if ! (JUCE_MAC || JUCE_IPHONE)
  30537. void MessageManager::runDispatchLoop()
  30538. {
  30539. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30540. runDispatchLoopUntil (-1);
  30541. }
  30542. void MessageManager::stopDispatchLoop()
  30543. {
  30544. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30545. m->messageRecipient = 0;
  30546. postMessageToQueue (m);
  30547. quitMessagePosted = true;
  30548. }
  30549. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30550. {
  30551. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30552. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30553. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30554. && ! quitMessageReceived)
  30555. {
  30556. JUCE_TRY
  30557. {
  30558. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30559. {
  30560. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30561. if (msToWait > 0)
  30562. Thread::sleep (jmin (5, msToWait));
  30563. }
  30564. }
  30565. JUCE_CATCH_EXCEPTION
  30566. }
  30567. return ! quitMessageReceived;
  30568. }
  30569. #endif
  30570. void MessageManager::deliverBroadcastMessage (const String& value)
  30571. {
  30572. if (broadcastListeners != 0)
  30573. broadcastListeners->sendActionMessage (value);
  30574. }
  30575. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30576. {
  30577. if (broadcastListeners == 0)
  30578. broadcastListeners = new ActionListenerList();
  30579. broadcastListeners->addActionListener (listener);
  30580. }
  30581. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30582. {
  30583. if (broadcastListeners != 0)
  30584. broadcastListeners->removeActionListener (listener);
  30585. }
  30586. bool MessageManager::isThisTheMessageThread() const throw()
  30587. {
  30588. return Thread::getCurrentThreadId() == messageThreadId;
  30589. }
  30590. void MessageManager::setCurrentMessageThread (const Thread::ThreadID threadId) throw()
  30591. {
  30592. messageThreadId = threadId;
  30593. }
  30594. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30595. {
  30596. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30597. return thisThread == messageThreadId || thisThread == threadWithLock;
  30598. }
  30599. class SharedLockingEvents : public ReferenceCountedObject
  30600. {
  30601. public:
  30602. SharedLockingEvents() throw() {}
  30603. ~SharedLockingEvents() {}
  30604. WaitableEvent lockedEvent, releaseEvent;
  30605. };
  30606. class MMLockMessage : public CallbackMessage
  30607. {
  30608. public:
  30609. MMLockMessage (SharedLockingEvents* const events_) throw()
  30610. : events (events_)
  30611. {}
  30612. ~MMLockMessage() throw() {}
  30613. ReferenceCountedObjectPtr <SharedLockingEvents> events;
  30614. void messageCallback()
  30615. {
  30616. events->lockedEvent.signal();
  30617. events->releaseEvent.wait();
  30618. }
  30619. juce_UseDebuggingNewOperator
  30620. MMLockMessage (const MMLockMessage&);
  30621. const MMLockMessage& operator= (const MMLockMessage&);
  30622. };
  30623. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30624. : locked (false),
  30625. needsUnlocking (false)
  30626. {
  30627. init (threadToCheck, 0);
  30628. }
  30629. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30630. : locked (false),
  30631. needsUnlocking (false)
  30632. {
  30633. init (0, jobToCheckForExitSignal);
  30634. }
  30635. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30636. {
  30637. if (MessageManager::instance != 0)
  30638. {
  30639. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30640. {
  30641. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30642. }
  30643. else
  30644. {
  30645. if (threadToCheck == 0 && job == 0)
  30646. {
  30647. MessageManager::instance->lockingLock.enter();
  30648. }
  30649. else
  30650. {
  30651. while (! MessageManager::instance->lockingLock.tryEnter())
  30652. {
  30653. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30654. || (job != 0 && job->shouldExit()))
  30655. return;
  30656. Thread::sleep (1);
  30657. }
  30658. }
  30659. SharedLockingEvents* const events = new SharedLockingEvents();
  30660. sharedEvents = events;
  30661. events->incReferenceCount();
  30662. (new MMLockMessage (events))->post();
  30663. while (! events->lockedEvent.wait (50))
  30664. {
  30665. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30666. || (job != 0 && job->shouldExit()))
  30667. {
  30668. events->releaseEvent.signal();
  30669. events->decReferenceCount();
  30670. MessageManager::instance->lockingLock.exit();
  30671. return;
  30672. }
  30673. }
  30674. jassert (MessageManager::instance->threadWithLock == 0);
  30675. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30676. locked = true;
  30677. needsUnlocking = true;
  30678. }
  30679. }
  30680. }
  30681. MessageManagerLock::~MessageManagerLock() throw()
  30682. {
  30683. if (needsUnlocking && MessageManager::instance != 0)
  30684. {
  30685. jassert (MessageManager::instance->currentThreadHasLockedMessageManager());
  30686. ((SharedLockingEvents*) sharedEvents)->releaseEvent.signal();
  30687. ((SharedLockingEvents*) sharedEvents)->decReferenceCount();
  30688. MessageManager::instance->threadWithLock = 0;
  30689. MessageManager::instance->lockingLock.exit();
  30690. }
  30691. }
  30692. END_JUCE_NAMESPACE
  30693. /*** End of inlined file: juce_MessageManager.cpp ***/
  30694. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30695. BEGIN_JUCE_NAMESPACE
  30696. class MultiTimer::MultiTimerCallback : public Timer
  30697. {
  30698. public:
  30699. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30700. : timerId (timerId_),
  30701. owner (owner_)
  30702. {
  30703. }
  30704. ~MultiTimerCallback()
  30705. {
  30706. }
  30707. void timerCallback()
  30708. {
  30709. owner.timerCallback (timerId);
  30710. }
  30711. const int timerId;
  30712. private:
  30713. MultiTimer& owner;
  30714. };
  30715. MultiTimer::MultiTimer() throw()
  30716. {
  30717. }
  30718. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30719. {
  30720. }
  30721. MultiTimer::~MultiTimer()
  30722. {
  30723. const ScopedLock sl (timerListLock);
  30724. timers.clear();
  30725. }
  30726. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30727. {
  30728. const ScopedLock sl (timerListLock);
  30729. for (int i = timers.size(); --i >= 0;)
  30730. {
  30731. MultiTimerCallback* const t = timers.getUnchecked(i);
  30732. if (t->timerId == timerId)
  30733. {
  30734. t->startTimer (intervalInMilliseconds);
  30735. return;
  30736. }
  30737. }
  30738. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30739. timers.add (newTimer);
  30740. newTimer->startTimer (intervalInMilliseconds);
  30741. }
  30742. void MultiTimer::stopTimer (const int timerId) throw()
  30743. {
  30744. const ScopedLock sl (timerListLock);
  30745. for (int i = timers.size(); --i >= 0;)
  30746. {
  30747. MultiTimerCallback* const t = timers.getUnchecked(i);
  30748. if (t->timerId == timerId)
  30749. t->stopTimer();
  30750. }
  30751. }
  30752. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30753. {
  30754. const ScopedLock sl (timerListLock);
  30755. for (int i = timers.size(); --i >= 0;)
  30756. {
  30757. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30758. if (t->timerId == timerId)
  30759. return t->isTimerRunning();
  30760. }
  30761. return false;
  30762. }
  30763. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30764. {
  30765. const ScopedLock sl (timerListLock);
  30766. for (int i = timers.size(); --i >= 0;)
  30767. {
  30768. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30769. if (t->timerId == timerId)
  30770. return t->getTimerInterval();
  30771. }
  30772. return 0;
  30773. }
  30774. END_JUCE_NAMESPACE
  30775. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30776. /*** Start of inlined file: juce_Timer.cpp ***/
  30777. BEGIN_JUCE_NAMESPACE
  30778. class InternalTimerThread : private Thread,
  30779. private MessageListener,
  30780. private DeletedAtShutdown,
  30781. private AsyncUpdater
  30782. {
  30783. public:
  30784. InternalTimerThread()
  30785. : Thread ("Juce Timer"),
  30786. firstTimer (0),
  30787. callbackNeeded (false)
  30788. {
  30789. triggerAsyncUpdate();
  30790. }
  30791. ~InternalTimerThread() throw()
  30792. {
  30793. stopThread (4000);
  30794. jassert (instance == this || instance == 0);
  30795. if (instance == this)
  30796. instance = 0;
  30797. }
  30798. void run()
  30799. {
  30800. uint32 lastTime = Time::getMillisecondCounter();
  30801. while (! threadShouldExit())
  30802. {
  30803. const uint32 now = Time::getMillisecondCounter();
  30804. if (now <= lastTime)
  30805. {
  30806. wait (2);
  30807. continue;
  30808. }
  30809. const int elapsed = now - lastTime;
  30810. lastTime = now;
  30811. lock.enter();
  30812. decrementAllCounters (elapsed);
  30813. const int timeUntilFirstTimer = (firstTimer != 0) ? firstTimer->countdownMs
  30814. : 1000;
  30815. lock.exit();
  30816. if (timeUntilFirstTimer <= 0)
  30817. {
  30818. if (callbackNeeded.set (true))
  30819. {
  30820. postMessage (new Message());
  30821. const uint32 messageDeliveryTimeout = now + 2000;
  30822. while (callbackNeeded.get())
  30823. {
  30824. wait (4);
  30825. if (threadShouldExit())
  30826. return;
  30827. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30828. break;
  30829. }
  30830. }
  30831. }
  30832. else
  30833. {
  30834. // don't wait for too long because running this loop also helps keep the
  30835. // Time::getApproximateMillisecondTimer value stay up-to-date
  30836. wait (jlimit (1, 50, timeUntilFirstTimer));
  30837. }
  30838. }
  30839. }
  30840. void handleMessage (const Message&)
  30841. {
  30842. const ScopedLock sl (lock);
  30843. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30844. {
  30845. Timer* const t = firstTimer;
  30846. t->countdownMs = t->periodMs;
  30847. removeTimer (t);
  30848. addTimer (t);
  30849. const ScopedUnlock ul (lock);
  30850. JUCE_TRY
  30851. {
  30852. t->timerCallback();
  30853. }
  30854. JUCE_CATCH_EXCEPTION
  30855. }
  30856. callbackNeeded.set (false);
  30857. }
  30858. static void callAnyTimersSynchronously()
  30859. {
  30860. if (InternalTimerThread::instance != 0)
  30861. {
  30862. const Message m;
  30863. InternalTimerThread::instance->handleMessage (m);
  30864. }
  30865. }
  30866. static inline void add (Timer* const tim) throw()
  30867. {
  30868. if (instance == 0)
  30869. instance = new InternalTimerThread();
  30870. const ScopedLock sl (instance->lock);
  30871. instance->addTimer (tim);
  30872. }
  30873. static inline void remove (Timer* const tim) throw()
  30874. {
  30875. if (instance != 0)
  30876. {
  30877. const ScopedLock sl (instance->lock);
  30878. instance->removeTimer (tim);
  30879. }
  30880. }
  30881. static inline void resetCounter (Timer* const tim,
  30882. const int newCounter) throw()
  30883. {
  30884. if (instance != 0)
  30885. {
  30886. tim->countdownMs = newCounter;
  30887. tim->periodMs = newCounter;
  30888. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30889. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30890. {
  30891. const ScopedLock sl (instance->lock);
  30892. instance->removeTimer (tim);
  30893. instance->addTimer (tim);
  30894. }
  30895. }
  30896. }
  30897. private:
  30898. friend class Timer;
  30899. static InternalTimerThread* instance;
  30900. static CriticalSection lock;
  30901. Timer* volatile firstTimer;
  30902. class AtomicBool
  30903. {
  30904. public:
  30905. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30906. ~AtomicBool() throw() {}
  30907. bool get() const throw() { return value != 0; }
  30908. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30909. private:
  30910. int32 value;
  30911. AtomicBool (const AtomicBool&);
  30912. AtomicBool& operator= (const AtomicBool&);
  30913. };
  30914. AtomicBool callbackNeeded;
  30915. void addTimer (Timer* const t) throw()
  30916. {
  30917. #ifdef JUCE_DEBUG
  30918. Timer* tt = firstTimer;
  30919. while (tt != 0)
  30920. {
  30921. // trying to add a timer that's already here - shouldn't get to this point,
  30922. // so if you get this assertion, let me know!
  30923. jassert (tt != t);
  30924. tt = tt->next;
  30925. }
  30926. jassert (t->previous == 0 && t->next == 0);
  30927. #endif
  30928. Timer* i = firstTimer;
  30929. if (i == 0 || i->countdownMs > t->countdownMs)
  30930. {
  30931. t->next = firstTimer;
  30932. firstTimer = t;
  30933. }
  30934. else
  30935. {
  30936. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30937. i = i->next;
  30938. jassert (i != 0);
  30939. t->next = i->next;
  30940. t->previous = i;
  30941. i->next = t;
  30942. }
  30943. if (t->next != 0)
  30944. t->next->previous = t;
  30945. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30946. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30947. notify();
  30948. }
  30949. void removeTimer (Timer* const t) throw()
  30950. {
  30951. #ifdef JUCE_DEBUG
  30952. Timer* tt = firstTimer;
  30953. bool found = false;
  30954. while (tt != 0)
  30955. {
  30956. if (tt == t)
  30957. {
  30958. found = true;
  30959. break;
  30960. }
  30961. tt = tt->next;
  30962. }
  30963. // trying to remove a timer that's not here - shouldn't get to this point,
  30964. // so if you get this assertion, let me know!
  30965. jassert (found);
  30966. #endif
  30967. if (t->previous != 0)
  30968. {
  30969. jassert (firstTimer != t);
  30970. t->previous->next = t->next;
  30971. }
  30972. else
  30973. {
  30974. jassert (firstTimer == t);
  30975. firstTimer = t->next;
  30976. }
  30977. if (t->next != 0)
  30978. t->next->previous = t->previous;
  30979. t->next = 0;
  30980. t->previous = 0;
  30981. }
  30982. void decrementAllCounters (const int numMillisecs) const
  30983. {
  30984. Timer* t = firstTimer;
  30985. while (t != 0)
  30986. {
  30987. t->countdownMs -= numMillisecs;
  30988. t = t->next;
  30989. }
  30990. }
  30991. void handleAsyncUpdate()
  30992. {
  30993. startThread (7);
  30994. }
  30995. InternalTimerThread (const InternalTimerThread&);
  30996. InternalTimerThread& operator= (const InternalTimerThread&);
  30997. };
  30998. InternalTimerThread* InternalTimerThread::instance = 0;
  30999. CriticalSection InternalTimerThread::lock;
  31000. void juce_callAnyTimersSynchronously()
  31001. {
  31002. InternalTimerThread::callAnyTimersSynchronously();
  31003. }
  31004. #ifdef JUCE_DEBUG
  31005. static SortedSet <Timer*> activeTimers;
  31006. #endif
  31007. Timer::Timer() throw()
  31008. : countdownMs (0),
  31009. periodMs (0),
  31010. previous (0),
  31011. next (0)
  31012. {
  31013. #ifdef JUCE_DEBUG
  31014. activeTimers.add (this);
  31015. #endif
  31016. }
  31017. Timer::Timer (const Timer&) throw()
  31018. : countdownMs (0),
  31019. periodMs (0),
  31020. previous (0),
  31021. next (0)
  31022. {
  31023. #ifdef JUCE_DEBUG
  31024. activeTimers.add (this);
  31025. #endif
  31026. }
  31027. Timer::~Timer()
  31028. {
  31029. stopTimer();
  31030. #ifdef JUCE_DEBUG
  31031. activeTimers.removeValue (this);
  31032. #endif
  31033. }
  31034. void Timer::startTimer (const int interval) throw()
  31035. {
  31036. const ScopedLock sl (InternalTimerThread::lock);
  31037. #ifdef JUCE_DEBUG
  31038. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31039. jassert (activeTimers.contains (this));
  31040. #endif
  31041. if (periodMs == 0)
  31042. {
  31043. countdownMs = interval;
  31044. periodMs = jmax (1, interval);
  31045. InternalTimerThread::add (this);
  31046. }
  31047. else
  31048. {
  31049. InternalTimerThread::resetCounter (this, interval);
  31050. }
  31051. }
  31052. void Timer::stopTimer() throw()
  31053. {
  31054. const ScopedLock sl (InternalTimerThread::lock);
  31055. #ifdef JUCE_DEBUG
  31056. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31057. jassert (activeTimers.contains (this));
  31058. #endif
  31059. if (periodMs > 0)
  31060. {
  31061. InternalTimerThread::remove (this);
  31062. periodMs = 0;
  31063. }
  31064. }
  31065. END_JUCE_NAMESPACE
  31066. /*** End of inlined file: juce_Timer.cpp ***/
  31067. #endif
  31068. #if JUCE_BUILD_GUI
  31069. /*** Start of inlined file: juce_Component.cpp ***/
  31070. BEGIN_JUCE_NAMESPACE
  31071. Component* Component::componentUnderMouse = 0;
  31072. Component* Component::currentlyFocusedComponent = 0;
  31073. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  31074. static Array <int> modalReturnValues;
  31075. static const int customCommandMessage = 0x7fff0001;
  31076. static const int exitModalStateMessage = 0x7fff0002;
  31077. static Point<int> unboundedMouseOffset;
  31078. static bool isUnboundedMouseModeOn = false;
  31079. static bool isCursorVisibleUntilOffscreen;
  31080. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  31081. static uint32 nextComponentUID = 0;
  31082. Component::Component() throw()
  31083. : parentComponent_ (0),
  31084. componentUID (++nextComponentUID),
  31085. numDeepMouseListeners (0),
  31086. lookAndFeel_ (0),
  31087. effect_ (0),
  31088. bufferedImage_ (0),
  31089. mouseListeners_ (0),
  31090. keyListeners_ (0),
  31091. componentListeners_ (0),
  31092. componentFlags_ (0)
  31093. {
  31094. }
  31095. Component::Component (const String& name) throw()
  31096. : componentName_ (name),
  31097. parentComponent_ (0),
  31098. componentUID (++nextComponentUID),
  31099. numDeepMouseListeners (0),
  31100. lookAndFeel_ (0),
  31101. effect_ (0),
  31102. bufferedImage_ (0),
  31103. mouseListeners_ (0),
  31104. keyListeners_ (0),
  31105. componentListeners_ (0),
  31106. componentFlags_ (0)
  31107. {
  31108. }
  31109. Component::~Component()
  31110. {
  31111. if (parentComponent_ != 0)
  31112. {
  31113. parentComponent_->removeChildComponent (this);
  31114. }
  31115. else if ((currentlyFocusedComponent == this)
  31116. || isParentOf (currentlyFocusedComponent))
  31117. {
  31118. giveAwayFocus();
  31119. }
  31120. if (componentUnderMouse == this)
  31121. componentUnderMouse = 0;
  31122. if (flags.hasHeavyweightPeerFlag)
  31123. removeFromDesktop();
  31124. modalComponentStack.removeValue (this);
  31125. for (int i = childComponentList_.size(); --i >= 0;)
  31126. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31127. delete bufferedImage_;
  31128. delete mouseListeners_;
  31129. delete keyListeners_;
  31130. delete componentListeners_;
  31131. }
  31132. void Component::setName (const String& name)
  31133. {
  31134. // if component methods are being called from threads other than the message
  31135. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31136. checkMessageManagerIsLocked
  31137. if (componentName_ != name)
  31138. {
  31139. componentName_ = name;
  31140. if (flags.hasHeavyweightPeerFlag)
  31141. {
  31142. ComponentPeer* const peer = getPeer();
  31143. jassert (peer != 0);
  31144. if (peer != 0)
  31145. peer->setTitle (name);
  31146. }
  31147. if (componentListeners_ != 0)
  31148. {
  31149. const ComponentDeletionWatcher deletionChecker (this);
  31150. for (int i = componentListeners_->size(); --i >= 0;)
  31151. {
  31152. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31153. ->componentNameChanged (*this);
  31154. if (deletionChecker.hasBeenDeleted())
  31155. return;
  31156. i = jmin (i, componentListeners_->size());
  31157. }
  31158. }
  31159. }
  31160. }
  31161. void Component::setVisible (bool shouldBeVisible)
  31162. {
  31163. if (flags.visibleFlag != shouldBeVisible)
  31164. {
  31165. // if component methods are being called from threads other than the message
  31166. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31167. checkMessageManagerIsLocked
  31168. const ComponentDeletionWatcher deletionChecker (this);
  31169. flags.visibleFlag = shouldBeVisible;
  31170. internalRepaint (0, 0, getWidth(), getHeight());
  31171. sendFakeMouseMove();
  31172. if (! shouldBeVisible)
  31173. {
  31174. if (currentlyFocusedComponent == this
  31175. || isParentOf (currentlyFocusedComponent))
  31176. {
  31177. if (parentComponent_ != 0)
  31178. parentComponent_->grabKeyboardFocus();
  31179. else
  31180. giveAwayFocus();
  31181. }
  31182. }
  31183. sendVisibilityChangeMessage();
  31184. if ((! deletionChecker.hasBeenDeleted()) && flags.hasHeavyweightPeerFlag)
  31185. {
  31186. ComponentPeer* const peer = getPeer();
  31187. jassert (peer != 0);
  31188. if (peer != 0)
  31189. {
  31190. peer->setVisible (shouldBeVisible);
  31191. internalHierarchyChanged();
  31192. }
  31193. }
  31194. }
  31195. }
  31196. void Component::visibilityChanged()
  31197. {
  31198. }
  31199. void Component::sendVisibilityChangeMessage()
  31200. {
  31201. const ComponentDeletionWatcher deletionChecker (this);
  31202. visibilityChanged();
  31203. if ((! deletionChecker.hasBeenDeleted()) && componentListeners_ != 0)
  31204. {
  31205. for (int i = componentListeners_->size(); --i >= 0;)
  31206. {
  31207. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31208. ->componentVisibilityChanged (*this);
  31209. if (deletionChecker.hasBeenDeleted())
  31210. return;
  31211. i = jmin (i, componentListeners_->size());
  31212. }
  31213. }
  31214. }
  31215. bool Component::isShowing() const throw()
  31216. {
  31217. if (flags.visibleFlag)
  31218. {
  31219. if (parentComponent_ != 0)
  31220. {
  31221. return parentComponent_->isShowing();
  31222. }
  31223. else
  31224. {
  31225. const ComponentPeer* const peer = getPeer();
  31226. return peer != 0 && ! peer->isMinimised();
  31227. }
  31228. }
  31229. return false;
  31230. }
  31231. class FadeOutProxyComponent : public Component,
  31232. public Timer
  31233. {
  31234. public:
  31235. FadeOutProxyComponent (Component* comp,
  31236. const int fadeLengthMs,
  31237. const int deltaXToMove,
  31238. const int deltaYToMove,
  31239. const float scaleFactorAtEnd)
  31240. : lastTime (0),
  31241. alpha (1.0f),
  31242. scale (1.0f)
  31243. {
  31244. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  31245. setBounds (comp->getBounds());
  31246. comp->getParentComponent()->addAndMakeVisible (this);
  31247. toBehind (comp);
  31248. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31249. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31250. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31251. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31252. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31253. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31254. setInterceptsMouseClicks (false, false);
  31255. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31256. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31257. }
  31258. ~FadeOutProxyComponent()
  31259. {
  31260. delete image;
  31261. }
  31262. void paint (Graphics& g)
  31263. {
  31264. g.setOpacity (alpha);
  31265. g.drawImage (image,
  31266. 0, 0, getWidth(), getHeight(),
  31267. 0, 0, image->getWidth(), image->getHeight());
  31268. }
  31269. void timerCallback()
  31270. {
  31271. const uint32 now = Time::getMillisecondCounter();
  31272. if (lastTime == 0)
  31273. lastTime = now;
  31274. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31275. lastTime = now;
  31276. alpha += alphaChangePerMs * msPassed;
  31277. if (alpha > 0)
  31278. {
  31279. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31280. {
  31281. centreX += xChangePerMs * msPassed;
  31282. centreY += yChangePerMs * msPassed;
  31283. scale += scaleChangePerMs * msPassed;
  31284. const int w = roundToInt (image->getWidth() * scale);
  31285. const int h = roundToInt (image->getHeight() * scale);
  31286. setBounds (roundToInt (centreX) - w / 2,
  31287. roundToInt (centreY) - h / 2,
  31288. w, h);
  31289. }
  31290. repaint();
  31291. }
  31292. else
  31293. {
  31294. delete this;
  31295. }
  31296. }
  31297. juce_UseDebuggingNewOperator
  31298. private:
  31299. Image* image;
  31300. uint32 lastTime;
  31301. float alpha, alphaChangePerMs;
  31302. float centreX, xChangePerMs;
  31303. float centreY, yChangePerMs;
  31304. float scale, scaleChangePerMs;
  31305. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31306. const FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31307. };
  31308. void Component::fadeOutComponent (const int millisecondsToFade,
  31309. const int deltaXToMove,
  31310. const int deltaYToMove,
  31311. const float scaleFactorAtEnd)
  31312. {
  31313. //xxx won't work for comps without parents
  31314. if (isShowing() && millisecondsToFade > 0)
  31315. new FadeOutProxyComponent (this, millisecondsToFade,
  31316. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31317. setVisible (false);
  31318. }
  31319. bool Component::isValidComponent() const throw()
  31320. {
  31321. return (this != 0) && isValidMessageListener();
  31322. }
  31323. void* Component::getWindowHandle() const throw()
  31324. {
  31325. const ComponentPeer* const peer = getPeer();
  31326. if (peer != 0)
  31327. return peer->getNativeHandle();
  31328. return 0;
  31329. }
  31330. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31331. {
  31332. // if component methods are being called from threads other than the message
  31333. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31334. checkMessageManagerIsLocked
  31335. if (isOpaque())
  31336. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31337. else
  31338. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31339. int currentStyleFlags = 0;
  31340. // don't use getPeer(), so that we only get the peer that's specifically
  31341. // for this comp, and not for one of its parents.
  31342. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31343. if (peer != 0)
  31344. currentStyleFlags = peer->getStyleFlags();
  31345. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31346. {
  31347. const ComponentDeletionWatcher deletionChecker (this);
  31348. #if JUCE_LINUX
  31349. // it's wise to give the component a non-zero size before
  31350. // putting it on the desktop, as X windows get confused by this, and
  31351. // a (1, 1) minimum size is enforced here.
  31352. setSize (jmax (1, getWidth()),
  31353. jmax (1, getHeight()));
  31354. #endif
  31355. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31356. bool wasFullscreen = false;
  31357. bool wasMinimised = false;
  31358. ComponentBoundsConstrainer* currentConstainer = 0;
  31359. Rectangle<int> oldNonFullScreenBounds;
  31360. if (peer != 0)
  31361. {
  31362. wasFullscreen = peer->isFullScreen();
  31363. wasMinimised = peer->isMinimised();
  31364. currentConstainer = peer->getConstrainer();
  31365. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31366. removeFromDesktop();
  31367. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31368. }
  31369. if (parentComponent_ != 0)
  31370. parentComponent_->removeChildComponent (this);
  31371. if (! deletionChecker.hasBeenDeleted())
  31372. {
  31373. flags.hasHeavyweightPeerFlag = true;
  31374. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31375. Desktop::getInstance().addDesktopComponent (this);
  31376. bounds_.setPosition (topLeft);
  31377. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31378. peer->setVisible (isVisible());
  31379. if (wasFullscreen)
  31380. {
  31381. peer->setFullScreen (true);
  31382. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31383. }
  31384. if (wasMinimised)
  31385. peer->setMinimised (true);
  31386. if (isAlwaysOnTop())
  31387. peer->setAlwaysOnTop (true);
  31388. peer->setConstrainer (currentConstainer);
  31389. repaint();
  31390. }
  31391. internalHierarchyChanged();
  31392. }
  31393. }
  31394. void Component::removeFromDesktop()
  31395. {
  31396. // if component methods are being called from threads other than the message
  31397. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31398. checkMessageManagerIsLocked
  31399. if (flags.hasHeavyweightPeerFlag)
  31400. {
  31401. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31402. flags.hasHeavyweightPeerFlag = false;
  31403. jassert (peer != 0);
  31404. delete peer;
  31405. Desktop::getInstance().removeDesktopComponent (this);
  31406. }
  31407. }
  31408. bool Component::isOnDesktop() const throw()
  31409. {
  31410. return flags.hasHeavyweightPeerFlag;
  31411. }
  31412. void Component::userTriedToCloseWindow()
  31413. {
  31414. /* This means that the user's trying to get rid of your window with the 'close window' system
  31415. menu option (on windows) or possibly the task manager - you should really handle this
  31416. and delete or hide your component in an appropriate way.
  31417. If you want to ignore the event and don't want to trigger this assertion, just override
  31418. this method and do nothing.
  31419. */
  31420. jassertfalse
  31421. }
  31422. void Component::minimisationStateChanged (bool)
  31423. {
  31424. }
  31425. void Component::setOpaque (const bool shouldBeOpaque) throw()
  31426. {
  31427. if (shouldBeOpaque != flags.opaqueFlag)
  31428. {
  31429. flags.opaqueFlag = shouldBeOpaque;
  31430. if (flags.hasHeavyweightPeerFlag)
  31431. {
  31432. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31433. if (peer != 0)
  31434. {
  31435. // to make it recreate the heavyweight window
  31436. addToDesktop (peer->getStyleFlags());
  31437. }
  31438. }
  31439. repaint();
  31440. }
  31441. }
  31442. bool Component::isOpaque() const throw()
  31443. {
  31444. return flags.opaqueFlag;
  31445. }
  31446. void Component::setBufferedToImage (const bool shouldBeBuffered) throw()
  31447. {
  31448. if (shouldBeBuffered != flags.bufferToImageFlag)
  31449. {
  31450. deleteAndZero (bufferedImage_);
  31451. flags.bufferToImageFlag = shouldBeBuffered;
  31452. }
  31453. }
  31454. void Component::toFront (const bool setAsForeground)
  31455. {
  31456. // if component methods are being called from threads other than the message
  31457. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31458. checkMessageManagerIsLocked
  31459. if (flags.hasHeavyweightPeerFlag)
  31460. {
  31461. ComponentPeer* const peer = getPeer();
  31462. if (peer != 0)
  31463. {
  31464. peer->toFront (setAsForeground);
  31465. if (setAsForeground && ! hasKeyboardFocus (true))
  31466. grabKeyboardFocus();
  31467. }
  31468. }
  31469. else if (parentComponent_ != 0)
  31470. {
  31471. if (parentComponent_->childComponentList_.getLast() != this)
  31472. {
  31473. const int index = parentComponent_->childComponentList_.indexOf (this);
  31474. if (index >= 0)
  31475. {
  31476. int insertIndex = -1;
  31477. if (! flags.alwaysOnTopFlag)
  31478. {
  31479. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31480. while (insertIndex > 0
  31481. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31482. {
  31483. --insertIndex;
  31484. }
  31485. }
  31486. if (index != insertIndex)
  31487. {
  31488. parentComponent_->childComponentList_.move (index, insertIndex);
  31489. sendFakeMouseMove();
  31490. repaintParent();
  31491. }
  31492. }
  31493. }
  31494. if (setAsForeground)
  31495. {
  31496. internalBroughtToFront();
  31497. grabKeyboardFocus();
  31498. }
  31499. }
  31500. }
  31501. void Component::toBehind (Component* const other)
  31502. {
  31503. if (other != 0)
  31504. {
  31505. // the two components must belong to the same parent..
  31506. jassert (parentComponent_ == other->parentComponent_);
  31507. if (parentComponent_ != 0)
  31508. {
  31509. const int index = parentComponent_->childComponentList_.indexOf (this);
  31510. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31511. if (index >= 0
  31512. && otherIndex >= 0
  31513. && index != otherIndex - 1
  31514. && other != this)
  31515. {
  31516. if (index < otherIndex)
  31517. --otherIndex;
  31518. parentComponent_->childComponentList_.move (index, otherIndex);
  31519. sendFakeMouseMove();
  31520. repaintParent();
  31521. }
  31522. }
  31523. else if (isOnDesktop())
  31524. {
  31525. jassert (other->isOnDesktop());
  31526. if (other->isOnDesktop())
  31527. {
  31528. ComponentPeer* const us = getPeer();
  31529. ComponentPeer* const them = other->getPeer();
  31530. jassert (us != 0 && them != 0);
  31531. if (us != 0 && them != 0)
  31532. us->toBehind (them);
  31533. }
  31534. }
  31535. }
  31536. }
  31537. void Component::toBack()
  31538. {
  31539. if (isOnDesktop())
  31540. {
  31541. jassertfalse //xxx need to add this to native window
  31542. }
  31543. else if (parentComponent_ != 0
  31544. && parentComponent_->childComponentList_.getFirst() != this)
  31545. {
  31546. const int index = parentComponent_->childComponentList_.indexOf (this);
  31547. if (index > 0)
  31548. {
  31549. int insertIndex = 0;
  31550. if (flags.alwaysOnTopFlag)
  31551. {
  31552. while (insertIndex < parentComponent_->childComponentList_.size()
  31553. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31554. {
  31555. ++insertIndex;
  31556. }
  31557. }
  31558. if (index != insertIndex)
  31559. {
  31560. parentComponent_->childComponentList_.move (index, insertIndex);
  31561. sendFakeMouseMove();
  31562. repaintParent();
  31563. }
  31564. }
  31565. }
  31566. }
  31567. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31568. {
  31569. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31570. {
  31571. flags.alwaysOnTopFlag = shouldStayOnTop;
  31572. if (isOnDesktop())
  31573. {
  31574. ComponentPeer* const peer = getPeer();
  31575. jassert (peer != 0);
  31576. if (peer != 0)
  31577. {
  31578. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31579. {
  31580. // some kinds of peer can't change their always-on-top status, so
  31581. // for these, we'll need to create a new window
  31582. const int oldFlags = peer->getStyleFlags();
  31583. removeFromDesktop();
  31584. addToDesktop (oldFlags);
  31585. }
  31586. }
  31587. }
  31588. if (shouldStayOnTop)
  31589. toFront (false);
  31590. internalHierarchyChanged();
  31591. }
  31592. }
  31593. bool Component::isAlwaysOnTop() const throw()
  31594. {
  31595. return flags.alwaysOnTopFlag;
  31596. }
  31597. int Component::proportionOfWidth (const float proportion) const throw()
  31598. {
  31599. return roundToInt (proportion * bounds_.getWidth());
  31600. }
  31601. int Component::proportionOfHeight (const float proportion) const throw()
  31602. {
  31603. return roundToInt (proportion * bounds_.getHeight());
  31604. }
  31605. int Component::getParentWidth() const throw()
  31606. {
  31607. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31608. : getParentMonitorArea().getWidth();
  31609. }
  31610. int Component::getParentHeight() const throw()
  31611. {
  31612. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31613. : getParentMonitorArea().getHeight();
  31614. }
  31615. int Component::getScreenX() const
  31616. {
  31617. return getScreenPosition().getX();
  31618. }
  31619. int Component::getScreenY() const
  31620. {
  31621. return getScreenPosition().getY();
  31622. }
  31623. const Point<int> Component::getScreenPosition() const
  31624. {
  31625. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31626. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31627. : getPosition());
  31628. }
  31629. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31630. {
  31631. const Component* c = this;
  31632. Point<int> p (relativePosition);
  31633. do
  31634. {
  31635. if (c->flags.hasHeavyweightPeerFlag)
  31636. return c->getPeer()->relativePositionToGlobal (p);
  31637. p += c->getPosition();
  31638. c = c->parentComponent_;
  31639. }
  31640. while (c != 0);
  31641. return p;
  31642. }
  31643. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31644. {
  31645. if (flags.hasHeavyweightPeerFlag)
  31646. {
  31647. return getPeer()->globalPositionToRelative (screenPosition);
  31648. }
  31649. else
  31650. {
  31651. if (parentComponent_ != 0)
  31652. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31653. return screenPosition - getPosition();
  31654. }
  31655. }
  31656. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31657. {
  31658. Point<int> p (positionRelativeToThis);
  31659. if (targetComponent != 0)
  31660. {
  31661. const Component* c = this;
  31662. do
  31663. {
  31664. if (c == targetComponent)
  31665. return p;
  31666. if (c->flags.hasHeavyweightPeerFlag)
  31667. {
  31668. p = c->getPeer()->relativePositionToGlobal (p);
  31669. break;
  31670. }
  31671. p += c->getPosition();
  31672. c = c->parentComponent_;
  31673. }
  31674. while (c != 0);
  31675. p = targetComponent->globalPositionToRelative (p);
  31676. }
  31677. return p;
  31678. }
  31679. void Component::setBounds (int x, int y, int w, int h)
  31680. {
  31681. // if component methods are being called from threads other than the message
  31682. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31683. checkMessageManagerIsLocked
  31684. if (w < 0) w = 0;
  31685. if (h < 0) h = 0;
  31686. const bool wasResized = (getWidth() != w || getHeight() != h);
  31687. const bool wasMoved = (getX() != x || getY() != y);
  31688. #ifdef JUCE_DEBUG
  31689. // It's a very bad idea to try to resize a window during its paint() method!
  31690. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31691. #endif
  31692. if (wasMoved || wasResized)
  31693. {
  31694. if (flags.visibleFlag)
  31695. {
  31696. // send a fake mouse move to trigger enter/exit messages if needed..
  31697. sendFakeMouseMove();
  31698. if (! flags.hasHeavyweightPeerFlag)
  31699. repaintParent();
  31700. }
  31701. bounds_.setBounds (x, y, w, h);
  31702. if (wasResized)
  31703. repaint();
  31704. else if (! flags.hasHeavyweightPeerFlag)
  31705. repaintParent();
  31706. if (flags.hasHeavyweightPeerFlag)
  31707. {
  31708. ComponentPeer* const peer = getPeer();
  31709. if (peer != 0)
  31710. {
  31711. if (wasMoved && wasResized)
  31712. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31713. else if (wasMoved)
  31714. peer->setPosition (getX(), getY());
  31715. else if (wasResized)
  31716. peer->setSize (getWidth(), getHeight());
  31717. }
  31718. }
  31719. sendMovedResizedMessages (wasMoved, wasResized);
  31720. }
  31721. }
  31722. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31723. {
  31724. JUCE_TRY
  31725. {
  31726. if (wasMoved)
  31727. moved();
  31728. if (wasResized)
  31729. {
  31730. resized();
  31731. for (int i = childComponentList_.size(); --i >= 0;)
  31732. {
  31733. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31734. i = jmin (i, childComponentList_.size());
  31735. }
  31736. }
  31737. if (parentComponent_ != 0)
  31738. parentComponent_->childBoundsChanged (this);
  31739. if (componentListeners_ != 0)
  31740. {
  31741. const ComponentDeletionWatcher deletionChecker (this);
  31742. for (int i = componentListeners_->size(); --i >= 0;)
  31743. {
  31744. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31745. ->componentMovedOrResized (*this, wasMoved, wasResized);
  31746. if (deletionChecker.hasBeenDeleted())
  31747. return;
  31748. i = jmin (i, componentListeners_->size());
  31749. }
  31750. }
  31751. }
  31752. JUCE_CATCH_EXCEPTION
  31753. }
  31754. void Component::setSize (const int w, const int h)
  31755. {
  31756. setBounds (getX(), getY(), w, h);
  31757. }
  31758. void Component::setTopLeftPosition (const int x, const int y)
  31759. {
  31760. setBounds (x, y, getWidth(), getHeight());
  31761. }
  31762. void Component::setTopRightPosition (const int x, const int y)
  31763. {
  31764. setTopLeftPosition (x - getWidth(), y);
  31765. }
  31766. void Component::setBounds (const Rectangle<int>& r)
  31767. {
  31768. setBounds (r.getX(),
  31769. r.getY(),
  31770. r.getWidth(),
  31771. r.getHeight());
  31772. }
  31773. void Component::setBoundsRelative (const float x, const float y,
  31774. const float w, const float h)
  31775. {
  31776. const int pw = getParentWidth();
  31777. const int ph = getParentHeight();
  31778. setBounds (roundToInt (x * pw),
  31779. roundToInt (y * ph),
  31780. roundToInt (w * pw),
  31781. roundToInt (h * ph));
  31782. }
  31783. void Component::setCentrePosition (const int x, const int y)
  31784. {
  31785. setTopLeftPosition (x - getWidth() / 2,
  31786. y - getHeight() / 2);
  31787. }
  31788. void Component::setCentreRelative (const float x, const float y)
  31789. {
  31790. setCentrePosition (roundToInt (getParentWidth() * x),
  31791. roundToInt (getParentHeight() * y));
  31792. }
  31793. void Component::centreWithSize (const int width, const int height)
  31794. {
  31795. setBounds ((getParentWidth() - width) / 2,
  31796. (getParentHeight() - height) / 2,
  31797. width,
  31798. height);
  31799. }
  31800. void Component::setBoundsInset (const BorderSize& borders)
  31801. {
  31802. setBounds (borders.getLeft(),
  31803. borders.getTop(),
  31804. getParentWidth() - (borders.getLeftAndRight()),
  31805. getParentHeight() - (borders.getTopAndBottom()));
  31806. }
  31807. void Component::setBoundsToFit (int x, int y, int width, int height,
  31808. const Justification& justification,
  31809. const bool onlyReduceInSize)
  31810. {
  31811. // it's no good calling this method unless both the component and
  31812. // target rectangle have a finite size.
  31813. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31814. if (getWidth() > 0 && getHeight() > 0
  31815. && width > 0 && height > 0)
  31816. {
  31817. int newW, newH;
  31818. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31819. {
  31820. newW = getWidth();
  31821. newH = getHeight();
  31822. }
  31823. else
  31824. {
  31825. const double imageRatio = getHeight() / (double) getWidth();
  31826. const double targetRatio = height / (double) width;
  31827. if (imageRatio <= targetRatio)
  31828. {
  31829. newW = width;
  31830. newH = jmin (height, roundToInt (newW * imageRatio));
  31831. }
  31832. else
  31833. {
  31834. newH = height;
  31835. newW = jmin (width, roundToInt (newH / imageRatio));
  31836. }
  31837. }
  31838. if (newW > 0 && newH > 0)
  31839. {
  31840. int newX, newY;
  31841. justification.applyToRectangle (newX, newY, newW, newH,
  31842. x, y, width, height);
  31843. setBounds (newX, newY, newW, newH);
  31844. }
  31845. }
  31846. }
  31847. bool Component::hitTest (int x, int y)
  31848. {
  31849. if (! flags.ignoresMouseClicksFlag)
  31850. return true;
  31851. if (flags.allowChildMouseClicksFlag)
  31852. {
  31853. for (int i = getNumChildComponents(); --i >= 0;)
  31854. {
  31855. Component* const c = getChildComponent (i);
  31856. if (c->isVisible()
  31857. && c->bounds_.contains (x, y)
  31858. && c->hitTest (x - c->getX(),
  31859. y - c->getY()))
  31860. {
  31861. return true;
  31862. }
  31863. }
  31864. }
  31865. return false;
  31866. }
  31867. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31868. const bool allowClicksOnChildComponents) throw()
  31869. {
  31870. flags.ignoresMouseClicksFlag = ! allowClicks;
  31871. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31872. }
  31873. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31874. bool& allowsClicksOnChildComponents) const throw()
  31875. {
  31876. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31877. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31878. }
  31879. bool Component::contains (const int x, const int y)
  31880. {
  31881. if (((unsigned int) x) < (unsigned int) getWidth()
  31882. && ((unsigned int) y) < (unsigned int) getHeight()
  31883. && hitTest (x, y))
  31884. {
  31885. if (parentComponent_ != 0)
  31886. {
  31887. return parentComponent_->contains (x + getX(),
  31888. y + getY());
  31889. }
  31890. else if (flags.hasHeavyweightPeerFlag)
  31891. {
  31892. const ComponentPeer* const peer = getPeer();
  31893. if (peer != 0)
  31894. return peer->contains (x, y, true);
  31895. }
  31896. }
  31897. return false;
  31898. }
  31899. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31900. {
  31901. if (! contains (x, y))
  31902. return false;
  31903. Component* p = this;
  31904. while (p->parentComponent_ != 0)
  31905. {
  31906. x += p->getX();
  31907. y += p->getY();
  31908. p = p->parentComponent_;
  31909. }
  31910. const Component* const c = p->getComponentAt (x, y);
  31911. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31912. }
  31913. Component* Component::getComponentAt (const int x, const int y)
  31914. {
  31915. if (flags.visibleFlag
  31916. && ((unsigned int) x) < (unsigned int) getWidth()
  31917. && ((unsigned int) y) < (unsigned int) getHeight()
  31918. && hitTest (x, y))
  31919. {
  31920. for (int i = childComponentList_.size(); --i >= 0;)
  31921. {
  31922. Component* const child = childComponentList_.getUnchecked(i);
  31923. Component* const c = child->getComponentAt (x - child->getX(),
  31924. y - child->getY());
  31925. if (c != 0)
  31926. return c;
  31927. }
  31928. return this;
  31929. }
  31930. return 0;
  31931. }
  31932. void Component::addChildComponent (Component* const child, int zOrder)
  31933. {
  31934. // if component methods are being called from threads other than the message
  31935. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31936. checkMessageManagerIsLocked
  31937. if (child != 0 && child->parentComponent_ != this)
  31938. {
  31939. if (child->parentComponent_ != 0)
  31940. child->parentComponent_->removeChildComponent (child);
  31941. else
  31942. child->removeFromDesktop();
  31943. child->parentComponent_ = this;
  31944. if (child->isVisible())
  31945. child->repaintParent();
  31946. if (! child->isAlwaysOnTop())
  31947. {
  31948. if (zOrder < 0 || zOrder > childComponentList_.size())
  31949. zOrder = childComponentList_.size();
  31950. while (zOrder > 0)
  31951. {
  31952. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31953. break;
  31954. --zOrder;
  31955. }
  31956. }
  31957. childComponentList_.insert (zOrder, child);
  31958. child->internalHierarchyChanged();
  31959. internalChildrenChanged();
  31960. }
  31961. }
  31962. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31963. {
  31964. if (child != 0)
  31965. {
  31966. child->setVisible (true);
  31967. addChildComponent (child, zOrder);
  31968. }
  31969. }
  31970. void Component::removeChildComponent (Component* const child)
  31971. {
  31972. removeChildComponent (childComponentList_.indexOf (child));
  31973. }
  31974. Component* Component::removeChildComponent (const int index)
  31975. {
  31976. // if component methods are being called from threads other than the message
  31977. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31978. checkMessageManagerIsLocked
  31979. Component* const child = childComponentList_ [index];
  31980. if (child != 0)
  31981. {
  31982. sendFakeMouseMove();
  31983. child->repaintParent();
  31984. childComponentList_.remove (index);
  31985. child->parentComponent_ = 0;
  31986. JUCE_TRY
  31987. {
  31988. if ((currentlyFocusedComponent == child)
  31989. || child->isParentOf (currentlyFocusedComponent))
  31990. {
  31991. // get rid first to force the grabKeyboardFocus to change to us.
  31992. giveAwayFocus();
  31993. grabKeyboardFocus();
  31994. }
  31995. }
  31996. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31997. catch (const std::exception& e)
  31998. {
  31999. currentlyFocusedComponent = 0;
  32000. Desktop::getInstance().triggerFocusCallback();
  32001. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32002. }
  32003. catch (...)
  32004. {
  32005. currentlyFocusedComponent = 0;
  32006. Desktop::getInstance().triggerFocusCallback();
  32007. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32008. }
  32009. #endif
  32010. child->internalHierarchyChanged();
  32011. internalChildrenChanged();
  32012. }
  32013. return child;
  32014. }
  32015. void Component::removeAllChildren()
  32016. {
  32017. for (int i = childComponentList_.size(); --i >= 0;)
  32018. removeChildComponent (i);
  32019. }
  32020. void Component::deleteAllChildren()
  32021. {
  32022. for (int i = childComponentList_.size(); --i >= 0;)
  32023. delete (removeChildComponent (i));
  32024. }
  32025. int Component::getNumChildComponents() const throw()
  32026. {
  32027. return childComponentList_.size();
  32028. }
  32029. Component* Component::getChildComponent (const int index) const throw()
  32030. {
  32031. return childComponentList_ [index];
  32032. }
  32033. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  32034. {
  32035. return childComponentList_.indexOf (const_cast <Component*> (child));
  32036. }
  32037. Component* Component::getTopLevelComponent() const throw()
  32038. {
  32039. const Component* comp = this;
  32040. while (comp->parentComponent_ != 0)
  32041. comp = comp->parentComponent_;
  32042. return (Component*) comp;
  32043. }
  32044. bool Component::isParentOf (const Component* possibleChild) const throw()
  32045. {
  32046. while (possibleChild->isValidComponent())
  32047. {
  32048. possibleChild = possibleChild->parentComponent_;
  32049. if (possibleChild == this)
  32050. return true;
  32051. }
  32052. return false;
  32053. }
  32054. void Component::parentHierarchyChanged()
  32055. {
  32056. }
  32057. void Component::childrenChanged()
  32058. {
  32059. }
  32060. void Component::internalChildrenChanged()
  32061. {
  32062. const ComponentDeletionWatcher deletionChecker (this);
  32063. const bool hasListeners = componentListeners_ != 0;
  32064. childrenChanged();
  32065. if (hasListeners)
  32066. {
  32067. if (deletionChecker.hasBeenDeleted())
  32068. return;
  32069. for (int i = componentListeners_->size(); --i >= 0;)
  32070. {
  32071. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32072. ->componentChildrenChanged (*this);
  32073. if (deletionChecker.hasBeenDeleted())
  32074. return;
  32075. i = jmin (i, componentListeners_->size());
  32076. }
  32077. }
  32078. }
  32079. void Component::internalHierarchyChanged()
  32080. {
  32081. parentHierarchyChanged();
  32082. const ComponentDeletionWatcher deletionChecker (this);
  32083. if (componentListeners_ != 0)
  32084. {
  32085. for (int i = componentListeners_->size(); --i >= 0;)
  32086. {
  32087. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32088. ->componentParentHierarchyChanged (*this);
  32089. if (deletionChecker.hasBeenDeleted())
  32090. return;
  32091. i = jmin (i, componentListeners_->size());
  32092. }
  32093. }
  32094. for (int i = childComponentList_.size(); --i >= 0;)
  32095. {
  32096. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  32097. // you really shouldn't delete the parent component during a callback telling you
  32098. // that it's changed..
  32099. jassert (! deletionChecker.hasBeenDeleted());
  32100. if (deletionChecker.hasBeenDeleted())
  32101. return;
  32102. i = jmin (i, childComponentList_.size());
  32103. }
  32104. }
  32105. void* Component::runModalLoopCallback (void* userData)
  32106. {
  32107. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  32108. }
  32109. int Component::runModalLoop()
  32110. {
  32111. if (! MessageManager::getInstance()->isThisTheMessageThread())
  32112. {
  32113. // use a callback so this can be called from non-gui threads
  32114. return (int) (pointer_sized_int)
  32115. MessageManager::getInstance()
  32116. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  32117. }
  32118. Component* const prevFocused = getCurrentlyFocusedComponent();
  32119. ScopedPointer <ComponentDeletionWatcher> deletionChecker;
  32120. if (prevFocused != 0)
  32121. deletionChecker = new ComponentDeletionWatcher (prevFocused);
  32122. if (! isCurrentlyModal())
  32123. enterModalState();
  32124. JUCE_TRY
  32125. {
  32126. while (flags.currentlyModalFlag && flags.visibleFlag)
  32127. {
  32128. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  32129. break;
  32130. // check whether this component was deleted during the last message
  32131. if (! isValidMessageListener())
  32132. break;
  32133. }
  32134. }
  32135. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32136. catch (const std::exception& e)
  32137. {
  32138. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32139. return 0;
  32140. }
  32141. catch (...)
  32142. {
  32143. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32144. return 0;
  32145. }
  32146. #endif
  32147. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32148. int returnValue = 0;
  32149. if (modalIndex >= 0)
  32150. {
  32151. modalComponentReturnValueKeys.remove (modalIndex);
  32152. returnValue = modalReturnValues.remove (modalIndex);
  32153. }
  32154. modalComponentStack.removeValue (this);
  32155. if (deletionChecker != 0 && ! deletionChecker->hasBeenDeleted())
  32156. prevFocused->grabKeyboardFocus();
  32157. return returnValue;
  32158. }
  32159. void Component::enterModalState (const bool takeKeyboardFocus_)
  32160. {
  32161. // if component methods are being called from threads other than the message
  32162. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32163. checkMessageManagerIsLocked
  32164. // Check for an attempt to make a component modal when it already is!
  32165. // This can cause nasty problems..
  32166. jassert (! flags.currentlyModalFlag);
  32167. if (! isCurrentlyModal())
  32168. {
  32169. modalComponentStack.add (this);
  32170. modalComponentReturnValueKeys.add (this);
  32171. modalReturnValues.add (0);
  32172. flags.currentlyModalFlag = true;
  32173. setVisible (true);
  32174. if (takeKeyboardFocus_)
  32175. grabKeyboardFocus();
  32176. }
  32177. }
  32178. void Component::exitModalState (const int returnValue)
  32179. {
  32180. if (isCurrentlyModal())
  32181. {
  32182. if (MessageManager::getInstance()->isThisTheMessageThread())
  32183. {
  32184. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32185. if (modalIndex >= 0)
  32186. {
  32187. modalReturnValues.set (modalIndex, returnValue);
  32188. }
  32189. else
  32190. {
  32191. modalComponentReturnValueKeys.add (this);
  32192. modalReturnValues.add (returnValue);
  32193. }
  32194. modalComponentStack.removeValue (this);
  32195. flags.currentlyModalFlag = false;
  32196. bringModalComponentToFront();
  32197. }
  32198. else
  32199. {
  32200. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32201. }
  32202. }
  32203. }
  32204. bool Component::isCurrentlyModal() const throw()
  32205. {
  32206. return flags.currentlyModalFlag
  32207. && getCurrentlyModalComponent() == this;
  32208. }
  32209. bool Component::isCurrentlyBlockedByAnotherModalComponent() const throw()
  32210. {
  32211. Component* const mc = getCurrentlyModalComponent();
  32212. return mc != 0
  32213. && mc != this
  32214. && (! mc->isParentOf (this))
  32215. && ! mc->canModalEventBeSentToComponent (this);
  32216. }
  32217. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32218. {
  32219. return modalComponentStack.size();
  32220. }
  32221. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32222. {
  32223. Component* const c = (Component*) (modalComponentStack [modalComponentStack.size() - index - 1]);
  32224. return c->isValidComponent() ? c : 0;
  32225. }
  32226. void Component::bringModalComponentToFront()
  32227. {
  32228. ComponentPeer* lastOne = 0;
  32229. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32230. {
  32231. Component* const c = getCurrentlyModalComponent (i);
  32232. if (c == 0)
  32233. break;
  32234. ComponentPeer* peer = c->getPeer();
  32235. if (peer != 0 && peer != lastOne)
  32236. {
  32237. if (lastOne == 0)
  32238. {
  32239. peer->toFront (true);
  32240. peer->grabFocus();
  32241. }
  32242. else
  32243. peer->toBehind (lastOne);
  32244. lastOne = peer;
  32245. }
  32246. }
  32247. }
  32248. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32249. {
  32250. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32251. }
  32252. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32253. {
  32254. return flags.bringToFrontOnClickFlag;
  32255. }
  32256. void Component::setMouseCursor (const MouseCursor& cursor) throw()
  32257. {
  32258. cursor_ = cursor;
  32259. if (flags.visibleFlag)
  32260. {
  32261. const Point<int> mousePos (getMouseXYRelative());
  32262. if (flags.draggingFlag || reallyContains (mousePos.getX(), mousePos.getY(), false))
  32263. {
  32264. internalUpdateMouseCursor (false);
  32265. }
  32266. }
  32267. }
  32268. const MouseCursor Component::getMouseCursor()
  32269. {
  32270. return cursor_;
  32271. }
  32272. void Component::updateMouseCursor() const throw()
  32273. {
  32274. sendFakeMouseMove();
  32275. }
  32276. void Component::internalUpdateMouseCursor (bool forcedUpdate) throw()
  32277. {
  32278. ComponentPeer* const peer = getPeer();
  32279. if (peer != 0)
  32280. {
  32281. MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this));
  32282. if (isUnboundedMouseModeOn
  32283. && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  32284. {
  32285. mc = MouseCursor::NoCursor;
  32286. forcedUpdate = true;
  32287. }
  32288. static void* currentCursorHandle = 0;
  32289. if (forcedUpdate || mc.getHandle() != currentCursorHandle)
  32290. {
  32291. currentCursorHandle = mc.getHandle();
  32292. mc.showInWindow (peer);
  32293. }
  32294. }
  32295. }
  32296. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32297. {
  32298. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32299. }
  32300. void Component::repaintParent() throw()
  32301. {
  32302. if (flags.visibleFlag)
  32303. internalRepaint (0, 0, getWidth(), getHeight());
  32304. }
  32305. void Component::repaint() throw()
  32306. {
  32307. repaint (0, 0, getWidth(), getHeight());
  32308. }
  32309. void Component::repaint (const int x, const int y,
  32310. const int w, const int h) throw()
  32311. {
  32312. deleteAndZero (bufferedImage_);
  32313. if (flags.visibleFlag)
  32314. internalRepaint (x, y, w, h);
  32315. }
  32316. void Component::internalRepaint (int x, int y, int w, int h)
  32317. {
  32318. // if component methods are being called from threads other than the message
  32319. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32320. checkMessageManagerIsLocked
  32321. if (x < 0)
  32322. {
  32323. w += x;
  32324. x = 0;
  32325. }
  32326. if (x + w > getWidth())
  32327. w = getWidth() - x;
  32328. if (w > 0)
  32329. {
  32330. if (y < 0)
  32331. {
  32332. h += y;
  32333. y = 0;
  32334. }
  32335. if (y + h > getHeight())
  32336. h = getHeight() - y;
  32337. if (h > 0)
  32338. {
  32339. if (parentComponent_ != 0)
  32340. {
  32341. x += getX();
  32342. y += getY();
  32343. if (parentComponent_->flags.visibleFlag)
  32344. parentComponent_->internalRepaint (x, y, w, h);
  32345. }
  32346. else if (flags.hasHeavyweightPeerFlag)
  32347. {
  32348. ComponentPeer* const peer = getPeer();
  32349. if (peer != 0)
  32350. peer->repaint (x, y, w, h);
  32351. }
  32352. }
  32353. }
  32354. }
  32355. void Component::paintEntireComponent (Graphics& originalContext)
  32356. {
  32357. jassert (! originalContext.isClipEmpty());
  32358. #ifdef JUCE_DEBUG
  32359. flags.isInsidePaintCall = true;
  32360. #endif
  32361. Graphics* g = &originalContext;
  32362. Image* effectImage = 0;
  32363. if (effect_ != 0)
  32364. {
  32365. effectImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32366. getWidth(), getHeight(),
  32367. ! flags.opaqueFlag);
  32368. g = new Graphics (*effectImage);
  32369. }
  32370. g->saveState();
  32371. clipObscuredRegions (*g, g->getClipBounds(), 0, 0);
  32372. if (! g->isClipEmpty())
  32373. {
  32374. if (bufferedImage_ != 0)
  32375. {
  32376. g->setColour (Colours::black);
  32377. g->drawImageAt (bufferedImage_, 0, 0);
  32378. }
  32379. else
  32380. {
  32381. if (flags.bufferToImageFlag)
  32382. {
  32383. if (bufferedImage_ == 0)
  32384. {
  32385. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32386. getWidth(), getHeight(), ! flags.opaqueFlag);
  32387. Graphics imG (*bufferedImage_);
  32388. paint (imG);
  32389. }
  32390. g->setColour (Colours::black);
  32391. g->drawImageAt (bufferedImage_, 0, 0);
  32392. }
  32393. else
  32394. {
  32395. paint (*g);
  32396. g->resetToDefaultState();
  32397. }
  32398. }
  32399. }
  32400. g->restoreState();
  32401. for (int i = 0; i < childComponentList_.size(); ++i)
  32402. {
  32403. Component* const child = childComponentList_.getUnchecked (i);
  32404. if (child->isVisible())
  32405. {
  32406. g->saveState();
  32407. if (g->reduceClipRegion (child->getX(), child->getY(),
  32408. child->getWidth(), child->getHeight()))
  32409. {
  32410. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32411. {
  32412. const Component* const sibling = childComponentList_.getUnchecked (j);
  32413. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32414. g->excludeClipRegion (sibling->getX(), sibling->getY(),
  32415. sibling->getWidth(), sibling->getHeight());
  32416. }
  32417. if (! g->isClipEmpty())
  32418. {
  32419. g->setOrigin (child->getX(), child->getY());
  32420. child->paintEntireComponent (*g);
  32421. }
  32422. }
  32423. g->restoreState();
  32424. }
  32425. }
  32426. JUCE_TRY
  32427. {
  32428. g->saveState();
  32429. paintOverChildren (*g);
  32430. g->restoreState();
  32431. }
  32432. JUCE_CATCH_EXCEPTION
  32433. if (effect_ != 0)
  32434. {
  32435. delete g;
  32436. effect_->applyEffect (*effectImage, originalContext);
  32437. delete effectImage;
  32438. }
  32439. #ifdef JUCE_DEBUG
  32440. flags.isInsidePaintCall = false;
  32441. #endif
  32442. }
  32443. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32444. const bool clipImageToComponentBounds)
  32445. {
  32446. Rectangle<int> r (areaToGrab);
  32447. if (clipImageToComponentBounds)
  32448. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32449. Image* const componentImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32450. jmax (1, r.getWidth()),
  32451. jmax (1, r.getHeight()),
  32452. true);
  32453. Graphics imageContext (*componentImage);
  32454. imageContext.setOrigin (-r.getX(),
  32455. -r.getY());
  32456. paintEntireComponent (imageContext);
  32457. return componentImage;
  32458. }
  32459. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32460. {
  32461. if (effect_ != effect)
  32462. {
  32463. effect_ = effect;
  32464. repaint();
  32465. }
  32466. }
  32467. LookAndFeel& Component::getLookAndFeel() const throw()
  32468. {
  32469. const Component* c = this;
  32470. do
  32471. {
  32472. if (c->lookAndFeel_ != 0)
  32473. return *(c->lookAndFeel_);
  32474. c = c->parentComponent_;
  32475. }
  32476. while (c != 0);
  32477. return LookAndFeel::getDefaultLookAndFeel();
  32478. }
  32479. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32480. {
  32481. if (lookAndFeel_ != newLookAndFeel)
  32482. {
  32483. lookAndFeel_ = newLookAndFeel;
  32484. sendLookAndFeelChange();
  32485. }
  32486. }
  32487. void Component::lookAndFeelChanged()
  32488. {
  32489. }
  32490. void Component::sendLookAndFeelChange()
  32491. {
  32492. repaint();
  32493. lookAndFeelChanged();
  32494. // (it's not a great idea to do anything that would delete this component
  32495. // during the lookAndFeelChanged() callback)
  32496. jassert (isValidComponent());
  32497. const ComponentDeletionWatcher deletionChecker (this);
  32498. for (int i = childComponentList_.size(); --i >= 0;)
  32499. {
  32500. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32501. if (deletionChecker.hasBeenDeleted())
  32502. return;
  32503. i = jmin (i, childComponentList_.size());
  32504. }
  32505. }
  32506. static const var::identifier getColourPropertyId (const int colourId)
  32507. {
  32508. String s;
  32509. s.preallocateStorage (18);
  32510. s << T("jcclr_") << colourId;
  32511. return s;
  32512. }
  32513. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const throw()
  32514. {
  32515. var* v = properties.getItem (getColourPropertyId (colourId));
  32516. if (v != 0)
  32517. return Colour ((int) *v);
  32518. if (inheritFromParent && parentComponent_ != 0)
  32519. return parentComponent_->findColour (colourId, true);
  32520. return getLookAndFeel().findColour (colourId);
  32521. }
  32522. bool Component::isColourSpecified (const int colourId) const throw()
  32523. {
  32524. return properties.contains (getColourPropertyId (colourId));
  32525. }
  32526. void Component::removeColour (const int colourId)
  32527. {
  32528. if (properties.remove (getColourPropertyId (colourId)))
  32529. colourChanged();
  32530. }
  32531. void Component::setColour (const int colourId, const Colour& colour)
  32532. {
  32533. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32534. colourChanged();
  32535. }
  32536. void Component::copyAllExplicitColoursTo (Component& target) const throw()
  32537. {
  32538. bool changed = false;
  32539. for (int i = properties.size(); --i >= 0;)
  32540. {
  32541. const var::identifier name (properties.getName(i));
  32542. if (name.name.startsWith (T("jcclr_")))
  32543. if (target.properties.set (name, properties [name]))
  32544. changed = true;
  32545. }
  32546. if (changed)
  32547. target.colourChanged();
  32548. }
  32549. void Component::colourChanged()
  32550. {
  32551. }
  32552. const Rectangle<int> Component::getUnclippedArea() const
  32553. {
  32554. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32555. Component* p = parentComponent_;
  32556. int px = getX();
  32557. int py = getY();
  32558. while (p != 0)
  32559. {
  32560. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32561. return Rectangle<int>();
  32562. px += p->getX();
  32563. py += p->getY();
  32564. p = p->parentComponent_;
  32565. }
  32566. return Rectangle<int> (x, y, w, h);
  32567. }
  32568. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32569. const int deltaX, const int deltaY) const throw()
  32570. {
  32571. for (int i = childComponentList_.size(); --i >= 0;)
  32572. {
  32573. const Component* const c = childComponentList_.getUnchecked(i);
  32574. if (c->isVisible())
  32575. {
  32576. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32577. if (! newClip.isEmpty())
  32578. {
  32579. if (c->isOpaque())
  32580. {
  32581. g.excludeClipRegion (deltaX + newClip.getX(),
  32582. deltaY + newClip.getY(),
  32583. newClip.getWidth(),
  32584. newClip.getHeight());
  32585. }
  32586. else
  32587. {
  32588. newClip.translate (-c->getX(), -c->getY());
  32589. c->clipObscuredRegions (g, newClip,
  32590. c->getX() + deltaX,
  32591. c->getY() + deltaY);
  32592. }
  32593. }
  32594. }
  32595. }
  32596. }
  32597. void Component::getVisibleArea (RectangleList& result,
  32598. const bool includeSiblings) const
  32599. {
  32600. result.clear();
  32601. const Rectangle<int> unclipped (getUnclippedArea());
  32602. if (! unclipped.isEmpty())
  32603. {
  32604. result.add (unclipped);
  32605. if (includeSiblings)
  32606. {
  32607. const Component* const c = getTopLevelComponent();
  32608. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32609. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32610. this);
  32611. }
  32612. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32613. result.consolidate();
  32614. }
  32615. }
  32616. void Component::subtractObscuredRegions (RectangleList& result,
  32617. const Point<int>& delta,
  32618. const Rectangle<int>& clipRect,
  32619. const Component* const compToAvoid) const throw()
  32620. {
  32621. for (int i = childComponentList_.size(); --i >= 0;)
  32622. {
  32623. const Component* const c = childComponentList_.getUnchecked(i);
  32624. if (c != compToAvoid && c->isVisible())
  32625. {
  32626. if (c->isOpaque())
  32627. {
  32628. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32629. childBounds.translate (delta.getX(), delta.getY());
  32630. result.subtract (childBounds);
  32631. }
  32632. else
  32633. {
  32634. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32635. newClip.translate (-c->getX(), -c->getY());
  32636. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32637. newClip, compToAvoid);
  32638. }
  32639. }
  32640. }
  32641. }
  32642. void Component::mouseEnter (const MouseEvent&)
  32643. {
  32644. // base class does nothing
  32645. }
  32646. void Component::mouseExit (const MouseEvent&)
  32647. {
  32648. // base class does nothing
  32649. }
  32650. void Component::mouseDown (const MouseEvent&)
  32651. {
  32652. // base class does nothing
  32653. }
  32654. void Component::mouseUp (const MouseEvent&)
  32655. {
  32656. // base class does nothing
  32657. }
  32658. void Component::mouseDrag (const MouseEvent&)
  32659. {
  32660. // base class does nothing
  32661. }
  32662. void Component::mouseMove (const MouseEvent&)
  32663. {
  32664. // base class does nothing
  32665. }
  32666. void Component::mouseDoubleClick (const MouseEvent&)
  32667. {
  32668. // base class does nothing
  32669. }
  32670. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32671. {
  32672. // the base class just passes this event up to its parent..
  32673. if (parentComponent_ != 0)
  32674. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32675. wheelIncrementX, wheelIncrementY);
  32676. }
  32677. void Component::resized()
  32678. {
  32679. // base class does nothing
  32680. }
  32681. void Component::moved()
  32682. {
  32683. // base class does nothing
  32684. }
  32685. void Component::childBoundsChanged (Component*)
  32686. {
  32687. // base class does nothing
  32688. }
  32689. void Component::parentSizeChanged()
  32690. {
  32691. // base class does nothing
  32692. }
  32693. void Component::addComponentListener (ComponentListener* const newListener) throw()
  32694. {
  32695. if (componentListeners_ == 0)
  32696. componentListeners_ = new VoidArray();
  32697. componentListeners_->addIfNotAlreadyThere (newListener);
  32698. }
  32699. void Component::removeComponentListener (ComponentListener* const listenerToRemove) throw()
  32700. {
  32701. jassert (isValidComponent());
  32702. if (componentListeners_ != 0)
  32703. componentListeners_->removeValue (listenerToRemove);
  32704. }
  32705. void Component::inputAttemptWhenModal()
  32706. {
  32707. bringModalComponentToFront();
  32708. getLookAndFeel().playAlertSound();
  32709. }
  32710. bool Component::canModalEventBeSentToComponent (const Component*)
  32711. {
  32712. return false;
  32713. }
  32714. void Component::internalModalInputAttempt()
  32715. {
  32716. Component* const current = getCurrentlyModalComponent();
  32717. if (current != 0)
  32718. current->inputAttemptWhenModal();
  32719. }
  32720. void Component::paint (Graphics&)
  32721. {
  32722. // all painting is done in the subclasses
  32723. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32724. }
  32725. void Component::paintOverChildren (Graphics&)
  32726. {
  32727. // all painting is done in the subclasses
  32728. }
  32729. void Component::handleMessage (const Message& message)
  32730. {
  32731. if (message.intParameter1 == exitModalStateMessage)
  32732. {
  32733. exitModalState (message.intParameter2);
  32734. }
  32735. else if (message.intParameter1 == customCommandMessage)
  32736. {
  32737. handleCommandMessage (message.intParameter2);
  32738. }
  32739. }
  32740. void Component::postCommandMessage (const int commandId) throw()
  32741. {
  32742. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32743. }
  32744. void Component::handleCommandMessage (int)
  32745. {
  32746. // used by subclasses
  32747. }
  32748. void Component::addMouseListener (MouseListener* const newListener,
  32749. const bool wantsEventsForAllNestedChildComponents) throw()
  32750. {
  32751. // if component methods are being called from threads other than the message
  32752. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32753. checkMessageManagerIsLocked
  32754. if (mouseListeners_ == 0)
  32755. mouseListeners_ = new VoidArray();
  32756. if (! mouseListeners_->contains (newListener))
  32757. {
  32758. if (wantsEventsForAllNestedChildComponents)
  32759. {
  32760. mouseListeners_->insert (0, newListener);
  32761. ++numDeepMouseListeners;
  32762. }
  32763. else
  32764. {
  32765. mouseListeners_->add (newListener);
  32766. }
  32767. }
  32768. }
  32769. void Component::removeMouseListener (MouseListener* const listenerToRemove) throw()
  32770. {
  32771. // if component methods are being called from threads other than the message
  32772. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32773. checkMessageManagerIsLocked
  32774. if (mouseListeners_ != 0)
  32775. {
  32776. const int index = mouseListeners_->indexOf (listenerToRemove);
  32777. if (index >= 0)
  32778. {
  32779. if (index < numDeepMouseListeners)
  32780. --numDeepMouseListeners;
  32781. mouseListeners_->remove (index);
  32782. }
  32783. }
  32784. }
  32785. void Component::internalMouseEnter (int x, int y, int64 time)
  32786. {
  32787. if (isCurrentlyBlockedByAnotherModalComponent())
  32788. {
  32789. // if something else is modal, always just show a normal mouse cursor
  32790. if (componentUnderMouse == this)
  32791. {
  32792. ComponentPeer* const peer = getPeer();
  32793. if (peer != 0)
  32794. {
  32795. MouseCursor mc (MouseCursor::NormalCursor);
  32796. mc.showInWindow (peer);
  32797. }
  32798. }
  32799. return;
  32800. }
  32801. if (isValidComponent() && ! flags.mouseInsideFlag)
  32802. {
  32803. flags.mouseInsideFlag = true;
  32804. flags.mouseOverFlag = true;
  32805. flags.draggingFlag = false;
  32806. const ComponentDeletionWatcher deletionChecker (this);
  32807. if (flags.repaintOnMouseActivityFlag)
  32808. repaint();
  32809. const MouseEvent me (Point<int> (x, y),
  32810. ModifierKeys::getCurrentModifiers(),
  32811. this,
  32812. Time (time),
  32813. Point<int> (x, y),
  32814. Time (time),
  32815. 0, false);
  32816. mouseEnter (me);
  32817. if (deletionChecker.hasBeenDeleted())
  32818. return;
  32819. Desktop::getInstance().resetTimer();
  32820. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32821. {
  32822. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseEnter (me);
  32823. if (deletionChecker.hasBeenDeleted())
  32824. return;
  32825. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32826. }
  32827. if (mouseListeners_ != 0)
  32828. {
  32829. for (int i = mouseListeners_->size(); --i >= 0;)
  32830. {
  32831. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32832. if (deletionChecker.hasBeenDeleted())
  32833. return;
  32834. i = jmin (i, mouseListeners_->size());
  32835. }
  32836. }
  32837. const Component* p = parentComponent_;
  32838. while (p != 0)
  32839. {
  32840. const ComponentDeletionWatcher parentDeletionChecker (p);
  32841. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32842. {
  32843. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32844. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32845. return;
  32846. i = jmin (i, p->numDeepMouseListeners);
  32847. }
  32848. p = p->parentComponent_;
  32849. }
  32850. }
  32851. if (componentUnderMouse == this)
  32852. internalUpdateMouseCursor (true);
  32853. }
  32854. void Component::internalMouseExit (int x, int y, int64 time)
  32855. {
  32856. const ComponentDeletionWatcher deletionChecker (this);
  32857. if (flags.draggingFlag)
  32858. {
  32859. internalMouseUp (ModifierKeys::getCurrentModifiers().getRawFlags(), x, y, time);
  32860. if (deletionChecker.hasBeenDeleted())
  32861. return;
  32862. }
  32863. enableUnboundedMouseMovement (false);
  32864. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32865. {
  32866. flags.mouseInsideFlag = false;
  32867. flags.mouseOverFlag = false;
  32868. flags.draggingFlag = false;
  32869. if (flags.repaintOnMouseActivityFlag)
  32870. repaint();
  32871. const MouseEvent me (Point<int> (x, y),
  32872. ModifierKeys::getCurrentModifiers(),
  32873. this,
  32874. Time (time),
  32875. Point<int> (x, y),
  32876. Time (time),
  32877. 0, false);
  32878. mouseExit (me);
  32879. if (deletionChecker.hasBeenDeleted())
  32880. return;
  32881. Desktop::getInstance().resetTimer();
  32882. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32883. {
  32884. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseExit (me);
  32885. if (deletionChecker.hasBeenDeleted())
  32886. return;
  32887. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32888. }
  32889. if (mouseListeners_ != 0)
  32890. {
  32891. for (int i = mouseListeners_->size(); --i >= 0;)
  32892. {
  32893. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32894. if (deletionChecker.hasBeenDeleted())
  32895. return;
  32896. i = jmin (i, mouseListeners_->size());
  32897. }
  32898. }
  32899. const Component* p = parentComponent_;
  32900. while (p != 0)
  32901. {
  32902. const ComponentDeletionWatcher parentDeletionChecker (p);
  32903. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32904. {
  32905. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32906. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32907. return;
  32908. i = jmin (i, p->numDeepMouseListeners);
  32909. }
  32910. p = p->parentComponent_;
  32911. }
  32912. }
  32913. }
  32914. class InternalDragRepeater : public Timer
  32915. {
  32916. public:
  32917. InternalDragRepeater() {}
  32918. ~InternalDragRepeater() {}
  32919. void timerCallback()
  32920. {
  32921. Component* const c = Component::getComponentUnderMouse();
  32922. if (c != 0 && c->isMouseButtonDown())
  32923. {
  32924. const Point<int> mousePos (c->getMouseXYRelative());
  32925. // the offsets have been added on, so must be taken off before calling the
  32926. // drag.. otherwise they'll be added twice
  32927. c->internalMouseDrag (mousePos.getX() - unboundedMouseOffset.getX(),
  32928. mousePos.getY() - unboundedMouseOffset.getY(),
  32929. Time::currentTimeMillis());
  32930. }
  32931. }
  32932. juce_UseDebuggingNewOperator
  32933. private:
  32934. InternalDragRepeater (const InternalDragRepeater&);
  32935. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32936. };
  32937. static InternalDragRepeater* dragRepeater = 0;
  32938. void Component::beginDragAutoRepeat (const int interval)
  32939. {
  32940. if (interval > 0)
  32941. {
  32942. if (dragRepeater == 0)
  32943. dragRepeater = new InternalDragRepeater();
  32944. if (dragRepeater->getTimerInterval() != interval)
  32945. dragRepeater->startTimer (interval);
  32946. }
  32947. else
  32948. {
  32949. deleteAndZero (dragRepeater);
  32950. }
  32951. }
  32952. void Component::internalMouseDown (const int x, const int y, const int64 time)
  32953. {
  32954. Desktop& desktop = Desktop::getInstance();
  32955. desktop.registerMouseDown (relativePositionToGlobal (Point<int> (x, y)), time, this);
  32956. const ComponentDeletionWatcher deletionChecker (this);
  32957. if (isCurrentlyBlockedByAnotherModalComponent())
  32958. {
  32959. internalModalInputAttempt();
  32960. if (deletionChecker.hasBeenDeleted())
  32961. return;
  32962. // If processing the input attempt has exited the modal loop, we'll allow the event
  32963. // to be delivered..
  32964. if (isCurrentlyBlockedByAnotherModalComponent())
  32965. {
  32966. // allow blocked mouse-events to go to global listeners..
  32967. const MouseEvent me (Point<int> (x, y),
  32968. ModifierKeys::getCurrentModifiers(),
  32969. this,
  32970. Time (time),
  32971. Point<int> (x, y),
  32972. desktop.getLastMouseDownTime(),
  32973. desktop.getNumberOfMultipleClicks(),
  32974. false);
  32975. desktop.resetTimer();
  32976. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  32977. {
  32978. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  32979. if (deletionChecker.hasBeenDeleted())
  32980. return;
  32981. i = jmin (i, desktop.mouseListeners.size());
  32982. }
  32983. return;
  32984. }
  32985. }
  32986. {
  32987. Component* c = this;
  32988. while (c != 0)
  32989. {
  32990. if (c->isBroughtToFrontOnMouseClick())
  32991. {
  32992. c->toFront (true);
  32993. if (deletionChecker.hasBeenDeleted())
  32994. return;
  32995. }
  32996. c = c->parentComponent_;
  32997. }
  32998. }
  32999. if (! flags.dontFocusOnMouseClickFlag)
  33000. grabFocusInternal (focusChangedByMouseClick);
  33001. if (! deletionChecker.hasBeenDeleted())
  33002. {
  33003. flags.draggingFlag = true;
  33004. flags.mouseOverFlag = true;
  33005. if (flags.repaintOnMouseActivityFlag)
  33006. repaint();
  33007. const MouseEvent me (Point<int> (x, y),
  33008. ModifierKeys::getCurrentModifiers(),
  33009. this,
  33010. desktop.getLastMouseDownTime(),
  33011. Point<int> (x, y),
  33012. desktop.getLastMouseDownTime(),
  33013. desktop.getNumberOfMultipleClicks(),
  33014. false);
  33015. mouseDown (me);
  33016. if (deletionChecker.hasBeenDeleted())
  33017. return;
  33018. desktop.resetTimer();
  33019. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33020. {
  33021. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  33022. if (deletionChecker.hasBeenDeleted())
  33023. return;
  33024. i = jmin (i, desktop.mouseListeners.size());
  33025. }
  33026. if (mouseListeners_ != 0)
  33027. {
  33028. for (int i = mouseListeners_->size(); --i >= 0;)
  33029. {
  33030. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  33031. if (deletionChecker.hasBeenDeleted())
  33032. return;
  33033. i = jmin (i, mouseListeners_->size());
  33034. }
  33035. }
  33036. const Component* p = parentComponent_;
  33037. while (p != 0)
  33038. {
  33039. const ComponentDeletionWatcher parentDeletionChecker (p);
  33040. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33041. {
  33042. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  33043. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33044. return;
  33045. i = jmin (i, p->numDeepMouseListeners);
  33046. }
  33047. p = p->parentComponent_;
  33048. }
  33049. }
  33050. }
  33051. void Component::internalMouseUp (const int oldModifiers, int x, int y, const int64 time)
  33052. {
  33053. if (isValidComponent() && flags.draggingFlag)
  33054. {
  33055. Desktop& desktop = Desktop::getInstance();
  33056. flags.draggingFlag = false;
  33057. deleteAndZero (dragRepeater);
  33058. x += unboundedMouseOffset.getX();
  33059. y += unboundedMouseOffset.getY();
  33060. desktop.registerMouseDrag (relativePositionToGlobal (Point<int> (x, y)));
  33061. const ComponentDeletionWatcher deletionChecker (this);
  33062. if (flags.repaintOnMouseActivityFlag)
  33063. repaint();
  33064. const Point<int> mouseDownPos (globalPositionToRelative (Desktop::getLastMouseDownPosition()));
  33065. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33066. const MouseEvent me (Point<int> (x, y),
  33067. oldModifiers,
  33068. this,
  33069. Time (time),
  33070. mouseDownPos,
  33071. lastMouseDownTime,
  33072. desktop.getNumberOfMultipleClicks(),
  33073. desktop.mouseMovedSignificantlySincePressed
  33074. || time > lastMouseDownTime.toMilliseconds() + 300);
  33075. mouseUp (me);
  33076. if (deletionChecker.hasBeenDeleted())
  33077. return;
  33078. desktop.resetTimer();
  33079. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33080. {
  33081. ((MouseListener*) desktop.mouseListeners[i])->mouseUp (me);
  33082. if (deletionChecker.hasBeenDeleted())
  33083. return;
  33084. i = jmin (i, desktop.mouseListeners.size());
  33085. }
  33086. if (mouseListeners_ != 0)
  33087. {
  33088. for (int i = mouseListeners_->size(); --i >= 0;)
  33089. {
  33090. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  33091. if (deletionChecker.hasBeenDeleted())
  33092. return;
  33093. i = jmin (i, mouseListeners_->size());
  33094. }
  33095. }
  33096. {
  33097. const Component* p = parentComponent_;
  33098. while (p != 0)
  33099. {
  33100. const ComponentDeletionWatcher parentDeletionChecker (p);
  33101. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33102. {
  33103. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  33104. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33105. return;
  33106. i = jmin (i, p->numDeepMouseListeners);
  33107. }
  33108. p = p->parentComponent_;
  33109. }
  33110. }
  33111. // check for double-click
  33112. if (me.getNumberOfClicks() >= 2)
  33113. {
  33114. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  33115. mouseDoubleClick (me);
  33116. int i;
  33117. for (i = desktop.mouseListeners.size(); --i >= 0;)
  33118. {
  33119. ((MouseListener*) desktop.mouseListeners[i])->mouseDoubleClick (me);
  33120. if (deletionChecker.hasBeenDeleted())
  33121. return;
  33122. i = jmin (i, desktop.mouseListeners.size());
  33123. }
  33124. for (i = numListeners; --i >= 0;)
  33125. {
  33126. if (deletionChecker.hasBeenDeleted() || mouseListeners_ == 0)
  33127. return;
  33128. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  33129. if (ml != 0)
  33130. ml->mouseDoubleClick (me);
  33131. }
  33132. if (deletionChecker.hasBeenDeleted())
  33133. return;
  33134. const Component* p = parentComponent_;
  33135. while (p != 0)
  33136. {
  33137. const ComponentDeletionWatcher parentDeletionChecker (p);
  33138. for (i = p->numDeepMouseListeners; --i >= 0;)
  33139. {
  33140. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  33141. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33142. return;
  33143. i = jmin (i, p->numDeepMouseListeners);
  33144. }
  33145. p = p->parentComponent_;
  33146. }
  33147. }
  33148. }
  33149. enableUnboundedMouseMovement (false);
  33150. }
  33151. void Component::internalMouseDrag (int x, int y, const int64 time)
  33152. {
  33153. if (isValidComponent() && flags.draggingFlag)
  33154. {
  33155. Desktop& desktop = Desktop::getInstance();
  33156. flags.mouseOverFlag = reallyContains (x, y, false);
  33157. x += unboundedMouseOffset.getX();
  33158. y += unboundedMouseOffset.getY();
  33159. desktop.registerMouseDrag (relativePositionToGlobal (Point<int> (x, y)));
  33160. const ComponentDeletionWatcher deletionChecker (this);
  33161. const Point<int> mouseDownPos (globalPositionToRelative (Desktop::getLastMouseDownPosition()));
  33162. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33163. const MouseEvent me (Point<int> (x, y),
  33164. ModifierKeys::getCurrentModifiers(),
  33165. this,
  33166. Time (time),
  33167. mouseDownPos,
  33168. lastMouseDownTime,
  33169. desktop.getNumberOfMultipleClicks(),
  33170. desktop.mouseMovedSignificantlySincePressed
  33171. || time > lastMouseDownTime.toMilliseconds() + 300);
  33172. mouseDrag (me);
  33173. if (deletionChecker.hasBeenDeleted())
  33174. return;
  33175. desktop.resetTimer();
  33176. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33177. {
  33178. ((MouseListener*) desktop.mouseListeners[i])->mouseDrag (me);
  33179. if (deletionChecker.hasBeenDeleted())
  33180. return;
  33181. i = jmin (i, desktop.mouseListeners.size());
  33182. }
  33183. if (mouseListeners_ != 0)
  33184. {
  33185. for (int i = mouseListeners_->size(); --i >= 0;)
  33186. {
  33187. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  33188. if (deletionChecker.hasBeenDeleted())
  33189. return;
  33190. i = jmin (i, mouseListeners_->size());
  33191. }
  33192. }
  33193. const Component* p = parentComponent_;
  33194. while (p != 0)
  33195. {
  33196. const ComponentDeletionWatcher parentDeletionChecker (p);
  33197. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33198. {
  33199. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  33200. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33201. return;
  33202. i = jmin (i, p->numDeepMouseListeners);
  33203. }
  33204. p = p->parentComponent_;
  33205. }
  33206. if (this == componentUnderMouse)
  33207. {
  33208. if (isUnboundedMouseModeOn)
  33209. {
  33210. Rectangle<int> screenArea (getParentMonitorArea().expanded (-2, -2));
  33211. Point<int> mousePos (Desktop::getMousePosition());
  33212. if (! screenArea.contains (mousePos))
  33213. {
  33214. int deltaX = 0, deltaY = 0;
  33215. if (mousePos.getX() <= screenArea.getX() || mousePos.getX() >= screenArea.getRight())
  33216. deltaX = getScreenX() + getWidth() / 2 - mousePos.getX();
  33217. if (mousePos.getY() <= screenArea.getY() || mousePos.getY() >= screenArea.getBottom())
  33218. deltaY = getScreenY() + getHeight() / 2 - mousePos.getY();
  33219. unboundedMouseOffset -= Point<int> (deltaX, deltaY);
  33220. Desktop::setMousePosition (mousePos + Point<int> (deltaX, deltaY));
  33221. }
  33222. else if (isCursorVisibleUntilOffscreen
  33223. && (! unboundedMouseOffset.isOrigin())
  33224. && screenArea.contains (mousePos + unboundedMouseOffset))
  33225. {
  33226. mousePos += unboundedMouseOffset;
  33227. unboundedMouseOffset = Point<int>();
  33228. Desktop::setMousePosition (mousePos);
  33229. }
  33230. }
  33231. internalUpdateMouseCursor (false);
  33232. }
  33233. }
  33234. }
  33235. void Component::internalMouseMove (const int x, const int y, const int64 time)
  33236. {
  33237. const ComponentDeletionWatcher deletionChecker (this);
  33238. if (isValidComponent())
  33239. {
  33240. Desktop& desktop = Desktop::getInstance();
  33241. const MouseEvent me (Point<int> (x, y),
  33242. ModifierKeys::getCurrentModifiers(),
  33243. this,
  33244. Time (time),
  33245. Point<int> (x, y),
  33246. Time (time),
  33247. 0, false);
  33248. if (isCurrentlyBlockedByAnotherModalComponent())
  33249. {
  33250. // allow blocked mouse-events to go to global listeners..
  33251. desktop.sendMouseMove();
  33252. }
  33253. else
  33254. {
  33255. if (this == componentUnderMouse)
  33256. internalUpdateMouseCursor (false);
  33257. flags.mouseOverFlag = true;
  33258. mouseMove (me);
  33259. if (deletionChecker.hasBeenDeleted())
  33260. return;
  33261. desktop.resetTimer();
  33262. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33263. {
  33264. ((MouseListener*) desktop.mouseListeners[i])->mouseMove (me);
  33265. if (deletionChecker.hasBeenDeleted())
  33266. return;
  33267. i = jmin (i, desktop.mouseListeners.size());
  33268. }
  33269. if (mouseListeners_ != 0)
  33270. {
  33271. for (int i = mouseListeners_->size(); --i >= 0;)
  33272. {
  33273. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  33274. if (deletionChecker.hasBeenDeleted())
  33275. return;
  33276. i = jmin (i, mouseListeners_->size());
  33277. }
  33278. }
  33279. const Component* p = parentComponent_;
  33280. while (p != 0)
  33281. {
  33282. const ComponentDeletionWatcher parentDeletionChecker (p);
  33283. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33284. {
  33285. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  33286. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33287. return;
  33288. i = jmin (i, p->numDeepMouseListeners);
  33289. }
  33290. p = p->parentComponent_;
  33291. }
  33292. }
  33293. }
  33294. }
  33295. void Component::internalMouseWheel (const int intAmountX, const int intAmountY, const int64 time)
  33296. {
  33297. Desktop& desktop = Desktop::getInstance();
  33298. const ComponentDeletionWatcher deletionChecker (this);
  33299. const float wheelIncrementX = intAmountX * (1.0f / 256.0f);
  33300. const float wheelIncrementY = intAmountY * (1.0f / 256.0f);
  33301. const Point<int> mousePos (getMouseXYRelative());
  33302. const MouseEvent me (mousePos,
  33303. ModifierKeys::getCurrentModifiers(),
  33304. this,
  33305. Time (time),
  33306. mousePos,
  33307. Time (time),
  33308. 0, false);
  33309. if (isCurrentlyBlockedByAnotherModalComponent())
  33310. {
  33311. // allow blocked mouse-events to go to global listeners..
  33312. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33313. {
  33314. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33315. if (deletionChecker.hasBeenDeleted())
  33316. return;
  33317. i = jmin (i, desktop.mouseListeners.size());
  33318. }
  33319. }
  33320. else
  33321. {
  33322. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33323. if (deletionChecker.hasBeenDeleted())
  33324. return;
  33325. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33326. {
  33327. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33328. if (deletionChecker.hasBeenDeleted())
  33329. return;
  33330. i = jmin (i, desktop.mouseListeners.size());
  33331. }
  33332. if (mouseListeners_ != 0)
  33333. {
  33334. for (int i = mouseListeners_->size(); --i >= 0;)
  33335. {
  33336. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33337. if (deletionChecker.hasBeenDeleted())
  33338. return;
  33339. i = jmin (i, mouseListeners_->size());
  33340. }
  33341. }
  33342. const Component* p = parentComponent_;
  33343. while (p != 0)
  33344. {
  33345. const ComponentDeletionWatcher parentDeletionChecker (p);
  33346. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33347. {
  33348. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33349. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33350. return;
  33351. i = jmin (i, p->numDeepMouseListeners);
  33352. }
  33353. p = p->parentComponent_;
  33354. }
  33355. sendFakeMouseMove();
  33356. }
  33357. }
  33358. void Component::sendFakeMouseMove() const
  33359. {
  33360. ComponentPeer* const peer = getPeer();
  33361. if (peer != 0)
  33362. peer->sendFakeMouseMove();
  33363. }
  33364. void Component::broughtToFront()
  33365. {
  33366. }
  33367. void Component::internalBroughtToFront()
  33368. {
  33369. if (isValidComponent())
  33370. {
  33371. if (flags.hasHeavyweightPeerFlag)
  33372. Desktop::getInstance().componentBroughtToFront (this);
  33373. const ComponentDeletionWatcher deletionChecker (this);
  33374. broughtToFront();
  33375. if (deletionChecker.hasBeenDeleted())
  33376. return;
  33377. if (componentListeners_ != 0)
  33378. {
  33379. for (int i = componentListeners_->size(); --i >= 0;)
  33380. {
  33381. ((ComponentListener*) componentListeners_->getUnchecked (i))
  33382. ->componentBroughtToFront (*this);
  33383. if (deletionChecker.hasBeenDeleted())
  33384. return;
  33385. i = jmin (i, componentListeners_->size());
  33386. }
  33387. }
  33388. // when brought to the front and there's a modal component blocking this one,
  33389. // we need to bring the modal one to the front instead..
  33390. Component* const cm = getCurrentlyModalComponent();
  33391. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33392. bringModalComponentToFront();
  33393. }
  33394. }
  33395. void Component::focusGained (FocusChangeType)
  33396. {
  33397. // base class does nothing
  33398. }
  33399. void Component::internalFocusGain (const FocusChangeType cause)
  33400. {
  33401. const ComponentDeletionWatcher deletionChecker (this);
  33402. focusGained (cause);
  33403. if (! deletionChecker.hasBeenDeleted())
  33404. internalChildFocusChange (cause);
  33405. }
  33406. void Component::focusLost (FocusChangeType)
  33407. {
  33408. // base class does nothing
  33409. }
  33410. void Component::internalFocusLoss (const FocusChangeType cause)
  33411. {
  33412. const ComponentDeletionWatcher deletionChecker (this);
  33413. focusLost (focusChangedDirectly);
  33414. if (! deletionChecker.hasBeenDeleted())
  33415. internalChildFocusChange (cause);
  33416. }
  33417. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33418. {
  33419. // base class does nothing
  33420. }
  33421. void Component::internalChildFocusChange (FocusChangeType cause)
  33422. {
  33423. const bool childIsNowFocused = hasKeyboardFocus (true);
  33424. if (flags.childCompFocusedFlag != childIsNowFocused)
  33425. {
  33426. flags.childCompFocusedFlag = childIsNowFocused;
  33427. const ComponentDeletionWatcher deletionChecker (this);
  33428. focusOfChildComponentChanged (cause);
  33429. if (deletionChecker.hasBeenDeleted())
  33430. return;
  33431. }
  33432. if (parentComponent_ != 0)
  33433. parentComponent_->internalChildFocusChange (cause);
  33434. }
  33435. bool Component::isEnabled() const throw()
  33436. {
  33437. return (! flags.isDisabledFlag)
  33438. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33439. }
  33440. void Component::setEnabled (const bool shouldBeEnabled)
  33441. {
  33442. if (flags.isDisabledFlag == shouldBeEnabled)
  33443. {
  33444. flags.isDisabledFlag = ! shouldBeEnabled;
  33445. // if any parent components are disabled, setting our flag won't make a difference,
  33446. // so no need to send a change message
  33447. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33448. sendEnablementChangeMessage();
  33449. }
  33450. }
  33451. void Component::sendEnablementChangeMessage()
  33452. {
  33453. const ComponentDeletionWatcher deletionChecker (this);
  33454. enablementChanged();
  33455. if (deletionChecker.hasBeenDeleted())
  33456. return;
  33457. for (int i = getNumChildComponents(); --i >= 0;)
  33458. {
  33459. Component* const c = getChildComponent (i);
  33460. if (c != 0)
  33461. {
  33462. c->sendEnablementChangeMessage();
  33463. if (deletionChecker.hasBeenDeleted())
  33464. return;
  33465. }
  33466. }
  33467. }
  33468. void Component::enablementChanged()
  33469. {
  33470. }
  33471. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33472. {
  33473. flags.wantsFocusFlag = wantsFocus;
  33474. }
  33475. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33476. {
  33477. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33478. }
  33479. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33480. {
  33481. return ! flags.dontFocusOnMouseClickFlag;
  33482. }
  33483. bool Component::getWantsKeyboardFocus() const throw()
  33484. {
  33485. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33486. }
  33487. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33488. {
  33489. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33490. }
  33491. bool Component::isFocusContainer() const throw()
  33492. {
  33493. return flags.isFocusContainerFlag;
  33494. }
  33495. int Component::getExplicitFocusOrder() const throw()
  33496. {
  33497. return properties ["_jexfo"];
  33498. }
  33499. void Component::setExplicitFocusOrder (const int newFocusOrderIndex) throw()
  33500. {
  33501. properties.set ("_jexfo", newFocusOrderIndex);
  33502. }
  33503. KeyboardFocusTraverser* Component::createFocusTraverser()
  33504. {
  33505. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33506. return new KeyboardFocusTraverser();
  33507. return parentComponent_->createFocusTraverser();
  33508. }
  33509. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33510. {
  33511. // give the focus to this component
  33512. if (currentlyFocusedComponent != this)
  33513. {
  33514. JUCE_TRY
  33515. {
  33516. // get the focus onto our desktop window
  33517. ComponentPeer* const peer = getPeer();
  33518. if (peer != 0)
  33519. {
  33520. const ComponentDeletionWatcher deletionChecker (this);
  33521. peer->grabFocus();
  33522. if (peer->isFocused() && currentlyFocusedComponent != this)
  33523. {
  33524. Component* const componentLosingFocus = currentlyFocusedComponent;
  33525. currentlyFocusedComponent = this;
  33526. Desktop::getInstance().triggerFocusCallback();
  33527. // call this after setting currentlyFocusedComponent so that the one that's
  33528. // losing it has a chance to see where focus is going
  33529. if (componentLosingFocus->isValidComponent())
  33530. componentLosingFocus->internalFocusLoss (cause);
  33531. if (currentlyFocusedComponent == this)
  33532. {
  33533. focusGained (cause);
  33534. if (! deletionChecker.hasBeenDeleted())
  33535. internalChildFocusChange (cause);
  33536. }
  33537. }
  33538. }
  33539. }
  33540. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33541. catch (const std::exception& e)
  33542. {
  33543. currentlyFocusedComponent = 0;
  33544. Desktop::getInstance().triggerFocusCallback();
  33545. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33546. }
  33547. catch (...)
  33548. {
  33549. currentlyFocusedComponent = 0;
  33550. Desktop::getInstance().triggerFocusCallback();
  33551. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33552. }
  33553. #endif
  33554. }
  33555. }
  33556. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33557. {
  33558. if (isShowing())
  33559. {
  33560. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33561. {
  33562. takeKeyboardFocus (cause);
  33563. }
  33564. else
  33565. {
  33566. if (isParentOf (currentlyFocusedComponent)
  33567. && currentlyFocusedComponent->isShowing())
  33568. {
  33569. // do nothing if the focused component is actually a child of ours..
  33570. }
  33571. else
  33572. {
  33573. // find the default child component..
  33574. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33575. if (traverser != 0)
  33576. {
  33577. Component* const defaultComp = traverser->getDefaultComponent (this);
  33578. traverser = 0;
  33579. if (defaultComp != 0)
  33580. {
  33581. defaultComp->grabFocusInternal (cause, false);
  33582. return;
  33583. }
  33584. }
  33585. if (canTryParent && parentComponent_ != 0)
  33586. {
  33587. // if no children want it and we're allowed to try our parent comp,
  33588. // then pass up to parent, which will try our siblings.
  33589. parentComponent_->grabFocusInternal (cause, true);
  33590. }
  33591. }
  33592. }
  33593. }
  33594. }
  33595. void Component::grabKeyboardFocus()
  33596. {
  33597. // if component methods are being called from threads other than the message
  33598. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33599. checkMessageManagerIsLocked
  33600. grabFocusInternal (focusChangedDirectly);
  33601. }
  33602. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33603. {
  33604. // if component methods are being called from threads other than the message
  33605. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33606. checkMessageManagerIsLocked
  33607. if (parentComponent_ != 0)
  33608. {
  33609. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33610. if (traverser != 0)
  33611. {
  33612. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33613. : traverser->getPreviousComponent (this);
  33614. traverser = 0;
  33615. if (nextComp != 0)
  33616. {
  33617. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33618. {
  33619. const ComponentDeletionWatcher deletionChecker (nextComp);
  33620. internalModalInputAttempt();
  33621. if (deletionChecker.hasBeenDeleted()
  33622. || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33623. return;
  33624. }
  33625. nextComp->grabFocusInternal (focusChangedByTabKey);
  33626. return;
  33627. }
  33628. }
  33629. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33630. }
  33631. }
  33632. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const throw()
  33633. {
  33634. return (currentlyFocusedComponent == this)
  33635. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33636. }
  33637. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33638. {
  33639. return currentlyFocusedComponent;
  33640. }
  33641. void Component::giveAwayFocus()
  33642. {
  33643. // use a copy so we can clear the value before the call
  33644. Component* const componentLosingFocus = currentlyFocusedComponent;
  33645. currentlyFocusedComponent = 0;
  33646. Desktop::getInstance().triggerFocusCallback();
  33647. if (componentLosingFocus->isValidComponent())
  33648. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33649. }
  33650. bool Component::isMouseOver() const throw()
  33651. {
  33652. return flags.mouseOverFlag;
  33653. }
  33654. bool Component::isMouseButtonDown() const throw()
  33655. {
  33656. return flags.draggingFlag;
  33657. }
  33658. bool Component::isMouseOverOrDragging() const throw()
  33659. {
  33660. return flags.mouseOverFlag || flags.draggingFlag;
  33661. }
  33662. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33663. {
  33664. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33665. }
  33666. const Point<int> Component::getMouseXYRelative() const
  33667. {
  33668. return globalPositionToRelative (Desktop::getMousePosition()) + unboundedMouseOffset;
  33669. }
  33670. void Component::enableUnboundedMouseMovement (bool enable,
  33671. bool keepCursorVisibleUntilOffscreen) throw()
  33672. {
  33673. enable = enable && isMouseButtonDown();
  33674. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  33675. if (enable != isUnboundedMouseModeOn)
  33676. {
  33677. if ((! enable) && ((! isCursorVisibleUntilOffscreen)
  33678. || ! unboundedMouseOffset.isOrigin()))
  33679. {
  33680. // when released, return the mouse to within the component's bounds
  33681. Desktop::setMousePosition (relativePositionToGlobal (Rectangle<int> (0, 0, getWidth(), getHeight())
  33682. .getConstrainedPoint (getMouseXYRelative())));
  33683. }
  33684. isUnboundedMouseModeOn = enable;
  33685. unboundedMouseOffset = Point<int>();
  33686. internalUpdateMouseCursor (true);
  33687. }
  33688. }
  33689. Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw()
  33690. {
  33691. return componentUnderMouse;
  33692. }
  33693. const Rectangle<int> Component::getParentMonitorArea() const throw()
  33694. {
  33695. return Desktop::getInstance()
  33696. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33697. getHeight() / 2)));
  33698. }
  33699. void Component::addKeyListener (KeyListener* const newListener) throw()
  33700. {
  33701. if (keyListeners_ == 0)
  33702. keyListeners_ = new VoidArray();
  33703. keyListeners_->addIfNotAlreadyThere (newListener);
  33704. }
  33705. void Component::removeKeyListener (KeyListener* const listenerToRemove) throw()
  33706. {
  33707. if (keyListeners_ != 0)
  33708. keyListeners_->removeValue (listenerToRemove);
  33709. }
  33710. bool Component::keyPressed (const KeyPress&)
  33711. {
  33712. return false;
  33713. }
  33714. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33715. {
  33716. return false;
  33717. }
  33718. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33719. {
  33720. if (parentComponent_ != 0)
  33721. parentComponent_->modifierKeysChanged (modifiers);
  33722. }
  33723. void Component::internalModifierKeysChanged()
  33724. {
  33725. sendFakeMouseMove();
  33726. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33727. }
  33728. ComponentPeer* Component::getPeer() const throw()
  33729. {
  33730. if (flags.hasHeavyweightPeerFlag)
  33731. return ComponentPeer::getPeerFor (this);
  33732. else if (parentComponent_ != 0)
  33733. return parentComponent_->getPeer();
  33734. else
  33735. return 0;
  33736. }
  33737. ComponentDeletionWatcher::ComponentDeletionWatcher (const Component* const componentToWatch_) throw()
  33738. : componentToWatch (componentToWatch_),
  33739. componentUID (componentToWatch_->getComponentUID())
  33740. {
  33741. // not possible to check on an already-deleted object..
  33742. jassert (componentToWatch_->isValidComponent());
  33743. }
  33744. ComponentDeletionWatcher::~ComponentDeletionWatcher() throw() {}
  33745. bool ComponentDeletionWatcher::hasBeenDeleted() const throw()
  33746. {
  33747. return ! (componentToWatch->isValidComponent()
  33748. && componentToWatch->getComponentUID() == componentUID);
  33749. }
  33750. const Component* ComponentDeletionWatcher::getComponent() const throw()
  33751. {
  33752. return hasBeenDeleted() ? 0 : componentToWatch;
  33753. }
  33754. END_JUCE_NAMESPACE
  33755. /*** End of inlined file: juce_Component.cpp ***/
  33756. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33757. BEGIN_JUCE_NAMESPACE
  33758. void ComponentListener::componentMovedOrResized (Component&, bool, bool)
  33759. {
  33760. }
  33761. void ComponentListener::componentBroughtToFront (Component&)
  33762. {
  33763. }
  33764. void ComponentListener::componentVisibilityChanged (Component&)
  33765. {
  33766. }
  33767. void ComponentListener::componentChildrenChanged (Component&)
  33768. {
  33769. }
  33770. void ComponentListener::componentParentHierarchyChanged (Component&)
  33771. {
  33772. }
  33773. void ComponentListener::componentNameChanged (Component&)
  33774. {
  33775. }
  33776. END_JUCE_NAMESPACE
  33777. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33778. /*** Start of inlined file: juce_Desktop.cpp ***/
  33779. BEGIN_JUCE_NAMESPACE
  33780. Desktop::Desktop() throw()
  33781. : mouseClickCounter (0),
  33782. mouseMovedSignificantlySincePressed (false),
  33783. kioskModeComponent (0)
  33784. {
  33785. zerostruct (mouseDowns);
  33786. refreshMonitorSizes();
  33787. }
  33788. Desktop::~Desktop() throw()
  33789. {
  33790. jassert (instance == this);
  33791. instance = 0;
  33792. // doh! If you don't delete all your windows before exiting, you're going to
  33793. // be leaking memory!
  33794. jassert (desktopComponents.size() == 0);
  33795. }
  33796. Desktop& JUCE_CALLTYPE Desktop::getInstance() throw()
  33797. {
  33798. if (instance == 0)
  33799. instance = new Desktop();
  33800. return *instance;
  33801. }
  33802. Desktop* Desktop::instance = 0;
  33803. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33804. const bool clipToWorkArea);
  33805. void Desktop::refreshMonitorSizes() throw()
  33806. {
  33807. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33808. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33809. monitorCoordsClipped.clear();
  33810. monitorCoordsUnclipped.clear();
  33811. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33812. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33813. jassert (monitorCoordsClipped.size() > 0
  33814. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33815. if (oldClipped != monitorCoordsClipped
  33816. || oldUnclipped != monitorCoordsUnclipped)
  33817. {
  33818. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33819. {
  33820. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33821. if (p != 0)
  33822. p->handleScreenSizeChange();
  33823. }
  33824. }
  33825. }
  33826. int Desktop::getNumDisplayMonitors() const throw()
  33827. {
  33828. return monitorCoordsClipped.size();
  33829. }
  33830. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33831. {
  33832. return clippedToWorkArea ? monitorCoordsClipped [index]
  33833. : monitorCoordsUnclipped [index];
  33834. }
  33835. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33836. {
  33837. RectangleList rl;
  33838. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33839. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33840. return rl;
  33841. }
  33842. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33843. {
  33844. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33845. }
  33846. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const throw()
  33847. {
  33848. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33849. double bestDistance = 1.0e10;
  33850. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33851. {
  33852. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33853. if (rect.contains (position))
  33854. return rect;
  33855. const double distance = rect.getCentre().getDistanceFrom (position);
  33856. if (distance < bestDistance)
  33857. {
  33858. bestDistance = distance;
  33859. best = rect;
  33860. }
  33861. }
  33862. return best;
  33863. }
  33864. int Desktop::getNumComponents() const throw()
  33865. {
  33866. return desktopComponents.size();
  33867. }
  33868. Component* Desktop::getComponent (const int index) const throw()
  33869. {
  33870. return desktopComponents [index];
  33871. }
  33872. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33873. {
  33874. for (int i = desktopComponents.size(); --i >= 0;)
  33875. {
  33876. Component* const c = desktopComponents.getUnchecked(i);
  33877. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33878. if (c->contains (relative.getX(), relative.getY()))
  33879. return c->getComponentAt (relative.getX(), relative.getY());
  33880. }
  33881. return 0;
  33882. }
  33883. void Desktop::addDesktopComponent (Component* const c) throw()
  33884. {
  33885. jassert (c != 0);
  33886. jassert (! desktopComponents.contains (c));
  33887. desktopComponents.addIfNotAlreadyThere (c);
  33888. }
  33889. void Desktop::removeDesktopComponent (Component* const c) throw()
  33890. {
  33891. desktopComponents.removeValue (c);
  33892. }
  33893. void Desktop::componentBroughtToFront (Component* const c) throw()
  33894. {
  33895. const int index = desktopComponents.indexOf (c);
  33896. jassert (index >= 0);
  33897. if (index >= 0)
  33898. {
  33899. int newIndex = -1;
  33900. if (! c->isAlwaysOnTop())
  33901. {
  33902. newIndex = desktopComponents.size();
  33903. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33904. --newIndex;
  33905. --newIndex;
  33906. }
  33907. desktopComponents.move (index, newIndex);
  33908. }
  33909. }
  33910. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33911. {
  33912. return getInstance().mouseDowns[0].position;
  33913. }
  33914. int Desktop::getMouseButtonClickCounter() throw()
  33915. {
  33916. return getInstance().mouseClickCounter;
  33917. }
  33918. void Desktop::incrementMouseClickCounter() throw()
  33919. {
  33920. ++mouseClickCounter;
  33921. }
  33922. const Time Desktop::getLastMouseDownTime() const throw()
  33923. {
  33924. return Time (mouseDowns[0].time);
  33925. }
  33926. void Desktop::registerMouseDown (const Point<int>& position, int64 time, Component* component) throw()
  33927. {
  33928. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  33929. mouseDowns[i] = mouseDowns[i - 1];
  33930. mouseDowns[0].position = position;
  33931. mouseDowns[0].time = time;
  33932. mouseDowns[0].component = component;
  33933. mouseMovedSignificantlySincePressed = false;
  33934. }
  33935. void Desktop::registerMouseDrag (const Point<int>& position) throw()
  33936. {
  33937. mouseMovedSignificantlySincePressed
  33938. = mouseMovedSignificantlySincePressed
  33939. || abs (mouseDowns[0].position.getX() - position.getX()) >= 4
  33940. || abs (mouseDowns[0].position.getY() - position.getY()) >= 4;
  33941. }
  33942. int Desktop::getNumberOfMultipleClicks() const throw()
  33943. {
  33944. int numClicks = 0;
  33945. if (mouseDowns[0].time != 0)
  33946. {
  33947. if (! mouseMovedSignificantlySincePressed)
  33948. ++numClicks;
  33949. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  33950. {
  33951. if (mouseDowns[0].time - mouseDowns[i].time
  33952. < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  33953. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  33954. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  33955. && mouseDowns[0].component == mouseDowns[i].component)
  33956. {
  33957. ++numClicks;
  33958. }
  33959. else
  33960. {
  33961. break;
  33962. }
  33963. }
  33964. }
  33965. return numClicks;
  33966. }
  33967. void Desktop::addGlobalMouseListener (MouseListener* const listener) throw()
  33968. {
  33969. jassert (listener != 0);
  33970. if (listener != 0)
  33971. {
  33972. mouseListeners.add (listener);
  33973. resetTimer();
  33974. }
  33975. }
  33976. void Desktop::removeGlobalMouseListener (MouseListener* const listener) throw()
  33977. {
  33978. mouseListeners.removeValue (listener);
  33979. resetTimer();
  33980. }
  33981. void Desktop::addFocusChangeListener (FocusChangeListener* const listener) throw()
  33982. {
  33983. jassert (listener != 0);
  33984. if (listener != 0)
  33985. focusListeners.add (listener);
  33986. }
  33987. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener) throw()
  33988. {
  33989. focusListeners.removeValue (listener);
  33990. }
  33991. void Desktop::triggerFocusCallback() throw()
  33992. {
  33993. triggerAsyncUpdate();
  33994. }
  33995. void Desktop::handleAsyncUpdate()
  33996. {
  33997. for (int i = focusListeners.size(); --i >= 0;)
  33998. {
  33999. ((FocusChangeListener*) focusListeners.getUnchecked (i))->globalFocusChanged (Component::getCurrentlyFocusedComponent());
  34000. i = jmin (i, focusListeners.size());
  34001. }
  34002. }
  34003. void Desktop::timerCallback()
  34004. {
  34005. if (lastFakeMouseMove != getMousePosition())
  34006. sendMouseMove();
  34007. }
  34008. void Desktop::sendMouseMove()
  34009. {
  34010. if (mouseListeners.size() > 0)
  34011. {
  34012. startTimer (20);
  34013. lastFakeMouseMove = getMousePosition();
  34014. Component* const target = findComponentAt (lastFakeMouseMove);
  34015. if (target != 0)
  34016. {
  34017. ComponentDeletionWatcher deletionChecker (target);
  34018. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  34019. const Time now (Time::getCurrentTime());
  34020. const MouseEvent me (pos, ModifierKeys::getCurrentModifiers(),
  34021. target, now, pos, now, 0, false);
  34022. for (int i = mouseListeners.size(); --i >= 0;)
  34023. {
  34024. if (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  34025. ((MouseListener*) mouseListeners[i])->mouseDrag (me);
  34026. else
  34027. ((MouseListener*) mouseListeners[i])->mouseMove (me);
  34028. if (deletionChecker.hasBeenDeleted())
  34029. return;
  34030. i = jmin (i, mouseListeners.size());
  34031. }
  34032. }
  34033. }
  34034. }
  34035. void Desktop::resetTimer() throw()
  34036. {
  34037. if (mouseListeners.size() == 0)
  34038. stopTimer();
  34039. else
  34040. startTimer (100);
  34041. lastFakeMouseMove = getMousePosition();
  34042. }
  34043. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  34044. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  34045. {
  34046. if (kioskModeComponent != componentToUse)
  34047. {
  34048. // agh! Don't delete a component without first stopping it being the kiosk comp
  34049. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  34050. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  34051. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  34052. if (kioskModeComponent->isValidComponent())
  34053. {
  34054. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  34055. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  34056. }
  34057. kioskModeComponent = componentToUse;
  34058. if (kioskModeComponent != 0)
  34059. {
  34060. jassert (kioskModeComponent->isValidComponent());
  34061. // Only components that are already on the desktop can be put into kiosk mode!
  34062. jassert (kioskModeComponent->isOnDesktop());
  34063. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  34064. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  34065. }
  34066. }
  34067. }
  34068. END_JUCE_NAMESPACE
  34069. /*** End of inlined file: juce_Desktop.cpp ***/
  34070. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  34071. BEGIN_JUCE_NAMESPACE
  34072. ArrowButton::ArrowButton (const String& name,
  34073. float arrowDirectionInRadians,
  34074. const Colour& arrowColour)
  34075. : Button (name),
  34076. colour (arrowColour)
  34077. {
  34078. path.lineTo (0.0f, 1.0f);
  34079. path.lineTo (1.0f, 0.5f);
  34080. path.closeSubPath();
  34081. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  34082. 0.5f, 0.5f));
  34083. setComponentEffect (&shadow);
  34084. buttonStateChanged();
  34085. }
  34086. ArrowButton::~ArrowButton()
  34087. {
  34088. }
  34089. void ArrowButton::paintButton (Graphics& g,
  34090. bool /*isMouseOverButton*/,
  34091. bool /*isButtonDown*/)
  34092. {
  34093. g.setColour (colour);
  34094. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  34095. (float) offset,
  34096. (float) (getWidth() - 3),
  34097. (float) (getHeight() - 3),
  34098. false));
  34099. }
  34100. void ArrowButton::buttonStateChanged()
  34101. {
  34102. offset = (isDown()) ? 1 : 0;
  34103. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  34104. 0.3f, -1, 0);
  34105. }
  34106. END_JUCE_NAMESPACE
  34107. /*** End of inlined file: juce_ArrowButton.cpp ***/
  34108. /*** Start of inlined file: juce_Button.cpp ***/
  34109. BEGIN_JUCE_NAMESPACE
  34110. class Button::RepeatTimer : public Timer
  34111. {
  34112. public:
  34113. RepeatTimer (Button& owner_) : owner (owner_) {}
  34114. void timerCallback() { owner.repeatTimerCallback(); }
  34115. juce_UseDebuggingNewOperator
  34116. private:
  34117. Button& owner;
  34118. RepeatTimer (const RepeatTimer&);
  34119. RepeatTimer& operator= (const RepeatTimer&);
  34120. };
  34121. Button::Button (const String& name)
  34122. : Component (name),
  34123. keySource (0),
  34124. text (name),
  34125. buttonPressTime (0),
  34126. lastTimeCallbackTime (0),
  34127. commandManagerToUse (0),
  34128. autoRepeatDelay (-1),
  34129. autoRepeatSpeed (0),
  34130. autoRepeatMinimumDelay (-1),
  34131. radioGroupId (0),
  34132. commandID (0),
  34133. connectedEdgeFlags (0),
  34134. buttonState (buttonNormal),
  34135. lastToggleState (false),
  34136. clickTogglesState (false),
  34137. needsToRelease (false),
  34138. needsRepainting (false),
  34139. isKeyDown (false),
  34140. triggerOnMouseDown (false),
  34141. generateTooltip (false)
  34142. {
  34143. setWantsKeyboardFocus (true);
  34144. isOn.addListener (this);
  34145. }
  34146. Button::~Button()
  34147. {
  34148. isOn.removeListener (this);
  34149. if (commandManagerToUse != 0)
  34150. commandManagerToUse->removeListener (this);
  34151. repeatTimer = 0;
  34152. clearShortcuts();
  34153. }
  34154. void Button::setButtonText (const String& newText)
  34155. {
  34156. if (text != newText)
  34157. {
  34158. text = newText;
  34159. repaint();
  34160. }
  34161. }
  34162. void Button::setTooltip (const String& newTooltip)
  34163. {
  34164. SettableTooltipClient::setTooltip (newTooltip);
  34165. generateTooltip = false;
  34166. }
  34167. const String Button::getTooltip()
  34168. {
  34169. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  34170. {
  34171. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  34172. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  34173. for (int i = 0; i < keyPresses.size(); ++i)
  34174. {
  34175. const String key (keyPresses.getReference(i).getTextDescription());
  34176. tt << " [";
  34177. if (key.length() == 1)
  34178. tt << TRANS("shortcut") << ": '" << key << "']";
  34179. else
  34180. tt << key << ']';
  34181. }
  34182. return tt;
  34183. }
  34184. return SettableTooltipClient::getTooltip();
  34185. }
  34186. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  34187. {
  34188. if (connectedEdgeFlags != connectedEdgeFlags_)
  34189. {
  34190. connectedEdgeFlags = connectedEdgeFlags_;
  34191. repaint();
  34192. }
  34193. }
  34194. void Button::setToggleState (const bool shouldBeOn,
  34195. const bool sendChangeNotification)
  34196. {
  34197. if (shouldBeOn != lastToggleState)
  34198. {
  34199. const ComponentDeletionWatcher deletionWatcher (this);
  34200. isOn = shouldBeOn;
  34201. lastToggleState = shouldBeOn;
  34202. repaint();
  34203. if (sendChangeNotification)
  34204. sendClickMessage (ModifierKeys());
  34205. if ((! deletionWatcher.hasBeenDeleted()) && lastToggleState)
  34206. turnOffOtherButtonsInGroup (sendChangeNotification);
  34207. }
  34208. }
  34209. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  34210. {
  34211. clickTogglesState = shouldToggle;
  34212. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34213. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34214. // it is that this button represents, and the button will update its state to reflect this
  34215. // in the applicationCommandListChanged() method.
  34216. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34217. }
  34218. bool Button::getClickingTogglesState() const throw()
  34219. {
  34220. return clickTogglesState;
  34221. }
  34222. void Button::valueChanged (Value& value)
  34223. {
  34224. if (value.refersToSameSourceAs (isOn))
  34225. setToggleState (isOn.getValue(), true);
  34226. }
  34227. void Button::setRadioGroupId (const int newGroupId)
  34228. {
  34229. if (radioGroupId != newGroupId)
  34230. {
  34231. radioGroupId = newGroupId;
  34232. if (lastToggleState)
  34233. turnOffOtherButtonsInGroup (true);
  34234. }
  34235. }
  34236. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  34237. {
  34238. Component* const p = getParentComponent();
  34239. if (p != 0 && radioGroupId != 0)
  34240. {
  34241. const ComponentDeletionWatcher deletionWatcher (this);
  34242. for (int i = p->getNumChildComponents(); --i >= 0;)
  34243. {
  34244. Component* const c = p->getChildComponent (i);
  34245. if (c != this)
  34246. {
  34247. Button* const b = dynamic_cast <Button*> (c);
  34248. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  34249. {
  34250. b->setToggleState (false, sendChangeNotification);
  34251. if (deletionWatcher.hasBeenDeleted())
  34252. return;
  34253. }
  34254. }
  34255. }
  34256. }
  34257. }
  34258. void Button::enablementChanged()
  34259. {
  34260. updateState (0);
  34261. repaint();
  34262. }
  34263. Button::ButtonState Button::updateState (const MouseEvent* const e)
  34264. {
  34265. ButtonState state = buttonNormal;
  34266. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  34267. {
  34268. Point<int> mousePos;
  34269. if (e == 0)
  34270. mousePos = getMouseXYRelative();
  34271. else
  34272. mousePos = e->getEventRelativeTo (this).getPosition();
  34273. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  34274. const bool down = isMouseButtonDown();
  34275. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  34276. state = buttonDown;
  34277. else if (over)
  34278. state = buttonOver;
  34279. }
  34280. setState (state);
  34281. return state;
  34282. }
  34283. void Button::setState (const ButtonState newState)
  34284. {
  34285. if (buttonState != newState)
  34286. {
  34287. buttonState = newState;
  34288. repaint();
  34289. if (buttonState == buttonDown)
  34290. {
  34291. buttonPressTime = Time::getApproximateMillisecondCounter();
  34292. lastTimeCallbackTime = buttonPressTime;
  34293. }
  34294. sendStateMessage();
  34295. }
  34296. }
  34297. bool Button::isDown() const throw()
  34298. {
  34299. return buttonState == buttonDown;
  34300. }
  34301. bool Button::isOver() const throw()
  34302. {
  34303. return buttonState != buttonNormal;
  34304. }
  34305. void Button::buttonStateChanged()
  34306. {
  34307. }
  34308. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  34309. {
  34310. const uint32 now = Time::getApproximateMillisecondCounter();
  34311. return now > buttonPressTime ? now - buttonPressTime : 0;
  34312. }
  34313. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  34314. {
  34315. triggerOnMouseDown = isTriggeredOnMouseDown;
  34316. }
  34317. void Button::clicked()
  34318. {
  34319. }
  34320. void Button::clicked (const ModifierKeys& /*modifiers*/)
  34321. {
  34322. clicked();
  34323. }
  34324. static const int clickMessageId = 0x2f3f4f99;
  34325. void Button::triggerClick()
  34326. {
  34327. postCommandMessage (clickMessageId);
  34328. }
  34329. void Button::internalClickCallback (const ModifierKeys& modifiers)
  34330. {
  34331. if (clickTogglesState)
  34332. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  34333. sendClickMessage (modifiers);
  34334. }
  34335. void Button::flashButtonState()
  34336. {
  34337. if (isEnabled())
  34338. {
  34339. needsToRelease = true;
  34340. setState (buttonDown);
  34341. getRepeatTimer().startTimer (100);
  34342. }
  34343. }
  34344. void Button::handleCommandMessage (int commandId)
  34345. {
  34346. if (commandId == clickMessageId)
  34347. {
  34348. if (isEnabled())
  34349. {
  34350. flashButtonState();
  34351. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34352. }
  34353. }
  34354. else
  34355. {
  34356. Component::handleCommandMessage (commandId);
  34357. }
  34358. }
  34359. void Button::addButtonListener (ButtonListener* const newListener)
  34360. {
  34361. jassert (newListener != 0);
  34362. jassert (! buttonListeners.contains (newListener)); // trying to add a listener to the list twice!
  34363. if (newListener != 0)
  34364. buttonListeners.add (newListener);
  34365. }
  34366. void Button::removeButtonListener (ButtonListener* const listener)
  34367. {
  34368. jassert (buttonListeners.contains (listener)); // trying to remove a listener that isn't on the list!
  34369. buttonListeners.removeValue (listener);
  34370. }
  34371. void Button::sendClickMessage (const ModifierKeys& modifiers)
  34372. {
  34373. const ComponentDeletionWatcher cdw (this);
  34374. if (commandManagerToUse != 0 && commandID != 0)
  34375. {
  34376. ApplicationCommandTarget::InvocationInfo info (commandID);
  34377. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34378. info.originatingComponent = this;
  34379. commandManagerToUse->invoke (info, true);
  34380. }
  34381. clicked (modifiers);
  34382. if (! cdw.hasBeenDeleted())
  34383. {
  34384. for (int i = buttonListeners.size(); --i >= 0;)
  34385. {
  34386. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34387. if (bl != 0)
  34388. {
  34389. bl->buttonClicked (this);
  34390. if (cdw.hasBeenDeleted())
  34391. return;
  34392. }
  34393. }
  34394. }
  34395. }
  34396. void Button::sendStateMessage()
  34397. {
  34398. const ComponentDeletionWatcher cdw (this);
  34399. buttonStateChanged();
  34400. if (cdw.hasBeenDeleted())
  34401. return;
  34402. for (int i = buttonListeners.size(); --i >= 0;)
  34403. {
  34404. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34405. if (bl != 0)
  34406. {
  34407. bl->buttonStateChanged (this);
  34408. if (cdw.hasBeenDeleted())
  34409. return;
  34410. }
  34411. }
  34412. }
  34413. void Button::paint (Graphics& g)
  34414. {
  34415. if (needsToRelease && isEnabled())
  34416. {
  34417. needsToRelease = false;
  34418. needsRepainting = true;
  34419. }
  34420. paintButton (g, isOver(), isDown());
  34421. }
  34422. void Button::mouseEnter (const MouseEvent& e)
  34423. {
  34424. updateState (&e);
  34425. }
  34426. void Button::mouseExit (const MouseEvent& e)
  34427. {
  34428. updateState (&e);
  34429. }
  34430. void Button::mouseDown (const MouseEvent& e)
  34431. {
  34432. updateState (&e);
  34433. if (isDown())
  34434. {
  34435. if (autoRepeatDelay >= 0)
  34436. getRepeatTimer().startTimer (autoRepeatDelay);
  34437. if (triggerOnMouseDown)
  34438. internalClickCallback (e.mods);
  34439. }
  34440. }
  34441. void Button::mouseUp (const MouseEvent& e)
  34442. {
  34443. const bool wasDown = isDown();
  34444. updateState (&e);
  34445. if (wasDown && isOver() && ! triggerOnMouseDown)
  34446. internalClickCallback (e.mods);
  34447. }
  34448. void Button::mouseDrag (const MouseEvent& e)
  34449. {
  34450. const ButtonState oldState = buttonState;
  34451. updateState (&e);
  34452. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34453. getRepeatTimer().startTimer (autoRepeatSpeed);
  34454. }
  34455. void Button::focusGained (FocusChangeType)
  34456. {
  34457. updateState (0);
  34458. repaint();
  34459. }
  34460. void Button::focusLost (FocusChangeType)
  34461. {
  34462. updateState (0);
  34463. repaint();
  34464. }
  34465. void Button::setVisible (bool shouldBeVisible)
  34466. {
  34467. if (shouldBeVisible != isVisible())
  34468. {
  34469. Component::setVisible (shouldBeVisible);
  34470. if (! shouldBeVisible)
  34471. needsToRelease = false;
  34472. updateState (0);
  34473. }
  34474. else
  34475. {
  34476. Component::setVisible (shouldBeVisible);
  34477. }
  34478. }
  34479. void Button::parentHierarchyChanged()
  34480. {
  34481. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34482. if (newKeySource != keySource)
  34483. {
  34484. if (keySource->isValidComponent())
  34485. keySource->removeKeyListener (this);
  34486. keySource = newKeySource;
  34487. if (keySource->isValidComponent())
  34488. keySource->addKeyListener (this);
  34489. }
  34490. }
  34491. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34492. const int commandID_,
  34493. const bool generateTooltip_)
  34494. {
  34495. commandID = commandID_;
  34496. generateTooltip = generateTooltip_;
  34497. if (commandManagerToUse != commandManagerToUse_)
  34498. {
  34499. if (commandManagerToUse != 0)
  34500. commandManagerToUse->removeListener (this);
  34501. commandManagerToUse = commandManagerToUse_;
  34502. if (commandManagerToUse != 0)
  34503. commandManagerToUse->addListener (this);
  34504. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34505. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34506. // it is that this button represents, and the button will update its state to reflect this
  34507. // in the applicationCommandListChanged() method.
  34508. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34509. }
  34510. if (commandManagerToUse != 0)
  34511. applicationCommandListChanged();
  34512. else
  34513. setEnabled (true);
  34514. }
  34515. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34516. {
  34517. if (info.commandID == commandID
  34518. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34519. {
  34520. flashButtonState();
  34521. }
  34522. }
  34523. void Button::applicationCommandListChanged()
  34524. {
  34525. if (commandManagerToUse != 0)
  34526. {
  34527. ApplicationCommandInfo info (0);
  34528. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34529. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34530. if (target != 0)
  34531. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34532. }
  34533. }
  34534. void Button::addShortcut (const KeyPress& key)
  34535. {
  34536. if (key.isValid())
  34537. {
  34538. jassert (! isRegisteredForShortcut (key)); // already registered!
  34539. shortcuts.add (key);
  34540. parentHierarchyChanged();
  34541. }
  34542. }
  34543. void Button::clearShortcuts()
  34544. {
  34545. shortcuts.clear();
  34546. parentHierarchyChanged();
  34547. }
  34548. bool Button::isShortcutPressed() const
  34549. {
  34550. if (! isCurrentlyBlockedByAnotherModalComponent())
  34551. {
  34552. for (int i = shortcuts.size(); --i >= 0;)
  34553. if (shortcuts.getReference(i).isCurrentlyDown())
  34554. return true;
  34555. }
  34556. return false;
  34557. }
  34558. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34559. {
  34560. for (int i = shortcuts.size(); --i >= 0;)
  34561. if (key == shortcuts.getReference(i))
  34562. return true;
  34563. return false;
  34564. }
  34565. bool Button::keyStateChanged (const bool, Component*)
  34566. {
  34567. if (! isEnabled())
  34568. return false;
  34569. const bool wasDown = isKeyDown;
  34570. isKeyDown = isShortcutPressed();
  34571. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34572. getRepeatTimer().startTimer (autoRepeatDelay);
  34573. updateState (0);
  34574. if (isEnabled() && wasDown && ! isKeyDown)
  34575. {
  34576. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34577. // (return immediately - this button may now have been deleted)
  34578. return true;
  34579. }
  34580. return wasDown || isKeyDown;
  34581. }
  34582. bool Button::keyPressed (const KeyPress&, Component*)
  34583. {
  34584. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34585. return isShortcutPressed();
  34586. }
  34587. bool Button::keyPressed (const KeyPress& key)
  34588. {
  34589. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34590. {
  34591. triggerClick();
  34592. return true;
  34593. }
  34594. return false;
  34595. }
  34596. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34597. const int repeatMillisecs,
  34598. const int minimumDelayInMillisecs) throw()
  34599. {
  34600. autoRepeatDelay = initialDelayMillisecs;
  34601. autoRepeatSpeed = repeatMillisecs;
  34602. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34603. }
  34604. void Button::repeatTimerCallback()
  34605. {
  34606. if (needsRepainting)
  34607. {
  34608. getRepeatTimer().stopTimer();
  34609. updateState (0);
  34610. needsRepainting = false;
  34611. }
  34612. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34613. {
  34614. int repeatSpeed = autoRepeatSpeed;
  34615. if (autoRepeatMinimumDelay >= 0)
  34616. {
  34617. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34618. timeHeldDown *= timeHeldDown;
  34619. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34620. }
  34621. repeatSpeed = jmax (1, repeatSpeed);
  34622. getRepeatTimer().startTimer (repeatSpeed);
  34623. const uint32 now = Time::getApproximateMillisecondCounter();
  34624. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34625. lastTimeCallbackTime = now;
  34626. const ComponentDeletionWatcher cdw (this);
  34627. for (int i = numTimesToCallback; --i >= 0;)
  34628. {
  34629. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34630. if (cdw.hasBeenDeleted() || ! isDown())
  34631. return;
  34632. }
  34633. }
  34634. else if (! needsToRelease)
  34635. {
  34636. getRepeatTimer().stopTimer();
  34637. }
  34638. }
  34639. Button::RepeatTimer& Button::getRepeatTimer()
  34640. {
  34641. if (repeatTimer == 0)
  34642. repeatTimer = new RepeatTimer (*this);
  34643. return *repeatTimer;
  34644. }
  34645. END_JUCE_NAMESPACE
  34646. /*** End of inlined file: juce_Button.cpp ***/
  34647. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34648. BEGIN_JUCE_NAMESPACE
  34649. DrawableButton::DrawableButton (const String& name,
  34650. const DrawableButton::ButtonStyle buttonStyle)
  34651. : Button (name),
  34652. style (buttonStyle),
  34653. edgeIndent (3)
  34654. {
  34655. if (buttonStyle == ImageOnButtonBackground)
  34656. {
  34657. backgroundOff = Colour (0xffbbbbff);
  34658. backgroundOn = Colour (0xff3333ff);
  34659. }
  34660. else
  34661. {
  34662. backgroundOff = Colours::transparentBlack;
  34663. backgroundOn = Colour (0xaabbbbff);
  34664. }
  34665. }
  34666. DrawableButton::~DrawableButton()
  34667. {
  34668. deleteImages();
  34669. }
  34670. void DrawableButton::deleteImages()
  34671. {
  34672. }
  34673. void DrawableButton::setImages (const Drawable* normal,
  34674. const Drawable* over,
  34675. const Drawable* down,
  34676. const Drawable* disabled,
  34677. const Drawable* normalOn,
  34678. const Drawable* overOn,
  34679. const Drawable* downOn,
  34680. const Drawable* disabledOn)
  34681. {
  34682. deleteImages();
  34683. jassert (normal != 0); // you really need to give it at least a normal image..
  34684. if (normal != 0)
  34685. normalImage = normal->createCopy();
  34686. if (over != 0)
  34687. overImage = over->createCopy();
  34688. if (down != 0)
  34689. downImage = down->createCopy();
  34690. if (disabled != 0)
  34691. disabledImage = disabled->createCopy();
  34692. if (normalOn != 0)
  34693. normalImageOn = normalOn->createCopy();
  34694. if (overOn != 0)
  34695. overImageOn = overOn->createCopy();
  34696. if (downOn != 0)
  34697. downImageOn = downOn->createCopy();
  34698. if (disabledOn != 0)
  34699. disabledImageOn = disabledOn->createCopy();
  34700. repaint();
  34701. }
  34702. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34703. {
  34704. if (style != newStyle)
  34705. {
  34706. style = newStyle;
  34707. repaint();
  34708. }
  34709. }
  34710. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34711. const Colour& toggledOnColour)
  34712. {
  34713. if (backgroundOff != toggledOffColour
  34714. || backgroundOn != toggledOnColour)
  34715. {
  34716. backgroundOff = toggledOffColour;
  34717. backgroundOn = toggledOnColour;
  34718. repaint();
  34719. }
  34720. }
  34721. const Colour& DrawableButton::getBackgroundColour() const throw()
  34722. {
  34723. return getToggleState() ? backgroundOn
  34724. : backgroundOff;
  34725. }
  34726. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34727. {
  34728. edgeIndent = numPixelsIndent;
  34729. repaint();
  34730. }
  34731. void DrawableButton::paintButton (Graphics& g,
  34732. bool isMouseOverButton,
  34733. bool isButtonDown)
  34734. {
  34735. Rectangle<int> imageSpace;
  34736. if (style == ImageOnButtonBackground)
  34737. {
  34738. const int insetX = getWidth() / 4;
  34739. const int insetY = getHeight() / 4;
  34740. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34741. getLookAndFeel().drawButtonBackground (g, *this,
  34742. getBackgroundColour(),
  34743. isMouseOverButton,
  34744. isButtonDown);
  34745. }
  34746. else
  34747. {
  34748. g.fillAll (getBackgroundColour());
  34749. const int textH = (style == ImageAboveTextLabel)
  34750. ? jmin (16, proportionOfHeight (0.25f))
  34751. : 0;
  34752. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34753. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34754. imageSpace.setBounds (indentX, indentY,
  34755. getWidth() - indentX * 2,
  34756. getHeight() - indentY * 2 - textH);
  34757. if (textH > 0)
  34758. {
  34759. g.setFont ((float) textH);
  34760. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34761. g.drawFittedText (getButtonText(),
  34762. 2, getHeight() - textH - 1,
  34763. getWidth() - 4, textH,
  34764. Justification::centred, 1);
  34765. }
  34766. }
  34767. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34768. g.setOpacity (1.0f);
  34769. const Drawable* imageToDraw = 0;
  34770. if (isEnabled())
  34771. {
  34772. imageToDraw = getCurrentImage();
  34773. }
  34774. else
  34775. {
  34776. imageToDraw = getToggleState() ? disabledImageOn
  34777. : disabledImage;
  34778. if (imageToDraw == 0)
  34779. {
  34780. g.setOpacity (0.4f);
  34781. imageToDraw = getNormalImage();
  34782. }
  34783. }
  34784. if (imageToDraw != 0)
  34785. {
  34786. if (style == ImageRaw)
  34787. {
  34788. imageToDraw->draw (g, 1.0f);
  34789. }
  34790. else
  34791. {
  34792. imageToDraw->drawWithin (g,
  34793. imageSpace.getX(),
  34794. imageSpace.getY(),
  34795. imageSpace.getWidth(),
  34796. imageSpace.getHeight(),
  34797. RectanglePlacement::centred,
  34798. 1.0f);
  34799. }
  34800. }
  34801. }
  34802. const Drawable* DrawableButton::getCurrentImage() const throw()
  34803. {
  34804. if (isDown())
  34805. return getDownImage();
  34806. if (isOver())
  34807. return getOverImage();
  34808. return getNormalImage();
  34809. }
  34810. const Drawable* DrawableButton::getNormalImage() const throw()
  34811. {
  34812. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34813. : normalImage;
  34814. }
  34815. const Drawable* DrawableButton::getOverImage() const throw()
  34816. {
  34817. const Drawable* d = normalImage;
  34818. if (getToggleState())
  34819. {
  34820. if (overImageOn != 0)
  34821. d = overImageOn;
  34822. else if (normalImageOn != 0)
  34823. d = normalImageOn;
  34824. else if (overImage != 0)
  34825. d = overImage;
  34826. }
  34827. else
  34828. {
  34829. if (overImage != 0)
  34830. d = overImage;
  34831. }
  34832. return d;
  34833. }
  34834. const Drawable* DrawableButton::getDownImage() const throw()
  34835. {
  34836. const Drawable* d = normalImage;
  34837. if (getToggleState())
  34838. {
  34839. if (downImageOn != 0)
  34840. d = downImageOn;
  34841. else if (overImageOn != 0)
  34842. d = overImageOn;
  34843. else if (normalImageOn != 0)
  34844. d = normalImageOn;
  34845. else if (downImage != 0)
  34846. d = downImage;
  34847. else
  34848. d = getOverImage();
  34849. }
  34850. else
  34851. {
  34852. if (downImage != 0)
  34853. d = downImage;
  34854. else
  34855. d = getOverImage();
  34856. }
  34857. return d;
  34858. }
  34859. END_JUCE_NAMESPACE
  34860. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34861. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34862. BEGIN_JUCE_NAMESPACE
  34863. HyperlinkButton::HyperlinkButton (const String& linkText,
  34864. const URL& linkURL)
  34865. : Button (linkText),
  34866. url (linkURL),
  34867. font (14.0f, Font::underlined),
  34868. resizeFont (true),
  34869. justification (Justification::centred)
  34870. {
  34871. setMouseCursor (MouseCursor::PointingHandCursor);
  34872. setTooltip (linkURL.toString (false));
  34873. }
  34874. HyperlinkButton::~HyperlinkButton()
  34875. {
  34876. }
  34877. void HyperlinkButton::setFont (const Font& newFont,
  34878. const bool resizeToMatchComponentHeight,
  34879. const Justification& justificationType)
  34880. {
  34881. font = newFont;
  34882. resizeFont = resizeToMatchComponentHeight;
  34883. justification = justificationType;
  34884. repaint();
  34885. }
  34886. void HyperlinkButton::setURL (const URL& newURL) throw()
  34887. {
  34888. url = newURL;
  34889. setTooltip (newURL.toString (false));
  34890. }
  34891. const Font HyperlinkButton::getFontToUse() const
  34892. {
  34893. Font f (font);
  34894. if (resizeFont)
  34895. f.setHeight (getHeight() * 0.7f);
  34896. return f;
  34897. }
  34898. void HyperlinkButton::changeWidthToFitText()
  34899. {
  34900. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34901. }
  34902. void HyperlinkButton::colourChanged()
  34903. {
  34904. repaint();
  34905. }
  34906. void HyperlinkButton::clicked()
  34907. {
  34908. if (url.isWellFormed())
  34909. url.launchInDefaultBrowser();
  34910. }
  34911. void HyperlinkButton::paintButton (Graphics& g,
  34912. bool isMouseOverButton,
  34913. bool isButtonDown)
  34914. {
  34915. const Colour textColour (findColour (textColourId));
  34916. if (isEnabled())
  34917. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34918. : textColour);
  34919. else
  34920. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34921. g.setFont (getFontToUse());
  34922. g.drawText (getButtonText(),
  34923. 2, 0, getWidth() - 2, getHeight(),
  34924. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34925. true);
  34926. }
  34927. END_JUCE_NAMESPACE
  34928. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34929. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34930. BEGIN_JUCE_NAMESPACE
  34931. ImageButton::ImageButton (const String& text_)
  34932. : Button (text_),
  34933. scaleImageToFit (true),
  34934. preserveProportions (true),
  34935. alphaThreshold (0),
  34936. imageX (0),
  34937. imageY (0),
  34938. imageW (0),
  34939. imageH (0),
  34940. normalImage (0),
  34941. overImage (0),
  34942. downImage (0)
  34943. {
  34944. }
  34945. ImageButton::~ImageButton()
  34946. {
  34947. deleteImages();
  34948. }
  34949. void ImageButton::deleteImages()
  34950. {
  34951. ImageCache::releaseOrDelete (normalImage);
  34952. ImageCache::releaseOrDelete (overImage);
  34953. ImageCache::releaseOrDelete (downImage);
  34954. }
  34955. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34956. const bool rescaleImagesWhenButtonSizeChanges,
  34957. const bool preserveImageProportions,
  34958. Image* const normalImage_,
  34959. const float imageOpacityWhenNormal,
  34960. const Colour& overlayColourWhenNormal,
  34961. Image* const overImage_,
  34962. const float imageOpacityWhenOver,
  34963. const Colour& overlayColourWhenOver,
  34964. Image* const downImage_,
  34965. const float imageOpacityWhenDown,
  34966. const Colour& overlayColourWhenDown,
  34967. const float hitTestAlphaThreshold)
  34968. {
  34969. deleteImages();
  34970. normalImage = normalImage_;
  34971. overImage = overImage_;
  34972. downImage = downImage_;
  34973. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34974. {
  34975. imageW = normalImage->getWidth();
  34976. imageH = normalImage->getHeight();
  34977. setSize (imageW, imageH);
  34978. }
  34979. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34980. preserveProportions = preserveImageProportions;
  34981. normalOpacity = imageOpacityWhenNormal;
  34982. normalOverlay = overlayColourWhenNormal;
  34983. overOpacity = imageOpacityWhenOver;
  34984. overOverlay = overlayColourWhenOver;
  34985. downOpacity = imageOpacityWhenDown;
  34986. downOverlay = overlayColourWhenDown;
  34987. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34988. repaint();
  34989. }
  34990. Image* ImageButton::getCurrentImage() const
  34991. {
  34992. if (isDown() || getToggleState())
  34993. return getDownImage();
  34994. if (isOver())
  34995. return getOverImage();
  34996. return getNormalImage();
  34997. }
  34998. Image* ImageButton::getNormalImage() const throw()
  34999. {
  35000. return normalImage;
  35001. }
  35002. Image* ImageButton::getOverImage() const throw()
  35003. {
  35004. return (overImage != 0) ? overImage
  35005. : normalImage;
  35006. }
  35007. Image* ImageButton::getDownImage() const throw()
  35008. {
  35009. return (downImage != 0) ? downImage
  35010. : getOverImage();
  35011. }
  35012. void ImageButton::paintButton (Graphics& g,
  35013. bool isMouseOverButton,
  35014. bool isButtonDown)
  35015. {
  35016. if (! isEnabled())
  35017. {
  35018. isMouseOverButton = false;
  35019. isButtonDown = false;
  35020. }
  35021. Image* const im = getCurrentImage();
  35022. if (im != 0)
  35023. {
  35024. const int iw = im->getWidth();
  35025. const int ih = im->getHeight();
  35026. imageW = getWidth();
  35027. imageH = getHeight();
  35028. imageX = (imageW - iw) >> 1;
  35029. imageY = (imageH - ih) >> 1;
  35030. if (scaleImageToFit)
  35031. {
  35032. if (preserveProportions)
  35033. {
  35034. int newW, newH;
  35035. const float imRatio = ih / (float)iw;
  35036. const float destRatio = imageH / (float)imageW;
  35037. if (imRatio > destRatio)
  35038. {
  35039. newW = roundToInt (imageH / imRatio);
  35040. newH = imageH;
  35041. }
  35042. else
  35043. {
  35044. newW = imageW;
  35045. newH = roundToInt (imageW * imRatio);
  35046. }
  35047. imageX = (imageW - newW) / 2;
  35048. imageY = (imageH - newH) / 2;
  35049. imageW = newW;
  35050. imageH = newH;
  35051. }
  35052. else
  35053. {
  35054. imageX = 0;
  35055. imageY = 0;
  35056. }
  35057. }
  35058. if (! scaleImageToFit)
  35059. {
  35060. imageW = iw;
  35061. imageH = ih;
  35062. }
  35063. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  35064. isButtonDown ? downOverlay
  35065. : (isMouseOverButton ? overOverlay
  35066. : normalOverlay),
  35067. isButtonDown ? downOpacity
  35068. : (isMouseOverButton ? overOpacity
  35069. : normalOpacity),
  35070. *this);
  35071. }
  35072. }
  35073. bool ImageButton::hitTest (int x, int y)
  35074. {
  35075. if (alphaThreshold == 0)
  35076. return true;
  35077. Image* const im = getCurrentImage();
  35078. return im == 0
  35079. || (imageW > 0 && imageH > 0
  35080. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  35081. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  35082. }
  35083. END_JUCE_NAMESPACE
  35084. /*** End of inlined file: juce_ImageButton.cpp ***/
  35085. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  35086. BEGIN_JUCE_NAMESPACE
  35087. ShapeButton::ShapeButton (const String& text_,
  35088. const Colour& normalColour_,
  35089. const Colour& overColour_,
  35090. const Colour& downColour_)
  35091. : Button (text_),
  35092. normalColour (normalColour_),
  35093. overColour (overColour_),
  35094. downColour (downColour_),
  35095. maintainShapeProportions (false),
  35096. outlineWidth (0.0f)
  35097. {
  35098. }
  35099. ShapeButton::~ShapeButton()
  35100. {
  35101. }
  35102. void ShapeButton::setColours (const Colour& newNormalColour,
  35103. const Colour& newOverColour,
  35104. const Colour& newDownColour)
  35105. {
  35106. normalColour = newNormalColour;
  35107. overColour = newOverColour;
  35108. downColour = newDownColour;
  35109. }
  35110. void ShapeButton::setOutline (const Colour& newOutlineColour,
  35111. const float newOutlineWidth)
  35112. {
  35113. outlineColour = newOutlineColour;
  35114. outlineWidth = newOutlineWidth;
  35115. }
  35116. void ShapeButton::setShape (const Path& newShape,
  35117. const bool resizeNowToFitThisShape,
  35118. const bool maintainShapeProportions_,
  35119. const bool hasShadow)
  35120. {
  35121. shape = newShape;
  35122. maintainShapeProportions = maintainShapeProportions_;
  35123. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  35124. setComponentEffect ((hasShadow) ? &shadow : 0);
  35125. if (resizeNowToFitThisShape)
  35126. {
  35127. Rectangle<float> bounds (shape.getBounds());
  35128. if (hasShadow)
  35129. bounds.expand (4.0f, 4.0f);
  35130. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  35131. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  35132. 1 + (int) (bounds.getHeight() + outlineWidth));
  35133. }
  35134. }
  35135. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  35136. {
  35137. if (! isEnabled())
  35138. {
  35139. isMouseOverButton = false;
  35140. isButtonDown = false;
  35141. }
  35142. g.setColour ((isButtonDown) ? downColour
  35143. : (isMouseOverButton) ? overColour
  35144. : normalColour);
  35145. int w = getWidth();
  35146. int h = getHeight();
  35147. if (getComponentEffect() != 0)
  35148. {
  35149. w -= 4;
  35150. h -= 4;
  35151. }
  35152. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  35153. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  35154. w - offset - outlineWidth,
  35155. h - offset - outlineWidth,
  35156. maintainShapeProportions));
  35157. g.fillPath (shape, trans);
  35158. if (outlineWidth > 0.0f)
  35159. {
  35160. g.setColour (outlineColour);
  35161. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  35162. }
  35163. }
  35164. END_JUCE_NAMESPACE
  35165. /*** End of inlined file: juce_ShapeButton.cpp ***/
  35166. /*** Start of inlined file: juce_TextButton.cpp ***/
  35167. BEGIN_JUCE_NAMESPACE
  35168. TextButton::TextButton (const String& name,
  35169. const String& toolTip)
  35170. : Button (name)
  35171. {
  35172. setTooltip (toolTip);
  35173. }
  35174. TextButton::~TextButton()
  35175. {
  35176. }
  35177. void TextButton::paintButton (Graphics& g,
  35178. bool isMouseOverButton,
  35179. bool isButtonDown)
  35180. {
  35181. getLookAndFeel().drawButtonBackground (g, *this,
  35182. findColour (getToggleState() ? buttonOnColourId
  35183. : buttonColourId),
  35184. isMouseOverButton,
  35185. isButtonDown);
  35186. getLookAndFeel().drawButtonText (g, *this,
  35187. isMouseOverButton,
  35188. isButtonDown);
  35189. }
  35190. void TextButton::colourChanged()
  35191. {
  35192. repaint();
  35193. }
  35194. const Font TextButton::getFont()
  35195. {
  35196. return Font (jmin (15.0f, getHeight() * 0.6f));
  35197. }
  35198. void TextButton::changeWidthToFitText (const int newHeight)
  35199. {
  35200. if (newHeight >= 0)
  35201. setSize (jmax (1, getWidth()), newHeight);
  35202. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  35203. getHeight());
  35204. }
  35205. END_JUCE_NAMESPACE
  35206. /*** End of inlined file: juce_TextButton.cpp ***/
  35207. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  35208. BEGIN_JUCE_NAMESPACE
  35209. ToggleButton::ToggleButton (const String& buttonText)
  35210. : Button (buttonText)
  35211. {
  35212. setClickingTogglesState (true);
  35213. }
  35214. ToggleButton::~ToggleButton()
  35215. {
  35216. }
  35217. void ToggleButton::paintButton (Graphics& g,
  35218. bool isMouseOverButton,
  35219. bool isButtonDown)
  35220. {
  35221. getLookAndFeel().drawToggleButton (g, *this,
  35222. isMouseOverButton,
  35223. isButtonDown);
  35224. }
  35225. void ToggleButton::changeWidthToFitText()
  35226. {
  35227. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  35228. }
  35229. void ToggleButton::colourChanged()
  35230. {
  35231. repaint();
  35232. }
  35233. END_JUCE_NAMESPACE
  35234. /*** End of inlined file: juce_ToggleButton.cpp ***/
  35235. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  35236. BEGIN_JUCE_NAMESPACE
  35237. ToolbarButton::ToolbarButton (const int itemId_,
  35238. const String& buttonText,
  35239. Drawable* const normalImage_,
  35240. Drawable* const toggledOnImage_)
  35241. : ToolbarItemComponent (itemId_, buttonText, true),
  35242. normalImage (normalImage_),
  35243. toggledOnImage (toggledOnImage_)
  35244. {
  35245. }
  35246. ToolbarButton::~ToolbarButton()
  35247. {
  35248. }
  35249. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  35250. bool /*isToolbarVertical*/,
  35251. int& preferredSize,
  35252. int& minSize, int& maxSize)
  35253. {
  35254. preferredSize = minSize = maxSize = toolbarDepth;
  35255. return true;
  35256. }
  35257. void ToolbarButton::paintButtonArea (Graphics& g,
  35258. int width, int height,
  35259. bool /*isMouseOver*/,
  35260. bool /*isMouseDown*/)
  35261. {
  35262. Drawable* d = normalImage;
  35263. if (getToggleState() && toggledOnImage != 0)
  35264. d = toggledOnImage;
  35265. if (! isEnabled())
  35266. {
  35267. Image im (Image::ARGB, width, height, true);
  35268. Graphics g2 (im);
  35269. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35270. im.desaturate();
  35271. g.drawImageAt (&im, 0, 0);
  35272. }
  35273. else
  35274. {
  35275. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35276. }
  35277. }
  35278. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  35279. {
  35280. }
  35281. END_JUCE_NAMESPACE
  35282. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  35283. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  35284. BEGIN_JUCE_NAMESPACE
  35285. class CodeDocumentLine
  35286. {
  35287. public:
  35288. CodeDocumentLine (const tchar* const line_,
  35289. const int lineLength_,
  35290. const int numNewLineChars,
  35291. const int lineStartInFile_)
  35292. : line (line_, lineLength_),
  35293. lineStartInFile (lineStartInFile_),
  35294. lineLength (lineLength_),
  35295. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  35296. {
  35297. }
  35298. ~CodeDocumentLine()
  35299. {
  35300. }
  35301. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  35302. {
  35303. const tchar* const t = (const tchar*) text;
  35304. int pos = 0;
  35305. while (t [pos] != 0)
  35306. {
  35307. const int startOfLine = pos;
  35308. int numNewLineChars = 0;
  35309. while (t[pos] != 0)
  35310. {
  35311. if (t[pos] == T('\r'))
  35312. {
  35313. ++numNewLineChars;
  35314. ++pos;
  35315. if (t[pos] == T('\n'))
  35316. {
  35317. ++numNewLineChars;
  35318. ++pos;
  35319. }
  35320. break;
  35321. }
  35322. if (t[pos] == T('\n'))
  35323. {
  35324. ++numNewLineChars;
  35325. ++pos;
  35326. break;
  35327. }
  35328. ++pos;
  35329. }
  35330. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  35331. numNewLineChars, startOfLine));
  35332. }
  35333. jassert (pos == text.length());
  35334. }
  35335. bool endsWithLineBreak() const throw()
  35336. {
  35337. return lineLengthWithoutNewLines != lineLength;
  35338. }
  35339. void updateLength() throw()
  35340. {
  35341. lineLengthWithoutNewLines = lineLength = line.length();
  35342. while (lineLengthWithoutNewLines > 0
  35343. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35344. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35345. {
  35346. --lineLengthWithoutNewLines;
  35347. }
  35348. }
  35349. String line;
  35350. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  35351. };
  35352. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  35353. : document (document_),
  35354. currentLine (document_->lines[0]),
  35355. line (0),
  35356. position (0)
  35357. {
  35358. }
  35359. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  35360. : document (other.document),
  35361. currentLine (other.currentLine),
  35362. line (other.line),
  35363. position (other.position)
  35364. {
  35365. }
  35366. const CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  35367. {
  35368. document = other.document;
  35369. currentLine = other.currentLine;
  35370. line = other.line;
  35371. position = other.position;
  35372. return *this;
  35373. }
  35374. CodeDocument::Iterator::~Iterator() throw()
  35375. {
  35376. }
  35377. juce_wchar CodeDocument::Iterator::nextChar()
  35378. {
  35379. if (currentLine == 0)
  35380. return 0;
  35381. jassert (currentLine == document->lines.getUnchecked (line));
  35382. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  35383. skip();
  35384. return result;
  35385. }
  35386. void CodeDocument::Iterator::skip()
  35387. {
  35388. if (currentLine != 0)
  35389. {
  35390. jassert (currentLine == document->lines.getUnchecked (line));
  35391. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35392. {
  35393. ++line;
  35394. currentLine = document->lines [line];
  35395. }
  35396. }
  35397. }
  35398. void CodeDocument::Iterator::skipToEndOfLine()
  35399. {
  35400. if (currentLine != 0)
  35401. {
  35402. jassert (currentLine == document->lines.getUnchecked (line));
  35403. ++line;
  35404. currentLine = document->lines [line];
  35405. if (currentLine != 0)
  35406. position = currentLine->lineStartInFile;
  35407. else
  35408. position = document->getNumCharacters();
  35409. }
  35410. }
  35411. juce_wchar CodeDocument::Iterator::peekNextChar() const
  35412. {
  35413. if (currentLine == 0)
  35414. return 0;
  35415. jassert (currentLine == document->lines.getUnchecked (line));
  35416. return currentLine->line [position - currentLine->lineStartInFile];
  35417. }
  35418. void CodeDocument::Iterator::skipWhitespace()
  35419. {
  35420. while (CharacterFunctions::isWhitespace (peekNextChar()))
  35421. skip();
  35422. }
  35423. bool CodeDocument::Iterator::isEOF() const throw()
  35424. {
  35425. return currentLine == 0;
  35426. }
  35427. CodeDocument::Position::Position() throw()
  35428. : owner (0), characterPos (0), line (0),
  35429. indexInLine (0), positionMaintained (false)
  35430. {
  35431. }
  35432. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35433. const int line_, const int indexInLine_) throw()
  35434. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35435. characterPos (0), line (line_),
  35436. indexInLine (indexInLine_), positionMaintained (false)
  35437. {
  35438. setLineAndIndex (line_, indexInLine_);
  35439. }
  35440. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35441. const int characterPos_) throw()
  35442. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35443. positionMaintained (false)
  35444. {
  35445. setPosition (characterPos_);
  35446. }
  35447. CodeDocument::Position::Position (const Position& other) throw()
  35448. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35449. indexInLine (other.indexInLine), positionMaintained (false)
  35450. {
  35451. jassert (*this == other);
  35452. }
  35453. CodeDocument::Position::~Position() throw()
  35454. {
  35455. setPositionMaintained (false);
  35456. }
  35457. const CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35458. {
  35459. if (this != &other)
  35460. {
  35461. const bool wasPositionMaintained = positionMaintained;
  35462. if (owner != other.owner)
  35463. setPositionMaintained (false);
  35464. owner = other.owner;
  35465. line = other.line;
  35466. indexInLine = other.indexInLine;
  35467. characterPos = other.characterPos;
  35468. setPositionMaintained (wasPositionMaintained);
  35469. jassert (*this == other);
  35470. }
  35471. return *this;
  35472. }
  35473. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35474. {
  35475. jassert ((characterPos == other.characterPos)
  35476. == (line == other.line && indexInLine == other.indexInLine));
  35477. return characterPos == other.characterPos
  35478. && line == other.line
  35479. && indexInLine == other.indexInLine
  35480. && owner == other.owner;
  35481. }
  35482. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35483. {
  35484. return ! operator== (other);
  35485. }
  35486. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35487. {
  35488. jassert (owner != 0);
  35489. if (owner->lines.size() == 0)
  35490. {
  35491. line = 0;
  35492. indexInLine = 0;
  35493. characterPos = 0;
  35494. }
  35495. else
  35496. {
  35497. if (newLine >= owner->lines.size())
  35498. {
  35499. line = owner->lines.size() - 1;
  35500. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35501. jassert (l != 0);
  35502. indexInLine = l->lineLengthWithoutNewLines;
  35503. characterPos = l->lineStartInFile + indexInLine;
  35504. }
  35505. else
  35506. {
  35507. line = jmax (0, newLine);
  35508. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35509. jassert (l != 0);
  35510. if (l->lineLengthWithoutNewLines > 0)
  35511. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35512. else
  35513. indexInLine = 0;
  35514. characterPos = l->lineStartInFile + indexInLine;
  35515. }
  35516. }
  35517. }
  35518. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35519. {
  35520. jassert (owner != 0);
  35521. line = 0;
  35522. indexInLine = 0;
  35523. characterPos = 0;
  35524. if (newPosition > 0)
  35525. {
  35526. int lineStart = 0;
  35527. int lineEnd = owner->lines.size();
  35528. for (;;)
  35529. {
  35530. if (lineEnd - lineStart < 4)
  35531. {
  35532. for (int i = lineStart; i < lineEnd; ++i)
  35533. {
  35534. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35535. int index = newPosition - l->lineStartInFile;
  35536. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35537. {
  35538. line = i;
  35539. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35540. characterPos = l->lineStartInFile + indexInLine;
  35541. }
  35542. }
  35543. break;
  35544. }
  35545. else
  35546. {
  35547. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35548. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35549. if (newPosition >= mid->lineStartInFile)
  35550. lineStart = midIndex;
  35551. else
  35552. lineEnd = midIndex;
  35553. }
  35554. }
  35555. }
  35556. }
  35557. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35558. {
  35559. jassert (owner != 0);
  35560. if (characterDelta == 1)
  35561. {
  35562. setPosition (getPosition());
  35563. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35564. if (line < owner->lines.size())
  35565. {
  35566. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35567. if (indexInLine + characterDelta < l->lineLength
  35568. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35569. ++characterDelta;
  35570. }
  35571. }
  35572. setPosition (characterPos + characterDelta);
  35573. }
  35574. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35575. {
  35576. CodeDocument::Position p (*this);
  35577. p.moveBy (characterDelta);
  35578. return p;
  35579. }
  35580. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35581. {
  35582. CodeDocument::Position p (*this);
  35583. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35584. return p;
  35585. }
  35586. const tchar CodeDocument::Position::getCharacter() const throw()
  35587. {
  35588. const CodeDocumentLine* const l = owner->lines [line];
  35589. return l == 0 ? 0 : l->line [getIndexInLine()];
  35590. }
  35591. const String CodeDocument::Position::getLineText() const throw()
  35592. {
  35593. const CodeDocumentLine* const l = owner->lines [line];
  35594. return l == 0 ? String::empty : l->line;
  35595. }
  35596. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35597. {
  35598. if (isMaintained != positionMaintained)
  35599. {
  35600. positionMaintained = isMaintained;
  35601. if (owner != 0)
  35602. {
  35603. if (isMaintained)
  35604. {
  35605. jassert (! owner->positionsToMaintain.contains (this));
  35606. owner->positionsToMaintain.add (this);
  35607. }
  35608. else
  35609. {
  35610. jassert (owner->positionsToMaintain.contains (this));
  35611. owner->positionsToMaintain.removeValue (this);
  35612. }
  35613. }
  35614. }
  35615. }
  35616. CodeDocument::CodeDocument()
  35617. : undoManager (std::numeric_limits<int>::max(), 10000),
  35618. currentActionIndex (0),
  35619. indexOfSavedState (-1),
  35620. maximumLineLength (-1),
  35621. newLineChars ("\r\n")
  35622. {
  35623. }
  35624. CodeDocument::~CodeDocument()
  35625. {
  35626. }
  35627. const String CodeDocument::getAllContent() const throw()
  35628. {
  35629. return getTextBetween (Position (this, 0),
  35630. Position (this, lines.size(), 0));
  35631. }
  35632. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35633. {
  35634. if (end.getPosition() <= start.getPosition())
  35635. return String::empty;
  35636. const int startLine = start.getLineNumber();
  35637. const int endLine = end.getLineNumber();
  35638. if (startLine == endLine)
  35639. {
  35640. CodeDocumentLine* const line = lines [startLine];
  35641. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35642. }
  35643. String result;
  35644. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35645. String::Concatenator concatenator (result);
  35646. const int maxLine = jmin (lines.size() - 1, endLine);
  35647. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35648. {
  35649. const CodeDocumentLine* line = lines.getUnchecked(i);
  35650. int len = line->lineLength;
  35651. if (i == startLine)
  35652. {
  35653. const int index = start.getIndexInLine();
  35654. concatenator.append (line->line.substring (index, len));
  35655. }
  35656. else if (i == endLine)
  35657. {
  35658. len = end.getIndexInLine();
  35659. concatenator.append (line->line.substring (0, len));
  35660. }
  35661. else
  35662. {
  35663. concatenator.append (line->line);
  35664. }
  35665. }
  35666. return result;
  35667. }
  35668. int CodeDocument::getNumCharacters() const throw()
  35669. {
  35670. const CodeDocumentLine* const lastLine = lines.getLast();
  35671. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35672. }
  35673. const String CodeDocument::getLine (const int lineIndex) const throw()
  35674. {
  35675. const CodeDocumentLine* const line = lines [lineIndex];
  35676. return (line == 0) ? String::empty : line->line;
  35677. }
  35678. int CodeDocument::getMaximumLineLength() throw()
  35679. {
  35680. if (maximumLineLength < 0)
  35681. {
  35682. maximumLineLength = 0;
  35683. for (int i = lines.size(); --i >= 0;)
  35684. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35685. }
  35686. return maximumLineLength;
  35687. }
  35688. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35689. {
  35690. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35691. }
  35692. void CodeDocument::insertText (const Position& position, const String& text)
  35693. {
  35694. insert (text, position.getPosition(), true);
  35695. }
  35696. void CodeDocument::replaceAllContent (const String& newContent)
  35697. {
  35698. remove (0, getNumCharacters(), true);
  35699. insert (newContent, 0, true);
  35700. }
  35701. bool CodeDocument::loadFromStream (InputStream& stream)
  35702. {
  35703. replaceAllContent (stream.readEntireStreamAsString());
  35704. setSavePoint();
  35705. clearUndoHistory();
  35706. return true;
  35707. }
  35708. bool CodeDocument::writeToStream (OutputStream& stream)
  35709. {
  35710. for (int i = 0; i < lines.size(); ++i)
  35711. {
  35712. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35713. const char* utf8 = temp.toUTF8();
  35714. if (! stream.write (utf8, (int) strlen (utf8)))
  35715. return false;
  35716. }
  35717. return true;
  35718. }
  35719. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35720. {
  35721. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35722. newLineChars = newLine;
  35723. }
  35724. void CodeDocument::newTransaction()
  35725. {
  35726. undoManager.beginNewTransaction (String::empty);
  35727. }
  35728. void CodeDocument::undo()
  35729. {
  35730. newTransaction();
  35731. undoManager.undo();
  35732. }
  35733. void CodeDocument::redo()
  35734. {
  35735. undoManager.redo();
  35736. }
  35737. void CodeDocument::clearUndoHistory()
  35738. {
  35739. undoManager.clearUndoHistory();
  35740. }
  35741. void CodeDocument::setSavePoint() throw()
  35742. {
  35743. indexOfSavedState = currentActionIndex;
  35744. }
  35745. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35746. {
  35747. return currentActionIndex != indexOfSavedState;
  35748. }
  35749. static int getCodeCharacterCategory (const tchar character) throw()
  35750. {
  35751. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35752. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35753. }
  35754. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35755. {
  35756. Position p (position);
  35757. const int maxDistance = 256;
  35758. int i = 0;
  35759. while (i < maxDistance
  35760. && CharacterFunctions::isWhitespace (p.getCharacter())
  35761. && (i == 0 || (p.getCharacter() != T('\n')
  35762. && p.getCharacter() != T('\r'))))
  35763. {
  35764. ++i;
  35765. p.moveBy (1);
  35766. }
  35767. if (i == 0)
  35768. {
  35769. const int type = getCodeCharacterCategory (p.getCharacter());
  35770. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35771. {
  35772. ++i;
  35773. p.moveBy (1);
  35774. }
  35775. while (i < maxDistance
  35776. && CharacterFunctions::isWhitespace (p.getCharacter())
  35777. && (i == 0 || (p.getCharacter() != T('\n')
  35778. && p.getCharacter() != T('\r'))))
  35779. {
  35780. ++i;
  35781. p.moveBy (1);
  35782. }
  35783. }
  35784. return p;
  35785. }
  35786. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35787. {
  35788. Position p (position);
  35789. const int maxDistance = 256;
  35790. int i = 0;
  35791. bool stoppedAtLineStart = false;
  35792. while (i < maxDistance)
  35793. {
  35794. const tchar c = p.movedBy (-1).getCharacter();
  35795. if (c == T('\r') || c == T('\n'))
  35796. {
  35797. stoppedAtLineStart = true;
  35798. if (i > 0)
  35799. break;
  35800. }
  35801. if (! CharacterFunctions::isWhitespace (c))
  35802. break;
  35803. p.moveBy (-1);
  35804. ++i;
  35805. }
  35806. if (i < maxDistance && ! stoppedAtLineStart)
  35807. {
  35808. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35809. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35810. {
  35811. p.moveBy (-1);
  35812. ++i;
  35813. }
  35814. }
  35815. return p;
  35816. }
  35817. void CodeDocument::checkLastLineStatus()
  35818. {
  35819. while (lines.size() > 0
  35820. && lines.getLast()->lineLength == 0
  35821. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35822. {
  35823. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35824. lines.removeLast();
  35825. }
  35826. const CodeDocumentLine* const lastLine = lines.getLast();
  35827. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35828. {
  35829. // check that there's an empty line at the end if the preceding one ends in a newline..
  35830. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35831. }
  35832. }
  35833. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35834. {
  35835. listeners.addIfNotAlreadyThere (listener);
  35836. }
  35837. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35838. {
  35839. listeners.removeValue (listener);
  35840. }
  35841. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35842. {
  35843. const Position startPos (this, startLine, 0);
  35844. const Position endPos (this, endLine, 0);
  35845. for (int i = listeners.size(); --i >= 0;)
  35846. {
  35847. Listener* const l = (Listener*) listeners[i];
  35848. if (l != 0)
  35849. l->codeDocumentChanged (startPos, endPos);
  35850. }
  35851. }
  35852. class CodeDocumentInsertAction : public UndoableAction
  35853. {
  35854. CodeDocument& owner;
  35855. const String text;
  35856. int insertPos;
  35857. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35858. const CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35859. public:
  35860. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35861. : owner (owner_),
  35862. text (text_),
  35863. insertPos (insertPos_)
  35864. {
  35865. }
  35866. ~CodeDocumentInsertAction() {}
  35867. bool perform()
  35868. {
  35869. owner.currentActionIndex++;
  35870. owner.insert (text, insertPos, false);
  35871. return true;
  35872. }
  35873. bool undo()
  35874. {
  35875. owner.currentActionIndex--;
  35876. owner.remove (insertPos, insertPos + text.length(), false);
  35877. return true;
  35878. }
  35879. int getSizeInUnits() { return text.length() + 32; }
  35880. };
  35881. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35882. {
  35883. if (text.isEmpty())
  35884. return;
  35885. if (undoable)
  35886. {
  35887. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35888. }
  35889. else
  35890. {
  35891. Position pos (this, insertPos);
  35892. const int firstAffectedLine = pos.getLineNumber();
  35893. int lastAffectedLine = firstAffectedLine + 1;
  35894. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35895. String textInsideOriginalLine (text);
  35896. if (firstLine != 0)
  35897. {
  35898. const int index = pos.getIndexInLine();
  35899. textInsideOriginalLine = firstLine->line.substring (0, index)
  35900. + textInsideOriginalLine
  35901. + firstLine->line.substring (index);
  35902. }
  35903. maximumLineLength = -1;
  35904. Array <CodeDocumentLine*> newLines;
  35905. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35906. jassert (newLines.size() > 0);
  35907. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35908. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35909. lines.set (firstAffectedLine, newFirstLine);
  35910. if (newLines.size() > 1)
  35911. {
  35912. for (int i = 1; i < newLines.size(); ++i)
  35913. {
  35914. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35915. lines.insert (firstAffectedLine + i, l);
  35916. }
  35917. lastAffectedLine = lines.size();
  35918. }
  35919. int i, lineStart = newFirstLine->lineStartInFile;
  35920. for (i = firstAffectedLine; i < lines.size(); ++i)
  35921. {
  35922. CodeDocumentLine* const l = lines.getUnchecked (i);
  35923. l->lineStartInFile = lineStart;
  35924. lineStart += l->lineLength;
  35925. }
  35926. checkLastLineStatus();
  35927. const int newTextLength = text.length();
  35928. for (i = 0; i < positionsToMaintain.size(); ++i)
  35929. {
  35930. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35931. if (p->getPosition() >= insertPos)
  35932. p->setPosition (p->getPosition() + newTextLength);
  35933. }
  35934. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35935. }
  35936. }
  35937. class CodeDocumentDeleteAction : public UndoableAction
  35938. {
  35939. CodeDocument& owner;
  35940. int startPos, endPos;
  35941. String removedText;
  35942. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35943. const CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35944. public:
  35945. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35946. : owner (owner_),
  35947. startPos (startPos_),
  35948. endPos (endPos_)
  35949. {
  35950. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35951. CodeDocument::Position (&owner, endPos));
  35952. }
  35953. ~CodeDocumentDeleteAction() {}
  35954. bool perform()
  35955. {
  35956. owner.currentActionIndex++;
  35957. owner.remove (startPos, endPos, false);
  35958. return true;
  35959. }
  35960. bool undo()
  35961. {
  35962. owner.currentActionIndex--;
  35963. owner.insert (removedText, startPos, false);
  35964. return true;
  35965. }
  35966. int getSizeInUnits() { return removedText.length() + 32; }
  35967. };
  35968. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35969. {
  35970. if (endPos <= startPos)
  35971. return;
  35972. if (undoable)
  35973. {
  35974. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35975. }
  35976. else
  35977. {
  35978. Position startPosition (this, startPos);
  35979. Position endPosition (this, endPos);
  35980. maximumLineLength = -1;
  35981. const int firstAffectedLine = startPosition.getLineNumber();
  35982. const int endLine = endPosition.getLineNumber();
  35983. int lastAffectedLine = firstAffectedLine + 1;
  35984. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35985. if (firstAffectedLine == endLine)
  35986. {
  35987. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35988. + firstLine->line.substring (endPosition.getIndexInLine());
  35989. firstLine->updateLength();
  35990. }
  35991. else
  35992. {
  35993. lastAffectedLine = lines.size();
  35994. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35995. jassert (lastLine != 0);
  35996. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35997. + lastLine->line.substring (endPosition.getIndexInLine());
  35998. firstLine->updateLength();
  35999. int numLinesToRemove = endLine - firstAffectedLine;
  36000. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  36001. }
  36002. int i;
  36003. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  36004. {
  36005. CodeDocumentLine* const l = lines.getUnchecked (i);
  36006. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  36007. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  36008. }
  36009. checkLastLineStatus();
  36010. const int totalChars = getNumCharacters();
  36011. for (i = 0; i < positionsToMaintain.size(); ++i)
  36012. {
  36013. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  36014. if (p->getPosition() > startPosition.getPosition())
  36015. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  36016. if (p->getPosition() > totalChars)
  36017. p->setPosition (totalChars);
  36018. }
  36019. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  36020. }
  36021. }
  36022. END_JUCE_NAMESPACE
  36023. /*** End of inlined file: juce_CodeDocument.cpp ***/
  36024. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  36025. BEGIN_JUCE_NAMESPACE
  36026. class CaretComponent : public Component,
  36027. public Timer
  36028. {
  36029. public:
  36030. CaretComponent()
  36031. {
  36032. setAlwaysOnTop (true);
  36033. setInterceptsMouseClicks (false, false);
  36034. }
  36035. ~CaretComponent()
  36036. {
  36037. }
  36038. void paint (Graphics& g)
  36039. {
  36040. if (getParentComponent()->hasKeyboardFocus (true))
  36041. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  36042. }
  36043. void timerCallback()
  36044. {
  36045. setVisible (! isVisible());
  36046. }
  36047. void updatePosition (CodeEditorComponent& owner)
  36048. {
  36049. startTimer (400);
  36050. setVisible (true);
  36051. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  36052. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  36053. }
  36054. };
  36055. class CodeEditorComponent::CodeEditorLine
  36056. {
  36057. public:
  36058. CodeEditorLine() throw()
  36059. {
  36060. }
  36061. ~CodeEditorLine() throw()
  36062. {
  36063. }
  36064. bool update (CodeDocument& document, int lineNum,
  36065. CodeDocument::Iterator& source,
  36066. CodeTokeniser* analyser, const int spacesPerTab,
  36067. const CodeDocument::Position& selectionStart,
  36068. const CodeDocument::Position& selectionEnd)
  36069. {
  36070. Array <SyntaxToken> newTokens;
  36071. newTokens.ensureStorageAllocated (8);
  36072. if (analyser == 0)
  36073. {
  36074. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  36075. }
  36076. else if (lineNum < document.getNumLines())
  36077. {
  36078. const CodeDocument::Position pos (&document, lineNum, 0);
  36079. createTokens (pos.getPosition(), pos.getLineText(),
  36080. source, analyser, newTokens);
  36081. }
  36082. replaceTabsWithSpaces (newTokens, spacesPerTab);
  36083. int newHighlightStart = 0;
  36084. int newHighlightEnd = 0;
  36085. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  36086. {
  36087. const String line (document.getLine (lineNum));
  36088. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  36089. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  36090. line, spacesPerTab);
  36091. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  36092. line, spacesPerTab);
  36093. }
  36094. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  36095. {
  36096. highlightColumnStart = newHighlightStart;
  36097. highlightColumnEnd = newHighlightEnd;
  36098. }
  36099. else
  36100. {
  36101. if (tokens.size() == newTokens.size())
  36102. {
  36103. bool allTheSame = true;
  36104. for (int i = newTokens.size(); --i >= 0;)
  36105. {
  36106. if (tokens.getReference(i) != newTokens.getReference(i))
  36107. {
  36108. allTheSame = false;
  36109. break;
  36110. }
  36111. }
  36112. if (allTheSame)
  36113. return false;
  36114. }
  36115. }
  36116. tokens.swapWithArray (newTokens);
  36117. return true;
  36118. }
  36119. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  36120. float x, const int y, const int baselineOffset, const int lineHeight,
  36121. const Colour& highlightColour) const throw()
  36122. {
  36123. if (highlightColumnStart < highlightColumnEnd)
  36124. {
  36125. g.setColour (highlightColour);
  36126. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  36127. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  36128. }
  36129. int lastType = std::numeric_limits<int>::min();
  36130. for (int i = 0; i < tokens.size(); ++i)
  36131. {
  36132. SyntaxToken& token = tokens.getReference(i);
  36133. if (lastType != token.tokenType)
  36134. {
  36135. lastType = token.tokenType;
  36136. g.setColour (owner.getColourForTokenType (lastType));
  36137. }
  36138. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  36139. if (i < tokens.size() - 1)
  36140. {
  36141. if (token.width < 0)
  36142. token.width = font.getStringWidthFloat (token.text);
  36143. x += token.width;
  36144. }
  36145. }
  36146. }
  36147. private:
  36148. struct SyntaxToken
  36149. {
  36150. String text;
  36151. int tokenType;
  36152. float width;
  36153. SyntaxToken (const String& text_, const int type) throw()
  36154. : text (text_), tokenType (type), width (-1.0f)
  36155. {
  36156. }
  36157. bool operator!= (const SyntaxToken& other) const throw()
  36158. {
  36159. return text != other.text || tokenType != other.tokenType;
  36160. }
  36161. };
  36162. Array <SyntaxToken> tokens;
  36163. int highlightColumnStart, highlightColumnEnd;
  36164. static void createTokens (int startPosition, const String& lineText,
  36165. CodeDocument::Iterator& source,
  36166. CodeTokeniser* analyser,
  36167. Array <SyntaxToken>& newTokens)
  36168. {
  36169. CodeDocument::Iterator lastIterator (source);
  36170. const int lineLength = lineText.length();
  36171. for (;;)
  36172. {
  36173. int tokenType = analyser->readNextToken (source);
  36174. int tokenStart = lastIterator.getPosition();
  36175. int tokenEnd = source.getPosition();
  36176. if (tokenEnd <= tokenStart)
  36177. break;
  36178. tokenEnd -= startPosition;
  36179. if (tokenEnd > 0)
  36180. {
  36181. tokenStart -= startPosition;
  36182. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  36183. tokenType));
  36184. if (tokenEnd >= lineLength)
  36185. break;
  36186. }
  36187. lastIterator = source;
  36188. }
  36189. source = lastIterator;
  36190. }
  36191. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  36192. {
  36193. int x = 0;
  36194. for (int i = 0; i < tokens.size(); ++i)
  36195. {
  36196. SyntaxToken& t = tokens.getReference(i);
  36197. for (;;)
  36198. {
  36199. int tabPos = t.text.indexOfChar (T('\t'));
  36200. if (tabPos < 0)
  36201. break;
  36202. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  36203. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  36204. }
  36205. x += t.text.length();
  36206. }
  36207. }
  36208. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  36209. {
  36210. jassert (index <= line.length());
  36211. int col = 0;
  36212. for (int i = 0; i < index; ++i)
  36213. {
  36214. if (line[i] != T('\t'))
  36215. ++col;
  36216. else
  36217. col += spacesPerTab - (col % spacesPerTab);
  36218. }
  36219. return col;
  36220. }
  36221. };
  36222. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  36223. CodeTokeniser* const codeTokeniser_)
  36224. : document (document_),
  36225. firstLineOnScreen (0),
  36226. gutter (5),
  36227. spacesPerTab (4),
  36228. lineHeight (0),
  36229. linesOnScreen (0),
  36230. columnsOnScreen (0),
  36231. scrollbarThickness (16),
  36232. columnToTryToMaintain (-1),
  36233. useSpacesForTabs (false),
  36234. xOffset (0),
  36235. codeTokeniser (codeTokeniser_)
  36236. {
  36237. caretPos = CodeDocument::Position (&document_, 0, 0);
  36238. caretPos.setPositionMaintained (true);
  36239. selectionStart = CodeDocument::Position (&document_, 0, 0);
  36240. selectionStart.setPositionMaintained (true);
  36241. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  36242. selectionEnd.setPositionMaintained (true);
  36243. setOpaque (true);
  36244. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  36245. setWantsKeyboardFocus (true);
  36246. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  36247. verticalScrollBar->setSingleStepSize (1.0);
  36248. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  36249. horizontalScrollBar->setSingleStepSize (1.0);
  36250. addAndMakeVisible (caret = new CaretComponent());
  36251. Font f (12.0f);
  36252. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  36253. setFont (f);
  36254. resetToDefaultColours();
  36255. verticalScrollBar->addListener (this);
  36256. horizontalScrollBar->addListener (this);
  36257. document.addListener (this);
  36258. }
  36259. CodeEditorComponent::~CodeEditorComponent()
  36260. {
  36261. document.removeListener (this);
  36262. deleteAllChildren();
  36263. }
  36264. void CodeEditorComponent::loadContent (const String& newContent)
  36265. {
  36266. clearCachedIterators (0);
  36267. document.replaceAllContent (newContent);
  36268. document.clearUndoHistory();
  36269. document.setSavePoint();
  36270. caretPos.setPosition (0);
  36271. selectionStart.setPosition (0);
  36272. selectionEnd.setPosition (0);
  36273. scrollToLine (0);
  36274. }
  36275. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  36276. const CodeDocument::Position& affectedTextEnd)
  36277. {
  36278. clearCachedIterators (affectedTextStart.getLineNumber());
  36279. triggerAsyncUpdate();
  36280. ((CaretComponent*) caret)->updatePosition (*this);
  36281. columnToTryToMaintain = -1;
  36282. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  36283. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  36284. deselectAll();
  36285. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  36286. || caretPos.getPosition() < affectedTextStart.getPosition())
  36287. moveCaretTo (affectedTextStart, false);
  36288. updateScrollBars();
  36289. }
  36290. void CodeEditorComponent::resized()
  36291. {
  36292. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  36293. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  36294. lines.clear();
  36295. rebuildLineTokens();
  36296. ((CaretComponent*) caret)->updatePosition (*this);
  36297. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  36298. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  36299. updateScrollBars();
  36300. }
  36301. void CodeEditorComponent::paint (Graphics& g)
  36302. {
  36303. handleUpdateNowIfNeeded();
  36304. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  36305. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  36306. g.setFont (font);
  36307. const int baselineOffset = (int) font.getAscent();
  36308. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  36309. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  36310. const Rectangle<int> clip (g.getClipBounds());
  36311. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  36312. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  36313. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  36314. {
  36315. lines.getUnchecked(j)->draw (*this, g, font,
  36316. (float) (gutter - xOffset * charWidth),
  36317. lineHeight * j, baselineOffset, lineHeight,
  36318. highlightColour);
  36319. }
  36320. }
  36321. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  36322. {
  36323. if (scrollbarThickness != thickness)
  36324. {
  36325. scrollbarThickness = thickness;
  36326. resized();
  36327. }
  36328. }
  36329. void CodeEditorComponent::handleAsyncUpdate()
  36330. {
  36331. rebuildLineTokens();
  36332. }
  36333. void CodeEditorComponent::rebuildLineTokens()
  36334. {
  36335. cancelPendingUpdate();
  36336. const int numNeeded = linesOnScreen + 1;
  36337. int minLineToRepaint = numNeeded;
  36338. int maxLineToRepaint = 0;
  36339. if (numNeeded != lines.size())
  36340. {
  36341. lines.clear();
  36342. for (int i = numNeeded; --i >= 0;)
  36343. lines.add (new CodeEditorLine());
  36344. minLineToRepaint = 0;
  36345. maxLineToRepaint = numNeeded;
  36346. }
  36347. jassert (numNeeded == lines.size());
  36348. CodeDocument::Iterator source (&document);
  36349. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  36350. for (int i = 0; i < numNeeded; ++i)
  36351. {
  36352. CodeEditorLine* const line = lines.getUnchecked(i);
  36353. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  36354. selectionStart, selectionEnd))
  36355. {
  36356. minLineToRepaint = jmin (minLineToRepaint, i);
  36357. maxLineToRepaint = jmax (maxLineToRepaint, i);
  36358. }
  36359. }
  36360. if (minLineToRepaint <= maxLineToRepaint)
  36361. {
  36362. repaint (gutter, lineHeight * minLineToRepaint - 1,
  36363. verticalScrollBar->getX() - gutter,
  36364. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  36365. }
  36366. }
  36367. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  36368. {
  36369. caretPos = newPos;
  36370. columnToTryToMaintain = -1;
  36371. if (highlighting)
  36372. {
  36373. if (dragType == notDragging)
  36374. {
  36375. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  36376. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  36377. dragType = draggingSelectionStart;
  36378. else
  36379. dragType = draggingSelectionEnd;
  36380. }
  36381. if (dragType == draggingSelectionStart)
  36382. {
  36383. selectionStart = caretPos;
  36384. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36385. {
  36386. const CodeDocument::Position temp (selectionStart);
  36387. selectionStart = selectionEnd;
  36388. selectionEnd = temp;
  36389. dragType = draggingSelectionEnd;
  36390. }
  36391. }
  36392. else
  36393. {
  36394. selectionEnd = caretPos;
  36395. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36396. {
  36397. const CodeDocument::Position temp (selectionStart);
  36398. selectionStart = selectionEnd;
  36399. selectionEnd = temp;
  36400. dragType = draggingSelectionStart;
  36401. }
  36402. }
  36403. triggerAsyncUpdate();
  36404. }
  36405. else
  36406. {
  36407. deselectAll();
  36408. }
  36409. ((CaretComponent*) caret)->updatePosition (*this);
  36410. scrollToKeepCaretOnScreen();
  36411. updateScrollBars();
  36412. }
  36413. void CodeEditorComponent::deselectAll()
  36414. {
  36415. if (selectionStart != selectionEnd)
  36416. triggerAsyncUpdate();
  36417. selectionStart = caretPos;
  36418. selectionEnd = caretPos;
  36419. }
  36420. void CodeEditorComponent::updateScrollBars()
  36421. {
  36422. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36423. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36424. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36425. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36426. }
  36427. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36428. {
  36429. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36430. newFirstLineOnScreen);
  36431. if (newFirstLineOnScreen != firstLineOnScreen)
  36432. {
  36433. firstLineOnScreen = newFirstLineOnScreen;
  36434. ((CaretComponent*) caret)->updatePosition (*this);
  36435. updateCachedIterators (firstLineOnScreen);
  36436. triggerAsyncUpdate();
  36437. }
  36438. }
  36439. void CodeEditorComponent::scrollToColumnInternal (double column)
  36440. {
  36441. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36442. if (xOffset != newOffset)
  36443. {
  36444. xOffset = newOffset;
  36445. ((CaretComponent*) caret)->updatePosition (*this);
  36446. repaint();
  36447. }
  36448. }
  36449. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36450. {
  36451. scrollToLineInternal (newFirstLineOnScreen);
  36452. updateScrollBars();
  36453. }
  36454. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36455. {
  36456. scrollToColumnInternal (newFirstColumnOnScreen);
  36457. updateScrollBars();
  36458. }
  36459. void CodeEditorComponent::scrollBy (int deltaLines)
  36460. {
  36461. scrollToLine (firstLineOnScreen + deltaLines);
  36462. }
  36463. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36464. {
  36465. if (caretPos.getLineNumber() < firstLineOnScreen)
  36466. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36467. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36468. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36469. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36470. if (column >= xOffset + columnsOnScreen - 1)
  36471. scrollToColumn (column + 1 - columnsOnScreen);
  36472. else if (column < xOffset)
  36473. scrollToColumn (column);
  36474. }
  36475. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36476. {
  36477. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36478. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36479. roundToInt (charWidth),
  36480. lineHeight);
  36481. }
  36482. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36483. {
  36484. const int line = y / lineHeight + firstLineOnScreen;
  36485. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36486. const int index = columnToIndex (line, column);
  36487. return CodeDocument::Position (&document, line, index);
  36488. }
  36489. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36490. {
  36491. document.deleteSection (selectionStart, selectionEnd);
  36492. if (newText.isNotEmpty())
  36493. document.insertText (caretPos, newText);
  36494. scrollToKeepCaretOnScreen();
  36495. }
  36496. void CodeEditorComponent::insertTabAtCaret()
  36497. {
  36498. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36499. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36500. {
  36501. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36502. }
  36503. if (useSpacesForTabs)
  36504. {
  36505. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36506. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36507. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36508. }
  36509. else
  36510. {
  36511. insertTextAtCaret (T("\t"));
  36512. }
  36513. }
  36514. void CodeEditorComponent::cut()
  36515. {
  36516. insertTextAtCaret (String::empty);
  36517. }
  36518. void CodeEditorComponent::copy()
  36519. {
  36520. newTransaction();
  36521. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36522. if (selection.isNotEmpty())
  36523. SystemClipboard::copyTextToClipboard (selection);
  36524. }
  36525. void CodeEditorComponent::copyThenCut()
  36526. {
  36527. copy();
  36528. cut();
  36529. newTransaction();
  36530. }
  36531. void CodeEditorComponent::paste()
  36532. {
  36533. newTransaction();
  36534. const String clip (SystemClipboard::getTextFromClipboard());
  36535. if (clip.isNotEmpty())
  36536. insertTextAtCaret (clip);
  36537. newTransaction();
  36538. }
  36539. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36540. {
  36541. newTransaction();
  36542. if (moveInWholeWordSteps)
  36543. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36544. else
  36545. moveCaretTo (caretPos.movedBy (-1), selecting);
  36546. }
  36547. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36548. {
  36549. newTransaction();
  36550. if (moveInWholeWordSteps)
  36551. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36552. else
  36553. moveCaretTo (caretPos.movedBy (1), selecting);
  36554. }
  36555. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36556. {
  36557. CodeDocument::Position pos (caretPos);
  36558. const int newLineNum = pos.getLineNumber() + delta;
  36559. if (columnToTryToMaintain < 0)
  36560. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36561. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36562. const int colToMaintain = columnToTryToMaintain;
  36563. moveCaretTo (pos, selecting);
  36564. columnToTryToMaintain = colToMaintain;
  36565. }
  36566. void CodeEditorComponent::cursorDown (const bool selecting)
  36567. {
  36568. newTransaction();
  36569. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36570. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36571. else
  36572. moveLineDelta (1, selecting);
  36573. }
  36574. void CodeEditorComponent::cursorUp (const bool selecting)
  36575. {
  36576. newTransaction();
  36577. if (caretPos.getLineNumber() == 0)
  36578. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36579. else
  36580. moveLineDelta (-1, selecting);
  36581. }
  36582. void CodeEditorComponent::pageDown (const bool selecting)
  36583. {
  36584. newTransaction();
  36585. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36586. moveLineDelta (linesOnScreen, selecting);
  36587. }
  36588. void CodeEditorComponent::pageUp (const bool selecting)
  36589. {
  36590. newTransaction();
  36591. scrollBy (-linesOnScreen);
  36592. moveLineDelta (-linesOnScreen, selecting);
  36593. }
  36594. void CodeEditorComponent::scrollUp()
  36595. {
  36596. newTransaction();
  36597. scrollBy (1);
  36598. if (caretPos.getLineNumber() < firstLineOnScreen)
  36599. moveLineDelta (1, false);
  36600. }
  36601. void CodeEditorComponent::scrollDown()
  36602. {
  36603. newTransaction();
  36604. scrollBy (-1);
  36605. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36606. moveLineDelta (-1, false);
  36607. }
  36608. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36609. {
  36610. newTransaction();
  36611. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36612. }
  36613. static int findFirstNonWhitespaceChar (const String& line) throw()
  36614. {
  36615. const int len = line.length();
  36616. for (int i = 0; i < len; ++i)
  36617. if (! CharacterFunctions::isWhitespace (line [i]))
  36618. return i;
  36619. return 0;
  36620. }
  36621. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36622. {
  36623. newTransaction();
  36624. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36625. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36626. index = 0;
  36627. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36628. }
  36629. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36630. {
  36631. newTransaction();
  36632. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36633. }
  36634. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36635. {
  36636. newTransaction();
  36637. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36638. }
  36639. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36640. {
  36641. if (moveInWholeWordSteps)
  36642. {
  36643. cut(); // in case something is already highlighted
  36644. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36645. }
  36646. else
  36647. {
  36648. if (selectionStart == selectionEnd)
  36649. selectionStart.moveBy (-1);
  36650. }
  36651. cut();
  36652. }
  36653. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36654. {
  36655. if (moveInWholeWordSteps)
  36656. {
  36657. cut(); // in case something is already highlighted
  36658. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36659. }
  36660. else
  36661. {
  36662. if (selectionStart == selectionEnd)
  36663. selectionEnd.moveBy (1);
  36664. else
  36665. newTransaction();
  36666. }
  36667. cut();
  36668. }
  36669. void CodeEditorComponent::selectAll()
  36670. {
  36671. newTransaction();
  36672. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36673. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36674. }
  36675. void CodeEditorComponent::undo()
  36676. {
  36677. document.undo();
  36678. scrollToKeepCaretOnScreen();
  36679. }
  36680. void CodeEditorComponent::redo()
  36681. {
  36682. document.redo();
  36683. scrollToKeepCaretOnScreen();
  36684. }
  36685. void CodeEditorComponent::newTransaction()
  36686. {
  36687. document.newTransaction();
  36688. startTimer (600);
  36689. }
  36690. void CodeEditorComponent::timerCallback()
  36691. {
  36692. newTransaction();
  36693. }
  36694. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36695. {
  36696. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36697. }
  36698. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36699. {
  36700. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36701. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36702. }
  36703. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36704. {
  36705. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36706. CodeDocument::Position (&document, range.getEnd()));
  36707. }
  36708. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36709. {
  36710. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36711. const bool shiftDown = key.getModifiers().isShiftDown();
  36712. if (key.isKeyCode (KeyPress::leftKey))
  36713. {
  36714. cursorLeft (moveInWholeWordSteps, shiftDown);
  36715. }
  36716. else if (key.isKeyCode (KeyPress::rightKey))
  36717. {
  36718. cursorRight (moveInWholeWordSteps, shiftDown);
  36719. }
  36720. else if (key.isKeyCode (KeyPress::upKey))
  36721. {
  36722. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36723. scrollDown();
  36724. #if JUCE_MAC
  36725. else if (key.getModifiers().isCommandDown())
  36726. goToStartOfDocument (shiftDown);
  36727. #endif
  36728. else
  36729. cursorUp (shiftDown);
  36730. }
  36731. else if (key.isKeyCode (KeyPress::downKey))
  36732. {
  36733. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36734. scrollUp();
  36735. #if JUCE_MAC
  36736. else if (key.getModifiers().isCommandDown())
  36737. goToEndOfDocument (shiftDown);
  36738. #endif
  36739. else
  36740. cursorDown (shiftDown);
  36741. }
  36742. else if (key.isKeyCode (KeyPress::pageDownKey))
  36743. {
  36744. pageDown (shiftDown);
  36745. }
  36746. else if (key.isKeyCode (KeyPress::pageUpKey))
  36747. {
  36748. pageUp (shiftDown);
  36749. }
  36750. else if (key.isKeyCode (KeyPress::homeKey))
  36751. {
  36752. if (moveInWholeWordSteps)
  36753. goToStartOfDocument (shiftDown);
  36754. else
  36755. goToStartOfLine (shiftDown);
  36756. }
  36757. else if (key.isKeyCode (KeyPress::endKey))
  36758. {
  36759. if (moveInWholeWordSteps)
  36760. goToEndOfDocument (shiftDown);
  36761. else
  36762. goToEndOfLine (shiftDown);
  36763. }
  36764. else if (key.isKeyCode (KeyPress::backspaceKey))
  36765. {
  36766. backspace (moveInWholeWordSteps);
  36767. }
  36768. else if (key.isKeyCode (KeyPress::deleteKey))
  36769. {
  36770. deleteForward (moveInWholeWordSteps);
  36771. }
  36772. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36773. {
  36774. copy();
  36775. }
  36776. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36777. {
  36778. copyThenCut();
  36779. }
  36780. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36781. {
  36782. paste();
  36783. }
  36784. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36785. {
  36786. undo();
  36787. }
  36788. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36789. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36790. {
  36791. redo();
  36792. }
  36793. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36794. {
  36795. selectAll();
  36796. }
  36797. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36798. {
  36799. insertTabAtCaret();
  36800. }
  36801. else if (key == KeyPress::returnKey)
  36802. {
  36803. newTransaction();
  36804. insertTextAtCaret (document.getNewLineCharacters());
  36805. }
  36806. else if (key.isKeyCode (KeyPress::escapeKey))
  36807. {
  36808. newTransaction();
  36809. }
  36810. else if (key.getTextCharacter() >= ' ')
  36811. {
  36812. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36813. }
  36814. else
  36815. {
  36816. return false;
  36817. }
  36818. return true;
  36819. }
  36820. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36821. {
  36822. newTransaction();
  36823. dragType = notDragging;
  36824. if (! e.mods.isPopupMenu())
  36825. {
  36826. beginDragAutoRepeat (100);
  36827. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36828. }
  36829. else
  36830. {
  36831. }
  36832. }
  36833. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36834. {
  36835. if (! e.mods.isPopupMenu())
  36836. moveCaretTo (getPositionAt (e.x, e.y), true);
  36837. }
  36838. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36839. {
  36840. newTransaction();
  36841. beginDragAutoRepeat (0);
  36842. dragType = notDragging;
  36843. }
  36844. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36845. {
  36846. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36847. CodeDocument::Position tokenEnd (tokenStart);
  36848. if (e.getNumberOfClicks() > 2)
  36849. {
  36850. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36851. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36852. }
  36853. else
  36854. {
  36855. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36856. tokenEnd.moveBy (1);
  36857. tokenStart = tokenEnd;
  36858. while (tokenStart.getIndexInLine() > 0
  36859. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36860. tokenStart.moveBy (-1);
  36861. }
  36862. moveCaretTo (tokenEnd, false);
  36863. moveCaretTo (tokenStart, true);
  36864. }
  36865. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36866. {
  36867. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36868. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36869. }
  36870. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  36871. {
  36872. if (scrollBarThatHasMoved == verticalScrollBar)
  36873. scrollToLineInternal ((int) newRangeStart);
  36874. else
  36875. scrollToColumnInternal (newRangeStart);
  36876. }
  36877. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36878. {
  36879. useSpacesForTabs = insertSpaces;
  36880. if (spacesPerTab != numSpaces)
  36881. {
  36882. spacesPerTab = numSpaces;
  36883. triggerAsyncUpdate();
  36884. }
  36885. }
  36886. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36887. {
  36888. const String line (document.getLine (lineNum));
  36889. jassert (index <= line.length());
  36890. int col = 0;
  36891. for (int i = 0; i < index; ++i)
  36892. {
  36893. if (line[i] != T('\t'))
  36894. ++col;
  36895. else
  36896. col += getTabSize() - (col % getTabSize());
  36897. }
  36898. return col;
  36899. }
  36900. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36901. {
  36902. const String line (document.getLine (lineNum));
  36903. const int lineLength = line.length();
  36904. int i, col = 0;
  36905. for (i = 0; i < lineLength; ++i)
  36906. {
  36907. if (line[i] != T('\t'))
  36908. ++col;
  36909. else
  36910. col += getTabSize() - (col % getTabSize());
  36911. if (col > column)
  36912. break;
  36913. }
  36914. return i;
  36915. }
  36916. void CodeEditorComponent::setFont (const Font& newFont)
  36917. {
  36918. font = newFont;
  36919. charWidth = font.getStringWidthFloat (T("0"));
  36920. lineHeight = roundToInt (font.getHeight());
  36921. resized();
  36922. }
  36923. void CodeEditorComponent::resetToDefaultColours()
  36924. {
  36925. coloursForTokenCategories.clear();
  36926. if (codeTokeniser != 0)
  36927. {
  36928. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36929. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36930. }
  36931. }
  36932. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36933. {
  36934. jassert (tokenType < 256);
  36935. while (coloursForTokenCategories.size() < tokenType)
  36936. coloursForTokenCategories.add (Colours::black);
  36937. coloursForTokenCategories.set (tokenType, colour);
  36938. repaint();
  36939. }
  36940. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36941. {
  36942. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36943. return findColour (CodeEditorComponent::defaultTextColourId);
  36944. return coloursForTokenCategories.getReference (tokenType);
  36945. }
  36946. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36947. {
  36948. int i;
  36949. for (i = cachedIterators.size(); --i >= 0;)
  36950. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36951. break;
  36952. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36953. }
  36954. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36955. {
  36956. const int maxNumCachedPositions = 5000;
  36957. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36958. if (cachedIterators.size() == 0)
  36959. cachedIterators.add (new CodeDocument::Iterator (&document));
  36960. if (codeTokeniser == 0)
  36961. return;
  36962. for (;;)
  36963. {
  36964. CodeDocument::Iterator* last = cachedIterators.getLast();
  36965. if (last->getLine() >= maxLineNum)
  36966. break;
  36967. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36968. cachedIterators.add (t);
  36969. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36970. for (;;)
  36971. {
  36972. codeTokeniser->readNextToken (*t);
  36973. if (t->getLine() >= targetLine)
  36974. break;
  36975. if (t->isEOF())
  36976. return;
  36977. }
  36978. }
  36979. }
  36980. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36981. {
  36982. if (codeTokeniser == 0)
  36983. return;
  36984. for (int i = cachedIterators.size(); --i >= 0;)
  36985. {
  36986. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36987. if (t->getPosition() <= position)
  36988. {
  36989. source = *t;
  36990. break;
  36991. }
  36992. }
  36993. while (source.getPosition() < position)
  36994. {
  36995. const CodeDocument::Iterator original (source);
  36996. codeTokeniser->readNextToken (source);
  36997. if (source.getPosition() > position || source.isEOF())
  36998. {
  36999. source = original;
  37000. break;
  37001. }
  37002. }
  37003. }
  37004. END_JUCE_NAMESPACE
  37005. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  37006. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37007. BEGIN_JUCE_NAMESPACE
  37008. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  37009. {
  37010. }
  37011. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  37012. {
  37013. }
  37014. namespace CppTokeniser
  37015. {
  37016. static bool isIdentifierStart (const tchar c) throw()
  37017. {
  37018. return CharacterFunctions::isLetter (c)
  37019. || c == T('_') || c == T('@');
  37020. }
  37021. static bool isIdentifierBody (const tchar c) throw()
  37022. {
  37023. return CharacterFunctions::isLetter (c)
  37024. || CharacterFunctions::isDigit (c)
  37025. || c == T('_') || c == T('@');
  37026. }
  37027. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  37028. {
  37029. static const tchar* keywords2Char[] =
  37030. { T("if"), T("do"), T("or"), 0 };
  37031. static const tchar* keywords3Char[] =
  37032. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  37033. static const tchar* keywords4Char[] =
  37034. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  37035. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  37036. static const tchar* keywords5Char[] =
  37037. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  37038. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  37039. static const tchar* keywords6Char[] =
  37040. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  37041. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  37042. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  37043. static const tchar* keywordsOther[] =
  37044. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  37045. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  37046. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  37047. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  37048. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  37049. int tokenLength = 0;
  37050. tchar possibleIdentifier [19];
  37051. while (isIdentifierBody (source.peekNextChar()))
  37052. {
  37053. const tchar c = source.nextChar();
  37054. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  37055. possibleIdentifier [tokenLength] = c;
  37056. ++tokenLength;
  37057. }
  37058. if (tokenLength > 1 && tokenLength <= 16)
  37059. {
  37060. possibleIdentifier [tokenLength] = 0;
  37061. const tchar** k;
  37062. switch (tokenLength)
  37063. {
  37064. case 2: k = keywords2Char; break;
  37065. case 3: k = keywords3Char; break;
  37066. case 4: k = keywords4Char; break;
  37067. case 5: k = keywords5Char; break;
  37068. case 6: k = keywords6Char; break;
  37069. default: k = keywordsOther; break;
  37070. }
  37071. int i = 0;
  37072. while (k[i] != 0)
  37073. {
  37074. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  37075. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  37076. ++i;
  37077. }
  37078. }
  37079. return CPlusPlusCodeTokeniser::tokenType_identifier;
  37080. }
  37081. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  37082. {
  37083. const juce_wchar c = source.peekNextChar();
  37084. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  37085. source.skip();
  37086. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  37087. return false;
  37088. return true;
  37089. }
  37090. static bool isHexDigit (const juce_wchar c) throw()
  37091. {
  37092. return (c >= '0' && c <= '9')
  37093. || (c >= 'a' && c <= 'f')
  37094. || (c >= 'A' && c <= 'F');
  37095. }
  37096. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  37097. {
  37098. if (source.nextChar() != '0')
  37099. return false;
  37100. juce_wchar c = source.nextChar();
  37101. if (c != 'x' && c != 'X')
  37102. return false;
  37103. int numDigits = 0;
  37104. while (isHexDigit (source.peekNextChar()))
  37105. {
  37106. ++numDigits;
  37107. source.skip();
  37108. }
  37109. if (numDigits == 0)
  37110. return false;
  37111. return skipNumberSuffix (source);
  37112. }
  37113. static bool isOctalDigit (const juce_wchar c) throw()
  37114. {
  37115. return c >= '0' && c <= '7';
  37116. }
  37117. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  37118. {
  37119. if (source.nextChar() != '0')
  37120. return false;
  37121. if (! isOctalDigit (source.nextChar()))
  37122. return false;
  37123. while (isOctalDigit (source.peekNextChar()))
  37124. source.skip();
  37125. return skipNumberSuffix (source);
  37126. }
  37127. static bool isDecimalDigit (const juce_wchar c) throw()
  37128. {
  37129. return c >= '0' && c <= '9';
  37130. }
  37131. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  37132. {
  37133. int numChars = 0;
  37134. while (isDecimalDigit (source.peekNextChar()))
  37135. {
  37136. ++numChars;
  37137. source.skip();
  37138. }
  37139. if (numChars == 0)
  37140. return false;
  37141. return skipNumberSuffix (source);
  37142. }
  37143. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  37144. {
  37145. int numDigits = 0;
  37146. while (isDecimalDigit (source.peekNextChar()))
  37147. {
  37148. source.skip();
  37149. ++numDigits;
  37150. }
  37151. const bool hasPoint = (source.peekNextChar() == '.');
  37152. if (hasPoint)
  37153. {
  37154. source.skip();
  37155. while (isDecimalDigit (source.peekNextChar()))
  37156. {
  37157. source.skip();
  37158. ++numDigits;
  37159. }
  37160. }
  37161. if (numDigits == 0)
  37162. return false;
  37163. juce_wchar c = source.peekNextChar();
  37164. const bool hasExponent = (c == 'e' || c == 'E');
  37165. if (hasExponent)
  37166. {
  37167. source.skip();
  37168. c = source.peekNextChar();
  37169. if (c == '+' || c == '-')
  37170. source.skip();
  37171. int numExpDigits = 0;
  37172. while (isDecimalDigit (source.peekNextChar()))
  37173. {
  37174. source.skip();
  37175. ++numExpDigits;
  37176. }
  37177. if (numExpDigits == 0)
  37178. return false;
  37179. }
  37180. c = source.peekNextChar();
  37181. if (c == 'f' || c == 'F')
  37182. source.skip();
  37183. else if (! (hasExponent || hasPoint))
  37184. return false;
  37185. return true;
  37186. }
  37187. static int parseNumber (CodeDocument::Iterator& source)
  37188. {
  37189. const CodeDocument::Iterator original (source);
  37190. if (parseFloatLiteral (source))
  37191. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  37192. source = original;
  37193. if (parseHexLiteral (source))
  37194. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37195. source = original;
  37196. if (parseOctalLiteral (source))
  37197. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37198. source = original;
  37199. if (parseDecimalLiteral (source))
  37200. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37201. source = original;
  37202. source.skip();
  37203. return CPlusPlusCodeTokeniser::tokenType_error;
  37204. }
  37205. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  37206. {
  37207. const juce_wchar quote = source.nextChar();
  37208. for (;;)
  37209. {
  37210. const juce_wchar c = source.nextChar();
  37211. if (c == quote || c == 0)
  37212. break;
  37213. if (c == '\\')
  37214. source.skip();
  37215. }
  37216. }
  37217. static void skipComment (CodeDocument::Iterator& source) throw()
  37218. {
  37219. bool lastWasStar = false;
  37220. for (;;)
  37221. {
  37222. const juce_wchar c = source.nextChar();
  37223. if (c == 0 || (c == T('/') && lastWasStar))
  37224. break;
  37225. lastWasStar = (c == '*');
  37226. }
  37227. }
  37228. }
  37229. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  37230. {
  37231. int result = tokenType_error;
  37232. source.skipWhitespace();
  37233. tchar firstChar = source.peekNextChar();
  37234. switch (firstChar)
  37235. {
  37236. case 0:
  37237. source.skip();
  37238. break;
  37239. case T('0'):
  37240. case T('1'):
  37241. case T('2'):
  37242. case T('3'):
  37243. case T('4'):
  37244. case T('5'):
  37245. case T('6'):
  37246. case T('7'):
  37247. case T('8'):
  37248. case T('9'):
  37249. result = CppTokeniser::parseNumber (source);
  37250. break;
  37251. case T('.'):
  37252. result = CppTokeniser::parseNumber (source);
  37253. if (result == tokenType_error)
  37254. result = tokenType_punctuation;
  37255. break;
  37256. case T(','):
  37257. case T(';'):
  37258. case T(':'):
  37259. source.skip();
  37260. result = tokenType_punctuation;
  37261. break;
  37262. case T('('):
  37263. case T(')'):
  37264. case T('{'):
  37265. case T('}'):
  37266. case T('['):
  37267. case T(']'):
  37268. source.skip();
  37269. result = tokenType_bracket;
  37270. break;
  37271. case T('"'):
  37272. case T('\''):
  37273. CppTokeniser::skipQuotedString (source);
  37274. result = tokenType_stringLiteral;
  37275. break;
  37276. case T('+'):
  37277. result = tokenType_operator;
  37278. source.skip();
  37279. if (source.peekNextChar() == T('+'))
  37280. source.skip();
  37281. else if (source.peekNextChar() == T('='))
  37282. source.skip();
  37283. break;
  37284. case T('-'):
  37285. source.skip();
  37286. result = CppTokeniser::parseNumber (source);
  37287. if (result == tokenType_error)
  37288. {
  37289. result = tokenType_operator;
  37290. if (source.peekNextChar() == T('-'))
  37291. source.skip();
  37292. else if (source.peekNextChar() == T('='))
  37293. source.skip();
  37294. }
  37295. break;
  37296. case T('*'):
  37297. case T('%'):
  37298. case T('='):
  37299. case T('!'):
  37300. result = tokenType_operator;
  37301. source.skip();
  37302. if (source.peekNextChar() == T('='))
  37303. source.skip();
  37304. break;
  37305. case T('/'):
  37306. result = tokenType_operator;
  37307. source.skip();
  37308. if (source.peekNextChar() == T('='))
  37309. {
  37310. source.skip();
  37311. }
  37312. else if (source.peekNextChar() == T('/'))
  37313. {
  37314. result = tokenType_comment;
  37315. source.skipToEndOfLine();
  37316. }
  37317. else if (source.peekNextChar() == T('*'))
  37318. {
  37319. source.skip();
  37320. result = tokenType_comment;
  37321. CppTokeniser::skipComment (source);
  37322. }
  37323. break;
  37324. case T('?'):
  37325. case T('~'):
  37326. source.skip();
  37327. result = tokenType_operator;
  37328. break;
  37329. case T('<'):
  37330. source.skip();
  37331. result = tokenType_operator;
  37332. if (source.peekNextChar() == T('='))
  37333. {
  37334. source.skip();
  37335. }
  37336. else if (source.peekNextChar() == T('<'))
  37337. {
  37338. source.skip();
  37339. if (source.peekNextChar() == T('='))
  37340. source.skip();
  37341. }
  37342. break;
  37343. case T('>'):
  37344. source.skip();
  37345. result = tokenType_operator;
  37346. if (source.peekNextChar() == T('='))
  37347. {
  37348. source.skip();
  37349. }
  37350. else if (source.peekNextChar() == T('<'))
  37351. {
  37352. source.skip();
  37353. if (source.peekNextChar() == T('='))
  37354. source.skip();
  37355. }
  37356. break;
  37357. case T('|'):
  37358. source.skip();
  37359. result = tokenType_operator;
  37360. if (source.peekNextChar() == T('='))
  37361. {
  37362. source.skip();
  37363. }
  37364. else if (source.peekNextChar() == T('|'))
  37365. {
  37366. source.skip();
  37367. if (source.peekNextChar() == T('='))
  37368. source.skip();
  37369. }
  37370. break;
  37371. case T('&'):
  37372. source.skip();
  37373. result = tokenType_operator;
  37374. if (source.peekNextChar() == T('='))
  37375. {
  37376. source.skip();
  37377. }
  37378. else if (source.peekNextChar() == T('&'))
  37379. {
  37380. source.skip();
  37381. if (source.peekNextChar() == T('='))
  37382. source.skip();
  37383. }
  37384. break;
  37385. case T('^'):
  37386. source.skip();
  37387. result = tokenType_operator;
  37388. if (source.peekNextChar() == T('='))
  37389. {
  37390. source.skip();
  37391. }
  37392. else if (source.peekNextChar() == T('^'))
  37393. {
  37394. source.skip();
  37395. if (source.peekNextChar() == T('='))
  37396. source.skip();
  37397. }
  37398. break;
  37399. case T('#'):
  37400. result = tokenType_preprocessor;
  37401. source.skipToEndOfLine();
  37402. break;
  37403. default:
  37404. if (CppTokeniser::isIdentifierStart (firstChar))
  37405. result = CppTokeniser::parseIdentifier (source);
  37406. else
  37407. source.skip();
  37408. break;
  37409. }
  37410. //jassert (result != tokenType_unknown);
  37411. return result;
  37412. }
  37413. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37414. {
  37415. StringArray s;
  37416. s.add ("Error");
  37417. s.add ("Comment");
  37418. s.add ("C++ keyword");
  37419. s.add ("Identifier");
  37420. s.add ("Integer literal");
  37421. s.add ("Float literal");
  37422. s.add ("String literal");
  37423. s.add ("Operator");
  37424. s.add ("Bracket");
  37425. s.add ("Punctuation");
  37426. s.add ("Preprocessor line");
  37427. return s;
  37428. }
  37429. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37430. {
  37431. const uint32 colours[] =
  37432. {
  37433. 0xffcc0000, // error
  37434. 0xff00aa00, // comment
  37435. 0xff0000cc, // keyword
  37436. 0xff000000, // identifier
  37437. 0xff880000, // int literal
  37438. 0xff885500, // float literal
  37439. 0xff990099, // string literal
  37440. 0xff225500, // operator
  37441. 0xff000055, // bracket
  37442. 0xff004400, // punctuation
  37443. 0xff660000 // preprocessor
  37444. };
  37445. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37446. return Colour (colours [tokenType]);
  37447. return Colours::black;
  37448. }
  37449. END_JUCE_NAMESPACE
  37450. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37451. /*** Start of inlined file: juce_ComboBox.cpp ***/
  37452. BEGIN_JUCE_NAMESPACE
  37453. ComboBox::ComboBox (const String& name)
  37454. : Component (name),
  37455. lastCurrentId (0),
  37456. isButtonDown (false),
  37457. separatorPending (false),
  37458. menuActive (false),
  37459. label (0)
  37460. {
  37461. noChoicesMessage = TRANS("(no choices)");
  37462. setRepaintsOnMouseActivity (true);
  37463. lookAndFeelChanged();
  37464. currentId.addListener (this);
  37465. }
  37466. ComboBox::~ComboBox()
  37467. {
  37468. currentId.removeListener (this);
  37469. if (menuActive)
  37470. PopupMenu::dismissAllActiveMenus();
  37471. deleteAllChildren();
  37472. }
  37473. void ComboBox::setEditableText (const bool isEditable)
  37474. {
  37475. label->setEditable (isEditable, isEditable, false);
  37476. setWantsKeyboardFocus (! isEditable);
  37477. resized();
  37478. }
  37479. bool ComboBox::isTextEditable() const throw()
  37480. {
  37481. return label->isEditable();
  37482. }
  37483. void ComboBox::setJustificationType (const Justification& justification) throw()
  37484. {
  37485. label->setJustificationType (justification);
  37486. }
  37487. const Justification ComboBox::getJustificationType() const throw()
  37488. {
  37489. return label->getJustificationType();
  37490. }
  37491. void ComboBox::setTooltip (const String& newTooltip)
  37492. {
  37493. SettableTooltipClient::setTooltip (newTooltip);
  37494. label->setTooltip (newTooltip);
  37495. }
  37496. void ComboBox::addItem (const String& newItemText,
  37497. const int newItemId) throw()
  37498. {
  37499. // you can't add empty strings to the list..
  37500. jassert (newItemText.isNotEmpty());
  37501. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37502. jassert (newItemId != 0);
  37503. // you shouldn't use duplicate item IDs!
  37504. jassert (getItemForId (newItemId) == 0);
  37505. if (newItemText.isNotEmpty() && newItemId != 0)
  37506. {
  37507. if (separatorPending)
  37508. {
  37509. separatorPending = false;
  37510. ItemInfo* const item = new ItemInfo();
  37511. item->itemId = 0;
  37512. item->isEnabled = false;
  37513. item->isHeading = false;
  37514. items.add (item);
  37515. }
  37516. ItemInfo* const item = new ItemInfo();
  37517. item->name = newItemText;
  37518. item->itemId = newItemId;
  37519. item->isEnabled = true;
  37520. item->isHeading = false;
  37521. items.add (item);
  37522. }
  37523. }
  37524. void ComboBox::addSeparator() throw()
  37525. {
  37526. separatorPending = (items.size() > 0);
  37527. }
  37528. void ComboBox::addSectionHeading (const String& headingName) throw()
  37529. {
  37530. // you can't add empty strings to the list..
  37531. jassert (headingName.isNotEmpty());
  37532. if (headingName.isNotEmpty())
  37533. {
  37534. if (separatorPending)
  37535. {
  37536. separatorPending = false;
  37537. ItemInfo* const item = new ItemInfo();
  37538. item->itemId = 0;
  37539. item->isEnabled = false;
  37540. item->isHeading = false;
  37541. items.add (item);
  37542. }
  37543. ItemInfo* const item = new ItemInfo();
  37544. item->name = headingName;
  37545. item->itemId = 0;
  37546. item->isEnabled = true;
  37547. item->isHeading = true;
  37548. items.add (item);
  37549. }
  37550. }
  37551. void ComboBox::setItemEnabled (const int itemId,
  37552. const bool shouldBeEnabled) throw()
  37553. {
  37554. ItemInfo* const item = getItemForId (itemId);
  37555. if (item != 0)
  37556. item->isEnabled = shouldBeEnabled;
  37557. }
  37558. void ComboBox::changeItemText (const int itemId,
  37559. const String& newText) throw()
  37560. {
  37561. ItemInfo* const item = getItemForId (itemId);
  37562. jassert (item != 0);
  37563. if (item != 0)
  37564. item->name = newText;
  37565. }
  37566. void ComboBox::clear (const bool dontSendChangeMessage)
  37567. {
  37568. items.clear();
  37569. separatorPending = false;
  37570. if (! label->isEditable())
  37571. setSelectedItemIndex (-1, dontSendChangeMessage);
  37572. }
  37573. bool ComboBox::ItemInfo::isSeparator() const throw()
  37574. {
  37575. return name.isEmpty();
  37576. }
  37577. bool ComboBox::ItemInfo::isRealItem() const throw()
  37578. {
  37579. return ! (isHeading || name.isEmpty());
  37580. }
  37581. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37582. {
  37583. if (itemId != 0)
  37584. {
  37585. for (int i = items.size(); --i >= 0;)
  37586. if (items.getUnchecked(i)->itemId == itemId)
  37587. return items.getUnchecked(i);
  37588. }
  37589. return 0;
  37590. }
  37591. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37592. {
  37593. int n = 0;
  37594. for (int i = 0; i < items.size(); ++i)
  37595. {
  37596. ItemInfo* const item = items.getUnchecked(i);
  37597. if (item->isRealItem())
  37598. if (n++ == index)
  37599. return item;
  37600. }
  37601. return 0;
  37602. }
  37603. int ComboBox::getNumItems() const throw()
  37604. {
  37605. int n = 0;
  37606. for (int i = items.size(); --i >= 0;)
  37607. if (items.getUnchecked(i)->isRealItem())
  37608. ++n;
  37609. return n;
  37610. }
  37611. const String ComboBox::getItemText (const int index) const throw()
  37612. {
  37613. const ItemInfo* const item = getItemForIndex (index);
  37614. if (item != 0)
  37615. return item->name;
  37616. return String::empty;
  37617. }
  37618. int ComboBox::getItemId (const int index) const throw()
  37619. {
  37620. const ItemInfo* const item = getItemForIndex (index);
  37621. return (item != 0) ? item->itemId : 0;
  37622. }
  37623. int ComboBox::indexOfItemId (const int itemId) const throw()
  37624. {
  37625. int n = 0;
  37626. for (int i = 0; i < items.size(); ++i)
  37627. {
  37628. const ItemInfo* const item = items.getUnchecked(i);
  37629. if (item->isRealItem())
  37630. {
  37631. if (item->itemId == itemId)
  37632. return n;
  37633. ++n;
  37634. }
  37635. }
  37636. return -1;
  37637. }
  37638. int ComboBox::getSelectedItemIndex() const throw()
  37639. {
  37640. int index = indexOfItemId (currentId.getValue());
  37641. if (getText() != getItemText (index))
  37642. index = -1;
  37643. return index;
  37644. }
  37645. void ComboBox::setSelectedItemIndex (const int index,
  37646. const bool dontSendChangeMessage) throw()
  37647. {
  37648. setSelectedId (getItemId (index), dontSendChangeMessage);
  37649. }
  37650. int ComboBox::getSelectedId() const throw()
  37651. {
  37652. const ItemInfo* const item = getItemForId (currentId.getValue());
  37653. return (item != 0 && getText() == item->name)
  37654. ? item->itemId
  37655. : 0;
  37656. }
  37657. void ComboBox::setSelectedId (const int newItemId,
  37658. const bool dontSendChangeMessage) throw()
  37659. {
  37660. const ItemInfo* const item = getItemForId (newItemId);
  37661. const String newItemText (item != 0 ? item->name : String::empty);
  37662. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37663. {
  37664. if (! dontSendChangeMessage)
  37665. triggerAsyncUpdate();
  37666. label->setText (newItemText, false);
  37667. lastCurrentId = newItemId;
  37668. currentId = newItemId;
  37669. repaint(); // for the benefit of the 'none selected' text
  37670. }
  37671. }
  37672. void ComboBox::valueChanged (Value&)
  37673. {
  37674. if (lastCurrentId != (int) currentId.getValue())
  37675. setSelectedId (currentId.getValue(), false);
  37676. }
  37677. const String ComboBox::getText() const throw()
  37678. {
  37679. return label->getText();
  37680. }
  37681. void ComboBox::setText (const String& newText,
  37682. const bool dontSendChangeMessage) throw()
  37683. {
  37684. for (int i = items.size(); --i >= 0;)
  37685. {
  37686. const ItemInfo* const item = items.getUnchecked(i);
  37687. if (item->isRealItem()
  37688. && item->name == newText)
  37689. {
  37690. setSelectedId (item->itemId, dontSendChangeMessage);
  37691. return;
  37692. }
  37693. }
  37694. lastCurrentId = 0;
  37695. currentId = 0;
  37696. if (label->getText() != newText)
  37697. {
  37698. label->setText (newText, false);
  37699. if (! dontSendChangeMessage)
  37700. triggerAsyncUpdate();
  37701. }
  37702. repaint();
  37703. }
  37704. void ComboBox::showEditor()
  37705. {
  37706. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37707. label->showEditor();
  37708. }
  37709. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37710. {
  37711. textWhenNothingSelected = newMessage;
  37712. repaint();
  37713. }
  37714. const String ComboBox::getTextWhenNothingSelected() const throw()
  37715. {
  37716. return textWhenNothingSelected;
  37717. }
  37718. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37719. {
  37720. noChoicesMessage = newMessage;
  37721. }
  37722. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37723. {
  37724. return noChoicesMessage;
  37725. }
  37726. void ComboBox::paint (Graphics& g)
  37727. {
  37728. getLookAndFeel().drawComboBox (g,
  37729. getWidth(),
  37730. getHeight(),
  37731. isButtonDown,
  37732. label->getRight(),
  37733. 0,
  37734. getWidth() - label->getRight(),
  37735. getHeight(),
  37736. *this);
  37737. if (textWhenNothingSelected.isNotEmpty()
  37738. && label->getText().isEmpty()
  37739. && ! label->isBeingEdited())
  37740. {
  37741. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37742. g.setFont (label->getFont());
  37743. g.drawFittedText (textWhenNothingSelected,
  37744. label->getX() + 2, label->getY() + 1,
  37745. label->getWidth() - 4, label->getHeight() - 2,
  37746. label->getJustificationType(),
  37747. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37748. }
  37749. }
  37750. void ComboBox::resized()
  37751. {
  37752. if (getHeight() > 0 && getWidth() > 0)
  37753. getLookAndFeel().positionComboBoxText (*this, *label);
  37754. }
  37755. void ComboBox::enablementChanged()
  37756. {
  37757. repaint();
  37758. }
  37759. void ComboBox::lookAndFeelChanged()
  37760. {
  37761. repaint();
  37762. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37763. if (label != 0)
  37764. {
  37765. newLabel->setEditable (label->isEditable());
  37766. newLabel->setJustificationType (label->getJustificationType());
  37767. newLabel->setTooltip (label->getTooltip());
  37768. newLabel->setText (label->getText(), false);
  37769. }
  37770. delete label;
  37771. label = newLabel;
  37772. addAndMakeVisible (newLabel);
  37773. newLabel->addListener (this);
  37774. newLabel->addMouseListener (this, false);
  37775. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37776. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37777. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37778. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37779. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37780. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37781. resized();
  37782. }
  37783. void ComboBox::colourChanged()
  37784. {
  37785. lookAndFeelChanged();
  37786. }
  37787. bool ComboBox::keyPressed (const KeyPress& key)
  37788. {
  37789. bool used = false;
  37790. if (key.isKeyCode (KeyPress::upKey)
  37791. || key.isKeyCode (KeyPress::leftKey))
  37792. {
  37793. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37794. used = true;
  37795. }
  37796. else if (key.isKeyCode (KeyPress::downKey)
  37797. || key.isKeyCode (KeyPress::rightKey))
  37798. {
  37799. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37800. used = true;
  37801. }
  37802. else if (key.isKeyCode (KeyPress::returnKey))
  37803. {
  37804. showPopup();
  37805. used = true;
  37806. }
  37807. return used;
  37808. }
  37809. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37810. {
  37811. // only forward key events that aren't used by this component
  37812. return isKeyDown
  37813. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37814. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37815. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37816. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37817. }
  37818. void ComboBox::focusGained (FocusChangeType)
  37819. {
  37820. repaint();
  37821. }
  37822. void ComboBox::focusLost (FocusChangeType)
  37823. {
  37824. repaint();
  37825. }
  37826. void ComboBox::labelTextChanged (Label*)
  37827. {
  37828. triggerAsyncUpdate();
  37829. }
  37830. void ComboBox::showPopup()
  37831. {
  37832. if (! menuActive)
  37833. {
  37834. const int selectedId = getSelectedId();
  37835. ComponentDeletionWatcher deletionWatcher (this);
  37836. PopupMenu menu;
  37837. menu.setLookAndFeel (&getLookAndFeel());
  37838. for (int i = 0; i < items.size(); ++i)
  37839. {
  37840. const ItemInfo* const item = items.getUnchecked(i);
  37841. if (item->isSeparator())
  37842. menu.addSeparator();
  37843. else if (item->isHeading)
  37844. menu.addSectionHeader (item->name);
  37845. else
  37846. menu.addItem (item->itemId, item->name,
  37847. item->isEnabled, item->itemId == selectedId);
  37848. }
  37849. if (items.size() == 0)
  37850. menu.addItem (1, noChoicesMessage, false);
  37851. const int itemHeight = jlimit (12, 24, getHeight());
  37852. menuActive = true;
  37853. const int resultId = menu.showAt (this, selectedId,
  37854. getWidth(), 1, itemHeight);
  37855. if (deletionWatcher.hasBeenDeleted())
  37856. return;
  37857. menuActive = false;
  37858. if (resultId != 0)
  37859. setSelectedId (resultId);
  37860. }
  37861. }
  37862. void ComboBox::mouseDown (const MouseEvent& e)
  37863. {
  37864. beginDragAutoRepeat (300);
  37865. isButtonDown = isEnabled();
  37866. if (isButtonDown
  37867. && (e.eventComponent == this || ! label->isEditable()))
  37868. {
  37869. showPopup();
  37870. }
  37871. }
  37872. void ComboBox::mouseDrag (const MouseEvent& e)
  37873. {
  37874. beginDragAutoRepeat (50);
  37875. if (isButtonDown && ! e.mouseWasClicked())
  37876. showPopup();
  37877. }
  37878. void ComboBox::mouseUp (const MouseEvent& e2)
  37879. {
  37880. if (isButtonDown)
  37881. {
  37882. isButtonDown = false;
  37883. repaint();
  37884. const MouseEvent e (e2.getEventRelativeTo (this));
  37885. if (reallyContains (e.x, e.y, true)
  37886. && (e2.eventComponent == this || ! label->isEditable()))
  37887. {
  37888. showPopup();
  37889. }
  37890. }
  37891. }
  37892. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37893. {
  37894. jassert (listener != 0);
  37895. if (listener != 0)
  37896. listeners.add (listener);
  37897. }
  37898. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37899. {
  37900. listeners.removeValue (listener);
  37901. }
  37902. void ComboBox::handleAsyncUpdate()
  37903. {
  37904. for (int i = listeners.size(); --i >= 0;)
  37905. {
  37906. ((ComboBoxListener*) listeners.getUnchecked (i))->comboBoxChanged (this);
  37907. i = jmin (i, listeners.size());
  37908. }
  37909. }
  37910. END_JUCE_NAMESPACE
  37911. /*** End of inlined file: juce_ComboBox.cpp ***/
  37912. /*** Start of inlined file: juce_Label.cpp ***/
  37913. BEGIN_JUCE_NAMESPACE
  37914. Label::Label (const String& componentName,
  37915. const String& labelText)
  37916. : Component (componentName),
  37917. textValue (labelText),
  37918. lastTextValue (labelText),
  37919. font (15.0f),
  37920. justification (Justification::centredLeft),
  37921. ownerComponent (0),
  37922. horizontalBorderSize (5),
  37923. verticalBorderSize (1),
  37924. minimumHorizontalScale (0.7f),
  37925. editSingleClick (false),
  37926. editDoubleClick (false),
  37927. lossOfFocusDiscardsChanges (false)
  37928. {
  37929. setColour (TextEditor::textColourId, Colours::black);
  37930. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37931. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37932. textValue.addListener (this);
  37933. }
  37934. Label::~Label()
  37935. {
  37936. textValue.removeListener (this);
  37937. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37938. ownerComponent->removeComponentListener (this);
  37939. editor = 0;
  37940. }
  37941. void Label::setText (const String& newText,
  37942. const bool broadcastChangeMessage)
  37943. {
  37944. hideEditor (true);
  37945. if (lastTextValue != newText)
  37946. {
  37947. lastTextValue = newText;
  37948. textValue = newText;
  37949. repaint();
  37950. textWasChanged();
  37951. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37952. componentMovedOrResized (*ownerComponent, true, true);
  37953. if (broadcastChangeMessage)
  37954. callChangeListeners();
  37955. }
  37956. }
  37957. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37958. {
  37959. return (returnActiveEditorContents && isBeingEdited())
  37960. ? editor->getText()
  37961. : textValue.toString();
  37962. }
  37963. void Label::valueChanged (Value&)
  37964. {
  37965. if (lastTextValue != textValue.toString())
  37966. setText (textValue.toString(), true);
  37967. }
  37968. void Label::setFont (const Font& newFont) throw()
  37969. {
  37970. font = newFont;
  37971. repaint();
  37972. }
  37973. const Font& Label::getFont() const throw()
  37974. {
  37975. return font;
  37976. }
  37977. void Label::setEditable (const bool editOnSingleClick,
  37978. const bool editOnDoubleClick,
  37979. const bool lossOfFocusDiscardsChanges_) throw()
  37980. {
  37981. editSingleClick = editOnSingleClick;
  37982. editDoubleClick = editOnDoubleClick;
  37983. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37984. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37985. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37986. }
  37987. void Label::setJustificationType (const Justification& justification_) throw()
  37988. {
  37989. justification = justification_;
  37990. repaint();
  37991. }
  37992. void Label::setBorderSize (int h, int v)
  37993. {
  37994. horizontalBorderSize = h;
  37995. verticalBorderSize = v;
  37996. repaint();
  37997. }
  37998. void Label::attachToComponent (Component* owner,
  37999. const bool onLeft)
  38000. {
  38001. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38002. ownerComponent->removeComponentListener (this);
  38003. deletionWatcher = 0;
  38004. ownerComponent = owner;
  38005. leftOfOwnerComp = onLeft;
  38006. if (ownerComponent != 0)
  38007. {
  38008. deletionWatcher = new ComponentDeletionWatcher (owner);
  38009. setVisible (owner->isVisible());
  38010. ownerComponent->addComponentListener (this);
  38011. componentParentHierarchyChanged (*ownerComponent);
  38012. componentMovedOrResized (*ownerComponent, true, true);
  38013. }
  38014. }
  38015. void Label::componentMovedOrResized (Component& component,
  38016. bool /*wasMoved*/,
  38017. bool /*wasResized*/)
  38018. {
  38019. if (leftOfOwnerComp)
  38020. {
  38021. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  38022. component.getHeight());
  38023. setTopRightPosition (component.getX(), component.getY());
  38024. }
  38025. else
  38026. {
  38027. setSize (component.getWidth(),
  38028. 8 + roundToInt (getFont().getHeight()));
  38029. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  38030. }
  38031. }
  38032. void Label::componentParentHierarchyChanged (Component& component)
  38033. {
  38034. if (component.getParentComponent() != 0)
  38035. component.getParentComponent()->addChildComponent (this);
  38036. }
  38037. void Label::componentVisibilityChanged (Component& component)
  38038. {
  38039. setVisible (component.isVisible());
  38040. }
  38041. void Label::textWasEdited()
  38042. {
  38043. }
  38044. void Label::textWasChanged()
  38045. {
  38046. }
  38047. void Label::showEditor()
  38048. {
  38049. if (editor == 0)
  38050. {
  38051. addAndMakeVisible (editor = createEditorComponent());
  38052. editor->setText (getText(), false);
  38053. editor->addListener (this);
  38054. editor->grabKeyboardFocus();
  38055. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  38056. editor->addListener (this);
  38057. resized();
  38058. repaint();
  38059. editorShown (editor);
  38060. enterModalState();
  38061. editor->grabKeyboardFocus();
  38062. }
  38063. }
  38064. void Label::editorShown (TextEditor* /*editorComponent*/)
  38065. {
  38066. }
  38067. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  38068. {
  38069. }
  38070. bool Label::updateFromTextEditorContents()
  38071. {
  38072. jassert (editor != 0);
  38073. const String newText (editor->getText());
  38074. if (textValue.toString() != newText)
  38075. {
  38076. lastTextValue = newText;
  38077. textValue = newText;
  38078. repaint();
  38079. textWasChanged();
  38080. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38081. componentMovedOrResized (*ownerComponent, true, true);
  38082. return true;
  38083. }
  38084. return false;
  38085. }
  38086. void Label::hideEditor (const bool discardCurrentEditorContents)
  38087. {
  38088. if (editor != 0)
  38089. {
  38090. editorAboutToBeHidden (editor);
  38091. const bool changed = (! discardCurrentEditorContents)
  38092. && updateFromTextEditorContents();
  38093. editor = 0;
  38094. repaint();
  38095. if (changed)
  38096. textWasEdited();
  38097. exitModalState (0);
  38098. if (changed && isValidComponent())
  38099. callChangeListeners();
  38100. }
  38101. }
  38102. void Label::inputAttemptWhenModal()
  38103. {
  38104. if (editor != 0)
  38105. {
  38106. if (lossOfFocusDiscardsChanges)
  38107. textEditorEscapeKeyPressed (*editor);
  38108. else
  38109. textEditorReturnKeyPressed (*editor);
  38110. }
  38111. }
  38112. bool Label::isBeingEdited() const throw()
  38113. {
  38114. return editor != 0;
  38115. }
  38116. TextEditor* Label::createEditorComponent()
  38117. {
  38118. TextEditor* const ed = new TextEditor (getName());
  38119. ed->setFont (font);
  38120. // copy these colours from our own settings..
  38121. const int cols[] = { TextEditor::backgroundColourId,
  38122. TextEditor::textColourId,
  38123. TextEditor::highlightColourId,
  38124. TextEditor::highlightedTextColourId,
  38125. TextEditor::caretColourId,
  38126. TextEditor::outlineColourId,
  38127. TextEditor::focusedOutlineColourId,
  38128. TextEditor::shadowColourId };
  38129. for (int i = 0; i < numElementsInArray (cols); ++i)
  38130. ed->setColour (cols[i], findColour (cols[i]));
  38131. return ed;
  38132. }
  38133. void Label::paint (Graphics& g)
  38134. {
  38135. getLookAndFeel().drawLabel (g, *this);
  38136. }
  38137. void Label::mouseUp (const MouseEvent& e)
  38138. {
  38139. if (editSingleClick
  38140. && e.mouseWasClicked()
  38141. && contains (e.x, e.y)
  38142. && ! e.mods.isPopupMenu())
  38143. {
  38144. showEditor();
  38145. }
  38146. }
  38147. void Label::mouseDoubleClick (const MouseEvent& e)
  38148. {
  38149. if (editDoubleClick && ! e.mods.isPopupMenu())
  38150. showEditor();
  38151. }
  38152. void Label::resized()
  38153. {
  38154. if (editor != 0)
  38155. editor->setBoundsInset (BorderSize (0));
  38156. }
  38157. void Label::focusGained (FocusChangeType cause)
  38158. {
  38159. if (editSingleClick && cause == focusChangedByTabKey)
  38160. showEditor();
  38161. }
  38162. void Label::enablementChanged()
  38163. {
  38164. repaint();
  38165. }
  38166. void Label::colourChanged()
  38167. {
  38168. repaint();
  38169. }
  38170. void Label::setMinimumHorizontalScale (const float newScale)
  38171. {
  38172. if (minimumHorizontalScale != newScale)
  38173. {
  38174. minimumHorizontalScale = newScale;
  38175. repaint();
  38176. }
  38177. }
  38178. // We'll use a custom focus traverser here to make sure focus goes from the
  38179. // text editor to another component rather than back to the label itself.
  38180. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  38181. {
  38182. public:
  38183. LabelKeyboardFocusTraverser() {}
  38184. Component* getNextComponent (Component* current)
  38185. {
  38186. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  38187. ? current->getParentComponent() : current);
  38188. }
  38189. Component* getPreviousComponent (Component* current)
  38190. {
  38191. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  38192. ? current->getParentComponent() : current);
  38193. }
  38194. };
  38195. KeyboardFocusTraverser* Label::createFocusTraverser()
  38196. {
  38197. return new LabelKeyboardFocusTraverser();
  38198. }
  38199. void Label::addListener (LabelListener* const listener) throw()
  38200. {
  38201. jassert (listener != 0);
  38202. if (listener != 0)
  38203. listeners.add (listener);
  38204. }
  38205. void Label::removeListener (LabelListener* const listener) throw()
  38206. {
  38207. listeners.removeValue (listener);
  38208. }
  38209. void Label::callChangeListeners()
  38210. {
  38211. for (int i = listeners.size(); --i >= 0;)
  38212. {
  38213. ((LabelListener*) listeners.getUnchecked (i))->labelTextChanged (this);
  38214. i = jmin (i, listeners.size());
  38215. }
  38216. }
  38217. void Label::textEditorTextChanged (TextEditor& ed)
  38218. {
  38219. if (editor != 0)
  38220. {
  38221. jassert (&ed == editor);
  38222. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  38223. {
  38224. if (lossOfFocusDiscardsChanges)
  38225. textEditorEscapeKeyPressed (ed);
  38226. else
  38227. textEditorReturnKeyPressed (ed);
  38228. }
  38229. }
  38230. }
  38231. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  38232. {
  38233. if (editor != 0)
  38234. {
  38235. jassert (&ed == editor);
  38236. (void) ed;
  38237. const bool changed = updateFromTextEditorContents();
  38238. hideEditor (true);
  38239. if (changed)
  38240. {
  38241. textWasEdited();
  38242. if (isValidComponent())
  38243. callChangeListeners();
  38244. }
  38245. }
  38246. }
  38247. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  38248. {
  38249. if (editor != 0)
  38250. {
  38251. jassert (&ed == editor);
  38252. (void) ed;
  38253. editor->setText (textValue.toString(), false);
  38254. hideEditor (true);
  38255. }
  38256. }
  38257. void Label::textEditorFocusLost (TextEditor& ed)
  38258. {
  38259. textEditorTextChanged (ed);
  38260. }
  38261. END_JUCE_NAMESPACE
  38262. /*** End of inlined file: juce_Label.cpp ***/
  38263. /*** Start of inlined file: juce_ListBox.cpp ***/
  38264. BEGIN_JUCE_NAMESPACE
  38265. class ListBoxRowComponent : public Component,
  38266. public TooltipClient
  38267. {
  38268. public:
  38269. ListBoxRowComponent (ListBox& owner_)
  38270. : owner (owner_),
  38271. row (-1),
  38272. selected (false),
  38273. isDragging (false)
  38274. {
  38275. }
  38276. ~ListBoxRowComponent()
  38277. {
  38278. deleteAllChildren();
  38279. }
  38280. void paint (Graphics& g)
  38281. {
  38282. if (owner.getModel() != 0)
  38283. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  38284. }
  38285. void update (const int row_, const bool selected_)
  38286. {
  38287. if (row != row_ || selected != selected_)
  38288. {
  38289. repaint();
  38290. row = row_;
  38291. selected = selected_;
  38292. }
  38293. if (owner.getModel() != 0)
  38294. {
  38295. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  38296. if (customComp != 0)
  38297. {
  38298. addAndMakeVisible (customComp);
  38299. customComp->setBounds (0, 0, getWidth(), getHeight());
  38300. for (int i = getNumChildComponents(); --i >= 0;)
  38301. if (getChildComponent (i) != customComp)
  38302. delete getChildComponent (i);
  38303. }
  38304. else
  38305. {
  38306. deleteAllChildren();
  38307. }
  38308. }
  38309. }
  38310. void mouseDown (const MouseEvent& e)
  38311. {
  38312. isDragging = false;
  38313. selectRowOnMouseUp = false;
  38314. if (isEnabled())
  38315. {
  38316. if (! selected)
  38317. {
  38318. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38319. if (owner.getModel() != 0)
  38320. owner.getModel()->listBoxItemClicked (row, e);
  38321. }
  38322. else
  38323. {
  38324. selectRowOnMouseUp = true;
  38325. }
  38326. }
  38327. }
  38328. void mouseUp (const MouseEvent& e)
  38329. {
  38330. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  38331. {
  38332. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38333. if (owner.getModel() != 0)
  38334. owner.getModel()->listBoxItemClicked (row, e);
  38335. }
  38336. }
  38337. void mouseDoubleClick (const MouseEvent& e)
  38338. {
  38339. if (owner.getModel() != 0 && isEnabled())
  38340. owner.getModel()->listBoxItemDoubleClicked (row, e);
  38341. }
  38342. void mouseDrag (const MouseEvent& e)
  38343. {
  38344. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  38345. {
  38346. const SparseSet <int> selectedRows (owner.getSelectedRows());
  38347. if (selectedRows.size() > 0)
  38348. {
  38349. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  38350. if (dragDescription.isNotEmpty())
  38351. {
  38352. isDragging = true;
  38353. owner.startDragAndDrop (e, dragDescription);
  38354. }
  38355. }
  38356. }
  38357. }
  38358. void resized()
  38359. {
  38360. if (getNumChildComponents() > 0)
  38361. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  38362. }
  38363. const String getTooltip()
  38364. {
  38365. if (owner.getModel() != 0)
  38366. return owner.getModel()->getTooltipForRow (row);
  38367. return String::empty;
  38368. }
  38369. juce_UseDebuggingNewOperator
  38370. bool neededFlag;
  38371. private:
  38372. ListBox& owner;
  38373. int row;
  38374. bool selected, isDragging, selectRowOnMouseUp;
  38375. ListBoxRowComponent (const ListBoxRowComponent&);
  38376. const ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  38377. };
  38378. class ListViewport : public Viewport
  38379. {
  38380. public:
  38381. int firstIndex, firstWholeIndex, lastWholeIndex;
  38382. bool hasUpdated;
  38383. ListViewport (ListBox& owner_)
  38384. : owner (owner_)
  38385. {
  38386. setWantsKeyboardFocus (false);
  38387. setViewedComponent (new Component());
  38388. getViewedComponent()->addMouseListener (this, false);
  38389. getViewedComponent()->setWantsKeyboardFocus (false);
  38390. }
  38391. ~ListViewport()
  38392. {
  38393. getViewedComponent()->removeMouseListener (this);
  38394. getViewedComponent()->deleteAllChildren();
  38395. }
  38396. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  38397. {
  38398. return (ListBoxRowComponent*) getViewedComponent()
  38399. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38400. }
  38401. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38402. {
  38403. const int index = getIndexOfChildComponent (rowComponent);
  38404. const int num = getViewedComponent()->getNumChildComponents();
  38405. for (int i = num; --i >= 0;)
  38406. if (((firstIndex + i) % jmax (1, num)) == index)
  38407. return firstIndex + i;
  38408. return -1;
  38409. }
  38410. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38411. {
  38412. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38413. ? getComponentForRow (row) : 0;
  38414. }
  38415. void visibleAreaChanged (int, int, int, int)
  38416. {
  38417. updateVisibleArea (true);
  38418. if (owner.getModel() != 0)
  38419. owner.getModel()->listWasScrolled();
  38420. }
  38421. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38422. {
  38423. hasUpdated = false;
  38424. const int newX = getViewedComponent()->getX();
  38425. int newY = getViewedComponent()->getY();
  38426. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38427. const int newH = owner.totalItems * owner.getRowHeight();
  38428. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38429. newY = getMaximumVisibleHeight() - newH;
  38430. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38431. if (makeSureItUpdatesContent && ! hasUpdated)
  38432. updateContents();
  38433. }
  38434. void updateContents()
  38435. {
  38436. hasUpdated = true;
  38437. const int rowHeight = owner.getRowHeight();
  38438. if (rowHeight > 0)
  38439. {
  38440. const int y = getViewPositionY();
  38441. const int w = getViewedComponent()->getWidth();
  38442. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38443. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38444. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38445. jassert (numNeeded >= 0);
  38446. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38447. {
  38448. Component* const rowToRemove
  38449. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38450. delete rowToRemove;
  38451. }
  38452. firstIndex = y / rowHeight;
  38453. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38454. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38455. for (int i = 0; i < numNeeded; ++i)
  38456. {
  38457. const int row = i + firstIndex;
  38458. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38459. if (rowComp != 0)
  38460. {
  38461. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38462. rowComp->update (row, owner.isRowSelected (row));
  38463. }
  38464. }
  38465. }
  38466. if (owner.headerComponent != 0)
  38467. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38468. owner.outlineThickness,
  38469. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38470. getViewedComponent()->getWidth()),
  38471. owner.headerComponent->getHeight());
  38472. }
  38473. void paint (Graphics& g)
  38474. {
  38475. if (isOpaque())
  38476. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38477. }
  38478. bool keyPressed (const KeyPress& key)
  38479. {
  38480. if (key.isKeyCode (KeyPress::upKey)
  38481. || key.isKeyCode (KeyPress::downKey)
  38482. || key.isKeyCode (KeyPress::pageUpKey)
  38483. || key.isKeyCode (KeyPress::pageDownKey)
  38484. || key.isKeyCode (KeyPress::homeKey)
  38485. || key.isKeyCode (KeyPress::endKey))
  38486. {
  38487. // we want to avoid these keypresses going to the viewport, and instead allow
  38488. // them to pass up to our listbox..
  38489. return false;
  38490. }
  38491. return Viewport::keyPressed (key);
  38492. }
  38493. juce_UseDebuggingNewOperator
  38494. private:
  38495. ListBox& owner;
  38496. ListViewport (const ListViewport&);
  38497. const ListViewport& operator= (const ListViewport&);
  38498. };
  38499. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38500. : Component (name),
  38501. model (model_),
  38502. headerComponent (0),
  38503. totalItems (0),
  38504. rowHeight (22),
  38505. minimumRowWidth (0),
  38506. outlineThickness (0),
  38507. lastRowSelected (-1),
  38508. mouseMoveSelects (false),
  38509. multipleSelection (false),
  38510. hasDoneInitialUpdate (false)
  38511. {
  38512. addAndMakeVisible (viewport = new ListViewport (*this));
  38513. setWantsKeyboardFocus (true);
  38514. colourChanged();
  38515. }
  38516. ListBox::~ListBox()
  38517. {
  38518. deleteAllChildren();
  38519. }
  38520. void ListBox::setModel (ListBoxModel* const newModel)
  38521. {
  38522. if (model != newModel)
  38523. {
  38524. model = newModel;
  38525. updateContent();
  38526. }
  38527. }
  38528. void ListBox::setMultipleSelectionEnabled (bool b)
  38529. {
  38530. multipleSelection = b;
  38531. }
  38532. void ListBox::setMouseMoveSelectsRows (bool b)
  38533. {
  38534. mouseMoveSelects = b;
  38535. if (b)
  38536. addMouseListener (this, true);
  38537. }
  38538. void ListBox::paint (Graphics& g)
  38539. {
  38540. if (! hasDoneInitialUpdate)
  38541. updateContent();
  38542. g.fillAll (findColour (backgroundColourId));
  38543. }
  38544. void ListBox::paintOverChildren (Graphics& g)
  38545. {
  38546. if (outlineThickness > 0)
  38547. {
  38548. g.setColour (findColour (outlineColourId));
  38549. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38550. }
  38551. }
  38552. void ListBox::resized()
  38553. {
  38554. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38555. outlineThickness,
  38556. outlineThickness,
  38557. outlineThickness));
  38558. viewport->setSingleStepSizes (20, getRowHeight());
  38559. viewport->updateVisibleArea (false);
  38560. }
  38561. void ListBox::visibilityChanged()
  38562. {
  38563. viewport->updateVisibleArea (true);
  38564. }
  38565. Viewport* ListBox::getViewport() const throw()
  38566. {
  38567. return viewport;
  38568. }
  38569. void ListBox::updateContent()
  38570. {
  38571. hasDoneInitialUpdate = true;
  38572. totalItems = (model != 0) ? model->getNumRows() : 0;
  38573. bool selectionChanged = false;
  38574. if (selected [selected.size() - 1] >= totalItems)
  38575. {
  38576. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38577. lastRowSelected = getSelectedRow (0);
  38578. selectionChanged = true;
  38579. }
  38580. viewport->updateVisibleArea (isVisible());
  38581. viewport->resized();
  38582. if (selectionChanged && model != 0)
  38583. model->selectedRowsChanged (lastRowSelected);
  38584. }
  38585. void ListBox::selectRow (const int row,
  38586. bool dontScroll,
  38587. bool deselectOthersFirst)
  38588. {
  38589. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38590. }
  38591. void ListBox::selectRowInternal (const int row,
  38592. bool dontScroll,
  38593. bool deselectOthersFirst,
  38594. bool isMouseClick)
  38595. {
  38596. if (! multipleSelection)
  38597. deselectOthersFirst = true;
  38598. if ((! isRowSelected (row))
  38599. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38600. {
  38601. if (((unsigned int) row) < (unsigned int) totalItems)
  38602. {
  38603. if (deselectOthersFirst)
  38604. selected.clear();
  38605. selected.addRange (row, 1);
  38606. if (getHeight() == 0 || getWidth() == 0)
  38607. dontScroll = true;
  38608. viewport->hasUpdated = false;
  38609. if (row < viewport->firstWholeIndex && ! dontScroll)
  38610. {
  38611. viewport->setViewPosition (viewport->getViewPositionX(),
  38612. row * getRowHeight());
  38613. }
  38614. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38615. {
  38616. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38617. if (row >= lastRowSelected + rowsOnScreen
  38618. && rowsOnScreen < totalItems - 1
  38619. && ! isMouseClick)
  38620. {
  38621. viewport->setViewPosition (viewport->getViewPositionX(),
  38622. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38623. * getRowHeight());
  38624. }
  38625. else
  38626. {
  38627. viewport->setViewPosition (viewport->getViewPositionX(),
  38628. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38629. }
  38630. }
  38631. if (! viewport->hasUpdated)
  38632. viewport->updateContents();
  38633. lastRowSelected = row;
  38634. model->selectedRowsChanged (row);
  38635. }
  38636. else
  38637. {
  38638. if (deselectOthersFirst)
  38639. deselectAllRows();
  38640. }
  38641. }
  38642. }
  38643. void ListBox::deselectRow (const int row)
  38644. {
  38645. if (selected.contains (row))
  38646. {
  38647. selected.removeRange (row, 1);
  38648. if (row == lastRowSelected)
  38649. lastRowSelected = getSelectedRow (0);
  38650. viewport->updateContents();
  38651. model->selectedRowsChanged (lastRowSelected);
  38652. }
  38653. }
  38654. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38655. const bool sendNotificationEventToModel)
  38656. {
  38657. selected = setOfRowsToBeSelected;
  38658. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38659. if (! isRowSelected (lastRowSelected))
  38660. lastRowSelected = getSelectedRow (0);
  38661. viewport->updateContents();
  38662. if ((model != 0) && sendNotificationEventToModel)
  38663. model->selectedRowsChanged (lastRowSelected);
  38664. }
  38665. const SparseSet<int> ListBox::getSelectedRows() const
  38666. {
  38667. return selected;
  38668. }
  38669. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38670. {
  38671. if (multipleSelection && (firstRow != lastRow))
  38672. {
  38673. const int numRows = totalItems - 1;
  38674. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38675. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38676. selected.addRange (jmin (firstRow, lastRow),
  38677. abs (firstRow - lastRow) + 1);
  38678. selected.removeRange (lastRow, 1);
  38679. }
  38680. selectRowInternal (lastRow, false, false, true);
  38681. }
  38682. void ListBox::flipRowSelection (const int row)
  38683. {
  38684. if (isRowSelected (row))
  38685. deselectRow (row);
  38686. else
  38687. selectRowInternal (row, false, false, true);
  38688. }
  38689. void ListBox::deselectAllRows()
  38690. {
  38691. if (! selected.isEmpty())
  38692. {
  38693. selected.clear();
  38694. lastRowSelected = -1;
  38695. viewport->updateContents();
  38696. if (model != 0)
  38697. model->selectedRowsChanged (lastRowSelected);
  38698. }
  38699. }
  38700. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38701. const ModifierKeys& mods)
  38702. {
  38703. if (multipleSelection && mods.isCommandDown())
  38704. {
  38705. flipRowSelection (row);
  38706. }
  38707. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38708. {
  38709. selectRangeOfRows (lastRowSelected, row);
  38710. }
  38711. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38712. {
  38713. selectRowInternal (row, false, true, true);
  38714. }
  38715. }
  38716. int ListBox::getNumSelectedRows() const
  38717. {
  38718. return selected.size();
  38719. }
  38720. int ListBox::getSelectedRow (const int index) const
  38721. {
  38722. return (((unsigned int) index) < (unsigned int) selected.size())
  38723. ? selected [index] : -1;
  38724. }
  38725. bool ListBox::isRowSelected (const int row) const
  38726. {
  38727. return selected.contains (row);
  38728. }
  38729. int ListBox::getLastRowSelected() const
  38730. {
  38731. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38732. }
  38733. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38734. {
  38735. if (((unsigned int) x) < (unsigned int) getWidth())
  38736. {
  38737. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38738. if (((unsigned int) row) < (unsigned int) totalItems)
  38739. return row;
  38740. }
  38741. return -1;
  38742. }
  38743. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38744. {
  38745. if (((unsigned int) x) < (unsigned int) getWidth())
  38746. {
  38747. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38748. return jlimit (0, totalItems, row);
  38749. }
  38750. return -1;
  38751. }
  38752. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38753. {
  38754. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38755. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38756. }
  38757. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38758. {
  38759. return viewport->getRowNumberOfComponent (rowComponent);
  38760. }
  38761. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38762. const bool relativeToComponentTopLeft) const throw()
  38763. {
  38764. const int rowHeight = getRowHeight();
  38765. int y = viewport->getY() + rowHeight * rowNumber;
  38766. if (relativeToComponentTopLeft)
  38767. y -= viewport->getViewPositionY();
  38768. return Rectangle<int> (viewport->getX(), y,
  38769. viewport->getViewedComponent()->getWidth(), rowHeight);
  38770. }
  38771. void ListBox::setVerticalPosition (const double proportion)
  38772. {
  38773. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38774. viewport->setViewPosition (viewport->getViewPositionX(),
  38775. jmax (0, roundToInt (proportion * offscreen)));
  38776. }
  38777. double ListBox::getVerticalPosition() const
  38778. {
  38779. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38780. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38781. : 0;
  38782. }
  38783. int ListBox::getVisibleRowWidth() const throw()
  38784. {
  38785. return viewport->getViewWidth();
  38786. }
  38787. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38788. {
  38789. if (row < viewport->firstWholeIndex)
  38790. {
  38791. viewport->setViewPosition (viewport->getViewPositionX(),
  38792. row * getRowHeight());
  38793. }
  38794. else if (row >= viewport->lastWholeIndex)
  38795. {
  38796. viewport->setViewPosition (viewport->getViewPositionX(),
  38797. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38798. }
  38799. }
  38800. bool ListBox::keyPressed (const KeyPress& key)
  38801. {
  38802. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38803. const bool multiple = multipleSelection
  38804. && (lastRowSelected >= 0)
  38805. && (key.getModifiers().isShiftDown()
  38806. || key.getModifiers().isCtrlDown()
  38807. || key.getModifiers().isCommandDown());
  38808. if (key.isKeyCode (KeyPress::upKey))
  38809. {
  38810. if (multiple)
  38811. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38812. else
  38813. selectRow (jmax (0, lastRowSelected - 1));
  38814. }
  38815. else if (key.isKeyCode (KeyPress::returnKey)
  38816. && isRowSelected (lastRowSelected))
  38817. {
  38818. if (model != 0)
  38819. model->returnKeyPressed (lastRowSelected);
  38820. }
  38821. else if (key.isKeyCode (KeyPress::pageUpKey))
  38822. {
  38823. if (multiple)
  38824. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38825. else
  38826. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38827. }
  38828. else if (key.isKeyCode (KeyPress::pageDownKey))
  38829. {
  38830. if (multiple)
  38831. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38832. else
  38833. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38834. }
  38835. else if (key.isKeyCode (KeyPress::homeKey))
  38836. {
  38837. if (multiple && key.getModifiers().isShiftDown())
  38838. selectRangeOfRows (lastRowSelected, 0);
  38839. else
  38840. selectRow (0);
  38841. }
  38842. else if (key.isKeyCode (KeyPress::endKey))
  38843. {
  38844. if (multiple && key.getModifiers().isShiftDown())
  38845. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38846. else
  38847. selectRow (totalItems - 1);
  38848. }
  38849. else if (key.isKeyCode (KeyPress::downKey))
  38850. {
  38851. if (multiple)
  38852. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38853. else
  38854. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38855. }
  38856. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38857. && isRowSelected (lastRowSelected))
  38858. {
  38859. if (model != 0)
  38860. model->deleteKeyPressed (lastRowSelected);
  38861. }
  38862. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38863. {
  38864. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38865. }
  38866. else
  38867. {
  38868. return false;
  38869. }
  38870. return true;
  38871. }
  38872. bool ListBox::keyStateChanged (const bool isKeyDown)
  38873. {
  38874. return isKeyDown
  38875. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38876. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38877. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38878. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38879. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38880. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38881. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38882. }
  38883. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38884. {
  38885. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38886. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38887. }
  38888. void ListBox::mouseMove (const MouseEvent& e)
  38889. {
  38890. if (mouseMoveSelects)
  38891. {
  38892. const MouseEvent e2 (e.getEventRelativeTo (this));
  38893. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38894. }
  38895. }
  38896. void ListBox::mouseExit (const MouseEvent& e)
  38897. {
  38898. mouseMove (e);
  38899. }
  38900. void ListBox::mouseUp (const MouseEvent& e)
  38901. {
  38902. if (e.mouseWasClicked() && model != 0)
  38903. model->backgroundClicked();
  38904. }
  38905. void ListBox::setRowHeight (const int newHeight)
  38906. {
  38907. rowHeight = jmax (1, newHeight);
  38908. viewport->setSingleStepSizes (20, rowHeight);
  38909. updateContent();
  38910. }
  38911. int ListBox::getNumRowsOnScreen() const throw()
  38912. {
  38913. return viewport->getMaximumVisibleHeight() / rowHeight;
  38914. }
  38915. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38916. {
  38917. minimumRowWidth = newMinimumWidth;
  38918. updateContent();
  38919. }
  38920. int ListBox::getVisibleContentWidth() const throw()
  38921. {
  38922. return viewport->getMaximumVisibleWidth();
  38923. }
  38924. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38925. {
  38926. return viewport->getVerticalScrollBar();
  38927. }
  38928. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38929. {
  38930. return viewport->getHorizontalScrollBar();
  38931. }
  38932. void ListBox::colourChanged()
  38933. {
  38934. setOpaque (findColour (backgroundColourId).isOpaque());
  38935. viewport->setOpaque (isOpaque());
  38936. repaint();
  38937. }
  38938. void ListBox::setOutlineThickness (const int outlineThickness_)
  38939. {
  38940. outlineThickness = outlineThickness_;
  38941. resized();
  38942. }
  38943. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38944. {
  38945. if (headerComponent != newHeaderComponent)
  38946. {
  38947. delete headerComponent;
  38948. headerComponent = newHeaderComponent;
  38949. addAndMakeVisible (newHeaderComponent);
  38950. ListBox::resized();
  38951. }
  38952. }
  38953. void ListBox::repaintRow (const int rowNumber) throw()
  38954. {
  38955. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38956. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38957. }
  38958. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38959. {
  38960. Rectangle<int> imageArea;
  38961. const int firstRow = getRowContainingPosition (0, 0);
  38962. int i;
  38963. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38964. {
  38965. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38966. if (rowComp != 0 && isRowSelected (firstRow + i))
  38967. {
  38968. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38969. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38970. if (imageArea.isEmpty())
  38971. imageArea = rowRect;
  38972. else
  38973. imageArea = imageArea.getUnion (rowRect);
  38974. }
  38975. }
  38976. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  38977. imageX = imageArea.getX();
  38978. imageY = imageArea.getY();
  38979. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38980. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38981. {
  38982. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38983. if (rowComp != 0 && isRowSelected (firstRow + i))
  38984. {
  38985. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38986. Graphics g (*snapshot);
  38987. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38988. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38989. rowComp->paintEntireComponent (g);
  38990. }
  38991. }
  38992. return snapshot;
  38993. }
  38994. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38995. {
  38996. DragAndDropContainer* const dragContainer
  38997. = DragAndDropContainer::findParentDragContainerFor (this);
  38998. if (dragContainer != 0)
  38999. {
  39000. int x, y;
  39001. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  39002. dragImage->multiplyAllAlphas (0.6f);
  39003. MouseEvent e2 (e.getEventRelativeTo (this));
  39004. const Point<int> p (x - e2.x, y - e2.y);
  39005. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  39006. }
  39007. else
  39008. {
  39009. // to be able to do a drag-and-drop operation, the listbox needs to
  39010. // be inside a component which is also a DragAndDropContainer.
  39011. jassertfalse
  39012. }
  39013. }
  39014. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  39015. {
  39016. (void) existingComponentToUpdate;
  39017. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  39018. return 0;
  39019. }
  39020. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  39021. {
  39022. }
  39023. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  39024. {
  39025. }
  39026. void ListBoxModel::backgroundClicked()
  39027. {
  39028. }
  39029. void ListBoxModel::selectedRowsChanged (int)
  39030. {
  39031. }
  39032. void ListBoxModel::deleteKeyPressed (int)
  39033. {
  39034. }
  39035. void ListBoxModel::returnKeyPressed (int)
  39036. {
  39037. }
  39038. void ListBoxModel::listWasScrolled()
  39039. {
  39040. }
  39041. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  39042. {
  39043. return String::empty;
  39044. }
  39045. const String ListBoxModel::getTooltipForRow (int)
  39046. {
  39047. return String::empty;
  39048. }
  39049. END_JUCE_NAMESPACE
  39050. /*** End of inlined file: juce_ListBox.cpp ***/
  39051. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  39052. BEGIN_JUCE_NAMESPACE
  39053. ProgressBar::ProgressBar (double& progress_)
  39054. : progress (progress_),
  39055. displayPercentage (true),
  39056. lastCallbackTime (0)
  39057. {
  39058. currentValue = jlimit (0.0, 1.0, progress);
  39059. }
  39060. ProgressBar::~ProgressBar()
  39061. {
  39062. }
  39063. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  39064. {
  39065. displayPercentage = shouldDisplayPercentage;
  39066. repaint();
  39067. }
  39068. void ProgressBar::setTextToDisplay (const String& text)
  39069. {
  39070. displayPercentage = false;
  39071. displayedMessage = text;
  39072. }
  39073. void ProgressBar::lookAndFeelChanged()
  39074. {
  39075. setOpaque (findColour (backgroundColourId).isOpaque());
  39076. }
  39077. void ProgressBar::colourChanged()
  39078. {
  39079. lookAndFeelChanged();
  39080. }
  39081. void ProgressBar::paint (Graphics& g)
  39082. {
  39083. String text;
  39084. if (displayPercentage)
  39085. {
  39086. if (currentValue >= 0 && currentValue <= 1.0)
  39087. text << roundToInt (currentValue * 100.0) << T("%");
  39088. }
  39089. else
  39090. {
  39091. text = displayedMessage;
  39092. }
  39093. getLookAndFeel().drawProgressBar (g, *this,
  39094. getWidth(), getHeight(),
  39095. currentValue, text);
  39096. }
  39097. void ProgressBar::visibilityChanged()
  39098. {
  39099. if (isVisible())
  39100. startTimer (30);
  39101. else
  39102. stopTimer();
  39103. }
  39104. void ProgressBar::timerCallback()
  39105. {
  39106. double newProgress = progress;
  39107. const uint32 now = Time::getMillisecondCounter();
  39108. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  39109. lastCallbackTime = now;
  39110. if (currentValue != newProgress
  39111. || newProgress < 0 || newProgress >= 1.0
  39112. || currentMessage != displayedMessage)
  39113. {
  39114. if (currentValue < newProgress
  39115. && newProgress >= 0 && newProgress < 1.0
  39116. && currentValue >= 0 && currentValue < 1.0)
  39117. {
  39118. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  39119. newProgress);
  39120. }
  39121. currentValue = newProgress;
  39122. currentMessage = displayedMessage;
  39123. repaint();
  39124. }
  39125. }
  39126. END_JUCE_NAMESPACE
  39127. /*** End of inlined file: juce_ProgressBar.cpp ***/
  39128. /*** Start of inlined file: juce_Slider.cpp ***/
  39129. BEGIN_JUCE_NAMESPACE
  39130. class SliderPopupDisplayComponent : public BubbleComponent
  39131. {
  39132. public:
  39133. SliderPopupDisplayComponent (Slider* const owner_)
  39134. : owner (owner_),
  39135. font (15.0f, Font::bold)
  39136. {
  39137. setAlwaysOnTop (true);
  39138. }
  39139. ~SliderPopupDisplayComponent()
  39140. {
  39141. }
  39142. void paintContent (Graphics& g, int w, int h)
  39143. {
  39144. g.setFont (font);
  39145. g.setColour (Colours::black);
  39146. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  39147. }
  39148. void getContentSize (int& w, int& h)
  39149. {
  39150. w = font.getStringWidth (text) + 18;
  39151. h = (int) (font.getHeight() * 1.6f);
  39152. }
  39153. void updatePosition (const String& newText)
  39154. {
  39155. if (text != newText)
  39156. {
  39157. text = newText;
  39158. repaint();
  39159. }
  39160. BubbleComponent::setPosition (owner);
  39161. }
  39162. juce_UseDebuggingNewOperator
  39163. private:
  39164. Slider* owner;
  39165. Font font;
  39166. String text;
  39167. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  39168. const SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  39169. };
  39170. Slider::Slider (const String& name)
  39171. : Component (name),
  39172. lastCurrentValue (0),
  39173. lastValueMin (0),
  39174. lastValueMax (0),
  39175. minimum (0),
  39176. maximum (10),
  39177. interval (0),
  39178. skewFactor (1.0),
  39179. velocityModeSensitivity (1.0),
  39180. velocityModeOffset (0.0),
  39181. velocityModeThreshold (1),
  39182. rotaryStart (float_Pi * 1.2f),
  39183. rotaryEnd (float_Pi * 2.8f),
  39184. numDecimalPlaces (7),
  39185. sliderRegionStart (0),
  39186. sliderRegionSize (1),
  39187. sliderBeingDragged (-1),
  39188. pixelsForFullDragExtent (250),
  39189. style (LinearHorizontal),
  39190. textBoxPos (TextBoxLeft),
  39191. textBoxWidth (80),
  39192. textBoxHeight (20),
  39193. incDecButtonMode (incDecButtonsNotDraggable),
  39194. editableText (true),
  39195. doubleClickToValue (false),
  39196. isVelocityBased (false),
  39197. userKeyOverridesVelocity (true),
  39198. rotaryStop (true),
  39199. incDecButtonsSideBySide (false),
  39200. sendChangeOnlyOnRelease (false),
  39201. popupDisplayEnabled (false),
  39202. menuEnabled (false),
  39203. menuShown (false),
  39204. scrollWheelEnabled (true),
  39205. snapsToMousePos (true),
  39206. valueBox (0),
  39207. incButton (0),
  39208. decButton (0),
  39209. popupDisplay (0),
  39210. parentForPopupDisplay (0)
  39211. {
  39212. setWantsKeyboardFocus (false);
  39213. setRepaintsOnMouseActivity (true);
  39214. lookAndFeelChanged();
  39215. updateText();
  39216. currentValue.addListener (this);
  39217. valueMin.addListener (this);
  39218. valueMax.addListener (this);
  39219. }
  39220. Slider::~Slider()
  39221. {
  39222. currentValue.removeListener (this);
  39223. valueMin.removeListener (this);
  39224. valueMax.removeListener (this);
  39225. popupDisplay = 0;
  39226. deleteAllChildren();
  39227. }
  39228. void Slider::handleAsyncUpdate()
  39229. {
  39230. cancelPendingUpdate();
  39231. for (int i = listeners.size(); --i >= 0;)
  39232. {
  39233. ((SliderListener*) listeners.getUnchecked (i))->sliderValueChanged (this);
  39234. i = jmin (i, listeners.size());
  39235. }
  39236. }
  39237. void Slider::sendDragStart()
  39238. {
  39239. startedDragging();
  39240. for (int i = listeners.size(); --i >= 0;)
  39241. {
  39242. ((SliderListener*) listeners.getUnchecked (i))->sliderDragStarted (this);
  39243. i = jmin (i, listeners.size());
  39244. }
  39245. }
  39246. void Slider::sendDragEnd()
  39247. {
  39248. stoppedDragging();
  39249. sliderBeingDragged = -1;
  39250. for (int i = listeners.size(); --i >= 0;)
  39251. {
  39252. ((SliderListener*) listeners.getUnchecked (i))->sliderDragEnded (this);
  39253. i = jmin (i, listeners.size());
  39254. }
  39255. }
  39256. void Slider::addListener (SliderListener* const listener)
  39257. {
  39258. jassert (listener != 0);
  39259. if (listener != 0)
  39260. listeners.add (listener);
  39261. }
  39262. void Slider::removeListener (SliderListener* const listener)
  39263. {
  39264. listeners.removeValue (listener);
  39265. }
  39266. void Slider::setSliderStyle (const SliderStyle newStyle)
  39267. {
  39268. if (style != newStyle)
  39269. {
  39270. style = newStyle;
  39271. repaint();
  39272. lookAndFeelChanged();
  39273. }
  39274. }
  39275. void Slider::setRotaryParameters (const float startAngleRadians,
  39276. const float endAngleRadians,
  39277. const bool stopAtEnd)
  39278. {
  39279. // make sure the values are sensible..
  39280. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  39281. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  39282. jassert (rotaryStart < rotaryEnd);
  39283. rotaryStart = startAngleRadians;
  39284. rotaryEnd = endAngleRadians;
  39285. rotaryStop = stopAtEnd;
  39286. }
  39287. void Slider::setVelocityBasedMode (const bool velBased)
  39288. {
  39289. isVelocityBased = velBased;
  39290. }
  39291. void Slider::setVelocityModeParameters (const double sensitivity,
  39292. const int threshold,
  39293. const double offset,
  39294. const bool userCanPressKeyToSwapMode)
  39295. {
  39296. jassert (threshold >= 0);
  39297. jassert (sensitivity > 0);
  39298. jassert (offset >= 0);
  39299. velocityModeSensitivity = sensitivity;
  39300. velocityModeOffset = offset;
  39301. velocityModeThreshold = threshold;
  39302. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  39303. }
  39304. void Slider::setSkewFactor (const double factor)
  39305. {
  39306. skewFactor = factor;
  39307. }
  39308. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  39309. {
  39310. if (maximum > minimum)
  39311. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  39312. / (maximum - minimum));
  39313. }
  39314. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  39315. {
  39316. jassert (distanceForFullScaleDrag > 0);
  39317. pixelsForFullDragExtent = distanceForFullScaleDrag;
  39318. }
  39319. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  39320. {
  39321. if (incDecButtonMode != mode)
  39322. {
  39323. incDecButtonMode = mode;
  39324. lookAndFeelChanged();
  39325. }
  39326. }
  39327. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  39328. const bool isReadOnly,
  39329. const int textEntryBoxWidth,
  39330. const int textEntryBoxHeight)
  39331. {
  39332. textBoxPos = newPosition;
  39333. editableText = ! isReadOnly;
  39334. textBoxWidth = textEntryBoxWidth;
  39335. textBoxHeight = textEntryBoxHeight;
  39336. repaint();
  39337. lookAndFeelChanged();
  39338. }
  39339. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  39340. {
  39341. editableText = shouldBeEditable;
  39342. if (valueBox != 0)
  39343. valueBox->setEditable (shouldBeEditable && isEnabled());
  39344. }
  39345. void Slider::showTextBox()
  39346. {
  39347. jassert (editableText); // this should probably be avoided in read-only sliders.
  39348. if (valueBox != 0)
  39349. valueBox->showEditor();
  39350. }
  39351. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  39352. {
  39353. if (valueBox != 0)
  39354. {
  39355. valueBox->hideEditor (discardCurrentEditorContents);
  39356. if (discardCurrentEditorContents)
  39357. updateText();
  39358. }
  39359. }
  39360. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  39361. {
  39362. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  39363. }
  39364. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  39365. {
  39366. snapsToMousePos = shouldSnapToMouse;
  39367. }
  39368. void Slider::setPopupDisplayEnabled (const bool enabled,
  39369. Component* const parentComponentToUse)
  39370. {
  39371. popupDisplayEnabled = enabled;
  39372. parentForPopupDisplay = parentComponentToUse;
  39373. }
  39374. void Slider::colourChanged()
  39375. {
  39376. lookAndFeelChanged();
  39377. }
  39378. void Slider::lookAndFeelChanged()
  39379. {
  39380. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  39381. : getTextFromValue (currentValue.getValue()));
  39382. deleteAllChildren();
  39383. valueBox = 0;
  39384. LookAndFeel& lf = getLookAndFeel();
  39385. if (textBoxPos != NoTextBox)
  39386. {
  39387. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  39388. valueBox->setWantsKeyboardFocus (false);
  39389. valueBox->setText (previousTextBoxContent, false);
  39390. valueBox->setEditable (editableText && isEnabled());
  39391. valueBox->addListener (this);
  39392. if (style == LinearBar)
  39393. valueBox->addMouseListener (this, false);
  39394. valueBox->setTooltip (getTooltip());
  39395. }
  39396. if (style == IncDecButtons)
  39397. {
  39398. addAndMakeVisible (incButton = lf.createSliderButton (true));
  39399. incButton->addButtonListener (this);
  39400. addAndMakeVisible (decButton = lf.createSliderButton (false));
  39401. decButton->addButtonListener (this);
  39402. if (incDecButtonMode != incDecButtonsNotDraggable)
  39403. {
  39404. incButton->addMouseListener (this, false);
  39405. decButton->addMouseListener (this, false);
  39406. }
  39407. else
  39408. {
  39409. incButton->setRepeatSpeed (300, 100, 20);
  39410. incButton->addMouseListener (decButton, false);
  39411. decButton->setRepeatSpeed (300, 100, 20);
  39412. decButton->addMouseListener (incButton, false);
  39413. }
  39414. incButton->setTooltip (getTooltip());
  39415. decButton->setTooltip (getTooltip());
  39416. }
  39417. setComponentEffect (lf.getSliderEffect());
  39418. resized();
  39419. repaint();
  39420. }
  39421. void Slider::setRange (const double newMin,
  39422. const double newMax,
  39423. const double newInt)
  39424. {
  39425. if (minimum != newMin
  39426. || maximum != newMax
  39427. || interval != newInt)
  39428. {
  39429. minimum = newMin;
  39430. maximum = newMax;
  39431. interval = newInt;
  39432. // figure out the number of DPs needed to display all values at this
  39433. // interval setting.
  39434. numDecimalPlaces = 7;
  39435. if (newInt != 0)
  39436. {
  39437. int v = abs ((int) (newInt * 10000000));
  39438. while ((v % 10) == 0)
  39439. {
  39440. --numDecimalPlaces;
  39441. v /= 10;
  39442. }
  39443. }
  39444. // keep the current values inside the new range..
  39445. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39446. {
  39447. setValue (getValue(), false, false);
  39448. }
  39449. else
  39450. {
  39451. setMinValue (getMinValue(), false, false);
  39452. setMaxValue (getMaxValue(), false, false);
  39453. }
  39454. updateText();
  39455. }
  39456. }
  39457. void Slider::triggerChangeMessage (const bool synchronous)
  39458. {
  39459. if (synchronous)
  39460. handleAsyncUpdate();
  39461. else
  39462. triggerAsyncUpdate();
  39463. valueChanged();
  39464. }
  39465. void Slider::valueChanged (Value& value)
  39466. {
  39467. if (value.refersToSameSourceAs (currentValue))
  39468. {
  39469. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39470. setValue (currentValue.getValue(), false, false);
  39471. }
  39472. else if (value.refersToSameSourceAs (valueMin))
  39473. setMinValue (valueMin.getValue(), false, false, true);
  39474. else if (value.refersToSameSourceAs (valueMax))
  39475. setMaxValue (valueMax.getValue(), false, false, true);
  39476. }
  39477. double Slider::getValue() const
  39478. {
  39479. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39480. // methods to get the two values.
  39481. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39482. return currentValue.getValue();
  39483. }
  39484. void Slider::setValue (double newValue,
  39485. const bool sendUpdateMessage,
  39486. const bool sendMessageSynchronously)
  39487. {
  39488. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39489. // methods to set the two values.
  39490. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39491. newValue = constrainedValue (newValue);
  39492. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39493. {
  39494. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39495. newValue = jlimit ((double) valueMin.getValue(),
  39496. (double) valueMax.getValue(),
  39497. newValue);
  39498. }
  39499. if (newValue != lastCurrentValue)
  39500. {
  39501. if (valueBox != 0)
  39502. valueBox->hideEditor (true);
  39503. lastCurrentValue = newValue;
  39504. currentValue = newValue;
  39505. updateText();
  39506. repaint();
  39507. if (popupDisplay != 0)
  39508. {
  39509. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39510. popupDisplay->repaint();
  39511. }
  39512. if (sendUpdateMessage)
  39513. triggerChangeMessage (sendMessageSynchronously);
  39514. }
  39515. }
  39516. double Slider::getMinValue() const
  39517. {
  39518. // The minimum value only applies to sliders that are in two- or three-value mode.
  39519. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39520. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39521. return valueMin.getValue();
  39522. }
  39523. double Slider::getMaxValue() const
  39524. {
  39525. // The maximum value only applies to sliders that are in two- or three-value mode.
  39526. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39527. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39528. return valueMax.getValue();
  39529. }
  39530. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39531. {
  39532. // The minimum value only applies to sliders that are in two- or three-value mode.
  39533. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39534. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39535. newValue = constrainedValue (newValue);
  39536. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39537. {
  39538. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39539. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39540. newValue = jmin ((double) valueMax.getValue(), newValue);
  39541. }
  39542. else
  39543. {
  39544. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39545. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39546. newValue = jmin (lastCurrentValue, newValue);
  39547. }
  39548. if (lastValueMin != newValue)
  39549. {
  39550. lastValueMin = newValue;
  39551. valueMin = newValue;
  39552. repaint();
  39553. if (popupDisplay != 0)
  39554. {
  39555. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39556. popupDisplay->repaint();
  39557. }
  39558. if (sendUpdateMessage)
  39559. triggerChangeMessage (sendMessageSynchronously);
  39560. }
  39561. }
  39562. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39563. {
  39564. // The maximum value only applies to sliders that are in two- or three-value mode.
  39565. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39566. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39567. newValue = constrainedValue (newValue);
  39568. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39569. {
  39570. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39571. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39572. newValue = jmax ((double) valueMin.getValue(), newValue);
  39573. }
  39574. else
  39575. {
  39576. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39577. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39578. newValue = jmax (lastCurrentValue, newValue);
  39579. }
  39580. if (lastValueMax != newValue)
  39581. {
  39582. lastValueMax = newValue;
  39583. valueMax = newValue;
  39584. repaint();
  39585. if (popupDisplay != 0)
  39586. {
  39587. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (valueMax.getValue()));
  39588. popupDisplay->repaint();
  39589. }
  39590. if (sendUpdateMessage)
  39591. triggerChangeMessage (sendMessageSynchronously);
  39592. }
  39593. }
  39594. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39595. const double valueToSetOnDoubleClick)
  39596. {
  39597. doubleClickToValue = isDoubleClickEnabled;
  39598. doubleClickReturnValue = valueToSetOnDoubleClick;
  39599. }
  39600. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39601. {
  39602. isEnabled_ = doubleClickToValue;
  39603. return doubleClickReturnValue;
  39604. }
  39605. void Slider::updateText()
  39606. {
  39607. if (valueBox != 0)
  39608. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39609. }
  39610. void Slider::setTextValueSuffix (const String& suffix)
  39611. {
  39612. if (textSuffix != suffix)
  39613. {
  39614. textSuffix = suffix;
  39615. updateText();
  39616. }
  39617. }
  39618. const String Slider::getTextFromValue (double v)
  39619. {
  39620. if (numDecimalPlaces > 0)
  39621. return String (v, numDecimalPlaces) + textSuffix;
  39622. else
  39623. return String (roundToInt (v)) + textSuffix;
  39624. }
  39625. double Slider::getValueFromText (const String& text)
  39626. {
  39627. String t (text.trimStart());
  39628. if (t.endsWith (textSuffix))
  39629. t = t.substring (0, t.length() - textSuffix.length());
  39630. while (t.startsWithChar (T('+')))
  39631. t = t.substring (1).trimStart();
  39632. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39633. .getDoubleValue();
  39634. }
  39635. double Slider::proportionOfLengthToValue (double proportion)
  39636. {
  39637. if (skewFactor != 1.0 && proportion > 0.0)
  39638. proportion = exp (log (proportion) / skewFactor);
  39639. return minimum + (maximum - minimum) * proportion;
  39640. }
  39641. double Slider::valueToProportionOfLength (double value)
  39642. {
  39643. const double n = (value - minimum) / (maximum - minimum);
  39644. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39645. }
  39646. double Slider::snapValue (double attemptedValue, const bool)
  39647. {
  39648. return attemptedValue;
  39649. }
  39650. void Slider::startedDragging()
  39651. {
  39652. }
  39653. void Slider::stoppedDragging()
  39654. {
  39655. }
  39656. void Slider::valueChanged()
  39657. {
  39658. }
  39659. void Slider::enablementChanged()
  39660. {
  39661. repaint();
  39662. }
  39663. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39664. {
  39665. menuEnabled = menuEnabled_;
  39666. }
  39667. void Slider::setScrollWheelEnabled (const bool enabled)
  39668. {
  39669. scrollWheelEnabled = enabled;
  39670. }
  39671. void Slider::labelTextChanged (Label* label)
  39672. {
  39673. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39674. if (newValue != (double) currentValue.getValue())
  39675. {
  39676. sendDragStart();
  39677. setValue (newValue, true, true);
  39678. sendDragEnd();
  39679. }
  39680. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39681. }
  39682. void Slider::buttonClicked (Button* button)
  39683. {
  39684. if (style == IncDecButtons)
  39685. {
  39686. sendDragStart();
  39687. if (button == incButton)
  39688. setValue (snapValue (getValue() + interval, false), true, true);
  39689. else if (button == decButton)
  39690. setValue (snapValue (getValue() - interval, false), true, true);
  39691. sendDragEnd();
  39692. }
  39693. }
  39694. double Slider::constrainedValue (double value) const
  39695. {
  39696. if (interval > 0)
  39697. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39698. if (value <= minimum || maximum <= minimum)
  39699. value = minimum;
  39700. else if (value >= maximum)
  39701. value = maximum;
  39702. return value;
  39703. }
  39704. float Slider::getLinearSliderPos (const double value)
  39705. {
  39706. double sliderPosProportional;
  39707. if (maximum > minimum)
  39708. {
  39709. if (value < minimum)
  39710. {
  39711. sliderPosProportional = 0.0;
  39712. }
  39713. else if (value > maximum)
  39714. {
  39715. sliderPosProportional = 1.0;
  39716. }
  39717. else
  39718. {
  39719. sliderPosProportional = valueToProportionOfLength (value);
  39720. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39721. }
  39722. }
  39723. else
  39724. {
  39725. sliderPosProportional = 0.5;
  39726. }
  39727. if (isVertical() || style == IncDecButtons)
  39728. sliderPosProportional = 1.0 - sliderPosProportional;
  39729. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39730. }
  39731. bool Slider::isHorizontal() const
  39732. {
  39733. return style == LinearHorizontal
  39734. || style == LinearBar
  39735. || style == TwoValueHorizontal
  39736. || style == ThreeValueHorizontal;
  39737. }
  39738. bool Slider::isVertical() const
  39739. {
  39740. return style == LinearVertical
  39741. || style == TwoValueVertical
  39742. || style == ThreeValueVertical;
  39743. }
  39744. bool Slider::incDecDragDirectionIsHorizontal() const
  39745. {
  39746. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39747. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39748. }
  39749. float Slider::getPositionOfValue (const double value)
  39750. {
  39751. if (isHorizontal() || isVertical())
  39752. {
  39753. return getLinearSliderPos (value);
  39754. }
  39755. else
  39756. {
  39757. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39758. return 0.0f;
  39759. }
  39760. }
  39761. void Slider::paint (Graphics& g)
  39762. {
  39763. if (style != IncDecButtons)
  39764. {
  39765. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39766. {
  39767. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39768. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39769. getLookAndFeel().drawRotarySlider (g,
  39770. sliderRect.getX(),
  39771. sliderRect.getY(),
  39772. sliderRect.getWidth(),
  39773. sliderRect.getHeight(),
  39774. sliderPos,
  39775. rotaryStart, rotaryEnd,
  39776. *this);
  39777. }
  39778. else
  39779. {
  39780. getLookAndFeel().drawLinearSlider (g,
  39781. sliderRect.getX(),
  39782. sliderRect.getY(),
  39783. sliderRect.getWidth(),
  39784. sliderRect.getHeight(),
  39785. getLinearSliderPos (lastCurrentValue),
  39786. getLinearSliderPos (lastValueMin),
  39787. getLinearSliderPos (lastValueMax),
  39788. style,
  39789. *this);
  39790. }
  39791. if (style == LinearBar && valueBox == 0)
  39792. {
  39793. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39794. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39795. }
  39796. }
  39797. }
  39798. void Slider::resized()
  39799. {
  39800. int minXSpace = 0;
  39801. int minYSpace = 0;
  39802. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39803. minXSpace = 30;
  39804. else
  39805. minYSpace = 15;
  39806. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39807. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39808. if (style == LinearBar)
  39809. {
  39810. if (valueBox != 0)
  39811. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39812. }
  39813. else
  39814. {
  39815. if (textBoxPos == NoTextBox)
  39816. {
  39817. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39818. }
  39819. else if (textBoxPos == TextBoxLeft)
  39820. {
  39821. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39822. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39823. }
  39824. else if (textBoxPos == TextBoxRight)
  39825. {
  39826. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39827. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39828. }
  39829. else if (textBoxPos == TextBoxAbove)
  39830. {
  39831. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39832. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39833. }
  39834. else if (textBoxPos == TextBoxBelow)
  39835. {
  39836. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39837. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39838. }
  39839. }
  39840. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39841. if (style == LinearBar)
  39842. {
  39843. const int barIndent = 1;
  39844. sliderRegionStart = barIndent;
  39845. sliderRegionSize = getWidth() - barIndent * 2;
  39846. sliderRect.setBounds (sliderRegionStart, barIndent,
  39847. sliderRegionSize, getHeight() - barIndent * 2);
  39848. }
  39849. else if (isHorizontal())
  39850. {
  39851. sliderRegionStart = sliderRect.getX() + indent;
  39852. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39853. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39854. sliderRegionSize, sliderRect.getHeight());
  39855. }
  39856. else if (isVertical())
  39857. {
  39858. sliderRegionStart = sliderRect.getY() + indent;
  39859. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39860. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39861. sliderRect.getWidth(), sliderRegionSize);
  39862. }
  39863. else
  39864. {
  39865. sliderRegionStart = 0;
  39866. sliderRegionSize = 100;
  39867. }
  39868. if (style == IncDecButtons)
  39869. {
  39870. Rectangle<int> buttonRect (sliderRect);
  39871. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39872. buttonRect.expand (-2, 0);
  39873. else
  39874. buttonRect.expand (0, -2);
  39875. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39876. if (incDecButtonsSideBySide)
  39877. {
  39878. decButton->setBounds (buttonRect.getX(),
  39879. buttonRect.getY(),
  39880. buttonRect.getWidth() / 2,
  39881. buttonRect.getHeight());
  39882. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39883. incButton->setBounds (buttonRect.getCentreX(),
  39884. buttonRect.getY(),
  39885. buttonRect.getWidth() / 2,
  39886. buttonRect.getHeight());
  39887. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39888. }
  39889. else
  39890. {
  39891. incButton->setBounds (buttonRect.getX(),
  39892. buttonRect.getY(),
  39893. buttonRect.getWidth(),
  39894. buttonRect.getHeight() / 2);
  39895. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39896. decButton->setBounds (buttonRect.getX(),
  39897. buttonRect.getCentreY(),
  39898. buttonRect.getWidth(),
  39899. buttonRect.getHeight() / 2);
  39900. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39901. }
  39902. }
  39903. }
  39904. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39905. {
  39906. repaint();
  39907. }
  39908. void Slider::mouseDown (const MouseEvent& e)
  39909. {
  39910. mouseWasHidden = false;
  39911. incDecDragged = false;
  39912. mouseXWhenLastDragged = e.x;
  39913. mouseYWhenLastDragged = e.y;
  39914. mouseDragStartX = e.getMouseDownX();
  39915. mouseDragStartY = e.getMouseDownY();
  39916. if (isEnabled())
  39917. {
  39918. if (e.mods.isPopupMenu() && menuEnabled)
  39919. {
  39920. menuShown = true;
  39921. PopupMenu m;
  39922. m.setLookAndFeel (&getLookAndFeel());
  39923. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39924. m.addSeparator();
  39925. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39926. {
  39927. PopupMenu rotaryMenu;
  39928. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39929. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39930. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39931. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39932. }
  39933. const int r = m.show();
  39934. if (r == 1)
  39935. {
  39936. setVelocityBasedMode (! isVelocityBased);
  39937. }
  39938. else if (r == 2)
  39939. {
  39940. setSliderStyle (Rotary);
  39941. }
  39942. else if (r == 3)
  39943. {
  39944. setSliderStyle (RotaryHorizontalDrag);
  39945. }
  39946. else if (r == 4)
  39947. {
  39948. setSliderStyle (RotaryVerticalDrag);
  39949. }
  39950. }
  39951. else if (maximum > minimum)
  39952. {
  39953. menuShown = false;
  39954. if (valueBox != 0)
  39955. valueBox->hideEditor (true);
  39956. sliderBeingDragged = 0;
  39957. if (style == TwoValueHorizontal
  39958. || style == TwoValueVertical
  39959. || style == ThreeValueHorizontal
  39960. || style == ThreeValueVertical)
  39961. {
  39962. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39963. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39964. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39965. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39966. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39967. {
  39968. if (maxPosDistance <= minPosDistance)
  39969. sliderBeingDragged = 2;
  39970. else
  39971. sliderBeingDragged = 1;
  39972. }
  39973. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39974. {
  39975. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39976. sliderBeingDragged = 1;
  39977. else if (normalPosDistance >= maxPosDistance)
  39978. sliderBeingDragged = 2;
  39979. }
  39980. }
  39981. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39982. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39983. * valueToProportionOfLength (currentValue.getValue());
  39984. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39985. : ((sliderBeingDragged == 1) ? valueMin
  39986. : currentValue)).getValue();
  39987. valueOnMouseDown = valueWhenLastDragged;
  39988. if (popupDisplayEnabled)
  39989. {
  39990. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39991. popupDisplay = popup;
  39992. if (parentForPopupDisplay != 0)
  39993. {
  39994. parentForPopupDisplay->addChildComponent (popup);
  39995. }
  39996. else
  39997. {
  39998. popup->addToDesktop (0);
  39999. }
  40000. popup->setVisible (true);
  40001. }
  40002. sendDragStart();
  40003. mouseDrag (e);
  40004. }
  40005. }
  40006. }
  40007. void Slider::mouseUp (const MouseEvent&)
  40008. {
  40009. if (isEnabled()
  40010. && (! menuShown)
  40011. && (maximum > minimum)
  40012. && (style != IncDecButtons || incDecDragged))
  40013. {
  40014. restoreMouseIfHidden();
  40015. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  40016. triggerChangeMessage (false);
  40017. sendDragEnd();
  40018. popupDisplay = 0;
  40019. if (style == IncDecButtons)
  40020. {
  40021. incButton->setState (Button::buttonNormal);
  40022. decButton->setState (Button::buttonNormal);
  40023. }
  40024. }
  40025. }
  40026. void Slider::restoreMouseIfHidden()
  40027. {
  40028. if (mouseWasHidden)
  40029. {
  40030. mouseWasHidden = false;
  40031. Component* c = Component::getComponentUnderMouse();
  40032. if (c == 0)
  40033. c = this;
  40034. c->enableUnboundedMouseMovement (false);
  40035. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  40036. : ((sliderBeingDragged == 1) ? getMinValue()
  40037. : (double) currentValue.getValue());
  40038. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  40039. {
  40040. Point<int> mousePos (Desktop::getMousePosition());
  40041. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  40042. if (style == RotaryHorizontalDrag)
  40043. {
  40044. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  40045. mousePos = Point<int> (roundToInt (pixelsForFullDragExtent * posDiff + lastMouseDown.getX()),
  40046. lastMouseDown.getY());
  40047. }
  40048. else
  40049. {
  40050. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  40051. mousePos = Point<int> (lastMouseDown.getX(),
  40052. roundToInt (pixelsForFullDragExtent * posDiff + lastMouseDown.getY()));
  40053. }
  40054. Desktop::setMousePosition (mousePos);
  40055. }
  40056. else
  40057. {
  40058. const int pixelPos = (int) getLinearSliderPos (pos);
  40059. const Point<int> pos (isHorizontal() ? pixelPos : (getWidth() / 2),
  40060. isVertical() ? pixelPos : (getHeight() / 2));
  40061. Desktop::setMousePosition (relativePositionToGlobal (pos));
  40062. }
  40063. }
  40064. }
  40065. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  40066. {
  40067. if (isEnabled()
  40068. && style != IncDecButtons
  40069. && style != Rotary
  40070. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  40071. {
  40072. restoreMouseIfHidden();
  40073. }
  40074. }
  40075. static double smallestAngleBetween (double a1, double a2)
  40076. {
  40077. return jmin (fabs (a1 - a2),
  40078. fabs (a1 + double_Pi * 2.0 - a2),
  40079. fabs (a2 + double_Pi * 2.0 - a1));
  40080. }
  40081. void Slider::mouseDrag (const MouseEvent& e)
  40082. {
  40083. if (isEnabled()
  40084. && (! menuShown)
  40085. && (maximum > minimum))
  40086. {
  40087. if (style == Rotary)
  40088. {
  40089. int dx = e.x - sliderRect.getCentreX();
  40090. int dy = e.y - sliderRect.getCentreY();
  40091. if (dx * dx + dy * dy > 25)
  40092. {
  40093. double angle = atan2 ((double) dx, (double) -dy);
  40094. while (angle < 0.0)
  40095. angle += double_Pi * 2.0;
  40096. if (rotaryStop && ! e.mouseWasClicked())
  40097. {
  40098. if (fabs (angle - lastAngle) > double_Pi)
  40099. {
  40100. if (angle >= lastAngle)
  40101. angle -= double_Pi * 2.0;
  40102. else
  40103. angle += double_Pi * 2.0;
  40104. }
  40105. if (angle >= lastAngle)
  40106. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  40107. else
  40108. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  40109. }
  40110. else
  40111. {
  40112. while (angle < rotaryStart)
  40113. angle += double_Pi * 2.0;
  40114. if (angle > rotaryEnd)
  40115. {
  40116. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  40117. angle = rotaryStart;
  40118. else
  40119. angle = rotaryEnd;
  40120. }
  40121. }
  40122. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  40123. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  40124. lastAngle = angle;
  40125. }
  40126. }
  40127. else
  40128. {
  40129. if (style == LinearBar && e.mouseWasClicked()
  40130. && valueBox != 0 && valueBox->isEditable())
  40131. return;
  40132. if (style == IncDecButtons && ! incDecDragged)
  40133. {
  40134. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  40135. return;
  40136. incDecDragged = true;
  40137. mouseDragStartX = e.x;
  40138. mouseDragStartY = e.y;
  40139. }
  40140. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  40141. : false))
  40142. || ((maximum - minimum) / sliderRegionSize < interval))
  40143. {
  40144. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  40145. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  40146. if (style == RotaryHorizontalDrag
  40147. || style == RotaryVerticalDrag
  40148. || style == IncDecButtons
  40149. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  40150. && ! snapsToMousePos))
  40151. {
  40152. const int mouseDiff = (style == RotaryHorizontalDrag
  40153. || style == LinearHorizontal
  40154. || style == LinearBar
  40155. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40156. ? e.x - mouseDragStartX
  40157. : mouseDragStartY - e.y;
  40158. double newPos = valueToProportionOfLength (valueOnMouseDown)
  40159. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  40160. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  40161. if (style == IncDecButtons)
  40162. {
  40163. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  40164. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  40165. }
  40166. }
  40167. else
  40168. {
  40169. if (isVertical())
  40170. scaledMousePos = 1.0 - scaledMousePos;
  40171. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  40172. }
  40173. }
  40174. else
  40175. {
  40176. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  40177. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40178. ? e.x - mouseXWhenLastDragged
  40179. : e.y - mouseYWhenLastDragged;
  40180. const double maxSpeed = jmax (200, sliderRegionSize);
  40181. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  40182. if (speed != 0)
  40183. {
  40184. speed = 0.2 * velocityModeSensitivity
  40185. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  40186. + jmax (0.0, (double) (speed - velocityModeThreshold))
  40187. / maxSpeed))));
  40188. if (mouseDiff < 0)
  40189. speed = -speed;
  40190. if (isVertical() || style == RotaryVerticalDrag
  40191. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  40192. speed = -speed;
  40193. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  40194. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  40195. e.originalComponent->enableUnboundedMouseMovement (true, false);
  40196. mouseWasHidden = true;
  40197. }
  40198. }
  40199. }
  40200. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  40201. if (sliderBeingDragged == 0)
  40202. {
  40203. setValue (snapValue (valueWhenLastDragged, true),
  40204. ! sendChangeOnlyOnRelease, true);
  40205. }
  40206. else if (sliderBeingDragged == 1)
  40207. {
  40208. setMinValue (snapValue (valueWhenLastDragged, true),
  40209. ! sendChangeOnlyOnRelease, false, true);
  40210. if (e.mods.isShiftDown())
  40211. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  40212. else
  40213. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40214. }
  40215. else
  40216. {
  40217. jassert (sliderBeingDragged == 2);
  40218. setMaxValue (snapValue (valueWhenLastDragged, true),
  40219. ! sendChangeOnlyOnRelease, false, true);
  40220. if (e.mods.isShiftDown())
  40221. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  40222. else
  40223. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40224. }
  40225. mouseXWhenLastDragged = e.x;
  40226. mouseYWhenLastDragged = e.y;
  40227. }
  40228. }
  40229. void Slider::mouseDoubleClick (const MouseEvent&)
  40230. {
  40231. if (doubleClickToValue
  40232. && isEnabled()
  40233. && style != IncDecButtons
  40234. && minimum <= doubleClickReturnValue
  40235. && maximum >= doubleClickReturnValue)
  40236. {
  40237. sendDragStart();
  40238. setValue (doubleClickReturnValue, true, true);
  40239. sendDragEnd();
  40240. }
  40241. }
  40242. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  40243. {
  40244. if (scrollWheelEnabled && isEnabled()
  40245. && style != TwoValueHorizontal
  40246. && style != TwoValueVertical)
  40247. {
  40248. if (maximum > minimum && ! isMouseButtonDownAnywhere())
  40249. {
  40250. if (valueBox != 0)
  40251. valueBox->hideEditor (false);
  40252. const double value = (double) currentValue.getValue();
  40253. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  40254. const double currentPos = valueToProportionOfLength (value);
  40255. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  40256. double delta = (newValue != value)
  40257. ? jmax (fabs (newValue - value), interval) : 0;
  40258. if (value > newValue)
  40259. delta = -delta;
  40260. sendDragStart();
  40261. setValue (snapValue (value + delta, false), true, true);
  40262. sendDragEnd();
  40263. }
  40264. }
  40265. else
  40266. {
  40267. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  40268. }
  40269. }
  40270. void SliderListener::sliderDragStarted (Slider*)
  40271. {
  40272. }
  40273. void SliderListener::sliderDragEnded (Slider*)
  40274. {
  40275. }
  40276. END_JUCE_NAMESPACE
  40277. /*** End of inlined file: juce_Slider.cpp ***/
  40278. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  40279. BEGIN_JUCE_NAMESPACE
  40280. class DragOverlayComp : public Component
  40281. {
  40282. public:
  40283. DragOverlayComp (Image* const image_)
  40284. : image (image_)
  40285. {
  40286. image->multiplyAllAlphas (0.8f);
  40287. setAlwaysOnTop (true);
  40288. }
  40289. ~DragOverlayComp()
  40290. {
  40291. }
  40292. void paint (Graphics& g)
  40293. {
  40294. g.drawImageAt (image, 0, 0);
  40295. }
  40296. private:
  40297. ScopedPointer <Image> image;
  40298. DragOverlayComp (const DragOverlayComp&);
  40299. const DragOverlayComp& operator= (const DragOverlayComp&);
  40300. };
  40301. TableHeaderComponent::TableHeaderComponent()
  40302. : columnsChanged (false),
  40303. columnsResized (false),
  40304. sortChanged (false),
  40305. menuActive (true),
  40306. stretchToFit (false),
  40307. columnIdBeingResized (0),
  40308. columnIdBeingDragged (0),
  40309. columnIdUnderMouse (0),
  40310. lastDeliberateWidth (0)
  40311. {
  40312. }
  40313. TableHeaderComponent::~TableHeaderComponent()
  40314. {
  40315. dragOverlayComp = 0;
  40316. }
  40317. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  40318. {
  40319. menuActive = hasMenu;
  40320. }
  40321. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  40322. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  40323. {
  40324. if (onlyCountVisibleColumns)
  40325. {
  40326. int num = 0;
  40327. for (int i = columns.size(); --i >= 0;)
  40328. if (columns.getUnchecked(i)->isVisible())
  40329. ++num;
  40330. return num;
  40331. }
  40332. else
  40333. {
  40334. return columns.size();
  40335. }
  40336. }
  40337. const String TableHeaderComponent::getColumnName (const int columnId) const
  40338. {
  40339. const ColumnInfo* const ci = getInfoForId (columnId);
  40340. return ci != 0 ? ci->name : String::empty;
  40341. }
  40342. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  40343. {
  40344. ColumnInfo* const ci = getInfoForId (columnId);
  40345. if (ci != 0 && ci->name != newName)
  40346. {
  40347. ci->name = newName;
  40348. sendColumnsChanged();
  40349. }
  40350. }
  40351. void TableHeaderComponent::addColumn (const String& columnName,
  40352. const int columnId,
  40353. const int width,
  40354. const int minimumWidth,
  40355. const int maximumWidth,
  40356. const int propertyFlags,
  40357. const int insertIndex)
  40358. {
  40359. // can't have a duplicate or null ID!
  40360. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  40361. jassert (width > 0);
  40362. ColumnInfo* const ci = new ColumnInfo();
  40363. ci->name = columnName;
  40364. ci->id = columnId;
  40365. ci->width = width;
  40366. ci->lastDeliberateWidth = width;
  40367. ci->minimumWidth = minimumWidth;
  40368. ci->maximumWidth = maximumWidth;
  40369. if (ci->maximumWidth < 0)
  40370. ci->maximumWidth = std::numeric_limits<int>::max();
  40371. jassert (ci->maximumWidth >= ci->minimumWidth);
  40372. ci->propertyFlags = propertyFlags;
  40373. columns.insert (insertIndex, ci);
  40374. sendColumnsChanged();
  40375. }
  40376. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  40377. {
  40378. const int index = getIndexOfColumnId (columnIdToRemove, false);
  40379. if (index >= 0)
  40380. {
  40381. columns.remove (index);
  40382. sortChanged = true;
  40383. sendColumnsChanged();
  40384. }
  40385. }
  40386. void TableHeaderComponent::removeAllColumns()
  40387. {
  40388. if (columns.size() > 0)
  40389. {
  40390. columns.clear();
  40391. sendColumnsChanged();
  40392. }
  40393. }
  40394. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  40395. {
  40396. const int currentIndex = getIndexOfColumnId (columnId, false);
  40397. newIndex = visibleIndexToTotalIndex (newIndex);
  40398. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  40399. {
  40400. columns.move (currentIndex, newIndex);
  40401. sendColumnsChanged();
  40402. }
  40403. }
  40404. int TableHeaderComponent::getColumnWidth (const int columnId) const
  40405. {
  40406. const ColumnInfo* const ci = getInfoForId (columnId);
  40407. return ci != 0 ? ci->width : 0;
  40408. }
  40409. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  40410. {
  40411. ColumnInfo* const ci = getInfoForId (columnId);
  40412. if (ci != 0 && ci->width != newWidth)
  40413. {
  40414. const int numColumns = getNumColumns (true);
  40415. ci->lastDeliberateWidth = ci->width
  40416. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40417. if (stretchToFit)
  40418. {
  40419. const int index = getIndexOfColumnId (columnId, true) + 1;
  40420. if (((unsigned int) index) < (unsigned int) numColumns)
  40421. {
  40422. const int x = getColumnPosition (index).getX();
  40423. if (lastDeliberateWidth == 0)
  40424. lastDeliberateWidth = getTotalWidth();
  40425. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40426. }
  40427. }
  40428. repaint();
  40429. columnsResized = true;
  40430. triggerAsyncUpdate();
  40431. }
  40432. }
  40433. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40434. {
  40435. int n = 0;
  40436. for (int i = 0; i < columns.size(); ++i)
  40437. {
  40438. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40439. {
  40440. if (columns.getUnchecked(i)->id == columnId)
  40441. return n;
  40442. ++n;
  40443. }
  40444. }
  40445. return -1;
  40446. }
  40447. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40448. {
  40449. if (onlyCountVisibleColumns)
  40450. index = visibleIndexToTotalIndex (index);
  40451. const ColumnInfo* const ci = columns [index];
  40452. return (ci != 0) ? ci->id : 0;
  40453. }
  40454. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  40455. {
  40456. int x = 0, width = 0, n = 0;
  40457. for (int i = 0; i < columns.size(); ++i)
  40458. {
  40459. x += width;
  40460. if (columns.getUnchecked(i)->isVisible())
  40461. {
  40462. width = columns.getUnchecked(i)->width;
  40463. if (n++ == index)
  40464. break;
  40465. }
  40466. else
  40467. {
  40468. width = 0;
  40469. }
  40470. }
  40471. return Rectangle<int> (x, 0, width, getHeight());
  40472. }
  40473. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40474. {
  40475. if (xToFind >= 0)
  40476. {
  40477. int x = 0;
  40478. for (int i = 0; i < columns.size(); ++i)
  40479. {
  40480. const ColumnInfo* const ci = columns.getUnchecked(i);
  40481. if (ci->isVisible())
  40482. {
  40483. x += ci->width;
  40484. if (xToFind < x)
  40485. return ci->id;
  40486. }
  40487. }
  40488. }
  40489. return 0;
  40490. }
  40491. int TableHeaderComponent::getTotalWidth() const
  40492. {
  40493. int w = 0;
  40494. for (int i = columns.size(); --i >= 0;)
  40495. if (columns.getUnchecked(i)->isVisible())
  40496. w += columns.getUnchecked(i)->width;
  40497. return w;
  40498. }
  40499. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40500. {
  40501. stretchToFit = shouldStretchToFit;
  40502. lastDeliberateWidth = getTotalWidth();
  40503. resized();
  40504. }
  40505. bool TableHeaderComponent::isStretchToFitActive() const
  40506. {
  40507. return stretchToFit;
  40508. }
  40509. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40510. {
  40511. if (stretchToFit && getWidth() > 0
  40512. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40513. {
  40514. lastDeliberateWidth = targetTotalWidth;
  40515. resizeColumnsToFit (0, targetTotalWidth);
  40516. }
  40517. }
  40518. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40519. {
  40520. targetTotalWidth = jmax (targetTotalWidth, 0);
  40521. StretchableObjectResizer sor;
  40522. int i;
  40523. for (i = firstColumnIndex; i < columns.size(); ++i)
  40524. {
  40525. ColumnInfo* const ci = columns.getUnchecked(i);
  40526. if (ci->isVisible())
  40527. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40528. }
  40529. sor.resizeToFit (targetTotalWidth);
  40530. int visIndex = 0;
  40531. for (i = firstColumnIndex; i < columns.size(); ++i)
  40532. {
  40533. ColumnInfo* const ci = columns.getUnchecked(i);
  40534. if (ci->isVisible())
  40535. {
  40536. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40537. (int) floor (sor.getItemSize (visIndex++)));
  40538. if (newWidth != ci->width)
  40539. {
  40540. ci->width = newWidth;
  40541. repaint();
  40542. columnsResized = true;
  40543. triggerAsyncUpdate();
  40544. }
  40545. }
  40546. }
  40547. }
  40548. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40549. {
  40550. ColumnInfo* const ci = getInfoForId (columnId);
  40551. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40552. {
  40553. if (shouldBeVisible)
  40554. ci->propertyFlags |= visible;
  40555. else
  40556. ci->propertyFlags &= ~visible;
  40557. sendColumnsChanged();
  40558. resized();
  40559. }
  40560. }
  40561. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40562. {
  40563. const ColumnInfo* const ci = getInfoForId (columnId);
  40564. return ci != 0 && ci->isVisible();
  40565. }
  40566. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40567. {
  40568. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40569. {
  40570. for (int i = columns.size(); --i >= 0;)
  40571. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40572. ColumnInfo* const ci = getInfoForId (columnId);
  40573. if (ci != 0)
  40574. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40575. reSortTable();
  40576. }
  40577. }
  40578. int TableHeaderComponent::getSortColumnId() const
  40579. {
  40580. for (int i = columns.size(); --i >= 0;)
  40581. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40582. return columns.getUnchecked(i)->id;
  40583. return 0;
  40584. }
  40585. bool TableHeaderComponent::isSortedForwards() const
  40586. {
  40587. for (int i = columns.size(); --i >= 0;)
  40588. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40589. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40590. return true;
  40591. }
  40592. void TableHeaderComponent::reSortTable()
  40593. {
  40594. sortChanged = true;
  40595. repaint();
  40596. triggerAsyncUpdate();
  40597. }
  40598. const String TableHeaderComponent::toString() const
  40599. {
  40600. String s;
  40601. XmlElement doc ("TABLELAYOUT");
  40602. doc.setAttribute ("sortedCol", getSortColumnId());
  40603. doc.setAttribute ("sortForwards", isSortedForwards());
  40604. for (int i = 0; i < columns.size(); ++i)
  40605. {
  40606. const ColumnInfo* const ci = columns.getUnchecked (i);
  40607. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40608. e->setAttribute ("id", ci->id);
  40609. e->setAttribute ("visible", ci->isVisible());
  40610. e->setAttribute ("width", ci->width);
  40611. }
  40612. return doc.createDocument (String::empty, true, false);
  40613. }
  40614. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40615. {
  40616. XmlDocument doc (storedVersion);
  40617. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40618. int index = 0;
  40619. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40620. {
  40621. forEachXmlChildElement (*storedXml, col)
  40622. {
  40623. const int tabId = col->getIntAttribute ("id");
  40624. ColumnInfo* const ci = getInfoForId (tabId);
  40625. if (ci != 0)
  40626. {
  40627. columns.move (columns.indexOf (ci), index);
  40628. ci->width = col->getIntAttribute ("width");
  40629. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40630. }
  40631. ++index;
  40632. }
  40633. columnsResized = true;
  40634. sendColumnsChanged();
  40635. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40636. storedXml->getBoolAttribute ("sortForwards", true));
  40637. }
  40638. }
  40639. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40640. {
  40641. listeners.addIfNotAlreadyThere (newListener);
  40642. }
  40643. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40644. {
  40645. listeners.removeValue (listenerToRemove);
  40646. }
  40647. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40648. {
  40649. const ColumnInfo* const ci = getInfoForId (columnId);
  40650. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40651. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40652. }
  40653. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40654. {
  40655. for (int i = 0; i < columns.size(); ++i)
  40656. {
  40657. const ColumnInfo* const ci = columns.getUnchecked(i);
  40658. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40659. menu.addItem (ci->id, ci->name,
  40660. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40661. isColumnVisible (ci->id));
  40662. }
  40663. }
  40664. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40665. {
  40666. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40667. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40668. }
  40669. void TableHeaderComponent::paint (Graphics& g)
  40670. {
  40671. LookAndFeel& lf = getLookAndFeel();
  40672. lf.drawTableHeaderBackground (g, *this);
  40673. const Rectangle<int> clip (g.getClipBounds());
  40674. int x = 0;
  40675. for (int i = 0; i < columns.size(); ++i)
  40676. {
  40677. const ColumnInfo* const ci = columns.getUnchecked(i);
  40678. if (ci->isVisible())
  40679. {
  40680. if (x + ci->width > clip.getX()
  40681. && (ci->id != columnIdBeingDragged
  40682. || dragOverlayComp == 0
  40683. || ! dragOverlayComp->isVisible()))
  40684. {
  40685. g.saveState();
  40686. g.setOrigin (x, 0);
  40687. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40688. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40689. ci->id == columnIdUnderMouse,
  40690. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40691. ci->propertyFlags);
  40692. g.restoreState();
  40693. }
  40694. x += ci->width;
  40695. if (x >= clip.getRight())
  40696. break;
  40697. }
  40698. }
  40699. }
  40700. void TableHeaderComponent::resized()
  40701. {
  40702. }
  40703. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40704. {
  40705. updateColumnUnderMouse (e.x, e.y);
  40706. }
  40707. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40708. {
  40709. updateColumnUnderMouse (e.x, e.y);
  40710. }
  40711. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40712. {
  40713. updateColumnUnderMouse (e.x, e.y);
  40714. }
  40715. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40716. {
  40717. repaint();
  40718. columnIdBeingResized = 0;
  40719. columnIdBeingDragged = 0;
  40720. if (columnIdUnderMouse != 0)
  40721. {
  40722. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40723. if (e.mods.isPopupMenu())
  40724. columnClicked (columnIdUnderMouse, e.mods);
  40725. }
  40726. if (menuActive && e.mods.isPopupMenu())
  40727. showColumnChooserMenu (columnIdUnderMouse);
  40728. }
  40729. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40730. {
  40731. if (columnIdBeingResized == 0
  40732. && columnIdBeingDragged == 0
  40733. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40734. {
  40735. dragOverlayComp = 0;
  40736. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40737. if (columnIdBeingResized != 0)
  40738. {
  40739. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40740. initialColumnWidth = ci->width;
  40741. }
  40742. else
  40743. {
  40744. beginDrag (e);
  40745. }
  40746. }
  40747. if (columnIdBeingResized != 0)
  40748. {
  40749. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40750. if (ci != 0)
  40751. {
  40752. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40753. initialColumnWidth + e.getDistanceFromDragStartX());
  40754. if (stretchToFit)
  40755. {
  40756. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40757. int minWidthOnRight = 0;
  40758. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40759. if (columns.getUnchecked (i)->isVisible())
  40760. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40761. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40762. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40763. }
  40764. setColumnWidth (columnIdBeingResized, w);
  40765. }
  40766. }
  40767. else if (columnIdBeingDragged != 0)
  40768. {
  40769. if (e.y >= -50 && e.y < getHeight() + 50)
  40770. {
  40771. if (dragOverlayComp != 0)
  40772. {
  40773. dragOverlayComp->setVisible (true);
  40774. dragOverlayComp->setBounds (jlimit (0,
  40775. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40776. e.x - draggingColumnOffset),
  40777. 0,
  40778. dragOverlayComp->getWidth(),
  40779. getHeight());
  40780. for (int i = columns.size(); --i >= 0;)
  40781. {
  40782. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40783. int newIndex = currentIndex;
  40784. if (newIndex > 0)
  40785. {
  40786. // if the previous column isn't draggable, we can't move our column
  40787. // past it, because that'd change the undraggable column's position..
  40788. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40789. if ((previous->propertyFlags & draggable) != 0)
  40790. {
  40791. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40792. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40793. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40794. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40795. {
  40796. --newIndex;
  40797. }
  40798. }
  40799. }
  40800. if (newIndex < columns.size() - 1)
  40801. {
  40802. // if the next column isn't draggable, we can't move our column
  40803. // past it, because that'd change the undraggable column's position..
  40804. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40805. if ((nextCol->propertyFlags & draggable) != 0)
  40806. {
  40807. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40808. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40809. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40810. > abs (dragOverlayComp->getRight() - rightOfNext))
  40811. {
  40812. ++newIndex;
  40813. }
  40814. }
  40815. }
  40816. if (newIndex != currentIndex)
  40817. moveColumn (columnIdBeingDragged, newIndex);
  40818. else
  40819. break;
  40820. }
  40821. }
  40822. }
  40823. else
  40824. {
  40825. endDrag (draggingColumnOriginalIndex);
  40826. }
  40827. }
  40828. }
  40829. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40830. {
  40831. if (columnIdBeingDragged == 0)
  40832. {
  40833. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40834. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40835. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40836. {
  40837. columnIdBeingDragged = 0;
  40838. }
  40839. else
  40840. {
  40841. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40842. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40843. const int temp = columnIdBeingDragged;
  40844. columnIdBeingDragged = 0;
  40845. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40846. columnIdBeingDragged = temp;
  40847. dragOverlayComp->setBounds (columnRect);
  40848. for (int i = listeners.size(); --i >= 0;)
  40849. {
  40850. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40851. i = jmin (i, listeners.size() - 1);
  40852. }
  40853. }
  40854. }
  40855. }
  40856. void TableHeaderComponent::endDrag (const int finalIndex)
  40857. {
  40858. if (columnIdBeingDragged != 0)
  40859. {
  40860. moveColumn (columnIdBeingDragged, finalIndex);
  40861. columnIdBeingDragged = 0;
  40862. repaint();
  40863. for (int i = listeners.size(); --i >= 0;)
  40864. {
  40865. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40866. i = jmin (i, listeners.size() - 1);
  40867. }
  40868. }
  40869. }
  40870. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40871. {
  40872. mouseDrag (e);
  40873. for (int i = columns.size(); --i >= 0;)
  40874. if (columns.getUnchecked (i)->isVisible())
  40875. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40876. columnIdBeingResized = 0;
  40877. repaint();
  40878. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40879. updateColumnUnderMouse (e.x, e.y);
  40880. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40881. columnClicked (columnIdUnderMouse, e.mods);
  40882. dragOverlayComp = 0;
  40883. }
  40884. const MouseCursor TableHeaderComponent::getMouseCursor()
  40885. {
  40886. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40887. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40888. return Component::getMouseCursor();
  40889. }
  40890. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40891. {
  40892. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40893. }
  40894. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40895. {
  40896. for (int i = columns.size(); --i >= 0;)
  40897. if (columns.getUnchecked(i)->id == id)
  40898. return columns.getUnchecked(i);
  40899. return 0;
  40900. }
  40901. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40902. {
  40903. int n = 0;
  40904. for (int i = 0; i < columns.size(); ++i)
  40905. {
  40906. if (columns.getUnchecked(i)->isVisible())
  40907. {
  40908. if (n == visibleIndex)
  40909. return i;
  40910. ++n;
  40911. }
  40912. }
  40913. return -1;
  40914. }
  40915. void TableHeaderComponent::sendColumnsChanged()
  40916. {
  40917. if (stretchToFit && lastDeliberateWidth > 0)
  40918. resizeAllColumnsToFit (lastDeliberateWidth);
  40919. repaint();
  40920. columnsChanged = true;
  40921. triggerAsyncUpdate();
  40922. }
  40923. void TableHeaderComponent::handleAsyncUpdate()
  40924. {
  40925. const bool changed = columnsChanged || sortChanged;
  40926. const bool sized = columnsResized || changed;
  40927. const bool sorted = sortChanged;
  40928. columnsChanged = false;
  40929. columnsResized = false;
  40930. sortChanged = false;
  40931. if (sorted)
  40932. {
  40933. for (int i = listeners.size(); --i >= 0;)
  40934. {
  40935. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40936. i = jmin (i, listeners.size() - 1);
  40937. }
  40938. }
  40939. if (changed)
  40940. {
  40941. for (int i = listeners.size(); --i >= 0;)
  40942. {
  40943. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40944. i = jmin (i, listeners.size() - 1);
  40945. }
  40946. }
  40947. if (sized)
  40948. {
  40949. for (int i = listeners.size(); --i >= 0;)
  40950. {
  40951. listeners.getUnchecked(i)->tableColumnsResized (this);
  40952. i = jmin (i, listeners.size() - 1);
  40953. }
  40954. }
  40955. }
  40956. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40957. {
  40958. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40959. {
  40960. const int draggableDistance = 3;
  40961. int x = 0;
  40962. for (int i = 0; i < columns.size(); ++i)
  40963. {
  40964. const ColumnInfo* const ci = columns.getUnchecked(i);
  40965. if (ci->isVisible())
  40966. {
  40967. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40968. && (ci->propertyFlags & resizable) != 0)
  40969. return ci->id;
  40970. x += ci->width;
  40971. }
  40972. }
  40973. }
  40974. return 0;
  40975. }
  40976. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40977. {
  40978. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40979. ? getColumnIdAtX (x) : 0;
  40980. if (newCol != columnIdUnderMouse)
  40981. {
  40982. columnIdUnderMouse = newCol;
  40983. repaint();
  40984. }
  40985. }
  40986. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40987. {
  40988. PopupMenu m;
  40989. addMenuItems (m, columnIdClicked);
  40990. if (m.getNumItems() > 0)
  40991. {
  40992. m.setLookAndFeel (&getLookAndFeel());
  40993. const int result = m.show();
  40994. if (result != 0)
  40995. reactToMenuItem (result, columnIdClicked);
  40996. }
  40997. }
  40998. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40999. {
  41000. }
  41001. END_JUCE_NAMESPACE
  41002. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  41003. /*** Start of inlined file: juce_TableListBox.cpp ***/
  41004. BEGIN_JUCE_NAMESPACE
  41005. static const char* const tableColumnPropertyTag = "_tableColumnID";
  41006. class TableListRowComp : public Component,
  41007. public TooltipClient
  41008. {
  41009. public:
  41010. TableListRowComp (TableListBox& owner_)
  41011. : owner (owner_),
  41012. row (-1),
  41013. isSelected (false)
  41014. {
  41015. }
  41016. ~TableListRowComp()
  41017. {
  41018. deleteAllChildren();
  41019. }
  41020. void paint (Graphics& g)
  41021. {
  41022. TableListBoxModel* const model = owner.getModel();
  41023. if (model != 0)
  41024. {
  41025. const TableHeaderComponent* const header = owner.getHeader();
  41026. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  41027. const int numColumns = header->getNumColumns (true);
  41028. for (int i = 0; i < numColumns; ++i)
  41029. {
  41030. if (! columnsWithComponents [i])
  41031. {
  41032. const int columnId = header->getColumnIdOfIndex (i, true);
  41033. Rectangle<int> columnRect (header->getColumnPosition (i));
  41034. columnRect.setSize (columnRect.getWidth(), getHeight());
  41035. g.saveState();
  41036. g.reduceClipRegion (columnRect);
  41037. g.setOrigin (columnRect.getX(), 0);
  41038. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  41039. g.restoreState();
  41040. }
  41041. }
  41042. }
  41043. }
  41044. void update (const int newRow, const bool isNowSelected)
  41045. {
  41046. if (newRow != row || isNowSelected != isSelected)
  41047. {
  41048. row = newRow;
  41049. isSelected = isNowSelected;
  41050. repaint();
  41051. }
  41052. if (row < owner.getNumRows())
  41053. {
  41054. jassert (row >= 0);
  41055. const var::identifier tagPropertyName ("_tableLastUseNum");
  41056. const int newTag = Random::getSystemRandom().nextInt();
  41057. const TableHeaderComponent* const header = owner.getHeader();
  41058. const int numColumns = header->getNumColumns (true);
  41059. int i;
  41060. columnsWithComponents.clear();
  41061. if (owner.getModel() != 0)
  41062. {
  41063. for (i = 0; i < numColumns; ++i)
  41064. {
  41065. const int columnId = header->getColumnIdOfIndex (i, true);
  41066. Component* const newComp
  41067. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  41068. findChildComponentForColumn (columnId));
  41069. if (newComp != 0)
  41070. {
  41071. addAndMakeVisible (newComp);
  41072. newComp->getProperties().set (tagPropertyName, newTag);
  41073. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  41074. const Rectangle<int> columnRect (header->getColumnPosition (i));
  41075. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41076. columnsWithComponents.setBit (i);
  41077. }
  41078. }
  41079. }
  41080. for (i = getNumChildComponents(); --i >= 0;)
  41081. {
  41082. Component* const c = getChildComponent (i);
  41083. if ((int) c->getProperties() [tagPropertyName] != newTag)
  41084. delete c;
  41085. }
  41086. }
  41087. else
  41088. {
  41089. columnsWithComponents.clear();
  41090. deleteAllChildren();
  41091. }
  41092. }
  41093. void resized()
  41094. {
  41095. for (int i = getNumChildComponents(); --i >= 0;)
  41096. {
  41097. Component* const c = getChildComponent (i);
  41098. const int columnId = c->getProperties() [tableColumnPropertyTag];
  41099. if (columnId != 0)
  41100. {
  41101. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  41102. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41103. }
  41104. }
  41105. }
  41106. void mouseDown (const MouseEvent& e)
  41107. {
  41108. isDragging = false;
  41109. selectRowOnMouseUp = false;
  41110. if (isEnabled())
  41111. {
  41112. if (! isSelected)
  41113. {
  41114. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41115. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41116. if (columnId != 0 && owner.getModel() != 0)
  41117. owner.getModel()->cellClicked (row, columnId, e);
  41118. }
  41119. else
  41120. {
  41121. selectRowOnMouseUp = true;
  41122. }
  41123. }
  41124. }
  41125. void mouseDrag (const MouseEvent& e)
  41126. {
  41127. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  41128. {
  41129. const SparseSet <int> selectedRows (owner.getSelectedRows());
  41130. if (selectedRows.size() > 0)
  41131. {
  41132. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  41133. if (dragDescription.isNotEmpty())
  41134. {
  41135. isDragging = true;
  41136. owner.startDragAndDrop (e, dragDescription);
  41137. }
  41138. }
  41139. }
  41140. }
  41141. void mouseUp (const MouseEvent& e)
  41142. {
  41143. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  41144. {
  41145. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41146. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41147. if (columnId != 0 && owner.getModel() != 0)
  41148. owner.getModel()->cellClicked (row, columnId, e);
  41149. }
  41150. }
  41151. void mouseDoubleClick (const MouseEvent& e)
  41152. {
  41153. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41154. if (columnId != 0 && owner.getModel() != 0)
  41155. owner.getModel()->cellDoubleClicked (row, columnId, e);
  41156. }
  41157. const String getTooltip()
  41158. {
  41159. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  41160. if (columnId != 0 && owner.getModel() != 0)
  41161. return owner.getModel()->getCellTooltip (row, columnId);
  41162. return String::empty;
  41163. }
  41164. juce_UseDebuggingNewOperator
  41165. private:
  41166. TableListBox& owner;
  41167. int row;
  41168. bool isSelected, isDragging, selectRowOnMouseUp;
  41169. BitArray columnsWithComponents;
  41170. Component* findChildComponentForColumn (const int columnId) const
  41171. {
  41172. for (int i = getNumChildComponents(); --i >= 0;)
  41173. {
  41174. Component* const c = getChildComponent (i);
  41175. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  41176. return c;
  41177. }
  41178. return 0;
  41179. }
  41180. TableListRowComp (const TableListRowComp&);
  41181. const TableListRowComp& operator= (const TableListRowComp&);
  41182. };
  41183. class TableListBoxHeader : public TableHeaderComponent
  41184. {
  41185. public:
  41186. TableListBoxHeader (TableListBox& owner_)
  41187. : owner (owner_)
  41188. {
  41189. }
  41190. ~TableListBoxHeader()
  41191. {
  41192. }
  41193. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  41194. {
  41195. if (owner.isAutoSizeMenuOptionShown())
  41196. {
  41197. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  41198. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  41199. menu.addSeparator();
  41200. }
  41201. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  41202. }
  41203. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  41204. {
  41205. if (menuReturnId == 0xf836743)
  41206. {
  41207. owner.autoSizeColumn (columnIdClicked);
  41208. }
  41209. else if (menuReturnId == 0xf836744)
  41210. {
  41211. owner.autoSizeAllColumns();
  41212. }
  41213. else
  41214. {
  41215. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  41216. }
  41217. }
  41218. juce_UseDebuggingNewOperator
  41219. private:
  41220. TableListBox& owner;
  41221. TableListBoxHeader (const TableListBoxHeader&);
  41222. const TableListBoxHeader& operator= (const TableListBoxHeader&);
  41223. };
  41224. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  41225. : ListBox (name, 0),
  41226. model (model_),
  41227. autoSizeOptionsShown (true)
  41228. {
  41229. ListBox::model = this;
  41230. header = new TableListBoxHeader (*this);
  41231. header->setSize (100, 28);
  41232. header->addListener (this);
  41233. setHeaderComponent (header);
  41234. }
  41235. TableListBox::~TableListBox()
  41236. {
  41237. deleteAllChildren();
  41238. }
  41239. void TableListBox::setModel (TableListBoxModel* const newModel)
  41240. {
  41241. if (model != newModel)
  41242. {
  41243. model = newModel;
  41244. updateContent();
  41245. }
  41246. }
  41247. int TableListBox::getHeaderHeight() const
  41248. {
  41249. return header->getHeight();
  41250. }
  41251. void TableListBox::setHeaderHeight (const int newHeight)
  41252. {
  41253. header->setSize (header->getWidth(), newHeight);
  41254. resized();
  41255. }
  41256. void TableListBox::autoSizeColumn (const int columnId)
  41257. {
  41258. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  41259. if (width > 0)
  41260. header->setColumnWidth (columnId, width);
  41261. }
  41262. void TableListBox::autoSizeAllColumns()
  41263. {
  41264. for (int i = 0; i < header->getNumColumns (true); ++i)
  41265. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  41266. }
  41267. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  41268. {
  41269. autoSizeOptionsShown = shouldBeShown;
  41270. }
  41271. bool TableListBox::isAutoSizeMenuOptionShown() const
  41272. {
  41273. return autoSizeOptionsShown;
  41274. }
  41275. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  41276. const int rowNumber,
  41277. const bool relativeToComponentTopLeft) const
  41278. {
  41279. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41280. if (relativeToComponentTopLeft)
  41281. headerCell.translate (header->getX(), 0);
  41282. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  41283. return Rectangle<int> (headerCell.getX(), row.getY(),
  41284. headerCell.getWidth(), row.getHeight());
  41285. }
  41286. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  41287. {
  41288. ScrollBar* const scrollbar = getHorizontalScrollBar();
  41289. if (scrollbar != 0)
  41290. {
  41291. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41292. double x = scrollbar->getCurrentRangeStart();
  41293. const double w = scrollbar->getCurrentRangeSize();
  41294. if (pos.getX() < x)
  41295. x = pos.getX();
  41296. else if (pos.getRight() > x + w)
  41297. x += jmax (0.0, pos.getRight() - (x + w));
  41298. scrollbar->setCurrentRangeStart (x);
  41299. }
  41300. }
  41301. int TableListBox::getNumRows()
  41302. {
  41303. return model != 0 ? model->getNumRows() : 0;
  41304. }
  41305. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  41306. {
  41307. }
  41308. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  41309. {
  41310. if (existingComponentToUpdate == 0)
  41311. existingComponentToUpdate = new TableListRowComp (*this);
  41312. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  41313. return existingComponentToUpdate;
  41314. }
  41315. void TableListBox::selectedRowsChanged (int row)
  41316. {
  41317. if (model != 0)
  41318. model->selectedRowsChanged (row);
  41319. }
  41320. void TableListBox::deleteKeyPressed (int row)
  41321. {
  41322. if (model != 0)
  41323. model->deleteKeyPressed (row);
  41324. }
  41325. void TableListBox::returnKeyPressed (int row)
  41326. {
  41327. if (model != 0)
  41328. model->returnKeyPressed (row);
  41329. }
  41330. void TableListBox::backgroundClicked()
  41331. {
  41332. if (model != 0)
  41333. model->backgroundClicked();
  41334. }
  41335. void TableListBox::listWasScrolled()
  41336. {
  41337. if (model != 0)
  41338. model->listWasScrolled();
  41339. }
  41340. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  41341. {
  41342. setMinimumContentWidth (header->getTotalWidth());
  41343. repaint();
  41344. updateColumnComponents();
  41345. }
  41346. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  41347. {
  41348. setMinimumContentWidth (header->getTotalWidth());
  41349. repaint();
  41350. updateColumnComponents();
  41351. }
  41352. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  41353. {
  41354. if (model != 0)
  41355. model->sortOrderChanged (header->getSortColumnId(),
  41356. header->isSortedForwards());
  41357. }
  41358. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  41359. {
  41360. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  41361. repaint();
  41362. }
  41363. void TableListBox::resized()
  41364. {
  41365. ListBox::resized();
  41366. header->resizeAllColumnsToFit (getVisibleContentWidth());
  41367. setMinimumContentWidth (header->getTotalWidth());
  41368. }
  41369. void TableListBox::updateColumnComponents() const
  41370. {
  41371. const int firstRow = getRowContainingPosition (0, 0);
  41372. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  41373. {
  41374. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  41375. if (rowComp != 0)
  41376. rowComp->resized();
  41377. }
  41378. }
  41379. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  41380. {
  41381. }
  41382. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  41383. {
  41384. }
  41385. void TableListBoxModel::backgroundClicked()
  41386. {
  41387. }
  41388. void TableListBoxModel::sortOrderChanged (int, const bool)
  41389. {
  41390. }
  41391. int TableListBoxModel::getColumnAutoSizeWidth (int)
  41392. {
  41393. return 0;
  41394. }
  41395. void TableListBoxModel::selectedRowsChanged (int)
  41396. {
  41397. }
  41398. void TableListBoxModel::deleteKeyPressed (int)
  41399. {
  41400. }
  41401. void TableListBoxModel::returnKeyPressed (int)
  41402. {
  41403. }
  41404. void TableListBoxModel::listWasScrolled()
  41405. {
  41406. }
  41407. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  41408. {
  41409. return String::empty;
  41410. }
  41411. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  41412. {
  41413. return String::empty;
  41414. }
  41415. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41416. {
  41417. (void) existingComponentToUpdate;
  41418. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41419. return 0;
  41420. }
  41421. END_JUCE_NAMESPACE
  41422. /*** End of inlined file: juce_TableListBox.cpp ***/
  41423. /*** Start of inlined file: juce_TextEditor.cpp ***/
  41424. BEGIN_JUCE_NAMESPACE
  41425. // a word or space that can't be broken down any further
  41426. struct TextAtom
  41427. {
  41428. String atomText;
  41429. float width;
  41430. uint16 numChars;
  41431. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41432. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41433. const String getText (const tchar passwordCharacter) const
  41434. {
  41435. if (passwordCharacter == 0)
  41436. return atomText;
  41437. else
  41438. return String::repeatedString (String::charToString (passwordCharacter),
  41439. atomText.length());
  41440. }
  41441. const String getTrimmedText (const tchar passwordCharacter) const
  41442. {
  41443. if (passwordCharacter == 0)
  41444. return atomText.substring (0, numChars);
  41445. else if (isNewLine())
  41446. return String::empty;
  41447. else
  41448. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41449. }
  41450. };
  41451. // a run of text with a single font and colour
  41452. class UniformTextSection
  41453. {
  41454. public:
  41455. UniformTextSection (const String& text,
  41456. const Font& font_,
  41457. const Colour& colour_,
  41458. const tchar passwordCharacter)
  41459. : font (font_),
  41460. colour (colour_)
  41461. {
  41462. initialiseAtoms (text, passwordCharacter);
  41463. }
  41464. UniformTextSection (const UniformTextSection& other)
  41465. : font (other.font),
  41466. colour (other.colour)
  41467. {
  41468. atoms.ensureStorageAllocated (other.atoms.size());
  41469. for (int i = 0; i < other.atoms.size(); ++i)
  41470. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41471. }
  41472. ~UniformTextSection()
  41473. {
  41474. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41475. }
  41476. void clear()
  41477. {
  41478. for (int i = atoms.size(); --i >= 0;)
  41479. delete getAtom(i);
  41480. atoms.clear();
  41481. }
  41482. int getNumAtoms() const
  41483. {
  41484. return atoms.size();
  41485. }
  41486. TextAtom* getAtom (const int index) const
  41487. {
  41488. return (TextAtom*) atoms.getUnchecked (index);
  41489. }
  41490. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41491. {
  41492. if (other.atoms.size() > 0)
  41493. {
  41494. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41495. int i = 0;
  41496. if (lastAtom != 0)
  41497. {
  41498. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41499. {
  41500. TextAtom* const first = other.getAtom(0);
  41501. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41502. {
  41503. lastAtom->atomText += first->atomText;
  41504. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41505. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41506. delete first;
  41507. ++i;
  41508. }
  41509. }
  41510. }
  41511. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41512. while (i < other.atoms.size())
  41513. {
  41514. atoms.add (other.getAtom(i));
  41515. ++i;
  41516. }
  41517. }
  41518. }
  41519. UniformTextSection* split (const int indexToBreakAt,
  41520. const tchar passwordCharacter)
  41521. {
  41522. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41523. font, colour,
  41524. passwordCharacter);
  41525. int index = 0;
  41526. for (int i = 0; i < atoms.size(); ++i)
  41527. {
  41528. TextAtom* const atom = getAtom(i);
  41529. const int nextIndex = index + atom->numChars;
  41530. if (index == indexToBreakAt)
  41531. {
  41532. int j;
  41533. for (j = i; j < atoms.size(); ++j)
  41534. section2->atoms.add (getAtom (j));
  41535. for (j = atoms.size(); --j >= i;)
  41536. atoms.remove (j);
  41537. break;
  41538. }
  41539. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41540. {
  41541. TextAtom* const secondAtom = new TextAtom();
  41542. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41543. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41544. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41545. section2->atoms.add (secondAtom);
  41546. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41547. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41548. atom->numChars = (uint16) (indexToBreakAt - index);
  41549. int j;
  41550. for (j = i + 1; j < atoms.size(); ++j)
  41551. section2->atoms.add (getAtom (j));
  41552. for (j = atoms.size(); --j > i;)
  41553. atoms.remove (j);
  41554. break;
  41555. }
  41556. index = nextIndex;
  41557. }
  41558. return section2;
  41559. }
  41560. void appendAllText (String::Concatenator& concatenator) const
  41561. {
  41562. for (int i = 0; i < atoms.size(); ++i)
  41563. concatenator.append (getAtom(i)->atomText);
  41564. }
  41565. void appendSubstring (String::Concatenator& concatenator,
  41566. const Range<int>& range) const
  41567. {
  41568. int index = 0;
  41569. for (int i = 0; i < atoms.size(); ++i)
  41570. {
  41571. const TextAtom* const atom = getAtom (i);
  41572. const int nextIndex = index + atom->numChars;
  41573. if (range.getStart() < nextIndex)
  41574. {
  41575. if (range.getEnd() <= index)
  41576. break;
  41577. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41578. if (! r.isEmpty())
  41579. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41580. }
  41581. index = nextIndex;
  41582. }
  41583. }
  41584. int getTotalLength() const
  41585. {
  41586. int total = 0;
  41587. for (int i = atoms.size(); --i >= 0;)
  41588. total += getAtom(i)->numChars;
  41589. return total;
  41590. }
  41591. void setFont (const Font& newFont,
  41592. const tchar passwordCharacter)
  41593. {
  41594. if (font != newFont)
  41595. {
  41596. font = newFont;
  41597. for (int i = atoms.size(); --i >= 0;)
  41598. {
  41599. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41600. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41601. }
  41602. }
  41603. }
  41604. juce_UseDebuggingNewOperator
  41605. Font font;
  41606. Colour colour;
  41607. private:
  41608. VoidArray atoms;
  41609. void initialiseAtoms (const String& textToParse,
  41610. const tchar passwordCharacter)
  41611. {
  41612. int i = 0;
  41613. const int len = textToParse.length();
  41614. const tchar* const text = (const tchar*) textToParse;
  41615. while (i < len)
  41616. {
  41617. int start = i;
  41618. // create a whitespace atom unless it starts with non-ws
  41619. if (CharacterFunctions::isWhitespace (text[i])
  41620. && text[i] != T('\r')
  41621. && text[i] != T('\n'))
  41622. {
  41623. while (i < len
  41624. && CharacterFunctions::isWhitespace (text[i])
  41625. && text[i] != T('\r')
  41626. && text[i] != T('\n'))
  41627. {
  41628. ++i;
  41629. }
  41630. }
  41631. else
  41632. {
  41633. if (text[i] == T('\r'))
  41634. {
  41635. ++i;
  41636. if ((i < len) && (text[i] == T('\n')))
  41637. {
  41638. ++start;
  41639. ++i;
  41640. }
  41641. }
  41642. else if (text[i] == T('\n'))
  41643. {
  41644. ++i;
  41645. }
  41646. else
  41647. {
  41648. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41649. ++i;
  41650. }
  41651. }
  41652. TextAtom* const atom = new TextAtom();
  41653. atom->atomText = String (text + start, i - start);
  41654. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41655. atom->numChars = (uint16) (i - start);
  41656. atoms.add (atom);
  41657. }
  41658. }
  41659. const UniformTextSection& operator= (const UniformTextSection& other);
  41660. };
  41661. class TextEditorIterator
  41662. {
  41663. public:
  41664. TextEditorIterator (const VoidArray& sections_,
  41665. const float wordWrapWidth_,
  41666. const tchar passwordCharacter_)
  41667. : indexInText (0),
  41668. lineY (0),
  41669. lineHeight (0),
  41670. maxDescent (0),
  41671. atomX (0),
  41672. atomRight (0),
  41673. atom (0),
  41674. currentSection (0),
  41675. sections (sections_),
  41676. sectionIndex (0),
  41677. atomIndex (0),
  41678. wordWrapWidth (wordWrapWidth_),
  41679. passwordCharacter (passwordCharacter_)
  41680. {
  41681. jassert (wordWrapWidth_ > 0);
  41682. if (sections.size() > 0)
  41683. {
  41684. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41685. if (currentSection != 0)
  41686. beginNewLine();
  41687. }
  41688. }
  41689. TextEditorIterator (const TextEditorIterator& other)
  41690. : indexInText (other.indexInText),
  41691. lineY (other.lineY),
  41692. lineHeight (other.lineHeight),
  41693. maxDescent (other.maxDescent),
  41694. atomX (other.atomX),
  41695. atomRight (other.atomRight),
  41696. atom (other.atom),
  41697. currentSection (other.currentSection),
  41698. sections (other.sections),
  41699. sectionIndex (other.sectionIndex),
  41700. atomIndex (other.atomIndex),
  41701. wordWrapWidth (other.wordWrapWidth),
  41702. passwordCharacter (other.passwordCharacter),
  41703. tempAtom (other.tempAtom)
  41704. {
  41705. }
  41706. ~TextEditorIterator()
  41707. {
  41708. }
  41709. bool next()
  41710. {
  41711. if (atom == &tempAtom)
  41712. {
  41713. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41714. if (numRemaining > 0)
  41715. {
  41716. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41717. atomX = 0;
  41718. if (tempAtom.numChars > 0)
  41719. lineY += lineHeight;
  41720. indexInText += tempAtom.numChars;
  41721. GlyphArrangement g;
  41722. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41723. int split;
  41724. for (split = 0; split < g.getNumGlyphs(); ++split)
  41725. if (shouldWrap (g.getGlyph (split).getRight()))
  41726. break;
  41727. if (split > 0 && split <= numRemaining)
  41728. {
  41729. tempAtom.numChars = (uint16) split;
  41730. tempAtom.width = g.getGlyph (split - 1).getRight();
  41731. atomRight = atomX + tempAtom.width;
  41732. return true;
  41733. }
  41734. }
  41735. }
  41736. bool forceNewLine = false;
  41737. if (sectionIndex >= sections.size())
  41738. {
  41739. moveToEndOfLastAtom();
  41740. return false;
  41741. }
  41742. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41743. {
  41744. if (atomIndex >= currentSection->getNumAtoms())
  41745. {
  41746. if (++sectionIndex >= sections.size())
  41747. {
  41748. moveToEndOfLastAtom();
  41749. return false;
  41750. }
  41751. atomIndex = 0;
  41752. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41753. }
  41754. else
  41755. {
  41756. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41757. if (! lastAtom->isWhitespace())
  41758. {
  41759. // handle the case where the last atom in a section is actually part of the same
  41760. // word as the first atom of the next section...
  41761. float right = atomRight + lastAtom->width;
  41762. float lineHeight2 = lineHeight;
  41763. float maxDescent2 = maxDescent;
  41764. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41765. {
  41766. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41767. if (s->getNumAtoms() == 0)
  41768. break;
  41769. const TextAtom* const nextAtom = s->getAtom (0);
  41770. if (nextAtom->isWhitespace())
  41771. break;
  41772. right += nextAtom->width;
  41773. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41774. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41775. if (shouldWrap (right))
  41776. {
  41777. lineHeight = lineHeight2;
  41778. maxDescent = maxDescent2;
  41779. forceNewLine = true;
  41780. break;
  41781. }
  41782. if (s->getNumAtoms() > 1)
  41783. break;
  41784. }
  41785. }
  41786. }
  41787. }
  41788. if (atom != 0)
  41789. {
  41790. atomX = atomRight;
  41791. indexInText += atom->numChars;
  41792. if (atom->isNewLine())
  41793. beginNewLine();
  41794. }
  41795. atom = currentSection->getAtom (atomIndex);
  41796. atomRight = atomX + atom->width;
  41797. ++atomIndex;
  41798. if (shouldWrap (atomRight) || forceNewLine)
  41799. {
  41800. if (atom->isWhitespace())
  41801. {
  41802. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41803. atomRight = jmin (atomRight, wordWrapWidth);
  41804. }
  41805. else
  41806. {
  41807. atomRight = atom->width;
  41808. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41809. {
  41810. tempAtom = *atom;
  41811. tempAtom.width = 0;
  41812. tempAtom.numChars = 0;
  41813. atom = &tempAtom;
  41814. if (atomX > 0)
  41815. beginNewLine();
  41816. return next();
  41817. }
  41818. beginNewLine();
  41819. return true;
  41820. }
  41821. }
  41822. return true;
  41823. }
  41824. void beginNewLine()
  41825. {
  41826. atomX = 0;
  41827. lineY += lineHeight;
  41828. int tempSectionIndex = sectionIndex;
  41829. int tempAtomIndex = atomIndex;
  41830. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41831. lineHeight = section->font.getHeight();
  41832. maxDescent = section->font.getDescent();
  41833. float x = (atom != 0) ? atom->width : 0;
  41834. while (! shouldWrap (x))
  41835. {
  41836. if (tempSectionIndex >= sections.size())
  41837. break;
  41838. bool checkSize = false;
  41839. if (tempAtomIndex >= section->getNumAtoms())
  41840. {
  41841. if (++tempSectionIndex >= sections.size())
  41842. break;
  41843. tempAtomIndex = 0;
  41844. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41845. checkSize = true;
  41846. }
  41847. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41848. if (nextAtom == 0)
  41849. break;
  41850. x += nextAtom->width;
  41851. if (shouldWrap (x) || nextAtom->isNewLine())
  41852. break;
  41853. if (checkSize)
  41854. {
  41855. lineHeight = jmax (lineHeight, section->font.getHeight());
  41856. maxDescent = jmax (maxDescent, section->font.getDescent());
  41857. }
  41858. ++tempAtomIndex;
  41859. }
  41860. }
  41861. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41862. {
  41863. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41864. {
  41865. if (lastSection != currentSection)
  41866. {
  41867. lastSection = currentSection;
  41868. g.setColour (currentSection->colour);
  41869. g.setFont (currentSection->font);
  41870. }
  41871. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41872. GlyphArrangement ga;
  41873. ga.addLineOfText (currentSection->font,
  41874. atom->getTrimmedText (passwordCharacter),
  41875. atomX,
  41876. (float) roundToInt (lineY + lineHeight - maxDescent));
  41877. ga.draw (g);
  41878. }
  41879. }
  41880. void drawSelection (Graphics& g,
  41881. const Range<int>& selection) const
  41882. {
  41883. const int startX = roundToInt (indexToX (selection.getStart()));
  41884. const int endX = roundToInt (indexToX (selection.getEnd()));
  41885. const int y = roundToInt (lineY);
  41886. const int nextY = roundToInt (lineY + lineHeight);
  41887. g.fillRect (startX, y, endX - startX, nextY - y);
  41888. }
  41889. void drawSelectedText (Graphics& g,
  41890. const Range<int>& selection,
  41891. const Colour& selectedTextColour) const
  41892. {
  41893. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41894. {
  41895. GlyphArrangement ga;
  41896. ga.addLineOfText (currentSection->font,
  41897. atom->getTrimmedText (passwordCharacter),
  41898. atomX,
  41899. (float) roundToInt (lineY + lineHeight - maxDescent));
  41900. if (selection.getEnd() < indexInText + atom->numChars)
  41901. {
  41902. GlyphArrangement ga2 (ga);
  41903. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41904. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41905. g.setColour (currentSection->colour);
  41906. ga2.draw (g);
  41907. }
  41908. if (selection.getStart() > indexInText)
  41909. {
  41910. GlyphArrangement ga2 (ga);
  41911. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41912. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41913. g.setColour (currentSection->colour);
  41914. ga2.draw (g);
  41915. }
  41916. g.setColour (selectedTextColour);
  41917. ga.draw (g);
  41918. }
  41919. }
  41920. float indexToX (const int indexToFind) const
  41921. {
  41922. if (indexToFind <= indexInText)
  41923. return atomX;
  41924. if (indexToFind >= indexInText + atom->numChars)
  41925. return atomRight;
  41926. GlyphArrangement g;
  41927. g.addLineOfText (currentSection->font,
  41928. atom->getText (passwordCharacter),
  41929. atomX, 0.0f);
  41930. if (indexToFind - indexInText >= g.getNumGlyphs())
  41931. return atomRight;
  41932. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41933. }
  41934. int xToIndex (const float xToFind) const
  41935. {
  41936. if (xToFind <= atomX || atom->isNewLine())
  41937. return indexInText;
  41938. if (xToFind >= atomRight)
  41939. return indexInText + atom->numChars;
  41940. GlyphArrangement g;
  41941. g.addLineOfText (currentSection->font,
  41942. atom->getText (passwordCharacter),
  41943. atomX, 0.0f);
  41944. int j;
  41945. for (j = 0; j < g.getNumGlyphs(); ++j)
  41946. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41947. break;
  41948. return indexInText + j;
  41949. }
  41950. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41951. {
  41952. while (next())
  41953. {
  41954. if (indexInText + atom->numChars > index)
  41955. {
  41956. cx = indexToX (index);
  41957. cy = lineY;
  41958. lineHeight_ = lineHeight;
  41959. return true;
  41960. }
  41961. }
  41962. cx = atomX;
  41963. cy = lineY;
  41964. lineHeight_ = lineHeight;
  41965. return false;
  41966. }
  41967. juce_UseDebuggingNewOperator
  41968. int indexInText;
  41969. float lineY, lineHeight, maxDescent;
  41970. float atomX, atomRight;
  41971. const TextAtom* atom;
  41972. const UniformTextSection* currentSection;
  41973. private:
  41974. const VoidArray& sections;
  41975. int sectionIndex, atomIndex;
  41976. const float wordWrapWidth;
  41977. const tchar passwordCharacter;
  41978. TextAtom tempAtom;
  41979. const TextEditorIterator& operator= (const TextEditorIterator&);
  41980. void moveToEndOfLastAtom()
  41981. {
  41982. if (atom != 0)
  41983. {
  41984. atomX = atomRight;
  41985. if (atom->isNewLine())
  41986. {
  41987. atomX = 0.0f;
  41988. lineY += lineHeight;
  41989. }
  41990. }
  41991. }
  41992. bool shouldWrap (const float x) const
  41993. {
  41994. return (x - 0.0001f) >= wordWrapWidth;
  41995. }
  41996. };
  41997. class TextEditorInsertAction : public UndoableAction
  41998. {
  41999. TextEditor& owner;
  42000. const String text;
  42001. const int insertIndex, oldCaretPos, newCaretPos;
  42002. const Font font;
  42003. const Colour colour;
  42004. TextEditorInsertAction (const TextEditorInsertAction&);
  42005. const TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  42006. public:
  42007. TextEditorInsertAction (TextEditor& owner_,
  42008. const String& text_,
  42009. const int insertIndex_,
  42010. const Font& font_,
  42011. const Colour& colour_,
  42012. const int oldCaretPos_,
  42013. const int newCaretPos_)
  42014. : owner (owner_),
  42015. text (text_),
  42016. insertIndex (insertIndex_),
  42017. oldCaretPos (oldCaretPos_),
  42018. newCaretPos (newCaretPos_),
  42019. font (font_),
  42020. colour (colour_)
  42021. {
  42022. }
  42023. ~TextEditorInsertAction()
  42024. {
  42025. }
  42026. bool perform()
  42027. {
  42028. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  42029. return true;
  42030. }
  42031. bool undo()
  42032. {
  42033. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  42034. return true;
  42035. }
  42036. int getSizeInUnits()
  42037. {
  42038. return text.length() + 16;
  42039. }
  42040. };
  42041. class TextEditorRemoveAction : public UndoableAction
  42042. {
  42043. TextEditor& owner;
  42044. const Range<int> range;
  42045. const int oldCaretPos, newCaretPos;
  42046. VoidArray removedSections;
  42047. TextEditorRemoveAction (const TextEditorRemoveAction&);
  42048. const TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  42049. public:
  42050. TextEditorRemoveAction (TextEditor& owner_,
  42051. const Range<int> range_,
  42052. const int oldCaretPos_,
  42053. const int newCaretPos_,
  42054. const VoidArray& removedSections_)
  42055. : owner (owner_),
  42056. range (range_),
  42057. oldCaretPos (oldCaretPos_),
  42058. newCaretPos (newCaretPos_),
  42059. removedSections (removedSections_)
  42060. {
  42061. }
  42062. ~TextEditorRemoveAction()
  42063. {
  42064. for (int i = removedSections.size(); --i >= 0;)
  42065. {
  42066. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42067. section->clear();
  42068. delete section;
  42069. }
  42070. }
  42071. bool perform()
  42072. {
  42073. owner.remove (range, 0, newCaretPos);
  42074. return true;
  42075. }
  42076. bool undo()
  42077. {
  42078. owner.reinsert (range.getStart(), removedSections);
  42079. owner.moveCursorTo (oldCaretPos, false);
  42080. return true;
  42081. }
  42082. int getSizeInUnits()
  42083. {
  42084. int n = 0;
  42085. for (int i = removedSections.size(); --i >= 0;)
  42086. {
  42087. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42088. n += section->getTotalLength();
  42089. }
  42090. return n + 16;
  42091. }
  42092. };
  42093. class TextHolderComponent : public Component,
  42094. public Timer,
  42095. public Value::Listener
  42096. {
  42097. TextEditor& owner;
  42098. TextHolderComponent (const TextHolderComponent&);
  42099. const TextHolderComponent& operator= (const TextHolderComponent&);
  42100. public:
  42101. TextHolderComponent (TextEditor& owner_)
  42102. : owner (owner_)
  42103. {
  42104. setWantsKeyboardFocus (false);
  42105. setInterceptsMouseClicks (false, true);
  42106. owner.getTextValue().addListener (this);
  42107. }
  42108. ~TextHolderComponent()
  42109. {
  42110. owner.getTextValue().removeListener (this);
  42111. }
  42112. void paint (Graphics& g)
  42113. {
  42114. owner.drawContent (g);
  42115. }
  42116. void timerCallback()
  42117. {
  42118. owner.timerCallbackInt();
  42119. }
  42120. const MouseCursor getMouseCursor()
  42121. {
  42122. return owner.getMouseCursor();
  42123. }
  42124. void valueChanged (Value&)
  42125. {
  42126. owner.textWasChangedByValue();
  42127. }
  42128. };
  42129. class TextEditorViewport : public Viewport
  42130. {
  42131. TextEditor* const owner;
  42132. float lastWordWrapWidth;
  42133. TextEditorViewport (const TextEditorViewport&);
  42134. const TextEditorViewport& operator= (const TextEditorViewport&);
  42135. public:
  42136. TextEditorViewport (TextEditor* const owner_)
  42137. : owner (owner_),
  42138. lastWordWrapWidth (0)
  42139. {
  42140. }
  42141. ~TextEditorViewport()
  42142. {
  42143. }
  42144. void visibleAreaChanged (int, int, int, int)
  42145. {
  42146. const float wordWrapWidth = owner->getWordWrapWidth();
  42147. if (wordWrapWidth != lastWordWrapWidth)
  42148. {
  42149. lastWordWrapWidth = wordWrapWidth;
  42150. owner->updateTextHolderSize();
  42151. }
  42152. }
  42153. };
  42154. namespace TextEditorDefs
  42155. {
  42156. const int flashSpeedIntervalMs = 380;
  42157. const int textChangeMessageId = 0x10003001;
  42158. const int returnKeyMessageId = 0x10003002;
  42159. const int escapeKeyMessageId = 0x10003003;
  42160. const int focusLossMessageId = 0x10003004;
  42161. const int maxActionsPerTransaction = 100;
  42162. }
  42163. TextEditor::TextEditor (const String& name,
  42164. const tchar passwordCharacter_)
  42165. : Component (name),
  42166. borderSize (1, 1, 1, 3),
  42167. readOnly (false),
  42168. multiline (false),
  42169. wordWrap (false),
  42170. returnKeyStartsNewLine (false),
  42171. caretVisible (true),
  42172. popupMenuEnabled (true),
  42173. selectAllTextWhenFocused (false),
  42174. scrollbarVisible (true),
  42175. wasFocused (false),
  42176. caretFlashState (true),
  42177. keepCursorOnScreen (true),
  42178. tabKeyUsed (false),
  42179. menuActive (false),
  42180. valueTextNeedsUpdating (false),
  42181. cursorX (0),
  42182. cursorY (0),
  42183. cursorHeight (0),
  42184. maxTextLength (0),
  42185. leftIndent (4),
  42186. topIndent (4),
  42187. lastTransactionTime (0),
  42188. currentFont (14.0f),
  42189. totalNumChars (0),
  42190. caretPosition (0),
  42191. passwordCharacter (passwordCharacter_),
  42192. dragType (notDragging)
  42193. {
  42194. setOpaque (true);
  42195. addAndMakeVisible (viewport = new TextEditorViewport (this));
  42196. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  42197. viewport->setWantsKeyboardFocus (false);
  42198. viewport->setScrollBarsShown (false, false);
  42199. setMouseCursor (MouseCursor::IBeamCursor);
  42200. setWantsKeyboardFocus (true);
  42201. }
  42202. TextEditor::~TextEditor()
  42203. {
  42204. textValue.referTo (Value());
  42205. clearInternal (0);
  42206. viewport = 0;
  42207. textHolder = 0;
  42208. }
  42209. void TextEditor::newTransaction()
  42210. {
  42211. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42212. undoManager.beginNewTransaction();
  42213. }
  42214. void TextEditor::doUndoRedo (const bool isRedo)
  42215. {
  42216. if (! isReadOnly())
  42217. {
  42218. if ((isRedo) ? undoManager.redo()
  42219. : undoManager.undo())
  42220. {
  42221. scrollToMakeSureCursorIsVisible();
  42222. repaint();
  42223. textChanged();
  42224. }
  42225. }
  42226. }
  42227. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  42228. const bool shouldWordWrap)
  42229. {
  42230. multiline = shouldBeMultiLine;
  42231. wordWrap = shouldWordWrap && shouldBeMultiLine;
  42232. setScrollbarsShown (scrollbarVisible);
  42233. viewport->setViewPosition (0, 0);
  42234. resized();
  42235. scrollToMakeSureCursorIsVisible();
  42236. }
  42237. bool TextEditor::isMultiLine() const
  42238. {
  42239. return multiline;
  42240. }
  42241. void TextEditor::setScrollbarsShown (bool enabled)
  42242. {
  42243. scrollbarVisible = enabled;
  42244. enabled = enabled && isMultiLine();
  42245. viewport->setScrollBarsShown (enabled, enabled);
  42246. }
  42247. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  42248. {
  42249. readOnly = shouldBeReadOnly;
  42250. enablementChanged();
  42251. }
  42252. bool TextEditor::isReadOnly() const
  42253. {
  42254. return readOnly || ! isEnabled();
  42255. }
  42256. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  42257. {
  42258. returnKeyStartsNewLine = shouldStartNewLine;
  42259. }
  42260. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  42261. {
  42262. tabKeyUsed = shouldTabKeyBeUsed;
  42263. }
  42264. void TextEditor::setPopupMenuEnabled (const bool b)
  42265. {
  42266. popupMenuEnabled = b;
  42267. }
  42268. void TextEditor::setSelectAllWhenFocused (const bool b)
  42269. {
  42270. selectAllTextWhenFocused = b;
  42271. }
  42272. const Font TextEditor::getFont() const
  42273. {
  42274. return currentFont;
  42275. }
  42276. void TextEditor::setFont (const Font& newFont)
  42277. {
  42278. currentFont = newFont;
  42279. scrollToMakeSureCursorIsVisible();
  42280. }
  42281. void TextEditor::applyFontToAllText (const Font& newFont)
  42282. {
  42283. currentFont = newFont;
  42284. const Colour overallColour (findColour (textColourId));
  42285. for (int i = sections.size(); --i >= 0;)
  42286. {
  42287. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  42288. uts->setFont (newFont, passwordCharacter);
  42289. uts->colour = overallColour;
  42290. }
  42291. coalesceSimilarSections();
  42292. updateTextHolderSize();
  42293. scrollToMakeSureCursorIsVisible();
  42294. repaint();
  42295. }
  42296. void TextEditor::colourChanged()
  42297. {
  42298. setOpaque (findColour (backgroundColourId).isOpaque());
  42299. repaint();
  42300. }
  42301. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  42302. {
  42303. caretVisible = shouldCaretBeVisible;
  42304. if (shouldCaretBeVisible)
  42305. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42306. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  42307. : MouseCursor::NormalCursor);
  42308. }
  42309. void TextEditor::setInputRestrictions (const int maxLen,
  42310. const String& chars)
  42311. {
  42312. maxTextLength = jmax (0, maxLen);
  42313. allowedCharacters = chars;
  42314. }
  42315. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  42316. {
  42317. textToShowWhenEmpty = text;
  42318. colourForTextWhenEmpty = colourToUse;
  42319. }
  42320. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  42321. {
  42322. if (passwordCharacter != newPasswordCharacter)
  42323. {
  42324. passwordCharacter = newPasswordCharacter;
  42325. resized();
  42326. repaint();
  42327. }
  42328. }
  42329. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  42330. {
  42331. viewport->setScrollBarThickness (newThicknessPixels);
  42332. }
  42333. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  42334. {
  42335. viewport->setScrollBarButtonVisibility (buttonsVisible);
  42336. }
  42337. void TextEditor::clear()
  42338. {
  42339. clearInternal (0);
  42340. updateTextHolderSize();
  42341. undoManager.clearUndoHistory();
  42342. }
  42343. void TextEditor::setText (const String& newText,
  42344. const bool sendTextChangeMessage)
  42345. {
  42346. const int newLength = newText.length();
  42347. if (newLength != getTotalNumChars() || getText() != newText)
  42348. {
  42349. const int oldCursorPos = caretPosition;
  42350. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  42351. clearInternal (0);
  42352. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  42353. // if you're adding text with line-feeds to a single-line text editor, it
  42354. // ain't gonna look right!
  42355. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  42356. if (cursorWasAtEnd && ! isMultiLine())
  42357. moveCursorTo (getTotalNumChars(), false);
  42358. else
  42359. moveCursorTo (oldCursorPos, false);
  42360. if (sendTextChangeMessage)
  42361. textChanged();
  42362. repaint();
  42363. }
  42364. updateTextHolderSize();
  42365. scrollToMakeSureCursorIsVisible();
  42366. undoManager.clearUndoHistory();
  42367. }
  42368. Value& TextEditor::getTextValue()
  42369. {
  42370. if (valueTextNeedsUpdating)
  42371. {
  42372. valueTextNeedsUpdating = false;
  42373. textValue = getText();
  42374. }
  42375. return textValue;
  42376. }
  42377. void TextEditor::textWasChangedByValue()
  42378. {
  42379. if (textValue.getValueSource().getReferenceCount() > 1)
  42380. setText (textValue.getValue());
  42381. }
  42382. void TextEditor::textChanged()
  42383. {
  42384. updateTextHolderSize();
  42385. postCommandMessage (TextEditorDefs::textChangeMessageId);
  42386. if (textValue.getValueSource().getReferenceCount() > 1)
  42387. {
  42388. valueTextNeedsUpdating = false;
  42389. textValue = getText();
  42390. }
  42391. }
  42392. void TextEditor::returnPressed()
  42393. {
  42394. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  42395. }
  42396. void TextEditor::escapePressed()
  42397. {
  42398. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  42399. }
  42400. void TextEditor::addListener (TextEditorListener* const newListener)
  42401. {
  42402. jassert (newListener != 0)
  42403. if (newListener != 0)
  42404. listeners.add (newListener);
  42405. }
  42406. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  42407. {
  42408. listeners.removeValue (listenerToRemove);
  42409. }
  42410. void TextEditor::timerCallbackInt()
  42411. {
  42412. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  42413. if (caretFlashState != newState)
  42414. {
  42415. caretFlashState = newState;
  42416. if (caretFlashState)
  42417. wasFocused = true;
  42418. if (caretVisible
  42419. && hasKeyboardFocus (false)
  42420. && ! isReadOnly())
  42421. {
  42422. repaintCaret();
  42423. }
  42424. }
  42425. const unsigned int now = Time::getApproximateMillisecondCounter();
  42426. if (now > lastTransactionTime + 200)
  42427. newTransaction();
  42428. }
  42429. void TextEditor::repaintCaret()
  42430. {
  42431. if (! findColour (caretColourId).isTransparent())
  42432. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42433. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42434. 4,
  42435. roundToInt (cursorHeight) + 2);
  42436. }
  42437. void TextEditor::repaintText (const Range<int>& range)
  42438. {
  42439. if (! range.isEmpty())
  42440. {
  42441. float x = 0, y = 0, lh = currentFont.getHeight();
  42442. const float wordWrapWidth = getWordWrapWidth();
  42443. if (wordWrapWidth > 0)
  42444. {
  42445. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42446. i.getCharPosition (range.getStart(), x, y, lh);
  42447. const int y1 = (int) y;
  42448. int y2;
  42449. if (range.getEnd() >= getTotalNumChars())
  42450. {
  42451. y2 = getHeight();
  42452. }
  42453. else
  42454. {
  42455. i.getCharPosition (range.getEnd(), x, y, lh);
  42456. y2 = (int) (y + lh * 2.0f);
  42457. }
  42458. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42459. }
  42460. }
  42461. }
  42462. void TextEditor::moveCaret (int newCaretPos)
  42463. {
  42464. if (newCaretPos < 0)
  42465. newCaretPos = 0;
  42466. else if (newCaretPos > getTotalNumChars())
  42467. newCaretPos = getTotalNumChars();
  42468. if (newCaretPos != getCaretPosition())
  42469. {
  42470. repaintCaret();
  42471. caretFlashState = true;
  42472. caretPosition = newCaretPos;
  42473. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42474. scrollToMakeSureCursorIsVisible();
  42475. repaintCaret();
  42476. }
  42477. }
  42478. void TextEditor::setCaretPosition (const int newIndex)
  42479. {
  42480. moveCursorTo (newIndex, false);
  42481. }
  42482. int TextEditor::getCaretPosition() const
  42483. {
  42484. return caretPosition;
  42485. }
  42486. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42487. const int desiredCaretY)
  42488. {
  42489. updateCaretPosition();
  42490. int vx = roundToInt (cursorX) - desiredCaretX;
  42491. int vy = roundToInt (cursorY) - desiredCaretY;
  42492. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42493. {
  42494. vx += desiredCaretX - proportionOfWidth (0.2f);
  42495. }
  42496. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42497. {
  42498. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42499. }
  42500. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42501. if (! isMultiLine())
  42502. {
  42503. vy = viewport->getViewPositionY();
  42504. }
  42505. else
  42506. {
  42507. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42508. const int curH = roundToInt (cursorHeight);
  42509. if (desiredCaretY < 0)
  42510. {
  42511. vy = jmax (0, desiredCaretY + vy);
  42512. }
  42513. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42514. {
  42515. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42516. }
  42517. }
  42518. viewport->setViewPosition (vx, vy);
  42519. }
  42520. const Rectangle<int> TextEditor::getCaretRectangle()
  42521. {
  42522. updateCaretPosition();
  42523. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42524. roundToInt (cursorY) - viewport->getY(),
  42525. 1, roundToInt (cursorHeight));
  42526. }
  42527. float TextEditor::getWordWrapWidth() const
  42528. {
  42529. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42530. : 1.0e10f;
  42531. }
  42532. void TextEditor::updateTextHolderSize()
  42533. {
  42534. const float wordWrapWidth = getWordWrapWidth();
  42535. if (wordWrapWidth > 0)
  42536. {
  42537. float maxWidth = 0.0f;
  42538. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42539. while (i.next())
  42540. maxWidth = jmax (maxWidth, i.atomRight);
  42541. const int w = leftIndent + roundToInt (maxWidth);
  42542. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42543. currentFont.getHeight()));
  42544. textHolder->setSize (w + 1, h + 1);
  42545. }
  42546. }
  42547. int TextEditor::getTextWidth() const
  42548. {
  42549. return textHolder->getWidth();
  42550. }
  42551. int TextEditor::getTextHeight() const
  42552. {
  42553. return textHolder->getHeight();
  42554. }
  42555. void TextEditor::setIndents (const int newLeftIndent,
  42556. const int newTopIndent)
  42557. {
  42558. leftIndent = newLeftIndent;
  42559. topIndent = newTopIndent;
  42560. }
  42561. void TextEditor::setBorder (const BorderSize& border)
  42562. {
  42563. borderSize = border;
  42564. resized();
  42565. }
  42566. const BorderSize TextEditor::getBorder() const
  42567. {
  42568. return borderSize;
  42569. }
  42570. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42571. {
  42572. keepCursorOnScreen = shouldScrollToShowCursor;
  42573. }
  42574. void TextEditor::updateCaretPosition()
  42575. {
  42576. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42577. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42578. }
  42579. void TextEditor::scrollToMakeSureCursorIsVisible()
  42580. {
  42581. updateCaretPosition();
  42582. if (keepCursorOnScreen)
  42583. {
  42584. int x = viewport->getViewPositionX();
  42585. int y = viewport->getViewPositionY();
  42586. const int relativeCursorX = roundToInt (cursorX) - x;
  42587. const int relativeCursorY = roundToInt (cursorY) - y;
  42588. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42589. {
  42590. x += relativeCursorX - proportionOfWidth (0.2f);
  42591. }
  42592. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42593. {
  42594. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42595. }
  42596. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42597. if (! isMultiLine())
  42598. {
  42599. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42600. }
  42601. else
  42602. {
  42603. const int curH = roundToInt (cursorHeight);
  42604. if (relativeCursorY < 0)
  42605. {
  42606. y = jmax (0, relativeCursorY + y);
  42607. }
  42608. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42609. {
  42610. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42611. }
  42612. }
  42613. viewport->setViewPosition (x, y);
  42614. }
  42615. }
  42616. void TextEditor::moveCursorTo (const int newPosition,
  42617. const bool isSelecting)
  42618. {
  42619. if (isSelecting)
  42620. {
  42621. moveCaret (newPosition);
  42622. const Range<int> oldSelection (selection);
  42623. if (dragType == notDragging)
  42624. {
  42625. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42626. dragType = draggingSelectionStart;
  42627. else
  42628. dragType = draggingSelectionEnd;
  42629. }
  42630. if (dragType == draggingSelectionStart)
  42631. {
  42632. if (getCaretPosition() >= selection.getEnd())
  42633. dragType = draggingSelectionEnd;
  42634. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42635. }
  42636. else
  42637. {
  42638. if (getCaretPosition() < selection.getStart())
  42639. dragType = draggingSelectionStart;
  42640. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42641. }
  42642. repaintText (selection.getUnionWith (oldSelection));
  42643. }
  42644. else
  42645. {
  42646. dragType = notDragging;
  42647. repaintText (selection);
  42648. moveCaret (newPosition);
  42649. selection = Range<int>::emptyRange (getCaretPosition());
  42650. }
  42651. }
  42652. int TextEditor::getTextIndexAt (const int x,
  42653. const int y)
  42654. {
  42655. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42656. (float) (y + viewport->getViewPositionY() - topIndent));
  42657. }
  42658. void TextEditor::insertTextAtCaret (const String& newText_)
  42659. {
  42660. String newText (newText_);
  42661. if (allowedCharacters.isNotEmpty())
  42662. newText = newText.retainCharacters (allowedCharacters);
  42663. if (! isMultiLine())
  42664. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42665. else
  42666. newText = newText.replace (T("\r\n"), T("\n"));
  42667. const int newCaretPos = selection.getStart() + newText.length();
  42668. const int insertIndex = selection.getStart();
  42669. remove (selection, &undoManager,
  42670. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42671. if (maxTextLength > 0)
  42672. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42673. if (newText.isNotEmpty())
  42674. insert (newText,
  42675. insertIndex,
  42676. currentFont,
  42677. findColour (textColourId),
  42678. &undoManager,
  42679. newCaretPos);
  42680. textChanged();
  42681. }
  42682. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42683. {
  42684. moveCursorTo (newSelection.getStart(), false);
  42685. moveCursorTo (newSelection.getEnd(), true);
  42686. }
  42687. void TextEditor::copy()
  42688. {
  42689. if (passwordCharacter == 0)
  42690. {
  42691. const String selection (getHighlightedText());
  42692. if (selection.isNotEmpty())
  42693. SystemClipboard::copyTextToClipboard (selection);
  42694. }
  42695. }
  42696. void TextEditor::paste()
  42697. {
  42698. if (! isReadOnly())
  42699. {
  42700. const String clip (SystemClipboard::getTextFromClipboard());
  42701. if (clip.isNotEmpty())
  42702. insertTextAtCaret (clip);
  42703. }
  42704. }
  42705. void TextEditor::cut()
  42706. {
  42707. if (! isReadOnly())
  42708. {
  42709. moveCaret (selection.getEnd());
  42710. insertTextAtCaret (String::empty);
  42711. }
  42712. }
  42713. void TextEditor::drawContent (Graphics& g)
  42714. {
  42715. const float wordWrapWidth = getWordWrapWidth();
  42716. if (wordWrapWidth > 0)
  42717. {
  42718. g.setOrigin (leftIndent, topIndent);
  42719. const Rectangle<int> clip (g.getClipBounds());
  42720. Colour selectedTextColour;
  42721. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42722. while (i.lineY + 200.0 < clip.getY() && i.next())
  42723. {}
  42724. if (! selection.isEmpty())
  42725. {
  42726. g.setColour (findColour (highlightColourId)
  42727. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42728. selectedTextColour = findColour (highlightedTextColourId);
  42729. TextEditorIterator i2 (i);
  42730. while (i2.next() && i2.lineY < clip.getBottom())
  42731. {
  42732. if (i2.lineY + i2.lineHeight >= clip.getY()
  42733. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42734. {
  42735. i2.drawSelection (g, selection);
  42736. }
  42737. }
  42738. }
  42739. const UniformTextSection* lastSection = 0;
  42740. while (i.next() && i.lineY < clip.getBottom())
  42741. {
  42742. if (i.lineY + i.lineHeight >= clip.getY())
  42743. {
  42744. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42745. {
  42746. i.drawSelectedText (g, selection, selectedTextColour);
  42747. lastSection = 0;
  42748. }
  42749. else
  42750. {
  42751. i.draw (g, lastSection);
  42752. }
  42753. }
  42754. }
  42755. }
  42756. }
  42757. void TextEditor::paint (Graphics& g)
  42758. {
  42759. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42760. }
  42761. void TextEditor::paintOverChildren (Graphics& g)
  42762. {
  42763. if (caretFlashState
  42764. && hasKeyboardFocus (false)
  42765. && caretVisible
  42766. && ! isReadOnly())
  42767. {
  42768. g.setColour (findColour (caretColourId));
  42769. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42770. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42771. 2.0f, cursorHeight);
  42772. }
  42773. if (textToShowWhenEmpty.isNotEmpty()
  42774. && (! hasKeyboardFocus (false))
  42775. && getTotalNumChars() == 0)
  42776. {
  42777. g.setColour (colourForTextWhenEmpty);
  42778. g.setFont (getFont());
  42779. if (isMultiLine())
  42780. {
  42781. g.drawText (textToShowWhenEmpty,
  42782. 0, 0, getWidth(), getHeight(),
  42783. Justification::centred, true);
  42784. }
  42785. else
  42786. {
  42787. g.drawText (textToShowWhenEmpty,
  42788. leftIndent, topIndent,
  42789. viewport->getWidth() - leftIndent,
  42790. viewport->getHeight() - topIndent,
  42791. Justification::centredLeft, true);
  42792. }
  42793. }
  42794. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42795. }
  42796. void TextEditor::mouseDown (const MouseEvent& e)
  42797. {
  42798. beginDragAutoRepeat (100);
  42799. newTransaction();
  42800. if (wasFocused || ! selectAllTextWhenFocused)
  42801. {
  42802. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42803. {
  42804. moveCursorTo (getTextIndexAt (e.x, e.y),
  42805. e.mods.isShiftDown());
  42806. }
  42807. else
  42808. {
  42809. PopupMenu m;
  42810. m.setLookAndFeel (&getLookAndFeel());
  42811. addPopupMenuItems (m, &e);
  42812. menuActive = true;
  42813. const int result = m.show();
  42814. menuActive = false;
  42815. if (result != 0)
  42816. performPopupMenuAction (result);
  42817. }
  42818. }
  42819. }
  42820. void TextEditor::mouseDrag (const MouseEvent& e)
  42821. {
  42822. if (wasFocused || ! selectAllTextWhenFocused)
  42823. {
  42824. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42825. {
  42826. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42827. }
  42828. }
  42829. }
  42830. void TextEditor::mouseUp (const MouseEvent& e)
  42831. {
  42832. newTransaction();
  42833. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42834. if (wasFocused || ! selectAllTextWhenFocused)
  42835. {
  42836. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42837. {
  42838. moveCaret (getTextIndexAt (e.x, e.y));
  42839. }
  42840. }
  42841. wasFocused = true;
  42842. }
  42843. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42844. {
  42845. int tokenEnd = getTextIndexAt (e.x, e.y);
  42846. int tokenStart = tokenEnd;
  42847. if (e.getNumberOfClicks() > 3)
  42848. {
  42849. tokenStart = 0;
  42850. tokenEnd = getTotalNumChars();
  42851. }
  42852. else
  42853. {
  42854. const String t (getText());
  42855. const int totalLength = getTotalNumChars();
  42856. while (tokenEnd < totalLength)
  42857. {
  42858. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42859. ++tokenEnd;
  42860. else
  42861. break;
  42862. }
  42863. tokenStart = tokenEnd;
  42864. while (tokenStart > 0)
  42865. {
  42866. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42867. --tokenStart;
  42868. else
  42869. break;
  42870. }
  42871. if (e.getNumberOfClicks() > 2)
  42872. {
  42873. while (tokenEnd < totalLength)
  42874. {
  42875. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42876. ++tokenEnd;
  42877. else
  42878. break;
  42879. }
  42880. while (tokenStart > 0)
  42881. {
  42882. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42883. --tokenStart;
  42884. else
  42885. break;
  42886. }
  42887. }
  42888. }
  42889. moveCursorTo (tokenEnd, false);
  42890. moveCursorTo (tokenStart, true);
  42891. }
  42892. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42893. {
  42894. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42895. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42896. }
  42897. bool TextEditor::keyPressed (const KeyPress& key)
  42898. {
  42899. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42900. return false;
  42901. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42902. if (key.isKeyCode (KeyPress::leftKey)
  42903. || key.isKeyCode (KeyPress::upKey))
  42904. {
  42905. newTransaction();
  42906. int newPos;
  42907. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42908. newPos = indexAtPosition (cursorX, cursorY - 1);
  42909. else if (moveInWholeWordSteps)
  42910. newPos = findWordBreakBefore (getCaretPosition());
  42911. else
  42912. newPos = getCaretPosition() - 1;
  42913. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42914. }
  42915. else if (key.isKeyCode (KeyPress::rightKey)
  42916. || key.isKeyCode (KeyPress::downKey))
  42917. {
  42918. newTransaction();
  42919. int newPos;
  42920. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42921. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42922. else if (moveInWholeWordSteps)
  42923. newPos = findWordBreakAfter (getCaretPosition());
  42924. else
  42925. newPos = getCaretPosition() + 1;
  42926. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42927. }
  42928. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42929. {
  42930. newTransaction();
  42931. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42932. key.getModifiers().isShiftDown());
  42933. }
  42934. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42935. {
  42936. newTransaction();
  42937. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42938. key.getModifiers().isShiftDown());
  42939. }
  42940. else if (key.isKeyCode (KeyPress::homeKey))
  42941. {
  42942. newTransaction();
  42943. if (isMultiLine() && ! moveInWholeWordSteps)
  42944. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42945. key.getModifiers().isShiftDown());
  42946. else
  42947. moveCursorTo (0, key.getModifiers().isShiftDown());
  42948. }
  42949. else if (key.isKeyCode (KeyPress::endKey))
  42950. {
  42951. newTransaction();
  42952. if (isMultiLine() && ! moveInWholeWordSteps)
  42953. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42954. key.getModifiers().isShiftDown());
  42955. else
  42956. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42957. }
  42958. else if (key.isKeyCode (KeyPress::backspaceKey))
  42959. {
  42960. if (moveInWholeWordSteps)
  42961. {
  42962. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42963. }
  42964. else
  42965. {
  42966. if (selection.isEmpty() && selection.getStart() > 0)
  42967. selection.setStart (selection.getEnd() - 1);
  42968. }
  42969. cut();
  42970. }
  42971. else if (key.isKeyCode (KeyPress::deleteKey))
  42972. {
  42973. if (key.getModifiers().isShiftDown())
  42974. copy();
  42975. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42976. selection.setEnd (selection.getStart() + 1);
  42977. cut();
  42978. }
  42979. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  42980. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42981. {
  42982. newTransaction();
  42983. copy();
  42984. }
  42985. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  42986. {
  42987. newTransaction();
  42988. copy();
  42989. cut();
  42990. }
  42991. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  42992. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42993. {
  42994. newTransaction();
  42995. paste();
  42996. }
  42997. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  42998. {
  42999. newTransaction();
  43000. doUndoRedo (false);
  43001. }
  43002. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  43003. {
  43004. newTransaction();
  43005. doUndoRedo (true);
  43006. }
  43007. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  43008. {
  43009. newTransaction();
  43010. moveCursorTo (getTotalNumChars(), false);
  43011. moveCursorTo (0, true);
  43012. }
  43013. else if (key == KeyPress::returnKey)
  43014. {
  43015. newTransaction();
  43016. if (returnKeyStartsNewLine)
  43017. insertTextAtCaret (T("\n"));
  43018. else
  43019. returnPressed();
  43020. }
  43021. else if (key.isKeyCode (KeyPress::escapeKey))
  43022. {
  43023. newTransaction();
  43024. moveCursorTo (getCaretPosition(), false);
  43025. escapePressed();
  43026. }
  43027. else if (key.getTextCharacter() >= ' '
  43028. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  43029. {
  43030. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  43031. lastTransactionTime = Time::getApproximateMillisecondCounter();
  43032. }
  43033. else
  43034. {
  43035. return false;
  43036. }
  43037. return true;
  43038. }
  43039. bool TextEditor::keyStateChanged (const bool isKeyDown)
  43040. {
  43041. if (! isKeyDown)
  43042. return false;
  43043. #if JUCE_WIN32
  43044. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  43045. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  43046. #endif
  43047. // (overridden to avoid forwarding key events to the parent)
  43048. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  43049. }
  43050. const int baseMenuItemID = 0x7fff0000;
  43051. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  43052. {
  43053. const bool writable = ! isReadOnly();
  43054. if (passwordCharacter == 0)
  43055. {
  43056. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  43057. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  43058. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  43059. }
  43060. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  43061. m.addSeparator();
  43062. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  43063. m.addSeparator();
  43064. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  43065. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  43066. }
  43067. void TextEditor::performPopupMenuAction (const int menuItemID)
  43068. {
  43069. switch (menuItemID)
  43070. {
  43071. case baseMenuItemID + 1:
  43072. copy();
  43073. cut();
  43074. break;
  43075. case baseMenuItemID + 2:
  43076. copy();
  43077. break;
  43078. case baseMenuItemID + 3:
  43079. paste();
  43080. break;
  43081. case baseMenuItemID + 4:
  43082. cut();
  43083. break;
  43084. case baseMenuItemID + 5:
  43085. moveCursorTo (getTotalNumChars(), false);
  43086. moveCursorTo (0, true);
  43087. break;
  43088. case baseMenuItemID + 6:
  43089. doUndoRedo (false);
  43090. break;
  43091. case baseMenuItemID + 7:
  43092. doUndoRedo (true);
  43093. break;
  43094. default:
  43095. break;
  43096. }
  43097. }
  43098. void TextEditor::focusGained (FocusChangeType)
  43099. {
  43100. newTransaction();
  43101. caretFlashState = true;
  43102. if (selectAllTextWhenFocused)
  43103. {
  43104. moveCursorTo (0, false);
  43105. moveCursorTo (getTotalNumChars(), true);
  43106. }
  43107. repaint();
  43108. if (caretVisible)
  43109. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  43110. ComponentPeer* const peer = getPeer();
  43111. if (peer != 0 && ! isReadOnly())
  43112. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  43113. }
  43114. void TextEditor::focusLost (FocusChangeType)
  43115. {
  43116. newTransaction();
  43117. wasFocused = false;
  43118. textHolder->stopTimer();
  43119. caretFlashState = false;
  43120. postCommandMessage (TextEditorDefs::focusLossMessageId);
  43121. repaint();
  43122. }
  43123. void TextEditor::resized()
  43124. {
  43125. viewport->setBoundsInset (borderSize);
  43126. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  43127. updateTextHolderSize();
  43128. if (! isMultiLine())
  43129. {
  43130. scrollToMakeSureCursorIsVisible();
  43131. }
  43132. else
  43133. {
  43134. updateCaretPosition();
  43135. }
  43136. }
  43137. void TextEditor::handleCommandMessage (const int commandId)
  43138. {
  43139. const ComponentDeletionWatcher deletionChecker (this);
  43140. for (int i = listeners.size(); --i >= 0;)
  43141. {
  43142. TextEditorListener* const tl = (TextEditorListener*) listeners [i];
  43143. if (tl != 0)
  43144. {
  43145. switch (commandId)
  43146. {
  43147. case TextEditorDefs::textChangeMessageId:
  43148. tl->textEditorTextChanged (*this);
  43149. break;
  43150. case TextEditorDefs::returnKeyMessageId:
  43151. tl->textEditorReturnKeyPressed (*this);
  43152. break;
  43153. case TextEditorDefs::escapeKeyMessageId:
  43154. tl->textEditorEscapeKeyPressed (*this);
  43155. break;
  43156. case TextEditorDefs::focusLossMessageId:
  43157. tl->textEditorFocusLost (*this);
  43158. break;
  43159. default:
  43160. jassertfalse
  43161. break;
  43162. }
  43163. if (i > 0 && deletionChecker.hasBeenDeleted())
  43164. return;
  43165. }
  43166. }
  43167. }
  43168. void TextEditor::enablementChanged()
  43169. {
  43170. setMouseCursor (MouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  43171. : MouseCursor::IBeamCursor));
  43172. repaint();
  43173. }
  43174. void TextEditor::clearInternal (UndoManager* const um)
  43175. {
  43176. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  43177. }
  43178. void TextEditor::insert (const String& text,
  43179. const int insertIndex,
  43180. const Font& font,
  43181. const Colour& colour,
  43182. UndoManager* const um,
  43183. const int caretPositionToMoveTo)
  43184. {
  43185. if (text.isNotEmpty())
  43186. {
  43187. if (um != 0)
  43188. {
  43189. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43190. newTransaction();
  43191. um->perform (new TextEditorInsertAction (*this,
  43192. text,
  43193. insertIndex,
  43194. font,
  43195. colour,
  43196. caretPosition,
  43197. caretPositionToMoveTo));
  43198. }
  43199. else
  43200. {
  43201. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  43202. // a line gets moved due to word wrap
  43203. int index = 0;
  43204. int nextIndex = 0;
  43205. for (int i = 0; i < sections.size(); ++i)
  43206. {
  43207. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43208. if (insertIndex == index)
  43209. {
  43210. sections.insert (i, new UniformTextSection (text,
  43211. font, colour,
  43212. passwordCharacter));
  43213. break;
  43214. }
  43215. else if (insertIndex > index && insertIndex < nextIndex)
  43216. {
  43217. splitSection (i, insertIndex - index);
  43218. sections.insert (i + 1, new UniformTextSection (text,
  43219. font, colour,
  43220. passwordCharacter));
  43221. break;
  43222. }
  43223. index = nextIndex;
  43224. }
  43225. if (nextIndex == insertIndex)
  43226. sections.add (new UniformTextSection (text,
  43227. font, colour,
  43228. passwordCharacter));
  43229. coalesceSimilarSections();
  43230. totalNumChars = -1;
  43231. valueTextNeedsUpdating = true;
  43232. moveCursorTo (caretPositionToMoveTo, false);
  43233. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  43234. }
  43235. }
  43236. }
  43237. void TextEditor::reinsert (const int insertIndex,
  43238. const VoidArray& sectionsToInsert)
  43239. {
  43240. int index = 0;
  43241. int nextIndex = 0;
  43242. for (int i = 0; i < sections.size(); ++i)
  43243. {
  43244. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43245. if (insertIndex == index)
  43246. {
  43247. for (int j = sectionsToInsert.size(); --j >= 0;)
  43248. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43249. break;
  43250. }
  43251. else if (insertIndex > index && insertIndex < nextIndex)
  43252. {
  43253. splitSection (i, insertIndex - index);
  43254. for (int j = sectionsToInsert.size(); --j >= 0;)
  43255. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43256. break;
  43257. }
  43258. index = nextIndex;
  43259. }
  43260. if (nextIndex == insertIndex)
  43261. {
  43262. for (int j = 0; j < sectionsToInsert.size(); ++j)
  43263. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43264. }
  43265. coalesceSimilarSections();
  43266. totalNumChars = -1;
  43267. valueTextNeedsUpdating = true;
  43268. }
  43269. void TextEditor::remove (const Range<int>& range,
  43270. UndoManager* const um,
  43271. const int caretPositionToMoveTo)
  43272. {
  43273. if (! range.isEmpty())
  43274. {
  43275. int index = 0;
  43276. for (int i = 0; i < sections.size(); ++i)
  43277. {
  43278. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  43279. if (range.getStart() > index && range.getStart() < nextIndex)
  43280. {
  43281. splitSection (i, range.getStart() - index);
  43282. --i;
  43283. }
  43284. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  43285. {
  43286. splitSection (i, range.getEnd() - index);
  43287. --i;
  43288. }
  43289. else
  43290. {
  43291. index = nextIndex;
  43292. if (index > range.getEnd())
  43293. break;
  43294. }
  43295. }
  43296. index = 0;
  43297. if (um != 0)
  43298. {
  43299. VoidArray removedSections;
  43300. for (int i = 0; i < sections.size(); ++i)
  43301. {
  43302. if (range.getEnd() <= range.getStart())
  43303. break;
  43304. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43305. const int nextIndex = index + section->getTotalLength();
  43306. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  43307. removedSections.add (new UniformTextSection (*section));
  43308. index = nextIndex;
  43309. }
  43310. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43311. newTransaction();
  43312. um->perform (new TextEditorRemoveAction (*this,
  43313. range,
  43314. caretPosition,
  43315. caretPositionToMoveTo,
  43316. removedSections));
  43317. }
  43318. else
  43319. {
  43320. Range<int> remainingRange (range);
  43321. for (int i = 0; i < sections.size(); ++i)
  43322. {
  43323. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43324. const int nextIndex = index + section->getTotalLength();
  43325. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  43326. {
  43327. sections.remove(i);
  43328. section->clear();
  43329. delete section;
  43330. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  43331. if (remainingRange.isEmpty())
  43332. break;
  43333. --i;
  43334. }
  43335. else
  43336. {
  43337. index = nextIndex;
  43338. }
  43339. }
  43340. coalesceSimilarSections();
  43341. totalNumChars = -1;
  43342. valueTextNeedsUpdating = true;
  43343. moveCursorTo (caretPositionToMoveTo, false);
  43344. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  43345. }
  43346. }
  43347. }
  43348. const String TextEditor::getText() const
  43349. {
  43350. String t;
  43351. t.preallocateStorage (getTotalNumChars());
  43352. String::Concatenator concatenator (t);
  43353. for (int i = 0; i < sections.size(); ++i)
  43354. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  43355. return t;
  43356. }
  43357. const String TextEditor::getTextInRange (const Range<int>& range) const
  43358. {
  43359. String t;
  43360. if (! range.isEmpty())
  43361. {
  43362. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  43363. String::Concatenator concatenator (t);
  43364. int index = 0;
  43365. for (int i = 0; i < sections.size(); ++i)
  43366. {
  43367. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  43368. const int nextIndex = index + s->getTotalLength();
  43369. if (range.getStart() < nextIndex)
  43370. {
  43371. if (range.getEnd() <= index)
  43372. break;
  43373. s->appendSubstring (concatenator, range - index);
  43374. }
  43375. index = nextIndex;
  43376. }
  43377. }
  43378. return t;
  43379. }
  43380. const String TextEditor::getHighlightedText() const
  43381. {
  43382. return getTextInRange (selection);
  43383. }
  43384. int TextEditor::getTotalNumChars() const
  43385. {
  43386. if (totalNumChars < 0)
  43387. {
  43388. totalNumChars = 0;
  43389. for (int i = sections.size(); --i >= 0;)
  43390. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43391. }
  43392. return totalNumChars;
  43393. }
  43394. bool TextEditor::isEmpty() const
  43395. {
  43396. return getTotalNumChars() == 0;
  43397. }
  43398. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  43399. {
  43400. const float wordWrapWidth = getWordWrapWidth();
  43401. if (wordWrapWidth > 0 && sections.size() > 0)
  43402. {
  43403. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43404. i.getCharPosition (index, cx, cy, lineHeight);
  43405. }
  43406. else
  43407. {
  43408. cx = cy = 0;
  43409. lineHeight = currentFont.getHeight();
  43410. }
  43411. }
  43412. int TextEditor::indexAtPosition (const float x, const float y)
  43413. {
  43414. const float wordWrapWidth = getWordWrapWidth();
  43415. if (wordWrapWidth > 0)
  43416. {
  43417. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43418. while (i.next())
  43419. {
  43420. if (i.lineY + i.lineHeight > y)
  43421. {
  43422. if (i.lineY > y)
  43423. return jmax (0, i.indexInText - 1);
  43424. if (i.atomX >= x)
  43425. return i.indexInText;
  43426. if (x < i.atomRight)
  43427. return i.xToIndex (x);
  43428. }
  43429. }
  43430. }
  43431. return getTotalNumChars();
  43432. }
  43433. static int getCharacterCategory (const tchar character)
  43434. {
  43435. return CharacterFunctions::isLetterOrDigit (character)
  43436. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43437. }
  43438. int TextEditor::findWordBreakAfter (const int position) const
  43439. {
  43440. const String t (getTextInRange (Range<int> (position, position + 512)));
  43441. const int totalLength = t.length();
  43442. int i = 0;
  43443. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43444. ++i;
  43445. const int type = getCharacterCategory (t[i]);
  43446. while (i < totalLength && type == getCharacterCategory (t[i]))
  43447. ++i;
  43448. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43449. ++i;
  43450. return position + i;
  43451. }
  43452. int TextEditor::findWordBreakBefore (const int position) const
  43453. {
  43454. if (position <= 0)
  43455. return 0;
  43456. const int startOfBuffer = jmax (0, position - 512);
  43457. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  43458. int i = position - startOfBuffer;
  43459. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43460. --i;
  43461. if (i > 0)
  43462. {
  43463. const int type = getCharacterCategory (t [i - 1]);
  43464. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43465. --i;
  43466. }
  43467. jassert (startOfBuffer + i >= 0);
  43468. return startOfBuffer + i;
  43469. }
  43470. void TextEditor::splitSection (const int sectionIndex,
  43471. const int charToSplitAt)
  43472. {
  43473. jassert (sections[sectionIndex] != 0);
  43474. sections.insert (sectionIndex + 1,
  43475. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43476. ->split (charToSplitAt, passwordCharacter));
  43477. }
  43478. void TextEditor::coalesceSimilarSections()
  43479. {
  43480. for (int i = 0; i < sections.size() - 1; ++i)
  43481. {
  43482. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43483. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43484. if (s1->font == s2->font
  43485. && s1->colour == s2->colour)
  43486. {
  43487. s1->append (*s2, passwordCharacter);
  43488. sections.remove (i + 1);
  43489. delete s2;
  43490. --i;
  43491. }
  43492. }
  43493. }
  43494. END_JUCE_NAMESPACE
  43495. /*** End of inlined file: juce_TextEditor.cpp ***/
  43496. /*** Start of inlined file: juce_Toolbar.cpp ***/
  43497. BEGIN_JUCE_NAMESPACE
  43498. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43499. class ToolbarSpacerComp : public ToolbarItemComponent
  43500. {
  43501. public:
  43502. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43503. : ToolbarItemComponent (itemId_, String::empty, false),
  43504. fixedSize (fixedSize_),
  43505. drawBar (drawBar_)
  43506. {
  43507. }
  43508. ~ToolbarSpacerComp()
  43509. {
  43510. }
  43511. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43512. int& preferredSize, int& minSize, int& maxSize)
  43513. {
  43514. if (fixedSize <= 0)
  43515. {
  43516. preferredSize = toolbarThickness * 2;
  43517. minSize = 4;
  43518. maxSize = 32768;
  43519. }
  43520. else
  43521. {
  43522. maxSize = roundToInt (toolbarThickness * fixedSize);
  43523. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43524. preferredSize = maxSize;
  43525. if (getEditingMode() == editableOnPalette)
  43526. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43527. }
  43528. return true;
  43529. }
  43530. void paintButtonArea (Graphics&, int, int, bool, bool)
  43531. {
  43532. }
  43533. void contentAreaChanged (const Rectangle<int>&)
  43534. {
  43535. }
  43536. int getResizeOrder() const throw()
  43537. {
  43538. return fixedSize <= 0 ? 0 : 1;
  43539. }
  43540. void paint (Graphics& g)
  43541. {
  43542. const int w = getWidth();
  43543. const int h = getHeight();
  43544. if (drawBar)
  43545. {
  43546. g.setColour (findColour (Toolbar::separatorColourId, true));
  43547. const float thickness = 0.2f;
  43548. if (isToolbarVertical())
  43549. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43550. else
  43551. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43552. }
  43553. if (getEditingMode() != normalMode && ! drawBar)
  43554. {
  43555. g.setColour (findColour (Toolbar::separatorColourId, true));
  43556. const int indentX = jmin (2, (w - 3) / 2);
  43557. const int indentY = jmin (2, (h - 3) / 2);
  43558. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43559. if (fixedSize <= 0)
  43560. {
  43561. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43562. if (isToolbarVertical())
  43563. {
  43564. x1 = w * 0.5f;
  43565. y1 = h * 0.4f;
  43566. x2 = x1;
  43567. y2 = indentX * 2.0f;
  43568. x3 = x1;
  43569. y3 = h * 0.6f;
  43570. x4 = x1;
  43571. y4 = h - y2;
  43572. hw = w * 0.15f;
  43573. hl = w * 0.2f;
  43574. }
  43575. else
  43576. {
  43577. x1 = w * 0.4f;
  43578. y1 = h * 0.5f;
  43579. x2 = indentX * 2.0f;
  43580. y2 = y1;
  43581. x3 = w * 0.6f;
  43582. y3 = y1;
  43583. x4 = w - x2;
  43584. y4 = y1;
  43585. hw = h * 0.15f;
  43586. hl = h * 0.2f;
  43587. }
  43588. Path p;
  43589. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43590. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43591. g.fillPath (p);
  43592. }
  43593. }
  43594. }
  43595. juce_UseDebuggingNewOperator
  43596. private:
  43597. const float fixedSize;
  43598. const bool drawBar;
  43599. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43600. const ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43601. };
  43602. class MissingItemsComponent : public PopupMenuCustomComponent
  43603. {
  43604. public:
  43605. MissingItemsComponent (Toolbar& owner_, const int height_)
  43606. : PopupMenuCustomComponent (true),
  43607. owner (owner_),
  43608. height (height_)
  43609. {
  43610. for (int i = owner_.items.size(); --i >= 0;)
  43611. {
  43612. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43613. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43614. {
  43615. oldIndexes.insert (0, i);
  43616. addAndMakeVisible (tc, 0);
  43617. }
  43618. }
  43619. layout (400);
  43620. }
  43621. ~MissingItemsComponent()
  43622. {
  43623. // deleting the toolbar while its menu it open??
  43624. jassert (owner.isValidComponent());
  43625. for (int i = 0; i < getNumChildComponents(); ++i)
  43626. {
  43627. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43628. if (tc != 0)
  43629. {
  43630. tc->setVisible (false);
  43631. const int index = oldIndexes.remove (i);
  43632. owner.addChildComponent (tc, index);
  43633. --i;
  43634. }
  43635. }
  43636. owner.resized();
  43637. }
  43638. void layout (const int preferredWidth)
  43639. {
  43640. const int indent = 8;
  43641. int x = indent;
  43642. int y = indent;
  43643. int maxX = 0;
  43644. for (int i = 0; i < getNumChildComponents(); ++i)
  43645. {
  43646. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43647. if (tc != 0)
  43648. {
  43649. int preferredSize = 1, minSize = 1, maxSize = 1;
  43650. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43651. {
  43652. if (x + preferredSize > preferredWidth && x > indent)
  43653. {
  43654. x = indent;
  43655. y += height;
  43656. }
  43657. tc->setBounds (x, y, preferredSize, height);
  43658. x += preferredSize;
  43659. maxX = jmax (maxX, x);
  43660. }
  43661. }
  43662. }
  43663. setSize (maxX + 8, y + height + 8);
  43664. }
  43665. void getIdealSize (int& idealWidth, int& idealHeight)
  43666. {
  43667. idealWidth = getWidth();
  43668. idealHeight = getHeight();
  43669. }
  43670. juce_UseDebuggingNewOperator
  43671. private:
  43672. Toolbar& owner;
  43673. const int height;
  43674. Array <int> oldIndexes;
  43675. MissingItemsComponent (const MissingItemsComponent&);
  43676. const MissingItemsComponent& operator= (const MissingItemsComponent&);
  43677. };
  43678. Toolbar::Toolbar()
  43679. : vertical (false),
  43680. isEditingActive (false),
  43681. toolbarStyle (Toolbar::iconsOnly)
  43682. {
  43683. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43684. missingItemsButton->setAlwaysOnTop (true);
  43685. missingItemsButton->addButtonListener (this);
  43686. }
  43687. Toolbar::~Toolbar()
  43688. {
  43689. animator.cancelAllAnimations (true);
  43690. deleteAllChildren();
  43691. }
  43692. void Toolbar::setVertical (const bool shouldBeVertical)
  43693. {
  43694. if (vertical != shouldBeVertical)
  43695. {
  43696. vertical = shouldBeVertical;
  43697. resized();
  43698. }
  43699. }
  43700. void Toolbar::clear()
  43701. {
  43702. for (int i = items.size(); --i >= 0;)
  43703. {
  43704. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43705. items.remove (i);
  43706. delete tc;
  43707. }
  43708. resized();
  43709. }
  43710. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43711. {
  43712. if (itemId == ToolbarItemFactory::separatorBarId)
  43713. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43714. else if (itemId == ToolbarItemFactory::spacerId)
  43715. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43716. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43717. return new ToolbarSpacerComp (itemId, 0, false);
  43718. return factory.createItem (itemId);
  43719. }
  43720. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43721. const int itemId,
  43722. const int insertIndex)
  43723. {
  43724. // An ID can't be zero - this might indicate a mistake somewhere?
  43725. jassert (itemId != 0);
  43726. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43727. if (tc != 0)
  43728. {
  43729. #ifdef JUCE_DEBUG
  43730. Array <int> allowedIds;
  43731. factory.getAllToolbarItemIds (allowedIds);
  43732. // If your factory can create an item for a given ID, it must also return
  43733. // that ID from its getAllToolbarItemIds() method!
  43734. jassert (allowedIds.contains (itemId));
  43735. #endif
  43736. items.insert (insertIndex, tc);
  43737. addAndMakeVisible (tc, insertIndex);
  43738. }
  43739. }
  43740. void Toolbar::addItem (ToolbarItemFactory& factory,
  43741. const int itemId,
  43742. const int insertIndex)
  43743. {
  43744. addItemInternal (factory, itemId, insertIndex);
  43745. resized();
  43746. }
  43747. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43748. {
  43749. Array <int> ids;
  43750. factoryToUse.getDefaultItemSet (ids);
  43751. clear();
  43752. for (int i = 0; i < ids.size(); ++i)
  43753. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43754. resized();
  43755. }
  43756. void Toolbar::removeToolbarItem (const int itemIndex)
  43757. {
  43758. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43759. if (tc != 0)
  43760. {
  43761. items.removeValue (tc);
  43762. delete tc;
  43763. resized();
  43764. }
  43765. }
  43766. int Toolbar::getNumItems() const throw()
  43767. {
  43768. return items.size();
  43769. }
  43770. int Toolbar::getItemId (const int itemIndex) const throw()
  43771. {
  43772. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43773. return tc != 0 ? tc->getItemId() : 0;
  43774. }
  43775. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43776. {
  43777. return items [itemIndex];
  43778. }
  43779. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43780. {
  43781. for (;;)
  43782. {
  43783. index += delta;
  43784. ToolbarItemComponent* const tc = getItemComponent (index);
  43785. if (tc == 0)
  43786. break;
  43787. if (tc->isActive)
  43788. return tc;
  43789. }
  43790. return 0;
  43791. }
  43792. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43793. {
  43794. if (toolbarStyle != newStyle)
  43795. {
  43796. toolbarStyle = newStyle;
  43797. updateAllItemPositions (false);
  43798. }
  43799. }
  43800. const String Toolbar::toString() const
  43801. {
  43802. String s (T("TB:"));
  43803. for (int i = 0; i < getNumItems(); ++i)
  43804. s << getItemId(i) << T(' ');
  43805. return s.trimEnd();
  43806. }
  43807. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43808. const String& savedVersion)
  43809. {
  43810. if (! savedVersion.startsWith (T("TB:")))
  43811. return false;
  43812. StringArray tokens;
  43813. tokens.addTokens (savedVersion.substring (3), false);
  43814. clear();
  43815. for (int i = 0; i < tokens.size(); ++i)
  43816. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43817. resized();
  43818. return true;
  43819. }
  43820. void Toolbar::paint (Graphics& g)
  43821. {
  43822. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43823. }
  43824. int Toolbar::getThickness() const throw()
  43825. {
  43826. return vertical ? getWidth() : getHeight();
  43827. }
  43828. int Toolbar::getLength() const throw()
  43829. {
  43830. return vertical ? getHeight() : getWidth();
  43831. }
  43832. void Toolbar::setEditingActive (const bool active)
  43833. {
  43834. if (isEditingActive != active)
  43835. {
  43836. isEditingActive = active;
  43837. updateAllItemPositions (false);
  43838. }
  43839. }
  43840. void Toolbar::resized()
  43841. {
  43842. updateAllItemPositions (false);
  43843. }
  43844. void Toolbar::updateAllItemPositions (const bool animate)
  43845. {
  43846. if (getWidth() > 0 && getHeight() > 0)
  43847. {
  43848. StretchableObjectResizer resizer;
  43849. int i;
  43850. for (i = 0; i < items.size(); ++i)
  43851. {
  43852. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43853. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43854. : ToolbarItemComponent::normalMode);
  43855. tc->setStyle (toolbarStyle);
  43856. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43857. int preferredSize = 1, minSize = 1, maxSize = 1;
  43858. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43859. preferredSize, minSize, maxSize))
  43860. {
  43861. tc->isActive = true;
  43862. resizer.addItem (preferredSize, minSize, maxSize,
  43863. spacer != 0 ? spacer->getResizeOrder() : 2);
  43864. }
  43865. else
  43866. {
  43867. tc->isActive = false;
  43868. tc->setVisible (false);
  43869. }
  43870. }
  43871. resizer.resizeToFit (getLength());
  43872. int totalLength = 0;
  43873. for (i = 0; i < resizer.getNumItems(); ++i)
  43874. totalLength += (int) resizer.getItemSize (i);
  43875. const bool itemsOffTheEnd = totalLength > getLength();
  43876. const int extrasButtonSize = getThickness() / 2;
  43877. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43878. missingItemsButton->setVisible (itemsOffTheEnd);
  43879. missingItemsButton->setEnabled (! isEditingActive);
  43880. if (vertical)
  43881. missingItemsButton->setCentrePosition (getWidth() / 2,
  43882. getHeight() - 4 - extrasButtonSize / 2);
  43883. else
  43884. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43885. getHeight() / 2);
  43886. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43887. : missingItemsButton->getX()) - 4
  43888. : getLength();
  43889. int pos = 0, activeIndex = 0;
  43890. for (i = 0; i < items.size(); ++i)
  43891. {
  43892. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43893. if (tc->isActive)
  43894. {
  43895. const int size = (int) resizer.getItemSize (activeIndex++);
  43896. Rectangle<int> newBounds;
  43897. if (vertical)
  43898. newBounds.setBounds (0, pos, getWidth(), size);
  43899. else
  43900. newBounds.setBounds (pos, 0, size, getHeight());
  43901. if (animate)
  43902. {
  43903. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43904. }
  43905. else
  43906. {
  43907. animator.cancelAnimation (tc, false);
  43908. tc->setBounds (newBounds);
  43909. }
  43910. pos += size;
  43911. tc->setVisible (pos <= maxLength
  43912. && ((! tc->isBeingDragged)
  43913. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43914. }
  43915. }
  43916. }
  43917. }
  43918. void Toolbar::buttonClicked (Button*)
  43919. {
  43920. jassert (missingItemsButton->isShowing());
  43921. if (missingItemsButton->isShowing())
  43922. {
  43923. PopupMenu m;
  43924. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43925. m.showAt (missingItemsButton);
  43926. }
  43927. }
  43928. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43929. Component* /*sourceComponent*/)
  43930. {
  43931. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43932. }
  43933. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43934. {
  43935. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43936. if (tc != 0)
  43937. {
  43938. if (getNumItems() == 0)
  43939. {
  43940. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43941. {
  43942. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43943. if (palette != 0)
  43944. palette->replaceComponent (tc);
  43945. }
  43946. else
  43947. {
  43948. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43949. }
  43950. items.add (tc);
  43951. addChildComponent (tc);
  43952. updateAllItemPositions (false);
  43953. }
  43954. else
  43955. {
  43956. for (int i = getNumItems(); --i >= 0;)
  43957. {
  43958. int currentIndex = getIndexOfChildComponent (tc);
  43959. if (currentIndex < 0)
  43960. {
  43961. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43962. {
  43963. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43964. if (palette != 0)
  43965. palette->replaceComponent (tc);
  43966. }
  43967. else
  43968. {
  43969. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43970. }
  43971. items.add (tc);
  43972. addChildComponent (tc);
  43973. currentIndex = getIndexOfChildComponent (tc);
  43974. updateAllItemPositions (true);
  43975. }
  43976. int newIndex = currentIndex;
  43977. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43978. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43979. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43980. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43981. if (prev != 0)
  43982. {
  43983. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43984. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43985. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43986. {
  43987. newIndex = getIndexOfChildComponent (prev);
  43988. }
  43989. }
  43990. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43991. if (next != 0)
  43992. {
  43993. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43994. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43995. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43996. {
  43997. newIndex = getIndexOfChildComponent (next) + 1;
  43998. }
  43999. }
  44000. if (newIndex != currentIndex)
  44001. {
  44002. items.removeValue (tc);
  44003. removeChildComponent (tc);
  44004. addChildComponent (tc, newIndex);
  44005. items.insert (newIndex, tc);
  44006. updateAllItemPositions (true);
  44007. }
  44008. else
  44009. {
  44010. break;
  44011. }
  44012. }
  44013. }
  44014. }
  44015. }
  44016. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  44017. {
  44018. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  44019. if (tc != 0)
  44020. {
  44021. if (isParentOf (tc))
  44022. {
  44023. items.removeValue (tc);
  44024. removeChildComponent (tc);
  44025. updateAllItemPositions (true);
  44026. }
  44027. }
  44028. }
  44029. void Toolbar::itemDropped (const String&, Component*, int, int)
  44030. {
  44031. }
  44032. void Toolbar::mouseDown (const MouseEvent& e)
  44033. {
  44034. if (e.mods.isPopupMenu())
  44035. {
  44036. }
  44037. }
  44038. class ToolbarCustomisationDialog : public DialogWindow
  44039. {
  44040. public:
  44041. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  44042. Toolbar* const toolbar_,
  44043. const int optionFlags)
  44044. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  44045. toolbar (toolbar_)
  44046. {
  44047. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  44048. setResizable (true, true);
  44049. setResizeLimits (400, 300, 1500, 1000);
  44050. positionNearBar();
  44051. }
  44052. ~ToolbarCustomisationDialog()
  44053. {
  44054. setContentComponent (0, true);
  44055. }
  44056. void closeButtonPressed()
  44057. {
  44058. setVisible (false);
  44059. }
  44060. bool canModalEventBeSentToComponent (const Component* comp)
  44061. {
  44062. return toolbar->isParentOf (comp);
  44063. }
  44064. void positionNearBar()
  44065. {
  44066. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  44067. const int tbx = toolbar->getScreenX();
  44068. const int tby = toolbar->getScreenY();
  44069. const int gap = 8;
  44070. int x, y;
  44071. if (toolbar->isVertical())
  44072. {
  44073. y = tby;
  44074. if (tbx > screenSize.getCentreX())
  44075. x = tbx - getWidth() - gap;
  44076. else
  44077. x = tbx + toolbar->getWidth() + gap;
  44078. }
  44079. else
  44080. {
  44081. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  44082. if (tby > screenSize.getCentreY())
  44083. y = tby - getHeight() - gap;
  44084. else
  44085. y = tby + toolbar->getHeight() + gap;
  44086. }
  44087. setTopLeftPosition (x, y);
  44088. }
  44089. private:
  44090. Toolbar* const toolbar;
  44091. class CustomiserPanel : public Component,
  44092. private ComboBoxListener,
  44093. private ButtonListener
  44094. {
  44095. public:
  44096. CustomiserPanel (ToolbarItemFactory& factory_,
  44097. Toolbar* const toolbar_,
  44098. const int optionFlags)
  44099. : factory (factory_),
  44100. toolbar (toolbar_),
  44101. styleBox (0),
  44102. defaultButton (0)
  44103. {
  44104. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  44105. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  44106. | Toolbar::allowIconsWithTextChoice
  44107. | Toolbar::allowTextOnlyChoice)) != 0)
  44108. {
  44109. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  44110. styleBox->setEditableText (false);
  44111. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  44112. styleBox->addItem (TRANS("Show icons only"), 1);
  44113. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  44114. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  44115. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  44116. styleBox->addItem (TRANS("Show descriptions only"), 3);
  44117. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  44118. styleBox->setSelectedId (1);
  44119. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  44120. styleBox->setSelectedId (2);
  44121. else if (toolbar_->getStyle() == Toolbar::textOnly)
  44122. styleBox->setSelectedId (3);
  44123. styleBox->addListener (this);
  44124. }
  44125. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  44126. {
  44127. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  44128. defaultButton->addButtonListener (this);
  44129. }
  44130. addAndMakeVisible (instructions = new Label (String::empty,
  44131. 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.")));
  44132. instructions->setFont (Font (13.0f));
  44133. setSize (500, 300);
  44134. }
  44135. ~CustomiserPanel()
  44136. {
  44137. deleteAllChildren();
  44138. }
  44139. void comboBoxChanged (ComboBox*)
  44140. {
  44141. if (styleBox->getSelectedId() == 1)
  44142. toolbar->setStyle (Toolbar::iconsOnly);
  44143. else if (styleBox->getSelectedId() == 2)
  44144. toolbar->setStyle (Toolbar::iconsWithText);
  44145. else if (styleBox->getSelectedId() == 3)
  44146. toolbar->setStyle (Toolbar::textOnly);
  44147. palette->resized(); // to make it update the styles
  44148. }
  44149. void buttonClicked (Button*)
  44150. {
  44151. toolbar->addDefaultItems (factory);
  44152. }
  44153. void paint (Graphics& g)
  44154. {
  44155. Colour background;
  44156. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  44157. if (dw != 0)
  44158. background = dw->getBackgroundColour();
  44159. g.setColour (background.contrasting().withAlpha (0.3f));
  44160. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  44161. }
  44162. void resized()
  44163. {
  44164. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  44165. if (styleBox != 0)
  44166. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  44167. if (defaultButton != 0)
  44168. {
  44169. defaultButton->changeWidthToFitText (22);
  44170. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  44171. }
  44172. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  44173. }
  44174. private:
  44175. ToolbarItemFactory& factory;
  44176. Toolbar* const toolbar;
  44177. Label* instructions;
  44178. ToolbarItemPalette* palette;
  44179. ComboBox* styleBox;
  44180. TextButton* defaultButton;
  44181. };
  44182. };
  44183. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  44184. {
  44185. setEditingActive (true);
  44186. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  44187. dw.runModalLoop();
  44188. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  44189. setEditingActive (false);
  44190. }
  44191. END_JUCE_NAMESPACE
  44192. /*** End of inlined file: juce_Toolbar.cpp ***/
  44193. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  44194. BEGIN_JUCE_NAMESPACE
  44195. ToolbarItemFactory::ToolbarItemFactory()
  44196. {
  44197. }
  44198. ToolbarItemFactory::~ToolbarItemFactory()
  44199. {
  44200. }
  44201. class ItemDragAndDropOverlayComponent : public Component
  44202. {
  44203. public:
  44204. ItemDragAndDropOverlayComponent()
  44205. : isDragging (false)
  44206. {
  44207. setAlwaysOnTop (true);
  44208. setRepaintsOnMouseActivity (true);
  44209. setMouseCursor (MouseCursor::DraggingHandCursor);
  44210. }
  44211. ~ItemDragAndDropOverlayComponent()
  44212. {
  44213. }
  44214. void paint (Graphics& g)
  44215. {
  44216. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44217. if (isMouseOverOrDragging()
  44218. && tc != 0
  44219. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44220. {
  44221. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  44222. g.drawRect (0, 0, getWidth(), getHeight(),
  44223. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  44224. }
  44225. }
  44226. void mouseDown (const MouseEvent& e)
  44227. {
  44228. isDragging = false;
  44229. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44230. if (tc != 0)
  44231. {
  44232. tc->dragOffsetX = e.x;
  44233. tc->dragOffsetY = e.y;
  44234. }
  44235. }
  44236. void mouseDrag (const MouseEvent& e)
  44237. {
  44238. if (! (isDragging || e.mouseWasClicked()))
  44239. {
  44240. isDragging = true;
  44241. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  44242. if (dnd != 0)
  44243. {
  44244. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  44245. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44246. if (tc != 0)
  44247. {
  44248. tc->isBeingDragged = true;
  44249. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44250. tc->setVisible (false);
  44251. }
  44252. }
  44253. }
  44254. }
  44255. void mouseUp (const MouseEvent&)
  44256. {
  44257. isDragging = false;
  44258. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44259. if (tc != 0)
  44260. {
  44261. tc->isBeingDragged = false;
  44262. Toolbar* const tb = tc->getToolbar();
  44263. if (tb != 0)
  44264. tb->updateAllItemPositions (true);
  44265. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44266. delete tc;
  44267. }
  44268. }
  44269. void parentSizeChanged()
  44270. {
  44271. setBounds (0, 0, getParentWidth(), getParentHeight());
  44272. }
  44273. juce_UseDebuggingNewOperator
  44274. private:
  44275. bool isDragging;
  44276. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  44277. const ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  44278. };
  44279. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  44280. const String& labelText,
  44281. const bool isBeingUsedAsAButton_)
  44282. : Button (labelText),
  44283. itemId (itemId_),
  44284. mode (normalMode),
  44285. toolbarStyle (Toolbar::iconsOnly),
  44286. dragOffsetX (0),
  44287. dragOffsetY (0),
  44288. isActive (true),
  44289. isBeingDragged (false),
  44290. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  44291. {
  44292. // Your item ID can't be 0!
  44293. jassert (itemId_ != 0);
  44294. }
  44295. ToolbarItemComponent::~ToolbarItemComponent()
  44296. {
  44297. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44298. overlayComp = 0;
  44299. }
  44300. Toolbar* ToolbarItemComponent::getToolbar() const
  44301. {
  44302. return dynamic_cast <Toolbar*> (getParentComponent());
  44303. }
  44304. bool ToolbarItemComponent::isToolbarVertical() const
  44305. {
  44306. const Toolbar* const t = getToolbar();
  44307. return t != 0 && t->isVertical();
  44308. }
  44309. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  44310. {
  44311. if (toolbarStyle != newStyle)
  44312. {
  44313. toolbarStyle = newStyle;
  44314. repaint();
  44315. resized();
  44316. }
  44317. }
  44318. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  44319. {
  44320. if (isBeingUsedAsAButton)
  44321. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  44322. isMouseOver, isMouseDown, *this);
  44323. if (toolbarStyle != Toolbar::iconsOnly)
  44324. {
  44325. const int indent = contentArea.getX();
  44326. int y = indent;
  44327. int h = getHeight() - indent * 2;
  44328. if (toolbarStyle == Toolbar::iconsWithText)
  44329. {
  44330. y = contentArea.getBottom() + indent / 2;
  44331. h -= contentArea.getHeight();
  44332. }
  44333. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  44334. getButtonText(), *this);
  44335. }
  44336. if (! contentArea.isEmpty())
  44337. {
  44338. g.saveState();
  44339. g.setOrigin (contentArea.getX(), contentArea.getY());
  44340. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  44341. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  44342. g.restoreState();
  44343. }
  44344. }
  44345. void ToolbarItemComponent::resized()
  44346. {
  44347. if (toolbarStyle != Toolbar::textOnly)
  44348. {
  44349. const int indent = jmin (proportionOfWidth (0.08f),
  44350. proportionOfHeight (0.08f));
  44351. contentArea = Rectangle<int> (indent, indent,
  44352. getWidth() - indent * 2,
  44353. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  44354. : (getHeight() - indent * 2));
  44355. }
  44356. else
  44357. {
  44358. contentArea = Rectangle<int>();
  44359. }
  44360. contentAreaChanged (contentArea);
  44361. }
  44362. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  44363. {
  44364. if (mode != newMode)
  44365. {
  44366. mode = newMode;
  44367. repaint();
  44368. if (mode == normalMode)
  44369. {
  44370. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44371. overlayComp = 0;
  44372. }
  44373. else if (overlayComp == 0)
  44374. {
  44375. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  44376. overlayComp->parentSizeChanged();
  44377. }
  44378. resized();
  44379. }
  44380. }
  44381. END_JUCE_NAMESPACE
  44382. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  44383. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  44384. BEGIN_JUCE_NAMESPACE
  44385. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  44386. Toolbar* const toolbar_)
  44387. : factory (factory_),
  44388. toolbar (toolbar_)
  44389. {
  44390. Component* const itemHolder = new Component();
  44391. Array <int> allIds;
  44392. factory_.getAllToolbarItemIds (allIds);
  44393. for (int i = 0; i < allIds.size(); ++i)
  44394. {
  44395. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  44396. jassert (tc != 0);
  44397. if (tc != 0)
  44398. {
  44399. itemHolder->addAndMakeVisible (tc);
  44400. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  44401. }
  44402. }
  44403. viewport = new Viewport();
  44404. viewport->setViewedComponent (itemHolder);
  44405. addAndMakeVisible (viewport);
  44406. }
  44407. ToolbarItemPalette::~ToolbarItemPalette()
  44408. {
  44409. viewport->getViewedComponent()->deleteAllChildren();
  44410. deleteAllChildren();
  44411. }
  44412. void ToolbarItemPalette::resized()
  44413. {
  44414. viewport->setBoundsInset (BorderSize (1));
  44415. Component* const itemHolder = viewport->getViewedComponent();
  44416. const int indent = 8;
  44417. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44418. const int height = toolbar->getThickness();
  44419. int x = indent;
  44420. int y = indent;
  44421. int maxX = 0;
  44422. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44423. {
  44424. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44425. if (tc != 0)
  44426. {
  44427. tc->setStyle (toolbar->getStyle());
  44428. int preferredSize = 1, minSize = 1, maxSize = 1;
  44429. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44430. {
  44431. if (x + preferredSize > preferredWidth && x > indent)
  44432. {
  44433. x = indent;
  44434. y += height;
  44435. }
  44436. tc->setBounds (x, y, preferredSize, height);
  44437. x += preferredSize + 8;
  44438. maxX = jmax (maxX, x);
  44439. }
  44440. }
  44441. }
  44442. itemHolder->setSize (maxX, y + height + 8);
  44443. }
  44444. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44445. {
  44446. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44447. jassert (tc != 0);
  44448. if (tc != 0)
  44449. {
  44450. tc->setBounds (comp->getBounds());
  44451. tc->setStyle (toolbar->getStyle());
  44452. tc->setEditingMode (comp->getEditingMode());
  44453. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44454. }
  44455. }
  44456. END_JUCE_NAMESPACE
  44457. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  44458. /*** Start of inlined file: juce_TreeView.cpp ***/
  44459. BEGIN_JUCE_NAMESPACE
  44460. class TreeViewContentComponent : public Component,
  44461. public TooltipClient
  44462. {
  44463. public:
  44464. TreeViewContentComponent (TreeView* const owner_)
  44465. : owner (owner_),
  44466. buttonUnderMouse (0),
  44467. isDragging (false)
  44468. {
  44469. }
  44470. ~TreeViewContentComponent()
  44471. {
  44472. deleteAllChildren();
  44473. }
  44474. void mouseDown (const MouseEvent& e)
  44475. {
  44476. updateButtonUnderMouse (e);
  44477. isDragging = false;
  44478. needSelectionOnMouseUp = false;
  44479. Rectangle<int> pos;
  44480. TreeViewItem* const item = findItemAt (e.y, pos);
  44481. if (item == 0)
  44482. return;
  44483. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44484. // as selection clicks)
  44485. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44486. {
  44487. if (e.x >= pos.getX() - owner->getIndentSize())
  44488. item->setOpen (! item->isOpen());
  44489. // (clicks to the left of an open/close button are ignored)
  44490. }
  44491. else
  44492. {
  44493. // mouse-down inside the body of the item..
  44494. if (! owner->isMultiSelectEnabled())
  44495. item->setSelected (true, true);
  44496. else if (item->isSelected())
  44497. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44498. else
  44499. selectBasedOnModifiers (item, e.mods);
  44500. MouseEvent e2 (e);
  44501. e2.x -= pos.getX();
  44502. e2.y -= pos.getY();
  44503. if (e2.x >= 0)
  44504. item->itemClicked (e2);
  44505. }
  44506. }
  44507. void mouseUp (const MouseEvent& e)
  44508. {
  44509. updateButtonUnderMouse (e);
  44510. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44511. {
  44512. Rectangle<int> pos;
  44513. TreeViewItem* const item = findItemAt (e.y, pos);
  44514. if (item != 0)
  44515. selectBasedOnModifiers (item, e.mods);
  44516. }
  44517. }
  44518. void mouseDoubleClick (const MouseEvent& e)
  44519. {
  44520. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44521. {
  44522. Rectangle<int> pos;
  44523. TreeViewItem* const item = findItemAt (e.y, pos);
  44524. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44525. {
  44526. MouseEvent e2 (e);
  44527. e2.x -= pos.getX();
  44528. e2.y -= pos.getY();
  44529. item->itemDoubleClicked (e2);
  44530. }
  44531. }
  44532. }
  44533. void mouseDrag (const MouseEvent& e)
  44534. {
  44535. if (isEnabled()
  44536. && ! (isDragging || e.mouseWasClicked()
  44537. || e.getDistanceFromDragStart() < 5
  44538. || e.mods.isPopupMenu()))
  44539. {
  44540. isDragging = true;
  44541. Rectangle<int> pos;
  44542. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44543. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44544. {
  44545. const String dragDescription (item->getDragSourceDescription());
  44546. if (dragDescription.isNotEmpty())
  44547. {
  44548. DragAndDropContainer* const dragContainer
  44549. = DragAndDropContainer::findParentDragContainerFor (this);
  44550. if (dragContainer != 0)
  44551. {
  44552. pos.setSize (pos.getWidth(), item->itemHeight);
  44553. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44554. dragImage->multiplyAllAlphas (0.6f);
  44555. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44556. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44557. }
  44558. else
  44559. {
  44560. // to be able to do a drag-and-drop operation, the treeview needs to
  44561. // be inside a component which is also a DragAndDropContainer.
  44562. jassertfalse
  44563. }
  44564. }
  44565. }
  44566. }
  44567. }
  44568. void mouseMove (const MouseEvent& e)
  44569. {
  44570. updateButtonUnderMouse (e);
  44571. }
  44572. void mouseExit (const MouseEvent& e)
  44573. {
  44574. updateButtonUnderMouse (e);
  44575. }
  44576. void paint (Graphics& g);
  44577. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44578. void updateComponents()
  44579. {
  44580. const int visibleTop = -getY();
  44581. const int visibleBottom = visibleTop + getParentHeight();
  44582. BitArray itemsToKeep;
  44583. TreeViewItem* item = owner->rootItem;
  44584. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44585. while (item != 0 && y < visibleBottom)
  44586. {
  44587. y += item->itemHeight;
  44588. if (y >= visibleTop)
  44589. {
  44590. const int index = rowComponentIds.indexOf (item->uid);
  44591. if (index < 0)
  44592. {
  44593. Component* const comp = item->createItemComponent();
  44594. if (comp != 0)
  44595. {
  44596. addAndMakeVisible (comp);
  44597. itemsToKeep.setBit (rowComponentItems.size());
  44598. rowComponentItems.add (item);
  44599. rowComponentIds.add (item->uid);
  44600. rowComponents.add (comp);
  44601. }
  44602. }
  44603. else
  44604. {
  44605. itemsToKeep.setBit (index);
  44606. }
  44607. }
  44608. item = item->getNextVisibleItem (true);
  44609. }
  44610. for (int i = rowComponentItems.size(); --i >= 0;)
  44611. {
  44612. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44613. bool keep = false;
  44614. if (isParentOf (comp))
  44615. {
  44616. if (itemsToKeep[i])
  44617. {
  44618. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44619. Rectangle<int> pos (item->getItemPosition (false));
  44620. pos.setSize (pos.getWidth(), item->itemHeight);
  44621. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44622. {
  44623. keep = true;
  44624. comp->setBounds (pos);
  44625. }
  44626. }
  44627. if ((! keep)
  44628. && Component::isMouseButtonDownAnywhere()
  44629. && (comp == Component::getComponentUnderMouse()
  44630. || comp->isParentOf (Component::getComponentUnderMouse())))
  44631. {
  44632. keep = true;
  44633. comp->setSize (0, 0);
  44634. }
  44635. }
  44636. if (! keep)
  44637. {
  44638. delete comp;
  44639. rowComponents.remove (i);
  44640. rowComponentIds.remove (i);
  44641. rowComponentItems.remove (i);
  44642. }
  44643. }
  44644. }
  44645. void updateButtonUnderMouse (const MouseEvent& e)
  44646. {
  44647. TreeViewItem* newItem = 0;
  44648. if (owner->openCloseButtonsVisible)
  44649. {
  44650. Rectangle<int> pos;
  44651. TreeViewItem* item = findItemAt (e.y, pos);
  44652. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44653. {
  44654. newItem = item;
  44655. if (! newItem->mightContainSubItems())
  44656. newItem = 0;
  44657. }
  44658. }
  44659. if (buttonUnderMouse != newItem)
  44660. {
  44661. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44662. {
  44663. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44664. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44665. }
  44666. buttonUnderMouse = newItem;
  44667. if (buttonUnderMouse != 0)
  44668. {
  44669. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44670. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44671. }
  44672. }
  44673. }
  44674. bool isMouseOverButton (TreeViewItem* item) const throw()
  44675. {
  44676. return item == buttonUnderMouse;
  44677. }
  44678. void resized()
  44679. {
  44680. owner->itemsChanged();
  44681. }
  44682. const String getTooltip()
  44683. {
  44684. Rectangle<int> pos;
  44685. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44686. if (item != 0)
  44687. return item->getTooltip();
  44688. return owner->getTooltip();
  44689. }
  44690. juce_UseDebuggingNewOperator
  44691. private:
  44692. TreeView* const owner;
  44693. VoidArray rowComponentItems;
  44694. Array <int> rowComponentIds;
  44695. VoidArray rowComponents;
  44696. TreeViewItem* buttonUnderMouse;
  44697. bool isDragging, needSelectionOnMouseUp;
  44698. TreeViewContentComponent (const TreeViewContentComponent&);
  44699. const TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44700. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44701. {
  44702. TreeViewItem* firstSelected = 0;
  44703. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44704. {
  44705. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44706. jassert (lastSelected != 0);
  44707. int rowStart = firstSelected->getRowNumberInTree();
  44708. int rowEnd = lastSelected->getRowNumberInTree();
  44709. if (rowStart > rowEnd)
  44710. swapVariables (rowStart, rowEnd);
  44711. int ourRow = item->getRowNumberInTree();
  44712. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44713. if (ourRow > otherEnd)
  44714. swapVariables (ourRow, otherEnd);
  44715. for (int i = ourRow; i <= otherEnd; ++i)
  44716. owner->getItemOnRow (i)->setSelected (true, false);
  44717. }
  44718. else
  44719. {
  44720. const bool cmd = modifiers.isCommandDown();
  44721. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44722. }
  44723. }
  44724. bool containsItem (TreeViewItem* const item) const
  44725. {
  44726. for (int i = rowComponentItems.size(); --i >= 0;)
  44727. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44728. return true;
  44729. return false;
  44730. }
  44731. };
  44732. class TreeViewport : public Viewport
  44733. {
  44734. public:
  44735. TreeViewport() throw() {}
  44736. ~TreeViewport() throw() {}
  44737. void updateComponents()
  44738. {
  44739. if (getViewedComponent() != 0)
  44740. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44741. repaint();
  44742. }
  44743. void visibleAreaChanged (int, int, int, int)
  44744. {
  44745. updateComponents();
  44746. }
  44747. juce_UseDebuggingNewOperator
  44748. private:
  44749. TreeViewport (const TreeViewport&);
  44750. const TreeViewport& operator= (const TreeViewport&);
  44751. };
  44752. TreeView::TreeView (const String& componentName)
  44753. : Component (componentName),
  44754. rootItem (0),
  44755. dragInsertPointHighlight (0),
  44756. dragTargetGroupHighlight (0),
  44757. indentSize (24),
  44758. defaultOpenness (false),
  44759. needsRecalculating (true),
  44760. rootItemVisible (true),
  44761. multiSelectEnabled (false),
  44762. openCloseButtonsVisible (true)
  44763. {
  44764. addAndMakeVisible (viewport = new TreeViewport());
  44765. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44766. viewport->setWantsKeyboardFocus (false);
  44767. setWantsKeyboardFocus (true);
  44768. }
  44769. TreeView::~TreeView()
  44770. {
  44771. if (rootItem != 0)
  44772. rootItem->setOwnerView (0);
  44773. deleteAllChildren();
  44774. }
  44775. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44776. {
  44777. if (rootItem != newRootItem)
  44778. {
  44779. if (newRootItem != 0)
  44780. {
  44781. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44782. if (newRootItem->ownerView != 0)
  44783. newRootItem->ownerView->setRootItem (0);
  44784. }
  44785. if (rootItem != 0)
  44786. rootItem->setOwnerView (0);
  44787. rootItem = newRootItem;
  44788. if (newRootItem != 0)
  44789. newRootItem->setOwnerView (this);
  44790. needsRecalculating = true;
  44791. handleAsyncUpdate();
  44792. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44793. {
  44794. rootItem->setOpen (false); // force a re-open
  44795. rootItem->setOpen (true);
  44796. }
  44797. }
  44798. }
  44799. void TreeView::deleteRootItem()
  44800. {
  44801. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44802. setRootItem (0);
  44803. }
  44804. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44805. {
  44806. rootItemVisible = shouldBeVisible;
  44807. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44808. {
  44809. rootItem->setOpen (false); // force a re-open
  44810. rootItem->setOpen (true);
  44811. }
  44812. itemsChanged();
  44813. }
  44814. void TreeView::colourChanged()
  44815. {
  44816. setOpaque (findColour (backgroundColourId).isOpaque());
  44817. repaint();
  44818. }
  44819. void TreeView::setIndentSize (const int newIndentSize)
  44820. {
  44821. if (indentSize != newIndentSize)
  44822. {
  44823. indentSize = newIndentSize;
  44824. resized();
  44825. }
  44826. }
  44827. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44828. {
  44829. if (defaultOpenness != isOpenByDefault)
  44830. {
  44831. defaultOpenness = isOpenByDefault;
  44832. itemsChanged();
  44833. }
  44834. }
  44835. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44836. {
  44837. multiSelectEnabled = canMultiSelect;
  44838. }
  44839. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44840. {
  44841. if (openCloseButtonsVisible != shouldBeVisible)
  44842. {
  44843. openCloseButtonsVisible = shouldBeVisible;
  44844. itemsChanged();
  44845. }
  44846. }
  44847. void TreeView::clearSelectedItems()
  44848. {
  44849. if (rootItem != 0)
  44850. rootItem->deselectAllRecursively();
  44851. }
  44852. int TreeView::getNumSelectedItems() const throw()
  44853. {
  44854. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44855. }
  44856. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44857. {
  44858. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44859. }
  44860. int TreeView::getNumRowsInTree() const
  44861. {
  44862. if (rootItem != 0)
  44863. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44864. return 0;
  44865. }
  44866. TreeViewItem* TreeView::getItemOnRow (int index) const
  44867. {
  44868. if (! rootItemVisible)
  44869. ++index;
  44870. if (rootItem != 0 && index >= 0)
  44871. return rootItem->getItemOnRow (index);
  44872. return 0;
  44873. }
  44874. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44875. {
  44876. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44877. Rectangle<int> pos;
  44878. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44879. }
  44880. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44881. {
  44882. if (rootItem == 0)
  44883. return 0;
  44884. return rootItem->findItemFromIdentifierString (identifierString);
  44885. }
  44886. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44887. {
  44888. XmlElement* e = 0;
  44889. if (rootItem != 0)
  44890. {
  44891. e = rootItem->getOpennessState();
  44892. if (e != 0 && alsoIncludeScrollPosition)
  44893. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44894. }
  44895. return e;
  44896. }
  44897. void TreeView::restoreOpennessState (const XmlElement& newState)
  44898. {
  44899. if (rootItem != 0)
  44900. {
  44901. rootItem->restoreOpennessState (newState);
  44902. if (newState.hasAttribute (T("scrollPos")))
  44903. viewport->setViewPosition (viewport->getViewPositionX(),
  44904. newState.getIntAttribute (T("scrollPos")));
  44905. }
  44906. }
  44907. void TreeView::paint (Graphics& g)
  44908. {
  44909. g.fillAll (findColour (backgroundColourId));
  44910. }
  44911. void TreeView::resized()
  44912. {
  44913. viewport->setBounds (0, 0, getWidth(), getHeight());
  44914. itemsChanged();
  44915. handleAsyncUpdate();
  44916. }
  44917. void TreeView::enablementChanged()
  44918. {
  44919. repaint();
  44920. }
  44921. void TreeView::moveSelectedRow (int delta)
  44922. {
  44923. if (delta == 0)
  44924. return;
  44925. int rowSelected = 0;
  44926. TreeViewItem* const firstSelected = getSelectedItem (0);
  44927. if (firstSelected != 0)
  44928. rowSelected = firstSelected->getRowNumberInTree();
  44929. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44930. for (;;)
  44931. {
  44932. TreeViewItem* item = getItemOnRow (rowSelected);
  44933. if (item != 0)
  44934. {
  44935. if (! item->canBeSelected())
  44936. {
  44937. // if the row we want to highlight doesn't allow it, try skipping
  44938. // to the next item..
  44939. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44940. rowSelected + (delta < 0 ? -1 : 1));
  44941. if (rowSelected != nextRowToTry)
  44942. {
  44943. rowSelected = nextRowToTry;
  44944. continue;
  44945. }
  44946. else
  44947. {
  44948. break;
  44949. }
  44950. }
  44951. item->setSelected (true, true);
  44952. scrollToKeepItemVisible (item);
  44953. }
  44954. break;
  44955. }
  44956. }
  44957. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44958. {
  44959. if (item != 0 && item->ownerView == this)
  44960. {
  44961. handleAsyncUpdate();
  44962. item = item->getDeepestOpenParentItem();
  44963. int y = item->y;
  44964. int viewTop = viewport->getViewPositionY();
  44965. if (y < viewTop)
  44966. {
  44967. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44968. }
  44969. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44970. {
  44971. viewport->setViewPosition (viewport->getViewPositionX(),
  44972. (y + item->itemHeight) - viewport->getViewHeight());
  44973. }
  44974. }
  44975. }
  44976. bool TreeView::keyPressed (const KeyPress& key)
  44977. {
  44978. if (key.isKeyCode (KeyPress::upKey))
  44979. {
  44980. moveSelectedRow (-1);
  44981. }
  44982. else if (key.isKeyCode (KeyPress::downKey))
  44983. {
  44984. moveSelectedRow (1);
  44985. }
  44986. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44987. {
  44988. if (rootItem != 0)
  44989. {
  44990. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44991. if (key.isKeyCode (KeyPress::pageUpKey))
  44992. rowsOnScreen = -rowsOnScreen;
  44993. moveSelectedRow (rowsOnScreen);
  44994. }
  44995. }
  44996. else if (key.isKeyCode (KeyPress::homeKey))
  44997. {
  44998. moveSelectedRow (-0x3fffffff);
  44999. }
  45000. else if (key.isKeyCode (KeyPress::endKey))
  45001. {
  45002. moveSelectedRow (0x3fffffff);
  45003. }
  45004. else if (key.isKeyCode (KeyPress::returnKey))
  45005. {
  45006. TreeViewItem* const firstSelected = getSelectedItem (0);
  45007. if (firstSelected != 0)
  45008. firstSelected->setOpen (! firstSelected->isOpen());
  45009. }
  45010. else if (key.isKeyCode (KeyPress::leftKey))
  45011. {
  45012. TreeViewItem* const firstSelected = getSelectedItem (0);
  45013. if (firstSelected != 0)
  45014. {
  45015. if (firstSelected->isOpen())
  45016. {
  45017. firstSelected->setOpen (false);
  45018. }
  45019. else
  45020. {
  45021. TreeViewItem* parent = firstSelected->parentItem;
  45022. if ((! rootItemVisible) && parent == rootItem)
  45023. parent = 0;
  45024. if (parent != 0)
  45025. {
  45026. parent->setSelected (true, true);
  45027. scrollToKeepItemVisible (parent);
  45028. }
  45029. }
  45030. }
  45031. }
  45032. else if (key.isKeyCode (KeyPress::rightKey))
  45033. {
  45034. TreeViewItem* const firstSelected = getSelectedItem (0);
  45035. if (firstSelected != 0)
  45036. {
  45037. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  45038. moveSelectedRow (1);
  45039. else
  45040. firstSelected->setOpen (true);
  45041. }
  45042. }
  45043. else
  45044. {
  45045. return false;
  45046. }
  45047. return true;
  45048. }
  45049. void TreeView::itemsChanged() throw()
  45050. {
  45051. needsRecalculating = true;
  45052. repaint();
  45053. triggerAsyncUpdate();
  45054. }
  45055. void TreeView::handleAsyncUpdate()
  45056. {
  45057. if (needsRecalculating)
  45058. {
  45059. needsRecalculating = false;
  45060. const ScopedLock sl (nodeAlterationLock);
  45061. if (rootItem != 0)
  45062. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  45063. ((TreeViewport*) viewport)->updateComponents();
  45064. if (rootItem != 0)
  45065. {
  45066. viewport->getViewedComponent()
  45067. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  45068. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  45069. }
  45070. else
  45071. {
  45072. viewport->getViewedComponent()->setSize (0, 0);
  45073. }
  45074. }
  45075. }
  45076. class TreeViewDragInsertPointHighlight : public Component
  45077. {
  45078. public:
  45079. TreeViewDragInsertPointHighlight()
  45080. : lastItem (0)
  45081. {
  45082. setSize (100, 12);
  45083. setAlwaysOnTop (true);
  45084. setInterceptsMouseClicks (false, false);
  45085. }
  45086. ~TreeViewDragInsertPointHighlight() {}
  45087. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  45088. {
  45089. lastItem = item;
  45090. lastIndex = insertIndex;
  45091. const int offset = getHeight() / 2;
  45092. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  45093. }
  45094. void paint (Graphics& g)
  45095. {
  45096. Path p;
  45097. const float h = (float) getHeight();
  45098. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  45099. p.startNewSubPath (h - 2.0f, h / 2.0f);
  45100. p.lineTo ((float) getWidth(), h / 2.0f);
  45101. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45102. g.strokePath (p, PathStrokeType (2.0f));
  45103. }
  45104. TreeViewItem* lastItem;
  45105. int lastIndex;
  45106. };
  45107. class TreeViewDragTargetGroupHighlight : public Component
  45108. {
  45109. public:
  45110. TreeViewDragTargetGroupHighlight()
  45111. {
  45112. setAlwaysOnTop (true);
  45113. setInterceptsMouseClicks (false, false);
  45114. }
  45115. ~TreeViewDragTargetGroupHighlight() {}
  45116. void setTargetPosition (TreeViewItem* const item) throw()
  45117. {
  45118. Rectangle<int> r (item->getItemPosition (true));
  45119. r.setHeight (item->getItemHeight());
  45120. setBounds (r);
  45121. }
  45122. void paint (Graphics& g)
  45123. {
  45124. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45125. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  45126. }
  45127. };
  45128. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  45129. {
  45130. beginDragAutoRepeat (1000 / 30);
  45131. if (dragInsertPointHighlight == 0)
  45132. {
  45133. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  45134. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  45135. }
  45136. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  45137. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  45138. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  45139. ->setTargetPosition (item);
  45140. }
  45141. void TreeView::hideDragHighlight() throw()
  45142. {
  45143. deleteAndZero (dragInsertPointHighlight);
  45144. deleteAndZero (dragTargetGroupHighlight);
  45145. }
  45146. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  45147. const StringArray& files, const String& sourceDescription,
  45148. Component* sourceComponent) const throw()
  45149. {
  45150. insertIndex = 0;
  45151. TreeViewItem* item = getItemAt (y);
  45152. if (item == 0)
  45153. return 0;
  45154. Rectangle<int> itemPos (item->getItemPosition (true));
  45155. insertIndex = item->getIndexInParent();
  45156. const int oldY = y;
  45157. y = itemPos.getY();
  45158. if (item->getNumSubItems() == 0 || ! item->isOpen())
  45159. {
  45160. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45161. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45162. {
  45163. // Check if we're trying to drag into an empty group item..
  45164. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  45165. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  45166. {
  45167. insertIndex = 0;
  45168. x = itemPos.getX() + getIndentSize();
  45169. y = itemPos.getBottom();
  45170. return item;
  45171. }
  45172. }
  45173. }
  45174. if (oldY > itemPos.getCentreY())
  45175. {
  45176. y += item->getItemHeight();
  45177. while (item->isLastOfSiblings() && item->parentItem != 0
  45178. && item->parentItem->parentItem != 0)
  45179. {
  45180. if (x > itemPos.getX())
  45181. break;
  45182. item = item->parentItem;
  45183. itemPos = item->getItemPosition (true);
  45184. insertIndex = item->getIndexInParent();
  45185. }
  45186. ++insertIndex;
  45187. }
  45188. x = itemPos.getX();
  45189. return item->parentItem;
  45190. }
  45191. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45192. {
  45193. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  45194. int insertIndex;
  45195. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45196. if (item != 0)
  45197. {
  45198. if (scrolled || dragInsertPointHighlight == 0
  45199. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  45200. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  45201. {
  45202. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45203. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45204. showDragHighlight (item, insertIndex, x, y);
  45205. else
  45206. hideDragHighlight();
  45207. }
  45208. }
  45209. else
  45210. {
  45211. hideDragHighlight();
  45212. }
  45213. }
  45214. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45215. {
  45216. hideDragHighlight();
  45217. int insertIndex;
  45218. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45219. if (item != 0)
  45220. {
  45221. if (files.size() > 0)
  45222. {
  45223. if (item->isInterestedInFileDrag (files))
  45224. item->filesDropped (files, insertIndex);
  45225. }
  45226. else
  45227. {
  45228. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45229. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  45230. }
  45231. }
  45232. }
  45233. bool TreeView::isInterestedInFileDrag (const StringArray&)
  45234. {
  45235. return true;
  45236. }
  45237. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  45238. {
  45239. fileDragMove (files, x, y);
  45240. }
  45241. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  45242. {
  45243. handleDrag (files, String::empty, 0, x, y);
  45244. }
  45245. void TreeView::fileDragExit (const StringArray&)
  45246. {
  45247. hideDragHighlight();
  45248. }
  45249. void TreeView::filesDropped (const StringArray& files, int x, int y)
  45250. {
  45251. handleDrop (files, String::empty, 0, x, y);
  45252. }
  45253. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45254. {
  45255. return true;
  45256. }
  45257. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45258. {
  45259. itemDragMove (sourceDescription, sourceComponent, x, y);
  45260. }
  45261. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45262. {
  45263. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  45264. }
  45265. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45266. {
  45267. hideDragHighlight();
  45268. }
  45269. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45270. {
  45271. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  45272. }
  45273. void TreeViewContentComponent::paint (Graphics& g)
  45274. {
  45275. if (owner->rootItem != 0)
  45276. {
  45277. owner->handleAsyncUpdate();
  45278. if (! owner->rootItemVisible)
  45279. g.setOrigin (0, -owner->rootItem->itemHeight);
  45280. owner->rootItem->paintRecursively (g, getWidth());
  45281. }
  45282. }
  45283. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  45284. {
  45285. if (owner->rootItem != 0)
  45286. {
  45287. owner->handleAsyncUpdate();
  45288. if (! owner->rootItemVisible)
  45289. y += owner->rootItem->itemHeight;
  45290. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  45291. if (ti != 0)
  45292. itemPosition = ti->getItemPosition (false);
  45293. return ti;
  45294. }
  45295. return 0;
  45296. }
  45297. enum TreeViewOpenness
  45298. {
  45299. opennessDefault = 0,
  45300. opennessClosed = 1,
  45301. opennessOpen = 2
  45302. };
  45303. TreeViewItem::TreeViewItem()
  45304. : ownerView (0),
  45305. parentItem (0),
  45306. y (0),
  45307. itemHeight (0),
  45308. totalHeight (0),
  45309. selected (false),
  45310. redrawNeeded (true),
  45311. drawLinesInside (true),
  45312. drawsInLeftMargin (false),
  45313. openness (opennessDefault)
  45314. {
  45315. static int nextUID = 0;
  45316. uid = nextUID++;
  45317. }
  45318. TreeViewItem::~TreeViewItem()
  45319. {
  45320. }
  45321. const String TreeViewItem::getUniqueName() const
  45322. {
  45323. return String::empty;
  45324. }
  45325. void TreeViewItem::itemOpennessChanged (bool)
  45326. {
  45327. }
  45328. int TreeViewItem::getNumSubItems() const throw()
  45329. {
  45330. return subItems.size();
  45331. }
  45332. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  45333. {
  45334. return subItems [index];
  45335. }
  45336. void TreeViewItem::clearSubItems()
  45337. {
  45338. if (subItems.size() > 0)
  45339. {
  45340. if (ownerView != 0)
  45341. {
  45342. const ScopedLock sl (ownerView->nodeAlterationLock);
  45343. subItems.clear();
  45344. treeHasChanged();
  45345. }
  45346. else
  45347. {
  45348. subItems.clear();
  45349. }
  45350. }
  45351. }
  45352. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  45353. {
  45354. if (newItem != 0)
  45355. {
  45356. newItem->parentItem = this;
  45357. newItem->setOwnerView (ownerView);
  45358. newItem->y = 0;
  45359. newItem->itemHeight = newItem->getItemHeight();
  45360. newItem->totalHeight = 0;
  45361. newItem->itemWidth = newItem->getItemWidth();
  45362. newItem->totalWidth = 0;
  45363. if (ownerView != 0)
  45364. {
  45365. const ScopedLock sl (ownerView->nodeAlterationLock);
  45366. subItems.insert (insertPosition, newItem);
  45367. treeHasChanged();
  45368. if (newItem->isOpen())
  45369. newItem->itemOpennessChanged (true);
  45370. }
  45371. else
  45372. {
  45373. subItems.insert (insertPosition, newItem);
  45374. if (newItem->isOpen())
  45375. newItem->itemOpennessChanged (true);
  45376. }
  45377. }
  45378. }
  45379. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  45380. {
  45381. if (ownerView != 0)
  45382. ownerView->nodeAlterationLock.enter();
  45383. if (((unsigned int) index) < (unsigned int) subItems.size())
  45384. {
  45385. subItems.remove (index, deleteItem);
  45386. treeHasChanged();
  45387. }
  45388. if (ownerView != 0)
  45389. ownerView->nodeAlterationLock.exit();
  45390. }
  45391. bool TreeViewItem::isOpen() const throw()
  45392. {
  45393. if (openness == opennessDefault)
  45394. return ownerView != 0 && ownerView->defaultOpenness;
  45395. else
  45396. return openness == opennessOpen;
  45397. }
  45398. void TreeViewItem::setOpen (const bool shouldBeOpen)
  45399. {
  45400. if (isOpen() != shouldBeOpen)
  45401. {
  45402. openness = shouldBeOpen ? opennessOpen
  45403. : opennessClosed;
  45404. treeHasChanged();
  45405. itemOpennessChanged (isOpen());
  45406. }
  45407. }
  45408. bool TreeViewItem::isSelected() const throw()
  45409. {
  45410. return selected;
  45411. }
  45412. void TreeViewItem::deselectAllRecursively()
  45413. {
  45414. setSelected (false, false);
  45415. for (int i = 0; i < subItems.size(); ++i)
  45416. subItems.getUnchecked(i)->deselectAllRecursively();
  45417. }
  45418. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45419. const bool deselectOtherItemsFirst)
  45420. {
  45421. if (shouldBeSelected && ! canBeSelected())
  45422. return;
  45423. if (deselectOtherItemsFirst)
  45424. getTopLevelItem()->deselectAllRecursively();
  45425. if (shouldBeSelected != selected)
  45426. {
  45427. selected = shouldBeSelected;
  45428. if (ownerView != 0)
  45429. ownerView->repaint();
  45430. itemSelectionChanged (shouldBeSelected);
  45431. }
  45432. }
  45433. void TreeViewItem::paintItem (Graphics&, int, int)
  45434. {
  45435. }
  45436. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45437. {
  45438. ownerView->getLookAndFeel()
  45439. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45440. }
  45441. void TreeViewItem::itemClicked (const MouseEvent&)
  45442. {
  45443. }
  45444. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45445. {
  45446. if (mightContainSubItems())
  45447. setOpen (! isOpen());
  45448. }
  45449. void TreeViewItem::itemSelectionChanged (bool)
  45450. {
  45451. }
  45452. const String TreeViewItem::getTooltip()
  45453. {
  45454. return String::empty;
  45455. }
  45456. const String TreeViewItem::getDragSourceDescription()
  45457. {
  45458. return String::empty;
  45459. }
  45460. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45461. {
  45462. return false;
  45463. }
  45464. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45465. {
  45466. }
  45467. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45468. {
  45469. return false;
  45470. }
  45471. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45472. {
  45473. }
  45474. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45475. {
  45476. const int indentX = getIndentX();
  45477. int width = itemWidth;
  45478. if (ownerView != 0 && width < 0)
  45479. width = ownerView->viewport->getViewWidth() - indentX;
  45480. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  45481. if (relativeToTreeViewTopLeft)
  45482. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45483. r.getY() - ownerView->viewport->getViewPositionY());
  45484. return r;
  45485. }
  45486. void TreeViewItem::treeHasChanged() const throw()
  45487. {
  45488. if (ownerView != 0)
  45489. ownerView->itemsChanged();
  45490. }
  45491. void TreeViewItem::repaintItem() const
  45492. {
  45493. if (ownerView != 0 && areAllParentsOpen())
  45494. {
  45495. const Rectangle<int> r (getItemPosition (true));
  45496. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45497. }
  45498. }
  45499. bool TreeViewItem::areAllParentsOpen() const throw()
  45500. {
  45501. return parentItem == 0
  45502. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45503. }
  45504. void TreeViewItem::updatePositions (int newY)
  45505. {
  45506. y = newY;
  45507. itemHeight = getItemHeight();
  45508. totalHeight = itemHeight;
  45509. itemWidth = getItemWidth();
  45510. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45511. if (isOpen())
  45512. {
  45513. newY += totalHeight;
  45514. for (int i = 0; i < subItems.size(); ++i)
  45515. {
  45516. TreeViewItem* const ti = subItems.getUnchecked(i);
  45517. ti->updatePositions (newY);
  45518. newY += ti->totalHeight;
  45519. totalHeight += ti->totalHeight;
  45520. totalWidth = jmax (totalWidth, ti->totalWidth);
  45521. }
  45522. }
  45523. }
  45524. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45525. {
  45526. TreeViewItem* result = this;
  45527. TreeViewItem* item = this;
  45528. while (item->parentItem != 0)
  45529. {
  45530. item = item->parentItem;
  45531. if (! item->isOpen())
  45532. result = item;
  45533. }
  45534. return result;
  45535. }
  45536. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45537. {
  45538. ownerView = newOwner;
  45539. for (int i = subItems.size(); --i >= 0;)
  45540. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45541. }
  45542. int TreeViewItem::getIndentX() const throw()
  45543. {
  45544. const int indentWidth = ownerView->getIndentSize();
  45545. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45546. if (! ownerView->openCloseButtonsVisible)
  45547. x -= indentWidth;
  45548. TreeViewItem* p = parentItem;
  45549. while (p != 0)
  45550. {
  45551. x += indentWidth;
  45552. p = p->parentItem;
  45553. }
  45554. return x;
  45555. }
  45556. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45557. {
  45558. drawsInLeftMargin = canDrawInLeftMargin;
  45559. }
  45560. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45561. {
  45562. jassert (ownerView != 0);
  45563. if (ownerView == 0)
  45564. return;
  45565. const int indent = getIndentX();
  45566. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45567. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45568. const float halfH = itemHeight * 0.5f;
  45569. int depth = 0;
  45570. TreeViewItem* p = parentItem;
  45571. while (p != 0)
  45572. {
  45573. ++depth;
  45574. p = p->parentItem;
  45575. }
  45576. if (! ownerView->rootItemVisible)
  45577. --depth;
  45578. const int indentWidth = ownerView->getIndentSize();
  45579. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45580. {
  45581. float x = (depth + 0.5f) * indentWidth;
  45582. if (depth >= 0)
  45583. {
  45584. if (parentItem != 0 && parentItem->drawLinesInside)
  45585. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45586. if ((parentItem != 0 && parentItem->drawLinesInside)
  45587. || (parentItem == 0 && drawLinesInside))
  45588. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45589. }
  45590. p = parentItem;
  45591. int d = depth;
  45592. while (p != 0 && --d >= 0)
  45593. {
  45594. x -= (float) indentWidth;
  45595. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45596. && ! p->isLastOfSiblings())
  45597. {
  45598. g.drawLine (x, 0, x, (float) itemHeight);
  45599. }
  45600. p = p->parentItem;
  45601. }
  45602. if (mightContainSubItems())
  45603. {
  45604. g.saveState();
  45605. g.setOrigin (depth * indentWidth, 0);
  45606. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45607. paintOpenCloseButton (g, indentWidth, itemHeight,
  45608. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45609. ->isMouseOverButton (this));
  45610. g.restoreState();
  45611. }
  45612. }
  45613. {
  45614. g.saveState();
  45615. g.setOrigin (indent, 0);
  45616. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45617. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45618. paintItem (g, itemW, itemHeight);
  45619. g.restoreState();
  45620. }
  45621. if (isOpen())
  45622. {
  45623. const Rectangle<int> clip (g.getClipBounds());
  45624. for (int i = 0; i < subItems.size(); ++i)
  45625. {
  45626. TreeViewItem* const ti = subItems.getUnchecked(i);
  45627. const int relY = ti->y - y;
  45628. if (relY >= clip.getBottom())
  45629. break;
  45630. if (relY + ti->totalHeight >= clip.getY())
  45631. {
  45632. g.saveState();
  45633. g.setOrigin (0, relY);
  45634. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45635. ti->paintRecursively (g, width);
  45636. g.restoreState();
  45637. }
  45638. }
  45639. }
  45640. }
  45641. bool TreeViewItem::isLastOfSiblings() const throw()
  45642. {
  45643. return parentItem == 0
  45644. || parentItem->subItems.getLast() == this;
  45645. }
  45646. int TreeViewItem::getIndexInParent() const throw()
  45647. {
  45648. if (parentItem == 0)
  45649. return 0;
  45650. return parentItem->subItems.indexOf (this);
  45651. }
  45652. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45653. {
  45654. return (parentItem == 0) ? this
  45655. : parentItem->getTopLevelItem();
  45656. }
  45657. int TreeViewItem::getNumRows() const throw()
  45658. {
  45659. int num = 1;
  45660. if (isOpen())
  45661. {
  45662. for (int i = subItems.size(); --i >= 0;)
  45663. num += subItems.getUnchecked(i)->getNumRows();
  45664. }
  45665. return num;
  45666. }
  45667. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45668. {
  45669. if (index == 0)
  45670. return this;
  45671. if (index > 0 && isOpen())
  45672. {
  45673. --index;
  45674. for (int i = 0; i < subItems.size(); ++i)
  45675. {
  45676. TreeViewItem* const item = subItems.getUnchecked(i);
  45677. if (index == 0)
  45678. return item;
  45679. const int numRows = item->getNumRows();
  45680. if (numRows > index)
  45681. return item->getItemOnRow (index);
  45682. index -= numRows;
  45683. }
  45684. }
  45685. return 0;
  45686. }
  45687. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45688. {
  45689. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45690. {
  45691. const int h = itemHeight;
  45692. if (targetY < h)
  45693. return this;
  45694. if (isOpen())
  45695. {
  45696. targetY -= h;
  45697. for (int i = 0; i < subItems.size(); ++i)
  45698. {
  45699. TreeViewItem* const ti = subItems.getUnchecked(i);
  45700. if (targetY < ti->totalHeight)
  45701. return ti->findItemRecursively (targetY);
  45702. targetY -= ti->totalHeight;
  45703. }
  45704. }
  45705. }
  45706. return 0;
  45707. }
  45708. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45709. {
  45710. int total = 0;
  45711. if (isSelected())
  45712. ++total;
  45713. for (int i = subItems.size(); --i >= 0;)
  45714. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45715. return total;
  45716. }
  45717. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45718. {
  45719. if (isSelected())
  45720. {
  45721. if (index == 0)
  45722. return this;
  45723. --index;
  45724. }
  45725. if (index >= 0)
  45726. {
  45727. for (int i = 0; i < subItems.size(); ++i)
  45728. {
  45729. TreeViewItem* const item = subItems.getUnchecked(i);
  45730. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45731. if (found != 0)
  45732. return found;
  45733. index -= item->countSelectedItemsRecursively();
  45734. }
  45735. }
  45736. return 0;
  45737. }
  45738. int TreeViewItem::getRowNumberInTree() const throw()
  45739. {
  45740. if (parentItem != 0 && ownerView != 0)
  45741. {
  45742. int n = 1 + parentItem->getRowNumberInTree();
  45743. int ourIndex = parentItem->subItems.indexOf (this);
  45744. jassert (ourIndex >= 0);
  45745. while (--ourIndex >= 0)
  45746. n += parentItem->subItems [ourIndex]->getNumRows();
  45747. if (parentItem->parentItem == 0
  45748. && ! ownerView->rootItemVisible)
  45749. --n;
  45750. return n;
  45751. }
  45752. else
  45753. {
  45754. return 0;
  45755. }
  45756. }
  45757. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45758. {
  45759. drawLinesInside = drawLines;
  45760. }
  45761. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45762. {
  45763. if (recurse && isOpen() && subItems.size() > 0)
  45764. return subItems [0];
  45765. if (parentItem != 0)
  45766. {
  45767. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45768. if (nextIndex >= parentItem->subItems.size())
  45769. return parentItem->getNextVisibleItem (false);
  45770. return parentItem->subItems [nextIndex];
  45771. }
  45772. return 0;
  45773. }
  45774. const String TreeViewItem::getItemIdentifierString() const
  45775. {
  45776. String s;
  45777. if (parentItem != 0)
  45778. s = parentItem->getItemIdentifierString();
  45779. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45780. }
  45781. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45782. {
  45783. const String uid (getUniqueName());
  45784. if (uid == identifierString)
  45785. return this;
  45786. if (identifierString.startsWith (uid + T("/")))
  45787. {
  45788. const String remainingPath (identifierString.substring (uid.length() + 1));
  45789. bool wasOpen = isOpen();
  45790. setOpen (true);
  45791. for (int i = subItems.size(); --i >= 0;)
  45792. {
  45793. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45794. if (item != 0)
  45795. return item;
  45796. }
  45797. setOpen (wasOpen);
  45798. }
  45799. return 0;
  45800. }
  45801. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45802. {
  45803. if (e.hasTagName (T("CLOSED")))
  45804. {
  45805. setOpen (false);
  45806. }
  45807. else if (e.hasTagName (T("OPEN")))
  45808. {
  45809. setOpen (true);
  45810. forEachXmlChildElement (e, n)
  45811. {
  45812. const String id (n->getStringAttribute (T("id")));
  45813. for (int i = 0; i < subItems.size(); ++i)
  45814. {
  45815. TreeViewItem* const ti = subItems.getUnchecked(i);
  45816. if (ti->getUniqueName() == id)
  45817. {
  45818. ti->restoreOpennessState (*n);
  45819. break;
  45820. }
  45821. }
  45822. }
  45823. }
  45824. }
  45825. XmlElement* TreeViewItem::getOpennessState() const throw()
  45826. {
  45827. const String name (getUniqueName());
  45828. if (name.isNotEmpty())
  45829. {
  45830. XmlElement* e;
  45831. if (isOpen())
  45832. {
  45833. e = new XmlElement (T("OPEN"));
  45834. for (int i = 0; i < subItems.size(); ++i)
  45835. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45836. }
  45837. else
  45838. {
  45839. e = new XmlElement (T("CLOSED"));
  45840. }
  45841. e->setAttribute (T("id"), name);
  45842. return e;
  45843. }
  45844. else
  45845. {
  45846. // trying to save the openness for an element that has no name - this won't
  45847. // work because it needs the names to identify what to open.
  45848. jassertfalse
  45849. }
  45850. return 0;
  45851. }
  45852. END_JUCE_NAMESPACE
  45853. /*** End of inlined file: juce_TreeView.cpp ***/
  45854. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45855. BEGIN_JUCE_NAMESPACE
  45856. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45857. : fileList (listToShow)
  45858. {
  45859. }
  45860. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45861. {
  45862. }
  45863. FileBrowserListener::~FileBrowserListener()
  45864. {
  45865. }
  45866. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45867. {
  45868. jassert (listener != 0);
  45869. if (listener != 0)
  45870. listeners.add (listener);
  45871. }
  45872. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45873. {
  45874. listeners.removeValue (listener);
  45875. }
  45876. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45877. {
  45878. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45879. for (int i = listeners.size(); --i >= 0;)
  45880. {
  45881. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  45882. if (deletionWatcher.hasBeenDeleted())
  45883. return;
  45884. i = jmin (i, listeners.size() - 1);
  45885. }
  45886. }
  45887. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45888. {
  45889. if (fileList.getDirectory().exists())
  45890. {
  45891. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45892. for (int i = listeners.size(); --i >= 0;)
  45893. {
  45894. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (file, e);
  45895. if (deletionWatcher.hasBeenDeleted())
  45896. return;
  45897. i = jmin (i, listeners.size() - 1);
  45898. }
  45899. }
  45900. }
  45901. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45902. {
  45903. if (fileList.getDirectory().exists())
  45904. {
  45905. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45906. for (int i = listeners.size(); --i >= 0;)
  45907. {
  45908. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (file);
  45909. if (deletionWatcher.hasBeenDeleted())
  45910. return;
  45911. i = jmin (i, listeners.size() - 1);
  45912. }
  45913. }
  45914. }
  45915. END_JUCE_NAMESPACE
  45916. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45917. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45918. BEGIN_JUCE_NAMESPACE
  45919. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45920. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45921. Time* creationTime, bool* isReadOnly);
  45922. bool juce_findFileNext (void* handle, String& resultFile,
  45923. bool* isDirectory, bool* isHidden, int64* fileSize,
  45924. Time* modTime, Time* creationTime, bool* isReadOnly);
  45925. void juce_findFileClose (void* handle);
  45926. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45927. TimeSliceThread& thread_)
  45928. : fileFilter (fileFilter_),
  45929. thread (thread_),
  45930. includeDirectories (false),
  45931. includeFiles (false),
  45932. ignoreHiddenFiles (true),
  45933. fileFindHandle (0),
  45934. shouldStop (true)
  45935. {
  45936. }
  45937. DirectoryContentsList::~DirectoryContentsList()
  45938. {
  45939. clear();
  45940. }
  45941. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45942. {
  45943. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45944. }
  45945. const File& DirectoryContentsList::getDirectory() const
  45946. {
  45947. return root;
  45948. }
  45949. void DirectoryContentsList::setDirectory (const File& directory,
  45950. const bool includeDirectories_,
  45951. const bool includeFiles_)
  45952. {
  45953. if (directory != root
  45954. || includeDirectories != includeDirectories_
  45955. || includeFiles != includeFiles_)
  45956. {
  45957. clear();
  45958. root = directory;
  45959. includeDirectories = includeDirectories_;
  45960. includeFiles = includeFiles_;
  45961. refresh();
  45962. }
  45963. }
  45964. void DirectoryContentsList::clear()
  45965. {
  45966. shouldStop = true;
  45967. thread.removeTimeSliceClient (this);
  45968. if (fileFindHandle != 0)
  45969. {
  45970. juce_findFileClose (fileFindHandle);
  45971. fileFindHandle = 0;
  45972. }
  45973. if (files.size() > 0)
  45974. {
  45975. files.clear();
  45976. changed();
  45977. }
  45978. }
  45979. void DirectoryContentsList::refresh()
  45980. {
  45981. clear();
  45982. if (root.isDirectory())
  45983. {
  45984. String fileFound;
  45985. bool fileFoundIsDir, isHidden, isReadOnly;
  45986. int64 fileSize;
  45987. Time modTime, creationTime;
  45988. String path (root.getFullPathName());
  45989. if (! path.endsWithChar (File::separator))
  45990. path += File::separator;
  45991. jassert (fileFindHandle == 0);
  45992. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  45993. &fileFoundIsDir,
  45994. &isHidden,
  45995. &fileSize,
  45996. &modTime,
  45997. &creationTime,
  45998. &isReadOnly);
  45999. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  46000. {
  46001. if (addFile (fileFound, fileFoundIsDir, isHidden,
  46002. fileSize, modTime, creationTime, isReadOnly))
  46003. {
  46004. changed();
  46005. }
  46006. }
  46007. shouldStop = false;
  46008. thread.addTimeSliceClient (this);
  46009. }
  46010. }
  46011. int DirectoryContentsList::getNumFiles() const
  46012. {
  46013. return files.size();
  46014. }
  46015. bool DirectoryContentsList::getFileInfo (const int index,
  46016. FileInfo& result) const
  46017. {
  46018. const ScopedLock sl (fileListLock);
  46019. const FileInfo* const info = files [index];
  46020. if (info != 0)
  46021. {
  46022. result = *info;
  46023. return true;
  46024. }
  46025. return false;
  46026. }
  46027. const File DirectoryContentsList::getFile (const int index) const
  46028. {
  46029. const ScopedLock sl (fileListLock);
  46030. const FileInfo* const info = files [index];
  46031. if (info != 0)
  46032. return root.getChildFile (info->filename);
  46033. return File::nonexistent;
  46034. }
  46035. bool DirectoryContentsList::isStillLoading() const
  46036. {
  46037. return fileFindHandle != 0;
  46038. }
  46039. void DirectoryContentsList::changed()
  46040. {
  46041. sendChangeMessage (this);
  46042. }
  46043. bool DirectoryContentsList::useTimeSlice()
  46044. {
  46045. const uint32 startTime = Time::getApproximateMillisecondCounter();
  46046. bool hasChanged = false;
  46047. for (int i = 100; --i >= 0;)
  46048. {
  46049. if (! checkNextFile (hasChanged))
  46050. {
  46051. if (hasChanged)
  46052. changed();
  46053. return false;
  46054. }
  46055. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  46056. break;
  46057. }
  46058. if (hasChanged)
  46059. changed();
  46060. return true;
  46061. }
  46062. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  46063. {
  46064. if (fileFindHandle != 0)
  46065. {
  46066. String fileFound;
  46067. bool fileFoundIsDir, isHidden, isReadOnly;
  46068. int64 fileSize;
  46069. Time modTime, creationTime;
  46070. if (juce_findFileNext (fileFindHandle, fileFound,
  46071. &fileFoundIsDir, &isHidden,
  46072. &fileSize,
  46073. &modTime,
  46074. &creationTime,
  46075. &isReadOnly))
  46076. {
  46077. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  46078. modTime, creationTime, isReadOnly))
  46079. {
  46080. hasChanged = true;
  46081. }
  46082. return true;
  46083. }
  46084. else
  46085. {
  46086. juce_findFileClose (fileFindHandle);
  46087. fileFindHandle = 0;
  46088. }
  46089. }
  46090. return false;
  46091. }
  46092. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  46093. const DirectoryContentsList::FileInfo* const second)
  46094. {
  46095. #if JUCE_WINDOWS
  46096. if (first->isDirectory != second->isDirectory)
  46097. return first->isDirectory ? -1 : 1;
  46098. #endif
  46099. return first->filename.compareIgnoreCase (second->filename);
  46100. }
  46101. bool DirectoryContentsList::addFile (const String& filename,
  46102. const bool isDir,
  46103. const bool isHidden,
  46104. const int64 fileSize,
  46105. const Time& modTime,
  46106. const Time& creationTime,
  46107. const bool isReadOnly)
  46108. {
  46109. if (filename == T("..")
  46110. || filename == T(".")
  46111. || (ignoreHiddenFiles && isHidden))
  46112. return false;
  46113. const File file (root.getChildFile (filename));
  46114. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  46115. && (fileFilter == 0
  46116. || ((! isDir) && fileFilter->isFileSuitable (file))
  46117. || (isDir && fileFilter->isDirectorySuitable (file))))
  46118. {
  46119. ScopedPointer <FileInfo> info (new FileInfo());
  46120. info->filename = filename;
  46121. info->fileSize = fileSize;
  46122. info->modificationTime = modTime;
  46123. info->creationTime = creationTime;
  46124. info->isDirectory = isDir;
  46125. info->isReadOnly = isReadOnly;
  46126. const ScopedLock sl (fileListLock);
  46127. for (int i = files.size(); --i >= 0;)
  46128. if (files.getUnchecked(i)->filename == info->filename)
  46129. return false;
  46130. files.addSorted (*this, info.release());
  46131. return true;
  46132. }
  46133. return false;
  46134. }
  46135. END_JUCE_NAMESPACE
  46136. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  46137. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  46138. BEGIN_JUCE_NAMESPACE
  46139. FileBrowserComponent::FileBrowserComponent (int flags_,
  46140. const File& initialFileOrDirectory,
  46141. const FileFilter* fileFilter_,
  46142. FilePreviewComponent* previewComp_)
  46143. : FileFilter (String::empty),
  46144. fileFilter (fileFilter_),
  46145. flags (flags_),
  46146. previewComp (previewComp_),
  46147. thread ("Juce FileBrowser")
  46148. {
  46149. // You need to specify one or other of the open/save flags..
  46150. jassert ((flags & (saveMode | openMode)) != 0);
  46151. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  46152. // You need to specify at least one of these flags..
  46153. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  46154. String filename;
  46155. if (initialFileOrDirectory == File::nonexistent)
  46156. {
  46157. currentRoot = File::getCurrentWorkingDirectory();
  46158. }
  46159. else if (initialFileOrDirectory.isDirectory())
  46160. {
  46161. currentRoot = initialFileOrDirectory;
  46162. }
  46163. else
  46164. {
  46165. chosenFiles.add (initialFileOrDirectory);
  46166. currentRoot = initialFileOrDirectory.getParentDirectory();
  46167. filename = initialFileOrDirectory.getFileName();
  46168. }
  46169. fileList = new DirectoryContentsList (this, thread);
  46170. if ((flags & useTreeView) != 0)
  46171. {
  46172. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  46173. if ((flags & canSelectMultipleItems) != 0)
  46174. tree->setMultiSelectEnabled (true);
  46175. addAndMakeVisible (tree);
  46176. fileListComponent = tree;
  46177. }
  46178. else
  46179. {
  46180. FileListComponent* const list = new FileListComponent (*fileList);
  46181. list->setOutlineThickness (1);
  46182. if ((flags & canSelectMultipleItems) != 0)
  46183. list->setMultipleSelectionEnabled (true);
  46184. addAndMakeVisible (list);
  46185. fileListComponent = list;
  46186. }
  46187. fileListComponent->addListener (this);
  46188. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  46189. currentPathBox->setEditableText (true);
  46190. StringArray rootNames, rootPaths;
  46191. const BitArray separators (getRoots (rootNames, rootPaths));
  46192. for (int i = 0; i < rootNames.size(); ++i)
  46193. {
  46194. if (separators [i])
  46195. currentPathBox->addSeparator();
  46196. currentPathBox->addItem (rootNames[i], i + 1);
  46197. }
  46198. currentPathBox->addSeparator();
  46199. currentPathBox->addListener (this);
  46200. addAndMakeVisible (filenameBox = new TextEditor());
  46201. filenameBox->setMultiLine (false);
  46202. filenameBox->setSelectAllWhenFocused (true);
  46203. filenameBox->setText (filename, false);
  46204. filenameBox->addListener (this);
  46205. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  46206. Label* label = new Label ("f", TRANS("file:"));
  46207. addAndMakeVisible (label);
  46208. label->attachToComponent (filenameBox, true);
  46209. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  46210. goUpButton->addButtonListener (this);
  46211. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  46212. if (previewComp != 0)
  46213. addAndMakeVisible (previewComp);
  46214. setRoot (currentRoot);
  46215. thread.startThread (4);
  46216. }
  46217. FileBrowserComponent::~FileBrowserComponent()
  46218. {
  46219. if (previewComp != 0)
  46220. removeChildComponent (previewComp);
  46221. deleteAllChildren();
  46222. fileList = 0;
  46223. thread.stopThread (10000);
  46224. }
  46225. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  46226. {
  46227. jassert (newListener != 0)
  46228. if (newListener != 0)
  46229. listeners.add (newListener);
  46230. }
  46231. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  46232. {
  46233. listeners.removeValue (listener);
  46234. }
  46235. bool FileBrowserComponent::isSaveMode() const throw()
  46236. {
  46237. return (flags & saveMode) != 0;
  46238. }
  46239. int FileBrowserComponent::getNumSelectedFiles() const throw()
  46240. {
  46241. if (chosenFiles.size() == 0 && currentFileIsValid())
  46242. return 1;
  46243. return chosenFiles.size();
  46244. }
  46245. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  46246. {
  46247. if (! filenameBox->isReadOnly())
  46248. return currentRoot.getChildFile (filenameBox->getText());
  46249. else
  46250. return chosenFiles[index];
  46251. }
  46252. bool FileBrowserComponent::currentFileIsValid() const
  46253. {
  46254. if (isSaveMode())
  46255. return ! getSelectedFile (0).isDirectory();
  46256. else
  46257. return getSelectedFile (0).exists();
  46258. }
  46259. const File FileBrowserComponent::getHighlightedFile() const throw()
  46260. {
  46261. return fileListComponent->getSelectedFile (0);
  46262. }
  46263. bool FileBrowserComponent::isFileSuitable (const File& file) const
  46264. {
  46265. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  46266. : false;
  46267. }
  46268. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  46269. {
  46270. return true;
  46271. }
  46272. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  46273. {
  46274. if (f.isDirectory())
  46275. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  46276. return (flags & canSelectFiles) != 0 && f.exists()
  46277. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  46278. }
  46279. const File FileBrowserComponent::getRoot() const
  46280. {
  46281. return currentRoot;
  46282. }
  46283. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  46284. {
  46285. if (currentRoot != newRootDirectory)
  46286. {
  46287. fileListComponent->scrollToTop();
  46288. String path (newRootDirectory.getFullPathName());
  46289. if (path.isEmpty())
  46290. path += File::separator;
  46291. StringArray rootNames, rootPaths;
  46292. getRoots (rootNames, rootPaths);
  46293. if (! rootPaths.contains (path, true))
  46294. {
  46295. bool alreadyListed = false;
  46296. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  46297. {
  46298. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  46299. {
  46300. alreadyListed = true;
  46301. break;
  46302. }
  46303. }
  46304. if (! alreadyListed)
  46305. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  46306. }
  46307. }
  46308. currentRoot = newRootDirectory;
  46309. fileList->setDirectory (currentRoot, true, true);
  46310. String currentRootName (currentRoot.getFullPathName());
  46311. if (currentRootName.isEmpty())
  46312. currentRootName += File::separator;
  46313. currentPathBox->setText (currentRootName, true);
  46314. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  46315. && currentRoot.getParentDirectory() != currentRoot);
  46316. }
  46317. void FileBrowserComponent::goUp()
  46318. {
  46319. setRoot (getRoot().getParentDirectory());
  46320. }
  46321. void FileBrowserComponent::refresh()
  46322. {
  46323. fileList->refresh();
  46324. }
  46325. const String FileBrowserComponent::getActionVerb() const
  46326. {
  46327. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  46328. }
  46329. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  46330. {
  46331. return previewComp;
  46332. }
  46333. void FileBrowserComponent::resized()
  46334. {
  46335. getLookAndFeel()
  46336. .layoutFileBrowserComponent (*this, fileListComponent,
  46337. previewComp, currentPathBox,
  46338. filenameBox, goUpButton);
  46339. }
  46340. void FileBrowserComponent::sendListenerChangeMessage()
  46341. {
  46342. ComponentDeletionWatcher deletionWatcher (this);
  46343. if (previewComp != 0)
  46344. previewComp->selectedFileChanged (getSelectedFile (0));
  46345. jassert (! deletionWatcher.hasBeenDeleted());
  46346. for (int i = listeners.size(); --i >= 0;)
  46347. {
  46348. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  46349. if (deletionWatcher.hasBeenDeleted())
  46350. return;
  46351. i = jmin (i, listeners.size() - 1);
  46352. }
  46353. }
  46354. void FileBrowserComponent::selectionChanged()
  46355. {
  46356. StringArray newFilenames;
  46357. bool resetChosenFiles = true;
  46358. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  46359. {
  46360. const File f (fileListComponent->getSelectedFile (i));
  46361. if (isFileOrDirSuitable (f))
  46362. {
  46363. if (resetChosenFiles)
  46364. {
  46365. chosenFiles.clear();
  46366. resetChosenFiles = false;
  46367. }
  46368. chosenFiles.add (f);
  46369. newFilenames.add (f.getRelativePathFrom (getRoot()));
  46370. }
  46371. }
  46372. if (newFilenames.size() > 0)
  46373. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  46374. sendListenerChangeMessage();
  46375. }
  46376. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  46377. {
  46378. ComponentDeletionWatcher deletionWatcher (this);
  46379. for (int i = listeners.size(); --i >= 0;)
  46380. {
  46381. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (f, e);
  46382. if (deletionWatcher.hasBeenDeleted())
  46383. return;
  46384. i = jmin (i, listeners.size() - 1);
  46385. }
  46386. }
  46387. void FileBrowserComponent::fileDoubleClicked (const File& f)
  46388. {
  46389. if (f.isDirectory())
  46390. {
  46391. setRoot (f);
  46392. }
  46393. else
  46394. {
  46395. ComponentDeletionWatcher deletionWatcher (this);
  46396. for (int i = listeners.size(); --i >= 0;)
  46397. {
  46398. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (f);
  46399. if (deletionWatcher.hasBeenDeleted())
  46400. return;
  46401. i = jmin (i, listeners.size() - 1);
  46402. }
  46403. }
  46404. }
  46405. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  46406. {
  46407. #if JUCE_LINUX || JUCE_WINDOWS
  46408. if (key.getModifiers().isCommandDown()
  46409. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  46410. {
  46411. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  46412. fileList->refresh();
  46413. return true;
  46414. }
  46415. #endif
  46416. return false;
  46417. }
  46418. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  46419. {
  46420. sendListenerChangeMessage();
  46421. }
  46422. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  46423. {
  46424. if (filenameBox->getText().containsChar (File::separator))
  46425. {
  46426. const File f (currentRoot.getChildFile (filenameBox->getText()));
  46427. if (f.isDirectory())
  46428. {
  46429. setRoot (f);
  46430. chosenFiles.clear();
  46431. filenameBox->setText (String::empty);
  46432. }
  46433. else
  46434. {
  46435. setRoot (f.getParentDirectory());
  46436. chosenFiles.clear();
  46437. chosenFiles.add (f);
  46438. filenameBox->setText (f.getFileName());
  46439. }
  46440. }
  46441. else
  46442. {
  46443. fileDoubleClicked (getSelectedFile (0));
  46444. }
  46445. }
  46446. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  46447. {
  46448. }
  46449. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46450. {
  46451. if (! isSaveMode())
  46452. selectionChanged();
  46453. }
  46454. void FileBrowserComponent::buttonClicked (Button*)
  46455. {
  46456. goUp();
  46457. }
  46458. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46459. {
  46460. const String newText (currentPathBox->getText().trim().unquoted());
  46461. if (newText.isNotEmpty())
  46462. {
  46463. const int index = currentPathBox->getSelectedId() - 1;
  46464. StringArray rootNames, rootPaths;
  46465. getRoots (rootNames, rootPaths);
  46466. if (rootPaths [index].isNotEmpty())
  46467. {
  46468. setRoot (File (rootPaths [index]));
  46469. }
  46470. else
  46471. {
  46472. File f (newText);
  46473. for (;;)
  46474. {
  46475. if (f.isDirectory())
  46476. {
  46477. setRoot (f);
  46478. break;
  46479. }
  46480. if (f.getParentDirectory() == f)
  46481. break;
  46482. f = f.getParentDirectory();
  46483. }
  46484. }
  46485. }
  46486. }
  46487. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46488. {
  46489. BitArray separators;
  46490. #if JUCE_WINDOWS
  46491. Array<File> roots;
  46492. File::findFileSystemRoots (roots);
  46493. rootPaths.clear();
  46494. for (int i = 0; i < roots.size(); ++i)
  46495. {
  46496. const File& drive = roots.getReference(i);
  46497. String name (drive.getFullPathName());
  46498. rootPaths.add (name);
  46499. if (drive.isOnHardDisk())
  46500. {
  46501. String volume (drive.getVolumeLabel());
  46502. if (volume.isEmpty())
  46503. volume = TRANS("Hard Drive");
  46504. name << " [" << drive.getVolumeLabel() << ']';
  46505. }
  46506. else if (drive.isOnCDRomDrive())
  46507. {
  46508. name << TRANS(" [CD/DVD drive]");
  46509. }
  46510. rootNames.add (name);
  46511. }
  46512. separators.setBit (rootPaths.size());
  46513. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46514. rootNames.add ("Documents");
  46515. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46516. rootNames.add ("Desktop");
  46517. #endif
  46518. #if JUCE_MAC
  46519. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46520. rootNames.add ("Home folder");
  46521. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46522. rootNames.add ("Documents");
  46523. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46524. rootNames.add ("Desktop");
  46525. separators.setBit (rootPaths.size());
  46526. Array <File> volumes;
  46527. File vol ("/Volumes");
  46528. vol.findChildFiles (volumes, File::findDirectories, false);
  46529. for (int i = 0; i < volumes.size(); ++i)
  46530. {
  46531. const File& volume = volumes.getReference(i);
  46532. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  46533. {
  46534. rootPaths.add (volume.getFullPathName());
  46535. rootNames.add (volume.getFileName());
  46536. }
  46537. }
  46538. #endif
  46539. #if JUCE_LINUX
  46540. rootPaths.add ("/");
  46541. rootNames.add ("/");
  46542. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46543. rootNames.add ("Home folder");
  46544. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46545. rootNames.add ("Desktop");
  46546. #endif
  46547. return separators;
  46548. }
  46549. END_JUCE_NAMESPACE
  46550. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46551. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46552. BEGIN_JUCE_NAMESPACE
  46553. FileChooser::FileChooser (const String& chooserBoxTitle,
  46554. const File& currentFileOrDirectory,
  46555. const String& fileFilters,
  46556. const bool useNativeDialogBox_)
  46557. : title (chooserBoxTitle),
  46558. filters (fileFilters),
  46559. startingFile (currentFileOrDirectory),
  46560. useNativeDialogBox (useNativeDialogBox_)
  46561. {
  46562. #if JUCE_LINUX
  46563. useNativeDialogBox = false;
  46564. #endif
  46565. if (! fileFilters.containsNonWhitespaceChars())
  46566. filters = T("*");
  46567. }
  46568. FileChooser::~FileChooser()
  46569. {
  46570. }
  46571. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46572. {
  46573. return showDialog (false, true, false, false, false, previewComponent);
  46574. }
  46575. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46576. {
  46577. return showDialog (false, true, false, false, true, previewComponent);
  46578. }
  46579. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46580. {
  46581. return showDialog (true, true, false, false, true, previewComponent);
  46582. }
  46583. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46584. {
  46585. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46586. }
  46587. bool FileChooser::browseForDirectory()
  46588. {
  46589. return showDialog (true, false, false, false, false, 0);
  46590. }
  46591. const File FileChooser::getResult() const
  46592. {
  46593. // if you've used a multiple-file select, you should use the getResults() method
  46594. // to retrieve all the files that were chosen.
  46595. jassert (results.size() <= 1);
  46596. return results.getFirst();
  46597. }
  46598. const Array<File>& FileChooser::getResults() const
  46599. {
  46600. return results;
  46601. }
  46602. bool FileChooser::showDialog (const bool selectsDirectories,
  46603. const bool selectsFiles,
  46604. const bool isSave,
  46605. const bool warnAboutOverwritingExistingFiles,
  46606. const bool selectMultipleFiles,
  46607. FilePreviewComponent* const previewComponent)
  46608. {
  46609. ScopedPointer <ComponentDeletionWatcher> currentlyFocusedChecker;
  46610. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  46611. if (currentlyFocused != 0)
  46612. currentlyFocusedChecker = new ComponentDeletionWatcher (currentlyFocused);
  46613. results.clear();
  46614. // the preview component needs to be the right size before you pass it in here..
  46615. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46616. && previewComponent->getHeight() > 10));
  46617. #if JUCE_WINDOWS
  46618. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46619. #elif JUCE_MAC
  46620. if (useNativeDialogBox && (previewComponent == 0))
  46621. #else
  46622. if (false)
  46623. #endif
  46624. {
  46625. showPlatformDialog (results, title, startingFile, filters,
  46626. selectsDirectories, selectsFiles, isSave,
  46627. warnAboutOverwritingExistingFiles,
  46628. selectMultipleFiles,
  46629. previewComponent);
  46630. }
  46631. else
  46632. {
  46633. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46634. selectsDirectories ? "*" : String::empty,
  46635. String::empty);
  46636. int flags = isSave ? FileBrowserComponent::saveMode
  46637. : FileBrowserComponent::openMode;
  46638. if (selectsFiles)
  46639. flags |= FileBrowserComponent::canSelectFiles;
  46640. if (selectsDirectories)
  46641. flags |= FileBrowserComponent::canSelectDirectories;
  46642. if (selectMultipleFiles)
  46643. flags |= FileBrowserComponent::canSelectMultipleItems;
  46644. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46645. FileChooserDialogBox box (title, String::empty,
  46646. browserComponent,
  46647. warnAboutOverwritingExistingFiles,
  46648. browserComponent.findColour (AlertWindow::backgroundColourId));
  46649. if (box.show())
  46650. {
  46651. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46652. results.add (browserComponent.getSelectedFile (i));
  46653. }
  46654. }
  46655. if (currentlyFocused != 0 && ! currentlyFocusedChecker->hasBeenDeleted())
  46656. currentlyFocused->grabKeyboardFocus();
  46657. return results.size() > 0;
  46658. }
  46659. FilePreviewComponent::FilePreviewComponent()
  46660. {
  46661. }
  46662. FilePreviewComponent::~FilePreviewComponent()
  46663. {
  46664. }
  46665. END_JUCE_NAMESPACE
  46666. /*** End of inlined file: juce_FileChooser.cpp ***/
  46667. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46668. BEGIN_JUCE_NAMESPACE
  46669. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46670. const String& instructions,
  46671. FileBrowserComponent& chooserComponent,
  46672. const bool warnAboutOverwritingExistingFiles_,
  46673. const Colour& backgroundColour)
  46674. : ResizableWindow (name, backgroundColour, true),
  46675. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46676. {
  46677. content = new ContentComponent();
  46678. content->setName (name);
  46679. content->instructions = instructions;
  46680. content->chooserComponent = &chooserComponent;
  46681. content->addAndMakeVisible (&chooserComponent);
  46682. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46683. content->addAndMakeVisible (content->okButton);
  46684. content->okButton->addButtonListener (this);
  46685. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46686. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46687. content->cancelButton = new TextButton (TRANS("Cancel"));
  46688. content->addAndMakeVisible (content->cancelButton);
  46689. content->cancelButton->addButtonListener (this);
  46690. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46691. setContentComponent (content);
  46692. setResizable (true, true);
  46693. setResizeLimits (300, 300, 1200, 1000);
  46694. content->chooserComponent->addListener (this);
  46695. }
  46696. FileChooserDialogBox::~FileChooserDialogBox()
  46697. {
  46698. content->chooserComponent->removeListener (this);
  46699. }
  46700. bool FileChooserDialogBox::show (int w, int h)
  46701. {
  46702. if (w <= 0)
  46703. {
  46704. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46705. if (previewComp != 0)
  46706. w = 400 + previewComp->getWidth();
  46707. else
  46708. w = 600;
  46709. }
  46710. if (h <= 0)
  46711. h = 500;
  46712. centreWithSize (w, h);
  46713. const bool ok = (runModalLoop() != 0);
  46714. setVisible (false);
  46715. return ok;
  46716. }
  46717. void FileChooserDialogBox::buttonClicked (Button* button)
  46718. {
  46719. if (button == content->okButton)
  46720. {
  46721. if (warnAboutOverwritingExistingFiles
  46722. && content->chooserComponent->isSaveMode()
  46723. && content->chooserComponent->getSelectedFile(0).exists())
  46724. {
  46725. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46726. TRANS("File already exists"),
  46727. TRANS("There's already a file called:\n\n")
  46728. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46729. + T("\n\nAre you sure you want to overwrite it?"),
  46730. TRANS("overwrite"),
  46731. TRANS("cancel")))
  46732. {
  46733. return;
  46734. }
  46735. }
  46736. exitModalState (1);
  46737. }
  46738. else if (button == content->cancelButton)
  46739. closeButtonPressed();
  46740. }
  46741. void FileChooserDialogBox::closeButtonPressed()
  46742. {
  46743. setVisible (false);
  46744. }
  46745. void FileChooserDialogBox::selectionChanged()
  46746. {
  46747. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46748. }
  46749. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46750. {
  46751. }
  46752. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46753. {
  46754. selectionChanged();
  46755. content->okButton->triggerClick();
  46756. }
  46757. FileChooserDialogBox::ContentComponent::ContentComponent()
  46758. {
  46759. setInterceptsMouseClicks (false, true);
  46760. }
  46761. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46762. {
  46763. delete okButton;
  46764. delete cancelButton;
  46765. }
  46766. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46767. {
  46768. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46769. text.draw (g);
  46770. }
  46771. void FileChooserDialogBox::ContentComponent::resized()
  46772. {
  46773. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46774. float left, top, right, bottom;
  46775. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46776. const int y = roundToInt (bottom) + 10;
  46777. const int buttonHeight = 26;
  46778. const int buttonY = getHeight() - buttonHeight - 8;
  46779. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46780. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46781. proportionOfWidth (0.2f), buttonHeight);
  46782. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46783. proportionOfWidth (0.2f), buttonHeight);
  46784. }
  46785. END_JUCE_NAMESPACE
  46786. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46787. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46788. BEGIN_JUCE_NAMESPACE
  46789. FileFilter::FileFilter (const String& filterDescription)
  46790. : description (filterDescription)
  46791. {
  46792. }
  46793. FileFilter::~FileFilter()
  46794. {
  46795. }
  46796. const String& FileFilter::getDescription() const throw()
  46797. {
  46798. return description;
  46799. }
  46800. END_JUCE_NAMESPACE
  46801. /*** End of inlined file: juce_FileFilter.cpp ***/
  46802. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46803. BEGIN_JUCE_NAMESPACE
  46804. Image* juce_createIconForFile (const File& file);
  46805. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46806. : ListBox (String::empty, 0),
  46807. DirectoryContentsDisplayComponent (listToShow)
  46808. {
  46809. setModel (this);
  46810. fileList.addChangeListener (this);
  46811. }
  46812. FileListComponent::~FileListComponent()
  46813. {
  46814. fileList.removeChangeListener (this);
  46815. deleteAllChildren();
  46816. }
  46817. int FileListComponent::getNumSelectedFiles() const
  46818. {
  46819. return getNumSelectedRows();
  46820. }
  46821. const File FileListComponent::getSelectedFile (int index) const
  46822. {
  46823. return fileList.getFile (getSelectedRow (index));
  46824. }
  46825. void FileListComponent::scrollToTop()
  46826. {
  46827. getVerticalScrollBar()->setCurrentRangeStart (0);
  46828. }
  46829. void FileListComponent::changeListenerCallback (void*)
  46830. {
  46831. updateContent();
  46832. if (lastDirectory != fileList.getDirectory())
  46833. {
  46834. lastDirectory = fileList.getDirectory();
  46835. deselectAllRows();
  46836. }
  46837. }
  46838. class FileListItemComponent : public Component,
  46839. public TimeSliceClient,
  46840. public AsyncUpdater
  46841. {
  46842. public:
  46843. FileListItemComponent (FileListComponent& owner_,
  46844. TimeSliceThread& thread_) throw()
  46845. : owner (owner_),
  46846. thread (thread_),
  46847. icon (0)
  46848. {
  46849. }
  46850. ~FileListItemComponent() throw()
  46851. {
  46852. thread.removeTimeSliceClient (this);
  46853. clearIcon();
  46854. }
  46855. void paint (Graphics& g)
  46856. {
  46857. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46858. file.getFileName(),
  46859. icon,
  46860. fileSize, modTime,
  46861. isDirectory, highlighted,
  46862. index);
  46863. }
  46864. void mouseDown (const MouseEvent& e)
  46865. {
  46866. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46867. owner.sendMouseClickMessage (file, e);
  46868. }
  46869. void mouseDoubleClick (const MouseEvent&)
  46870. {
  46871. owner.sendDoubleClickMessage (file);
  46872. }
  46873. void update (const File& root,
  46874. const DirectoryContentsList::FileInfo* const fileInfo,
  46875. const int index_,
  46876. const bool highlighted_) throw()
  46877. {
  46878. thread.removeTimeSliceClient (this);
  46879. if (highlighted_ != highlighted
  46880. || index_ != index)
  46881. {
  46882. index = index_;
  46883. highlighted = highlighted_;
  46884. repaint();
  46885. }
  46886. File newFile;
  46887. String newFileSize;
  46888. String newModTime;
  46889. if (fileInfo != 0)
  46890. {
  46891. newFile = root.getChildFile (fileInfo->filename);
  46892. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46893. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46894. }
  46895. if (newFile != file
  46896. || fileSize != newFileSize
  46897. || modTime != newModTime)
  46898. {
  46899. file = newFile;
  46900. fileSize = newFileSize;
  46901. modTime = newModTime;
  46902. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46903. repaint();
  46904. clearIcon();
  46905. }
  46906. if (file != File::nonexistent
  46907. && icon == 0 && ! isDirectory)
  46908. {
  46909. updateIcon (true);
  46910. if (icon == 0)
  46911. thread.addTimeSliceClient (this);
  46912. }
  46913. }
  46914. bool useTimeSlice()
  46915. {
  46916. updateIcon (false);
  46917. return false;
  46918. }
  46919. void handleAsyncUpdate()
  46920. {
  46921. repaint();
  46922. }
  46923. juce_UseDebuggingNewOperator
  46924. private:
  46925. FileListComponent& owner;
  46926. TimeSliceThread& thread;
  46927. bool highlighted;
  46928. int index;
  46929. File file;
  46930. String fileSize;
  46931. String modTime;
  46932. Image* icon;
  46933. bool isDirectory;
  46934. void clearIcon() throw()
  46935. {
  46936. ImageCache::release (icon);
  46937. icon = 0;
  46938. }
  46939. void updateIcon (const bool onlyUpdateIfCached) throw()
  46940. {
  46941. if (icon == 0)
  46942. {
  46943. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46944. Image* im = ImageCache::getFromHashCode (hashCode);
  46945. if (im == 0 && ! onlyUpdateIfCached)
  46946. {
  46947. im = juce_createIconForFile (file);
  46948. if (im != 0)
  46949. ImageCache::addImageToCache (im, hashCode);
  46950. }
  46951. if (im != 0)
  46952. {
  46953. icon = im;
  46954. triggerAsyncUpdate();
  46955. }
  46956. }
  46957. }
  46958. };
  46959. int FileListComponent::getNumRows()
  46960. {
  46961. return fileList.getNumFiles();
  46962. }
  46963. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46964. {
  46965. }
  46966. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46967. {
  46968. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46969. if (comp == 0)
  46970. {
  46971. delete existingComponentToUpdate;
  46972. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46973. }
  46974. DirectoryContentsList::FileInfo fileInfo;
  46975. if (fileList.getFileInfo (row, fileInfo))
  46976. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46977. else
  46978. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46979. return comp;
  46980. }
  46981. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46982. {
  46983. sendSelectionChangeMessage();
  46984. }
  46985. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46986. {
  46987. }
  46988. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46989. {
  46990. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46991. }
  46992. END_JUCE_NAMESPACE
  46993. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46994. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46995. BEGIN_JUCE_NAMESPACE
  46996. FilenameComponent::FilenameComponent (const String& name,
  46997. const File& currentFile,
  46998. const bool canEditFilename,
  46999. const bool isDirectory,
  47000. const bool isForSaving,
  47001. const String& fileBrowserWildcard,
  47002. const String& enforcedSuffix_,
  47003. const String& textWhenNothingSelected)
  47004. : Component (name),
  47005. maxRecentFiles (30),
  47006. isDir (isDirectory),
  47007. isSaving (isForSaving),
  47008. isFileDragOver (false),
  47009. wildcard (fileBrowserWildcard),
  47010. enforcedSuffix (enforcedSuffix_)
  47011. {
  47012. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  47013. filenameBox->setEditableText (canEditFilename);
  47014. filenameBox->addListener (this);
  47015. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  47016. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  47017. browseButton = 0;
  47018. setBrowseButtonText (T("..."));
  47019. setCurrentFile (currentFile, true);
  47020. }
  47021. FilenameComponent::~FilenameComponent()
  47022. {
  47023. deleteAllChildren();
  47024. }
  47025. void FilenameComponent::paintOverChildren (Graphics& g)
  47026. {
  47027. if (isFileDragOver)
  47028. {
  47029. g.setColour (Colours::red.withAlpha (0.2f));
  47030. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  47031. }
  47032. }
  47033. void FilenameComponent::resized()
  47034. {
  47035. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  47036. }
  47037. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  47038. {
  47039. browseButtonText = newBrowseButtonText;
  47040. lookAndFeelChanged();
  47041. }
  47042. void FilenameComponent::lookAndFeelChanged()
  47043. {
  47044. deleteAndZero (browseButton);
  47045. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  47046. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  47047. resized();
  47048. browseButton->addButtonListener (this);
  47049. }
  47050. void FilenameComponent::setTooltip (const String& newTooltip)
  47051. {
  47052. SettableTooltipClient::setTooltip (newTooltip);
  47053. filenameBox->setTooltip (newTooltip);
  47054. }
  47055. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47056. {
  47057. defaultBrowseFile = newDefaultDirectory;
  47058. }
  47059. void FilenameComponent::buttonClicked (Button*)
  47060. {
  47061. FileChooser fc (TRANS("Choose a new file"),
  47062. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  47063. : getCurrentFile(),
  47064. wildcard);
  47065. if (isDir ? fc.browseForDirectory()
  47066. : (isSaving ? fc.browseForFileToSave (false)
  47067. : fc.browseForFileToOpen()))
  47068. {
  47069. setCurrentFile (fc.getResult(), true);
  47070. }
  47071. }
  47072. void FilenameComponent::comboBoxChanged (ComboBox*)
  47073. {
  47074. setCurrentFile (getCurrentFile(), true);
  47075. }
  47076. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  47077. {
  47078. return true;
  47079. }
  47080. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  47081. {
  47082. isFileDragOver = false;
  47083. repaint();
  47084. const File f (filenames[0]);
  47085. if (f.exists() && (f.isDirectory() == isDir))
  47086. setCurrentFile (f, true);
  47087. }
  47088. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  47089. {
  47090. isFileDragOver = true;
  47091. repaint();
  47092. }
  47093. void FilenameComponent::fileDragExit (const StringArray&)
  47094. {
  47095. isFileDragOver = false;
  47096. repaint();
  47097. }
  47098. const File FilenameComponent::getCurrentFile() const
  47099. {
  47100. File f (filenameBox->getText());
  47101. if (enforcedSuffix.isNotEmpty())
  47102. f = f.withFileExtension (enforcedSuffix);
  47103. return f;
  47104. }
  47105. void FilenameComponent::setCurrentFile (File newFile,
  47106. const bool addToRecentlyUsedList,
  47107. const bool sendChangeNotification)
  47108. {
  47109. if (enforcedSuffix.isNotEmpty())
  47110. newFile = newFile.withFileExtension (enforcedSuffix);
  47111. if (newFile.getFullPathName() != lastFilename)
  47112. {
  47113. lastFilename = newFile.getFullPathName();
  47114. if (addToRecentlyUsedList)
  47115. addRecentlyUsedFile (newFile);
  47116. filenameBox->setText (lastFilename, true);
  47117. if (sendChangeNotification)
  47118. triggerAsyncUpdate();
  47119. }
  47120. }
  47121. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  47122. {
  47123. filenameBox->setEditableText (shouldBeEditable);
  47124. }
  47125. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  47126. {
  47127. StringArray names;
  47128. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  47129. names.add (filenameBox->getItemText (i));
  47130. return names;
  47131. }
  47132. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  47133. {
  47134. if (filenames != getRecentlyUsedFilenames())
  47135. {
  47136. filenameBox->clear();
  47137. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  47138. filenameBox->addItem (filenames[i], i + 1);
  47139. }
  47140. }
  47141. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  47142. {
  47143. maxRecentFiles = jmax (1, newMaximum);
  47144. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  47145. }
  47146. void FilenameComponent::addRecentlyUsedFile (const File& file)
  47147. {
  47148. StringArray files (getRecentlyUsedFilenames());
  47149. if (file.getFullPathName().isNotEmpty())
  47150. {
  47151. files.removeString (file.getFullPathName(), true);
  47152. files.insert (0, file.getFullPathName());
  47153. setRecentlyUsedFilenames (files);
  47154. }
  47155. }
  47156. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  47157. {
  47158. jassert (listener != 0);
  47159. if (listener != 0)
  47160. listeners.add (listener);
  47161. }
  47162. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  47163. {
  47164. listeners.removeValue (listener);
  47165. }
  47166. void FilenameComponent::handleAsyncUpdate()
  47167. {
  47168. for (int i = listeners.size(); --i >= 0;)
  47169. {
  47170. ((FilenameComponentListener*) listeners.getUnchecked (i))->filenameComponentChanged (this);
  47171. i = jmin (i, listeners.size());
  47172. }
  47173. }
  47174. END_JUCE_NAMESPACE
  47175. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  47176. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47177. BEGIN_JUCE_NAMESPACE
  47178. FileSearchPathListComponent::FileSearchPathListComponent()
  47179. {
  47180. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  47181. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  47182. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  47183. listBox->setOutlineThickness (1);
  47184. addAndMakeVisible (addButton = new TextButton ("+"));
  47185. addButton->addButtonListener (this);
  47186. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47187. addAndMakeVisible (removeButton = new TextButton ("-"));
  47188. removeButton->addButtonListener (this);
  47189. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47190. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  47191. changeButton->addButtonListener (this);
  47192. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47193. upButton->addButtonListener (this);
  47194. {
  47195. Path arrowPath;
  47196. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  47197. DrawablePath arrowImage;
  47198. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47199. arrowImage.setPath (arrowPath);
  47200. ((DrawableButton*) upButton)->setImages (&arrowImage);
  47201. }
  47202. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47203. downButton->addButtonListener (this);
  47204. {
  47205. Path arrowPath;
  47206. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  47207. DrawablePath arrowImage;
  47208. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47209. arrowImage.setPath (arrowPath);
  47210. ((DrawableButton*) downButton)->setImages (&arrowImage);
  47211. }
  47212. updateButtons();
  47213. }
  47214. FileSearchPathListComponent::~FileSearchPathListComponent()
  47215. {
  47216. deleteAllChildren();
  47217. }
  47218. void FileSearchPathListComponent::updateButtons() throw()
  47219. {
  47220. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  47221. removeButton->setEnabled (anythingSelected);
  47222. changeButton->setEnabled (anythingSelected);
  47223. upButton->setEnabled (anythingSelected);
  47224. downButton->setEnabled (anythingSelected);
  47225. }
  47226. void FileSearchPathListComponent::changed() throw()
  47227. {
  47228. listBox->updateContent();
  47229. listBox->repaint();
  47230. updateButtons();
  47231. }
  47232. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  47233. {
  47234. if (newPath.toString() != path.toString())
  47235. {
  47236. path = newPath;
  47237. changed();
  47238. }
  47239. }
  47240. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47241. {
  47242. defaultBrowseTarget = newDefaultDirectory;
  47243. }
  47244. int FileSearchPathListComponent::getNumRows()
  47245. {
  47246. return path.getNumPaths();
  47247. }
  47248. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  47249. {
  47250. if (rowIsSelected)
  47251. g.fillAll (findColour (TextEditor::highlightColourId));
  47252. g.setColour (findColour (ListBox::textColourId));
  47253. Font f (height * 0.7f);
  47254. f.setHorizontalScale (0.9f);
  47255. g.setFont (f);
  47256. g.drawText (path [rowNumber].getFullPathName(),
  47257. 4, 0, width - 6, height,
  47258. Justification::centredLeft, true);
  47259. }
  47260. void FileSearchPathListComponent::deleteKeyPressed (int row)
  47261. {
  47262. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  47263. {
  47264. path.remove (row);
  47265. changed();
  47266. }
  47267. }
  47268. void FileSearchPathListComponent::returnKeyPressed (int row)
  47269. {
  47270. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  47271. if (chooser.browseForDirectory())
  47272. {
  47273. path.remove (row);
  47274. path.add (chooser.getResult(), row);
  47275. changed();
  47276. }
  47277. }
  47278. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  47279. {
  47280. returnKeyPressed (row);
  47281. }
  47282. void FileSearchPathListComponent::selectedRowsChanged (int)
  47283. {
  47284. updateButtons();
  47285. }
  47286. void FileSearchPathListComponent::paint (Graphics& g)
  47287. {
  47288. g.fillAll (findColour (backgroundColourId));
  47289. }
  47290. void FileSearchPathListComponent::resized()
  47291. {
  47292. const int buttonH = 22;
  47293. const int buttonY = getHeight() - buttonH - 4;
  47294. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  47295. addButton->setBounds (2, buttonY, buttonH, buttonH);
  47296. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  47297. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  47298. downButton->setSize (buttonH * 2, buttonH);
  47299. upButton->setSize (buttonH * 2, buttonH);
  47300. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  47301. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  47302. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  47303. }
  47304. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  47305. {
  47306. return true;
  47307. }
  47308. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  47309. {
  47310. for (int i = filenames.size(); --i >= 0;)
  47311. {
  47312. const File f (filenames[i]);
  47313. if (f.isDirectory())
  47314. {
  47315. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  47316. path.add (f, row);
  47317. changed();
  47318. }
  47319. }
  47320. }
  47321. void FileSearchPathListComponent::buttonClicked (Button* button)
  47322. {
  47323. const int currentRow = listBox->getSelectedRow();
  47324. if (button == removeButton)
  47325. {
  47326. deleteKeyPressed (currentRow);
  47327. }
  47328. else if (button == addButton)
  47329. {
  47330. File start (defaultBrowseTarget);
  47331. if (start == File::nonexistent)
  47332. start = path [0];
  47333. if (start == File::nonexistent)
  47334. start = File::getCurrentWorkingDirectory();
  47335. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  47336. if (chooser.browseForDirectory())
  47337. {
  47338. path.add (chooser.getResult(), currentRow);
  47339. }
  47340. }
  47341. else if (button == changeButton)
  47342. {
  47343. returnKeyPressed (currentRow);
  47344. }
  47345. else if (button == upButton)
  47346. {
  47347. if (currentRow > 0 && currentRow < path.getNumPaths())
  47348. {
  47349. const File f (path[currentRow]);
  47350. path.remove (currentRow);
  47351. path.add (f, currentRow - 1);
  47352. listBox->selectRow (currentRow - 1);
  47353. }
  47354. }
  47355. else if (button == downButton)
  47356. {
  47357. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  47358. {
  47359. const File f (path[currentRow]);
  47360. path.remove (currentRow);
  47361. path.add (f, currentRow + 1);
  47362. listBox->selectRow (currentRow + 1);
  47363. }
  47364. }
  47365. changed();
  47366. }
  47367. END_JUCE_NAMESPACE
  47368. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47369. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  47370. BEGIN_JUCE_NAMESPACE
  47371. Image* juce_createIconForFile (const File& file);
  47372. class FileListTreeItem : public TreeViewItem,
  47373. public TimeSliceClient,
  47374. public AsyncUpdater,
  47375. public ChangeListener
  47376. {
  47377. public:
  47378. FileListTreeItem (FileTreeComponent& owner_,
  47379. DirectoryContentsList* const parentContentsList_,
  47380. const int indexInContentsList_,
  47381. const File& file_,
  47382. TimeSliceThread& thread_) throw()
  47383. : file (file_),
  47384. owner (owner_),
  47385. parentContentsList (parentContentsList_),
  47386. indexInContentsList (indexInContentsList_),
  47387. subContentsList (0),
  47388. canDeleteSubContentsList (false),
  47389. thread (thread_),
  47390. icon (0)
  47391. {
  47392. DirectoryContentsList::FileInfo fileInfo;
  47393. if (parentContentsList_ != 0
  47394. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  47395. {
  47396. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  47397. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  47398. isDirectory = fileInfo.isDirectory;
  47399. }
  47400. else
  47401. {
  47402. isDirectory = true;
  47403. }
  47404. }
  47405. ~FileListTreeItem() throw()
  47406. {
  47407. thread.removeTimeSliceClient (this);
  47408. clearSubItems();
  47409. ImageCache::release (icon);
  47410. if (canDeleteSubContentsList)
  47411. delete subContentsList;
  47412. }
  47413. bool mightContainSubItems() { return isDirectory; }
  47414. const String getUniqueName() const { return file.getFullPathName(); }
  47415. int getItemHeight() const { return 22; }
  47416. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  47417. void itemOpennessChanged (bool isNowOpen)
  47418. {
  47419. if (isNowOpen)
  47420. {
  47421. clearSubItems();
  47422. isDirectory = file.isDirectory();
  47423. if (isDirectory)
  47424. {
  47425. if (subContentsList == 0)
  47426. {
  47427. jassert (parentContentsList != 0);
  47428. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  47429. l->setDirectory (file, true, true);
  47430. setSubContentsList (l);
  47431. canDeleteSubContentsList = true;
  47432. }
  47433. changeListenerCallback (0);
  47434. }
  47435. }
  47436. }
  47437. void setSubContentsList (DirectoryContentsList* newList) throw()
  47438. {
  47439. jassert (subContentsList == 0);
  47440. subContentsList = newList;
  47441. newList->addChangeListener (this);
  47442. }
  47443. void changeListenerCallback (void*)
  47444. {
  47445. clearSubItems();
  47446. if (isOpen() && subContentsList != 0)
  47447. {
  47448. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  47449. {
  47450. FileListTreeItem* const item
  47451. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  47452. addSubItem (item);
  47453. }
  47454. }
  47455. }
  47456. void paintItem (Graphics& g, int width, int height)
  47457. {
  47458. if (file != File::nonexistent)
  47459. {
  47460. updateIcon (true);
  47461. if (icon == 0)
  47462. thread.addTimeSliceClient (this);
  47463. }
  47464. owner.getLookAndFeel()
  47465. .drawFileBrowserRow (g, width, height,
  47466. file.getFileName(),
  47467. icon,
  47468. fileSize, modTime,
  47469. isDirectory, isSelected(),
  47470. indexInContentsList);
  47471. }
  47472. void itemClicked (const MouseEvent& e)
  47473. {
  47474. owner.sendMouseClickMessage (file, e);
  47475. }
  47476. void itemDoubleClicked (const MouseEvent& e)
  47477. {
  47478. TreeViewItem::itemDoubleClicked (e);
  47479. owner.sendDoubleClickMessage (file);
  47480. }
  47481. void itemSelectionChanged (bool)
  47482. {
  47483. owner.sendSelectionChangeMessage();
  47484. }
  47485. bool useTimeSlice()
  47486. {
  47487. updateIcon (false);
  47488. thread.removeTimeSliceClient (this);
  47489. return false;
  47490. }
  47491. void handleAsyncUpdate()
  47492. {
  47493. owner.repaint();
  47494. }
  47495. const File file;
  47496. juce_UseDebuggingNewOperator
  47497. private:
  47498. FileTreeComponent& owner;
  47499. DirectoryContentsList* parentContentsList;
  47500. int indexInContentsList;
  47501. DirectoryContentsList* subContentsList;
  47502. bool isDirectory, canDeleteSubContentsList;
  47503. TimeSliceThread& thread;
  47504. Image* icon;
  47505. String fileSize;
  47506. String modTime;
  47507. void updateIcon (const bool onlyUpdateIfCached) throw()
  47508. {
  47509. if (icon == 0)
  47510. {
  47511. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47512. Image* im = ImageCache::getFromHashCode (hashCode);
  47513. if (im == 0 && ! onlyUpdateIfCached)
  47514. {
  47515. im = juce_createIconForFile (file);
  47516. if (im != 0)
  47517. ImageCache::addImageToCache (im, hashCode);
  47518. }
  47519. if (im != 0)
  47520. {
  47521. icon = im;
  47522. triggerAsyncUpdate();
  47523. }
  47524. }
  47525. }
  47526. };
  47527. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47528. : DirectoryContentsDisplayComponent (listToShow)
  47529. {
  47530. FileListTreeItem* const root
  47531. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47532. listToShow.getTimeSliceThread());
  47533. root->setSubContentsList (&listToShow);
  47534. setRootItemVisible (false);
  47535. setRootItem (root);
  47536. }
  47537. FileTreeComponent::~FileTreeComponent()
  47538. {
  47539. deleteRootItem();
  47540. }
  47541. const File FileTreeComponent::getSelectedFile (const int index) const
  47542. {
  47543. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47544. if (item != 0)
  47545. return item->file;
  47546. return File::nonexistent;
  47547. }
  47548. void FileTreeComponent::scrollToTop()
  47549. {
  47550. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47551. }
  47552. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47553. {
  47554. dragAndDropDescription = description;
  47555. }
  47556. END_JUCE_NAMESPACE
  47557. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47558. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47559. BEGIN_JUCE_NAMESPACE
  47560. ImagePreviewComponent::ImagePreviewComponent()
  47561. {
  47562. }
  47563. ImagePreviewComponent::~ImagePreviewComponent()
  47564. {
  47565. }
  47566. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47567. {
  47568. const int availableW = proportionOfWidth (0.97f);
  47569. const int availableH = getHeight() - 13 * 4;
  47570. const double scale = jmin (1.0,
  47571. availableW / (double) w,
  47572. availableH / (double) h);
  47573. w = roundToInt (scale * w);
  47574. h = roundToInt (scale * h);
  47575. }
  47576. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47577. {
  47578. if (fileToLoad != file)
  47579. {
  47580. fileToLoad = file;
  47581. startTimer (100);
  47582. }
  47583. }
  47584. void ImagePreviewComponent::timerCallback()
  47585. {
  47586. stopTimer();
  47587. currentThumbnail = 0;
  47588. currentDetails = String::empty;
  47589. repaint();
  47590. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47591. if (in != 0)
  47592. {
  47593. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47594. if (format != 0)
  47595. {
  47596. currentThumbnail = format->decodeImage (*in);
  47597. if (currentThumbnail != 0)
  47598. {
  47599. int w = currentThumbnail->getWidth();
  47600. int h = currentThumbnail->getHeight();
  47601. currentDetails
  47602. << fileToLoad.getFileName() << "\n"
  47603. << format->getFormatName() << "\n"
  47604. << w << " x " << h << " pixels\n"
  47605. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47606. getThumbSize (w, h);
  47607. currentThumbnail = currentThumbnail->createCopy (w, h);
  47608. }
  47609. }
  47610. }
  47611. }
  47612. void ImagePreviewComponent::paint (Graphics& g)
  47613. {
  47614. if (currentThumbnail != 0)
  47615. {
  47616. g.setFont (13.0f);
  47617. int w = currentThumbnail->getWidth();
  47618. int h = currentThumbnail->getHeight();
  47619. getThumbSize (w, h);
  47620. const int numLines = 4;
  47621. const int totalH = 13 * numLines + h + 4;
  47622. const int y = (getHeight() - totalH) / 2;
  47623. g.drawImageWithin (currentThumbnail,
  47624. (getWidth() - w) / 2, y, w, h,
  47625. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47626. false);
  47627. g.drawFittedText (currentDetails,
  47628. 0, y + h + 4, getWidth(), 100,
  47629. Justification::centredTop, numLines);
  47630. }
  47631. }
  47632. END_JUCE_NAMESPACE
  47633. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47634. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47635. BEGIN_JUCE_NAMESPACE
  47636. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47637. const String& directoryWildcardPatterns,
  47638. const String& description_)
  47639. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47640. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47641. {
  47642. parse (fileWildcardPatterns, fileWildcards);
  47643. parse (directoryWildcardPatterns, directoryWildcards);
  47644. }
  47645. WildcardFileFilter::~WildcardFileFilter()
  47646. {
  47647. }
  47648. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47649. {
  47650. return match (file, fileWildcards);
  47651. }
  47652. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47653. {
  47654. return match (file, directoryWildcards);
  47655. }
  47656. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47657. {
  47658. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47659. result.trim();
  47660. result.removeEmptyStrings();
  47661. // special case for *.*, because people use it to mean "any file", but it
  47662. // would actually ignore files with no extension.
  47663. for (int i = result.size(); --i >= 0;)
  47664. if (result[i] == T("*.*"))
  47665. result.set (i, T("*"));
  47666. }
  47667. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47668. {
  47669. const String filename (file.getFileName());
  47670. for (int i = wildcards.size(); --i >= 0;)
  47671. if (filename.matchesWildcard (wildcards[i], true))
  47672. return true;
  47673. return false;
  47674. }
  47675. END_JUCE_NAMESPACE
  47676. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47677. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47678. BEGIN_JUCE_NAMESPACE
  47679. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47680. {
  47681. }
  47682. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47683. {
  47684. }
  47685. // This will sort a set of components, so that they are ordered in terms of
  47686. // left-to-right and then top-to-bottom.
  47687. class ScreenPositionComparator
  47688. {
  47689. public:
  47690. ScreenPositionComparator() {}
  47691. static int compareElements (const Component* const first, const Component* const second) throw()
  47692. {
  47693. int explicitOrder1 = first->getExplicitFocusOrder();
  47694. if (explicitOrder1 <= 0)
  47695. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47696. int explicitOrder2 = second->getExplicitFocusOrder();
  47697. if (explicitOrder2 <= 0)
  47698. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47699. if (explicitOrder1 != explicitOrder2)
  47700. return explicitOrder1 - explicitOrder2;
  47701. const int diff = first->getY() - second->getY();
  47702. return (diff == 0) ? first->getX() - second->getX()
  47703. : diff;
  47704. }
  47705. };
  47706. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47707. {
  47708. if (parent->getNumChildComponents() > 0)
  47709. {
  47710. Array <Component*> localComps;
  47711. ScreenPositionComparator comparator;
  47712. int i;
  47713. for (i = parent->getNumChildComponents(); --i >= 0;)
  47714. {
  47715. Component* const c = parent->getChildComponent (i);
  47716. if (c->isVisible() && c->isEnabled())
  47717. localComps.addSorted (comparator, c);
  47718. }
  47719. for (i = 0; i < localComps.size(); ++i)
  47720. {
  47721. Component* const c = localComps.getUnchecked (i);
  47722. if (c->getWantsKeyboardFocus())
  47723. comps.add (c);
  47724. if (! c->isFocusContainer())
  47725. findAllFocusableComponents (c, comps);
  47726. }
  47727. }
  47728. }
  47729. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47730. {
  47731. Component* focusContainer = current->getParentComponent();
  47732. if (focusContainer != 0)
  47733. {
  47734. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47735. focusContainer = focusContainer->getParentComponent();
  47736. if (focusContainer != 0)
  47737. {
  47738. Array <Component*> comps;
  47739. findAllFocusableComponents (focusContainer, comps);
  47740. if (comps.size() > 0)
  47741. {
  47742. const int index = comps.indexOf (current);
  47743. return comps [(index + comps.size() + delta) % comps.size()];
  47744. }
  47745. }
  47746. }
  47747. return 0;
  47748. }
  47749. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47750. {
  47751. return getIncrementedComponent (current, 1);
  47752. }
  47753. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47754. {
  47755. return getIncrementedComponent (current, -1);
  47756. }
  47757. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47758. {
  47759. Array <Component*> comps;
  47760. if (parentComponent != 0)
  47761. findAllFocusableComponents (parentComponent, comps);
  47762. return comps.getFirst();
  47763. }
  47764. END_JUCE_NAMESPACE
  47765. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47766. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47767. BEGIN_JUCE_NAMESPACE
  47768. bool KeyListener::keyStateChanged (const bool, Component*)
  47769. {
  47770. return false;
  47771. }
  47772. END_JUCE_NAMESPACE
  47773. /*** End of inlined file: juce_KeyListener.cpp ***/
  47774. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47775. BEGIN_JUCE_NAMESPACE
  47776. // N.B. these two includes are put here deliberately to avoid problems with
  47777. // old GCCs failing on long include paths
  47778. const int maxKeys = 3;
  47779. class KeyMappingChangeButton : public Button
  47780. {
  47781. public:
  47782. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47783. const CommandID commandID_,
  47784. const String& keyName,
  47785. const int keyNum_)
  47786. : Button (keyName),
  47787. owner (owner_),
  47788. commandID (commandID_),
  47789. keyNum (keyNum_)
  47790. {
  47791. setWantsKeyboardFocus (false);
  47792. setTriggeredOnMouseDown (keyNum >= 0);
  47793. if (keyNum_ < 0)
  47794. setTooltip (TRANS("adds a new key-mapping"));
  47795. else
  47796. setTooltip (TRANS("click to change this key-mapping"));
  47797. }
  47798. ~KeyMappingChangeButton()
  47799. {
  47800. }
  47801. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47802. {
  47803. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47804. keyNum >= 0 ? getName() : String::empty);
  47805. }
  47806. void clicked()
  47807. {
  47808. if (keyNum >= 0)
  47809. {
  47810. // existing key clicked..
  47811. PopupMenu m;
  47812. m.addItem (1, TRANS("change this key-mapping"));
  47813. m.addSeparator();
  47814. m.addItem (2, TRANS("remove this key-mapping"));
  47815. const int res = m.show();
  47816. if (res == 1)
  47817. {
  47818. owner->assignNewKey (commandID, keyNum);
  47819. }
  47820. else if (res == 2)
  47821. {
  47822. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47823. }
  47824. }
  47825. else
  47826. {
  47827. // + button pressed..
  47828. owner->assignNewKey (commandID, -1);
  47829. }
  47830. }
  47831. void fitToContent (const int h) throw()
  47832. {
  47833. if (keyNum < 0)
  47834. {
  47835. setSize (h, h);
  47836. }
  47837. else
  47838. {
  47839. Font f (h * 0.6f);
  47840. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47841. }
  47842. }
  47843. juce_UseDebuggingNewOperator
  47844. private:
  47845. KeyMappingEditorComponent* const owner;
  47846. const CommandID commandID;
  47847. const int keyNum;
  47848. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47849. const KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47850. };
  47851. class KeyMappingItemComponent : public Component
  47852. {
  47853. public:
  47854. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47855. const CommandID commandID_)
  47856. : owner (owner_),
  47857. commandID (commandID_)
  47858. {
  47859. setInterceptsMouseClicks (false, true);
  47860. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47861. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47862. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47863. {
  47864. KeyMappingChangeButton* const kb
  47865. = new KeyMappingChangeButton (owner_, commandID,
  47866. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47867. kb->setEnabled (! isReadOnly);
  47868. addAndMakeVisible (kb);
  47869. }
  47870. KeyMappingChangeButton* const kb
  47871. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47872. addChildComponent (kb);
  47873. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47874. }
  47875. ~KeyMappingItemComponent()
  47876. {
  47877. deleteAllChildren();
  47878. }
  47879. void paint (Graphics& g)
  47880. {
  47881. g.setFont (getHeight() * 0.7f);
  47882. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47883. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47884. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47885. Justification::centredLeft, true);
  47886. }
  47887. void resized()
  47888. {
  47889. int x = getWidth() - 4;
  47890. for (int i = getNumChildComponents(); --i >= 0;)
  47891. {
  47892. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47893. kb->fitToContent (getHeight() - 2);
  47894. kb->setTopRightPosition (x, 1);
  47895. x -= kb->getWidth() + 5;
  47896. }
  47897. }
  47898. juce_UseDebuggingNewOperator
  47899. private:
  47900. KeyMappingEditorComponent* const owner;
  47901. const CommandID commandID;
  47902. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47903. const KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47904. };
  47905. class KeyMappingTreeViewItem : public TreeViewItem
  47906. {
  47907. public:
  47908. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47909. const CommandID commandID_)
  47910. : owner (owner_),
  47911. commandID (commandID_)
  47912. {
  47913. }
  47914. ~KeyMappingTreeViewItem()
  47915. {
  47916. }
  47917. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47918. bool mightContainSubItems() { return false; }
  47919. int getItemHeight() const { return 20; }
  47920. Component* createItemComponent()
  47921. {
  47922. return new KeyMappingItemComponent (owner, commandID);
  47923. }
  47924. juce_UseDebuggingNewOperator
  47925. private:
  47926. KeyMappingEditorComponent* const owner;
  47927. const CommandID commandID;
  47928. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47929. const KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47930. };
  47931. class KeyCategoryTreeViewItem : public TreeViewItem
  47932. {
  47933. public:
  47934. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47935. const String& name)
  47936. : owner (owner_),
  47937. categoryName (name)
  47938. {
  47939. }
  47940. ~KeyCategoryTreeViewItem()
  47941. {
  47942. }
  47943. const String getUniqueName() const { return categoryName + "_cat"; }
  47944. bool mightContainSubItems() { return true; }
  47945. int getItemHeight() const { return 28; }
  47946. void paintItem (Graphics& g, int width, int height)
  47947. {
  47948. g.setFont (height * 0.6f, Font::bold);
  47949. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47950. g.drawText (categoryName,
  47951. 2, 0, width - 2, height,
  47952. Justification::centredLeft, true);
  47953. }
  47954. void itemOpennessChanged (bool isNowOpen)
  47955. {
  47956. if (isNowOpen)
  47957. {
  47958. if (getNumSubItems() == 0)
  47959. {
  47960. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47961. for (int i = 0; i < commands.size(); ++i)
  47962. {
  47963. if (owner->shouldCommandBeIncluded (commands[i]))
  47964. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47965. }
  47966. }
  47967. }
  47968. else
  47969. {
  47970. clearSubItems();
  47971. }
  47972. }
  47973. juce_UseDebuggingNewOperator
  47974. private:
  47975. KeyMappingEditorComponent* owner;
  47976. String categoryName;
  47977. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47978. const KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47979. };
  47980. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47981. const bool showResetToDefaultButton)
  47982. : mappings (mappingManager)
  47983. {
  47984. jassert (mappingManager != 0); // can't be null!
  47985. mappingManager->addChangeListener (this);
  47986. setLinesDrawnForSubItems (false);
  47987. resetButton = 0;
  47988. if (showResetToDefaultButton)
  47989. {
  47990. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47991. resetButton->addButtonListener (this);
  47992. }
  47993. addAndMakeVisible (tree = new TreeView());
  47994. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47995. tree->setRootItemVisible (false);
  47996. tree->setDefaultOpenness (true);
  47997. tree->setRootItem (this);
  47998. }
  47999. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  48000. {
  48001. mappings->removeChangeListener (this);
  48002. deleteAllChildren();
  48003. }
  48004. bool KeyMappingEditorComponent::mightContainSubItems()
  48005. {
  48006. return true;
  48007. }
  48008. const String KeyMappingEditorComponent::getUniqueName() const
  48009. {
  48010. return T("keys");
  48011. }
  48012. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  48013. const Colour& textColour)
  48014. {
  48015. setColour (backgroundColourId, mainBackground);
  48016. setColour (textColourId, textColour);
  48017. tree->setColour (TreeView::backgroundColourId, mainBackground);
  48018. }
  48019. void KeyMappingEditorComponent::parentHierarchyChanged()
  48020. {
  48021. changeListenerCallback (0);
  48022. }
  48023. void KeyMappingEditorComponent::resized()
  48024. {
  48025. int h = getHeight();
  48026. if (resetButton != 0)
  48027. {
  48028. const int buttonHeight = 20;
  48029. h -= buttonHeight + 8;
  48030. int x = getWidth() - 8;
  48031. const int y = h + 6;
  48032. resetButton->changeWidthToFitText (buttonHeight);
  48033. resetButton->setTopRightPosition (x, y);
  48034. }
  48035. tree->setBounds (0, 0, getWidth(), h);
  48036. }
  48037. void KeyMappingEditorComponent::buttonClicked (Button* button)
  48038. {
  48039. if (button == resetButton)
  48040. {
  48041. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  48042. TRANS("Reset to defaults"),
  48043. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  48044. TRANS("Reset")))
  48045. {
  48046. mappings->resetToDefaultMappings();
  48047. }
  48048. }
  48049. }
  48050. void KeyMappingEditorComponent::changeListenerCallback (void*)
  48051. {
  48052. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  48053. clearSubItems();
  48054. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  48055. for (int i = 0; i < categories.size(); ++i)
  48056. {
  48057. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  48058. int count = 0;
  48059. for (int j = 0; j < commands.size(); ++j)
  48060. if (shouldCommandBeIncluded (commands[j]))
  48061. ++count;
  48062. if (count > 0)
  48063. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  48064. }
  48065. if (openness != 0)
  48066. tree->restoreOpennessState (*openness);
  48067. }
  48068. class KeyEntryWindow : public AlertWindow
  48069. {
  48070. public:
  48071. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  48072. : AlertWindow (TRANS("New key-mapping"),
  48073. TRANS("Please press a key combination now..."),
  48074. AlertWindow::NoIcon),
  48075. owner (owner_)
  48076. {
  48077. addButton (TRANS("ok"), 1);
  48078. addButton (TRANS("cancel"), 0);
  48079. // (avoid return + escape keys getting processed by the buttons..)
  48080. for (int i = getNumChildComponents(); --i >= 0;)
  48081. getChildComponent (i)->setWantsKeyboardFocus (false);
  48082. setWantsKeyboardFocus (true);
  48083. grabKeyboardFocus();
  48084. }
  48085. ~KeyEntryWindow()
  48086. {
  48087. }
  48088. bool keyPressed (const KeyPress& key)
  48089. {
  48090. lastPress = key;
  48091. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  48092. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  48093. if (previousCommand != 0)
  48094. {
  48095. message << "\n\n"
  48096. << TRANS("(Currently assigned to \"")
  48097. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  48098. << "\")";
  48099. }
  48100. setMessage (message);
  48101. return true;
  48102. }
  48103. bool keyStateChanged (const bool)
  48104. {
  48105. return true;
  48106. }
  48107. KeyPress lastPress;
  48108. juce_UseDebuggingNewOperator
  48109. private:
  48110. KeyMappingEditorComponent* owner;
  48111. KeyEntryWindow (const KeyEntryWindow&);
  48112. const KeyEntryWindow& operator= (const KeyEntryWindow&);
  48113. };
  48114. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  48115. {
  48116. KeyEntryWindow entryWindow (this);
  48117. if (entryWindow.runModalLoop() != 0)
  48118. {
  48119. entryWindow.setVisible (false);
  48120. if (entryWindow.lastPress.isValid())
  48121. {
  48122. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  48123. if (previousCommand != 0)
  48124. {
  48125. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  48126. TRANS("Change key-mapping"),
  48127. TRANS("This key is already assigned to the command \"")
  48128. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  48129. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  48130. TRANS("re-assign"),
  48131. TRANS("cancel")))
  48132. {
  48133. return;
  48134. }
  48135. }
  48136. mappings->removeKeyPress (entryWindow.lastPress);
  48137. if (index >= 0)
  48138. mappings->removeKeyPress (commandID, index);
  48139. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  48140. }
  48141. }
  48142. }
  48143. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  48144. {
  48145. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48146. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  48147. }
  48148. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  48149. {
  48150. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48151. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  48152. }
  48153. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  48154. {
  48155. return key.getTextDescription();
  48156. }
  48157. END_JUCE_NAMESPACE
  48158. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  48159. /*** Start of inlined file: juce_KeyPress.cpp ***/
  48160. BEGIN_JUCE_NAMESPACE
  48161. KeyPress::KeyPress() throw()
  48162. : keyCode (0),
  48163. mods (0),
  48164. textCharacter (0)
  48165. {
  48166. }
  48167. KeyPress::KeyPress (const int keyCode_,
  48168. const ModifierKeys& mods_,
  48169. const juce_wchar textCharacter_) throw()
  48170. : keyCode (keyCode_),
  48171. mods (mods_),
  48172. textCharacter (textCharacter_)
  48173. {
  48174. }
  48175. KeyPress::KeyPress (const int keyCode_) throw()
  48176. : keyCode (keyCode_),
  48177. textCharacter (0)
  48178. {
  48179. }
  48180. KeyPress::KeyPress (const KeyPress& other) throw()
  48181. : keyCode (other.keyCode),
  48182. mods (other.mods),
  48183. textCharacter (other.textCharacter)
  48184. {
  48185. }
  48186. const KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  48187. {
  48188. keyCode = other.keyCode;
  48189. mods = other.mods;
  48190. textCharacter = other.textCharacter;
  48191. return *this;
  48192. }
  48193. bool KeyPress::operator== (const KeyPress& other) const throw()
  48194. {
  48195. return mods.getRawFlags() == other.mods.getRawFlags()
  48196. && (textCharacter == other.textCharacter
  48197. || textCharacter == 0
  48198. || other.textCharacter == 0)
  48199. && (keyCode == other.keyCode
  48200. || (keyCode < 256
  48201. && other.keyCode < 256
  48202. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  48203. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  48204. }
  48205. bool KeyPress::operator!= (const KeyPress& other) const throw()
  48206. {
  48207. return ! operator== (other);
  48208. }
  48209. bool KeyPress::isCurrentlyDown() const throw()
  48210. {
  48211. return isKeyCurrentlyDown (keyCode)
  48212. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  48213. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  48214. }
  48215. struct KeyNameAndCode
  48216. {
  48217. const char* name;
  48218. int code;
  48219. };
  48220. static const KeyNameAndCode keyNameTranslations[] =
  48221. {
  48222. { "spacebar", KeyPress::spaceKey },
  48223. { "return", KeyPress::returnKey },
  48224. { "escape", KeyPress::escapeKey },
  48225. { "backspace", KeyPress::backspaceKey },
  48226. { "cursor left", KeyPress::leftKey },
  48227. { "cursor right", KeyPress::rightKey },
  48228. { "cursor up", KeyPress::upKey },
  48229. { "cursor down", KeyPress::downKey },
  48230. { "page up", KeyPress::pageUpKey },
  48231. { "page down", KeyPress::pageDownKey },
  48232. { "home", KeyPress::homeKey },
  48233. { "end", KeyPress::endKey },
  48234. { "delete", KeyPress::deleteKey },
  48235. { "insert", KeyPress::insertKey },
  48236. { "tab", KeyPress::tabKey },
  48237. { "play", KeyPress::playKey },
  48238. { "stop", KeyPress::stopKey },
  48239. { "fast forward", KeyPress::fastForwardKey },
  48240. { "rewind", KeyPress::rewindKey }
  48241. };
  48242. static const tchar* const numberPadPrefix = T("numpad ");
  48243. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  48244. {
  48245. int modifiers = 0;
  48246. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  48247. || desc.containsWholeWordIgnoreCase (T("control"))
  48248. || desc.containsWholeWordIgnoreCase (T("ctl")))
  48249. modifiers |= ModifierKeys::ctrlModifier;
  48250. if (desc.containsWholeWordIgnoreCase (T("shift"))
  48251. || desc.containsWholeWordIgnoreCase (T("shft")))
  48252. modifiers |= ModifierKeys::shiftModifier;
  48253. if (desc.containsWholeWordIgnoreCase (T("alt"))
  48254. || desc.containsWholeWordIgnoreCase (T("option")))
  48255. modifiers |= ModifierKeys::altModifier;
  48256. if (desc.containsWholeWordIgnoreCase (T("command"))
  48257. || desc.containsWholeWordIgnoreCase (T("cmd")))
  48258. modifiers |= ModifierKeys::commandModifier;
  48259. int key = 0;
  48260. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48261. {
  48262. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  48263. {
  48264. key = keyNameTranslations[i].code;
  48265. break;
  48266. }
  48267. }
  48268. if (key == 0)
  48269. {
  48270. // see if it's a numpad key..
  48271. if (desc.containsIgnoreCase (numberPadPrefix))
  48272. {
  48273. const tchar lastChar = desc.trimEnd().getLastCharacter();
  48274. if (lastChar >= T('0') && lastChar <= T('9'))
  48275. key = numberPad0 + lastChar - T('0');
  48276. else if (lastChar == T('+'))
  48277. key = numberPadAdd;
  48278. else if (lastChar == T('-'))
  48279. key = numberPadSubtract;
  48280. else if (lastChar == T('*'))
  48281. key = numberPadMultiply;
  48282. else if (lastChar == T('/'))
  48283. key = numberPadDivide;
  48284. else if (lastChar == T('.'))
  48285. key = numberPadDecimalPoint;
  48286. else if (lastChar == T('='))
  48287. key = numberPadEquals;
  48288. else if (desc.endsWith (T("separator")))
  48289. key = numberPadSeparator;
  48290. else if (desc.endsWith (T("delete")))
  48291. key = numberPadDelete;
  48292. }
  48293. if (key == 0)
  48294. {
  48295. // see if it's a function key..
  48296. for (int i = 1; i <= 12; ++i)
  48297. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  48298. key = F1Key + i - 1;
  48299. if (key == 0)
  48300. {
  48301. // give up and use the hex code..
  48302. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  48303. .toLowerCase()
  48304. .retainCharacters (T("0123456789abcdef"))
  48305. .getHexValue32();
  48306. if (hexCode > 0)
  48307. key = hexCode;
  48308. else
  48309. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  48310. }
  48311. }
  48312. }
  48313. return KeyPress (key, ModifierKeys (modifiers), 0);
  48314. }
  48315. const String KeyPress::getTextDescription() const throw()
  48316. {
  48317. String desc;
  48318. if (keyCode > 0)
  48319. {
  48320. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  48321. // want to store it as being a slash, not shift+whatever.
  48322. if (textCharacter == T('/'))
  48323. return "/";
  48324. if (mods.isCtrlDown())
  48325. desc << "ctrl + ";
  48326. if (mods.isShiftDown())
  48327. desc << "shift + ";
  48328. #if JUCE_MAC
  48329. // only do this on the mac, because on Windows ctrl and command are the same,
  48330. // and this would get confusing
  48331. if (mods.isCommandDown())
  48332. desc << "command + ";
  48333. if (mods.isAltDown())
  48334. desc << "option + ";
  48335. #else
  48336. if (mods.isAltDown())
  48337. desc << "alt + ";
  48338. #endif
  48339. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48340. if (keyCode == keyNameTranslations[i].code)
  48341. return desc + keyNameTranslations[i].name;
  48342. if (keyCode >= F1Key && keyCode <= F16Key)
  48343. desc << 'F' << (1 + keyCode - F1Key);
  48344. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  48345. desc << numberPadPrefix << (keyCode - numberPad0);
  48346. else if (keyCode >= 33 && keyCode < 176)
  48347. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  48348. else if (keyCode == numberPadAdd)
  48349. desc << numberPadPrefix << '+';
  48350. else if (keyCode == numberPadSubtract)
  48351. desc << numberPadPrefix << '-';
  48352. else if (keyCode == numberPadMultiply)
  48353. desc << numberPadPrefix << '*';
  48354. else if (keyCode == numberPadDivide)
  48355. desc << numberPadPrefix << '/';
  48356. else if (keyCode == numberPadSeparator)
  48357. desc << numberPadPrefix << "separator";
  48358. else if (keyCode == numberPadDecimalPoint)
  48359. desc << numberPadPrefix << '.';
  48360. else if (keyCode == numberPadDelete)
  48361. desc << numberPadPrefix << "delete";
  48362. else
  48363. desc << '#' << String::toHexString (keyCode);
  48364. }
  48365. return desc;
  48366. }
  48367. END_JUCE_NAMESPACE
  48368. /*** End of inlined file: juce_KeyPress.cpp ***/
  48369. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  48370. BEGIN_JUCE_NAMESPACE
  48371. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  48372. : commandManager (commandManager_)
  48373. {
  48374. // A manager is needed to get the descriptions of commands, and will be called when
  48375. // a command is invoked. So you can't leave this null..
  48376. jassert (commandManager_ != 0);
  48377. Desktop::getInstance().addFocusChangeListener (this);
  48378. }
  48379. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  48380. : commandManager (other.commandManager)
  48381. {
  48382. Desktop::getInstance().addFocusChangeListener (this);
  48383. }
  48384. KeyPressMappingSet::~KeyPressMappingSet()
  48385. {
  48386. Desktop::getInstance().removeFocusChangeListener (this);
  48387. }
  48388. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  48389. {
  48390. for (int i = 0; i < mappings.size(); ++i)
  48391. if (mappings.getUnchecked(i)->commandID == commandID)
  48392. return mappings.getUnchecked (i)->keypresses;
  48393. return Array <KeyPress> ();
  48394. }
  48395. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  48396. const KeyPress& newKeyPress,
  48397. int insertIndex) throw()
  48398. {
  48399. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  48400. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  48401. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  48402. && ! newKeyPress.getModifiers().isShiftDown()));
  48403. if (findCommandForKeyPress (newKeyPress) != commandID)
  48404. {
  48405. removeKeyPress (newKeyPress);
  48406. if (newKeyPress.isValid())
  48407. {
  48408. for (int i = mappings.size(); --i >= 0;)
  48409. {
  48410. if (mappings.getUnchecked(i)->commandID == commandID)
  48411. {
  48412. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  48413. sendChangeMessage (this);
  48414. return;
  48415. }
  48416. }
  48417. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48418. if (ci != 0)
  48419. {
  48420. CommandMapping* const cm = new CommandMapping();
  48421. cm->commandID = commandID;
  48422. cm->keypresses.add (newKeyPress);
  48423. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  48424. mappings.add (cm);
  48425. sendChangeMessage (this);
  48426. }
  48427. }
  48428. }
  48429. }
  48430. void KeyPressMappingSet::resetToDefaultMappings() throw()
  48431. {
  48432. mappings.clear();
  48433. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  48434. {
  48435. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  48436. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48437. {
  48438. addKeyPress (ci->commandID,
  48439. ci->defaultKeypresses.getReference (j));
  48440. }
  48441. }
  48442. sendChangeMessage (this);
  48443. }
  48444. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  48445. {
  48446. clearAllKeyPresses (commandID);
  48447. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48448. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48449. {
  48450. addKeyPress (ci->commandID,
  48451. ci->defaultKeypresses.getReference (j));
  48452. }
  48453. }
  48454. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48455. {
  48456. if (mappings.size() > 0)
  48457. {
  48458. sendChangeMessage (this);
  48459. mappings.clear();
  48460. }
  48461. }
  48462. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48463. {
  48464. for (int i = mappings.size(); --i >= 0;)
  48465. {
  48466. if (mappings.getUnchecked(i)->commandID == commandID)
  48467. {
  48468. mappings.remove (i);
  48469. sendChangeMessage (this);
  48470. }
  48471. }
  48472. }
  48473. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48474. {
  48475. if (keypress.isValid())
  48476. {
  48477. for (int i = mappings.size(); --i >= 0;)
  48478. {
  48479. CommandMapping* const cm = mappings.getUnchecked(i);
  48480. for (int j = cm->keypresses.size(); --j >= 0;)
  48481. {
  48482. if (keypress == cm->keypresses [j])
  48483. {
  48484. cm->keypresses.remove (j);
  48485. sendChangeMessage (this);
  48486. }
  48487. }
  48488. }
  48489. }
  48490. }
  48491. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48492. const int keyPressIndex) throw()
  48493. {
  48494. for (int i = mappings.size(); --i >= 0;)
  48495. {
  48496. if (mappings.getUnchecked(i)->commandID == commandID)
  48497. {
  48498. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48499. sendChangeMessage (this);
  48500. break;
  48501. }
  48502. }
  48503. }
  48504. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48505. {
  48506. for (int i = 0; i < mappings.size(); ++i)
  48507. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48508. return mappings.getUnchecked(i)->commandID;
  48509. return 0;
  48510. }
  48511. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48512. const KeyPress& keyPress) const throw()
  48513. {
  48514. for (int i = mappings.size(); --i >= 0;)
  48515. if (mappings.getUnchecked(i)->commandID == commandID)
  48516. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48517. return false;
  48518. }
  48519. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48520. const KeyPress& key,
  48521. const bool isKeyDown,
  48522. const int millisecsSinceKeyPressed,
  48523. Component* const originatingComponent) const
  48524. {
  48525. ApplicationCommandTarget::InvocationInfo info (commandID);
  48526. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48527. info.isKeyDown = isKeyDown;
  48528. info.keyPress = key;
  48529. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48530. info.originatingComponent = originatingComponent;
  48531. commandManager->invoke (info, false);
  48532. }
  48533. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48534. {
  48535. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48536. {
  48537. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48538. {
  48539. // if the XML was created as a set of differences from the default mappings,
  48540. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48541. resetToDefaultMappings();
  48542. }
  48543. else
  48544. {
  48545. // if the XML was created calling createXml (false), then we need to clear all
  48546. // the keys and treat the xml as describing the entire set of mappings.
  48547. clearAllKeyPresses();
  48548. }
  48549. forEachXmlChildElement (xmlVersion, map)
  48550. {
  48551. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48552. if (commandId != 0)
  48553. {
  48554. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48555. if (map->hasTagName (T("MAPPING")))
  48556. {
  48557. addKeyPress (commandId, key);
  48558. }
  48559. else if (map->hasTagName (T("UNMAPPING")))
  48560. {
  48561. if (containsMapping (commandId, key))
  48562. removeKeyPress (key);
  48563. }
  48564. }
  48565. }
  48566. return true;
  48567. }
  48568. return false;
  48569. }
  48570. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48571. {
  48572. ScopedPointer <KeyPressMappingSet> defaultSet;
  48573. if (saveDifferencesFromDefaultSet)
  48574. {
  48575. defaultSet = new KeyPressMappingSet (commandManager);
  48576. defaultSet->resetToDefaultMappings();
  48577. }
  48578. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48579. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48580. int i;
  48581. for (i = 0; i < mappings.size(); ++i)
  48582. {
  48583. const CommandMapping* const cm = mappings.getUnchecked(i);
  48584. for (int j = 0; j < cm->keypresses.size(); ++j)
  48585. {
  48586. if (defaultSet == 0
  48587. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48588. {
  48589. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48590. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48591. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48592. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48593. }
  48594. }
  48595. }
  48596. if (defaultSet != 0)
  48597. {
  48598. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48599. {
  48600. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48601. for (int j = 0; j < cm->keypresses.size(); ++j)
  48602. {
  48603. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48604. {
  48605. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48606. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48607. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48608. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48609. }
  48610. }
  48611. }
  48612. }
  48613. return doc;
  48614. }
  48615. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48616. Component* originatingComponent)
  48617. {
  48618. bool used = false;
  48619. const CommandID commandID = findCommandForKeyPress (key);
  48620. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48621. if (ci != 0
  48622. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48623. {
  48624. ApplicationCommandInfo info (0);
  48625. if (commandManager->getTargetForCommand (commandID, info) != 0
  48626. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48627. {
  48628. invokeCommand (commandID, key, true, 0, originatingComponent);
  48629. used = true;
  48630. }
  48631. else
  48632. {
  48633. if (originatingComponent != 0)
  48634. originatingComponent->getLookAndFeel().playAlertSound();
  48635. }
  48636. }
  48637. return used;
  48638. }
  48639. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48640. {
  48641. bool used = false;
  48642. const uint32 now = Time::getMillisecondCounter();
  48643. for (int i = mappings.size(); --i >= 0;)
  48644. {
  48645. CommandMapping* const cm = mappings.getUnchecked(i);
  48646. if (cm->wantsKeyUpDownCallbacks)
  48647. {
  48648. for (int j = cm->keypresses.size(); --j >= 0;)
  48649. {
  48650. const KeyPress key (cm->keypresses.getReference (j));
  48651. const bool isDown = key.isCurrentlyDown();
  48652. int keyPressEntryIndex = 0;
  48653. bool wasDown = false;
  48654. for (int k = keysDown.size(); --k >= 0;)
  48655. {
  48656. if (key == keysDown.getUnchecked(k)->key)
  48657. {
  48658. keyPressEntryIndex = k;
  48659. wasDown = true;
  48660. used = true;
  48661. break;
  48662. }
  48663. }
  48664. if (isDown != wasDown)
  48665. {
  48666. int millisecs = 0;
  48667. if (isDown)
  48668. {
  48669. KeyPressTime* const k = new KeyPressTime();
  48670. k->key = key;
  48671. k->timeWhenPressed = now;
  48672. keysDown.add (k);
  48673. }
  48674. else
  48675. {
  48676. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48677. if (now > pressTime)
  48678. millisecs = now - pressTime;
  48679. keysDown.remove (keyPressEntryIndex);
  48680. }
  48681. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48682. used = true;
  48683. }
  48684. }
  48685. }
  48686. }
  48687. return used;
  48688. }
  48689. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48690. {
  48691. if (focusedComponent != 0)
  48692. focusedComponent->keyStateChanged (false);
  48693. }
  48694. END_JUCE_NAMESPACE
  48695. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48696. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48697. BEGIN_JUCE_NAMESPACE
  48698. ModifierKeys::ModifierKeys (const int flags_) throw()
  48699. : flags (flags_)
  48700. {
  48701. }
  48702. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48703. : flags (other.flags)
  48704. {
  48705. }
  48706. const ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48707. {
  48708. flags = other.flags;
  48709. return *this;
  48710. }
  48711. int ModifierKeys::currentModifierFlags = 0;
  48712. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48713. {
  48714. return ModifierKeys (currentModifierFlags);
  48715. }
  48716. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48717. {
  48718. int num = 0;
  48719. if (isLeftButtonDown()) ++num;
  48720. if (isRightButtonDown()) ++num;
  48721. if (isMiddleButtonDown()) ++num;
  48722. return num;
  48723. }
  48724. END_JUCE_NAMESPACE
  48725. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48726. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48727. BEGIN_JUCE_NAMESPACE
  48728. struct AnimationTask
  48729. {
  48730. AnimationTask (Component* const comp)
  48731. : component (comp),
  48732. watcher (comp)
  48733. {
  48734. }
  48735. Component* component;
  48736. ComponentDeletionWatcher watcher;
  48737. Rectangle<int> destination;
  48738. int msElapsed, msTotal;
  48739. double startSpeed, midSpeed, endSpeed, lastProgress;
  48740. double left, top, right, bottom;
  48741. bool useTimeslice (const int elapsed)
  48742. {
  48743. if (watcher.hasBeenDeleted())
  48744. return false;
  48745. msElapsed += elapsed;
  48746. double newProgress = msElapsed / (double) msTotal;
  48747. if (newProgress >= 0 && newProgress < 1.0)
  48748. {
  48749. newProgress = timeToDistance (newProgress);
  48750. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48751. jassert (newProgress >= lastProgress);
  48752. lastProgress = newProgress;
  48753. left += (destination.getX() - left) * delta;
  48754. top += (destination.getY() - top) * delta;
  48755. right += (destination.getRight() - right) * delta;
  48756. bottom += (destination.getBottom() - bottom) * delta;
  48757. if (delta < 1.0)
  48758. {
  48759. const Rectangle<int> newBounds (roundToInt (left),
  48760. roundToInt (top),
  48761. roundToInt (right - left),
  48762. roundToInt (bottom - top));
  48763. if (newBounds != destination)
  48764. {
  48765. component->setBounds (newBounds);
  48766. return true;
  48767. }
  48768. }
  48769. }
  48770. component->setBounds (destination);
  48771. return false;
  48772. }
  48773. void moveToFinalDestination()
  48774. {
  48775. if (! watcher.hasBeenDeleted())
  48776. component->setBounds (destination);
  48777. }
  48778. private:
  48779. inline double timeToDistance (const double time) const
  48780. {
  48781. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48782. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48783. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48784. }
  48785. };
  48786. ComponentAnimator::ComponentAnimator()
  48787. : lastTime (0)
  48788. {
  48789. }
  48790. ComponentAnimator::~ComponentAnimator()
  48791. {
  48792. cancelAllAnimations (false);
  48793. jassert (tasks.size() == 0);
  48794. }
  48795. void* ComponentAnimator::findTaskFor (Component* const component) const
  48796. {
  48797. for (int i = tasks.size(); --i >= 0;)
  48798. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component)
  48799. return tasks.getUnchecked(i);
  48800. return 0;
  48801. }
  48802. void ComponentAnimator::animateComponent (Component* const component,
  48803. const Rectangle<int>& finalPosition,
  48804. const int millisecondsToSpendMoving,
  48805. const double startSpeed,
  48806. const double endSpeed)
  48807. {
  48808. if (component != 0)
  48809. {
  48810. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48811. if (at == 0)
  48812. {
  48813. at = new AnimationTask (component);
  48814. tasks.add (at);
  48815. sendChangeMessage (this);
  48816. }
  48817. at->msElapsed = 0;
  48818. at->lastProgress = 0;
  48819. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48820. at->destination = finalPosition;
  48821. // the speeds must be 0 or greater!
  48822. jassert (startSpeed >= 0 && endSpeed >= 0)
  48823. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48824. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48825. at->midSpeed = invTotalDistance;
  48826. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48827. at->left = component->getX();
  48828. at->top = component->getY();
  48829. at->right = component->getRight();
  48830. at->bottom = component->getBottom();
  48831. if (! isTimerRunning())
  48832. {
  48833. lastTime = Time::getMillisecondCounter();
  48834. startTimer (1000 / 50);
  48835. }
  48836. }
  48837. }
  48838. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48839. {
  48840. for (int i = tasks.size(); --i >= 0;)
  48841. {
  48842. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48843. if (moveComponentsToTheirFinalPositions)
  48844. at->moveToFinalDestination();
  48845. delete at;
  48846. tasks.remove (i);
  48847. sendChangeMessage (this);
  48848. }
  48849. }
  48850. void ComponentAnimator::cancelAnimation (Component* const component,
  48851. const bool moveComponentToItsFinalPosition)
  48852. {
  48853. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48854. if (at != 0)
  48855. {
  48856. if (moveComponentToItsFinalPosition)
  48857. at->moveToFinalDestination();
  48858. tasks.removeValue (at);
  48859. delete at;
  48860. sendChangeMessage (this);
  48861. }
  48862. }
  48863. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48864. {
  48865. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48866. if (at != 0)
  48867. return at->destination;
  48868. else if (component != 0)
  48869. return component->getBounds();
  48870. return Rectangle<int>();
  48871. }
  48872. bool ComponentAnimator::isAnimating (Component* component) const
  48873. {
  48874. return findTaskFor (component) != 0;
  48875. }
  48876. void ComponentAnimator::timerCallback()
  48877. {
  48878. const uint32 timeNow = Time::getMillisecondCounter();
  48879. if (lastTime == 0 || lastTime == timeNow)
  48880. lastTime = timeNow;
  48881. const int elapsed = timeNow - lastTime;
  48882. for (int i = tasks.size(); --i >= 0;)
  48883. {
  48884. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48885. if (! at->useTimeslice (elapsed))
  48886. {
  48887. tasks.remove (i);
  48888. delete at;
  48889. sendChangeMessage (this);
  48890. }
  48891. }
  48892. lastTime = timeNow;
  48893. if (tasks.size() == 0)
  48894. stopTimer();
  48895. }
  48896. END_JUCE_NAMESPACE
  48897. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48898. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48899. BEGIN_JUCE_NAMESPACE
  48900. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48901. : minW (0),
  48902. maxW (0x3fffffff),
  48903. minH (0),
  48904. maxH (0x3fffffff),
  48905. minOffTop (0),
  48906. minOffLeft (0),
  48907. minOffBottom (0),
  48908. minOffRight (0),
  48909. aspectRatio (0.0)
  48910. {
  48911. }
  48912. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48913. {
  48914. }
  48915. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48916. {
  48917. minW = minimumWidth;
  48918. }
  48919. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48920. {
  48921. maxW = maximumWidth;
  48922. }
  48923. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48924. {
  48925. minH = minimumHeight;
  48926. }
  48927. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48928. {
  48929. maxH = maximumHeight;
  48930. }
  48931. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48932. {
  48933. jassert (maxW >= minimumWidth);
  48934. jassert (maxH >= minimumHeight);
  48935. jassert (minimumWidth > 0 && minimumHeight > 0);
  48936. minW = minimumWidth;
  48937. minH = minimumHeight;
  48938. if (minW > maxW)
  48939. maxW = minW;
  48940. if (minH > maxH)
  48941. maxH = minH;
  48942. }
  48943. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48944. {
  48945. jassert (maximumWidth >= minW);
  48946. jassert (maximumHeight >= minH);
  48947. jassert (maximumWidth > 0 && maximumHeight > 0);
  48948. maxW = jmax (minW, maximumWidth);
  48949. maxH = jmax (minH, maximumHeight);
  48950. }
  48951. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48952. const int minimumHeight,
  48953. const int maximumWidth,
  48954. const int maximumHeight) throw()
  48955. {
  48956. jassert (maximumWidth >= minimumWidth);
  48957. jassert (maximumHeight >= minimumHeight);
  48958. jassert (maximumWidth > 0 && maximumHeight > 0);
  48959. jassert (minimumWidth > 0 && minimumHeight > 0);
  48960. minW = jmax (0, minimumWidth);
  48961. minH = jmax (0, minimumHeight);
  48962. maxW = jmax (minW, maximumWidth);
  48963. maxH = jmax (minH, maximumHeight);
  48964. }
  48965. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48966. const int minimumWhenOffTheLeft,
  48967. const int minimumWhenOffTheBottom,
  48968. const int minimumWhenOffTheRight) throw()
  48969. {
  48970. minOffTop = minimumWhenOffTheTop;
  48971. minOffLeft = minimumWhenOffTheLeft;
  48972. minOffBottom = minimumWhenOffTheBottom;
  48973. minOffRight = minimumWhenOffTheRight;
  48974. }
  48975. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48976. {
  48977. aspectRatio = jmax (0.0, widthOverHeight);
  48978. }
  48979. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48980. {
  48981. return aspectRatio;
  48982. }
  48983. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48984. const Rectangle<int>& targetBounds,
  48985. const bool isStretchingTop,
  48986. const bool isStretchingLeft,
  48987. const bool isStretchingBottom,
  48988. const bool isStretchingRight)
  48989. {
  48990. jassert (component != 0);
  48991. Rectangle<int> limits, bounds (targetBounds);
  48992. BorderSize border;
  48993. Component* const parent = component->getParentComponent();
  48994. if (parent == 0)
  48995. {
  48996. ComponentPeer* peer = component->getPeer();
  48997. if (peer != 0)
  48998. border = peer->getFrameSize();
  48999. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  49000. }
  49001. else
  49002. {
  49003. limits.setSize (parent->getWidth(), parent->getHeight());
  49004. }
  49005. border.addTo (bounds);
  49006. checkBounds (bounds,
  49007. border.addedTo (component->getBounds()), limits,
  49008. isStretchingTop, isStretchingLeft,
  49009. isStretchingBottom, isStretchingRight);
  49010. border.subtractFrom (bounds);
  49011. applyBoundsToComponent (component, bounds);
  49012. }
  49013. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  49014. {
  49015. setBoundsForComponent (component, component->getBounds(),
  49016. false, false, false, false);
  49017. }
  49018. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  49019. const Rectangle<int>& bounds)
  49020. {
  49021. component->setBounds (bounds);
  49022. }
  49023. void ComponentBoundsConstrainer::resizeStart()
  49024. {
  49025. }
  49026. void ComponentBoundsConstrainer::resizeEnd()
  49027. {
  49028. }
  49029. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  49030. const Rectangle<int>& old,
  49031. const Rectangle<int>& limits,
  49032. const bool isStretchingTop,
  49033. const bool isStretchingLeft,
  49034. const bool isStretchingBottom,
  49035. const bool isStretchingRight)
  49036. {
  49037. int x = bounds.getX();
  49038. int y = bounds.getY();
  49039. int w = bounds.getWidth();
  49040. int h = bounds.getHeight();
  49041. // constrain the size if it's being stretched..
  49042. if (isStretchingLeft)
  49043. {
  49044. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  49045. w = old.getRight() - x;
  49046. }
  49047. if (isStretchingRight)
  49048. {
  49049. w = jlimit (minW, maxW, w);
  49050. }
  49051. if (isStretchingTop)
  49052. {
  49053. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  49054. h = old.getBottom() - y;
  49055. }
  49056. if (isStretchingBottom)
  49057. {
  49058. h = jlimit (minH, maxH, h);
  49059. }
  49060. // constrain the aspect ratio if one has been specified..
  49061. if (aspectRatio > 0.0 && w > 0 && h > 0)
  49062. {
  49063. bool adjustWidth;
  49064. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49065. {
  49066. adjustWidth = true;
  49067. }
  49068. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49069. {
  49070. adjustWidth = false;
  49071. }
  49072. else
  49073. {
  49074. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  49075. const double newRatio = fabs (w / (double) h);
  49076. adjustWidth = (oldRatio > newRatio);
  49077. }
  49078. if (adjustWidth)
  49079. {
  49080. w = roundToInt (h * aspectRatio);
  49081. if (w > maxW || w < minW)
  49082. {
  49083. w = jlimit (minW, maxW, w);
  49084. h = roundToInt (w / aspectRatio);
  49085. }
  49086. }
  49087. else
  49088. {
  49089. h = roundToInt (w / aspectRatio);
  49090. if (h > maxH || h < minH)
  49091. {
  49092. h = jlimit (minH, maxH, h);
  49093. w = roundToInt (h * aspectRatio);
  49094. }
  49095. }
  49096. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49097. {
  49098. x = old.getX() + (old.getWidth() - w) / 2;
  49099. }
  49100. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49101. {
  49102. y = old.getY() + (old.getHeight() - h) / 2;
  49103. }
  49104. else
  49105. {
  49106. if (isStretchingLeft)
  49107. x = old.getRight() - w;
  49108. if (isStretchingTop)
  49109. y = old.getBottom() - h;
  49110. }
  49111. }
  49112. // ...and constrain the position if limits have been set for that.
  49113. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  49114. {
  49115. if (minOffTop > 0)
  49116. {
  49117. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  49118. if (y < limit)
  49119. {
  49120. if (isStretchingTop)
  49121. h -= (limit - y);
  49122. y = limit;
  49123. }
  49124. }
  49125. if (minOffLeft > 0)
  49126. {
  49127. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  49128. if (x < limit)
  49129. {
  49130. if (isStretchingLeft)
  49131. w -= (limit - x);
  49132. x = limit;
  49133. }
  49134. }
  49135. if (minOffBottom > 0)
  49136. {
  49137. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  49138. if (y > limit)
  49139. {
  49140. if (isStretchingBottom)
  49141. h += (limit - y);
  49142. else
  49143. y = limit;
  49144. }
  49145. }
  49146. if (minOffRight > 0)
  49147. {
  49148. const int limit = limits.getRight() - jmin (minOffRight, w);
  49149. if (x > limit)
  49150. {
  49151. if (isStretchingRight)
  49152. w += (limit - x);
  49153. else
  49154. x = limit;
  49155. }
  49156. }
  49157. }
  49158. jassert (w >= 0 && h >= 0);
  49159. bounds = Rectangle<int> (x, y, w, h);
  49160. }
  49161. END_JUCE_NAMESPACE
  49162. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  49163. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49164. BEGIN_JUCE_NAMESPACE
  49165. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  49166. : component (component_),
  49167. lastPeer (0),
  49168. reentrant (false)
  49169. {
  49170. jassert (component != 0); // can't use this with a null pointer..
  49171. #ifdef JUCE_DEBUG
  49172. deletionWatcher = new ComponentDeletionWatcher (component_);
  49173. #endif
  49174. component->addComponentListener (this);
  49175. registerWithParentComps();
  49176. }
  49177. ComponentMovementWatcher::~ComponentMovementWatcher()
  49178. {
  49179. component->removeComponentListener (this);
  49180. unregister();
  49181. }
  49182. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  49183. {
  49184. #ifdef JUCE_DEBUG
  49185. // agh! don't delete the target component without deleting this object first!
  49186. jassert (! deletionWatcher->hasBeenDeleted());
  49187. #endif
  49188. if (! reentrant)
  49189. {
  49190. reentrant = true;
  49191. ComponentPeer* const peer = component->getPeer();
  49192. if (peer != lastPeer)
  49193. {
  49194. ComponentDeletionWatcher watcher (component);
  49195. componentPeerChanged();
  49196. if (watcher.hasBeenDeleted())
  49197. return;
  49198. lastPeer = peer;
  49199. }
  49200. unregister();
  49201. registerWithParentComps();
  49202. reentrant = false;
  49203. componentMovedOrResized (*component, true, true);
  49204. }
  49205. }
  49206. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  49207. {
  49208. #ifdef JUCE_DEBUG
  49209. // agh! don't delete the target component without deleting this object first!
  49210. jassert (! deletionWatcher->hasBeenDeleted());
  49211. #endif
  49212. if (wasMoved)
  49213. {
  49214. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  49215. wasMoved = lastBounds.getPosition() != pos;
  49216. lastBounds.setPosition (pos);
  49217. }
  49218. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  49219. lastBounds.setSize (component->getWidth(), component->getHeight());
  49220. if (wasMoved || wasResized)
  49221. componentMovedOrResized (wasMoved, wasResized);
  49222. }
  49223. void ComponentMovementWatcher::registerWithParentComps() throw()
  49224. {
  49225. Component* p = component->getParentComponent();
  49226. while (p != 0)
  49227. {
  49228. p->addComponentListener (this);
  49229. registeredParentComps.add (p);
  49230. p = p->getParentComponent();
  49231. }
  49232. }
  49233. void ComponentMovementWatcher::unregister() throw()
  49234. {
  49235. for (int i = registeredParentComps.size(); --i >= 0;)
  49236. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  49237. registeredParentComps.clear();
  49238. }
  49239. END_JUCE_NAMESPACE
  49240. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49241. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  49242. BEGIN_JUCE_NAMESPACE
  49243. GroupComponent::GroupComponent (const String& componentName,
  49244. const String& labelText)
  49245. : Component (componentName),
  49246. text (labelText),
  49247. justification (Justification::left)
  49248. {
  49249. setInterceptsMouseClicks (false, true);
  49250. }
  49251. GroupComponent::~GroupComponent()
  49252. {
  49253. }
  49254. void GroupComponent::setText (const String& newText) throw()
  49255. {
  49256. if (text != newText)
  49257. {
  49258. text = newText;
  49259. repaint();
  49260. }
  49261. }
  49262. const String GroupComponent::getText() const throw()
  49263. {
  49264. return text;
  49265. }
  49266. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  49267. {
  49268. if (justification.getFlags() != newJustification.getFlags())
  49269. {
  49270. justification = newJustification;
  49271. repaint();
  49272. }
  49273. }
  49274. void GroupComponent::paint (Graphics& g)
  49275. {
  49276. getLookAndFeel()
  49277. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  49278. text, justification,
  49279. *this);
  49280. }
  49281. void GroupComponent::enablementChanged()
  49282. {
  49283. repaint();
  49284. }
  49285. void GroupComponent::colourChanged()
  49286. {
  49287. repaint();
  49288. }
  49289. END_JUCE_NAMESPACE
  49290. /*** End of inlined file: juce_GroupComponent.cpp ***/
  49291. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  49292. BEGIN_JUCE_NAMESPACE
  49293. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  49294. : DocumentWindow (String::empty, backgroundColour,
  49295. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  49296. {
  49297. }
  49298. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  49299. {
  49300. }
  49301. void MultiDocumentPanelWindow::maximiseButtonPressed()
  49302. {
  49303. MultiDocumentPanel* const owner = getOwner();
  49304. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49305. if (owner != 0)
  49306. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  49307. }
  49308. void MultiDocumentPanelWindow::closeButtonPressed()
  49309. {
  49310. MultiDocumentPanel* const owner = getOwner();
  49311. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49312. if (owner != 0)
  49313. owner->closeDocument (getContentComponent(), true);
  49314. }
  49315. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  49316. {
  49317. DocumentWindow::activeWindowStatusChanged();
  49318. updateOrder();
  49319. }
  49320. void MultiDocumentPanelWindow::broughtToFront()
  49321. {
  49322. DocumentWindow::broughtToFront();
  49323. updateOrder();
  49324. }
  49325. void MultiDocumentPanelWindow::updateOrder()
  49326. {
  49327. MultiDocumentPanel* const owner = getOwner();
  49328. if (owner != 0)
  49329. owner->updateOrder();
  49330. }
  49331. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  49332. {
  49333. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49334. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49335. }
  49336. class MDITabbedComponentInternal : public TabbedComponent
  49337. {
  49338. public:
  49339. MDITabbedComponentInternal()
  49340. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  49341. {
  49342. }
  49343. ~MDITabbedComponentInternal()
  49344. {
  49345. }
  49346. void currentTabChanged (const int, const String&)
  49347. {
  49348. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49349. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49350. if (owner != 0)
  49351. owner->updateOrder();
  49352. }
  49353. };
  49354. MultiDocumentPanel::MultiDocumentPanel()
  49355. : mode (MaximisedWindowsWithTabs),
  49356. tabComponent (0),
  49357. backgroundColour (Colours::lightblue),
  49358. maximumNumDocuments (0),
  49359. numDocsBeforeTabsUsed (0)
  49360. {
  49361. setOpaque (true);
  49362. }
  49363. MultiDocumentPanel::~MultiDocumentPanel()
  49364. {
  49365. closeAllDocuments (false);
  49366. }
  49367. static bool shouldDeleteComp (Component* const c)
  49368. {
  49369. return c->getProperties() ["mdiDocumentDelete_"];
  49370. }
  49371. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  49372. {
  49373. while (components.size() > 0)
  49374. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  49375. return false;
  49376. return true;
  49377. }
  49378. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  49379. {
  49380. return new MultiDocumentPanelWindow (backgroundColour);
  49381. }
  49382. void MultiDocumentPanel::addWindow (Component* component)
  49383. {
  49384. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  49385. dw->setResizable (true, false);
  49386. dw->setContentComponent (component, false, true);
  49387. dw->setName (component->getName());
  49388. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  49389. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  49390. int x = 4;
  49391. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  49392. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  49393. x += 16;
  49394. dw->setTopLeftPosition (x, x);
  49395. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  49396. if (pos.toString().isNotEmpty())
  49397. dw->restoreWindowStateFromString (pos.toString());
  49398. addAndMakeVisible (dw);
  49399. dw->toFront (true);
  49400. }
  49401. bool MultiDocumentPanel::addDocument (Component* const component,
  49402. const Colour& docColour,
  49403. const bool deleteWhenRemoved)
  49404. {
  49405. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  49406. // with a frame-within-a-frame! Just pass in the bare content component.
  49407. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  49408. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  49409. return false;
  49410. components.add (component);
  49411. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  49412. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  49413. component->addComponentListener (this);
  49414. if (mode == FloatingWindows)
  49415. {
  49416. if (isFullscreenWhenOneDocument())
  49417. {
  49418. if (components.size() == 1)
  49419. {
  49420. addAndMakeVisible (component);
  49421. }
  49422. else
  49423. {
  49424. if (components.size() == 2)
  49425. addWindow (components.getFirst());
  49426. addWindow (component);
  49427. }
  49428. }
  49429. else
  49430. {
  49431. addWindow (component);
  49432. }
  49433. }
  49434. else
  49435. {
  49436. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  49437. {
  49438. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  49439. Array <Component*> temp (components);
  49440. for (int i = 0; i < temp.size(); ++i)
  49441. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  49442. resized();
  49443. }
  49444. else
  49445. {
  49446. if (tabComponent != 0)
  49447. tabComponent->addTab (component->getName(), docColour, component, false);
  49448. else
  49449. addAndMakeVisible (component);
  49450. }
  49451. setActiveDocument (component);
  49452. }
  49453. resized();
  49454. activeDocumentChanged();
  49455. return true;
  49456. }
  49457. bool MultiDocumentPanel::closeDocument (Component* component,
  49458. const bool checkItsOkToCloseFirst)
  49459. {
  49460. if (components.contains (component))
  49461. {
  49462. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  49463. return false;
  49464. component->removeComponentListener (this);
  49465. const bool shouldDelete = shouldDeleteComp (component);
  49466. component->getProperties().remove ("mdiDocumentDelete_");
  49467. component->getProperties().remove ("mdiDocumentBkg_");
  49468. if (mode == FloatingWindows)
  49469. {
  49470. for (int i = getNumChildComponents(); --i >= 0;)
  49471. {
  49472. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49473. if (dw != 0 && dw->getContentComponent() == component)
  49474. {
  49475. dw->setContentComponent (0, false);
  49476. delete dw;
  49477. break;
  49478. }
  49479. }
  49480. if (shouldDelete)
  49481. delete component;
  49482. components.removeValue (component);
  49483. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49484. {
  49485. for (int i = getNumChildComponents(); --i >= 0;)
  49486. {
  49487. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49488. if (dw != 0)
  49489. {
  49490. dw->setContentComponent (0, false);
  49491. delete dw;
  49492. }
  49493. }
  49494. addAndMakeVisible (components.getFirst());
  49495. }
  49496. }
  49497. else
  49498. {
  49499. jassert (components.indexOf (component) >= 0);
  49500. if (tabComponent != 0)
  49501. {
  49502. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49503. if (tabComponent->getTabContentComponent (i) == component)
  49504. tabComponent->removeTab (i);
  49505. }
  49506. else
  49507. {
  49508. removeChildComponent (component);
  49509. }
  49510. if (shouldDelete)
  49511. delete component;
  49512. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49513. deleteAndZero (tabComponent);
  49514. components.removeValue (component);
  49515. if (components.size() > 0 && tabComponent == 0)
  49516. addAndMakeVisible (components.getFirst());
  49517. }
  49518. resized();
  49519. activeDocumentChanged();
  49520. }
  49521. else
  49522. {
  49523. jassertfalse
  49524. }
  49525. return true;
  49526. }
  49527. int MultiDocumentPanel::getNumDocuments() const throw()
  49528. {
  49529. return components.size();
  49530. }
  49531. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49532. {
  49533. return components [index];
  49534. }
  49535. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49536. {
  49537. if (mode == FloatingWindows)
  49538. {
  49539. for (int i = getNumChildComponents(); --i >= 0;)
  49540. {
  49541. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49542. if (dw != 0 && dw->isActiveWindow())
  49543. return dw->getContentComponent();
  49544. }
  49545. }
  49546. return components.getLast();
  49547. }
  49548. void MultiDocumentPanel::setActiveDocument (Component* component)
  49549. {
  49550. if (mode == FloatingWindows)
  49551. {
  49552. component = getContainerComp (component);
  49553. if (component != 0)
  49554. component->toFront (true);
  49555. }
  49556. else if (tabComponent != 0)
  49557. {
  49558. jassert (components.indexOf (component) >= 0);
  49559. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49560. {
  49561. if (tabComponent->getTabContentComponent (i) == component)
  49562. {
  49563. tabComponent->setCurrentTabIndex (i);
  49564. break;
  49565. }
  49566. }
  49567. }
  49568. else
  49569. {
  49570. component->grabKeyboardFocus();
  49571. }
  49572. }
  49573. void MultiDocumentPanel::activeDocumentChanged()
  49574. {
  49575. }
  49576. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49577. {
  49578. maximumNumDocuments = newNumber;
  49579. }
  49580. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49581. {
  49582. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49583. }
  49584. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49585. {
  49586. return numDocsBeforeTabsUsed != 0;
  49587. }
  49588. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49589. {
  49590. if (mode != newLayoutMode)
  49591. {
  49592. mode = newLayoutMode;
  49593. if (mode == FloatingWindows)
  49594. {
  49595. deleteAndZero (tabComponent);
  49596. }
  49597. else
  49598. {
  49599. for (int i = getNumChildComponents(); --i >= 0;)
  49600. {
  49601. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49602. if (dw != 0)
  49603. {
  49604. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49605. dw->setContentComponent (0, false);
  49606. delete dw;
  49607. }
  49608. }
  49609. }
  49610. resized();
  49611. const Array <Component*> tempComps (components);
  49612. components.clear();
  49613. for (int i = 0; i < tempComps.size(); ++i)
  49614. {
  49615. Component* const c = tempComps.getUnchecked(i);
  49616. addDocument (c,
  49617. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49618. shouldDeleteComp (c));
  49619. }
  49620. }
  49621. }
  49622. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49623. {
  49624. if (backgroundColour != newBackgroundColour)
  49625. {
  49626. backgroundColour = newBackgroundColour;
  49627. setOpaque (newBackgroundColour.isOpaque());
  49628. repaint();
  49629. }
  49630. }
  49631. void MultiDocumentPanel::paint (Graphics& g)
  49632. {
  49633. g.fillAll (backgroundColour);
  49634. }
  49635. void MultiDocumentPanel::resized()
  49636. {
  49637. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49638. {
  49639. for (int i = getNumChildComponents(); --i >= 0;)
  49640. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49641. }
  49642. setWantsKeyboardFocus (components.size() == 0);
  49643. }
  49644. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49645. {
  49646. if (mode == FloatingWindows)
  49647. {
  49648. for (int i = 0; i < getNumChildComponents(); ++i)
  49649. {
  49650. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49651. if (dw != 0 && dw->getContentComponent() == c)
  49652. {
  49653. c = dw;
  49654. break;
  49655. }
  49656. }
  49657. }
  49658. return c;
  49659. }
  49660. void MultiDocumentPanel::componentNameChanged (Component&)
  49661. {
  49662. if (mode == FloatingWindows)
  49663. {
  49664. for (int i = 0; i < getNumChildComponents(); ++i)
  49665. {
  49666. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49667. if (dw != 0)
  49668. dw->setName (dw->getContentComponent()->getName());
  49669. }
  49670. }
  49671. else if (tabComponent != 0)
  49672. {
  49673. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49674. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49675. }
  49676. }
  49677. void MultiDocumentPanel::updateOrder()
  49678. {
  49679. const Array <Component*> oldList (components);
  49680. if (mode == FloatingWindows)
  49681. {
  49682. components.clear();
  49683. for (int i = 0; i < getNumChildComponents(); ++i)
  49684. {
  49685. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49686. if (dw != 0)
  49687. components.add (dw->getContentComponent());
  49688. }
  49689. }
  49690. else
  49691. {
  49692. if (tabComponent != 0)
  49693. {
  49694. Component* const current = tabComponent->getCurrentContentComponent();
  49695. if (current != 0)
  49696. {
  49697. components.removeValue (current);
  49698. components.add (current);
  49699. }
  49700. }
  49701. }
  49702. if (components != oldList)
  49703. activeDocumentChanged();
  49704. }
  49705. END_JUCE_NAMESPACE
  49706. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49707. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49708. BEGIN_JUCE_NAMESPACE
  49709. const int zoneL = 1;
  49710. const int zoneR = 2;
  49711. const int zoneT = 4;
  49712. const int zoneB = 8;
  49713. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49714. ComponentBoundsConstrainer* const constrainer_)
  49715. : component (componentToResize),
  49716. constrainer (constrainer_),
  49717. borderSize (5),
  49718. mouseZone (0)
  49719. {
  49720. }
  49721. ResizableBorderComponent::~ResizableBorderComponent()
  49722. {
  49723. }
  49724. void ResizableBorderComponent::paint (Graphics& g)
  49725. {
  49726. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49727. }
  49728. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49729. {
  49730. updateMouseZone (e);
  49731. }
  49732. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49733. {
  49734. updateMouseZone (e);
  49735. }
  49736. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49737. {
  49738. if (component->isValidComponent())
  49739. {
  49740. updateMouseZone (e);
  49741. originalX = component->getX();
  49742. originalY = component->getY();
  49743. originalW = component->getWidth();
  49744. originalH = component->getHeight();
  49745. if (constrainer != 0)
  49746. constrainer->resizeStart();
  49747. }
  49748. else
  49749. {
  49750. jassertfalse
  49751. }
  49752. }
  49753. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49754. {
  49755. if (! component->isValidComponent())
  49756. {
  49757. jassertfalse
  49758. return;
  49759. }
  49760. int x = originalX;
  49761. int y = originalY;
  49762. int w = originalW;
  49763. int h = originalH;
  49764. const int dx = e.getDistanceFromDragStartX();
  49765. const int dy = e.getDistanceFromDragStartY();
  49766. if ((mouseZone & zoneL) != 0)
  49767. {
  49768. x += dx;
  49769. w -= dx;
  49770. }
  49771. if ((mouseZone & zoneT) != 0)
  49772. {
  49773. y += dy;
  49774. h -= dy;
  49775. }
  49776. if ((mouseZone & zoneR) != 0)
  49777. w += dx;
  49778. if ((mouseZone & zoneB) != 0)
  49779. h += dy;
  49780. if (constrainer != 0)
  49781. constrainer->setBoundsForComponent (component,
  49782. Rectangle<int> (x, y, w, h),
  49783. (mouseZone & zoneT) != 0,
  49784. (mouseZone & zoneL) != 0,
  49785. (mouseZone & zoneB) != 0,
  49786. (mouseZone & zoneR) != 0);
  49787. else
  49788. component->setBounds (x, y, w, h);
  49789. }
  49790. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49791. {
  49792. if (constrainer != 0)
  49793. constrainer->resizeEnd();
  49794. }
  49795. bool ResizableBorderComponent::hitTest (int x, int y)
  49796. {
  49797. return x < borderSize.getLeft()
  49798. || x >= getWidth() - borderSize.getRight()
  49799. || y < borderSize.getTop()
  49800. || y >= getHeight() - borderSize.getBottom();
  49801. }
  49802. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) throw()
  49803. {
  49804. if (borderSize != newBorderSize)
  49805. {
  49806. borderSize = newBorderSize;
  49807. repaint();
  49808. }
  49809. }
  49810. const BorderSize ResizableBorderComponent::getBorderThickness() const throw()
  49811. {
  49812. return borderSize;
  49813. }
  49814. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw()
  49815. {
  49816. int newZone = 0;
  49817. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49818. {
  49819. if (e.x < jmax (borderSize.getLeft(),
  49820. proportionOfWidth (0.1f),
  49821. jmin (10, proportionOfWidth (0.33f))))
  49822. newZone |= zoneL;
  49823. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49824. proportionOfWidth (0.9f),
  49825. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49826. newZone |= zoneR;
  49827. if (e.y < jmax (borderSize.getTop(),
  49828. proportionOfHeight (0.1f),
  49829. jmin (10, proportionOfHeight (0.33f))))
  49830. newZone |= zoneT;
  49831. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49832. proportionOfHeight (0.9f),
  49833. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49834. newZone |= zoneB;
  49835. }
  49836. if (mouseZone != newZone)
  49837. {
  49838. mouseZone = newZone;
  49839. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49840. switch (newZone)
  49841. {
  49842. case (zoneL | zoneT):
  49843. mc = MouseCursor::TopLeftCornerResizeCursor;
  49844. break;
  49845. case zoneT:
  49846. mc = MouseCursor::TopEdgeResizeCursor;
  49847. break;
  49848. case (zoneR | zoneT):
  49849. mc = MouseCursor::TopRightCornerResizeCursor;
  49850. break;
  49851. case zoneL:
  49852. mc = MouseCursor::LeftEdgeResizeCursor;
  49853. break;
  49854. case zoneR:
  49855. mc = MouseCursor::RightEdgeResizeCursor;
  49856. break;
  49857. case (zoneL | zoneB):
  49858. mc = MouseCursor::BottomLeftCornerResizeCursor;
  49859. break;
  49860. case zoneB:
  49861. mc = MouseCursor::BottomEdgeResizeCursor;
  49862. break;
  49863. case (zoneR | zoneB):
  49864. mc = MouseCursor::BottomRightCornerResizeCursor;
  49865. break;
  49866. default:
  49867. break;
  49868. }
  49869. setMouseCursor (mc);
  49870. }
  49871. }
  49872. END_JUCE_NAMESPACE
  49873. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49874. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49875. BEGIN_JUCE_NAMESPACE
  49876. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49877. ComponentBoundsConstrainer* const constrainer_)
  49878. : component (componentToResize),
  49879. constrainer (constrainer_)
  49880. {
  49881. setRepaintsOnMouseActivity (true);
  49882. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49883. }
  49884. ResizableCornerComponent::~ResizableCornerComponent()
  49885. {
  49886. }
  49887. void ResizableCornerComponent::paint (Graphics& g)
  49888. {
  49889. getLookAndFeel()
  49890. .drawCornerResizer (g, getWidth(), getHeight(),
  49891. isMouseOverOrDragging(),
  49892. isMouseButtonDown());
  49893. }
  49894. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49895. {
  49896. if (component->isValidComponent())
  49897. {
  49898. originalX = component->getX();
  49899. originalY = component->getY();
  49900. originalW = component->getWidth();
  49901. originalH = component->getHeight();
  49902. if (constrainer != 0)
  49903. constrainer->resizeStart();
  49904. }
  49905. else
  49906. {
  49907. jassertfalse
  49908. }
  49909. }
  49910. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49911. {
  49912. if (! component->isValidComponent())
  49913. {
  49914. jassertfalse
  49915. return;
  49916. }
  49917. int x = originalX;
  49918. int y = originalY;
  49919. int w = originalW + e.getDistanceFromDragStartX();
  49920. int h = originalH + e.getDistanceFromDragStartY();
  49921. if (constrainer != 0)
  49922. constrainer->setBoundsForComponent (component, Rectangle<int> (x, y, w, h),
  49923. false, false, true, true);
  49924. else
  49925. component->setBounds (x, y, w, h);
  49926. }
  49927. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49928. {
  49929. if (constrainer != 0)
  49930. constrainer->resizeStart();
  49931. }
  49932. bool ResizableCornerComponent::hitTest (int x, int y)
  49933. {
  49934. if (getWidth() <= 0)
  49935. return false;
  49936. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49937. return y >= yAtX - getHeight() / 4;
  49938. }
  49939. END_JUCE_NAMESPACE
  49940. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49941. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49942. BEGIN_JUCE_NAMESPACE
  49943. class ScrollbarButton : public Button
  49944. {
  49945. public:
  49946. int direction;
  49947. ScrollbarButton (const int direction_,
  49948. ScrollBar& owner_) throw()
  49949. : Button (String::empty),
  49950. direction (direction_),
  49951. owner (owner_)
  49952. {
  49953. setWantsKeyboardFocus (false);
  49954. }
  49955. ~ScrollbarButton()
  49956. {
  49957. }
  49958. void paintButton (Graphics& g,
  49959. bool isMouseOver,
  49960. bool isMouseDown)
  49961. {
  49962. getLookAndFeel()
  49963. .drawScrollbarButton (g, owner,
  49964. getWidth(), getHeight(),
  49965. direction,
  49966. owner.isVertical(),
  49967. isMouseOver, isMouseDown);
  49968. }
  49969. void clicked()
  49970. {
  49971. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49972. }
  49973. juce_UseDebuggingNewOperator
  49974. private:
  49975. ScrollBar& owner;
  49976. ScrollbarButton (const ScrollbarButton&);
  49977. const ScrollbarButton& operator= (const ScrollbarButton&);
  49978. };
  49979. ScrollBar::ScrollBar (const bool vertical_,
  49980. const bool buttonsAreVisible)
  49981. : minimum (0.0),
  49982. maximum (1.0),
  49983. rangeStart (0.0),
  49984. rangeSize (0.1),
  49985. singleStepSize (0.1),
  49986. thumbAreaStart (0),
  49987. thumbAreaSize (0),
  49988. thumbStart (0),
  49989. thumbSize (0),
  49990. initialDelayInMillisecs (100),
  49991. repeatDelayInMillisecs (50),
  49992. minimumDelayInMillisecs (10),
  49993. vertical (vertical_),
  49994. isDraggingThumb (false),
  49995. alwaysVisible (false),
  49996. upButton (0),
  49997. downButton (0)
  49998. {
  49999. setButtonVisibility (buttonsAreVisible);
  50000. setRepaintsOnMouseActivity (true);
  50001. setFocusContainer (true);
  50002. }
  50003. ScrollBar::~ScrollBar()
  50004. {
  50005. deleteAllChildren();
  50006. }
  50007. void ScrollBar::setRangeLimits (const double newMinimum,
  50008. const double newMaximum) throw()
  50009. {
  50010. minimum = newMinimum;
  50011. maximum = newMaximum;
  50012. jassert (maximum >= minimum); // these can't be the wrong way round!
  50013. setCurrentRangeStart (rangeStart);
  50014. updateThumbPosition();
  50015. }
  50016. void ScrollBar::setCurrentRange (double newStart,
  50017. double newSize) throw()
  50018. {
  50019. newSize = jlimit (0.0, maximum - minimum, newSize);
  50020. newStart = jlimit (minimum, maximum - newSize, newStart);
  50021. if (rangeStart != newStart
  50022. || rangeSize != newSize)
  50023. {
  50024. rangeStart = newStart;
  50025. rangeSize = newSize;
  50026. updateThumbPosition();
  50027. triggerAsyncUpdate();
  50028. }
  50029. }
  50030. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  50031. {
  50032. setCurrentRange (newStart, rangeSize);
  50033. }
  50034. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  50035. {
  50036. singleStepSize = newSingleStepSize;
  50037. }
  50038. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  50039. {
  50040. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  50041. }
  50042. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  50043. {
  50044. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  50045. }
  50046. void ScrollBar::scrollToTop() throw()
  50047. {
  50048. setCurrentRangeStart (minimum);
  50049. }
  50050. void ScrollBar::scrollToBottom() throw()
  50051. {
  50052. setCurrentRangeStart (maximum - rangeSize);
  50053. }
  50054. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  50055. const int repeatDelayInMillisecs_,
  50056. const int minimumDelayInMillisecs_) throw()
  50057. {
  50058. initialDelayInMillisecs = initialDelayInMillisecs_;
  50059. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  50060. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  50061. if (upButton != 0)
  50062. {
  50063. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50064. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50065. }
  50066. }
  50067. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  50068. {
  50069. jassert (listener != 0);
  50070. if (listener != 0)
  50071. listeners.add (listener);
  50072. }
  50073. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  50074. {
  50075. listeners.removeValue (listener);
  50076. }
  50077. void ScrollBar::handleAsyncUpdate()
  50078. {
  50079. const double value = getCurrentRangeStart();
  50080. for (int i = listeners.size(); --i >= 0;)
  50081. {
  50082. ((ScrollBarListener*) listeners.getUnchecked (i))->scrollBarMoved (this, value);
  50083. i = jmin (i, listeners.size());
  50084. }
  50085. }
  50086. void ScrollBar::updateThumbPosition() throw()
  50087. {
  50088. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  50089. : thumbAreaSize);
  50090. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50091. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  50092. if (newThumbSize > thumbAreaSize)
  50093. newThumbSize = thumbAreaSize;
  50094. int newThumbStart = thumbAreaStart;
  50095. if (maximum - minimum > rangeSize)
  50096. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  50097. / ((maximum - minimum) - rangeSize));
  50098. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  50099. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  50100. {
  50101. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  50102. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  50103. if (vertical)
  50104. repaint (0, repaintStart, getWidth(), repaintSize);
  50105. else
  50106. repaint (repaintStart, 0, repaintSize, getHeight());
  50107. thumbStart = newThumbStart;
  50108. thumbSize = newThumbSize;
  50109. }
  50110. }
  50111. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  50112. {
  50113. if (vertical != shouldBeVertical)
  50114. {
  50115. vertical = shouldBeVertical;
  50116. if (upButton != 0)
  50117. {
  50118. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  50119. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  50120. }
  50121. updateThumbPosition();
  50122. }
  50123. }
  50124. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  50125. {
  50126. deleteAndZero (upButton);
  50127. deleteAndZero (downButton);
  50128. if (buttonsAreVisible)
  50129. {
  50130. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  50131. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  50132. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50133. }
  50134. updateThumbPosition();
  50135. }
  50136. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  50137. {
  50138. alwaysVisible = ! shouldHideWhenFullRange;
  50139. updateThumbPosition();
  50140. }
  50141. void ScrollBar::paint (Graphics& g)
  50142. {
  50143. if (thumbAreaSize > 0)
  50144. {
  50145. LookAndFeel& lf = getLookAndFeel();
  50146. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  50147. ? thumbSize : 0;
  50148. if (vertical)
  50149. {
  50150. lf.drawScrollbar (g, *this,
  50151. 0, thumbAreaStart,
  50152. getWidth(), thumbAreaSize,
  50153. vertical,
  50154. thumbStart, thumb,
  50155. isMouseOver(), isMouseButtonDown());
  50156. }
  50157. else
  50158. {
  50159. lf.drawScrollbar (g, *this,
  50160. thumbAreaStart, 0,
  50161. thumbAreaSize, getHeight(),
  50162. vertical,
  50163. thumbStart, thumb,
  50164. isMouseOver(), isMouseButtonDown());
  50165. }
  50166. }
  50167. }
  50168. void ScrollBar::lookAndFeelChanged()
  50169. {
  50170. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  50171. }
  50172. void ScrollBar::resized()
  50173. {
  50174. const int length = ((vertical) ? getHeight() : getWidth());
  50175. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  50176. : 0;
  50177. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50178. {
  50179. thumbAreaStart = length >> 1;
  50180. thumbAreaSize = 0;
  50181. }
  50182. else
  50183. {
  50184. thumbAreaStart = buttonSize;
  50185. thumbAreaSize = length - (buttonSize << 1);
  50186. }
  50187. if (upButton != 0)
  50188. {
  50189. if (vertical)
  50190. {
  50191. upButton->setBounds (0, 0, getWidth(), buttonSize);
  50192. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  50193. }
  50194. else
  50195. {
  50196. upButton->setBounds (0, 0, buttonSize, getHeight());
  50197. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  50198. }
  50199. }
  50200. updateThumbPosition();
  50201. }
  50202. void ScrollBar::mouseDown (const MouseEvent& e)
  50203. {
  50204. isDraggingThumb = false;
  50205. lastMousePos = vertical ? e.y : e.x;
  50206. dragStartMousePos = lastMousePos;
  50207. dragStartRange = rangeStart;
  50208. if (dragStartMousePos < thumbStart)
  50209. {
  50210. moveScrollbarInPages (-1);
  50211. startTimer (400);
  50212. }
  50213. else if (dragStartMousePos >= thumbStart + thumbSize)
  50214. {
  50215. moveScrollbarInPages (1);
  50216. startTimer (400);
  50217. }
  50218. else
  50219. {
  50220. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50221. && (thumbAreaSize > thumbSize);
  50222. }
  50223. }
  50224. void ScrollBar::mouseDrag (const MouseEvent& e)
  50225. {
  50226. if (isDraggingThumb)
  50227. {
  50228. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  50229. setCurrentRangeStart (dragStartRange
  50230. + deltaPixels * ((maximum - minimum) - rangeSize)
  50231. / (thumbAreaSize - thumbSize));
  50232. }
  50233. else
  50234. {
  50235. lastMousePos = (vertical) ? e.y : e.x;
  50236. }
  50237. }
  50238. void ScrollBar::mouseUp (const MouseEvent&)
  50239. {
  50240. isDraggingThumb = false;
  50241. stopTimer();
  50242. repaint();
  50243. }
  50244. void ScrollBar::mouseWheelMove (const MouseEvent&,
  50245. float wheelIncrementX,
  50246. float wheelIncrementY)
  50247. {
  50248. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  50249. if (increment < 0)
  50250. increment = jmin (increment * 10.0f, -1.0f);
  50251. else if (increment > 0)
  50252. increment = jmax (increment * 10.0f, 1.0f);
  50253. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  50254. }
  50255. void ScrollBar::timerCallback()
  50256. {
  50257. if (isMouseButtonDown())
  50258. {
  50259. startTimer (40);
  50260. if (lastMousePos < thumbStart)
  50261. setCurrentRangeStart (rangeStart - rangeSize);
  50262. else if (lastMousePos > thumbStart + thumbSize)
  50263. setCurrentRangeStart (rangeStart + rangeSize);
  50264. }
  50265. else
  50266. {
  50267. stopTimer();
  50268. }
  50269. }
  50270. bool ScrollBar::keyPressed (const KeyPress& key)
  50271. {
  50272. if (! isVisible())
  50273. return false;
  50274. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  50275. moveScrollbarInSteps (-1);
  50276. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  50277. moveScrollbarInSteps (1);
  50278. else if (key.isKeyCode (KeyPress::pageUpKey))
  50279. moveScrollbarInPages (-1);
  50280. else if (key.isKeyCode (KeyPress::pageDownKey))
  50281. moveScrollbarInPages (1);
  50282. else if (key.isKeyCode (KeyPress::homeKey))
  50283. scrollToTop();
  50284. else if (key.isKeyCode (KeyPress::endKey))
  50285. scrollToBottom();
  50286. else
  50287. return false;
  50288. return true;
  50289. }
  50290. END_JUCE_NAMESPACE
  50291. /*** End of inlined file: juce_ScrollBar.cpp ***/
  50292. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  50293. BEGIN_JUCE_NAMESPACE
  50294. StretchableLayoutManager::StretchableLayoutManager()
  50295. : totalSize (0)
  50296. {
  50297. }
  50298. StretchableLayoutManager::~StretchableLayoutManager()
  50299. {
  50300. }
  50301. void StretchableLayoutManager::clearAllItems()
  50302. {
  50303. items.clear();
  50304. totalSize = 0;
  50305. }
  50306. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  50307. const double minimumSize,
  50308. const double maximumSize,
  50309. const double preferredSize)
  50310. {
  50311. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  50312. if (layout == 0)
  50313. {
  50314. layout = new ItemLayoutProperties();
  50315. layout->itemIndex = itemIndex;
  50316. int i;
  50317. for (i = 0; i < items.size(); ++i)
  50318. if (items.getUnchecked (i)->itemIndex > itemIndex)
  50319. break;
  50320. items.insert (i, layout);
  50321. }
  50322. layout->minSize = minimumSize;
  50323. layout->maxSize = maximumSize;
  50324. layout->preferredSize = preferredSize;
  50325. layout->currentSize = 0;
  50326. }
  50327. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  50328. double& minimumSize,
  50329. double& maximumSize,
  50330. double& preferredSize) const
  50331. {
  50332. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50333. if (layout != 0)
  50334. {
  50335. minimumSize = layout->minSize;
  50336. maximumSize = layout->maxSize;
  50337. preferredSize = layout->preferredSize;
  50338. return true;
  50339. }
  50340. return false;
  50341. }
  50342. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  50343. {
  50344. totalSize = newTotalSize;
  50345. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  50346. }
  50347. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  50348. {
  50349. int pos = 0;
  50350. for (int i = 0; i < itemIndex; ++i)
  50351. {
  50352. const ItemLayoutProperties* const layout = getInfoFor (i);
  50353. if (layout != 0)
  50354. pos += layout->currentSize;
  50355. }
  50356. return pos;
  50357. }
  50358. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  50359. {
  50360. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50361. if (layout != 0)
  50362. return layout->currentSize;
  50363. return 0;
  50364. }
  50365. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  50366. {
  50367. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50368. if (layout != 0)
  50369. return -layout->currentSize / (double) totalSize;
  50370. return 0;
  50371. }
  50372. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  50373. int newPosition)
  50374. {
  50375. for (int i = items.size(); --i >= 0;)
  50376. {
  50377. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  50378. if (layout->itemIndex == itemIndex)
  50379. {
  50380. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  50381. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  50382. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  50383. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  50384. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  50385. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  50386. endPos += layout->currentSize;
  50387. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  50388. updatePrefSizesToMatchCurrentPositions();
  50389. break;
  50390. }
  50391. }
  50392. }
  50393. void StretchableLayoutManager::layOutComponents (Component** const components,
  50394. int numComponents,
  50395. int x, int y, int w, int h,
  50396. const bool vertically,
  50397. const bool resizeOtherDimension)
  50398. {
  50399. setTotalSize (vertically ? h : w);
  50400. int pos = vertically ? y : x;
  50401. for (int i = 0; i < numComponents; ++i)
  50402. {
  50403. const ItemLayoutProperties* const layout = getInfoFor (i);
  50404. if (layout != 0)
  50405. {
  50406. Component* const c = components[i];
  50407. if (c != 0)
  50408. {
  50409. if (i == numComponents - 1)
  50410. {
  50411. // if it's the last item, crop it to exactly fit the available space..
  50412. if (resizeOtherDimension)
  50413. {
  50414. if (vertically)
  50415. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  50416. else
  50417. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  50418. }
  50419. else
  50420. {
  50421. if (vertically)
  50422. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  50423. else
  50424. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  50425. }
  50426. }
  50427. else
  50428. {
  50429. if (resizeOtherDimension)
  50430. {
  50431. if (vertically)
  50432. c->setBounds (x, pos, w, layout->currentSize);
  50433. else
  50434. c->setBounds (pos, y, layout->currentSize, h);
  50435. }
  50436. else
  50437. {
  50438. if (vertically)
  50439. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  50440. else
  50441. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  50442. }
  50443. }
  50444. }
  50445. pos += layout->currentSize;
  50446. }
  50447. }
  50448. }
  50449. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  50450. {
  50451. for (int i = items.size(); --i >= 0;)
  50452. if (items.getUnchecked(i)->itemIndex == itemIndex)
  50453. return items.getUnchecked(i);
  50454. return 0;
  50455. }
  50456. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  50457. const int endIndex,
  50458. const int availableSpace,
  50459. int startPos)
  50460. {
  50461. // calculate the total sizes
  50462. int i;
  50463. double totalIdealSize = 0.0;
  50464. int totalMinimums = 0;
  50465. for (i = startIndex; i < endIndex; ++i)
  50466. {
  50467. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50468. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  50469. totalMinimums += layout->currentSize;
  50470. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  50471. }
  50472. if (totalIdealSize <= 0)
  50473. totalIdealSize = 1.0;
  50474. // now calc the best sizes..
  50475. int extraSpace = availableSpace - totalMinimums;
  50476. while (extraSpace > 0)
  50477. {
  50478. int numWantingMoreSpace = 0;
  50479. int numHavingTakenExtraSpace = 0;
  50480. // first figure out how many comps want a slice of the extra space..
  50481. for (i = startIndex; i < endIndex; ++i)
  50482. {
  50483. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50484. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50485. const int bestSize = jlimit (layout->currentSize,
  50486. jmax (layout->currentSize,
  50487. sizeToRealSize (layout->maxSize, totalSize)),
  50488. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50489. if (bestSize > layout->currentSize)
  50490. ++numWantingMoreSpace;
  50491. }
  50492. // ..share out the extra space..
  50493. for (i = startIndex; i < endIndex; ++i)
  50494. {
  50495. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50496. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50497. int bestSize = jlimit (layout->currentSize,
  50498. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  50499. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50500. const int extraWanted = bestSize - layout->currentSize;
  50501. if (extraWanted > 0)
  50502. {
  50503. const int extraAllowed = jmin (extraWanted,
  50504. extraSpace / jmax (1, numWantingMoreSpace));
  50505. if (extraAllowed > 0)
  50506. {
  50507. ++numHavingTakenExtraSpace;
  50508. --numWantingMoreSpace;
  50509. layout->currentSize += extraAllowed;
  50510. extraSpace -= extraAllowed;
  50511. }
  50512. }
  50513. }
  50514. if (numHavingTakenExtraSpace <= 0)
  50515. break;
  50516. }
  50517. // ..and calculate the end position
  50518. for (i = startIndex; i < endIndex; ++i)
  50519. {
  50520. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50521. startPos += layout->currentSize;
  50522. }
  50523. return startPos;
  50524. }
  50525. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50526. const int endIndex) const
  50527. {
  50528. int totalMinimums = 0;
  50529. for (int i = startIndex; i < endIndex; ++i)
  50530. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50531. return totalMinimums;
  50532. }
  50533. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50534. {
  50535. int totalMaximums = 0;
  50536. for (int i = startIndex; i < endIndex; ++i)
  50537. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50538. return totalMaximums;
  50539. }
  50540. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50541. {
  50542. for (int i = 0; i < items.size(); ++i)
  50543. {
  50544. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50545. layout->preferredSize
  50546. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50547. : getItemCurrentAbsoluteSize (i);
  50548. }
  50549. }
  50550. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50551. {
  50552. if (size < 0)
  50553. size *= -totalSpace;
  50554. return roundToInt (size);
  50555. }
  50556. END_JUCE_NAMESPACE
  50557. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  50558. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50559. BEGIN_JUCE_NAMESPACE
  50560. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50561. const int itemIndex_,
  50562. const bool isVertical_)
  50563. : layout (layout_),
  50564. itemIndex (itemIndex_),
  50565. isVertical (isVertical_)
  50566. {
  50567. setRepaintsOnMouseActivity (true);
  50568. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50569. : MouseCursor::UpDownResizeCursor));
  50570. }
  50571. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50572. {
  50573. }
  50574. void StretchableLayoutResizerBar::paint (Graphics& g)
  50575. {
  50576. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50577. getWidth(), getHeight(),
  50578. isVertical,
  50579. isMouseOver(),
  50580. isMouseButtonDown());
  50581. }
  50582. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50583. {
  50584. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50585. }
  50586. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50587. {
  50588. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50589. : e.getDistanceFromDragStartY());
  50590. layout->setItemPosition (itemIndex, desiredPos);
  50591. hasBeenMoved();
  50592. }
  50593. void StretchableLayoutResizerBar::hasBeenMoved()
  50594. {
  50595. if (getParentComponent() != 0)
  50596. getParentComponent()->resized();
  50597. }
  50598. END_JUCE_NAMESPACE
  50599. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50600. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50601. BEGIN_JUCE_NAMESPACE
  50602. StretchableObjectResizer::StretchableObjectResizer()
  50603. {
  50604. }
  50605. StretchableObjectResizer::~StretchableObjectResizer()
  50606. {
  50607. }
  50608. void StretchableObjectResizer::addItem (const double size,
  50609. const double minSize, const double maxSize,
  50610. const int order)
  50611. {
  50612. // the order must be >= 0 but less than the maximum integer value.
  50613. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50614. Item* const item = new Item();
  50615. item->size = size;
  50616. item->minSize = minSize;
  50617. item->maxSize = maxSize;
  50618. item->order = order;
  50619. items.add (item);
  50620. }
  50621. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50622. {
  50623. const Item* const it = items [index];
  50624. return it != 0 ? it->size : 0;
  50625. }
  50626. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50627. {
  50628. int order = 0;
  50629. for (;;)
  50630. {
  50631. double currentSize = 0;
  50632. double minSize = 0;
  50633. double maxSize = 0;
  50634. int nextHighestOrder = std::numeric_limits<int>::max();
  50635. for (int i = 0; i < items.size(); ++i)
  50636. {
  50637. const Item* const it = items.getUnchecked(i);
  50638. currentSize += it->size;
  50639. if (it->order <= order)
  50640. {
  50641. minSize += it->minSize;
  50642. maxSize += it->maxSize;
  50643. }
  50644. else
  50645. {
  50646. minSize += it->size;
  50647. maxSize += it->size;
  50648. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50649. }
  50650. }
  50651. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50652. if (thisIterationTarget >= currentSize)
  50653. {
  50654. const double availableExtraSpace = maxSize - currentSize;
  50655. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50656. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50657. for (int i = 0; i < items.size(); ++i)
  50658. {
  50659. Item* const it = items.getUnchecked(i);
  50660. if (it->order <= order)
  50661. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50662. }
  50663. }
  50664. else
  50665. {
  50666. const double amountOfSlack = currentSize - minSize;
  50667. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50668. const double scale = targetAmountOfSlack / amountOfSlack;
  50669. for (int i = 0; i < items.size(); ++i)
  50670. {
  50671. Item* const it = items.getUnchecked(i);
  50672. if (it->order <= order)
  50673. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50674. }
  50675. }
  50676. if (nextHighestOrder < std::numeric_limits<int>::max())
  50677. order = nextHighestOrder;
  50678. else
  50679. break;
  50680. }
  50681. }
  50682. END_JUCE_NAMESPACE
  50683. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50684. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50685. BEGIN_JUCE_NAMESPACE
  50686. TabBarButton::TabBarButton (const String& name,
  50687. TabbedButtonBar* const owner_,
  50688. const int index)
  50689. : Button (name),
  50690. owner (owner_),
  50691. tabIndex (index),
  50692. overlapPixels (0)
  50693. {
  50694. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50695. setComponentEffect (&shadow);
  50696. setWantsKeyboardFocus (false);
  50697. }
  50698. TabBarButton::~TabBarButton()
  50699. {
  50700. }
  50701. void TabBarButton::paintButton (Graphics& g,
  50702. bool isMouseOverButton,
  50703. bool isButtonDown)
  50704. {
  50705. int x, y, w, h;
  50706. getActiveArea (x, y, w, h);
  50707. g.setOrigin (x, y);
  50708. getLookAndFeel()
  50709. .drawTabButton (g, w, h,
  50710. owner->getTabBackgroundColour (tabIndex),
  50711. tabIndex, getButtonText(), *this,
  50712. owner->getOrientation(),
  50713. isMouseOverButton, isButtonDown,
  50714. getToggleState());
  50715. }
  50716. void TabBarButton::clicked (const ModifierKeys& mods)
  50717. {
  50718. if (mods.isPopupMenu())
  50719. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50720. else
  50721. owner->setCurrentTabIndex (tabIndex);
  50722. }
  50723. bool TabBarButton::hitTest (int mx, int my)
  50724. {
  50725. int x, y, w, h;
  50726. getActiveArea (x, y, w, h);
  50727. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50728. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50729. {
  50730. if (((unsigned int) mx) < (unsigned int) getWidth()
  50731. && my >= y + overlapPixels
  50732. && my < y + h - overlapPixels)
  50733. return true;
  50734. }
  50735. else
  50736. {
  50737. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50738. && ((unsigned int) my) < (unsigned int) getHeight())
  50739. return true;
  50740. }
  50741. Path p;
  50742. getLookAndFeel()
  50743. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50744. owner->getOrientation(),
  50745. false, false, getToggleState());
  50746. return p.contains ((float) (mx - x),
  50747. (float) (my - y));
  50748. }
  50749. int TabBarButton::getBestTabLength (const int depth)
  50750. {
  50751. return jlimit (depth * 2,
  50752. depth * 7,
  50753. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50754. }
  50755. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50756. {
  50757. x = 0;
  50758. y = 0;
  50759. int r = getWidth();
  50760. int b = getHeight();
  50761. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50762. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50763. r -= spaceAroundImage;
  50764. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50765. x += spaceAroundImage;
  50766. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50767. y += spaceAroundImage;
  50768. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50769. b -= spaceAroundImage;
  50770. w = r - x;
  50771. h = b - y;
  50772. }
  50773. class TabAreaBehindFrontButtonComponent : public Component
  50774. {
  50775. public:
  50776. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50777. : owner (owner_)
  50778. {
  50779. setInterceptsMouseClicks (false, false);
  50780. }
  50781. ~TabAreaBehindFrontButtonComponent()
  50782. {
  50783. }
  50784. void paint (Graphics& g)
  50785. {
  50786. getLookAndFeel()
  50787. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50788. *owner, owner->getOrientation());
  50789. }
  50790. void enablementChanged()
  50791. {
  50792. repaint();
  50793. }
  50794. private:
  50795. TabbedButtonBar* const owner;
  50796. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50797. const TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50798. };
  50799. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50800. : orientation (orientation_),
  50801. currentTabIndex (-1),
  50802. extraTabsButton (0)
  50803. {
  50804. setInterceptsMouseClicks (false, true);
  50805. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50806. setFocusContainer (true);
  50807. }
  50808. TabbedButtonBar::~TabbedButtonBar()
  50809. {
  50810. deleteAllChildren();
  50811. }
  50812. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50813. {
  50814. orientation = newOrientation;
  50815. for (int i = getNumChildComponents(); --i >= 0;)
  50816. getChildComponent (i)->resized();
  50817. resized();
  50818. }
  50819. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50820. {
  50821. return new TabBarButton (name, this, index);
  50822. }
  50823. void TabbedButtonBar::clearTabs()
  50824. {
  50825. tabs.clear();
  50826. tabColours.clear();
  50827. currentTabIndex = -1;
  50828. deleteAndZero (extraTabsButton);
  50829. removeChildComponent (behindFrontTab);
  50830. deleteAllChildren();
  50831. addChildComponent (behindFrontTab);
  50832. setCurrentTabIndex (-1);
  50833. }
  50834. void TabbedButtonBar::addTab (const String& tabName,
  50835. const Colour& tabBackgroundColour,
  50836. int insertIndex)
  50837. {
  50838. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50839. if (tabName.isNotEmpty())
  50840. {
  50841. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50842. insertIndex = tabs.size();
  50843. for (int i = tabs.size(); --i >= insertIndex;)
  50844. {
  50845. TabBarButton* const tb = getTabButton (i);
  50846. if (tb != 0)
  50847. tb->tabIndex++;
  50848. }
  50849. tabs.insert (insertIndex, tabName);
  50850. tabColours.insert (insertIndex, tabBackgroundColour);
  50851. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50852. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50853. addAndMakeVisible (tb, insertIndex);
  50854. resized();
  50855. if (currentTabIndex < 0)
  50856. setCurrentTabIndex (0);
  50857. }
  50858. }
  50859. void TabbedButtonBar::setTabName (const int tabIndex,
  50860. const String& newName)
  50861. {
  50862. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50863. && tabs[tabIndex] != newName)
  50864. {
  50865. tabs.set (tabIndex, newName);
  50866. TabBarButton* const tb = getTabButton (tabIndex);
  50867. if (tb != 0)
  50868. tb->setButtonText (newName);
  50869. resized();
  50870. }
  50871. }
  50872. void TabbedButtonBar::removeTab (const int tabIndex)
  50873. {
  50874. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50875. {
  50876. const int oldTabIndex = currentTabIndex;
  50877. if (currentTabIndex == tabIndex)
  50878. currentTabIndex = -1;
  50879. tabs.remove (tabIndex);
  50880. tabColours.remove (tabIndex);
  50881. delete getTabButton (tabIndex);
  50882. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50883. {
  50884. TabBarButton* const tb = getTabButton (i);
  50885. if (tb != 0)
  50886. tb->tabIndex--;
  50887. }
  50888. resized();
  50889. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50890. }
  50891. }
  50892. void TabbedButtonBar::moveTab (const int currentIndex,
  50893. const int newIndex)
  50894. {
  50895. tabs.move (currentIndex, newIndex);
  50896. tabColours.move (currentIndex, newIndex);
  50897. resized();
  50898. }
  50899. int TabbedButtonBar::getNumTabs() const
  50900. {
  50901. return tabs.size();
  50902. }
  50903. const StringArray TabbedButtonBar::getTabNames() const
  50904. {
  50905. return tabs;
  50906. }
  50907. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50908. {
  50909. if (currentTabIndex != newIndex)
  50910. {
  50911. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50912. newIndex = -1;
  50913. currentTabIndex = newIndex;
  50914. for (int i = 0; i < getNumChildComponents(); ++i)
  50915. {
  50916. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50917. if (tb != 0)
  50918. tb->setToggleState (tb->tabIndex == newIndex, false);
  50919. }
  50920. resized();
  50921. if (sendChangeMessage_)
  50922. sendChangeMessage (this);
  50923. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50924. }
  50925. }
  50926. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50927. {
  50928. for (int i = getNumChildComponents(); --i >= 0;)
  50929. {
  50930. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50931. if (tb != 0 && tb->tabIndex == index)
  50932. return tb;
  50933. }
  50934. return 0;
  50935. }
  50936. void TabbedButtonBar::lookAndFeelChanged()
  50937. {
  50938. deleteAndZero (extraTabsButton);
  50939. resized();
  50940. }
  50941. void TabbedButtonBar::resized()
  50942. {
  50943. const double minimumScale = 0.7;
  50944. int depth = getWidth();
  50945. int length = getHeight();
  50946. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50947. swapVariables (depth, length);
  50948. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50949. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50950. int i, totalLength = overlap;
  50951. int numVisibleButtons = tabs.size();
  50952. for (i = 0; i < getNumChildComponents(); ++i)
  50953. {
  50954. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50955. if (tb != 0)
  50956. {
  50957. totalLength += tb->getBestTabLength (depth) - overlap;
  50958. tb->overlapPixels = overlap / 2;
  50959. }
  50960. }
  50961. double scale = 1.0;
  50962. if (totalLength > length)
  50963. scale = jmax (minimumScale, length / (double) totalLength);
  50964. const bool isTooBig = totalLength * scale > length;
  50965. int tabsButtonPos = 0;
  50966. if (isTooBig)
  50967. {
  50968. if (extraTabsButton == 0)
  50969. {
  50970. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50971. extraTabsButton->addButtonListener (this);
  50972. extraTabsButton->setAlwaysOnTop (true);
  50973. extraTabsButton->setTriggeredOnMouseDown (true);
  50974. }
  50975. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50976. extraTabsButton->setSize (buttonSize, buttonSize);
  50977. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50978. {
  50979. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50980. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50981. }
  50982. else
  50983. {
  50984. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50985. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50986. }
  50987. totalLength = 0;
  50988. for (i = 0; i < tabs.size(); ++i)
  50989. {
  50990. TabBarButton* const tb = getTabButton (i);
  50991. if (tb != 0)
  50992. {
  50993. const int newLength = totalLength + tb->getBestTabLength (depth);
  50994. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50995. {
  50996. totalLength += overlap;
  50997. break;
  50998. }
  50999. numVisibleButtons = i + 1;
  51000. totalLength = newLength - overlap;
  51001. }
  51002. }
  51003. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  51004. }
  51005. else
  51006. {
  51007. deleteAndZero (extraTabsButton);
  51008. }
  51009. int pos = 0;
  51010. TabBarButton* frontTab = 0;
  51011. for (i = 0; i < tabs.size(); ++i)
  51012. {
  51013. TabBarButton* const tb = getTabButton (i);
  51014. if (tb != 0)
  51015. {
  51016. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  51017. if (i < numVisibleButtons)
  51018. {
  51019. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51020. tb->setBounds (pos, 0, bestLength, getHeight());
  51021. else
  51022. tb->setBounds (0, pos, getWidth(), bestLength);
  51023. tb->toBack();
  51024. if (tb->tabIndex == currentTabIndex)
  51025. frontTab = tb;
  51026. tb->setVisible (true);
  51027. }
  51028. else
  51029. {
  51030. tb->setVisible (false);
  51031. }
  51032. pos += bestLength - overlap;
  51033. }
  51034. }
  51035. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  51036. if (frontTab != 0)
  51037. {
  51038. frontTab->toFront (false);
  51039. behindFrontTab->toBehind (frontTab);
  51040. }
  51041. }
  51042. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  51043. {
  51044. return tabColours [tabIndex];
  51045. }
  51046. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51047. {
  51048. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  51049. && tabColours [tabIndex] != newColour)
  51050. {
  51051. tabColours.set (tabIndex, newColour);
  51052. repaint();
  51053. }
  51054. }
  51055. void TabbedButtonBar::buttonClicked (Button* button)
  51056. {
  51057. if (extraTabsButton == button)
  51058. {
  51059. PopupMenu m;
  51060. for (int i = 0; i < tabs.size(); ++i)
  51061. {
  51062. TabBarButton* const tb = getTabButton (i);
  51063. if (tb != 0 && ! tb->isVisible())
  51064. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  51065. }
  51066. const int res = m.showAt (extraTabsButton);
  51067. if (res != 0)
  51068. setCurrentTabIndex (res - 1);
  51069. }
  51070. }
  51071. void TabbedButtonBar::currentTabChanged (const int, const String&)
  51072. {
  51073. }
  51074. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  51075. {
  51076. }
  51077. END_JUCE_NAMESPACE
  51078. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  51079. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  51080. BEGIN_JUCE_NAMESPACE
  51081. class TabCompButtonBar : public TabbedButtonBar
  51082. {
  51083. public:
  51084. TabCompButtonBar (TabbedComponent* const owner_,
  51085. const TabbedButtonBar::Orientation orientation)
  51086. : TabbedButtonBar (orientation),
  51087. owner (owner_)
  51088. {
  51089. }
  51090. ~TabCompButtonBar()
  51091. {
  51092. }
  51093. void currentTabChanged (const int newCurrentTabIndex,
  51094. const String& newTabName)
  51095. {
  51096. owner->changeCallback (newCurrentTabIndex, newTabName);
  51097. }
  51098. void popupMenuClickOnTab (const int tabIndex,
  51099. const String& tabName)
  51100. {
  51101. owner->popupMenuClickOnTab (tabIndex, tabName);
  51102. }
  51103. const Colour getTabBackgroundColour (const int tabIndex)
  51104. {
  51105. return owner->tabs->getTabBackgroundColour (tabIndex);
  51106. }
  51107. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  51108. {
  51109. return owner->createTabButton (tabName, tabIndex);
  51110. }
  51111. juce_UseDebuggingNewOperator
  51112. private:
  51113. TabbedComponent* const owner;
  51114. TabCompButtonBar (const TabCompButtonBar&);
  51115. const TabCompButtonBar& operator= (const TabCompButtonBar&);
  51116. };
  51117. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  51118. : panelComponent (0),
  51119. tabDepth (30),
  51120. outlineThickness (1),
  51121. edgeIndent (0)
  51122. {
  51123. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  51124. }
  51125. TabbedComponent::~TabbedComponent()
  51126. {
  51127. clearTabs();
  51128. delete tabs;
  51129. }
  51130. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  51131. {
  51132. tabs->setOrientation (orientation);
  51133. resized();
  51134. }
  51135. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  51136. {
  51137. return tabs->getOrientation();
  51138. }
  51139. void TabbedComponent::setTabBarDepth (const int newDepth)
  51140. {
  51141. if (tabDepth != newDepth)
  51142. {
  51143. tabDepth = newDepth;
  51144. resized();
  51145. }
  51146. }
  51147. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  51148. {
  51149. return new TabBarButton (tabName, tabs, tabIndex);
  51150. }
  51151. void TabbedComponent::clearTabs()
  51152. {
  51153. if (panelComponent != 0)
  51154. {
  51155. panelComponent->setVisible (false);
  51156. removeChildComponent (panelComponent);
  51157. panelComponent = 0;
  51158. }
  51159. tabs->clearTabs();
  51160. for (int i = contentComponents.size(); --i >= 0;)
  51161. {
  51162. Component* const c = contentComponents.getUnchecked(i);
  51163. // be careful not to delete these components until they've been removed from the tab component
  51164. jassert (c == 0 || c->isValidComponent());
  51165. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51166. delete c;
  51167. }
  51168. contentComponents.clear();
  51169. }
  51170. void TabbedComponent::addTab (const String& tabName,
  51171. const Colour& tabBackgroundColour,
  51172. Component* const contentComponent,
  51173. const bool deleteComponentWhenNotNeeded,
  51174. const int insertIndex)
  51175. {
  51176. contentComponents.insert (insertIndex, contentComponent);
  51177. if (contentComponent != 0)
  51178. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  51179. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  51180. }
  51181. void TabbedComponent::setTabName (const int tabIndex,
  51182. const String& newName)
  51183. {
  51184. tabs->setTabName (tabIndex, newName);
  51185. }
  51186. void TabbedComponent::removeTab (const int tabIndex)
  51187. {
  51188. Component* const c = contentComponents [tabIndex];
  51189. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51190. {
  51191. if (c == panelComponent)
  51192. panelComponent = 0;
  51193. delete c;
  51194. }
  51195. contentComponents.remove (tabIndex);
  51196. tabs->removeTab (tabIndex);
  51197. }
  51198. int TabbedComponent::getNumTabs() const
  51199. {
  51200. return tabs->getNumTabs();
  51201. }
  51202. const StringArray TabbedComponent::getTabNames() const
  51203. {
  51204. return tabs->getTabNames();
  51205. }
  51206. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  51207. {
  51208. return contentComponents [tabIndex];
  51209. }
  51210. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  51211. {
  51212. return tabs->getTabBackgroundColour (tabIndex);
  51213. }
  51214. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51215. {
  51216. tabs->setTabBackgroundColour (tabIndex, newColour);
  51217. if (getCurrentTabIndex() == tabIndex)
  51218. repaint();
  51219. }
  51220. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  51221. {
  51222. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  51223. }
  51224. int TabbedComponent::getCurrentTabIndex() const
  51225. {
  51226. return tabs->getCurrentTabIndex();
  51227. }
  51228. const String& TabbedComponent::getCurrentTabName() const
  51229. {
  51230. return tabs->getCurrentTabName();
  51231. }
  51232. void TabbedComponent::setOutline (int thickness)
  51233. {
  51234. outlineThickness = thickness;
  51235. repaint();
  51236. }
  51237. void TabbedComponent::setIndent (const int indentThickness)
  51238. {
  51239. edgeIndent = indentThickness;
  51240. }
  51241. void TabbedComponent::paint (Graphics& g)
  51242. {
  51243. g.fillAll (findColour (backgroundColourId));
  51244. const TabbedButtonBar::Orientation o = getOrientation();
  51245. int x = 0;
  51246. int y = 0;
  51247. int r = getWidth();
  51248. int b = getHeight();
  51249. if (o == TabbedButtonBar::TabsAtTop)
  51250. y += tabDepth;
  51251. else if (o == TabbedButtonBar::TabsAtBottom)
  51252. b -= tabDepth;
  51253. else if (o == TabbedButtonBar::TabsAtLeft)
  51254. x += tabDepth;
  51255. else if (o == TabbedButtonBar::TabsAtRight)
  51256. r -= tabDepth;
  51257. g.reduceClipRegion (x, y, r - x, b - y);
  51258. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  51259. if (outlineThickness > 0)
  51260. {
  51261. if (o == TabbedButtonBar::TabsAtTop)
  51262. --y;
  51263. else if (o == TabbedButtonBar::TabsAtBottom)
  51264. ++b;
  51265. else if (o == TabbedButtonBar::TabsAtLeft)
  51266. --x;
  51267. else if (o == TabbedButtonBar::TabsAtRight)
  51268. ++r;
  51269. g.setColour (findColour (outlineColourId));
  51270. g.drawRect (x, y, r - x, b - y, outlineThickness);
  51271. }
  51272. }
  51273. void TabbedComponent::resized()
  51274. {
  51275. const TabbedButtonBar::Orientation o = getOrientation();
  51276. const int indent = edgeIndent + outlineThickness;
  51277. BorderSize indents (indent);
  51278. if (o == TabbedButtonBar::TabsAtTop)
  51279. {
  51280. tabs->setBounds (0, 0, getWidth(), tabDepth);
  51281. indents.setTop (tabDepth + edgeIndent);
  51282. }
  51283. else if (o == TabbedButtonBar::TabsAtBottom)
  51284. {
  51285. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  51286. indents.setBottom (tabDepth + edgeIndent);
  51287. }
  51288. else if (o == TabbedButtonBar::TabsAtLeft)
  51289. {
  51290. tabs->setBounds (0, 0, tabDepth, getHeight());
  51291. indents.setLeft (tabDepth + edgeIndent);
  51292. }
  51293. else if (o == TabbedButtonBar::TabsAtRight)
  51294. {
  51295. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  51296. indents.setRight (tabDepth + edgeIndent);
  51297. }
  51298. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  51299. for (int i = contentComponents.size(); --i >= 0;)
  51300. if (contentComponents.getUnchecked (i) != 0)
  51301. contentComponents.getUnchecked (i)->setBounds (bounds);
  51302. }
  51303. void TabbedComponent::lookAndFeelChanged()
  51304. {
  51305. for (int i = contentComponents.size(); --i >= 0;)
  51306. if (contentComponents.getUnchecked (i) != 0)
  51307. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  51308. }
  51309. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  51310. const String& newTabName)
  51311. {
  51312. if (panelComponent != 0)
  51313. {
  51314. panelComponent->setVisible (false);
  51315. removeChildComponent (panelComponent);
  51316. panelComponent = 0;
  51317. }
  51318. if (getCurrentTabIndex() >= 0)
  51319. {
  51320. panelComponent = contentComponents [getCurrentTabIndex()];
  51321. if (panelComponent != 0)
  51322. {
  51323. // do these ops as two stages instead of addAndMakeVisible() so that the
  51324. // component has always got a parent when it gets the visibilityChanged() callback
  51325. addChildComponent (panelComponent);
  51326. panelComponent->setVisible (true);
  51327. panelComponent->toFront (true);
  51328. }
  51329. repaint();
  51330. }
  51331. resized();
  51332. currentTabChanged (newCurrentTabIndex, newTabName);
  51333. }
  51334. void TabbedComponent::currentTabChanged (const int, const String&)
  51335. {
  51336. }
  51337. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  51338. {
  51339. }
  51340. END_JUCE_NAMESPACE
  51341. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  51342. /*** Start of inlined file: juce_Viewport.cpp ***/
  51343. BEGIN_JUCE_NAMESPACE
  51344. Viewport::Viewport (const String& componentName)
  51345. : Component (componentName),
  51346. contentComp (0),
  51347. lastVX (0),
  51348. lastVY (0),
  51349. lastVW (0),
  51350. lastVH (0),
  51351. scrollBarThickness (0),
  51352. singleStepX (16),
  51353. singleStepY (16),
  51354. showHScrollbar (true),
  51355. showVScrollbar (true)
  51356. {
  51357. // content holder is used to clip the contents so they don't overlap the scrollbars
  51358. addAndMakeVisible (contentHolder = new Component());
  51359. contentHolder->setInterceptsMouseClicks (false, true);
  51360. verticalScrollBar = new ScrollBar (true);
  51361. horizontalScrollBar = new ScrollBar (false);
  51362. addChildComponent (verticalScrollBar);
  51363. addChildComponent (horizontalScrollBar);
  51364. verticalScrollBar->addListener (this);
  51365. horizontalScrollBar->addListener (this);
  51366. setInterceptsMouseClicks (false, true);
  51367. setWantsKeyboardFocus (true);
  51368. }
  51369. Viewport::~Viewport()
  51370. {
  51371. contentHolder->deleteAllChildren();
  51372. deleteAllChildren();
  51373. }
  51374. void Viewport::visibleAreaChanged (int, int, int, int)
  51375. {
  51376. }
  51377. void Viewport::setViewedComponent (Component* const newViewedComponent)
  51378. {
  51379. if (contentComp != newViewedComponent)
  51380. {
  51381. if (contentComp->isValidComponent())
  51382. {
  51383. Component* const oldComp = contentComp;
  51384. contentComp = 0;
  51385. delete oldComp;
  51386. }
  51387. contentComp = newViewedComponent;
  51388. if (contentComp != 0)
  51389. {
  51390. contentComp->setTopLeftPosition (0, 0);
  51391. contentHolder->addAndMakeVisible (contentComp);
  51392. contentComp->addComponentListener (this);
  51393. }
  51394. updateVisibleRegion();
  51395. }
  51396. }
  51397. int Viewport::getMaximumVisibleWidth() const throw()
  51398. {
  51399. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51400. }
  51401. int Viewport::getMaximumVisibleHeight() const throw()
  51402. {
  51403. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51404. }
  51405. void Viewport::setViewPosition (const int xPixelsOffset,
  51406. const int yPixelsOffset)
  51407. {
  51408. if (contentComp != 0)
  51409. contentComp->setTopLeftPosition (-xPixelsOffset,
  51410. -yPixelsOffset);
  51411. }
  51412. void Viewport::setViewPositionProportionately (const double x,
  51413. const double y)
  51414. {
  51415. if (contentComp != 0)
  51416. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  51417. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  51418. }
  51419. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  51420. {
  51421. if (contentComp != 0)
  51422. {
  51423. int dx = 0, dy = 0;
  51424. if (mouseX < activeBorderThickness)
  51425. dx = activeBorderThickness - mouseX;
  51426. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  51427. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  51428. if (dx < 0)
  51429. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  51430. else
  51431. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  51432. if (mouseY < activeBorderThickness)
  51433. dy = activeBorderThickness - mouseY;
  51434. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  51435. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  51436. if (dy < 0)
  51437. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  51438. else
  51439. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  51440. if (dx != 0 || dy != 0)
  51441. {
  51442. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  51443. contentComp->getY() + dy);
  51444. return true;
  51445. }
  51446. }
  51447. return false;
  51448. }
  51449. void Viewport::componentMovedOrResized (Component&, bool, bool)
  51450. {
  51451. updateVisibleRegion();
  51452. }
  51453. void Viewport::resized()
  51454. {
  51455. updateVisibleRegion();
  51456. }
  51457. void Viewport::updateVisibleRegion()
  51458. {
  51459. if (contentComp != 0)
  51460. {
  51461. const int newVX = -contentComp->getX();
  51462. const int newVY = -contentComp->getY();
  51463. if (newVX == 0 && newVY == 0
  51464. && contentComp->getWidth() <= getWidth()
  51465. && contentComp->getHeight() <= getHeight())
  51466. {
  51467. horizontalScrollBar->setVisible (false);
  51468. verticalScrollBar->setVisible (false);
  51469. }
  51470. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  51471. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51472. horizontalScrollBar->setSingleStepSize (singleStepX);
  51473. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  51474. horizontalScrollBar->setVisible (false);
  51475. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  51476. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51477. verticalScrollBar->setSingleStepSize (singleStepY);
  51478. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  51479. verticalScrollBar->setVisible (false);
  51480. if (verticalScrollBar->isVisible())
  51481. {
  51482. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51483. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51484. verticalScrollBar
  51485. ->setBounds (getMaximumVisibleWidth(), 0,
  51486. getScrollBarThickness(), getMaximumVisibleHeight());
  51487. }
  51488. if (horizontalScrollBar->isVisible())
  51489. {
  51490. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51491. horizontalScrollBar
  51492. ->setBounds (0, getMaximumVisibleHeight(),
  51493. getMaximumVisibleWidth(), getScrollBarThickness());
  51494. }
  51495. contentHolder->setSize (getMaximumVisibleWidth(),
  51496. getMaximumVisibleHeight());
  51497. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  51498. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  51499. if (newVX != lastVX
  51500. || newVY != lastVY
  51501. || newVW != lastVW
  51502. || newVH != lastVH)
  51503. {
  51504. lastVX = newVX;
  51505. lastVY = newVY;
  51506. lastVW = newVW;
  51507. lastVH = newVH;
  51508. visibleAreaChanged (newVX, newVY, newVW, newVH);
  51509. }
  51510. horizontalScrollBar->handleUpdateNowIfNeeded();
  51511. verticalScrollBar->handleUpdateNowIfNeeded();
  51512. }
  51513. else
  51514. {
  51515. horizontalScrollBar->setVisible (false);
  51516. verticalScrollBar->setVisible (false);
  51517. }
  51518. }
  51519. void Viewport::setSingleStepSizes (const int stepX,
  51520. const int stepY)
  51521. {
  51522. singleStepX = stepX;
  51523. singleStepY = stepY;
  51524. updateVisibleRegion();
  51525. }
  51526. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51527. const bool showHorizontalScrollbarIfNeeded)
  51528. {
  51529. showVScrollbar = showVerticalScrollbarIfNeeded;
  51530. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51531. updateVisibleRegion();
  51532. }
  51533. void Viewport::setScrollBarThickness (const int thickness)
  51534. {
  51535. scrollBarThickness = thickness;
  51536. updateVisibleRegion();
  51537. }
  51538. int Viewport::getScrollBarThickness() const throw()
  51539. {
  51540. return (scrollBarThickness > 0) ? scrollBarThickness
  51541. : getLookAndFeel().getDefaultScrollbarWidth();
  51542. }
  51543. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51544. {
  51545. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51546. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51547. }
  51548. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  51549. {
  51550. if (scrollBarThatHasMoved == horizontalScrollBar)
  51551. {
  51552. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51553. }
  51554. else if (scrollBarThatHasMoved == verticalScrollBar)
  51555. {
  51556. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51557. }
  51558. }
  51559. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51560. {
  51561. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51562. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51563. }
  51564. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51565. {
  51566. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51567. {
  51568. const bool hasVertBar = verticalScrollBar->isVisible();
  51569. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51570. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51571. {
  51572. if (wheelIncrementX == 0 && ! hasVertBar)
  51573. wheelIncrementX = wheelIncrementY;
  51574. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51575. wheelIncrementX, wheelIncrementY);
  51576. return true;
  51577. }
  51578. else if (hasVertBar && wheelIncrementY != 0)
  51579. {
  51580. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51581. wheelIncrementX, wheelIncrementY);
  51582. return true;
  51583. }
  51584. }
  51585. return false;
  51586. }
  51587. bool Viewport::keyPressed (const KeyPress& key)
  51588. {
  51589. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51590. || key.isKeyCode (KeyPress::downKey)
  51591. || key.isKeyCode (KeyPress::pageUpKey)
  51592. || key.isKeyCode (KeyPress::pageDownKey)
  51593. || key.isKeyCode (KeyPress::homeKey)
  51594. || key.isKeyCode (KeyPress::endKey);
  51595. if (verticalScrollBar->isVisible() && isUpDownKey)
  51596. return verticalScrollBar->keyPressed (key);
  51597. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51598. || key.isKeyCode (KeyPress::rightKey);
  51599. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51600. return horizontalScrollBar->keyPressed (key);
  51601. return false;
  51602. }
  51603. END_JUCE_NAMESPACE
  51604. /*** End of inlined file: juce_Viewport.cpp ***/
  51605. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51606. BEGIN_JUCE_NAMESPACE
  51607. static const Colour createBaseColour (const Colour& buttonColour,
  51608. const bool hasKeyboardFocus,
  51609. const bool isMouseOverButton,
  51610. const bool isButtonDown) throw()
  51611. {
  51612. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51613. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51614. if (isButtonDown)
  51615. return baseColour.contrasting (0.2f);
  51616. else if (isMouseOverButton)
  51617. return baseColour.contrasting (0.1f);
  51618. return baseColour;
  51619. }
  51620. static String defaultSansName, defaultSerifName, defaultFixedName;
  51621. void clearUpDefaultFontNames() throw()
  51622. {
  51623. defaultSansName = String::empty;
  51624. defaultSerifName = String::empty;
  51625. defaultFixedName = String::empty;
  51626. }
  51627. LookAndFeel::LookAndFeel()
  51628. {
  51629. /* if this fails it means you're trying to create a LookAndFeel object before
  51630. the static Colours have been initialised. That ain't gonna work. It probably
  51631. means that you're using a static LookAndFeel object and that your compiler has
  51632. decided to intialise it before the Colours class.
  51633. */
  51634. jassert (Colours::white == Colour (0xffffffff));
  51635. // set up the standard set of colours..
  51636. const int textButtonColour = 0xffbbbbff;
  51637. const int textHighlightColour = 0x401111ee;
  51638. const int standardOutlineColour = 0xb2808080;
  51639. static const int standardColours[] =
  51640. {
  51641. TextButton::buttonColourId, textButtonColour,
  51642. TextButton::buttonOnColourId, 0xff4444ff,
  51643. TextButton::textColourOnId, 0xff000000,
  51644. TextButton::textColourOffId, 0xff000000,
  51645. ComboBox::buttonColourId, 0xffbbbbff,
  51646. ComboBox::outlineColourId, standardOutlineColour,
  51647. ToggleButton::textColourId, 0xff000000,
  51648. TextEditor::backgroundColourId, 0xffffffff,
  51649. TextEditor::textColourId, 0xff000000,
  51650. TextEditor::highlightColourId, textHighlightColour,
  51651. TextEditor::highlightedTextColourId, 0xff000000,
  51652. TextEditor::caretColourId, 0xff000000,
  51653. TextEditor::outlineColourId, 0x00000000,
  51654. TextEditor::focusedOutlineColourId, textButtonColour,
  51655. TextEditor::shadowColourId, 0x38000000,
  51656. Label::backgroundColourId, 0x00000000,
  51657. Label::textColourId, 0xff000000,
  51658. Label::outlineColourId, 0x00000000,
  51659. ScrollBar::backgroundColourId, 0x00000000,
  51660. ScrollBar::thumbColourId, 0xffffffff,
  51661. ScrollBar::trackColourId, 0xffffffff,
  51662. TreeView::linesColourId, 0x4c000000,
  51663. TreeView::backgroundColourId, 0x00000000,
  51664. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51665. PopupMenu::backgroundColourId, 0xffffffff,
  51666. PopupMenu::textColourId, 0xff000000,
  51667. PopupMenu::headerTextColourId, 0xff000000,
  51668. PopupMenu::highlightedTextColourId, 0xffffffff,
  51669. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51670. ComboBox::textColourId, 0xff000000,
  51671. ComboBox::backgroundColourId, 0xffffffff,
  51672. ComboBox::arrowColourId, 0x99000000,
  51673. ListBox::backgroundColourId, 0xffffffff,
  51674. ListBox::outlineColourId, standardOutlineColour,
  51675. ListBox::textColourId, 0xff000000,
  51676. Slider::backgroundColourId, 0x00000000,
  51677. Slider::thumbColourId, textButtonColour,
  51678. Slider::trackColourId, 0x7fffffff,
  51679. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51680. Slider::rotarySliderOutlineColourId, 0x66000000,
  51681. Slider::textBoxTextColourId, 0xff000000,
  51682. Slider::textBoxBackgroundColourId, 0xffffffff,
  51683. Slider::textBoxHighlightColourId, textHighlightColour,
  51684. Slider::textBoxOutlineColourId, standardOutlineColour,
  51685. ResizableWindow::backgroundColourId, 0xff777777,
  51686. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51687. AlertWindow::backgroundColourId, 0xffededed,
  51688. AlertWindow::textColourId, 0xff000000,
  51689. AlertWindow::outlineColourId, 0xff666666,
  51690. ProgressBar::backgroundColourId, 0xffeeeeee,
  51691. ProgressBar::foregroundColourId, 0xffaaaaee,
  51692. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51693. TooltipWindow::textColourId, 0xff000000,
  51694. TooltipWindow::outlineColourId, 0x4c000000,
  51695. TabbedComponent::backgroundColourId, 0x00000000,
  51696. TabbedComponent::outlineColourId, 0xff777777,
  51697. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51698. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51699. Toolbar::backgroundColourId, 0xfff6f8f9,
  51700. Toolbar::separatorColourId, 0x4c000000,
  51701. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51702. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51703. Toolbar::labelTextColourId, 0xff000000,
  51704. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51705. HyperlinkButton::textColourId, 0xcc1111ee,
  51706. GroupComponent::outlineColourId, 0x66000000,
  51707. GroupComponent::textColourId, 0xff000000,
  51708. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51709. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51710. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51711. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51712. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51713. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51714. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51715. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51716. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51717. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51718. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51719. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51720. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51721. CodeEditorComponent::caretColourId, 0xff000000,
  51722. CodeEditorComponent::highlightColourId, textHighlightColour,
  51723. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51724. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51725. ColourSelector::labelTextColourId, 0xff000000,
  51726. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51727. KeyMappingEditorComponent::textColourId, 0xff000000,
  51728. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51729. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51730. };
  51731. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51732. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51733. if (defaultSansName.isEmpty())
  51734. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51735. defaultSans = defaultSansName;
  51736. defaultSerif = defaultSerifName;
  51737. defaultFixed = defaultFixedName;
  51738. }
  51739. LookAndFeel::~LookAndFeel()
  51740. {
  51741. }
  51742. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51743. {
  51744. const int index = colourIds.indexOf (colourId);
  51745. if (index >= 0)
  51746. return colours [index];
  51747. jassertfalse
  51748. return Colours::black;
  51749. }
  51750. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51751. {
  51752. const int index = colourIds.indexOf (colourId);
  51753. if (index >= 0)
  51754. colours.set (index, colour);
  51755. colourIds.add (colourId);
  51756. colours.add (colour);
  51757. }
  51758. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51759. {
  51760. return colourIds.contains (colourId);
  51761. }
  51762. static LookAndFeel* defaultLF = 0;
  51763. static LookAndFeel* currentDefaultLF = 0;
  51764. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51765. {
  51766. // if this happens, your app hasn't initialised itself properly.. if you're
  51767. // trying to hack your own main() function, have a look at
  51768. // JUCEApplication::initialiseForGUI()
  51769. jassert (currentDefaultLF != 0);
  51770. return *currentDefaultLF;
  51771. }
  51772. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51773. {
  51774. if (newDefaultLookAndFeel == 0)
  51775. {
  51776. if (defaultLF == 0)
  51777. defaultLF = new LookAndFeel();
  51778. newDefaultLookAndFeel = defaultLF;
  51779. }
  51780. currentDefaultLF = newDefaultLookAndFeel;
  51781. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51782. {
  51783. Component* const c = Desktop::getInstance().getComponent (i);
  51784. if (c != 0)
  51785. c->sendLookAndFeelChange();
  51786. }
  51787. }
  51788. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51789. {
  51790. if (currentDefaultLF == defaultLF)
  51791. currentDefaultLF = 0;
  51792. deleteAndZero (defaultLF);
  51793. }
  51794. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51795. {
  51796. String faceName (font.getTypefaceName());
  51797. if (faceName == Font::getDefaultSansSerifFontName())
  51798. faceName = defaultSans;
  51799. else if (faceName == Font::getDefaultSerifFontName())
  51800. faceName = defaultSerif;
  51801. else if (faceName == Font::getDefaultMonospacedFontName())
  51802. faceName = defaultFixed;
  51803. Font f (font);
  51804. f.setTypefaceName (faceName);
  51805. return Typeface::createSystemTypefaceFor (f);
  51806. }
  51807. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51808. {
  51809. defaultSans = newName;
  51810. }
  51811. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51812. {
  51813. return component.getMouseCursor();
  51814. }
  51815. void LookAndFeel::drawButtonBackground (Graphics& g,
  51816. Button& button,
  51817. const Colour& backgroundColour,
  51818. bool isMouseOverButton,
  51819. bool isButtonDown)
  51820. {
  51821. const int width = button.getWidth();
  51822. const int height = button.getHeight();
  51823. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51824. const float halfThickness = outlineThickness * 0.5f;
  51825. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51826. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51827. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51828. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51829. const Colour baseColour (createBaseColour (backgroundColour,
  51830. button.hasKeyboardFocus (true),
  51831. isMouseOverButton, isButtonDown)
  51832. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51833. drawGlassLozenge (g,
  51834. indentL,
  51835. indentT,
  51836. width - indentL - indentR,
  51837. height - indentT - indentB,
  51838. baseColour, outlineThickness, -1.0f,
  51839. button.isConnectedOnLeft(),
  51840. button.isConnectedOnRight(),
  51841. button.isConnectedOnTop(),
  51842. button.isConnectedOnBottom());
  51843. }
  51844. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51845. {
  51846. return button.getFont();
  51847. }
  51848. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51849. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51850. {
  51851. Font font (getFontForTextButton (button));
  51852. g.setFont (font);
  51853. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51854. : TextButton::textColourOffId)
  51855. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51856. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51857. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51858. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51859. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51860. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51861. g.drawFittedText (button.getButtonText(),
  51862. leftIndent,
  51863. yIndent,
  51864. button.getWidth() - leftIndent - rightIndent,
  51865. button.getHeight() - yIndent * 2,
  51866. Justification::centred, 2);
  51867. }
  51868. void LookAndFeel::drawTickBox (Graphics& g,
  51869. Component& component,
  51870. float x, float y, float w, float h,
  51871. const bool ticked,
  51872. const bool isEnabled,
  51873. const bool isMouseOverButton,
  51874. const bool isButtonDown)
  51875. {
  51876. const float boxSize = w * 0.7f;
  51877. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51878. createBaseColour (component.findColour (TextButton::buttonColourId)
  51879. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51880. true,
  51881. isMouseOverButton,
  51882. isButtonDown),
  51883. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51884. if (ticked)
  51885. {
  51886. Path tick;
  51887. tick.startNewSubPath (1.5f, 3.0f);
  51888. tick.lineTo (3.0f, 6.0f);
  51889. tick.lineTo (6.0f, 0.0f);
  51890. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51891. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51892. .translated (x, y));
  51893. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51894. }
  51895. }
  51896. void LookAndFeel::drawToggleButton (Graphics& g,
  51897. ToggleButton& button,
  51898. bool isMouseOverButton,
  51899. bool isButtonDown)
  51900. {
  51901. if (button.hasKeyboardFocus (true))
  51902. {
  51903. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51904. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51905. }
  51906. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51907. const float tickWidth = fontSize * 1.1f;
  51908. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51909. tickWidth, tickWidth,
  51910. button.getToggleState(),
  51911. button.isEnabled(),
  51912. isMouseOverButton,
  51913. isButtonDown);
  51914. g.setColour (button.findColour (ToggleButton::textColourId));
  51915. g.setFont (fontSize);
  51916. if (! button.isEnabled())
  51917. g.setOpacity (0.5f);
  51918. const int textX = (int) tickWidth + 5;
  51919. g.drawFittedText (button.getButtonText(),
  51920. textX, 0,
  51921. button.getWidth() - textX - 2, button.getHeight(),
  51922. Justification::centredLeft, 10);
  51923. }
  51924. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51925. {
  51926. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51927. const int tickWidth = jmin (24, button.getHeight());
  51928. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51929. button.getHeight());
  51930. }
  51931. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51932. const String& message,
  51933. const String& button1,
  51934. const String& button2,
  51935. const String& button3,
  51936. AlertWindow::AlertIconType iconType,
  51937. int numButtons,
  51938. Component* associatedComponent)
  51939. {
  51940. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51941. if (numButtons == 1)
  51942. {
  51943. aw->addButton (button1, 0,
  51944. KeyPress (KeyPress::escapeKey, 0, 0),
  51945. KeyPress (KeyPress::returnKey, 0, 0));
  51946. }
  51947. else
  51948. {
  51949. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51950. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51951. if (button1ShortCut == button2ShortCut)
  51952. button2ShortCut = KeyPress();
  51953. if (numButtons == 2)
  51954. {
  51955. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51956. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51957. }
  51958. else if (numButtons == 3)
  51959. {
  51960. aw->addButton (button1, 1, button1ShortCut);
  51961. aw->addButton (button2, 2, button2ShortCut);
  51962. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51963. }
  51964. }
  51965. return aw;
  51966. }
  51967. void LookAndFeel::drawAlertBox (Graphics& g,
  51968. AlertWindow& alert,
  51969. const Rectangle<int>& textArea,
  51970. TextLayout& textLayout)
  51971. {
  51972. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51973. int iconSpaceUsed = 0;
  51974. Justification alignment (Justification::horizontallyCentred);
  51975. const int iconWidth = 80;
  51976. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51977. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51978. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51979. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51980. iconSize, iconSize);
  51981. if (alert.getAlertType() != AlertWindow::NoIcon)
  51982. {
  51983. Path icon;
  51984. uint32 colour;
  51985. char character;
  51986. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51987. {
  51988. colour = 0x55ff5555;
  51989. character = '!';
  51990. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51991. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51992. (float) iconRect.getX(), (float) iconRect.getBottom());
  51993. icon = icon.createPathWithRoundedCorners (5.0f);
  51994. }
  51995. else
  51996. {
  51997. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51998. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51999. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  52000. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  52001. }
  52002. GlyphArrangement ga;
  52003. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  52004. String::charToString (character),
  52005. (float) iconRect.getX(), (float) iconRect.getY(),
  52006. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  52007. Justification::centred, false);
  52008. ga.createPath (icon);
  52009. icon.setUsingNonZeroWinding (false);
  52010. g.setColour (Colour (colour));
  52011. g.fillPath (icon);
  52012. iconSpaceUsed = iconWidth;
  52013. alignment = Justification::left;
  52014. }
  52015. g.setColour (alert.findColour (AlertWindow::textColourId));
  52016. textLayout.drawWithin (g,
  52017. textArea.getX() + iconSpaceUsed, textArea.getY(),
  52018. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  52019. alignment.getFlags() | Justification::top);
  52020. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  52021. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  52022. }
  52023. int LookAndFeel::getAlertBoxWindowFlags()
  52024. {
  52025. return ComponentPeer::windowAppearsOnTaskbar
  52026. | ComponentPeer::windowHasDropShadow;
  52027. }
  52028. int LookAndFeel::getAlertWindowButtonHeight()
  52029. {
  52030. return 28;
  52031. }
  52032. const Font LookAndFeel::getAlertWindowFont()
  52033. {
  52034. return Font (12.0f);
  52035. }
  52036. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  52037. int width, int height,
  52038. double progress, const String& textToShow)
  52039. {
  52040. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  52041. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  52042. g.fillAll (background);
  52043. if (progress >= 0.0f && progress < 1.0f)
  52044. {
  52045. drawGlassLozenge (g, 1.0f, 1.0f,
  52046. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  52047. (float) (height - 2),
  52048. foreground,
  52049. 0.5f, 0.0f,
  52050. true, true, true, true);
  52051. }
  52052. else
  52053. {
  52054. // spinning bar..
  52055. g.setColour (foreground);
  52056. const int stripeWidth = height * 2;
  52057. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  52058. Path p;
  52059. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  52060. p.addQuadrilateral (x, 0.0f,
  52061. x + stripeWidth * 0.5f, 0.0f,
  52062. x, (float) height,
  52063. x - stripeWidth * 0.5f, (float) height);
  52064. Image im (Image::ARGB, width, height, true);
  52065. {
  52066. Graphics g2 (im);
  52067. drawGlassLozenge (g2, 1.0f, 1.0f,
  52068. (float) (width - 2),
  52069. (float) (height - 2),
  52070. foreground,
  52071. 0.5f, 0.0f,
  52072. true, true, true, true);
  52073. }
  52074. g.setTiledImageFill (im, 0, 0, 0.85f);
  52075. g.fillPath (p);
  52076. }
  52077. if (textToShow.isNotEmpty())
  52078. {
  52079. g.setColour (Colour::contrasting (background, foreground));
  52080. g.setFont (height * 0.6f);
  52081. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  52082. }
  52083. }
  52084. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  52085. {
  52086. const float radius = jmin (w, h) * 0.4f;
  52087. const float thickness = radius * 0.15f;
  52088. Path p;
  52089. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  52090. radius * 0.6f, thickness,
  52091. thickness * 0.5f);
  52092. const float cx = x + w * 0.5f;
  52093. const float cy = y + h * 0.5f;
  52094. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  52095. for (int i = 0; i < 12; ++i)
  52096. {
  52097. const int n = (i + 12 - animationIndex) % 12;
  52098. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  52099. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  52100. .translated (cx, cy));
  52101. }
  52102. }
  52103. void LookAndFeel::drawScrollbarButton (Graphics& g,
  52104. ScrollBar& scrollbar,
  52105. int width, int height,
  52106. int buttonDirection,
  52107. bool /*isScrollbarVertical*/,
  52108. bool /*isMouseOverButton*/,
  52109. bool isButtonDown)
  52110. {
  52111. Path p;
  52112. if (buttonDirection == 0)
  52113. p.addTriangle (width * 0.5f, height * 0.2f,
  52114. width * 0.1f, height * 0.7f,
  52115. width * 0.9f, height * 0.7f);
  52116. else if (buttonDirection == 1)
  52117. p.addTriangle (width * 0.8f, height * 0.5f,
  52118. width * 0.3f, height * 0.1f,
  52119. width * 0.3f, height * 0.9f);
  52120. else if (buttonDirection == 2)
  52121. p.addTriangle (width * 0.5f, height * 0.8f,
  52122. width * 0.1f, height * 0.3f,
  52123. width * 0.9f, height * 0.3f);
  52124. else if (buttonDirection == 3)
  52125. p.addTriangle (width * 0.2f, height * 0.5f,
  52126. width * 0.7f, height * 0.1f,
  52127. width * 0.7f, height * 0.9f);
  52128. if (isButtonDown)
  52129. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  52130. else
  52131. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52132. g.fillPath (p);
  52133. g.setColour (Colour (0x80000000));
  52134. g.strokePath (p, PathStrokeType (0.5f));
  52135. }
  52136. void LookAndFeel::drawScrollbar (Graphics& g,
  52137. ScrollBar& scrollbar,
  52138. int x, int y,
  52139. int width, int height,
  52140. bool isScrollbarVertical,
  52141. int thumbStartPosition,
  52142. int thumbSize,
  52143. bool /*isMouseOver*/,
  52144. bool /*isMouseDown*/)
  52145. {
  52146. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  52147. Path slotPath, thumbPath;
  52148. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  52149. const float slotIndentx2 = slotIndent * 2.0f;
  52150. const float thumbIndent = slotIndent + 1.0f;
  52151. const float thumbIndentx2 = thumbIndent * 2.0f;
  52152. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  52153. if (isScrollbarVertical)
  52154. {
  52155. slotPath.addRoundedRectangle (x + slotIndent,
  52156. y + slotIndent,
  52157. width - slotIndentx2,
  52158. height - slotIndentx2,
  52159. (width - slotIndentx2) * 0.5f);
  52160. if (thumbSize > 0)
  52161. thumbPath.addRoundedRectangle (x + thumbIndent,
  52162. thumbStartPosition + thumbIndent,
  52163. width - thumbIndentx2,
  52164. thumbSize - thumbIndentx2,
  52165. (width - thumbIndentx2) * 0.5f);
  52166. gx1 = (float) x;
  52167. gx2 = x + width * 0.7f;
  52168. }
  52169. else
  52170. {
  52171. slotPath.addRoundedRectangle (x + slotIndent,
  52172. y + slotIndent,
  52173. width - slotIndentx2,
  52174. height - slotIndentx2,
  52175. (height - slotIndentx2) * 0.5f);
  52176. if (thumbSize > 0)
  52177. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  52178. y + thumbIndent,
  52179. thumbSize - thumbIndentx2,
  52180. height - thumbIndentx2,
  52181. (height - thumbIndentx2) * 0.5f);
  52182. gy1 = (float) y;
  52183. gy2 = y + height * 0.7f;
  52184. }
  52185. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52186. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  52187. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  52188. g.fillPath (slotPath);
  52189. if (isScrollbarVertical)
  52190. {
  52191. gx1 = x + width * 0.6f;
  52192. gx2 = (float) x + width;
  52193. }
  52194. else
  52195. {
  52196. gy1 = y + height * 0.6f;
  52197. gy2 = (float) y + height;
  52198. }
  52199. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  52200. Colour (0x19000000), gx2, gy2, false));
  52201. g.fillPath (slotPath);
  52202. g.setColour (thumbColour);
  52203. g.fillPath (thumbPath);
  52204. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  52205. Colours::transparentBlack, gx2, gy2, false));
  52206. g.saveState();
  52207. if (isScrollbarVertical)
  52208. g.reduceClipRegion (x + width / 2, y, width, height);
  52209. else
  52210. g.reduceClipRegion (x, y + height / 2, width, height);
  52211. g.fillPath (thumbPath);
  52212. g.restoreState();
  52213. g.setColour (Colour (0x4c000000));
  52214. g.strokePath (thumbPath, PathStrokeType (0.4f));
  52215. }
  52216. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  52217. {
  52218. return 0;
  52219. }
  52220. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  52221. {
  52222. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  52223. }
  52224. int LookAndFeel::getDefaultScrollbarWidth()
  52225. {
  52226. return 18;
  52227. }
  52228. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  52229. {
  52230. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  52231. : scrollbar.getHeight());
  52232. }
  52233. const Path LookAndFeel::getTickShape (const float height)
  52234. {
  52235. static const unsigned char tickShapeData[] =
  52236. {
  52237. 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,
  52238. 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,
  52239. 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,
  52240. 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,
  52241. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  52242. };
  52243. Path p;
  52244. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  52245. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52246. return p;
  52247. }
  52248. const Path LookAndFeel::getCrossShape (const float height)
  52249. {
  52250. static const unsigned char crossShapeData[] =
  52251. {
  52252. 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,
  52253. 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,
  52254. 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,
  52255. 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,
  52256. 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,
  52257. 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,
  52258. 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
  52259. };
  52260. Path p;
  52261. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  52262. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52263. return p;
  52264. }
  52265. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  52266. {
  52267. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  52268. x += (w - boxSize) >> 1;
  52269. y += (h - boxSize) >> 1;
  52270. w = boxSize;
  52271. h = boxSize;
  52272. g.setColour (Colour (0xe5ffffff));
  52273. g.fillRect (x, y, w, h);
  52274. g.setColour (Colour (0x80000000));
  52275. g.drawRect (x, y, w, h);
  52276. const float size = boxSize / 2 + 1.0f;
  52277. const float centre = (float) (boxSize / 2);
  52278. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  52279. if (isPlus)
  52280. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  52281. }
  52282. void LookAndFeel::drawBubble (Graphics& g,
  52283. float tipX, float tipY,
  52284. float boxX, float boxY,
  52285. float boxW, float boxH)
  52286. {
  52287. int side = 0;
  52288. if (tipX < boxX)
  52289. side = 1;
  52290. else if (tipX > boxX + boxW)
  52291. side = 3;
  52292. else if (tipY > boxY + boxH)
  52293. side = 2;
  52294. const float indent = 2.0f;
  52295. Path p;
  52296. p.addBubble (boxX + indent,
  52297. boxY + indent,
  52298. boxW - indent * 2.0f,
  52299. boxH - indent * 2.0f,
  52300. 5.0f,
  52301. tipX, tipY,
  52302. side,
  52303. 0.5f,
  52304. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  52305. //xxx need to take comp as param for colour
  52306. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  52307. g.fillPath (p);
  52308. //xxx as above
  52309. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  52310. g.strokePath (p, PathStrokeType (1.33f));
  52311. }
  52312. const Font LookAndFeel::getPopupMenuFont()
  52313. {
  52314. return Font (17.0f);
  52315. }
  52316. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  52317. const bool isSeparator,
  52318. int standardMenuItemHeight,
  52319. int& idealWidth,
  52320. int& idealHeight)
  52321. {
  52322. if (isSeparator)
  52323. {
  52324. idealWidth = 50;
  52325. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  52326. }
  52327. else
  52328. {
  52329. Font font (getPopupMenuFont());
  52330. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  52331. font.setHeight (standardMenuItemHeight / 1.3f);
  52332. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  52333. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  52334. }
  52335. }
  52336. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  52337. {
  52338. const Colour background (findColour (PopupMenu::backgroundColourId));
  52339. g.fillAll (background);
  52340. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  52341. for (int i = 0; i < height; i += 3)
  52342. g.fillRect (0, i, width, 1);
  52343. #if ! JUCE_MAC
  52344. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  52345. g.drawRect (0, 0, width, height);
  52346. #endif
  52347. }
  52348. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  52349. int width, int height,
  52350. bool isScrollUpArrow)
  52351. {
  52352. const Colour background (findColour (PopupMenu::backgroundColourId));
  52353. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  52354. background.withAlpha (0.0f),
  52355. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  52356. false));
  52357. g.fillRect (1, 1, width - 2, height - 2);
  52358. const float hw = width * 0.5f;
  52359. const float arrowW = height * 0.3f;
  52360. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  52361. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  52362. Path p;
  52363. p.addTriangle (hw - arrowW, y1,
  52364. hw + arrowW, y1,
  52365. hw, y2);
  52366. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  52367. g.fillPath (p);
  52368. }
  52369. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  52370. int width, int height,
  52371. const bool isSeparator,
  52372. const bool isActive,
  52373. const bool isHighlighted,
  52374. const bool isTicked,
  52375. const bool hasSubMenu,
  52376. const String& text,
  52377. const String& shortcutKeyText,
  52378. Image* image,
  52379. const Colour* const textColourToUse)
  52380. {
  52381. const float halfH = height * 0.5f;
  52382. if (isSeparator)
  52383. {
  52384. const float separatorIndent = 5.5f;
  52385. g.setColour (Colour (0x33000000));
  52386. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  52387. g.setColour (Colour (0x66ffffff));
  52388. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  52389. }
  52390. else
  52391. {
  52392. Colour textColour (findColour (PopupMenu::textColourId));
  52393. if (textColourToUse != 0)
  52394. textColour = *textColourToUse;
  52395. if (isHighlighted)
  52396. {
  52397. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  52398. g.fillRect (1, 1, width - 2, height - 2);
  52399. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  52400. }
  52401. else
  52402. {
  52403. g.setColour (textColour);
  52404. }
  52405. if (! isActive)
  52406. g.setOpacity (0.3f);
  52407. Font font (getPopupMenuFont());
  52408. if (font.getHeight() > height / 1.3f)
  52409. font.setHeight (height / 1.3f);
  52410. g.setFont (font);
  52411. const int leftBorder = (height * 5) / 4;
  52412. const int rightBorder = 4;
  52413. if (image != 0)
  52414. {
  52415. g.drawImageWithin (image,
  52416. 2, 1, leftBorder - 4, height - 2,
  52417. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  52418. }
  52419. else if (isTicked)
  52420. {
  52421. const Path tick (getTickShape (1.0f));
  52422. const float th = font.getAscent();
  52423. const float ty = halfH - th * 0.5f;
  52424. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  52425. th, true));
  52426. }
  52427. g.drawFittedText (text,
  52428. leftBorder, 0,
  52429. width - (leftBorder + rightBorder), height,
  52430. Justification::centredLeft, 1);
  52431. if (shortcutKeyText.isNotEmpty())
  52432. {
  52433. Font f2 (font);
  52434. f2.setHeight (f2.getHeight() * 0.75f);
  52435. f2.setHorizontalScale (0.95f);
  52436. g.setFont (f2);
  52437. g.drawText (shortcutKeyText,
  52438. leftBorder,
  52439. 0,
  52440. width - (leftBorder + rightBorder + 4),
  52441. height,
  52442. Justification::centredRight,
  52443. true);
  52444. }
  52445. if (hasSubMenu)
  52446. {
  52447. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  52448. const float x = width - height * 0.6f;
  52449. Path p;
  52450. p.addTriangle (x, halfH - arrowH * 0.5f,
  52451. x, halfH + arrowH * 0.5f,
  52452. x + arrowH * 0.6f, halfH);
  52453. g.fillPath (p);
  52454. }
  52455. }
  52456. }
  52457. int LookAndFeel::getMenuWindowFlags()
  52458. {
  52459. return ComponentPeer::windowHasDropShadow;
  52460. }
  52461. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  52462. bool, MenuBarComponent& menuBar)
  52463. {
  52464. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  52465. if (menuBar.isEnabled())
  52466. {
  52467. drawShinyButtonShape (g,
  52468. -4.0f, 0.0f,
  52469. width + 8.0f, (float) height,
  52470. 0.0f,
  52471. baseColour,
  52472. 0.4f,
  52473. true, true, true, true);
  52474. }
  52475. else
  52476. {
  52477. g.fillAll (baseColour);
  52478. }
  52479. }
  52480. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  52481. {
  52482. return Font (menuBar.getHeight() * 0.7f);
  52483. }
  52484. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  52485. {
  52486. return getMenuBarFont (menuBar, itemIndex, itemText)
  52487. .getStringWidth (itemText) + menuBar.getHeight();
  52488. }
  52489. void LookAndFeel::drawMenuBarItem (Graphics& g,
  52490. int width, int height,
  52491. int itemIndex,
  52492. const String& itemText,
  52493. bool isMouseOverItem,
  52494. bool isMenuOpen,
  52495. bool /*isMouseOverBar*/,
  52496. MenuBarComponent& menuBar)
  52497. {
  52498. if (! menuBar.isEnabled())
  52499. {
  52500. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  52501. .withMultipliedAlpha (0.5f));
  52502. }
  52503. else if (isMenuOpen || isMouseOverItem)
  52504. {
  52505. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  52506. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  52507. }
  52508. else
  52509. {
  52510. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  52511. }
  52512. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52513. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52514. }
  52515. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52516. TextEditor& textEditor)
  52517. {
  52518. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52519. }
  52520. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52521. {
  52522. if (textEditor.isEnabled())
  52523. {
  52524. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52525. {
  52526. const int border = 2;
  52527. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52528. g.drawRect (0, 0, width, height, border);
  52529. g.setOpacity (1.0f);
  52530. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52531. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52532. }
  52533. else
  52534. {
  52535. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52536. g.drawRect (0, 0, width, height);
  52537. g.setOpacity (1.0f);
  52538. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52539. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52540. }
  52541. }
  52542. }
  52543. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52544. const bool isButtonDown,
  52545. int buttonX, int buttonY,
  52546. int buttonW, int buttonH,
  52547. ComboBox& box)
  52548. {
  52549. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52550. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52551. {
  52552. g.setColour (box.findColour (TextButton::buttonColourId));
  52553. g.drawRect (0, 0, width, height, 2);
  52554. }
  52555. else
  52556. {
  52557. g.setColour (box.findColour (ComboBox::outlineColourId));
  52558. g.drawRect (0, 0, width, height);
  52559. }
  52560. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52561. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52562. box.hasKeyboardFocus (true),
  52563. false, isButtonDown)
  52564. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52565. drawGlassLozenge (g,
  52566. buttonX + outlineThickness, buttonY + outlineThickness,
  52567. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52568. baseColour, outlineThickness, -1.0f,
  52569. true, true, true, true);
  52570. if (box.isEnabled())
  52571. {
  52572. const float arrowX = 0.3f;
  52573. const float arrowH = 0.2f;
  52574. Path p;
  52575. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52576. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52577. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52578. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52579. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52580. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52581. g.setColour (box.findColour (ComboBox::arrowColourId));
  52582. g.fillPath (p);
  52583. }
  52584. }
  52585. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52586. {
  52587. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52588. }
  52589. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52590. {
  52591. return new Label (String::empty, String::empty);
  52592. }
  52593. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52594. {
  52595. label.setBounds (1, 1,
  52596. box.getWidth() + 3 - box.getHeight(),
  52597. box.getHeight() - 2);
  52598. label.setFont (getComboBoxFont (box));
  52599. }
  52600. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52601. {
  52602. g.fillAll (label.findColour (Label::backgroundColourId));
  52603. if (! label.isBeingEdited())
  52604. {
  52605. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52606. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52607. g.setFont (label.getFont());
  52608. g.drawFittedText (label.getText(),
  52609. label.getHorizontalBorderSize(),
  52610. label.getVerticalBorderSize(),
  52611. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52612. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52613. label.getJustificationType(),
  52614. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52615. label.getMinimumHorizontalScale());
  52616. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52617. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52618. }
  52619. else if (label.isEnabled())
  52620. {
  52621. g.setColour (label.findColour (Label::outlineColourId));
  52622. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52623. }
  52624. }
  52625. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52626. int x, int y,
  52627. int width, int height,
  52628. float /*sliderPos*/,
  52629. float /*minSliderPos*/,
  52630. float /*maxSliderPos*/,
  52631. const Slider::SliderStyle /*style*/,
  52632. Slider& slider)
  52633. {
  52634. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52635. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52636. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52637. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52638. Path indent;
  52639. if (slider.isHorizontal())
  52640. {
  52641. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52642. const float ih = sliderRadius;
  52643. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52644. gradCol2, 0.0f, iy + ih, false));
  52645. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52646. width + sliderRadius, ih,
  52647. 5.0f);
  52648. g.fillPath (indent);
  52649. }
  52650. else
  52651. {
  52652. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52653. const float iw = sliderRadius;
  52654. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52655. gradCol2, ix + iw, 0.0f, false));
  52656. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52657. iw, height + sliderRadius,
  52658. 5.0f);
  52659. g.fillPath (indent);
  52660. }
  52661. g.setColour (Colour (0x4c000000));
  52662. g.strokePath (indent, PathStrokeType (0.5f));
  52663. }
  52664. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52665. int x, int y,
  52666. int width, int height,
  52667. float sliderPos,
  52668. float minSliderPos,
  52669. float maxSliderPos,
  52670. const Slider::SliderStyle style,
  52671. Slider& slider)
  52672. {
  52673. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52674. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52675. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52676. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52677. slider.isMouseButtonDown() && slider.isEnabled()));
  52678. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52679. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52680. {
  52681. float kx, ky;
  52682. if (style == Slider::LinearVertical)
  52683. {
  52684. kx = x + width * 0.5f;
  52685. ky = sliderPos;
  52686. }
  52687. else
  52688. {
  52689. kx = sliderPos;
  52690. ky = y + height * 0.5f;
  52691. }
  52692. drawGlassSphere (g,
  52693. kx - sliderRadius,
  52694. ky - sliderRadius,
  52695. sliderRadius * 2.0f,
  52696. knobColour, outlineThickness);
  52697. }
  52698. else
  52699. {
  52700. if (style == Slider::ThreeValueVertical)
  52701. {
  52702. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52703. sliderPos - sliderRadius,
  52704. sliderRadius * 2.0f,
  52705. knobColour, outlineThickness);
  52706. }
  52707. else if (style == Slider::ThreeValueHorizontal)
  52708. {
  52709. drawGlassSphere (g,sliderPos - sliderRadius,
  52710. y + height * 0.5f - sliderRadius,
  52711. sliderRadius * 2.0f,
  52712. knobColour, outlineThickness);
  52713. }
  52714. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52715. {
  52716. const float sr = jmin (sliderRadius, width * 0.4f);
  52717. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52718. minSliderPos - sliderRadius,
  52719. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52720. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52721. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52722. }
  52723. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52724. {
  52725. const float sr = jmin (sliderRadius, height * 0.4f);
  52726. drawGlassPointer (g, minSliderPos - sr,
  52727. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52728. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52729. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52730. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52731. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52732. }
  52733. }
  52734. }
  52735. void LookAndFeel::drawLinearSlider (Graphics& g,
  52736. int x, int y,
  52737. int width, int height,
  52738. float sliderPos,
  52739. float minSliderPos,
  52740. float maxSliderPos,
  52741. const Slider::SliderStyle style,
  52742. Slider& slider)
  52743. {
  52744. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52745. if (style == Slider::LinearBar)
  52746. {
  52747. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52748. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52749. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52750. false,
  52751. isMouseOver,
  52752. isMouseOver || slider.isMouseButtonDown()));
  52753. drawShinyButtonShape (g,
  52754. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52755. baseColour,
  52756. slider.isEnabled() ? 0.9f : 0.3f,
  52757. true, true, true, true);
  52758. }
  52759. else
  52760. {
  52761. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52762. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52763. }
  52764. }
  52765. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52766. {
  52767. return jmin (7,
  52768. slider.getHeight() / 2,
  52769. slider.getWidth() / 2) + 2;
  52770. }
  52771. void LookAndFeel::drawRotarySlider (Graphics& g,
  52772. int x, int y,
  52773. int width, int height,
  52774. float sliderPos,
  52775. const float rotaryStartAngle,
  52776. const float rotaryEndAngle,
  52777. Slider& slider)
  52778. {
  52779. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52780. const float centreX = x + width * 0.5f;
  52781. const float centreY = y + height * 0.5f;
  52782. const float rx = centreX - radius;
  52783. const float ry = centreY - radius;
  52784. const float rw = radius * 2.0f;
  52785. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52786. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52787. if (radius > 12.0f)
  52788. {
  52789. if (slider.isEnabled())
  52790. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52791. else
  52792. g.setColour (Colour (0x80808080));
  52793. const float thickness = 0.7f;
  52794. {
  52795. Path filledArc;
  52796. filledArc.addPieSegment (rx, ry, rw, rw,
  52797. rotaryStartAngle,
  52798. angle,
  52799. thickness);
  52800. g.fillPath (filledArc);
  52801. }
  52802. if (thickness > 0)
  52803. {
  52804. const float innerRadius = radius * 0.2f;
  52805. Path p;
  52806. p.addTriangle (-innerRadius, 0.0f,
  52807. 0.0f, -radius * thickness * 1.1f,
  52808. innerRadius, 0.0f);
  52809. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52810. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52811. }
  52812. if (slider.isEnabled())
  52813. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52814. else
  52815. g.setColour (Colour (0x80808080));
  52816. Path outlineArc;
  52817. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52818. outlineArc.closeSubPath();
  52819. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52820. }
  52821. else
  52822. {
  52823. if (slider.isEnabled())
  52824. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52825. else
  52826. g.setColour (Colour (0x80808080));
  52827. Path p;
  52828. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52829. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52830. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52831. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52832. }
  52833. }
  52834. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52835. {
  52836. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52837. }
  52838. class SliderLabelComp : public Label
  52839. {
  52840. public:
  52841. SliderLabelComp() : Label (String::empty, String::empty) {}
  52842. ~SliderLabelComp() {}
  52843. void mouseWheelMove (const MouseEvent&, float, float) {}
  52844. };
  52845. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52846. {
  52847. Label* const l = new SliderLabelComp();
  52848. l->setJustificationType (Justification::centred);
  52849. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52850. l->setColour (Label::backgroundColourId,
  52851. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52852. : slider.findColour (Slider::textBoxBackgroundColourId));
  52853. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52854. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52855. l->setColour (TextEditor::backgroundColourId,
  52856. slider.findColour (Slider::textBoxBackgroundColourId)
  52857. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52858. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52859. return l;
  52860. }
  52861. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52862. {
  52863. return 0;
  52864. }
  52865. static const TextLayout layoutTooltipText (const String& text) throw()
  52866. {
  52867. const float tooltipFontSize = 12.0f;
  52868. const int maxToolTipWidth = 400;
  52869. const Font f (tooltipFontSize, Font::bold);
  52870. TextLayout tl (text, f);
  52871. tl.layout (maxToolTipWidth, Justification::left, true);
  52872. return tl;
  52873. }
  52874. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52875. {
  52876. const TextLayout tl (layoutTooltipText (tipText));
  52877. width = tl.getWidth() + 14;
  52878. height = tl.getHeight() + 6;
  52879. }
  52880. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52881. {
  52882. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52883. const Colour textCol (findColour (TooltipWindow::textColourId));
  52884. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52885. g.setColour (findColour (TooltipWindow::outlineColourId));
  52886. g.drawRect (0, 0, width, height, 1);
  52887. #endif
  52888. const TextLayout tl (layoutTooltipText (text));
  52889. g.setColour (findColour (TooltipWindow::textColourId));
  52890. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52891. }
  52892. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52893. {
  52894. return new TextButton (text, TRANS("click to browse for a different file"));
  52895. }
  52896. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52897. ComboBox* filenameBox,
  52898. Button* browseButton)
  52899. {
  52900. browseButton->setSize (80, filenameComp.getHeight());
  52901. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52902. if (tb != 0)
  52903. tb->changeWidthToFitText();
  52904. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52905. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52906. }
  52907. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52908. int imageX, int imageY, int imageW, int imageH,
  52909. const Colour& overlayColour,
  52910. float imageOpacity,
  52911. ImageButton& button)
  52912. {
  52913. if (! button.isEnabled())
  52914. imageOpacity *= 0.3f;
  52915. if (! overlayColour.isOpaque())
  52916. {
  52917. g.setOpacity (imageOpacity);
  52918. g.drawImage (image, imageX, imageY, imageW, imageH,
  52919. 0, 0, image->getWidth(), image->getHeight(), false);
  52920. }
  52921. if (! overlayColour.isTransparent())
  52922. {
  52923. g.setColour (overlayColour);
  52924. g.drawImage (image, imageX, imageY, imageW, imageH,
  52925. 0, 0, image->getWidth(), image->getHeight(), true);
  52926. }
  52927. }
  52928. void LookAndFeel::drawCornerResizer (Graphics& g,
  52929. int w, int h,
  52930. bool /*isMouseOver*/,
  52931. bool /*isMouseDragging*/)
  52932. {
  52933. const float lineThickness = jmin (w, h) * 0.075f;
  52934. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52935. {
  52936. g.setColour (Colours::lightgrey);
  52937. g.drawLine (w * i,
  52938. h + 1.0f,
  52939. w + 1.0f,
  52940. h * i,
  52941. lineThickness);
  52942. g.setColour (Colours::darkgrey);
  52943. g.drawLine (w * i + lineThickness,
  52944. h + 1.0f,
  52945. w + 1.0f,
  52946. h * i + lineThickness,
  52947. lineThickness);
  52948. }
  52949. }
  52950. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52951. const BorderSize& /*borders*/)
  52952. {
  52953. }
  52954. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52955. const BorderSize& /*border*/, ResizableWindow& window)
  52956. {
  52957. g.fillAll (window.getBackgroundColour());
  52958. }
  52959. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52960. const BorderSize& border, ResizableWindow&)
  52961. {
  52962. g.setColour (Colour (0x80000000));
  52963. g.drawRect (0, 0, w, h);
  52964. g.setColour (Colour (0x19000000));
  52965. g.drawRect (border.getLeft() - 1,
  52966. border.getTop() - 1,
  52967. w + 2 - border.getLeftAndRight(),
  52968. h + 2 - border.getTopAndBottom());
  52969. }
  52970. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52971. Graphics& g, int w, int h,
  52972. int titleSpaceX, int titleSpaceW,
  52973. const Image* icon,
  52974. bool drawTitleTextOnLeft)
  52975. {
  52976. const bool isActive = window.isActiveWindow();
  52977. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52978. 0.0f, 0.0f,
  52979. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52980. 0.0f, (float) h, false));
  52981. g.fillAll();
  52982. Font font (h * 0.65f, Font::bold);
  52983. g.setFont (font);
  52984. int textW = font.getStringWidth (window.getName());
  52985. int iconW = 0;
  52986. int iconH = 0;
  52987. if (icon != 0)
  52988. {
  52989. iconH = (int) font.getHeight();
  52990. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52991. }
  52992. textW = jmin (titleSpaceW, textW + iconW);
  52993. int textX = drawTitleTextOnLeft ? titleSpaceX
  52994. : jmax (titleSpaceX, (w - textW) / 2);
  52995. if (textX + textW > titleSpaceX + titleSpaceW)
  52996. textX = titleSpaceX + titleSpaceW - textW;
  52997. if (icon != 0)
  52998. {
  52999. g.setOpacity (isActive ? 1.0f : 0.6f);
  53000. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  53001. RectanglePlacement::centred, false);
  53002. textX += iconW;
  53003. textW -= iconW;
  53004. }
  53005. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  53006. g.setColour (findColour (DocumentWindow::textColourId));
  53007. else
  53008. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  53009. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  53010. }
  53011. class GlassWindowButton : public Button
  53012. {
  53013. public:
  53014. GlassWindowButton (const String& name, const Colour& col,
  53015. const Path& normalShape_,
  53016. const Path& toggledShape_) throw()
  53017. : Button (name),
  53018. colour (col),
  53019. normalShape (normalShape_),
  53020. toggledShape (toggledShape_)
  53021. {
  53022. }
  53023. ~GlassWindowButton()
  53024. {
  53025. }
  53026. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  53027. {
  53028. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  53029. if (! isEnabled())
  53030. alpha *= 0.5f;
  53031. float x = 0, y = 0, diam;
  53032. if (getWidth() < getHeight())
  53033. {
  53034. diam = (float) getWidth();
  53035. y = (getHeight() - getWidth()) * 0.5f;
  53036. }
  53037. else
  53038. {
  53039. diam = (float) getHeight();
  53040. y = (getWidth() - getHeight()) * 0.5f;
  53041. }
  53042. x += diam * 0.05f;
  53043. y += diam * 0.05f;
  53044. diam *= 0.9f;
  53045. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  53046. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  53047. g.fillEllipse (x, y, diam, diam);
  53048. x += 2.0f;
  53049. y += 2.0f;
  53050. diam -= 4.0f;
  53051. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  53052. Path& p = getToggleState() ? toggledShape : normalShape;
  53053. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  53054. diam * 0.4f, diam * 0.4f, true));
  53055. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  53056. g.fillPath (p, t);
  53057. }
  53058. juce_UseDebuggingNewOperator
  53059. private:
  53060. Colour colour;
  53061. Path normalShape, toggledShape;
  53062. GlassWindowButton (const GlassWindowButton&);
  53063. const GlassWindowButton& operator= (const GlassWindowButton&);
  53064. };
  53065. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  53066. {
  53067. Path shape;
  53068. const float crossThickness = 0.25f;
  53069. if (buttonType == DocumentWindow::closeButton)
  53070. {
  53071. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  53072. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  53073. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  53074. }
  53075. else if (buttonType == DocumentWindow::minimiseButton)
  53076. {
  53077. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53078. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  53079. }
  53080. else if (buttonType == DocumentWindow::maximiseButton)
  53081. {
  53082. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  53083. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53084. Path fullscreenShape;
  53085. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  53086. fullscreenShape.lineTo (0.0f, 100.0f);
  53087. fullscreenShape.lineTo (0.0f, 0.0f);
  53088. fullscreenShape.lineTo (100.0f, 0.0f);
  53089. fullscreenShape.lineTo (100.0f, 45.0f);
  53090. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  53091. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  53092. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  53093. }
  53094. jassertfalse
  53095. return 0;
  53096. }
  53097. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53098. int titleBarX,
  53099. int titleBarY,
  53100. int titleBarW,
  53101. int titleBarH,
  53102. Button* minimiseButton,
  53103. Button* maximiseButton,
  53104. Button* closeButton,
  53105. bool positionTitleBarButtonsOnLeft)
  53106. {
  53107. const int buttonW = titleBarH - titleBarH / 8;
  53108. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53109. : titleBarX + titleBarW - buttonW - buttonW / 4;
  53110. if (closeButton != 0)
  53111. {
  53112. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53113. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  53114. }
  53115. if (positionTitleBarButtonsOnLeft)
  53116. swapVariables (minimiseButton, maximiseButton);
  53117. if (maximiseButton != 0)
  53118. {
  53119. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53120. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53121. }
  53122. if (minimiseButton != 0)
  53123. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53124. }
  53125. int LookAndFeel::getDefaultMenuBarHeight()
  53126. {
  53127. return 24;
  53128. }
  53129. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  53130. {
  53131. return new DropShadower (0.4f, 1, 5, 10);
  53132. }
  53133. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  53134. int w, int h,
  53135. bool /*isVerticalBar*/,
  53136. bool isMouseOver,
  53137. bool isMouseDragging)
  53138. {
  53139. float alpha = 0.5f;
  53140. if (isMouseOver || isMouseDragging)
  53141. {
  53142. g.fillAll (Colour (0x190000ff));
  53143. alpha = 1.0f;
  53144. }
  53145. const float cx = w * 0.5f;
  53146. const float cy = h * 0.5f;
  53147. const float cr = jmin (w, h) * 0.4f;
  53148. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  53149. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  53150. true));
  53151. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  53152. }
  53153. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  53154. const String& text,
  53155. const Justification& position,
  53156. GroupComponent& group)
  53157. {
  53158. const float textH = 15.0f;
  53159. const float indent = 3.0f;
  53160. const float textEdgeGap = 4.0f;
  53161. float cs = 5.0f;
  53162. Font f (textH);
  53163. Path p;
  53164. float x = indent;
  53165. float y = f.getAscent() - 3.0f;
  53166. float w = jmax (0.0f, width - x * 2.0f);
  53167. float h = jmax (0.0f, height - y - indent);
  53168. cs = jmin (cs, w * 0.5f, h * 0.5f);
  53169. const float cs2 = 2.0f * cs;
  53170. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  53171. float textX = cs + textEdgeGap;
  53172. if (position.testFlags (Justification::horizontallyCentred))
  53173. textX = cs + (w - cs2 - textW) * 0.5f;
  53174. else if (position.testFlags (Justification::right))
  53175. textX = w - cs - textW - textEdgeGap;
  53176. p.startNewSubPath (x + textX + textW, y);
  53177. p.lineTo (x + w - cs, y);
  53178. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  53179. p.lineTo (x + w, y + h - cs);
  53180. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53181. p.lineTo (x + cs, y + h);
  53182. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53183. p.lineTo (x, y + cs);
  53184. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53185. p.lineTo (x + textX, y);
  53186. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  53187. g.setColour (group.findColour (GroupComponent::outlineColourId)
  53188. .withMultipliedAlpha (alpha));
  53189. g.strokePath (p, PathStrokeType (2.0f));
  53190. g.setColour (group.findColour (GroupComponent::textColourId)
  53191. .withMultipliedAlpha (alpha));
  53192. g.setFont (f);
  53193. g.drawText (text,
  53194. roundToInt (x + textX), 0,
  53195. roundToInt (textW),
  53196. roundToInt (textH),
  53197. Justification::centred, true);
  53198. }
  53199. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  53200. {
  53201. return 1 + tabDepth / 3;
  53202. }
  53203. int LookAndFeel::getTabButtonSpaceAroundImage()
  53204. {
  53205. return 4;
  53206. }
  53207. void LookAndFeel::createTabButtonShape (Path& p,
  53208. int width, int height,
  53209. int /*tabIndex*/,
  53210. const String& /*text*/,
  53211. Button& /*button*/,
  53212. TabbedButtonBar::Orientation orientation,
  53213. const bool /*isMouseOver*/,
  53214. const bool /*isMouseDown*/,
  53215. const bool /*isFrontTab*/)
  53216. {
  53217. const float w = (float) width;
  53218. const float h = (float) height;
  53219. float length = w;
  53220. float depth = h;
  53221. if (orientation == TabbedButtonBar::TabsAtLeft
  53222. || orientation == TabbedButtonBar::TabsAtRight)
  53223. {
  53224. swapVariables (length, depth);
  53225. }
  53226. const float indent = (float) getTabButtonOverlap ((int) depth);
  53227. const float overhang = 4.0f;
  53228. if (orientation == TabbedButtonBar::TabsAtLeft)
  53229. {
  53230. p.startNewSubPath (w, 0.0f);
  53231. p.lineTo (0.0f, indent);
  53232. p.lineTo (0.0f, h - indent);
  53233. p.lineTo (w, h);
  53234. p.lineTo (w + overhang, h + overhang);
  53235. p.lineTo (w + overhang, -overhang);
  53236. }
  53237. else if (orientation == TabbedButtonBar::TabsAtRight)
  53238. {
  53239. p.startNewSubPath (0.0f, 0.0f);
  53240. p.lineTo (w, indent);
  53241. p.lineTo (w, h - indent);
  53242. p.lineTo (0.0f, h);
  53243. p.lineTo (-overhang, h + overhang);
  53244. p.lineTo (-overhang, -overhang);
  53245. }
  53246. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53247. {
  53248. p.startNewSubPath (0.0f, 0.0f);
  53249. p.lineTo (indent, h);
  53250. p.lineTo (w - indent, h);
  53251. p.lineTo (w, 0.0f);
  53252. p.lineTo (w + overhang, -overhang);
  53253. p.lineTo (-overhang, -overhang);
  53254. }
  53255. else
  53256. {
  53257. p.startNewSubPath (0.0f, h);
  53258. p.lineTo (indent, 0.0f);
  53259. p.lineTo (w - indent, 0.0f);
  53260. p.lineTo (w, h);
  53261. p.lineTo (w + overhang, h + overhang);
  53262. p.lineTo (-overhang, h + overhang);
  53263. }
  53264. p.closeSubPath();
  53265. p = p.createPathWithRoundedCorners (3.0f);
  53266. }
  53267. void LookAndFeel::fillTabButtonShape (Graphics& g,
  53268. const Path& path,
  53269. const Colour& preferredColour,
  53270. int /*tabIndex*/,
  53271. const String& /*text*/,
  53272. Button& button,
  53273. TabbedButtonBar::Orientation /*orientation*/,
  53274. const bool /*isMouseOver*/,
  53275. const bool /*isMouseDown*/,
  53276. const bool isFrontTab)
  53277. {
  53278. g.setColour (isFrontTab ? preferredColour
  53279. : preferredColour.withMultipliedAlpha (0.9f));
  53280. g.fillPath (path);
  53281. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  53282. : TabbedButtonBar::tabOutlineColourId, false)
  53283. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  53284. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  53285. }
  53286. void LookAndFeel::drawTabButtonText (Graphics& g,
  53287. int x, int y, int w, int h,
  53288. const Colour& preferredBackgroundColour,
  53289. int /*tabIndex*/,
  53290. const String& text,
  53291. Button& button,
  53292. TabbedButtonBar::Orientation orientation,
  53293. const bool isMouseOver,
  53294. const bool isMouseDown,
  53295. const bool isFrontTab)
  53296. {
  53297. int length = w;
  53298. int depth = h;
  53299. if (orientation == TabbedButtonBar::TabsAtLeft
  53300. || orientation == TabbedButtonBar::TabsAtRight)
  53301. {
  53302. swapVariables (length, depth);
  53303. }
  53304. Font font (depth * 0.6f);
  53305. font.setUnderline (button.hasKeyboardFocus (false));
  53306. GlyphArrangement textLayout;
  53307. textLayout.addFittedText (font, text.trim(),
  53308. 0.0f, 0.0f, (float) length, (float) depth,
  53309. Justification::centred,
  53310. jmax (1, depth / 12));
  53311. AffineTransform transform;
  53312. if (orientation == TabbedButtonBar::TabsAtLeft)
  53313. {
  53314. transform = transform.rotated (float_Pi * -0.5f)
  53315. .translated ((float) x, (float) (y + h));
  53316. }
  53317. else if (orientation == TabbedButtonBar::TabsAtRight)
  53318. {
  53319. transform = transform.rotated (float_Pi * 0.5f)
  53320. .translated ((float) (x + w), (float) y);
  53321. }
  53322. else
  53323. {
  53324. transform = transform.translated ((float) x, (float) y);
  53325. }
  53326. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  53327. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  53328. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  53329. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  53330. else
  53331. g.setColour (preferredBackgroundColour.contrasting());
  53332. if (! (isMouseOver || isMouseDown))
  53333. g.setOpacity (0.8f);
  53334. if (! button.isEnabled())
  53335. g.setOpacity (0.3f);
  53336. textLayout.draw (g, transform);
  53337. }
  53338. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  53339. const String& text,
  53340. int tabDepth,
  53341. Button&)
  53342. {
  53343. Font f (tabDepth * 0.6f);
  53344. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  53345. }
  53346. void LookAndFeel::drawTabButton (Graphics& g,
  53347. int w, int h,
  53348. const Colour& preferredColour,
  53349. int tabIndex,
  53350. const String& text,
  53351. Button& button,
  53352. TabbedButtonBar::Orientation orientation,
  53353. const bool isMouseOver,
  53354. const bool isMouseDown,
  53355. const bool isFrontTab)
  53356. {
  53357. int length = w;
  53358. int depth = h;
  53359. if (orientation == TabbedButtonBar::TabsAtLeft
  53360. || orientation == TabbedButtonBar::TabsAtRight)
  53361. {
  53362. swapVariables (length, depth);
  53363. }
  53364. Path tabShape;
  53365. createTabButtonShape (tabShape, w, h,
  53366. tabIndex, text, button, orientation,
  53367. isMouseOver, isMouseDown, isFrontTab);
  53368. fillTabButtonShape (g, tabShape, preferredColour,
  53369. tabIndex, text, button, orientation,
  53370. isMouseOver, isMouseDown, isFrontTab);
  53371. const int indent = getTabButtonOverlap (depth);
  53372. int x = 0, y = 0;
  53373. if (orientation == TabbedButtonBar::TabsAtLeft
  53374. || orientation == TabbedButtonBar::TabsAtRight)
  53375. {
  53376. y += indent;
  53377. h -= indent * 2;
  53378. }
  53379. else
  53380. {
  53381. x += indent;
  53382. w -= indent * 2;
  53383. }
  53384. drawTabButtonText (g, x, y, w, h, preferredColour,
  53385. tabIndex, text, button, orientation,
  53386. isMouseOver, isMouseDown, isFrontTab);
  53387. }
  53388. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  53389. int w, int h,
  53390. TabbedButtonBar& tabBar,
  53391. TabbedButtonBar::Orientation orientation)
  53392. {
  53393. const float shadowSize = 0.2f;
  53394. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  53395. Rectangle<int> shadowRect;
  53396. if (orientation == TabbedButtonBar::TabsAtLeft)
  53397. {
  53398. x1 = (float) w;
  53399. x2 = w * (1.0f - shadowSize);
  53400. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  53401. }
  53402. else if (orientation == TabbedButtonBar::TabsAtRight)
  53403. {
  53404. x2 = w * shadowSize;
  53405. shadowRect.setBounds (0, 0, (int) x2, h);
  53406. }
  53407. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53408. {
  53409. y2 = h * shadowSize;
  53410. shadowRect.setBounds (0, 0, w, (int) y2);
  53411. }
  53412. else
  53413. {
  53414. y1 = (float) h;
  53415. y2 = h * (1.0f - shadowSize);
  53416. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  53417. }
  53418. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  53419. Colours::transparentBlack, x2, y2, false));
  53420. shadowRect.expand (2, 2);
  53421. g.fillRect (shadowRect);
  53422. g.setColour (Colour (0x80000000));
  53423. if (orientation == TabbedButtonBar::TabsAtLeft)
  53424. {
  53425. g.fillRect (w - 1, 0, 1, h);
  53426. }
  53427. else if (orientation == TabbedButtonBar::TabsAtRight)
  53428. {
  53429. g.fillRect (0, 0, 1, h);
  53430. }
  53431. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53432. {
  53433. g.fillRect (0, 0, w, 1);
  53434. }
  53435. else
  53436. {
  53437. g.fillRect (0, h - 1, w, 1);
  53438. }
  53439. }
  53440. Button* LookAndFeel::createTabBarExtrasButton()
  53441. {
  53442. const float thickness = 7.0f;
  53443. const float indent = 22.0f;
  53444. Path p;
  53445. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  53446. DrawablePath ellipse;
  53447. ellipse.setPath (p);
  53448. ellipse.setFill (Colour (0x99ffffff));
  53449. p.clear();
  53450. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53451. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53452. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53453. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53454. p.setUsingNonZeroWinding (false);
  53455. DrawablePath dp;
  53456. dp.setPath (p);
  53457. dp.setFill (Colour (0x59000000));
  53458. DrawableComposite normalImage;
  53459. normalImage.insertDrawable (ellipse);
  53460. normalImage.insertDrawable (dp);
  53461. dp.setFill (Colour (0xcc000000));
  53462. DrawableComposite overImage;
  53463. overImage.insertDrawable (ellipse);
  53464. overImage.insertDrawable (dp);
  53465. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  53466. db->setImages (&normalImage, &overImage, 0);
  53467. return db;
  53468. }
  53469. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  53470. {
  53471. g.fillAll (Colours::white);
  53472. const int w = header.getWidth();
  53473. const int h = header.getHeight();
  53474. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  53475. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  53476. false));
  53477. g.fillRect (0, h / 2, w, h);
  53478. g.setColour (Colour (0x33000000));
  53479. g.fillRect (0, h - 1, w, 1);
  53480. for (int i = header.getNumColumns (true); --i >= 0;)
  53481. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  53482. }
  53483. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  53484. int width, int height,
  53485. bool isMouseOver, bool isMouseDown,
  53486. int columnFlags)
  53487. {
  53488. if (isMouseDown)
  53489. g.fillAll (Colour (0x8899aadd));
  53490. else if (isMouseOver)
  53491. g.fillAll (Colour (0x5599aadd));
  53492. int rightOfText = width - 4;
  53493. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  53494. {
  53495. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  53496. const float bottom = height - top;
  53497. const float w = height * 0.5f;
  53498. const float x = rightOfText - (w * 1.25f);
  53499. rightOfText = (int) x;
  53500. Path sortArrow;
  53501. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  53502. g.setColour (Colour (0x99000000));
  53503. g.fillPath (sortArrow);
  53504. }
  53505. g.setColour (Colours::black);
  53506. g.setFont (height * 0.5f, Font::bold);
  53507. const int textX = 4;
  53508. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  53509. }
  53510. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  53511. {
  53512. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53513. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53514. background.darker (0.1f),
  53515. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53516. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53517. false));
  53518. g.fillAll();
  53519. }
  53520. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53521. {
  53522. return createTabBarExtrasButton();
  53523. }
  53524. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53525. bool isMouseOver, bool isMouseDown,
  53526. ToolbarItemComponent& component)
  53527. {
  53528. if (isMouseDown)
  53529. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53530. else if (isMouseOver)
  53531. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53532. }
  53533. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53534. const String& text, ToolbarItemComponent& component)
  53535. {
  53536. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53537. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53538. const float fontHeight = jmin (14.0f, height * 0.85f);
  53539. g.setFont (fontHeight);
  53540. g.drawFittedText (text,
  53541. x, y, width, height,
  53542. Justification::centred,
  53543. jmax (1, height / (int) fontHeight));
  53544. }
  53545. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53546. bool isOpen, int width, int height)
  53547. {
  53548. const int buttonSize = (height * 3) / 4;
  53549. const int buttonIndent = (height - buttonSize) / 2;
  53550. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53551. const int textX = buttonIndent * 2 + buttonSize + 2;
  53552. g.setColour (Colours::black);
  53553. g.setFont (height * 0.7f, Font::bold);
  53554. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53555. }
  53556. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53557. PropertyComponent&)
  53558. {
  53559. g.setColour (Colour (0x66ffffff));
  53560. g.fillRect (0, 0, width, height - 1);
  53561. }
  53562. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53563. PropertyComponent& component)
  53564. {
  53565. g.setColour (Colours::black);
  53566. if (! component.isEnabled())
  53567. g.setOpacity (0.6f);
  53568. g.setFont (jmin (height, 24) * 0.65f);
  53569. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  53570. g.drawFittedText (component.getName(),
  53571. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53572. Justification::centredLeft, 2);
  53573. }
  53574. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53575. {
  53576. return Rectangle<int> (component.getWidth() / 3, 1,
  53577. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53578. }
  53579. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53580. const String& instructions,
  53581. GlyphArrangement& text,
  53582. int width)
  53583. {
  53584. text.clear();
  53585. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53586. 8.0f, 22.0f, width - 16.0f,
  53587. Justification::centred);
  53588. text.addJustifiedText (Font (14.0f), instructions,
  53589. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53590. Justification::centred);
  53591. }
  53592. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53593. const String& filename, Image* icon,
  53594. const String& fileSizeDescription,
  53595. const String& fileTimeDescription,
  53596. const bool isDirectory,
  53597. const bool isItemSelected,
  53598. const int /*itemIndex*/)
  53599. {
  53600. if (isItemSelected)
  53601. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53602. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53603. g.setFont (height * 0.7f);
  53604. Image* im = icon;
  53605. Image* toRelease = 0;
  53606. if (im == 0)
  53607. {
  53608. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53609. : getDefaultDocumentFileImage());
  53610. }
  53611. const int x = 32;
  53612. if (im != 0)
  53613. {
  53614. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53615. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53616. false);
  53617. ImageCache::release (toRelease);
  53618. }
  53619. if (width > 450 && ! isDirectory)
  53620. {
  53621. const int sizeX = roundToInt (width * 0.7f);
  53622. const int dateX = roundToInt (width * 0.8f);
  53623. g.drawFittedText (filename,
  53624. x, 0, sizeX - x, height,
  53625. Justification::centredLeft, 1);
  53626. g.setFont (height * 0.5f);
  53627. g.setColour (Colours::darkgrey);
  53628. if (! isDirectory)
  53629. {
  53630. g.drawFittedText (fileSizeDescription,
  53631. sizeX, 0, dateX - sizeX - 8, height,
  53632. Justification::centredRight, 1);
  53633. g.drawFittedText (fileTimeDescription,
  53634. dateX, 0, width - 8 - dateX, height,
  53635. Justification::centredRight, 1);
  53636. }
  53637. }
  53638. else
  53639. {
  53640. g.drawFittedText (filename,
  53641. x, 0, width - x, height,
  53642. Justification::centredLeft, 1);
  53643. }
  53644. }
  53645. Button* LookAndFeel::createFileBrowserGoUpButton()
  53646. {
  53647. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53648. Path arrowPath;
  53649. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53650. DrawablePath arrowImage;
  53651. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53652. arrowImage.setPath (arrowPath);
  53653. goUpButton->setImages (&arrowImage);
  53654. return goUpButton;
  53655. }
  53656. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53657. DirectoryContentsDisplayComponent* fileListComponent,
  53658. FilePreviewComponent* previewComp,
  53659. ComboBox* currentPathBox,
  53660. TextEditor* filenameBox,
  53661. Button* goUpButton)
  53662. {
  53663. const int x = 8;
  53664. int w = browserComp.getWidth() - x - x;
  53665. if (previewComp != 0)
  53666. {
  53667. const int previewWidth = w / 3;
  53668. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53669. w -= previewWidth + 4;
  53670. }
  53671. int y = 4;
  53672. const int controlsHeight = 22;
  53673. const int bottomSectionHeight = controlsHeight + 8;
  53674. const int upButtonWidth = 50;
  53675. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53676. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53677. y += controlsHeight + 4;
  53678. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53679. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53680. y = listAsComp->getBottom() + 4;
  53681. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53682. }
  53683. Image* LookAndFeel::getDefaultFolderImage()
  53684. {
  53685. 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,
  53686. 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,
  53687. 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,
  53688. 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,
  53689. 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,
  53690. 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,
  53691. 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,
  53692. 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,
  53693. 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,
  53694. 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,
  53695. 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,
  53696. 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,
  53697. 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,
  53698. 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,
  53699. 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,
  53700. 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,
  53701. 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,
  53702. 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,
  53703. 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,
  53704. 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,
  53705. 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,
  53706. 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,
  53707. 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,
  53708. 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,
  53709. 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,
  53710. 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,
  53711. 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,
  53712. 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,
  53713. 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,
  53714. 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,
  53715. 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,
  53716. 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,
  53717. 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,
  53718. 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,
  53719. 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,
  53720. 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,
  53721. 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,
  53722. 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,
  53723. 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,
  53724. 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,
  53725. 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,
  53726. 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,
  53727. 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,
  53728. 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};
  53729. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53730. }
  53731. Image* LookAndFeel::getDefaultDocumentFileImage()
  53732. {
  53733. 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,
  53734. 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,
  53735. 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,
  53736. 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,
  53737. 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,
  53738. 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,
  53739. 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,
  53740. 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,
  53741. 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,
  53742. 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,
  53743. 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,
  53744. 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,
  53745. 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,
  53746. 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,
  53747. 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,
  53748. 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,
  53749. 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,
  53750. 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,
  53751. 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,
  53752. 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,
  53753. 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,
  53754. 174,66,96,130,0,0};
  53755. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53756. }
  53757. void LookAndFeel::playAlertSound()
  53758. {
  53759. PlatformUtilities::beep();
  53760. }
  53761. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53762. {
  53763. g.setColour (Colours::white.withAlpha (0.7f));
  53764. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53765. g.setColour (Colours::black.withAlpha (0.2f));
  53766. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53767. const int totalBlocks = 7;
  53768. const int numBlocks = roundToInt (totalBlocks * level);
  53769. const float w = (width - 6.0f) / (float) totalBlocks;
  53770. for (int i = 0; i < totalBlocks; ++i)
  53771. {
  53772. if (i >= numBlocks)
  53773. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53774. else
  53775. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53776. : Colours::red);
  53777. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53778. }
  53779. }
  53780. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53781. {
  53782. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53783. if (keyDescription.isNotEmpty())
  53784. {
  53785. if (button.isEnabled())
  53786. {
  53787. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53788. g.fillAll (textColour.withAlpha (alpha));
  53789. g.setOpacity (0.3f);
  53790. g.drawBevel (0, 0, width, height, 2);
  53791. }
  53792. g.setColour (textColour);
  53793. g.setFont (height * 0.6f);
  53794. g.drawFittedText (keyDescription,
  53795. 3, 0, width - 6, height,
  53796. Justification::centred, 1);
  53797. }
  53798. else
  53799. {
  53800. const float thickness = 7.0f;
  53801. const float indent = 22.0f;
  53802. Path p;
  53803. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53804. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53805. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53806. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53807. p.setUsingNonZeroWinding (false);
  53808. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53809. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53810. }
  53811. if (button.hasKeyboardFocus (false))
  53812. {
  53813. g.setColour (textColour.withAlpha (0.4f));
  53814. g.drawRect (0, 0, width, height);
  53815. }
  53816. }
  53817. static void createRoundedPath (Path& p,
  53818. const float x, const float y,
  53819. const float w, const float h,
  53820. const float cs,
  53821. const bool curveTopLeft, const bool curveTopRight,
  53822. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53823. {
  53824. const float cs2 = 2.0f * cs;
  53825. if (curveTopLeft)
  53826. {
  53827. p.startNewSubPath (x, y + cs);
  53828. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53829. }
  53830. else
  53831. {
  53832. p.startNewSubPath (x, y);
  53833. }
  53834. if (curveTopRight)
  53835. {
  53836. p.lineTo (x + w - cs, y);
  53837. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53838. }
  53839. else
  53840. {
  53841. p.lineTo (x + w, y);
  53842. }
  53843. if (curveBottomRight)
  53844. {
  53845. p.lineTo (x + w, y + h - cs);
  53846. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53847. }
  53848. else
  53849. {
  53850. p.lineTo (x + w, y + h);
  53851. }
  53852. if (curveBottomLeft)
  53853. {
  53854. p.lineTo (x + cs, y + h);
  53855. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53856. }
  53857. else
  53858. {
  53859. p.lineTo (x, y + h);
  53860. }
  53861. p.closeSubPath();
  53862. }
  53863. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53864. float x, float y, float w, float h,
  53865. float maxCornerSize,
  53866. const Colour& baseColour,
  53867. const float strokeWidth,
  53868. const bool flatOnLeft,
  53869. const bool flatOnRight,
  53870. const bool flatOnTop,
  53871. const bool flatOnBottom) throw()
  53872. {
  53873. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53874. return;
  53875. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53876. Path outline;
  53877. createRoundedPath (outline, x, y, w, h, cs,
  53878. ! (flatOnLeft || flatOnTop),
  53879. ! (flatOnRight || flatOnTop),
  53880. ! (flatOnLeft || flatOnBottom),
  53881. ! (flatOnRight || flatOnBottom));
  53882. ColourGradient cg (baseColour, 0.0f, y,
  53883. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53884. false);
  53885. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53886. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53887. g.setGradientFill (cg);
  53888. g.fillPath (outline);
  53889. g.setColour (Colour (0x80000000));
  53890. g.strokePath (outline, PathStrokeType (strokeWidth));
  53891. }
  53892. void LookAndFeel::drawGlassSphere (Graphics& g,
  53893. const float x, const float y,
  53894. const float diameter,
  53895. const Colour& colour,
  53896. const float outlineThickness) throw()
  53897. {
  53898. if (diameter <= outlineThickness)
  53899. return;
  53900. Path p;
  53901. p.addEllipse (x, y, diameter, diameter);
  53902. {
  53903. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53904. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53905. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53906. g.setGradientFill (cg);
  53907. g.fillPath (p);
  53908. }
  53909. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53910. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53911. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53912. ColourGradient cg (Colours::transparentBlack,
  53913. x + diameter * 0.5f, y + diameter * 0.5f,
  53914. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53915. x, y + diameter * 0.5f, true);
  53916. cg.addColour (0.7, Colours::transparentBlack);
  53917. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53918. g.setGradientFill (cg);
  53919. g.fillPath (p);
  53920. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53921. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53922. }
  53923. void LookAndFeel::drawGlassPointer (Graphics& g,
  53924. const float x, const float y,
  53925. const float diameter,
  53926. const Colour& colour, const float outlineThickness,
  53927. const int direction) throw()
  53928. {
  53929. if (diameter <= outlineThickness)
  53930. return;
  53931. Path p;
  53932. p.startNewSubPath (x + diameter * 0.5f, y);
  53933. p.lineTo (x + diameter, y + diameter * 0.6f);
  53934. p.lineTo (x + diameter, y + diameter);
  53935. p.lineTo (x, y + diameter);
  53936. p.lineTo (x, y + diameter * 0.6f);
  53937. p.closeSubPath();
  53938. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53939. {
  53940. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53941. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53942. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53943. g.setGradientFill (cg);
  53944. g.fillPath (p);
  53945. }
  53946. ColourGradient cg (Colours::transparentBlack,
  53947. x + diameter * 0.5f, y + diameter * 0.5f,
  53948. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53949. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53950. cg.addColour (0.5, Colours::transparentBlack);
  53951. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53952. g.setGradientFill (cg);
  53953. g.fillPath (p);
  53954. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53955. g.strokePath (p, PathStrokeType (outlineThickness));
  53956. }
  53957. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53958. const float x, const float y,
  53959. const float width, const float height,
  53960. const Colour& colour,
  53961. const float outlineThickness,
  53962. const float cornerSize,
  53963. const bool flatOnLeft,
  53964. const bool flatOnRight,
  53965. const bool flatOnTop,
  53966. const bool flatOnBottom) throw()
  53967. {
  53968. if (width <= outlineThickness || height <= outlineThickness)
  53969. return;
  53970. const int intX = (int) x;
  53971. const int intY = (int) y;
  53972. const int intW = (int) width;
  53973. const int intH = (int) height;
  53974. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53975. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53976. const int intEdge = (int) edgeBlurRadius;
  53977. Path outline;
  53978. createRoundedPath (outline, x, y, width, height, cs,
  53979. ! (flatOnLeft || flatOnTop),
  53980. ! (flatOnRight || flatOnTop),
  53981. ! (flatOnLeft || flatOnBottom),
  53982. ! (flatOnRight || flatOnBottom));
  53983. {
  53984. ColourGradient cg (colour.darker (0.2f), 0, y,
  53985. colour.darker (0.2f), 0, y + height, false);
  53986. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53987. cg.addColour (0.4, colour);
  53988. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53989. g.setGradientFill (cg);
  53990. g.fillPath (outline);
  53991. }
  53992. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53993. colour.darker (0.2f), x, y + height * 0.5f, true);
  53994. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53995. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53996. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53997. {
  53998. g.saveState();
  53999. g.setGradientFill (cg);
  54000. g.reduceClipRegion (intX, intY, intEdge, intH);
  54001. g.fillPath (outline);
  54002. g.restoreState();
  54003. }
  54004. if (! (flatOnRight || flatOnTop || flatOnBottom))
  54005. {
  54006. cg.x1 = x + width - edgeBlurRadius;
  54007. cg.x2 = x + width;
  54008. g.saveState();
  54009. g.setGradientFill (cg);
  54010. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  54011. g.fillPath (outline);
  54012. g.restoreState();
  54013. }
  54014. {
  54015. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  54016. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  54017. Path highlight;
  54018. createRoundedPath (highlight,
  54019. x + leftIndent,
  54020. y + cs * 0.1f,
  54021. width - (leftIndent + rightIndent),
  54022. height * 0.4f, cs * 0.4f,
  54023. ! (flatOnLeft || flatOnTop),
  54024. ! (flatOnRight || flatOnTop),
  54025. ! (flatOnLeft || flatOnBottom),
  54026. ! (flatOnRight || flatOnBottom));
  54027. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  54028. Colours::transparentWhite, 0, y + height * 0.4f, false));
  54029. g.fillPath (highlight);
  54030. }
  54031. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  54032. g.strokePath (outline, PathStrokeType (outlineThickness));
  54033. }
  54034. END_JUCE_NAMESPACE
  54035. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  54036. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54037. BEGIN_JUCE_NAMESPACE
  54038. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  54039. {
  54040. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  54041. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  54042. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  54043. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  54044. setColour (Slider::thumbColourId, Colours::white);
  54045. setColour (Slider::trackColourId, Colour (0x7f000000));
  54046. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  54047. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  54048. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  54049. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  54050. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  54051. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  54052. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  54053. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  54054. }
  54055. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  54056. {
  54057. }
  54058. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  54059. Button& button,
  54060. const Colour& backgroundColour,
  54061. bool isMouseOverButton,
  54062. bool isButtonDown)
  54063. {
  54064. const int width = button.getWidth();
  54065. const int height = button.getHeight();
  54066. const float indent = 2.0f;
  54067. const int cornerSize = jmin (roundToInt (width * 0.4f),
  54068. roundToInt (height * 0.4f));
  54069. Path p;
  54070. p.addRoundedRectangle (indent, indent,
  54071. width - indent * 2.0f,
  54072. height - indent * 2.0f,
  54073. (float) cornerSize);
  54074. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  54075. if (isMouseOverButton)
  54076. {
  54077. if (isButtonDown)
  54078. bc = bc.brighter();
  54079. else if (bc.getBrightness() > 0.5f)
  54080. bc = bc.darker (0.1f);
  54081. else
  54082. bc = bc.brighter (0.1f);
  54083. }
  54084. g.setColour (bc);
  54085. g.fillPath (p);
  54086. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  54087. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  54088. }
  54089. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  54090. Component& /*component*/,
  54091. float x, float y, float w, float h,
  54092. const bool ticked,
  54093. const bool isEnabled,
  54094. const bool /*isMouseOverButton*/,
  54095. const bool isButtonDown)
  54096. {
  54097. Path box;
  54098. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  54099. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  54100. : Colours::lightgrey.withAlpha (0.1f));
  54101. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  54102. g.fillPath (box, trans);
  54103. g.setColour (Colours::black.withAlpha (0.6f));
  54104. g.strokePath (box, PathStrokeType (0.9f), trans);
  54105. if (ticked)
  54106. {
  54107. Path tick;
  54108. tick.startNewSubPath (1.5f, 3.0f);
  54109. tick.lineTo (3.0f, 6.0f);
  54110. tick.lineTo (6.0f, 0.0f);
  54111. g.setColour (isEnabled ? Colours::black : Colours::grey);
  54112. g.strokePath (tick, PathStrokeType (2.5f), trans);
  54113. }
  54114. }
  54115. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  54116. ToggleButton& button,
  54117. bool isMouseOverButton,
  54118. bool isButtonDown)
  54119. {
  54120. if (button.hasKeyboardFocus (true))
  54121. {
  54122. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  54123. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  54124. }
  54125. const int tickWidth = jmin (20, button.getHeight() - 4);
  54126. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  54127. (float) tickWidth, (float) tickWidth,
  54128. button.getToggleState(),
  54129. button.isEnabled(),
  54130. isMouseOverButton,
  54131. isButtonDown);
  54132. g.setColour (button.findColour (ToggleButton::textColourId));
  54133. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  54134. if (! button.isEnabled())
  54135. g.setOpacity (0.5f);
  54136. const int textX = tickWidth + 5;
  54137. g.drawFittedText (button.getButtonText(),
  54138. textX, 4,
  54139. button.getWidth() - textX - 2, button.getHeight() - 8,
  54140. Justification::centredLeft, 10);
  54141. }
  54142. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  54143. int width, int height,
  54144. double progress, const String& textToShow)
  54145. {
  54146. if (progress < 0 || progress >= 1.0)
  54147. {
  54148. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  54149. }
  54150. else
  54151. {
  54152. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  54153. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  54154. g.fillAll (background);
  54155. g.setColour (foreground);
  54156. g.fillRect (1, 1,
  54157. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  54158. height - 2);
  54159. if (textToShow.isNotEmpty())
  54160. {
  54161. g.setColour (Colour::contrasting (background, foreground));
  54162. g.setFont (height * 0.6f);
  54163. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  54164. }
  54165. }
  54166. }
  54167. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  54168. ScrollBar& bar,
  54169. int width, int height,
  54170. int buttonDirection,
  54171. bool isScrollbarVertical,
  54172. bool isMouseOverButton,
  54173. bool isButtonDown)
  54174. {
  54175. if (isScrollbarVertical)
  54176. width -= 2;
  54177. else
  54178. height -= 2;
  54179. Path p;
  54180. if (buttonDirection == 0)
  54181. p.addTriangle (width * 0.5f, height * 0.2f,
  54182. width * 0.1f, height * 0.7f,
  54183. width * 0.9f, height * 0.7f);
  54184. else if (buttonDirection == 1)
  54185. p.addTriangle (width * 0.8f, height * 0.5f,
  54186. width * 0.3f, height * 0.1f,
  54187. width * 0.3f, height * 0.9f);
  54188. else if (buttonDirection == 2)
  54189. p.addTriangle (width * 0.5f, height * 0.8f,
  54190. width * 0.1f, height * 0.3f,
  54191. width * 0.9f, height * 0.3f);
  54192. else if (buttonDirection == 3)
  54193. p.addTriangle (width * 0.2f, height * 0.5f,
  54194. width * 0.7f, height * 0.1f,
  54195. width * 0.7f, height * 0.9f);
  54196. if (isButtonDown)
  54197. g.setColour (Colours::white);
  54198. else if (isMouseOverButton)
  54199. g.setColour (Colours::white.withAlpha (0.7f));
  54200. else
  54201. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  54202. g.fillPath (p);
  54203. g.setColour (Colours::black.withAlpha (0.5f));
  54204. g.strokePath (p, PathStrokeType (0.5f));
  54205. }
  54206. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  54207. ScrollBar& bar,
  54208. int x, int y,
  54209. int width, int height,
  54210. bool isScrollbarVertical,
  54211. int thumbStartPosition,
  54212. int thumbSize,
  54213. bool isMouseOver,
  54214. bool isMouseDown)
  54215. {
  54216. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  54217. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54218. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  54219. if (thumbSize > 0.0f)
  54220. {
  54221. Rectangle<int> thumb;
  54222. if (isScrollbarVertical)
  54223. {
  54224. width -= 2;
  54225. g.fillRect (x + roundToInt (width * 0.35f), y,
  54226. roundToInt (width * 0.3f), height);
  54227. thumb.setBounds (x + 1, thumbStartPosition,
  54228. width - 2, thumbSize);
  54229. }
  54230. else
  54231. {
  54232. height -= 2;
  54233. g.fillRect (x, y + roundToInt (height * 0.35f),
  54234. width, roundToInt (height * 0.3f));
  54235. thumb.setBounds (thumbStartPosition, y + 1,
  54236. thumbSize, height - 2);
  54237. }
  54238. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54239. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  54240. g.fillRect (thumb);
  54241. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  54242. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  54243. if (thumbSize > 16)
  54244. {
  54245. for (int i = 3; --i >= 0;)
  54246. {
  54247. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  54248. g.setColour (Colours::black.withAlpha (0.15f));
  54249. if (isScrollbarVertical)
  54250. {
  54251. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  54252. g.setColour (Colours::white.withAlpha (0.15f));
  54253. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  54254. }
  54255. else
  54256. {
  54257. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  54258. g.setColour (Colours::white.withAlpha (0.15f));
  54259. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  54260. }
  54261. }
  54262. }
  54263. }
  54264. }
  54265. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  54266. {
  54267. return &scrollbarShadow;
  54268. }
  54269. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  54270. {
  54271. g.fillAll (findColour (PopupMenu::backgroundColourId));
  54272. g.setColour (Colours::black.withAlpha (0.6f));
  54273. g.drawRect (0, 0, width, height);
  54274. }
  54275. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  54276. bool, MenuBarComponent& menuBar)
  54277. {
  54278. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  54279. }
  54280. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  54281. {
  54282. if (textEditor.isEnabled())
  54283. {
  54284. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  54285. g.drawRect (0, 0, width, height);
  54286. }
  54287. }
  54288. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  54289. const bool isButtonDown,
  54290. int buttonX, int buttonY,
  54291. int buttonW, int buttonH,
  54292. ComboBox& box)
  54293. {
  54294. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  54295. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  54296. : ComboBox::backgroundColourId));
  54297. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  54298. g.setColour (box.findColour (ComboBox::outlineColourId));
  54299. g.drawRect (0, 0, width, height);
  54300. const float arrowX = 0.2f;
  54301. const float arrowH = 0.3f;
  54302. if (box.isEnabled())
  54303. {
  54304. Path p;
  54305. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  54306. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  54307. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  54308. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  54309. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  54310. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  54311. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  54312. : ComboBox::buttonColourId));
  54313. g.fillPath (p);
  54314. }
  54315. }
  54316. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  54317. {
  54318. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  54319. f.setHorizontalScale (0.9f);
  54320. return f;
  54321. }
  54322. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  54323. {
  54324. Path p;
  54325. p.addTriangle (x1, y1, x2, y2, x3, y3);
  54326. g.setColour (fill);
  54327. g.fillPath (p);
  54328. g.setColour (outline);
  54329. g.strokePath (p, PathStrokeType (0.3f));
  54330. }
  54331. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  54332. int x, int y,
  54333. int w, int h,
  54334. float sliderPos,
  54335. float minSliderPos,
  54336. float maxSliderPos,
  54337. const Slider::SliderStyle style,
  54338. Slider& slider)
  54339. {
  54340. g.fillAll (slider.findColour (Slider::backgroundColourId));
  54341. if (style == Slider::LinearBar)
  54342. {
  54343. g.setColour (slider.findColour (Slider::thumbColourId));
  54344. g.fillRect (x, y, (int) sliderPos - x, h);
  54345. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  54346. g.drawRect (x, y, (int) sliderPos - x, h);
  54347. }
  54348. else
  54349. {
  54350. g.setColour (slider.findColour (Slider::trackColourId)
  54351. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  54352. if (slider.isHorizontal())
  54353. {
  54354. g.fillRect (x, y + roundToInt (h * 0.6f),
  54355. w, roundToInt (h * 0.2f));
  54356. }
  54357. else
  54358. {
  54359. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  54360. jmin (4, roundToInt (w * 0.2f)), h);
  54361. }
  54362. float alpha = 0.35f;
  54363. if (slider.isEnabled())
  54364. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  54365. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  54366. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  54367. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  54368. {
  54369. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  54370. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  54371. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  54372. fill, outline);
  54373. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  54374. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  54375. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  54376. fill, outline);
  54377. }
  54378. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  54379. {
  54380. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54381. minSliderPos - 7.0f, y + h * 0.9f ,
  54382. minSliderPos, y + h * 0.9f,
  54383. fill, outline);
  54384. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54385. maxSliderPos, y + h * 0.9f,
  54386. maxSliderPos + 7.0f, y + h * 0.9f,
  54387. fill, outline);
  54388. }
  54389. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  54390. {
  54391. drawTriangle (g, sliderPos, y + h * 0.9f,
  54392. sliderPos - 7.0f, y + h * 0.2f,
  54393. sliderPos + 7.0f, y + h * 0.2f,
  54394. fill, outline);
  54395. }
  54396. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  54397. {
  54398. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  54399. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  54400. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  54401. fill, outline);
  54402. }
  54403. }
  54404. }
  54405. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  54406. {
  54407. if (isIncrement)
  54408. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  54409. else
  54410. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  54411. }
  54412. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  54413. {
  54414. return &scrollbarShadow;
  54415. }
  54416. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  54417. {
  54418. return 8;
  54419. }
  54420. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  54421. int w, int h,
  54422. bool isMouseOver,
  54423. bool isMouseDragging)
  54424. {
  54425. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  54426. : Colours::darkgrey);
  54427. const float lineThickness = jmin (w, h) * 0.1f;
  54428. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  54429. {
  54430. g.drawLine (w * i,
  54431. h + 1.0f,
  54432. w + 1.0f,
  54433. h * i,
  54434. lineThickness);
  54435. }
  54436. }
  54437. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  54438. {
  54439. Path shape;
  54440. if (buttonType == DocumentWindow::closeButton)
  54441. {
  54442. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  54443. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  54444. ShapeButton* const b = new ShapeButton ("close",
  54445. Colour (0x7fff3333),
  54446. Colour (0xd7ff3333),
  54447. Colour (0xf7ff3333));
  54448. b->setShape (shape, true, true, true);
  54449. return b;
  54450. }
  54451. else if (buttonType == DocumentWindow::minimiseButton)
  54452. {
  54453. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54454. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  54455. DrawablePath dp;
  54456. dp.setPath (shape);
  54457. dp.setFill (Colours::black.withAlpha (0.3f));
  54458. b->setImages (&dp);
  54459. return b;
  54460. }
  54461. else if (buttonType == DocumentWindow::maximiseButton)
  54462. {
  54463. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  54464. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54465. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  54466. DrawablePath dp;
  54467. dp.setPath (shape);
  54468. dp.setFill (Colours::black.withAlpha (0.3f));
  54469. b->setImages (&dp);
  54470. return b;
  54471. }
  54472. jassertfalse
  54473. return 0;
  54474. }
  54475. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  54476. int titleBarX,
  54477. int titleBarY,
  54478. int titleBarW,
  54479. int titleBarH,
  54480. Button* minimiseButton,
  54481. Button* maximiseButton,
  54482. Button* closeButton,
  54483. bool positionTitleBarButtonsOnLeft)
  54484. {
  54485. titleBarY += titleBarH / 8;
  54486. titleBarH -= titleBarH / 4;
  54487. const int buttonW = titleBarH;
  54488. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  54489. : titleBarX + titleBarW - buttonW - 4;
  54490. if (closeButton != 0)
  54491. {
  54492. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  54493. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  54494. : -(buttonW + buttonW / 5);
  54495. }
  54496. if (positionTitleBarButtonsOnLeft)
  54497. swapVariables (minimiseButton, maximiseButton);
  54498. if (maximiseButton != 0)
  54499. {
  54500. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54501. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  54502. }
  54503. if (minimiseButton != 0)
  54504. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54505. }
  54506. END_JUCE_NAMESPACE
  54507. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54508. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  54509. BEGIN_JUCE_NAMESPACE
  54510. class DummyMenuComponent : public Component
  54511. {
  54512. DummyMenuComponent (const DummyMenuComponent&);
  54513. const DummyMenuComponent& operator= (const DummyMenuComponent&);
  54514. public:
  54515. DummyMenuComponent() {}
  54516. ~DummyMenuComponent() {}
  54517. void inputAttemptWhenModal()
  54518. {
  54519. exitModalState (0);
  54520. }
  54521. };
  54522. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54523. : model (0),
  54524. itemUnderMouse (-1),
  54525. currentPopupIndex (-1),
  54526. indexToShowAgain (-1),
  54527. lastMouseX (0),
  54528. lastMouseY (0),
  54529. inModalState (false)
  54530. {
  54531. setRepaintsOnMouseActivity (true);
  54532. setWantsKeyboardFocus (false);
  54533. setMouseClickGrabsKeyboardFocus (false);
  54534. setModel (model_);
  54535. }
  54536. MenuBarComponent::~MenuBarComponent()
  54537. {
  54538. setModel (0);
  54539. Desktop::getInstance().removeGlobalMouseListener (this);
  54540. currentPopup = 0;
  54541. }
  54542. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54543. {
  54544. if (model != newModel)
  54545. {
  54546. if (model != 0)
  54547. model->removeListener (this);
  54548. model = newModel;
  54549. if (model != 0)
  54550. model->addListener (this);
  54551. repaint();
  54552. menuBarItemsChanged (0);
  54553. }
  54554. }
  54555. void MenuBarComponent::paint (Graphics& g)
  54556. {
  54557. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54558. getLookAndFeel().drawMenuBarBackground (g,
  54559. getWidth(),
  54560. getHeight(),
  54561. isMouseOverBar,
  54562. *this);
  54563. if (model != 0)
  54564. {
  54565. for (int i = 0; i < menuNames.size(); ++i)
  54566. {
  54567. g.saveState();
  54568. g.setOrigin (xPositions [i], 0);
  54569. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54570. getLookAndFeel().drawMenuBarItem (g,
  54571. xPositions[i + 1] - xPositions[i],
  54572. getHeight(),
  54573. i,
  54574. menuNames[i],
  54575. i == itemUnderMouse,
  54576. i == currentPopupIndex,
  54577. isMouseOverBar,
  54578. *this);
  54579. g.restoreState();
  54580. }
  54581. }
  54582. }
  54583. void MenuBarComponent::resized()
  54584. {
  54585. xPositions.clear();
  54586. int x = 2;
  54587. xPositions.add (x);
  54588. for (int i = 0; i < menuNames.size(); ++i)
  54589. {
  54590. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54591. xPositions.add (x);
  54592. }
  54593. }
  54594. int MenuBarComponent::getItemAt (const int x, const int y)
  54595. {
  54596. for (int i = 0; i < xPositions.size(); ++i)
  54597. if (x >= xPositions[i] && x < xPositions[i + 1])
  54598. return reallyContains (x, y, true) ? i : -1;
  54599. return -1;
  54600. }
  54601. void MenuBarComponent::repaintMenuItem (int index)
  54602. {
  54603. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54604. {
  54605. const int x1 = xPositions [index];
  54606. const int x2 = xPositions [index + 1];
  54607. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54608. }
  54609. }
  54610. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54611. {
  54612. const int newItem = getItemAt (x, y);
  54613. if (itemUnderMouse != newItem)
  54614. {
  54615. repaintMenuItem (itemUnderMouse);
  54616. itemUnderMouse = newItem;
  54617. repaintMenuItem (itemUnderMouse);
  54618. }
  54619. }
  54620. void MenuBarComponent::hideCurrentMenu()
  54621. {
  54622. currentPopup = 0;
  54623. repaint();
  54624. }
  54625. void MenuBarComponent::showMenu (int index)
  54626. {
  54627. if (index != currentPopupIndex)
  54628. {
  54629. if (inModalState)
  54630. {
  54631. hideCurrentMenu();
  54632. indexToShowAgain = index;
  54633. return;
  54634. }
  54635. indexToShowAgain = -1;
  54636. currentPopupIndex = -1;
  54637. itemUnderMouse = index;
  54638. currentPopup = 0;
  54639. menuBarItemsChanged (0);
  54640. Component* const prevFocused = getCurrentlyFocusedComponent();
  54641. ScopedPointer <ComponentDeletionWatcher> prevCompDeletionChecker;
  54642. if (prevFocused != 0)
  54643. prevCompDeletionChecker = new ComponentDeletionWatcher (prevFocused);
  54644. ComponentDeletionWatcher deletionChecker (this);
  54645. enterModalState (false);
  54646. inModalState = true;
  54647. int result = 0;
  54648. ApplicationCommandManager* managerOfChosenCommand = 0;
  54649. Desktop::getInstance().addGlobalMouseListener (this);
  54650. for (;;)
  54651. {
  54652. const int x = getScreenX() + xPositions [itemUnderMouse];
  54653. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54654. currentPopupIndex = itemUnderMouse;
  54655. indexToShowAgain = -1;
  54656. repaint();
  54657. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54658. {
  54659. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54660. menuNames [itemUnderMouse]));
  54661. if (m.lookAndFeel == 0)
  54662. m.setLookAndFeel (&getLookAndFeel());
  54663. currentPopup = m.createMenuComponent (x, getScreenY(),
  54664. w, getHeight(),
  54665. 0, w, 0, 0,
  54666. true, this,
  54667. &managerOfChosenCommand,
  54668. this);
  54669. }
  54670. if (currentPopup == 0)
  54671. {
  54672. currentPopup = new DummyMenuComponent();
  54673. addAndMakeVisible (currentPopup);
  54674. }
  54675. currentPopup->enterModalState (false);
  54676. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54677. // be stuck behind other comps that are already modal..
  54678. result = currentPopup->runModalLoop();
  54679. if (deletionChecker.hasBeenDeleted())
  54680. return;
  54681. const int lastPopupIndex = currentPopupIndex;
  54682. currentPopup = 0;
  54683. currentPopupIndex = -1;
  54684. if (result != 0)
  54685. {
  54686. topLevelIndexClicked = lastPopupIndex;
  54687. break;
  54688. }
  54689. else if (indexToShowAgain >= 0)
  54690. {
  54691. menuBarItemsChanged (0);
  54692. repaint();
  54693. itemUnderMouse = indexToShowAgain;
  54694. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54695. break;
  54696. }
  54697. else
  54698. {
  54699. break;
  54700. }
  54701. }
  54702. Desktop::getInstance().removeGlobalMouseListener (this);
  54703. inModalState = false;
  54704. exitModalState (0);
  54705. if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted())
  54706. prevFocused->grabKeyboardFocus();
  54707. const Point<int> mousePos (getMouseXYRelative());
  54708. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54709. repaint();
  54710. if (result != 0)
  54711. {
  54712. if (managerOfChosenCommand != 0)
  54713. {
  54714. ApplicationCommandTarget::InvocationInfo info (result);
  54715. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54716. managerOfChosenCommand->invoke (info, true);
  54717. }
  54718. postCommandMessage (result);
  54719. }
  54720. }
  54721. }
  54722. void MenuBarComponent::handleCommandMessage (int commandId)
  54723. {
  54724. if (model != 0)
  54725. model->menuItemSelected (commandId, topLevelIndexClicked);
  54726. }
  54727. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54728. {
  54729. if (e.eventComponent == this)
  54730. updateItemUnderMouse (e.x, e.y);
  54731. }
  54732. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54733. {
  54734. if (e.eventComponent == this)
  54735. updateItemUnderMouse (e.x, e.y);
  54736. }
  54737. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54738. {
  54739. if (currentPopupIndex < 0)
  54740. {
  54741. const MouseEvent e2 (e.getEventRelativeTo (this));
  54742. updateItemUnderMouse (e2.x, e2.y);
  54743. currentPopupIndex = -2;
  54744. showMenu (itemUnderMouse);
  54745. }
  54746. }
  54747. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54748. {
  54749. const MouseEvent e2 (e.getEventRelativeTo (this));
  54750. const int item = getItemAt (e2.x, e2.y);
  54751. if (item >= 0)
  54752. showMenu (item);
  54753. }
  54754. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54755. {
  54756. const MouseEvent e2 (e.getEventRelativeTo (this));
  54757. updateItemUnderMouse (e2.x, e2.y);
  54758. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54759. hideCurrentMenu();
  54760. }
  54761. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54762. {
  54763. const MouseEvent e2 (e.getEventRelativeTo (this));
  54764. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54765. {
  54766. if (currentPopupIndex >= 0)
  54767. {
  54768. const int item = getItemAt (e2.x, e2.y);
  54769. if (item >= 0)
  54770. showMenu (item);
  54771. }
  54772. else
  54773. {
  54774. updateItemUnderMouse (e2.x, e2.y);
  54775. }
  54776. lastMouseX = e2.x;
  54777. lastMouseY = e2.y;
  54778. }
  54779. }
  54780. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54781. {
  54782. bool used = false;
  54783. const int numMenus = menuNames.size();
  54784. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54785. if (key.isKeyCode (KeyPress::leftKey))
  54786. {
  54787. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54788. used = true;
  54789. }
  54790. else if (key.isKeyCode (KeyPress::rightKey))
  54791. {
  54792. showMenu ((currentIndex + 1) % numMenus);
  54793. used = true;
  54794. }
  54795. return used;
  54796. }
  54797. void MenuBarComponent::inputAttemptWhenModal()
  54798. {
  54799. hideCurrentMenu();
  54800. }
  54801. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54802. {
  54803. StringArray newNames;
  54804. if (model != 0)
  54805. newNames = model->getMenuBarNames();
  54806. if (newNames != menuNames)
  54807. {
  54808. menuNames = newNames;
  54809. repaint();
  54810. resized();
  54811. }
  54812. }
  54813. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54814. const ApplicationCommandTarget::InvocationInfo& info)
  54815. {
  54816. if (model == 0
  54817. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54818. return;
  54819. for (int i = 0; i < menuNames.size(); ++i)
  54820. {
  54821. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54822. if (menu.containsCommandItem (info.commandID))
  54823. {
  54824. itemUnderMouse = i;
  54825. repaintMenuItem (i);
  54826. startTimer (200);
  54827. break;
  54828. }
  54829. }
  54830. }
  54831. void MenuBarComponent::timerCallback()
  54832. {
  54833. stopTimer();
  54834. const Point<int> mousePos (getMouseXYRelative());
  54835. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54836. }
  54837. END_JUCE_NAMESPACE
  54838. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54839. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54840. BEGIN_JUCE_NAMESPACE
  54841. MenuBarModel::MenuBarModel() throw()
  54842. : manager (0)
  54843. {
  54844. }
  54845. MenuBarModel::~MenuBarModel()
  54846. {
  54847. setApplicationCommandManagerToWatch (0);
  54848. }
  54849. void MenuBarModel::menuItemsChanged()
  54850. {
  54851. triggerAsyncUpdate();
  54852. }
  54853. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54854. {
  54855. if (manager != newManager)
  54856. {
  54857. if (manager != 0)
  54858. manager->removeListener (this);
  54859. manager = newManager;
  54860. if (manager != 0)
  54861. manager->addListener (this);
  54862. }
  54863. }
  54864. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54865. {
  54866. jassert (newListener != 0);
  54867. jassert (! listeners.contains (newListener)); // trying to add a listener to the list twice!
  54868. if (newListener != 0)
  54869. listeners.add (newListener);
  54870. }
  54871. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54872. {
  54873. // Trying to remove a listener that isn't on the list!
  54874. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54875. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54876. jassert (listeners.contains (listenerToRemove));
  54877. listeners.removeValue (listenerToRemove);
  54878. }
  54879. void MenuBarModel::handleAsyncUpdate()
  54880. {
  54881. for (int i = listeners.size(); --i >= 0;)
  54882. {
  54883. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuBarItemsChanged (this);
  54884. i = jmin (i, listeners.size());
  54885. }
  54886. }
  54887. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54888. {
  54889. for (int i = listeners.size(); --i >= 0;)
  54890. {
  54891. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuCommandInvoked (this, info);
  54892. i = jmin (i, listeners.size());
  54893. }
  54894. }
  54895. void MenuBarModel::applicationCommandListChanged()
  54896. {
  54897. menuItemsChanged();
  54898. }
  54899. END_JUCE_NAMESPACE
  54900. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54901. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54902. BEGIN_JUCE_NAMESPACE
  54903. class PopupMenu::Item
  54904. {
  54905. public:
  54906. Item()
  54907. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54908. usesColour (false), customComp (0), commandManager (0)
  54909. {
  54910. }
  54911. Item (const int itemId_,
  54912. const String& text_,
  54913. const bool active_,
  54914. const bool isTicked_,
  54915. const Image* im,
  54916. const Colour& textColour_,
  54917. const bool usesColour_,
  54918. PopupMenuCustomComponent* const customComp_,
  54919. const PopupMenu* const subMenu_,
  54920. ApplicationCommandManager* const commandManager_)
  54921. : itemId (itemId_), text (text_), textColour (textColour_),
  54922. active (active_), isSeparator (false), isTicked (isTicked_),
  54923. usesColour (usesColour_), customComp (customComp_),
  54924. commandManager (commandManager_)
  54925. {
  54926. if (subMenu_ != 0)
  54927. subMenu = new PopupMenu (*subMenu_);
  54928. if (im != 0)
  54929. image = im->createCopy();
  54930. if (commandManager_ != 0 && itemId_ != 0)
  54931. {
  54932. String shortcutKey;
  54933. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54934. ->getKeyPressesAssignedToCommand (itemId_));
  54935. for (int i = 0; i < keyPresses.size(); ++i)
  54936. {
  54937. const String key (keyPresses.getReference(i).getTextDescription());
  54938. if (shortcutKey.isNotEmpty())
  54939. shortcutKey << ", ";
  54940. if (key.length() == 1)
  54941. shortcutKey << "shortcut: '" << key << '\'';
  54942. else
  54943. shortcutKey << key;
  54944. }
  54945. shortcutKey = shortcutKey.trim();
  54946. if (shortcutKey.isNotEmpty())
  54947. text << "<end>" << shortcutKey;
  54948. }
  54949. }
  54950. Item (const Item& other)
  54951. : itemId (other.itemId),
  54952. text (other.text),
  54953. textColour (other.textColour),
  54954. active (other.active),
  54955. isSeparator (other.isSeparator),
  54956. isTicked (other.isTicked),
  54957. usesColour (other.usesColour),
  54958. customComp (other.customComp),
  54959. commandManager (other.commandManager)
  54960. {
  54961. if (other.subMenu != 0)
  54962. subMenu = new PopupMenu (*(other.subMenu));
  54963. if (other.image != 0)
  54964. image = other.image->createCopy();
  54965. }
  54966. ~Item()
  54967. {
  54968. customComp = 0;
  54969. }
  54970. bool canBeTriggered() const throw()
  54971. {
  54972. return active && ! (isSeparator || (subMenu != 0));
  54973. }
  54974. bool hasActiveSubMenu() const throw()
  54975. {
  54976. return active && (subMenu != 0);
  54977. }
  54978. const int itemId;
  54979. String text;
  54980. const Colour textColour;
  54981. const bool active, isSeparator, isTicked, usesColour;
  54982. ScopedPointer <Image> image;
  54983. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54984. ScopedPointer <PopupMenu> subMenu;
  54985. ApplicationCommandManager* const commandManager;
  54986. juce_UseDebuggingNewOperator
  54987. private:
  54988. Item& operator= (const Item&);
  54989. };
  54990. class PopupMenu::ItemComponent : public Component
  54991. {
  54992. public:
  54993. ItemComponent (const PopupMenu::Item& itemInfo_)
  54994. : itemInfo (itemInfo_),
  54995. isHighlighted (false)
  54996. {
  54997. if (itemInfo.customComp != 0)
  54998. addAndMakeVisible (itemInfo.customComp);
  54999. }
  55000. ~ItemComponent()
  55001. {
  55002. if (itemInfo.customComp != 0)
  55003. removeChildComponent (itemInfo.customComp);
  55004. }
  55005. void getIdealSize (int& idealWidth,
  55006. int& idealHeight,
  55007. const int standardItemHeight)
  55008. {
  55009. if (itemInfo.customComp != 0)
  55010. {
  55011. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  55012. }
  55013. else
  55014. {
  55015. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  55016. itemInfo.isSeparator,
  55017. standardItemHeight,
  55018. idealWidth,
  55019. idealHeight);
  55020. }
  55021. }
  55022. void paint (Graphics& g)
  55023. {
  55024. if (itemInfo.customComp == 0)
  55025. {
  55026. String mainText (itemInfo.text);
  55027. String endText;
  55028. const int endIndex = mainText.indexOf (T("<end>"));
  55029. if (endIndex >= 0)
  55030. {
  55031. endText = mainText.substring (endIndex + 5).trim();
  55032. mainText = mainText.substring (0, endIndex);
  55033. }
  55034. getLookAndFeel()
  55035. .drawPopupMenuItem (g, getWidth(), getHeight(),
  55036. itemInfo.isSeparator,
  55037. itemInfo.active,
  55038. isHighlighted,
  55039. itemInfo.isTicked,
  55040. itemInfo.subMenu != 0,
  55041. mainText, endText,
  55042. itemInfo.image,
  55043. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  55044. }
  55045. }
  55046. void resized()
  55047. {
  55048. if (getNumChildComponents() > 0)
  55049. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  55050. }
  55051. void setHighlighted (bool shouldBeHighlighted)
  55052. {
  55053. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  55054. if (isHighlighted != shouldBeHighlighted)
  55055. {
  55056. isHighlighted = shouldBeHighlighted;
  55057. if (itemInfo.customComp != 0)
  55058. {
  55059. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  55060. itemInfo.customComp->repaint();
  55061. }
  55062. repaint();
  55063. }
  55064. }
  55065. PopupMenu::Item itemInfo;
  55066. juce_UseDebuggingNewOperator
  55067. private:
  55068. bool isHighlighted;
  55069. ItemComponent (const ItemComponent&);
  55070. ItemComponent& operator= (const ItemComponent&);
  55071. };
  55072. namespace PopupMenuSettings
  55073. {
  55074. static const int scrollZone = 24;
  55075. static const int borderSize = 2;
  55076. static const int timerInterval = 50;
  55077. static const int dismissCommandId = 0x6287345f;
  55078. }
  55079. class PopupMenu::Window : public Component,
  55080. private Timer
  55081. {
  55082. public:
  55083. Window()
  55084. : Component (T("menu")),
  55085. owner (0),
  55086. currentChild (0),
  55087. activeSubMenu (0),
  55088. menuBarComponent (0),
  55089. managerOfChosenCommand (0),
  55090. componentAttachedTo (0),
  55091. minimumWidth (0),
  55092. maximumNumColumns (7),
  55093. standardItemHeight (0),
  55094. isOver (false),
  55095. hasBeenOver (false),
  55096. isDown (false),
  55097. needsToScroll (false),
  55098. hideOnExit (false),
  55099. disableMouseMoves (false),
  55100. hasAnyJuceCompHadFocus (false),
  55101. numColumns (0),
  55102. contentHeight (0),
  55103. childYOffset (0),
  55104. timeEnteredCurrentChildComp (0),
  55105. scrollAcceleration (1.0)
  55106. {
  55107. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  55108. setWantsKeyboardFocus (true);
  55109. setMouseClickGrabsKeyboardFocus (false);
  55110. setOpaque (true);
  55111. setAlwaysOnTop (true);
  55112. Desktop::getInstance().addGlobalMouseListener (this);
  55113. getActiveWindows().add (this);
  55114. }
  55115. ~Window()
  55116. {
  55117. getActiveWindows().removeValue (this);
  55118. Desktop::getInstance().removeGlobalMouseListener (this);
  55119. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55120. activeSubMenu = 0;
  55121. deleteAllChildren();
  55122. attachedCompWatcher = 0;
  55123. }
  55124. static Window* create (const PopupMenu& menu,
  55125. const bool dismissOnMouseUp,
  55126. Window* const owner_,
  55127. const int minX, const int maxX,
  55128. const int minY, const int maxY,
  55129. const int minimumWidth,
  55130. const int maximumNumColumns,
  55131. const int standardItemHeight,
  55132. const bool alignToRectangle,
  55133. const int itemIdThatMustBeVisible,
  55134. Component* const menuBarComponent,
  55135. ApplicationCommandManager** managerOfChosenCommand,
  55136. Component* const componentAttachedTo)
  55137. {
  55138. if (menu.items.size() > 0)
  55139. {
  55140. int totalItems = 0;
  55141. ScopedPointer <Window> mw (new Window());
  55142. mw->setLookAndFeel (menu.lookAndFeel);
  55143. mw->setWantsKeyboardFocus (false);
  55144. mw->minimumWidth = minimumWidth;
  55145. mw->maximumNumColumns = maximumNumColumns;
  55146. mw->standardItemHeight = standardItemHeight;
  55147. mw->dismissOnMouseUp = dismissOnMouseUp;
  55148. for (int i = 0; i < menu.items.size(); ++i)
  55149. {
  55150. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  55151. mw->addItem (*item);
  55152. ++totalItems;
  55153. }
  55154. if (totalItems > 0)
  55155. {
  55156. mw->owner = owner_;
  55157. mw->menuBarComponent = menuBarComponent;
  55158. mw->managerOfChosenCommand = managerOfChosenCommand;
  55159. mw->componentAttachedTo = componentAttachedTo;
  55160. mw->attachedCompWatcher = componentAttachedTo != 0 ? new ComponentDeletionWatcher (componentAttachedTo) : 0;
  55161. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  55162. mw->setTopLeftPosition (mw->windowPos.getX(),
  55163. mw->windowPos.getY());
  55164. mw->updateYPositions();
  55165. if (itemIdThatMustBeVisible != 0)
  55166. {
  55167. const int y = minY - mw->windowPos.getY();
  55168. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  55169. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  55170. }
  55171. mw->resizeToBestWindowPos();
  55172. mw->addToDesktop (ComponentPeer::windowIsTemporary
  55173. | mw->getLookAndFeel().getMenuWindowFlags());
  55174. return mw.release();
  55175. }
  55176. }
  55177. return 0;
  55178. }
  55179. void paint (Graphics& g)
  55180. {
  55181. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  55182. }
  55183. void paintOverChildren (Graphics& g)
  55184. {
  55185. if (isScrolling())
  55186. {
  55187. LookAndFeel& lf = getLookAndFeel();
  55188. if (isScrollZoneActive (false))
  55189. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  55190. if (isScrollZoneActive (true))
  55191. {
  55192. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  55193. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  55194. }
  55195. }
  55196. }
  55197. bool isScrollZoneActive (bool bottomOne) const
  55198. {
  55199. return isScrolling()
  55200. && (bottomOne
  55201. ? childYOffset < contentHeight - windowPos.getHeight()
  55202. : childYOffset > 0);
  55203. }
  55204. void addItem (const PopupMenu::Item& item)
  55205. {
  55206. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  55207. addAndMakeVisible (mic);
  55208. int itemW = 80;
  55209. int itemH = 16;
  55210. mic->getIdealSize (itemW, itemH, standardItemHeight);
  55211. mic->setSize (itemW, jlimit (2, 600, itemH));
  55212. mic->addMouseListener (this, false);
  55213. }
  55214. // hide this and all sub-comps
  55215. void hide (const PopupMenu::Item* const item)
  55216. {
  55217. if (isVisible())
  55218. {
  55219. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55220. activeSubMenu = 0;
  55221. currentChild = 0;
  55222. exitModalState (item != 0 ? item->itemId : 0);
  55223. setVisible (false);
  55224. if (item != 0
  55225. && item->commandManager != 0
  55226. && item->itemId != 0)
  55227. {
  55228. *managerOfChosenCommand = item->commandManager;
  55229. }
  55230. }
  55231. }
  55232. void dismissMenu (const PopupMenu::Item* const item)
  55233. {
  55234. if (owner != 0)
  55235. {
  55236. owner->dismissMenu (item);
  55237. }
  55238. else
  55239. {
  55240. if (item != 0)
  55241. {
  55242. // need a copy of this on the stack as the one passed in will get deleted during this call
  55243. const PopupMenu::Item mi (*item);
  55244. hide (&mi);
  55245. }
  55246. else
  55247. {
  55248. hide (0);
  55249. }
  55250. }
  55251. }
  55252. void mouseMove (const MouseEvent&)
  55253. {
  55254. timerCallback();
  55255. }
  55256. void mouseDown (const MouseEvent&)
  55257. {
  55258. timerCallback();
  55259. }
  55260. void mouseDrag (const MouseEvent&)
  55261. {
  55262. timerCallback();
  55263. }
  55264. void mouseUp (const MouseEvent&)
  55265. {
  55266. timerCallback();
  55267. }
  55268. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  55269. {
  55270. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  55271. lastMouse = Point<int> (-1, -1);
  55272. }
  55273. bool keyPressed (const KeyPress& key)
  55274. {
  55275. if (key.isKeyCode (KeyPress::downKey))
  55276. {
  55277. selectNextItem (1);
  55278. }
  55279. else if (key.isKeyCode (KeyPress::upKey))
  55280. {
  55281. selectNextItem (-1);
  55282. }
  55283. else if (key.isKeyCode (KeyPress::leftKey))
  55284. {
  55285. Window* parentWindow = owner;
  55286. if (parentWindow != 0)
  55287. {
  55288. PopupMenu::ItemComponent* currentChildOfParent
  55289. = (parentWindow != 0) ? parentWindow->currentChild : 0;
  55290. hide (0);
  55291. if (parentWindow->isValidComponent())
  55292. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  55293. disableTimerUntilMouseMoves();
  55294. }
  55295. else if (menuBarComponent != 0)
  55296. {
  55297. menuBarComponent->keyPressed (key);
  55298. }
  55299. }
  55300. else if (key.isKeyCode (KeyPress::rightKey))
  55301. {
  55302. disableTimerUntilMouseMoves();
  55303. if (showSubMenuFor (currentChild))
  55304. {
  55305. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55306. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  55307. activeSubMenu->selectNextItem (1);
  55308. }
  55309. else if (menuBarComponent != 0)
  55310. {
  55311. menuBarComponent->keyPressed (key);
  55312. }
  55313. }
  55314. else if (key.isKeyCode (KeyPress::returnKey))
  55315. {
  55316. triggerCurrentlyHighlightedItem();
  55317. }
  55318. else if (key.isKeyCode (KeyPress::escapeKey))
  55319. {
  55320. dismissMenu (0);
  55321. }
  55322. else
  55323. {
  55324. return false;
  55325. }
  55326. return true;
  55327. }
  55328. void inputAttemptWhenModal()
  55329. {
  55330. timerCallback();
  55331. if (! isOverAnyMenu())
  55332. {
  55333. if (componentAttachedTo != 0 && ! attachedCompWatcher->hasBeenDeleted())
  55334. {
  55335. // we want to dismiss the menu, but if we do it synchronously, then
  55336. // the mouse-click will be allowed to pass through. That's good, except
  55337. // when the user clicks on the button that orginally popped the menu up,
  55338. // as they'll expect the menu to go away, and in fact it'll just
  55339. // come back. So only dismiss synchronously if they're not on the original
  55340. // comp that we're attached to.
  55341. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  55342. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  55343. {
  55344. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  55345. return;
  55346. }
  55347. }
  55348. dismissMenu (0);
  55349. }
  55350. }
  55351. void handleCommandMessage (int commandId)
  55352. {
  55353. Component::handleCommandMessage (commandId);
  55354. if (commandId == PopupMenuSettings::dismissCommandId)
  55355. dismissMenu (0);
  55356. }
  55357. void timerCallback()
  55358. {
  55359. if (! isVisible())
  55360. return;
  55361. if (attachedCompWatcher != 0 && attachedCompWatcher->hasBeenDeleted())
  55362. {
  55363. dismissMenu (0);
  55364. return;
  55365. }
  55366. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  55367. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  55368. return;
  55369. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  55370. // move rather than a real timer callback
  55371. const Point<int> globalMousePos (Desktop::getMousePosition());
  55372. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  55373. const uint32 now = Time::getMillisecondCounter();
  55374. if (now > timeEnteredCurrentChildComp + 100
  55375. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  55376. && currentChild->isValidComponent()
  55377. && (! disableMouseMoves)
  55378. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  55379. {
  55380. showSubMenuFor (currentChild);
  55381. }
  55382. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  55383. {
  55384. highlightItemUnderMouse (globalMousePos, localMousePos);
  55385. }
  55386. bool overScrollArea = false;
  55387. if (isScrolling()
  55388. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  55389. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  55390. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  55391. {
  55392. if (now > lastScroll + 20)
  55393. {
  55394. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  55395. int amount = 0;
  55396. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  55397. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  55398. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  55399. lastScroll = now;
  55400. }
  55401. overScrollArea = true;
  55402. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  55403. }
  55404. else
  55405. {
  55406. scrollAcceleration = 1.0;
  55407. }
  55408. const bool wasDown = isDown;
  55409. bool isOverAny = isOverAnyMenu();
  55410. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  55411. {
  55412. activeSubMenu->updateMouseOverStatus (globalMousePos);
  55413. isOverAny = isOverAnyMenu();
  55414. }
  55415. if (hideOnExit && hasBeenOver && ! isOverAny)
  55416. {
  55417. hide (0);
  55418. }
  55419. else
  55420. {
  55421. isDown = hasBeenOver
  55422. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  55423. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  55424. bool anyFocused = Process::isForegroundProcess();
  55425. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  55426. {
  55427. // because no component at all may have focus, our test here will
  55428. // only be triggered when something has focus and then loses it.
  55429. anyFocused = ! hasAnyJuceCompHadFocus;
  55430. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  55431. {
  55432. if (ComponentPeer::getPeer (i)->isFocused())
  55433. {
  55434. anyFocused = true;
  55435. hasAnyJuceCompHadFocus = true;
  55436. break;
  55437. }
  55438. }
  55439. }
  55440. if (! anyFocused)
  55441. {
  55442. if (now > lastFocused + 10)
  55443. {
  55444. wasHiddenBecauseOfAppChange() = true;
  55445. dismissMenu (0);
  55446. return; // may have been deleted by the previous call..
  55447. }
  55448. }
  55449. else if (wasDown && now > menuCreationTime + 250
  55450. && ! (isDown || overScrollArea))
  55451. {
  55452. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55453. if (isOver)
  55454. {
  55455. triggerCurrentlyHighlightedItem();
  55456. }
  55457. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  55458. {
  55459. dismissMenu (0);
  55460. }
  55461. return; // may have been deleted by the previous calls..
  55462. }
  55463. else
  55464. {
  55465. lastFocused = now;
  55466. }
  55467. }
  55468. }
  55469. static Array<Window*>& getActiveWindows()
  55470. {
  55471. static Array<Window*> activeMenuWindows;
  55472. return activeMenuWindows;
  55473. }
  55474. static bool& wasHiddenBecauseOfAppChange() throw()
  55475. {
  55476. static bool b = false;
  55477. return b;
  55478. }
  55479. juce_UseDebuggingNewOperator
  55480. private:
  55481. Window* owner;
  55482. PopupMenu::ItemComponent* currentChild;
  55483. ScopedPointer <Window> activeSubMenu;
  55484. Component* menuBarComponent;
  55485. ApplicationCommandManager** managerOfChosenCommand;
  55486. Component* componentAttachedTo;
  55487. ScopedPointer <ComponentDeletionWatcher> attachedCompWatcher;
  55488. Rectangle<int> windowPos;
  55489. Point<int> lastMouse;
  55490. int minimumWidth, maximumNumColumns, standardItemHeight;
  55491. bool isOver, hasBeenOver, isDown, needsToScroll;
  55492. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  55493. int numColumns, contentHeight, childYOffset;
  55494. Array <int> columnWidths;
  55495. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  55496. double scrollAcceleration;
  55497. bool overlaps (const Rectangle<int>& r) const
  55498. {
  55499. return r.intersects (getBounds())
  55500. || (owner != 0 && owner->overlaps (r));
  55501. }
  55502. bool isOverAnyMenu() const
  55503. {
  55504. return (owner != 0) ? owner->isOverAnyMenu()
  55505. : isOverChildren();
  55506. }
  55507. bool isOverChildren() const
  55508. {
  55509. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55510. return isVisible()
  55511. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  55512. }
  55513. void updateMouseOverStatus (const Point<int>& globalMousePos)
  55514. {
  55515. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  55516. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  55517. if (activeSubMenu != 0)
  55518. activeSubMenu->updateMouseOverStatus (globalMousePos);
  55519. }
  55520. bool treeContains (const Window* const window) const throw()
  55521. {
  55522. const Window* mw = this;
  55523. while (mw->owner != 0)
  55524. mw = mw->owner;
  55525. while (mw != 0)
  55526. {
  55527. if (mw == window)
  55528. return true;
  55529. mw = mw->activeSubMenu;
  55530. }
  55531. return false;
  55532. }
  55533. void calculateWindowPos (const int minX, const int maxX,
  55534. const int minY, const int maxY,
  55535. const bool alignToRectangle)
  55536. {
  55537. const Rectangle<int> mon (Desktop::getInstance()
  55538. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  55539. (minY + maxY) / 2),
  55540. #if JUCE_MAC
  55541. true));
  55542. #else
  55543. false)); // on windows, don't stop the menu overlapping the taskbar
  55544. #endif
  55545. int x, y, widthToUse, heightToUse;
  55546. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55547. if (alignToRectangle)
  55548. {
  55549. x = minX;
  55550. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55551. const int spaceOver = minY - mon.getY();
  55552. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55553. y = maxY;
  55554. else
  55555. y = minY - heightToUse;
  55556. }
  55557. else
  55558. {
  55559. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55560. if (owner != 0)
  55561. {
  55562. if (owner->owner != 0)
  55563. {
  55564. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55565. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55566. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55567. tendTowardsRight = true;
  55568. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55569. tendTowardsRight = false;
  55570. }
  55571. else if (maxX + widthToUse < mon.getRight() - 32)
  55572. {
  55573. tendTowardsRight = true;
  55574. }
  55575. }
  55576. const int biggestSpace = jmax (mon.getRight() - maxX,
  55577. minX - mon.getX()) - 32;
  55578. if (biggestSpace < widthToUse)
  55579. {
  55580. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55581. if (numColumns > 1)
  55582. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55583. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55584. }
  55585. if (tendTowardsRight)
  55586. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55587. else
  55588. x = jmax (mon.getX() + 4, minX - widthToUse);
  55589. y = minY;
  55590. if ((minY + maxY) / 2 > mon.getCentreY())
  55591. y = jmax (mon.getY(), maxY - heightToUse);
  55592. }
  55593. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55594. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55595. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55596. // sets this flag if it's big enough to obscure any of its parent menus
  55597. hideOnExit = (owner != 0)
  55598. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55599. }
  55600. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55601. {
  55602. numColumns = 0;
  55603. contentHeight = 0;
  55604. const int maxMenuH = getParentHeight() - 24;
  55605. int totalW;
  55606. do
  55607. {
  55608. ++numColumns;
  55609. totalW = workOutBestSize (maxMenuW);
  55610. if (totalW > maxMenuW)
  55611. {
  55612. numColumns = jmax (1, numColumns - 1);
  55613. totalW = workOutBestSize (maxMenuW); // to update col widths
  55614. break;
  55615. }
  55616. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55617. {
  55618. break;
  55619. }
  55620. } while (numColumns < maximumNumColumns);
  55621. const int actualH = jmin (contentHeight, maxMenuH);
  55622. needsToScroll = contentHeight > actualH;
  55623. width = updateYPositions();
  55624. height = actualH + PopupMenuSettings::borderSize * 2;
  55625. }
  55626. int workOutBestSize (const int maxMenuW)
  55627. {
  55628. int totalW = 0;
  55629. contentHeight = 0;
  55630. int childNum = 0;
  55631. for (int col = 0; col < numColumns; ++col)
  55632. {
  55633. int i, colW = 50, colH = 0;
  55634. const int numChildren = jmin (getNumChildComponents() - childNum,
  55635. (getNumChildComponents() + numColumns - 1) / numColumns);
  55636. for (i = numChildren; --i >= 0;)
  55637. {
  55638. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55639. colH += getChildComponent (childNum + i)->getHeight();
  55640. }
  55641. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55642. columnWidths.set (col, colW);
  55643. totalW += colW;
  55644. contentHeight = jmax (contentHeight, colH);
  55645. childNum += numChildren;
  55646. }
  55647. if (totalW < minimumWidth)
  55648. {
  55649. totalW = minimumWidth;
  55650. for (int col = 0; col < numColumns; ++col)
  55651. columnWidths.set (0, totalW / numColumns);
  55652. }
  55653. return totalW;
  55654. }
  55655. void ensureItemIsVisible (const int itemId, int wantedY)
  55656. {
  55657. jassert (itemId != 0)
  55658. for (int i = getNumChildComponents(); --i >= 0;)
  55659. {
  55660. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55661. if (m != 0
  55662. && m->itemInfo.itemId == itemId
  55663. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55664. {
  55665. const int currentY = m->getY();
  55666. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55667. {
  55668. if (wantedY < 0)
  55669. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55670. jmax (PopupMenuSettings::scrollZone,
  55671. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55672. currentY);
  55673. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55674. int deltaY = wantedY - currentY;
  55675. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55676. jmin (windowPos.getHeight(), mon.getHeight()));
  55677. const int newY = jlimit (mon.getY(),
  55678. mon.getBottom() - windowPos.getHeight(),
  55679. windowPos.getY() + deltaY);
  55680. deltaY -= newY - windowPos.getY();
  55681. childYOffset -= deltaY;
  55682. windowPos.setPosition (windowPos.getX(), newY);
  55683. updateYPositions();
  55684. }
  55685. break;
  55686. }
  55687. }
  55688. }
  55689. void resizeToBestWindowPos()
  55690. {
  55691. Rectangle<int> r (windowPos);
  55692. if (childYOffset < 0)
  55693. {
  55694. r.setBounds (r.getX(), r.getY() - childYOffset,
  55695. r.getWidth(), r.getHeight() + childYOffset);
  55696. }
  55697. else if (childYOffset > 0)
  55698. {
  55699. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55700. if (spaceAtBottom > 0)
  55701. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55702. }
  55703. setBounds (r);
  55704. updateYPositions();
  55705. }
  55706. void alterChildYPos (const int delta)
  55707. {
  55708. if (isScrolling())
  55709. {
  55710. childYOffset += delta;
  55711. if (delta < 0)
  55712. {
  55713. childYOffset = jmax (childYOffset, 0);
  55714. }
  55715. else if (delta > 0)
  55716. {
  55717. childYOffset = jmin (childYOffset,
  55718. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55719. }
  55720. updateYPositions();
  55721. }
  55722. else
  55723. {
  55724. childYOffset = 0;
  55725. }
  55726. resizeToBestWindowPos();
  55727. repaint();
  55728. }
  55729. int updateYPositions()
  55730. {
  55731. int x = 0;
  55732. int childNum = 0;
  55733. for (int col = 0; col < numColumns; ++col)
  55734. {
  55735. const int numChildren = jmin (getNumChildComponents() - childNum,
  55736. (getNumChildComponents() + numColumns - 1) / numColumns);
  55737. const int colW = columnWidths [col];
  55738. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55739. for (int i = 0; i < numChildren; ++i)
  55740. {
  55741. Component* const c = getChildComponent (childNum + i);
  55742. c->setBounds (x, y, colW, c->getHeight());
  55743. y += c->getHeight();
  55744. }
  55745. x += colW;
  55746. childNum += numChildren;
  55747. }
  55748. return x;
  55749. }
  55750. bool isScrolling() const throw()
  55751. {
  55752. return childYOffset != 0 || needsToScroll;
  55753. }
  55754. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55755. {
  55756. if (currentChild->isValidComponent())
  55757. currentChild->setHighlighted (false);
  55758. currentChild = child;
  55759. if (currentChild != 0)
  55760. {
  55761. currentChild->setHighlighted (true);
  55762. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55763. }
  55764. }
  55765. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55766. {
  55767. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55768. activeSubMenu = 0;
  55769. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55770. {
  55771. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55772. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55773. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55774. dismissOnMouseUp,
  55775. this,
  55776. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55777. 0, maximumNumColumns,
  55778. standardItemHeight,
  55779. false, 0, menuBarComponent,
  55780. managerOfChosenCommand,
  55781. componentAttachedTo);
  55782. if (activeSubMenu != 0)
  55783. {
  55784. activeSubMenu->setVisible (true);
  55785. activeSubMenu->enterModalState (false);
  55786. activeSubMenu->toFront (false);
  55787. return true;
  55788. }
  55789. }
  55790. return false;
  55791. }
  55792. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55793. {
  55794. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55795. if (isOver)
  55796. hasBeenOver = true;
  55797. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55798. {
  55799. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55800. if (disableMouseMoves && isOver)
  55801. disableMouseMoves = false;
  55802. }
  55803. if (disableMouseMoves)
  55804. return;
  55805. bool isMovingTowardsMenu = false;
  55806. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55807. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55808. {
  55809. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55810. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55811. // extends from the last mouse pos to the submenu's rectangle..
  55812. float subX = (float) activeSubMenu->getScreenX();
  55813. if (activeSubMenu->getX() > getX())
  55814. {
  55815. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55816. }
  55817. else
  55818. {
  55819. lastMouse += Point<int> (2, 0);
  55820. subX += activeSubMenu->getWidth();
  55821. }
  55822. Path areaTowardsSubMenu;
  55823. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55824. (float) lastMouse.getY(),
  55825. subX,
  55826. (float) activeSubMenu->getScreenY(),
  55827. subX,
  55828. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55829. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55830. }
  55831. lastMouse = globalMousePos;
  55832. if (! isMovingTowardsMenu)
  55833. {
  55834. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55835. if (c == this)
  55836. c = 0;
  55837. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55838. if (mic == 0 && c != 0)
  55839. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55840. if (mic != currentChild
  55841. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55842. {
  55843. if (isOver && (c != 0) && (activeSubMenu != 0))
  55844. {
  55845. activeSubMenu->hide (0);
  55846. }
  55847. if (! isOver)
  55848. mic = 0;
  55849. setCurrentlyHighlightedChild (mic);
  55850. }
  55851. }
  55852. }
  55853. void triggerCurrentlyHighlightedItem()
  55854. {
  55855. if (currentChild->isValidComponent()
  55856. && currentChild->itemInfo.canBeTriggered()
  55857. && (currentChild->itemInfo.customComp == 0
  55858. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55859. {
  55860. dismissMenu (&currentChild->itemInfo);
  55861. }
  55862. }
  55863. void selectNextItem (const int delta)
  55864. {
  55865. disableTimerUntilMouseMoves();
  55866. PopupMenu::ItemComponent* mic = 0;
  55867. bool wasLastOne = (currentChild == 0);
  55868. const int numItems = getNumChildComponents();
  55869. for (int i = 0; i < numItems + 1; ++i)
  55870. {
  55871. int index = (delta > 0) ? i : (numItems - 1 - i);
  55872. index = (index + numItems) % numItems;
  55873. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55874. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55875. && wasLastOne)
  55876. break;
  55877. if (mic == currentChild)
  55878. wasLastOne = true;
  55879. }
  55880. setCurrentlyHighlightedChild (mic);
  55881. }
  55882. void disableTimerUntilMouseMoves()
  55883. {
  55884. disableMouseMoves = true;
  55885. if (owner != 0)
  55886. owner->disableTimerUntilMouseMoves();
  55887. }
  55888. Window (const Window&);
  55889. Window& operator= (const Window&);
  55890. };
  55891. PopupMenu::PopupMenu()
  55892. : lookAndFeel (0),
  55893. separatorPending (false)
  55894. {
  55895. }
  55896. PopupMenu::PopupMenu (const PopupMenu& other)
  55897. : lookAndFeel (other.lookAndFeel),
  55898. separatorPending (false)
  55899. {
  55900. items.ensureStorageAllocated (other.items.size());
  55901. for (int i = 0; i < other.items.size(); ++i)
  55902. items.add (new Item (*other.items.getUnchecked(i)));
  55903. }
  55904. const PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55905. {
  55906. if (this != &other)
  55907. {
  55908. lookAndFeel = other.lookAndFeel;
  55909. clear();
  55910. items.ensureStorageAllocated (other.items.size());
  55911. for (int i = 0; i < other.items.size(); ++i)
  55912. items.add (new Item (*other.items.getUnchecked(i)));
  55913. }
  55914. return *this;
  55915. }
  55916. PopupMenu::~PopupMenu()
  55917. {
  55918. clear();
  55919. }
  55920. void PopupMenu::clear()
  55921. {
  55922. items.clear();
  55923. separatorPending = false;
  55924. }
  55925. void PopupMenu::addSeparatorIfPending()
  55926. {
  55927. if (separatorPending)
  55928. {
  55929. separatorPending = false;
  55930. if (items.size() > 0)
  55931. items.add (new Item());
  55932. }
  55933. }
  55934. void PopupMenu::addItem (const int itemResultId,
  55935. const String& itemText,
  55936. const bool isActive,
  55937. const bool isTicked,
  55938. const Image* const iconToUse)
  55939. {
  55940. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55941. // didn't pick anything, so you shouldn't use it as the id
  55942. // for an item..
  55943. addSeparatorIfPending();
  55944. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55945. iconToUse, Colours::black, false, 0, 0, 0));
  55946. }
  55947. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55948. const int commandID,
  55949. const String& displayName)
  55950. {
  55951. jassert (commandManager != 0 && commandID != 0);
  55952. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55953. if (registeredInfo != 0)
  55954. {
  55955. ApplicationCommandInfo info (*registeredInfo);
  55956. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55957. addSeparatorIfPending();
  55958. items.add (new Item (commandID,
  55959. displayName.isNotEmpty() ? displayName
  55960. : info.shortName,
  55961. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55962. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55963. 0,
  55964. Colours::black,
  55965. false,
  55966. 0, 0,
  55967. commandManager));
  55968. }
  55969. }
  55970. void PopupMenu::addColouredItem (const int itemResultId,
  55971. const String& itemText,
  55972. const Colour& itemTextColour,
  55973. const bool isActive,
  55974. const bool isTicked,
  55975. const Image* const iconToUse)
  55976. {
  55977. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55978. // didn't pick anything, so you shouldn't use it as the id
  55979. // for an item..
  55980. addSeparatorIfPending();
  55981. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55982. iconToUse, itemTextColour, true, 0, 0, 0));
  55983. }
  55984. void PopupMenu::addCustomItem (const int itemResultId,
  55985. PopupMenuCustomComponent* const customComponent)
  55986. {
  55987. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55988. // didn't pick anything, so you shouldn't use it as the id
  55989. // for an item..
  55990. addSeparatorIfPending();
  55991. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55992. Colours::black, false, customComponent, 0, 0));
  55993. }
  55994. class NormalComponentWrapper : public PopupMenuCustomComponent
  55995. {
  55996. public:
  55997. NormalComponentWrapper (Component* const comp,
  55998. const int w, const int h,
  55999. const bool triggerMenuItemAutomaticallyWhenClicked)
  56000. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  56001. width (w),
  56002. height (h)
  56003. {
  56004. addAndMakeVisible (comp);
  56005. }
  56006. ~NormalComponentWrapper() {}
  56007. void getIdealSize (int& idealWidth, int& idealHeight)
  56008. {
  56009. idealWidth = width;
  56010. idealHeight = height;
  56011. }
  56012. void resized()
  56013. {
  56014. if (getChildComponent(0) != 0)
  56015. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  56016. }
  56017. juce_UseDebuggingNewOperator
  56018. private:
  56019. const int width, height;
  56020. NormalComponentWrapper (const NormalComponentWrapper&);
  56021. const NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  56022. };
  56023. void PopupMenu::addCustomItem (const int itemResultId,
  56024. Component* customComponent,
  56025. int idealWidth, int idealHeight,
  56026. const bool triggerMenuItemAutomaticallyWhenClicked)
  56027. {
  56028. addCustomItem (itemResultId,
  56029. new NormalComponentWrapper (customComponent,
  56030. idealWidth, idealHeight,
  56031. triggerMenuItemAutomaticallyWhenClicked));
  56032. }
  56033. void PopupMenu::addSubMenu (const String& subMenuName,
  56034. const PopupMenu& subMenu,
  56035. const bool isActive,
  56036. Image* const iconToUse,
  56037. const bool isTicked)
  56038. {
  56039. addSeparatorIfPending();
  56040. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  56041. iconToUse, Colours::black, false, 0, &subMenu, 0));
  56042. }
  56043. void PopupMenu::addSeparator()
  56044. {
  56045. separatorPending = true;
  56046. }
  56047. class HeaderItemComponent : public PopupMenuCustomComponent
  56048. {
  56049. public:
  56050. HeaderItemComponent (const String& name)
  56051. : PopupMenuCustomComponent (false)
  56052. {
  56053. setName (name);
  56054. }
  56055. ~HeaderItemComponent()
  56056. {
  56057. }
  56058. void paint (Graphics& g)
  56059. {
  56060. Font f (getLookAndFeel().getPopupMenuFont());
  56061. f.setBold (true);
  56062. g.setFont (f);
  56063. g.setColour (findColour (PopupMenu::headerTextColourId));
  56064. g.drawFittedText (getName(),
  56065. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  56066. Justification::bottomLeft, 1);
  56067. }
  56068. void getIdealSize (int& idealWidth,
  56069. int& idealHeight)
  56070. {
  56071. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  56072. idealHeight += idealHeight / 2;
  56073. idealWidth += idealWidth / 4;
  56074. }
  56075. juce_UseDebuggingNewOperator
  56076. };
  56077. void PopupMenu::addSectionHeader (const String& title)
  56078. {
  56079. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  56080. }
  56081. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  56082. const int itemIdThatMustBeVisible,
  56083. const int minimumWidth,
  56084. const int maximumNumColumns,
  56085. const int standardItemHeight,
  56086. const bool alignToRectangle,
  56087. Component* menuBarComponent,
  56088. ApplicationCommandManager** managerOfChosenCommand,
  56089. Component* const componentAttachedTo)
  56090. {
  56091. Window* const pw
  56092. = Window::create (*this,
  56093. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  56094. 0,
  56095. x, x + w,
  56096. y, y + h,
  56097. minimumWidth,
  56098. maximumNumColumns,
  56099. standardItemHeight,
  56100. alignToRectangle,
  56101. itemIdThatMustBeVisible,
  56102. menuBarComponent,
  56103. managerOfChosenCommand,
  56104. componentAttachedTo);
  56105. if (pw != 0)
  56106. pw->setVisible (true);
  56107. return pw;
  56108. }
  56109. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  56110. const int itemIdThatMustBeVisible,
  56111. const int minimumWidth,
  56112. const int maximumNumColumns,
  56113. const int standardItemHeight,
  56114. const bool alignToRectangle,
  56115. Component* const componentAttachedTo)
  56116. {
  56117. Component* const prevFocused = Component::getCurrentlyFocusedComponent();
  56118. ScopedPointer <ComponentDeletionWatcher> deletionChecker[2];
  56119. if (prevFocused != 0)
  56120. deletionChecker[0] = new ComponentDeletionWatcher (prevFocused);
  56121. Component* const prevTopLevel = (prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0;
  56122. if (prevTopLevel != 0)
  56123. deletionChecker[1] = new ComponentDeletionWatcher (prevTopLevel);
  56124. Window::wasHiddenBecauseOfAppChange() = false;
  56125. int result = 0;
  56126. ApplicationCommandManager* managerOfChosenCommand = 0;
  56127. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  56128. itemIdThatMustBeVisible,
  56129. minimumWidth,
  56130. maximumNumColumns > 0 ? maximumNumColumns : 7,
  56131. standardItemHeight,
  56132. alignToRectangle, 0,
  56133. &managerOfChosenCommand,
  56134. componentAttachedTo));
  56135. if (popupComp != 0)
  56136. {
  56137. popupComp->enterModalState (false);
  56138. popupComp->toFront (false); // need to do this after making it modal, or it could
  56139. // be stuck behind other comps that are already modal..
  56140. result = popupComp->runModalLoop();
  56141. popupComp = 0;
  56142. if (! Window::wasHiddenBecauseOfAppChange())
  56143. {
  56144. if (deletionChecker[1] != 0 && ! deletionChecker[1]->hasBeenDeleted())
  56145. prevTopLevel->toFront (true);
  56146. if (deletionChecker[0] != 0 && ! deletionChecker[0]->hasBeenDeleted())
  56147. prevFocused->grabKeyboardFocus();
  56148. }
  56149. }
  56150. if (managerOfChosenCommand != 0 && result != 0)
  56151. {
  56152. ApplicationCommandTarget::InvocationInfo info (result);
  56153. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  56154. managerOfChosenCommand->invoke (info, true);
  56155. }
  56156. return result;
  56157. }
  56158. int PopupMenu::show (const int itemIdThatMustBeVisible,
  56159. const int minimumWidth,
  56160. const int maximumNumColumns,
  56161. const int standardItemHeight)
  56162. {
  56163. const Point<int> mousePos (Desktop::getMousePosition());
  56164. return showAt (mousePos.getX(), mousePos.getY(),
  56165. itemIdThatMustBeVisible,
  56166. minimumWidth,
  56167. maximumNumColumns,
  56168. standardItemHeight);
  56169. }
  56170. int PopupMenu::showAt (const int screenX,
  56171. const int screenY,
  56172. const int itemIdThatMustBeVisible,
  56173. const int minimumWidth,
  56174. const int maximumNumColumns,
  56175. const int standardItemHeight)
  56176. {
  56177. return showMenu (screenX, screenY, 1, 1,
  56178. itemIdThatMustBeVisible,
  56179. minimumWidth, maximumNumColumns,
  56180. standardItemHeight,
  56181. false, 0);
  56182. }
  56183. int PopupMenu::showAt (Component* componentToAttachTo,
  56184. const int itemIdThatMustBeVisible,
  56185. const int minimumWidth,
  56186. const int maximumNumColumns,
  56187. const int standardItemHeight)
  56188. {
  56189. if (componentToAttachTo != 0)
  56190. {
  56191. return showMenu (componentToAttachTo->getScreenX(),
  56192. componentToAttachTo->getScreenY(),
  56193. componentToAttachTo->getWidth(),
  56194. componentToAttachTo->getHeight(),
  56195. itemIdThatMustBeVisible,
  56196. minimumWidth,
  56197. maximumNumColumns,
  56198. standardItemHeight,
  56199. true, componentToAttachTo);
  56200. }
  56201. else
  56202. {
  56203. return show (itemIdThatMustBeVisible,
  56204. minimumWidth,
  56205. maximumNumColumns,
  56206. standardItemHeight);
  56207. }
  56208. }
  56209. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  56210. {
  56211. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  56212. {
  56213. Window* const pmw = Window::getActiveWindows()[i];
  56214. if (pmw != 0)
  56215. pmw->dismissMenu (0);
  56216. }
  56217. }
  56218. int PopupMenu::getNumItems() const throw()
  56219. {
  56220. int num = 0;
  56221. for (int i = items.size(); --i >= 0;)
  56222. if (! (items.getUnchecked(i))->isSeparator)
  56223. ++num;
  56224. return num;
  56225. }
  56226. bool PopupMenu::containsCommandItem (const int commandID) const
  56227. {
  56228. for (int i = items.size(); --i >= 0;)
  56229. {
  56230. const Item* mi = items.getUnchecked (i);
  56231. if ((mi->itemId == commandID && mi->commandManager != 0)
  56232. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  56233. {
  56234. return true;
  56235. }
  56236. }
  56237. return false;
  56238. }
  56239. bool PopupMenu::containsAnyActiveItems() const throw()
  56240. {
  56241. for (int i = items.size(); --i >= 0;)
  56242. {
  56243. const Item* const mi = items.getUnchecked (i);
  56244. if (mi->subMenu != 0)
  56245. {
  56246. if (mi->subMenu->containsAnyActiveItems())
  56247. return true;
  56248. }
  56249. else if (mi->active)
  56250. {
  56251. return true;
  56252. }
  56253. }
  56254. return false;
  56255. }
  56256. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  56257. {
  56258. lookAndFeel = newLookAndFeel;
  56259. }
  56260. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  56261. : isHighlighted (false),
  56262. isTriggeredAutomatically (isTriggeredAutomatically_)
  56263. {
  56264. }
  56265. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  56266. {
  56267. }
  56268. void PopupMenuCustomComponent::triggerMenuItem()
  56269. {
  56270. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  56271. if (mic != 0)
  56272. {
  56273. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  56274. if (pmw != 0)
  56275. {
  56276. pmw->dismissMenu (&mic->itemInfo);
  56277. }
  56278. else
  56279. {
  56280. // something must have gone wrong with the component hierarchy if this happens..
  56281. jassertfalse
  56282. }
  56283. }
  56284. else
  56285. {
  56286. // why isn't this component inside a menu? Not much point triggering the item if
  56287. // there's no menu.
  56288. jassertfalse
  56289. }
  56290. }
  56291. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  56292. : subMenu (0),
  56293. itemId (0),
  56294. isSeparator (false),
  56295. isTicked (false),
  56296. isEnabled (false),
  56297. isCustomComponent (false),
  56298. isSectionHeader (false),
  56299. customColour (0),
  56300. customImage (0),
  56301. menu (menu_),
  56302. index (0)
  56303. {
  56304. }
  56305. PopupMenu::MenuItemIterator::~MenuItemIterator()
  56306. {
  56307. }
  56308. bool PopupMenu::MenuItemIterator::next()
  56309. {
  56310. if (index >= menu.items.size())
  56311. return false;
  56312. const Item* const item = menu.items.getUnchecked (index);
  56313. ++index;
  56314. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  56315. subMenu = item->subMenu;
  56316. itemId = item->itemId;
  56317. isSeparator = item->isSeparator;
  56318. isTicked = item->isTicked;
  56319. isEnabled = item->active;
  56320. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  56321. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  56322. customColour = item->usesColour ? &(item->textColour) : 0;
  56323. customImage = item->image;
  56324. commandManager = item->commandManager;
  56325. return true;
  56326. }
  56327. END_JUCE_NAMESPACE
  56328. /*** End of inlined file: juce_PopupMenu.cpp ***/
  56329. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  56330. BEGIN_JUCE_NAMESPACE
  56331. ComponentDragger::ComponentDragger()
  56332. : constrainer (0)
  56333. {
  56334. }
  56335. ComponentDragger::~ComponentDragger()
  56336. {
  56337. }
  56338. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  56339. ComponentBoundsConstrainer* const constrainer_)
  56340. {
  56341. jassert (componentToDrag->isValidComponent());
  56342. if (componentToDrag->isValidComponent())
  56343. {
  56344. constrainer = constrainer_;
  56345. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  56346. }
  56347. }
  56348. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  56349. {
  56350. jassert (componentToDrag->isValidComponent());
  56351. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  56352. if (componentToDrag->isValidComponent())
  56353. {
  56354. Point<int> pos (originalPos);
  56355. int w = componentToDrag->getWidth();
  56356. int h = componentToDrag->getHeight();
  56357. const Component* const parentComp = componentToDrag->getParentComponent();
  56358. if (parentComp != 0)
  56359. pos = parentComp->globalPositionToRelative (pos);
  56360. pos += Point<int> (e.getDistanceFromDragStartX(),
  56361. e.getDistanceFromDragStartY());
  56362. if (constrainer != 0)
  56363. constrainer->setBoundsForComponent (componentToDrag, Rectangle<int> (pos.getX(), pos.getY(), w, h),
  56364. false, false, false, false);
  56365. else
  56366. componentToDrag->setBounds (pos.getX(), pos.getY(), w, h);
  56367. }
  56368. }
  56369. END_JUCE_NAMESPACE
  56370. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  56371. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  56372. BEGIN_JUCE_NAMESPACE
  56373. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  56374. bool juce_performDragDropText (const String& text, bool& shouldStop);
  56375. class DragImageComponent : public Component,
  56376. public Timer
  56377. {
  56378. private:
  56379. ScopedPointer <Image> image;
  56380. Component* const source;
  56381. DragAndDropContainer* const owner;
  56382. ScopedPointer <ComponentDeletionWatcher> sourceWatcher, mouseDragSourceWatcher, currentlyOverWatcher;
  56383. Component* mouseDragSource;
  56384. DragAndDropTarget* currentlyOver;
  56385. String dragDesc;
  56386. const Point<int> imageOffset;
  56387. bool hasCheckedForExternalDrag, drawImage;
  56388. DragImageComponent (const DragImageComponent&);
  56389. const DragImageComponent& operator= (const DragImageComponent&);
  56390. public:
  56391. DragImageComponent (Image* const im,
  56392. const String& desc,
  56393. Component* const s,
  56394. DragAndDropContainer* const o,
  56395. const Point<int>& imageOffset_)
  56396. : image (im),
  56397. source (s),
  56398. owner (o),
  56399. currentlyOver (0),
  56400. dragDesc (desc),
  56401. imageOffset (imageOffset_),
  56402. hasCheckedForExternalDrag (false),
  56403. drawImage (true)
  56404. {
  56405. setSize (im->getWidth(), im->getHeight());
  56406. sourceWatcher = new ComponentDeletionWatcher (source);
  56407. mouseDragSource = Component::getComponentUnderMouse();
  56408. if (mouseDragSource == 0)
  56409. mouseDragSource = source;
  56410. mouseDragSourceWatcher = new ComponentDeletionWatcher (mouseDragSource);
  56411. mouseDragSource->addMouseListener (this, false);
  56412. startTimer (200);
  56413. setInterceptsMouseClicks (false, false);
  56414. setAlwaysOnTop (true);
  56415. }
  56416. ~DragImageComponent()
  56417. {
  56418. if ((DragImageComponent*) owner->dragImageComponent == this)
  56419. owner->dragImageComponent.release();
  56420. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56421. {
  56422. mouseDragSource->removeMouseListener (this);
  56423. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56424. if (currentlyOver->isInterestedInDragSource (dragDesc, source))
  56425. currentlyOver->itemDragExit (dragDesc, source);
  56426. }
  56427. }
  56428. void paint (Graphics& g)
  56429. {
  56430. if (isOpaque())
  56431. g.fillAll (Colours::white);
  56432. if (drawImage)
  56433. {
  56434. g.setOpacity (1.0f);
  56435. g.drawImageAt (image, 0, 0);
  56436. }
  56437. }
  56438. DragAndDropTarget* findTarget (const Point<int>& screenPos,
  56439. Point<int>& relativePos) const
  56440. {
  56441. Component* hit = getParentComponent();
  56442. if (hit == 0)
  56443. {
  56444. hit = Desktop::getInstance().findComponentAt (screenPos);
  56445. }
  56446. else
  56447. {
  56448. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  56449. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  56450. }
  56451. // (note: use a local copy of the dragDesc member in case the callback runs
  56452. // a modal loop and deletes this object before the method completes)
  56453. const String dragDescLocal (dragDesc);
  56454. while (hit != 0)
  56455. {
  56456. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  56457. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  56458. {
  56459. relativePos = hit->globalPositionToRelative (screenPos);
  56460. return ddt;
  56461. }
  56462. hit = hit->getParentComponent();
  56463. }
  56464. return 0;
  56465. }
  56466. void mouseUp (const MouseEvent& e)
  56467. {
  56468. if (e.originalComponent != this)
  56469. {
  56470. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56471. mouseDragSource->removeMouseListener (this);
  56472. bool dropAccepted = false;
  56473. DragAndDropTarget* ddt = 0;
  56474. Point<int> relPos;
  56475. if (isVisible())
  56476. {
  56477. setVisible (false);
  56478. ddt = findTarget (e.getScreenPosition(), relPos);
  56479. // fade this component and remove it - it'll be deleted later by the timer callback
  56480. dropAccepted = ddt != 0;
  56481. setVisible (true);
  56482. if (dropAccepted || sourceWatcher->hasBeenDeleted())
  56483. {
  56484. fadeOutComponent (120);
  56485. }
  56486. else
  56487. {
  56488. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  56489. source->getHeight() / 2)));
  56490. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  56491. getHeight() / 2)));
  56492. fadeOutComponent (120,
  56493. target.getX() - ourCentre.getX(),
  56494. target.getY() - ourCentre.getY());
  56495. }
  56496. }
  56497. if (getParentComponent() != 0)
  56498. getParentComponent()->removeChildComponent (this);
  56499. if (dropAccepted && ddt != 0)
  56500. {
  56501. // (note: use a local copy of the dragDesc member in case the callback runs
  56502. // a modal loop and deletes this object before the method completes)
  56503. const String dragDescLocal (dragDesc);
  56504. currentlyOverWatcher = 0;
  56505. currentlyOver = 0;
  56506. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  56507. }
  56508. // careful - this object could now be deleted..
  56509. }
  56510. }
  56511. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  56512. {
  56513. // (note: use a local copy of the dragDesc member in case the callback runs
  56514. // a modal loop and deletes this object before it returns)
  56515. const String dragDescLocal (dragDesc);
  56516. Point<int> newPos (screenPos + imageOffset);
  56517. if (getParentComponent() != 0)
  56518. newPos = getParentComponent()->globalPositionToRelative (newPos);
  56519. //if (newX != getX() || newY != getY())
  56520. {
  56521. setTopLeftPosition (newPos.getX(), newPos.getY());
  56522. Point<int> relPos;
  56523. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  56524. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  56525. if (ddt != currentlyOver)
  56526. {
  56527. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56528. {
  56529. Component* const over = dynamic_cast <Component*> (currentlyOver);
  56530. if (over != 0
  56531. && over->isValidComponent()
  56532. && ! (sourceWatcher->hasBeenDeleted())
  56533. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56534. {
  56535. currentlyOver->itemDragExit (dragDescLocal, source);
  56536. }
  56537. }
  56538. currentlyOver = ddt;
  56539. currentlyOverWatcher = 0;
  56540. if (ddt != 0)
  56541. {
  56542. currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast <Component*> (ddt));
  56543. if (currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56544. currentlyOver->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  56545. }
  56546. }
  56547. else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted())
  56548. {
  56549. currentlyOver = 0;
  56550. currentlyOverWatcher = 0;
  56551. }
  56552. if (currentlyOver != 0
  56553. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56554. currentlyOver->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  56555. if (currentlyOver == 0
  56556. && canDoExternalDrag
  56557. && ! hasCheckedForExternalDrag)
  56558. {
  56559. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  56560. {
  56561. hasCheckedForExternalDrag = true;
  56562. StringArray files;
  56563. bool canMoveFiles = false;
  56564. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  56565. && files.size() > 0)
  56566. {
  56567. ComponentDeletionWatcher cdw (this);
  56568. setVisible (false);
  56569. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  56570. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56571. if (! cdw.hasBeenDeleted())
  56572. delete this;
  56573. return;
  56574. }
  56575. }
  56576. }
  56577. }
  56578. }
  56579. void mouseDrag (const MouseEvent& e)
  56580. {
  56581. if (e.originalComponent != this)
  56582. updateLocation (true, e.getScreenPosition());
  56583. }
  56584. void timerCallback()
  56585. {
  56586. if (sourceWatcher->hasBeenDeleted())
  56587. {
  56588. delete this;
  56589. }
  56590. else if (! isMouseButtonDownAnywhere())
  56591. {
  56592. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56593. mouseDragSource->removeMouseListener (this);
  56594. delete this;
  56595. }
  56596. }
  56597. };
  56598. DragAndDropContainer::DragAndDropContainer()
  56599. {
  56600. }
  56601. DragAndDropContainer::~DragAndDropContainer()
  56602. {
  56603. dragImageComponent = 0;
  56604. }
  56605. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56606. Component* sourceComponent,
  56607. Image* dragImage_,
  56608. const bool allowDraggingToExternalWindows,
  56609. const Point<int>* imageOffsetFromMouse)
  56610. {
  56611. ScopedPointer <Image> dragImage (dragImage_);
  56612. if (dragImageComponent == 0)
  56613. {
  56614. Component* const thisComp = dynamic_cast <Component*> (this);
  56615. if (thisComp != 0)
  56616. {
  56617. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  56618. Point<int> imageOffset;
  56619. if (dragImage == 0)
  56620. {
  56621. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56622. if (dragImage->getFormat() != Image::ARGB)
  56623. {
  56624. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56625. Graphics g2 (*newIm);
  56626. g2.drawImageAt (dragImage, 0, 0);
  56627. dragImage = newIm;
  56628. }
  56629. dragImage->multiplyAllAlphas (0.6f);
  56630. const int lo = 150;
  56631. const int hi = 400;
  56632. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  56633. Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
  56634. .getConstrainedPoint (relPos));
  56635. for (int y = dragImage->getHeight(); --y >= 0;)
  56636. {
  56637. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  56638. for (int x = dragImage->getWidth(); --x >= 0;)
  56639. {
  56640. const int dx = x - clipped.getX();
  56641. const int distance = roundToInt (sqrt (dx * dx + dy));
  56642. if (distance > lo)
  56643. {
  56644. const float alpha = (distance > hi) ? 0
  56645. : (hi - distance) / (float) (hi - lo)
  56646. + Random::getSystemRandom().nextFloat() * 0.008f;
  56647. dragImage->multiplyAlphaAt (x, y, alpha);
  56648. }
  56649. }
  56650. }
  56651. imageOffset = Point<int>() - clipped;
  56652. }
  56653. else
  56654. {
  56655. if (imageOffsetFromMouse == 0)
  56656. imageOffset = Point<int> (dragImage->getWidth() / -2,
  56657. dragImage->getHeight() / -2);
  56658. else
  56659. imageOffset = *imageOffsetFromMouse;
  56660. }
  56661. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56662. this, imageOffset);
  56663. currentDragDesc = sourceDescription;
  56664. if (allowDraggingToExternalWindows)
  56665. {
  56666. if (! Desktop::canUseSemiTransparentWindows())
  56667. dragImageComponent->setOpaque (true);
  56668. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56669. | ComponentPeer::windowIsTemporary
  56670. | ComponentPeer::windowIgnoresKeyPresses);
  56671. }
  56672. else
  56673. thisComp->addChildComponent (dragImageComponent);
  56674. ((DragImageComponent*) dragImageComponent)->updateLocation (false, lastMouseDown);
  56675. dragImageComponent->setVisible (true);
  56676. }
  56677. else
  56678. {
  56679. // this class must only be implemented by an object that
  56680. // is also a Component.
  56681. jassertfalse
  56682. }
  56683. }
  56684. }
  56685. bool DragAndDropContainer::isDragAndDropActive() const
  56686. {
  56687. return dragImageComponent != 0;
  56688. }
  56689. const String DragAndDropContainer::getCurrentDragDescription() const
  56690. {
  56691. return (dragImageComponent != 0) ? currentDragDesc
  56692. : String::empty;
  56693. }
  56694. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56695. {
  56696. if (c == 0)
  56697. return 0;
  56698. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56699. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56700. }
  56701. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56702. {
  56703. return false;
  56704. }
  56705. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56706. {
  56707. }
  56708. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56709. {
  56710. }
  56711. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56712. {
  56713. }
  56714. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56715. {
  56716. return true;
  56717. }
  56718. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56719. {
  56720. }
  56721. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56722. {
  56723. }
  56724. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56725. {
  56726. }
  56727. END_JUCE_NAMESPACE
  56728. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56729. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56730. BEGIN_JUCE_NAMESPACE
  56731. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56732. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56733. // isStandard set depending on which interface was used to create the cursor
  56734. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56735. static CriticalSection activeCursorListLock;
  56736. static VoidArray activeCursors;
  56737. class SharedMouseCursorInternal : public ReferenceCountedObject
  56738. {
  56739. public:
  56740. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56741. : standardType (type),
  56742. isStandard (true)
  56743. {
  56744. handle = juce_createStandardMouseCursor (standardType);
  56745. activeCursors.add (this);
  56746. }
  56747. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56748. : standardType (MouseCursor::NormalCursor),
  56749. isStandard (false)
  56750. {
  56751. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56752. }
  56753. ~SharedMouseCursorInternal() throw()
  56754. {
  56755. juce_deleteMouseCursor (handle, isStandard);
  56756. activeCursors.removeValue (this);
  56757. }
  56758. void* getHandle() const throw()
  56759. {
  56760. return handle;
  56761. }
  56762. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56763. {
  56764. for (int i = activeCursors.size(); --i >= 0;)
  56765. {
  56766. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56767. if (r->standardType == type)
  56768. return r;
  56769. }
  56770. return new SharedMouseCursorInternal (type);
  56771. }
  56772. juce_UseDebuggingNewOperator
  56773. private:
  56774. void* handle;
  56775. const MouseCursor::StandardCursorType standardType;
  56776. const bool isStandard;
  56777. const SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56778. };
  56779. MouseCursor::MouseCursor() throw()
  56780. {
  56781. const ScopedLock sl (activeCursorListLock);
  56782. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56783. }
  56784. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56785. {
  56786. const ScopedLock sl (activeCursorListLock);
  56787. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56788. }
  56789. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56790. {
  56791. const ScopedLock sl (activeCursorListLock);
  56792. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56793. }
  56794. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56795. : cursorHandle (other.cursorHandle)
  56796. {
  56797. }
  56798. MouseCursor::~MouseCursor() throw()
  56799. {
  56800. }
  56801. const MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56802. {
  56803. cursorHandle = other.cursorHandle;
  56804. return *this;
  56805. }
  56806. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56807. {
  56808. return cursorHandle == other.cursorHandle;
  56809. }
  56810. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56811. {
  56812. return cursorHandle != other.cursorHandle;
  56813. }
  56814. void* MouseCursor::getHandle() const throw()
  56815. {
  56816. return cursorHandle->getHandle();
  56817. }
  56818. void MouseCursor::showWaitCursor() throw()
  56819. {
  56820. const MouseCursor mc (MouseCursor::WaitCursor);
  56821. mc.showInAllWindows();
  56822. }
  56823. void MouseCursor::hideWaitCursor() throw()
  56824. {
  56825. Component* const c = Component::getComponentUnderMouse();
  56826. MouseCursor mc (c->isValidComponent() ? c->getLookAndFeel().getMouseCursorFor (*c)
  56827. : MouseCursor::NormalCursor);
  56828. mc.showInAllWindows();
  56829. }
  56830. END_JUCE_NAMESPACE
  56831. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56832. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56833. BEGIN_JUCE_NAMESPACE
  56834. MouseEvent::MouseEvent (const Point<int>& position,
  56835. const ModifierKeys& mods_,
  56836. Component* const originator,
  56837. const Time& eventTime_,
  56838. const Point<int> mouseDownPos_,
  56839. const Time& mouseDownTime_,
  56840. const int numberOfClicks_,
  56841. const bool mouseWasDragged) throw()
  56842. : x (position.getX()),
  56843. y (position.getY()),
  56844. mods (mods_),
  56845. eventComponent (originator),
  56846. originalComponent (originator),
  56847. eventTime (eventTime_),
  56848. mouseDownPos (mouseDownPos_),
  56849. mouseDownTime (mouseDownTime_),
  56850. numberOfClicks (numberOfClicks_),
  56851. wasMovedSinceMouseDown (mouseWasDragged)
  56852. {
  56853. }
  56854. MouseEvent::~MouseEvent() throw()
  56855. {
  56856. }
  56857. bool MouseEvent::mouseWasClicked() const throw()
  56858. {
  56859. return ! wasMovedSinceMouseDown;
  56860. }
  56861. int MouseEvent::getMouseDownX() const throw()
  56862. {
  56863. return mouseDownPos.getX();
  56864. }
  56865. int MouseEvent::getMouseDownY() const throw()
  56866. {
  56867. return mouseDownPos.getY();
  56868. }
  56869. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56870. {
  56871. return mouseDownPos;
  56872. }
  56873. int MouseEvent::getDistanceFromDragStartX() const throw()
  56874. {
  56875. return x - mouseDownPos.getX();
  56876. }
  56877. int MouseEvent::getDistanceFromDragStartY() const throw()
  56878. {
  56879. return y - mouseDownPos.getY();
  56880. }
  56881. int MouseEvent::getDistanceFromDragStart() const throw()
  56882. {
  56883. return roundToInt (juce_hypot (getDistanceFromDragStartX(),
  56884. getDistanceFromDragStartY()));
  56885. }
  56886. int MouseEvent::getLengthOfMousePress() const throw()
  56887. {
  56888. if (mouseDownTime.toMilliseconds() > 0)
  56889. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56890. return 0;
  56891. }
  56892. const Point<int> MouseEvent::getPosition() const throw()
  56893. {
  56894. return Point<int> (x, y);
  56895. }
  56896. int MouseEvent::getScreenX() const
  56897. {
  56898. return getScreenPosition().getX();
  56899. }
  56900. int MouseEvent::getScreenY() const
  56901. {
  56902. return getScreenPosition().getY();
  56903. }
  56904. const Point<int> MouseEvent::getScreenPosition() const
  56905. {
  56906. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56907. }
  56908. int MouseEvent::getMouseDownScreenX() const
  56909. {
  56910. return getMouseDownScreenPosition().getX();
  56911. }
  56912. int MouseEvent::getMouseDownScreenY() const
  56913. {
  56914. return getMouseDownScreenPosition().getY();
  56915. }
  56916. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56917. {
  56918. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56919. }
  56920. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56921. {
  56922. if (otherComponent == 0)
  56923. {
  56924. jassertfalse
  56925. return *this;
  56926. }
  56927. return MouseEvent (eventComponent->relativePositionToOtherComponent (otherComponent, Point<int> (x, y)),
  56928. mods,
  56929. originalComponent,
  56930. eventTime,
  56931. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56932. mouseDownTime,
  56933. numberOfClicks,
  56934. wasMovedSinceMouseDown);
  56935. }
  56936. static int doubleClickTimeOutMs = 400;
  56937. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56938. {
  56939. doubleClickTimeOutMs = newTime;
  56940. }
  56941. int MouseEvent::getDoubleClickTimeout() throw()
  56942. {
  56943. return doubleClickTimeOutMs;
  56944. }
  56945. END_JUCE_NAMESPACE
  56946. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56947. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56948. BEGIN_JUCE_NAMESPACE
  56949. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56950. : source (0),
  56951. hoverTimeMillisecs (hoverTimeMillisecs_),
  56952. hasJustHovered (false)
  56953. {
  56954. internalTimer.owner = this;
  56955. }
  56956. MouseHoverDetector::~MouseHoverDetector()
  56957. {
  56958. setHoverComponent (0);
  56959. }
  56960. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56961. {
  56962. hoverTimeMillisecs = newTimeInMillisecs;
  56963. }
  56964. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56965. {
  56966. if (source != newSourceComponent)
  56967. {
  56968. internalTimer.stopTimer();
  56969. hasJustHovered = false;
  56970. if (source != 0)
  56971. {
  56972. // ! you need to delete the hover detector before deleting its component
  56973. jassert (source->isValidComponent());
  56974. source->removeMouseListener (&internalTimer);
  56975. }
  56976. source = newSourceComponent;
  56977. if (newSourceComponent != 0)
  56978. newSourceComponent->addMouseListener (&internalTimer, false);
  56979. }
  56980. }
  56981. void MouseHoverDetector::hoverTimerCallback()
  56982. {
  56983. internalTimer.stopTimer();
  56984. if (source != 0)
  56985. {
  56986. const Point<int> pos (source->getMouseXYRelative());
  56987. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56988. {
  56989. hasJustHovered = true;
  56990. mouseHovered (pos.getX(), pos.getY());
  56991. }
  56992. }
  56993. }
  56994. void MouseHoverDetector::checkJustHoveredCallback()
  56995. {
  56996. if (hasJustHovered)
  56997. {
  56998. hasJustHovered = false;
  56999. mouseMovedAfterHover();
  57000. }
  57001. }
  57002. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  57003. {
  57004. owner->hoverTimerCallback();
  57005. }
  57006. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  57007. {
  57008. stopTimer();
  57009. owner->checkJustHoveredCallback();
  57010. }
  57011. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  57012. {
  57013. stopTimer();
  57014. owner->checkJustHoveredCallback();
  57015. }
  57016. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  57017. {
  57018. stopTimer();
  57019. owner->checkJustHoveredCallback();
  57020. }
  57021. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  57022. {
  57023. stopTimer();
  57024. owner->checkJustHoveredCallback();
  57025. }
  57026. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  57027. {
  57028. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  57029. {
  57030. lastX = e.x;
  57031. lastY = e.y;
  57032. if (owner->source != 0)
  57033. startTimer (owner->hoverTimeMillisecs);
  57034. owner->checkJustHoveredCallback();
  57035. }
  57036. }
  57037. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  57038. {
  57039. stopTimer();
  57040. owner->checkJustHoveredCallback();
  57041. }
  57042. END_JUCE_NAMESPACE
  57043. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  57044. /*** Start of inlined file: juce_MouseListener.cpp ***/
  57045. BEGIN_JUCE_NAMESPACE
  57046. void MouseListener::mouseEnter (const MouseEvent&)
  57047. {
  57048. }
  57049. void MouseListener::mouseExit (const MouseEvent&)
  57050. {
  57051. }
  57052. void MouseListener::mouseDown (const MouseEvent&)
  57053. {
  57054. }
  57055. void MouseListener::mouseUp (const MouseEvent&)
  57056. {
  57057. }
  57058. void MouseListener::mouseDrag (const MouseEvent&)
  57059. {
  57060. }
  57061. void MouseListener::mouseMove (const MouseEvent&)
  57062. {
  57063. }
  57064. void MouseListener::mouseDoubleClick (const MouseEvent&)
  57065. {
  57066. }
  57067. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  57068. {
  57069. }
  57070. END_JUCE_NAMESPACE
  57071. /*** End of inlined file: juce_MouseListener.cpp ***/
  57072. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57073. BEGIN_JUCE_NAMESPACE
  57074. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  57075. const String& buttonTextWhenTrue,
  57076. const String& buttonTextWhenFalse)
  57077. : PropertyComponent (name),
  57078. onText (buttonTextWhenTrue),
  57079. offText (buttonTextWhenFalse)
  57080. {
  57081. createButton();
  57082. button->addButtonListener (this);
  57083. }
  57084. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  57085. const String& name,
  57086. const String& buttonText)
  57087. : PropertyComponent (name),
  57088. onText (buttonText),
  57089. offText (buttonText)
  57090. {
  57091. createButton();
  57092. button->setButtonText (buttonText);
  57093. button->getToggleStateValue().referTo (valueToControl);
  57094. button->setClickingTogglesState (true);
  57095. }
  57096. BooleanPropertyComponent::~BooleanPropertyComponent()
  57097. {
  57098. deleteAllChildren();
  57099. }
  57100. void BooleanPropertyComponent::createButton()
  57101. {
  57102. addAndMakeVisible (button = new ToggleButton (String::empty));
  57103. button->setClickingTogglesState (false);
  57104. }
  57105. void BooleanPropertyComponent::setState (const bool newState)
  57106. {
  57107. button->setToggleState (newState, true);
  57108. }
  57109. bool BooleanPropertyComponent::getState() const
  57110. {
  57111. return button->getToggleState();
  57112. }
  57113. void BooleanPropertyComponent::paint (Graphics& g)
  57114. {
  57115. PropertyComponent::paint (g);
  57116. const Rectangle<int> r (button->getBounds());
  57117. g.setColour (Colours::white);
  57118. g.fillRect (r);
  57119. g.setColour (findColour (ComboBox::outlineColourId));
  57120. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  57121. }
  57122. void BooleanPropertyComponent::refresh()
  57123. {
  57124. button->setToggleState (getState(), false);
  57125. button->setButtonText (button->getToggleState() ? onText : offText);
  57126. }
  57127. void BooleanPropertyComponent::buttonClicked (Button*)
  57128. {
  57129. setState (! getState());
  57130. }
  57131. END_JUCE_NAMESPACE
  57132. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57133. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57134. BEGIN_JUCE_NAMESPACE
  57135. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  57136. const bool triggerOnMouseDown)
  57137. : PropertyComponent (name)
  57138. {
  57139. addAndMakeVisible (button = new TextButton (String::empty));
  57140. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  57141. button->addButtonListener (this);
  57142. }
  57143. ButtonPropertyComponent::~ButtonPropertyComponent()
  57144. {
  57145. deleteAllChildren();
  57146. }
  57147. void ButtonPropertyComponent::refresh()
  57148. {
  57149. button->setButtonText (getButtonText());
  57150. }
  57151. void ButtonPropertyComponent::buttonClicked (Button*)
  57152. {
  57153. buttonClicked();
  57154. }
  57155. END_JUCE_NAMESPACE
  57156. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57157. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57158. BEGIN_JUCE_NAMESPACE
  57159. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57160. : PropertyComponent (name),
  57161. comboBox (0)
  57162. {
  57163. }
  57164. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57165. const String& name,
  57166. const StringArray& choices_,
  57167. const Array <int>* choiceIDs)
  57168. : PropertyComponent (name),
  57169. choices (choices_),
  57170. comboBox (0)
  57171. {
  57172. createComboBox (choiceIDs);
  57173. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57174. }
  57175. ChoicePropertyComponent::~ChoicePropertyComponent()
  57176. {
  57177. deleteAllChildren();
  57178. }
  57179. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  57180. {
  57181. // The array of IDs must contain the same number of values as the choices list!
  57182. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  57183. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57184. for (int i = 0; i < choices.size(); ++i)
  57185. {
  57186. if (choices[i].isNotEmpty())
  57187. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  57188. : ((*choiceIDs)[i]));
  57189. else
  57190. comboBox->addSeparator();
  57191. }
  57192. comboBox->setEditableText (false);
  57193. }
  57194. void ChoicePropertyComponent::setIndex (const int newIndex)
  57195. {
  57196. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57197. }
  57198. int ChoicePropertyComponent::getIndex() const
  57199. {
  57200. return comboBox->getSelectedItemIndex();
  57201. }
  57202. const StringArray& ChoicePropertyComponent::getChoices() const
  57203. {
  57204. return choices;
  57205. }
  57206. void ChoicePropertyComponent::refresh()
  57207. {
  57208. if (comboBox == 0)
  57209. {
  57210. createComboBox (0);
  57211. comboBox->addListener (this);
  57212. }
  57213. comboBox->setSelectedId (getIndex() + 1, true);
  57214. }
  57215. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57216. {
  57217. const int newIndex = comboBox->getSelectedId() - 1;
  57218. if (newIndex != getIndex())
  57219. setIndex (newIndex);
  57220. }
  57221. END_JUCE_NAMESPACE
  57222. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57223. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  57224. BEGIN_JUCE_NAMESPACE
  57225. PropertyComponent::PropertyComponent (const String& name,
  57226. const int preferredHeight_)
  57227. : Component (name),
  57228. preferredHeight (preferredHeight_)
  57229. {
  57230. jassert (name.isNotEmpty());
  57231. }
  57232. PropertyComponent::~PropertyComponent()
  57233. {
  57234. }
  57235. void PropertyComponent::paint (Graphics& g)
  57236. {
  57237. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57238. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57239. }
  57240. void PropertyComponent::resized()
  57241. {
  57242. if (getNumChildComponents() > 0)
  57243. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57244. }
  57245. void PropertyComponent::enablementChanged()
  57246. {
  57247. repaint();
  57248. }
  57249. END_JUCE_NAMESPACE
  57250. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  57251. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  57252. BEGIN_JUCE_NAMESPACE
  57253. class PropertyHolderComponent : public Component
  57254. {
  57255. public:
  57256. PropertyHolderComponent()
  57257. {
  57258. }
  57259. ~PropertyHolderComponent()
  57260. {
  57261. deleteAllChildren();
  57262. }
  57263. void paint (Graphics&)
  57264. {
  57265. }
  57266. void updateLayout (const int width);
  57267. void refreshAll() const;
  57268. };
  57269. class PropertySectionComponent : public Component
  57270. {
  57271. public:
  57272. PropertySectionComponent (const String& sectionTitle,
  57273. const Array <PropertyComponent*>& newProperties,
  57274. const bool open)
  57275. : Component (sectionTitle),
  57276. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57277. isOpen_ (open)
  57278. {
  57279. for (int i = newProperties.size(); --i >= 0;)
  57280. {
  57281. addAndMakeVisible (newProperties.getUnchecked(i));
  57282. newProperties.getUnchecked(i)->refresh();
  57283. }
  57284. }
  57285. ~PropertySectionComponent()
  57286. {
  57287. deleteAllChildren();
  57288. }
  57289. void paint (Graphics& g)
  57290. {
  57291. if (titleHeight > 0)
  57292. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57293. }
  57294. void resized()
  57295. {
  57296. int y = titleHeight;
  57297. for (int i = getNumChildComponents(); --i >= 0;)
  57298. {
  57299. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57300. if (pec != 0)
  57301. {
  57302. const int prefH = pec->getPreferredHeight();
  57303. pec->setBounds (1, y, getWidth() - 2, prefH);
  57304. y += prefH;
  57305. }
  57306. }
  57307. }
  57308. int getPreferredHeight() const
  57309. {
  57310. int y = titleHeight;
  57311. if (isOpen())
  57312. {
  57313. for (int i = 0; i < getNumChildComponents(); ++i)
  57314. {
  57315. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57316. if (pec != 0)
  57317. y += pec->getPreferredHeight();
  57318. }
  57319. }
  57320. return y;
  57321. }
  57322. void setOpen (const bool open)
  57323. {
  57324. if (isOpen_ != open)
  57325. {
  57326. isOpen_ = open;
  57327. for (int i = 0; i < getNumChildComponents(); ++i)
  57328. {
  57329. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57330. if (pec != 0)
  57331. pec->setVisible (open);
  57332. }
  57333. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57334. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57335. if (pp != 0)
  57336. pp->resized();
  57337. }
  57338. }
  57339. bool isOpen() const
  57340. {
  57341. return isOpen_;
  57342. }
  57343. void refreshAll() const
  57344. {
  57345. for (int i = 0; i < getNumChildComponents(); ++i)
  57346. {
  57347. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57348. if (pec != 0)
  57349. pec->refresh();
  57350. }
  57351. }
  57352. void mouseDown (const MouseEvent&)
  57353. {
  57354. }
  57355. void mouseUp (const MouseEvent& e)
  57356. {
  57357. if (e.getMouseDownX() < titleHeight
  57358. && e.x < titleHeight
  57359. && e.y < titleHeight
  57360. && e.getNumberOfClicks() != 2)
  57361. {
  57362. setOpen (! isOpen());
  57363. }
  57364. }
  57365. void mouseDoubleClick (const MouseEvent& e)
  57366. {
  57367. if (e.y < titleHeight)
  57368. setOpen (! isOpen());
  57369. }
  57370. private:
  57371. int titleHeight;
  57372. bool isOpen_;
  57373. };
  57374. void PropertyHolderComponent::updateLayout (const int width)
  57375. {
  57376. int y = 0;
  57377. for (int i = getNumChildComponents(); --i >= 0;)
  57378. {
  57379. PropertySectionComponent* const section
  57380. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57381. if (section != 0)
  57382. {
  57383. const int prefH = section->getPreferredHeight();
  57384. section->setBounds (0, y, width, prefH);
  57385. y += prefH;
  57386. }
  57387. }
  57388. setSize (width, y);
  57389. repaint();
  57390. }
  57391. void PropertyHolderComponent::refreshAll() const
  57392. {
  57393. for (int i = getNumChildComponents(); --i >= 0;)
  57394. {
  57395. PropertySectionComponent* const section
  57396. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57397. if (section != 0)
  57398. section->refreshAll();
  57399. }
  57400. }
  57401. PropertyPanel::PropertyPanel()
  57402. {
  57403. messageWhenEmpty = TRANS("(nothing selected)");
  57404. addAndMakeVisible (viewport = new Viewport());
  57405. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57406. viewport->setFocusContainer (true);
  57407. }
  57408. PropertyPanel::~PropertyPanel()
  57409. {
  57410. clear();
  57411. deleteAllChildren();
  57412. }
  57413. void PropertyPanel::paint (Graphics& g)
  57414. {
  57415. if (propertyHolderComponent->getNumChildComponents() == 0)
  57416. {
  57417. g.setColour (Colours::black.withAlpha (0.5f));
  57418. g.setFont (14.0f);
  57419. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57420. Justification::centred, true);
  57421. }
  57422. }
  57423. void PropertyPanel::resized()
  57424. {
  57425. viewport->setBounds (0, 0, getWidth(), getHeight());
  57426. updatePropHolderLayout();
  57427. }
  57428. void PropertyPanel::clear()
  57429. {
  57430. if (propertyHolderComponent->getNumChildComponents() > 0)
  57431. {
  57432. propertyHolderComponent->deleteAllChildren();
  57433. repaint();
  57434. }
  57435. }
  57436. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57437. {
  57438. if (propertyHolderComponent->getNumChildComponents() == 0)
  57439. repaint();
  57440. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57441. newProperties,
  57442. true), 0);
  57443. updatePropHolderLayout();
  57444. }
  57445. void PropertyPanel::addSection (const String& sectionTitle,
  57446. const Array <PropertyComponent*>& newProperties,
  57447. const bool shouldBeOpen)
  57448. {
  57449. jassert (sectionTitle.isNotEmpty());
  57450. if (propertyHolderComponent->getNumChildComponents() == 0)
  57451. repaint();
  57452. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57453. newProperties,
  57454. shouldBeOpen), 0);
  57455. updatePropHolderLayout();
  57456. }
  57457. void PropertyPanel::updatePropHolderLayout() const
  57458. {
  57459. const int maxWidth = viewport->getMaximumVisibleWidth();
  57460. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57461. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57462. if (maxWidth != newMaxWidth)
  57463. {
  57464. // need to do this twice because of scrollbars changing the size, etc.
  57465. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57466. }
  57467. }
  57468. void PropertyPanel::refreshAll() const
  57469. {
  57470. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57471. }
  57472. const StringArray PropertyPanel::getSectionNames() const
  57473. {
  57474. StringArray s;
  57475. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57476. {
  57477. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57478. if (section != 0 && section->getName().isNotEmpty())
  57479. s.add (section->getName());
  57480. }
  57481. return s;
  57482. }
  57483. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57484. {
  57485. int index = 0;
  57486. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57487. {
  57488. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57489. if (section != 0 && section->getName().isNotEmpty())
  57490. {
  57491. if (index == sectionIndex)
  57492. return section->isOpen();
  57493. ++index;
  57494. }
  57495. }
  57496. return false;
  57497. }
  57498. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57499. {
  57500. int index = 0;
  57501. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57502. {
  57503. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57504. if (section != 0 && section->getName().isNotEmpty())
  57505. {
  57506. if (index == sectionIndex)
  57507. {
  57508. section->setOpen (shouldBeOpen);
  57509. break;
  57510. }
  57511. ++index;
  57512. }
  57513. }
  57514. }
  57515. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57516. {
  57517. int index = 0;
  57518. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57519. {
  57520. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57521. if (section != 0 && section->getName().isNotEmpty())
  57522. {
  57523. if (index == sectionIndex)
  57524. {
  57525. section->setEnabled (shouldBeEnabled);
  57526. break;
  57527. }
  57528. ++index;
  57529. }
  57530. }
  57531. }
  57532. XmlElement* PropertyPanel::getOpennessState() const
  57533. {
  57534. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57535. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57536. const StringArray sections (getSectionNames());
  57537. for (int i = 0; i < sections.size(); ++i)
  57538. {
  57539. if (sections[i].isNotEmpty())
  57540. {
  57541. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57542. e->setAttribute ("name", sections[i]);
  57543. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57544. }
  57545. }
  57546. return xml;
  57547. }
  57548. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57549. {
  57550. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57551. {
  57552. const StringArray sections (getSectionNames());
  57553. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57554. {
  57555. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57556. e->getBoolAttribute (T("open")));
  57557. }
  57558. viewport->setViewPosition (viewport->getViewPositionX(),
  57559. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57560. }
  57561. }
  57562. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57563. {
  57564. if (messageWhenEmpty != newMessage)
  57565. {
  57566. messageWhenEmpty = newMessage;
  57567. repaint();
  57568. }
  57569. }
  57570. const String& PropertyPanel::getMessageWhenEmpty() const
  57571. {
  57572. return messageWhenEmpty;
  57573. }
  57574. END_JUCE_NAMESPACE
  57575. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57576. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57577. BEGIN_JUCE_NAMESPACE
  57578. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57579. const double rangeMin,
  57580. const double rangeMax,
  57581. const double interval,
  57582. const double skewFactor)
  57583. : PropertyComponent (name)
  57584. {
  57585. addAndMakeVisible (slider = new Slider (name));
  57586. slider->setRange (rangeMin, rangeMax, interval);
  57587. slider->setSkewFactor (skewFactor);
  57588. slider->setSliderStyle (Slider::LinearBar);
  57589. slider->addListener (this);
  57590. }
  57591. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57592. const String& name,
  57593. const double rangeMin,
  57594. const double rangeMax,
  57595. const double interval,
  57596. const double skewFactor)
  57597. : PropertyComponent (name)
  57598. {
  57599. addAndMakeVisible (slider = new Slider (name));
  57600. slider->setRange (rangeMin, rangeMax, interval);
  57601. slider->setSkewFactor (skewFactor);
  57602. slider->setSliderStyle (Slider::LinearBar);
  57603. slider->getValueObject().referTo (valueToControl);
  57604. }
  57605. SliderPropertyComponent::~SliderPropertyComponent()
  57606. {
  57607. deleteAllChildren();
  57608. }
  57609. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57610. {
  57611. }
  57612. const double SliderPropertyComponent::getValue() const
  57613. {
  57614. return slider->getValue();
  57615. }
  57616. void SliderPropertyComponent::refresh()
  57617. {
  57618. slider->setValue (getValue(), false);
  57619. }
  57620. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57621. {
  57622. if (getValue() != slider->getValue())
  57623. setValue (slider->getValue());
  57624. }
  57625. END_JUCE_NAMESPACE
  57626. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57627. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57628. BEGIN_JUCE_NAMESPACE
  57629. class TextPropLabel : public Label
  57630. {
  57631. TextPropertyComponent& owner;
  57632. int maxChars;
  57633. bool isMultiline;
  57634. public:
  57635. TextPropLabel (TextPropertyComponent& owner_,
  57636. const int maxChars_, const bool isMultiline_)
  57637. : Label (String::empty, String::empty),
  57638. owner (owner_),
  57639. maxChars (maxChars_),
  57640. isMultiline (isMultiline_)
  57641. {
  57642. setEditable (true, true, false);
  57643. setColour (backgroundColourId, Colours::white);
  57644. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57645. }
  57646. ~TextPropLabel()
  57647. {
  57648. }
  57649. TextEditor* createEditorComponent()
  57650. {
  57651. TextEditor* const textEditor = Label::createEditorComponent();
  57652. textEditor->setInputRestrictions (maxChars);
  57653. if (isMultiline)
  57654. {
  57655. textEditor->setMultiLine (true, true);
  57656. textEditor->setReturnKeyStartsNewLine (true);
  57657. }
  57658. return textEditor;
  57659. }
  57660. void textWasEdited()
  57661. {
  57662. owner.textWasEdited();
  57663. }
  57664. };
  57665. TextPropertyComponent::TextPropertyComponent (const String& name,
  57666. const int maxNumChars,
  57667. const bool isMultiLine)
  57668. : PropertyComponent (name)
  57669. {
  57670. createEditor (maxNumChars, isMultiLine);
  57671. }
  57672. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57673. const String& name,
  57674. const int maxNumChars,
  57675. const bool isMultiLine)
  57676. : PropertyComponent (name)
  57677. {
  57678. createEditor (maxNumChars, isMultiLine);
  57679. textEditor->getTextValue().referTo (valueToControl);
  57680. }
  57681. TextPropertyComponent::~TextPropertyComponent()
  57682. {
  57683. deleteAllChildren();
  57684. }
  57685. void TextPropertyComponent::setText (const String& newText)
  57686. {
  57687. textEditor->setText (newText, true);
  57688. }
  57689. const String TextPropertyComponent::getText() const
  57690. {
  57691. return textEditor->getText();
  57692. }
  57693. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57694. {
  57695. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57696. if (isMultiLine)
  57697. {
  57698. textEditor->setJustificationType (Justification::topLeft);
  57699. preferredHeight = 120;
  57700. }
  57701. }
  57702. void TextPropertyComponent::refresh()
  57703. {
  57704. textEditor->setText (getText(), false);
  57705. }
  57706. void TextPropertyComponent::textWasEdited()
  57707. {
  57708. const String newText (textEditor->getText());
  57709. if (getText() != newText)
  57710. setText (newText);
  57711. }
  57712. END_JUCE_NAMESPACE
  57713. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57714. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57715. BEGIN_JUCE_NAMESPACE
  57716. class SimpleDeviceManagerInputLevelMeter : public Component,
  57717. public Timer
  57718. {
  57719. public:
  57720. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57721. : manager (manager_),
  57722. level (0)
  57723. {
  57724. startTimer (50);
  57725. manager->enableInputLevelMeasurement (true);
  57726. }
  57727. ~SimpleDeviceManagerInputLevelMeter()
  57728. {
  57729. manager->enableInputLevelMeasurement (false);
  57730. }
  57731. void timerCallback()
  57732. {
  57733. const float newLevel = (float) manager->getCurrentInputLevel();
  57734. if (fabsf (level - newLevel) > 0.005f)
  57735. {
  57736. level = newLevel;
  57737. repaint();
  57738. }
  57739. }
  57740. void paint (Graphics& g)
  57741. {
  57742. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57743. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57744. }
  57745. private:
  57746. AudioDeviceManager* const manager;
  57747. float level;
  57748. };
  57749. class MidiInputSelectorComponentListBox : public ListBox,
  57750. public ListBoxModel
  57751. {
  57752. public:
  57753. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57754. const String& noItemsMessage_,
  57755. const int minNumber_,
  57756. const int maxNumber_)
  57757. : ListBox (String::empty, 0),
  57758. deviceManager (deviceManager_),
  57759. noItemsMessage (noItemsMessage_),
  57760. minNumber (minNumber_),
  57761. maxNumber (maxNumber_)
  57762. {
  57763. items = MidiInput::getDevices();
  57764. setModel (this);
  57765. setOutlineThickness (1);
  57766. }
  57767. ~MidiInputSelectorComponentListBox()
  57768. {
  57769. }
  57770. int getNumRows()
  57771. {
  57772. return items.size();
  57773. }
  57774. void paintListBoxItem (int row,
  57775. Graphics& g,
  57776. int width, int height,
  57777. bool rowIsSelected)
  57778. {
  57779. if (((unsigned int) row) < (unsigned int) items.size())
  57780. {
  57781. if (rowIsSelected)
  57782. g.fillAll (findColour (TextEditor::highlightColourId)
  57783. .withMultipliedAlpha (0.3f));
  57784. const String item (items [row]);
  57785. bool enabled = deviceManager.isMidiInputEnabled (item);
  57786. const int x = getTickX();
  57787. const float tickW = height * 0.75f;
  57788. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57789. enabled, true, true, false);
  57790. g.setFont (height * 0.6f);
  57791. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57792. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57793. }
  57794. }
  57795. void listBoxItemClicked (int row, const MouseEvent& e)
  57796. {
  57797. selectRow (row);
  57798. if (e.x < getTickX())
  57799. flipEnablement (row);
  57800. }
  57801. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57802. {
  57803. flipEnablement (row);
  57804. }
  57805. void returnKeyPressed (int row)
  57806. {
  57807. flipEnablement (row);
  57808. }
  57809. void paint (Graphics& g)
  57810. {
  57811. ListBox::paint (g);
  57812. if (items.size() == 0)
  57813. {
  57814. g.setColour (Colours::grey);
  57815. g.setFont (13.0f);
  57816. g.drawText (noItemsMessage,
  57817. 0, 0, getWidth(), getHeight() / 2,
  57818. Justification::centred, true);
  57819. }
  57820. }
  57821. int getBestHeight (const int preferredHeight)
  57822. {
  57823. const int extra = getOutlineThickness() * 2;
  57824. return jmax (getRowHeight() * 2 + extra,
  57825. jmin (getRowHeight() * getNumRows() + extra,
  57826. preferredHeight));
  57827. }
  57828. juce_UseDebuggingNewOperator
  57829. private:
  57830. AudioDeviceManager& deviceManager;
  57831. const String noItemsMessage;
  57832. StringArray items;
  57833. int minNumber, maxNumber;
  57834. void flipEnablement (const int row)
  57835. {
  57836. if (((unsigned int) row) < (unsigned int) items.size())
  57837. {
  57838. const String item (items [row]);
  57839. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57840. }
  57841. }
  57842. int getTickX() const
  57843. {
  57844. return getRowHeight() + 5;
  57845. }
  57846. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57847. const MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57848. };
  57849. class AudioDeviceSettingsPanel : public Component,
  57850. public ComboBoxListener,
  57851. public ChangeListener,
  57852. public ButtonListener
  57853. {
  57854. public:
  57855. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57856. AudioIODeviceType::DeviceSetupDetails& setup_,
  57857. const bool hideAdvancedOptionsWithButton)
  57858. : type (type_),
  57859. setup (setup_)
  57860. {
  57861. sampleRateDropDown = 0;
  57862. sampleRateLabel = 0;
  57863. bufferSizeDropDown = 0;
  57864. bufferSizeLabel = 0;
  57865. outputDeviceDropDown = 0;
  57866. outputDeviceLabel = 0;
  57867. inputDeviceDropDown = 0;
  57868. inputDeviceLabel = 0;
  57869. testButton = 0;
  57870. inputLevelMeter = 0;
  57871. showUIButton = 0;
  57872. inputChanList = 0;
  57873. outputChanList = 0;
  57874. inputChanLabel = 0;
  57875. outputChanLabel = 0;
  57876. showAdvancedSettingsButton = 0;
  57877. if (hideAdvancedOptionsWithButton)
  57878. {
  57879. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57880. showAdvancedSettingsButton->addButtonListener (this);
  57881. }
  57882. type->scanForDevices();
  57883. setup.manager->addChangeListener (this);
  57884. changeListenerCallback (0);
  57885. }
  57886. ~AudioDeviceSettingsPanel()
  57887. {
  57888. setup.manager->removeChangeListener (this);
  57889. deleteAndZero (outputDeviceLabel);
  57890. deleteAndZero (inputDeviceLabel);
  57891. deleteAndZero (sampleRateLabel);
  57892. deleteAndZero (bufferSizeLabel);
  57893. deleteAndZero (showUIButton);
  57894. deleteAndZero (inputChanLabel);
  57895. deleteAndZero (outputChanLabel);
  57896. deleteAndZero (showAdvancedSettingsButton);
  57897. deleteAllChildren();
  57898. }
  57899. void resized()
  57900. {
  57901. const int lx = proportionOfWidth (0.35f);
  57902. const int w = proportionOfWidth (0.4f);
  57903. const int h = 24;
  57904. const int space = 6;
  57905. const int dh = h + space;
  57906. int y = 0;
  57907. if (outputDeviceDropDown != 0)
  57908. {
  57909. outputDeviceDropDown->setBounds (lx, y, w, h);
  57910. if (testButton != 0)
  57911. testButton->setBounds (proportionOfWidth (0.77f),
  57912. outputDeviceDropDown->getY(),
  57913. proportionOfWidth (0.18f),
  57914. h);
  57915. y += dh;
  57916. }
  57917. if (inputDeviceDropDown != 0)
  57918. {
  57919. inputDeviceDropDown->setBounds (lx, y, w, h);
  57920. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57921. inputDeviceDropDown->getY(),
  57922. proportionOfWidth (0.18f),
  57923. h);
  57924. y += dh;
  57925. }
  57926. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57927. if (outputChanList != 0)
  57928. {
  57929. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57930. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57931. y += bh + space;
  57932. }
  57933. if (inputChanList != 0)
  57934. {
  57935. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57936. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57937. y += bh + space;
  57938. }
  57939. y += space * 2;
  57940. if (showAdvancedSettingsButton != 0)
  57941. {
  57942. showAdvancedSettingsButton->changeWidthToFitText (h);
  57943. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57944. }
  57945. if (sampleRateDropDown != 0)
  57946. {
  57947. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57948. || ! showAdvancedSettingsButton->isVisible());
  57949. sampleRateDropDown->setBounds (lx, y, w, h);
  57950. y += dh;
  57951. }
  57952. if (bufferSizeDropDown != 0)
  57953. {
  57954. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57955. || ! showAdvancedSettingsButton->isVisible());
  57956. bufferSizeDropDown->setBounds (lx, y, w, h);
  57957. y += dh;
  57958. }
  57959. if (showUIButton != 0)
  57960. {
  57961. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57962. || ! showAdvancedSettingsButton->isVisible());
  57963. showUIButton->changeWidthToFitText (h);
  57964. showUIButton->setTopLeftPosition (lx, y);
  57965. }
  57966. }
  57967. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57968. {
  57969. if (comboBoxThatHasChanged == 0)
  57970. return;
  57971. AudioDeviceManager::AudioDeviceSetup config;
  57972. setup.manager->getAudioDeviceSetup (config);
  57973. String error;
  57974. if (comboBoxThatHasChanged == outputDeviceDropDown
  57975. || comboBoxThatHasChanged == inputDeviceDropDown)
  57976. {
  57977. if (outputDeviceDropDown != 0)
  57978. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57979. : outputDeviceDropDown->getText();
  57980. if (inputDeviceDropDown != 0)
  57981. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57982. : inputDeviceDropDown->getText();
  57983. if (! type->hasSeparateInputsAndOutputs())
  57984. config.inputDeviceName = config.outputDeviceName;
  57985. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57986. config.useDefaultInputChannels = true;
  57987. else
  57988. config.useDefaultOutputChannels = true;
  57989. error = setup.manager->setAudioDeviceSetup (config, true);
  57990. showCorrectDeviceName (inputDeviceDropDown, true);
  57991. showCorrectDeviceName (outputDeviceDropDown, false);
  57992. updateControlPanelButton();
  57993. resized();
  57994. }
  57995. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57996. {
  57997. if (sampleRateDropDown->getSelectedId() > 0)
  57998. {
  57999. config.sampleRate = sampleRateDropDown->getSelectedId();
  58000. error = setup.manager->setAudioDeviceSetup (config, true);
  58001. }
  58002. }
  58003. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  58004. {
  58005. if (bufferSizeDropDown->getSelectedId() > 0)
  58006. {
  58007. config.bufferSize = bufferSizeDropDown->getSelectedId();
  58008. error = setup.manager->setAudioDeviceSetup (config, true);
  58009. }
  58010. }
  58011. if (error.isNotEmpty())
  58012. {
  58013. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  58014. T("Error when trying to open audio device!"),
  58015. error);
  58016. }
  58017. }
  58018. void buttonClicked (Button* button)
  58019. {
  58020. if (button == showAdvancedSettingsButton)
  58021. {
  58022. showAdvancedSettingsButton->setVisible (false);
  58023. resized();
  58024. }
  58025. else if (button == showUIButton)
  58026. {
  58027. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  58028. if (device != 0 && device->showControlPanel())
  58029. {
  58030. setup.manager->closeAudioDevice();
  58031. setup.manager->restartLastAudioDevice();
  58032. getTopLevelComponent()->toFront (true);
  58033. }
  58034. }
  58035. else if (button == testButton && testButton != 0)
  58036. {
  58037. setup.manager->playTestSound();
  58038. }
  58039. }
  58040. void updateControlPanelButton()
  58041. {
  58042. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58043. deleteAndZero (showUIButton);
  58044. if (currentDevice != 0 && currentDevice->hasControlPanel())
  58045. {
  58046. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  58047. TRANS ("opens the device's own control panel")));
  58048. showUIButton->addButtonListener (this);
  58049. }
  58050. resized();
  58051. }
  58052. void changeListenerCallback (void*)
  58053. {
  58054. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58055. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  58056. {
  58057. if (outputDeviceDropDown == 0)
  58058. {
  58059. outputDeviceDropDown = new ComboBox (String::empty);
  58060. outputDeviceDropDown->addListener (this);
  58061. addAndMakeVisible (outputDeviceDropDown);
  58062. outputDeviceLabel = new Label (String::empty,
  58063. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  58064. : TRANS ("device:"));
  58065. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  58066. if (setup.maxNumOutputChannels > 0)
  58067. {
  58068. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  58069. testButton->addButtonListener (this);
  58070. }
  58071. }
  58072. addNamesToDeviceBox (*outputDeviceDropDown, false);
  58073. }
  58074. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  58075. {
  58076. if (inputDeviceDropDown == 0)
  58077. {
  58078. inputDeviceDropDown = new ComboBox (String::empty);
  58079. inputDeviceDropDown->addListener (this);
  58080. addAndMakeVisible (inputDeviceDropDown);
  58081. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  58082. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  58083. addAndMakeVisible (inputLevelMeter
  58084. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  58085. }
  58086. addNamesToDeviceBox (*inputDeviceDropDown, true);
  58087. }
  58088. updateControlPanelButton();
  58089. showCorrectDeviceName (inputDeviceDropDown, true);
  58090. showCorrectDeviceName (outputDeviceDropDown, false);
  58091. if (currentDevice != 0)
  58092. {
  58093. if (setup.maxNumOutputChannels > 0
  58094. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  58095. {
  58096. if (outputChanList == 0)
  58097. {
  58098. addAndMakeVisible (outputChanList
  58099. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  58100. TRANS ("(no audio output channels found)")));
  58101. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  58102. outputChanLabel->attachToComponent (outputChanList, true);
  58103. }
  58104. outputChanList->refresh();
  58105. }
  58106. else
  58107. {
  58108. deleteAndZero (outputChanLabel);
  58109. deleteAndZero (outputChanList);
  58110. }
  58111. if (setup.maxNumInputChannels > 0
  58112. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  58113. {
  58114. if (inputChanList == 0)
  58115. {
  58116. addAndMakeVisible (inputChanList
  58117. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  58118. TRANS ("(no audio input channels found)")));
  58119. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  58120. inputChanLabel->attachToComponent (inputChanList, true);
  58121. }
  58122. inputChanList->refresh();
  58123. }
  58124. else
  58125. {
  58126. deleteAndZero (inputChanLabel);
  58127. deleteAndZero (inputChanList);
  58128. }
  58129. // sample rate..
  58130. {
  58131. if (sampleRateDropDown == 0)
  58132. {
  58133. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  58134. sampleRateDropDown->addListener (this);
  58135. delete sampleRateLabel;
  58136. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  58137. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  58138. }
  58139. else
  58140. {
  58141. sampleRateDropDown->clear();
  58142. sampleRateDropDown->removeListener (this);
  58143. }
  58144. const int numRates = currentDevice->getNumSampleRates();
  58145. for (int i = 0; i < numRates; ++i)
  58146. {
  58147. const int rate = roundToInt (currentDevice->getSampleRate (i));
  58148. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  58149. }
  58150. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  58151. sampleRateDropDown->addListener (this);
  58152. }
  58153. // buffer size
  58154. {
  58155. if (bufferSizeDropDown == 0)
  58156. {
  58157. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58158. bufferSizeDropDown->addListener (this);
  58159. delete bufferSizeLabel;
  58160. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58161. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58162. }
  58163. else
  58164. {
  58165. bufferSizeDropDown->clear();
  58166. }
  58167. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58168. double currentRate = currentDevice->getCurrentSampleRate();
  58169. if (currentRate == 0)
  58170. currentRate = 48000.0;
  58171. for (int i = 0; i < numBufferSizes; ++i)
  58172. {
  58173. const int bs = currentDevice->getBufferSizeSamples (i);
  58174. bufferSizeDropDown->addItem (String (bs)
  58175. + T(" samples (")
  58176. + String (bs * 1000.0 / currentRate, 1)
  58177. + T(" ms)"),
  58178. bs);
  58179. }
  58180. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58181. }
  58182. }
  58183. else
  58184. {
  58185. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58186. deleteAndZero (sampleRateLabel);
  58187. deleteAndZero (bufferSizeLabel);
  58188. deleteAndZero (sampleRateDropDown);
  58189. deleteAndZero (bufferSizeDropDown);
  58190. if (outputDeviceDropDown != 0)
  58191. outputDeviceDropDown->setSelectedId (-1, true);
  58192. if (inputDeviceDropDown != 0)
  58193. inputDeviceDropDown->setSelectedId (-1, true);
  58194. }
  58195. resized();
  58196. setSize (getWidth(), getLowestY() + 4);
  58197. }
  58198. private:
  58199. AudioIODeviceType* const type;
  58200. const AudioIODeviceType::DeviceSetupDetails setup;
  58201. ComboBox* outputDeviceDropDown;
  58202. ComboBox* inputDeviceDropDown;
  58203. ComboBox* sampleRateDropDown;
  58204. ComboBox* bufferSizeDropDown;
  58205. Label* outputDeviceLabel;
  58206. Label* inputDeviceLabel;
  58207. Label* sampleRateLabel;
  58208. Label* bufferSizeLabel;
  58209. Label* inputChanLabel;
  58210. Label* outputChanLabel;
  58211. TextButton* testButton;
  58212. Component* inputLevelMeter;
  58213. TextButton* showUIButton;
  58214. TextButton* showAdvancedSettingsButton;
  58215. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58216. {
  58217. if (box != 0)
  58218. {
  58219. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58220. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58221. box->setSelectedId (index + 1, true);
  58222. if (testButton != 0 && ! isInput)
  58223. testButton->setEnabled (index >= 0);
  58224. }
  58225. }
  58226. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58227. {
  58228. const StringArray devs (type->getDeviceNames (isInputs));
  58229. combo.clear (true);
  58230. for (int i = 0; i < devs.size(); ++i)
  58231. combo.addItem (devs[i], i + 1);
  58232. combo.addItem (TRANS("<< none >>"), -1);
  58233. combo.setSelectedId (-1, true);
  58234. }
  58235. int getLowestY() const
  58236. {
  58237. int y = 0;
  58238. for (int i = getNumChildComponents(); --i >= 0;)
  58239. y = jmax (y, getChildComponent (i)->getBottom());
  58240. return y;
  58241. }
  58242. public:
  58243. class ChannelSelectorListBox : public ListBox,
  58244. public ListBoxModel
  58245. {
  58246. public:
  58247. enum BoxType
  58248. {
  58249. audioInputType,
  58250. audioOutputType
  58251. };
  58252. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58253. const BoxType type_,
  58254. const String& noItemsMessage_)
  58255. : ListBox (String::empty, 0),
  58256. setup (setup_),
  58257. type (type_),
  58258. noItemsMessage (noItemsMessage_)
  58259. {
  58260. refresh();
  58261. setModel (this);
  58262. setOutlineThickness (1);
  58263. }
  58264. ~ChannelSelectorListBox()
  58265. {
  58266. }
  58267. void refresh()
  58268. {
  58269. items.clear();
  58270. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58271. if (currentDevice != 0)
  58272. {
  58273. if (type == audioInputType)
  58274. items = currentDevice->getInputChannelNames();
  58275. else if (type == audioOutputType)
  58276. items = currentDevice->getOutputChannelNames();
  58277. if (setup.useStereoPairs)
  58278. {
  58279. StringArray pairs;
  58280. for (int i = 0; i < items.size(); i += 2)
  58281. {
  58282. String name (items[i]);
  58283. String name2 (items[i + 1]);
  58284. String commonBit;
  58285. for (int j = 0; j < name.length(); ++j)
  58286. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58287. commonBit = name.substring (0, j);
  58288. pairs.add (name.trim()
  58289. + " + "
  58290. + name2.substring (commonBit.length()).trim());
  58291. }
  58292. items = pairs;
  58293. }
  58294. }
  58295. updateContent();
  58296. repaint();
  58297. }
  58298. int getNumRows()
  58299. {
  58300. return items.size();
  58301. }
  58302. void paintListBoxItem (int row,
  58303. Graphics& g,
  58304. int width, int height,
  58305. bool rowIsSelected)
  58306. {
  58307. if (((unsigned int) row) < (unsigned int) items.size())
  58308. {
  58309. if (rowIsSelected)
  58310. g.fillAll (findColour (TextEditor::highlightColourId)
  58311. .withMultipliedAlpha (0.3f));
  58312. const String item (items [row]);
  58313. bool enabled = false;
  58314. AudioDeviceManager::AudioDeviceSetup config;
  58315. setup.manager->getAudioDeviceSetup (config);
  58316. if (setup.useStereoPairs)
  58317. {
  58318. if (type == audioInputType)
  58319. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58320. else if (type == audioOutputType)
  58321. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58322. }
  58323. else
  58324. {
  58325. if (type == audioInputType)
  58326. enabled = config.inputChannels [row];
  58327. else if (type == audioOutputType)
  58328. enabled = config.outputChannels [row];
  58329. }
  58330. const int x = getTickX();
  58331. const float tickW = height * 0.75f;
  58332. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58333. enabled, true, true, false);
  58334. g.setFont (height * 0.6f);
  58335. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58336. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58337. }
  58338. }
  58339. void listBoxItemClicked (int row, const MouseEvent& e)
  58340. {
  58341. selectRow (row);
  58342. if (e.x < getTickX())
  58343. flipEnablement (row);
  58344. }
  58345. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58346. {
  58347. flipEnablement (row);
  58348. }
  58349. void returnKeyPressed (int row)
  58350. {
  58351. flipEnablement (row);
  58352. }
  58353. void paint (Graphics& g)
  58354. {
  58355. ListBox::paint (g);
  58356. if (items.size() == 0)
  58357. {
  58358. g.setColour (Colours::grey);
  58359. g.setFont (13.0f);
  58360. g.drawText (noItemsMessage,
  58361. 0, 0, getWidth(), getHeight() / 2,
  58362. Justification::centred, true);
  58363. }
  58364. }
  58365. int getBestHeight (int maxHeight)
  58366. {
  58367. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58368. getNumRows())
  58369. + getOutlineThickness() * 2;
  58370. }
  58371. juce_UseDebuggingNewOperator
  58372. private:
  58373. const AudioIODeviceType::DeviceSetupDetails setup;
  58374. const BoxType type;
  58375. const String noItemsMessage;
  58376. StringArray items;
  58377. void flipEnablement (const int row)
  58378. {
  58379. jassert (type == audioInputType || type == audioOutputType);
  58380. if (((unsigned int) row) < (unsigned int) items.size())
  58381. {
  58382. AudioDeviceManager::AudioDeviceSetup config;
  58383. setup.manager->getAudioDeviceSetup (config);
  58384. if (setup.useStereoPairs)
  58385. {
  58386. BitArray bits;
  58387. BitArray& original = (type == audioInputType ? config.inputChannels
  58388. : config.outputChannels);
  58389. int i;
  58390. for (i = 0; i < 256; i += 2)
  58391. bits.setBit (i / 2, original [i] || original [i + 1]);
  58392. if (type == audioInputType)
  58393. {
  58394. config.useDefaultInputChannels = false;
  58395. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58396. }
  58397. else
  58398. {
  58399. config.useDefaultOutputChannels = false;
  58400. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58401. }
  58402. for (i = 0; i < 256; ++i)
  58403. original.setBit (i, bits [i / 2]);
  58404. }
  58405. else
  58406. {
  58407. if (type == audioInputType)
  58408. {
  58409. config.useDefaultInputChannels = false;
  58410. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58411. }
  58412. else
  58413. {
  58414. config.useDefaultOutputChannels = false;
  58415. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58416. }
  58417. }
  58418. String error (setup.manager->setAudioDeviceSetup (config, true));
  58419. if (! error.isEmpty())
  58420. {
  58421. //xxx
  58422. }
  58423. }
  58424. }
  58425. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58426. {
  58427. const int numActive = chans.countNumberOfSetBits();
  58428. if (chans [index])
  58429. {
  58430. if (numActive > minNumber)
  58431. chans.setBit (index, false);
  58432. }
  58433. else
  58434. {
  58435. if (numActive >= maxNumber)
  58436. {
  58437. const int firstActiveChan = chans.findNextSetBit();
  58438. chans.setBit (index > firstActiveChan
  58439. ? firstActiveChan : chans.getHighestBit(),
  58440. false);
  58441. }
  58442. chans.setBit (index, true);
  58443. }
  58444. }
  58445. int getTickX() const
  58446. {
  58447. return getRowHeight() + 5;
  58448. }
  58449. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58450. const ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58451. };
  58452. private:
  58453. ChannelSelectorListBox* inputChanList;
  58454. ChannelSelectorListBox* outputChanList;
  58455. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58456. const AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58457. };
  58458. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58459. const int minInputChannels_,
  58460. const int maxInputChannels_,
  58461. const int minOutputChannels_,
  58462. const int maxOutputChannels_,
  58463. const bool showMidiInputOptions,
  58464. const bool showMidiOutputSelector,
  58465. const bool showChannelsAsStereoPairs_,
  58466. const bool hideAdvancedOptionsWithButton_)
  58467. : deviceManager (deviceManager_),
  58468. deviceTypeDropDown (0),
  58469. deviceTypeDropDownLabel (0),
  58470. audioDeviceSettingsComp (0),
  58471. minOutputChannels (minOutputChannels_),
  58472. maxOutputChannels (maxOutputChannels_),
  58473. minInputChannels (minInputChannels_),
  58474. maxInputChannels (maxInputChannels_),
  58475. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58476. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58477. {
  58478. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58479. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58480. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58481. {
  58482. deviceTypeDropDown = new ComboBox (String::empty);
  58483. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58484. {
  58485. deviceTypeDropDown
  58486. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58487. i + 1);
  58488. }
  58489. addAndMakeVisible (deviceTypeDropDown);
  58490. deviceTypeDropDown->addListener (this);
  58491. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58492. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58493. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58494. }
  58495. if (showMidiInputOptions)
  58496. {
  58497. addAndMakeVisible (midiInputsList
  58498. = new MidiInputSelectorComponentListBox (deviceManager,
  58499. TRANS("(no midi inputs available)"),
  58500. 0, 0));
  58501. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58502. midiInputsLabel->setJustificationType (Justification::topRight);
  58503. midiInputsLabel->attachToComponent (midiInputsList, true);
  58504. }
  58505. else
  58506. {
  58507. midiInputsList = 0;
  58508. midiInputsLabel = 0;
  58509. }
  58510. if (showMidiOutputSelector)
  58511. {
  58512. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58513. midiOutputSelector->addListener (this);
  58514. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58515. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58516. }
  58517. else
  58518. {
  58519. midiOutputSelector = 0;
  58520. midiOutputLabel = 0;
  58521. }
  58522. deviceManager_.addChangeListener (this);
  58523. changeListenerCallback (0);
  58524. }
  58525. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58526. {
  58527. deviceManager.removeChangeListener (this);
  58528. deleteAllChildren();
  58529. }
  58530. void AudioDeviceSelectorComponent::resized()
  58531. {
  58532. const int lx = proportionOfWidth (0.35f);
  58533. const int w = proportionOfWidth (0.4f);
  58534. const int h = 24;
  58535. const int space = 6;
  58536. const int dh = h + space;
  58537. int y = 15;
  58538. if (deviceTypeDropDown != 0)
  58539. {
  58540. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58541. y += dh + space * 2;
  58542. }
  58543. if (audioDeviceSettingsComp != 0)
  58544. {
  58545. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58546. y += audioDeviceSettingsComp->getHeight() + space;
  58547. }
  58548. if (midiInputsList != 0)
  58549. {
  58550. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58551. midiInputsList->setBounds (lx, y, w, bh);
  58552. y += bh + space;
  58553. }
  58554. if (midiOutputSelector != 0)
  58555. midiOutputSelector->setBounds (lx, y, w, h);
  58556. }
  58557. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58558. {
  58559. if (child == audioDeviceSettingsComp)
  58560. resized();
  58561. }
  58562. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58563. {
  58564. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58565. if (device != 0 && device->hasControlPanel())
  58566. {
  58567. if (device->showControlPanel())
  58568. deviceManager.restartLastAudioDevice();
  58569. getTopLevelComponent()->toFront (true);
  58570. }
  58571. }
  58572. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58573. {
  58574. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58575. {
  58576. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58577. if (type != 0)
  58578. {
  58579. deleteAndZero (audioDeviceSettingsComp);
  58580. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58581. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58582. }
  58583. }
  58584. else if (comboBoxThatHasChanged == midiOutputSelector)
  58585. {
  58586. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58587. }
  58588. }
  58589. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58590. {
  58591. if (deviceTypeDropDown != 0)
  58592. {
  58593. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58594. }
  58595. if (audioDeviceSettingsComp == 0
  58596. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58597. {
  58598. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58599. deleteAndZero (audioDeviceSettingsComp);
  58600. AudioIODeviceType* const type
  58601. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58602. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58603. if (type != 0)
  58604. {
  58605. AudioIODeviceType::DeviceSetupDetails details;
  58606. details.manager = &deviceManager;
  58607. details.minNumInputChannels = minInputChannels;
  58608. details.maxNumInputChannels = maxInputChannels;
  58609. details.minNumOutputChannels = minOutputChannels;
  58610. details.maxNumOutputChannels = maxOutputChannels;
  58611. details.useStereoPairs = showChannelsAsStereoPairs;
  58612. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58613. if (audioDeviceSettingsComp != 0)
  58614. {
  58615. addAndMakeVisible (audioDeviceSettingsComp);
  58616. audioDeviceSettingsComp->resized();
  58617. }
  58618. }
  58619. }
  58620. if (midiInputsList != 0)
  58621. {
  58622. midiInputsList->updateContent();
  58623. midiInputsList->repaint();
  58624. }
  58625. if (midiOutputSelector != 0)
  58626. {
  58627. midiOutputSelector->clear();
  58628. const StringArray midiOuts (MidiOutput::getDevices());
  58629. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58630. midiOutputSelector->addSeparator();
  58631. for (int i = 0; i < midiOuts.size(); ++i)
  58632. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58633. int current = -1;
  58634. if (deviceManager.getDefaultMidiOutput() != 0)
  58635. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58636. midiOutputSelector->setSelectedId (current, true);
  58637. }
  58638. resized();
  58639. }
  58640. END_JUCE_NAMESPACE
  58641. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58642. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58643. BEGIN_JUCE_NAMESPACE
  58644. BubbleComponent::BubbleComponent()
  58645. : side (0),
  58646. allowablePlacements (above | below | left | right),
  58647. arrowTipX (0.0f),
  58648. arrowTipY (0.0f)
  58649. {
  58650. setInterceptsMouseClicks (false, false);
  58651. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58652. setComponentEffect (&shadow);
  58653. }
  58654. BubbleComponent::~BubbleComponent()
  58655. {
  58656. }
  58657. void BubbleComponent::paint (Graphics& g)
  58658. {
  58659. int x = content.getX();
  58660. int y = content.getY();
  58661. int w = content.getWidth();
  58662. int h = content.getHeight();
  58663. int cw, ch;
  58664. getContentSize (cw, ch);
  58665. if (side == 3)
  58666. x += w - cw;
  58667. else if (side != 1)
  58668. x += (w - cw) / 2;
  58669. w = cw;
  58670. if (side == 2)
  58671. y += h - ch;
  58672. else if (side != 0)
  58673. y += (h - ch) / 2;
  58674. h = ch;
  58675. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58676. (float) x, (float) y,
  58677. (float) w, (float) h);
  58678. const int cx = x + (w - cw) / 2;
  58679. const int cy = y + (h - ch) / 2;
  58680. const int indent = 3;
  58681. g.setOrigin (cx + indent, cy + indent);
  58682. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58683. paintContent (g, cw - indent * 2, ch - indent * 2);
  58684. }
  58685. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58686. {
  58687. allowablePlacements = newPlacement;
  58688. }
  58689. void BubbleComponent::setPosition (Component* componentToPointTo)
  58690. {
  58691. jassert (componentToPointTo->isValidComponent());
  58692. Point<int> pos;
  58693. if (getParentComponent() != 0)
  58694. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58695. else
  58696. pos = componentToPointTo->relativePositionToGlobal (pos);
  58697. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58698. }
  58699. void BubbleComponent::setPosition (const int arrowTipX_,
  58700. const int arrowTipY_)
  58701. {
  58702. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58703. }
  58704. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58705. {
  58706. Rectangle<int> availableSpace;
  58707. if (getParentComponent() != 0)
  58708. {
  58709. availableSpace.setSize (getParentComponent()->getWidth(),
  58710. getParentComponent()->getHeight());
  58711. }
  58712. else
  58713. {
  58714. availableSpace = getParentMonitorArea();
  58715. }
  58716. int x = 0;
  58717. int y = 0;
  58718. int w = 150;
  58719. int h = 30;
  58720. getContentSize (w, h);
  58721. w += 30;
  58722. h += 30;
  58723. const float edgeIndent = 2.0f;
  58724. const int arrowLength = jmin (10, h / 3, w / 3);
  58725. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58726. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58727. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58728. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58729. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58730. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58731. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58732. {
  58733. spaceLeft = spaceRight = 0;
  58734. }
  58735. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58736. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58737. {
  58738. spaceAbove = spaceBelow = 0;
  58739. }
  58740. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58741. {
  58742. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58743. arrowTipX = w * 0.5f;
  58744. content.setSize (w, h - arrowLength);
  58745. if (spaceAbove >= spaceBelow)
  58746. {
  58747. // above
  58748. y = rectangleToPointTo.getY() - h;
  58749. content.setPosition (0, 0);
  58750. arrowTipY = h - edgeIndent;
  58751. side = 2;
  58752. }
  58753. else
  58754. {
  58755. // below
  58756. y = rectangleToPointTo.getBottom();
  58757. content.setPosition (0, arrowLength);
  58758. arrowTipY = edgeIndent;
  58759. side = 0;
  58760. }
  58761. }
  58762. else
  58763. {
  58764. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58765. arrowTipY = h * 0.5f;
  58766. content.setSize (w - arrowLength, h);
  58767. if (spaceLeft > spaceRight)
  58768. {
  58769. // on the left
  58770. x = rectangleToPointTo.getX() - w;
  58771. content.setPosition (0, 0);
  58772. arrowTipX = w - edgeIndent;
  58773. side = 3;
  58774. }
  58775. else
  58776. {
  58777. // on the right
  58778. x = rectangleToPointTo.getRight();
  58779. content.setPosition (arrowLength, 0);
  58780. arrowTipX = edgeIndent;
  58781. side = 1;
  58782. }
  58783. }
  58784. setBounds (x, y, w, h);
  58785. }
  58786. END_JUCE_NAMESPACE
  58787. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58788. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58789. BEGIN_JUCE_NAMESPACE
  58790. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58791. : fadeOutLength (fadeOutLengthMs),
  58792. deleteAfterUse (false)
  58793. {
  58794. }
  58795. BubbleMessageComponent::~BubbleMessageComponent()
  58796. {
  58797. fadeOutComponent (fadeOutLength);
  58798. }
  58799. void BubbleMessageComponent::showAt (int x, int y,
  58800. const String& text,
  58801. const int numMillisecondsBeforeRemoving,
  58802. const bool removeWhenMouseClicked,
  58803. const bool deleteSelfAfterUse)
  58804. {
  58805. textLayout.clear();
  58806. textLayout.setText (text, Font (14.0f));
  58807. textLayout.layout (256, Justification::centredLeft, true);
  58808. setPosition (x, y);
  58809. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58810. }
  58811. void BubbleMessageComponent::showAt (Component* const component,
  58812. const String& text,
  58813. const int numMillisecondsBeforeRemoving,
  58814. const bool removeWhenMouseClicked,
  58815. const bool deleteSelfAfterUse)
  58816. {
  58817. textLayout.clear();
  58818. textLayout.setText (text, Font (14.0f));
  58819. textLayout.layout (256, Justification::centredLeft, true);
  58820. setPosition (component);
  58821. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58822. }
  58823. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58824. const bool removeWhenMouseClicked,
  58825. const bool deleteSelfAfterUse)
  58826. {
  58827. setVisible (true);
  58828. deleteAfterUse = deleteSelfAfterUse;
  58829. if (numMillisecondsBeforeRemoving > 0)
  58830. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58831. else
  58832. expiryTime = 0;
  58833. startTimer (77);
  58834. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58835. if (! (removeWhenMouseClicked && isShowing()))
  58836. mouseClickCounter += 0xfffff;
  58837. repaint();
  58838. }
  58839. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58840. {
  58841. w = textLayout.getWidth() + 16;
  58842. h = textLayout.getHeight() + 16;
  58843. }
  58844. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58845. {
  58846. g.setColour (findColour (TooltipWindow::textColourId));
  58847. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58848. }
  58849. void BubbleMessageComponent::timerCallback()
  58850. {
  58851. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58852. {
  58853. stopTimer();
  58854. setVisible (false);
  58855. if (deleteAfterUse)
  58856. delete this;
  58857. }
  58858. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58859. {
  58860. stopTimer();
  58861. fadeOutComponent (fadeOutLength);
  58862. if (deleteAfterUse)
  58863. delete this;
  58864. }
  58865. }
  58866. END_JUCE_NAMESPACE
  58867. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58868. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58869. BEGIN_JUCE_NAMESPACE
  58870. static const int swatchesPerRow = 8;
  58871. static const int swatchHeight = 22;
  58872. class ColourComponentSlider : public Slider
  58873. {
  58874. public:
  58875. ColourComponentSlider (const String& name)
  58876. : Slider (name)
  58877. {
  58878. setRange (0.0, 255.0, 1.0);
  58879. }
  58880. ~ColourComponentSlider()
  58881. {
  58882. }
  58883. const String getTextFromValue (double value)
  58884. {
  58885. return String::formatted (T("%02X"), (int) value);
  58886. }
  58887. double getValueFromText (const String& text)
  58888. {
  58889. return (double) text.getHexValue32();
  58890. }
  58891. private:
  58892. ColourComponentSlider (const ColourComponentSlider&);
  58893. const ColourComponentSlider& operator= (const ColourComponentSlider&);
  58894. };
  58895. class ColourSpaceMarker : public Component
  58896. {
  58897. public:
  58898. ColourSpaceMarker()
  58899. {
  58900. setInterceptsMouseClicks (false, false);
  58901. }
  58902. ~ColourSpaceMarker()
  58903. {
  58904. }
  58905. void paint (Graphics& g)
  58906. {
  58907. g.setColour (Colour::greyLevel (0.1f));
  58908. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58909. g.setColour (Colour::greyLevel (0.9f));
  58910. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58911. }
  58912. private:
  58913. ColourSpaceMarker (const ColourSpaceMarker&);
  58914. const ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58915. };
  58916. class ColourSpaceView : public Component
  58917. {
  58918. ColourSelector* const owner;
  58919. float& h;
  58920. float& s;
  58921. float& v;
  58922. float lastHue;
  58923. ColourSpaceMarker* marker;
  58924. const int edge;
  58925. public:
  58926. ColourSpaceView (ColourSelector* owner_,
  58927. float& h_, float& s_, float& v_,
  58928. const int edgeSize)
  58929. : owner (owner_),
  58930. h (h_), s (s_), v (v_),
  58931. lastHue (0.0f),
  58932. edge (edgeSize)
  58933. {
  58934. addAndMakeVisible (marker = new ColourSpaceMarker());
  58935. setMouseCursor (MouseCursor::CrosshairCursor);
  58936. }
  58937. ~ColourSpaceView()
  58938. {
  58939. deleteAllChildren();
  58940. }
  58941. void paint (Graphics& g)
  58942. {
  58943. if (colours == 0)
  58944. {
  58945. const int width = getWidth() / 2;
  58946. const int height = getHeight() / 2;
  58947. colours = new Image (Image::RGB, width, height, false);
  58948. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58949. for (int y = 0; y < height; ++y)
  58950. {
  58951. const float v = 1.0f - y / (float) height;
  58952. for (int x = 0; x < width; ++x)
  58953. {
  58954. const float s = x / (float) width;
  58955. const Colour col (h, s, v, 1.0f);
  58956. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58957. pix->set (col.getPixelARGB());
  58958. }
  58959. }
  58960. }
  58961. g.setOpacity (1.0f);
  58962. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58963. 0, 0, colours->getWidth(), colours->getHeight());
  58964. }
  58965. void mouseDown (const MouseEvent& e)
  58966. {
  58967. mouseDrag (e);
  58968. }
  58969. void mouseDrag (const MouseEvent& e)
  58970. {
  58971. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58972. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58973. owner->setSV (s, v);
  58974. }
  58975. void updateIfNeeded()
  58976. {
  58977. if (lastHue != h)
  58978. {
  58979. lastHue = h;
  58980. colours = 0;
  58981. repaint();
  58982. }
  58983. updateMarker();
  58984. }
  58985. void resized()
  58986. {
  58987. colours = 0;
  58988. updateMarker();
  58989. }
  58990. private:
  58991. ScopedPointer <Image> colours;
  58992. void updateMarker() const throw()
  58993. {
  58994. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58995. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58996. edge * 2, edge * 2);
  58997. }
  58998. ColourSpaceView (const ColourSpaceView&);
  58999. const ColourSpaceView& operator= (const ColourSpaceView&);
  59000. };
  59001. class HueSelectorMarker : public Component
  59002. {
  59003. public:
  59004. HueSelectorMarker()
  59005. {
  59006. setInterceptsMouseClicks (false, false);
  59007. }
  59008. ~HueSelectorMarker()
  59009. {
  59010. }
  59011. void paint (Graphics& g)
  59012. {
  59013. Path p;
  59014. p.addTriangle (1.0f, 1.0f,
  59015. getWidth() * 0.3f, getHeight() * 0.5f,
  59016. 1.0f, getHeight() - 1.0f);
  59017. p.addTriangle (getWidth() - 1.0f, 1.0f,
  59018. getWidth() * 0.7f, getHeight() * 0.5f,
  59019. getWidth() - 1.0f, getHeight() - 1.0f);
  59020. g.setColour (Colours::white.withAlpha (0.75f));
  59021. g.fillPath (p);
  59022. g.setColour (Colours::black.withAlpha (0.75f));
  59023. g.strokePath (p, PathStrokeType (1.2f));
  59024. }
  59025. private:
  59026. HueSelectorMarker (const HueSelectorMarker&);
  59027. const HueSelectorMarker& operator= (const HueSelectorMarker&);
  59028. };
  59029. class HueSelectorComp : public Component
  59030. {
  59031. public:
  59032. HueSelectorComp (ColourSelector* owner_,
  59033. float& h_, float& s_, float& v_,
  59034. const int edgeSize)
  59035. : owner (owner_),
  59036. h (h_), s (s_), v (v_),
  59037. lastHue (0.0f),
  59038. edge (edgeSize)
  59039. {
  59040. addAndMakeVisible (marker = new HueSelectorMarker());
  59041. }
  59042. ~HueSelectorComp()
  59043. {
  59044. deleteAllChildren();
  59045. }
  59046. void paint (Graphics& g)
  59047. {
  59048. const float yScale = 1.0f / (getHeight() - edge * 2);
  59049. const Rectangle<int> clip (g.getClipBounds());
  59050. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  59051. {
  59052. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  59053. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  59054. }
  59055. }
  59056. void resized()
  59057. {
  59058. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  59059. getWidth(), edge * 2);
  59060. }
  59061. void mouseDown (const MouseEvent& e)
  59062. {
  59063. mouseDrag (e);
  59064. }
  59065. void mouseDrag (const MouseEvent& e)
  59066. {
  59067. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  59068. owner->setHue (hue);
  59069. }
  59070. void updateIfNeeded()
  59071. {
  59072. resized();
  59073. }
  59074. private:
  59075. ColourSelector* const owner;
  59076. float& h;
  59077. float& s;
  59078. float& v;
  59079. float lastHue;
  59080. HueSelectorMarker* marker;
  59081. const int edge;
  59082. HueSelectorComp (const HueSelectorComp&);
  59083. const HueSelectorComp& operator= (const HueSelectorComp&);
  59084. };
  59085. class ColourSelector::SwatchComponent : public Component
  59086. {
  59087. public:
  59088. SwatchComponent (ColourSelector* owner_, int index_)
  59089. : owner (owner_),
  59090. index (index_)
  59091. {
  59092. }
  59093. ~SwatchComponent()
  59094. {
  59095. }
  59096. void paint (Graphics& g)
  59097. {
  59098. const Colour colour (owner->getSwatchColour (index));
  59099. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  59100. 6, 6,
  59101. Colour (0xffdddddd).overlaidWith (colour),
  59102. Colour (0xffffffff).overlaidWith (colour));
  59103. }
  59104. void mouseDown (const MouseEvent&)
  59105. {
  59106. PopupMenu m;
  59107. m.addItem (1, TRANS("Use this swatch as the current colour"));
  59108. m.addSeparator();
  59109. m.addItem (2, TRANS("Set this swatch to the current colour"));
  59110. const int r = m.showAt (this);
  59111. if (r == 1)
  59112. {
  59113. owner->setCurrentColour (owner->getSwatchColour (index));
  59114. }
  59115. else if (r == 2)
  59116. {
  59117. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  59118. {
  59119. owner->setSwatchColour (index, owner->getCurrentColour());
  59120. repaint();
  59121. }
  59122. }
  59123. }
  59124. private:
  59125. ColourSelector* const owner;
  59126. const int index;
  59127. SwatchComponent (const SwatchComponent&);
  59128. const SwatchComponent& operator= (const SwatchComponent&);
  59129. };
  59130. ColourSelector::ColourSelector (const int flags_,
  59131. const int edgeGap_,
  59132. const int gapAroundColourSpaceComponent)
  59133. : colour (Colours::white),
  59134. flags (flags_),
  59135. topSpace (0),
  59136. edgeGap (edgeGap_)
  59137. {
  59138. // not much point having a selector with no components in it!
  59139. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  59140. updateHSV();
  59141. if ((flags & showSliders) != 0)
  59142. {
  59143. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  59144. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  59145. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  59146. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  59147. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  59148. for (int i = 4; --i >= 0;)
  59149. sliders[i]->addListener (this);
  59150. }
  59151. else
  59152. {
  59153. zeromem (sliders, sizeof (sliders));
  59154. }
  59155. if ((flags & showColourspace) != 0)
  59156. {
  59157. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59158. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59159. }
  59160. else
  59161. {
  59162. colourSpace = 0;
  59163. hueSelector = 0;
  59164. }
  59165. update();
  59166. }
  59167. ColourSelector::~ColourSelector()
  59168. {
  59169. dispatchPendingMessages();
  59170. swatchComponents.clear();
  59171. deleteAllChildren();
  59172. }
  59173. const Colour ColourSelector::getCurrentColour() const
  59174. {
  59175. return ((flags & showAlphaChannel) != 0) ? colour
  59176. : colour.withAlpha ((uint8) 0xff);
  59177. }
  59178. void ColourSelector::setCurrentColour (const Colour& c)
  59179. {
  59180. if (c != colour)
  59181. {
  59182. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59183. updateHSV();
  59184. update();
  59185. }
  59186. }
  59187. void ColourSelector::setHue (float newH)
  59188. {
  59189. newH = jlimit (0.0f, 1.0f, newH);
  59190. if (h != newH)
  59191. {
  59192. h = newH;
  59193. colour = Colour (h, s, v, colour.getFloatAlpha());
  59194. update();
  59195. }
  59196. }
  59197. void ColourSelector::setSV (float newS, float newV)
  59198. {
  59199. newS = jlimit (0.0f, 1.0f, newS);
  59200. newV = jlimit (0.0f, 1.0f, newV);
  59201. if (s != newS || v != newV)
  59202. {
  59203. s = newS;
  59204. v = newV;
  59205. colour = Colour (h, s, v, colour.getFloatAlpha());
  59206. update();
  59207. }
  59208. }
  59209. void ColourSelector::updateHSV()
  59210. {
  59211. colour.getHSB (h, s, v);
  59212. }
  59213. void ColourSelector::update()
  59214. {
  59215. if (sliders[0] != 0)
  59216. {
  59217. sliders[0]->setValue ((int) colour.getRed());
  59218. sliders[1]->setValue ((int) colour.getGreen());
  59219. sliders[2]->setValue ((int) colour.getBlue());
  59220. sliders[3]->setValue ((int) colour.getAlpha());
  59221. }
  59222. if (colourSpace != 0)
  59223. {
  59224. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59225. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59226. }
  59227. if ((flags & showColourAtTop) != 0)
  59228. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59229. sendChangeMessage (this);
  59230. }
  59231. void ColourSelector::paint (Graphics& g)
  59232. {
  59233. g.fillAll (findColour (backgroundColourId));
  59234. if ((flags & showColourAtTop) != 0)
  59235. {
  59236. const Colour colour (getCurrentColour());
  59237. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59238. 10, 10,
  59239. Colour (0xffdddddd).overlaidWith (colour),
  59240. Colour (0xffffffff).overlaidWith (colour));
  59241. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59242. g.setFont (14.0f, true);
  59243. g.drawText (((flags & showAlphaChannel) != 0)
  59244. ? String::formatted (T("#%02X%02X%02X%02X"),
  59245. (int) colour.getAlpha(),
  59246. (int) colour.getRed(),
  59247. (int) colour.getGreen(),
  59248. (int) colour.getBlue())
  59249. : String::formatted (T("#%02X%02X%02X"),
  59250. (int) colour.getRed(),
  59251. (int) colour.getGreen(),
  59252. (int) colour.getBlue()),
  59253. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59254. Justification::centred, false);
  59255. }
  59256. if ((flags & showSliders) != 0)
  59257. {
  59258. g.setColour (findColour (labelTextColourId));
  59259. g.setFont (11.0f);
  59260. for (int i = 4; --i >= 0;)
  59261. {
  59262. if (sliders[i]->isVisible())
  59263. g.drawText (sliders[i]->getName() + T(":"),
  59264. 0, sliders[i]->getY(),
  59265. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59266. Justification::centredRight, false);
  59267. }
  59268. }
  59269. }
  59270. void ColourSelector::resized()
  59271. {
  59272. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59273. const int numSwatches = getNumSwatches();
  59274. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59275. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59276. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59277. int y = topSpace;
  59278. if ((flags & showColourspace) != 0)
  59279. {
  59280. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59281. colourSpace->setBounds (edgeGap, y,
  59282. getWidth() - hueWidth - edgeGap - 4,
  59283. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59284. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59285. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59286. colourSpace->getHeight());
  59287. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59288. }
  59289. if ((flags & showSliders) != 0)
  59290. {
  59291. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59292. for (int i = 0; i < numSliders; ++i)
  59293. {
  59294. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59295. proportionOfWidth (0.72f), sliderHeight - 2);
  59296. y += sliderHeight;
  59297. }
  59298. }
  59299. if (numSwatches > 0)
  59300. {
  59301. const int startX = 8;
  59302. const int xGap = 4;
  59303. const int yGap = 4;
  59304. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59305. y += edgeGap;
  59306. if (swatchComponents.size() != numSwatches)
  59307. {
  59308. swatchComponents.clear();
  59309. for (int i = 0; i < numSwatches; ++i)
  59310. {
  59311. SwatchComponent* const sc = new SwatchComponent (this, i);
  59312. swatchComponents.add (sc);
  59313. addAndMakeVisible (sc);
  59314. }
  59315. }
  59316. int x = startX;
  59317. for (int i = 0; i < swatchComponents.size(); ++i)
  59318. {
  59319. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59320. sc->setBounds (x + xGap / 2,
  59321. y + yGap / 2,
  59322. swatchWidth - xGap,
  59323. swatchHeight - yGap);
  59324. if (((i + 1) % swatchesPerRow) == 0)
  59325. {
  59326. x = startX;
  59327. y += swatchHeight;
  59328. }
  59329. else
  59330. {
  59331. x += swatchWidth;
  59332. }
  59333. }
  59334. }
  59335. }
  59336. void ColourSelector::sliderValueChanged (Slider*)
  59337. {
  59338. if (sliders[0] != 0)
  59339. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59340. (uint8) sliders[1]->getValue(),
  59341. (uint8) sliders[2]->getValue(),
  59342. (uint8) sliders[3]->getValue()));
  59343. }
  59344. int ColourSelector::getNumSwatches() const
  59345. {
  59346. return 0;
  59347. }
  59348. const Colour ColourSelector::getSwatchColour (const int) const
  59349. {
  59350. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59351. return Colours::black;
  59352. }
  59353. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59354. {
  59355. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59356. }
  59357. END_JUCE_NAMESPACE
  59358. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59359. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59360. BEGIN_JUCE_NAMESPACE
  59361. class ShadowWindow : public Component
  59362. {
  59363. Component* owner;
  59364. Image** shadowImageSections;
  59365. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59366. public:
  59367. ShadowWindow (Component* const owner_,
  59368. const int type_,
  59369. Image** const shadowImageSections_)
  59370. : owner (owner_),
  59371. shadowImageSections (shadowImageSections_),
  59372. type (type_)
  59373. {
  59374. setInterceptsMouseClicks (false, false);
  59375. if (owner_->isOnDesktop())
  59376. {
  59377. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59378. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59379. | ComponentPeer::windowIsTemporary
  59380. | ComponentPeer::windowIgnoresKeyPresses);
  59381. }
  59382. else if (owner_->getParentComponent() != 0)
  59383. {
  59384. owner_->getParentComponent()->addChildComponent (this);
  59385. }
  59386. }
  59387. ~ShadowWindow()
  59388. {
  59389. }
  59390. void paint (Graphics& g)
  59391. {
  59392. Image* const topLeft = shadowImageSections [type * 3];
  59393. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59394. Image* const filler = shadowImageSections [type * 3 + 2];
  59395. g.setOpacity (1.0f);
  59396. if (type < 2)
  59397. {
  59398. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59399. g.drawImage (topLeft,
  59400. 0, 0, topLeft->getWidth(), imH,
  59401. 0, 0, topLeft->getWidth(), imH);
  59402. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59403. g.drawImage (bottomRight,
  59404. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59405. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59406. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59407. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59408. }
  59409. else
  59410. {
  59411. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59412. g.drawImage (topLeft,
  59413. 0, 0, imW, topLeft->getHeight(),
  59414. 0, 0, imW, topLeft->getHeight());
  59415. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59416. g.drawImage (bottomRight,
  59417. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59418. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59419. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59420. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59421. }
  59422. }
  59423. void resized()
  59424. {
  59425. repaint(); // (needed for correct repainting)
  59426. }
  59427. private:
  59428. ShadowWindow (const ShadowWindow&);
  59429. const ShadowWindow& operator= (const ShadowWindow&);
  59430. };
  59431. DropShadower::DropShadower (const float alpha_,
  59432. const int xOffset_,
  59433. const int yOffset_,
  59434. const float blurRadius_)
  59435. : owner (0),
  59436. numShadows (0),
  59437. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59438. xOffset (xOffset_),
  59439. yOffset (yOffset_),
  59440. alpha (alpha_),
  59441. blurRadius (blurRadius_),
  59442. inDestructor (false),
  59443. reentrant (false)
  59444. {
  59445. }
  59446. DropShadower::~DropShadower()
  59447. {
  59448. if (owner != 0)
  59449. owner->removeComponentListener (this);
  59450. inDestructor = true;
  59451. deleteShadowWindows();
  59452. }
  59453. void DropShadower::deleteShadowWindows()
  59454. {
  59455. if (numShadows > 0)
  59456. {
  59457. int i;
  59458. for (i = numShadows; --i >= 0;)
  59459. delete shadowWindows[i];
  59460. for (i = 12; --i >= 0;)
  59461. delete shadowImageSections[i];
  59462. numShadows = 0;
  59463. }
  59464. }
  59465. void DropShadower::setOwner (Component* componentToFollow)
  59466. {
  59467. if (componentToFollow != owner)
  59468. {
  59469. if (owner != 0)
  59470. owner->removeComponentListener (this);
  59471. // (the component can't be null)
  59472. jassert (componentToFollow != 0);
  59473. owner = componentToFollow;
  59474. jassert (owner != 0);
  59475. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59476. owner->addComponentListener (this);
  59477. updateShadows();
  59478. }
  59479. }
  59480. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59481. {
  59482. updateShadows();
  59483. }
  59484. void DropShadower::componentBroughtToFront (Component&)
  59485. {
  59486. bringShadowWindowsToFront();
  59487. }
  59488. void DropShadower::componentChildrenChanged (Component&)
  59489. {
  59490. }
  59491. void DropShadower::componentParentHierarchyChanged (Component&)
  59492. {
  59493. deleteShadowWindows();
  59494. updateShadows();
  59495. }
  59496. void DropShadower::componentVisibilityChanged (Component&)
  59497. {
  59498. updateShadows();
  59499. }
  59500. void DropShadower::updateShadows()
  59501. {
  59502. if (reentrant || inDestructor || (owner == 0))
  59503. return;
  59504. reentrant = true;
  59505. ComponentPeer* const nw = owner->getPeer();
  59506. const bool isOwnerVisible = owner->isVisible()
  59507. && (nw == 0 || ! nw->isMinimised());
  59508. const bool createShadowWindows = numShadows == 0
  59509. && owner->getWidth() > 0
  59510. && owner->getHeight() > 0
  59511. && isOwnerVisible
  59512. && (Desktop::canUseSemiTransparentWindows()
  59513. || owner->getParentComponent() != 0);
  59514. if (createShadowWindows)
  59515. {
  59516. // keep a cached version of the image to save doing the gaussian too often
  59517. String imageId;
  59518. imageId << shadowEdge << T(',')
  59519. << xOffset << T(',')
  59520. << yOffset << T(',')
  59521. << alpha;
  59522. const int hash = imageId.hashCode();
  59523. Image* bigIm = ImageCache::getFromHashCode (hash);
  59524. if (bigIm == 0)
  59525. {
  59526. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59527. Graphics bigG (*bigIm);
  59528. bigG.setColour (Colours::black.withAlpha (alpha));
  59529. bigG.fillRect (shadowEdge + xOffset,
  59530. shadowEdge + yOffset,
  59531. bigIm->getWidth() - (shadowEdge * 2),
  59532. bigIm->getHeight() - (shadowEdge * 2));
  59533. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59534. blurKernel.createGaussianBlur (blurRadius);
  59535. blurKernel.applyToImage (*bigIm, 0,
  59536. xOffset,
  59537. yOffset,
  59538. bigIm->getWidth(),
  59539. bigIm->getHeight());
  59540. ImageCache::addImageToCache (bigIm, hash);
  59541. }
  59542. const int iw = bigIm->getWidth();
  59543. const int ih = bigIm->getHeight();
  59544. const int shadowEdge2 = shadowEdge * 2;
  59545. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59546. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59547. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59548. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59549. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59550. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59551. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59552. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59553. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59554. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59555. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59556. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59557. ImageCache::release (bigIm);
  59558. for (int i = 0; i < 4; ++i)
  59559. {
  59560. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59561. ++numShadows;
  59562. }
  59563. }
  59564. if (numShadows > 0)
  59565. {
  59566. for (int i = numShadows; --i >= 0;)
  59567. {
  59568. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59569. shadowWindows[i]->setVisible (isOwnerVisible);
  59570. }
  59571. const int x = owner->getX();
  59572. const int y = owner->getY() - shadowEdge;
  59573. const int w = owner->getWidth();
  59574. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59575. shadowWindows[0]->setBounds (x - shadowEdge,
  59576. y,
  59577. shadowEdge,
  59578. h);
  59579. shadowWindows[1]->setBounds (x + w,
  59580. y,
  59581. shadowEdge,
  59582. h);
  59583. shadowWindows[2]->setBounds (x,
  59584. y,
  59585. w,
  59586. shadowEdge);
  59587. shadowWindows[3]->setBounds (x,
  59588. owner->getBottom(),
  59589. w,
  59590. shadowEdge);
  59591. }
  59592. reentrant = false;
  59593. if (createShadowWindows)
  59594. bringShadowWindowsToFront();
  59595. }
  59596. void DropShadower::setShadowImage (Image* const src,
  59597. const int num,
  59598. const int w,
  59599. const int h,
  59600. const int sx,
  59601. const int sy)
  59602. {
  59603. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59604. Graphics g (*shadowImageSections[num]);
  59605. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59606. }
  59607. void DropShadower::bringShadowWindowsToFront()
  59608. {
  59609. if (! (inDestructor || reentrant))
  59610. {
  59611. updateShadows();
  59612. reentrant = true;
  59613. for (int i = numShadows; --i >= 0;)
  59614. shadowWindows[i]->toBehind (owner);
  59615. reentrant = false;
  59616. }
  59617. }
  59618. END_JUCE_NAMESPACE
  59619. /*** End of inlined file: juce_DropShadower.cpp ***/
  59620. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59621. BEGIN_JUCE_NAMESPACE
  59622. class MagnifyingPeer : public ComponentPeer
  59623. {
  59624. public:
  59625. MagnifyingPeer (Component* const component_,
  59626. MagnifierComponent* const magnifierComp_)
  59627. : ComponentPeer (component_, 0),
  59628. magnifierComp (magnifierComp_)
  59629. {
  59630. }
  59631. ~MagnifyingPeer()
  59632. {
  59633. }
  59634. void* getNativeHandle() const { return 0; }
  59635. void setVisible (bool) {}
  59636. void setTitle (const String&) {}
  59637. void setPosition (int, int) {}
  59638. void setSize (int, int) {}
  59639. void setBounds (int, int, int, int, const bool) {}
  59640. void setMinimised (bool) {}
  59641. bool isMinimised() const { return false; }
  59642. void setFullScreen (bool) {}
  59643. bool isFullScreen() const { return false; }
  59644. const BorderSize getFrameSize() const { return BorderSize (0); }
  59645. bool setAlwaysOnTop (bool) { return true; }
  59646. void toFront (bool) {}
  59647. void toBehind (ComponentPeer*) {}
  59648. void setIcon (const Image&) {}
  59649. bool isFocused() const
  59650. {
  59651. return magnifierComp->hasKeyboardFocus (true);
  59652. }
  59653. void grabFocus()
  59654. {
  59655. ComponentPeer* peer = magnifierComp->getPeer();
  59656. if (peer != 0)
  59657. peer->grabFocus();
  59658. }
  59659. void textInputRequired (const Point<int>& position)
  59660. {
  59661. ComponentPeer* peer = magnifierComp->getPeer();
  59662. if (peer != 0)
  59663. peer->textInputRequired (position);
  59664. }
  59665. void getBounds (int& x, int& y, int& w, int& h) const
  59666. {
  59667. x = magnifierComp->getScreenX();
  59668. y = magnifierComp->getScreenY();
  59669. w = component->getWidth();
  59670. h = 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. const 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. const 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 (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(), 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 (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 (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 (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 (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. const 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. const 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. const 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. AlertTextComp (const AlertTextComp&);
  61080. const AlertTextComp& operator= (const AlertTextComp&);
  61081. int bestWidth;
  61082. public:
  61083. AlertTextComp (const String& message,
  61084. const Font& font)
  61085. {
  61086. setReadOnly (true);
  61087. setMultiLine (true, true);
  61088. setCaretVisible (false);
  61089. setScrollbarsShown (true);
  61090. lookAndFeelChanged();
  61091. setWantsKeyboardFocus (false);
  61092. setFont (font);
  61093. setText (message, false);
  61094. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  61095. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  61096. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  61097. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  61098. }
  61099. ~AlertTextComp()
  61100. {
  61101. }
  61102. int getPreferredWidth() const throw() { return bestWidth; }
  61103. void updateLayout (const int width)
  61104. {
  61105. TextLayout text;
  61106. text.appendText (getText(), getFont());
  61107. text.layout (width - 8, Justification::topLeft, true);
  61108. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  61109. }
  61110. };
  61111. void AlertWindow::addTextBlock (const String& text)
  61112. {
  61113. AlertTextComp* const c = new AlertTextComp (text, font);
  61114. textBlocks.add (c);
  61115. allComps.add (c);
  61116. addAndMakeVisible (c);
  61117. updateLayout (false);
  61118. }
  61119. void AlertWindow::addProgressBarComponent (double& progressValue)
  61120. {
  61121. ProgressBar* const pb = new ProgressBar (progressValue);
  61122. progressBars.add (pb);
  61123. allComps.add (pb);
  61124. addAndMakeVisible (pb);
  61125. updateLayout (false);
  61126. }
  61127. void AlertWindow::addCustomComponent (Component* const component)
  61128. {
  61129. customComps.add (component);
  61130. allComps.add (component);
  61131. addAndMakeVisible (component);
  61132. updateLayout (false);
  61133. }
  61134. int AlertWindow::getNumCustomComponents() const
  61135. {
  61136. return customComps.size();
  61137. }
  61138. Component* AlertWindow::getCustomComponent (const int index) const
  61139. {
  61140. return (Component*) customComps [index];
  61141. }
  61142. Component* AlertWindow::removeCustomComponent (const int index)
  61143. {
  61144. Component* const c = getCustomComponent (index);
  61145. if (c != 0)
  61146. {
  61147. customComps.removeValue (c);
  61148. allComps.removeValue (c);
  61149. removeChildComponent (c);
  61150. updateLayout (false);
  61151. }
  61152. return c;
  61153. }
  61154. void AlertWindow::paint (Graphics& g)
  61155. {
  61156. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  61157. g.setColour (findColour (textColourId));
  61158. g.setFont (getLookAndFeel().getAlertWindowFont());
  61159. int i;
  61160. for (i = textBoxes.size(); --i >= 0;)
  61161. {
  61162. const TextEditor* const te = (TextEditor*) textBoxes[i];
  61163. g.drawFittedText (textboxNames[i],
  61164. te->getX(), te->getY() - 14,
  61165. te->getWidth(), 14,
  61166. Justification::centredLeft, 1);
  61167. }
  61168. for (i = comboBoxNames.size(); --i >= 0;)
  61169. {
  61170. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61171. g.drawFittedText (comboBoxNames[i],
  61172. cb->getX(), cb->getY() - 14,
  61173. cb->getWidth(), 14,
  61174. Justification::centredLeft, 1);
  61175. }
  61176. for (i = customComps.size(); --i >= 0;)
  61177. {
  61178. const Component* const c = (Component*) customComps[i];
  61179. g.drawFittedText (c->getName(),
  61180. c->getX(), c->getY() - 14,
  61181. c->getWidth(), 14,
  61182. Justification::centredLeft, 1);
  61183. }
  61184. }
  61185. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61186. {
  61187. const int wid = jmax (font.getStringWidth (text),
  61188. font.getStringWidth (getName()));
  61189. const int sw = (int) sqrt (font.getHeight() * wid);
  61190. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61191. const int edgeGap = 10;
  61192. const int labelHeight = 18;
  61193. int iconSpace;
  61194. if (alertIconType == NoIcon)
  61195. {
  61196. textLayout.layout (w, Justification::horizontallyCentred, true);
  61197. iconSpace = 0;
  61198. }
  61199. else
  61200. {
  61201. textLayout.layout (w, Justification::left, true);
  61202. iconSpace = iconWidth;
  61203. }
  61204. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61205. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61206. const int textLayoutH = textLayout.getHeight();
  61207. const int textBottom = 16 + titleH + textLayoutH;
  61208. int h = textBottom;
  61209. int buttonW = 40;
  61210. int i;
  61211. for (i = 0; i < buttons.size(); ++i)
  61212. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61213. w = jmax (buttonW, w);
  61214. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61215. if (buttons.size() > 0)
  61216. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61217. for (i = customComps.size(); --i >= 0;)
  61218. {
  61219. Component* c = (Component*) customComps[i];
  61220. w = jmax (w, (c->getWidth() * 100) / 80);
  61221. h += 10 + c->getHeight();
  61222. if (c->getName().isNotEmpty())
  61223. h += labelHeight;
  61224. }
  61225. for (i = textBlocks.size(); --i >= 0;)
  61226. {
  61227. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61228. w = jmax (w, ac->getPreferredWidth());
  61229. }
  61230. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61231. for (i = textBlocks.size(); --i >= 0;)
  61232. {
  61233. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61234. ac->updateLayout ((int) (w * 0.8f));
  61235. h += ac->getHeight() + 10;
  61236. }
  61237. h = jmin (getParentHeight() - 50, h);
  61238. if (onlyIncreaseSize)
  61239. {
  61240. w = jmax (w, getWidth());
  61241. h = jmax (h, getHeight());
  61242. }
  61243. if (! isVisible())
  61244. {
  61245. centreAroundComponent (associatedComponent, w, h);
  61246. }
  61247. else
  61248. {
  61249. const int cx = getX() + getWidth() / 2;
  61250. const int cy = getY() + getHeight() / 2;
  61251. setBounds (cx - w / 2,
  61252. cy - h / 2,
  61253. w, h);
  61254. }
  61255. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61256. const int spacer = 16;
  61257. int totalWidth = -spacer;
  61258. for (i = buttons.size(); --i >= 0;)
  61259. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61260. int x = (w - totalWidth) / 2;
  61261. int y = (int) (getHeight() * 0.95f);
  61262. for (i = 0; i < buttons.size(); ++i)
  61263. {
  61264. TextButton* const c = (TextButton*) buttons[i];
  61265. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61266. c->setTopLeftPosition (x, ny);
  61267. if (ny < y)
  61268. y = ny;
  61269. x += c->getWidth() + spacer;
  61270. c->toFront (false);
  61271. }
  61272. y = textBottom;
  61273. for (i = 0; i < allComps.size(); ++i)
  61274. {
  61275. Component* const c = (Component*) allComps[i];
  61276. int h = 22;
  61277. const int comboIndex = comboBoxes.indexOf (c);
  61278. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61279. y += labelHeight;
  61280. const int tbIndex = textBoxes.indexOf (c);
  61281. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61282. y += labelHeight;
  61283. if (customComps.contains (c))
  61284. {
  61285. if (c->getName().isNotEmpty())
  61286. y += labelHeight;
  61287. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61288. h = c->getHeight();
  61289. }
  61290. else if (textBlocks.contains (c))
  61291. {
  61292. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61293. h = c->getHeight();
  61294. }
  61295. else
  61296. {
  61297. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61298. }
  61299. y += h + 10;
  61300. }
  61301. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61302. }
  61303. bool AlertWindow::containsAnyExtraComponents() const
  61304. {
  61305. return textBoxes.size()
  61306. + comboBoxes.size()
  61307. + progressBars.size()
  61308. + customComps.size() > 0;
  61309. }
  61310. void AlertWindow::mouseDown (const MouseEvent&)
  61311. {
  61312. dragger.startDraggingComponent (this, &constrainer);
  61313. }
  61314. void AlertWindow::mouseDrag (const MouseEvent& e)
  61315. {
  61316. dragger.dragComponent (this, e);
  61317. }
  61318. bool AlertWindow::keyPressed (const KeyPress& key)
  61319. {
  61320. for (int i = buttons.size(); --i >= 0;)
  61321. {
  61322. TextButton* const b = (TextButton*) buttons[i];
  61323. if (b->isRegisteredForShortcut (key))
  61324. {
  61325. b->triggerClick();
  61326. return true;
  61327. }
  61328. }
  61329. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61330. {
  61331. exitModalState (0);
  61332. return true;
  61333. }
  61334. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61335. {
  61336. ((TextButton*) buttons.getFirst())->triggerClick();
  61337. return true;
  61338. }
  61339. return false;
  61340. }
  61341. void AlertWindow::lookAndFeelChanged()
  61342. {
  61343. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61344. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61345. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61346. }
  61347. int AlertWindow::getDesktopWindowStyleFlags() const
  61348. {
  61349. return getLookAndFeel().getAlertBoxWindowFlags();
  61350. }
  61351. struct AlertWindowInfo
  61352. {
  61353. String title, message, button1, button2, button3;
  61354. AlertWindow::AlertIconType iconType;
  61355. int numButtons;
  61356. Component* associatedComponent;
  61357. int run() const
  61358. {
  61359. return (int) (pointer_sized_int)
  61360. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61361. }
  61362. private:
  61363. int show() const
  61364. {
  61365. jassert (associatedComponent == 0 || associatedComponent->isValidComponent()); // has your comp been deleted?
  61366. LookAndFeel& lf = associatedComponent->isValidComponent() ? associatedComponent->getLookAndFeel()
  61367. : LookAndFeel::getDefaultLookAndFeel();
  61368. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61369. iconType, numButtons, associatedComponent));
  61370. jassert (alertBox != 0); // you have to return one of these!
  61371. return alertBox->runModalLoop();
  61372. }
  61373. static void* showCallback (void* userData)
  61374. {
  61375. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61376. }
  61377. };
  61378. void AlertWindow::showMessageBox (AlertIconType iconType,
  61379. const String& title,
  61380. const String& message,
  61381. const String& buttonText,
  61382. Component* associatedComponent)
  61383. {
  61384. AlertWindowInfo info;
  61385. info.title = title;
  61386. info.message = message;
  61387. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61388. info.iconType = iconType;
  61389. info.numButtons = 1;
  61390. info.associatedComponent = associatedComponent;
  61391. info.run();
  61392. }
  61393. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61394. const String& title,
  61395. const String& message,
  61396. const String& button1Text,
  61397. const String& button2Text,
  61398. Component* associatedComponent)
  61399. {
  61400. AlertWindowInfo info;
  61401. info.title = title;
  61402. info.message = message;
  61403. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61404. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61405. info.iconType = iconType;
  61406. info.numButtons = 2;
  61407. info.associatedComponent = associatedComponent;
  61408. return info.run() != 0;
  61409. }
  61410. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61411. const String& title,
  61412. const String& message,
  61413. const String& button1Text,
  61414. const String& button2Text,
  61415. const String& button3Text,
  61416. Component* associatedComponent)
  61417. {
  61418. AlertWindowInfo info;
  61419. info.title = title;
  61420. info.message = message;
  61421. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61422. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61423. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61424. info.iconType = iconType;
  61425. info.numButtons = 3;
  61426. info.associatedComponent = associatedComponent;
  61427. return info.run();
  61428. }
  61429. END_JUCE_NAMESPACE
  61430. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61431. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61432. BEGIN_JUCE_NAMESPACE
  61433. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61434. static const int fakeMouseMoveMessage = 0x7fff00ff;
  61435. static VoidArray heavyweightPeers;
  61436. ComponentPeer::ComponentPeer (Component* const component_,
  61437. const int styleFlags_) throw()
  61438. : component (component_),
  61439. styleFlags (styleFlags_),
  61440. lastPaintTime (0),
  61441. constrainer (0),
  61442. lastFocusedComponent (0),
  61443. lastDragAndDropCompUnderMouse (0),
  61444. fakeMouseMessageSent (false),
  61445. isWindowMinimised (false)
  61446. {
  61447. heavyweightPeers.add (this);
  61448. }
  61449. ComponentPeer::~ComponentPeer()
  61450. {
  61451. heavyweightPeers.removeValue (this);
  61452. Desktop::getInstance().triggerFocusCallback();
  61453. }
  61454. int ComponentPeer::getNumPeers() throw()
  61455. {
  61456. return heavyweightPeers.size();
  61457. }
  61458. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61459. {
  61460. return (ComponentPeer*) heavyweightPeers [index];
  61461. }
  61462. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61463. {
  61464. for (int i = heavyweightPeers.size(); --i >= 0;)
  61465. {
  61466. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61467. if (peer->getComponent() == component)
  61468. return peer;
  61469. }
  61470. return 0;
  61471. }
  61472. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61473. {
  61474. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61475. }
  61476. void ComponentPeer::updateCurrentModifiers() throw()
  61477. {
  61478. ModifierKeys::updateCurrentModifiers();
  61479. }
  61480. void ComponentPeer::handleMouseEnter (int x, int y, const int64 time)
  61481. {
  61482. jassert (component->isValidComponent());
  61483. updateCurrentModifiers();
  61484. Component* c = component->getComponentAt (x, y);
  61485. const ComponentDeletionWatcher deletionChecker (component);
  61486. if (c != Component::componentUnderMouse && Component::componentUnderMouse != 0)
  61487. {
  61488. jassert (Component::componentUnderMouse->isValidComponent());
  61489. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point<int> (x, y)));
  61490. Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time);
  61491. Component::componentUnderMouse = 0;
  61492. if (deletionChecker.hasBeenDeleted())
  61493. return;
  61494. c = component->getComponentAt (x, y);
  61495. }
  61496. Component::componentUnderMouse = c;
  61497. if (Component::componentUnderMouse != 0)
  61498. {
  61499. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point<int> (x, y)));
  61500. Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time);
  61501. }
  61502. }
  61503. void ComponentPeer::handleMouseMove (int x, int y, const int64 time)
  61504. {
  61505. jassert (component->isValidComponent());
  61506. updateCurrentModifiers();
  61507. fakeMouseMessageSent = false;
  61508. const ComponentDeletionWatcher deletionChecker (component);
  61509. Component* c = component->getComponentAt (x, y);
  61510. if (c != Component::componentUnderMouse)
  61511. {
  61512. if (Component::componentUnderMouse != 0)
  61513. {
  61514. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point<int> (x, y)));
  61515. Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time);
  61516. Component::componentUnderMouse = 0;
  61517. if (deletionChecker.hasBeenDeleted())
  61518. return; // if this window has just been deleted..
  61519. c = component->getComponentAt (x, y);
  61520. }
  61521. Component::componentUnderMouse = c;
  61522. if (c != 0)
  61523. {
  61524. const Point<int> relPos (component->relativePositionToOtherComponent (c, Point<int> (x, y)));
  61525. c->internalMouseEnter (relPos.getX(), relPos.getY(), time);
  61526. if (deletionChecker.hasBeenDeleted())
  61527. return; // if this window has just been deleted..
  61528. }
  61529. }
  61530. if (Component::componentUnderMouse != 0)
  61531. {
  61532. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point<int> (x, y)));
  61533. Component::componentUnderMouse->internalMouseMove (relPos.getX(), relPos.getY(), time);
  61534. }
  61535. }
  61536. void ComponentPeer::handleMouseDown (int x, int y, const int64 time)
  61537. {
  61538. Desktop::getInstance().incrementMouseClickCounter();
  61539. updateCurrentModifiers();
  61540. if (ModifierKeys::getCurrentModifiers().getNumMouseButtonsDown() == 1)
  61541. {
  61542. Component::componentUnderMouse = component->getComponentAt (x, y);
  61543. if (Component::componentUnderMouse != 0)
  61544. {
  61545. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point<int> (x, y)));
  61546. Component::componentUnderMouse->internalMouseDown (relPos.getX(), relPos.getY(), time);
  61547. }
  61548. }
  61549. }
  61550. void ComponentPeer::handleMouseDrag (int x, int y, const int64 time)
  61551. {
  61552. updateCurrentModifiers();
  61553. if (Component::componentUnderMouse != 0)
  61554. {
  61555. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point<int> (x, y)));
  61556. Component::componentUnderMouse->internalMouseDrag (relPos.getX(), relPos.getY(), time);
  61557. }
  61558. }
  61559. void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const int64 time)
  61560. {
  61561. updateCurrentModifiers();
  61562. if (ModifierKeys (oldModifiers).getNumMouseButtonsDown() == 1)
  61563. {
  61564. const ComponentDeletionWatcher deletionChecker (component);
  61565. Component* c = component->getComponentAt (x, y);
  61566. if (c != Component::componentUnderMouse)
  61567. {
  61568. if (Component::componentUnderMouse != 0)
  61569. {
  61570. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point<int> (x, y)));
  61571. Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time);
  61572. if (Component::componentUnderMouse != 0)
  61573. Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time);
  61574. if (deletionChecker.hasBeenDeleted())
  61575. return;
  61576. c = component->getComponentAt (x, y);
  61577. }
  61578. Component::componentUnderMouse = c;
  61579. if (Component::componentUnderMouse != 0)
  61580. {
  61581. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point<int> (x, y)));
  61582. Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time);
  61583. }
  61584. }
  61585. else
  61586. {
  61587. if (Component::componentUnderMouse != 0)
  61588. {
  61589. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point<int> (x, y)));
  61590. Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time);
  61591. }
  61592. }
  61593. }
  61594. }
  61595. void ComponentPeer::handleMouseExit (int x, int y, const int64 time)
  61596. {
  61597. jassert (component->isValidComponent());
  61598. updateCurrentModifiers();
  61599. if (Component::componentUnderMouse != 0)
  61600. {
  61601. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point<int> (x, y)));
  61602. Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time);
  61603. Component::componentUnderMouse = 0;
  61604. }
  61605. }
  61606. void ComponentPeer::handleMouseWheel (const int amountX, const int amountY, const int64 time)
  61607. {
  61608. updateCurrentModifiers();
  61609. if (Component::componentUnderMouse != 0)
  61610. Component::componentUnderMouse->internalMouseWheel (amountX, amountY, time);
  61611. }
  61612. void ComponentPeer::sendFakeMouseMove() throw()
  61613. {
  61614. if ((! fakeMouseMessageSent)
  61615. && component->flags.hasHeavyweightPeerFlag
  61616. && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61617. {
  61618. if (! isMinimised())
  61619. {
  61620. int realX, realY, realW, realH;
  61621. getBounds (realX, realY, realW, realH);
  61622. component->bounds_.setBounds (realX, realY, realW, realH);
  61623. }
  61624. const Point<int> pos (component->getMouseXYRelative());
  61625. if (((unsigned int) pos.getX()) < (unsigned int) component->getWidth()
  61626. && ((unsigned int) pos.getY()) < (unsigned int) component->getHeight()
  61627. && contains (pos.getX(), pos.getY(), false))
  61628. {
  61629. postMessage (new Message (fakeMouseMoveMessage, pos.getX(), pos.getY(), 0));
  61630. }
  61631. fakeMouseMessageSent = true;
  61632. }
  61633. }
  61634. void ComponentPeer::handleMessage (const Message& message)
  61635. {
  61636. if (message.intParameter1 == fakeMouseMoveMessage)
  61637. {
  61638. if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61639. handleMouseMove (message.intParameter2,
  61640. message.intParameter3,
  61641. Time::currentTimeMillis());
  61642. }
  61643. }
  61644. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61645. {
  61646. Graphics g (&contextToPaintTo);
  61647. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61648. g.saveState();
  61649. #endif
  61650. JUCE_TRY
  61651. {
  61652. component->paintEntireComponent (g);
  61653. }
  61654. JUCE_CATCH_EXCEPTION
  61655. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61656. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61657. // clearly when things are being repainted.
  61658. {
  61659. g.restoreState();
  61660. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61661. (uint8) Random::getSystemRandom().nextInt (255),
  61662. (uint8) Random::getSystemRandom().nextInt (255),
  61663. (uint8) 0x50));
  61664. }
  61665. #endif
  61666. }
  61667. bool ComponentPeer::handleKeyPress (const int keyCode,
  61668. const juce_wchar textCharacter)
  61669. {
  61670. updateCurrentModifiers();
  61671. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61672. ? Component::currentlyFocusedComponent
  61673. : component;
  61674. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61675. {
  61676. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61677. if (currentModalComp != 0)
  61678. target = currentModalComp;
  61679. }
  61680. const KeyPress keyInfo (keyCode,
  61681. ModifierKeys::getCurrentModifiers().getRawFlags()
  61682. & ModifierKeys::allKeyboardModifiers,
  61683. textCharacter);
  61684. bool keyWasUsed = false;
  61685. while (target != 0)
  61686. {
  61687. const ComponentDeletionWatcher deletionChecker (target);
  61688. if (target->keyListeners_ != 0)
  61689. {
  61690. for (int i = target->keyListeners_->size(); --i >= 0;)
  61691. {
  61692. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61693. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61694. return keyWasUsed;
  61695. i = jmin (i, target->keyListeners_->size());
  61696. }
  61697. }
  61698. keyWasUsed = target->keyPressed (keyInfo);
  61699. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61700. break;
  61701. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61702. {
  61703. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61704. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61705. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61706. break;
  61707. }
  61708. target = target->parentComponent_;
  61709. }
  61710. return keyWasUsed;
  61711. }
  61712. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61713. {
  61714. updateCurrentModifiers();
  61715. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61716. ? Component::currentlyFocusedComponent
  61717. : component;
  61718. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61719. {
  61720. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61721. if (currentModalComp != 0)
  61722. target = currentModalComp;
  61723. }
  61724. bool keyWasUsed = false;
  61725. while (target != 0)
  61726. {
  61727. const ComponentDeletionWatcher deletionChecker (target);
  61728. keyWasUsed = target->keyStateChanged (isKeyDown);
  61729. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61730. break;
  61731. if (target->keyListeners_ != 0)
  61732. {
  61733. for (int i = target->keyListeners_->size(); --i >= 0;)
  61734. {
  61735. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61736. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61737. return keyWasUsed;
  61738. i = jmin (i, target->keyListeners_->size());
  61739. }
  61740. }
  61741. target = target->parentComponent_;
  61742. }
  61743. return keyWasUsed;
  61744. }
  61745. void ComponentPeer::handleModifierKeysChange()
  61746. {
  61747. updateCurrentModifiers();
  61748. Component* target = Component::getComponentUnderMouse();
  61749. if (target == 0)
  61750. target = Component::getCurrentlyFocusedComponent();
  61751. if (target == 0)
  61752. target = component;
  61753. if (target->isValidComponent())
  61754. target->internalModifierKeysChanged();
  61755. }
  61756. void ComponentPeer::handleBroughtToFront()
  61757. {
  61758. updateCurrentModifiers();
  61759. if (component != 0)
  61760. component->internalBroughtToFront();
  61761. }
  61762. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61763. {
  61764. constrainer = newConstrainer;
  61765. }
  61766. void ComponentPeer::handleMovedOrResized()
  61767. {
  61768. jassert (component->isValidComponent());
  61769. updateCurrentModifiers();
  61770. const bool nowMinimised = isMinimised();
  61771. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61772. {
  61773. const ComponentDeletionWatcher deletionChecker (component);
  61774. int realX, realY, realW, realH;
  61775. getBounds (realX, realY, realW, realH);
  61776. const bool wasMoved = (component->getX() != realX || component->getY() != realY);
  61777. const bool wasResized = (component->getWidth() != realW || component->getHeight() != realH);
  61778. if (wasMoved || wasResized)
  61779. {
  61780. component->bounds_.setBounds (realX, realY, realW, realH);
  61781. if (wasResized)
  61782. component->repaint();
  61783. component->sendMovedResizedMessages (wasMoved, wasResized);
  61784. if (deletionChecker.hasBeenDeleted())
  61785. return;
  61786. }
  61787. }
  61788. if (isWindowMinimised != nowMinimised)
  61789. {
  61790. isWindowMinimised = nowMinimised;
  61791. component->minimisationStateChanged (nowMinimised);
  61792. component->sendVisibilityChangeMessage();
  61793. }
  61794. if (! isFullScreen())
  61795. lastNonFullscreenBounds = component->getBounds();
  61796. }
  61797. void ComponentPeer::handleFocusGain()
  61798. {
  61799. updateCurrentModifiers();
  61800. if (component->isParentOf (lastFocusedComponent))
  61801. {
  61802. Component::currentlyFocusedComponent = lastFocusedComponent;
  61803. Desktop::getInstance().triggerFocusCallback();
  61804. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61805. }
  61806. else
  61807. {
  61808. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61809. component->grabKeyboardFocus();
  61810. else
  61811. Component::bringModalComponentToFront();
  61812. }
  61813. }
  61814. void ComponentPeer::handleFocusLoss()
  61815. {
  61816. updateCurrentModifiers();
  61817. if (component->hasKeyboardFocus (true))
  61818. {
  61819. lastFocusedComponent = Component::currentlyFocusedComponent;
  61820. if (lastFocusedComponent != 0)
  61821. {
  61822. Component::currentlyFocusedComponent = 0;
  61823. Desktop::getInstance().triggerFocusCallback();
  61824. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61825. }
  61826. }
  61827. }
  61828. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61829. {
  61830. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61831. ? lastFocusedComponent
  61832. : component;
  61833. }
  61834. void ComponentPeer::handleScreenSizeChange()
  61835. {
  61836. updateCurrentModifiers();
  61837. component->parentSizeChanged();
  61838. handleMovedOrResized();
  61839. }
  61840. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61841. {
  61842. lastNonFullscreenBounds = newBounds;
  61843. }
  61844. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61845. {
  61846. return lastNonFullscreenBounds;
  61847. }
  61848. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61849. const StringArray& files,
  61850. FileDragAndDropTarget* const lastOne)
  61851. {
  61852. while (c != 0)
  61853. {
  61854. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61855. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61856. return t;
  61857. c = c->getParentComponent();
  61858. }
  61859. return 0;
  61860. }
  61861. void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y)
  61862. {
  61863. updateCurrentModifiers();
  61864. FileDragAndDropTarget* lastTarget = 0;
  61865. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61866. lastTarget = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61867. FileDragAndDropTarget* newTarget = 0;
  61868. Component* const compUnderMouse = component->getComponentAt (x, y);
  61869. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61870. {
  61871. lastDragAndDropCompUnderMouse = compUnderMouse;
  61872. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61873. if (newTarget != lastTarget)
  61874. {
  61875. if (lastTarget != 0)
  61876. lastTarget->fileDragExit (files);
  61877. dragAndDropTargetComponent = 0;
  61878. if (newTarget != 0)
  61879. {
  61880. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61881. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, Point<int> (x, y)));
  61882. dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast <Component*> (newTarget));
  61883. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61884. }
  61885. }
  61886. }
  61887. else
  61888. {
  61889. newTarget = lastTarget;
  61890. }
  61891. if (newTarget != 0)
  61892. {
  61893. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61894. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, Point<int> (x, y)));
  61895. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61896. }
  61897. }
  61898. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61899. {
  61900. handleFileDragMove (files, -1, -1);
  61901. jassert (dragAndDropTargetComponent == 0);
  61902. lastDragAndDropCompUnderMouse = 0;
  61903. }
  61904. void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y)
  61905. {
  61906. handleFileDragMove (files, x, y);
  61907. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61908. {
  61909. FileDragAndDropTarget* const target = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61910. dragAndDropTargetComponent = 0;
  61911. lastDragAndDropCompUnderMouse = 0;
  61912. if (target != 0)
  61913. {
  61914. Component* const targetComp = dynamic_cast <Component*> (target);
  61915. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61916. {
  61917. targetComp->internalModalInputAttempt();
  61918. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61919. return;
  61920. }
  61921. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, Point<int> (x, y)));
  61922. target->filesDropped (files, pos.getX(), pos.getY());
  61923. }
  61924. }
  61925. }
  61926. void ComponentPeer::handleUserClosingWindow()
  61927. {
  61928. updateCurrentModifiers();
  61929. component->userTriedToCloseWindow();
  61930. }
  61931. void ComponentPeer::bringModalComponentToFront()
  61932. {
  61933. Component::bringModalComponentToFront();
  61934. }
  61935. void ComponentPeer::clearMaskedRegion() throw()
  61936. {
  61937. maskedRegion.clear();
  61938. }
  61939. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61940. {
  61941. maskedRegion.add (x, y, w, h);
  61942. }
  61943. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61944. {
  61945. StringArray s;
  61946. s.add ("Software Renderer");
  61947. return s;
  61948. }
  61949. int ComponentPeer::getCurrentRenderingEngine() throw()
  61950. {
  61951. return 0;
  61952. }
  61953. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61954. {
  61955. }
  61956. END_JUCE_NAMESPACE
  61957. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61958. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61959. BEGIN_JUCE_NAMESPACE
  61960. DialogWindow::DialogWindow (const String& name,
  61961. const Colour& backgroundColour_,
  61962. const bool escapeKeyTriggersCloseButton_,
  61963. const bool addToDesktop_)
  61964. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61965. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61966. {
  61967. }
  61968. DialogWindow::~DialogWindow()
  61969. {
  61970. }
  61971. void DialogWindow::resized()
  61972. {
  61973. DocumentWindow::resized();
  61974. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61975. if (escapeKeyTriggersCloseButton
  61976. && getCloseButton() != 0
  61977. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61978. {
  61979. getCloseButton()->addShortcut (esc);
  61980. }
  61981. }
  61982. class TempDialogWindow : public DialogWindow
  61983. {
  61984. public:
  61985. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61986. : DialogWindow (title, colour, escapeCloses, true)
  61987. {
  61988. }
  61989. ~TempDialogWindow()
  61990. {
  61991. }
  61992. void closeButtonPressed()
  61993. {
  61994. setVisible (false);
  61995. }
  61996. private:
  61997. TempDialogWindow (const TempDialogWindow&);
  61998. const TempDialogWindow& operator= (const TempDialogWindow&);
  61999. };
  62000. int DialogWindow::showModalDialog (const String& dialogTitle,
  62001. Component* contentComponent,
  62002. Component* componentToCentreAround,
  62003. const Colour& colour,
  62004. const bool escapeKeyTriggersCloseButton,
  62005. const bool shouldBeResizable,
  62006. const bool useBottomRightCornerResizer)
  62007. {
  62008. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  62009. dw.setContentComponent (contentComponent, true, true);
  62010. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  62011. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62012. const int result = dw.runModalLoop();
  62013. dw.setContentComponent (0, false);
  62014. return result;
  62015. }
  62016. END_JUCE_NAMESPACE
  62017. /*** End of inlined file: juce_DialogWindow.cpp ***/
  62018. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  62019. BEGIN_JUCE_NAMESPACE
  62020. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  62021. {
  62022. public:
  62023. ButtonListenerProxy (DocumentWindow& owner_)
  62024. : owner (owner_)
  62025. {
  62026. }
  62027. void buttonClicked (Button* button)
  62028. {
  62029. if (button == owner.getMinimiseButton())
  62030. owner.minimiseButtonPressed();
  62031. else if (button == owner.getMaximiseButton())
  62032. owner.maximiseButtonPressed();
  62033. else if (button == owner.getCloseButton())
  62034. owner.closeButtonPressed();
  62035. }
  62036. juce_UseDebuggingNewOperator
  62037. private:
  62038. DocumentWindow& owner;
  62039. ButtonListenerProxy (const ButtonListenerProxy&);
  62040. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  62041. };
  62042. DocumentWindow::DocumentWindow (const String& title,
  62043. const Colour& backgroundColour,
  62044. const int requiredButtons_,
  62045. const bool addToDesktop_)
  62046. : ResizableWindow (title, backgroundColour, addToDesktop_),
  62047. titleBarHeight (26),
  62048. menuBarHeight (24),
  62049. requiredButtons (requiredButtons_),
  62050. #if JUCE_MAC
  62051. positionTitleBarButtonsOnLeft (true),
  62052. #else
  62053. positionTitleBarButtonsOnLeft (false),
  62054. #endif
  62055. drawTitleTextCentred (true),
  62056. menuBarModel (0)
  62057. {
  62058. setResizeLimits (128, 128, 32768, 32768);
  62059. lookAndFeelChanged();
  62060. }
  62061. DocumentWindow::~DocumentWindow()
  62062. {
  62063. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62064. titleBarButtons[i] = 0;
  62065. menuBar = 0;
  62066. }
  62067. void DocumentWindow::repaintTitleBar()
  62068. {
  62069. const Rectangle<int> titleBarArea (getTitleBarArea());
  62070. repaint (titleBarArea.getX(), titleBarArea.getY(),
  62071. titleBarArea.getWidth(), titleBarArea.getHeight());
  62072. }
  62073. void DocumentWindow::setName (const String& newName)
  62074. {
  62075. if (newName != getName())
  62076. {
  62077. Component::setName (newName);
  62078. repaintTitleBar();
  62079. }
  62080. }
  62081. void DocumentWindow::setIcon (const Image* imageToUse)
  62082. {
  62083. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  62084. repaintTitleBar();
  62085. }
  62086. void DocumentWindow::setTitleBarHeight (const int newHeight)
  62087. {
  62088. titleBarHeight = newHeight;
  62089. resized();
  62090. repaintTitleBar();
  62091. }
  62092. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  62093. const bool positionTitleBarButtonsOnLeft_)
  62094. {
  62095. requiredButtons = requiredButtons_;
  62096. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  62097. lookAndFeelChanged();
  62098. }
  62099. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  62100. {
  62101. drawTitleTextCentred = textShouldBeCentred;
  62102. repaintTitleBar();
  62103. }
  62104. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  62105. const int menuBarHeight_)
  62106. {
  62107. if (menuBarModel != menuBarModel_)
  62108. {
  62109. menuBar = 0;
  62110. menuBarModel = menuBarModel_;
  62111. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  62112. : getLookAndFeel().getDefaultMenuBarHeight();
  62113. if (menuBarModel != 0)
  62114. {
  62115. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62116. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  62117. menuBar->setEnabled (isActiveWindow());
  62118. }
  62119. resized();
  62120. }
  62121. }
  62122. void DocumentWindow::closeButtonPressed()
  62123. {
  62124. /* If you've got a close button, you have to override this method to get
  62125. rid of your window!
  62126. If the window is just a pop-up, you should override this method and make
  62127. it delete the window in whatever way is appropriate for your app. E.g. you
  62128. might just want to call "delete this".
  62129. If your app is centred around this window such that the whole app should quit when
  62130. the window is closed, then you will probably want to use this method as an opportunity
  62131. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  62132. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  62133. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  62134. or closing it via the taskbar icon on Windows).
  62135. */
  62136. jassertfalse
  62137. }
  62138. void DocumentWindow::minimiseButtonPressed()
  62139. {
  62140. setMinimised (true);
  62141. }
  62142. void DocumentWindow::maximiseButtonPressed()
  62143. {
  62144. setFullScreen (! isFullScreen());
  62145. }
  62146. void DocumentWindow::paint (Graphics& g)
  62147. {
  62148. ResizableWindow::paint (g);
  62149. if (resizableBorder == 0)
  62150. {
  62151. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  62152. const BorderSize border (getBorderThickness());
  62153. g.fillRect (0, 0, getWidth(), border.getTop());
  62154. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  62155. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  62156. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  62157. }
  62158. const Rectangle<int> titleBarArea (getTitleBarArea());
  62159. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  62160. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  62161. int titleSpaceX1 = 6;
  62162. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  62163. for (int i = 0; i < 3; ++i)
  62164. {
  62165. if (titleBarButtons[i] != 0)
  62166. {
  62167. if (positionTitleBarButtonsOnLeft)
  62168. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  62169. else
  62170. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  62171. }
  62172. }
  62173. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  62174. titleBarArea.getWidth(),
  62175. titleBarArea.getHeight(),
  62176. titleSpaceX1,
  62177. jmax (1, titleSpaceX2 - titleSpaceX1),
  62178. titleBarIcon,
  62179. ! drawTitleTextCentred);
  62180. }
  62181. void DocumentWindow::resized()
  62182. {
  62183. ResizableWindow::resized();
  62184. if (titleBarButtons[1] != 0)
  62185. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  62186. const Rectangle<int> titleBarArea (getTitleBarArea());
  62187. getLookAndFeel()
  62188. .positionDocumentWindowButtons (*this,
  62189. titleBarArea.getX(), titleBarArea.getY(),
  62190. titleBarArea.getWidth(), titleBarArea.getHeight(),
  62191. titleBarButtons[0],
  62192. titleBarButtons[1],
  62193. titleBarButtons[2],
  62194. positionTitleBarButtonsOnLeft);
  62195. if (menuBar != 0)
  62196. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  62197. titleBarArea.getWidth(), menuBarHeight);
  62198. }
  62199. const BorderSize DocumentWindow::getBorderThickness()
  62200. {
  62201. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  62202. ? 0 : (resizableBorder != 0 ? 4 : 1));
  62203. }
  62204. const BorderSize DocumentWindow::getContentComponentBorder()
  62205. {
  62206. BorderSize border (getBorderThickness());
  62207. border.setTop (border.getTop()
  62208. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  62209. + (menuBar != 0 ? menuBarHeight : 0));
  62210. return border;
  62211. }
  62212. int DocumentWindow::getTitleBarHeight() const
  62213. {
  62214. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  62215. }
  62216. const Rectangle<int> DocumentWindow::getTitleBarArea()
  62217. {
  62218. const BorderSize border (getBorderThickness());
  62219. return Rectangle<int> (border.getLeft(), border.getTop(),
  62220. getWidth() - border.getLeftAndRight(),
  62221. getTitleBarHeight());
  62222. }
  62223. Button* DocumentWindow::getCloseButton() const throw()
  62224. {
  62225. return titleBarButtons[2];
  62226. }
  62227. Button* DocumentWindow::getMinimiseButton() const throw()
  62228. {
  62229. return titleBarButtons[0];
  62230. }
  62231. Button* DocumentWindow::getMaximiseButton() const throw()
  62232. {
  62233. return titleBarButtons[1];
  62234. }
  62235. int DocumentWindow::getDesktopWindowStyleFlags() const
  62236. {
  62237. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  62238. if ((requiredButtons & minimiseButton) != 0)
  62239. flags |= ComponentPeer::windowHasMinimiseButton;
  62240. if ((requiredButtons & maximiseButton) != 0)
  62241. flags |= ComponentPeer::windowHasMaximiseButton;
  62242. if ((requiredButtons & closeButton) != 0)
  62243. flags |= ComponentPeer::windowHasCloseButton;
  62244. return flags;
  62245. }
  62246. void DocumentWindow::lookAndFeelChanged()
  62247. {
  62248. int i;
  62249. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  62250. titleBarButtons[i] = 0;
  62251. if (! isUsingNativeTitleBar())
  62252. {
  62253. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  62254. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  62255. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  62256. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  62257. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  62258. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  62259. for (i = 0; i < 3; ++i)
  62260. {
  62261. if (titleBarButtons[i] != 0)
  62262. {
  62263. if (buttonListener == 0)
  62264. buttonListener = new ButtonListenerProxy (*this);
  62265. titleBarButtons[i]->addButtonListener (buttonListener);
  62266. titleBarButtons[i]->setWantsKeyboardFocus (false);
  62267. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62268. Component::addAndMakeVisible (titleBarButtons[i]);
  62269. }
  62270. }
  62271. if (getCloseButton() != 0)
  62272. {
  62273. #if JUCE_MAC
  62274. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  62275. #else
  62276. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  62277. #endif
  62278. }
  62279. }
  62280. activeWindowStatusChanged();
  62281. ResizableWindow::lookAndFeelChanged();
  62282. }
  62283. void DocumentWindow::parentHierarchyChanged()
  62284. {
  62285. lookAndFeelChanged();
  62286. }
  62287. void DocumentWindow::activeWindowStatusChanged()
  62288. {
  62289. ResizableWindow::activeWindowStatusChanged();
  62290. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62291. if (titleBarButtons[i] != 0)
  62292. titleBarButtons[i]->setEnabled (isActiveWindow());
  62293. if (menuBar != 0)
  62294. menuBar->setEnabled (isActiveWindow());
  62295. }
  62296. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  62297. {
  62298. if (getTitleBarArea().contains (e.x, e.y)
  62299. && getMaximiseButton() != 0)
  62300. {
  62301. getMaximiseButton()->triggerClick();
  62302. }
  62303. }
  62304. void DocumentWindow::userTriedToCloseWindow()
  62305. {
  62306. closeButtonPressed();
  62307. }
  62308. END_JUCE_NAMESPACE
  62309. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  62310. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  62311. BEGIN_JUCE_NAMESPACE
  62312. ResizableWindow::ResizableWindow (const String& name,
  62313. const bool addToDesktop_)
  62314. : TopLevelWindow (name, addToDesktop_),
  62315. resizeToFitContent (false),
  62316. fullscreen (false),
  62317. lastNonFullScreenPos (50, 50, 256, 256),
  62318. constrainer (0)
  62319. #ifdef JUCE_DEBUG
  62320. , hasBeenResized (false)
  62321. #endif
  62322. {
  62323. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62324. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62325. if (addToDesktop_)
  62326. Component::addToDesktop (getDesktopWindowStyleFlags());
  62327. }
  62328. ResizableWindow::ResizableWindow (const String& name,
  62329. const Colour& backgroundColour_,
  62330. const bool addToDesktop_)
  62331. : TopLevelWindow (name, addToDesktop_),
  62332. resizeToFitContent (false),
  62333. fullscreen (false),
  62334. lastNonFullScreenPos (50, 50, 256, 256),
  62335. constrainer (0)
  62336. #ifdef JUCE_DEBUG
  62337. , hasBeenResized (false)
  62338. #endif
  62339. {
  62340. setBackgroundColour (backgroundColour_);
  62341. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62342. if (addToDesktop_)
  62343. Component::addToDesktop (getDesktopWindowStyleFlags());
  62344. }
  62345. ResizableWindow::~ResizableWindow()
  62346. {
  62347. resizableCorner = 0;
  62348. resizableBorder = 0;
  62349. contentComponent = 0;
  62350. // have you been adding your own components directly to this window..? tut tut tut.
  62351. // Read the instructions for using a ResizableWindow!
  62352. jassert (getNumChildComponents() == 0);
  62353. }
  62354. int ResizableWindow::getDesktopWindowStyleFlags() const
  62355. {
  62356. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62357. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62358. flags |= ComponentPeer::windowIsResizable;
  62359. return flags;
  62360. }
  62361. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62362. const bool deleteOldOne,
  62363. const bool resizeToFit)
  62364. {
  62365. resizeToFitContent = resizeToFit;
  62366. if (newContentComponent != (Component*) contentComponent)
  62367. {
  62368. if (! deleteOldOne)
  62369. removeChildComponent (contentComponent.release());
  62370. contentComponent = newContentComponent;
  62371. Component::addAndMakeVisible (contentComponent);
  62372. }
  62373. if (resizeToFit)
  62374. childBoundsChanged (contentComponent);
  62375. resized(); // must always be called to position the new content comp
  62376. }
  62377. void ResizableWindow::setContentComponentSize (int width, int height)
  62378. {
  62379. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62380. const BorderSize border (getContentComponentBorder());
  62381. setSize (width + border.getLeftAndRight(),
  62382. height + border.getTopAndBottom());
  62383. }
  62384. const BorderSize ResizableWindow::getBorderThickness()
  62385. {
  62386. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62387. }
  62388. const BorderSize ResizableWindow::getContentComponentBorder()
  62389. {
  62390. return getBorderThickness();
  62391. }
  62392. void ResizableWindow::moved()
  62393. {
  62394. updateLastPos();
  62395. }
  62396. void ResizableWindow::visibilityChanged()
  62397. {
  62398. TopLevelWindow::visibilityChanged();
  62399. updateLastPos();
  62400. }
  62401. void ResizableWindow::resized()
  62402. {
  62403. if (resizableBorder != 0)
  62404. {
  62405. resizableBorder->setVisible (! isFullScreen());
  62406. resizableBorder->setBorderThickness (getBorderThickness());
  62407. resizableBorder->setSize (getWidth(), getHeight());
  62408. resizableBorder->toBack();
  62409. }
  62410. if (resizableCorner != 0)
  62411. {
  62412. resizableCorner->setVisible (! isFullScreen());
  62413. const int resizerSize = 18;
  62414. resizableCorner->setBounds (getWidth() - resizerSize,
  62415. getHeight() - resizerSize,
  62416. resizerSize, resizerSize);
  62417. }
  62418. if (contentComponent != 0)
  62419. contentComponent->setBoundsInset (getContentComponentBorder());
  62420. updateLastPos();
  62421. #ifdef JUCE_DEBUG
  62422. hasBeenResized = true;
  62423. #endif
  62424. }
  62425. void ResizableWindow::childBoundsChanged (Component* child)
  62426. {
  62427. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62428. {
  62429. // not going to look very good if this component has a zero size..
  62430. jassert (child->getWidth() > 0);
  62431. jassert (child->getHeight() > 0);
  62432. const BorderSize borders (getContentComponentBorder());
  62433. setSize (child->getWidth() + borders.getLeftAndRight(),
  62434. child->getHeight() + borders.getTopAndBottom());
  62435. }
  62436. }
  62437. void ResizableWindow::activeWindowStatusChanged()
  62438. {
  62439. const BorderSize borders (getContentComponentBorder());
  62440. repaint (0, 0, getWidth(), borders.getTop());
  62441. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62442. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62443. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62444. }
  62445. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62446. const bool useBottomRightCornerResizer)
  62447. {
  62448. if (shouldBeResizable)
  62449. {
  62450. if (useBottomRightCornerResizer)
  62451. {
  62452. resizableBorder = 0;
  62453. if (resizableCorner == 0)
  62454. {
  62455. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62456. resizableCorner->setAlwaysOnTop (true);
  62457. }
  62458. }
  62459. else
  62460. {
  62461. resizableCorner = 0;
  62462. if (resizableBorder == 0)
  62463. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62464. }
  62465. }
  62466. else
  62467. {
  62468. resizableCorner = 0;
  62469. resizableBorder = 0;
  62470. }
  62471. if (isUsingNativeTitleBar())
  62472. recreateDesktopWindow();
  62473. childBoundsChanged (contentComponent);
  62474. resized();
  62475. }
  62476. bool ResizableWindow::isResizable() const throw()
  62477. {
  62478. return resizableCorner != 0
  62479. || resizableBorder != 0;
  62480. }
  62481. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62482. const int newMinimumHeight,
  62483. const int newMaximumWidth,
  62484. const int newMaximumHeight) throw()
  62485. {
  62486. // if you've set up a custom constrainer then these settings won't have any effect..
  62487. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62488. if (constrainer == 0)
  62489. setConstrainer (&defaultConstrainer);
  62490. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62491. newMaximumWidth, newMaximumHeight);
  62492. setBoundsConstrained (getBounds());
  62493. }
  62494. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62495. {
  62496. if (constrainer != newConstrainer)
  62497. {
  62498. constrainer = newConstrainer;
  62499. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62500. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62501. resizableCorner = 0;
  62502. resizableBorder = 0;
  62503. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62504. ComponentPeer* const peer = getPeer();
  62505. if (peer != 0)
  62506. peer->setConstrainer (newConstrainer);
  62507. }
  62508. }
  62509. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62510. {
  62511. if (constrainer != 0)
  62512. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62513. else
  62514. setBounds (bounds);
  62515. }
  62516. void ResizableWindow::paint (Graphics& g)
  62517. {
  62518. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62519. getBorderThickness(), *this);
  62520. if (! isFullScreen())
  62521. {
  62522. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62523. getBorderThickness(), *this);
  62524. }
  62525. #ifdef JUCE_DEBUG
  62526. /* If this fails, then you've probably written a subclass with a resized()
  62527. callback but forgotten to make it call its parent class's resized() method.
  62528. It's important when you override methods like resized(), moved(),
  62529. etc., that you make sure the base class methods also get called.
  62530. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62531. because your content should all be inside the content component - and it's the
  62532. content component's resized() method that you should be using to do your
  62533. layout.
  62534. */
  62535. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62536. #endif
  62537. }
  62538. void ResizableWindow::lookAndFeelChanged()
  62539. {
  62540. resized();
  62541. if (isOnDesktop())
  62542. {
  62543. Component::addToDesktop (getDesktopWindowStyleFlags());
  62544. ComponentPeer* const peer = getPeer();
  62545. if (peer != 0)
  62546. peer->setConstrainer (constrainer);
  62547. }
  62548. }
  62549. const Colour ResizableWindow::getBackgroundColour() const throw()
  62550. {
  62551. return findColour (backgroundColourId, false);
  62552. }
  62553. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62554. {
  62555. Colour backgroundColour (newColour);
  62556. if (! Desktop::canUseSemiTransparentWindows())
  62557. backgroundColour = newColour.withAlpha (1.0f);
  62558. setColour (backgroundColourId, backgroundColour);
  62559. setOpaque (backgroundColour.isOpaque());
  62560. repaint();
  62561. }
  62562. bool ResizableWindow::isFullScreen() const
  62563. {
  62564. if (isOnDesktop())
  62565. {
  62566. ComponentPeer* const peer = getPeer();
  62567. return peer != 0 && peer->isFullScreen();
  62568. }
  62569. return fullscreen;
  62570. }
  62571. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62572. {
  62573. if (shouldBeFullScreen != isFullScreen())
  62574. {
  62575. updateLastPos();
  62576. fullscreen = shouldBeFullScreen;
  62577. if (isOnDesktop())
  62578. {
  62579. ComponentPeer* const peer = getPeer();
  62580. if (peer != 0)
  62581. {
  62582. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62583. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62584. peer->setFullScreen (shouldBeFullScreen);
  62585. if (! shouldBeFullScreen)
  62586. setBounds (lastPos);
  62587. }
  62588. else
  62589. {
  62590. jassertfalse
  62591. }
  62592. }
  62593. else
  62594. {
  62595. if (shouldBeFullScreen)
  62596. setBounds (0, 0, getParentWidth(), getParentHeight());
  62597. else
  62598. setBounds (lastNonFullScreenPos);
  62599. }
  62600. resized();
  62601. }
  62602. }
  62603. bool ResizableWindow::isMinimised() const
  62604. {
  62605. ComponentPeer* const peer = getPeer();
  62606. return (peer != 0) && peer->isMinimised();
  62607. }
  62608. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62609. {
  62610. if (shouldMinimise != isMinimised())
  62611. {
  62612. ComponentPeer* const peer = getPeer();
  62613. if (peer != 0)
  62614. {
  62615. updateLastPos();
  62616. peer->setMinimised (shouldMinimise);
  62617. }
  62618. else
  62619. {
  62620. jassertfalse
  62621. }
  62622. }
  62623. }
  62624. void ResizableWindow::updateLastPos()
  62625. {
  62626. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62627. {
  62628. lastNonFullScreenPos = getBounds();
  62629. }
  62630. }
  62631. void ResizableWindow::parentSizeChanged()
  62632. {
  62633. if (isFullScreen() && getParentComponent() != 0)
  62634. {
  62635. setBounds (0, 0, getParentWidth(), getParentHeight());
  62636. }
  62637. }
  62638. const String ResizableWindow::getWindowStateAsString()
  62639. {
  62640. updateLastPos();
  62641. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62642. }
  62643. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62644. {
  62645. StringArray tokens;
  62646. tokens.addTokens (s, false);
  62647. tokens.removeEmptyStrings();
  62648. tokens.trim();
  62649. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62650. const int firstCoord = fs ? 1 : 0;
  62651. if (tokens.size() != firstCoord + 4)
  62652. return false;
  62653. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62654. tokens[firstCoord + 1].getIntValue(),
  62655. tokens[firstCoord + 2].getIntValue(),
  62656. tokens[firstCoord + 3].getIntValue());
  62657. if (newPos.isEmpty())
  62658. return false;
  62659. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62660. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62661. if (peer != 0)
  62662. peer->getFrameSize().addTo (newPos);
  62663. if (! screen.contains (newPos))
  62664. {
  62665. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62666. jmin (newPos.getHeight(), screen.getHeight()));
  62667. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62668. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62669. }
  62670. if (peer != 0)
  62671. {
  62672. peer->getFrameSize().subtractFrom (newPos);
  62673. peer->setNonFullScreenBounds (newPos);
  62674. }
  62675. lastNonFullScreenPos = newPos;
  62676. setFullScreen (fs);
  62677. if (! fs)
  62678. setBoundsConstrained (newPos);
  62679. return true;
  62680. }
  62681. void ResizableWindow::mouseDown (const MouseEvent&)
  62682. {
  62683. if (! isFullScreen())
  62684. dragger.startDraggingComponent (this, constrainer);
  62685. }
  62686. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62687. {
  62688. if (! isFullScreen())
  62689. dragger.dragComponent (this, e);
  62690. }
  62691. #ifdef JUCE_DEBUG
  62692. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62693. {
  62694. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62695. manages its child components automatically, and if you add your own it'll cause
  62696. trouble. Instead, use setContentComponent() to give it a component which
  62697. will be automatically resized and kept in the right place - then you can add
  62698. subcomponents to the content comp. See the notes for the ResizableWindow class
  62699. for more info.
  62700. If you really know what you're doing and want to avoid this assertion, just call
  62701. Component::addChildComponent directly.
  62702. */
  62703. jassertfalse
  62704. Component::addChildComponent (child, zOrder);
  62705. }
  62706. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62707. {
  62708. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62709. manages its child components automatically, and if you add your own it'll cause
  62710. trouble. Instead, use setContentComponent() to give it a component which
  62711. will be automatically resized and kept in the right place - then you can add
  62712. subcomponents to the content comp. See the notes for the ResizableWindow class
  62713. for more info.
  62714. If you really know what you're doing and want to avoid this assertion, just call
  62715. Component::addAndMakeVisible directly.
  62716. */
  62717. jassertfalse
  62718. Component::addAndMakeVisible (child, zOrder);
  62719. }
  62720. #endif
  62721. END_JUCE_NAMESPACE
  62722. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62723. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62724. BEGIN_JUCE_NAMESPACE
  62725. SplashScreen::SplashScreen()
  62726. : backgroundImage (0)
  62727. {
  62728. setOpaque (true);
  62729. }
  62730. SplashScreen::~SplashScreen()
  62731. {
  62732. ImageCache::releaseOrDelete (backgroundImage);
  62733. }
  62734. void SplashScreen::show (const String& title,
  62735. Image* const backgroundImage_,
  62736. const int minimumTimeToDisplayFor,
  62737. const bool useDropShadow,
  62738. const bool removeOnMouseClick)
  62739. {
  62740. backgroundImage = backgroundImage_;
  62741. jassert (backgroundImage_ != 0);
  62742. if (backgroundImage_ != 0)
  62743. {
  62744. setOpaque (! backgroundImage_->hasAlphaChannel());
  62745. show (title,
  62746. backgroundImage_->getWidth(),
  62747. backgroundImage_->getHeight(),
  62748. minimumTimeToDisplayFor,
  62749. useDropShadow,
  62750. removeOnMouseClick);
  62751. }
  62752. }
  62753. void SplashScreen::show (const String& title,
  62754. const int width,
  62755. const int height,
  62756. const int minimumTimeToDisplayFor,
  62757. const bool useDropShadow,
  62758. const bool removeOnMouseClick)
  62759. {
  62760. setName (title);
  62761. setAlwaysOnTop (true);
  62762. setVisible (true);
  62763. centreWithSize (width, height);
  62764. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62765. toFront (false);
  62766. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62767. repaint();
  62768. originalClickCounter = removeOnMouseClick
  62769. ? Desktop::getMouseButtonClickCounter()
  62770. : std::numeric_limits<int>::max();
  62771. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62772. startTimer (50);
  62773. }
  62774. void SplashScreen::paint (Graphics& g)
  62775. {
  62776. if (backgroundImage != 0)
  62777. {
  62778. g.setOpacity (1.0f);
  62779. g.drawImage (backgroundImage,
  62780. 0, 0, getWidth(), getHeight(),
  62781. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62782. }
  62783. }
  62784. void SplashScreen::timerCallback()
  62785. {
  62786. if (Time::getCurrentTime() > earliestTimeToDelete
  62787. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62788. {
  62789. delete this;
  62790. }
  62791. }
  62792. END_JUCE_NAMESPACE
  62793. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62794. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62795. BEGIN_JUCE_NAMESPACE
  62796. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62797. const bool hasProgressBar,
  62798. const bool hasCancelButton,
  62799. const int timeOutMsWhenCancelling_,
  62800. const String& cancelButtonText)
  62801. : Thread ("Juce Progress Window"),
  62802. progress (0.0),
  62803. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62804. {
  62805. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62806. .createAlertWindow (title, String::empty, cancelButtonText,
  62807. String::empty, String::empty,
  62808. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62809. if (hasProgressBar)
  62810. alertWindow->addProgressBarComponent (progress);
  62811. }
  62812. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62813. {
  62814. stopThread (timeOutMsWhenCancelling);
  62815. }
  62816. bool ThreadWithProgressWindow::runThread (const int priority)
  62817. {
  62818. startThread (priority);
  62819. startTimer (100);
  62820. {
  62821. const ScopedLock sl (messageLock);
  62822. alertWindow->setMessage (message);
  62823. }
  62824. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62825. stopThread (timeOutMsWhenCancelling);
  62826. alertWindow->setVisible (false);
  62827. return finishedNaturally;
  62828. }
  62829. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62830. {
  62831. progress = newProgress;
  62832. }
  62833. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62834. {
  62835. const ScopedLock sl (messageLock);
  62836. message = newStatusMessage;
  62837. }
  62838. void ThreadWithProgressWindow::timerCallback()
  62839. {
  62840. if (! isThreadRunning())
  62841. {
  62842. // thread has finished normally..
  62843. alertWindow->exitModalState (1);
  62844. alertWindow->setVisible (false);
  62845. }
  62846. else
  62847. {
  62848. const ScopedLock sl (messageLock);
  62849. alertWindow->setMessage (message);
  62850. }
  62851. }
  62852. END_JUCE_NAMESPACE
  62853. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62854. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62855. BEGIN_JUCE_NAMESPACE
  62856. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62857. const int millisecondsBeforeTipAppears_)
  62858. : Component ("tooltip"),
  62859. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62860. lastHideTime (0),
  62861. lastComponentUnderMouse (0),
  62862. changedCompsSinceShown (true)
  62863. {
  62864. startTimer (123);
  62865. setAlwaysOnTop (true);
  62866. setOpaque (true);
  62867. if (parentComponent != 0)
  62868. parentComponent->addChildComponent (this);
  62869. }
  62870. TooltipWindow::~TooltipWindow()
  62871. {
  62872. hide();
  62873. }
  62874. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62875. {
  62876. millisecondsBeforeTipAppears = newTimeMs;
  62877. }
  62878. void TooltipWindow::paint (Graphics& g)
  62879. {
  62880. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62881. }
  62882. void TooltipWindow::mouseEnter (const MouseEvent&)
  62883. {
  62884. hide();
  62885. }
  62886. void TooltipWindow::showFor (const String& tip)
  62887. {
  62888. jassert (tip.isNotEmpty());
  62889. tipShowing = tip;
  62890. Point<int> mousePos (Desktop::getMousePosition());
  62891. if (getParentComponent() != 0)
  62892. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62893. int x, y, w, h;
  62894. getLookAndFeel().getTooltipSize (tip, w, h);
  62895. if (mousePos.getX() > getParentWidth() / 2)
  62896. x = mousePos.getX() - (w + 12);
  62897. else
  62898. x = mousePos.getX() + 24;
  62899. if (mousePos.getY() > getParentHeight() / 2)
  62900. y = mousePos.getY() - (h + 6);
  62901. else
  62902. y = mousePos.getY() + 6;
  62903. setBounds (x, y, w, h);
  62904. setVisible (true);
  62905. if (getParentComponent() == 0)
  62906. {
  62907. addToDesktop (ComponentPeer::windowHasDropShadow
  62908. | ComponentPeer::windowIsTemporary
  62909. | ComponentPeer::windowIgnoresKeyPresses);
  62910. }
  62911. toFront (false);
  62912. }
  62913. const String TooltipWindow::getTipFor (Component* const c)
  62914. {
  62915. if (c->isValidComponent()
  62916. && Process::isForegroundProcess()
  62917. && ! Component::isMouseButtonDownAnywhere())
  62918. {
  62919. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62920. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62921. return ttc->getTooltip();
  62922. }
  62923. return String::empty;
  62924. }
  62925. void TooltipWindow::hide()
  62926. {
  62927. tipShowing = String::empty;
  62928. removeFromDesktop();
  62929. setVisible (false);
  62930. }
  62931. void TooltipWindow::timerCallback()
  62932. {
  62933. const unsigned int now = Time::getApproximateMillisecondCounter();
  62934. Component* const newComp = Component::getComponentUnderMouse();
  62935. const String newTip (getTipFor (newComp));
  62936. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62937. lastComponentUnderMouse = newComp;
  62938. lastTipUnderMouse = newTip;
  62939. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62940. const bool mouseWasClicked = clickCount > mouseClicks;
  62941. mouseClicks = clickCount;
  62942. const Point<int> mousePos (Desktop::getMousePosition());
  62943. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62944. lastMousePos = mousePos;
  62945. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62946. lastCompChangeTime = now;
  62947. if (isVisible() || now < lastHideTime + 500)
  62948. {
  62949. // if a tip is currently visible (or has just disappeared), update to a new one
  62950. // immediately if needed..
  62951. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62952. {
  62953. if (isVisible())
  62954. {
  62955. lastHideTime = now;
  62956. hide();
  62957. }
  62958. }
  62959. else if (tipChanged)
  62960. {
  62961. showFor (newTip);
  62962. }
  62963. }
  62964. else
  62965. {
  62966. // if there isn't currently a tip, but one is needed, only let it
  62967. // appear after a timeout..
  62968. if (newTip.isNotEmpty()
  62969. && newTip != tipShowing
  62970. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62971. {
  62972. showFor (newTip);
  62973. }
  62974. }
  62975. }
  62976. END_JUCE_NAMESPACE
  62977. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62978. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62979. BEGIN_JUCE_NAMESPACE
  62980. class TopLevelWindowManager : public Timer,
  62981. public DeletedAtShutdown
  62982. {
  62983. public:
  62984. TopLevelWindowManager()
  62985. : currentActive (0)
  62986. {
  62987. }
  62988. ~TopLevelWindowManager()
  62989. {
  62990. clearSingletonInstance();
  62991. }
  62992. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62993. void timerCallback()
  62994. {
  62995. startTimer (jmin (1731, getTimerInterval() * 2));
  62996. TopLevelWindow* active = 0;
  62997. if (Process::isForegroundProcess())
  62998. {
  62999. active = currentActive;
  63000. Component* const c = Component::getCurrentlyFocusedComponent();
  63001. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  63002. if (tlw == 0 && c != 0)
  63003. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  63004. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  63005. if (tlw != 0)
  63006. active = tlw;
  63007. }
  63008. if (active != currentActive)
  63009. {
  63010. currentActive = active;
  63011. for (int i = windows.size(); --i >= 0;)
  63012. {
  63013. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  63014. tlw->setWindowActive (isWindowActive (tlw));
  63015. i = jmin (i, windows.size() - 1);
  63016. }
  63017. Desktop::getInstance().triggerFocusCallback();
  63018. }
  63019. }
  63020. bool addWindow (TopLevelWindow* const w) throw()
  63021. {
  63022. windows.add (w);
  63023. startTimer (10);
  63024. return isWindowActive (w);
  63025. }
  63026. void removeWindow (TopLevelWindow* const w) throw()
  63027. {
  63028. startTimer (10);
  63029. if (currentActive == w)
  63030. currentActive = 0;
  63031. windows.removeValue (w);
  63032. if (windows.size() == 0)
  63033. deleteInstance();
  63034. }
  63035. VoidArray windows;
  63036. private:
  63037. TopLevelWindow* currentActive;
  63038. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  63039. {
  63040. return (tlw == currentActive
  63041. || tlw->isParentOf (currentActive)
  63042. || tlw->hasKeyboardFocus (true))
  63043. && tlw->isShowing();
  63044. }
  63045. TopLevelWindowManager (const TopLevelWindowManager&);
  63046. const TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  63047. };
  63048. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  63049. void juce_CheckCurrentlyFocusedTopLevelWindow()
  63050. {
  63051. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  63052. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  63053. }
  63054. TopLevelWindow::TopLevelWindow (const String& name,
  63055. const bool addToDesktop_)
  63056. : Component (name),
  63057. useDropShadow (true),
  63058. useNativeTitleBar (false),
  63059. windowIsActive_ (false)
  63060. {
  63061. setOpaque (true);
  63062. if (addToDesktop_)
  63063. Component::addToDesktop (getDesktopWindowStyleFlags());
  63064. else
  63065. setDropShadowEnabled (true);
  63066. setWantsKeyboardFocus (true);
  63067. setBroughtToFrontOnMouseClick (true);
  63068. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  63069. }
  63070. TopLevelWindow::~TopLevelWindow()
  63071. {
  63072. shadower = 0;
  63073. TopLevelWindowManager::getInstance()->removeWindow (this);
  63074. }
  63075. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  63076. {
  63077. if (hasKeyboardFocus (true))
  63078. TopLevelWindowManager::getInstance()->timerCallback();
  63079. else
  63080. TopLevelWindowManager::getInstance()->startTimer (10);
  63081. }
  63082. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  63083. {
  63084. if (windowIsActive_ != isNowActive)
  63085. {
  63086. windowIsActive_ = isNowActive;
  63087. activeWindowStatusChanged();
  63088. }
  63089. }
  63090. void TopLevelWindow::activeWindowStatusChanged()
  63091. {
  63092. }
  63093. void TopLevelWindow::parentHierarchyChanged()
  63094. {
  63095. setDropShadowEnabled (useDropShadow);
  63096. }
  63097. void TopLevelWindow::visibilityChanged()
  63098. {
  63099. if (isShowing())
  63100. toFront (true);
  63101. }
  63102. int TopLevelWindow::getDesktopWindowStyleFlags() const
  63103. {
  63104. int flags = ComponentPeer::windowAppearsOnTaskbar;
  63105. if (useDropShadow)
  63106. flags |= ComponentPeer::windowHasDropShadow;
  63107. if (useNativeTitleBar)
  63108. flags |= ComponentPeer::windowHasTitleBar;
  63109. return flags;
  63110. }
  63111. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  63112. {
  63113. useDropShadow = useShadow;
  63114. if (isOnDesktop())
  63115. {
  63116. shadower = 0;
  63117. Component::addToDesktop (getDesktopWindowStyleFlags());
  63118. }
  63119. else
  63120. {
  63121. if (useShadow && isOpaque())
  63122. {
  63123. if (shadower == 0)
  63124. {
  63125. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  63126. if (shadower != 0)
  63127. shadower->setOwner (this);
  63128. }
  63129. }
  63130. else
  63131. {
  63132. shadower = 0;
  63133. }
  63134. }
  63135. }
  63136. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  63137. {
  63138. if (useNativeTitleBar != useNativeTitleBar_)
  63139. {
  63140. useNativeTitleBar = useNativeTitleBar_;
  63141. recreateDesktopWindow();
  63142. sendLookAndFeelChange();
  63143. }
  63144. }
  63145. void TopLevelWindow::recreateDesktopWindow()
  63146. {
  63147. if (isOnDesktop())
  63148. {
  63149. Component::addToDesktop (getDesktopWindowStyleFlags());
  63150. toFront (true);
  63151. }
  63152. }
  63153. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  63154. {
  63155. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  63156. because this class needs to make sure its layout corresponds with settings like whether
  63157. it's got a native title bar or not.
  63158. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  63159. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  63160. method, then add or remove whatever flags are necessary from this value before returning it.
  63161. */
  63162. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  63163. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  63164. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  63165. if (windowStyleFlags != getDesktopWindowStyleFlags())
  63166. sendLookAndFeelChange();
  63167. }
  63168. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  63169. {
  63170. if (c == 0)
  63171. c = TopLevelWindow::getActiveTopLevelWindow();
  63172. if (c == 0)
  63173. {
  63174. centreWithSize (width, height);
  63175. }
  63176. else
  63177. {
  63178. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  63179. (c->getHeight() - height) / 2)));
  63180. Rectangle<int> parentArea (c->getParentMonitorArea());
  63181. if (getParentComponent() != 0)
  63182. {
  63183. p = getParentComponent()->globalPositionToRelative (p);
  63184. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  63185. }
  63186. parentArea.reduce (12, 12);
  63187. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  63188. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  63189. width, height);
  63190. }
  63191. }
  63192. int TopLevelWindow::getNumTopLevelWindows() throw()
  63193. {
  63194. return TopLevelWindowManager::getInstance()->windows.size();
  63195. }
  63196. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  63197. {
  63198. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  63199. }
  63200. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  63201. {
  63202. TopLevelWindow* best = 0;
  63203. int bestNumTWLParents = -1;
  63204. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  63205. {
  63206. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  63207. if (tlw->isActiveWindow())
  63208. {
  63209. int numTWLParents = 0;
  63210. const Component* c = tlw->getParentComponent();
  63211. while (c != 0)
  63212. {
  63213. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  63214. ++numTWLParents;
  63215. c = c->getParentComponent();
  63216. }
  63217. if (bestNumTWLParents < numTWLParents)
  63218. {
  63219. best = tlw;
  63220. bestNumTWLParents = numTWLParents;
  63221. }
  63222. }
  63223. }
  63224. return best;
  63225. }
  63226. END_JUCE_NAMESPACE
  63227. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  63228. /*** Start of inlined file: juce_Colour.cpp ***/
  63229. BEGIN_JUCE_NAMESPACE
  63230. static uint8 floatAlphaToInt (const float alpha)
  63231. {
  63232. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  63233. }
  63234. static const float oneOver255 = 1.0f / 255.0f;
  63235. Colour::Colour() throw()
  63236. : argb (0)
  63237. {
  63238. }
  63239. Colour::Colour (const Colour& other) throw()
  63240. : argb (other.argb)
  63241. {
  63242. }
  63243. const Colour& Colour::operator= (const Colour& other) throw()
  63244. {
  63245. argb = other.argb;
  63246. return *this;
  63247. }
  63248. bool Colour::operator== (const Colour& other) const throw()
  63249. {
  63250. return argb.getARGB() == other.argb.getARGB();
  63251. }
  63252. bool Colour::operator!= (const Colour& other) const throw()
  63253. {
  63254. return argb.getARGB() != other.argb.getARGB();
  63255. }
  63256. Colour::Colour (const uint32 argb_) throw()
  63257. : argb (argb_)
  63258. {
  63259. }
  63260. Colour::Colour (const uint8 red,
  63261. const uint8 green,
  63262. const uint8 blue) throw()
  63263. {
  63264. argb.setARGB (0xff, red, green, blue);
  63265. }
  63266. const Colour Colour::fromRGB (const uint8 red,
  63267. const uint8 green,
  63268. const uint8 blue) throw()
  63269. {
  63270. return Colour (red, green, blue);
  63271. }
  63272. Colour::Colour (const uint8 red,
  63273. const uint8 green,
  63274. const uint8 blue,
  63275. const uint8 alpha) throw()
  63276. {
  63277. argb.setARGB (alpha, red, green, blue);
  63278. }
  63279. const Colour Colour::fromRGBA (const uint8 red,
  63280. const uint8 green,
  63281. const uint8 blue,
  63282. const uint8 alpha) throw()
  63283. {
  63284. return Colour (red, green, blue, alpha);
  63285. }
  63286. Colour::Colour (const uint8 red,
  63287. const uint8 green,
  63288. const uint8 blue,
  63289. const float alpha) throw()
  63290. {
  63291. argb.setARGB (floatAlphaToInt (alpha), red, green, blue);
  63292. }
  63293. const Colour Colour::fromRGBAFloat (const uint8 red,
  63294. const uint8 green,
  63295. const uint8 blue,
  63296. const float alpha) throw()
  63297. {
  63298. return Colour (red, green, blue, alpha);
  63299. }
  63300. static void convertHSBtoRGB (float h, float s, float v,
  63301. uint8& r, uint8& g, uint8& b) throw()
  63302. {
  63303. v = jlimit (0.0f, 1.0f, v);
  63304. v *= 255.0f;
  63305. const uint8 intV = (uint8) roundToInt (v);
  63306. if (s <= 0)
  63307. {
  63308. r = intV;
  63309. g = intV;
  63310. b = intV;
  63311. }
  63312. else
  63313. {
  63314. s = jmin (1.0f, s);
  63315. h = jlimit (0.0f, 1.0f, h);
  63316. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  63317. const float f = h - floorf (h);
  63318. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  63319. const float y = v * (1.0f - s * f);
  63320. const float z = v * (1.0f - (s * (1.0f - f)));
  63321. if (h < 1.0f)
  63322. {
  63323. r = intV;
  63324. g = (uint8) roundToInt (z);
  63325. b = x;
  63326. }
  63327. else if (h < 2.0f)
  63328. {
  63329. r = (uint8) roundToInt (y);
  63330. g = intV;
  63331. b = x;
  63332. }
  63333. else if (h < 3.0f)
  63334. {
  63335. r = x;
  63336. g = intV;
  63337. b = (uint8) roundToInt (z);
  63338. }
  63339. else if (h < 4.0f)
  63340. {
  63341. r = x;
  63342. g = (uint8) roundToInt (y);
  63343. b = intV;
  63344. }
  63345. else if (h < 5.0f)
  63346. {
  63347. r = (uint8) roundToInt (z);
  63348. g = x;
  63349. b = intV;
  63350. }
  63351. else if (h < 6.0f)
  63352. {
  63353. r = intV;
  63354. g = x;
  63355. b = (uint8) roundToInt (y);
  63356. }
  63357. else
  63358. {
  63359. r = 0;
  63360. g = 0;
  63361. b = 0;
  63362. }
  63363. }
  63364. }
  63365. Colour::Colour (const float hue,
  63366. const float saturation,
  63367. const float brightness,
  63368. const float alpha) throw()
  63369. {
  63370. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63371. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63372. argb.setARGB (floatAlphaToInt (alpha), r, g, b);
  63373. }
  63374. const Colour Colour::fromHSV (const float hue,
  63375. const float saturation,
  63376. const float brightness,
  63377. const float alpha) throw()
  63378. {
  63379. return Colour (hue, saturation, brightness, alpha);
  63380. }
  63381. Colour::Colour (const float hue,
  63382. const float saturation,
  63383. const float brightness,
  63384. const uint8 alpha) throw()
  63385. {
  63386. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63387. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63388. argb.setARGB (alpha, r, g, b);
  63389. }
  63390. Colour::~Colour() throw()
  63391. {
  63392. }
  63393. const PixelARGB Colour::getPixelARGB() const throw()
  63394. {
  63395. PixelARGB p (argb);
  63396. p.premultiply();
  63397. return p;
  63398. }
  63399. uint32 Colour::getARGB() const throw()
  63400. {
  63401. return argb.getARGB();
  63402. }
  63403. bool Colour::isTransparent() const throw()
  63404. {
  63405. return getAlpha() == 0;
  63406. }
  63407. bool Colour::isOpaque() const throw()
  63408. {
  63409. return getAlpha() == 0xff;
  63410. }
  63411. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63412. {
  63413. PixelARGB newCol (argb);
  63414. newCol.setAlpha (newAlpha);
  63415. return Colour (newCol.getARGB());
  63416. }
  63417. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63418. {
  63419. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63420. PixelARGB newCol (argb);
  63421. newCol.setAlpha (floatAlphaToInt (newAlpha));
  63422. return Colour (newCol.getARGB());
  63423. }
  63424. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63425. {
  63426. jassert (alphaMultiplier >= 0);
  63427. PixelARGB newCol (argb);
  63428. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63429. return Colour (newCol.getARGB());
  63430. }
  63431. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63432. {
  63433. const int destAlpha = getAlpha();
  63434. if (destAlpha > 0)
  63435. {
  63436. const int invA = 0xff - (int) src.getAlpha();
  63437. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63438. if (resA > 0)
  63439. {
  63440. const int da = (invA * destAlpha) / resA;
  63441. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63442. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63443. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63444. (uint8) resA);
  63445. }
  63446. return *this;
  63447. }
  63448. else
  63449. {
  63450. return src;
  63451. }
  63452. }
  63453. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63454. {
  63455. if (proportionOfOther <= 0)
  63456. return *this;
  63457. if (proportionOfOther >= 1.0f)
  63458. return other;
  63459. PixelARGB c1 (getPixelARGB());
  63460. const PixelARGB c2 (other.getPixelARGB());
  63461. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63462. c1.unpremultiply();
  63463. return Colour (c1.getARGB());
  63464. }
  63465. float Colour::getFloatRed() const throw()
  63466. {
  63467. return getRed() * oneOver255;
  63468. }
  63469. float Colour::getFloatGreen() const throw()
  63470. {
  63471. return getGreen() * oneOver255;
  63472. }
  63473. float Colour::getFloatBlue() const throw()
  63474. {
  63475. return getBlue() * oneOver255;
  63476. }
  63477. float Colour::getFloatAlpha() const throw()
  63478. {
  63479. return getAlpha() * oneOver255;
  63480. }
  63481. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63482. {
  63483. const int r = getRed();
  63484. const int g = getGreen();
  63485. const int b = getBlue();
  63486. const int hi = jmax (r, g, b);
  63487. const int lo = jmin (r, g, b);
  63488. if (hi != 0)
  63489. {
  63490. s = (hi - lo) / (float) hi;
  63491. if (s != 0)
  63492. {
  63493. const float invDiff = 1.0f / (hi - lo);
  63494. const float red = (hi - r) * invDiff;
  63495. const float green = (hi - g) * invDiff;
  63496. const float blue = (hi - b) * invDiff;
  63497. if (r == hi)
  63498. h = blue - green;
  63499. else if (g == hi)
  63500. h = 2.0f + red - blue;
  63501. else
  63502. h = 4.0f + green - red;
  63503. h *= 1.0f / 6.0f;
  63504. if (h < 0)
  63505. ++h;
  63506. }
  63507. else
  63508. {
  63509. h = 0;
  63510. }
  63511. }
  63512. else
  63513. {
  63514. s = 0;
  63515. h = 0;
  63516. }
  63517. v = hi * oneOver255;
  63518. }
  63519. float Colour::getHue() const throw()
  63520. {
  63521. float h, s, b;
  63522. getHSB (h, s, b);
  63523. return h;
  63524. }
  63525. const Colour Colour::withHue (const float hue) const throw()
  63526. {
  63527. float h, s, b;
  63528. getHSB (h, s, b);
  63529. return Colour (hue, s, b, getAlpha());
  63530. }
  63531. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63532. {
  63533. float h, s, b;
  63534. getHSB (h, s, b);
  63535. h += amountToRotate;
  63536. h -= floorf (h);
  63537. return Colour (h, s, b, getAlpha());
  63538. }
  63539. float Colour::getSaturation() const throw()
  63540. {
  63541. float h, s, b;
  63542. getHSB (h, s, b);
  63543. return s;
  63544. }
  63545. const Colour Colour::withSaturation (const float saturation) const throw()
  63546. {
  63547. float h, s, b;
  63548. getHSB (h, s, b);
  63549. return Colour (h, saturation, b, getAlpha());
  63550. }
  63551. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63552. {
  63553. float h, s, b;
  63554. getHSB (h, s, b);
  63555. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63556. }
  63557. float Colour::getBrightness() const throw()
  63558. {
  63559. float h, s, b;
  63560. getHSB (h, s, b);
  63561. return b;
  63562. }
  63563. const Colour Colour::withBrightness (const float brightness) const throw()
  63564. {
  63565. float h, s, b;
  63566. getHSB (h, s, b);
  63567. return Colour (h, s, brightness, getAlpha());
  63568. }
  63569. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63570. {
  63571. float h, s, b;
  63572. getHSB (h, s, b);
  63573. b *= amount;
  63574. if (b > 1.0f)
  63575. b = 1.0f;
  63576. return Colour (h, s, b, getAlpha());
  63577. }
  63578. const Colour Colour::brighter (float amount) const throw()
  63579. {
  63580. amount = 1.0f / (1.0f + amount);
  63581. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63582. (uint8) (255 - (amount * (255 - getGreen()))),
  63583. (uint8) (255 - (amount * (255 - getBlue()))),
  63584. getAlpha());
  63585. }
  63586. const Colour Colour::darker (float amount) const throw()
  63587. {
  63588. amount = 1.0f / (1.0f + amount);
  63589. return Colour ((uint8) (amount * getRed()),
  63590. (uint8) (amount * getGreen()),
  63591. (uint8) (amount * getBlue()),
  63592. getAlpha());
  63593. }
  63594. const Colour Colour::greyLevel (const float brightness) throw()
  63595. {
  63596. const uint8 level
  63597. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63598. return Colour (level, level, level);
  63599. }
  63600. const Colour Colour::contrasting (const float amount) const throw()
  63601. {
  63602. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63603. ? Colours::black
  63604. : Colours::white).withAlpha (amount));
  63605. }
  63606. const Colour Colour::contrasting (const Colour& colour1,
  63607. const Colour& colour2) throw()
  63608. {
  63609. const float b1 = colour1.getBrightness();
  63610. const float b2 = colour2.getBrightness();
  63611. float best = 0.0f;
  63612. float bestDist = 0.0f;
  63613. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63614. {
  63615. const float d1 = fabsf (i - b1);
  63616. const float d2 = fabsf (i - b2);
  63617. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63618. if (dist > bestDist)
  63619. {
  63620. best = i;
  63621. bestDist = dist;
  63622. }
  63623. }
  63624. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63625. .withBrightness (best);
  63626. }
  63627. const String Colour::toString() const throw()
  63628. {
  63629. return String::toHexString ((int) argb.getARGB());
  63630. }
  63631. const Colour Colour::fromString (const String& encodedColourString)
  63632. {
  63633. return Colour ((uint32) encodedColourString.getHexValue32());
  63634. }
  63635. END_JUCE_NAMESPACE
  63636. /*** End of inlined file: juce_Colour.cpp ***/
  63637. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63638. BEGIN_JUCE_NAMESPACE
  63639. ColourGradient::ColourGradient() throw()
  63640. {
  63641. #ifdef JUCE_DEBUG
  63642. x1 = 987654.0f;
  63643. #endif
  63644. }
  63645. ColourGradient::ColourGradient (const Colour& colour1,
  63646. const float x1_,
  63647. const float y1_,
  63648. const Colour& colour2,
  63649. const float x2_,
  63650. const float y2_,
  63651. const bool isRadial_) throw()
  63652. : x1 (x1_),
  63653. y1 (y1_),
  63654. x2 (x2_),
  63655. y2 (y2_),
  63656. isRadial (isRadial_)
  63657. {
  63658. colours.add (0);
  63659. colours.add (colour1.getARGB());
  63660. colours.add (1 << 16);
  63661. colours.add (colour2.getARGB());
  63662. }
  63663. ColourGradient::~ColourGradient() throw()
  63664. {
  63665. }
  63666. void ColourGradient::clearColours() throw()
  63667. {
  63668. colours.clear();
  63669. }
  63670. void ColourGradient::addColour (const double proportionAlongGradient,
  63671. const Colour& colour) throw()
  63672. {
  63673. // must be within the two end-points
  63674. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63675. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63676. int i;
  63677. for (i = 0; i < colours.size(); i += 2)
  63678. if (colours.getUnchecked(i) > pos)
  63679. break;
  63680. colours.insert (i, pos);
  63681. colours.insert (i + 1, colour.getARGB());
  63682. }
  63683. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63684. {
  63685. for (int i = 1; i < colours.size(); i += 2)
  63686. {
  63687. const Colour c (colours.getUnchecked(i));
  63688. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63689. }
  63690. }
  63691. int ColourGradient::getNumColours() const throw()
  63692. {
  63693. return colours.size() >> 1;
  63694. }
  63695. double ColourGradient::getColourPosition (const int index) const throw()
  63696. {
  63697. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63698. }
  63699. const Colour ColourGradient::getColour (const int index) const throw()
  63700. {
  63701. return Colour (colours [(index << 1) + 1]);
  63702. }
  63703. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63704. {
  63705. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63706. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63707. if (integerPos <= 0 || colours.size() <= 2)
  63708. return getColour (0);
  63709. int i = colours.size() - 2;
  63710. while (integerPos < (int) colours.getUnchecked(i))
  63711. i -= 2;
  63712. if (i >= colours.size() - 2)
  63713. return Colour (colours.getUnchecked(i));
  63714. const int pos1 = colours.getUnchecked (i);
  63715. const Colour col1 (colours.getUnchecked (i + 1));
  63716. const int pos2 = colours.getUnchecked (i + 2);
  63717. const Colour col2 (colours.getUnchecked (i + 3));
  63718. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63719. }
  63720. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63721. {
  63722. #ifdef JUCE_DEBUG
  63723. // trying to use the object without setting its co-ordinates? Have a careful read of
  63724. // the comments for the constructors.
  63725. jassert (x1 != 987654.0f);
  63726. #endif
  63727. const int numColours = colours.size() >> 1;
  63728. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63729. transform.transformPoint (tx1, ty1);
  63730. transform.transformPoint (tx2, ty2);
  63731. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63732. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63733. lookupTable.malloc (numEntries);
  63734. if (numColours >= 2)
  63735. {
  63736. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63737. PixelARGB pix1 (colours.getUnchecked (1));
  63738. pix1.premultiply();
  63739. int index = 0;
  63740. for (int j = 2; j < colours.size(); j += 2)
  63741. {
  63742. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63743. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63744. pix2.premultiply();
  63745. for (int i = 0; i < numToDo; ++i)
  63746. {
  63747. jassert (index >= 0 && index < numEntries);
  63748. lookupTable[index] = pix1;
  63749. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63750. ++index;
  63751. }
  63752. pix1 = pix2;
  63753. }
  63754. while (index < numEntries)
  63755. lookupTable [index++] = pix1;
  63756. }
  63757. else
  63758. {
  63759. jassertfalse // no colours specified!
  63760. }
  63761. return numEntries;
  63762. }
  63763. bool ColourGradient::isOpaque() const throw()
  63764. {
  63765. for (int i = 1; i < colours.size(); i += 2)
  63766. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63767. return false;
  63768. return true;
  63769. }
  63770. bool ColourGradient::isInvisible() const throw()
  63771. {
  63772. for (int i = 1; i < colours.size(); i += 2)
  63773. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63774. return false;
  63775. return true;
  63776. }
  63777. END_JUCE_NAMESPACE
  63778. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63779. /*** Start of inlined file: juce_Colours.cpp ***/
  63780. BEGIN_JUCE_NAMESPACE
  63781. const Colour Colours::transparentBlack (0);
  63782. const Colour Colours::transparentWhite (0x00ffffff);
  63783. const Colour Colours::aliceblue (0xfff0f8ff);
  63784. const Colour Colours::antiquewhite (0xfffaebd7);
  63785. const Colour Colours::aqua (0xff00ffff);
  63786. const Colour Colours::aquamarine (0xff7fffd4);
  63787. const Colour Colours::azure (0xfff0ffff);
  63788. const Colour Colours::beige (0xfff5f5dc);
  63789. const Colour Colours::bisque (0xffffe4c4);
  63790. const Colour Colours::black (0xff000000);
  63791. const Colour Colours::blanchedalmond (0xffffebcd);
  63792. const Colour Colours::blue (0xff0000ff);
  63793. const Colour Colours::blueviolet (0xff8a2be2);
  63794. const Colour Colours::brown (0xffa52a2a);
  63795. const Colour Colours::burlywood (0xffdeb887);
  63796. const Colour Colours::cadetblue (0xff5f9ea0);
  63797. const Colour Colours::chartreuse (0xff7fff00);
  63798. const Colour Colours::chocolate (0xffd2691e);
  63799. const Colour Colours::coral (0xffff7f50);
  63800. const Colour Colours::cornflowerblue (0xff6495ed);
  63801. const Colour Colours::cornsilk (0xfffff8dc);
  63802. const Colour Colours::crimson (0xffdc143c);
  63803. const Colour Colours::cyan (0xff00ffff);
  63804. const Colour Colours::darkblue (0xff00008b);
  63805. const Colour Colours::darkcyan (0xff008b8b);
  63806. const Colour Colours::darkgoldenrod (0xffb8860b);
  63807. const Colour Colours::darkgrey (0xff555555);
  63808. const Colour Colours::darkgreen (0xff006400);
  63809. const Colour Colours::darkkhaki (0xffbdb76b);
  63810. const Colour Colours::darkmagenta (0xff8b008b);
  63811. const Colour Colours::darkolivegreen (0xff556b2f);
  63812. const Colour Colours::darkorange (0xffff8c00);
  63813. const Colour Colours::darkorchid (0xff9932cc);
  63814. const Colour Colours::darkred (0xff8b0000);
  63815. const Colour Colours::darksalmon (0xffe9967a);
  63816. const Colour Colours::darkseagreen (0xff8fbc8f);
  63817. const Colour Colours::darkslateblue (0xff483d8b);
  63818. const Colour Colours::darkslategrey (0xff2f4f4f);
  63819. const Colour Colours::darkturquoise (0xff00ced1);
  63820. const Colour Colours::darkviolet (0xff9400d3);
  63821. const Colour Colours::deeppink (0xffff1493);
  63822. const Colour Colours::deepskyblue (0xff00bfff);
  63823. const Colour Colours::dimgrey (0xff696969);
  63824. const Colour Colours::dodgerblue (0xff1e90ff);
  63825. const Colour Colours::firebrick (0xffb22222);
  63826. const Colour Colours::floralwhite (0xfffffaf0);
  63827. const Colour Colours::forestgreen (0xff228b22);
  63828. const Colour Colours::fuchsia (0xffff00ff);
  63829. const Colour Colours::gainsboro (0xffdcdcdc);
  63830. const Colour Colours::gold (0xffffd700);
  63831. const Colour Colours::goldenrod (0xffdaa520);
  63832. const Colour Colours::grey (0xff808080);
  63833. const Colour Colours::green (0xff008000);
  63834. const Colour Colours::greenyellow (0xffadff2f);
  63835. const Colour Colours::honeydew (0xfff0fff0);
  63836. const Colour Colours::hotpink (0xffff69b4);
  63837. const Colour Colours::indianred (0xffcd5c5c);
  63838. const Colour Colours::indigo (0xff4b0082);
  63839. const Colour Colours::ivory (0xfffffff0);
  63840. const Colour Colours::khaki (0xfff0e68c);
  63841. const Colour Colours::lavender (0xffe6e6fa);
  63842. const Colour Colours::lavenderblush (0xfffff0f5);
  63843. const Colour Colours::lemonchiffon (0xfffffacd);
  63844. const Colour Colours::lightblue (0xffadd8e6);
  63845. const Colour Colours::lightcoral (0xfff08080);
  63846. const Colour Colours::lightcyan (0xffe0ffff);
  63847. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63848. const Colour Colours::lightgreen (0xff90ee90);
  63849. const Colour Colours::lightgrey (0xffd3d3d3);
  63850. const Colour Colours::lightpink (0xffffb6c1);
  63851. const Colour Colours::lightsalmon (0xffffa07a);
  63852. const Colour Colours::lightseagreen (0xff20b2aa);
  63853. const Colour Colours::lightskyblue (0xff87cefa);
  63854. const Colour Colours::lightslategrey (0xff778899);
  63855. const Colour Colours::lightsteelblue (0xffb0c4de);
  63856. const Colour Colours::lightyellow (0xffffffe0);
  63857. const Colour Colours::lime (0xff00ff00);
  63858. const Colour Colours::limegreen (0xff32cd32);
  63859. const Colour Colours::linen (0xfffaf0e6);
  63860. const Colour Colours::magenta (0xffff00ff);
  63861. const Colour Colours::maroon (0xff800000);
  63862. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63863. const Colour Colours::mediumblue (0xff0000cd);
  63864. const Colour Colours::mediumorchid (0xffba55d3);
  63865. const Colour Colours::mediumpurple (0xff9370db);
  63866. const Colour Colours::mediumseagreen (0xff3cb371);
  63867. const Colour Colours::mediumslateblue (0xff7b68ee);
  63868. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63869. const Colour Colours::mediumturquoise (0xff48d1cc);
  63870. const Colour Colours::mediumvioletred (0xffc71585);
  63871. const Colour Colours::midnightblue (0xff191970);
  63872. const Colour Colours::mintcream (0xfff5fffa);
  63873. const Colour Colours::mistyrose (0xffffe4e1);
  63874. const Colour Colours::navajowhite (0xffffdead);
  63875. const Colour Colours::navy (0xff000080);
  63876. const Colour Colours::oldlace (0xfffdf5e6);
  63877. const Colour Colours::olive (0xff808000);
  63878. const Colour Colours::olivedrab (0xff6b8e23);
  63879. const Colour Colours::orange (0xffffa500);
  63880. const Colour Colours::orangered (0xffff4500);
  63881. const Colour Colours::orchid (0xffda70d6);
  63882. const Colour Colours::palegoldenrod (0xffeee8aa);
  63883. const Colour Colours::palegreen (0xff98fb98);
  63884. const Colour Colours::paleturquoise (0xffafeeee);
  63885. const Colour Colours::palevioletred (0xffdb7093);
  63886. const Colour Colours::papayawhip (0xffffefd5);
  63887. const Colour Colours::peachpuff (0xffffdab9);
  63888. const Colour Colours::peru (0xffcd853f);
  63889. const Colour Colours::pink (0xffffc0cb);
  63890. const Colour Colours::plum (0xffdda0dd);
  63891. const Colour Colours::powderblue (0xffb0e0e6);
  63892. const Colour Colours::purple (0xff800080);
  63893. const Colour Colours::red (0xffff0000);
  63894. const Colour Colours::rosybrown (0xffbc8f8f);
  63895. const Colour Colours::royalblue (0xff4169e1);
  63896. const Colour Colours::saddlebrown (0xff8b4513);
  63897. const Colour Colours::salmon (0xfffa8072);
  63898. const Colour Colours::sandybrown (0xfff4a460);
  63899. const Colour Colours::seagreen (0xff2e8b57);
  63900. const Colour Colours::seashell (0xfffff5ee);
  63901. const Colour Colours::sienna (0xffa0522d);
  63902. const Colour Colours::silver (0xffc0c0c0);
  63903. const Colour Colours::skyblue (0xff87ceeb);
  63904. const Colour Colours::slateblue (0xff6a5acd);
  63905. const Colour Colours::slategrey (0xff708090);
  63906. const Colour Colours::snow (0xfffffafa);
  63907. const Colour Colours::springgreen (0xff00ff7f);
  63908. const Colour Colours::steelblue (0xff4682b4);
  63909. const Colour Colours::tan (0xffd2b48c);
  63910. const Colour Colours::teal (0xff008080);
  63911. const Colour Colours::thistle (0xffd8bfd8);
  63912. const Colour Colours::tomato (0xffff6347);
  63913. const Colour Colours::turquoise (0xff40e0d0);
  63914. const Colour Colours::violet (0xffee82ee);
  63915. const Colour Colours::wheat (0xfff5deb3);
  63916. const Colour Colours::white (0xffffffff);
  63917. const Colour Colours::whitesmoke (0xfff5f5f5);
  63918. const Colour Colours::yellow (0xffffff00);
  63919. const Colour Colours::yellowgreen (0xff9acd32);
  63920. const Colour Colours::findColourForName (const String& colourName,
  63921. const Colour& defaultColour)
  63922. {
  63923. static const int presets[] =
  63924. {
  63925. // (first value is the string's hashcode, second is ARGB)
  63926. 0x05978fff, 0xff000000, /* black */
  63927. 0x06bdcc29, 0xffffffff, /* white */
  63928. 0x002e305a, 0xff0000ff, /* blue */
  63929. 0x00308adf, 0xff808080, /* grey */
  63930. 0x05e0cf03, 0xff008000, /* green */
  63931. 0x0001b891, 0xffff0000, /* red */
  63932. 0xd43c6474, 0xffffff00, /* yellow */
  63933. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63934. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63935. 0x002dcebc, 0xff00ffff, /* aqua */
  63936. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63937. 0x0590228f, 0xfff0ffff, /* azure */
  63938. 0x05947fe4, 0xfff5f5dc, /* beige */
  63939. 0xad388e35, 0xffffe4c4, /* bisque */
  63940. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63941. 0x39129959, 0xff8a2be2, /* blueviolet */
  63942. 0x059a8136, 0xffa52a2a, /* brown */
  63943. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63944. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63945. 0x6b748956, 0xff7fff00, /* chartreuse */
  63946. 0x2903623c, 0xffd2691e, /* chocolate */
  63947. 0x05a74431, 0xffff7f50, /* coral */
  63948. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63949. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63950. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63951. 0x002ed323, 0xff00ffff, /* cyan */
  63952. 0x67cc74d0, 0xff00008b, /* darkblue */
  63953. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63954. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63955. 0x67cecf55, 0xff555555, /* darkgrey */
  63956. 0x920b194d, 0xff006400, /* darkgreen */
  63957. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63958. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63959. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63960. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63961. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63962. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63963. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63964. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63965. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63966. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63967. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63968. 0xc8769375, 0xff9400d3, /* darkviolet */
  63969. 0x25832862, 0xffff1493, /* deeppink */
  63970. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63971. 0x634c8b67, 0xff696969, /* dimgrey */
  63972. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63973. 0xef19e3cb, 0xffb22222, /* firebrick */
  63974. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63975. 0xd086fd06, 0xff228b22, /* forestgreen */
  63976. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63977. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63978. 0x00308060, 0xffffd700, /* gold */
  63979. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63980. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63981. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63982. 0x41892743, 0xffff69b4, /* hotpink */
  63983. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63984. 0xb969fed2, 0xff4b0082, /* indigo */
  63985. 0x05fef6a9, 0xfffffff0, /* ivory */
  63986. 0x06149302, 0xfff0e68c, /* khaki */
  63987. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63988. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63989. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63990. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63991. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63992. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63993. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63994. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63995. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63996. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63997. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63998. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63999. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  64000. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  64001. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  64002. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  64003. 0x0032afd5, 0xff00ff00, /* lime */
  64004. 0x607bbc4e, 0xff32cd32, /* limegreen */
  64005. 0x06234efa, 0xfffaf0e6, /* linen */
  64006. 0x316858a9, 0xffff00ff, /* magenta */
  64007. 0xbf8ca470, 0xff800000, /* maroon */
  64008. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  64009. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  64010. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  64011. 0x07556b71, 0xff9370db, /* mediumpurple */
  64012. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  64013. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  64014. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  64015. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  64016. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  64017. 0x168eb32a, 0xff191970, /* midnightblue */
  64018. 0x4306b960, 0xfff5fffa, /* mintcream */
  64019. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  64020. 0xe97218a6, 0xffffdead, /* navajowhite */
  64021. 0x00337bb6, 0xff000080, /* navy */
  64022. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  64023. 0x064ee1db, 0xff808000, /* olive */
  64024. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  64025. 0xc3de262e, 0xffffa500, /* orange */
  64026. 0x58bebba3, 0xffff4500, /* orangered */
  64027. 0xc3def8a3, 0xffda70d6, /* orchid */
  64028. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  64029. 0x3d9dd619, 0xff98fb98, /* palegreen */
  64030. 0x74022737, 0xffafeeee, /* paleturquoise */
  64031. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  64032. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  64033. 0x93e1b776, 0xffffdab9, /* peachpuff */
  64034. 0x003472f8, 0xffcd853f, /* peru */
  64035. 0x00348176, 0xffffc0cb, /* pink */
  64036. 0x00348d94, 0xffdda0dd, /* plum */
  64037. 0xd036be93, 0xffb0e0e6, /* powderblue */
  64038. 0xc5c507bc, 0xff800080, /* purple */
  64039. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  64040. 0xbd9413e1, 0xff4169e1, /* royalblue */
  64041. 0xf456044f, 0xff8b4513, /* saddlebrown */
  64042. 0xc9c6f66e, 0xfffa8072, /* salmon */
  64043. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  64044. 0x34636c14, 0xff2e8b57, /* seagreen */
  64045. 0x3507fb41, 0xfffff5ee, /* seashell */
  64046. 0xca348772, 0xffa0522d, /* sienna */
  64047. 0xca37d30d, 0xffc0c0c0, /* silver */
  64048. 0x80da74fb, 0xff87ceeb, /* skyblue */
  64049. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  64050. 0x44ab37f8, 0xff708090, /* slategrey */
  64051. 0x0035f183, 0xfffffafa, /* snow */
  64052. 0xd5440d16, 0xff00ff7f, /* springgreen */
  64053. 0x3e1524a5, 0xff4682b4, /* steelblue */
  64054. 0x0001bfa1, 0xffd2b48c, /* tan */
  64055. 0x0036425c, 0xff008080, /* teal */
  64056. 0xafc8858f, 0xffd8bfd8, /* thistle */
  64057. 0xcc41600a, 0xffff6347, /* tomato */
  64058. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  64059. 0xcf57947f, 0xffee82ee, /* violet */
  64060. 0x06bdbae7, 0xfff5deb3, /* wheat */
  64061. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  64062. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  64063. };
  64064. const int hash = colourName.trim().toLowerCase().hashCode();
  64065. for (int i = 0; i < numElementsInArray (presets); i += 2)
  64066. if (presets [i] == hash)
  64067. return Colour (presets [i + 1]);
  64068. return defaultColour;
  64069. }
  64070. END_JUCE_NAMESPACE
  64071. /*** End of inlined file: juce_Colours.cpp ***/
  64072. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  64073. BEGIN_JUCE_NAMESPACE
  64074. const int juce_edgeTableDefaultEdgesPerLine = 32;
  64075. static void copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  64076. {
  64077. while (--numLines >= 0)
  64078. {
  64079. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  64080. src += srcLineStride;
  64081. dest += destLineStride;
  64082. }
  64083. }
  64084. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  64085. const Path& path, const AffineTransform& transform) throw()
  64086. : bounds (bounds_),
  64087. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64088. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64089. needToCheckEmptinesss (true)
  64090. {
  64091. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  64092. int* t = table;
  64093. for (int i = bounds.getHeight(); --i >= 0;)
  64094. {
  64095. *t = 0;
  64096. t += lineStrideElements;
  64097. }
  64098. const int topLimit = bounds.getY() << 8;
  64099. const int heightLimit = bounds.getHeight() << 8;
  64100. const int leftLimit = bounds.getX() << 8;
  64101. const int rightLimit = bounds.getRight() << 8;
  64102. PathFlatteningIterator iter (path, transform);
  64103. while (iter.next())
  64104. {
  64105. int y1 = roundToInt (iter.y1 * 256.0f);
  64106. int y2 = roundToInt (iter.y2 * 256.0f);
  64107. if (y1 != y2)
  64108. {
  64109. y1 -= topLimit;
  64110. y2 -= topLimit;
  64111. const int startY = y1;
  64112. int direction = -1;
  64113. if (y1 > y2)
  64114. {
  64115. swapVariables (y1, y2);
  64116. direction = 1;
  64117. }
  64118. if (y1 < 0)
  64119. y1 = 0;
  64120. if (y2 > heightLimit)
  64121. y2 = heightLimit;
  64122. if (y1 < y2)
  64123. {
  64124. const double startX = 256.0f * iter.x1;
  64125. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  64126. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  64127. do
  64128. {
  64129. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  64130. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  64131. if (x < leftLimit)
  64132. x = leftLimit;
  64133. else if (x >= rightLimit)
  64134. x = rightLimit - 1;
  64135. addEdgePoint (x, y1 >> 8, direction * step);
  64136. y1 += step;
  64137. }
  64138. while (y1 < y2);
  64139. }
  64140. }
  64141. }
  64142. sanitiseLevels (path.isUsingNonZeroWinding());
  64143. }
  64144. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd) throw()
  64145. : bounds (rectangleToAdd),
  64146. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64147. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64148. needToCheckEmptinesss (true)
  64149. {
  64150. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64151. table[0] = 0;
  64152. const int x1 = rectangleToAdd.getX() << 8;
  64153. const int x2 = rectangleToAdd.getRight() << 8;
  64154. int* t = table;
  64155. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  64156. {
  64157. t[0] = 2;
  64158. t[1] = x1;
  64159. t[2] = 255;
  64160. t[3] = x2;
  64161. t[4] = 0;
  64162. t += lineStrideElements;
  64163. }
  64164. }
  64165. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd) throw()
  64166. : bounds (rectanglesToAdd.getBounds()),
  64167. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64168. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64169. needToCheckEmptinesss (true)
  64170. {
  64171. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64172. int* t = table;
  64173. for (int i = bounds.getHeight(); --i >= 0;)
  64174. {
  64175. *t = 0;
  64176. t += lineStrideElements;
  64177. }
  64178. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  64179. {
  64180. const Rectangle<int>* const r = iter.getRectangle();
  64181. const int x1 = r->getX() << 8;
  64182. const int x2 = r->getRight() << 8;
  64183. int y = r->getY() - bounds.getY();
  64184. for (int j = r->getHeight(); --j >= 0;)
  64185. {
  64186. addEdgePoint (x1, y, 255);
  64187. addEdgePoint (x2, y, -255);
  64188. ++y;
  64189. }
  64190. }
  64191. sanitiseLevels (true);
  64192. }
  64193. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h) throw()
  64194. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  64195. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64196. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64197. needToCheckEmptinesss (true)
  64198. {
  64199. jassert (w > 0 && h > 0);
  64200. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64201. table[0] = 0;
  64202. const int x1 = roundToInt (x * 256.0f);
  64203. const int x2 = roundToInt ((x + w) * 256.0f);
  64204. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  64205. jassert (y1 < 256);
  64206. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  64207. if (x2 <= x1 || y2 <= y1)
  64208. {
  64209. bounds.setHeight (0);
  64210. return;
  64211. }
  64212. int lineY = 0;
  64213. int* t = table;
  64214. if ((y1 >> 8) == (y2 >> 8))
  64215. {
  64216. t[0] = 2;
  64217. t[1] = x1;
  64218. t[2] = y2 - y1;
  64219. t[3] = x2;
  64220. t[4] = 0;
  64221. ++lineY;
  64222. t += lineStrideElements;
  64223. }
  64224. else
  64225. {
  64226. t[0] = 2;
  64227. t[1] = x1;
  64228. t[2] = 255 - (y1 & 255);
  64229. t[3] = x2;
  64230. t[4] = 0;
  64231. ++lineY;
  64232. t += lineStrideElements;
  64233. while (lineY < (y2 >> 8))
  64234. {
  64235. t[0] = 2;
  64236. t[1] = x1;
  64237. t[2] = 255;
  64238. t[3] = x2;
  64239. t[4] = 0;
  64240. ++lineY;
  64241. t += lineStrideElements;
  64242. }
  64243. jassert (lineY < bounds.getHeight());
  64244. t[0] = 2;
  64245. t[1] = x1;
  64246. t[2] = y2 & 255;
  64247. t[3] = x2;
  64248. t[4] = 0;
  64249. ++lineY;
  64250. t += lineStrideElements;
  64251. }
  64252. while (lineY < bounds.getHeight())
  64253. {
  64254. t[0] = 0;
  64255. t += lineStrideElements;
  64256. ++lineY;
  64257. }
  64258. }
  64259. EdgeTable::EdgeTable (const EdgeTable& other) throw()
  64260. : table (0)
  64261. {
  64262. operator= (other);
  64263. }
  64264. const EdgeTable& EdgeTable::operator= (const EdgeTable& other) throw()
  64265. {
  64266. bounds = other.bounds;
  64267. maxEdgesPerLine = other.maxEdgesPerLine;
  64268. lineStrideElements = other.lineStrideElements;
  64269. needToCheckEmptinesss = other.needToCheckEmptinesss;
  64270. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64271. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  64272. return *this;
  64273. }
  64274. EdgeTable::~EdgeTable() throw()
  64275. {
  64276. }
  64277. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  64278. {
  64279. // Convert the table from relative windings to absolute levels..
  64280. int* lineStart = table;
  64281. for (int i = bounds.getHeight(); --i >= 0;)
  64282. {
  64283. int* line = lineStart;
  64284. lineStart += lineStrideElements;
  64285. int num = *line;
  64286. if (num == 0)
  64287. continue;
  64288. int level = 0;
  64289. if (useNonZeroWinding)
  64290. {
  64291. while (--num > 0)
  64292. {
  64293. line += 2;
  64294. level += *line;
  64295. int corrected = abs (level);
  64296. if (corrected >> 8)
  64297. corrected = 255;
  64298. *line = corrected;
  64299. }
  64300. }
  64301. else
  64302. {
  64303. while (--num > 0)
  64304. {
  64305. line += 2;
  64306. level += *line;
  64307. int corrected = abs (level);
  64308. if (corrected >> 8)
  64309. {
  64310. corrected &= 511;
  64311. if (corrected >> 8)
  64312. corrected = 511 - corrected;
  64313. }
  64314. *line = corrected;
  64315. }
  64316. }
  64317. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64318. }
  64319. }
  64320. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64321. {
  64322. if (newNumEdgesPerLine != maxEdgesPerLine)
  64323. {
  64324. maxEdgesPerLine = newNumEdgesPerLine;
  64325. jassert (bounds.getHeight() > 0);
  64326. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64327. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64328. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64329. table.swapWith (newTable);
  64330. lineStrideElements = newLineStrideElements;
  64331. }
  64332. }
  64333. void EdgeTable::optimiseTable() throw()
  64334. {
  64335. int maxLineElements = 0;
  64336. for (int i = bounds.getHeight(); --i >= 0;)
  64337. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64338. remapTableForNumEdges (maxLineElements);
  64339. }
  64340. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64341. {
  64342. jassert (y >= 0 && y < bounds.getHeight());
  64343. int* line = table + lineStrideElements * y;
  64344. const int numPoints = line[0];
  64345. int n = numPoints << 1;
  64346. if (n > 0)
  64347. {
  64348. while (n > 0)
  64349. {
  64350. const int cx = line [n - 1];
  64351. if (cx <= x)
  64352. {
  64353. if (cx == x)
  64354. {
  64355. line [n] += winding;
  64356. return;
  64357. }
  64358. break;
  64359. }
  64360. n -= 2;
  64361. }
  64362. if (numPoints >= maxEdgesPerLine)
  64363. {
  64364. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64365. jassert (numPoints < maxEdgesPerLine);
  64366. line = table + lineStrideElements * y;
  64367. }
  64368. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64369. }
  64370. line [n + 1] = x;
  64371. line [n + 2] = winding;
  64372. line[0]++;
  64373. }
  64374. void EdgeTable::translate (float dx, int dy) throw()
  64375. {
  64376. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64377. int* lineStart = table;
  64378. const int intDx = (int) (dx * 256.0f);
  64379. for (int i = bounds.getHeight(); --i >= 0;)
  64380. {
  64381. int* line = lineStart;
  64382. lineStart += lineStrideElements;
  64383. int num = *line++;
  64384. while (--num >= 0)
  64385. {
  64386. *line += intDx;
  64387. line += 2;
  64388. }
  64389. }
  64390. }
  64391. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64392. {
  64393. jassert (y >= 0 && y < bounds.getHeight());
  64394. int* dest = table + lineStrideElements * y;
  64395. if (dest[0] == 0)
  64396. return;
  64397. int otherNumPoints = *otherLine;
  64398. if (otherNumPoints == 0)
  64399. {
  64400. *dest = 0;
  64401. return;
  64402. }
  64403. const int right = bounds.getRight() << 8;
  64404. // optimise for the common case where our line lies entirely within a
  64405. // single pair of points, as happens when clipping to a simple rect.
  64406. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64407. {
  64408. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64409. return;
  64410. }
  64411. ++otherLine;
  64412. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64413. int* temp = (int*) alloca (lineSizeBytes);
  64414. memcpy (temp, dest, lineSizeBytes);
  64415. const int* src1 = temp;
  64416. int srcNum1 = *src1++;
  64417. int x1 = *src1++;
  64418. const int* src2 = otherLine;
  64419. int srcNum2 = otherNumPoints;
  64420. int x2 = *src2++;
  64421. int destIndex = 0, destTotal = 0;
  64422. int level1 = 0, level2 = 0;
  64423. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64424. while (srcNum1 > 0 && srcNum2 > 0)
  64425. {
  64426. int nextX;
  64427. if (x1 < x2)
  64428. {
  64429. nextX = x1;
  64430. level1 = *src1++;
  64431. x1 = *src1++;
  64432. --srcNum1;
  64433. }
  64434. else if (x1 == x2)
  64435. {
  64436. nextX = x1;
  64437. level1 = *src1++;
  64438. level2 = *src2++;
  64439. x1 = *src1++;
  64440. x2 = *src2++;
  64441. --srcNum1;
  64442. --srcNum2;
  64443. }
  64444. else
  64445. {
  64446. nextX = x2;
  64447. level2 = *src2++;
  64448. x2 = *src2++;
  64449. --srcNum2;
  64450. }
  64451. if (nextX > lastX)
  64452. {
  64453. if (nextX >= right)
  64454. break;
  64455. lastX = nextX;
  64456. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64457. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64458. if (nextLevel != lastLevel)
  64459. {
  64460. if (destTotal >= maxEdgesPerLine)
  64461. {
  64462. dest[0] = destTotal;
  64463. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64464. dest = table + lineStrideElements * y;
  64465. }
  64466. ++destTotal;
  64467. lastLevel = nextLevel;
  64468. dest[++destIndex] = nextX;
  64469. dest[++destIndex] = nextLevel;
  64470. }
  64471. }
  64472. }
  64473. if (lastLevel > 0)
  64474. {
  64475. if (destTotal >= maxEdgesPerLine)
  64476. {
  64477. dest[0] = destTotal;
  64478. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64479. dest = table + lineStrideElements * y;
  64480. }
  64481. ++destTotal;
  64482. dest[++destIndex] = right;
  64483. dest[++destIndex] = 0;
  64484. }
  64485. dest[0] = destTotal;
  64486. #if JUCE_DEBUG
  64487. int last = std::numeric_limits<int>::min();
  64488. for (int i = 0; i < dest[0]; ++i)
  64489. {
  64490. jassert (dest[i * 2 + 1] > last);
  64491. last = dest[i * 2 + 1];
  64492. }
  64493. jassert (dest [dest[0] * 2] == 0);
  64494. #endif
  64495. }
  64496. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64497. {
  64498. int* lastItem = dest + (dest[0] * 2 - 1);
  64499. if (x2 < lastItem[0])
  64500. {
  64501. if (x2 <= dest[1])
  64502. {
  64503. dest[0] = 0;
  64504. return;
  64505. }
  64506. while (x2 < lastItem[-2])
  64507. {
  64508. --(dest[0]);
  64509. lastItem -= 2;
  64510. }
  64511. lastItem[0] = x2;
  64512. lastItem[1] = 0;
  64513. }
  64514. if (x1 > dest[1])
  64515. {
  64516. while (lastItem[0] > x1)
  64517. lastItem -= 2;
  64518. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64519. if (itemsRemoved > 0)
  64520. {
  64521. dest[0] -= itemsRemoved;
  64522. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64523. }
  64524. dest[1] = x1;
  64525. }
  64526. }
  64527. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64528. {
  64529. const Rectangle<int> clipped (r.getIntersection (bounds));
  64530. if (clipped.isEmpty())
  64531. {
  64532. needToCheckEmptinesss = false;
  64533. bounds.setHeight (0);
  64534. }
  64535. else
  64536. {
  64537. const int top = clipped.getY() - bounds.getY();
  64538. const int bottom = clipped.getBottom() - bounds.getY();
  64539. if (bottom < bounds.getHeight())
  64540. bounds.setHeight (bottom);
  64541. if (clipped.getRight() < bounds.getRight())
  64542. bounds.setRight (clipped.getRight());
  64543. for (int i = top; --i >= 0;)
  64544. table [lineStrideElements * i] = 0;
  64545. if (clipped.getX() > bounds.getX())
  64546. {
  64547. const int x1 = clipped.getX() << 8;
  64548. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64549. int* line = table + lineStrideElements * top;
  64550. for (int i = bottom - top; --i >= 0;)
  64551. {
  64552. if (line[0] != 0)
  64553. clipEdgeTableLineToRange (line, x1, x2);
  64554. line += lineStrideElements;
  64555. }
  64556. }
  64557. needToCheckEmptinesss = true;
  64558. }
  64559. }
  64560. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64561. {
  64562. const Rectangle<int> clipped (r.getIntersection (bounds));
  64563. if (! clipped.isEmpty())
  64564. {
  64565. const int top = clipped.getY() - bounds.getY();
  64566. const int bottom = clipped.getBottom() - bounds.getY();
  64567. //XXX optimise here by shortening the table if it fills top or bottom
  64568. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64569. clipped.getX() << 8, 0,
  64570. clipped.getRight() << 8, 255,
  64571. std::numeric_limits<int>::max(), 0 };
  64572. for (int i = top; i < bottom; ++i)
  64573. intersectWithEdgeTableLine (i, rectLine);
  64574. needToCheckEmptinesss = true;
  64575. }
  64576. }
  64577. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64578. {
  64579. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64580. if (clipped.isEmpty())
  64581. {
  64582. needToCheckEmptinesss = false;
  64583. bounds.setHeight (0);
  64584. }
  64585. else
  64586. {
  64587. const int top = clipped.getY() - bounds.getY();
  64588. const int bottom = clipped.getBottom() - bounds.getY();
  64589. if (bottom < bounds.getHeight())
  64590. bounds.setHeight (bottom);
  64591. if (clipped.getRight() < bounds.getRight())
  64592. bounds.setRight (clipped.getRight());
  64593. int i = 0;
  64594. for (i = top; --i >= 0;)
  64595. table [lineStrideElements * i] = 0;
  64596. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64597. for (i = top; i < bottom; ++i)
  64598. {
  64599. intersectWithEdgeTableLine (i, otherLine);
  64600. otherLine += other.lineStrideElements;
  64601. }
  64602. needToCheckEmptinesss = true;
  64603. }
  64604. }
  64605. void EdgeTable::clipLineToMask (int x, int y, uint8* mask, int maskStride, int numPixels) throw()
  64606. {
  64607. y -= bounds.getY();
  64608. if (y < 0 || y >= bounds.getHeight())
  64609. return;
  64610. needToCheckEmptinesss = true;
  64611. if (numPixels <= 0)
  64612. {
  64613. table [lineStrideElements * y] = 0;
  64614. return;
  64615. }
  64616. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64617. int destIndex = 0, lastLevel = 0;
  64618. while (--numPixels >= 0)
  64619. {
  64620. const int alpha = *mask;
  64621. mask += maskStride;
  64622. if (alpha != lastLevel)
  64623. {
  64624. tempLine[++destIndex] = (x << 8);
  64625. tempLine[++destIndex] = alpha;
  64626. lastLevel = alpha;
  64627. }
  64628. ++x;
  64629. }
  64630. if (lastLevel > 0)
  64631. {
  64632. tempLine[++destIndex] = (x << 8);
  64633. tempLine[++destIndex] = 0;
  64634. }
  64635. tempLine[0] = destIndex >> 1;
  64636. intersectWithEdgeTableLine (y, tempLine);
  64637. }
  64638. bool EdgeTable::isEmpty() throw()
  64639. {
  64640. if (needToCheckEmptinesss)
  64641. {
  64642. needToCheckEmptinesss = false;
  64643. int* t = table;
  64644. for (int i = bounds.getHeight(); --i >= 0;)
  64645. {
  64646. if (t[0] > 1)
  64647. return false;
  64648. t += lineStrideElements;
  64649. }
  64650. bounds.setHeight (0);
  64651. }
  64652. return bounds.getHeight() == 0;
  64653. }
  64654. END_JUCE_NAMESPACE
  64655. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64656. /*** Start of inlined file: juce_FillType.cpp ***/
  64657. BEGIN_JUCE_NAMESPACE
  64658. FillType::FillType() throw()
  64659. : colour (0xff000000), image (0)
  64660. {
  64661. }
  64662. FillType::FillType (const Colour& colour_) throw()
  64663. : colour (colour_), image (0)
  64664. {
  64665. }
  64666. FillType::FillType (const ColourGradient& gradient_) throw()
  64667. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64668. {
  64669. }
  64670. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64671. : colour (0xff000000), image (&image_), transform (transform_)
  64672. {
  64673. }
  64674. FillType::FillType (const FillType& other) throw()
  64675. : colour (other.colour),
  64676. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64677. image (other.image), transform (other.transform)
  64678. {
  64679. }
  64680. const FillType& FillType::operator= (const FillType& other) throw()
  64681. {
  64682. if (this != &other)
  64683. {
  64684. colour = other.colour;
  64685. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64686. image = other.image;
  64687. transform = other.transform;
  64688. }
  64689. return *this;
  64690. }
  64691. FillType::~FillType() throw()
  64692. {
  64693. }
  64694. void FillType::setColour (const Colour& newColour) throw()
  64695. {
  64696. gradient = 0;
  64697. image = 0;
  64698. colour = newColour;
  64699. }
  64700. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64701. {
  64702. if (gradient != 0)
  64703. {
  64704. *gradient = newGradient;
  64705. }
  64706. else
  64707. {
  64708. image = 0;
  64709. gradient = new ColourGradient (newGradient);
  64710. colour = Colours::black;
  64711. }
  64712. }
  64713. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64714. {
  64715. gradient = 0;
  64716. image = &image_;
  64717. transform = transform_;
  64718. colour = Colours::black;
  64719. }
  64720. void FillType::setOpacity (const float newOpacity) throw()
  64721. {
  64722. colour = colour.withAlpha (newOpacity);
  64723. }
  64724. END_JUCE_NAMESPACE
  64725. /*** End of inlined file: juce_FillType.cpp ***/
  64726. /*** Start of inlined file: juce_Graphics.cpp ***/
  64727. BEGIN_JUCE_NAMESPACE
  64728. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64729. template <typename Type>
  64730. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64731. {
  64732. const int maxVal = 0x3fffffff;
  64733. return (int) x >= -maxVal && (int) x <= maxVal
  64734. && (int) y >= -maxVal && (int) y <= maxVal
  64735. && (int) w >= -maxVal && (int) w <= maxVal
  64736. && (int) h >= -maxVal && (int) h <= maxVal;
  64737. }
  64738. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64739. {
  64740. }
  64741. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64742. {
  64743. }
  64744. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64745. : context (imageToDrawOnto.createLowLevelContext()),
  64746. contextToDelete (context),
  64747. saveStatePending (false)
  64748. {
  64749. resetToDefaultState();
  64750. }
  64751. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64752. : context (internalContext),
  64753. saveStatePending (false)
  64754. {
  64755. resetToDefaultState();
  64756. }
  64757. Graphics::~Graphics() throw()
  64758. {
  64759. }
  64760. void Graphics::resetToDefaultState() throw()
  64761. {
  64762. saveStateIfPending();
  64763. context->setFill (FillType());
  64764. context->setFont (Font());
  64765. context->setInterpolationQuality (defaultQuality);
  64766. }
  64767. bool Graphics::isVectorDevice() const throw()
  64768. {
  64769. return context->isVectorDevice();
  64770. }
  64771. bool Graphics::reduceClipRegion (const int x, const int y,
  64772. const int w, const int h) throw()
  64773. {
  64774. saveStateIfPending();
  64775. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64776. }
  64777. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64778. {
  64779. saveStateIfPending();
  64780. return context->clipToRectangleList (clipRegion);
  64781. }
  64782. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64783. {
  64784. saveStateIfPending();
  64785. context->clipToPath (path, transform);
  64786. return ! context->isClipEmpty();
  64787. }
  64788. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64789. {
  64790. saveStateIfPending();
  64791. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64792. return ! context->isClipEmpty();
  64793. }
  64794. void Graphics::excludeClipRegion (const int x, const int y,
  64795. const int w, const int h) throw()
  64796. {
  64797. saveStateIfPending();
  64798. context->excludeClipRectangle (Rectangle<int> (x, y, w, h));
  64799. }
  64800. bool Graphics::isClipEmpty() const throw()
  64801. {
  64802. return context->isClipEmpty();
  64803. }
  64804. const Rectangle<int> Graphics::getClipBounds() const throw()
  64805. {
  64806. return context->getClipBounds();
  64807. }
  64808. void Graphics::saveState() throw()
  64809. {
  64810. saveStateIfPending();
  64811. saveStatePending = true;
  64812. }
  64813. void Graphics::restoreState() throw()
  64814. {
  64815. if (saveStatePending)
  64816. saveStatePending = false;
  64817. else
  64818. context->restoreState();
  64819. }
  64820. void Graphics::saveStateIfPending() throw()
  64821. {
  64822. if (saveStatePending)
  64823. {
  64824. saveStatePending = false;
  64825. context->saveState();
  64826. }
  64827. }
  64828. void Graphics::setOrigin (const int newOriginX,
  64829. const int newOriginY) throw()
  64830. {
  64831. saveStateIfPending();
  64832. context->setOrigin (newOriginX, newOriginY);
  64833. }
  64834. bool Graphics::clipRegionIntersects (const int x, const int y,
  64835. const int w, const int h) const throw()
  64836. {
  64837. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64838. }
  64839. void Graphics::setColour (const Colour& newColour) throw()
  64840. {
  64841. saveStateIfPending();
  64842. context->setFill (FillType (newColour));
  64843. }
  64844. void Graphics::setOpacity (const float newOpacity) throw()
  64845. {
  64846. saveStateIfPending();
  64847. context->setOpacity (newOpacity);
  64848. }
  64849. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64850. {
  64851. saveStateIfPending();
  64852. context->setFill (FillType (gradient));
  64853. }
  64854. void Graphics::setTiledImageFill (const Image& imageToUse,
  64855. const int anchorX,
  64856. const int anchorY,
  64857. const float opacity) throw()
  64858. {
  64859. saveStateIfPending();
  64860. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64861. context->setOpacity (opacity);
  64862. }
  64863. void Graphics::setFillType (const FillType& newFill) throw()
  64864. {
  64865. saveStateIfPending();
  64866. context->setFill (newFill);
  64867. }
  64868. void Graphics::setFont (const Font& newFont) throw()
  64869. {
  64870. saveStateIfPending();
  64871. context->setFont (newFont);
  64872. }
  64873. void Graphics::setFont (const float newFontHeight,
  64874. const int newFontStyleFlags) throw()
  64875. {
  64876. saveStateIfPending();
  64877. Font f (context->getFont());
  64878. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64879. context->setFont (f);
  64880. }
  64881. void Graphics::drawSingleLineText (const String& text,
  64882. const int startX,
  64883. const int baselineY) const throw()
  64884. {
  64885. if (text.isNotEmpty()
  64886. && startX < context->getClipBounds().getRight())
  64887. {
  64888. GlyphArrangement arr;
  64889. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64890. arr.draw (*this);
  64891. }
  64892. }
  64893. void Graphics::drawTextAsPath (const String& text,
  64894. const AffineTransform& transform) const throw()
  64895. {
  64896. if (text.isNotEmpty())
  64897. {
  64898. GlyphArrangement arr;
  64899. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64900. arr.draw (*this, transform);
  64901. }
  64902. }
  64903. void Graphics::drawMultiLineText (const String& text,
  64904. const int startX,
  64905. const int baselineY,
  64906. const int maximumLineWidth) const throw()
  64907. {
  64908. if (text.isNotEmpty()
  64909. && startX < context->getClipBounds().getRight())
  64910. {
  64911. GlyphArrangement arr;
  64912. arr.addJustifiedText (context->getFont(), text,
  64913. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64914. Justification::left);
  64915. arr.draw (*this);
  64916. }
  64917. }
  64918. void Graphics::drawText (const String& text,
  64919. const int x,
  64920. const int y,
  64921. const int width,
  64922. const int height,
  64923. const Justification& justificationType,
  64924. const bool useEllipsesIfTooBig) const throw()
  64925. {
  64926. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64927. {
  64928. GlyphArrangement arr;
  64929. arr.addCurtailedLineOfText (context->getFont(), text,
  64930. 0.0f, 0.0f, (float)width,
  64931. useEllipsesIfTooBig);
  64932. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64933. (float) x, (float) y,
  64934. (float) width, (float) height,
  64935. justificationType);
  64936. arr.draw (*this);
  64937. }
  64938. }
  64939. void Graphics::drawFittedText (const String& text,
  64940. const int x,
  64941. const int y,
  64942. const int width,
  64943. const int height,
  64944. const Justification& justification,
  64945. const int maximumNumberOfLines,
  64946. const float minimumHorizontalScale) const throw()
  64947. {
  64948. if (text.isNotEmpty()
  64949. && width > 0 && height > 0
  64950. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64951. {
  64952. GlyphArrangement arr;
  64953. arr.addFittedText (context->getFont(), text,
  64954. (float) x, (float) y,
  64955. (float) width, (float) height,
  64956. justification,
  64957. maximumNumberOfLines,
  64958. minimumHorizontalScale);
  64959. arr.draw (*this);
  64960. }
  64961. }
  64962. void Graphics::fillRect (int x,
  64963. int y,
  64964. int width,
  64965. int height) const throw()
  64966. {
  64967. // passing in a silly number can cause maths problems in rendering!
  64968. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64969. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64970. }
  64971. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  64972. {
  64973. context->fillRect (r, false);
  64974. }
  64975. void Graphics::fillRect (const float x,
  64976. const float y,
  64977. const float width,
  64978. const float height) const throw()
  64979. {
  64980. // passing in a silly number can cause maths problems in rendering!
  64981. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64982. Path p;
  64983. p.addRectangle (x, y, width, height);
  64984. fillPath (p);
  64985. }
  64986. void Graphics::setPixel (int x, int y) const throw()
  64987. {
  64988. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64989. }
  64990. void Graphics::fillAll() const throw()
  64991. {
  64992. fillRect (context->getClipBounds());
  64993. }
  64994. void Graphics::fillAll (const Colour& colourToUse) const throw()
  64995. {
  64996. if (! colourToUse.isTransparent())
  64997. {
  64998. const Rectangle<int> clip (context->getClipBounds());
  64999. context->saveState();
  65000. context->setFill (FillType (colourToUse));
  65001. context->fillRect (clip, false);
  65002. context->restoreState();
  65003. }
  65004. }
  65005. void Graphics::fillPath (const Path& path,
  65006. const AffineTransform& transform) const throw()
  65007. {
  65008. if ((! context->isClipEmpty()) && ! path.isEmpty())
  65009. context->fillPath (path, transform);
  65010. }
  65011. void Graphics::strokePath (const Path& path,
  65012. const PathStrokeType& strokeType,
  65013. const AffineTransform& transform) const throw()
  65014. {
  65015. Path stroke;
  65016. strokeType.createStrokedPath (stroke, path, transform);
  65017. fillPath (stroke);
  65018. }
  65019. void Graphics::drawRect (const int x,
  65020. const int y,
  65021. const int width,
  65022. const int height,
  65023. const int lineThickness) const throw()
  65024. {
  65025. // passing in a silly number can cause maths problems in rendering!
  65026. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65027. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  65028. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65029. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65030. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  65031. }
  65032. void Graphics::drawRect (const float x,
  65033. const float y,
  65034. const float width,
  65035. const float height,
  65036. const float lineThickness) const throw()
  65037. {
  65038. // passing in a silly number can cause maths problems in rendering!
  65039. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65040. Path p;
  65041. p.addRectangle (x, y, width, lineThickness);
  65042. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65043. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65044. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  65045. fillPath (p);
  65046. }
  65047. void Graphics::drawRect (const Rectangle<int>& r,
  65048. const int lineThickness) const throw()
  65049. {
  65050. drawRect (r.getX(), r.getY(),
  65051. r.getWidth(), r.getHeight(),
  65052. lineThickness);
  65053. }
  65054. void Graphics::drawBevel (const int x,
  65055. const int y,
  65056. const int width,
  65057. const int height,
  65058. const int bevelThickness,
  65059. const Colour& topLeftColour,
  65060. const Colour& bottomRightColour,
  65061. const bool useGradient,
  65062. const bool sharpEdgeOnOutside) const throw()
  65063. {
  65064. // passing in a silly number can cause maths problems in rendering!
  65065. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65066. if (clipRegionIntersects (x, y, width, height))
  65067. {
  65068. context->saveState();
  65069. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  65070. const float ramp = oldOpacity / bevelThickness;
  65071. for (int i = bevelThickness; --i >= 0;)
  65072. {
  65073. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  65074. : oldOpacity;
  65075. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  65076. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  65077. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  65078. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  65079. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  65080. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  65081. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  65082. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  65083. }
  65084. context->restoreState();
  65085. }
  65086. }
  65087. void Graphics::fillEllipse (const float x,
  65088. const float y,
  65089. const float width,
  65090. const float height) const throw()
  65091. {
  65092. // passing in a silly number can cause maths problems in rendering!
  65093. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65094. Path p;
  65095. p.addEllipse (x, y, width, height);
  65096. fillPath (p);
  65097. }
  65098. void Graphics::drawEllipse (const float x,
  65099. const float y,
  65100. const float width,
  65101. const float height,
  65102. const float lineThickness) const throw()
  65103. {
  65104. // passing in a silly number can cause maths problems in rendering!
  65105. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65106. Path p;
  65107. p.addEllipse (x, y, width, height);
  65108. strokePath (p, PathStrokeType (lineThickness));
  65109. }
  65110. void Graphics::fillRoundedRectangle (const float x,
  65111. const float y,
  65112. const float width,
  65113. const float height,
  65114. const float cornerSize) const throw()
  65115. {
  65116. // passing in a silly number can cause maths problems in rendering!
  65117. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65118. Path p;
  65119. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65120. fillPath (p);
  65121. }
  65122. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  65123. const float cornerSize) const throw()
  65124. {
  65125. fillRoundedRectangle ((float) r.getX(),
  65126. (float) r.getY(),
  65127. (float) r.getWidth(),
  65128. (float) r.getHeight(),
  65129. cornerSize);
  65130. }
  65131. void Graphics::drawRoundedRectangle (const float x,
  65132. const float y,
  65133. const float width,
  65134. const float height,
  65135. const float cornerSize,
  65136. const float lineThickness) const throw()
  65137. {
  65138. // passing in a silly number can cause maths problems in rendering!
  65139. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65140. Path p;
  65141. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65142. strokePath (p, PathStrokeType (lineThickness));
  65143. }
  65144. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  65145. const float cornerSize,
  65146. const float lineThickness) const throw()
  65147. {
  65148. drawRoundedRectangle ((float) r.getX(),
  65149. (float) r.getY(),
  65150. (float) r.getWidth(),
  65151. (float) r.getHeight(),
  65152. cornerSize, lineThickness);
  65153. }
  65154. void Graphics::drawArrow (const float startX,
  65155. const float startY,
  65156. const float endX,
  65157. const float endY,
  65158. const float lineThickness,
  65159. const float arrowheadWidth,
  65160. const float arrowheadLength) const throw()
  65161. {
  65162. Path p;
  65163. p.addArrow (startX, startY, endX, endY,
  65164. lineThickness, arrowheadWidth, arrowheadLength);
  65165. fillPath (p);
  65166. }
  65167. void Graphics::fillCheckerBoard (int x, int y,
  65168. int width, int height,
  65169. const int checkWidth,
  65170. const int checkHeight,
  65171. const Colour& colour1,
  65172. const Colour& colour2) const throw()
  65173. {
  65174. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  65175. if (checkWidth > 0 && checkHeight > 0)
  65176. {
  65177. context->saveState();
  65178. if (colour1 == colour2)
  65179. {
  65180. context->setFill (FillType (colour1));
  65181. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65182. }
  65183. else
  65184. {
  65185. const Rectangle<int> clip (context->getClipBounds());
  65186. const int right = jmin (x + width, clip.getRight());
  65187. const int bottom = jmin (y + height, clip.getBottom());
  65188. int cy = 0;
  65189. while (y < bottom)
  65190. {
  65191. int cx = cy;
  65192. for (int xx = x; xx < right; xx += checkWidth)
  65193. {
  65194. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  65195. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  65196. false);
  65197. }
  65198. ++cy;
  65199. y += checkHeight;
  65200. }
  65201. }
  65202. context->restoreState();
  65203. }
  65204. }
  65205. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  65206. {
  65207. context->drawVerticalLine (x, top, bottom);
  65208. }
  65209. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  65210. {
  65211. context->drawHorizontalLine (y, left, right);
  65212. }
  65213. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  65214. {
  65215. context->drawLine (x1, y1, x2, y2);
  65216. }
  65217. void Graphics::drawLine (const float startX,
  65218. const float startY,
  65219. const float endX,
  65220. const float endY,
  65221. const float lineThickness) const throw()
  65222. {
  65223. Path p;
  65224. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  65225. fillPath (p);
  65226. }
  65227. void Graphics::drawLine (const Line& line) const throw()
  65228. {
  65229. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  65230. }
  65231. void Graphics::drawLine (const Line& line,
  65232. const float lineThickness) const throw()
  65233. {
  65234. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  65235. }
  65236. void Graphics::drawDashedLine (const float startX,
  65237. const float startY,
  65238. const float endX,
  65239. const float endY,
  65240. const float* const dashLengths,
  65241. const int numDashLengths,
  65242. const float lineThickness) const throw()
  65243. {
  65244. const double dx = endX - startX;
  65245. const double dy = endY - startY;
  65246. const double totalLen = juce_hypot (dx, dy);
  65247. if (totalLen >= 0.5)
  65248. {
  65249. const double onePixAlpha = 1.0 / totalLen;
  65250. double alpha = 0.0;
  65251. float x = startX;
  65252. float y = startY;
  65253. int n = 0;
  65254. while (alpha < 1.0f)
  65255. {
  65256. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  65257. n = n % numDashLengths;
  65258. const float oldX = x;
  65259. const float oldY = y;
  65260. x = (float) (startX + dx * alpha);
  65261. y = (float) (startY + dy * alpha);
  65262. if ((n & 1) != 0)
  65263. {
  65264. if (lineThickness != 1.0f)
  65265. drawLine (oldX, oldY, x, y, lineThickness);
  65266. else
  65267. drawLine (oldX, oldY, x, y);
  65268. }
  65269. }
  65270. }
  65271. }
  65272. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  65273. {
  65274. saveStateIfPending();
  65275. context->setInterpolationQuality (newQuality);
  65276. }
  65277. void Graphics::drawImageAt (const Image* const imageToDraw,
  65278. const int topLeftX,
  65279. const int topLeftY,
  65280. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65281. {
  65282. if (imageToDraw != 0)
  65283. {
  65284. const int imageW = imageToDraw->getWidth();
  65285. const int imageH = imageToDraw->getHeight();
  65286. drawImage (imageToDraw,
  65287. topLeftX, topLeftY, imageW, imageH,
  65288. 0, 0, imageW, imageH,
  65289. fillAlphaChannelWithCurrentBrush);
  65290. }
  65291. }
  65292. void Graphics::drawImageWithin (const Image* const imageToDraw,
  65293. const int destX,
  65294. const int destY,
  65295. const int destW,
  65296. const int destH,
  65297. const RectanglePlacement& placementWithinTarget,
  65298. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65299. {
  65300. // passing in a silly number can cause maths problems in rendering!
  65301. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  65302. if (imageToDraw != 0)
  65303. {
  65304. const int imageW = imageToDraw->getWidth();
  65305. const int imageH = imageToDraw->getHeight();
  65306. if (imageW > 0 && imageH > 0)
  65307. {
  65308. double newX = 0.0, newY = 0.0;
  65309. double newW = imageW;
  65310. double newH = imageH;
  65311. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65312. destX, destY, destW, destH);
  65313. if (newW > 0 && newH > 0)
  65314. {
  65315. drawImage (imageToDraw,
  65316. roundToInt (newX), roundToInt (newY),
  65317. roundToInt (newW), roundToInt (newH),
  65318. 0, 0, imageW, imageH,
  65319. fillAlphaChannelWithCurrentBrush);
  65320. }
  65321. }
  65322. }
  65323. }
  65324. void Graphics::drawImage (const Image* const imageToDraw,
  65325. int dx, int dy, int dw, int dh,
  65326. int sx, int sy, int sw, int sh,
  65327. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65328. {
  65329. // passing in a silly number can cause maths problems in rendering!
  65330. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65331. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65332. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  65333. {
  65334. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  65335. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65336. .translated ((float) dx, (float) dy),
  65337. fillAlphaChannelWithCurrentBrush);
  65338. }
  65339. }
  65340. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65341. const Rectangle<int>& imageSubRegion,
  65342. const AffineTransform& transform,
  65343. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65344. {
  65345. if (imageToDraw != 0 && ! context->isClipEmpty())
  65346. {
  65347. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65348. if (fillAlphaChannelWithCurrentBrush)
  65349. {
  65350. context->saveState();
  65351. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65352. fillAll();
  65353. context->restoreState();
  65354. }
  65355. else
  65356. {
  65357. context->drawImage (*imageToDraw, srcClip, transform, false);
  65358. }
  65359. }
  65360. }
  65361. END_JUCE_NAMESPACE
  65362. /*** End of inlined file: juce_Graphics.cpp ***/
  65363. /*** Start of inlined file: juce_Justification.cpp ***/
  65364. BEGIN_JUCE_NAMESPACE
  65365. Justification::Justification (const Justification& other) throw()
  65366. : flags (other.flags)
  65367. {
  65368. }
  65369. const Justification& Justification::operator= (const Justification& other) throw()
  65370. {
  65371. flags = other.flags;
  65372. return *this;
  65373. }
  65374. int Justification::getOnlyVerticalFlags() const throw()
  65375. {
  65376. return flags & (top | bottom | verticallyCentred);
  65377. }
  65378. int Justification::getOnlyHorizontalFlags() const throw()
  65379. {
  65380. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65381. }
  65382. void Justification::applyToRectangle (int& x, int& y,
  65383. const int w, const int h,
  65384. const int spaceX, const int spaceY,
  65385. const int spaceW, const int spaceH) const throw()
  65386. {
  65387. if ((flags & horizontallyCentred) != 0)
  65388. {
  65389. x = spaceX + ((spaceW - w) >> 1);
  65390. }
  65391. else if ((flags & right) != 0)
  65392. {
  65393. x = spaceX + spaceW - w;
  65394. }
  65395. else
  65396. {
  65397. x = spaceX;
  65398. }
  65399. if ((flags & verticallyCentred) != 0)
  65400. {
  65401. y = spaceY + ((spaceH - h) >> 1);
  65402. }
  65403. else if ((flags & bottom) != 0)
  65404. {
  65405. y = spaceY + spaceH - h;
  65406. }
  65407. else
  65408. {
  65409. y = spaceY;
  65410. }
  65411. }
  65412. END_JUCE_NAMESPACE
  65413. /*** End of inlined file: juce_Justification.cpp ***/
  65414. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65415. BEGIN_JUCE_NAMESPACE
  65416. // this will throw an assertion if you try to draw something that's not
  65417. // possible in postscript
  65418. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65419. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65420. #define notPossibleInPostscriptAssert jassertfalse
  65421. #else
  65422. #define notPossibleInPostscriptAssert
  65423. #endif
  65424. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65425. const String& documentTitle,
  65426. const int totalWidth_,
  65427. const int totalHeight_)
  65428. : out (resultingPostScript),
  65429. totalWidth (totalWidth_),
  65430. totalHeight (totalHeight_),
  65431. needToClip (true)
  65432. {
  65433. stateStack.add (new SavedState());
  65434. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65435. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65436. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65437. "\n%%BoundingBox: 0 0 600 824"
  65438. "\n%%Pages: 0"
  65439. "\n%%Creator: Raw Material Software JUCE"
  65440. "\n%%Title: " << documentTitle <<
  65441. "\n%%CreationDate: none"
  65442. "\n%%LanguageLevel: 2"
  65443. "\n%%EndComments"
  65444. "\n%%BeginProlog"
  65445. "\n%%BeginResource: JRes"
  65446. "\n/bd {bind def} bind def"
  65447. "\n/c {setrgbcolor} bd"
  65448. "\n/m {moveto} bd"
  65449. "\n/l {lineto} bd"
  65450. "\n/rl {rlineto} bd"
  65451. "\n/ct {curveto} bd"
  65452. "\n/cp {closepath} bd"
  65453. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65454. "\n/doclip {initclip newpath} bd"
  65455. "\n/endclip {clip newpath} bd"
  65456. "\n%%EndResource"
  65457. "\n%%EndProlog"
  65458. "\n%%BeginSetup"
  65459. "\n%%EndSetup"
  65460. "\n%%Page: 1 1"
  65461. "\n%%BeginPageSetup"
  65462. "\n%%EndPageSetup\n\n"
  65463. << "40 800 translate\n"
  65464. << scale << ' ' << scale << " scale\n\n";
  65465. }
  65466. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65467. {
  65468. }
  65469. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65470. {
  65471. return true;
  65472. }
  65473. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65474. {
  65475. if (x != 0 || y != 0)
  65476. {
  65477. stateStack.getLast()->xOffset += x;
  65478. stateStack.getLast()->yOffset += y;
  65479. needToClip = true;
  65480. }
  65481. }
  65482. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65483. {
  65484. needToClip = true;
  65485. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65486. }
  65487. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65488. {
  65489. needToClip = true;
  65490. return stateStack.getLast()->clip.clipTo (clipRegion);
  65491. }
  65492. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65493. {
  65494. needToClip = true;
  65495. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65496. }
  65497. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65498. {
  65499. writeClip();
  65500. Path p (path);
  65501. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65502. writePath (p);
  65503. out << "clip\n";
  65504. }
  65505. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65506. {
  65507. needToClip = true;
  65508. jassertfalse // xxx
  65509. }
  65510. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65511. {
  65512. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65513. }
  65514. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65515. {
  65516. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65517. -stateStack.getLast()->yOffset);
  65518. }
  65519. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65520. {
  65521. return stateStack.getLast()->clip.isEmpty();
  65522. }
  65523. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65524. : xOffset (0),
  65525. yOffset (0)
  65526. {
  65527. }
  65528. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65529. {
  65530. }
  65531. void LowLevelGraphicsPostScriptRenderer::saveState()
  65532. {
  65533. stateStack.add (new SavedState (*stateStack.getLast()));
  65534. }
  65535. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65536. {
  65537. jassert (stateStack.size() > 0);
  65538. if (stateStack.size() > 0)
  65539. stateStack.removeLast();
  65540. }
  65541. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65542. {
  65543. if (needToClip)
  65544. {
  65545. needToClip = false;
  65546. out << "doclip ";
  65547. int itemsOnLine = 0;
  65548. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65549. {
  65550. if (++itemsOnLine == 6)
  65551. {
  65552. itemsOnLine = 0;
  65553. out << '\n';
  65554. }
  65555. const Rectangle<int>& r = *i.getRectangle();
  65556. out << r.getX() << ' ' << -r.getY() << ' '
  65557. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65558. }
  65559. out << "endclip\n";
  65560. }
  65561. }
  65562. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65563. {
  65564. Colour c (Colours::white.overlaidWith (colour));
  65565. if (lastColour != c)
  65566. {
  65567. lastColour = c;
  65568. out << String (c.getFloatRed(), 3) << ' '
  65569. << String (c.getFloatGreen(), 3) << ' '
  65570. << String (c.getFloatBlue(), 3) << " c\n";
  65571. }
  65572. }
  65573. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65574. {
  65575. out << String (x, 2) << ' '
  65576. << String (-y, 2) << ' ';
  65577. }
  65578. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65579. {
  65580. out << "newpath ";
  65581. float lastX = 0.0f;
  65582. float lastY = 0.0f;
  65583. int itemsOnLine = 0;
  65584. Path::Iterator i (path);
  65585. while (i.next())
  65586. {
  65587. if (++itemsOnLine == 4)
  65588. {
  65589. itemsOnLine = 0;
  65590. out << '\n';
  65591. }
  65592. switch (i.elementType)
  65593. {
  65594. case Path::Iterator::startNewSubPath:
  65595. writeXY (i.x1, i.y1);
  65596. lastX = i.x1;
  65597. lastY = i.y1;
  65598. out << "m ";
  65599. break;
  65600. case Path::Iterator::lineTo:
  65601. writeXY (i.x1, i.y1);
  65602. lastX = i.x1;
  65603. lastY = i.y1;
  65604. out << "l ";
  65605. break;
  65606. case Path::Iterator::quadraticTo:
  65607. {
  65608. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65609. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65610. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65611. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65612. writeXY (cp1x, cp1y);
  65613. writeXY (cp2x, cp2y);
  65614. writeXY (i.x2, i.y2);
  65615. out << "ct ";
  65616. lastX = i.x2;
  65617. lastY = i.y2;
  65618. }
  65619. break;
  65620. case Path::Iterator::cubicTo:
  65621. writeXY (i.x1, i.y1);
  65622. writeXY (i.x2, i.y2);
  65623. writeXY (i.x3, i.y3);
  65624. out << "ct ";
  65625. lastX = i.x3;
  65626. lastY = i.y3;
  65627. break;
  65628. case Path::Iterator::closePath:
  65629. out << "cp ";
  65630. break;
  65631. default:
  65632. jassertfalse
  65633. break;
  65634. }
  65635. }
  65636. out << '\n';
  65637. }
  65638. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65639. {
  65640. out << "[ "
  65641. << trans.mat00 << ' '
  65642. << trans.mat10 << ' '
  65643. << trans.mat01 << ' '
  65644. << trans.mat11 << ' '
  65645. << trans.mat02 << ' '
  65646. << trans.mat12 << " ] concat ";
  65647. }
  65648. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65649. {
  65650. stateStack.getLast()->fillType = fillType;
  65651. }
  65652. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65653. {
  65654. }
  65655. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65656. {
  65657. }
  65658. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65659. {
  65660. if (stateStack.getLast()->fillType.isColour())
  65661. {
  65662. writeClip();
  65663. writeColour (stateStack.getLast()->fillType.colour);
  65664. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65665. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65666. }
  65667. else
  65668. {
  65669. Path p;
  65670. p.addRectangle (r);
  65671. fillPath (p, AffineTransform::identity);
  65672. }
  65673. }
  65674. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65675. {
  65676. if (stateStack.getLast()->fillType.isColour())
  65677. {
  65678. writeClip();
  65679. Path p (path);
  65680. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65681. (float) stateStack.getLast()->yOffset));
  65682. writePath (p);
  65683. writeColour (stateStack.getLast()->fillType.colour);
  65684. out << "fill\n";
  65685. }
  65686. else if (stateStack.getLast()->fillType.isGradient())
  65687. {
  65688. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65689. // postscript can't do semi-transparent ones.
  65690. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65691. writeClip();
  65692. out << "gsave ";
  65693. {
  65694. Path p (path);
  65695. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65696. writePath (p);
  65697. out << "clip\n";
  65698. }
  65699. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65700. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65701. // time-being, this just fills it with the average colour..
  65702. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65703. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65704. out << "grestore\n";
  65705. }
  65706. }
  65707. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65708. const int sx, const int sy,
  65709. const int maxW, const int maxH) const
  65710. {
  65711. out << "{<\n";
  65712. const int w = jmin (maxW, im.getWidth());
  65713. const int h = jmin (maxH, im.getHeight());
  65714. int charsOnLine = 0;
  65715. const Image::BitmapData srcData (im, 0, 0, w, h);
  65716. Colour pixel;
  65717. for (int y = h; --y >= 0;)
  65718. {
  65719. for (int x = 0; x < w; ++x)
  65720. {
  65721. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65722. if (x >= sx && y >= sy)
  65723. {
  65724. if (im.isARGB())
  65725. {
  65726. PixelARGB p (*(const PixelARGB*) pixelData);
  65727. p.unpremultiply();
  65728. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65729. }
  65730. else if (im.isRGB())
  65731. {
  65732. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65733. }
  65734. else
  65735. {
  65736. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65737. }
  65738. }
  65739. else
  65740. {
  65741. pixel = Colours::transparentWhite;
  65742. }
  65743. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65744. out << String::toHexString (pixelValues, 3, 0);
  65745. charsOnLine += 3;
  65746. if (charsOnLine > 100)
  65747. {
  65748. out << '\n';
  65749. charsOnLine = 0;
  65750. }
  65751. }
  65752. }
  65753. out << "\n>}\n";
  65754. }
  65755. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65756. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65757. {
  65758. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65759. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65760. writeClip();
  65761. out << "gsave ";
  65762. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65763. .scaled (1.0f, -1.0f));
  65764. RectangleList imageClip;
  65765. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65766. imageClip.clipTo (srcClip);
  65767. out << "newpath ";
  65768. int itemsOnLine = 0;
  65769. for (RectangleList::Iterator i (imageClip); i.next();)
  65770. {
  65771. if (++itemsOnLine == 6)
  65772. {
  65773. out << '\n';
  65774. itemsOnLine = 0;
  65775. }
  65776. const Rectangle<int>& r = *i.getRectangle();
  65777. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65778. }
  65779. out << " clip newpath\n";
  65780. out << w << ' ' << h << " scale\n";
  65781. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65782. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65783. out << "false 3 colorimage grestore\n";
  65784. needToClip = true;
  65785. }
  65786. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65787. {
  65788. Path p;
  65789. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65790. fillPath (p, AffineTransform::identity);
  65791. }
  65792. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65793. {
  65794. drawLine (x, top, x, bottom);
  65795. }
  65796. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65797. {
  65798. drawLine (left, y, right, y);
  65799. }
  65800. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65801. {
  65802. stateStack.getLast()->font = newFont;
  65803. }
  65804. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65805. {
  65806. return stateStack.getLast()->font;
  65807. }
  65808. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65809. {
  65810. Path p;
  65811. Font& font = stateStack.getLast()->font;
  65812. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65813. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65814. }
  65815. END_JUCE_NAMESPACE
  65816. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65817. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65818. BEGIN_JUCE_NAMESPACE
  65819. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65820. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65821. #endif
  65822. #if JUCE_MSVC && JUCE_DEBUG
  65823. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65824. #endif
  65825. #if JUCE_MSVC
  65826. #pragma warning (push)
  65827. #pragma warning (disable: 4127) // "expression is constant" warning
  65828. #endif
  65829. template <class PixelType, bool replaceExisting = false>
  65830. class SolidColourEdgeTableRenderer
  65831. {
  65832. public:
  65833. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65834. : data (data_),
  65835. sourceColour (colour)
  65836. {
  65837. if (sizeof (PixelType) == 3)
  65838. {
  65839. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65840. && sourceColour.getGreen() == sourceColour.getBlue();
  65841. filler[0].set (sourceColour);
  65842. filler[1].set (sourceColour);
  65843. filler[2].set (sourceColour);
  65844. filler[3].set (sourceColour);
  65845. }
  65846. }
  65847. forcedinline void setEdgeTableYPos (const int y) throw()
  65848. {
  65849. linePixels = (PixelType*) data.getLinePointer (y);
  65850. }
  65851. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65852. {
  65853. if (replaceExisting)
  65854. linePixels[x].set (sourceColour);
  65855. else
  65856. linePixels[x].blend (sourceColour, alphaLevel);
  65857. }
  65858. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65859. {
  65860. PixelARGB p (sourceColour);
  65861. p.multiplyAlpha (alphaLevel);
  65862. PixelType* dest = linePixels + x;
  65863. if (replaceExisting || p.getAlpha() >= 0xff)
  65864. replaceLine (dest, p, width);
  65865. else
  65866. blendLine (dest, p, width);
  65867. }
  65868. private:
  65869. const Image::BitmapData& data;
  65870. PixelType* linePixels;
  65871. PixelARGB sourceColour;
  65872. PixelRGB filler [4];
  65873. bool areRGBComponentsEqual;
  65874. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const
  65875. {
  65876. do
  65877. {
  65878. dest->blend (colour);
  65879. ++dest;
  65880. } while (--width > 0);
  65881. }
  65882. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65883. {
  65884. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65885. {
  65886. memset (dest, colour.getRed(), width * 3);
  65887. }
  65888. else
  65889. {
  65890. if (width >> 5)
  65891. {
  65892. const int* const intFiller = (const int*) filler;
  65893. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65894. {
  65895. dest->set (colour);
  65896. ++dest;
  65897. --width;
  65898. }
  65899. while (width > 4)
  65900. {
  65901. ((int*) dest) [0] = intFiller[0];
  65902. ((int*) dest) [1] = intFiller[1];
  65903. ((int*) dest) [2] = intFiller[2];
  65904. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65905. width -= 4;
  65906. }
  65907. }
  65908. while (--width >= 0)
  65909. {
  65910. dest->set (colour);
  65911. ++dest;
  65912. }
  65913. }
  65914. }
  65915. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65916. {
  65917. memset (dest, colour.getAlpha(), width);
  65918. }
  65919. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65920. {
  65921. do
  65922. {
  65923. dest->set (colour);
  65924. ++dest;
  65925. } while (--width > 0);
  65926. }
  65927. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65928. const SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65929. };
  65930. class LinearGradientPixelGenerator
  65931. {
  65932. public:
  65933. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65934. : lookupTable (lookupTable_), numEntries (numEntries_)
  65935. {
  65936. jassert (numEntries_ >= 0);
  65937. float x1 = gradient.x1;
  65938. float y1 = gradient.y1;
  65939. float x2 = gradient.x2;
  65940. float y2 = gradient.y2;
  65941. if (! transform.isIdentity())
  65942. {
  65943. const Line l (x2, y2, x1, y1);
  65944. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65945. float x3 = p3.getX();
  65946. float y3 = p3.getY();
  65947. transform.transformPoint (x1, y1);
  65948. transform.transformPoint (x2, y2);
  65949. transform.transformPoint (x3, y3);
  65950. const Line l2 (x2, y2, x3, y3);
  65951. const float prop = l2.findNearestPointTo (x1, y1);
  65952. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65953. x2 = newP2.getX();
  65954. y2 = newP2.getY();
  65955. }
  65956. vertical = fabs (x1 - x2) < 0.001f;
  65957. horizontal = fabs (y1 - y2) < 0.001f;
  65958. if (vertical)
  65959. {
  65960. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65961. start = roundToInt (y1 * scale);
  65962. }
  65963. else if (horizontal)
  65964. {
  65965. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65966. start = roundToInt (x1 * scale);
  65967. }
  65968. else
  65969. {
  65970. grad = (y2 - y1) / (double) (x1 - x2);
  65971. yTerm = y1 - x1 / grad;
  65972. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65973. grad *= scale;
  65974. }
  65975. }
  65976. forcedinline void setY (const int y) throw()
  65977. {
  65978. if (vertical)
  65979. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65980. else if (! horizontal)
  65981. start = roundToInt ((y - yTerm) * grad);
  65982. }
  65983. forcedinline const PixelARGB getPixel (const int x) const throw()
  65984. {
  65985. return vertical ? linePix
  65986. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65987. }
  65988. private:
  65989. const PixelARGB* const lookupTable;
  65990. const int numEntries;
  65991. PixelARGB linePix;
  65992. int start, scale;
  65993. double grad, yTerm;
  65994. bool vertical, horizontal;
  65995. enum { numScaleBits = 12 };
  65996. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65997. const LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65998. };
  65999. class RadialGradientPixelGenerator
  66000. {
  66001. public:
  66002. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  66003. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66004. : lookupTable (lookupTable_),
  66005. numEntries (numEntries_),
  66006. gx1 (gradient.x1),
  66007. gy1 (gradient.y1)
  66008. {
  66009. jassert (numEntries_ >= 0);
  66010. const float gdx = gradient.x1 - gradient.x2;
  66011. const float gdy = gradient.y1 - gradient.y2;
  66012. maxDist = gdx * gdx + gdy * gdy;
  66013. invScale = numEntries / sqrt (maxDist);
  66014. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  66015. }
  66016. forcedinline void setY (const int y) throw()
  66017. {
  66018. dy = y - gy1;
  66019. dy *= dy;
  66020. }
  66021. forcedinline const PixelARGB getPixel (const int px) const throw()
  66022. {
  66023. double x = px - gx1;
  66024. x *= x;
  66025. x += dy;
  66026. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  66027. }
  66028. protected:
  66029. const PixelARGB* const lookupTable;
  66030. const int numEntries;
  66031. const double gx1, gy1;
  66032. double maxDist, invScale, dy;
  66033. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  66034. const RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  66035. };
  66036. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  66037. {
  66038. public:
  66039. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  66040. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66041. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  66042. inverseTransform (transform.inverted())
  66043. {
  66044. tM10 = inverseTransform.mat10;
  66045. tM00 = inverseTransform.mat00;
  66046. }
  66047. forcedinline void setY (const int y) throw()
  66048. {
  66049. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  66050. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  66051. }
  66052. forcedinline const PixelARGB getPixel (const int px) const throw()
  66053. {
  66054. double x = px;
  66055. const double y = tM10 * x + lineYM11;
  66056. x = tM00 * x + lineYM01;
  66057. x *= x;
  66058. x += y * y;
  66059. if (x >= maxDist)
  66060. return lookupTable [numEntries];
  66061. else
  66062. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  66063. }
  66064. private:
  66065. double tM10, tM00, lineYM01, lineYM11;
  66066. const AffineTransform inverseTransform;
  66067. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  66068. const TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  66069. };
  66070. template <class PixelType, class GradientType>
  66071. class GradientEdgeTableRenderer : public GradientType
  66072. {
  66073. public:
  66074. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  66075. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66076. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  66077. destData (destData_)
  66078. {
  66079. }
  66080. forcedinline void setEdgeTableYPos (const int y) throw()
  66081. {
  66082. linePixels = (PixelType*) destData.getLinePointer (y);
  66083. GradientType::setY (y);
  66084. }
  66085. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  66086. {
  66087. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  66088. }
  66089. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  66090. {
  66091. PixelType* dest = linePixels + x;
  66092. if (alphaLevel < 0xff)
  66093. {
  66094. do
  66095. {
  66096. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  66097. } while (--width > 0);
  66098. }
  66099. else
  66100. {
  66101. do
  66102. {
  66103. (dest++)->blend (GradientType::getPixel (x++));
  66104. } while (--width > 0);
  66105. }
  66106. }
  66107. private:
  66108. const Image::BitmapData& destData;
  66109. PixelType* linePixels;
  66110. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  66111. const GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  66112. };
  66113. static forcedinline int safeModulo (int n, const int divisor) throw()
  66114. {
  66115. jassert (divisor > 0);
  66116. n %= divisor;
  66117. return (n < 0) ? (n + divisor) : n;
  66118. }
  66119. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66120. class ImageFillEdgeTableRenderer
  66121. {
  66122. public:
  66123. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66124. const Image::BitmapData& srcData_,
  66125. const int extraAlpha_,
  66126. const int x, const int y) throw()
  66127. : destData (destData_),
  66128. srcData (srcData_),
  66129. extraAlpha (extraAlpha_ + 1),
  66130. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  66131. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  66132. {
  66133. }
  66134. forcedinline void setEdgeTableYPos (int y) throw()
  66135. {
  66136. linePixels = (DestPixelType*) destData.getLinePointer (y);
  66137. y -= yOffset;
  66138. if (repeatPattern)
  66139. {
  66140. jassert (y >= 0);
  66141. y %= srcData.height;
  66142. }
  66143. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  66144. }
  66145. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  66146. {
  66147. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66148. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  66149. }
  66150. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  66151. {
  66152. DestPixelType* dest = linePixels + x;
  66153. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66154. x -= xOffset;
  66155. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  66156. if (alphaLevel < 0xfe)
  66157. {
  66158. do
  66159. {
  66160. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  66161. } while (--width > 0);
  66162. }
  66163. else
  66164. {
  66165. if (repeatPattern)
  66166. {
  66167. do
  66168. {
  66169. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  66170. } while (--width > 0);
  66171. }
  66172. else
  66173. {
  66174. copyRow (dest, sourceLineStart + x, width);
  66175. }
  66176. }
  66177. }
  66178. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  66179. {
  66180. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  66181. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  66182. uint8* mask = (uint8*) (s + x - xOffset);
  66183. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66184. mask += PixelARGB::indexA;
  66185. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  66186. }
  66187. private:
  66188. const Image::BitmapData& destData;
  66189. const Image::BitmapData& srcData;
  66190. const int extraAlpha, xOffset, yOffset;
  66191. DestPixelType* linePixels;
  66192. SrcPixelType* sourceLineStart;
  66193. template <class PixelType1, class PixelType2>
  66194. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  66195. {
  66196. do
  66197. {
  66198. dest++ ->blend (*src++);
  66199. } while (--width > 0);
  66200. }
  66201. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  66202. {
  66203. memcpy (dest, src, width * sizeof (PixelRGB));
  66204. }
  66205. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  66206. const ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  66207. };
  66208. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66209. class TransformedImageFillEdgeTableRenderer
  66210. {
  66211. public:
  66212. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66213. const Image::BitmapData& srcData_,
  66214. const AffineTransform& transform,
  66215. const int extraAlpha_,
  66216. const bool betterQuality_) throw()
  66217. : interpolator (transform),
  66218. destData (destData_),
  66219. srcData (srcData_),
  66220. extraAlpha (extraAlpha_ + 1),
  66221. betterQuality (betterQuality_),
  66222. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  66223. pixelOffsetInt (betterQuality_ ? -128 : 0),
  66224. maxX (srcData_.width - 1),
  66225. maxY (srcData_.height - 1),
  66226. scratchSize (2048)
  66227. {
  66228. scratchBuffer.malloc (scratchSize);
  66229. }
  66230. ~TransformedImageFillEdgeTableRenderer() throw()
  66231. {
  66232. }
  66233. forcedinline void setEdgeTableYPos (const int newY) throw()
  66234. {
  66235. y = newY;
  66236. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  66237. }
  66238. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  66239. {
  66240. alphaLevel *= extraAlpha;
  66241. alphaLevel >>= 8;
  66242. SrcPixelType p;
  66243. generate (&p, x, 1);
  66244. linePixels[x].blend (p, alphaLevel);
  66245. }
  66246. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  66247. {
  66248. if (width > scratchSize)
  66249. {
  66250. scratchSize = width;
  66251. scratchBuffer.malloc (scratchSize);
  66252. }
  66253. SrcPixelType* span = scratchBuffer;
  66254. generate (span, x, width);
  66255. DestPixelType* dest = linePixels + x;
  66256. alphaLevel *= extraAlpha;
  66257. alphaLevel >>= 8;
  66258. if (alphaLevel < 0xfe)
  66259. {
  66260. do
  66261. {
  66262. dest++ ->blend (*span++, alphaLevel);
  66263. } while (--width > 0);
  66264. }
  66265. else
  66266. {
  66267. do
  66268. {
  66269. dest++ ->blend (*span++);
  66270. } while (--width > 0);
  66271. }
  66272. }
  66273. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  66274. {
  66275. if (width > scratchSize)
  66276. {
  66277. scratchSize = width;
  66278. scratchBuffer.malloc (scratchSize);
  66279. }
  66280. uint8* mask = (uint8*) scratchBuffer;
  66281. y = y_;
  66282. generate ((SrcPixelType*) mask, x, width);
  66283. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66284. mask += PixelARGB::indexA;
  66285. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  66286. }
  66287. private:
  66288. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  66289. {
  66290. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66291. do
  66292. {
  66293. int hiResX, hiResY;
  66294. this->interpolator.next (hiResX, hiResY);
  66295. hiResX += pixelOffsetInt;
  66296. hiResY += pixelOffsetInt;
  66297. int loResX = hiResX >> 8;
  66298. int loResY = hiResY >> 8;
  66299. if (repeatPattern)
  66300. {
  66301. loResX = safeModulo (loResX, srcData.width);
  66302. loResY = safeModulo (loResY, srcData.height);
  66303. }
  66304. if (betterQuality
  66305. && ((unsigned int) loResX) < (unsigned int) maxX
  66306. && ((unsigned int) loResY) < (unsigned int) maxY)
  66307. {
  66308. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  66309. hiResX &= 255;
  66310. hiResY &= 255;
  66311. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66312. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66313. c[0] += weight * src[0];
  66314. c[1] += weight * src[1];
  66315. c[2] += weight * src[2];
  66316. c[3] += weight * src[3];
  66317. weight = hiResX * (256 - hiResY);
  66318. c[0] += weight * src[4];
  66319. c[1] += weight * src[5];
  66320. c[2] += weight * src[6];
  66321. c[3] += weight * src[7];
  66322. src += this->srcData.lineStride;
  66323. weight = (256 - hiResX) * hiResY;
  66324. c[0] += weight * src[0];
  66325. c[1] += weight * src[1];
  66326. c[2] += weight * src[2];
  66327. c[3] += weight * src[3];
  66328. weight = hiResX * hiResY;
  66329. c[0] += weight * src[4];
  66330. c[1] += weight * src[5];
  66331. c[2] += weight * src[6];
  66332. c[3] += weight * src[7];
  66333. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66334. (uint8) (c[PixelARGB::indexR] >> 16),
  66335. (uint8) (c[PixelARGB::indexG] >> 16),
  66336. (uint8) (c[PixelARGB::indexB] >> 16));
  66337. }
  66338. else
  66339. {
  66340. if (! repeatPattern)
  66341. {
  66342. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66343. if (loResX < 0) loResX = 0;
  66344. if (loResY < 0) loResY = 0;
  66345. if (loResX > maxX) loResX = maxX;
  66346. if (loResY > maxY) loResY = maxY;
  66347. }
  66348. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66349. }
  66350. ++dest;
  66351. } while (--numPixels > 0);
  66352. }
  66353. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66354. {
  66355. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66356. do
  66357. {
  66358. int hiResX, hiResY;
  66359. this->interpolator.next (hiResX, hiResY);
  66360. hiResX += pixelOffsetInt;
  66361. hiResY += pixelOffsetInt;
  66362. int loResX = hiResX >> 8;
  66363. int loResY = hiResY >> 8;
  66364. if (repeatPattern)
  66365. {
  66366. loResX = safeModulo (loResX, srcData.width);
  66367. loResY = safeModulo (loResY, srcData.height);
  66368. }
  66369. if (betterQuality
  66370. && ((unsigned int) loResX) < (unsigned int) maxX
  66371. && ((unsigned int) loResY) < (unsigned int) maxY)
  66372. {
  66373. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66374. hiResX &= 255;
  66375. hiResY &= 255;
  66376. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66377. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66378. c[0] += weight * src[0];
  66379. c[1] += weight * src[1];
  66380. c[2] += weight * src[2];
  66381. weight = hiResX * (256 - hiResY);
  66382. c[0] += weight * src[3];
  66383. c[1] += weight * src[4];
  66384. c[2] += weight * src[5];
  66385. src += this->srcData.lineStride;
  66386. weight = (256 - hiResX) * hiResY;
  66387. c[0] += weight * src[0];
  66388. c[1] += weight * src[1];
  66389. c[2] += weight * src[2];
  66390. weight = hiResX * hiResY;
  66391. c[0] += weight * src[3];
  66392. c[1] += weight * src[4];
  66393. c[2] += weight * src[5];
  66394. dest->setARGB ((uint8) 255,
  66395. (uint8) (c[PixelRGB::indexR] >> 16),
  66396. (uint8) (c[PixelRGB::indexG] >> 16),
  66397. (uint8) (c[PixelRGB::indexB] >> 16));
  66398. }
  66399. else
  66400. {
  66401. if (! repeatPattern)
  66402. {
  66403. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66404. if (loResX < 0) loResX = 0;
  66405. if (loResY < 0) loResY = 0;
  66406. if (loResX > maxX) loResX = maxX;
  66407. if (loResY > maxY) loResY = maxY;
  66408. }
  66409. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66410. }
  66411. ++dest;
  66412. } while (--numPixels > 0);
  66413. }
  66414. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66415. {
  66416. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66417. do
  66418. {
  66419. int hiResX, hiResY;
  66420. this->interpolator.next (hiResX, hiResY);
  66421. hiResX += pixelOffsetInt;
  66422. hiResY += pixelOffsetInt;
  66423. int loResX = hiResX >> 8;
  66424. int loResY = hiResY >> 8;
  66425. if (repeatPattern)
  66426. {
  66427. loResX = safeModulo (loResX, srcData.width);
  66428. loResY = safeModulo (loResY, srcData.height);
  66429. }
  66430. if (betterQuality
  66431. && ((unsigned int) loResX) < (unsigned int) maxX
  66432. && ((unsigned int) loResY) < (unsigned int) maxY)
  66433. {
  66434. hiResX &= 255;
  66435. hiResY &= 255;
  66436. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66437. uint32 c = 256 * 128;
  66438. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66439. c += src[1] * (hiResX * (256 - hiResY));
  66440. src += this->srcData.lineStride;
  66441. c += src[0] * ((256 - hiResX) * hiResY);
  66442. c += src[1] * (hiResX * hiResY);
  66443. *((uint8*) dest) = (uint8) c;
  66444. }
  66445. else
  66446. {
  66447. if (! repeatPattern)
  66448. {
  66449. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66450. if (loResX < 0) loResX = 0;
  66451. if (loResY < 0) loResY = 0;
  66452. if (loResX > maxX) loResX = maxX;
  66453. if (loResY > maxY) loResY = maxY;
  66454. }
  66455. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66456. }
  66457. ++dest;
  66458. } while (--numPixels > 0);
  66459. }
  66460. class TransformedImageSpanInterpolator
  66461. {
  66462. public:
  66463. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66464. : inverseTransform (transform.inverted())
  66465. {}
  66466. void setStartOfLine (float x, float y, const int numPixels) throw()
  66467. {
  66468. float x1 = x, y1 = y;
  66469. inverseTransform.transformPoint (x1, y1);
  66470. x += numPixels;
  66471. inverseTransform.transformPoint (x, y);
  66472. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66473. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66474. }
  66475. void next (int& x, int& y) throw()
  66476. {
  66477. x = xBresenham.n;
  66478. xBresenham.stepToNext();
  66479. y = yBresenham.n;
  66480. yBresenham.stepToNext();
  66481. }
  66482. private:
  66483. class BresenhamInterpolator
  66484. {
  66485. public:
  66486. BresenhamInterpolator() throw() {}
  66487. void set (const int n1, const int n2, const int numSteps_) throw()
  66488. {
  66489. numSteps = jmax (1, numSteps_);
  66490. step = (n2 - n1) / numSteps;
  66491. remainder = modulo = (n2 - n1) % numSteps;
  66492. n = n1;
  66493. if (modulo <= 0)
  66494. {
  66495. modulo += numSteps;
  66496. remainder += numSteps;
  66497. --step;
  66498. }
  66499. modulo -= numSteps;
  66500. }
  66501. forcedinline void stepToNext() throw()
  66502. {
  66503. modulo += remainder;
  66504. n += step;
  66505. if (modulo > 0)
  66506. {
  66507. modulo -= numSteps;
  66508. ++n;
  66509. }
  66510. }
  66511. int n;
  66512. private:
  66513. int numSteps, step, modulo, remainder;
  66514. };
  66515. const AffineTransform inverseTransform;
  66516. BresenhamInterpolator xBresenham, yBresenham;
  66517. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66518. const TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66519. };
  66520. TransformedImageSpanInterpolator interpolator;
  66521. const Image::BitmapData& destData;
  66522. const Image::BitmapData& srcData;
  66523. const int extraAlpha;
  66524. const bool betterQuality;
  66525. const float pixelOffset;
  66526. const int pixelOffsetInt, maxX, maxY;
  66527. int y;
  66528. DestPixelType* linePixels;
  66529. HeapBlock <SrcPixelType> scratchBuffer;
  66530. int scratchSize;
  66531. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66532. const TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66533. };
  66534. class LLGCSavedState
  66535. {
  66536. public:
  66537. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66538. const Font& font_, const FillType& fillType_,
  66539. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66540. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66541. xOffset (xOffset_), yOffset (yOffset_),
  66542. font (font_), fillType (fillType_),
  66543. interpolationQuality (interpolationQuality_)
  66544. {
  66545. }
  66546. LLGCSavedState (const LLGCSavedState& other) throw()
  66547. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66548. yOffset (other.yOffset), font (other.font),
  66549. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66550. {
  66551. }
  66552. ~LLGCSavedState() throw()
  66553. {
  66554. }
  66555. bool clipToRectangle (const Rectangle<int>& r) throw()
  66556. {
  66557. dupeEdgeTableIfMultiplyReferenced();
  66558. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66559. return ! edgeTable->edgeTable.isEmpty();
  66560. }
  66561. bool clipToRectangleList (const RectangleList& r) throw()
  66562. {
  66563. dupeEdgeTableIfMultiplyReferenced();
  66564. RectangleList offsetList (r);
  66565. offsetList.offsetAll (xOffset, yOffset);
  66566. EdgeTable e2 (offsetList);
  66567. edgeTable->edgeTable.clipToEdgeTable (e2);
  66568. return ! edgeTable->edgeTable.isEmpty();
  66569. }
  66570. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66571. {
  66572. dupeEdgeTableIfMultiplyReferenced();
  66573. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66574. return ! edgeTable->edgeTable.isEmpty();
  66575. }
  66576. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66577. {
  66578. dupeEdgeTableIfMultiplyReferenced();
  66579. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66580. edgeTable->edgeTable.clipToEdgeTable (et);
  66581. }
  66582. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66583. {
  66584. et.clipToEdgeTable (edgeTable->edgeTable);
  66585. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66586. if (fillType.isGradient())
  66587. {
  66588. jassert (! replaceContents); // that option is just for solid colours
  66589. ColourGradient g2 (*(fillType.gradient));
  66590. g2.multiplyOpacity (fillType.getOpacity());
  66591. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66592. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66593. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66594. const bool isIdentity = transform.isOnlyTranslation();
  66595. if (isIdentity)
  66596. {
  66597. // If our translation doesn't involve any distortion, we can speed it up..
  66598. transform.transformPoint (g2.x1, g2.y1);
  66599. transform.transformPoint (g2.x2, g2.y2);
  66600. transform = AffineTransform::identity;
  66601. }
  66602. HeapBlock <PixelARGB> lookupTable;
  66603. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66604. jassert (numLookupEntries > 0);
  66605. switch (image.getFormat())
  66606. {
  66607. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66608. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66609. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66610. }
  66611. }
  66612. else if (fillType.isTiledImage())
  66613. {
  66614. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66615. }
  66616. else
  66617. {
  66618. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66619. switch (image.getFormat())
  66620. {
  66621. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66622. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66623. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66624. }
  66625. }
  66626. }
  66627. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66628. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66629. {
  66630. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66631. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66632. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66633. const int alpha = fillType.colour.getAlpha();
  66634. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66635. if (transform.isOnlyTranslation())
  66636. {
  66637. // If our translation doesn't involve any distortion, just use a simple blit..
  66638. int tx = (int) (transform.getTranslationX() * 256.0f);
  66639. int ty = (int) (transform.getTranslationY() * 256.0f);
  66640. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66641. {
  66642. tx = ((tx + 128) >> 8);
  66643. ty = ((ty + 128) >> 8);
  66644. if (tiledFillClipRegion != 0)
  66645. {
  66646. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66647. }
  66648. else
  66649. {
  66650. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66651. et.clipToEdgeTable (edgeTable->edgeTable);
  66652. if (! et.isEmpty())
  66653. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66654. }
  66655. return;
  66656. }
  66657. }
  66658. if (transform.isSingularity())
  66659. return;
  66660. if (tiledFillClipRegion != 0)
  66661. {
  66662. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66663. }
  66664. else
  66665. {
  66666. Path p;
  66667. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66668. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66669. et.clipToEdgeTable (edgeTable->edgeTable);
  66670. if (! et.isEmpty())
  66671. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66672. }
  66673. }
  66674. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66675. {
  66676. if (! image.hasAlphaChannel())
  66677. {
  66678. Path p;
  66679. p.addRectangle (srcClip);
  66680. clipToPath (p, t);
  66681. return;
  66682. }
  66683. dupeEdgeTableIfMultiplyReferenced();
  66684. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66685. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66686. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66687. EdgeTable& et = edgeTable->edgeTable;
  66688. if (transform.isOnlyTranslation())
  66689. {
  66690. // If our translation doesn't involve any distortion, just use a simple blit..
  66691. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66692. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66693. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66694. {
  66695. const int imageX = ((tx + 128) >> 8);
  66696. const int imageY = ((ty + 128) >> 8);
  66697. if (image.getFormat() == Image::ARGB)
  66698. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66699. else
  66700. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66701. return;
  66702. }
  66703. }
  66704. if (transform.isSingularity())
  66705. {
  66706. et.clipToRectangle (Rectangle<int>());
  66707. return;
  66708. }
  66709. {
  66710. Path p;
  66711. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66712. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66713. et.clipToEdgeTable (et2);
  66714. }
  66715. if (! et.isEmpty())
  66716. {
  66717. if (image.getFormat() == Image::ARGB)
  66718. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66719. else
  66720. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66721. }
  66722. }
  66723. template <class SrcPixelType>
  66724. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66725. {
  66726. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66727. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66728. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66729. et.getMaximumBounds().getWidth());
  66730. }
  66731. template <class SrcPixelType>
  66732. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66733. {
  66734. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66735. et.clipToRectangle (r);
  66736. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66737. for (int y = 0; y < r.getHeight(); ++y)
  66738. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66739. }
  66740. class EdgeTableHolder : public ReferenceCountedObject
  66741. {
  66742. public:
  66743. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66744. EdgeTable edgeTable;
  66745. };
  66746. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66747. int xOffset, yOffset;
  66748. Font font;
  66749. FillType fillType;
  66750. Graphics::ResamplingQuality interpolationQuality;
  66751. private:
  66752. const LLGCSavedState& operator= (const LLGCSavedState&);
  66753. void dupeEdgeTableIfMultiplyReferenced() throw()
  66754. {
  66755. if (edgeTable->getReferenceCount() > 1)
  66756. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66757. }
  66758. template <class DestPixelType>
  66759. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66760. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66761. {
  66762. jassert (destData.pixelStride == sizeof (DestPixelType));
  66763. if (g.isRadial)
  66764. {
  66765. if (isIdentity)
  66766. {
  66767. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66768. et.iterate (renderer);
  66769. }
  66770. else
  66771. {
  66772. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66773. et.iterate (renderer);
  66774. }
  66775. }
  66776. else
  66777. {
  66778. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66779. et.iterate (renderer);
  66780. }
  66781. }
  66782. template <class DestPixelType>
  66783. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66784. {
  66785. jassert (destData.pixelStride == sizeof (DestPixelType));
  66786. if (replaceContents)
  66787. {
  66788. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66789. et.iterate (r);
  66790. }
  66791. else
  66792. {
  66793. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66794. et.iterate (r);
  66795. }
  66796. }
  66797. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66798. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66799. {
  66800. switch (destImage.getFormat())
  66801. {
  66802. case Image::ARGB:
  66803. switch (srcImage.getFormat())
  66804. {
  66805. case Image::ARGB:
  66806. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66807. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66808. break;
  66809. case Image::RGB:
  66810. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66811. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66812. break;
  66813. default:
  66814. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66815. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66816. break;
  66817. }
  66818. break;
  66819. case Image::RGB:
  66820. switch (srcImage.getFormat())
  66821. {
  66822. case Image::ARGB:
  66823. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66824. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66825. break;
  66826. case Image::RGB:
  66827. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66828. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66829. break;
  66830. default:
  66831. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66832. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66833. break;
  66834. }
  66835. break;
  66836. default:
  66837. switch (srcImage.getFormat())
  66838. {
  66839. case Image::ARGB:
  66840. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66841. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66842. break;
  66843. case Image::RGB:
  66844. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66845. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66846. break;
  66847. default:
  66848. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66849. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66850. break;
  66851. }
  66852. break;
  66853. }
  66854. }
  66855. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66856. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66857. {
  66858. switch (destImage.getFormat())
  66859. {
  66860. case Image::ARGB:
  66861. switch (srcImage.getFormat())
  66862. {
  66863. case Image::ARGB:
  66864. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66865. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66866. break;
  66867. case Image::RGB:
  66868. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66869. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66870. break;
  66871. default:
  66872. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66873. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66874. break;
  66875. }
  66876. break;
  66877. case Image::RGB:
  66878. switch (srcImage.getFormat())
  66879. {
  66880. case Image::ARGB:
  66881. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66882. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66883. break;
  66884. case Image::RGB:
  66885. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66886. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66887. break;
  66888. default:
  66889. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66890. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66891. break;
  66892. }
  66893. break;
  66894. default:
  66895. switch (srcImage.getFormat())
  66896. {
  66897. case Image::ARGB:
  66898. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66899. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66900. break;
  66901. case Image::RGB:
  66902. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66903. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66904. break;
  66905. default:
  66906. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66907. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66908. break;
  66909. }
  66910. break;
  66911. }
  66912. }
  66913. };
  66914. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66915. : image (image_)
  66916. {
  66917. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66918. FillType(), Graphics::mediumResamplingQuality);
  66919. }
  66920. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66921. {
  66922. }
  66923. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66924. {
  66925. return false;
  66926. }
  66927. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66928. {
  66929. currentState->xOffset += x;
  66930. currentState->yOffset += y;
  66931. }
  66932. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66933. {
  66934. return currentState->clipToRectangle (r);
  66935. }
  66936. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66937. {
  66938. return currentState->clipToRectangleList (clipRegion);
  66939. }
  66940. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66941. {
  66942. currentState->excludeClipRectangle (r);
  66943. }
  66944. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66945. {
  66946. currentState->clipToPath (path, transform);
  66947. }
  66948. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66949. {
  66950. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66951. }
  66952. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66953. {
  66954. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66955. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66956. }
  66957. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66958. {
  66959. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66960. }
  66961. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66962. {
  66963. return currentState->edgeTable->edgeTable.isEmpty();
  66964. }
  66965. void LowLevelGraphicsSoftwareRenderer::saveState()
  66966. {
  66967. stateStack.add (new LLGCSavedState (*currentState));
  66968. }
  66969. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66970. {
  66971. LLGCSavedState* const top = stateStack.getLast();
  66972. if (top != 0)
  66973. {
  66974. currentState = top;
  66975. stateStack.removeLast (1, false);
  66976. }
  66977. else
  66978. {
  66979. jassertfalse // trying to pop with an empty stack!
  66980. }
  66981. }
  66982. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66983. {
  66984. currentState->fillType = fillType;
  66985. }
  66986. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66987. {
  66988. currentState->fillType.setOpacity (newOpacity);
  66989. }
  66990. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66991. {
  66992. currentState->interpolationQuality = quality;
  66993. }
  66994. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66995. {
  66996. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66997. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66998. if (! clipped.isEmpty())
  66999. {
  67000. EdgeTable et (clipped);
  67001. currentState->fillEdgeTable (image, et, replaceExistingContents);
  67002. }
  67003. }
  67004. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  67005. {
  67006. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  67007. path, transform.translated ((float) currentState->xOffset,
  67008. (float) currentState->yOffset));
  67009. currentState->fillEdgeTable (image, et);
  67010. }
  67011. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  67012. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  67013. {
  67014. jassert (sourceImage.getBounds().contains (srcClip));
  67015. currentState->renderImage (image, sourceImage, srcClip, transform,
  67016. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  67017. }
  67018. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  67019. {
  67020. Path p;
  67021. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  67022. fillPath (p, AffineTransform::identity);
  67023. }
  67024. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  67025. {
  67026. if (bottom > top)
  67027. {
  67028. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  67029. currentState->fillEdgeTable (image, et);
  67030. }
  67031. }
  67032. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  67033. {
  67034. if (right > left)
  67035. {
  67036. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  67037. (float) (right - left), 1.0f);
  67038. currentState->fillEdgeTable (image, et);
  67039. }
  67040. }
  67041. class GlyphCache : private DeletedAtShutdown
  67042. {
  67043. public:
  67044. GlyphCache() throw()
  67045. : accessCounter (0), hits (0), misses (0)
  67046. {
  67047. for (int i = 120; --i >= 0;)
  67048. glyphs.add (new CachedGlyph());
  67049. }
  67050. ~GlyphCache() throw()
  67051. {
  67052. clearSingletonInstance();
  67053. }
  67054. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  67055. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  67056. {
  67057. ++accessCounter;
  67058. int oldestCounter = std::numeric_limits<int>::max();
  67059. CachedGlyph* oldest = 0;
  67060. for (int i = glyphs.size(); --i >= 0;)
  67061. {
  67062. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  67063. if (glyph->glyph == glyphNumber && glyph->font == font)
  67064. {
  67065. ++hits;
  67066. glyph->lastAccessCount = accessCounter;
  67067. glyph->draw (state, image, x, y);
  67068. return;
  67069. }
  67070. if (glyph->lastAccessCount <= oldestCounter)
  67071. {
  67072. oldestCounter = glyph->lastAccessCount;
  67073. oldest = glyph;
  67074. }
  67075. }
  67076. if (hits + ++misses > (glyphs.size() << 4))
  67077. {
  67078. if (misses * 2 > hits)
  67079. {
  67080. for (int i = 32; --i >= 0;)
  67081. glyphs.add (new CachedGlyph());
  67082. }
  67083. hits = misses = 0;
  67084. oldest = glyphs.getLast();
  67085. }
  67086. jassert (oldest != 0);
  67087. oldest->lastAccessCount = accessCounter;
  67088. oldest->generate (font, glyphNumber);
  67089. oldest->draw (state, image, x, y);
  67090. }
  67091. class CachedGlyph
  67092. {
  67093. public:
  67094. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  67095. ~CachedGlyph() {}
  67096. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  67097. {
  67098. if (edgeTable != 0)
  67099. {
  67100. EdgeTable et (*edgeTable);
  67101. et.translate (x, roundToInt (y));
  67102. state.fillEdgeTable (image, et, false);
  67103. }
  67104. }
  67105. void generate (const Font& newFont, const int glyphNumber) throw()
  67106. {
  67107. font = newFont;
  67108. glyph = glyphNumber;
  67109. edgeTable = 0;
  67110. Path glyphPath;
  67111. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  67112. if (! glyphPath.isEmpty())
  67113. {
  67114. const float fontHeight = font.getHeight();
  67115. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  67116. .translated (0.0f, -0.5f));
  67117. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  67118. glyphPath, transform);
  67119. }
  67120. }
  67121. int glyph, lastAccessCount;
  67122. Font font;
  67123. juce_UseDebuggingNewOperator
  67124. private:
  67125. ScopedPointer <EdgeTable> edgeTable;
  67126. CachedGlyph (const CachedGlyph&);
  67127. const CachedGlyph& operator= (const CachedGlyph&);
  67128. };
  67129. juce_UseDebuggingNewOperator
  67130. private:
  67131. OwnedArray <CachedGlyph> glyphs;
  67132. int accessCounter, hits, misses;
  67133. GlyphCache (const GlyphCache&);
  67134. const GlyphCache& operator= (const GlyphCache&);
  67135. };
  67136. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  67137. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  67138. {
  67139. currentState->font = newFont;
  67140. }
  67141. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  67142. {
  67143. return currentState->font;
  67144. }
  67145. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  67146. {
  67147. Font& f = currentState->font;
  67148. if (transform.isOnlyTranslation())
  67149. {
  67150. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  67151. transform.getTranslationX() + (float) currentState->xOffset,
  67152. transform.getTranslationY() + (float) currentState->yOffset);
  67153. }
  67154. else
  67155. {
  67156. Path p;
  67157. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  67158. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  67159. }
  67160. }
  67161. #if JUCE_MSVC
  67162. #pragma warning (pop)
  67163. #endif
  67164. END_JUCE_NAMESPACE
  67165. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  67166. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  67167. BEGIN_JUCE_NAMESPACE
  67168. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  67169. : flags (other.flags)
  67170. {
  67171. }
  67172. const RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  67173. {
  67174. flags = other.flags;
  67175. return *this;
  67176. }
  67177. void RectanglePlacement::applyTo (double& x, double& y,
  67178. double& w, double& h,
  67179. const double dx, const double dy,
  67180. const double dw, const double dh) const throw()
  67181. {
  67182. if (w == 0 || h == 0)
  67183. return;
  67184. if ((flags & stretchToFit) != 0)
  67185. {
  67186. x = dx;
  67187. y = dy;
  67188. w = dw;
  67189. h = dh;
  67190. }
  67191. else
  67192. {
  67193. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  67194. : jmin (dw / w, dh / h);
  67195. if ((flags & onlyReduceInSize) != 0)
  67196. scale = jmin (scale, 1.0);
  67197. if ((flags & onlyIncreaseInSize) != 0)
  67198. scale = jmax (scale, 1.0);
  67199. w *= scale;
  67200. h *= scale;
  67201. if ((flags & xLeft) != 0)
  67202. x = dx;
  67203. else if ((flags & xRight) != 0)
  67204. x = dx + dw - w;
  67205. else
  67206. x = dx + (dw - w) * 0.5;
  67207. if ((flags & yTop) != 0)
  67208. y = dy;
  67209. else if ((flags & yBottom) != 0)
  67210. y = dy + dh - h;
  67211. else
  67212. y = dy + (dh - h) * 0.5;
  67213. }
  67214. }
  67215. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  67216. float w, float h,
  67217. const float dx, const float dy,
  67218. const float dw, const float dh) const throw()
  67219. {
  67220. if (w == 0 || h == 0)
  67221. return AffineTransform::identity;
  67222. const float scaleX = dw / w;
  67223. const float scaleY = dh / h;
  67224. if ((flags & stretchToFit) != 0)
  67225. return AffineTransform::translation (-x, -y)
  67226. .scaled (scaleX, scaleY)
  67227. .translated (dx, dy);
  67228. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  67229. : jmin (scaleX, scaleY);
  67230. if ((flags & onlyReduceInSize) != 0)
  67231. scale = jmin (scale, 1.0f);
  67232. if ((flags & onlyIncreaseInSize) != 0)
  67233. scale = jmax (scale, 1.0f);
  67234. w *= scale;
  67235. h *= scale;
  67236. float newX = dx;
  67237. if ((flags & xRight) != 0)
  67238. newX += dw - w; // right
  67239. else if ((flags & xLeft) == 0)
  67240. newX += (dw - w) / 2.0f; // centre
  67241. float newY = dy;
  67242. if ((flags & yBottom) != 0)
  67243. newY += dh - h; // bottom
  67244. else if ((flags & yTop) == 0)
  67245. newY += (dh - h) / 2.0f; // centre
  67246. return AffineTransform::translation (-x, -y)
  67247. .scaled (scale, scale)
  67248. .translated (newX, newY);
  67249. }
  67250. END_JUCE_NAMESPACE
  67251. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  67252. /*** Start of inlined file: juce_Drawable.cpp ***/
  67253. BEGIN_JUCE_NAMESPACE
  67254. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  67255. const AffineTransform& transform_,
  67256. const float opacity_) throw()
  67257. : g (g_),
  67258. transform (transform_),
  67259. opacity (opacity_)
  67260. {
  67261. }
  67262. Drawable::Drawable()
  67263. {
  67264. }
  67265. Drawable::~Drawable()
  67266. {
  67267. }
  67268. void Drawable::draw (Graphics& g, const float opacity,
  67269. const AffineTransform& transform) const
  67270. {
  67271. render (RenderingContext (g, transform, opacity));
  67272. }
  67273. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  67274. {
  67275. draw (g, opacity, AffineTransform::translation (x, y));
  67276. }
  67277. void Drawable::drawWithin (Graphics& g,
  67278. const int destX,
  67279. const int destY,
  67280. const int destW,
  67281. const int destH,
  67282. const RectanglePlacement& placement,
  67283. const float opacity) const
  67284. {
  67285. if (destW > 0 && destH > 0)
  67286. {
  67287. Rectangle<float> bounds (getBounds());
  67288. draw (g, opacity,
  67289. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  67290. (float) destX, (float) destY,
  67291. (float) destW, (float) destH));
  67292. }
  67293. }
  67294. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  67295. {
  67296. Drawable* result = 0;
  67297. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  67298. if (image != 0)
  67299. {
  67300. DrawableImage* const di = new DrawableImage();
  67301. di->setImage (image, true);
  67302. result = di;
  67303. }
  67304. else
  67305. {
  67306. const String asString (String::createStringFromData (data, (int) numBytes));
  67307. XmlDocument doc (asString);
  67308. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  67309. if (outer != 0 && outer->hasTagName (T("svg")))
  67310. {
  67311. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67312. if (svg != 0)
  67313. result = Drawable::createFromSVG (*svg);
  67314. }
  67315. }
  67316. return result;
  67317. }
  67318. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67319. {
  67320. MemoryBlock mb;
  67321. dataSource.readIntoMemoryBlock (mb);
  67322. return createFromImageData (mb.getData(), mb.getSize());
  67323. }
  67324. Drawable* Drawable::createFromImageFile (const File& file)
  67325. {
  67326. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67327. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67328. }
  67329. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67330. {
  67331. Drawable* d = DrawablePath::createFromValueTree (tree);
  67332. if (d == 0)
  67333. {
  67334. d = DrawableComposite::createFromValueTree (tree);
  67335. if (d == 0)
  67336. {
  67337. d = DrawableImage::createFromValueTree (tree);
  67338. if (d == 0)
  67339. d = DrawableText::createFromValueTree (tree);
  67340. }
  67341. }
  67342. return d;
  67343. }
  67344. END_JUCE_NAMESPACE
  67345. /*** End of inlined file: juce_Drawable.cpp ***/
  67346. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  67347. BEGIN_JUCE_NAMESPACE
  67348. DrawableComposite::DrawableComposite()
  67349. {
  67350. }
  67351. DrawableComposite::~DrawableComposite()
  67352. {
  67353. }
  67354. void DrawableComposite::insertDrawable (Drawable* drawable,
  67355. const AffineTransform& transform,
  67356. const int index)
  67357. {
  67358. if (drawable != 0)
  67359. {
  67360. if (! drawables.contains (drawable))
  67361. {
  67362. drawables.insert (index, drawable);
  67363. if (transform.isIdentity())
  67364. transforms.insert (index, 0);
  67365. else
  67366. transforms.insert (index, new AffineTransform (transform));
  67367. }
  67368. else
  67369. {
  67370. jassertfalse // trying to add a drawable that's already in here!
  67371. }
  67372. }
  67373. }
  67374. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67375. const AffineTransform& transform,
  67376. const int index)
  67377. {
  67378. insertDrawable (drawable.createCopy(), transform, index);
  67379. }
  67380. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67381. {
  67382. drawables.remove (index, deleteDrawable);
  67383. transforms.remove (index);
  67384. }
  67385. void DrawableComposite::bringToFront (const int index)
  67386. {
  67387. if (index >= 0 && index < drawables.size() - 1)
  67388. {
  67389. drawables.move (index, -1);
  67390. transforms.move (index, -1);
  67391. }
  67392. }
  67393. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67394. {
  67395. if (drawables.size() > 0 && context.opacity > 0)
  67396. {
  67397. if (context.opacity >= 1.0f || drawables.size() == 1)
  67398. {
  67399. Drawable::RenderingContext contextCopy (context);
  67400. for (int i = 0; i < drawables.size(); ++i)
  67401. {
  67402. const AffineTransform* const t = transforms.getUnchecked(i);
  67403. contextCopy.transform = (t == 0) ? context.transform
  67404. : t->followedBy (context.transform);
  67405. drawables.getUnchecked(i)->render (contextCopy);
  67406. }
  67407. }
  67408. else
  67409. {
  67410. // To correctly render a whole composite layer with an overall transparency,
  67411. // we need to render everything opaquely into a temp buffer, then blend that
  67412. // with the target opacity...
  67413. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67414. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67415. {
  67416. Graphics tempG (tempImage);
  67417. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67418. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67419. render (tempContext);
  67420. }
  67421. context.g.setOpacity (context.opacity);
  67422. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67423. }
  67424. }
  67425. }
  67426. const Rectangle<float> DrawableComposite::getBounds() const
  67427. {
  67428. Rectangle<float> bounds;
  67429. for (int i = 0; i < drawables.size(); ++i)
  67430. {
  67431. const Drawable* const d = drawables.getUnchecked(i);
  67432. const AffineTransform* const t = transforms.getUnchecked(i);
  67433. bounds = bounds.getUnion (t == 0 ? d->getBounds()
  67434. : d->getBounds().transformed (*t));
  67435. }
  67436. return bounds;
  67437. }
  67438. bool DrawableComposite::hitTest (float x, float y) const
  67439. {
  67440. for (int i = 0; i < drawables.size(); ++i)
  67441. {
  67442. float tx = x;
  67443. float ty = y;
  67444. const AffineTransform* const t = transforms.getUnchecked(i);
  67445. if (t != 0)
  67446. t->inverted().transformPoint (tx, ty);
  67447. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67448. return true;
  67449. }
  67450. return false;
  67451. }
  67452. Drawable* DrawableComposite::createCopy() const
  67453. {
  67454. DrawableComposite* const dc = new DrawableComposite();
  67455. for (int i = 0; i < drawables.size(); ++i)
  67456. {
  67457. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67458. const AffineTransform* const t = transforms.getUnchecked(i);
  67459. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67460. }
  67461. return dc;
  67462. }
  67463. ValueTree DrawableComposite::createValueTree() const throw()
  67464. {
  67465. ValueTree v (T("Group"));
  67466. if (getName().isNotEmpty())
  67467. v.setProperty ("id", getName(), 0);
  67468. for (int i = 0; i < drawables.size(); ++i)
  67469. {
  67470. Drawable* const d = drawables.getUnchecked(i);
  67471. ValueTree child (d->createValueTree());
  67472. AffineTransform* transform = transforms.getUnchecked(i);
  67473. if (transform != 0)
  67474. {
  67475. String t;
  67476. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67477. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67478. child.setProperty ("transform", t, 0);
  67479. }
  67480. v.addChild (child, -1, 0);
  67481. }
  67482. return v;
  67483. }
  67484. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67485. {
  67486. if (! tree.hasType ("Group"))
  67487. return 0;
  67488. DrawableComposite* dc = new DrawableComposite();
  67489. dc->setName (tree ["id"]);
  67490. for (int i = 0; i < tree.getNumChildren(); ++i)
  67491. {
  67492. ValueTree childTree (tree.getChild (i));
  67493. Drawable* d = Drawable::createFromValueTree (childTree);
  67494. if (d != 0)
  67495. {
  67496. AffineTransform transform;
  67497. const String transformAtt (childTree ["transform"].toString());
  67498. if (transformAtt.isNotEmpty())
  67499. {
  67500. StringArray tokens;
  67501. tokens.addTokens (transformAtt.trim(), false);
  67502. tokens.removeEmptyStrings (true);
  67503. if (tokens.size() == 6)
  67504. {
  67505. float f[6];
  67506. for (int j = 0; j < 6; ++j)
  67507. f[j] = (float) tokens[j].getDoubleValue();
  67508. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67509. }
  67510. }
  67511. dc->insertDrawable (d, transform);
  67512. }
  67513. }
  67514. return dc;
  67515. }
  67516. END_JUCE_NAMESPACE
  67517. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67518. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67519. BEGIN_JUCE_NAMESPACE
  67520. DrawableImage::DrawableImage()
  67521. : image (0),
  67522. canDeleteImage (false),
  67523. opacity (1.0f),
  67524. overlayColour (0x00000000)
  67525. {
  67526. }
  67527. DrawableImage::~DrawableImage()
  67528. {
  67529. clearImage();
  67530. }
  67531. void DrawableImage::clearImage()
  67532. {
  67533. if (canDeleteImage && image != 0)
  67534. ImageCache::releaseOrDelete (image);
  67535. image = 0;
  67536. }
  67537. void DrawableImage::setImage (const Image& imageToCopy)
  67538. {
  67539. clearImage();
  67540. image = new Image (imageToCopy);
  67541. canDeleteImage = true;
  67542. }
  67543. void DrawableImage::setImage (Image* imageToUse,
  67544. const bool releaseWhenNotNeeded)
  67545. {
  67546. clearImage();
  67547. image = imageToUse;
  67548. canDeleteImage = releaseWhenNotNeeded;
  67549. }
  67550. void DrawableImage::setOpacity (const float newOpacity)
  67551. {
  67552. opacity = newOpacity;
  67553. }
  67554. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67555. {
  67556. overlayColour = newOverlayColour;
  67557. }
  67558. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67559. {
  67560. if (image != 0)
  67561. {
  67562. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67563. {
  67564. context.g.setOpacity (context.opacity * opacity);
  67565. context.g.drawImageTransformed (image, image->getBounds(),
  67566. context.transform, false);
  67567. }
  67568. if (! overlayColour.isTransparent())
  67569. {
  67570. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67571. context.g.drawImageTransformed (image, image->getBounds(),
  67572. context.transform, true);
  67573. }
  67574. }
  67575. }
  67576. const Rectangle<float> DrawableImage::getBounds() const
  67577. {
  67578. if (image == 0)
  67579. return Rectangle<float>();
  67580. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67581. }
  67582. bool DrawableImage::hitTest (float x, float y) const
  67583. {
  67584. return image != 0
  67585. && x >= 0.0f
  67586. && y >= 0.0f
  67587. && x < image->getWidth()
  67588. && y < image->getHeight()
  67589. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67590. }
  67591. Drawable* DrawableImage::createCopy() const
  67592. {
  67593. DrawableImage* const di = new DrawableImage();
  67594. di->opacity = opacity;
  67595. di->overlayColour = overlayColour;
  67596. if (image != 0)
  67597. {
  67598. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67599. {
  67600. di->setImage (*image);
  67601. }
  67602. else
  67603. {
  67604. ImageCache::incReferenceCount (image);
  67605. di->setImage (image, true);
  67606. }
  67607. }
  67608. return di;
  67609. }
  67610. ValueTree DrawableImage::createValueTree() const throw()
  67611. {
  67612. ValueTree v (T("Image"));
  67613. if (getName().isNotEmpty())
  67614. v.setProperty ("id", getName(), 0);
  67615. if (opacity < 1.0f)
  67616. v.setProperty ("opacity", (double) opacity, 0);
  67617. if (! overlayColour.isTransparent())
  67618. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67619. if (image != 0)
  67620. {
  67621. MemoryOutputStream imageData;
  67622. PNGImageFormat pngFormat;
  67623. if (pngFormat.writeImageToStream (*image, imageData))
  67624. {
  67625. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67626. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67627. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67628. v.setProperty ("data", base64, 0);
  67629. }
  67630. }
  67631. return v;
  67632. }
  67633. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67634. {
  67635. if (! tree.hasType ("Image"))
  67636. return 0;
  67637. DrawableImage* di = new DrawableImage();
  67638. di->setName (tree ["id"]);
  67639. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67640. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67641. MemoryBlock imageData;
  67642. if (imageData.fromBase64Encoding (tree ["data"]))
  67643. {
  67644. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67645. if (im == 0)
  67646. return false;
  67647. di->setImage (im, true);
  67648. }
  67649. return di;
  67650. }
  67651. END_JUCE_NAMESPACE
  67652. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67653. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67654. BEGIN_JUCE_NAMESPACE
  67655. DrawablePath::DrawablePath()
  67656. : mainFill (FillType (Colours::black)),
  67657. strokeFill (FillType (Colours::transparentBlack)),
  67658. strokeType (0.0f)
  67659. {
  67660. }
  67661. DrawablePath::~DrawablePath()
  67662. {
  67663. }
  67664. void DrawablePath::setPath (const Path& newPath) throw()
  67665. {
  67666. path = newPath;
  67667. updateOutline();
  67668. }
  67669. void DrawablePath::setFill (const FillType& newFill) throw()
  67670. {
  67671. mainFill = newFill;
  67672. }
  67673. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67674. {
  67675. strokeFill = newFill;
  67676. }
  67677. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67678. {
  67679. strokeType = newStrokeType;
  67680. updateOutline();
  67681. }
  67682. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67683. {
  67684. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67685. }
  67686. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67687. {
  67688. {
  67689. FillType f (mainFill);
  67690. if (f.isGradient())
  67691. f.gradient->multiplyOpacity (context.opacity);
  67692. f.transform = f.transform.followedBy (context.transform);
  67693. context.g.setFillType (f);
  67694. context.g.fillPath (path, context.transform);
  67695. }
  67696. if (strokeType.getStrokeThickness() > 0.0f)
  67697. {
  67698. FillType f (strokeFill);
  67699. if (f.isGradient())
  67700. f.gradient->multiplyOpacity (context.opacity);
  67701. f.transform = f.transform.followedBy (context.transform);
  67702. context.g.setFillType (f);
  67703. context.g.fillPath (stroke, context.transform);
  67704. }
  67705. }
  67706. void DrawablePath::updateOutline()
  67707. {
  67708. stroke.clear();
  67709. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67710. }
  67711. const Rectangle<float> DrawablePath::getBounds() const
  67712. {
  67713. if (strokeType.getStrokeThickness() > 0.0f)
  67714. return stroke.getBounds();
  67715. else
  67716. return path.getBounds();
  67717. }
  67718. bool DrawablePath::hitTest (float x, float y) const
  67719. {
  67720. return path.contains (x, y)
  67721. || stroke.contains (x, y);
  67722. }
  67723. Drawable* DrawablePath::createCopy() const
  67724. {
  67725. DrawablePath* const dp = new DrawablePath();
  67726. dp->path = path;
  67727. dp->stroke = stroke;
  67728. dp->mainFill = mainFill;
  67729. dp->strokeFill = strokeFill;
  67730. dp->strokeType = strokeType;
  67731. return dp;
  67732. }
  67733. static const FillType readFillTypeFromTree (const ValueTree& v)
  67734. {
  67735. const String type (v["type"].toString());
  67736. if (type.equalsIgnoreCase (T("solid")))
  67737. {
  67738. const String colour (v ["colour"].toString());
  67739. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67740. : (uint32) colour.getHexValue32()));
  67741. }
  67742. else if (type.equalsIgnoreCase ("gradient"))
  67743. {
  67744. ColourGradient g;
  67745. g.x1 = v["x1"];
  67746. g.y1 = v["y1"];
  67747. g.x2 = v["x2"];
  67748. g.y2 = v["y2"];
  67749. g.isRadial = v["radial"];
  67750. StringArray colours;
  67751. colours.addTokens (v["colours"].toString(), false);
  67752. for (int i = 0; i < colours.size() / 2; ++i)
  67753. g.addColour (colours[i * 2].getDoubleValue(),
  67754. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67755. return FillType (g);
  67756. }
  67757. jassertfalse
  67758. return FillType();
  67759. }
  67760. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67761. {
  67762. ValueTree v (tagName);
  67763. if (fillType.isColour())
  67764. {
  67765. v.setProperty ("type", T("solid"), 0);
  67766. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67767. }
  67768. else if (fillType.isGradient())
  67769. {
  67770. v.setProperty ("type", T("gradient"), 0);
  67771. v.setProperty ("x1", fillType.gradient->x1, 0);
  67772. v.setProperty ("y1", fillType.gradient->y1, 0);
  67773. v.setProperty ("x2", fillType.gradient->x2, 0);
  67774. v.setProperty ("y2", fillType.gradient->y2, 0);
  67775. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67776. String s;
  67777. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67778. s << " " << fillType.gradient->getColourPosition (i)
  67779. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67780. v.setProperty ("colours", s.trimStart(), 0);
  67781. }
  67782. else
  67783. {
  67784. jassertfalse //xxx
  67785. }
  67786. return v;
  67787. }
  67788. ValueTree DrawablePath::createValueTree() const throw()
  67789. {
  67790. ValueTree v (T("Path"));
  67791. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67792. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67793. if (getName().isNotEmpty())
  67794. v.setProperty ("id", getName(), 0);
  67795. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67796. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67797. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67798. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67799. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67800. v.setProperty ("path", path.toString(), 0);
  67801. return v;
  67802. }
  67803. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67804. {
  67805. if (! tree.hasType ("Path"))
  67806. return 0;
  67807. DrawablePath* p = new DrawablePath();
  67808. p->setName (tree ["id"]);
  67809. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67810. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67811. const String jointStyle (tree ["jointStyle"].toString());
  67812. const String endStyle (tree ["capStyle"].toString());
  67813. p->strokeType
  67814. = PathStrokeType (tree ["strokeWidth"],
  67815. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67816. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67817. : PathStrokeType::mitered),
  67818. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67819. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67820. : PathStrokeType::butt));
  67821. p->path.clear();
  67822. p->path.restoreFromString (tree ["path"]);
  67823. p->updateOutline();
  67824. return p;
  67825. }
  67826. END_JUCE_NAMESPACE
  67827. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67828. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67829. BEGIN_JUCE_NAMESPACE
  67830. DrawableText::DrawableText()
  67831. : colour (Colours::white)
  67832. {
  67833. }
  67834. DrawableText::~DrawableText()
  67835. {
  67836. }
  67837. void DrawableText::setText (const GlyphArrangement& newText)
  67838. {
  67839. text = newText;
  67840. }
  67841. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67842. {
  67843. text.clear();
  67844. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67845. }
  67846. void DrawableText::setColour (const Colour& newColour)
  67847. {
  67848. colour = newColour;
  67849. }
  67850. void DrawableText::render (const Drawable::RenderingContext& context) const
  67851. {
  67852. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67853. text.draw (context.g, context.transform);
  67854. }
  67855. const Rectangle<float> DrawableText::getBounds() const
  67856. {
  67857. float x, y, w, h;
  67858. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67859. w -= x;
  67860. h -= y;
  67861. return Rectangle<float> (x, y, w, h);
  67862. }
  67863. bool DrawableText::hitTest (float x, float y) const
  67864. {
  67865. return text.findGlyphIndexAt (x, y) >= 0;
  67866. }
  67867. Drawable* DrawableText::createCopy() const
  67868. {
  67869. DrawableText* const dt = new DrawableText();
  67870. dt->text = text;
  67871. dt->colour = colour;
  67872. return dt;
  67873. }
  67874. ValueTree DrawableText::createValueTree() const throw()
  67875. {
  67876. ValueTree v (T("Text"));
  67877. if (getName().isNotEmpty())
  67878. v.setProperty ("id", getName(), 0);
  67879. jassertfalse // xxx not finished!
  67880. return v;
  67881. }
  67882. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67883. {
  67884. if (! tree.hasType ("Text"))
  67885. return 0;
  67886. DrawableText* dt = new DrawableText();
  67887. dt->setName (tree ["id"]);
  67888. jassertfalse // xxx not finished!
  67889. return dt;
  67890. }
  67891. END_JUCE_NAMESPACE
  67892. /*** End of inlined file: juce_DrawableText.cpp ***/
  67893. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67894. BEGIN_JUCE_NAMESPACE
  67895. class SVGState
  67896. {
  67897. public:
  67898. SVGState (const XmlElement* const topLevel)
  67899. : topLevelXml (topLevel),
  67900. elementX (0), elementY (0),
  67901. width (512), height (512),
  67902. viewBoxW (0), viewBoxH (0)
  67903. {
  67904. }
  67905. ~SVGState()
  67906. {
  67907. }
  67908. Drawable* parseSVGElement (const XmlElement& xml)
  67909. {
  67910. if (! xml.hasTagName (T("svg")))
  67911. return 0;
  67912. DrawableComposite* const drawable = new DrawableComposite();
  67913. drawable->setName (xml.getStringAttribute (T("id")));
  67914. SVGState newState (*this);
  67915. if (xml.hasAttribute (T("transform")))
  67916. newState.addTransform (xml);
  67917. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  67918. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  67919. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  67920. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  67921. if (xml.hasAttribute (T("viewBox")))
  67922. {
  67923. const String viewParams (xml.getStringAttribute (T("viewBox")));
  67924. int i = 0;
  67925. float vx, vy, vw, vh;
  67926. if (parseCoords (viewParams, vx, vy, i, true)
  67927. && parseCoords (viewParams, vw, vh, i, true)
  67928. && vw > 0
  67929. && vh > 0)
  67930. {
  67931. newState.viewBoxW = vw;
  67932. newState.viewBoxH = vh;
  67933. int placementFlags = 0;
  67934. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  67935. if (aspect.containsIgnoreCase (T("none")))
  67936. {
  67937. placementFlags = RectanglePlacement::stretchToFit;
  67938. }
  67939. else
  67940. {
  67941. if (aspect.containsIgnoreCase (T("slice")))
  67942. placementFlags |= RectanglePlacement::fillDestination;
  67943. if (aspect.containsIgnoreCase (T("xMin")))
  67944. placementFlags |= RectanglePlacement::xLeft;
  67945. else if (aspect.containsIgnoreCase (T("xMax")))
  67946. placementFlags |= RectanglePlacement::xRight;
  67947. else
  67948. placementFlags |= RectanglePlacement::xMid;
  67949. if (aspect.containsIgnoreCase (T("yMin")))
  67950. placementFlags |= RectanglePlacement::yTop;
  67951. else if (aspect.containsIgnoreCase (T("yMax")))
  67952. placementFlags |= RectanglePlacement::yBottom;
  67953. else
  67954. placementFlags |= RectanglePlacement::yMid;
  67955. }
  67956. const RectanglePlacement placement (placementFlags);
  67957. newState.transform
  67958. = placement.getTransformToFit (vx, vy, vw, vh,
  67959. 0.0f, 0.0f, newState.width, newState.height)
  67960. .followedBy (newState.transform);
  67961. }
  67962. }
  67963. else
  67964. {
  67965. if (viewBoxW == 0)
  67966. newState.viewBoxW = newState.width;
  67967. if (viewBoxH == 0)
  67968. newState.viewBoxH = newState.height;
  67969. }
  67970. newState.parseSubElements (xml, drawable);
  67971. return drawable;
  67972. }
  67973. private:
  67974. const XmlElement* const topLevelXml;
  67975. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67976. AffineTransform transform;
  67977. String cssStyleText;
  67978. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67979. {
  67980. forEachXmlChildElement (xml, e)
  67981. {
  67982. Drawable* d = 0;
  67983. if (e->hasTagName (T("g")))
  67984. d = parseGroupElement (*e);
  67985. else if (e->hasTagName (T("svg")))
  67986. d = parseSVGElement (*e);
  67987. else if (e->hasTagName (T("path")))
  67988. d = parsePath (*e);
  67989. else if (e->hasTagName (T("rect")))
  67990. d = parseRect (*e);
  67991. else if (e->hasTagName (T("circle")))
  67992. d = parseCircle (*e);
  67993. else if (e->hasTagName (T("ellipse")))
  67994. d = parseEllipse (*e);
  67995. else if (e->hasTagName (T("line")))
  67996. d = parseLine (*e);
  67997. else if (e->hasTagName (T("polyline")))
  67998. d = parsePolygon (*e, true);
  67999. else if (e->hasTagName (T("polygon")))
  68000. d = parsePolygon (*e, false);
  68001. else if (e->hasTagName (T("text")))
  68002. d = parseText (*e);
  68003. else if (e->hasTagName (T("switch")))
  68004. d = parseSwitch (*e);
  68005. else if (e->hasTagName (T("style")))
  68006. parseCSSStyle (*e);
  68007. parentDrawable->insertDrawable (d);
  68008. }
  68009. }
  68010. DrawableComposite* parseSwitch (const XmlElement& xml)
  68011. {
  68012. const XmlElement* const group = xml.getChildByName (T("g"));
  68013. if (group != 0)
  68014. return parseGroupElement (*group);
  68015. return 0;
  68016. }
  68017. DrawableComposite* parseGroupElement (const XmlElement& xml)
  68018. {
  68019. DrawableComposite* const drawable = new DrawableComposite();
  68020. drawable->setName (xml.getStringAttribute (T("id")));
  68021. if (xml.hasAttribute (T("transform")))
  68022. {
  68023. SVGState newState (*this);
  68024. newState.addTransform (xml);
  68025. newState.parseSubElements (xml, drawable);
  68026. }
  68027. else
  68028. {
  68029. parseSubElements (xml, drawable);
  68030. }
  68031. return drawable;
  68032. }
  68033. Drawable* parsePath (const XmlElement& xml) const
  68034. {
  68035. const String d (xml.getStringAttribute (T("d")).trimStart());
  68036. Path path;
  68037. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  68038. path.setUsingNonZeroWinding (false);
  68039. int index = 0;
  68040. float lastX = 0, lastY = 0;
  68041. float lastX2 = 0, lastY2 = 0;
  68042. tchar lastCommandChar = 0;
  68043. bool carryOn = true;
  68044. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  68045. for (;;)
  68046. {
  68047. float x, y, x2, y2, x3, y3;
  68048. const bool isRelative = (d[index] >= 'a' && d[index] <= 'z');
  68049. if (validCommandChars.containsChar (d[index]))
  68050. lastCommandChar = d [index++];
  68051. switch (lastCommandChar)
  68052. {
  68053. case T('M'):
  68054. case T('m'):
  68055. case T('L'):
  68056. case T('l'):
  68057. if (parseCoords (d, x, y, index, false))
  68058. {
  68059. if (isRelative)
  68060. {
  68061. x += lastX;
  68062. y += lastY;
  68063. }
  68064. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  68065. path.startNewSubPath (x, y);
  68066. else
  68067. path.lineTo (x, y);
  68068. lastX2 = lastX;
  68069. lastY2 = lastY;
  68070. lastX = x;
  68071. lastY = y;
  68072. }
  68073. else
  68074. {
  68075. ++index;
  68076. }
  68077. break;
  68078. case T('H'):
  68079. case T('h'):
  68080. if (parseCoord (d, x, index, false, true))
  68081. {
  68082. if (isRelative)
  68083. x += lastX;
  68084. path.lineTo (x, lastY);
  68085. lastX2 = lastX;
  68086. lastX = x;
  68087. }
  68088. else
  68089. {
  68090. ++index;
  68091. }
  68092. break;
  68093. case T('V'):
  68094. case T('v'):
  68095. if (parseCoord (d, y, index, false, false))
  68096. {
  68097. if (isRelative)
  68098. y += lastY;
  68099. path.lineTo (lastX, y);
  68100. lastY2 = lastY;
  68101. lastY = y;
  68102. }
  68103. else
  68104. {
  68105. ++index;
  68106. }
  68107. break;
  68108. case T('C'):
  68109. case T('c'):
  68110. if (parseCoords (d, x, y, index, false)
  68111. && parseCoords (d, x2, y2, index, false)
  68112. && parseCoords (d, x3, y3, index, false))
  68113. {
  68114. if (isRelative)
  68115. {
  68116. x += lastX;
  68117. y += lastY;
  68118. x2 += lastX;
  68119. y2 += lastY;
  68120. x3 += lastX;
  68121. y3 += lastY;
  68122. }
  68123. path.cubicTo (x, y, x2, y2, x3, y3);
  68124. lastX2 = x2;
  68125. lastY2 = y2;
  68126. lastX = x3;
  68127. lastY = y3;
  68128. }
  68129. else
  68130. {
  68131. ++index;
  68132. }
  68133. break;
  68134. case T('S'):
  68135. case T('s'):
  68136. if (parseCoords (d, x, y, index, false)
  68137. && parseCoords (d, x3, y3, index, false))
  68138. {
  68139. if (isRelative)
  68140. {
  68141. x += lastX;
  68142. y += lastY;
  68143. x3 += lastX;
  68144. y3 += lastY;
  68145. }
  68146. x2 = lastX + (lastX - lastX2);
  68147. y2 = lastY + (lastY - lastY2);
  68148. path.cubicTo (x2, y2, x, y, x3, y3);
  68149. lastX2 = x;
  68150. lastY2 = y;
  68151. lastX = x3;
  68152. lastY = y3;
  68153. }
  68154. else
  68155. {
  68156. ++index;
  68157. }
  68158. break;
  68159. case T('Q'):
  68160. case T('q'):
  68161. if (parseCoords (d, x, y, index, false)
  68162. && parseCoords (d, x2, y2, index, false))
  68163. {
  68164. if (isRelative)
  68165. {
  68166. x += lastX;
  68167. y += lastY;
  68168. x2 += lastX;
  68169. y2 += lastY;
  68170. }
  68171. path.quadraticTo (x, y, x2, y2);
  68172. lastX2 = x;
  68173. lastY2 = y;
  68174. lastX = x2;
  68175. lastY = y2;
  68176. }
  68177. else
  68178. {
  68179. ++index;
  68180. }
  68181. break;
  68182. case T('T'):
  68183. case T('t'):
  68184. if (parseCoords (d, x, y, index, false))
  68185. {
  68186. if (isRelative)
  68187. {
  68188. x += lastX;
  68189. y += lastY;
  68190. }
  68191. x2 = lastX + (lastX - lastX2);
  68192. y2 = lastY + (lastY - lastY2);
  68193. path.quadraticTo (x2, y2, x, y);
  68194. lastX2 = x2;
  68195. lastY2 = y2;
  68196. lastX = x;
  68197. lastY = y;
  68198. }
  68199. else
  68200. {
  68201. ++index;
  68202. }
  68203. break;
  68204. case T('A'):
  68205. case T('a'):
  68206. if (parseCoords (d, x, y, index, false))
  68207. {
  68208. String num;
  68209. if (parseNextNumber (d, num, index, false))
  68210. {
  68211. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  68212. if (parseNextNumber (d, num, index, false))
  68213. {
  68214. const bool largeArc = num.getIntValue() != 0;
  68215. if (parseNextNumber (d, num, index, false))
  68216. {
  68217. const bool sweep = num.getIntValue() != 0;
  68218. if (parseCoords (d, x2, y2, index, false))
  68219. {
  68220. if (isRelative)
  68221. {
  68222. x2 += lastX;
  68223. y2 += lastY;
  68224. }
  68225. if (lastX != x2 || lastY != y2)
  68226. {
  68227. double centreX, centreY, startAngle, deltaAngle;
  68228. double rx = x, ry = y;
  68229. endpointToCentreParameters (lastX, lastY, x2, y2,
  68230. angle, largeArc, sweep,
  68231. rx, ry, centreX, centreY,
  68232. startAngle, deltaAngle);
  68233. path.addCentredArc ((float) centreX, (float) centreY,
  68234. (float) rx, (float) ry,
  68235. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  68236. false);
  68237. path.lineTo (x2, y2);
  68238. }
  68239. lastX2 = lastX;
  68240. lastY2 = lastY;
  68241. lastX = x2;
  68242. lastY = y2;
  68243. }
  68244. }
  68245. }
  68246. }
  68247. }
  68248. else
  68249. {
  68250. ++index;
  68251. }
  68252. break;
  68253. case T('Z'):
  68254. case T('z'):
  68255. path.closeSubPath();
  68256. while (CharacterFunctions::isWhitespace (d [index]))
  68257. ++index;
  68258. break;
  68259. default:
  68260. carryOn = false;
  68261. break;
  68262. }
  68263. if (! carryOn)
  68264. break;
  68265. }
  68266. return parseShape (xml, path);
  68267. }
  68268. Drawable* parseRect (const XmlElement& xml) const
  68269. {
  68270. Path rect;
  68271. const bool hasRX = xml.hasAttribute (T("rx"));
  68272. const bool hasRY = xml.hasAttribute (T("ry"));
  68273. if (hasRX || hasRY)
  68274. {
  68275. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68276. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68277. if (! hasRX)
  68278. rx = ry;
  68279. else if (! hasRY)
  68280. ry = rx;
  68281. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68282. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68283. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68284. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  68285. rx, ry);
  68286. }
  68287. else
  68288. {
  68289. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68290. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68291. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68292. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  68293. }
  68294. return parseShape (xml, rect);
  68295. }
  68296. Drawable* parseCircle (const XmlElement& xml) const
  68297. {
  68298. Path circle;
  68299. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68300. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68301. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  68302. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  68303. return parseShape (xml, circle);
  68304. }
  68305. Drawable* parseEllipse (const XmlElement& xml) const
  68306. {
  68307. Path ellipse;
  68308. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68309. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68310. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68311. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68312. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68313. return parseShape (xml, ellipse);
  68314. }
  68315. Drawable* parseLine (const XmlElement& xml) const
  68316. {
  68317. Path line;
  68318. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68319. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68320. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68321. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68322. line.startNewSubPath (x1, y1);
  68323. line.lineTo (x2, y2);
  68324. return parseShape (xml, line);
  68325. }
  68326. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68327. {
  68328. const String points (xml.getStringAttribute (T("points")));
  68329. Path path;
  68330. int index = 0;
  68331. float x, y;
  68332. if (parseCoords (points, x, y, index, true))
  68333. {
  68334. float firstX = x;
  68335. float firstY = y;
  68336. float lastX = 0, lastY = 0;
  68337. path.startNewSubPath (x, y);
  68338. while (parseCoords (points, x, y, index, true))
  68339. {
  68340. lastX = x;
  68341. lastY = y;
  68342. path.lineTo (x, y);
  68343. }
  68344. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68345. path.closeSubPath();
  68346. }
  68347. return parseShape (xml, path);
  68348. }
  68349. Drawable* parseShape (const XmlElement& xml, Path& path,
  68350. const bool shouldParseTransform = true) const
  68351. {
  68352. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68353. {
  68354. SVGState newState (*this);
  68355. newState.addTransform (xml);
  68356. return newState.parseShape (xml, path, false);
  68357. }
  68358. DrawablePath* dp = new DrawablePath();
  68359. dp->setName (xml.getStringAttribute (T("id")));
  68360. dp->setFill (FillType (Colours::transparentBlack));
  68361. path.applyTransform (transform);
  68362. dp->setPath (path);
  68363. Path::Iterator iter (path);
  68364. bool containsClosedSubPath = false;
  68365. while (iter.next())
  68366. {
  68367. if (iter.elementType == Path::Iterator::closePath)
  68368. {
  68369. containsClosedSubPath = true;
  68370. break;
  68371. }
  68372. }
  68373. dp->setFill (getPathFillType (path,
  68374. getStyleAttribute (&xml, T("fill")),
  68375. getStyleAttribute (&xml, T("fill-opacity")),
  68376. getStyleAttribute (&xml, T("opacity")),
  68377. containsClosedSubPath ? Colours::black
  68378. : Colours::transparentBlack));
  68379. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68380. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68381. {
  68382. dp->setStrokeFill (getPathFillType (path, strokeType,
  68383. getStyleAttribute (&xml, T("stroke-opacity")),
  68384. getStyleAttribute (&xml, T("opacity")),
  68385. Colours::transparentBlack));
  68386. dp->setStrokeType (getStrokeFor (&xml));
  68387. }
  68388. return dp;
  68389. }
  68390. const XmlElement* findLinkedElement (const XmlElement* e) const
  68391. {
  68392. const String id (e->getStringAttribute (T("xlink:href")));
  68393. if (! id.startsWithChar (T('#')))
  68394. return 0;
  68395. return findElementForId (topLevelXml, id.substring (1));
  68396. }
  68397. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68398. {
  68399. if (fillXml == 0)
  68400. return;
  68401. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68402. {
  68403. int index = 0;
  68404. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68405. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68406. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68407. double offset = e->getDoubleAttribute (T("offset"));
  68408. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68409. offset *= 0.01;
  68410. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68411. }
  68412. }
  68413. const FillType getPathFillType (const Path& path,
  68414. const String& fill,
  68415. const String& fillOpacity,
  68416. const String& overallOpacity,
  68417. const Colour& defaultColour) const
  68418. {
  68419. float opacity = 1.0f;
  68420. if (overallOpacity.isNotEmpty())
  68421. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68422. if (fillOpacity.isNotEmpty())
  68423. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68424. if (fill.startsWithIgnoreCase (T("url")))
  68425. {
  68426. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68427. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68428. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68429. if (fillXml != 0
  68430. && (fillXml->hasTagName (T("linearGradient"))
  68431. || fillXml->hasTagName (T("radialGradient"))))
  68432. {
  68433. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68434. ColourGradient gradient;
  68435. addGradientStopsIn (gradient, inheritedFrom);
  68436. addGradientStopsIn (gradient, fillXml);
  68437. if (gradient.getNumColours() > 0)
  68438. {
  68439. gradient.addColour (0.0, gradient.getColour (0));
  68440. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68441. }
  68442. else
  68443. {
  68444. gradient.addColour (0.0, Colours::black);
  68445. gradient.addColour (1.0, Colours::black);
  68446. }
  68447. if (overallOpacity.isNotEmpty())
  68448. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68449. jassert (gradient.getNumColours() > 0);
  68450. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68451. float width = viewBoxW;
  68452. float height = viewBoxH;
  68453. float dx = 0.0f;
  68454. float dy = 0.0f;
  68455. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68456. if (! userSpace)
  68457. {
  68458. const Rectangle<float> bounds (path.getBounds());
  68459. dx = bounds.getX();
  68460. dy = bounds.getY();
  68461. width = bounds.getWidth();
  68462. height = bounds.getHeight();
  68463. }
  68464. if (gradient.isRadial)
  68465. {
  68466. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68467. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68468. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68469. gradient.x2 = gradient.x1 + radius;
  68470. gradient.y2 = gradient.y1;
  68471. //xxx (the fx, fy focal point isn't handled properly here..)
  68472. }
  68473. else
  68474. {
  68475. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68476. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68477. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68478. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68479. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68480. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68481. }
  68482. FillType type (gradient);
  68483. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68484. .followedBy (transform);
  68485. return type;
  68486. }
  68487. }
  68488. if (fill.equalsIgnoreCase (T("none")))
  68489. return Colours::transparentBlack;
  68490. int i = 0;
  68491. const Colour colour (parseColour (fill, i, defaultColour));
  68492. return colour.withMultipliedAlpha (opacity);
  68493. }
  68494. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68495. {
  68496. const String width (getStyleAttribute (xml, T("stroke-width")));
  68497. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68498. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68499. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68500. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68501. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68502. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68503. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68504. if (join.equalsIgnoreCase (T("round")))
  68505. joinStyle = PathStrokeType::curved;
  68506. else if (join.equalsIgnoreCase (T("bevel")))
  68507. joinStyle = PathStrokeType::beveled;
  68508. if (cap.equalsIgnoreCase (T("round")))
  68509. capStyle = PathStrokeType::rounded;
  68510. else if (cap.equalsIgnoreCase (T("square")))
  68511. capStyle = PathStrokeType::square;
  68512. float ox = 0.0f, oy = 0.0f;
  68513. transform.transformPoint (ox, oy);
  68514. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68515. transform.transformPoint (x, y);
  68516. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68517. joinStyle, capStyle);
  68518. }
  68519. Drawable* parseText (const XmlElement& xml)
  68520. {
  68521. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68522. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68523. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68524. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68525. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68526. //xxx not done text yet!
  68527. forEachXmlChildElement (xml, e)
  68528. {
  68529. if (e->isTextElement())
  68530. {
  68531. const String text (e->getText());
  68532. Path path;
  68533. Drawable* s = parseShape (*e, path);
  68534. delete s;
  68535. }
  68536. else if (e->hasTagName (T("tspan")))
  68537. {
  68538. Drawable* s = parseText (*e);
  68539. delete s;
  68540. }
  68541. }
  68542. return 0;
  68543. }
  68544. void addTransform (const XmlElement& xml)
  68545. {
  68546. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68547. .followedBy (transform);
  68548. }
  68549. bool parseCoord (const String& s, float& value, int& index,
  68550. const bool allowUnits, const bool isX) const
  68551. {
  68552. String number;
  68553. if (! parseNextNumber (s, number, index, allowUnits))
  68554. {
  68555. value = 0;
  68556. return false;
  68557. }
  68558. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68559. return true;
  68560. }
  68561. bool parseCoords (const String& s, float& x, float& y,
  68562. int& index, const bool allowUnits) const
  68563. {
  68564. return parseCoord (s, x, index, allowUnits, true)
  68565. && parseCoord (s, y, index, allowUnits, false);
  68566. }
  68567. float getCoordLength (const String& s, const float sizeForProportions) const
  68568. {
  68569. float n = s.getFloatValue();
  68570. const int len = s.length();
  68571. if (len > 2)
  68572. {
  68573. const float dpi = 96.0f;
  68574. const tchar n1 = s [len - 2];
  68575. const tchar n2 = s [len - 1];
  68576. if (n1 == T('i') && n2 == T('n'))
  68577. n *= dpi;
  68578. else if (n1 == T('m') && n2 == T('m'))
  68579. n *= dpi / 25.4f;
  68580. else if (n1 == T('c') && n2 == T('m'))
  68581. n *= dpi / 2.54f;
  68582. else if (n1 == T('p') && n2 == T('c'))
  68583. n *= 15.0f;
  68584. else if (n2 == T('%'))
  68585. n *= 0.01f * sizeForProportions;
  68586. }
  68587. return n;
  68588. }
  68589. void getCoordList (Array <float>& coords, const String& list,
  68590. const bool allowUnits, const bool isX) const
  68591. {
  68592. int index = 0;
  68593. float value;
  68594. while (parseCoord (list, value, index, allowUnits, isX))
  68595. coords.add (value);
  68596. }
  68597. void parseCSSStyle (const XmlElement& xml)
  68598. {
  68599. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68600. }
  68601. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68602. const String& defaultValue = String::empty) const
  68603. {
  68604. if (xml->hasAttribute (attributeName))
  68605. return xml->getStringAttribute (attributeName, defaultValue);
  68606. const String styleAtt (xml->getStringAttribute (T("style")));
  68607. if (styleAtt.isNotEmpty())
  68608. {
  68609. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68610. if (value.isNotEmpty())
  68611. return value;
  68612. }
  68613. else if (xml->hasAttribute (T("class")))
  68614. {
  68615. const String className (T(".") + xml->getStringAttribute (T("class")));
  68616. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68617. if (index < 0)
  68618. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68619. if (index >= 0)
  68620. {
  68621. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68622. if (openBracket > index)
  68623. {
  68624. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68625. if (closeBracket > openBracket)
  68626. {
  68627. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68628. if (value.isNotEmpty())
  68629. return value;
  68630. }
  68631. }
  68632. }
  68633. }
  68634. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68635. if (xml != 0)
  68636. return getStyleAttribute (xml, attributeName, defaultValue);
  68637. return defaultValue;
  68638. }
  68639. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68640. {
  68641. if (xml->hasAttribute (attributeName))
  68642. return xml->getStringAttribute (attributeName);
  68643. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68644. if (xml != 0)
  68645. return getInheritedAttribute (xml, attributeName);
  68646. return String::empty;
  68647. }
  68648. static bool isIdentifierChar (const tchar c)
  68649. {
  68650. return CharacterFunctions::isLetter (c) || c == T('-');
  68651. }
  68652. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68653. {
  68654. int i = 0;
  68655. for (;;)
  68656. {
  68657. i = list.indexOf (i, attributeName);
  68658. if (i < 0)
  68659. break;
  68660. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68661. && ! isIdentifierChar (list [i + attributeName.length()]))
  68662. {
  68663. i = list.indexOfChar (i, T(':'));
  68664. if (i < 0)
  68665. break;
  68666. int end = list.indexOfChar (i, T(';'));
  68667. if (end < 0)
  68668. end = 0x7ffff;
  68669. return list.substring (i + 1, end).trim();
  68670. }
  68671. ++i;
  68672. }
  68673. return defaultValue;
  68674. }
  68675. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68676. {
  68677. const tchar* const s = (const tchar*) source;
  68678. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68679. ++index;
  68680. int start = index;
  68681. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68682. ++index;
  68683. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68684. ++index;
  68685. if ((s[index] == T('e') || s[index] == T('E'))
  68686. && (CharacterFunctions::isDigit (s[index + 1])
  68687. || s[index + 1] == T('-')
  68688. || s[index + 1] == T('+')))
  68689. {
  68690. index += 2;
  68691. while (CharacterFunctions::isDigit (s[index]))
  68692. ++index;
  68693. }
  68694. if (allowUnits)
  68695. {
  68696. while (CharacterFunctions::isLetter (s[index]))
  68697. ++index;
  68698. }
  68699. if (index == start)
  68700. return false;
  68701. value = String (s + start, index - start);
  68702. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68703. ++index;
  68704. return true;
  68705. }
  68706. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68707. {
  68708. if (s [index] == T('#'))
  68709. {
  68710. uint32 hex [6];
  68711. zeromem (hex, sizeof (hex));
  68712. int numChars = 0;
  68713. for (int i = 6; --i >= 0;)
  68714. {
  68715. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68716. if (hexValue >= 0)
  68717. hex [numChars++] = hexValue;
  68718. else
  68719. break;
  68720. }
  68721. if (numChars <= 3)
  68722. return Colour ((uint8) (hex [0] * 0x11),
  68723. (uint8) (hex [1] * 0x11),
  68724. (uint8) (hex [2] * 0x11));
  68725. else
  68726. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68727. (uint8) ((hex [2] << 4) + hex [3]),
  68728. (uint8) ((hex [4] << 4) + hex [5]));
  68729. }
  68730. else if (s [index] == T('r')
  68731. && s [index + 1] == T('g')
  68732. && s [index + 2] == T('b'))
  68733. {
  68734. const int openBracket = s.indexOfChar (index, T('('));
  68735. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68736. if (openBracket >= 3 && closeBracket > openBracket)
  68737. {
  68738. index = closeBracket;
  68739. StringArray tokens;
  68740. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68741. tokens.trim();
  68742. tokens.removeEmptyStrings();
  68743. if (tokens[0].containsChar (T('%')))
  68744. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68745. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68746. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68747. else
  68748. return Colour ((uint8) tokens[0].getIntValue(),
  68749. (uint8) tokens[1].getIntValue(),
  68750. (uint8) tokens[2].getIntValue());
  68751. }
  68752. }
  68753. return Colours::findColourForName (s, defaultColour);
  68754. }
  68755. static const AffineTransform parseTransform (String t)
  68756. {
  68757. AffineTransform result;
  68758. while (t.isNotEmpty())
  68759. {
  68760. StringArray tokens;
  68761. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68762. .upToFirstOccurrenceOf (T(")"), false, false),
  68763. T(", "), 0);
  68764. tokens.removeEmptyStrings (true);
  68765. float numbers [6];
  68766. for (int i = 0; i < 6; ++i)
  68767. numbers[i] = tokens[i].getFloatValue();
  68768. AffineTransform trans;
  68769. if (t.startsWithIgnoreCase (T("matrix")))
  68770. {
  68771. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68772. numbers[1], numbers[3], numbers[5]);
  68773. }
  68774. else if (t.startsWithIgnoreCase (T("translate")))
  68775. {
  68776. trans = trans.translated (numbers[0], numbers[1]);
  68777. }
  68778. else if (t.startsWithIgnoreCase (T("scale")))
  68779. {
  68780. if (tokens.size() == 1)
  68781. trans = trans.scaled (numbers[0], numbers[0]);
  68782. else
  68783. trans = trans.scaled (numbers[0], numbers[1]);
  68784. }
  68785. else if (t.startsWithIgnoreCase (T("rotate")))
  68786. {
  68787. if (tokens.size() != 3)
  68788. trans = trans.rotated (numbers[0] / (180.0f / float_Pi));
  68789. else
  68790. trans = trans.rotated (numbers[0] / (180.0f / float_Pi),
  68791. numbers[1], numbers[2]);
  68792. }
  68793. else if (t.startsWithIgnoreCase (T("skewX")))
  68794. {
  68795. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68796. 0.0f, 1.0f, 0.0f);
  68797. }
  68798. else if (t.startsWithIgnoreCase (T("skewY")))
  68799. {
  68800. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68801. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68802. }
  68803. result = trans.followedBy (result);
  68804. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68805. }
  68806. return result;
  68807. }
  68808. static void endpointToCentreParameters (const double x1, const double y1,
  68809. const double x2, const double y2,
  68810. const double angle,
  68811. const bool largeArc, const bool sweep,
  68812. double& rx, double& ry,
  68813. double& centreX, double& centreY,
  68814. double& startAngle, double& deltaAngle)
  68815. {
  68816. const double midX = (x1 - x2) * 0.5;
  68817. const double midY = (y1 - y2) * 0.5;
  68818. const double cosAngle = cos (angle);
  68819. const double sinAngle = sin (angle);
  68820. const double xp = cosAngle * midX + sinAngle * midY;
  68821. const double yp = cosAngle * midY - sinAngle * midX;
  68822. const double xp2 = xp * xp;
  68823. const double yp2 = yp * yp;
  68824. double rx2 = rx * rx;
  68825. double ry2 = ry * ry;
  68826. const double s = (xp2 / rx2) + (yp2 / ry2);
  68827. double c;
  68828. if (s <= 1.0)
  68829. {
  68830. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68831. / (( rx2 * yp2) + (ry2 * xp2))));
  68832. if (largeArc == sweep)
  68833. c = -c;
  68834. }
  68835. else
  68836. {
  68837. const double s2 = sqrt (s);
  68838. rx *= s2;
  68839. ry *= s2;
  68840. rx2 = rx * rx;
  68841. ry2 = ry * ry;
  68842. c = 0;
  68843. }
  68844. const double cpx = ((rx * yp) / ry) * c;
  68845. const double cpy = ((-ry * xp) / rx) * c;
  68846. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68847. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68848. const double ux = (xp - cpx) / rx;
  68849. const double uy = (yp - cpy) / ry;
  68850. const double vx = (-xp - cpx) / rx;
  68851. const double vy = (-yp - cpy) / ry;
  68852. const double length = juce_hypot (ux, uy);
  68853. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68854. if (uy < 0)
  68855. startAngle = -startAngle;
  68856. startAngle += double_Pi * 0.5;
  68857. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68858. / (length * juce_hypot (vx, vy))));
  68859. if ((ux * vy) - (uy * vx) < 0)
  68860. deltaAngle = -deltaAngle;
  68861. if (sweep)
  68862. {
  68863. if (deltaAngle < 0)
  68864. deltaAngle += double_Pi * 2.0;
  68865. }
  68866. else
  68867. {
  68868. if (deltaAngle > 0)
  68869. deltaAngle -= double_Pi * 2.0;
  68870. }
  68871. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68872. }
  68873. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68874. {
  68875. forEachXmlChildElement (*parent, e)
  68876. {
  68877. if (e->compareAttribute (T("id"), id))
  68878. return e;
  68879. const XmlElement* const found = findElementForId (e, id);
  68880. if (found != 0)
  68881. return found;
  68882. }
  68883. return 0;
  68884. }
  68885. const SVGState& operator= (const SVGState&);
  68886. };
  68887. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68888. {
  68889. SVGState state (&svgDocument);
  68890. return state.parseSVGElement (svgDocument);
  68891. }
  68892. END_JUCE_NAMESPACE
  68893. /*** End of inlined file: juce_SVGParser.cpp ***/
  68894. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68895. BEGIN_JUCE_NAMESPACE
  68896. #if JUCE_MSVC
  68897. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68898. #endif
  68899. DropShadowEffect::DropShadowEffect()
  68900. : offsetX (0),
  68901. offsetY (0),
  68902. radius (4),
  68903. opacity (0.6f)
  68904. {
  68905. }
  68906. DropShadowEffect::~DropShadowEffect()
  68907. {
  68908. }
  68909. void DropShadowEffect::setShadowProperties (const float newRadius,
  68910. const float newOpacity,
  68911. const int newShadowOffsetX,
  68912. const int newShadowOffsetY)
  68913. {
  68914. radius = jmax (1.1f, newRadius);
  68915. offsetX = newShadowOffsetX;
  68916. offsetY = newShadowOffsetY;
  68917. opacity = newOpacity;
  68918. }
  68919. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68920. {
  68921. const int w = image.getWidth();
  68922. const int h = image.getHeight();
  68923. Image shadowImage (Image::SingleChannel, w, h, false);
  68924. const Image::BitmapData srcData (image, 0, 0, w, h);
  68925. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68926. const int filter = roundToInt (63.0f / radius);
  68927. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68928. for (int x = w; --x >= 0;)
  68929. {
  68930. int shadowAlpha = 0;
  68931. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68932. uint8* shadowPix = destData.data + x;
  68933. for (int y = h; --y >= 0;)
  68934. {
  68935. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68936. *shadowPix = (uint8) shadowAlpha;
  68937. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68938. shadowPix += destData.lineStride;
  68939. }
  68940. }
  68941. for (int y = h; --y >= 0;)
  68942. {
  68943. int shadowAlpha = 0;
  68944. uint8* shadowPix = destData.getLinePointer (y);
  68945. for (int x = w; --x >= 0;)
  68946. {
  68947. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68948. *shadowPix++ = (uint8) shadowAlpha;
  68949. }
  68950. }
  68951. g.setColour (Colours::black.withAlpha (opacity));
  68952. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68953. g.setOpacity (1.0f);
  68954. g.drawImageAt (&image, 0, 0);
  68955. }
  68956. END_JUCE_NAMESPACE
  68957. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68958. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68959. BEGIN_JUCE_NAMESPACE
  68960. GlowEffect::GlowEffect()
  68961. : radius (2.0f),
  68962. colour (Colours::white)
  68963. {
  68964. }
  68965. GlowEffect::~GlowEffect()
  68966. {
  68967. }
  68968. void GlowEffect::setGlowProperties (const float newRadius,
  68969. const Colour& newColour)
  68970. {
  68971. radius = newRadius;
  68972. colour = newColour;
  68973. }
  68974. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68975. {
  68976. const int w = image.getWidth();
  68977. const int h = image.getHeight();
  68978. Image temp (image.getFormat(), w, h, true);
  68979. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68980. blurKernel.createGaussianBlur (radius);
  68981. blurKernel.rescaleAllValues (radius);
  68982. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  68983. g.setColour (colour);
  68984. g.drawImageAt (&temp, 0, 0, true);
  68985. g.setOpacity (1.0f);
  68986. g.drawImageAt (&image, 0, 0, false);
  68987. }
  68988. END_JUCE_NAMESPACE
  68989. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68990. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68991. BEGIN_JUCE_NAMESPACE
  68992. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68993. : opacity (opacity_)
  68994. {
  68995. }
  68996. ReduceOpacityEffect::~ReduceOpacityEffect()
  68997. {
  68998. }
  68999. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  69000. {
  69001. opacity = jlimit (0.0f, 1.0f, newOpacity);
  69002. }
  69003. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  69004. {
  69005. g.setOpacity (opacity);
  69006. g.drawImageAt (&image, 0, 0);
  69007. }
  69008. END_JUCE_NAMESPACE
  69009. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69010. /*** Start of inlined file: juce_Font.cpp ***/
  69011. BEGIN_JUCE_NAMESPACE
  69012. static const float minFontHeight = 0.1f;
  69013. static const float maxFontHeight = 10000.0f;
  69014. static const float defaultFontHeight = 14.0f;
  69015. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  69016. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  69017. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  69018. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  69019. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  69020. const float kerning_, const float ascent_, const int styleFlags_,
  69021. Typeface* const typeface_) throw()
  69022. : typefaceName (typefaceName_),
  69023. height (height_),
  69024. horizontalScale (horizontalScale_),
  69025. kerning (kerning_),
  69026. ascent (ascent_),
  69027. styleFlags (styleFlags_),
  69028. typeface (typeface_)
  69029. {
  69030. }
  69031. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  69032. : typefaceName (other.typefaceName),
  69033. height (other.height),
  69034. horizontalScale (other.horizontalScale),
  69035. kerning (other.kerning),
  69036. ascent (other.ascent),
  69037. styleFlags (other.styleFlags),
  69038. typeface (other.typeface)
  69039. {
  69040. }
  69041. Font::Font() throw()
  69042. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  69043. 1.0f, 0, 0, Font::plain, 0))
  69044. {
  69045. }
  69046. Font::Font (const float fontHeight, const int styleFlags_) throw()
  69047. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69048. 1.0f, 0, 0, styleFlags_, 0))
  69049. {
  69050. }
  69051. Font::Font (const String& typefaceName_,
  69052. const float fontHeight,
  69053. const int styleFlags_) throw()
  69054. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69055. 1.0f, 0, 0, styleFlags_, 0))
  69056. {
  69057. }
  69058. Font::Font (const Font& other) throw()
  69059. : font (other.font)
  69060. {
  69061. }
  69062. const Font& Font::operator= (const Font& other) throw()
  69063. {
  69064. font = other.font;
  69065. return *this;
  69066. }
  69067. Font::~Font() throw()
  69068. {
  69069. }
  69070. Font::Font (const Typeface::Ptr& typeface) throw()
  69071. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  69072. 1.0f, 0, 0, Font::plain, typeface))
  69073. {
  69074. }
  69075. bool Font::operator== (const Font& other) const throw()
  69076. {
  69077. return font == other.font
  69078. || (font->height == other.font->height
  69079. && font->styleFlags == other.font->styleFlags
  69080. && font->horizontalScale == other.font->horizontalScale
  69081. && font->kerning == other.font->kerning
  69082. && font->typefaceName == other.font->typefaceName);
  69083. }
  69084. bool Font::operator!= (const Font& other) const throw()
  69085. {
  69086. return ! operator== (other);
  69087. }
  69088. void Font::dupeInternalIfShared() throw()
  69089. {
  69090. if (font->getReferenceCount() > 1)
  69091. font = new SharedFontInternal (*font);
  69092. }
  69093. const String Font::getDefaultSansSerifFontName() throw()
  69094. {
  69095. return juce_defaultFontNameSans;
  69096. }
  69097. const String Font::getDefaultSerifFontName() throw()
  69098. {
  69099. return juce_defaultFontNameSerif;
  69100. }
  69101. const String Font::getDefaultMonospacedFontName() throw()
  69102. {
  69103. return juce_defaultFontNameMono;
  69104. }
  69105. void Font::setTypefaceName (const String& faceName) throw()
  69106. {
  69107. if (faceName != font->typefaceName)
  69108. {
  69109. dupeInternalIfShared();
  69110. font->typefaceName = faceName;
  69111. font->typeface = 0;
  69112. font->ascent = 0;
  69113. }
  69114. }
  69115. static String fallbackFont;
  69116. const String Font::getFallbackFontName() throw()
  69117. {
  69118. return fallbackFont;
  69119. }
  69120. void Font::setFallbackFontName (const String& name) throw()
  69121. {
  69122. fallbackFont = name;
  69123. }
  69124. void Font::setHeight (float newHeight) throw()
  69125. {
  69126. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69127. if (font->height != newHeight)
  69128. {
  69129. dupeInternalIfShared();
  69130. font->height = newHeight;
  69131. }
  69132. }
  69133. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  69134. {
  69135. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69136. if (font->height != newHeight)
  69137. {
  69138. dupeInternalIfShared();
  69139. font->horizontalScale *= (font->height / newHeight);
  69140. font->height = newHeight;
  69141. }
  69142. }
  69143. void Font::setStyleFlags (const int newFlags) throw()
  69144. {
  69145. if (font->styleFlags != newFlags)
  69146. {
  69147. dupeInternalIfShared();
  69148. font->styleFlags = newFlags;
  69149. font->typeface = 0;
  69150. font->ascent = 0;
  69151. }
  69152. }
  69153. void Font::setSizeAndStyle (float newHeight,
  69154. const int newStyleFlags,
  69155. const float newHorizontalScale,
  69156. const float newKerningAmount) throw()
  69157. {
  69158. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69159. if (font->height != newHeight
  69160. || font->horizontalScale != newHorizontalScale
  69161. || font->kerning != newKerningAmount)
  69162. {
  69163. dupeInternalIfShared();
  69164. font->height = newHeight;
  69165. font->horizontalScale = newHorizontalScale;
  69166. font->kerning = newKerningAmount;
  69167. }
  69168. setStyleFlags (newStyleFlags);
  69169. }
  69170. void Font::setHorizontalScale (const float scaleFactor) throw()
  69171. {
  69172. dupeInternalIfShared();
  69173. font->horizontalScale = scaleFactor;
  69174. }
  69175. void Font::setExtraKerningFactor (const float extraKerning) throw()
  69176. {
  69177. dupeInternalIfShared();
  69178. font->kerning = extraKerning;
  69179. }
  69180. void Font::setBold (const bool shouldBeBold) throw()
  69181. {
  69182. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  69183. : (font->styleFlags & ~bold));
  69184. }
  69185. bool Font::isBold() const throw()
  69186. {
  69187. return (font->styleFlags & bold) != 0;
  69188. }
  69189. void Font::setItalic (const bool shouldBeItalic) throw()
  69190. {
  69191. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  69192. : (font->styleFlags & ~italic));
  69193. }
  69194. bool Font::isItalic() const throw()
  69195. {
  69196. return (font->styleFlags & italic) != 0;
  69197. }
  69198. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  69199. {
  69200. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  69201. : (font->styleFlags & ~underlined));
  69202. }
  69203. bool Font::isUnderlined() const throw()
  69204. {
  69205. return (font->styleFlags & underlined) != 0;
  69206. }
  69207. float Font::getAscent() const throw()
  69208. {
  69209. if (font->ascent == 0)
  69210. font->ascent = getTypeface()->getAscent();
  69211. return font->height * font->ascent;
  69212. }
  69213. float Font::getDescent() const throw()
  69214. {
  69215. return font->height - getAscent();
  69216. }
  69217. int Font::getStringWidth (const String& text) const throw()
  69218. {
  69219. return roundToInt (getStringWidthFloat (text));
  69220. }
  69221. float Font::getStringWidthFloat (const String& text) const throw()
  69222. {
  69223. float w = getTypeface()->getStringWidth (text);
  69224. if (font->kerning != 0)
  69225. w += font->kerning * text.length();
  69226. return w * font->height * font->horizontalScale;
  69227. }
  69228. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  69229. {
  69230. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  69231. const float scale = font->height * font->horizontalScale;
  69232. const int num = xOffsets.size();
  69233. if (num > 0)
  69234. {
  69235. float* const x = &(xOffsets.getReference(0));
  69236. if (font->kerning != 0)
  69237. {
  69238. for (int i = 0; i < num; ++i)
  69239. x[i] = (x[i] + i * font->kerning) * scale;
  69240. }
  69241. else
  69242. {
  69243. for (int i = 0; i < num; ++i)
  69244. x[i] *= scale;
  69245. }
  69246. }
  69247. }
  69248. void Font::findFonts (Array<Font>& destArray) throw()
  69249. {
  69250. const StringArray names (findAllTypefaceNames());
  69251. for (int i = 0; i < names.size(); ++i)
  69252. destArray.add (Font (names[i], defaultFontHeight, Font::plain));
  69253. }
  69254. class TypefaceCache : public DeletedAtShutdown
  69255. {
  69256. public:
  69257. TypefaceCache (int numToCache = 10) throw()
  69258. : counter (1)
  69259. {
  69260. while (--numToCache >= 0)
  69261. faces.add (new CachedFace());
  69262. }
  69263. ~TypefaceCache()
  69264. {
  69265. clearUpDefaultFontNames();
  69266. clearSingletonInstance();
  69267. }
  69268. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  69269. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  69270. {
  69271. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  69272. const String faceName (font.getTypefaceName());
  69273. int i;
  69274. for (i = faces.size(); --i >= 0;)
  69275. {
  69276. CachedFace* const face = faces.getUnchecked(i);
  69277. if (face->flags == flags
  69278. && face->typefaceName == faceName)
  69279. {
  69280. face->lastUsageCount = ++counter;
  69281. return face->typeFace;
  69282. }
  69283. }
  69284. int replaceIndex = 0;
  69285. int bestLastUsageCount = std::numeric_limits<int>::max();
  69286. for (i = faces.size(); --i >= 0;)
  69287. {
  69288. const int lu = faces.getUnchecked(i)->lastUsageCount;
  69289. if (bestLastUsageCount > lu)
  69290. {
  69291. bestLastUsageCount = lu;
  69292. replaceIndex = i;
  69293. }
  69294. }
  69295. CachedFace* const face = faces.getUnchecked (replaceIndex);
  69296. face->typefaceName = faceName;
  69297. face->flags = flags;
  69298. face->lastUsageCount = ++counter;
  69299. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  69300. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  69301. return face->typeFace;
  69302. }
  69303. juce_UseDebuggingNewOperator
  69304. private:
  69305. struct CachedFace
  69306. {
  69307. CachedFace() throw()
  69308. : lastUsageCount (0), flags (-1)
  69309. {
  69310. }
  69311. String typefaceName;
  69312. int lastUsageCount;
  69313. int flags;
  69314. Typeface::Ptr typeFace;
  69315. };
  69316. int counter;
  69317. OwnedArray <CachedFace> faces;
  69318. TypefaceCache (const TypefaceCache&);
  69319. const TypefaceCache& operator= (const TypefaceCache&);
  69320. };
  69321. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69322. Typeface* Font::getTypeface() const throw()
  69323. {
  69324. if (font->typeface == 0)
  69325. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69326. return font->typeface;
  69327. }
  69328. END_JUCE_NAMESPACE
  69329. /*** End of inlined file: juce_Font.cpp ***/
  69330. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  69331. BEGIN_JUCE_NAMESPACE
  69332. PositionedGlyph::PositionedGlyph()
  69333. {
  69334. }
  69335. void PositionedGlyph::draw (const Graphics& g) const
  69336. {
  69337. if (! isWhitespace())
  69338. {
  69339. g.getInternalContext()->setFont (font);
  69340. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69341. }
  69342. }
  69343. void PositionedGlyph::draw (const Graphics& g,
  69344. const AffineTransform& transform) const
  69345. {
  69346. if (! isWhitespace())
  69347. {
  69348. g.getInternalContext()->setFont (font);
  69349. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69350. .followedBy (transform));
  69351. }
  69352. }
  69353. void PositionedGlyph::createPath (Path& path) const
  69354. {
  69355. if (! isWhitespace())
  69356. {
  69357. Typeface* const t = font.getTypeface();
  69358. if (t != 0)
  69359. {
  69360. Path p;
  69361. t->getOutlineForGlyph (glyph, p);
  69362. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69363. .translated (x, y));
  69364. }
  69365. }
  69366. }
  69367. bool PositionedGlyph::hitTest (float px, float py) const
  69368. {
  69369. if (px >= getLeft() && px < getRight()
  69370. && py >= getTop() && py < getBottom()
  69371. && ! isWhitespace())
  69372. {
  69373. Typeface* const t = font.getTypeface();
  69374. if (t != 0)
  69375. {
  69376. Path p;
  69377. t->getOutlineForGlyph (glyph, p);
  69378. AffineTransform::translation (-x, -y)
  69379. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69380. .transformPoint (px, py);
  69381. return p.contains (px, py);
  69382. }
  69383. }
  69384. return false;
  69385. }
  69386. void PositionedGlyph::moveBy (const float deltaX,
  69387. const float deltaY)
  69388. {
  69389. x += deltaX;
  69390. y += deltaY;
  69391. }
  69392. GlyphArrangement::GlyphArrangement()
  69393. {
  69394. glyphs.ensureStorageAllocated (128);
  69395. }
  69396. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69397. {
  69398. addGlyphArrangement (other);
  69399. }
  69400. const GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69401. {
  69402. if (this != &other)
  69403. {
  69404. clear();
  69405. addGlyphArrangement (other);
  69406. }
  69407. return *this;
  69408. }
  69409. GlyphArrangement::~GlyphArrangement()
  69410. {
  69411. }
  69412. void GlyphArrangement::clear()
  69413. {
  69414. glyphs.clear();
  69415. }
  69416. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69417. {
  69418. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69419. return *glyphs [index];
  69420. }
  69421. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69422. {
  69423. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69424. for (int i = 0; i < other.glyphs.size(); ++i)
  69425. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69426. }
  69427. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69428. {
  69429. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69430. }
  69431. void GlyphArrangement::addLineOfText (const Font& font,
  69432. const String& text,
  69433. const float xOffset,
  69434. const float yOffset)
  69435. {
  69436. addCurtailedLineOfText (font, text,
  69437. xOffset, yOffset,
  69438. 1.0e10f, false);
  69439. }
  69440. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69441. const String& text,
  69442. float xOffset,
  69443. const float yOffset,
  69444. const float maxWidthPixels,
  69445. const bool useEllipsis)
  69446. {
  69447. int textLen = text.length();
  69448. if (textLen > 0)
  69449. {
  69450. Array <int> newGlyphs;
  69451. Array <float> xOffsets;
  69452. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69453. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69454. textLen = jmin (textLen, newGlyphs.size());
  69455. for (int i = 0; i < textLen; ++i)
  69456. {
  69457. const float thisX = xOffsets.getUnchecked (i);
  69458. const float nextX = xOffsets.getUnchecked (i + 1);
  69459. if (nextX > maxWidthPixels + 1.0f)
  69460. {
  69461. // curtail the string if it's too wide..
  69462. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69463. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69464. break;
  69465. }
  69466. else
  69467. {
  69468. PositionedGlyph* const pg = new PositionedGlyph();
  69469. pg->x = xOffset + thisX;
  69470. pg->y = yOffset;
  69471. pg->w = nextX - thisX;
  69472. pg->font = font;
  69473. pg->glyph = newGlyphs.getUnchecked(i);
  69474. pg->character = unicodeText[i];
  69475. glyphs.add (pg);
  69476. }
  69477. }
  69478. }
  69479. }
  69480. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69481. const int startIndex, int endIndex)
  69482. {
  69483. int numDeleted = 0;
  69484. if (glyphs.size() > 0)
  69485. {
  69486. Array<int> dotGlyphs;
  69487. Array<float> dotXs;
  69488. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69489. const float dx = dotXs[1];
  69490. float xOffset = 0.0f, yOffset = 0.0f;
  69491. while (endIndex > startIndex)
  69492. {
  69493. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69494. xOffset = pg->x;
  69495. yOffset = pg->y;
  69496. glyphs.remove (endIndex);
  69497. ++numDeleted;
  69498. if (xOffset + dx * 3 <= maxXPos)
  69499. break;
  69500. }
  69501. for (int i = 3; --i >= 0;)
  69502. {
  69503. PositionedGlyph* const pg = new PositionedGlyph();
  69504. pg->x = xOffset;
  69505. pg->y = yOffset;
  69506. pg->w = dx;
  69507. pg->font = font;
  69508. pg->character = '.';
  69509. pg->glyph = dotGlyphs.getFirst();
  69510. glyphs.insert (endIndex++, pg);
  69511. --numDeleted;
  69512. xOffset += dx;
  69513. if (xOffset > maxXPos)
  69514. break;
  69515. }
  69516. }
  69517. return numDeleted;
  69518. }
  69519. void GlyphArrangement::addJustifiedText (const Font& font,
  69520. const String& text,
  69521. float x, float y,
  69522. const float maxLineWidth,
  69523. const Justification& horizontalLayout)
  69524. {
  69525. int lineStartIndex = glyphs.size();
  69526. addLineOfText (font, text, x, y);
  69527. const float originalY = y;
  69528. while (lineStartIndex < glyphs.size())
  69529. {
  69530. int i = lineStartIndex;
  69531. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69532. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69533. ++i;
  69534. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69535. int lastWordBreakIndex = -1;
  69536. while (i < glyphs.size())
  69537. {
  69538. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69539. const juce_wchar c = pg->getCharacter();
  69540. if (c == T('\r') || c == T('\n'))
  69541. {
  69542. ++i;
  69543. if (c == T('\r') && i < glyphs.size()
  69544. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69545. ++i;
  69546. break;
  69547. }
  69548. else if (pg->isWhitespace())
  69549. {
  69550. lastWordBreakIndex = i + 1;
  69551. }
  69552. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69553. {
  69554. if (lastWordBreakIndex >= 0)
  69555. i = lastWordBreakIndex;
  69556. break;
  69557. }
  69558. ++i;
  69559. }
  69560. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69561. float currentLineEndX = currentLineStartX;
  69562. for (int j = i; --j >= lineStartIndex;)
  69563. {
  69564. if (! glyphs.getUnchecked (j)->isWhitespace())
  69565. {
  69566. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69567. break;
  69568. }
  69569. }
  69570. float deltaX = 0.0f;
  69571. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69572. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69573. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69574. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69575. else if (horizontalLayout.testFlags (Justification::right))
  69576. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69577. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69578. x + deltaX - currentLineStartX, y - originalY);
  69579. lineStartIndex = i;
  69580. y += font.getHeight();
  69581. }
  69582. }
  69583. void GlyphArrangement::addFittedText (const Font& f,
  69584. const String& text,
  69585. const float x, const float y,
  69586. const float width, const float height,
  69587. const Justification& layout,
  69588. int maximumLines,
  69589. const float minimumHorizontalScale)
  69590. {
  69591. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69592. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69593. if (text.containsAnyOf (T("\r\n")))
  69594. {
  69595. GlyphArrangement ga;
  69596. ga.addJustifiedText (f, text, x, y, width, layout);
  69597. float l, t, r, b;
  69598. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69599. float dy = y - t;
  69600. if (layout.testFlags (Justification::verticallyCentred))
  69601. dy += (height - (b - t)) * 0.5f;
  69602. else if (layout.testFlags (Justification::bottom))
  69603. dy += height - (b - t);
  69604. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69605. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69606. for (int i = 0; i < ga.glyphs.size(); ++i)
  69607. glyphs.add (ga.glyphs.getUnchecked (i));
  69608. ga.glyphs.clear (false);
  69609. return;
  69610. }
  69611. int startIndex = glyphs.size();
  69612. addLineOfText (f, text.trim(), x, y);
  69613. if (glyphs.size() > startIndex)
  69614. {
  69615. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69616. - glyphs.getUnchecked (startIndex)->getLeft();
  69617. if (lineWidth <= 0)
  69618. return;
  69619. if (lineWidth * minimumHorizontalScale < width)
  69620. {
  69621. if (lineWidth > width)
  69622. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69623. width / lineWidth);
  69624. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69625. x, y, width, height, layout);
  69626. }
  69627. else if (maximumLines <= 1)
  69628. {
  69629. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69630. x, y, width, height, f, layout, minimumHorizontalScale);
  69631. }
  69632. else
  69633. {
  69634. Font font (f);
  69635. String txt (text.trim());
  69636. const int length = txt.length();
  69637. const int originalStartIndex = startIndex;
  69638. int numLines = 1;
  69639. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69640. maximumLines = 1;
  69641. maximumLines = jmin (maximumLines, length);
  69642. while (numLines < maximumLines)
  69643. {
  69644. ++numLines;
  69645. const float newFontHeight = height / (float) numLines;
  69646. if (newFontHeight < font.getHeight())
  69647. {
  69648. font.setHeight (jmax (8.0f, newFontHeight));
  69649. removeRangeOfGlyphs (startIndex, -1);
  69650. addLineOfText (font, txt, x, y);
  69651. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69652. - glyphs.getUnchecked (startIndex)->getLeft();
  69653. }
  69654. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69655. break;
  69656. }
  69657. if (numLines < 1)
  69658. numLines = 1;
  69659. float lineY = y;
  69660. float widthPerLine = lineWidth / numLines;
  69661. int lastLineStartIndex = 0;
  69662. for (int line = 0; line < numLines; ++line)
  69663. {
  69664. int i = startIndex;
  69665. lastLineStartIndex = i;
  69666. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69667. if (line == numLines - 1)
  69668. {
  69669. widthPerLine = width;
  69670. i = glyphs.size();
  69671. }
  69672. else
  69673. {
  69674. while (i < glyphs.size())
  69675. {
  69676. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69677. if (lineWidth > widthPerLine)
  69678. {
  69679. // got to a point where the line's too long, so skip forward to find a
  69680. // good place to break it..
  69681. const int searchStartIndex = i;
  69682. while (i < glyphs.size())
  69683. {
  69684. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69685. {
  69686. if (glyphs.getUnchecked (i)->isWhitespace()
  69687. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69688. {
  69689. ++i;
  69690. break;
  69691. }
  69692. }
  69693. else
  69694. {
  69695. // can't find a suitable break, so try looking backwards..
  69696. i = searchStartIndex;
  69697. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69698. {
  69699. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69700. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69701. {
  69702. i -= back - 1;
  69703. break;
  69704. }
  69705. }
  69706. break;
  69707. }
  69708. ++i;
  69709. }
  69710. break;
  69711. }
  69712. ++i;
  69713. }
  69714. int wsStart = i;
  69715. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69716. --wsStart;
  69717. int wsEnd = i;
  69718. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69719. ++wsEnd;
  69720. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69721. i = jmax (wsStart, startIndex + 1);
  69722. }
  69723. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69724. x, lineY, width, font.getHeight(), font,
  69725. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69726. minimumHorizontalScale);
  69727. startIndex = i;
  69728. lineY += font.getHeight();
  69729. if (startIndex >= glyphs.size())
  69730. break;
  69731. }
  69732. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69733. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69734. }
  69735. }
  69736. }
  69737. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69738. const float dx, const float dy)
  69739. {
  69740. jassert (startIndex >= 0);
  69741. if (dx != 0.0f || dy != 0.0f)
  69742. {
  69743. if (num < 0 || startIndex + num > glyphs.size())
  69744. num = glyphs.size() - startIndex;
  69745. while (--num >= 0)
  69746. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69747. }
  69748. }
  69749. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69750. const Justification& justification, float minimumHorizontalScale)
  69751. {
  69752. int numDeleted = 0;
  69753. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69754. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69755. if (lineWidth > w)
  69756. {
  69757. if (minimumHorizontalScale < 1.0f)
  69758. {
  69759. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69760. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69761. }
  69762. if (lineWidth > w)
  69763. {
  69764. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69765. numGlyphs -= numDeleted;
  69766. }
  69767. }
  69768. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69769. return numDeleted;
  69770. }
  69771. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69772. const float horizontalScaleFactor)
  69773. {
  69774. jassert (startIndex >= 0);
  69775. if (num < 0 || startIndex + num > glyphs.size())
  69776. num = glyphs.size() - startIndex;
  69777. if (num > 0)
  69778. {
  69779. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69780. while (--num >= 0)
  69781. {
  69782. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69783. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69784. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69785. pg->w *= horizontalScaleFactor;
  69786. }
  69787. }
  69788. }
  69789. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69790. float& left,
  69791. float& top,
  69792. float& right,
  69793. float& bottom,
  69794. const bool includeWhitespace) const
  69795. {
  69796. jassert (startIndex >= 0);
  69797. if (num < 0 || startIndex + num > glyphs.size())
  69798. num = glyphs.size() - startIndex;
  69799. left = 0.0f;
  69800. top = 0.0f;
  69801. right = 0.0f;
  69802. bottom = 0.0f;
  69803. bool isFirst = true;
  69804. while (--num >= 0)
  69805. {
  69806. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69807. if (includeWhitespace || ! pg->isWhitespace())
  69808. {
  69809. if (isFirst)
  69810. {
  69811. isFirst = false;
  69812. left = pg->getLeft();
  69813. top = pg->getTop();
  69814. right = pg->getRight();
  69815. bottom = pg->getBottom();
  69816. }
  69817. else
  69818. {
  69819. left = jmin (left, pg->getLeft());
  69820. top = jmin (top, pg->getTop());
  69821. right = jmax (right, pg->getRight());
  69822. bottom = jmax (bottom, pg->getBottom());
  69823. }
  69824. }
  69825. }
  69826. }
  69827. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69828. const int num,
  69829. const float x, const float y,
  69830. const float width, const float height,
  69831. const Justification& justification)
  69832. {
  69833. jassert (num >= 0 && startIndex >= 0);
  69834. if (glyphs.size() > 0 && num > 0)
  69835. {
  69836. float left, top, right, bottom;
  69837. getBoundingBox (startIndex, num, left, top, right, bottom,
  69838. ! justification.testFlags (Justification::horizontallyJustified
  69839. | Justification::horizontallyCentred));
  69840. float deltaX = 0.0f;
  69841. if (justification.testFlags (Justification::horizontallyJustified))
  69842. deltaX = x - left;
  69843. else if (justification.testFlags (Justification::horizontallyCentred))
  69844. deltaX = x + (width - (right - left)) * 0.5f - left;
  69845. else if (justification.testFlags (Justification::right))
  69846. deltaX = (x + width) - right;
  69847. else
  69848. deltaX = x - left;
  69849. float deltaY = 0.0f;
  69850. if (justification.testFlags (Justification::top))
  69851. deltaY = y - top;
  69852. else if (justification.testFlags (Justification::bottom))
  69853. deltaY = (y + height) - bottom;
  69854. else
  69855. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69856. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69857. if (justification.testFlags (Justification::horizontallyJustified))
  69858. {
  69859. int lineStart = 0;
  69860. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69861. int i;
  69862. for (i = 0; i < num; ++i)
  69863. {
  69864. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69865. if (glyphY != baseY)
  69866. {
  69867. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69868. lineStart = i;
  69869. baseY = glyphY;
  69870. }
  69871. }
  69872. if (i > lineStart)
  69873. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69874. }
  69875. }
  69876. }
  69877. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69878. {
  69879. if (start + num < glyphs.size()
  69880. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  69881. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  69882. {
  69883. int numSpaces = 0;
  69884. int spacesAtEnd = 0;
  69885. for (int i = 0; i < num; ++i)
  69886. {
  69887. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69888. {
  69889. ++spacesAtEnd;
  69890. ++numSpaces;
  69891. }
  69892. else
  69893. {
  69894. spacesAtEnd = 0;
  69895. }
  69896. }
  69897. numSpaces -= spacesAtEnd;
  69898. if (numSpaces > 0)
  69899. {
  69900. const float startX = glyphs.getUnchecked (start)->getLeft();
  69901. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69902. const float extraPaddingBetweenWords
  69903. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69904. float deltaX = 0.0f;
  69905. for (int i = 0; i < num; ++i)
  69906. {
  69907. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69908. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69909. deltaX += extraPaddingBetweenWords;
  69910. }
  69911. }
  69912. }
  69913. }
  69914. void GlyphArrangement::draw (const Graphics& g) const
  69915. {
  69916. for (int i = 0; i < glyphs.size(); ++i)
  69917. {
  69918. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69919. if (pg->font.isUnderlined())
  69920. {
  69921. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69922. float nextX = pg->x + pg->w;
  69923. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69924. nextX = glyphs.getUnchecked (i + 1)->x;
  69925. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69926. nextX - pg->x, lineThickness);
  69927. }
  69928. pg->draw (g);
  69929. }
  69930. }
  69931. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69932. {
  69933. for (int i = 0; i < glyphs.size(); ++i)
  69934. {
  69935. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69936. if (pg->font.isUnderlined())
  69937. {
  69938. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69939. float nextX = pg->x + pg->w;
  69940. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69941. nextX = glyphs.getUnchecked (i + 1)->x;
  69942. Path p;
  69943. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69944. nextX, pg->y + lineThickness * 2.0f,
  69945. lineThickness);
  69946. g.fillPath (p, transform);
  69947. }
  69948. pg->draw (g, transform);
  69949. }
  69950. }
  69951. void GlyphArrangement::createPath (Path& path) const
  69952. {
  69953. for (int i = 0; i < glyphs.size(); ++i)
  69954. glyphs.getUnchecked (i)->createPath (path);
  69955. }
  69956. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69957. {
  69958. for (int i = 0; i < glyphs.size(); ++i)
  69959. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69960. return i;
  69961. return -1;
  69962. }
  69963. END_JUCE_NAMESPACE
  69964. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69965. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69966. BEGIN_JUCE_NAMESPACE
  69967. class TextLayout::Token
  69968. {
  69969. public:
  69970. String text;
  69971. Font font;
  69972. int x, y, w, h;
  69973. int line, lineHeight;
  69974. bool isWhitespace, isNewLine;
  69975. Token (const String& t,
  69976. const Font& f,
  69977. const bool isWhitespace_) throw()
  69978. : text (t),
  69979. font (f),
  69980. x(0),
  69981. y(0),
  69982. isWhitespace (isWhitespace_)
  69983. {
  69984. w = font.getStringWidth (t);
  69985. h = roundToInt (f.getHeight());
  69986. isNewLine = t.containsAnyOf (T("\r\n"));
  69987. }
  69988. Token (const Token& other) throw()
  69989. : text (other.text),
  69990. font (other.font),
  69991. x (other.x),
  69992. y (other.y),
  69993. w (other.w),
  69994. h (other.h),
  69995. line (other.line),
  69996. lineHeight (other.lineHeight),
  69997. isWhitespace (other.isWhitespace),
  69998. isNewLine (other.isNewLine)
  69999. {
  70000. }
  70001. ~Token() throw()
  70002. {
  70003. }
  70004. void draw (Graphics& g,
  70005. const int xOffset,
  70006. const int yOffset) throw()
  70007. {
  70008. if (! isWhitespace)
  70009. {
  70010. g.setFont (font);
  70011. g.drawSingleLineText (text.trimEnd(),
  70012. xOffset + x,
  70013. yOffset + y + (lineHeight - h)
  70014. + roundToInt (font.getAscent()));
  70015. }
  70016. }
  70017. juce_UseDebuggingNewOperator
  70018. };
  70019. TextLayout::TextLayout() throw()
  70020. : totalLines (0)
  70021. {
  70022. tokens.ensureStorageAllocated (64);
  70023. }
  70024. TextLayout::TextLayout (const String& text,
  70025. const Font& font) throw()
  70026. : totalLines (0)
  70027. {
  70028. tokens.ensureStorageAllocated (64);
  70029. appendText (text, font);
  70030. }
  70031. TextLayout::TextLayout (const TextLayout& other) throw()
  70032. : totalLines (0)
  70033. {
  70034. *this = other;
  70035. }
  70036. const TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  70037. {
  70038. if (this != &other)
  70039. {
  70040. clear();
  70041. totalLines = other.totalLines;
  70042. for (int i = 0; i < other.tokens.size(); ++i)
  70043. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  70044. }
  70045. return *this;
  70046. }
  70047. TextLayout::~TextLayout() throw()
  70048. {
  70049. clear();
  70050. }
  70051. void TextLayout::clear() throw()
  70052. {
  70053. tokens.clear();
  70054. totalLines = 0;
  70055. }
  70056. void TextLayout::appendText (const String& text,
  70057. const Font& font) throw()
  70058. {
  70059. const tchar* t = text;
  70060. String currentString;
  70061. int lastCharType = 0;
  70062. for (;;)
  70063. {
  70064. const tchar c = *t++;
  70065. if (c == 0)
  70066. break;
  70067. int charType;
  70068. if (c == T('\r') || c == T('\n'))
  70069. {
  70070. charType = 0;
  70071. }
  70072. else if (CharacterFunctions::isWhitespace (c))
  70073. {
  70074. charType = 2;
  70075. }
  70076. else
  70077. {
  70078. charType = 1;
  70079. }
  70080. if (charType == 0 || charType != lastCharType)
  70081. {
  70082. if (currentString.isNotEmpty())
  70083. {
  70084. tokens.add (new Token (currentString, font,
  70085. lastCharType == 2 || lastCharType == 0));
  70086. }
  70087. currentString = String::charToString (c);
  70088. if (c == T('\r') && *t == T('\n'))
  70089. currentString += *t++;
  70090. }
  70091. else
  70092. {
  70093. currentString += c;
  70094. }
  70095. lastCharType = charType;
  70096. }
  70097. if (currentString.isNotEmpty())
  70098. tokens.add (new Token (currentString, font, lastCharType == 2));
  70099. }
  70100. void TextLayout::setText (const String& text, const Font& font) throw()
  70101. {
  70102. clear();
  70103. appendText (text, font);
  70104. }
  70105. void TextLayout::layout (int maxWidth,
  70106. const Justification& justification,
  70107. const bool attemptToBalanceLineLengths) throw()
  70108. {
  70109. if (attemptToBalanceLineLengths)
  70110. {
  70111. const int originalW = maxWidth;
  70112. int bestWidth = maxWidth;
  70113. float bestLineProportion = 0.0f;
  70114. while (maxWidth > originalW / 2)
  70115. {
  70116. layout (maxWidth, justification, false);
  70117. if (getNumLines() <= 1)
  70118. return;
  70119. const int lastLineW = getLineWidth (getNumLines() - 1);
  70120. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  70121. const float prop = lastLineW / (float) lastButOneLineW;
  70122. if (prop > 0.9f)
  70123. return;
  70124. if (prop > bestLineProportion)
  70125. {
  70126. bestLineProportion = prop;
  70127. bestWidth = maxWidth;
  70128. }
  70129. maxWidth -= 10;
  70130. }
  70131. layout (bestWidth, justification, false);
  70132. }
  70133. else
  70134. {
  70135. int x = 0;
  70136. int y = 0;
  70137. int h = 0;
  70138. totalLines = 0;
  70139. int i;
  70140. for (i = 0; i < tokens.size(); ++i)
  70141. {
  70142. Token* const t = tokens.getUnchecked(i);
  70143. t->x = x;
  70144. t->y = y;
  70145. t->line = totalLines;
  70146. x += t->w;
  70147. h = jmax (h, t->h);
  70148. const Token* nextTok = tokens [i + 1];
  70149. if (nextTok == 0)
  70150. break;
  70151. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  70152. {
  70153. // finished a line, so go back and update the heights of the things on it
  70154. for (int j = i; j >= 0; --j)
  70155. {
  70156. Token* const tok = tokens.getUnchecked(j);
  70157. if (tok->line == totalLines)
  70158. tok->lineHeight = h;
  70159. else
  70160. break;
  70161. }
  70162. x = 0;
  70163. y += h;
  70164. h = 0;
  70165. ++totalLines;
  70166. }
  70167. }
  70168. // finished a line, so go back and update the heights of the things on it
  70169. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  70170. {
  70171. Token* const t = tokens.getUnchecked(j);
  70172. if (t->line == totalLines)
  70173. t->lineHeight = h;
  70174. else
  70175. break;
  70176. }
  70177. ++totalLines;
  70178. if (! justification.testFlags (Justification::left))
  70179. {
  70180. int totalW = getWidth();
  70181. for (i = totalLines; --i >= 0;)
  70182. {
  70183. const int lineW = getLineWidth (i);
  70184. int dx = 0;
  70185. if (justification.testFlags (Justification::horizontallyCentred))
  70186. dx = (totalW - lineW) / 2;
  70187. else if (justification.testFlags (Justification::right))
  70188. dx = totalW - lineW;
  70189. for (int j = tokens.size(); --j >= 0;)
  70190. {
  70191. Token* const t = tokens.getUnchecked(j);
  70192. if (t->line == i)
  70193. t->x += dx;
  70194. }
  70195. }
  70196. }
  70197. }
  70198. }
  70199. int TextLayout::getLineWidth (const int lineNumber) const throw()
  70200. {
  70201. int maxW = 0;
  70202. for (int i = tokens.size(); --i >= 0;)
  70203. {
  70204. const Token* const t = tokens.getUnchecked(i);
  70205. if (t->line == lineNumber && ! t->isWhitespace)
  70206. maxW = jmax (maxW, t->x + t->w);
  70207. }
  70208. return maxW;
  70209. }
  70210. int TextLayout::getWidth() const throw()
  70211. {
  70212. int maxW = 0;
  70213. for (int i = tokens.size(); --i >= 0;)
  70214. {
  70215. const Token* const t = tokens.getUnchecked(i);
  70216. if (! t->isWhitespace)
  70217. maxW = jmax (maxW, t->x + t->w);
  70218. }
  70219. return maxW;
  70220. }
  70221. int TextLayout::getHeight() const throw()
  70222. {
  70223. int maxH = 0;
  70224. for (int i = tokens.size(); --i >= 0;)
  70225. {
  70226. const Token* const t = tokens.getUnchecked(i);
  70227. if (! t->isWhitespace)
  70228. maxH = jmax (maxH, t->y + t->h);
  70229. }
  70230. return maxH;
  70231. }
  70232. void TextLayout::draw (Graphics& g,
  70233. const int xOffset,
  70234. const int yOffset) const throw()
  70235. {
  70236. for (int i = tokens.size(); --i >= 0;)
  70237. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  70238. }
  70239. void TextLayout::drawWithin (Graphics& g,
  70240. int x, int y, int w, int h,
  70241. const Justification& justification) const throw()
  70242. {
  70243. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  70244. x, y, w, h);
  70245. draw (g, x, y);
  70246. }
  70247. END_JUCE_NAMESPACE
  70248. /*** End of inlined file: juce_TextLayout.cpp ***/
  70249. /*** Start of inlined file: juce_Typeface.cpp ***/
  70250. BEGIN_JUCE_NAMESPACE
  70251. Typeface::Typeface (const String& name_) throw()
  70252. : name (name_)
  70253. {
  70254. }
  70255. Typeface::~Typeface()
  70256. {
  70257. }
  70258. class CustomTypeface::GlyphInfo
  70259. {
  70260. public:
  70261. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  70262. : character (character_), path (path_), width (width_)
  70263. {
  70264. }
  70265. ~GlyphInfo() throw()
  70266. {
  70267. }
  70268. struct KerningPair
  70269. {
  70270. juce_wchar character2;
  70271. float kerningAmount;
  70272. };
  70273. void addKerningPair (const juce_wchar subsequentCharacter,
  70274. const float extraKerningAmount) throw()
  70275. {
  70276. KerningPair kp;
  70277. kp.character2 = subsequentCharacter;
  70278. kp.kerningAmount = extraKerningAmount;
  70279. kerningPairs.add (kp);
  70280. }
  70281. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  70282. {
  70283. if (subsequentCharacter != 0)
  70284. {
  70285. for (int i = kerningPairs.size(); --i >= 0;)
  70286. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  70287. return width + kerningPairs.getReference(i).kerningAmount;
  70288. }
  70289. return width;
  70290. }
  70291. const juce_wchar character;
  70292. const Path path;
  70293. float width;
  70294. Array <KerningPair> kerningPairs;
  70295. juce_UseDebuggingNewOperator
  70296. private:
  70297. GlyphInfo (const GlyphInfo&);
  70298. const GlyphInfo& operator= (const GlyphInfo&);
  70299. };
  70300. CustomTypeface::CustomTypeface()
  70301. : Typeface (String::empty)
  70302. {
  70303. clear();
  70304. }
  70305. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70306. : Typeface (String::empty)
  70307. {
  70308. clear();
  70309. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70310. BufferedInputStream in (&gzin, 32768, false);
  70311. name = in.readString();
  70312. isBold = in.readBool();
  70313. isItalic = in.readBool();
  70314. ascent = in.readFloat();
  70315. defaultCharacter = (juce_wchar) in.readShort();
  70316. int i, numChars = in.readInt();
  70317. for (i = 0; i < numChars; ++i)
  70318. {
  70319. const juce_wchar c = (juce_wchar) in.readShort();
  70320. const float width = in.readFloat();
  70321. Path p;
  70322. p.loadPathFromStream (in);
  70323. addGlyph (c, p, width);
  70324. }
  70325. const int numKerningPairs = in.readInt();
  70326. for (i = 0; i < numKerningPairs; ++i)
  70327. {
  70328. const juce_wchar char1 = (juce_wchar) in.readShort();
  70329. const juce_wchar char2 = (juce_wchar) in.readShort();
  70330. addKerningPair (char1, char2, in.readFloat());
  70331. }
  70332. }
  70333. CustomTypeface::~CustomTypeface()
  70334. {
  70335. }
  70336. void CustomTypeface::clear()
  70337. {
  70338. defaultCharacter = 0;
  70339. ascent = 1.0f;
  70340. isBold = isItalic = false;
  70341. zeromem (lookupTable, sizeof (lookupTable));
  70342. glyphs.clear();
  70343. }
  70344. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70345. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70346. {
  70347. name = name_;
  70348. defaultCharacter = defaultCharacter_;
  70349. ascent = ascent_;
  70350. isBold = isBold_;
  70351. isItalic = isItalic_;
  70352. }
  70353. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70354. {
  70355. // Check that you're not trying to add the same character twice..
  70356. jassert (findGlyph (character, false) == 0);
  70357. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70358. lookupTable [character] = (short) glyphs.size();
  70359. glyphs.add (new GlyphInfo (character, path, width));
  70360. }
  70361. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70362. {
  70363. if (extraAmount != 0)
  70364. {
  70365. GlyphInfo* const g = findGlyph (char1, true);
  70366. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70367. if (g != 0)
  70368. g->addKerningPair (char2, extraAmount);
  70369. }
  70370. }
  70371. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70372. {
  70373. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70374. return glyphs [(int) lookupTable [(int) character]];
  70375. for (int i = 0; i < glyphs.size(); ++i)
  70376. {
  70377. GlyphInfo* const g = glyphs.getUnchecked(i);
  70378. if (g->character == character)
  70379. return g;
  70380. }
  70381. if (loadIfNeeded && loadGlyphIfPossible (character))
  70382. return findGlyph (character, false);
  70383. return 0;
  70384. }
  70385. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70386. {
  70387. GlyphInfo* glyph = findGlyph (character, true);
  70388. if (glyph == 0)
  70389. {
  70390. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70391. glyph = findGlyph (L' ', true);
  70392. if (glyph == 0)
  70393. {
  70394. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70395. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70396. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70397. {
  70398. //xxx
  70399. }
  70400. if (glyph == 0)
  70401. glyph = findGlyph (defaultCharacter, true);
  70402. }
  70403. }
  70404. return glyph;
  70405. }
  70406. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70407. {
  70408. return false;
  70409. }
  70410. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70411. {
  70412. for (int i = 0; i < numCharacters; ++i)
  70413. {
  70414. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70415. Array <int> glyphIndexes;
  70416. Array <float> offsets;
  70417. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70418. const int glyphIndex = glyphIndexes.getFirst();
  70419. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70420. {
  70421. const float glyphWidth = offsets[1];
  70422. Path p;
  70423. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70424. addGlyph (c, p, glyphWidth);
  70425. for (int j = glyphs.size() - 1; --j >= 0;)
  70426. {
  70427. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70428. glyphIndexes.clearQuick();
  70429. offsets.clearQuick();
  70430. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70431. if (offsets.size() > 1)
  70432. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70433. }
  70434. }
  70435. }
  70436. }
  70437. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70438. {
  70439. GZIPCompressorOutputStream out (&outputStream);
  70440. out.writeString (name);
  70441. out.writeBool (isBold);
  70442. out.writeBool (isItalic);
  70443. out.writeFloat (ascent);
  70444. out.writeShort ((short) (unsigned short) defaultCharacter);
  70445. out.writeInt (glyphs.size());
  70446. int i, numKerningPairs = 0;
  70447. for (i = 0; i < glyphs.size(); ++i)
  70448. {
  70449. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70450. out.writeShort ((short) (unsigned short) g->character);
  70451. out.writeFloat (g->width);
  70452. g->path.writePathToStream (out);
  70453. numKerningPairs += g->kerningPairs.size();
  70454. }
  70455. out.writeInt (numKerningPairs);
  70456. for (i = 0; i < glyphs.size(); ++i)
  70457. {
  70458. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70459. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70460. {
  70461. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70462. out.writeShort ((short) (unsigned short) g->character);
  70463. out.writeShort ((short) (unsigned short) p.character2);
  70464. out.writeFloat (p.kerningAmount);
  70465. }
  70466. }
  70467. return true;
  70468. }
  70469. float CustomTypeface::getAscent() const
  70470. {
  70471. return ascent;
  70472. }
  70473. float CustomTypeface::getDescent() const
  70474. {
  70475. return 1.0f - ascent;
  70476. }
  70477. float CustomTypeface::getStringWidth (const String& text)
  70478. {
  70479. float x = 0;
  70480. const juce_wchar* t = (const juce_wchar*) text;
  70481. while (*t != 0)
  70482. {
  70483. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70484. if (glyph != 0)
  70485. x += glyph->getHorizontalSpacing (*t);
  70486. }
  70487. return x;
  70488. }
  70489. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70490. {
  70491. xOffsets.add (0);
  70492. float x = 0;
  70493. const juce_wchar* t = (const juce_wchar*) text;
  70494. while (*t != 0)
  70495. {
  70496. const juce_wchar c = *t++;
  70497. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70498. if (glyph != 0)
  70499. {
  70500. x += glyph->getHorizontalSpacing (*t);
  70501. resultGlyphs.add ((int) glyph->character);
  70502. xOffsets.add (x);
  70503. }
  70504. }
  70505. }
  70506. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70507. {
  70508. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70509. if (glyph != 0)
  70510. {
  70511. path = glyph->path;
  70512. return true;
  70513. }
  70514. return false;
  70515. }
  70516. END_JUCE_NAMESPACE
  70517. /*** End of inlined file: juce_Typeface.cpp ***/
  70518. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70519. BEGIN_JUCE_NAMESPACE
  70520. AffineTransform::AffineTransform() throw()
  70521. : mat00 (1.0f),
  70522. mat01 (0),
  70523. mat02 (0),
  70524. mat10 (0),
  70525. mat11 (1.0f),
  70526. mat12 (0)
  70527. {
  70528. }
  70529. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70530. : mat00 (other.mat00),
  70531. mat01 (other.mat01),
  70532. mat02 (other.mat02),
  70533. mat10 (other.mat10),
  70534. mat11 (other.mat11),
  70535. mat12 (other.mat12)
  70536. {
  70537. }
  70538. AffineTransform::AffineTransform (const float mat00_,
  70539. const float mat01_,
  70540. const float mat02_,
  70541. const float mat10_,
  70542. const float mat11_,
  70543. const float mat12_) throw()
  70544. : mat00 (mat00_),
  70545. mat01 (mat01_),
  70546. mat02 (mat02_),
  70547. mat10 (mat10_),
  70548. mat11 (mat11_),
  70549. mat12 (mat12_)
  70550. {
  70551. }
  70552. const AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70553. {
  70554. mat00 = other.mat00;
  70555. mat01 = other.mat01;
  70556. mat02 = other.mat02;
  70557. mat10 = other.mat10;
  70558. mat11 = other.mat11;
  70559. mat12 = other.mat12;
  70560. return *this;
  70561. }
  70562. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70563. {
  70564. return mat00 == other.mat00
  70565. && mat01 == other.mat01
  70566. && mat02 == other.mat02
  70567. && mat10 == other.mat10
  70568. && mat11 == other.mat11
  70569. && mat12 == other.mat12;
  70570. }
  70571. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70572. {
  70573. return ! operator== (other);
  70574. }
  70575. bool AffineTransform::isIdentity() const throw()
  70576. {
  70577. return (mat01 == 0)
  70578. && (mat02 == 0)
  70579. && (mat10 == 0)
  70580. && (mat12 == 0)
  70581. && (mat00 == 1.0f)
  70582. && (mat11 == 1.0f);
  70583. }
  70584. const AffineTransform AffineTransform::identity;
  70585. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70586. {
  70587. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70588. other.mat00 * mat01 + other.mat01 * mat11,
  70589. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70590. other.mat10 * mat00 + other.mat11 * mat10,
  70591. other.mat10 * mat01 + other.mat11 * mat11,
  70592. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70593. }
  70594. const AffineTransform AffineTransform::followedBy (const float omat00,
  70595. const float omat01,
  70596. const float omat02,
  70597. const float omat10,
  70598. const float omat11,
  70599. const float omat12) const throw()
  70600. {
  70601. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70602. omat00 * mat01 + omat01 * mat11,
  70603. omat00 * mat02 + omat01 * mat12 + omat02,
  70604. omat10 * mat00 + omat11 * mat10,
  70605. omat10 * mat01 + omat11 * mat11,
  70606. omat10 * mat02 + omat11 * mat12 + omat12);
  70607. }
  70608. const AffineTransform AffineTransform::translated (const float dx,
  70609. const float dy) const throw()
  70610. {
  70611. return AffineTransform (mat00, mat01, mat02 + dx,
  70612. mat10, mat11, mat12 + dy);
  70613. }
  70614. const AffineTransform AffineTransform::translation (const float dx,
  70615. const float dy) throw()
  70616. {
  70617. return AffineTransform (1.0f, 0, dx,
  70618. 0, 1.0f, dy);
  70619. }
  70620. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70621. {
  70622. const float cosRad = cosf (rad);
  70623. const float sinRad = sinf (rad);
  70624. return followedBy (cosRad, -sinRad, 0,
  70625. sinRad, cosRad, 0);
  70626. }
  70627. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70628. {
  70629. const float cosRad = cosf (rad);
  70630. const float sinRad = sinf (rad);
  70631. return AffineTransform (cosRad, -sinRad, 0,
  70632. sinRad, cosRad, 0);
  70633. }
  70634. const AffineTransform AffineTransform::rotated (const float angle,
  70635. const float pivotX,
  70636. const float pivotY) const throw()
  70637. {
  70638. return translated (-pivotX, -pivotY)
  70639. .rotated (angle)
  70640. .translated (pivotX, pivotY);
  70641. }
  70642. const AffineTransform AffineTransform::rotation (const float angle,
  70643. const float pivotX,
  70644. const float pivotY) throw()
  70645. {
  70646. return translation (-pivotX, -pivotY)
  70647. .rotated (angle)
  70648. .translated (pivotX, pivotY);
  70649. }
  70650. const AffineTransform AffineTransform::scaled (const float factorX,
  70651. const float factorY) const throw()
  70652. {
  70653. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70654. factorY * mat10, factorY * mat11, factorY * mat12);
  70655. }
  70656. const AffineTransform AffineTransform::scale (const float factorX,
  70657. const float factorY) throw()
  70658. {
  70659. return AffineTransform (factorX, 0, 0,
  70660. 0, factorY, 0);
  70661. }
  70662. const AffineTransform AffineTransform::sheared (const float shearX,
  70663. const float shearY) const throw()
  70664. {
  70665. return followedBy (1.0f, shearX, 0,
  70666. shearY, 1.0f, 0);
  70667. }
  70668. const AffineTransform AffineTransform::inverted() const throw()
  70669. {
  70670. double determinant = (mat00 * mat11 - mat10 * mat01);
  70671. if (determinant != 0.0)
  70672. {
  70673. determinant = 1.0 / determinant;
  70674. const float dst00 = (float) (mat11 * determinant);
  70675. const float dst10 = (float) (-mat10 * determinant);
  70676. const float dst01 = (float) (-mat01 * determinant);
  70677. const float dst11 = (float) (mat00 * determinant);
  70678. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70679. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70680. }
  70681. else
  70682. {
  70683. // singularity..
  70684. return *this;
  70685. }
  70686. }
  70687. bool AffineTransform::isSingularity() const throw()
  70688. {
  70689. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70690. }
  70691. bool AffineTransform::isOnlyTranslation() const throw()
  70692. {
  70693. return (mat01 == 0)
  70694. && (mat10 == 0)
  70695. && (mat00 == 1.0f)
  70696. && (mat11 == 1.0f);
  70697. }
  70698. void AffineTransform::transformPoint (float& x,
  70699. float& y) const throw()
  70700. {
  70701. const float oldX = x;
  70702. x = mat00 * oldX + mat01 * y + mat02;
  70703. y = mat10 * oldX + mat11 * y + mat12;
  70704. }
  70705. void AffineTransform::transformPoint (double& x,
  70706. double& y) const throw()
  70707. {
  70708. const double oldX = x;
  70709. x = mat00 * oldX + mat01 * y + mat02;
  70710. y = mat10 * oldX + mat11 * y + mat12;
  70711. }
  70712. END_JUCE_NAMESPACE
  70713. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70714. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70715. BEGIN_JUCE_NAMESPACE
  70716. BorderSize::BorderSize() throw()
  70717. : top (0),
  70718. left (0),
  70719. bottom (0),
  70720. right (0)
  70721. {
  70722. }
  70723. BorderSize::BorderSize (const BorderSize& other) throw()
  70724. : top (other.top),
  70725. left (other.left),
  70726. bottom (other.bottom),
  70727. right (other.right)
  70728. {
  70729. }
  70730. BorderSize::BorderSize (const int topGap,
  70731. const int leftGap,
  70732. const int bottomGap,
  70733. const int rightGap) throw()
  70734. : top (topGap),
  70735. left (leftGap),
  70736. bottom (bottomGap),
  70737. right (rightGap)
  70738. {
  70739. }
  70740. BorderSize::BorderSize (const int allGaps) throw()
  70741. : top (allGaps),
  70742. left (allGaps),
  70743. bottom (allGaps),
  70744. right (allGaps)
  70745. {
  70746. }
  70747. BorderSize::~BorderSize() throw()
  70748. {
  70749. }
  70750. void BorderSize::setTop (const int newTopGap) throw()
  70751. {
  70752. top = newTopGap;
  70753. }
  70754. void BorderSize::setLeft (const int newLeftGap) throw()
  70755. {
  70756. left = newLeftGap;
  70757. }
  70758. void BorderSize::setBottom (const int newBottomGap) throw()
  70759. {
  70760. bottom = newBottomGap;
  70761. }
  70762. void BorderSize::setRight (const int newRightGap) throw()
  70763. {
  70764. right = newRightGap;
  70765. }
  70766. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70767. {
  70768. return Rectangle<int> (r.getX() + left,
  70769. r.getY() + top,
  70770. r.getWidth() - (left + right),
  70771. r.getHeight() - (top + bottom));
  70772. }
  70773. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70774. {
  70775. r.setBounds (r.getX() + left,
  70776. r.getY() + top,
  70777. r.getWidth() - (left + right),
  70778. r.getHeight() - (top + bottom));
  70779. }
  70780. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70781. {
  70782. return Rectangle<int> (r.getX() - left,
  70783. r.getY() - top,
  70784. r.getWidth() + (left + right),
  70785. r.getHeight() + (top + bottom));
  70786. }
  70787. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70788. {
  70789. r.setBounds (r.getX() - left,
  70790. r.getY() - top,
  70791. r.getWidth() + (left + right),
  70792. r.getHeight() + (top + bottom));
  70793. }
  70794. bool BorderSize::operator== (const BorderSize& other) const throw()
  70795. {
  70796. return top == other.top
  70797. && left == other.left
  70798. && bottom == other.bottom
  70799. && right == other.right;
  70800. }
  70801. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70802. {
  70803. return ! operator== (other);
  70804. }
  70805. END_JUCE_NAMESPACE
  70806. /*** End of inlined file: juce_BorderSize.cpp ***/
  70807. /*** Start of inlined file: juce_Line.cpp ***/
  70808. BEGIN_JUCE_NAMESPACE
  70809. static bool juce_lineIntersection (const float x1, const float y1,
  70810. const float x2, const float y2,
  70811. const float x3, const float y3,
  70812. const float x4, const float y4,
  70813. float& intersectionX,
  70814. float& intersectionY) throw()
  70815. {
  70816. if (x2 != x3 || y2 != y3)
  70817. {
  70818. const float dx1 = x2 - x1;
  70819. const float dy1 = y2 - y1;
  70820. const float dx2 = x4 - x3;
  70821. const float dy2 = y4 - y3;
  70822. const float divisor = dx1 * dy2 - dx2 * dy1;
  70823. if (divisor == 0)
  70824. {
  70825. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70826. {
  70827. if (dy1 == 0 && dy2 != 0)
  70828. {
  70829. const float along = (y1 - y3) / dy2;
  70830. intersectionX = x3 + along * dx2;
  70831. intersectionY = y1;
  70832. return along >= 0 && along <= 1.0f;
  70833. }
  70834. else if (dy2 == 0 && dy1 != 0)
  70835. {
  70836. const float along = (y3 - y1) / dy1;
  70837. intersectionX = x1 + along * dx1;
  70838. intersectionY = y3;
  70839. return along >= 0 && along <= 1.0f;
  70840. }
  70841. else if (dx1 == 0 && dx2 != 0)
  70842. {
  70843. const float along = (x1 - x3) / dx2;
  70844. intersectionX = x1;
  70845. intersectionY = y3 + along * dy2;
  70846. return along >= 0 && along <= 1.0f;
  70847. }
  70848. else if (dx2 == 0 && dx1 != 0)
  70849. {
  70850. const float along = (x3 - x1) / dx1;
  70851. intersectionX = x3;
  70852. intersectionY = y1 + along * dy1;
  70853. return along >= 0 && along <= 1.0f;
  70854. }
  70855. }
  70856. intersectionX = 0.5f * (x2 + x3);
  70857. intersectionY = 0.5f * (y2 + y3);
  70858. return false;
  70859. }
  70860. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70861. intersectionX = x1 + along1 * dx1;
  70862. intersectionY = y1 + along1 * dy1;
  70863. if (along1 < 0 || along1 > 1.0f)
  70864. return false;
  70865. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70866. return along2 >= 0 && along2 <= 1.0f;
  70867. }
  70868. intersectionX = x2;
  70869. intersectionY = y2;
  70870. return true;
  70871. }
  70872. Line::Line() throw()
  70873. : startX (0.0f),
  70874. startY (0.0f),
  70875. endX (0.0f),
  70876. endY (0.0f)
  70877. {
  70878. }
  70879. Line::Line (const Line& other) throw()
  70880. : startX (other.startX),
  70881. startY (other.startY),
  70882. endX (other.endX),
  70883. endY (other.endY)
  70884. {
  70885. }
  70886. Line::Line (const float startX_, const float startY_,
  70887. const float endX_, const float endY_) throw()
  70888. : startX (startX_),
  70889. startY (startY_),
  70890. endX (endX_),
  70891. endY (endY_)
  70892. {
  70893. }
  70894. Line::Line (const Point<float>& start,
  70895. const Point<float>& end) throw()
  70896. : startX (start.getX()),
  70897. startY (start.getY()),
  70898. endX (end.getX()),
  70899. endY (end.getY())
  70900. {
  70901. }
  70902. const Line& Line::operator= (const Line& other) throw()
  70903. {
  70904. startX = other.startX;
  70905. startY = other.startY;
  70906. endX = other.endX;
  70907. endY = other.endY;
  70908. return *this;
  70909. }
  70910. Line::~Line() throw()
  70911. {
  70912. }
  70913. const Point<float> Line::getStart() const throw()
  70914. {
  70915. return Point<float> (startX, startY);
  70916. }
  70917. const Point<float> Line::getEnd() const throw()
  70918. {
  70919. return Point<float> (endX, endY);
  70920. }
  70921. void Line::setStart (const float newStartX,
  70922. const float newStartY) throw()
  70923. {
  70924. startX = newStartX;
  70925. startY = newStartY;
  70926. }
  70927. void Line::setStart (const Point<float>& newStart) throw()
  70928. {
  70929. startX = newStart.getX();
  70930. startY = newStart.getY();
  70931. }
  70932. void Line::setEnd (const float newEndX,
  70933. const float newEndY) throw()
  70934. {
  70935. endX = newEndX;
  70936. endY = newEndY;
  70937. }
  70938. void Line::setEnd (const Point<float>& newEnd) throw()
  70939. {
  70940. endX = newEnd.getX();
  70941. endY = newEnd.getY();
  70942. }
  70943. bool Line::operator== (const Line& other) const throw()
  70944. {
  70945. return startX == other.startX
  70946. && startY == other.startY
  70947. && endX == other.endX
  70948. && endY == other.endY;
  70949. }
  70950. bool Line::operator!= (const Line& other) const throw()
  70951. {
  70952. return startX != other.startX
  70953. || startY != other.startY
  70954. || endX != other.endX
  70955. || endY != other.endY;
  70956. }
  70957. void Line::applyTransform (const AffineTransform& transform) throw()
  70958. {
  70959. transform.transformPoint (startX, startY);
  70960. transform.transformPoint (endX, endY);
  70961. }
  70962. float Line::getLength() const throw()
  70963. {
  70964. return (float) juce_hypot (startX - endX,
  70965. startY - endY);
  70966. }
  70967. float Line::getAngle() const throw()
  70968. {
  70969. return atan2f (endX - startX,
  70970. endY - startY);
  70971. }
  70972. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70973. {
  70974. const float alpha = distanceFromStart / getLength();
  70975. return Point<float> (startX + (endX - startX) * alpha,
  70976. startY + (endY - startY) * alpha);
  70977. }
  70978. const Point<float> Line::getPointAlongLine (const float offsetX,
  70979. const float offsetY) const throw()
  70980. {
  70981. const float dx = endX - startX;
  70982. const float dy = endY - startY;
  70983. const double length = juce_hypot (dx, dy);
  70984. if (length == 0)
  70985. return Point<float> (startX, startY);
  70986. else
  70987. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70988. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70989. }
  70990. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70991. {
  70992. return Point<float> (startX + (endX - startX) * alpha,
  70993. startY + (endY - startY) * alpha);
  70994. }
  70995. float Line::getDistanceFromLine (const float x,
  70996. const float y) const throw()
  70997. {
  70998. const double dx = endX - startX;
  70999. const double dy = endY - startY;
  71000. const double length = dx * dx + dy * dy;
  71001. if (length > 0)
  71002. {
  71003. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  71004. if (prop >= 0.0f && prop < 1.0f)
  71005. {
  71006. return (float) juce_hypot (x - (startX + prop * dx),
  71007. y - (startY + prop * dy));
  71008. }
  71009. }
  71010. return (float) jmin (juce_hypot (x - startX, y - startY),
  71011. juce_hypot (x - endX, y - endY));
  71012. }
  71013. float Line::findNearestPointTo (const float x,
  71014. const float y) const throw()
  71015. {
  71016. const double dx = endX - startX;
  71017. const double dy = endY - startY;
  71018. const double length = dx * dx + dy * dy;
  71019. if (length <= 0.0)
  71020. return 0.0f;
  71021. return jlimit (0.0f, 1.0f,
  71022. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  71023. }
  71024. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  71025. {
  71026. const float length = getLength();
  71027. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  71028. getEnd());
  71029. }
  71030. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  71031. {
  71032. const float length = getLength();
  71033. return Line (getStart(),
  71034. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  71035. }
  71036. bool Line::clipToPath (const Path& path,
  71037. const bool keepSectionOutsidePath) throw()
  71038. {
  71039. const bool startInside = path.contains (startX, startY);
  71040. const bool endInside = path.contains (endX, endY);
  71041. if (startInside == endInside)
  71042. {
  71043. if (keepSectionOutsidePath != startInside)
  71044. {
  71045. // entirely outside the path
  71046. return false;
  71047. }
  71048. else
  71049. {
  71050. // entirely inside the path
  71051. startX = 0.0f;
  71052. startY = 0.0f;
  71053. endX = 0.0f;
  71054. endY = 0.0f;
  71055. return true;
  71056. }
  71057. }
  71058. else
  71059. {
  71060. bool changed = false;
  71061. PathFlatteningIterator iter (path, AffineTransform::identity);
  71062. while (iter.next())
  71063. {
  71064. float ix, iy;
  71065. if (intersects (Line (iter.x1, iter.y1,
  71066. iter.x2, iter.y2),
  71067. ix, iy))
  71068. {
  71069. if ((startInside && keepSectionOutsidePath)
  71070. || (endInside && ! keepSectionOutsidePath))
  71071. {
  71072. setStart (ix, iy);
  71073. }
  71074. else
  71075. {
  71076. setEnd (ix, iy);
  71077. }
  71078. changed = true;
  71079. }
  71080. }
  71081. return changed;
  71082. }
  71083. }
  71084. bool Line::intersects (const Line& line,
  71085. float& intersectionX,
  71086. float& intersectionY) const throw()
  71087. {
  71088. return juce_lineIntersection (startX, startY,
  71089. endX, endY,
  71090. line.startX, line.startY,
  71091. line.endX, line.endY,
  71092. intersectionX,
  71093. intersectionY);
  71094. }
  71095. bool Line::isVertical() const throw()
  71096. {
  71097. return startX == endX;
  71098. }
  71099. bool Line::isHorizontal() const throw()
  71100. {
  71101. return startY == endY;
  71102. }
  71103. bool Line::isPointAbove (const float x, const float y) const throw()
  71104. {
  71105. return startX != endX
  71106. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  71107. }
  71108. END_JUCE_NAMESPACE
  71109. /*** End of inlined file: juce_Line.cpp ***/
  71110. /*** Start of inlined file: juce_Path.cpp ***/
  71111. BEGIN_JUCE_NAMESPACE
  71112. // tests that some co-ords aren't NaNs
  71113. #define CHECK_COORDS_ARE_VALID(x, y) \
  71114. jassert (x == x && y == y);
  71115. const float Path::lineMarker = 100001.0f;
  71116. const float Path::moveMarker = 100002.0f;
  71117. const float Path::quadMarker = 100003.0f;
  71118. const float Path::cubicMarker = 100004.0f;
  71119. const float Path::closeSubPathMarker = 100005.0f;
  71120. static const int defaultGranularity = 32;
  71121. Path::Path() throw()
  71122. : numElements (0),
  71123. pathXMin (0),
  71124. pathXMax (0),
  71125. pathYMin (0),
  71126. pathYMax (0),
  71127. useNonZeroWinding (true)
  71128. {
  71129. }
  71130. Path::~Path() throw()
  71131. {
  71132. }
  71133. Path::Path (const Path& other) throw()
  71134. : numElements (other.numElements),
  71135. pathXMin (other.pathXMin),
  71136. pathXMax (other.pathXMax),
  71137. pathYMin (other.pathYMin),
  71138. pathYMax (other.pathYMax),
  71139. useNonZeroWinding (other.useNonZeroWinding)
  71140. {
  71141. if (numElements > 0)
  71142. {
  71143. data.setAllocatedSize (numElements);
  71144. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71145. }
  71146. }
  71147. const Path& Path::operator= (const Path& other) throw()
  71148. {
  71149. if (this != &other)
  71150. {
  71151. data.ensureAllocatedSize (other.numElements);
  71152. numElements = other.numElements;
  71153. pathXMin = other.pathXMin;
  71154. pathXMax = other.pathXMax;
  71155. pathYMin = other.pathYMin;
  71156. pathYMax = other.pathYMax;
  71157. useNonZeroWinding = other.useNonZeroWinding;
  71158. if (numElements > 0)
  71159. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71160. }
  71161. return *this;
  71162. }
  71163. void Path::clear() throw()
  71164. {
  71165. numElements = 0;
  71166. pathXMin = 0;
  71167. pathYMin = 0;
  71168. pathYMax = 0;
  71169. pathXMax = 0;
  71170. }
  71171. void Path::swapWithPath (Path& other)
  71172. {
  71173. data.swapWith (other.data);
  71174. swapVariables <int> (numElements, other.numElements);
  71175. swapVariables <float> (pathXMin, other.pathXMin);
  71176. swapVariables <float> (pathXMax, other.pathXMax);
  71177. swapVariables <float> (pathYMin, other.pathYMin);
  71178. swapVariables <float> (pathYMax, other.pathYMax);
  71179. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  71180. }
  71181. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  71182. {
  71183. useNonZeroWinding = isNonZero;
  71184. }
  71185. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  71186. const bool preserveProportions) throw()
  71187. {
  71188. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  71189. }
  71190. bool Path::isEmpty() const throw()
  71191. {
  71192. int i = 0;
  71193. while (i < numElements)
  71194. {
  71195. const float type = data.elements [i++];
  71196. if (type == moveMarker)
  71197. {
  71198. i += 2;
  71199. }
  71200. else if (type == lineMarker
  71201. || type == quadMarker
  71202. || type == cubicMarker)
  71203. {
  71204. return false;
  71205. }
  71206. }
  71207. return true;
  71208. }
  71209. const Rectangle<float> Path::getBounds () const throw()
  71210. {
  71211. return Rectangle<float> (pathXMin, pathYMin,
  71212. pathXMax - pathXMin,
  71213. pathYMax - pathYMin);
  71214. }
  71215. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  71216. {
  71217. return getBounds().transformed (transform);
  71218. }
  71219. void Path::startNewSubPath (const float x,
  71220. const float y) throw()
  71221. {
  71222. CHECK_COORDS_ARE_VALID (x, y);
  71223. if (numElements == 0)
  71224. {
  71225. pathXMin = pathXMax = x;
  71226. pathYMin = pathYMax = y;
  71227. }
  71228. else
  71229. {
  71230. pathXMin = jmin (pathXMin, x);
  71231. pathXMax = jmax (pathXMax, x);
  71232. pathYMin = jmin (pathYMin, y);
  71233. pathYMax = jmax (pathYMax, y);
  71234. }
  71235. data.ensureAllocatedSize (numElements + 3);
  71236. data.elements [numElements++] = moveMarker;
  71237. data.elements [numElements++] = x;
  71238. data.elements [numElements++] = y;
  71239. }
  71240. void Path::lineTo (const float x, const float y) throw()
  71241. {
  71242. CHECK_COORDS_ARE_VALID (x, y);
  71243. if (numElements == 0)
  71244. startNewSubPath (0, 0);
  71245. data.ensureAllocatedSize (numElements + 3);
  71246. data.elements [numElements++] = lineMarker;
  71247. data.elements [numElements++] = x;
  71248. data.elements [numElements++] = y;
  71249. pathXMin = jmin (pathXMin, x);
  71250. pathXMax = jmax (pathXMax, x);
  71251. pathYMin = jmin (pathYMin, y);
  71252. pathYMax = jmax (pathYMax, y);
  71253. }
  71254. void Path::quadraticTo (const float x1, const float y1,
  71255. const float x2, const float y2) throw()
  71256. {
  71257. CHECK_COORDS_ARE_VALID (x1, y1);
  71258. CHECK_COORDS_ARE_VALID (x2, y2);
  71259. if (numElements == 0)
  71260. startNewSubPath (0, 0);
  71261. data.ensureAllocatedSize (numElements + 5);
  71262. data.elements [numElements++] = quadMarker;
  71263. data.elements [numElements++] = x1;
  71264. data.elements [numElements++] = y1;
  71265. data.elements [numElements++] = x2;
  71266. data.elements [numElements++] = y2;
  71267. pathXMin = jmin (pathXMin, x1, x2);
  71268. pathXMax = jmax (pathXMax, x1, x2);
  71269. pathYMin = jmin (pathYMin, y1, y2);
  71270. pathYMax = jmax (pathYMax, y1, y2);
  71271. }
  71272. void Path::cubicTo (const float x1, const float y1,
  71273. const float x2, const float y2,
  71274. const float x3, const float y3) throw()
  71275. {
  71276. CHECK_COORDS_ARE_VALID (x1, y1);
  71277. CHECK_COORDS_ARE_VALID (x2, y2);
  71278. CHECK_COORDS_ARE_VALID (x3, y3);
  71279. if (numElements == 0)
  71280. startNewSubPath (0, 0);
  71281. data.ensureAllocatedSize (numElements + 7);
  71282. data.elements [numElements++] = cubicMarker;
  71283. data.elements [numElements++] = x1;
  71284. data.elements [numElements++] = y1;
  71285. data.elements [numElements++] = x2;
  71286. data.elements [numElements++] = y2;
  71287. data.elements [numElements++] = x3;
  71288. data.elements [numElements++] = y3;
  71289. pathXMin = jmin (pathXMin, x1, x2, x3);
  71290. pathXMax = jmax (pathXMax, x1, x2, x3);
  71291. pathYMin = jmin (pathYMin, y1, y2, y3);
  71292. pathYMax = jmax (pathYMax, y1, y2, y3);
  71293. }
  71294. void Path::closeSubPath() throw()
  71295. {
  71296. if (numElements > 0
  71297. && data.elements [numElements - 1] != closeSubPathMarker)
  71298. {
  71299. data.ensureAllocatedSize (numElements + 1);
  71300. data.elements [numElements++] = closeSubPathMarker;
  71301. }
  71302. }
  71303. const Point<float> Path::getCurrentPosition() const
  71304. {
  71305. int i = numElements - 1;
  71306. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71307. {
  71308. while (i >= 0)
  71309. {
  71310. if (data.elements[i] == moveMarker)
  71311. {
  71312. i += 2;
  71313. break;
  71314. }
  71315. --i;
  71316. }
  71317. }
  71318. if (i > 0)
  71319. return Point<float> (data.elements [i - 1], data.elements [i]);
  71320. return Point<float>();
  71321. }
  71322. void Path::addRectangle (const float x, const float y,
  71323. const float w, const float h) throw()
  71324. {
  71325. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71326. if (w < 0)
  71327. swapVariables (x1, x2);
  71328. if (h < 0)
  71329. swapVariables (y1, y2);
  71330. data.ensureAllocatedSize (numElements + 13);
  71331. if (numElements == 0)
  71332. {
  71333. pathXMin = x1;
  71334. pathXMax = x2;
  71335. pathYMin = y1;
  71336. pathYMax = y2;
  71337. }
  71338. else
  71339. {
  71340. pathXMin = jmin (pathXMin, x1);
  71341. pathXMax = jmax (pathXMax, x2);
  71342. pathYMin = jmin (pathYMin, y1);
  71343. pathYMax = jmax (pathYMax, y2);
  71344. }
  71345. data.elements [numElements++] = moveMarker;
  71346. data.elements [numElements++] = x1;
  71347. data.elements [numElements++] = y2;
  71348. data.elements [numElements++] = lineMarker;
  71349. data.elements [numElements++] = x1;
  71350. data.elements [numElements++] = y1;
  71351. data.elements [numElements++] = lineMarker;
  71352. data.elements [numElements++] = x2;
  71353. data.elements [numElements++] = y1;
  71354. data.elements [numElements++] = lineMarker;
  71355. data.elements [numElements++] = x2;
  71356. data.elements [numElements++] = y2;
  71357. data.elements [numElements++] = closeSubPathMarker;
  71358. }
  71359. void Path::addRectangle (const Rectangle<int>& rectangle) throw()
  71360. {
  71361. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71362. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71363. }
  71364. void Path::addRoundedRectangle (const float x, const float y,
  71365. const float w, const float h,
  71366. float csx,
  71367. float csy) throw()
  71368. {
  71369. csx = jmin (csx, w * 0.5f);
  71370. csy = jmin (csy, h * 0.5f);
  71371. const float cs45x = csx * 0.45f;
  71372. const float cs45y = csy * 0.45f;
  71373. const float x2 = x + w;
  71374. const float y2 = y + h;
  71375. startNewSubPath (x + csx, y);
  71376. lineTo (x2 - csx, y);
  71377. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71378. lineTo (x2, y2 - csy);
  71379. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71380. lineTo (x + csx, y2);
  71381. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71382. lineTo (x, y + csy);
  71383. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71384. closeSubPath();
  71385. }
  71386. void Path::addRoundedRectangle (const float x, const float y,
  71387. const float w, const float h,
  71388. float cs) throw()
  71389. {
  71390. addRoundedRectangle (x, y, w, h, cs, cs);
  71391. }
  71392. void Path::addTriangle (const float x1, const float y1,
  71393. const float x2, const float y2,
  71394. const float x3, const float y3) throw()
  71395. {
  71396. startNewSubPath (x1, y1);
  71397. lineTo (x2, y2);
  71398. lineTo (x3, y3);
  71399. closeSubPath();
  71400. }
  71401. void Path::addQuadrilateral (const float x1, const float y1,
  71402. const float x2, const float y2,
  71403. const float x3, const float y3,
  71404. const float x4, const float y4) throw()
  71405. {
  71406. startNewSubPath (x1, y1);
  71407. lineTo (x2, y2);
  71408. lineTo (x3, y3);
  71409. lineTo (x4, y4);
  71410. closeSubPath();
  71411. }
  71412. void Path::addEllipse (const float x, const float y,
  71413. const float w, const float h) throw()
  71414. {
  71415. const float hw = w * 0.5f;
  71416. const float hw55 = hw * 0.55f;
  71417. const float hh = h * 0.5f;
  71418. const float hh45 = hh * 0.55f;
  71419. const float cx = x + hw;
  71420. const float cy = y + hh;
  71421. startNewSubPath (cx, cy - hh);
  71422. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71423. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71424. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71425. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71426. closeSubPath();
  71427. }
  71428. void Path::addArc (const float x, const float y,
  71429. const float w, const float h,
  71430. const float fromRadians,
  71431. const float toRadians,
  71432. const bool startAsNewSubPath) throw()
  71433. {
  71434. const float radiusX = w / 2.0f;
  71435. const float radiusY = h / 2.0f;
  71436. addCentredArc (x + radiusX,
  71437. y + radiusY,
  71438. radiusX, radiusY,
  71439. 0.0f,
  71440. fromRadians, toRadians,
  71441. startAsNewSubPath);
  71442. }
  71443. static const float ellipseAngularIncrement = 0.05f;
  71444. void Path::addCentredArc (const float centreX, const float centreY,
  71445. const float radiusX, const float radiusY,
  71446. const float rotationOfEllipse,
  71447. const float fromRadians,
  71448. const float toRadians,
  71449. const bool startAsNewSubPath) throw()
  71450. {
  71451. if (radiusX > 0.0f && radiusY > 0.0f)
  71452. {
  71453. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71454. float angle = fromRadians;
  71455. if (startAsNewSubPath)
  71456. {
  71457. float x = centreX + radiusX * sinf (angle);
  71458. float y = centreY - radiusY * cosf (angle);
  71459. if (rotationOfEllipse != 0)
  71460. rotation.transformPoint (x, y);
  71461. startNewSubPath (x, y);
  71462. }
  71463. if (fromRadians < toRadians)
  71464. {
  71465. if (startAsNewSubPath)
  71466. angle += ellipseAngularIncrement;
  71467. while (angle < toRadians)
  71468. {
  71469. float x = centreX + radiusX * sinf (angle);
  71470. float y = centreY - radiusY * cosf (angle);
  71471. if (rotationOfEllipse != 0)
  71472. rotation.transformPoint (x, y);
  71473. lineTo (x, y);
  71474. angle += ellipseAngularIncrement;
  71475. }
  71476. }
  71477. else
  71478. {
  71479. if (startAsNewSubPath)
  71480. angle -= ellipseAngularIncrement;
  71481. while (angle > toRadians)
  71482. {
  71483. float x = centreX + radiusX * sinf (angle);
  71484. float y = centreY - radiusY * cosf (angle);
  71485. if (rotationOfEllipse != 0)
  71486. rotation.transformPoint (x, y);
  71487. lineTo (x, y);
  71488. angle -= ellipseAngularIncrement;
  71489. }
  71490. }
  71491. float x = centreX + radiusX * sinf (toRadians);
  71492. float y = centreY - radiusY * cosf (toRadians);
  71493. if (rotationOfEllipse != 0)
  71494. rotation.transformPoint (x, y);
  71495. lineTo (x, y);
  71496. }
  71497. }
  71498. void Path::addPieSegment (const float x, const float y,
  71499. const float width, const float height,
  71500. const float fromRadians,
  71501. const float toRadians,
  71502. const float innerCircleProportionalSize)
  71503. {
  71504. float hw = width * 0.5f;
  71505. float hh = height * 0.5f;
  71506. const float centreX = x + hw;
  71507. const float centreY = y + hh;
  71508. startNewSubPath (centreX + hw * sinf (fromRadians),
  71509. centreY - hh * cosf (fromRadians));
  71510. addArc (x, y, width, height, fromRadians, toRadians);
  71511. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71512. {
  71513. closeSubPath();
  71514. if (innerCircleProportionalSize > 0)
  71515. {
  71516. hw *= innerCircleProportionalSize;
  71517. hh *= innerCircleProportionalSize;
  71518. startNewSubPath (centreX + hw * sinf (toRadians),
  71519. centreY - hh * cosf (toRadians));
  71520. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71521. toRadians, fromRadians);
  71522. }
  71523. }
  71524. else
  71525. {
  71526. if (innerCircleProportionalSize > 0)
  71527. {
  71528. hw *= innerCircleProportionalSize;
  71529. hh *= innerCircleProportionalSize;
  71530. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71531. toRadians, fromRadians);
  71532. }
  71533. else
  71534. {
  71535. lineTo (centreX, centreY);
  71536. }
  71537. }
  71538. closeSubPath();
  71539. }
  71540. static void perpendicularOffset (const float x1, const float y1,
  71541. const float x2, const float y2,
  71542. const float offsetX, const float offsetY,
  71543. float& resultX, float& resultY) throw()
  71544. {
  71545. const float dx = x2 - x1;
  71546. const float dy = y2 - y1;
  71547. const float len = juce_hypotf (dx, dy);
  71548. if (len == 0)
  71549. {
  71550. resultX = x1;
  71551. resultY = y1;
  71552. }
  71553. else
  71554. {
  71555. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71556. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71557. }
  71558. }
  71559. void Path::addLineSegment (const float startX, const float startY,
  71560. const float endX, const float endY,
  71561. float lineThickness) throw()
  71562. {
  71563. lineThickness *= 0.5f;
  71564. float x, y;
  71565. perpendicularOffset (startX, startY, endX, endY,
  71566. 0, lineThickness, x, y);
  71567. startNewSubPath (x, y);
  71568. perpendicularOffset (startX, startY, endX, endY,
  71569. 0, -lineThickness, x, y);
  71570. lineTo (x, y);
  71571. perpendicularOffset (endX, endY, startX, startY,
  71572. 0, lineThickness, x, y);
  71573. lineTo (x, y);
  71574. perpendicularOffset (endX, endY, startX, startY,
  71575. 0, -lineThickness, x, y);
  71576. lineTo (x, y);
  71577. closeSubPath();
  71578. }
  71579. void Path::addArrow (const float startX, const float startY,
  71580. const float endX, const float endY,
  71581. float lineThickness,
  71582. float arrowheadWidth,
  71583. float arrowheadLength) throw()
  71584. {
  71585. lineThickness *= 0.5f;
  71586. arrowheadWidth *= 0.5f;
  71587. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71588. startY - endY));
  71589. float x, y;
  71590. perpendicularOffset (startX, startY, endX, endY,
  71591. 0, lineThickness, x, y);
  71592. startNewSubPath (x, y);
  71593. perpendicularOffset (startX, startY, endX, endY,
  71594. 0, -lineThickness, x, y);
  71595. lineTo (x, y);
  71596. perpendicularOffset (endX, endY, startX, startY,
  71597. arrowheadLength, lineThickness, x, y);
  71598. lineTo (x, y);
  71599. perpendicularOffset (endX, endY, startX, startY,
  71600. arrowheadLength, arrowheadWidth, x, y);
  71601. lineTo (x, y);
  71602. perpendicularOffset (endX, endY, startX, startY,
  71603. 0, 0, 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. arrowheadLength, -lineThickness, x, y);
  71610. lineTo (x, y);
  71611. closeSubPath();
  71612. }
  71613. void Path::addStar (const float centreX,
  71614. const float centreY,
  71615. const int numberOfPoints,
  71616. const float innerRadius,
  71617. const float outerRadius,
  71618. const float startAngle)
  71619. {
  71620. jassert (numberOfPoints > 1); // this would be silly.
  71621. if (numberOfPoints > 1)
  71622. {
  71623. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71624. for (int i = 0; i < numberOfPoints; ++i)
  71625. {
  71626. float angle = startAngle + i * angleBetweenPoints;
  71627. const float x = centreX + outerRadius * sinf (angle);
  71628. const float y = centreY - outerRadius * cosf (angle);
  71629. if (i == 0)
  71630. startNewSubPath (x, y);
  71631. else
  71632. lineTo (x, y);
  71633. angle += angleBetweenPoints * 0.5f;
  71634. lineTo (centreX + innerRadius * sinf (angle),
  71635. centreY - innerRadius * cosf (angle));
  71636. }
  71637. closeSubPath();
  71638. }
  71639. }
  71640. void Path::addBubble (float x, float y,
  71641. float w, float h,
  71642. float cs,
  71643. float tipX,
  71644. float tipY,
  71645. int whichSide,
  71646. float arrowPos,
  71647. float arrowWidth)
  71648. {
  71649. if (w > 1.0f && h > 1.0f)
  71650. {
  71651. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71652. const float cs2 = 2.0f * cs;
  71653. startNewSubPath (x + cs, y);
  71654. if (whichSide == 0)
  71655. {
  71656. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71657. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71658. lineTo (arrowX1, y);
  71659. lineTo (tipX, tipY);
  71660. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71661. }
  71662. lineTo (x + w - cs, y);
  71663. if (cs > 0.0f)
  71664. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71665. if (whichSide == 3)
  71666. {
  71667. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71668. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71669. lineTo (x + w, arrowY1);
  71670. lineTo (tipX, tipY);
  71671. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71672. }
  71673. lineTo (x + w, y + h - cs);
  71674. if (cs > 0.0f)
  71675. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71676. if (whichSide == 2)
  71677. {
  71678. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71679. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71680. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71681. lineTo (tipX, tipY);
  71682. lineTo (arrowX1, y + h);
  71683. }
  71684. lineTo (x + cs, y + h);
  71685. if (cs > 0.0f)
  71686. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71687. if (whichSide == 1)
  71688. {
  71689. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71690. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71691. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71692. lineTo (tipX, tipY);
  71693. lineTo (x, arrowY1);
  71694. }
  71695. lineTo (x, y + cs);
  71696. if (cs > 0.0f)
  71697. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71698. closeSubPath();
  71699. }
  71700. }
  71701. void Path::addPath (const Path& other) throw()
  71702. {
  71703. int i = 0;
  71704. while (i < other.numElements)
  71705. {
  71706. const float type = other.data.elements [i++];
  71707. if (type == moveMarker)
  71708. {
  71709. startNewSubPath (other.data.elements [i],
  71710. other.data.elements [i + 1]);
  71711. i += 2;
  71712. }
  71713. else if (type == lineMarker)
  71714. {
  71715. lineTo (other.data.elements [i],
  71716. other.data.elements [i + 1]);
  71717. i += 2;
  71718. }
  71719. else if (type == quadMarker)
  71720. {
  71721. quadraticTo (other.data.elements [i],
  71722. other.data.elements [i + 1],
  71723. other.data.elements [i + 2],
  71724. other.data.elements [i + 3]);
  71725. i += 4;
  71726. }
  71727. else if (type == cubicMarker)
  71728. {
  71729. cubicTo (other.data.elements [i],
  71730. other.data.elements [i + 1],
  71731. other.data.elements [i + 2],
  71732. other.data.elements [i + 3],
  71733. other.data.elements [i + 4],
  71734. other.data.elements [i + 5]);
  71735. i += 6;
  71736. }
  71737. else if (type == closeSubPathMarker)
  71738. {
  71739. closeSubPath();
  71740. }
  71741. else
  71742. {
  71743. // something's gone wrong with the element list!
  71744. jassertfalse
  71745. }
  71746. }
  71747. }
  71748. void Path::addPath (const Path& other,
  71749. const AffineTransform& transformToApply) throw()
  71750. {
  71751. int i = 0;
  71752. while (i < other.numElements)
  71753. {
  71754. const float type = other.data.elements [i++];
  71755. if (type == closeSubPathMarker)
  71756. {
  71757. closeSubPath();
  71758. }
  71759. else
  71760. {
  71761. float x = other.data.elements [i++];
  71762. float y = other.data.elements [i++];
  71763. transformToApply.transformPoint (x, y);
  71764. if (type == moveMarker)
  71765. {
  71766. startNewSubPath (x, y);
  71767. }
  71768. else if (type == lineMarker)
  71769. {
  71770. lineTo (x, y);
  71771. }
  71772. else if (type == quadMarker)
  71773. {
  71774. float x2 = other.data.elements [i++];
  71775. float y2 = other.data.elements [i++];
  71776. transformToApply.transformPoint (x2, y2);
  71777. quadraticTo (x, y, x2, y2);
  71778. }
  71779. else if (type == cubicMarker)
  71780. {
  71781. float x2 = other.data.elements [i++];
  71782. float y2 = other.data.elements [i++];
  71783. float x3 = other.data.elements [i++];
  71784. float y3 = other.data.elements [i++];
  71785. transformToApply.transformPoint (x2, y2);
  71786. transformToApply.transformPoint (x3, y3);
  71787. cubicTo (x, y, x2, y2, x3, y3);
  71788. }
  71789. else
  71790. {
  71791. // something's gone wrong with the element list!
  71792. jassertfalse
  71793. }
  71794. }
  71795. }
  71796. }
  71797. void Path::applyTransform (const AffineTransform& transform) throw()
  71798. {
  71799. int i = 0;
  71800. pathYMin = pathXMin = 0;
  71801. pathYMax = pathXMax = 0;
  71802. bool setMaxMin = false;
  71803. while (i < numElements)
  71804. {
  71805. const float type = data.elements [i++];
  71806. if (type == moveMarker)
  71807. {
  71808. transform.transformPoint (data.elements [i],
  71809. data.elements [i + 1]);
  71810. if (setMaxMin)
  71811. {
  71812. pathXMin = jmin (pathXMin, data.elements [i]);
  71813. pathXMax = jmax (pathXMax, data.elements [i]);
  71814. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71815. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71816. }
  71817. else
  71818. {
  71819. pathXMin = pathXMax = data.elements [i];
  71820. pathYMin = pathYMax = data.elements [i + 1];
  71821. setMaxMin = true;
  71822. }
  71823. i += 2;
  71824. }
  71825. else if (type == lineMarker)
  71826. {
  71827. transform.transformPoint (data.elements [i],
  71828. data.elements [i + 1]);
  71829. pathXMin = jmin (pathXMin, data.elements [i]);
  71830. pathXMax = jmax (pathXMax, data.elements [i]);
  71831. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71832. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71833. i += 2;
  71834. }
  71835. else if (type == quadMarker)
  71836. {
  71837. transform.transformPoint (data.elements [i],
  71838. data.elements [i + 1]);
  71839. transform.transformPoint (data.elements [i + 2],
  71840. data.elements [i + 3]);
  71841. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71842. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71843. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71844. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71845. i += 4;
  71846. }
  71847. else if (type == cubicMarker)
  71848. {
  71849. transform.transformPoint (data.elements [i],
  71850. data.elements [i + 1]);
  71851. transform.transformPoint (data.elements [i + 2],
  71852. data.elements [i + 3]);
  71853. transform.transformPoint (data.elements [i + 4],
  71854. data.elements [i + 5]);
  71855. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71856. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71857. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71858. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71859. i += 6;
  71860. }
  71861. }
  71862. }
  71863. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71864. const float w, const float h,
  71865. const bool preserveProportions,
  71866. const Justification& justification) const throw()
  71867. {
  71868. Rectangle<float> bounds (getBounds());
  71869. if (preserveProportions)
  71870. {
  71871. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71872. return AffineTransform::identity;
  71873. float newW, newH;
  71874. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71875. if (srcRatio > h / w)
  71876. {
  71877. newW = h / srcRatio;
  71878. newH = h;
  71879. }
  71880. else
  71881. {
  71882. newW = w;
  71883. newH = w * srcRatio;
  71884. }
  71885. float newXCentre = x;
  71886. float newYCentre = y;
  71887. if (justification.testFlags (Justification::left))
  71888. newXCentre += newW * 0.5f;
  71889. else if (justification.testFlags (Justification::right))
  71890. newXCentre += w - newW * 0.5f;
  71891. else
  71892. newXCentre += w * 0.5f;
  71893. if (justification.testFlags (Justification::top))
  71894. newYCentre += newH * 0.5f;
  71895. else if (justification.testFlags (Justification::bottom))
  71896. newYCentre += h - newH * 0.5f;
  71897. else
  71898. newYCentre += h * 0.5f;
  71899. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71900. bounds.getHeight() * -0.5f - bounds.getY())
  71901. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71902. .translated (newXCentre, newYCentre);
  71903. }
  71904. else
  71905. {
  71906. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71907. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71908. .translated (x, y);
  71909. }
  71910. }
  71911. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  71912. {
  71913. if (x <= pathXMin || x >= pathXMax
  71914. || y <= pathYMin || y >= pathYMax)
  71915. return false;
  71916. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71917. int positiveCrossings = 0;
  71918. int negativeCrossings = 0;
  71919. while (i.next())
  71920. {
  71921. if ((i.y1 <= y && i.y2 > y)
  71922. || (i.y2 <= y && i.y1 > y))
  71923. {
  71924. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71925. if (intersectX <= x)
  71926. {
  71927. if (i.y1 < i.y2)
  71928. ++positiveCrossings;
  71929. else
  71930. ++negativeCrossings;
  71931. }
  71932. }
  71933. }
  71934. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71935. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71936. }
  71937. bool Path::intersectsLine (const float x1, const float y1,
  71938. const float x2, const float y2,
  71939. const float tolerence) throw()
  71940. {
  71941. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71942. const Line line1 (x1, y1, x2, y2);
  71943. while (i.next())
  71944. {
  71945. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71946. float ix, iy;
  71947. if (line1.intersects (line2, ix, iy))
  71948. return true;
  71949. }
  71950. return false;
  71951. }
  71952. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  71953. {
  71954. if (cornerRadius <= 0.01f)
  71955. return *this;
  71956. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71957. int n = 0;
  71958. bool lastWasLine = false, firstWasLine = false;
  71959. Path p;
  71960. while (n < numElements)
  71961. {
  71962. const float type = data.elements [n++];
  71963. if (type == moveMarker)
  71964. {
  71965. indexOfPathStart = p.numElements;
  71966. indexOfPathStartThis = n - 1;
  71967. const float x = data.elements [n++];
  71968. const float y = data.elements [n++];
  71969. p.startNewSubPath (x, y);
  71970. lastWasLine = false;
  71971. firstWasLine = (data.elements [n] == lineMarker);
  71972. }
  71973. else if (type == lineMarker || type == closeSubPathMarker)
  71974. {
  71975. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71976. if (type == lineMarker)
  71977. {
  71978. endX = data.elements [n++];
  71979. endY = data.elements [n++];
  71980. if (n > 8)
  71981. {
  71982. startX = data.elements [n - 8];
  71983. startY = data.elements [n - 7];
  71984. joinX = data.elements [n - 5];
  71985. joinY = data.elements [n - 4];
  71986. }
  71987. }
  71988. else
  71989. {
  71990. endX = data.elements [indexOfPathStartThis + 1];
  71991. endY = data.elements [indexOfPathStartThis + 2];
  71992. if (n > 6)
  71993. {
  71994. startX = data.elements [n - 6];
  71995. startY = data.elements [n - 5];
  71996. joinX = data.elements [n - 3];
  71997. joinY = data.elements [n - 2];
  71998. }
  71999. }
  72000. if (lastWasLine)
  72001. {
  72002. const double len1 = juce_hypot (startX - joinX,
  72003. startY - joinY);
  72004. if (len1 > 0)
  72005. {
  72006. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72007. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72008. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72009. }
  72010. const double len2 = juce_hypot (endX - joinX,
  72011. endY - joinY);
  72012. if (len2 > 0)
  72013. {
  72014. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72015. p.quadraticTo (joinX, joinY,
  72016. (float) (joinX + (endX - joinX) * propNeeded),
  72017. (float) (joinY + (endY - joinY) * propNeeded));
  72018. }
  72019. p.lineTo (endX, endY);
  72020. }
  72021. else if (type == lineMarker)
  72022. {
  72023. p.lineTo (endX, endY);
  72024. lastWasLine = true;
  72025. }
  72026. if (type == closeSubPathMarker)
  72027. {
  72028. if (firstWasLine)
  72029. {
  72030. startX = data.elements [n - 3];
  72031. startY = data.elements [n - 2];
  72032. joinX = endX;
  72033. joinY = endY;
  72034. endX = data.elements [indexOfPathStartThis + 4];
  72035. endY = data.elements [indexOfPathStartThis + 5];
  72036. const double len1 = juce_hypot (startX - joinX,
  72037. startY - joinY);
  72038. if (len1 > 0)
  72039. {
  72040. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72041. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72042. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72043. }
  72044. const double len2 = juce_hypot (endX - joinX,
  72045. endY - joinY);
  72046. if (len2 > 0)
  72047. {
  72048. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72049. endX = (float) (joinX + (endX - joinX) * propNeeded);
  72050. endY = (float) (joinY + (endY - joinY) * propNeeded);
  72051. p.quadraticTo (joinX, joinY, endX, endY);
  72052. p.data.elements [indexOfPathStart + 1] = endX;
  72053. p.data.elements [indexOfPathStart + 2] = endY;
  72054. }
  72055. }
  72056. p.closeSubPath();
  72057. }
  72058. }
  72059. else if (type == quadMarker)
  72060. {
  72061. lastWasLine = false;
  72062. const float x1 = data.elements [n++];
  72063. const float y1 = data.elements [n++];
  72064. const float x2 = data.elements [n++];
  72065. const float y2 = data.elements [n++];
  72066. p.quadraticTo (x1, y1, x2, y2);
  72067. }
  72068. else if (type == cubicMarker)
  72069. {
  72070. lastWasLine = false;
  72071. const float x1 = data.elements [n++];
  72072. const float y1 = data.elements [n++];
  72073. const float x2 = data.elements [n++];
  72074. const float y2 = data.elements [n++];
  72075. const float x3 = data.elements [n++];
  72076. const float y3 = data.elements [n++];
  72077. p.cubicTo (x1, y1, x2, y2, x3, y3);
  72078. }
  72079. }
  72080. return p;
  72081. }
  72082. void Path::loadPathFromStream (InputStream& source)
  72083. {
  72084. while (! source.isExhausted())
  72085. {
  72086. switch (source.readByte())
  72087. {
  72088. case 'm':
  72089. {
  72090. const float x = source.readFloat();
  72091. const float y = source.readFloat();
  72092. startNewSubPath (x, y);
  72093. break;
  72094. }
  72095. case 'l':
  72096. {
  72097. const float x = source.readFloat();
  72098. const float y = source.readFloat();
  72099. lineTo (x, y);
  72100. break;
  72101. }
  72102. case 'q':
  72103. {
  72104. const float x1 = source.readFloat();
  72105. const float y1 = source.readFloat();
  72106. const float x2 = source.readFloat();
  72107. const float y2 = source.readFloat();
  72108. quadraticTo (x1, y1, x2, y2);
  72109. break;
  72110. }
  72111. case 'b':
  72112. {
  72113. const float x1 = source.readFloat();
  72114. const float y1 = source.readFloat();
  72115. const float x2 = source.readFloat();
  72116. const float y2 = source.readFloat();
  72117. const float x3 = source.readFloat();
  72118. const float y3 = source.readFloat();
  72119. cubicTo (x1, y1, x2, y2, x3, y3);
  72120. break;
  72121. }
  72122. case 'c':
  72123. closeSubPath();
  72124. break;
  72125. case 'n':
  72126. useNonZeroWinding = true;
  72127. break;
  72128. case 'z':
  72129. useNonZeroWinding = false;
  72130. break;
  72131. case 'e':
  72132. return; // end of path marker
  72133. default:
  72134. jassertfalse // illegal char in the stream
  72135. break;
  72136. }
  72137. }
  72138. }
  72139. void Path::loadPathFromData (const unsigned char* const data,
  72140. const int numberOfBytes) throw()
  72141. {
  72142. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  72143. loadPathFromStream (in);
  72144. }
  72145. void Path::writePathToStream (OutputStream& dest) const
  72146. {
  72147. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  72148. int i = 0;
  72149. while (i < numElements)
  72150. {
  72151. const float type = data.elements [i++];
  72152. if (type == moveMarker)
  72153. {
  72154. dest.writeByte ('m');
  72155. dest.writeFloat (data.elements [i++]);
  72156. dest.writeFloat (data.elements [i++]);
  72157. }
  72158. else if (type == lineMarker)
  72159. {
  72160. dest.writeByte ('l');
  72161. dest.writeFloat (data.elements [i++]);
  72162. dest.writeFloat (data.elements [i++]);
  72163. }
  72164. else if (type == quadMarker)
  72165. {
  72166. dest.writeByte ('q');
  72167. dest.writeFloat (data.elements [i++]);
  72168. dest.writeFloat (data.elements [i++]);
  72169. dest.writeFloat (data.elements [i++]);
  72170. dest.writeFloat (data.elements [i++]);
  72171. }
  72172. else if (type == cubicMarker)
  72173. {
  72174. dest.writeByte ('b');
  72175. dest.writeFloat (data.elements [i++]);
  72176. dest.writeFloat (data.elements [i++]);
  72177. dest.writeFloat (data.elements [i++]);
  72178. dest.writeFloat (data.elements [i++]);
  72179. dest.writeFloat (data.elements [i++]);
  72180. dest.writeFloat (data.elements [i++]);
  72181. }
  72182. else if (type == closeSubPathMarker)
  72183. {
  72184. dest.writeByte ('c');
  72185. }
  72186. }
  72187. dest.writeByte ('e'); // marks the end-of-path
  72188. }
  72189. const String Path::toString() const
  72190. {
  72191. MemoryOutputStream s (2048, 2048);
  72192. if (! useNonZeroWinding)
  72193. s << "a ";
  72194. int i = 0;
  72195. float lastMarker = 0.0f;
  72196. while (i < numElements)
  72197. {
  72198. const float marker = data.elements [i++];
  72199. char markerChar = 0;
  72200. int numCoords = 0;
  72201. if (marker == moveMarker)
  72202. {
  72203. markerChar = 'm';
  72204. numCoords = 2;
  72205. }
  72206. else if (marker == lineMarker)
  72207. {
  72208. markerChar = 'l';
  72209. numCoords = 2;
  72210. }
  72211. else if (marker == quadMarker)
  72212. {
  72213. markerChar = 'q';
  72214. numCoords = 4;
  72215. }
  72216. else if (marker == cubicMarker)
  72217. {
  72218. markerChar = 'c';
  72219. numCoords = 6;
  72220. }
  72221. else
  72222. {
  72223. jassert (marker == closeSubPathMarker);
  72224. markerChar = 'z';
  72225. }
  72226. if (marker != lastMarker)
  72227. {
  72228. s << markerChar << ' ';
  72229. lastMarker = marker;
  72230. }
  72231. while (--numCoords >= 0 && i < numElements)
  72232. {
  72233. String n (data.elements [i++], 3);
  72234. if (n.endsWithChar (T('0')))
  72235. {
  72236. do
  72237. {
  72238. n = n.dropLastCharacters (1);
  72239. } while (n.endsWithChar (T('0')));
  72240. if (n.endsWithChar (T('.')))
  72241. n = n.dropLastCharacters (1);
  72242. }
  72243. s << n << ' ';
  72244. }
  72245. }
  72246. const char* const result = (const char*) s.getData();
  72247. size_t len = s.getDataSize();
  72248. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  72249. --len;
  72250. return String (result, len);
  72251. }
  72252. static const String nextToken (const tchar*& t)
  72253. {
  72254. while (CharacterFunctions::isWhitespace (*t))
  72255. ++t;
  72256. const tchar* const start = t;
  72257. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  72258. ++t;
  72259. const int length = (int) (t - start);
  72260. while (CharacterFunctions::isWhitespace (*t))
  72261. ++t;
  72262. return String (start, length);
  72263. }
  72264. void Path::restoreFromString (const String& stringVersion)
  72265. {
  72266. clear();
  72267. setUsingNonZeroWinding (true);
  72268. const tchar* t = stringVersion;
  72269. tchar marker = T('m');
  72270. int numValues = 2;
  72271. float values [6];
  72272. while (*t != 0)
  72273. {
  72274. const String token (nextToken (t));
  72275. const tchar firstChar = token[0];
  72276. int startNum = 0;
  72277. if (firstChar == T('m') || firstChar == T('l'))
  72278. {
  72279. marker = firstChar;
  72280. numValues = 2;
  72281. }
  72282. else if (firstChar == T('q'))
  72283. {
  72284. marker = firstChar;
  72285. numValues = 4;
  72286. }
  72287. else if (firstChar == T('c'))
  72288. {
  72289. marker = firstChar;
  72290. numValues = 6;
  72291. }
  72292. else if (firstChar == T('z'))
  72293. {
  72294. marker = firstChar;
  72295. numValues = 0;
  72296. }
  72297. else if (firstChar == T('a'))
  72298. {
  72299. setUsingNonZeroWinding (false);
  72300. continue;
  72301. }
  72302. else
  72303. {
  72304. ++startNum;
  72305. values [0] = token.getFloatValue();
  72306. }
  72307. for (int i = startNum; i < numValues; ++i)
  72308. values [i] = nextToken (t).getFloatValue();
  72309. switch (marker)
  72310. {
  72311. case T('m'):
  72312. startNewSubPath (values[0], values[1]);
  72313. break;
  72314. case T('l'):
  72315. lineTo (values[0], values[1]);
  72316. break;
  72317. case T('q'):
  72318. quadraticTo (values[0], values[1],
  72319. values[2], values[3]);
  72320. break;
  72321. case T('c'):
  72322. cubicTo (values[0], values[1],
  72323. values[2], values[3],
  72324. values[4], values[5]);
  72325. break;
  72326. case T('z'):
  72327. closeSubPath();
  72328. break;
  72329. default:
  72330. jassertfalse // illegal string format?
  72331. break;
  72332. }
  72333. }
  72334. }
  72335. Path::Iterator::Iterator (const Path& path_)
  72336. : path (path_),
  72337. index (0)
  72338. {
  72339. }
  72340. Path::Iterator::~Iterator()
  72341. {
  72342. }
  72343. bool Path::Iterator::next()
  72344. {
  72345. const float* const elements = path.data.elements;
  72346. if (index < path.numElements)
  72347. {
  72348. const float type = elements [index++];
  72349. if (type == moveMarker)
  72350. {
  72351. elementType = startNewSubPath;
  72352. x1 = elements [index++];
  72353. y1 = elements [index++];
  72354. }
  72355. else if (type == lineMarker)
  72356. {
  72357. elementType = lineTo;
  72358. x1 = elements [index++];
  72359. y1 = elements [index++];
  72360. }
  72361. else if (type == quadMarker)
  72362. {
  72363. elementType = quadraticTo;
  72364. x1 = elements [index++];
  72365. y1 = elements [index++];
  72366. x2 = elements [index++];
  72367. y2 = elements [index++];
  72368. }
  72369. else if (type == cubicMarker)
  72370. {
  72371. elementType = cubicTo;
  72372. x1 = elements [index++];
  72373. y1 = elements [index++];
  72374. x2 = elements [index++];
  72375. y2 = elements [index++];
  72376. x3 = elements [index++];
  72377. y3 = elements [index++];
  72378. }
  72379. else if (type == closeSubPathMarker)
  72380. {
  72381. elementType = closePath;
  72382. }
  72383. return true;
  72384. }
  72385. return false;
  72386. }
  72387. END_JUCE_NAMESPACE
  72388. /*** End of inlined file: juce_Path.cpp ***/
  72389. /*** Start of inlined file: juce_PathIterator.cpp ***/
  72390. BEGIN_JUCE_NAMESPACE
  72391. #if JUCE_MSVC
  72392. #pragma optimize ("t", on)
  72393. #endif
  72394. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72395. const AffineTransform& transform_,
  72396. float tolerence_) throw()
  72397. : x2 (0),
  72398. y2 (0),
  72399. closesSubPath (false),
  72400. subPathIndex (-1),
  72401. path (path_),
  72402. transform (transform_),
  72403. points (path_.data.elements),
  72404. tolerence (tolerence_ * tolerence_),
  72405. subPathCloseX (0),
  72406. subPathCloseY (0),
  72407. stackBase (32),
  72408. index (0),
  72409. stackSize (32)
  72410. {
  72411. isIdentityTransform = transform.isIdentity();
  72412. stackPos = stackBase;
  72413. }
  72414. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72415. {
  72416. }
  72417. bool PathFlatteningIterator::next() throw()
  72418. {
  72419. x1 = x2;
  72420. y1 = y2;
  72421. float x3 = 0;
  72422. float y3 = 0;
  72423. float x4 = 0;
  72424. float y4 = 0;
  72425. float type;
  72426. for (;;)
  72427. {
  72428. if (stackPos == stackBase)
  72429. {
  72430. if (index >= path.numElements)
  72431. {
  72432. return false;
  72433. }
  72434. else
  72435. {
  72436. type = points [index++];
  72437. if (type != Path::closeSubPathMarker)
  72438. {
  72439. x2 = points [index++];
  72440. y2 = points [index++];
  72441. if (! isIdentityTransform)
  72442. transform.transformPoint (x2, y2);
  72443. if (type == Path::quadMarker)
  72444. {
  72445. x3 = points [index++];
  72446. y3 = points [index++];
  72447. if (! isIdentityTransform)
  72448. transform.transformPoint (x3, y3);
  72449. }
  72450. else if (type == Path::cubicMarker)
  72451. {
  72452. x3 = points [index++];
  72453. y3 = points [index++];
  72454. x4 = points [index++];
  72455. y4 = points [index++];
  72456. if (! isIdentityTransform)
  72457. {
  72458. transform.transformPoint (x3, y3);
  72459. transform.transformPoint (x4, y4);
  72460. }
  72461. }
  72462. }
  72463. }
  72464. }
  72465. else
  72466. {
  72467. type = *--stackPos;
  72468. if (type != Path::closeSubPathMarker)
  72469. {
  72470. x2 = *--stackPos;
  72471. y2 = *--stackPos;
  72472. if (type == Path::quadMarker)
  72473. {
  72474. x3 = *--stackPos;
  72475. y3 = *--stackPos;
  72476. }
  72477. else if (type == Path::cubicMarker)
  72478. {
  72479. x3 = *--stackPos;
  72480. y3 = *--stackPos;
  72481. x4 = *--stackPos;
  72482. y4 = *--stackPos;
  72483. }
  72484. }
  72485. }
  72486. if (type == Path::lineMarker)
  72487. {
  72488. ++subPathIndex;
  72489. closesSubPath = (stackPos == stackBase)
  72490. && (index < path.numElements)
  72491. && (points [index] == Path::closeSubPathMarker)
  72492. && x2 == subPathCloseX
  72493. && y2 == subPathCloseY;
  72494. return true;
  72495. }
  72496. else if (type == Path::quadMarker)
  72497. {
  72498. const int offset = (int) (stackPos - stackBase);
  72499. if (offset >= stackSize - 10)
  72500. {
  72501. stackSize <<= 1;
  72502. stackBase.realloc (stackSize);
  72503. stackPos = stackBase + offset;
  72504. }
  72505. const float dx1 = x1 - x2;
  72506. const float dy1 = y1 - y2;
  72507. const float dx2 = x2 - x3;
  72508. const float dy2 = y2 - y3;
  72509. const float m1x = (x1 + x2) * 0.5f;
  72510. const float m1y = (y1 + y2) * 0.5f;
  72511. const float m2x = (x2 + x3) * 0.5f;
  72512. const float m2y = (y2 + y3) * 0.5f;
  72513. const float m3x = (m1x + m2x) * 0.5f;
  72514. const float m3y = (m1y + m2y) * 0.5f;
  72515. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72516. {
  72517. *stackPos++ = y3;
  72518. *stackPos++ = x3;
  72519. *stackPos++ = m2y;
  72520. *stackPos++ = m2x;
  72521. *stackPos++ = Path::quadMarker;
  72522. *stackPos++ = m3y;
  72523. *stackPos++ = m3x;
  72524. *stackPos++ = m1y;
  72525. *stackPos++ = m1x;
  72526. *stackPos++ = Path::quadMarker;
  72527. }
  72528. else
  72529. {
  72530. *stackPos++ = y3;
  72531. *stackPos++ = x3;
  72532. *stackPos++ = Path::lineMarker;
  72533. *stackPos++ = m3y;
  72534. *stackPos++ = m3x;
  72535. *stackPos++ = Path::lineMarker;
  72536. }
  72537. jassert (stackPos < stackBase + stackSize);
  72538. }
  72539. else if (type == Path::cubicMarker)
  72540. {
  72541. const int offset = (int) (stackPos - stackBase);
  72542. if (offset >= stackSize - 16)
  72543. {
  72544. stackSize <<= 1;
  72545. stackBase.realloc (stackSize);
  72546. stackPos = stackBase + offset;
  72547. }
  72548. const float dx1 = x1 - x2;
  72549. const float dy1 = y1 - y2;
  72550. const float dx2 = x2 - x3;
  72551. const float dy2 = y2 - y3;
  72552. const float dx3 = x3 - x4;
  72553. const float dy3 = y3 - y4;
  72554. const float m1x = (x1 + x2) * 0.5f;
  72555. const float m1y = (y1 + y2) * 0.5f;
  72556. const float m2x = (x3 + x2) * 0.5f;
  72557. const float m2y = (y3 + y2) * 0.5f;
  72558. const float m3x = (x3 + x4) * 0.5f;
  72559. const float m3y = (y3 + y4) * 0.5f;
  72560. const float m4x = (m1x + m2x) * 0.5f;
  72561. const float m4y = (m1y + m2y) * 0.5f;
  72562. const float m5x = (m3x + m2x) * 0.5f;
  72563. const float m5y = (m3y + m2y) * 0.5f;
  72564. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72565. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72566. {
  72567. *stackPos++ = y4;
  72568. *stackPos++ = x4;
  72569. *stackPos++ = m3y;
  72570. *stackPos++ = m3x;
  72571. *stackPos++ = m5y;
  72572. *stackPos++ = m5x;
  72573. *stackPos++ = Path::cubicMarker;
  72574. *stackPos++ = (m4y + m5y) * 0.5f;
  72575. *stackPos++ = (m4x + m5x) * 0.5f;
  72576. *stackPos++ = m4y;
  72577. *stackPos++ = m4x;
  72578. *stackPos++ = m1y;
  72579. *stackPos++ = m1x;
  72580. *stackPos++ = Path::cubicMarker;
  72581. }
  72582. else
  72583. {
  72584. *stackPos++ = y4;
  72585. *stackPos++ = x4;
  72586. *stackPos++ = Path::lineMarker;
  72587. *stackPos++ = m5y;
  72588. *stackPos++ = m5x;
  72589. *stackPos++ = Path::lineMarker;
  72590. *stackPos++ = m4y;
  72591. *stackPos++ = m4x;
  72592. *stackPos++ = Path::lineMarker;
  72593. }
  72594. }
  72595. else if (type == Path::closeSubPathMarker)
  72596. {
  72597. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72598. {
  72599. x1 = x2;
  72600. y1 = y2;
  72601. x2 = subPathCloseX;
  72602. y2 = subPathCloseY;
  72603. closesSubPath = true;
  72604. return true;
  72605. }
  72606. }
  72607. else
  72608. {
  72609. jassert (type == Path::moveMarker);
  72610. subPathIndex = -1;
  72611. subPathCloseX = x1 = x2;
  72612. subPathCloseY = y1 = y2;
  72613. }
  72614. }
  72615. }
  72616. END_JUCE_NAMESPACE
  72617. /*** End of inlined file: juce_PathIterator.cpp ***/
  72618. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72619. BEGIN_JUCE_NAMESPACE
  72620. PathStrokeType::PathStrokeType (const float strokeThickness,
  72621. const JointStyle jointStyle_,
  72622. const EndCapStyle endStyle_) throw()
  72623. : thickness (strokeThickness),
  72624. jointStyle (jointStyle_),
  72625. endStyle (endStyle_)
  72626. {
  72627. }
  72628. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72629. : thickness (other.thickness),
  72630. jointStyle (other.jointStyle),
  72631. endStyle (other.endStyle)
  72632. {
  72633. }
  72634. const PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72635. {
  72636. thickness = other.thickness;
  72637. jointStyle = other.jointStyle;
  72638. endStyle = other.endStyle;
  72639. return *this;
  72640. }
  72641. PathStrokeType::~PathStrokeType() throw()
  72642. {
  72643. }
  72644. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72645. {
  72646. return thickness == other.thickness
  72647. && jointStyle == other.jointStyle
  72648. && endStyle == other.endStyle;
  72649. }
  72650. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72651. {
  72652. return ! operator== (other);
  72653. }
  72654. static bool lineIntersection (const float x1, const float y1,
  72655. const float x2, const float y2,
  72656. const float x3, const float y3,
  72657. const float x4, const float y4,
  72658. float& intersectionX,
  72659. float& intersectionY,
  72660. float& distanceBeyondLine1EndSquared) throw()
  72661. {
  72662. if (x2 != x3 || y2 != y3)
  72663. {
  72664. const float dx1 = x2 - x1;
  72665. const float dy1 = y2 - y1;
  72666. const float dx2 = x4 - x3;
  72667. const float dy2 = y4 - y3;
  72668. const float divisor = dx1 * dy2 - dx2 * dy1;
  72669. if (divisor == 0)
  72670. {
  72671. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72672. {
  72673. if (dy1 == 0 && dy2 != 0)
  72674. {
  72675. const float along = (y1 - y3) / dy2;
  72676. intersectionX = x3 + along * dx2;
  72677. intersectionY = y1;
  72678. distanceBeyondLine1EndSquared = intersectionX - x2;
  72679. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72680. if ((x2 > x1) == (intersectionX < x2))
  72681. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72682. return along >= 0 && along <= 1.0f;
  72683. }
  72684. else if (dy2 == 0 && dy1 != 0)
  72685. {
  72686. const float along = (y3 - y1) / dy1;
  72687. intersectionX = x1 + along * dx1;
  72688. intersectionY = y3;
  72689. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72690. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72691. if (along < 1.0f)
  72692. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72693. return along >= 0 && along <= 1.0f;
  72694. }
  72695. else if (dx1 == 0 && dx2 != 0)
  72696. {
  72697. const float along = (x1 - x3) / dx2;
  72698. intersectionX = x1;
  72699. intersectionY = y3 + along * dy2;
  72700. distanceBeyondLine1EndSquared = intersectionY - y2;
  72701. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72702. if ((y2 > y1) == (intersectionY < y2))
  72703. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72704. return along >= 0 && along <= 1.0f;
  72705. }
  72706. else if (dx2 == 0 && dx1 != 0)
  72707. {
  72708. const float along = (x3 - x1) / dx1;
  72709. intersectionX = x3;
  72710. intersectionY = y1 + along * dy1;
  72711. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72712. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72713. if (along < 1.0f)
  72714. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72715. return along >= 0 && along <= 1.0f;
  72716. }
  72717. }
  72718. intersectionX = 0.5f * (x2 + x3);
  72719. intersectionY = 0.5f * (y2 + y3);
  72720. distanceBeyondLine1EndSquared = 0.0f;
  72721. return false;
  72722. }
  72723. else
  72724. {
  72725. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72726. intersectionX = x1 + along1 * dx1;
  72727. intersectionY = y1 + along1 * dy1;
  72728. if (along1 >= 0 && along1 <= 1.0f)
  72729. {
  72730. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72731. if (along2 >= 0 && along2 <= divisor)
  72732. {
  72733. distanceBeyondLine1EndSquared = 0.0f;
  72734. return true;
  72735. }
  72736. }
  72737. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72738. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72739. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72740. if (along1 < 1.0f)
  72741. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72742. return false;
  72743. }
  72744. }
  72745. intersectionX = x2;
  72746. intersectionY = y2;
  72747. distanceBeyondLine1EndSquared = 0.0f;
  72748. return true;
  72749. }
  72750. // part of stroke drawing stuff
  72751. static void addEdgeAndJoint (Path& destPath,
  72752. const PathStrokeType::JointStyle style,
  72753. const float maxMiterExtensionSquared, const float width,
  72754. const float x1, const float y1,
  72755. const float x2, const float y2,
  72756. const float x3, const float y3,
  72757. const float x4, const float y4,
  72758. const float midX, const float midY) throw()
  72759. {
  72760. if (style == PathStrokeType::beveled
  72761. || (x3 == x4 && y3 == y4)
  72762. || (x1 == x2 && y1 == y2))
  72763. {
  72764. destPath.lineTo (x2, y2);
  72765. destPath.lineTo (x3, y3);
  72766. }
  72767. else
  72768. {
  72769. float jx, jy, distanceBeyondLine1EndSquared;
  72770. // if they intersect, use this point..
  72771. if (lineIntersection (x1, y1, x2, y2,
  72772. x3, y3, x4, y4,
  72773. jx, jy, distanceBeyondLine1EndSquared))
  72774. {
  72775. destPath.lineTo (jx, jy);
  72776. }
  72777. else
  72778. {
  72779. if (style == PathStrokeType::mitered)
  72780. {
  72781. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72782. && distanceBeyondLine1EndSquared > 0.0f)
  72783. {
  72784. destPath.lineTo (jx, jy);
  72785. }
  72786. else
  72787. {
  72788. // the end sticks out too far, so just use a blunt joint
  72789. destPath.lineTo (x2, y2);
  72790. destPath.lineTo (x3, y3);
  72791. }
  72792. }
  72793. else
  72794. {
  72795. // curved joints
  72796. float angle1 = atan2f (x2 - midX, y2 - midY);
  72797. float angle2 = atan2f (x3 - midX, y3 - midY);
  72798. const float angleIncrement = 0.1f;
  72799. destPath.lineTo (x2, y2);
  72800. if (fabs (angle1 - angle2) > angleIncrement)
  72801. {
  72802. if (angle2 > angle1 + float_Pi
  72803. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72804. {
  72805. if (angle2 > angle1)
  72806. angle2 -= float_Pi * 2.0f;
  72807. jassert (angle1 <= angle2 + float_Pi);
  72808. angle1 -= angleIncrement;
  72809. while (angle1 > angle2)
  72810. {
  72811. destPath.lineTo (midX + width * sinf (angle1),
  72812. midY + width * cosf (angle1));
  72813. angle1 -= angleIncrement;
  72814. }
  72815. }
  72816. else
  72817. {
  72818. if (angle1 > angle2)
  72819. angle1 -= float_Pi * 2.0f;
  72820. jassert (angle1 >= angle2 - float_Pi);
  72821. angle1 += angleIncrement;
  72822. while (angle1 < angle2)
  72823. {
  72824. destPath.lineTo (midX + width * sinf (angle1),
  72825. midY + width * cosf (angle1));
  72826. angle1 += angleIncrement;
  72827. }
  72828. }
  72829. }
  72830. destPath.lineTo (x3, y3);
  72831. }
  72832. }
  72833. }
  72834. }
  72835. static inline void addLineEnd (Path& destPath,
  72836. const PathStrokeType::EndCapStyle style,
  72837. const float x1, const float y1,
  72838. const float x2, const float y2,
  72839. const float width) throw()
  72840. {
  72841. if (style == PathStrokeType::butt)
  72842. {
  72843. destPath.lineTo (x2, y2);
  72844. }
  72845. else
  72846. {
  72847. float offx1, offy1, offx2, offy2;
  72848. float dx = x2 - x1;
  72849. float dy = y2 - y1;
  72850. const float len = juce_hypotf (dx, dy);
  72851. if (len == 0)
  72852. {
  72853. offx1 = offx2 = x1;
  72854. offy1 = offy2 = y1;
  72855. }
  72856. else
  72857. {
  72858. const float offset = width / len;
  72859. dx *= offset;
  72860. dy *= offset;
  72861. offx1 = x1 + dy;
  72862. offy1 = y1 - dx;
  72863. offx2 = x2 + dy;
  72864. offy2 = y2 - dx;
  72865. }
  72866. if (style == PathStrokeType::square)
  72867. {
  72868. // sqaure ends
  72869. destPath.lineTo (offx1, offy1);
  72870. destPath.lineTo (offx2, offy2);
  72871. destPath.lineTo (x2, y2);
  72872. }
  72873. else
  72874. {
  72875. // rounded ends
  72876. const float midx = (offx1 + offx2) * 0.5f;
  72877. const float midy = (offy1 + offy2) * 0.5f;
  72878. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72879. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72880. midx, midy);
  72881. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72882. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72883. x2, y2);
  72884. }
  72885. }
  72886. }
  72887. struct LineSection
  72888. {
  72889. LineSection() {}
  72890. LineSection (int) {}
  72891. float x1, y1, x2, y2; // original line
  72892. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72893. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72894. };
  72895. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72896. const bool isClosed,
  72897. const float width, const float maxMiterExtensionSquared,
  72898. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle) throw()
  72899. {
  72900. jassert (subPath.size() > 0);
  72901. const LineSection& firstLine = subPath.getReference (0);
  72902. float lastX1 = firstLine.lx1;
  72903. float lastY1 = firstLine.ly1;
  72904. float lastX2 = firstLine.lx2;
  72905. float lastY2 = firstLine.ly2;
  72906. if (isClosed)
  72907. {
  72908. destPath.startNewSubPath (lastX1, lastY1);
  72909. }
  72910. else
  72911. {
  72912. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72913. addLineEnd (destPath, endStyle,
  72914. firstLine.rx2, firstLine.ry2,
  72915. lastX1, lastY1,
  72916. width);
  72917. }
  72918. int i;
  72919. for (i = 1; i < subPath.size(); ++i)
  72920. {
  72921. const LineSection& l = subPath.getReference (i);
  72922. addEdgeAndJoint (destPath, jointStyle,
  72923. maxMiterExtensionSquared, width,
  72924. lastX1, lastY1, lastX2, lastY2,
  72925. l.lx1, l.ly1, l.lx2, l.ly2,
  72926. l.x1, l.y1);
  72927. lastX1 = l.lx1;
  72928. lastY1 = l.ly1;
  72929. lastX2 = l.lx2;
  72930. lastY2 = l.ly2;
  72931. }
  72932. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72933. if (isClosed)
  72934. {
  72935. const LineSection& l = subPath.getReference (0);
  72936. addEdgeAndJoint (destPath, jointStyle,
  72937. maxMiterExtensionSquared, width,
  72938. lastX1, lastY1, lastX2, lastY2,
  72939. l.lx1, l.ly1, l.lx2, l.ly2,
  72940. l.x1, l.y1);
  72941. destPath.closeSubPath();
  72942. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72943. }
  72944. else
  72945. {
  72946. destPath.lineTo (lastX2, lastY2);
  72947. addLineEnd (destPath, endStyle,
  72948. lastX2, lastY2,
  72949. lastLine.rx1, lastLine.ry1,
  72950. width);
  72951. }
  72952. lastX1 = lastLine.rx1;
  72953. lastY1 = lastLine.ry1;
  72954. lastX2 = lastLine.rx2;
  72955. lastY2 = lastLine.ry2;
  72956. for (i = subPath.size() - 1; --i >= 0;)
  72957. {
  72958. const LineSection& l = subPath.getReference (i);
  72959. addEdgeAndJoint (destPath, jointStyle,
  72960. maxMiterExtensionSquared, width,
  72961. lastX1, lastY1, lastX2, lastY2,
  72962. l.rx1, l.ry1, l.rx2, l.ry2,
  72963. l.x2, l.y2);
  72964. lastX1 = l.rx1;
  72965. lastY1 = l.ry1;
  72966. lastX2 = l.rx2;
  72967. lastY2 = l.ry2;
  72968. }
  72969. if (isClosed)
  72970. {
  72971. addEdgeAndJoint (destPath, jointStyle,
  72972. maxMiterExtensionSquared, width,
  72973. lastX1, lastY1, lastX2, lastY2,
  72974. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72975. lastLine.x2, lastLine.y2);
  72976. }
  72977. else
  72978. {
  72979. // do the last line
  72980. destPath.lineTo (lastX2, lastY2);
  72981. }
  72982. destPath.closeSubPath();
  72983. }
  72984. void PathStrokeType::createStrokedPath (Path& destPath,
  72985. const Path& source,
  72986. const AffineTransform& transform,
  72987. const float extraAccuracy) const throw()
  72988. {
  72989. if (thickness <= 0)
  72990. {
  72991. destPath.clear();
  72992. return;
  72993. }
  72994. const Path* sourcePath = &source;
  72995. Path temp;
  72996. if (sourcePath == &destPath)
  72997. {
  72998. destPath.swapWithPath (temp);
  72999. sourcePath = &temp;
  73000. }
  73001. else
  73002. {
  73003. destPath.clear();
  73004. }
  73005. destPath.setUsingNonZeroWinding (true);
  73006. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  73007. const float width = 0.5f * thickness;
  73008. // Iterate the path, creating a list of the
  73009. // left/right-hand lines along either side of it...
  73010. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  73011. Array <LineSection> subPath;
  73012. LineSection l;
  73013. l.x1 = 0;
  73014. l.y1 = 0;
  73015. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  73016. while (it.next())
  73017. {
  73018. if (it.subPathIndex == 0)
  73019. {
  73020. if (subPath.size() > 0)
  73021. {
  73022. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73023. subPath.clearQuick();
  73024. }
  73025. l.x1 = it.x1;
  73026. l.y1 = it.y1;
  73027. }
  73028. l.x2 = it.x2;
  73029. l.y2 = it.y2;
  73030. float dx = l.x2 - l.x1;
  73031. float dy = l.y2 - l.y1;
  73032. const float hypotSquared = dx*dx + dy*dy;
  73033. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  73034. {
  73035. const float len = sqrtf (hypotSquared);
  73036. if (len == 0)
  73037. {
  73038. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  73039. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  73040. }
  73041. else
  73042. {
  73043. const float offset = width / len;
  73044. dx *= offset;
  73045. dy *= offset;
  73046. l.rx2 = l.x1 - dy;
  73047. l.ry2 = l.y1 + dx;
  73048. l.lx1 = l.x1 + dy;
  73049. l.ly1 = l.y1 - dx;
  73050. l.lx2 = l.x2 + dy;
  73051. l.ly2 = l.y2 - dx;
  73052. l.rx1 = l.x2 - dy;
  73053. l.ry1 = l.y2 + dx;
  73054. }
  73055. subPath.add (l);
  73056. if (it.closesSubPath)
  73057. {
  73058. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73059. subPath.clearQuick();
  73060. }
  73061. else
  73062. {
  73063. l.x1 = it.x2;
  73064. l.y1 = it.y2;
  73065. }
  73066. }
  73067. }
  73068. if (subPath.size() > 0)
  73069. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73070. }
  73071. void PathStrokeType::createDashedStroke (Path& destPath,
  73072. const Path& sourcePath,
  73073. const float* dashLengths,
  73074. int numDashLengths,
  73075. const AffineTransform& transform,
  73076. const float extraAccuracy) const throw()
  73077. {
  73078. if (thickness <= 0)
  73079. return;
  73080. // this should really be an even number..
  73081. jassert ((numDashLengths & 1) == 0);
  73082. Path newDestPath;
  73083. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  73084. bool first = true;
  73085. int dashNum = 0;
  73086. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  73087. float dx = 0.0f, dy = 0.0f;
  73088. for (;;)
  73089. {
  73090. const bool isSolid = ((dashNum & 1) == 0);
  73091. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  73092. jassert (dashLen > 0); // must be a positive increment!
  73093. if (dashLen <= 0)
  73094. break;
  73095. pos += dashLen;
  73096. while (pos > lineEndPos)
  73097. {
  73098. if (! it.next())
  73099. {
  73100. if (isSolid && ! first)
  73101. newDestPath.lineTo (it.x2, it.y2);
  73102. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  73103. return;
  73104. }
  73105. if (isSolid && ! first)
  73106. newDestPath.lineTo (it.x1, it.y1);
  73107. else
  73108. newDestPath.startNewSubPath (it.x1, it.y1);
  73109. dx = it.x2 - it.x1;
  73110. dy = it.y2 - it.y1;
  73111. lineLen = juce_hypotf (dx, dy);
  73112. lineEndPos += lineLen;
  73113. first = it.closesSubPath;
  73114. }
  73115. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  73116. if (isSolid)
  73117. newDestPath.lineTo (it.x1 + dx * alpha,
  73118. it.y1 + dy * alpha);
  73119. else
  73120. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  73121. it.y1 + dy * alpha);
  73122. }
  73123. }
  73124. END_JUCE_NAMESPACE
  73125. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  73126. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  73127. BEGIN_JUCE_NAMESPACE
  73128. PositionedRectangle::PositionedRectangle() throw()
  73129. : x (0.0),
  73130. y (0.0),
  73131. w (0.0),
  73132. h (0.0),
  73133. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73134. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73135. wMode (absoluteSize),
  73136. hMode (absoluteSize)
  73137. {
  73138. }
  73139. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  73140. : x (other.x),
  73141. y (other.y),
  73142. w (other.w),
  73143. h (other.h),
  73144. xMode (other.xMode),
  73145. yMode (other.yMode),
  73146. wMode (other.wMode),
  73147. hMode (other.hMode)
  73148. {
  73149. }
  73150. const PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  73151. {
  73152. x = other.x;
  73153. y = other.y;
  73154. w = other.w;
  73155. h = other.h;
  73156. xMode = other.xMode;
  73157. yMode = other.yMode;
  73158. wMode = other.wMode;
  73159. hMode = other.hMode;
  73160. return *this;
  73161. }
  73162. PositionedRectangle::~PositionedRectangle() throw()
  73163. {
  73164. }
  73165. const bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  73166. {
  73167. return x == other.x
  73168. && y == other.y
  73169. && w == other.w
  73170. && h == other.h
  73171. && xMode == other.xMode
  73172. && yMode == other.yMode
  73173. && wMode == other.wMode
  73174. && hMode == other.hMode;
  73175. }
  73176. const bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  73177. {
  73178. return ! operator== (other);
  73179. }
  73180. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  73181. {
  73182. StringArray tokens;
  73183. tokens.addTokens (stringVersion, false);
  73184. decodePosString (tokens [0], xMode, x);
  73185. decodePosString (tokens [1], yMode, y);
  73186. decodeSizeString (tokens [2], wMode, w);
  73187. decodeSizeString (tokens [3], hMode, h);
  73188. }
  73189. const String PositionedRectangle::toString() const throw()
  73190. {
  73191. String s;
  73192. s.preallocateStorage (12);
  73193. addPosDescription (s, xMode, x);
  73194. s << T(' ');
  73195. addPosDescription (s, yMode, y);
  73196. s << T(' ');
  73197. addSizeDescription (s, wMode, w);
  73198. s << T(' ');
  73199. addSizeDescription (s, hMode, h);
  73200. return s;
  73201. }
  73202. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  73203. {
  73204. jassert (! target.isEmpty());
  73205. double x_, y_, w_, h_;
  73206. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73207. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73208. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  73209. roundToInt (w_), roundToInt (h_));
  73210. }
  73211. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  73212. double& x_, double& y_,
  73213. double& w_, double& h_) const throw()
  73214. {
  73215. jassert (! target.isEmpty());
  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. }
  73219. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  73220. {
  73221. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  73222. }
  73223. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  73224. const Rectangle<int>& target) throw()
  73225. {
  73226. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  73227. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  73228. }
  73229. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  73230. const double newW, const double newH,
  73231. const Rectangle<int>& target) throw()
  73232. {
  73233. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  73234. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  73235. }
  73236. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  73237. {
  73238. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  73239. updateFrom (comp.getBounds(), Rectangle<int>());
  73240. else
  73241. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  73242. }
  73243. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  73244. {
  73245. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73246. }
  73247. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  73248. {
  73249. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  73250. | absoluteFromParentBottomRight
  73251. | absoluteFromParentCentre
  73252. | proportionOfParentSize));
  73253. }
  73254. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  73255. {
  73256. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73257. }
  73258. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  73259. {
  73260. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  73261. | absoluteFromParentBottomRight
  73262. | absoluteFromParentCentre
  73263. | proportionOfParentSize));
  73264. }
  73265. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  73266. {
  73267. return (SizeMode) wMode;
  73268. }
  73269. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  73270. {
  73271. return (SizeMode) hMode;
  73272. }
  73273. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  73274. const PositionMode xMode_,
  73275. const AnchorPoint yAnchor,
  73276. const PositionMode yMode_,
  73277. const SizeMode widthMode,
  73278. const SizeMode heightMode,
  73279. const Rectangle<int>& target) throw()
  73280. {
  73281. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  73282. {
  73283. double tx, tw;
  73284. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  73285. xMode = (uint8) (xAnchor | xMode_);
  73286. wMode = (uint8) widthMode;
  73287. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  73288. }
  73289. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  73290. {
  73291. double ty, th;
  73292. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  73293. yMode = (uint8) (yAnchor | yMode_);
  73294. hMode = (uint8) heightMode;
  73295. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73296. }
  73297. }
  73298. bool PositionedRectangle::isPositionAbsolute() const throw()
  73299. {
  73300. return xMode == absoluteFromParentTopLeft
  73301. && yMode == absoluteFromParentTopLeft
  73302. && wMode == absoluteSize
  73303. && hMode == absoluteSize;
  73304. }
  73305. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73306. {
  73307. if ((mode & proportionOfParentSize) != 0)
  73308. {
  73309. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73310. }
  73311. else
  73312. {
  73313. s << (roundToInt (value * 100.0) / 100.0);
  73314. if ((mode & absoluteFromParentBottomRight) != 0)
  73315. s << T('R');
  73316. else if ((mode & absoluteFromParentCentre) != 0)
  73317. s << T('C');
  73318. }
  73319. if ((mode & anchorAtRightOrBottom) != 0)
  73320. s << T('r');
  73321. else if ((mode & anchorAtCentre) != 0)
  73322. s << T('c');
  73323. }
  73324. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73325. {
  73326. if (mode == proportionalSize)
  73327. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73328. else if (mode == parentSizeMinusAbsolute)
  73329. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73330. else
  73331. s << (roundToInt (value * 100.0) / 100.0);
  73332. }
  73333. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73334. {
  73335. if (s.containsChar (T('r')))
  73336. mode = anchorAtRightOrBottom;
  73337. else if (s.containsChar (T('c')))
  73338. mode = anchorAtCentre;
  73339. else
  73340. mode = anchorAtLeftOrTop;
  73341. if (s.containsChar (T('%')))
  73342. {
  73343. mode |= proportionOfParentSize;
  73344. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73345. }
  73346. else
  73347. {
  73348. if (s.containsChar (T('R')))
  73349. mode |= absoluteFromParentBottomRight;
  73350. else if (s.containsChar (T('C')))
  73351. mode |= absoluteFromParentCentre;
  73352. else
  73353. mode |= absoluteFromParentTopLeft;
  73354. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73355. }
  73356. }
  73357. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73358. {
  73359. if (s.containsChar (T('%')))
  73360. {
  73361. mode = proportionalSize;
  73362. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73363. }
  73364. else if (s.containsChar (T('M')))
  73365. {
  73366. mode = parentSizeMinusAbsolute;
  73367. value = s.getDoubleValue();
  73368. }
  73369. else
  73370. {
  73371. mode = absoluteSize;
  73372. value = s.getDoubleValue();
  73373. }
  73374. }
  73375. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73376. const double x_, const double w_,
  73377. const uint8 xMode_, const uint8 wMode_,
  73378. const int parentPos,
  73379. const int parentSize) const throw()
  73380. {
  73381. if (wMode_ == proportionalSize)
  73382. wOut = roundToInt (w_ * parentSize);
  73383. else if (wMode_ == parentSizeMinusAbsolute)
  73384. wOut = jmax (0, parentSize - roundToInt (w_));
  73385. else
  73386. wOut = roundToInt (w_);
  73387. if ((xMode_ & proportionOfParentSize) != 0)
  73388. xOut = parentPos + x_ * parentSize;
  73389. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73390. xOut = (parentPos + parentSize) - x_;
  73391. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73392. xOut = x_ + (parentPos + parentSize / 2);
  73393. else
  73394. xOut = x_ + parentPos;
  73395. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73396. xOut -= wOut;
  73397. else if ((xMode_ & anchorAtCentre) != 0)
  73398. xOut -= wOut / 2;
  73399. }
  73400. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73401. double x_, const double w_,
  73402. const uint8 xMode_, const uint8 wMode_,
  73403. const int parentPos,
  73404. const int parentSize) const throw()
  73405. {
  73406. if (wMode_ == proportionalSize)
  73407. {
  73408. if (parentSize > 0)
  73409. wOut = w_ / parentSize;
  73410. }
  73411. else if (wMode_ == parentSizeMinusAbsolute)
  73412. wOut = parentSize - w_;
  73413. else
  73414. wOut = w_;
  73415. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73416. x_ += w_;
  73417. else if ((xMode_ & anchorAtCentre) != 0)
  73418. x_ += w_ / 2;
  73419. if ((xMode_ & proportionOfParentSize) != 0)
  73420. {
  73421. if (parentSize > 0)
  73422. xOut = (x_ - parentPos) / parentSize;
  73423. }
  73424. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73425. xOut = (parentPos + parentSize) - x_;
  73426. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73427. xOut = x_ - (parentPos + parentSize / 2);
  73428. else
  73429. xOut = x_ - parentPos;
  73430. }
  73431. END_JUCE_NAMESPACE
  73432. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73433. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73434. BEGIN_JUCE_NAMESPACE
  73435. RectangleList::RectangleList() throw()
  73436. {
  73437. }
  73438. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73439. {
  73440. if (! rect.isEmpty())
  73441. rects.add (rect);
  73442. }
  73443. RectangleList::RectangleList (const RectangleList& other) throw()
  73444. : rects (other.rects)
  73445. {
  73446. }
  73447. const RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73448. {
  73449. rects = other.rects;
  73450. return *this;
  73451. }
  73452. RectangleList::~RectangleList() throw()
  73453. {
  73454. }
  73455. void RectangleList::clear() throw()
  73456. {
  73457. rects.clearQuick();
  73458. }
  73459. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73460. {
  73461. if (((unsigned int) index) < (unsigned int) rects.size())
  73462. return rects.getReference (index);
  73463. return Rectangle<int>();
  73464. }
  73465. bool RectangleList::isEmpty() const throw()
  73466. {
  73467. return rects.size() == 0;
  73468. }
  73469. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73470. : current (0),
  73471. owner (list),
  73472. index (list.rects.size())
  73473. {
  73474. }
  73475. RectangleList::Iterator::~Iterator() throw()
  73476. {
  73477. }
  73478. bool RectangleList::Iterator::next() throw()
  73479. {
  73480. if (--index >= 0)
  73481. {
  73482. current = & (owner.rects.getReference (index));
  73483. return true;
  73484. }
  73485. return false;
  73486. }
  73487. void RectangleList::add (const Rectangle<int>& rect) throw()
  73488. {
  73489. if (! rect.isEmpty())
  73490. {
  73491. if (rects.size() == 0)
  73492. {
  73493. rects.add (rect);
  73494. }
  73495. else
  73496. {
  73497. bool anyOverlaps = false;
  73498. int i;
  73499. for (i = rects.size(); --i >= 0;)
  73500. {
  73501. Rectangle<int>& ourRect = rects.getReference (i);
  73502. if (rect.intersects (ourRect))
  73503. {
  73504. if (rect.contains (ourRect))
  73505. rects.remove (i);
  73506. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73507. anyOverlaps = true;
  73508. }
  73509. }
  73510. if (anyOverlaps && rects.size() > 0)
  73511. {
  73512. RectangleList r (rect);
  73513. for (i = rects.size(); --i >= 0;)
  73514. {
  73515. const Rectangle<int>& ourRect = rects.getReference (i);
  73516. if (rect.intersects (ourRect))
  73517. {
  73518. r.subtract (ourRect);
  73519. if (r.rects.size() == 0)
  73520. return;
  73521. }
  73522. }
  73523. for (i = r.getNumRectangles(); --i >= 0;)
  73524. rects.add (r.rects.getReference (i));
  73525. }
  73526. else
  73527. {
  73528. rects.add (rect);
  73529. }
  73530. }
  73531. }
  73532. }
  73533. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73534. {
  73535. rects.add (rect);
  73536. }
  73537. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73538. {
  73539. if (rects.size() == 0)
  73540. {
  73541. if (w > 0 && h > 0)
  73542. rects.add (Rectangle<int> (x, y, w, h));
  73543. }
  73544. else
  73545. {
  73546. add (Rectangle<int> (x, y, w, h));
  73547. }
  73548. }
  73549. void RectangleList::add (const RectangleList& other) throw()
  73550. {
  73551. for (int i = 0; i < other.rects.size(); ++i)
  73552. add (other.rects.getReference (i));
  73553. }
  73554. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73555. {
  73556. const int originalNumRects = rects.size();
  73557. if (originalNumRects > 0)
  73558. {
  73559. const int x1 = rect.x;
  73560. const int y1 = rect.y;
  73561. const int x2 = x1 + rect.w;
  73562. const int y2 = y1 + rect.h;
  73563. for (int i = getNumRectangles(); --i >= 0;)
  73564. {
  73565. Rectangle<int>& r = rects.getReference (i);
  73566. const int rx1 = r.x;
  73567. const int ry1 = r.y;
  73568. const int rx2 = rx1 + r.w;
  73569. const int ry2 = ry1 + r.h;
  73570. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73571. {
  73572. if (x1 > rx1 && x1 < rx2)
  73573. {
  73574. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73575. {
  73576. r.w = x1 - rx1;
  73577. }
  73578. else
  73579. {
  73580. r.x = x1;
  73581. r.w = rx2 - x1;
  73582. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73583. i += 2;
  73584. }
  73585. }
  73586. else if (x2 > rx1 && x2 < rx2)
  73587. {
  73588. r.x = x2;
  73589. r.w = rx2 - x2;
  73590. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73591. {
  73592. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73593. i += 2;
  73594. }
  73595. }
  73596. else if (y1 > ry1 && y1 < ry2)
  73597. {
  73598. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73599. {
  73600. r.h = y1 - ry1;
  73601. }
  73602. else
  73603. {
  73604. r.y = y1;
  73605. r.h = ry2 - y1;
  73606. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73607. i += 2;
  73608. }
  73609. }
  73610. else if (y2 > ry1 && y2 < ry2)
  73611. {
  73612. r.y = y2;
  73613. r.h = ry2 - y2;
  73614. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73615. {
  73616. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73617. i += 2;
  73618. }
  73619. }
  73620. else
  73621. {
  73622. rects.remove (i);
  73623. }
  73624. }
  73625. }
  73626. if (rects.size() > originalNumRects + 10)
  73627. consolidate();
  73628. }
  73629. }
  73630. void RectangleList::subtract (const RectangleList& otherList) throw()
  73631. {
  73632. for (int i = otherList.rects.size(); --i >= 0;)
  73633. subtract (otherList.rects.getReference (i));
  73634. }
  73635. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73636. {
  73637. bool notEmpty = false;
  73638. if (rect.isEmpty())
  73639. {
  73640. clear();
  73641. }
  73642. else
  73643. {
  73644. for (int i = rects.size(); --i >= 0;)
  73645. {
  73646. Rectangle<int>& r = rects.getReference (i);
  73647. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73648. rects.remove (i);
  73649. else
  73650. notEmpty = true;
  73651. }
  73652. }
  73653. return notEmpty;
  73654. }
  73655. bool RectangleList::clipTo (const RectangleList& other) throw()
  73656. {
  73657. if (rects.size() == 0)
  73658. return false;
  73659. RectangleList result;
  73660. for (int j = 0; j < rects.size(); ++j)
  73661. {
  73662. const Rectangle<int>& rect = rects.getReference (j);
  73663. for (int i = other.rects.size(); --i >= 0;)
  73664. {
  73665. Rectangle<int> r (other.rects.getReference (i));
  73666. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73667. result.rects.add (r);
  73668. }
  73669. }
  73670. swapWith (result);
  73671. return ! isEmpty();
  73672. }
  73673. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73674. {
  73675. destRegion.clear();
  73676. if (! rect.isEmpty())
  73677. {
  73678. for (int i = rects.size(); --i >= 0;)
  73679. {
  73680. Rectangle<int> r (rects.getReference (i));
  73681. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73682. destRegion.rects.add (r);
  73683. }
  73684. }
  73685. return destRegion.rects.size() > 0;
  73686. }
  73687. void RectangleList::swapWith (RectangleList& otherList) throw()
  73688. {
  73689. rects.swapWithArray (otherList.rects);
  73690. }
  73691. void RectangleList::consolidate() throw()
  73692. {
  73693. int i;
  73694. for (i = 0; i < getNumRectangles() - 1; ++i)
  73695. {
  73696. Rectangle<int>& r = rects.getReference (i);
  73697. const int rx1 = r.x;
  73698. const int ry1 = r.y;
  73699. const int rx2 = rx1 + r.w;
  73700. const int ry2 = ry1 + r.h;
  73701. for (int j = rects.size(); --j > i;)
  73702. {
  73703. Rectangle<int>& r2 = rects.getReference (j);
  73704. const int jrx1 = r2.x;
  73705. const int jry1 = r2.y;
  73706. const int jrx2 = jrx1 + r2.w;
  73707. const int jry2 = jry1 + r2.h;
  73708. // if the vertical edges of any blocks are touching and their horizontals don't
  73709. // line up, split them horizontally..
  73710. if (jrx1 == rx2 || jrx2 == rx1)
  73711. {
  73712. if (jry1 > ry1 && jry1 < ry2)
  73713. {
  73714. r.h = jry1 - ry1;
  73715. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73716. i = -1;
  73717. break;
  73718. }
  73719. if (jry2 > ry1 && jry2 < ry2)
  73720. {
  73721. r.h = jry2 - ry1;
  73722. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73723. i = -1;
  73724. break;
  73725. }
  73726. else if (ry1 > jry1 && ry1 < jry2)
  73727. {
  73728. r2.h = ry1 - jry1;
  73729. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73730. i = -1;
  73731. break;
  73732. }
  73733. else if (ry2 > jry1 && ry2 < jry2)
  73734. {
  73735. r2.h = ry2 - jry1;
  73736. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73737. i = -1;
  73738. break;
  73739. }
  73740. }
  73741. }
  73742. }
  73743. for (i = 0; i < rects.size() - 1; ++i)
  73744. {
  73745. Rectangle<int>& r = rects.getReference (i);
  73746. for (int j = rects.size(); --j > i;)
  73747. {
  73748. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73749. {
  73750. rects.remove (j);
  73751. i = -1;
  73752. break;
  73753. }
  73754. }
  73755. }
  73756. }
  73757. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73758. {
  73759. for (int i = getNumRectangles(); --i >= 0;)
  73760. if (rects.getReference (i).contains (x, y))
  73761. return true;
  73762. return false;
  73763. }
  73764. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73765. {
  73766. if (rects.size() > 1)
  73767. {
  73768. RectangleList r (rectangleToCheck);
  73769. for (int i = rects.size(); --i >= 0;)
  73770. {
  73771. r.subtract (rects.getReference (i));
  73772. if (r.rects.size() == 0)
  73773. return true;
  73774. }
  73775. }
  73776. else if (rects.size() > 0)
  73777. {
  73778. return rects.getReference (0).contains (rectangleToCheck);
  73779. }
  73780. return false;
  73781. }
  73782. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73783. {
  73784. for (int i = rects.size(); --i >= 0;)
  73785. if (rects.getReference (i).intersects (rectangleToCheck))
  73786. return true;
  73787. return false;
  73788. }
  73789. bool RectangleList::intersects (const RectangleList& other) const throw()
  73790. {
  73791. for (int i = rects.size(); --i >= 0;)
  73792. if (other.intersectsRectangle (rects.getReference (i)))
  73793. return true;
  73794. return false;
  73795. }
  73796. const Rectangle<int> RectangleList::getBounds() const throw()
  73797. {
  73798. if (rects.size() <= 1)
  73799. {
  73800. if (rects.size() == 0)
  73801. return Rectangle<int>();
  73802. else
  73803. return rects.getReference (0);
  73804. }
  73805. else
  73806. {
  73807. const Rectangle<int>& r = rects.getReference (0);
  73808. int minX = r.x;
  73809. int minY = r.y;
  73810. int maxX = minX + r.w;
  73811. int maxY = minY + r.h;
  73812. for (int i = rects.size(); --i > 0;)
  73813. {
  73814. const Rectangle<int>& r2 = rects.getReference (i);
  73815. minX = jmin (minX, r2.x);
  73816. minY = jmin (minY, r2.y);
  73817. maxX = jmax (maxX, r2.getRight());
  73818. maxY = jmax (maxY, r2.getBottom());
  73819. }
  73820. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73821. }
  73822. }
  73823. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73824. {
  73825. for (int i = rects.size(); --i >= 0;)
  73826. {
  73827. Rectangle<int>& r = rects.getReference (i);
  73828. r.x += dx;
  73829. r.y += dy;
  73830. }
  73831. }
  73832. const Path RectangleList::toPath() const throw()
  73833. {
  73834. Path p;
  73835. for (int i = rects.size(); --i >= 0;)
  73836. {
  73837. const Rectangle<int>& r = rects.getReference (i);
  73838. p.addRectangle ((float) r.x,
  73839. (float) r.y,
  73840. (float) r.w,
  73841. (float) r.h);
  73842. }
  73843. return p;
  73844. }
  73845. END_JUCE_NAMESPACE
  73846. /*** End of inlined file: juce_RectangleList.cpp ***/
  73847. /*** Start of inlined file: juce_Image.cpp ***/
  73848. BEGIN_JUCE_NAMESPACE
  73849. static const int fullAlphaThreshold = 253;
  73850. Image::Image (const PixelFormat format_,
  73851. const int imageWidth_,
  73852. const int imageHeight_)
  73853. : format (format_),
  73854. imageWidth (imageWidth_),
  73855. imageHeight (imageHeight_),
  73856. imageData (0)
  73857. {
  73858. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73859. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73860. // actual image will be at least 1x1.
  73861. }
  73862. Image::Image (const PixelFormat format_,
  73863. const int imageWidth_,
  73864. const int imageHeight_,
  73865. const bool clearImage)
  73866. : format (format_),
  73867. imageWidth (imageWidth_),
  73868. imageHeight (imageHeight_)
  73869. {
  73870. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73871. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73872. // actual image will be at least 1x1.
  73873. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73874. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73875. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73876. imageData = imageDataAllocated;
  73877. }
  73878. Image::Image (const Image& other)
  73879. : format (other.format),
  73880. imageWidth (other.imageWidth),
  73881. imageHeight (other.imageHeight)
  73882. {
  73883. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73884. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73885. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73886. imageData = imageDataAllocated;
  73887. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73888. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73889. }
  73890. Image::~Image()
  73891. {
  73892. }
  73893. LowLevelGraphicsContext* Image::createLowLevelContext()
  73894. {
  73895. return new LowLevelGraphicsSoftwareRenderer (*this);
  73896. }
  73897. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73898. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73899. lineStride (image.lineStride),
  73900. pixelStride (image.pixelStride),
  73901. width (w),
  73902. height (h)
  73903. {
  73904. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73905. }
  73906. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73907. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73908. lineStride (image.lineStride),
  73909. pixelStride (image.pixelStride),
  73910. width (w),
  73911. height (h)
  73912. {
  73913. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73914. }
  73915. Image::BitmapData::~BitmapData()
  73916. {
  73917. }
  73918. void Image::setPixelData (int x, int y, int w, int h,
  73919. const uint8* sourcePixelData, int sourceLineStride)
  73920. {
  73921. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73922. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73923. {
  73924. const BitmapData dest (*this, x, y, w, h, true);
  73925. for (int i = 0; i < h; ++i)
  73926. {
  73927. memcpy (dest.getLinePointer(i),
  73928. sourcePixelData + sourceLineStride * i,
  73929. w * dest.pixelStride);
  73930. }
  73931. }
  73932. }
  73933. void Image::clear (int dx, int dy, int dw, int dh,
  73934. const Colour& colourToClearTo)
  73935. {
  73936. const PixelARGB col (colourToClearTo.getPixelARGB());
  73937. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73938. uint8* dest = destData.data;
  73939. while (--dh >= 0)
  73940. {
  73941. uint8* line = dest;
  73942. dest += destData.lineStride;
  73943. if (isARGB())
  73944. {
  73945. for (int x = dw; --x >= 0;)
  73946. {
  73947. ((PixelARGB*) line)->set (col);
  73948. line += destData.pixelStride;
  73949. }
  73950. }
  73951. else if (isRGB())
  73952. {
  73953. for (int x = dw; --x >= 0;)
  73954. {
  73955. ((PixelRGB*) line)->set (col);
  73956. line += destData.pixelStride;
  73957. }
  73958. }
  73959. else
  73960. {
  73961. for (int x = dw; --x >= 0;)
  73962. {
  73963. *line = col.getAlpha();
  73964. line += destData.pixelStride;
  73965. }
  73966. }
  73967. }
  73968. }
  73969. Image* Image::createCopy (int newWidth, int newHeight,
  73970. const Graphics::ResamplingQuality quality) const
  73971. {
  73972. if (newWidth < 0)
  73973. newWidth = imageWidth;
  73974. if (newHeight < 0)
  73975. newHeight = imageHeight;
  73976. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73977. Graphics g (*newImage);
  73978. g.setImageResamplingQuality (quality);
  73979. g.drawImage (this,
  73980. 0, 0, newWidth, newHeight,
  73981. 0, 0, imageWidth, imageHeight,
  73982. false);
  73983. return newImage;
  73984. }
  73985. Image* Image::createCopyOfAlphaChannel() const
  73986. {
  73987. jassert (format != SingleChannel);
  73988. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73989. if (! hasAlphaChannel())
  73990. {
  73991. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73992. }
  73993. else
  73994. {
  73995. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73996. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73997. for (int y = 0; y < imageHeight; ++y)
  73998. {
  73999. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  74000. uint8* dst = destData.getLinePointer (y);
  74001. for (int x = imageWidth; --x >= 0;)
  74002. {
  74003. *dst++ = src->getAlpha();
  74004. ++src;
  74005. }
  74006. }
  74007. }
  74008. return newImage;
  74009. }
  74010. const Colour Image::getPixelAt (const int x, const int y) const
  74011. {
  74012. Colour c;
  74013. if (((unsigned int) x) < (unsigned int) imageWidth
  74014. && ((unsigned int) y) < (unsigned int) imageHeight)
  74015. {
  74016. const BitmapData srcData (*this, x, y, 1, 1);
  74017. if (isARGB())
  74018. {
  74019. PixelARGB p (*(const PixelARGB*) srcData.data);
  74020. p.unpremultiply();
  74021. c = Colour (p.getARGB());
  74022. }
  74023. else if (isRGB())
  74024. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  74025. else
  74026. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  74027. }
  74028. return c;
  74029. }
  74030. void Image::setPixelAt (const int x, const int y,
  74031. const Colour& colour)
  74032. {
  74033. if (((unsigned int) x) < (unsigned int) imageWidth
  74034. && ((unsigned int) y) < (unsigned int) imageHeight)
  74035. {
  74036. const BitmapData destData (*this, x, y, 1, 1, true);
  74037. const PixelARGB col (colour.getPixelARGB());
  74038. if (isARGB())
  74039. ((PixelARGB*) destData.data)->set (col);
  74040. else if (isRGB())
  74041. ((PixelRGB*) destData.data)->set (col);
  74042. else
  74043. *(destData.data) = col.getAlpha();
  74044. }
  74045. }
  74046. void Image::multiplyAlphaAt (const int x, const int y,
  74047. const float multiplier)
  74048. {
  74049. if (((unsigned int) x) < (unsigned int) imageWidth
  74050. && ((unsigned int) y) < (unsigned int) imageHeight
  74051. && hasAlphaChannel())
  74052. {
  74053. const BitmapData destData (*this, x, y, 1, 1, true);
  74054. if (isARGB())
  74055. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  74056. else
  74057. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  74058. }
  74059. }
  74060. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  74061. {
  74062. if (hasAlphaChannel())
  74063. {
  74064. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74065. if (isARGB())
  74066. {
  74067. for (int y = 0; y < imageHeight; ++y)
  74068. {
  74069. uint8* p = destData.getLinePointer (y);
  74070. for (int x = 0; x < imageWidth; ++x)
  74071. {
  74072. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  74073. p += destData.pixelStride;
  74074. }
  74075. }
  74076. }
  74077. else
  74078. {
  74079. for (int y = 0; y < imageHeight; ++y)
  74080. {
  74081. uint8* p = destData.getLinePointer (y);
  74082. for (int x = 0; x < imageWidth; ++x)
  74083. {
  74084. *p = (uint8) (*p * amountToMultiplyBy);
  74085. p += destData.pixelStride;
  74086. }
  74087. }
  74088. }
  74089. }
  74090. else
  74091. {
  74092. jassertfalse // can't do this without an alpha-channel!
  74093. }
  74094. }
  74095. void Image::desaturate()
  74096. {
  74097. if (isARGB() || isRGB())
  74098. {
  74099. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74100. if (isARGB())
  74101. {
  74102. for (int y = 0; y < imageHeight; ++y)
  74103. {
  74104. uint8* p = destData.getLinePointer (y);
  74105. for (int x = 0; x < imageWidth; ++x)
  74106. {
  74107. ((PixelARGB*) p)->desaturate();
  74108. p += destData.pixelStride;
  74109. }
  74110. }
  74111. }
  74112. else
  74113. {
  74114. for (int y = 0; y < imageHeight; ++y)
  74115. {
  74116. uint8* p = destData.getLinePointer (y);
  74117. for (int x = 0; x < imageWidth; ++x)
  74118. {
  74119. ((PixelRGB*) p)->desaturate();
  74120. p += destData.pixelStride;
  74121. }
  74122. }
  74123. }
  74124. }
  74125. }
  74126. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  74127. {
  74128. if (hasAlphaChannel())
  74129. {
  74130. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  74131. SparseSet <int> pixelsOnRow;
  74132. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  74133. for (int y = 0; y < imageHeight; ++y)
  74134. {
  74135. pixelsOnRow.clear();
  74136. const uint8* lineData = srcData.getLinePointer (y);
  74137. if (isARGB())
  74138. {
  74139. for (int x = 0; x < imageWidth; ++x)
  74140. {
  74141. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  74142. pixelsOnRow.addRange (x, 1);
  74143. lineData += srcData.pixelStride;
  74144. }
  74145. }
  74146. else
  74147. {
  74148. for (int x = 0; x < imageWidth; ++x)
  74149. {
  74150. if (*lineData >= threshold)
  74151. pixelsOnRow.addRange (x, 1);
  74152. lineData += srcData.pixelStride;
  74153. }
  74154. }
  74155. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  74156. {
  74157. int x, w;
  74158. if (pixelsOnRow.getRange (i, x, w))
  74159. result.add (Rectangle<int> (x, y, w, 1));
  74160. }
  74161. result.consolidate();
  74162. }
  74163. }
  74164. else
  74165. {
  74166. result.add (0, 0, imageWidth, imageHeight);
  74167. }
  74168. }
  74169. void Image::moveImageSection (int dx, int dy,
  74170. int sx, int sy,
  74171. int w, int h)
  74172. {
  74173. if (dx < 0)
  74174. {
  74175. w += dx;
  74176. sx -= dx;
  74177. dx = 0;
  74178. }
  74179. if (dy < 0)
  74180. {
  74181. h += dy;
  74182. sy -= dy;
  74183. dy = 0;
  74184. }
  74185. if (sx < 0)
  74186. {
  74187. w += sx;
  74188. dx -= sx;
  74189. sx = 0;
  74190. }
  74191. if (sy < 0)
  74192. {
  74193. h += sy;
  74194. dy -= sy;
  74195. sy = 0;
  74196. }
  74197. const int minX = jmin (dx, sx);
  74198. const int minY = jmin (dy, sy);
  74199. w = jmin (w, getWidth() - jmax (sx, dx));
  74200. h = jmin (h, getHeight() - jmax (sy, dy));
  74201. if (w > 0 && h > 0)
  74202. {
  74203. const int maxX = jmax (dx, sx) + w;
  74204. const int maxY = jmax (dy, sy) + h;
  74205. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  74206. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  74207. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  74208. const int lineSize = destData.pixelStride * w;
  74209. if (dy > sy)
  74210. {
  74211. while (--h >= 0)
  74212. {
  74213. const int offset = h * destData.lineStride;
  74214. memmove (dst + offset, src + offset, lineSize);
  74215. }
  74216. }
  74217. else if (dst != src)
  74218. {
  74219. while (--h >= 0)
  74220. {
  74221. memmove (dst, src, lineSize);
  74222. dst += destData.lineStride;
  74223. src += destData.lineStride;
  74224. }
  74225. }
  74226. }
  74227. }
  74228. END_JUCE_NAMESPACE
  74229. /*** End of inlined file: juce_Image.cpp ***/
  74230. /*** Start of inlined file: juce_ImageCache.cpp ***/
  74231. BEGIN_JUCE_NAMESPACE
  74232. struct ImageCacheItem
  74233. {
  74234. ScopedPointer <Image> image;
  74235. int64 hashCode;
  74236. int refCount;
  74237. uint32 releaseTime;
  74238. juce_UseDebuggingNewOperator
  74239. };
  74240. static ImageCache* instance = 0;
  74241. static int cacheTimeout = 5000;
  74242. ImageCache::ImageCache()
  74243. {
  74244. }
  74245. ImageCache::~ImageCache()
  74246. {
  74247. jassert (instance == this);
  74248. instance = 0;
  74249. }
  74250. Image* ImageCache::getFromHashCode (const int64 hashCode)
  74251. {
  74252. if (instance != 0)
  74253. {
  74254. const ScopedLock sl (instance->lock);
  74255. for (int i = instance->images.size(); --i >= 0;)
  74256. {
  74257. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74258. if (ci->hashCode == hashCode)
  74259. {
  74260. ci->refCount++;
  74261. return ci->image;
  74262. }
  74263. }
  74264. }
  74265. return 0;
  74266. }
  74267. void ImageCache::addImageToCache (Image* const image,
  74268. const int64 hashCode)
  74269. {
  74270. if (image != 0)
  74271. {
  74272. if (instance == 0)
  74273. instance = new ImageCache();
  74274. ImageCacheItem* const newC = new ImageCacheItem();
  74275. newC->hashCode = hashCode;
  74276. newC->image = image;
  74277. newC->refCount = 1;
  74278. newC->releaseTime = 0;
  74279. const ScopedLock sl (instance->lock);
  74280. instance->images.add (newC);
  74281. }
  74282. }
  74283. void ImageCache::release (Image* const imageToRelease)
  74284. {
  74285. if (imageToRelease != 0 && instance != 0)
  74286. {
  74287. const ScopedLock sl (instance->lock);
  74288. for (int i = instance->images.size(); --i >= 0;)
  74289. {
  74290. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74291. if ((Image*) ci->image == imageToRelease)
  74292. {
  74293. if (--(ci->refCount) == 0)
  74294. ci->releaseTime = Time::getApproximateMillisecondCounter();
  74295. if (! instance->isTimerRunning())
  74296. instance->startTimer (999);
  74297. break;
  74298. }
  74299. }
  74300. }
  74301. }
  74302. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74303. {
  74304. if (isImageInCache (imageToRelease))
  74305. release (imageToRelease);
  74306. else
  74307. delete imageToRelease;
  74308. }
  74309. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74310. {
  74311. if (instance != 0)
  74312. {
  74313. const ScopedLock sl (instance->lock);
  74314. for (int i = instance->images.size(); --i >= 0;)
  74315. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74316. return true;
  74317. }
  74318. return false;
  74319. }
  74320. void ImageCache::incReferenceCount (Image* const image)
  74321. {
  74322. if (instance != 0)
  74323. {
  74324. const ScopedLock sl (instance->lock);
  74325. for (int i = instance->images.size(); --i >= 0;)
  74326. {
  74327. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74328. if ((Image*) ci->image == image)
  74329. {
  74330. ci->refCount++;
  74331. return;
  74332. }
  74333. }
  74334. }
  74335. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74336. }
  74337. void ImageCache::timerCallback()
  74338. {
  74339. int numberStillNeedingReleasing = 0;
  74340. const unsigned int now = Time::getApproximateMillisecondCounter();
  74341. const ScopedLock sl (lock);
  74342. for (int i = images.size(); --i >= 0;)
  74343. {
  74344. ImageCacheItem* const ci = images.getUnchecked(i);
  74345. if (ci->refCount <= 0)
  74346. {
  74347. if (now > ci->releaseTime + cacheTimeout
  74348. || now < ci->releaseTime - 1000)
  74349. {
  74350. images.remove (i);
  74351. }
  74352. else
  74353. {
  74354. ++numberStillNeedingReleasing;
  74355. }
  74356. }
  74357. }
  74358. if (numberStillNeedingReleasing == 0)
  74359. stopTimer();
  74360. }
  74361. Image* ImageCache::getFromFile (const File& file)
  74362. {
  74363. const int64 hashCode = file.hashCode64();
  74364. Image* image = getFromHashCode (hashCode);
  74365. if (image == 0)
  74366. {
  74367. image = ImageFileFormat::loadFrom (file);
  74368. addImageToCache (image, hashCode);
  74369. }
  74370. return image;
  74371. }
  74372. Image* ImageCache::getFromMemory (const void* imageData,
  74373. const int dataSize)
  74374. {
  74375. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74376. Image* image = getFromHashCode (hashCode);
  74377. if (image == 0)
  74378. {
  74379. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74380. addImageToCache (image, hashCode);
  74381. }
  74382. return image;
  74383. }
  74384. void ImageCache::setCacheTimeout (const int millisecs)
  74385. {
  74386. cacheTimeout = millisecs;
  74387. }
  74388. END_JUCE_NAMESPACE
  74389. /*** End of inlined file: juce_ImageCache.cpp ***/
  74390. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74391. BEGIN_JUCE_NAMESPACE
  74392. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74393. : values (size_ * size_),
  74394. size (size_)
  74395. {
  74396. clear();
  74397. }
  74398. ImageConvolutionKernel::~ImageConvolutionKernel()
  74399. {
  74400. }
  74401. void ImageConvolutionKernel::setKernelValue (const int x,
  74402. const int y,
  74403. const float value)
  74404. {
  74405. if (((unsigned int) x) < (unsigned int) size
  74406. && ((unsigned int) y) < (unsigned int) size)
  74407. {
  74408. values [x + y * size] = value;
  74409. }
  74410. else
  74411. {
  74412. jassertfalse
  74413. }
  74414. }
  74415. void ImageConvolutionKernel::clear()
  74416. {
  74417. for (int i = size * size; --i >= 0;)
  74418. values[i] = 0;
  74419. }
  74420. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74421. {
  74422. double currentTotal = 0.0;
  74423. for (int i = size * size; --i >= 0;)
  74424. currentTotal += values[i];
  74425. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74426. }
  74427. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74428. {
  74429. for (int i = size * size; --i >= 0;)
  74430. values[i] *= multiplier;
  74431. }
  74432. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74433. {
  74434. const double radiusFactor = -1.0 / (radius * radius * 2);
  74435. const int centre = size >> 1;
  74436. for (int y = size; --y >= 0;)
  74437. {
  74438. for (int x = size; --x >= 0;)
  74439. {
  74440. const int cx = x - centre;
  74441. const int cy = y - centre;
  74442. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74443. }
  74444. }
  74445. setOverallSum (1.0f);
  74446. }
  74447. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74448. const Image* sourceImage,
  74449. int dx,
  74450. int dy,
  74451. int dw,
  74452. int dh) const
  74453. {
  74454. ScopedPointer <Image> imageCreated;
  74455. if (sourceImage == 0)
  74456. {
  74457. sourceImage = imageCreated = destImage.createCopy();
  74458. }
  74459. else
  74460. {
  74461. jassert (sourceImage->getWidth() == destImage.getWidth()
  74462. && sourceImage->getHeight() == destImage.getHeight()
  74463. && sourceImage->getFormat() == destImage.getFormat());
  74464. if (sourceImage->getWidth() != destImage.getWidth()
  74465. || sourceImage->getHeight() != destImage.getHeight()
  74466. || sourceImage->getFormat() != destImage.getFormat())
  74467. return;
  74468. }
  74469. const int imageWidth = destImage.getWidth();
  74470. const int imageHeight = destImage.getHeight();
  74471. if (dx >= imageWidth || dy >= imageHeight)
  74472. return;
  74473. if (dx + dw > imageWidth)
  74474. dw = imageWidth - dx;
  74475. if (dy + dh > imageHeight)
  74476. dh = imageHeight - dy;
  74477. const int dx2 = dx + dw;
  74478. const int dy2 = dy + dh;
  74479. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74480. uint8* line = destData.data;
  74481. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74482. if (destData.pixelStride == 4)
  74483. {
  74484. for (int y = dy; y < dy2; ++y)
  74485. {
  74486. uint8* dest = line;
  74487. line += destData.lineStride;
  74488. for (int x = dx; x < dx2; ++x)
  74489. {
  74490. float c1 = 0;
  74491. float c2 = 0;
  74492. float c3 = 0;
  74493. float c4 = 0;
  74494. for (int yy = 0; yy < size; ++yy)
  74495. {
  74496. const int sy = y + yy - (size >> 1);
  74497. if (sy >= imageHeight)
  74498. break;
  74499. if (sy >= 0)
  74500. {
  74501. int sx = x - (size >> 1);
  74502. const uint8* src = srcData.getPixelPointer (sx, sy);
  74503. for (int xx = 0; xx < size; ++xx)
  74504. {
  74505. if (sx >= imageWidth)
  74506. break;
  74507. if (sx >= 0)
  74508. {
  74509. const float kernelMult = values [xx + yy * size];
  74510. c1 += kernelMult * *src++;
  74511. c2 += kernelMult * *src++;
  74512. c3 += kernelMult * *src++;
  74513. c4 += kernelMult * *src++;
  74514. }
  74515. else
  74516. {
  74517. src += 4;
  74518. }
  74519. ++sx;
  74520. }
  74521. }
  74522. }
  74523. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74524. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74525. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74526. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74527. }
  74528. }
  74529. }
  74530. else if (destData.pixelStride == 3)
  74531. {
  74532. for (int y = dy; y < dy2; ++y)
  74533. {
  74534. uint8* dest = line;
  74535. line += destData.lineStride;
  74536. for (int x = dx; x < dx2; ++x)
  74537. {
  74538. float c1 = 0;
  74539. float c2 = 0;
  74540. float c3 = 0;
  74541. for (int yy = 0; yy < size; ++yy)
  74542. {
  74543. const int sy = y + yy - (size >> 1);
  74544. if (sy >= imageHeight)
  74545. break;
  74546. if (sy >= 0)
  74547. {
  74548. int sx = x - (size >> 1);
  74549. const uint8* src = srcData.getPixelPointer (sx, sy);
  74550. for (int xx = 0; xx < size; ++xx)
  74551. {
  74552. if (sx >= imageWidth)
  74553. break;
  74554. if (sx >= 0)
  74555. {
  74556. const float kernelMult = values [xx + yy * size];
  74557. c1 += kernelMult * *src++;
  74558. c2 += kernelMult * *src++;
  74559. c3 += kernelMult * *src++;
  74560. }
  74561. else
  74562. {
  74563. src += 3;
  74564. }
  74565. ++sx;
  74566. }
  74567. }
  74568. }
  74569. *dest++ = (uint8) roundToInt (c1);
  74570. *dest++ = (uint8) roundToInt (c2);
  74571. *dest++ = (uint8) roundToInt (c3);
  74572. }
  74573. }
  74574. }
  74575. }
  74576. END_JUCE_NAMESPACE
  74577. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74578. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74579. BEGIN_JUCE_NAMESPACE
  74580. /*** Start of inlined file: juce_GIFLoader.h ***/
  74581. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74582. #define __JUCE_GIFLOADER_JUCEHEADER__
  74583. #ifndef DOXYGEN
  74584. class GIFLoader
  74585. {
  74586. public:
  74587. GIFLoader (InputStream& in);
  74588. ~GIFLoader();
  74589. Image* getImage() const { return image; }
  74590. private:
  74591. Image* image;
  74592. InputStream& input;
  74593. uint8 buffer [300];
  74594. uint8 palette [256][4];
  74595. bool dataBlockIsZero, fresh, finished;
  74596. int currentBit, lastBit, lastByteIndex;
  74597. int codeSize, setCodeSize;
  74598. int maxCode, maxCodeSize;
  74599. int firstcode, oldcode;
  74600. int clearCode, end_code;
  74601. enum { maxGifCode = 1 << 12 };
  74602. int table [2] [maxGifCode];
  74603. int stack [2 * maxGifCode];
  74604. int *sp;
  74605. bool getSizeFromHeader (int& width, int& height);
  74606. bool readPalette (const int numCols);
  74607. int readDataBlock (unsigned char* dest);
  74608. int processExtension (int type, int& transparent);
  74609. int readLZWByte (bool initialise, int input_code_size);
  74610. int getCode (int code_size, bool initialise);
  74611. bool readImage (int width, int height, int interlace, int transparent);
  74612. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74613. GIFLoader (const GIFLoader&);
  74614. const GIFLoader& operator= (const GIFLoader&);
  74615. };
  74616. #endif // DOXYGEN
  74617. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74618. /*** End of inlined file: juce_GIFLoader.h ***/
  74619. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74620. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74621. PNGImageFormat::PNGImageFormat() {}
  74622. PNGImageFormat::~PNGImageFormat() {}
  74623. const String PNGImageFormat::getFormatName()
  74624. {
  74625. return T("PNG");
  74626. }
  74627. bool PNGImageFormat::canUnderstand (InputStream& in)
  74628. {
  74629. const int bytesNeeded = 4;
  74630. char header [bytesNeeded];
  74631. return in.read (header, bytesNeeded) == bytesNeeded
  74632. && header[1] == 'P'
  74633. && header[2] == 'N'
  74634. && header[3] == 'G';
  74635. }
  74636. Image* PNGImageFormat::decodeImage (InputStream& in)
  74637. {
  74638. return juce_loadPNGImageFromStream (in);
  74639. }
  74640. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74641. OutputStream& destStream)
  74642. {
  74643. return juce_writePNGImageToStream (sourceImage, destStream);
  74644. }
  74645. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74646. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74647. JPEGImageFormat::JPEGImageFormat()
  74648. : quality (-1.0f)
  74649. {
  74650. }
  74651. JPEGImageFormat::~JPEGImageFormat() {}
  74652. void JPEGImageFormat::setQuality (const float newQuality)
  74653. {
  74654. quality = newQuality;
  74655. }
  74656. const String JPEGImageFormat::getFormatName()
  74657. {
  74658. return T("JPEG");
  74659. }
  74660. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74661. {
  74662. const int bytesNeeded = 10;
  74663. uint8 header [bytesNeeded];
  74664. if (in.read (header, bytesNeeded) == bytesNeeded)
  74665. {
  74666. return header[0] == 0xff
  74667. && header[1] == 0xd8
  74668. && header[2] == 0xff
  74669. && (header[3] == 0xe0 || header[3] == 0xe1);
  74670. }
  74671. return false;
  74672. }
  74673. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74674. {
  74675. return juce_loadJPEGImageFromStream (in);
  74676. }
  74677. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74678. OutputStream& destStream)
  74679. {
  74680. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74681. }
  74682. class GIFImageFormat : public ImageFileFormat
  74683. {
  74684. public:
  74685. GIFImageFormat() {}
  74686. ~GIFImageFormat() {}
  74687. const String getFormatName()
  74688. {
  74689. return T("GIF");
  74690. }
  74691. bool canUnderstand (InputStream& in)
  74692. {
  74693. const int bytesNeeded = 4;
  74694. char header [bytesNeeded];
  74695. return (in.read (header, bytesNeeded) == bytesNeeded)
  74696. && header[0] == 'G'
  74697. && header[1] == 'I'
  74698. && header[2] == 'F';
  74699. }
  74700. Image* decodeImage (InputStream& in)
  74701. {
  74702. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74703. return loader->getImage();
  74704. }
  74705. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74706. {
  74707. return false;
  74708. }
  74709. };
  74710. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74711. {
  74712. static PNGImageFormat png;
  74713. static JPEGImageFormat jpg;
  74714. static GIFImageFormat gif;
  74715. ImageFileFormat* formats[4];
  74716. int numFormats = 0;
  74717. formats [numFormats++] = &png;
  74718. formats [numFormats++] = &jpg;
  74719. formats [numFormats++] = &gif;
  74720. const int64 streamPos = input.getPosition();
  74721. for (int i = 0; i < numFormats; ++i)
  74722. {
  74723. const bool found = formats[i]->canUnderstand (input);
  74724. input.setPosition (streamPos);
  74725. if (found)
  74726. return formats[i];
  74727. }
  74728. return 0;
  74729. }
  74730. Image* ImageFileFormat::loadFrom (InputStream& input)
  74731. {
  74732. ImageFileFormat* const format = findImageFormatForStream (input);
  74733. if (format != 0)
  74734. return format->decodeImage (input);
  74735. return 0;
  74736. }
  74737. Image* ImageFileFormat::loadFrom (const File& file)
  74738. {
  74739. InputStream* const in = file.createInputStream();
  74740. if (in != 0)
  74741. {
  74742. BufferedInputStream b (in, 8192, true);
  74743. return loadFrom (b);
  74744. }
  74745. return 0;
  74746. }
  74747. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74748. {
  74749. if (rawData != 0 && numBytes > 4)
  74750. {
  74751. MemoryInputStream stream (rawData, numBytes, false);
  74752. return loadFrom (stream);
  74753. }
  74754. return 0;
  74755. }
  74756. END_JUCE_NAMESPACE
  74757. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74758. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74759. BEGIN_JUCE_NAMESPACE
  74760. GIFLoader::GIFLoader (InputStream& in)
  74761. : image (0),
  74762. input (in),
  74763. dataBlockIsZero (false),
  74764. fresh (false),
  74765. finished (false)
  74766. {
  74767. currentBit = lastBit = lastByteIndex = 0;
  74768. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74769. firstcode = oldcode = 0;
  74770. clearCode = end_code = 0;
  74771. int imageWidth, imageHeight;
  74772. int transparent = -1;
  74773. if (! getSizeFromHeader (imageWidth, imageHeight))
  74774. return;
  74775. if ((imageWidth <= 0) || (imageHeight <= 0))
  74776. return;
  74777. unsigned char buf [16];
  74778. if (in.read (buf, 3) != 3)
  74779. return;
  74780. int numColours = 2 << (buf[0] & 7);
  74781. if ((buf[0] & 0x80) != 0)
  74782. readPalette (numColours);
  74783. for (;;)
  74784. {
  74785. if (input.read (buf, 1) != 1)
  74786. break;
  74787. if (buf[0] == ';')
  74788. break;
  74789. if (buf[0] == '!')
  74790. {
  74791. if (input.read (buf, 1) != 1)
  74792. break;
  74793. if (processExtension (buf[0], transparent) < 0)
  74794. break;
  74795. continue;
  74796. }
  74797. if (buf[0] != ',')
  74798. continue;
  74799. if (input.read (buf, 9) != 9)
  74800. break;
  74801. imageWidth = makeWord (buf[4], buf[5]);
  74802. imageHeight = makeWord (buf[6], buf[7]);
  74803. numColours = 2 << (buf[8] & 7);
  74804. if ((buf[8] & 0x80) != 0)
  74805. if (! readPalette (numColours))
  74806. break;
  74807. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74808. imageWidth, imageHeight, (transparent >= 0));
  74809. readImage (imageWidth, imageHeight,
  74810. (buf[8] & 0x40) != 0,
  74811. transparent);
  74812. break;
  74813. }
  74814. }
  74815. GIFLoader::~GIFLoader()
  74816. {
  74817. }
  74818. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74819. {
  74820. unsigned char b [8];
  74821. if (input.read (b, 6) == 6)
  74822. {
  74823. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74824. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74825. {
  74826. if (input.read (b, 4) == 4)
  74827. {
  74828. w = makeWord (b[0], b[1]);
  74829. h = makeWord (b[2], b[3]);
  74830. return true;
  74831. }
  74832. }
  74833. }
  74834. return false;
  74835. }
  74836. bool GIFLoader::readPalette (const int numCols)
  74837. {
  74838. unsigned char rgb[4];
  74839. for (int i = 0; i < numCols; ++i)
  74840. {
  74841. input.read (rgb, 3);
  74842. palette [i][0] = rgb[0];
  74843. palette [i][1] = rgb[1];
  74844. palette [i][2] = rgb[2];
  74845. palette [i][3] = 0xff;
  74846. }
  74847. return true;
  74848. }
  74849. int GIFLoader::readDataBlock (unsigned char* const dest)
  74850. {
  74851. unsigned char n;
  74852. if (input.read (&n, 1) == 1)
  74853. {
  74854. dataBlockIsZero = (n == 0);
  74855. if (dataBlockIsZero || (input.read (dest, n) == n))
  74856. return n;
  74857. }
  74858. return -1;
  74859. }
  74860. int GIFLoader::processExtension (const int type, int& transparent)
  74861. {
  74862. unsigned char b [300];
  74863. int n = 0;
  74864. if (type == 0xf9)
  74865. {
  74866. n = readDataBlock (b);
  74867. if (n < 0)
  74868. return 1;
  74869. if ((b[0] & 0x1) != 0)
  74870. transparent = b[3];
  74871. }
  74872. do
  74873. {
  74874. n = readDataBlock (b);
  74875. }
  74876. while (n > 0);
  74877. return n;
  74878. }
  74879. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74880. {
  74881. if (initialise)
  74882. {
  74883. currentBit = 0;
  74884. lastBit = 0;
  74885. finished = false;
  74886. return 0;
  74887. }
  74888. if ((currentBit + codeSize_) >= lastBit)
  74889. {
  74890. if (finished)
  74891. return -1;
  74892. buffer[0] = buffer [lastByteIndex - 2];
  74893. buffer[1] = buffer [lastByteIndex - 1];
  74894. const int n = readDataBlock (&buffer[2]);
  74895. if (n == 0)
  74896. finished = true;
  74897. lastByteIndex = 2 + n;
  74898. currentBit = (currentBit - lastBit) + 16;
  74899. lastBit = (2 + n) * 8 ;
  74900. }
  74901. int result = 0;
  74902. int i = currentBit;
  74903. for (int j = 0; j < codeSize_; ++j)
  74904. {
  74905. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74906. ++i;
  74907. }
  74908. currentBit += codeSize_;
  74909. return result;
  74910. }
  74911. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74912. {
  74913. int code, incode, i;
  74914. if (initialise)
  74915. {
  74916. setCodeSize = inputCodeSize;
  74917. codeSize = setCodeSize + 1;
  74918. clearCode = 1 << setCodeSize;
  74919. end_code = clearCode + 1;
  74920. maxCodeSize = 2 * clearCode;
  74921. maxCode = clearCode + 2;
  74922. getCode (0, true);
  74923. fresh = true;
  74924. for (i = 0; i < clearCode; ++i)
  74925. {
  74926. table[0][i] = 0;
  74927. table[1][i] = i;
  74928. }
  74929. for (; i < maxGifCode; ++i)
  74930. {
  74931. table[0][i] = 0;
  74932. table[1][i] = 0;
  74933. }
  74934. sp = stack;
  74935. return 0;
  74936. }
  74937. else if (fresh)
  74938. {
  74939. fresh = false;
  74940. do
  74941. {
  74942. firstcode = oldcode
  74943. = getCode (codeSize, false);
  74944. }
  74945. while (firstcode == clearCode);
  74946. return firstcode;
  74947. }
  74948. if (sp > stack)
  74949. return *--sp;
  74950. while ((code = getCode (codeSize, false)) >= 0)
  74951. {
  74952. if (code == clearCode)
  74953. {
  74954. for (i = 0; i < clearCode; ++i)
  74955. {
  74956. table[0][i] = 0;
  74957. table[1][i] = i;
  74958. }
  74959. for (; i < maxGifCode; ++i)
  74960. {
  74961. table[0][i] = 0;
  74962. table[1][i] = 0;
  74963. }
  74964. codeSize = setCodeSize + 1;
  74965. maxCodeSize = 2 * clearCode;
  74966. maxCode = clearCode + 2;
  74967. sp = stack;
  74968. firstcode = oldcode = getCode (codeSize, false);
  74969. return firstcode;
  74970. }
  74971. else if (code == end_code)
  74972. {
  74973. if (dataBlockIsZero)
  74974. return -2;
  74975. unsigned char buf [260];
  74976. int n;
  74977. while ((n = readDataBlock (buf)) > 0)
  74978. {}
  74979. if (n != 0)
  74980. return -2;
  74981. }
  74982. incode = code;
  74983. if (code >= maxCode)
  74984. {
  74985. *sp++ = firstcode;
  74986. code = oldcode;
  74987. }
  74988. while (code >= clearCode)
  74989. {
  74990. *sp++ = table[1][code];
  74991. if (code == table[0][code])
  74992. return -2;
  74993. code = table[0][code];
  74994. }
  74995. *sp++ = firstcode = table[1][code];
  74996. if ((code = maxCode) < maxGifCode)
  74997. {
  74998. table[0][code] = oldcode;
  74999. table[1][code] = firstcode;
  75000. ++maxCode;
  75001. if ((maxCode >= maxCodeSize)
  75002. && (maxCodeSize < maxGifCode))
  75003. {
  75004. maxCodeSize <<= 1;
  75005. ++codeSize;
  75006. }
  75007. }
  75008. oldcode = incode;
  75009. if (sp > stack)
  75010. return *--sp;
  75011. }
  75012. return code;
  75013. }
  75014. bool GIFLoader::readImage (const int width, const int height,
  75015. const int interlace, const int transparent)
  75016. {
  75017. unsigned char c;
  75018. if (input.read (&c, 1) != 1
  75019. || readLZWByte (true, c) < 0)
  75020. return false;
  75021. if (transparent >= 0)
  75022. {
  75023. palette [transparent][0] = 0;
  75024. palette [transparent][1] = 0;
  75025. palette [transparent][2] = 0;
  75026. palette [transparent][3] = 0;
  75027. }
  75028. int index;
  75029. int xpos = 0, ypos = 0, pass = 0;
  75030. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  75031. uint8* p = destData.data;
  75032. const bool hasAlpha = image->hasAlphaChannel();
  75033. while ((index = readLZWByte (false, c)) >= 0)
  75034. {
  75035. const uint8* const paletteEntry = palette [index];
  75036. if (hasAlpha)
  75037. {
  75038. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  75039. paletteEntry[0],
  75040. paletteEntry[1],
  75041. paletteEntry[2]);
  75042. ((PixelARGB*) p)->premultiply();
  75043. }
  75044. else
  75045. {
  75046. ((PixelRGB*) p)->setARGB (0,
  75047. paletteEntry[0],
  75048. paletteEntry[1],
  75049. paletteEntry[2]);
  75050. }
  75051. p += destData.pixelStride;
  75052. ++xpos;
  75053. if (xpos == width)
  75054. {
  75055. xpos = 0;
  75056. if (interlace)
  75057. {
  75058. switch (pass)
  75059. {
  75060. case 0:
  75061. case 1:
  75062. ypos += 8;
  75063. break;
  75064. case 2:
  75065. ypos += 4;
  75066. break;
  75067. case 3:
  75068. ypos += 2;
  75069. break;
  75070. }
  75071. while (ypos >= height)
  75072. {
  75073. ++pass;
  75074. switch (pass)
  75075. {
  75076. case 1:
  75077. ypos = 4;
  75078. break;
  75079. case 2:
  75080. ypos = 2;
  75081. break;
  75082. case 3:
  75083. ypos = 1;
  75084. break;
  75085. default:
  75086. return true;
  75087. }
  75088. }
  75089. }
  75090. else
  75091. {
  75092. ++ypos;
  75093. }
  75094. p = destData.getPixelPointer (xpos, ypos);
  75095. }
  75096. if (ypos >= height)
  75097. break;
  75098. }
  75099. return true;
  75100. }
  75101. END_JUCE_NAMESPACE
  75102. /*** End of inlined file: juce_GIFLoader.cpp ***/
  75103. #endif
  75104. //==============================================================================
  75105. // some files include lots of library code, so leave them to the end to avoid cluttering
  75106. // up the build for the clean files.
  75107. #if JUCE_BUILD_CORE
  75108. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75109. namespace zlibNamespace
  75110. {
  75111. #if JUCE_INCLUDE_ZLIB_CODE
  75112. #undef OS_CODE
  75113. #undef fdopen
  75114. /*** Start of inlined file: zlib.h ***/
  75115. #ifndef ZLIB_H
  75116. #define ZLIB_H
  75117. /*** Start of inlined file: zconf.h ***/
  75118. #ifndef ZCONF_H
  75119. #define ZCONF_H
  75120. // *** Just a few hacks here to make it compile nicely with Juce..
  75121. #define Z_PREFIX 1
  75122. #undef __MACTYPES__
  75123. #ifdef _MSC_VER
  75124. #pragma warning (disable : 4131 4127 4244 4267)
  75125. #endif
  75126. #ifdef Z_PREFIX
  75127. # define deflateInit_ z_deflateInit_
  75128. # define deflate z_deflate
  75129. # define deflateEnd z_deflateEnd
  75130. # define inflateInit_ z_inflateInit_
  75131. # define inflate z_inflate
  75132. # define inflateEnd z_inflateEnd
  75133. # define deflateInit2_ z_deflateInit2_
  75134. # define deflateSetDictionary z_deflateSetDictionary
  75135. # define deflateCopy z_deflateCopy
  75136. # define deflateReset z_deflateReset
  75137. # define deflateParams z_deflateParams
  75138. # define deflateBound z_deflateBound
  75139. # define deflatePrime z_deflatePrime
  75140. # define inflateInit2_ z_inflateInit2_
  75141. # define inflateSetDictionary z_inflateSetDictionary
  75142. # define inflateSync z_inflateSync
  75143. # define inflateSyncPoint z_inflateSyncPoint
  75144. # define inflateCopy z_inflateCopy
  75145. # define inflateReset z_inflateReset
  75146. # define inflateBack z_inflateBack
  75147. # define inflateBackEnd z_inflateBackEnd
  75148. # define compress z_compress
  75149. # define compress2 z_compress2
  75150. # define compressBound z_compressBound
  75151. # define uncompress z_uncompress
  75152. # define adler32 z_adler32
  75153. # define crc32 z_crc32
  75154. # define get_crc_table z_get_crc_table
  75155. # define zError z_zError
  75156. # define alloc_func z_alloc_func
  75157. # define free_func z_free_func
  75158. # define in_func z_in_func
  75159. # define out_func z_out_func
  75160. # define Byte z_Byte
  75161. # define uInt z_uInt
  75162. # define uLong z_uLong
  75163. # define Bytef z_Bytef
  75164. # define charf z_charf
  75165. # define intf z_intf
  75166. # define uIntf z_uIntf
  75167. # define uLongf z_uLongf
  75168. # define voidpf z_voidpf
  75169. # define voidp z_voidp
  75170. #endif
  75171. #if defined(__MSDOS__) && !defined(MSDOS)
  75172. # define MSDOS
  75173. #endif
  75174. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  75175. # define OS2
  75176. #endif
  75177. #if defined(_WINDOWS) && !defined(WINDOWS)
  75178. # define WINDOWS
  75179. #endif
  75180. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  75181. # ifndef WIN32
  75182. # define WIN32
  75183. # endif
  75184. #endif
  75185. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  75186. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  75187. # ifndef SYS16BIT
  75188. # define SYS16BIT
  75189. # endif
  75190. # endif
  75191. #endif
  75192. #ifdef SYS16BIT
  75193. # define MAXSEG_64K
  75194. #endif
  75195. #ifdef MSDOS
  75196. # define UNALIGNED_OK
  75197. #endif
  75198. #ifdef __STDC_VERSION__
  75199. # ifndef STDC
  75200. # define STDC
  75201. # endif
  75202. # if __STDC_VERSION__ >= 199901L
  75203. # ifndef STDC99
  75204. # define STDC99
  75205. # endif
  75206. # endif
  75207. #endif
  75208. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  75209. # define STDC
  75210. #endif
  75211. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  75212. # define STDC
  75213. #endif
  75214. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  75215. # define STDC
  75216. #endif
  75217. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  75218. # define STDC
  75219. #endif
  75220. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  75221. # define STDC
  75222. #endif
  75223. #ifndef STDC
  75224. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  75225. # define const /* note: need a more gentle solution here */
  75226. # endif
  75227. #endif
  75228. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  75229. # define NO_DUMMY_DECL
  75230. #endif
  75231. #ifndef MAX_MEM_LEVEL
  75232. # ifdef MAXSEG_64K
  75233. # define MAX_MEM_LEVEL 8
  75234. # else
  75235. # define MAX_MEM_LEVEL 9
  75236. # endif
  75237. #endif
  75238. #ifndef MAX_WBITS
  75239. # define MAX_WBITS 15 /* 32K LZ77 window */
  75240. #endif
  75241. #ifndef OF /* function prototypes */
  75242. # ifdef STDC
  75243. # define OF(args) args
  75244. # else
  75245. # define OF(args) ()
  75246. # endif
  75247. #endif
  75248. #ifdef SYS16BIT
  75249. # if defined(M_I86SM) || defined(M_I86MM)
  75250. # define SMALL_MEDIUM
  75251. # ifdef _MSC_VER
  75252. # define FAR _far
  75253. # else
  75254. # define FAR far
  75255. # endif
  75256. # endif
  75257. # if (defined(__SMALL__) || defined(__MEDIUM__))
  75258. # define SMALL_MEDIUM
  75259. # ifdef __BORLANDC__
  75260. # define FAR _far
  75261. # else
  75262. # define FAR far
  75263. # endif
  75264. # endif
  75265. #endif
  75266. #if defined(WINDOWS) || defined(WIN32)
  75267. # ifdef ZLIB_DLL
  75268. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  75269. # ifdef ZLIB_INTERNAL
  75270. # define ZEXTERN extern __declspec(dllexport)
  75271. # else
  75272. # define ZEXTERN extern __declspec(dllimport)
  75273. # endif
  75274. # endif
  75275. # endif /* ZLIB_DLL */
  75276. # ifdef ZLIB_WINAPI
  75277. # ifdef FAR
  75278. # undef FAR
  75279. # endif
  75280. # include <windows.h>
  75281. # define ZEXPORT WINAPI
  75282. # ifdef WIN32
  75283. # define ZEXPORTVA WINAPIV
  75284. # else
  75285. # define ZEXPORTVA FAR CDECL
  75286. # endif
  75287. # endif
  75288. #endif
  75289. #if defined (__BEOS__)
  75290. # ifdef ZLIB_DLL
  75291. # ifdef ZLIB_INTERNAL
  75292. # define ZEXPORT __declspec(dllexport)
  75293. # define ZEXPORTVA __declspec(dllexport)
  75294. # else
  75295. # define ZEXPORT __declspec(dllimport)
  75296. # define ZEXPORTVA __declspec(dllimport)
  75297. # endif
  75298. # endif
  75299. #endif
  75300. #ifndef ZEXTERN
  75301. # define ZEXTERN extern
  75302. #endif
  75303. #ifndef ZEXPORT
  75304. # define ZEXPORT
  75305. #endif
  75306. #ifndef ZEXPORTVA
  75307. # define ZEXPORTVA
  75308. #endif
  75309. #ifndef FAR
  75310. # define FAR
  75311. #endif
  75312. #if !defined(__MACTYPES__)
  75313. typedef unsigned char Byte; /* 8 bits */
  75314. #endif
  75315. typedef unsigned int uInt; /* 16 bits or more */
  75316. typedef unsigned long uLong; /* 32 bits or more */
  75317. #ifdef SMALL_MEDIUM
  75318. # define Bytef Byte FAR
  75319. #else
  75320. typedef Byte FAR Bytef;
  75321. #endif
  75322. typedef char FAR charf;
  75323. typedef int FAR intf;
  75324. typedef uInt FAR uIntf;
  75325. typedef uLong FAR uLongf;
  75326. #ifdef STDC
  75327. typedef void const *voidpc;
  75328. typedef void FAR *voidpf;
  75329. typedef void *voidp;
  75330. #else
  75331. typedef Byte const *voidpc;
  75332. typedef Byte FAR *voidpf;
  75333. typedef Byte *voidp;
  75334. #endif
  75335. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75336. # include <sys/types.h> /* for off_t */
  75337. # include <unistd.h> /* for SEEK_* and off_t */
  75338. # ifdef VMS
  75339. # include <unixio.h> /* for off_t */
  75340. # endif
  75341. # define z_off_t off_t
  75342. #endif
  75343. #ifndef SEEK_SET
  75344. # define SEEK_SET 0 /* Seek from beginning of file. */
  75345. # define SEEK_CUR 1 /* Seek from current position. */
  75346. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75347. #endif
  75348. #ifndef z_off_t
  75349. # define z_off_t long
  75350. #endif
  75351. #if defined(__OS400__)
  75352. # define NO_vsnprintf
  75353. #endif
  75354. #if defined(__MVS__)
  75355. # define NO_vsnprintf
  75356. # ifdef FAR
  75357. # undef FAR
  75358. # endif
  75359. #endif
  75360. #if defined(__MVS__)
  75361. # pragma map(deflateInit_,"DEIN")
  75362. # pragma map(deflateInit2_,"DEIN2")
  75363. # pragma map(deflateEnd,"DEEND")
  75364. # pragma map(deflateBound,"DEBND")
  75365. # pragma map(inflateInit_,"ININ")
  75366. # pragma map(inflateInit2_,"ININ2")
  75367. # pragma map(inflateEnd,"INEND")
  75368. # pragma map(inflateSync,"INSY")
  75369. # pragma map(inflateSetDictionary,"INSEDI")
  75370. # pragma map(compressBound,"CMBND")
  75371. # pragma map(inflate_table,"INTABL")
  75372. # pragma map(inflate_fast,"INFA")
  75373. # pragma map(inflate_copyright,"INCOPY")
  75374. #endif
  75375. #endif /* ZCONF_H */
  75376. /*** End of inlined file: zconf.h ***/
  75377. #ifdef __cplusplus
  75378. extern "C" {
  75379. #endif
  75380. #define ZLIB_VERSION "1.2.3"
  75381. #define ZLIB_VERNUM 0x1230
  75382. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75383. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75384. struct internal_state;
  75385. typedef struct z_stream_s {
  75386. Bytef *next_in; /* next input byte */
  75387. uInt avail_in; /* number of bytes available at next_in */
  75388. uLong total_in; /* total nb of input bytes read so far */
  75389. Bytef *next_out; /* next output byte should be put there */
  75390. uInt avail_out; /* remaining free space at next_out */
  75391. uLong total_out; /* total nb of bytes output so far */
  75392. char *msg; /* last error message, NULL if no error */
  75393. struct internal_state FAR *state; /* not visible by applications */
  75394. alloc_func zalloc; /* used to allocate the internal state */
  75395. free_func zfree; /* used to free the internal state */
  75396. voidpf opaque; /* private data object passed to zalloc and zfree */
  75397. int data_type; /* best guess about the data type: binary or text */
  75398. uLong adler; /* adler32 value of the uncompressed data */
  75399. uLong reserved; /* reserved for future use */
  75400. } z_stream;
  75401. typedef z_stream FAR *z_streamp;
  75402. typedef struct gz_header_s {
  75403. int text; /* true if compressed data believed to be text */
  75404. uLong time; /* modification time */
  75405. int xflags; /* extra flags (not used when writing a gzip file) */
  75406. int os; /* operating system */
  75407. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75408. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75409. uInt extra_max; /* space at extra (only when reading header) */
  75410. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75411. uInt name_max; /* space at name (only when reading header) */
  75412. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75413. uInt comm_max; /* space at comment (only when reading header) */
  75414. int hcrc; /* true if there was or will be a header crc */
  75415. int done; /* true when done reading gzip header (not used
  75416. when writing a gzip file) */
  75417. } gz_header;
  75418. typedef gz_header FAR *gz_headerp;
  75419. #define Z_NO_FLUSH 0
  75420. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75421. #define Z_SYNC_FLUSH 2
  75422. #define Z_FULL_FLUSH 3
  75423. #define Z_FINISH 4
  75424. #define Z_BLOCK 5
  75425. #define Z_OK 0
  75426. #define Z_STREAM_END 1
  75427. #define Z_NEED_DICT 2
  75428. #define Z_ERRNO (-1)
  75429. #define Z_STREAM_ERROR (-2)
  75430. #define Z_DATA_ERROR (-3)
  75431. #define Z_MEM_ERROR (-4)
  75432. #define Z_BUF_ERROR (-5)
  75433. #define Z_VERSION_ERROR (-6)
  75434. #define Z_NO_COMPRESSION 0
  75435. #define Z_BEST_SPEED 1
  75436. #define Z_BEST_COMPRESSION 9
  75437. #define Z_DEFAULT_COMPRESSION (-1)
  75438. #define Z_FILTERED 1
  75439. #define Z_HUFFMAN_ONLY 2
  75440. #define Z_RLE 3
  75441. #define Z_FIXED 4
  75442. #define Z_DEFAULT_STRATEGY 0
  75443. #define Z_BINARY 0
  75444. #define Z_TEXT 1
  75445. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75446. #define Z_UNKNOWN 2
  75447. #define Z_DEFLATED 8
  75448. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75449. #define zlib_version zlibVersion()
  75450. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75451. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75452. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75453. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75454. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75455. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75456. const Bytef *dictionary,
  75457. uInt dictLength));
  75458. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75459. z_streamp source));
  75460. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75461. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75462. int level,
  75463. int strategy));
  75464. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75465. int good_length,
  75466. int max_lazy,
  75467. int nice_length,
  75468. int max_chain));
  75469. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75470. uLong sourceLen));
  75471. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75472. int bits,
  75473. int value));
  75474. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75475. gz_headerp head));
  75476. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75477. const Bytef *dictionary,
  75478. uInt dictLength));
  75479. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75480. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75481. z_streamp source));
  75482. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75483. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75484. int bits,
  75485. int value));
  75486. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75487. gz_headerp head));
  75488. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75489. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75490. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75491. in_func in, void FAR *in_desc,
  75492. out_func out, void FAR *out_desc));
  75493. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75494. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75495. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75496. const Bytef *source, uLong sourceLen));
  75497. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75498. const Bytef *source, uLong sourceLen,
  75499. int level));
  75500. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75501. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75502. const Bytef *source, uLong sourceLen));
  75503. typedef voidp gzFile;
  75504. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75505. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75506. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75507. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75508. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75509. voidpc buf, unsigned len));
  75510. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75511. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75512. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75513. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75514. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75515. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75516. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75517. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75518. z_off_t offset, int whence));
  75519. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75520. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75521. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75522. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75523. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75524. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75525. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75526. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75527. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75528. z_off_t len2));
  75529. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75530. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75531. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75532. const char *version, int stream_size));
  75533. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75534. const char *version, int stream_size));
  75535. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75536. int windowBits, int memLevel,
  75537. int strategy, const char *version,
  75538. int stream_size));
  75539. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75540. const char *version, int stream_size));
  75541. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75542. unsigned char FAR *window,
  75543. const char *version,
  75544. int stream_size));
  75545. #define deflateInit(strm, level) \
  75546. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75547. #define inflateInit(strm) \
  75548. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75549. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75550. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75551. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75552. #define inflateInit2(strm, windowBits) \
  75553. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75554. #define inflateBackInit(strm, windowBits, window) \
  75555. inflateBackInit_((strm), (windowBits), (window), \
  75556. ZLIB_VERSION, sizeof(z_stream))
  75557. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75558. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75559. #endif
  75560. ZEXTERN const char * ZEXPORT zError OF((int));
  75561. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75562. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75563. #ifdef __cplusplus
  75564. }
  75565. #endif
  75566. #endif /* ZLIB_H */
  75567. /*** End of inlined file: zlib.h ***/
  75568. #undef OS_CODE
  75569. #else
  75570. #include <zlib.h>
  75571. #endif
  75572. }
  75573. BEGIN_JUCE_NAMESPACE
  75574. using namespace zlibNamespace;
  75575. // internal helper object that holds the zlib structures so they don't have to be
  75576. // included publicly.
  75577. class GZIPCompressorHelper
  75578. {
  75579. public:
  75580. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75581. : data (0),
  75582. dataSize (0),
  75583. compLevel (compressionLevel),
  75584. strategy (0),
  75585. setParams (true),
  75586. streamIsValid (false),
  75587. finished (false),
  75588. shouldFinish (false)
  75589. {
  75590. zerostruct (stream);
  75591. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75592. nowrap ? -MAX_WBITS : MAX_WBITS,
  75593. 8, strategy) == Z_OK);
  75594. }
  75595. ~GZIPCompressorHelper()
  75596. {
  75597. if (streamIsValid)
  75598. deflateEnd (&stream);
  75599. }
  75600. bool needsInput() const throw()
  75601. {
  75602. return dataSize <= 0;
  75603. }
  75604. void setInput (uint8* const newData, const int size) throw()
  75605. {
  75606. data = newData;
  75607. dataSize = size;
  75608. }
  75609. int doNextBlock (uint8* const dest, const int destSize) throw()
  75610. {
  75611. if (streamIsValid)
  75612. {
  75613. stream.next_in = data;
  75614. stream.next_out = dest;
  75615. stream.avail_in = dataSize;
  75616. stream.avail_out = destSize;
  75617. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75618. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75619. setParams = false;
  75620. switch (result)
  75621. {
  75622. case Z_STREAM_END:
  75623. finished = true;
  75624. // Deliberate fall-through..
  75625. case Z_OK:
  75626. data += dataSize - stream.avail_in;
  75627. dataSize = stream.avail_in;
  75628. return destSize - stream.avail_out;
  75629. default:
  75630. break;
  75631. }
  75632. }
  75633. return 0;
  75634. }
  75635. private:
  75636. z_stream stream;
  75637. uint8* data;
  75638. int dataSize, compLevel, strategy;
  75639. bool setParams, streamIsValid;
  75640. public:
  75641. bool finished, shouldFinish;
  75642. };
  75643. const int gzipCompBufferSize = 32768;
  75644. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75645. int compressionLevel,
  75646. const bool deleteDestStream,
  75647. const bool noWrap)
  75648. : destStream (destStream_),
  75649. streamToDelete (deleteDestStream ? destStream_ : 0),
  75650. buffer (gzipCompBufferSize)
  75651. {
  75652. if (compressionLevel < 1 || compressionLevel > 9)
  75653. compressionLevel = -1;
  75654. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75655. }
  75656. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75657. {
  75658. flush();
  75659. }
  75660. void GZIPCompressorOutputStream::flush()
  75661. {
  75662. if (! helper->finished)
  75663. {
  75664. helper->shouldFinish = true;
  75665. while (! helper->finished)
  75666. doNextBlock();
  75667. }
  75668. destStream->flush();
  75669. }
  75670. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75671. {
  75672. if (! helper->finished)
  75673. {
  75674. helper->setInput ((uint8*) destBuffer, howMany);
  75675. while (! helper->needsInput())
  75676. {
  75677. if (! doNextBlock())
  75678. return false;
  75679. }
  75680. }
  75681. return true;
  75682. }
  75683. bool GZIPCompressorOutputStream::doNextBlock()
  75684. {
  75685. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75686. if (len > 0)
  75687. return destStream->write (buffer, len);
  75688. else
  75689. return true;
  75690. }
  75691. int64 GZIPCompressorOutputStream::getPosition()
  75692. {
  75693. return destStream->getPosition();
  75694. }
  75695. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75696. {
  75697. jassertfalse // can't do it!
  75698. return false;
  75699. }
  75700. END_JUCE_NAMESPACE
  75701. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75702. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75703. #if JUCE_MSVC
  75704. #pragma warning (push)
  75705. #pragma warning (disable: 4309 4305)
  75706. #endif
  75707. namespace zlibNamespace
  75708. {
  75709. #if JUCE_INCLUDE_ZLIB_CODE
  75710. extern "C"
  75711. {
  75712. #undef OS_CODE
  75713. #undef fdopen
  75714. #define ZLIB_INTERNAL
  75715. #define NO_DUMMY_DECL
  75716. /*** Start of inlined file: adler32.c ***/
  75717. #define ZLIB_INTERNAL
  75718. #define BASE 65521UL /* largest prime smaller than 65536 */
  75719. #define NMAX 5552
  75720. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75721. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75722. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75723. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75724. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75725. #ifdef NO_DIVIDE
  75726. # define MOD(a) \
  75727. do { \
  75728. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75729. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75730. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75731. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75732. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75733. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75734. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75735. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75736. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75737. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75738. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75739. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75740. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75741. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75742. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75743. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75744. if (a >= BASE) a -= BASE; \
  75745. } while (0)
  75746. # define MOD4(a) \
  75747. do { \
  75748. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75749. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75750. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75751. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75752. if (a >= BASE) a -= BASE; \
  75753. } while (0)
  75754. #else
  75755. # define MOD(a) a %= BASE
  75756. # define MOD4(a) a %= BASE
  75757. #endif
  75758. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75759. {
  75760. unsigned long sum2;
  75761. unsigned n;
  75762. sum2 = (adler >> 16) & 0xffff;
  75763. adler &= 0xffff;
  75764. if (len == 1) {
  75765. adler += buf[0];
  75766. if (adler >= BASE)
  75767. adler -= BASE;
  75768. sum2 += adler;
  75769. if (sum2 >= BASE)
  75770. sum2 -= BASE;
  75771. return adler | (sum2 << 16);
  75772. }
  75773. if (buf == Z_NULL)
  75774. return 1L;
  75775. if (len < 16) {
  75776. while (len--) {
  75777. adler += *buf++;
  75778. sum2 += adler;
  75779. }
  75780. if (adler >= BASE)
  75781. adler -= BASE;
  75782. MOD4(sum2); /* only added so many BASE's */
  75783. return adler | (sum2 << 16);
  75784. }
  75785. while (len >= NMAX) {
  75786. len -= NMAX;
  75787. n = NMAX / 16; /* NMAX is divisible by 16 */
  75788. do {
  75789. DO16(buf); /* 16 sums unrolled */
  75790. buf += 16;
  75791. } while (--n);
  75792. MOD(adler);
  75793. MOD(sum2);
  75794. }
  75795. if (len) { /* avoid modulos if none remaining */
  75796. while (len >= 16) {
  75797. len -= 16;
  75798. DO16(buf);
  75799. buf += 16;
  75800. }
  75801. while (len--) {
  75802. adler += *buf++;
  75803. sum2 += adler;
  75804. }
  75805. MOD(adler);
  75806. MOD(sum2);
  75807. }
  75808. return adler | (sum2 << 16);
  75809. }
  75810. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75811. {
  75812. unsigned long sum1;
  75813. unsigned long sum2;
  75814. unsigned rem;
  75815. rem = (unsigned)(len2 % BASE);
  75816. sum1 = adler1 & 0xffff;
  75817. sum2 = rem * sum1;
  75818. MOD(sum2);
  75819. sum1 += (adler2 & 0xffff) + BASE - 1;
  75820. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75821. if (sum1 > BASE) sum1 -= BASE;
  75822. if (sum1 > BASE) sum1 -= BASE;
  75823. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75824. if (sum2 > BASE) sum2 -= BASE;
  75825. return sum1 | (sum2 << 16);
  75826. }
  75827. /*** End of inlined file: adler32.c ***/
  75828. /*** Start of inlined file: compress.c ***/
  75829. #define ZLIB_INTERNAL
  75830. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75831. uLong sourceLen, int level)
  75832. {
  75833. z_stream stream;
  75834. int err;
  75835. stream.next_in = (Bytef*)source;
  75836. stream.avail_in = (uInt)sourceLen;
  75837. #ifdef MAXSEG_64K
  75838. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75839. #endif
  75840. stream.next_out = dest;
  75841. stream.avail_out = (uInt)*destLen;
  75842. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75843. stream.zalloc = (alloc_func)0;
  75844. stream.zfree = (free_func)0;
  75845. stream.opaque = (voidpf)0;
  75846. err = deflateInit(&stream, level);
  75847. if (err != Z_OK) return err;
  75848. err = deflate(&stream, Z_FINISH);
  75849. if (err != Z_STREAM_END) {
  75850. deflateEnd(&stream);
  75851. return err == Z_OK ? Z_BUF_ERROR : err;
  75852. }
  75853. *destLen = stream.total_out;
  75854. err = deflateEnd(&stream);
  75855. return err;
  75856. }
  75857. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75858. {
  75859. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75860. }
  75861. uLong ZEXPORT compressBound (uLong sourceLen)
  75862. {
  75863. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75864. }
  75865. /*** End of inlined file: compress.c ***/
  75866. #undef DO1
  75867. #undef DO8
  75868. /*** Start of inlined file: crc32.c ***/
  75869. #ifdef MAKECRCH
  75870. # include <stdio.h>
  75871. # ifndef DYNAMIC_CRC_TABLE
  75872. # define DYNAMIC_CRC_TABLE
  75873. # endif /* !DYNAMIC_CRC_TABLE */
  75874. #endif /* MAKECRCH */
  75875. /*** Start of inlined file: zutil.h ***/
  75876. #ifndef ZUTIL_H
  75877. #define ZUTIL_H
  75878. #define ZLIB_INTERNAL
  75879. #ifdef STDC
  75880. # ifndef _WIN32_WCE
  75881. # include <stddef.h>
  75882. # endif
  75883. # include <string.h>
  75884. # include <stdlib.h>
  75885. #endif
  75886. #ifdef NO_ERRNO_H
  75887. # ifdef _WIN32_WCE
  75888. # define errno z_errno
  75889. # endif
  75890. extern int errno;
  75891. #else
  75892. # ifndef _WIN32_WCE
  75893. # include <errno.h>
  75894. # endif
  75895. #endif
  75896. #ifndef local
  75897. # define local static
  75898. #endif
  75899. typedef unsigned char uch;
  75900. typedef uch FAR uchf;
  75901. typedef unsigned short ush;
  75902. typedef ush FAR ushf;
  75903. typedef unsigned long ulg;
  75904. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75905. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75906. #define ERR_RETURN(strm,err) \
  75907. return (strm->msg = (char*)ERR_MSG(err), (err))
  75908. #ifndef DEF_WBITS
  75909. # define DEF_WBITS MAX_WBITS
  75910. #endif
  75911. #if MAX_MEM_LEVEL >= 8
  75912. # define DEF_MEM_LEVEL 8
  75913. #else
  75914. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75915. #endif
  75916. #define STORED_BLOCK 0
  75917. #define STATIC_TREES 1
  75918. #define DYN_TREES 2
  75919. #define MIN_MATCH 3
  75920. #define MAX_MATCH 258
  75921. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75922. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75923. # define OS_CODE 0x00
  75924. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75925. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75926. void _Cdecl farfree( void *block );
  75927. void *_Cdecl farmalloc( unsigned long nbytes );
  75928. # else
  75929. # include <alloc.h>
  75930. # endif
  75931. # else /* MSC or DJGPP */
  75932. # include <malloc.h>
  75933. # endif
  75934. #endif
  75935. #ifdef AMIGA
  75936. # define OS_CODE 0x01
  75937. #endif
  75938. #if defined(VAXC) || defined(VMS)
  75939. # define OS_CODE 0x02
  75940. # define F_OPEN(name, mode) \
  75941. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75942. #endif
  75943. #if defined(ATARI) || defined(atarist)
  75944. # define OS_CODE 0x05
  75945. #endif
  75946. #ifdef OS2
  75947. # define OS_CODE 0x06
  75948. # ifdef M_I86
  75949. #include <malloc.h>
  75950. # endif
  75951. #endif
  75952. #if defined(MACOS) || TARGET_OS_MAC
  75953. # define OS_CODE 0x07
  75954. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75955. # include <unix.h> /* for fdopen */
  75956. # else
  75957. # ifndef fdopen
  75958. # define fdopen(fd,mode) NULL /* No fdopen() */
  75959. # endif
  75960. # endif
  75961. #endif
  75962. #ifdef TOPS20
  75963. # define OS_CODE 0x0a
  75964. #endif
  75965. #ifdef WIN32
  75966. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75967. # define OS_CODE 0x0b
  75968. # endif
  75969. #endif
  75970. #ifdef __50SERIES /* Prime/PRIMOS */
  75971. # define OS_CODE 0x0f
  75972. #endif
  75973. #if defined(_BEOS_) || defined(RISCOS)
  75974. # define fdopen(fd,mode) NULL /* No fdopen() */
  75975. #endif
  75976. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75977. # if defined(_WIN32_WCE)
  75978. # define fdopen(fd,mode) NULL /* No fdopen() */
  75979. # ifndef _PTRDIFF_T_DEFINED
  75980. typedef int ptrdiff_t;
  75981. # define _PTRDIFF_T_DEFINED
  75982. # endif
  75983. # else
  75984. # define fdopen(fd,type) _fdopen(fd,type)
  75985. # endif
  75986. #endif
  75987. #ifndef OS_CODE
  75988. # define OS_CODE 0x03 /* assume Unix */
  75989. #endif
  75990. #ifndef F_OPEN
  75991. # define F_OPEN(name, mode) fopen((name), (mode))
  75992. #endif
  75993. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75994. # ifndef HAVE_VSNPRINTF
  75995. # define HAVE_VSNPRINTF
  75996. # endif
  75997. #endif
  75998. #if defined(__CYGWIN__)
  75999. # ifndef HAVE_VSNPRINTF
  76000. # define HAVE_VSNPRINTF
  76001. # endif
  76002. #endif
  76003. #ifndef HAVE_VSNPRINTF
  76004. # ifdef MSDOS
  76005. # define NO_vsnprintf
  76006. # endif
  76007. # ifdef __TURBOC__
  76008. # define NO_vsnprintf
  76009. # endif
  76010. # ifdef WIN32
  76011. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  76012. # define vsnprintf _vsnprintf
  76013. # endif
  76014. # endif
  76015. # ifdef __SASC
  76016. # define NO_vsnprintf
  76017. # endif
  76018. #endif
  76019. #ifdef VMS
  76020. # define NO_vsnprintf
  76021. #endif
  76022. #if defined(pyr)
  76023. # define NO_MEMCPY
  76024. #endif
  76025. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  76026. # define NO_MEMCPY
  76027. #endif
  76028. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  76029. # define HAVE_MEMCPY
  76030. #endif
  76031. #ifdef HAVE_MEMCPY
  76032. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  76033. # define zmemcpy _fmemcpy
  76034. # define zmemcmp _fmemcmp
  76035. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  76036. # else
  76037. # define zmemcpy memcpy
  76038. # define zmemcmp memcmp
  76039. # define zmemzero(dest, len) memset(dest, 0, len)
  76040. # endif
  76041. #else
  76042. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  76043. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  76044. extern void zmemzero OF((Bytef* dest, uInt len));
  76045. #endif
  76046. #ifdef DEBUG
  76047. # include <stdio.h>
  76048. extern int z_verbose;
  76049. extern void z_error OF((const char *m));
  76050. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  76051. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  76052. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  76053. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  76054. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  76055. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  76056. #else
  76057. # define Assert(cond,msg)
  76058. # define Trace(x)
  76059. # define Tracev(x)
  76060. # define Tracevv(x)
  76061. # define Tracec(c,x)
  76062. # define Tracecv(c,x)
  76063. #endif
  76064. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  76065. void zcfree OF((voidpf opaque, voidpf ptr));
  76066. #define ZALLOC(strm, items, size) \
  76067. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  76068. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  76069. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  76070. #endif /* ZUTIL_H */
  76071. /*** End of inlined file: zutil.h ***/
  76072. /* for STDC and FAR definitions */
  76073. #define local static
  76074. #ifndef NOBYFOUR
  76075. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  76076. # include <limits.h>
  76077. # define BYFOUR
  76078. # if (UINT_MAX == 0xffffffffUL)
  76079. typedef unsigned int u4;
  76080. # else
  76081. # if (ULONG_MAX == 0xffffffffUL)
  76082. typedef unsigned long u4;
  76083. # else
  76084. # if (USHRT_MAX == 0xffffffffUL)
  76085. typedef unsigned short u4;
  76086. # else
  76087. # undef BYFOUR /* can't find a four-byte integer type! */
  76088. # endif
  76089. # endif
  76090. # endif
  76091. # endif /* STDC */
  76092. #endif /* !NOBYFOUR */
  76093. #ifdef BYFOUR
  76094. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  76095. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  76096. local unsigned long crc32_little OF((unsigned long,
  76097. const unsigned char FAR *, unsigned));
  76098. local unsigned long crc32_big OF((unsigned long,
  76099. const unsigned char FAR *, unsigned));
  76100. # define TBLS 8
  76101. #else
  76102. # define TBLS 1
  76103. #endif /* BYFOUR */
  76104. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  76105. unsigned long vec));
  76106. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  76107. #ifdef DYNAMIC_CRC_TABLE
  76108. local volatile int crc_table_empty = 1;
  76109. local unsigned long FAR crc_table[TBLS][256];
  76110. local void make_crc_table OF((void));
  76111. #ifdef MAKECRCH
  76112. local void write_table OF((FILE *, const unsigned long FAR *));
  76113. #endif /* MAKECRCH */
  76114. local void make_crc_table()
  76115. {
  76116. unsigned long c;
  76117. int n, k;
  76118. unsigned long poly; /* polynomial exclusive-or pattern */
  76119. static volatile int first = 1; /* flag to limit concurrent making */
  76120. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  76121. if (first) {
  76122. first = 0;
  76123. poly = 0UL;
  76124. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  76125. poly |= 1UL << (31 - p[n]);
  76126. for (n = 0; n < 256; n++) {
  76127. c = (unsigned long)n;
  76128. for (k = 0; k < 8; k++)
  76129. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  76130. crc_table[0][n] = c;
  76131. }
  76132. #ifdef BYFOUR
  76133. for (n = 0; n < 256; n++) {
  76134. c = crc_table[0][n];
  76135. crc_table[4][n] = REV(c);
  76136. for (k = 1; k < 4; k++) {
  76137. c = crc_table[0][c & 0xff] ^ (c >> 8);
  76138. crc_table[k][n] = c;
  76139. crc_table[k + 4][n] = REV(c);
  76140. }
  76141. }
  76142. #endif /* BYFOUR */
  76143. crc_table_empty = 0;
  76144. }
  76145. else { /* not first */
  76146. while (crc_table_empty)
  76147. ;
  76148. }
  76149. #ifdef MAKECRCH
  76150. {
  76151. FILE *out;
  76152. out = fopen("crc32.h", "w");
  76153. if (out == NULL) return;
  76154. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  76155. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  76156. fprintf(out, "local const unsigned long FAR ");
  76157. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  76158. write_table(out, crc_table[0]);
  76159. # ifdef BYFOUR
  76160. fprintf(out, "#ifdef BYFOUR\n");
  76161. for (k = 1; k < 8; k++) {
  76162. fprintf(out, " },\n {\n");
  76163. write_table(out, crc_table[k]);
  76164. }
  76165. fprintf(out, "#endif\n");
  76166. # endif /* BYFOUR */
  76167. fprintf(out, " }\n};\n");
  76168. fclose(out);
  76169. }
  76170. #endif /* MAKECRCH */
  76171. }
  76172. #ifdef MAKECRCH
  76173. local void write_table(out, table)
  76174. FILE *out;
  76175. const unsigned long FAR *table;
  76176. {
  76177. int n;
  76178. for (n = 0; n < 256; n++)
  76179. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  76180. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  76181. }
  76182. #endif /* MAKECRCH */
  76183. #else /* !DYNAMIC_CRC_TABLE */
  76184. /*** Start of inlined file: crc32.h ***/
  76185. local const unsigned long FAR crc_table[TBLS][256] =
  76186. {
  76187. {
  76188. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  76189. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  76190. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  76191. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  76192. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  76193. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  76194. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  76195. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  76196. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  76197. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  76198. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  76199. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  76200. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  76201. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  76202. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  76203. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  76204. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  76205. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  76206. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  76207. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  76208. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  76209. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  76210. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  76211. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  76212. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  76213. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  76214. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  76215. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  76216. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  76217. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  76218. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  76219. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  76220. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  76221. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  76222. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  76223. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  76224. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  76225. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  76226. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  76227. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  76228. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  76229. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  76230. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  76231. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  76232. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  76233. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  76234. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  76235. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  76236. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  76237. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  76238. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  76239. 0x2d02ef8dUL
  76240. #ifdef BYFOUR
  76241. },
  76242. {
  76243. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  76244. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  76245. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  76246. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  76247. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  76248. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  76249. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  76250. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  76251. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  76252. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  76253. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  76254. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  76255. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  76256. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  76257. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  76258. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  76259. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  76260. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  76261. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  76262. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  76263. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  76264. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  76265. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  76266. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  76267. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  76268. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  76269. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  76270. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  76271. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  76272. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  76273. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  76274. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  76275. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  76276. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  76277. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  76278. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  76279. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  76280. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  76281. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  76282. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  76283. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  76284. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76285. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76286. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76287. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76288. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76289. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76290. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76291. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76292. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76293. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76294. 0x9324fd72UL
  76295. },
  76296. {
  76297. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76298. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76299. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76300. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76301. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76302. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76303. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76304. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76305. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76306. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76307. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76308. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76309. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76310. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76311. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76312. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76313. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76314. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76315. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76316. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76317. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76318. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76319. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76320. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76321. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76322. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76323. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76324. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76325. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76326. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76327. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76328. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76329. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76330. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76331. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76332. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76333. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76334. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76335. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76336. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76337. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76338. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76339. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76340. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76341. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76342. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76343. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76344. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76345. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76346. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76347. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76348. 0xbe9834edUL
  76349. },
  76350. {
  76351. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76352. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76353. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76354. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76355. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76356. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76357. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76358. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76359. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76360. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76361. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76362. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76363. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76364. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76365. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76366. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76367. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76368. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76369. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76370. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76371. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76372. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76373. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76374. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76375. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76376. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76377. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76378. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76379. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76380. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76381. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76382. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76383. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76384. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76385. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76386. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76387. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76388. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76389. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76390. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76391. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76392. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76393. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76394. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76395. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76396. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76397. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76398. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76399. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76400. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76401. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76402. 0xde0506f1UL
  76403. },
  76404. {
  76405. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76406. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76407. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76408. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76409. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76410. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76411. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76412. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76413. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76414. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76415. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76416. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76417. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76418. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76419. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76420. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76421. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76422. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76423. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76424. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76425. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76426. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76427. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76428. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76429. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76430. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76431. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76432. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76433. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76434. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76435. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76436. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76437. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76438. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76439. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76440. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76441. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76442. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76443. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76444. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76445. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76446. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76447. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76448. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76449. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76450. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76451. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76452. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76453. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76454. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76455. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76456. 0x8def022dUL
  76457. },
  76458. {
  76459. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76460. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76461. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76462. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76463. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76464. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76465. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76466. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76467. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76468. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76469. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76470. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76471. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76472. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76473. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76474. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76475. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76476. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76477. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76478. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76479. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76480. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76481. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76482. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76483. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76484. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76485. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76486. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76487. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76488. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76489. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76490. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76491. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76492. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76493. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76494. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76495. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76496. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76497. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76498. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76499. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76500. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76501. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76502. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76503. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76504. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76505. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76506. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76507. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76508. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76509. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76510. 0x72fd2493UL
  76511. },
  76512. {
  76513. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76514. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76515. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76516. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76517. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76518. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76519. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76520. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76521. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76522. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76523. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76524. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76525. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76526. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76527. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76528. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76529. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76530. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76531. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76532. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76533. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76534. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76535. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76536. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76537. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76538. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76539. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76540. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76541. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76542. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76543. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76544. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76545. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76546. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76547. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76548. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76549. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76550. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76551. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76552. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76553. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76554. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76555. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76556. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76557. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76558. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76559. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76560. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76561. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76562. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76563. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76564. 0xed3498beUL
  76565. },
  76566. {
  76567. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76568. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76569. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76570. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76571. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76572. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76573. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76574. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76575. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76576. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76577. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76578. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76579. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76580. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76581. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76582. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76583. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76584. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76585. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76586. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76587. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76588. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76589. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76590. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76591. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76592. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76593. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76594. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76595. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76596. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76597. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76598. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76599. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76600. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76601. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76602. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76603. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76604. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76605. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76606. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76607. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76608. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76609. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76610. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76611. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76612. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76613. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76614. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76615. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76616. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76617. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76618. 0xf10605deUL
  76619. #endif
  76620. }
  76621. };
  76622. /*** End of inlined file: crc32.h ***/
  76623. #endif /* DYNAMIC_CRC_TABLE */
  76624. const unsigned long FAR * ZEXPORT get_crc_table()
  76625. {
  76626. #ifdef DYNAMIC_CRC_TABLE
  76627. if (crc_table_empty)
  76628. make_crc_table();
  76629. #endif /* DYNAMIC_CRC_TABLE */
  76630. return (const unsigned long FAR *)crc_table;
  76631. }
  76632. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76633. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76634. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76635. {
  76636. if (buf == Z_NULL) return 0UL;
  76637. #ifdef DYNAMIC_CRC_TABLE
  76638. if (crc_table_empty)
  76639. make_crc_table();
  76640. #endif /* DYNAMIC_CRC_TABLE */
  76641. #ifdef BYFOUR
  76642. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76643. u4 endian;
  76644. endian = 1;
  76645. if (*((unsigned char *)(&endian)))
  76646. return crc32_little(crc, buf, len);
  76647. else
  76648. return crc32_big(crc, buf, len);
  76649. }
  76650. #endif /* BYFOUR */
  76651. crc = crc ^ 0xffffffffUL;
  76652. while (len >= 8) {
  76653. DO8;
  76654. len -= 8;
  76655. }
  76656. if (len) do {
  76657. DO1;
  76658. } while (--len);
  76659. return crc ^ 0xffffffffUL;
  76660. }
  76661. #ifdef BYFOUR
  76662. #define DOLIT4 c ^= *buf4++; \
  76663. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76664. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76665. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76666. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76667. {
  76668. register u4 c;
  76669. register const u4 FAR *buf4;
  76670. c = (u4)crc;
  76671. c = ~c;
  76672. while (len && ((ptrdiff_t)buf & 3)) {
  76673. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76674. len--;
  76675. }
  76676. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76677. while (len >= 32) {
  76678. DOLIT32;
  76679. len -= 32;
  76680. }
  76681. while (len >= 4) {
  76682. DOLIT4;
  76683. len -= 4;
  76684. }
  76685. buf = (const unsigned char FAR *)buf4;
  76686. if (len) do {
  76687. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76688. } while (--len);
  76689. c = ~c;
  76690. return (unsigned long)c;
  76691. }
  76692. #define DOBIG4 c ^= *++buf4; \
  76693. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76694. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76695. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76696. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76697. {
  76698. register u4 c;
  76699. register const u4 FAR *buf4;
  76700. c = REV((u4)crc);
  76701. c = ~c;
  76702. while (len && ((ptrdiff_t)buf & 3)) {
  76703. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76704. len--;
  76705. }
  76706. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76707. buf4--;
  76708. while (len >= 32) {
  76709. DOBIG32;
  76710. len -= 32;
  76711. }
  76712. while (len >= 4) {
  76713. DOBIG4;
  76714. len -= 4;
  76715. }
  76716. buf4++;
  76717. buf = (const unsigned char FAR *)buf4;
  76718. if (len) do {
  76719. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76720. } while (--len);
  76721. c = ~c;
  76722. return (unsigned long)(REV(c));
  76723. }
  76724. #endif /* BYFOUR */
  76725. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76726. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76727. {
  76728. unsigned long sum;
  76729. sum = 0;
  76730. while (vec) {
  76731. if (vec & 1)
  76732. sum ^= *mat;
  76733. vec >>= 1;
  76734. mat++;
  76735. }
  76736. return sum;
  76737. }
  76738. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76739. {
  76740. int n;
  76741. for (n = 0; n < GF2_DIM; n++)
  76742. square[n] = gf2_matrix_times(mat, mat[n]);
  76743. }
  76744. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76745. {
  76746. int n;
  76747. unsigned long row;
  76748. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76749. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76750. if (len2 == 0)
  76751. return crc1;
  76752. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76753. row = 1;
  76754. for (n = 1; n < GF2_DIM; n++) {
  76755. odd[n] = row;
  76756. row <<= 1;
  76757. }
  76758. gf2_matrix_square(even, odd);
  76759. gf2_matrix_square(odd, even);
  76760. do {
  76761. gf2_matrix_square(even, odd);
  76762. if (len2 & 1)
  76763. crc1 = gf2_matrix_times(even, crc1);
  76764. len2 >>= 1;
  76765. if (len2 == 0)
  76766. break;
  76767. gf2_matrix_square(odd, even);
  76768. if (len2 & 1)
  76769. crc1 = gf2_matrix_times(odd, crc1);
  76770. len2 >>= 1;
  76771. } while (len2 != 0);
  76772. crc1 ^= crc2;
  76773. return crc1;
  76774. }
  76775. /*** End of inlined file: crc32.c ***/
  76776. /*** Start of inlined file: deflate.c ***/
  76777. /*** Start of inlined file: deflate.h ***/
  76778. #ifndef DEFLATE_H
  76779. #define DEFLATE_H
  76780. #ifndef NO_GZIP
  76781. # define GZIP
  76782. #endif
  76783. #define NO_DUMMY_DECL
  76784. #define LENGTH_CODES 29
  76785. #define LITERALS 256
  76786. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76787. #define D_CODES 30
  76788. #define BL_CODES 19
  76789. #define HEAP_SIZE (2*L_CODES+1)
  76790. #define MAX_BITS 15
  76791. #define INIT_STATE 42
  76792. #define EXTRA_STATE 69
  76793. #define NAME_STATE 73
  76794. #define COMMENT_STATE 91
  76795. #define HCRC_STATE 103
  76796. #define BUSY_STATE 113
  76797. #define FINISH_STATE 666
  76798. typedef struct ct_data_s {
  76799. union {
  76800. ush freq; /* frequency count */
  76801. ush code; /* bit string */
  76802. } fc;
  76803. union {
  76804. ush dad; /* father node in Huffman tree */
  76805. ush len; /* length of bit string */
  76806. } dl;
  76807. } FAR ct_data;
  76808. #define Freq fc.freq
  76809. #define Code fc.code
  76810. #define Dad dl.dad
  76811. #define Len dl.len
  76812. typedef struct static_tree_desc_s static_tree_desc;
  76813. typedef struct tree_desc_s {
  76814. ct_data *dyn_tree; /* the dynamic tree */
  76815. int max_code; /* largest code with non zero frequency */
  76816. static_tree_desc *stat_desc; /* the corresponding static tree */
  76817. } FAR tree_desc;
  76818. typedef ush Pos;
  76819. typedef Pos FAR Posf;
  76820. typedef unsigned IPos;
  76821. typedef struct internal_state {
  76822. z_streamp strm; /* pointer back to this zlib stream */
  76823. int status; /* as the name implies */
  76824. Bytef *pending_buf; /* output still pending */
  76825. ulg pending_buf_size; /* size of pending_buf */
  76826. Bytef *pending_out; /* next pending byte to output to the stream */
  76827. uInt pending; /* nb of bytes in the pending buffer */
  76828. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76829. gz_headerp gzhead; /* gzip header information to write */
  76830. uInt gzindex; /* where in extra, name, or comment */
  76831. Byte method; /* STORED (for zip only) or DEFLATED */
  76832. int last_flush; /* value of flush param for previous deflate call */
  76833. uInt w_size; /* LZ77 window size (32K by default) */
  76834. uInt w_bits; /* log2(w_size) (8..16) */
  76835. uInt w_mask; /* w_size - 1 */
  76836. Bytef *window;
  76837. ulg window_size;
  76838. Posf *prev;
  76839. Posf *head; /* Heads of the hash chains or NIL. */
  76840. uInt ins_h; /* hash index of string to be inserted */
  76841. uInt hash_size; /* number of elements in hash table */
  76842. uInt hash_bits; /* log2(hash_size) */
  76843. uInt hash_mask; /* hash_size-1 */
  76844. uInt hash_shift;
  76845. long block_start;
  76846. uInt match_length; /* length of best match */
  76847. IPos prev_match; /* previous match */
  76848. int match_available; /* set if previous match exists */
  76849. uInt strstart; /* start of string to insert */
  76850. uInt match_start; /* start of matching string */
  76851. uInt lookahead; /* number of valid bytes ahead in window */
  76852. uInt prev_length;
  76853. uInt max_chain_length;
  76854. uInt max_lazy_match;
  76855. # define max_insert_length max_lazy_match
  76856. int level; /* compression level (1..9) */
  76857. int strategy; /* favor or force Huffman coding*/
  76858. uInt good_match;
  76859. int nice_match; /* Stop searching when current match exceeds this */
  76860. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76861. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76862. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76863. struct tree_desc_s l_desc; /* desc. for literal tree */
  76864. struct tree_desc_s d_desc; /* desc. for distance tree */
  76865. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76866. ush bl_count[MAX_BITS+1];
  76867. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76868. int heap_len; /* number of elements in the heap */
  76869. int heap_max; /* element of largest frequency */
  76870. uch depth[2*L_CODES+1];
  76871. uchf *l_buf; /* buffer for literals or lengths */
  76872. uInt lit_bufsize;
  76873. uInt last_lit; /* running index in l_buf */
  76874. ushf *d_buf;
  76875. ulg opt_len; /* bit length of current block with optimal trees */
  76876. ulg static_len; /* bit length of current block with static trees */
  76877. uInt matches; /* number of string matches in current block */
  76878. int last_eob_len; /* bit length of EOB code for last block */
  76879. #ifdef DEBUG
  76880. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76881. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76882. #endif
  76883. ush bi_buf;
  76884. int bi_valid;
  76885. } FAR deflate_state;
  76886. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76887. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76888. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76889. void _tr_init OF((deflate_state *s));
  76890. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76891. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76892. int eof));
  76893. void _tr_align OF((deflate_state *s));
  76894. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76895. int eof));
  76896. #define d_code(dist) \
  76897. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76898. #ifndef DEBUG
  76899. #if defined(GEN_TREES_H) || !defined(STDC)
  76900. extern uch _length_code[];
  76901. extern uch _dist_code[];
  76902. #else
  76903. extern const uch _length_code[];
  76904. extern const uch _dist_code[];
  76905. #endif
  76906. # define _tr_tally_lit(s, c, flush) \
  76907. { uch cc = (c); \
  76908. s->d_buf[s->last_lit] = 0; \
  76909. s->l_buf[s->last_lit++] = cc; \
  76910. s->dyn_ltree[cc].Freq++; \
  76911. flush = (s->last_lit == s->lit_bufsize-1); \
  76912. }
  76913. # define _tr_tally_dist(s, distance, length, flush) \
  76914. { uch len = (length); \
  76915. ush dist = (distance); \
  76916. s->d_buf[s->last_lit] = dist; \
  76917. s->l_buf[s->last_lit++] = len; \
  76918. dist--; \
  76919. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76920. s->dyn_dtree[d_code(dist)].Freq++; \
  76921. flush = (s->last_lit == s->lit_bufsize-1); \
  76922. }
  76923. #else
  76924. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76925. # define _tr_tally_dist(s, distance, length, flush) \
  76926. flush = _tr_tally(s, distance, length)
  76927. #endif
  76928. #endif /* DEFLATE_H */
  76929. /*** End of inlined file: deflate.h ***/
  76930. const char deflate_copyright[] =
  76931. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76932. typedef enum {
  76933. need_more, /* block not completed, need more input or more output */
  76934. block_done, /* block flush performed */
  76935. finish_started, /* finish started, need only more output at next deflate */
  76936. finish_done /* finish done, accept no more input or output */
  76937. } block_state;
  76938. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76939. local void fill_window OF((deflate_state *s));
  76940. local block_state deflate_stored OF((deflate_state *s, int flush));
  76941. local block_state deflate_fast OF((deflate_state *s, int flush));
  76942. #ifndef FASTEST
  76943. local block_state deflate_slow OF((deflate_state *s, int flush));
  76944. #endif
  76945. local void lm_init OF((deflate_state *s));
  76946. local void putShortMSB OF((deflate_state *s, uInt b));
  76947. local void flush_pending OF((z_streamp strm));
  76948. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76949. #ifndef FASTEST
  76950. #ifdef ASMV
  76951. void match_init OF((void)); /* asm code initialization */
  76952. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76953. #else
  76954. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76955. #endif
  76956. #endif
  76957. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76958. #ifdef DEBUG
  76959. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76960. int length));
  76961. #endif
  76962. #define NIL 0
  76963. #ifndef TOO_FAR
  76964. # define TOO_FAR 4096
  76965. #endif
  76966. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76967. typedef struct config_s {
  76968. ush good_length; /* reduce lazy search above this match length */
  76969. ush max_lazy; /* do not perform lazy search above this match length */
  76970. ush nice_length; /* quit search above this match length */
  76971. ush max_chain;
  76972. compress_func func;
  76973. } config;
  76974. #ifdef FASTEST
  76975. local const config configuration_table[2] = {
  76976. {0, 0, 0, 0, deflate_stored}, /* store only */
  76977. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76978. #else
  76979. local const config configuration_table[10] = {
  76980. {0, 0, 0, 0, deflate_stored}, /* store only */
  76981. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76982. {4, 5, 16, 8, deflate_fast},
  76983. {4, 6, 32, 32, deflate_fast},
  76984. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76985. {8, 16, 32, 32, deflate_slow},
  76986. {8, 16, 128, 128, deflate_slow},
  76987. {8, 32, 128, 256, deflate_slow},
  76988. {32, 128, 258, 1024, deflate_slow},
  76989. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76990. #endif
  76991. #define EQUAL 0
  76992. #ifndef NO_DUMMY_DECL
  76993. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76994. #endif
  76995. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76996. #ifdef FASTEST
  76997. #define INSERT_STRING(s, str, match_head) \
  76998. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76999. match_head = s->head[s->ins_h], \
  77000. s->head[s->ins_h] = (Pos)(str))
  77001. #else
  77002. #define INSERT_STRING(s, str, match_head) \
  77003. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77004. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  77005. s->head[s->ins_h] = (Pos)(str))
  77006. #endif
  77007. #define CLEAR_HASH(s) \
  77008. s->head[s->hash_size-1] = NIL; \
  77009. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  77010. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  77011. {
  77012. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  77013. Z_DEFAULT_STRATEGY, version, stream_size);
  77014. }
  77015. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  77016. {
  77017. deflate_state *s;
  77018. int wrap = 1;
  77019. static const char my_version[] = ZLIB_VERSION;
  77020. ushf *overlay;
  77021. if (version == Z_NULL || version[0] != my_version[0] ||
  77022. stream_size != sizeof(z_stream)) {
  77023. return Z_VERSION_ERROR;
  77024. }
  77025. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77026. strm->msg = Z_NULL;
  77027. if (strm->zalloc == (alloc_func)0) {
  77028. strm->zalloc = zcalloc;
  77029. strm->opaque = (voidpf)0;
  77030. }
  77031. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77032. #ifdef FASTEST
  77033. if (level != 0) level = 1;
  77034. #else
  77035. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77036. #endif
  77037. if (windowBits < 0) { /* suppress zlib wrapper */
  77038. wrap = 0;
  77039. windowBits = -windowBits;
  77040. }
  77041. #ifdef GZIP
  77042. else if (windowBits > 15) {
  77043. wrap = 2; /* write gzip wrapper instead */
  77044. windowBits -= 16;
  77045. }
  77046. #endif
  77047. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  77048. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  77049. strategy < 0 || strategy > Z_FIXED) {
  77050. return Z_STREAM_ERROR;
  77051. }
  77052. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  77053. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  77054. if (s == Z_NULL) return Z_MEM_ERROR;
  77055. strm->state = (struct internal_state FAR *)s;
  77056. s->strm = strm;
  77057. s->wrap = wrap;
  77058. s->gzhead = Z_NULL;
  77059. s->w_bits = windowBits;
  77060. s->w_size = 1 << s->w_bits;
  77061. s->w_mask = s->w_size - 1;
  77062. s->hash_bits = memLevel + 7;
  77063. s->hash_size = 1 << s->hash_bits;
  77064. s->hash_mask = s->hash_size - 1;
  77065. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  77066. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  77067. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  77068. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  77069. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  77070. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  77071. s->pending_buf = (uchf *) overlay;
  77072. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  77073. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  77074. s->pending_buf == Z_NULL) {
  77075. s->status = FINISH_STATE;
  77076. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  77077. deflateEnd (strm);
  77078. return Z_MEM_ERROR;
  77079. }
  77080. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  77081. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  77082. s->level = level;
  77083. s->strategy = strategy;
  77084. s->method = (Byte)method;
  77085. return deflateReset(strm);
  77086. }
  77087. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  77088. {
  77089. deflate_state *s;
  77090. uInt length = dictLength;
  77091. uInt n;
  77092. IPos hash_head = 0;
  77093. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  77094. strm->state->wrap == 2 ||
  77095. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  77096. return Z_STREAM_ERROR;
  77097. s = strm->state;
  77098. if (s->wrap)
  77099. strm->adler = adler32(strm->adler, dictionary, dictLength);
  77100. if (length < MIN_MATCH) return Z_OK;
  77101. if (length > MAX_DIST(s)) {
  77102. length = MAX_DIST(s);
  77103. dictionary += dictLength - length; /* use the tail of the dictionary */
  77104. }
  77105. zmemcpy(s->window, dictionary, length);
  77106. s->strstart = length;
  77107. s->block_start = (long)length;
  77108. s->ins_h = s->window[0];
  77109. UPDATE_HASH(s, s->ins_h, s->window[1]);
  77110. for (n = 0; n <= length - MIN_MATCH; n++) {
  77111. INSERT_STRING(s, n, hash_head);
  77112. }
  77113. if (hash_head) hash_head = 0; /* to make compiler happy */
  77114. return Z_OK;
  77115. }
  77116. int ZEXPORT deflateReset (z_streamp strm)
  77117. {
  77118. deflate_state *s;
  77119. if (strm == Z_NULL || strm->state == Z_NULL ||
  77120. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  77121. return Z_STREAM_ERROR;
  77122. }
  77123. strm->total_in = strm->total_out = 0;
  77124. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  77125. strm->data_type = Z_UNKNOWN;
  77126. s = (deflate_state *)strm->state;
  77127. s->pending = 0;
  77128. s->pending_out = s->pending_buf;
  77129. if (s->wrap < 0) {
  77130. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  77131. }
  77132. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  77133. strm->adler =
  77134. #ifdef GZIP
  77135. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  77136. #endif
  77137. adler32(0L, Z_NULL, 0);
  77138. s->last_flush = Z_NO_FLUSH;
  77139. _tr_init(s);
  77140. lm_init(s);
  77141. return Z_OK;
  77142. }
  77143. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  77144. {
  77145. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77146. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  77147. strm->state->gzhead = head;
  77148. return Z_OK;
  77149. }
  77150. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  77151. {
  77152. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77153. strm->state->bi_valid = bits;
  77154. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  77155. return Z_OK;
  77156. }
  77157. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  77158. {
  77159. deflate_state *s;
  77160. compress_func func;
  77161. int err = Z_OK;
  77162. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77163. s = strm->state;
  77164. #ifdef FASTEST
  77165. if (level != 0) level = 1;
  77166. #else
  77167. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77168. #endif
  77169. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  77170. return Z_STREAM_ERROR;
  77171. }
  77172. func = configuration_table[s->level].func;
  77173. if (func != configuration_table[level].func && strm->total_in != 0) {
  77174. err = deflate(strm, Z_PARTIAL_FLUSH);
  77175. }
  77176. if (s->level != level) {
  77177. s->level = level;
  77178. s->max_lazy_match = configuration_table[level].max_lazy;
  77179. s->good_match = configuration_table[level].good_length;
  77180. s->nice_match = configuration_table[level].nice_length;
  77181. s->max_chain_length = configuration_table[level].max_chain;
  77182. }
  77183. s->strategy = strategy;
  77184. return err;
  77185. }
  77186. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  77187. {
  77188. deflate_state *s;
  77189. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77190. s = strm->state;
  77191. s->good_match = good_length;
  77192. s->max_lazy_match = max_lazy;
  77193. s->nice_match = nice_length;
  77194. s->max_chain_length = max_chain;
  77195. return Z_OK;
  77196. }
  77197. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  77198. {
  77199. deflate_state *s;
  77200. uLong destLen;
  77201. destLen = sourceLen +
  77202. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  77203. if (strm == Z_NULL || strm->state == Z_NULL)
  77204. return destLen;
  77205. s = strm->state;
  77206. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  77207. return destLen;
  77208. return compressBound(sourceLen);
  77209. }
  77210. local void putShortMSB (deflate_state *s, uInt b)
  77211. {
  77212. put_byte(s, (Byte)(b >> 8));
  77213. put_byte(s, (Byte)(b & 0xff));
  77214. }
  77215. local void flush_pending (z_streamp strm)
  77216. {
  77217. unsigned len = strm->state->pending;
  77218. if (len > strm->avail_out) len = strm->avail_out;
  77219. if (len == 0) return;
  77220. zmemcpy(strm->next_out, strm->state->pending_out, len);
  77221. strm->next_out += len;
  77222. strm->state->pending_out += len;
  77223. strm->total_out += len;
  77224. strm->avail_out -= len;
  77225. strm->state->pending -= len;
  77226. if (strm->state->pending == 0) {
  77227. strm->state->pending_out = strm->state->pending_buf;
  77228. }
  77229. }
  77230. int ZEXPORT deflate (z_streamp strm, int flush)
  77231. {
  77232. int old_flush; /* value of flush param for previous deflate call */
  77233. deflate_state *s;
  77234. if (strm == Z_NULL || strm->state == Z_NULL ||
  77235. flush > Z_FINISH || flush < 0) {
  77236. return Z_STREAM_ERROR;
  77237. }
  77238. s = strm->state;
  77239. if (strm->next_out == Z_NULL ||
  77240. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  77241. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  77242. ERR_RETURN(strm, Z_STREAM_ERROR);
  77243. }
  77244. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  77245. s->strm = strm; /* just in case */
  77246. old_flush = s->last_flush;
  77247. s->last_flush = flush;
  77248. if (s->status == INIT_STATE) {
  77249. #ifdef GZIP
  77250. if (s->wrap == 2) {
  77251. strm->adler = crc32(0L, Z_NULL, 0);
  77252. put_byte(s, 31);
  77253. put_byte(s, 139);
  77254. put_byte(s, 8);
  77255. if (s->gzhead == NULL) {
  77256. put_byte(s, 0);
  77257. put_byte(s, 0);
  77258. put_byte(s, 0);
  77259. put_byte(s, 0);
  77260. put_byte(s, 0);
  77261. put_byte(s, s->level == 9 ? 2 :
  77262. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77263. 4 : 0));
  77264. put_byte(s, OS_CODE);
  77265. s->status = BUSY_STATE;
  77266. }
  77267. else {
  77268. put_byte(s, (s->gzhead->text ? 1 : 0) +
  77269. (s->gzhead->hcrc ? 2 : 0) +
  77270. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  77271. (s->gzhead->name == Z_NULL ? 0 : 8) +
  77272. (s->gzhead->comment == Z_NULL ? 0 : 16)
  77273. );
  77274. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  77275. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  77276. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  77277. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  77278. put_byte(s, s->level == 9 ? 2 :
  77279. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77280. 4 : 0));
  77281. put_byte(s, s->gzhead->os & 0xff);
  77282. if (s->gzhead->extra != NULL) {
  77283. put_byte(s, s->gzhead->extra_len & 0xff);
  77284. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77285. }
  77286. if (s->gzhead->hcrc)
  77287. strm->adler = crc32(strm->adler, s->pending_buf,
  77288. s->pending);
  77289. s->gzindex = 0;
  77290. s->status = EXTRA_STATE;
  77291. }
  77292. }
  77293. else
  77294. #endif
  77295. {
  77296. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77297. uInt level_flags;
  77298. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77299. level_flags = 0;
  77300. else if (s->level < 6)
  77301. level_flags = 1;
  77302. else if (s->level == 6)
  77303. level_flags = 2;
  77304. else
  77305. level_flags = 3;
  77306. header |= (level_flags << 6);
  77307. if (s->strstart != 0) header |= PRESET_DICT;
  77308. header += 31 - (header % 31);
  77309. s->status = BUSY_STATE;
  77310. putShortMSB(s, header);
  77311. if (s->strstart != 0) {
  77312. putShortMSB(s, (uInt)(strm->adler >> 16));
  77313. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77314. }
  77315. strm->adler = adler32(0L, Z_NULL, 0);
  77316. }
  77317. }
  77318. #ifdef GZIP
  77319. if (s->status == EXTRA_STATE) {
  77320. if (s->gzhead->extra != NULL) {
  77321. uInt beg = s->pending; /* start of bytes to update crc */
  77322. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77323. if (s->pending == s->pending_buf_size) {
  77324. if (s->gzhead->hcrc && s->pending > beg)
  77325. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77326. s->pending - beg);
  77327. flush_pending(strm);
  77328. beg = s->pending;
  77329. if (s->pending == s->pending_buf_size)
  77330. break;
  77331. }
  77332. put_byte(s, s->gzhead->extra[s->gzindex]);
  77333. s->gzindex++;
  77334. }
  77335. if (s->gzhead->hcrc && s->pending > beg)
  77336. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77337. s->pending - beg);
  77338. if (s->gzindex == s->gzhead->extra_len) {
  77339. s->gzindex = 0;
  77340. s->status = NAME_STATE;
  77341. }
  77342. }
  77343. else
  77344. s->status = NAME_STATE;
  77345. }
  77346. if (s->status == NAME_STATE) {
  77347. if (s->gzhead->name != NULL) {
  77348. uInt beg = s->pending; /* start of bytes to update crc */
  77349. int val;
  77350. do {
  77351. if (s->pending == s->pending_buf_size) {
  77352. if (s->gzhead->hcrc && s->pending > beg)
  77353. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77354. s->pending - beg);
  77355. flush_pending(strm);
  77356. beg = s->pending;
  77357. if (s->pending == s->pending_buf_size) {
  77358. val = 1;
  77359. break;
  77360. }
  77361. }
  77362. val = s->gzhead->name[s->gzindex++];
  77363. put_byte(s, val);
  77364. } while (val != 0);
  77365. if (s->gzhead->hcrc && s->pending > beg)
  77366. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77367. s->pending - beg);
  77368. if (val == 0) {
  77369. s->gzindex = 0;
  77370. s->status = COMMENT_STATE;
  77371. }
  77372. }
  77373. else
  77374. s->status = COMMENT_STATE;
  77375. }
  77376. if (s->status == COMMENT_STATE) {
  77377. if (s->gzhead->comment != NULL) {
  77378. uInt beg = s->pending; /* start of bytes to update crc */
  77379. int val;
  77380. do {
  77381. if (s->pending == s->pending_buf_size) {
  77382. if (s->gzhead->hcrc && s->pending > beg)
  77383. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77384. s->pending - beg);
  77385. flush_pending(strm);
  77386. beg = s->pending;
  77387. if (s->pending == s->pending_buf_size) {
  77388. val = 1;
  77389. break;
  77390. }
  77391. }
  77392. val = s->gzhead->comment[s->gzindex++];
  77393. put_byte(s, val);
  77394. } while (val != 0);
  77395. if (s->gzhead->hcrc && s->pending > beg)
  77396. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77397. s->pending - beg);
  77398. if (val == 0)
  77399. s->status = HCRC_STATE;
  77400. }
  77401. else
  77402. s->status = HCRC_STATE;
  77403. }
  77404. if (s->status == HCRC_STATE) {
  77405. if (s->gzhead->hcrc) {
  77406. if (s->pending + 2 > s->pending_buf_size)
  77407. flush_pending(strm);
  77408. if (s->pending + 2 <= s->pending_buf_size) {
  77409. put_byte(s, (Byte)(strm->adler & 0xff));
  77410. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77411. strm->adler = crc32(0L, Z_NULL, 0);
  77412. s->status = BUSY_STATE;
  77413. }
  77414. }
  77415. else
  77416. s->status = BUSY_STATE;
  77417. }
  77418. #endif
  77419. if (s->pending != 0) {
  77420. flush_pending(strm);
  77421. if (strm->avail_out == 0) {
  77422. s->last_flush = -1;
  77423. return Z_OK;
  77424. }
  77425. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77426. flush != Z_FINISH) {
  77427. ERR_RETURN(strm, Z_BUF_ERROR);
  77428. }
  77429. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77430. ERR_RETURN(strm, Z_BUF_ERROR);
  77431. }
  77432. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77433. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77434. block_state bstate;
  77435. bstate = (*(configuration_table[s->level].func))(s, flush);
  77436. if (bstate == finish_started || bstate == finish_done) {
  77437. s->status = FINISH_STATE;
  77438. }
  77439. if (bstate == need_more || bstate == finish_started) {
  77440. if (strm->avail_out == 0) {
  77441. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77442. }
  77443. return Z_OK;
  77444. }
  77445. if (bstate == block_done) {
  77446. if (flush == Z_PARTIAL_FLUSH) {
  77447. _tr_align(s);
  77448. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77449. _tr_stored_block(s, (char*)0, 0L, 0);
  77450. if (flush == Z_FULL_FLUSH) {
  77451. CLEAR_HASH(s); /* forget history */
  77452. }
  77453. }
  77454. flush_pending(strm);
  77455. if (strm->avail_out == 0) {
  77456. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77457. return Z_OK;
  77458. }
  77459. }
  77460. }
  77461. Assert(strm->avail_out > 0, "bug2");
  77462. if (flush != Z_FINISH) return Z_OK;
  77463. if (s->wrap <= 0) return Z_STREAM_END;
  77464. #ifdef GZIP
  77465. if (s->wrap == 2) {
  77466. put_byte(s, (Byte)(strm->adler & 0xff));
  77467. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77468. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77469. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77470. put_byte(s, (Byte)(strm->total_in & 0xff));
  77471. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77472. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77473. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77474. }
  77475. else
  77476. #endif
  77477. {
  77478. putShortMSB(s, (uInt)(strm->adler >> 16));
  77479. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77480. }
  77481. flush_pending(strm);
  77482. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77483. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77484. }
  77485. int ZEXPORT deflateEnd (z_streamp strm)
  77486. {
  77487. int status;
  77488. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77489. status = strm->state->status;
  77490. if (status != INIT_STATE &&
  77491. status != EXTRA_STATE &&
  77492. status != NAME_STATE &&
  77493. status != COMMENT_STATE &&
  77494. status != HCRC_STATE &&
  77495. status != BUSY_STATE &&
  77496. status != FINISH_STATE) {
  77497. return Z_STREAM_ERROR;
  77498. }
  77499. TRY_FREE(strm, strm->state->pending_buf);
  77500. TRY_FREE(strm, strm->state->head);
  77501. TRY_FREE(strm, strm->state->prev);
  77502. TRY_FREE(strm, strm->state->window);
  77503. ZFREE(strm, strm->state);
  77504. strm->state = Z_NULL;
  77505. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77506. }
  77507. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77508. {
  77509. #ifdef MAXSEG_64K
  77510. return Z_STREAM_ERROR;
  77511. #else
  77512. deflate_state *ds;
  77513. deflate_state *ss;
  77514. ushf *overlay;
  77515. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77516. return Z_STREAM_ERROR;
  77517. }
  77518. ss = source->state;
  77519. zmemcpy(dest, source, sizeof(z_stream));
  77520. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77521. if (ds == Z_NULL) return Z_MEM_ERROR;
  77522. dest->state = (struct internal_state FAR *) ds;
  77523. zmemcpy(ds, ss, sizeof(deflate_state));
  77524. ds->strm = dest;
  77525. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77526. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77527. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77528. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77529. ds->pending_buf = (uchf *) overlay;
  77530. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77531. ds->pending_buf == Z_NULL) {
  77532. deflateEnd (dest);
  77533. return Z_MEM_ERROR;
  77534. }
  77535. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77536. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77537. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77538. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77539. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77540. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77541. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77542. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77543. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77544. ds->bl_desc.dyn_tree = ds->bl_tree;
  77545. return Z_OK;
  77546. #endif /* MAXSEG_64K */
  77547. }
  77548. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77549. {
  77550. unsigned len = strm->avail_in;
  77551. if (len > size) len = size;
  77552. if (len == 0) return 0;
  77553. strm->avail_in -= len;
  77554. if (strm->state->wrap == 1) {
  77555. strm->adler = adler32(strm->adler, strm->next_in, len);
  77556. }
  77557. #ifdef GZIP
  77558. else if (strm->state->wrap == 2) {
  77559. strm->adler = crc32(strm->adler, strm->next_in, len);
  77560. }
  77561. #endif
  77562. zmemcpy(buf, strm->next_in, len);
  77563. strm->next_in += len;
  77564. strm->total_in += len;
  77565. return (int)len;
  77566. }
  77567. local void lm_init (deflate_state *s)
  77568. {
  77569. s->window_size = (ulg)2L*s->w_size;
  77570. CLEAR_HASH(s);
  77571. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77572. s->good_match = configuration_table[s->level].good_length;
  77573. s->nice_match = configuration_table[s->level].nice_length;
  77574. s->max_chain_length = configuration_table[s->level].max_chain;
  77575. s->strstart = 0;
  77576. s->block_start = 0L;
  77577. s->lookahead = 0;
  77578. s->match_length = s->prev_length = MIN_MATCH-1;
  77579. s->match_available = 0;
  77580. s->ins_h = 0;
  77581. #ifndef FASTEST
  77582. #ifdef ASMV
  77583. match_init(); /* initialize the asm code */
  77584. #endif
  77585. #endif
  77586. }
  77587. #ifndef FASTEST
  77588. #ifndef ASMV
  77589. local uInt longest_match(deflate_state *s, IPos cur_match)
  77590. {
  77591. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77592. register Bytef *scan = s->window + s->strstart; /* current string */
  77593. register Bytef *match; /* matched string */
  77594. register int len; /* length of current match */
  77595. int best_len = s->prev_length; /* best match length so far */
  77596. int nice_match = s->nice_match; /* stop if match long enough */
  77597. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77598. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77599. Posf *prev = s->prev;
  77600. uInt wmask = s->w_mask;
  77601. #ifdef UNALIGNED_OK
  77602. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77603. register ush scan_start = *(ushf*)scan;
  77604. register ush scan_end = *(ushf*)(scan+best_len-1);
  77605. #else
  77606. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77607. register Byte scan_end1 = scan[best_len-1];
  77608. register Byte scan_end = scan[best_len];
  77609. #endif
  77610. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77611. if (s->prev_length >= s->good_match) {
  77612. chain_length >>= 2;
  77613. }
  77614. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77615. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77616. do {
  77617. Assert(cur_match < s->strstart, "no future");
  77618. match = s->window + cur_match;
  77619. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77620. if (*(ushf*)(match+best_len-1) != scan_end ||
  77621. *(ushf*)match != scan_start) continue;
  77622. Assert(scan[2] == match[2], "scan[2]?");
  77623. scan++, match++;
  77624. do {
  77625. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77626. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77627. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77628. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77629. scan < strend);
  77630. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77631. if (*scan == *match) scan++;
  77632. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77633. scan = strend - (MAX_MATCH-1);
  77634. #else /* UNALIGNED_OK */
  77635. if (match[best_len] != scan_end ||
  77636. match[best_len-1] != scan_end1 ||
  77637. *match != *scan ||
  77638. *++match != scan[1]) continue;
  77639. scan += 2, match++;
  77640. Assert(*scan == *match, "match[2]?");
  77641. do {
  77642. } while (*++scan == *++match && *++scan == *++match &&
  77643. *++scan == *++match && *++scan == *++match &&
  77644. *++scan == *++match && *++scan == *++match &&
  77645. *++scan == *++match && *++scan == *++match &&
  77646. scan < strend);
  77647. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77648. len = MAX_MATCH - (int)(strend - scan);
  77649. scan = strend - MAX_MATCH;
  77650. #endif /* UNALIGNED_OK */
  77651. if (len > best_len) {
  77652. s->match_start = cur_match;
  77653. best_len = len;
  77654. if (len >= nice_match) break;
  77655. #ifdef UNALIGNED_OK
  77656. scan_end = *(ushf*)(scan+best_len-1);
  77657. #else
  77658. scan_end1 = scan[best_len-1];
  77659. scan_end = scan[best_len];
  77660. #endif
  77661. }
  77662. } while ((cur_match = prev[cur_match & wmask]) > limit
  77663. && --chain_length != 0);
  77664. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77665. return s->lookahead;
  77666. }
  77667. #endif /* ASMV */
  77668. #endif /* FASTEST */
  77669. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77670. {
  77671. register Bytef *scan = s->window + s->strstart; /* current string */
  77672. register Bytef *match; /* matched string */
  77673. register int len; /* length of current match */
  77674. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77675. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77676. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77677. Assert(cur_match < s->strstart, "no future");
  77678. match = s->window + cur_match;
  77679. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77680. scan += 2, match += 2;
  77681. Assert(*scan == *match, "match[2]?");
  77682. do {
  77683. } while (*++scan == *++match && *++scan == *++match &&
  77684. *++scan == *++match && *++scan == *++match &&
  77685. *++scan == *++match && *++scan == *++match &&
  77686. *++scan == *++match && *++scan == *++match &&
  77687. scan < strend);
  77688. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77689. len = MAX_MATCH - (int)(strend - scan);
  77690. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77691. s->match_start = cur_match;
  77692. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77693. }
  77694. #ifdef DEBUG
  77695. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77696. {
  77697. if (zmemcmp(s->window + match,
  77698. s->window + start, length) != EQUAL) {
  77699. fprintf(stderr, " start %u, match %u, length %d\n",
  77700. start, match, length);
  77701. do {
  77702. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77703. } while (--length != 0);
  77704. z_error("invalid match");
  77705. }
  77706. if (z_verbose > 1) {
  77707. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77708. do { putc(s->window[start++], stderr); } while (--length != 0);
  77709. }
  77710. }
  77711. #else
  77712. # define check_match(s, start, match, length)
  77713. #endif /* DEBUG */
  77714. local void fill_window (deflate_state *s)
  77715. {
  77716. register unsigned n, m;
  77717. register Posf *p;
  77718. unsigned more; /* Amount of free space at the end of the window. */
  77719. uInt wsize = s->w_size;
  77720. do {
  77721. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77722. if (sizeof(int) <= 2) {
  77723. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77724. more = wsize;
  77725. } else if (more == (unsigned)(-1)) {
  77726. more--;
  77727. }
  77728. }
  77729. if (s->strstart >= wsize+MAX_DIST(s)) {
  77730. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77731. s->match_start -= wsize;
  77732. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77733. s->block_start -= (long) wsize;
  77734. n = s->hash_size;
  77735. p = &s->head[n];
  77736. do {
  77737. m = *--p;
  77738. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77739. } while (--n);
  77740. n = wsize;
  77741. #ifndef FASTEST
  77742. p = &s->prev[n];
  77743. do {
  77744. m = *--p;
  77745. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77746. } while (--n);
  77747. #endif
  77748. more += wsize;
  77749. }
  77750. if (s->strm->avail_in == 0) return;
  77751. Assert(more >= 2, "more < 2");
  77752. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77753. s->lookahead += n;
  77754. if (s->lookahead >= MIN_MATCH) {
  77755. s->ins_h = s->window[s->strstart];
  77756. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77757. #if MIN_MATCH != 3
  77758. Call UPDATE_HASH() MIN_MATCH-3 more times
  77759. #endif
  77760. }
  77761. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77762. }
  77763. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77764. _tr_flush_block(s, (s->block_start >= 0L ? \
  77765. (charf *)&s->window[(unsigned)s->block_start] : \
  77766. (charf *)Z_NULL), \
  77767. (ulg)((long)s->strstart - s->block_start), \
  77768. (eof)); \
  77769. s->block_start = s->strstart; \
  77770. flush_pending(s->strm); \
  77771. Tracev((stderr,"[FLUSH]")); \
  77772. }
  77773. #define FLUSH_BLOCK(s, eof) { \
  77774. FLUSH_BLOCK_ONLY(s, eof); \
  77775. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77776. }
  77777. local block_state deflate_stored(deflate_state *s, int flush)
  77778. {
  77779. ulg max_block_size = 0xffff;
  77780. ulg max_start;
  77781. if (max_block_size > s->pending_buf_size - 5) {
  77782. max_block_size = s->pending_buf_size - 5;
  77783. }
  77784. for (;;) {
  77785. if (s->lookahead <= 1) {
  77786. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77787. s->block_start >= (long)s->w_size, "slide too late");
  77788. fill_window(s);
  77789. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77790. if (s->lookahead == 0) break; /* flush the current block */
  77791. }
  77792. Assert(s->block_start >= 0L, "block gone");
  77793. s->strstart += s->lookahead;
  77794. s->lookahead = 0;
  77795. max_start = s->block_start + max_block_size;
  77796. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77797. s->lookahead = (uInt)(s->strstart - max_start);
  77798. s->strstart = (uInt)max_start;
  77799. FLUSH_BLOCK(s, 0);
  77800. }
  77801. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77802. FLUSH_BLOCK(s, 0);
  77803. }
  77804. }
  77805. FLUSH_BLOCK(s, flush == Z_FINISH);
  77806. return flush == Z_FINISH ? finish_done : block_done;
  77807. }
  77808. local block_state deflate_fast(deflate_state *s, int flush)
  77809. {
  77810. IPos hash_head = NIL; /* head of the hash chain */
  77811. int bflush; /* set if current block must be flushed */
  77812. for (;;) {
  77813. if (s->lookahead < MIN_LOOKAHEAD) {
  77814. fill_window(s);
  77815. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77816. return need_more;
  77817. }
  77818. if (s->lookahead == 0) break; /* flush the current block */
  77819. }
  77820. if (s->lookahead >= MIN_MATCH) {
  77821. INSERT_STRING(s, s->strstart, hash_head);
  77822. }
  77823. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77824. #ifdef FASTEST
  77825. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77826. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77827. s->match_length = longest_match_fast (s, hash_head);
  77828. }
  77829. #else
  77830. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77831. s->match_length = longest_match (s, hash_head);
  77832. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77833. s->match_length = longest_match_fast (s, hash_head);
  77834. }
  77835. #endif
  77836. }
  77837. if (s->match_length >= MIN_MATCH) {
  77838. check_match(s, s->strstart, s->match_start, s->match_length);
  77839. _tr_tally_dist(s, s->strstart - s->match_start,
  77840. s->match_length - MIN_MATCH, bflush);
  77841. s->lookahead -= s->match_length;
  77842. #ifndef FASTEST
  77843. if (s->match_length <= s->max_insert_length &&
  77844. s->lookahead >= MIN_MATCH) {
  77845. s->match_length--; /* string at strstart already in table */
  77846. do {
  77847. s->strstart++;
  77848. INSERT_STRING(s, s->strstart, hash_head);
  77849. } while (--s->match_length != 0);
  77850. s->strstart++;
  77851. } else
  77852. #endif
  77853. {
  77854. s->strstart += s->match_length;
  77855. s->match_length = 0;
  77856. s->ins_h = s->window[s->strstart];
  77857. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77858. #if MIN_MATCH != 3
  77859. Call UPDATE_HASH() MIN_MATCH-3 more times
  77860. #endif
  77861. }
  77862. } else {
  77863. Tracevv((stderr,"%c", s->window[s->strstart]));
  77864. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77865. s->lookahead--;
  77866. s->strstart++;
  77867. }
  77868. if (bflush) FLUSH_BLOCK(s, 0);
  77869. }
  77870. FLUSH_BLOCK(s, flush == Z_FINISH);
  77871. return flush == Z_FINISH ? finish_done : block_done;
  77872. }
  77873. #ifndef FASTEST
  77874. local block_state deflate_slow(deflate_state *s, int flush)
  77875. {
  77876. IPos hash_head = NIL; /* head of hash chain */
  77877. int bflush; /* set if current block must be flushed */
  77878. for (;;) {
  77879. if (s->lookahead < MIN_LOOKAHEAD) {
  77880. fill_window(s);
  77881. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77882. return need_more;
  77883. }
  77884. if (s->lookahead == 0) break; /* flush the current block */
  77885. }
  77886. if (s->lookahead >= MIN_MATCH) {
  77887. INSERT_STRING(s, s->strstart, hash_head);
  77888. }
  77889. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77890. s->match_length = MIN_MATCH-1;
  77891. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77892. s->strstart - hash_head <= MAX_DIST(s)) {
  77893. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77894. s->match_length = longest_match (s, hash_head);
  77895. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77896. s->match_length = longest_match_fast (s, hash_head);
  77897. }
  77898. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77899. #if TOO_FAR <= 32767
  77900. || (s->match_length == MIN_MATCH &&
  77901. s->strstart - s->match_start > TOO_FAR)
  77902. #endif
  77903. )) {
  77904. s->match_length = MIN_MATCH-1;
  77905. }
  77906. }
  77907. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77908. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77909. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77910. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77911. s->prev_length - MIN_MATCH, bflush);
  77912. s->lookahead -= s->prev_length-1;
  77913. s->prev_length -= 2;
  77914. do {
  77915. if (++s->strstart <= max_insert) {
  77916. INSERT_STRING(s, s->strstart, hash_head);
  77917. }
  77918. } while (--s->prev_length != 0);
  77919. s->match_available = 0;
  77920. s->match_length = MIN_MATCH-1;
  77921. s->strstart++;
  77922. if (bflush) FLUSH_BLOCK(s, 0);
  77923. } else if (s->match_available) {
  77924. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77925. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77926. if (bflush) {
  77927. FLUSH_BLOCK_ONLY(s, 0);
  77928. }
  77929. s->strstart++;
  77930. s->lookahead--;
  77931. if (s->strm->avail_out == 0) return need_more;
  77932. } else {
  77933. s->match_available = 1;
  77934. s->strstart++;
  77935. s->lookahead--;
  77936. }
  77937. }
  77938. Assert (flush != Z_NO_FLUSH, "no flush?");
  77939. if (s->match_available) {
  77940. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77941. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77942. s->match_available = 0;
  77943. }
  77944. FLUSH_BLOCK(s, flush == Z_FINISH);
  77945. return flush == Z_FINISH ? finish_done : block_done;
  77946. }
  77947. #endif /* FASTEST */
  77948. #if 0
  77949. local block_state deflate_rle(s, flush)
  77950. deflate_state *s;
  77951. int flush;
  77952. {
  77953. int bflush; /* set if current block must be flushed */
  77954. uInt run; /* length of run */
  77955. uInt max; /* maximum length of run */
  77956. uInt prev; /* byte at distance one to match */
  77957. Bytef *scan; /* scan for end of run */
  77958. for (;;) {
  77959. if (s->lookahead < MAX_MATCH) {
  77960. fill_window(s);
  77961. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77962. return need_more;
  77963. }
  77964. if (s->lookahead == 0) break; /* flush the current block */
  77965. }
  77966. run = 0;
  77967. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77968. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77969. scan = s->window + s->strstart - 1;
  77970. prev = *scan++;
  77971. do {
  77972. if (*scan++ != prev)
  77973. break;
  77974. } while (++run < max);
  77975. }
  77976. if (run >= MIN_MATCH) {
  77977. check_match(s, s->strstart, s->strstart - 1, run);
  77978. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77979. s->lookahead -= run;
  77980. s->strstart += run;
  77981. } else {
  77982. Tracevv((stderr,"%c", s->window[s->strstart]));
  77983. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77984. s->lookahead--;
  77985. s->strstart++;
  77986. }
  77987. if (bflush) FLUSH_BLOCK(s, 0);
  77988. }
  77989. FLUSH_BLOCK(s, flush == Z_FINISH);
  77990. return flush == Z_FINISH ? finish_done : block_done;
  77991. }
  77992. #endif
  77993. /*** End of inlined file: deflate.c ***/
  77994. /*** Start of inlined file: inffast.c ***/
  77995. /*** Start of inlined file: inftrees.h ***/
  77996. #ifndef _INFTREES_H_
  77997. #define _INFTREES_H_
  77998. typedef struct {
  77999. unsigned char op; /* operation, extra bits, table bits */
  78000. unsigned char bits; /* bits in this part of the code */
  78001. unsigned short val; /* offset in table or code value */
  78002. } code;
  78003. #define ENOUGH 2048
  78004. #define MAXD 592
  78005. typedef enum {
  78006. CODES,
  78007. LENS,
  78008. DISTS
  78009. } codetype;
  78010. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  78011. unsigned codes, code FAR * FAR *table,
  78012. unsigned FAR *bits, unsigned short FAR *work));
  78013. #endif
  78014. /*** End of inlined file: inftrees.h ***/
  78015. /*** Start of inlined file: inflate.h ***/
  78016. #ifndef _INFLATE_H_
  78017. #define _INFLATE_H_
  78018. #ifndef NO_GZIP
  78019. # define GUNZIP
  78020. #endif
  78021. typedef enum {
  78022. HEAD, /* i: waiting for magic header */
  78023. FLAGS, /* i: waiting for method and flags (gzip) */
  78024. TIME, /* i: waiting for modification time (gzip) */
  78025. OS, /* i: waiting for extra flags and operating system (gzip) */
  78026. EXLEN, /* i: waiting for extra length (gzip) */
  78027. EXTRA, /* i: waiting for extra bytes (gzip) */
  78028. NAME, /* i: waiting for end of file name (gzip) */
  78029. COMMENT, /* i: waiting for end of comment (gzip) */
  78030. HCRC, /* i: waiting for header crc (gzip) */
  78031. DICTID, /* i: waiting for dictionary check value */
  78032. DICT, /* waiting for inflateSetDictionary() call */
  78033. TYPE, /* i: waiting for type bits, including last-flag bit */
  78034. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  78035. STORED, /* i: waiting for stored size (length and complement) */
  78036. COPY, /* i/o: waiting for input or output to copy stored block */
  78037. TABLE, /* i: waiting for dynamic block table lengths */
  78038. LENLENS, /* i: waiting for code length code lengths */
  78039. CODELENS, /* i: waiting for length/lit and distance code lengths */
  78040. LEN, /* i: waiting for length/lit code */
  78041. LENEXT, /* i: waiting for length extra bits */
  78042. DIST, /* i: waiting for distance code */
  78043. DISTEXT, /* i: waiting for distance extra bits */
  78044. MATCH, /* o: waiting for output space to copy string */
  78045. LIT, /* o: waiting for output space to write literal */
  78046. CHECK, /* i: waiting for 32-bit check value */
  78047. LENGTH, /* i: waiting for 32-bit length (gzip) */
  78048. DONE, /* finished check, done -- remain here until reset */
  78049. BAD, /* got a data error -- remain here until reset */
  78050. MEM, /* got an inflate() memory error -- remain here until reset */
  78051. SYNC /* looking for synchronization bytes to restart inflate() */
  78052. } inflate_mode;
  78053. struct inflate_state {
  78054. inflate_mode mode; /* current inflate mode */
  78055. int last; /* true if processing last block */
  78056. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  78057. int havedict; /* true if dictionary provided */
  78058. int flags; /* gzip header method and flags (0 if zlib) */
  78059. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  78060. unsigned long check; /* protected copy of check value */
  78061. unsigned long total; /* protected copy of output count */
  78062. gz_headerp head; /* where to save gzip header information */
  78063. unsigned wbits; /* log base 2 of requested window size */
  78064. unsigned wsize; /* window size or zero if not using window */
  78065. unsigned whave; /* valid bytes in the window */
  78066. unsigned write; /* window write index */
  78067. unsigned char FAR *window; /* allocated sliding window, if needed */
  78068. unsigned long hold; /* input bit accumulator */
  78069. unsigned bits; /* number of bits in "in" */
  78070. unsigned length; /* literal or length of data to copy */
  78071. unsigned offset; /* distance back to copy string from */
  78072. unsigned extra; /* extra bits needed */
  78073. code const FAR *lencode; /* starting table for length/literal codes */
  78074. code const FAR *distcode; /* starting table for distance codes */
  78075. unsigned lenbits; /* index bits for lencode */
  78076. unsigned distbits; /* index bits for distcode */
  78077. unsigned ncode; /* number of code length code lengths */
  78078. unsigned nlen; /* number of length code lengths */
  78079. unsigned ndist; /* number of distance code lengths */
  78080. unsigned have; /* number of code lengths in lens[] */
  78081. code FAR *next; /* next available space in codes[] */
  78082. unsigned short lens[320]; /* temporary storage for code lengths */
  78083. unsigned short work[288]; /* work area for code table building */
  78084. code codes[ENOUGH]; /* space for code tables */
  78085. };
  78086. #endif
  78087. /*** End of inlined file: inflate.h ***/
  78088. /*** Start of inlined file: inffast.h ***/
  78089. void inflate_fast OF((z_streamp strm, unsigned start));
  78090. /*** End of inlined file: inffast.h ***/
  78091. #ifndef ASMINF
  78092. #ifdef POSTINC
  78093. # define OFF 0
  78094. # define PUP(a) *(a)++
  78095. #else
  78096. # define OFF 1
  78097. # define PUP(a) *++(a)
  78098. #endif
  78099. void inflate_fast (z_streamp strm, unsigned start)
  78100. {
  78101. struct inflate_state FAR *state;
  78102. unsigned char FAR *in; /* local strm->next_in */
  78103. unsigned char FAR *last; /* while in < last, enough input available */
  78104. unsigned char FAR *out; /* local strm->next_out */
  78105. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  78106. unsigned char FAR *end; /* while out < end, enough space available */
  78107. #ifdef INFLATE_STRICT
  78108. unsigned dmax; /* maximum distance from zlib header */
  78109. #endif
  78110. unsigned wsize; /* window size or zero if not using window */
  78111. unsigned whave; /* valid bytes in the window */
  78112. unsigned write; /* window write index */
  78113. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  78114. unsigned long hold; /* local strm->hold */
  78115. unsigned bits; /* local strm->bits */
  78116. code const FAR *lcode; /* local strm->lencode */
  78117. code const FAR *dcode; /* local strm->distcode */
  78118. unsigned lmask; /* mask for first level of length codes */
  78119. unsigned dmask; /* mask for first level of distance codes */
  78120. code thisx; /* retrieved table entry */
  78121. unsigned op; /* code bits, operation, extra bits, or */
  78122. unsigned len; /* match length, unused bytes */
  78123. unsigned dist; /* match distance */
  78124. unsigned char FAR *from; /* where to copy match from */
  78125. state = (struct inflate_state FAR *)strm->state;
  78126. in = strm->next_in - OFF;
  78127. last = in + (strm->avail_in - 5);
  78128. out = strm->next_out - OFF;
  78129. beg = out - (start - strm->avail_out);
  78130. end = out + (strm->avail_out - 257);
  78131. #ifdef INFLATE_STRICT
  78132. dmax = state->dmax;
  78133. #endif
  78134. wsize = state->wsize;
  78135. whave = state->whave;
  78136. write = state->write;
  78137. window = state->window;
  78138. hold = state->hold;
  78139. bits = state->bits;
  78140. lcode = state->lencode;
  78141. dcode = state->distcode;
  78142. lmask = (1U << state->lenbits) - 1;
  78143. dmask = (1U << state->distbits) - 1;
  78144. do {
  78145. if (bits < 15) {
  78146. hold += (unsigned long)(PUP(in)) << bits;
  78147. bits += 8;
  78148. hold += (unsigned long)(PUP(in)) << bits;
  78149. bits += 8;
  78150. }
  78151. thisx = lcode[hold & lmask];
  78152. dolen:
  78153. op = (unsigned)(thisx.bits);
  78154. hold >>= op;
  78155. bits -= op;
  78156. op = (unsigned)(thisx.op);
  78157. if (op == 0) { /* literal */
  78158. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78159. "inflate: literal '%c'\n" :
  78160. "inflate: literal 0x%02x\n", thisx.val));
  78161. PUP(out) = (unsigned char)(thisx.val);
  78162. }
  78163. else if (op & 16) { /* length base */
  78164. len = (unsigned)(thisx.val);
  78165. op &= 15; /* number of extra bits */
  78166. if (op) {
  78167. if (bits < op) {
  78168. hold += (unsigned long)(PUP(in)) << bits;
  78169. bits += 8;
  78170. }
  78171. len += (unsigned)hold & ((1U << op) - 1);
  78172. hold >>= op;
  78173. bits -= op;
  78174. }
  78175. Tracevv((stderr, "inflate: length %u\n", len));
  78176. if (bits < 15) {
  78177. hold += (unsigned long)(PUP(in)) << bits;
  78178. bits += 8;
  78179. hold += (unsigned long)(PUP(in)) << bits;
  78180. bits += 8;
  78181. }
  78182. thisx = dcode[hold & dmask];
  78183. dodist:
  78184. op = (unsigned)(thisx.bits);
  78185. hold >>= op;
  78186. bits -= op;
  78187. op = (unsigned)(thisx.op);
  78188. if (op & 16) { /* distance base */
  78189. dist = (unsigned)(thisx.val);
  78190. op &= 15; /* number of extra bits */
  78191. if (bits < op) {
  78192. hold += (unsigned long)(PUP(in)) << bits;
  78193. bits += 8;
  78194. if (bits < op) {
  78195. hold += (unsigned long)(PUP(in)) << bits;
  78196. bits += 8;
  78197. }
  78198. }
  78199. dist += (unsigned)hold & ((1U << op) - 1);
  78200. #ifdef INFLATE_STRICT
  78201. if (dist > dmax) {
  78202. strm->msg = (char *)"invalid distance too far back";
  78203. state->mode = BAD;
  78204. break;
  78205. }
  78206. #endif
  78207. hold >>= op;
  78208. bits -= op;
  78209. Tracevv((stderr, "inflate: distance %u\n", dist));
  78210. op = (unsigned)(out - beg); /* max distance in output */
  78211. if (dist > op) { /* see if copy from window */
  78212. op = dist - op; /* distance back in window */
  78213. if (op > whave) {
  78214. strm->msg = (char *)"invalid distance too far back";
  78215. state->mode = BAD;
  78216. break;
  78217. }
  78218. from = window - OFF;
  78219. if (write == 0) { /* very common case */
  78220. from += wsize - op;
  78221. if (op < len) { /* some from window */
  78222. len -= op;
  78223. do {
  78224. PUP(out) = PUP(from);
  78225. } while (--op);
  78226. from = out - dist; /* rest from output */
  78227. }
  78228. }
  78229. else if (write < op) { /* wrap around window */
  78230. from += wsize + write - op;
  78231. op -= write;
  78232. if (op < len) { /* some from end of window */
  78233. len -= op;
  78234. do {
  78235. PUP(out) = PUP(from);
  78236. } while (--op);
  78237. from = window - OFF;
  78238. if (write < len) { /* some from start of window */
  78239. op = write;
  78240. len -= op;
  78241. do {
  78242. PUP(out) = PUP(from);
  78243. } while (--op);
  78244. from = out - dist; /* rest from output */
  78245. }
  78246. }
  78247. }
  78248. else { /* contiguous in window */
  78249. from += write - op;
  78250. if (op < len) { /* some from window */
  78251. len -= op;
  78252. do {
  78253. PUP(out) = PUP(from);
  78254. } while (--op);
  78255. from = out - dist; /* rest from output */
  78256. }
  78257. }
  78258. while (len > 2) {
  78259. PUP(out) = PUP(from);
  78260. PUP(out) = PUP(from);
  78261. PUP(out) = PUP(from);
  78262. len -= 3;
  78263. }
  78264. if (len) {
  78265. PUP(out) = PUP(from);
  78266. if (len > 1)
  78267. PUP(out) = PUP(from);
  78268. }
  78269. }
  78270. else {
  78271. from = out - dist; /* copy direct from output */
  78272. do { /* minimum length is three */
  78273. PUP(out) = PUP(from);
  78274. PUP(out) = PUP(from);
  78275. PUP(out) = PUP(from);
  78276. len -= 3;
  78277. } while (len > 2);
  78278. if (len) {
  78279. PUP(out) = PUP(from);
  78280. if (len > 1)
  78281. PUP(out) = PUP(from);
  78282. }
  78283. }
  78284. }
  78285. else if ((op & 64) == 0) { /* 2nd level distance code */
  78286. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78287. goto dodist;
  78288. }
  78289. else {
  78290. strm->msg = (char *)"invalid distance code";
  78291. state->mode = BAD;
  78292. break;
  78293. }
  78294. }
  78295. else if ((op & 64) == 0) { /* 2nd level length code */
  78296. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78297. goto dolen;
  78298. }
  78299. else if (op & 32) { /* end-of-block */
  78300. Tracevv((stderr, "inflate: end of block\n"));
  78301. state->mode = TYPE;
  78302. break;
  78303. }
  78304. else {
  78305. strm->msg = (char *)"invalid literal/length code";
  78306. state->mode = BAD;
  78307. break;
  78308. }
  78309. } while (in < last && out < end);
  78310. len = bits >> 3;
  78311. in -= len;
  78312. bits -= len << 3;
  78313. hold &= (1U << bits) - 1;
  78314. strm->next_in = in + OFF;
  78315. strm->next_out = out + OFF;
  78316. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78317. strm->avail_out = (unsigned)(out < end ?
  78318. 257 + (end - out) : 257 - (out - end));
  78319. state->hold = hold;
  78320. state->bits = bits;
  78321. return;
  78322. }
  78323. #endif /* !ASMINF */
  78324. /*** End of inlined file: inffast.c ***/
  78325. #undef PULLBYTE
  78326. #undef LOAD
  78327. #undef RESTORE
  78328. #undef INITBITS
  78329. #undef NEEDBITS
  78330. #undef DROPBITS
  78331. #undef BYTEBITS
  78332. /*** Start of inlined file: inflate.c ***/
  78333. /*** Start of inlined file: inffast.h ***/
  78334. void inflate_fast OF((z_streamp strm, unsigned start));
  78335. /*** End of inlined file: inffast.h ***/
  78336. #ifdef MAKEFIXED
  78337. # ifndef BUILDFIXED
  78338. # define BUILDFIXED
  78339. # endif
  78340. #endif
  78341. local void fixedtables OF((struct inflate_state FAR *state));
  78342. local int updatewindow OF((z_streamp strm, unsigned out));
  78343. #ifdef BUILDFIXED
  78344. void makefixed OF((void));
  78345. #endif
  78346. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78347. unsigned len));
  78348. int ZEXPORT inflateReset (z_streamp strm)
  78349. {
  78350. struct inflate_state FAR *state;
  78351. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78352. state = (struct inflate_state FAR *)strm->state;
  78353. strm->total_in = strm->total_out = state->total = 0;
  78354. strm->msg = Z_NULL;
  78355. strm->adler = 1; /* to support ill-conceived Java test suite */
  78356. state->mode = HEAD;
  78357. state->last = 0;
  78358. state->havedict = 0;
  78359. state->dmax = 32768U;
  78360. state->head = Z_NULL;
  78361. state->wsize = 0;
  78362. state->whave = 0;
  78363. state->write = 0;
  78364. state->hold = 0;
  78365. state->bits = 0;
  78366. state->lencode = state->distcode = state->next = state->codes;
  78367. Tracev((stderr, "inflate: reset\n"));
  78368. return Z_OK;
  78369. }
  78370. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78371. {
  78372. struct inflate_state FAR *state;
  78373. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78374. state = (struct inflate_state FAR *)strm->state;
  78375. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78376. value &= (1L << bits) - 1;
  78377. state->hold += value << state->bits;
  78378. state->bits += bits;
  78379. return Z_OK;
  78380. }
  78381. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78382. {
  78383. struct inflate_state FAR *state;
  78384. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78385. stream_size != (int)(sizeof(z_stream)))
  78386. return Z_VERSION_ERROR;
  78387. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78388. strm->msg = Z_NULL; /* in case we return an error */
  78389. if (strm->zalloc == (alloc_func)0) {
  78390. strm->zalloc = zcalloc;
  78391. strm->opaque = (voidpf)0;
  78392. }
  78393. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78394. state = (struct inflate_state FAR *)
  78395. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78396. if (state == Z_NULL) return Z_MEM_ERROR;
  78397. Tracev((stderr, "inflate: allocated\n"));
  78398. strm->state = (struct internal_state FAR *)state;
  78399. if (windowBits < 0) {
  78400. state->wrap = 0;
  78401. windowBits = -windowBits;
  78402. }
  78403. else {
  78404. state->wrap = (windowBits >> 4) + 1;
  78405. #ifdef GUNZIP
  78406. if (windowBits < 48) windowBits &= 15;
  78407. #endif
  78408. }
  78409. if (windowBits < 8 || windowBits > 15) {
  78410. ZFREE(strm, state);
  78411. strm->state = Z_NULL;
  78412. return Z_STREAM_ERROR;
  78413. }
  78414. state->wbits = (unsigned)windowBits;
  78415. state->window = Z_NULL;
  78416. return inflateReset(strm);
  78417. }
  78418. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78419. {
  78420. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78421. }
  78422. local void fixedtables (struct inflate_state FAR *state)
  78423. {
  78424. #ifdef BUILDFIXED
  78425. static int virgin = 1;
  78426. static code *lenfix, *distfix;
  78427. static code fixed[544];
  78428. if (virgin) {
  78429. unsigned sym, bits;
  78430. static code *next;
  78431. sym = 0;
  78432. while (sym < 144) state->lens[sym++] = 8;
  78433. while (sym < 256) state->lens[sym++] = 9;
  78434. while (sym < 280) state->lens[sym++] = 7;
  78435. while (sym < 288) state->lens[sym++] = 8;
  78436. next = fixed;
  78437. lenfix = next;
  78438. bits = 9;
  78439. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78440. sym = 0;
  78441. while (sym < 32) state->lens[sym++] = 5;
  78442. distfix = next;
  78443. bits = 5;
  78444. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78445. virgin = 0;
  78446. }
  78447. #else /* !BUILDFIXED */
  78448. /*** Start of inlined file: inffixed.h ***/
  78449. static const code lenfix[512] = {
  78450. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78451. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78452. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78453. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78454. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78455. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78456. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78457. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78458. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78459. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78460. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78461. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78462. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78463. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78464. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78465. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78466. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78467. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78468. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78469. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78470. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78471. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78472. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78473. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78474. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78475. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78476. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78477. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78478. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78479. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78480. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78481. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78482. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78483. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78484. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78485. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78486. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78487. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78488. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78489. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78490. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78491. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78492. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78493. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78494. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78495. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78496. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78497. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78498. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78499. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78500. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78501. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78502. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78503. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78504. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78505. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78506. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78507. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78508. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78509. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78510. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78511. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78512. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78513. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78514. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78515. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78516. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78517. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78518. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78519. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78520. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78521. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78522. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78523. {0,9,255}
  78524. };
  78525. static const code distfix[32] = {
  78526. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78527. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78528. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78529. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78530. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78531. {22,5,193},{64,5,0}
  78532. };
  78533. /*** End of inlined file: inffixed.h ***/
  78534. #endif /* BUILDFIXED */
  78535. state->lencode = lenfix;
  78536. state->lenbits = 9;
  78537. state->distcode = distfix;
  78538. state->distbits = 5;
  78539. }
  78540. #ifdef MAKEFIXED
  78541. #include <stdio.h>
  78542. void makefixed()
  78543. {
  78544. unsigned low, size;
  78545. struct inflate_state state;
  78546. fixedtables(&state);
  78547. puts(" /* inffixed.h -- table for decoding fixed codes");
  78548. puts(" * Generated automatically by makefixed().");
  78549. puts(" */");
  78550. puts("");
  78551. puts(" /* WARNING: this file should *not* be used by applications.");
  78552. puts(" It is part of the implementation of this library and is");
  78553. puts(" subject to change. Applications should only use zlib.h.");
  78554. puts(" */");
  78555. puts("");
  78556. size = 1U << 9;
  78557. printf(" static const code lenfix[%u] = {", size);
  78558. low = 0;
  78559. for (;;) {
  78560. if ((low % 7) == 0) printf("\n ");
  78561. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78562. state.lencode[low].val);
  78563. if (++low == size) break;
  78564. putchar(',');
  78565. }
  78566. puts("\n };");
  78567. size = 1U << 5;
  78568. printf("\n static const code distfix[%u] = {", size);
  78569. low = 0;
  78570. for (;;) {
  78571. if ((low % 6) == 0) printf("\n ");
  78572. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78573. state.distcode[low].val);
  78574. if (++low == size) break;
  78575. putchar(',');
  78576. }
  78577. puts("\n };");
  78578. }
  78579. #endif /* MAKEFIXED */
  78580. local int updatewindow (z_streamp strm, unsigned out)
  78581. {
  78582. struct inflate_state FAR *state;
  78583. unsigned copy, dist;
  78584. state = (struct inflate_state FAR *)strm->state;
  78585. if (state->window == Z_NULL) {
  78586. state->window = (unsigned char FAR *)
  78587. ZALLOC(strm, 1U << state->wbits,
  78588. sizeof(unsigned char));
  78589. if (state->window == Z_NULL) return 1;
  78590. }
  78591. if (state->wsize == 0) {
  78592. state->wsize = 1U << state->wbits;
  78593. state->write = 0;
  78594. state->whave = 0;
  78595. }
  78596. copy = out - strm->avail_out;
  78597. if (copy >= state->wsize) {
  78598. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78599. state->write = 0;
  78600. state->whave = state->wsize;
  78601. }
  78602. else {
  78603. dist = state->wsize - state->write;
  78604. if (dist > copy) dist = copy;
  78605. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78606. copy -= dist;
  78607. if (copy) {
  78608. zmemcpy(state->window, strm->next_out - copy, copy);
  78609. state->write = copy;
  78610. state->whave = state->wsize;
  78611. }
  78612. else {
  78613. state->write += dist;
  78614. if (state->write == state->wsize) state->write = 0;
  78615. if (state->whave < state->wsize) state->whave += dist;
  78616. }
  78617. }
  78618. return 0;
  78619. }
  78620. #ifdef GUNZIP
  78621. # define UPDATE(check, buf, len) \
  78622. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78623. #else
  78624. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78625. #endif
  78626. #ifdef GUNZIP
  78627. # define CRC2(check, word) \
  78628. do { \
  78629. hbuf[0] = (unsigned char)(word); \
  78630. hbuf[1] = (unsigned char)((word) >> 8); \
  78631. check = crc32(check, hbuf, 2); \
  78632. } while (0)
  78633. # define CRC4(check, word) \
  78634. do { \
  78635. hbuf[0] = (unsigned char)(word); \
  78636. hbuf[1] = (unsigned char)((word) >> 8); \
  78637. hbuf[2] = (unsigned char)((word) >> 16); \
  78638. hbuf[3] = (unsigned char)((word) >> 24); \
  78639. check = crc32(check, hbuf, 4); \
  78640. } while (0)
  78641. #endif
  78642. #define LOAD() \
  78643. do { \
  78644. put = strm->next_out; \
  78645. left = strm->avail_out; \
  78646. next = strm->next_in; \
  78647. have = strm->avail_in; \
  78648. hold = state->hold; \
  78649. bits = state->bits; \
  78650. } while (0)
  78651. #define RESTORE() \
  78652. do { \
  78653. strm->next_out = put; \
  78654. strm->avail_out = left; \
  78655. strm->next_in = next; \
  78656. strm->avail_in = have; \
  78657. state->hold = hold; \
  78658. state->bits = bits; \
  78659. } while (0)
  78660. #define INITBITS() \
  78661. do { \
  78662. hold = 0; \
  78663. bits = 0; \
  78664. } while (0)
  78665. #define PULLBYTE() \
  78666. do { \
  78667. if (have == 0) goto inf_leave; \
  78668. have--; \
  78669. hold += (unsigned long)(*next++) << bits; \
  78670. bits += 8; \
  78671. } while (0)
  78672. #define NEEDBITS(n) \
  78673. do { \
  78674. while (bits < (unsigned)(n)) \
  78675. PULLBYTE(); \
  78676. } while (0)
  78677. #define BITS(n) \
  78678. ((unsigned)hold & ((1U << (n)) - 1))
  78679. #define DROPBITS(n) \
  78680. do { \
  78681. hold >>= (n); \
  78682. bits -= (unsigned)(n); \
  78683. } while (0)
  78684. #define BYTEBITS() \
  78685. do { \
  78686. hold >>= bits & 7; \
  78687. bits -= bits & 7; \
  78688. } while (0)
  78689. #define REVERSE(q) \
  78690. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78691. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78692. int ZEXPORT inflate (z_streamp strm, int flush)
  78693. {
  78694. struct inflate_state FAR *state;
  78695. unsigned char FAR *next; /* next input */
  78696. unsigned char FAR *put; /* next output */
  78697. unsigned have, left; /* available input and output */
  78698. unsigned long hold; /* bit buffer */
  78699. unsigned bits; /* bits in bit buffer */
  78700. unsigned in, out; /* save starting available input and output */
  78701. unsigned copy; /* number of stored or match bytes to copy */
  78702. unsigned char FAR *from; /* where to copy match bytes from */
  78703. code thisx; /* current decoding table entry */
  78704. code last; /* parent table entry */
  78705. unsigned len; /* length to copy for repeats, bits to drop */
  78706. int ret; /* return code */
  78707. #ifdef GUNZIP
  78708. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78709. #endif
  78710. static const unsigned short order[19] = /* permutation of code lengths */
  78711. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78712. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78713. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78714. return Z_STREAM_ERROR;
  78715. state = (struct inflate_state FAR *)strm->state;
  78716. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78717. LOAD();
  78718. in = have;
  78719. out = left;
  78720. ret = Z_OK;
  78721. for (;;)
  78722. switch (state->mode) {
  78723. case HEAD:
  78724. if (state->wrap == 0) {
  78725. state->mode = TYPEDO;
  78726. break;
  78727. }
  78728. NEEDBITS(16);
  78729. #ifdef GUNZIP
  78730. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78731. state->check = crc32(0L, Z_NULL, 0);
  78732. CRC2(state->check, hold);
  78733. INITBITS();
  78734. state->mode = FLAGS;
  78735. break;
  78736. }
  78737. state->flags = 0; /* expect zlib header */
  78738. if (state->head != Z_NULL)
  78739. state->head->done = -1;
  78740. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78741. #else
  78742. if (
  78743. #endif
  78744. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78745. strm->msg = (char *)"incorrect header check";
  78746. state->mode = BAD;
  78747. break;
  78748. }
  78749. if (BITS(4) != Z_DEFLATED) {
  78750. strm->msg = (char *)"unknown compression method";
  78751. state->mode = BAD;
  78752. break;
  78753. }
  78754. DROPBITS(4);
  78755. len = BITS(4) + 8;
  78756. if (len > state->wbits) {
  78757. strm->msg = (char *)"invalid window size";
  78758. state->mode = BAD;
  78759. break;
  78760. }
  78761. state->dmax = 1U << len;
  78762. Tracev((stderr, "inflate: zlib header ok\n"));
  78763. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78764. state->mode = hold & 0x200 ? DICTID : TYPE;
  78765. INITBITS();
  78766. break;
  78767. #ifdef GUNZIP
  78768. case FLAGS:
  78769. NEEDBITS(16);
  78770. state->flags = (int)(hold);
  78771. if ((state->flags & 0xff) != Z_DEFLATED) {
  78772. strm->msg = (char *)"unknown compression method";
  78773. state->mode = BAD;
  78774. break;
  78775. }
  78776. if (state->flags & 0xe000) {
  78777. strm->msg = (char *)"unknown header flags set";
  78778. state->mode = BAD;
  78779. break;
  78780. }
  78781. if (state->head != Z_NULL)
  78782. state->head->text = (int)((hold >> 8) & 1);
  78783. if (state->flags & 0x0200) CRC2(state->check, hold);
  78784. INITBITS();
  78785. state->mode = TIME;
  78786. case TIME:
  78787. NEEDBITS(32);
  78788. if (state->head != Z_NULL)
  78789. state->head->time = hold;
  78790. if (state->flags & 0x0200) CRC4(state->check, hold);
  78791. INITBITS();
  78792. state->mode = OS;
  78793. case OS:
  78794. NEEDBITS(16);
  78795. if (state->head != Z_NULL) {
  78796. state->head->xflags = (int)(hold & 0xff);
  78797. state->head->os = (int)(hold >> 8);
  78798. }
  78799. if (state->flags & 0x0200) CRC2(state->check, hold);
  78800. INITBITS();
  78801. state->mode = EXLEN;
  78802. case EXLEN:
  78803. if (state->flags & 0x0400) {
  78804. NEEDBITS(16);
  78805. state->length = (unsigned)(hold);
  78806. if (state->head != Z_NULL)
  78807. state->head->extra_len = (unsigned)hold;
  78808. if (state->flags & 0x0200) CRC2(state->check, hold);
  78809. INITBITS();
  78810. }
  78811. else if (state->head != Z_NULL)
  78812. state->head->extra = Z_NULL;
  78813. state->mode = EXTRA;
  78814. case EXTRA:
  78815. if (state->flags & 0x0400) {
  78816. copy = state->length;
  78817. if (copy > have) copy = have;
  78818. if (copy) {
  78819. if (state->head != Z_NULL &&
  78820. state->head->extra != Z_NULL) {
  78821. len = state->head->extra_len - state->length;
  78822. zmemcpy(state->head->extra + len, next,
  78823. len + copy > state->head->extra_max ?
  78824. state->head->extra_max - len : copy);
  78825. }
  78826. if (state->flags & 0x0200)
  78827. state->check = crc32(state->check, next, copy);
  78828. have -= copy;
  78829. next += copy;
  78830. state->length -= copy;
  78831. }
  78832. if (state->length) goto inf_leave;
  78833. }
  78834. state->length = 0;
  78835. state->mode = NAME;
  78836. case NAME:
  78837. if (state->flags & 0x0800) {
  78838. if (have == 0) goto inf_leave;
  78839. copy = 0;
  78840. do {
  78841. len = (unsigned)(next[copy++]);
  78842. if (state->head != Z_NULL &&
  78843. state->head->name != Z_NULL &&
  78844. state->length < state->head->name_max)
  78845. state->head->name[state->length++] = len;
  78846. } while (len && copy < have);
  78847. if (state->flags & 0x0200)
  78848. state->check = crc32(state->check, next, copy);
  78849. have -= copy;
  78850. next += copy;
  78851. if (len) goto inf_leave;
  78852. }
  78853. else if (state->head != Z_NULL)
  78854. state->head->name = Z_NULL;
  78855. state->length = 0;
  78856. state->mode = COMMENT;
  78857. case COMMENT:
  78858. if (state->flags & 0x1000) {
  78859. if (have == 0) goto inf_leave;
  78860. copy = 0;
  78861. do {
  78862. len = (unsigned)(next[copy++]);
  78863. if (state->head != Z_NULL &&
  78864. state->head->comment != Z_NULL &&
  78865. state->length < state->head->comm_max)
  78866. state->head->comment[state->length++] = len;
  78867. } while (len && copy < have);
  78868. if (state->flags & 0x0200)
  78869. state->check = crc32(state->check, next, copy);
  78870. have -= copy;
  78871. next += copy;
  78872. if (len) goto inf_leave;
  78873. }
  78874. else if (state->head != Z_NULL)
  78875. state->head->comment = Z_NULL;
  78876. state->mode = HCRC;
  78877. case HCRC:
  78878. if (state->flags & 0x0200) {
  78879. NEEDBITS(16);
  78880. if (hold != (state->check & 0xffff)) {
  78881. strm->msg = (char *)"header crc mismatch";
  78882. state->mode = BAD;
  78883. break;
  78884. }
  78885. INITBITS();
  78886. }
  78887. if (state->head != Z_NULL) {
  78888. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78889. state->head->done = 1;
  78890. }
  78891. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78892. state->mode = TYPE;
  78893. break;
  78894. #endif
  78895. case DICTID:
  78896. NEEDBITS(32);
  78897. strm->adler = state->check = REVERSE(hold);
  78898. INITBITS();
  78899. state->mode = DICT;
  78900. case DICT:
  78901. if (state->havedict == 0) {
  78902. RESTORE();
  78903. return Z_NEED_DICT;
  78904. }
  78905. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78906. state->mode = TYPE;
  78907. case TYPE:
  78908. if (flush == Z_BLOCK) goto inf_leave;
  78909. case TYPEDO:
  78910. if (state->last) {
  78911. BYTEBITS();
  78912. state->mode = CHECK;
  78913. break;
  78914. }
  78915. NEEDBITS(3);
  78916. state->last = BITS(1);
  78917. DROPBITS(1);
  78918. switch (BITS(2)) {
  78919. case 0: /* stored block */
  78920. Tracev((stderr, "inflate: stored block%s\n",
  78921. state->last ? " (last)" : ""));
  78922. state->mode = STORED;
  78923. break;
  78924. case 1: /* fixed block */
  78925. fixedtables(state);
  78926. Tracev((stderr, "inflate: fixed codes block%s\n",
  78927. state->last ? " (last)" : ""));
  78928. state->mode = LEN; /* decode codes */
  78929. break;
  78930. case 2: /* dynamic block */
  78931. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78932. state->last ? " (last)" : ""));
  78933. state->mode = TABLE;
  78934. break;
  78935. case 3:
  78936. strm->msg = (char *)"invalid block type";
  78937. state->mode = BAD;
  78938. }
  78939. DROPBITS(2);
  78940. break;
  78941. case STORED:
  78942. BYTEBITS(); /* go to byte boundary */
  78943. NEEDBITS(32);
  78944. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78945. strm->msg = (char *)"invalid stored block lengths";
  78946. state->mode = BAD;
  78947. break;
  78948. }
  78949. state->length = (unsigned)hold & 0xffff;
  78950. Tracev((stderr, "inflate: stored length %u\n",
  78951. state->length));
  78952. INITBITS();
  78953. state->mode = COPY;
  78954. case COPY:
  78955. copy = state->length;
  78956. if (copy) {
  78957. if (copy > have) copy = have;
  78958. if (copy > left) copy = left;
  78959. if (copy == 0) goto inf_leave;
  78960. zmemcpy(put, next, copy);
  78961. have -= copy;
  78962. next += copy;
  78963. left -= copy;
  78964. put += copy;
  78965. state->length -= copy;
  78966. break;
  78967. }
  78968. Tracev((stderr, "inflate: stored end\n"));
  78969. state->mode = TYPE;
  78970. break;
  78971. case TABLE:
  78972. NEEDBITS(14);
  78973. state->nlen = BITS(5) + 257;
  78974. DROPBITS(5);
  78975. state->ndist = BITS(5) + 1;
  78976. DROPBITS(5);
  78977. state->ncode = BITS(4) + 4;
  78978. DROPBITS(4);
  78979. #ifndef PKZIP_BUG_WORKAROUND
  78980. if (state->nlen > 286 || state->ndist > 30) {
  78981. strm->msg = (char *)"too many length or distance symbols";
  78982. state->mode = BAD;
  78983. break;
  78984. }
  78985. #endif
  78986. Tracev((stderr, "inflate: table sizes ok\n"));
  78987. state->have = 0;
  78988. state->mode = LENLENS;
  78989. case LENLENS:
  78990. while (state->have < state->ncode) {
  78991. NEEDBITS(3);
  78992. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78993. DROPBITS(3);
  78994. }
  78995. while (state->have < 19)
  78996. state->lens[order[state->have++]] = 0;
  78997. state->next = state->codes;
  78998. state->lencode = (code const FAR *)(state->next);
  78999. state->lenbits = 7;
  79000. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  79001. &(state->lenbits), state->work);
  79002. if (ret) {
  79003. strm->msg = (char *)"invalid code lengths set";
  79004. state->mode = BAD;
  79005. break;
  79006. }
  79007. Tracev((stderr, "inflate: code lengths ok\n"));
  79008. state->have = 0;
  79009. state->mode = CODELENS;
  79010. case CODELENS:
  79011. while (state->have < state->nlen + state->ndist) {
  79012. for (;;) {
  79013. thisx = state->lencode[BITS(state->lenbits)];
  79014. if ((unsigned)(thisx.bits) <= bits) break;
  79015. PULLBYTE();
  79016. }
  79017. if (thisx.val < 16) {
  79018. NEEDBITS(thisx.bits);
  79019. DROPBITS(thisx.bits);
  79020. state->lens[state->have++] = thisx.val;
  79021. }
  79022. else {
  79023. if (thisx.val == 16) {
  79024. NEEDBITS(thisx.bits + 2);
  79025. DROPBITS(thisx.bits);
  79026. if (state->have == 0) {
  79027. strm->msg = (char *)"invalid bit length repeat";
  79028. state->mode = BAD;
  79029. break;
  79030. }
  79031. len = state->lens[state->have - 1];
  79032. copy = 3 + BITS(2);
  79033. DROPBITS(2);
  79034. }
  79035. else if (thisx.val == 17) {
  79036. NEEDBITS(thisx.bits + 3);
  79037. DROPBITS(thisx.bits);
  79038. len = 0;
  79039. copy = 3 + BITS(3);
  79040. DROPBITS(3);
  79041. }
  79042. else {
  79043. NEEDBITS(thisx.bits + 7);
  79044. DROPBITS(thisx.bits);
  79045. len = 0;
  79046. copy = 11 + BITS(7);
  79047. DROPBITS(7);
  79048. }
  79049. if (state->have + copy > state->nlen + state->ndist) {
  79050. strm->msg = (char *)"invalid bit length repeat";
  79051. state->mode = BAD;
  79052. break;
  79053. }
  79054. while (copy--)
  79055. state->lens[state->have++] = (unsigned short)len;
  79056. }
  79057. }
  79058. if (state->mode == BAD) break;
  79059. state->next = state->codes;
  79060. state->lencode = (code const FAR *)(state->next);
  79061. state->lenbits = 9;
  79062. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  79063. &(state->lenbits), state->work);
  79064. if (ret) {
  79065. strm->msg = (char *)"invalid literal/lengths set";
  79066. state->mode = BAD;
  79067. break;
  79068. }
  79069. state->distcode = (code const FAR *)(state->next);
  79070. state->distbits = 6;
  79071. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  79072. &(state->next), &(state->distbits), state->work);
  79073. if (ret) {
  79074. strm->msg = (char *)"invalid distances set";
  79075. state->mode = BAD;
  79076. break;
  79077. }
  79078. Tracev((stderr, "inflate: codes ok\n"));
  79079. state->mode = LEN;
  79080. case LEN:
  79081. if (have >= 6 && left >= 258) {
  79082. RESTORE();
  79083. inflate_fast(strm, out);
  79084. LOAD();
  79085. break;
  79086. }
  79087. for (;;) {
  79088. thisx = state->lencode[BITS(state->lenbits)];
  79089. if ((unsigned)(thisx.bits) <= bits) break;
  79090. PULLBYTE();
  79091. }
  79092. if (thisx.op && (thisx.op & 0xf0) == 0) {
  79093. last = thisx;
  79094. for (;;) {
  79095. thisx = state->lencode[last.val +
  79096. (BITS(last.bits + last.op) >> last.bits)];
  79097. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79098. PULLBYTE();
  79099. }
  79100. DROPBITS(last.bits);
  79101. }
  79102. DROPBITS(thisx.bits);
  79103. state->length = (unsigned)thisx.val;
  79104. if ((int)(thisx.op) == 0) {
  79105. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  79106. "inflate: literal '%c'\n" :
  79107. "inflate: literal 0x%02x\n", thisx.val));
  79108. state->mode = LIT;
  79109. break;
  79110. }
  79111. if (thisx.op & 32) {
  79112. Tracevv((stderr, "inflate: end of block\n"));
  79113. state->mode = TYPE;
  79114. break;
  79115. }
  79116. if (thisx.op & 64) {
  79117. strm->msg = (char *)"invalid literal/length code";
  79118. state->mode = BAD;
  79119. break;
  79120. }
  79121. state->extra = (unsigned)(thisx.op) & 15;
  79122. state->mode = LENEXT;
  79123. case LENEXT:
  79124. if (state->extra) {
  79125. NEEDBITS(state->extra);
  79126. state->length += BITS(state->extra);
  79127. DROPBITS(state->extra);
  79128. }
  79129. Tracevv((stderr, "inflate: length %u\n", state->length));
  79130. state->mode = DIST;
  79131. case DIST:
  79132. for (;;) {
  79133. thisx = state->distcode[BITS(state->distbits)];
  79134. if ((unsigned)(thisx.bits) <= bits) break;
  79135. PULLBYTE();
  79136. }
  79137. if ((thisx.op & 0xf0) == 0) {
  79138. last = thisx;
  79139. for (;;) {
  79140. thisx = state->distcode[last.val +
  79141. (BITS(last.bits + last.op) >> last.bits)];
  79142. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79143. PULLBYTE();
  79144. }
  79145. DROPBITS(last.bits);
  79146. }
  79147. DROPBITS(thisx.bits);
  79148. if (thisx.op & 64) {
  79149. strm->msg = (char *)"invalid distance code";
  79150. state->mode = BAD;
  79151. break;
  79152. }
  79153. state->offset = (unsigned)thisx.val;
  79154. state->extra = (unsigned)(thisx.op) & 15;
  79155. state->mode = DISTEXT;
  79156. case DISTEXT:
  79157. if (state->extra) {
  79158. NEEDBITS(state->extra);
  79159. state->offset += BITS(state->extra);
  79160. DROPBITS(state->extra);
  79161. }
  79162. #ifdef INFLATE_STRICT
  79163. if (state->offset > state->dmax) {
  79164. strm->msg = (char *)"invalid distance too far back";
  79165. state->mode = BAD;
  79166. break;
  79167. }
  79168. #endif
  79169. if (state->offset > state->whave + out - left) {
  79170. strm->msg = (char *)"invalid distance too far back";
  79171. state->mode = BAD;
  79172. break;
  79173. }
  79174. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  79175. state->mode = MATCH;
  79176. case MATCH:
  79177. if (left == 0) goto inf_leave;
  79178. copy = out - left;
  79179. if (state->offset > copy) { /* copy from window */
  79180. copy = state->offset - copy;
  79181. if (copy > state->write) {
  79182. copy -= state->write;
  79183. from = state->window + (state->wsize - copy);
  79184. }
  79185. else
  79186. from = state->window + (state->write - copy);
  79187. if (copy > state->length) copy = state->length;
  79188. }
  79189. else { /* copy from output */
  79190. from = put - state->offset;
  79191. copy = state->length;
  79192. }
  79193. if (copy > left) copy = left;
  79194. left -= copy;
  79195. state->length -= copy;
  79196. do {
  79197. *put++ = *from++;
  79198. } while (--copy);
  79199. if (state->length == 0) state->mode = LEN;
  79200. break;
  79201. case LIT:
  79202. if (left == 0) goto inf_leave;
  79203. *put++ = (unsigned char)(state->length);
  79204. left--;
  79205. state->mode = LEN;
  79206. break;
  79207. case CHECK:
  79208. if (state->wrap) {
  79209. NEEDBITS(32);
  79210. out -= left;
  79211. strm->total_out += out;
  79212. state->total += out;
  79213. if (out)
  79214. strm->adler = state->check =
  79215. UPDATE(state->check, put - out, out);
  79216. out = left;
  79217. if ((
  79218. #ifdef GUNZIP
  79219. state->flags ? hold :
  79220. #endif
  79221. REVERSE(hold)) != state->check) {
  79222. strm->msg = (char *)"incorrect data check";
  79223. state->mode = BAD;
  79224. break;
  79225. }
  79226. INITBITS();
  79227. Tracev((stderr, "inflate: check matches trailer\n"));
  79228. }
  79229. #ifdef GUNZIP
  79230. state->mode = LENGTH;
  79231. case LENGTH:
  79232. if (state->wrap && state->flags) {
  79233. NEEDBITS(32);
  79234. if (hold != (state->total & 0xffffffffUL)) {
  79235. strm->msg = (char *)"incorrect length check";
  79236. state->mode = BAD;
  79237. break;
  79238. }
  79239. INITBITS();
  79240. Tracev((stderr, "inflate: length matches trailer\n"));
  79241. }
  79242. #endif
  79243. state->mode = DONE;
  79244. case DONE:
  79245. ret = Z_STREAM_END;
  79246. goto inf_leave;
  79247. case BAD:
  79248. ret = Z_DATA_ERROR;
  79249. goto inf_leave;
  79250. case MEM:
  79251. return Z_MEM_ERROR;
  79252. case SYNC:
  79253. default:
  79254. return Z_STREAM_ERROR;
  79255. }
  79256. inf_leave:
  79257. RESTORE();
  79258. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  79259. if (updatewindow(strm, out)) {
  79260. state->mode = MEM;
  79261. return Z_MEM_ERROR;
  79262. }
  79263. in -= strm->avail_in;
  79264. out -= strm->avail_out;
  79265. strm->total_in += in;
  79266. strm->total_out += out;
  79267. state->total += out;
  79268. if (state->wrap && out)
  79269. strm->adler = state->check =
  79270. UPDATE(state->check, strm->next_out - out, out);
  79271. strm->data_type = state->bits + (state->last ? 64 : 0) +
  79272. (state->mode == TYPE ? 128 : 0);
  79273. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  79274. ret = Z_BUF_ERROR;
  79275. return ret;
  79276. }
  79277. int ZEXPORT inflateEnd (z_streamp strm)
  79278. {
  79279. struct inflate_state FAR *state;
  79280. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  79281. return Z_STREAM_ERROR;
  79282. state = (struct inflate_state FAR *)strm->state;
  79283. if (state->window != Z_NULL) ZFREE(strm, state->window);
  79284. ZFREE(strm, strm->state);
  79285. strm->state = Z_NULL;
  79286. Tracev((stderr, "inflate: end\n"));
  79287. return Z_OK;
  79288. }
  79289. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79290. {
  79291. struct inflate_state FAR *state;
  79292. unsigned long id_;
  79293. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79294. state = (struct inflate_state FAR *)strm->state;
  79295. if (state->wrap != 0 && state->mode != DICT)
  79296. return Z_STREAM_ERROR;
  79297. if (state->mode == DICT) {
  79298. id_ = adler32(0L, Z_NULL, 0);
  79299. id_ = adler32(id_, dictionary, dictLength);
  79300. if (id_ != state->check)
  79301. return Z_DATA_ERROR;
  79302. }
  79303. if (updatewindow(strm, strm->avail_out)) {
  79304. state->mode = MEM;
  79305. return Z_MEM_ERROR;
  79306. }
  79307. if (dictLength > state->wsize) {
  79308. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79309. state->wsize);
  79310. state->whave = state->wsize;
  79311. }
  79312. else {
  79313. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79314. dictLength);
  79315. state->whave = dictLength;
  79316. }
  79317. state->havedict = 1;
  79318. Tracev((stderr, "inflate: dictionary set\n"));
  79319. return Z_OK;
  79320. }
  79321. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79322. {
  79323. struct inflate_state FAR *state;
  79324. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79325. state = (struct inflate_state FAR *)strm->state;
  79326. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79327. state->head = head;
  79328. head->done = 0;
  79329. return Z_OK;
  79330. }
  79331. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79332. {
  79333. unsigned got;
  79334. unsigned next;
  79335. got = *have;
  79336. next = 0;
  79337. while (next < len && got < 4) {
  79338. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79339. got++;
  79340. else if (buf[next])
  79341. got = 0;
  79342. else
  79343. got = 4 - got;
  79344. next++;
  79345. }
  79346. *have = got;
  79347. return next;
  79348. }
  79349. int ZEXPORT inflateSync (z_streamp strm)
  79350. {
  79351. unsigned len; /* number of bytes to look at or looked at */
  79352. unsigned long in, out; /* temporary to save total_in and total_out */
  79353. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79354. struct inflate_state FAR *state;
  79355. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79356. state = (struct inflate_state FAR *)strm->state;
  79357. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79358. if (state->mode != SYNC) {
  79359. state->mode = SYNC;
  79360. state->hold <<= state->bits & 7;
  79361. state->bits -= state->bits & 7;
  79362. len = 0;
  79363. while (state->bits >= 8) {
  79364. buf[len++] = (unsigned char)(state->hold);
  79365. state->hold >>= 8;
  79366. state->bits -= 8;
  79367. }
  79368. state->have = 0;
  79369. syncsearch(&(state->have), buf, len);
  79370. }
  79371. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79372. strm->avail_in -= len;
  79373. strm->next_in += len;
  79374. strm->total_in += len;
  79375. if (state->have != 4) return Z_DATA_ERROR;
  79376. in = strm->total_in; out = strm->total_out;
  79377. inflateReset(strm);
  79378. strm->total_in = in; strm->total_out = out;
  79379. state->mode = TYPE;
  79380. return Z_OK;
  79381. }
  79382. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79383. {
  79384. struct inflate_state FAR *state;
  79385. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79386. state = (struct inflate_state FAR *)strm->state;
  79387. return state->mode == STORED && state->bits == 0;
  79388. }
  79389. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79390. {
  79391. struct inflate_state FAR *state;
  79392. struct inflate_state FAR *copy;
  79393. unsigned char FAR *window;
  79394. unsigned wsize;
  79395. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79396. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79397. return Z_STREAM_ERROR;
  79398. state = (struct inflate_state FAR *)source->state;
  79399. copy = (struct inflate_state FAR *)
  79400. ZALLOC(source, 1, sizeof(struct inflate_state));
  79401. if (copy == Z_NULL) return Z_MEM_ERROR;
  79402. window = Z_NULL;
  79403. if (state->window != Z_NULL) {
  79404. window = (unsigned char FAR *)
  79405. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79406. if (window == Z_NULL) {
  79407. ZFREE(source, copy);
  79408. return Z_MEM_ERROR;
  79409. }
  79410. }
  79411. zmemcpy(dest, source, sizeof(z_stream));
  79412. zmemcpy(copy, state, sizeof(struct inflate_state));
  79413. if (state->lencode >= state->codes &&
  79414. state->lencode <= state->codes + ENOUGH - 1) {
  79415. copy->lencode = copy->codes + (state->lencode - state->codes);
  79416. copy->distcode = copy->codes + (state->distcode - state->codes);
  79417. }
  79418. copy->next = copy->codes + (state->next - state->codes);
  79419. if (window != Z_NULL) {
  79420. wsize = 1U << state->wbits;
  79421. zmemcpy(window, state->window, wsize);
  79422. }
  79423. copy->window = window;
  79424. dest->state = (struct internal_state FAR *)copy;
  79425. return Z_OK;
  79426. }
  79427. /*** End of inlined file: inflate.c ***/
  79428. /*** Start of inlined file: inftrees.c ***/
  79429. #define MAXBITS 15
  79430. const char inflate_copyright[] =
  79431. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79432. int inflate_table (codetype type,
  79433. unsigned short FAR *lens,
  79434. unsigned codes,
  79435. code FAR * FAR *table,
  79436. unsigned FAR *bits,
  79437. unsigned short FAR *work)
  79438. {
  79439. unsigned len; /* a code's length in bits */
  79440. unsigned sym; /* index of code symbols */
  79441. unsigned min, max; /* minimum and maximum code lengths */
  79442. unsigned root; /* number of index bits for root table */
  79443. unsigned curr; /* number of index bits for current table */
  79444. unsigned drop; /* code bits to drop for sub-table */
  79445. int left; /* number of prefix codes available */
  79446. unsigned used; /* code entries in table used */
  79447. unsigned huff; /* Huffman code */
  79448. unsigned incr; /* for incrementing code, index */
  79449. unsigned fill; /* index for replicating entries */
  79450. unsigned low; /* low bits for current root entry */
  79451. unsigned mask; /* mask for low root bits */
  79452. code thisx; /* table entry for duplication */
  79453. code FAR *next; /* next available space in table */
  79454. const unsigned short FAR *base; /* base value table to use */
  79455. const unsigned short FAR *extra; /* extra bits table to use */
  79456. int end; /* use base and extra for symbol > end */
  79457. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79458. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79459. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79460. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79461. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79462. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79463. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79464. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79465. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79466. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79467. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79468. 8193, 12289, 16385, 24577, 0, 0};
  79469. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79470. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79471. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79472. 28, 28, 29, 29, 64, 64};
  79473. for (len = 0; len <= MAXBITS; len++)
  79474. count[len] = 0;
  79475. for (sym = 0; sym < codes; sym++)
  79476. count[lens[sym]]++;
  79477. root = *bits;
  79478. for (max = MAXBITS; max >= 1; max--)
  79479. if (count[max] != 0) break;
  79480. if (root > max) root = max;
  79481. if (max == 0) { /* no symbols to code at all */
  79482. thisx.op = (unsigned char)64; /* invalid code marker */
  79483. thisx.bits = (unsigned char)1;
  79484. thisx.val = (unsigned short)0;
  79485. *(*table)++ = thisx; /* make a table to force an error */
  79486. *(*table)++ = thisx;
  79487. *bits = 1;
  79488. return 0; /* no symbols, but wait for decoding to report error */
  79489. }
  79490. for (min = 1; min <= MAXBITS; min++)
  79491. if (count[min] != 0) break;
  79492. if (root < min) root = min;
  79493. left = 1;
  79494. for (len = 1; len <= MAXBITS; len++) {
  79495. left <<= 1;
  79496. left -= count[len];
  79497. if (left < 0) return -1; /* over-subscribed */
  79498. }
  79499. if (left > 0 && (type == CODES || max != 1))
  79500. return -1; /* incomplete set */
  79501. offs[1] = 0;
  79502. for (len = 1; len < MAXBITS; len++)
  79503. offs[len + 1] = offs[len] + count[len];
  79504. for (sym = 0; sym < codes; sym++)
  79505. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79506. switch (type) {
  79507. case CODES:
  79508. base = extra = work; /* dummy value--not used */
  79509. end = 19;
  79510. break;
  79511. case LENS:
  79512. base = lbase;
  79513. base -= 257;
  79514. extra = lext;
  79515. extra -= 257;
  79516. end = 256;
  79517. break;
  79518. default: /* DISTS */
  79519. base = dbase;
  79520. extra = dext;
  79521. end = -1;
  79522. }
  79523. huff = 0; /* starting code */
  79524. sym = 0; /* starting code symbol */
  79525. len = min; /* starting code length */
  79526. next = *table; /* current table to fill in */
  79527. curr = root; /* current table index bits */
  79528. drop = 0; /* current bits to drop from code for index */
  79529. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79530. used = 1U << root; /* use root table entries */
  79531. mask = used - 1; /* mask for comparing low */
  79532. if (type == LENS && used >= ENOUGH - MAXD)
  79533. return 1;
  79534. for (;;) {
  79535. thisx.bits = (unsigned char)(len - drop);
  79536. if ((int)(work[sym]) < end) {
  79537. thisx.op = (unsigned char)0;
  79538. thisx.val = work[sym];
  79539. }
  79540. else if ((int)(work[sym]) > end) {
  79541. thisx.op = (unsigned char)(extra[work[sym]]);
  79542. thisx.val = base[work[sym]];
  79543. }
  79544. else {
  79545. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79546. thisx.val = 0;
  79547. }
  79548. incr = 1U << (len - drop);
  79549. fill = 1U << curr;
  79550. min = fill; /* save offset to next table */
  79551. do {
  79552. fill -= incr;
  79553. next[(huff >> drop) + fill] = thisx;
  79554. } while (fill != 0);
  79555. incr = 1U << (len - 1);
  79556. while (huff & incr)
  79557. incr >>= 1;
  79558. if (incr != 0) {
  79559. huff &= incr - 1;
  79560. huff += incr;
  79561. }
  79562. else
  79563. huff = 0;
  79564. sym++;
  79565. if (--(count[len]) == 0) {
  79566. if (len == max) break;
  79567. len = lens[work[sym]];
  79568. }
  79569. if (len > root && (huff & mask) != low) {
  79570. if (drop == 0)
  79571. drop = root;
  79572. next += min; /* here min is 1 << curr */
  79573. curr = len - drop;
  79574. left = (int)(1 << curr);
  79575. while (curr + drop < max) {
  79576. left -= count[curr + drop];
  79577. if (left <= 0) break;
  79578. curr++;
  79579. left <<= 1;
  79580. }
  79581. used += 1U << curr;
  79582. if (type == LENS && used >= ENOUGH - MAXD)
  79583. return 1;
  79584. low = huff & mask;
  79585. (*table)[low].op = (unsigned char)curr;
  79586. (*table)[low].bits = (unsigned char)root;
  79587. (*table)[low].val = (unsigned short)(next - *table);
  79588. }
  79589. }
  79590. thisx.op = (unsigned char)64; /* invalid code marker */
  79591. thisx.bits = (unsigned char)(len - drop);
  79592. thisx.val = (unsigned short)0;
  79593. while (huff != 0) {
  79594. if (drop != 0 && (huff & mask) != low) {
  79595. drop = 0;
  79596. len = root;
  79597. next = *table;
  79598. thisx.bits = (unsigned char)len;
  79599. }
  79600. next[huff >> drop] = thisx;
  79601. incr = 1U << (len - 1);
  79602. while (huff & incr)
  79603. incr >>= 1;
  79604. if (incr != 0) {
  79605. huff &= incr - 1;
  79606. huff += incr;
  79607. }
  79608. else
  79609. huff = 0;
  79610. }
  79611. *table += used;
  79612. *bits = root;
  79613. return 0;
  79614. }
  79615. /*** End of inlined file: inftrees.c ***/
  79616. /*** Start of inlined file: trees.c ***/
  79617. #ifdef DEBUG
  79618. # include <ctype.h>
  79619. #endif
  79620. #define MAX_BL_BITS 7
  79621. #define END_BLOCK 256
  79622. #define REP_3_6 16
  79623. #define REPZ_3_10 17
  79624. #define REPZ_11_138 18
  79625. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79626. = {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};
  79627. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79628. = {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};
  79629. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79630. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79631. local const uch bl_order[BL_CODES]
  79632. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79633. #define Buf_size (8 * 2*sizeof(char))
  79634. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79635. #if defined(GEN_TREES_H) || !defined(STDC)
  79636. local ct_data static_ltree[L_CODES+2];
  79637. local ct_data static_dtree[D_CODES];
  79638. uch _dist_code[DIST_CODE_LEN];
  79639. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79640. local int base_length[LENGTH_CODES];
  79641. local int base_dist[D_CODES];
  79642. #else
  79643. /*** Start of inlined file: trees.h ***/
  79644. local const ct_data static_ltree[L_CODES+2] = {
  79645. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79646. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79647. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79648. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79649. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79650. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79651. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79652. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79653. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79654. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79655. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79656. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79657. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79658. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79659. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79660. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79661. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79662. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79663. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79664. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79665. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79666. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79667. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79668. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79669. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79670. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79671. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79672. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79673. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79674. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79675. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79676. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79677. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79678. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79679. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79680. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79681. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79682. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79683. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79684. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79685. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79686. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79687. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79688. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79689. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79690. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79691. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79692. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79693. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79694. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79695. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79696. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79697. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79698. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79699. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79700. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79701. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79702. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79703. };
  79704. local const ct_data static_dtree[D_CODES] = {
  79705. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79706. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79707. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79708. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79709. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79710. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79711. };
  79712. const uch _dist_code[DIST_CODE_LEN] = {
  79713. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79714. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79715. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79716. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79717. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79718. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79719. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79720. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79721. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79722. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79723. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79724. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79725. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79726. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79727. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79728. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79729. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79730. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79731. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79732. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79733. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79734. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79735. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79736. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79737. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79738. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79739. };
  79740. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79741. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79742. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79743. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79744. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79745. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79746. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79747. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79748. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79749. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79750. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79751. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79752. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79753. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79754. };
  79755. local const int base_length[LENGTH_CODES] = {
  79756. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79757. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79758. };
  79759. local const int base_dist[D_CODES] = {
  79760. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79761. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79762. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79763. };
  79764. /*** End of inlined file: trees.h ***/
  79765. #endif /* GEN_TREES_H */
  79766. struct static_tree_desc_s {
  79767. const ct_data *static_tree; /* static tree or NULL */
  79768. const intf *extra_bits; /* extra bits for each code or NULL */
  79769. int extra_base; /* base index for extra_bits */
  79770. int elems; /* max number of elements in the tree */
  79771. int max_length; /* max bit length for the codes */
  79772. };
  79773. local static_tree_desc static_l_desc =
  79774. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79775. local static_tree_desc static_d_desc =
  79776. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79777. local static_tree_desc static_bl_desc =
  79778. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79779. local void tr_static_init OF((void));
  79780. local void init_block OF((deflate_state *s));
  79781. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79782. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79783. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79784. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79785. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79786. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79787. local int build_bl_tree OF((deflate_state *s));
  79788. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79789. int blcodes));
  79790. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79791. ct_data *dtree));
  79792. local void set_data_type OF((deflate_state *s));
  79793. local unsigned bi_reverse OF((unsigned value, int length));
  79794. local void bi_windup OF((deflate_state *s));
  79795. local void bi_flush OF((deflate_state *s));
  79796. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79797. int header));
  79798. #ifdef GEN_TREES_H
  79799. local void gen_trees_header OF((void));
  79800. #endif
  79801. #ifndef DEBUG
  79802. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79803. #else /* DEBUG */
  79804. # define send_code(s, c, tree) \
  79805. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79806. send_bits(s, tree[c].Code, tree[c].Len); }
  79807. #endif
  79808. #define put_short(s, w) { \
  79809. put_byte(s, (uch)((w) & 0xff)); \
  79810. put_byte(s, (uch)((ush)(w) >> 8)); \
  79811. }
  79812. #ifdef DEBUG
  79813. local void send_bits OF((deflate_state *s, int value, int length));
  79814. local void send_bits (deflate_state *s, int value, int length)
  79815. {
  79816. Tracevv((stderr," l %2d v %4x ", length, value));
  79817. Assert(length > 0 && length <= 15, "invalid length");
  79818. s->bits_sent += (ulg)length;
  79819. if (s->bi_valid > (int)Buf_size - length) {
  79820. s->bi_buf |= (value << s->bi_valid);
  79821. put_short(s, s->bi_buf);
  79822. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79823. s->bi_valid += length - Buf_size;
  79824. } else {
  79825. s->bi_buf |= value << s->bi_valid;
  79826. s->bi_valid += length;
  79827. }
  79828. }
  79829. #else /* !DEBUG */
  79830. #define send_bits(s, value, length) \
  79831. { int len = length;\
  79832. if (s->bi_valid > (int)Buf_size - len) {\
  79833. int val = value;\
  79834. s->bi_buf |= (val << s->bi_valid);\
  79835. put_short(s, s->bi_buf);\
  79836. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79837. s->bi_valid += len - Buf_size;\
  79838. } else {\
  79839. s->bi_buf |= (value) << s->bi_valid;\
  79840. s->bi_valid += len;\
  79841. }\
  79842. }
  79843. #endif /* DEBUG */
  79844. local void tr_static_init()
  79845. {
  79846. #if defined(GEN_TREES_H) || !defined(STDC)
  79847. static int static_init_done = 0;
  79848. int n; /* iterates over tree elements */
  79849. int bits; /* bit counter */
  79850. int length; /* length value */
  79851. int code; /* code value */
  79852. int dist; /* distance index */
  79853. ush bl_count[MAX_BITS+1];
  79854. if (static_init_done) return;
  79855. static_l_desc.static_tree = static_ltree;
  79856. static_l_desc.extra_bits = extra_lbits;
  79857. static_d_desc.static_tree = static_dtree;
  79858. static_d_desc.extra_bits = extra_dbits;
  79859. static_bl_desc.extra_bits = extra_blbits;
  79860. length = 0;
  79861. for (code = 0; code < LENGTH_CODES-1; code++) {
  79862. base_length[code] = length;
  79863. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79864. _length_code[length++] = (uch)code;
  79865. }
  79866. }
  79867. Assert (length == 256, "tr_static_init: length != 256");
  79868. _length_code[length-1] = (uch)code;
  79869. dist = 0;
  79870. for (code = 0 ; code < 16; code++) {
  79871. base_dist[code] = dist;
  79872. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79873. _dist_code[dist++] = (uch)code;
  79874. }
  79875. }
  79876. Assert (dist == 256, "tr_static_init: dist != 256");
  79877. dist >>= 7; /* from now on, all distances are divided by 128 */
  79878. for ( ; code < D_CODES; code++) {
  79879. base_dist[code] = dist << 7;
  79880. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79881. _dist_code[256 + dist++] = (uch)code;
  79882. }
  79883. }
  79884. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79885. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79886. n = 0;
  79887. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79888. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79889. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79890. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79891. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79892. for (n = 0; n < D_CODES; n++) {
  79893. static_dtree[n].Len = 5;
  79894. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79895. }
  79896. static_init_done = 1;
  79897. # ifdef GEN_TREES_H
  79898. gen_trees_header();
  79899. # endif
  79900. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79901. }
  79902. #ifdef GEN_TREES_H
  79903. # ifndef DEBUG
  79904. # include <stdio.h>
  79905. # endif
  79906. # define SEPARATOR(i, last, width) \
  79907. ((i) == (last)? "\n};\n\n" : \
  79908. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79909. void gen_trees_header()
  79910. {
  79911. FILE *header = fopen("trees.h", "w");
  79912. int i;
  79913. Assert (header != NULL, "Can't open trees.h");
  79914. fprintf(header,
  79915. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79916. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79917. for (i = 0; i < L_CODES+2; i++) {
  79918. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79919. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79920. }
  79921. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79922. for (i = 0; i < D_CODES; i++) {
  79923. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79924. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79925. }
  79926. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79927. for (i = 0; i < DIST_CODE_LEN; i++) {
  79928. fprintf(header, "%2u%s", _dist_code[i],
  79929. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79930. }
  79931. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79932. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79933. fprintf(header, "%2u%s", _length_code[i],
  79934. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79935. }
  79936. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79937. for (i = 0; i < LENGTH_CODES; i++) {
  79938. fprintf(header, "%1u%s", base_length[i],
  79939. SEPARATOR(i, LENGTH_CODES-1, 20));
  79940. }
  79941. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79942. for (i = 0; i < D_CODES; i++) {
  79943. fprintf(header, "%5u%s", base_dist[i],
  79944. SEPARATOR(i, D_CODES-1, 10));
  79945. }
  79946. fclose(header);
  79947. }
  79948. #endif /* GEN_TREES_H */
  79949. void _tr_init(deflate_state *s)
  79950. {
  79951. tr_static_init();
  79952. s->l_desc.dyn_tree = s->dyn_ltree;
  79953. s->l_desc.stat_desc = &static_l_desc;
  79954. s->d_desc.dyn_tree = s->dyn_dtree;
  79955. s->d_desc.stat_desc = &static_d_desc;
  79956. s->bl_desc.dyn_tree = s->bl_tree;
  79957. s->bl_desc.stat_desc = &static_bl_desc;
  79958. s->bi_buf = 0;
  79959. s->bi_valid = 0;
  79960. s->last_eob_len = 8; /* enough lookahead for inflate */
  79961. #ifdef DEBUG
  79962. s->compressed_len = 0L;
  79963. s->bits_sent = 0L;
  79964. #endif
  79965. init_block(s);
  79966. }
  79967. local void init_block (deflate_state *s)
  79968. {
  79969. int n; /* iterates over tree elements */
  79970. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79971. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79972. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79973. s->dyn_ltree[END_BLOCK].Freq = 1;
  79974. s->opt_len = s->static_len = 0L;
  79975. s->last_lit = s->matches = 0;
  79976. }
  79977. #define SMALLEST 1
  79978. #define pqremove(s, tree, top) \
  79979. {\
  79980. top = s->heap[SMALLEST]; \
  79981. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79982. pqdownheap(s, tree, SMALLEST); \
  79983. }
  79984. #define smaller(tree, n, m, depth) \
  79985. (tree[n].Freq < tree[m].Freq || \
  79986. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79987. local void pqdownheap (deflate_state *s,
  79988. ct_data *tree, /* the tree to restore */
  79989. int k) /* node to move down */
  79990. {
  79991. int v = s->heap[k];
  79992. int j = k << 1; /* left son of k */
  79993. while (j <= s->heap_len) {
  79994. if (j < s->heap_len &&
  79995. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79996. j++;
  79997. }
  79998. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79999. s->heap[k] = s->heap[j]; k = j;
  80000. j <<= 1;
  80001. }
  80002. s->heap[k] = v;
  80003. }
  80004. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  80005. {
  80006. ct_data *tree = desc->dyn_tree;
  80007. int max_code = desc->max_code;
  80008. const ct_data *stree = desc->stat_desc->static_tree;
  80009. const intf *extra = desc->stat_desc->extra_bits;
  80010. int base = desc->stat_desc->extra_base;
  80011. int max_length = desc->stat_desc->max_length;
  80012. int h; /* heap index */
  80013. int n, m; /* iterate over the tree elements */
  80014. int bits; /* bit length */
  80015. int xbits; /* extra bits */
  80016. ush f; /* frequency */
  80017. int overflow = 0; /* number of elements with bit length too large */
  80018. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  80019. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  80020. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  80021. n = s->heap[h];
  80022. bits = tree[tree[n].Dad].Len + 1;
  80023. if (bits > max_length) bits = max_length, overflow++;
  80024. tree[n].Len = (ush)bits;
  80025. if (n > max_code) continue; /* not a leaf node */
  80026. s->bl_count[bits]++;
  80027. xbits = 0;
  80028. if (n >= base) xbits = extra[n-base];
  80029. f = tree[n].Freq;
  80030. s->opt_len += (ulg)f * (bits + xbits);
  80031. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  80032. }
  80033. if (overflow == 0) return;
  80034. Trace((stderr,"\nbit length overflow\n"));
  80035. do {
  80036. bits = max_length-1;
  80037. while (s->bl_count[bits] == 0) bits--;
  80038. s->bl_count[bits]--; /* move one leaf down the tree */
  80039. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  80040. s->bl_count[max_length]--;
  80041. overflow -= 2;
  80042. } while (overflow > 0);
  80043. for (bits = max_length; bits != 0; bits--) {
  80044. n = s->bl_count[bits];
  80045. while (n != 0) {
  80046. m = s->heap[--h];
  80047. if (m > max_code) continue;
  80048. if ((unsigned) tree[m].Len != (unsigned) bits) {
  80049. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  80050. s->opt_len += ((long)bits - (long)tree[m].Len)
  80051. *(long)tree[m].Freq;
  80052. tree[m].Len = (ush)bits;
  80053. }
  80054. n--;
  80055. }
  80056. }
  80057. }
  80058. local void gen_codes (ct_data *tree, /* the tree to decorate */
  80059. int max_code, /* largest code with non zero frequency */
  80060. ushf *bl_count) /* number of codes at each bit length */
  80061. {
  80062. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  80063. ush code = 0; /* running code value */
  80064. int bits; /* bit index */
  80065. int n; /* code index */
  80066. for (bits = 1; bits <= MAX_BITS; bits++) {
  80067. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  80068. }
  80069. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  80070. "inconsistent bit counts");
  80071. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  80072. for (n = 0; n <= max_code; n++) {
  80073. int len = tree[n].Len;
  80074. if (len == 0) continue;
  80075. tree[n].Code = bi_reverse(next_code[len]++, len);
  80076. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  80077. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  80078. }
  80079. }
  80080. local void build_tree (deflate_state *s,
  80081. tree_desc *desc) /* the tree descriptor */
  80082. {
  80083. ct_data *tree = desc->dyn_tree;
  80084. const ct_data *stree = desc->stat_desc->static_tree;
  80085. int elems = desc->stat_desc->elems;
  80086. int n, m; /* iterate over heap elements */
  80087. int max_code = -1; /* largest code with non zero frequency */
  80088. int node; /* new node being created */
  80089. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  80090. for (n = 0; n < elems; n++) {
  80091. if (tree[n].Freq != 0) {
  80092. s->heap[++(s->heap_len)] = max_code = n;
  80093. s->depth[n] = 0;
  80094. } else {
  80095. tree[n].Len = 0;
  80096. }
  80097. }
  80098. while (s->heap_len < 2) {
  80099. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  80100. tree[node].Freq = 1;
  80101. s->depth[node] = 0;
  80102. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  80103. }
  80104. desc->max_code = max_code;
  80105. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  80106. node = elems; /* next internal node of the tree */
  80107. do {
  80108. pqremove(s, tree, n); /* n = node of least frequency */
  80109. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  80110. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  80111. s->heap[--(s->heap_max)] = m;
  80112. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  80113. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  80114. s->depth[n] : s->depth[m]) + 1);
  80115. tree[n].Dad = tree[m].Dad = (ush)node;
  80116. #ifdef DUMP_BL_TREE
  80117. if (tree == s->bl_tree) {
  80118. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  80119. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  80120. }
  80121. #endif
  80122. s->heap[SMALLEST] = node++;
  80123. pqdownheap(s, tree, SMALLEST);
  80124. } while (s->heap_len >= 2);
  80125. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  80126. gen_bitlen(s, (tree_desc *)desc);
  80127. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  80128. }
  80129. local void scan_tree (deflate_state *s,
  80130. ct_data *tree, /* the tree to be scanned */
  80131. int max_code) /* and its largest code of non zero frequency */
  80132. {
  80133. int n; /* iterates over all tree elements */
  80134. int prevlen = -1; /* last emitted length */
  80135. int curlen; /* length of current code */
  80136. int nextlen = tree[0].Len; /* length of next code */
  80137. int count = 0; /* repeat count of the current code */
  80138. int max_count = 7; /* max repeat count */
  80139. int min_count = 4; /* min repeat count */
  80140. if (nextlen == 0) max_count = 138, min_count = 3;
  80141. tree[max_code+1].Len = (ush)0xffff; /* guard */
  80142. for (n = 0; n <= max_code; n++) {
  80143. curlen = nextlen; nextlen = tree[n+1].Len;
  80144. if (++count < max_count && curlen == nextlen) {
  80145. continue;
  80146. } else if (count < min_count) {
  80147. s->bl_tree[curlen].Freq += count;
  80148. } else if (curlen != 0) {
  80149. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  80150. s->bl_tree[REP_3_6].Freq++;
  80151. } else if (count <= 10) {
  80152. s->bl_tree[REPZ_3_10].Freq++;
  80153. } else {
  80154. s->bl_tree[REPZ_11_138].Freq++;
  80155. }
  80156. count = 0; prevlen = curlen;
  80157. if (nextlen == 0) {
  80158. max_count = 138, min_count = 3;
  80159. } else if (curlen == nextlen) {
  80160. max_count = 6, min_count = 3;
  80161. } else {
  80162. max_count = 7, min_count = 4;
  80163. }
  80164. }
  80165. }
  80166. local void send_tree (deflate_state *s,
  80167. ct_data *tree, /* the tree to be scanned */
  80168. int max_code) /* and its largest code of non zero frequency */
  80169. {
  80170. int n; /* iterates over all tree elements */
  80171. int prevlen = -1; /* last emitted length */
  80172. int curlen; /* length of current code */
  80173. int nextlen = tree[0].Len; /* length of next code */
  80174. int count = 0; /* repeat count of the current code */
  80175. int max_count = 7; /* max repeat count */
  80176. int min_count = 4; /* min repeat count */
  80177. /* guard already set */
  80178. if (nextlen == 0) max_count = 138, min_count = 3;
  80179. for (n = 0; n <= max_code; n++) {
  80180. curlen = nextlen; nextlen = tree[n+1].Len;
  80181. if (++count < max_count && curlen == nextlen) {
  80182. continue;
  80183. } else if (count < min_count) {
  80184. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  80185. } else if (curlen != 0) {
  80186. if (curlen != prevlen) {
  80187. send_code(s, curlen, s->bl_tree); count--;
  80188. }
  80189. Assert(count >= 3 && count <= 6, " 3_6?");
  80190. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  80191. } else if (count <= 10) {
  80192. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  80193. } else {
  80194. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  80195. }
  80196. count = 0; prevlen = curlen;
  80197. if (nextlen == 0) {
  80198. max_count = 138, min_count = 3;
  80199. } else if (curlen == nextlen) {
  80200. max_count = 6, min_count = 3;
  80201. } else {
  80202. max_count = 7, min_count = 4;
  80203. }
  80204. }
  80205. }
  80206. local int build_bl_tree (deflate_state *s)
  80207. {
  80208. int max_blindex; /* index of last bit length code of non zero freq */
  80209. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  80210. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  80211. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  80212. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  80213. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  80214. }
  80215. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  80216. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  80217. s->opt_len, s->static_len));
  80218. return max_blindex;
  80219. }
  80220. local void send_all_trees (deflate_state *s,
  80221. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  80222. {
  80223. int rank; /* index in bl_order */
  80224. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  80225. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  80226. "too many codes");
  80227. Tracev((stderr, "\nbl counts: "));
  80228. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  80229. send_bits(s, dcodes-1, 5);
  80230. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  80231. for (rank = 0; rank < blcodes; rank++) {
  80232. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  80233. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  80234. }
  80235. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  80236. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  80237. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  80238. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  80239. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  80240. }
  80241. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  80242. {
  80243. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  80244. #ifdef DEBUG
  80245. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  80246. s->compressed_len += (stored_len + 4) << 3;
  80247. #endif
  80248. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  80249. }
  80250. void _tr_align (deflate_state *s)
  80251. {
  80252. send_bits(s, STATIC_TREES<<1, 3);
  80253. send_code(s, END_BLOCK, static_ltree);
  80254. #ifdef DEBUG
  80255. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  80256. #endif
  80257. bi_flush(s);
  80258. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  80259. send_bits(s, STATIC_TREES<<1, 3);
  80260. send_code(s, END_BLOCK, static_ltree);
  80261. #ifdef DEBUG
  80262. s->compressed_len += 10L;
  80263. #endif
  80264. bi_flush(s);
  80265. }
  80266. s->last_eob_len = 7;
  80267. }
  80268. void _tr_flush_block (deflate_state *s,
  80269. charf *buf, /* input block, or NULL if too old */
  80270. ulg stored_len, /* length of input block */
  80271. int eof) /* true if this is the last block for a file */
  80272. {
  80273. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  80274. int max_blindex = 0; /* index of last bit length code of non zero freq */
  80275. if (s->level > 0) {
  80276. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  80277. set_data_type(s);
  80278. build_tree(s, (tree_desc *)(&(s->l_desc)));
  80279. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  80280. s->static_len));
  80281. build_tree(s, (tree_desc *)(&(s->d_desc)));
  80282. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  80283. s->static_len));
  80284. max_blindex = build_bl_tree(s);
  80285. opt_lenb = (s->opt_len+3+7)>>3;
  80286. static_lenb = (s->static_len+3+7)>>3;
  80287. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80288. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80289. s->last_lit));
  80290. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80291. } else {
  80292. Assert(buf != (char*)0, "lost buf");
  80293. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80294. }
  80295. #ifdef FORCE_STORED
  80296. if (buf != (char*)0) { /* force stored block */
  80297. #else
  80298. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80299. #endif
  80300. _tr_stored_block(s, buf, stored_len, eof);
  80301. #ifdef FORCE_STATIC
  80302. } else if (static_lenb >= 0) { /* force static trees */
  80303. #else
  80304. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80305. #endif
  80306. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80307. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80308. #ifdef DEBUG
  80309. s->compressed_len += 3 + s->static_len;
  80310. #endif
  80311. } else {
  80312. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80313. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80314. max_blindex+1);
  80315. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80316. #ifdef DEBUG
  80317. s->compressed_len += 3 + s->opt_len;
  80318. #endif
  80319. }
  80320. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80321. init_block(s);
  80322. if (eof) {
  80323. bi_windup(s);
  80324. #ifdef DEBUG
  80325. s->compressed_len += 7; /* align on byte boundary */
  80326. #endif
  80327. }
  80328. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80329. s->compressed_len-7*eof));
  80330. }
  80331. int _tr_tally (deflate_state *s,
  80332. unsigned dist, /* distance of matched string */
  80333. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80334. {
  80335. s->d_buf[s->last_lit] = (ush)dist;
  80336. s->l_buf[s->last_lit++] = (uch)lc;
  80337. if (dist == 0) {
  80338. s->dyn_ltree[lc].Freq++;
  80339. } else {
  80340. s->matches++;
  80341. dist--; /* dist = match distance - 1 */
  80342. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80343. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80344. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80345. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80346. s->dyn_dtree[d_code(dist)].Freq++;
  80347. }
  80348. #ifdef TRUNCATE_BLOCK
  80349. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80350. ulg out_length = (ulg)s->last_lit*8L;
  80351. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80352. int dcode;
  80353. for (dcode = 0; dcode < D_CODES; dcode++) {
  80354. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80355. (5L+extra_dbits[dcode]);
  80356. }
  80357. out_length >>= 3;
  80358. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80359. s->last_lit, in_length, out_length,
  80360. 100L - out_length*100L/in_length));
  80361. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80362. }
  80363. #endif
  80364. return (s->last_lit == s->lit_bufsize-1);
  80365. }
  80366. local void compress_block (deflate_state *s,
  80367. ct_data *ltree, /* literal tree */
  80368. ct_data *dtree) /* distance tree */
  80369. {
  80370. unsigned dist; /* distance of matched string */
  80371. int lc; /* match length or unmatched char (if dist == 0) */
  80372. unsigned lx = 0; /* running index in l_buf */
  80373. unsigned code; /* the code to send */
  80374. int extra; /* number of extra bits to send */
  80375. if (s->last_lit != 0) do {
  80376. dist = s->d_buf[lx];
  80377. lc = s->l_buf[lx++];
  80378. if (dist == 0) {
  80379. send_code(s, lc, ltree); /* send a literal byte */
  80380. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80381. } else {
  80382. code = _length_code[lc];
  80383. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80384. extra = extra_lbits[code];
  80385. if (extra != 0) {
  80386. lc -= base_length[code];
  80387. send_bits(s, lc, extra); /* send the extra length bits */
  80388. }
  80389. dist--; /* dist is now the match distance - 1 */
  80390. code = d_code(dist);
  80391. Assert (code < D_CODES, "bad d_code");
  80392. send_code(s, code, dtree); /* send the distance code */
  80393. extra = extra_dbits[code];
  80394. if (extra != 0) {
  80395. dist -= base_dist[code];
  80396. send_bits(s, dist, extra); /* send the extra distance bits */
  80397. }
  80398. } /* literal or match pair ? */
  80399. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80400. "pendingBuf overflow");
  80401. } while (lx < s->last_lit);
  80402. send_code(s, END_BLOCK, ltree);
  80403. s->last_eob_len = ltree[END_BLOCK].Len;
  80404. }
  80405. local void set_data_type (deflate_state *s)
  80406. {
  80407. int n;
  80408. for (n = 0; n < 9; n++)
  80409. if (s->dyn_ltree[n].Freq != 0)
  80410. break;
  80411. if (n == 9)
  80412. for (n = 14; n < 32; n++)
  80413. if (s->dyn_ltree[n].Freq != 0)
  80414. break;
  80415. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80416. }
  80417. local unsigned bi_reverse (unsigned code, int len)
  80418. {
  80419. register unsigned res = 0;
  80420. do {
  80421. res |= code & 1;
  80422. code >>= 1, res <<= 1;
  80423. } while (--len > 0);
  80424. return res >> 1;
  80425. }
  80426. local void bi_flush (deflate_state *s)
  80427. {
  80428. if (s->bi_valid == 16) {
  80429. put_short(s, s->bi_buf);
  80430. s->bi_buf = 0;
  80431. s->bi_valid = 0;
  80432. } else if (s->bi_valid >= 8) {
  80433. put_byte(s, (Byte)s->bi_buf);
  80434. s->bi_buf >>= 8;
  80435. s->bi_valid -= 8;
  80436. }
  80437. }
  80438. local void bi_windup (deflate_state *s)
  80439. {
  80440. if (s->bi_valid > 8) {
  80441. put_short(s, s->bi_buf);
  80442. } else if (s->bi_valid > 0) {
  80443. put_byte(s, (Byte)s->bi_buf);
  80444. }
  80445. s->bi_buf = 0;
  80446. s->bi_valid = 0;
  80447. #ifdef DEBUG
  80448. s->bits_sent = (s->bits_sent+7) & ~7;
  80449. #endif
  80450. }
  80451. local void copy_block(deflate_state *s,
  80452. charf *buf, /* the input data */
  80453. unsigned len, /* its length */
  80454. int header) /* true if block header must be written */
  80455. {
  80456. bi_windup(s); /* align on byte boundary */
  80457. s->last_eob_len = 8; /* enough lookahead for inflate */
  80458. if (header) {
  80459. put_short(s, (ush)len);
  80460. put_short(s, (ush)~len);
  80461. #ifdef DEBUG
  80462. s->bits_sent += 2*16;
  80463. #endif
  80464. }
  80465. #ifdef DEBUG
  80466. s->bits_sent += (ulg)len<<3;
  80467. #endif
  80468. while (len--) {
  80469. put_byte(s, *buf++);
  80470. }
  80471. }
  80472. /*** End of inlined file: trees.c ***/
  80473. /*** Start of inlined file: zutil.c ***/
  80474. #ifndef NO_DUMMY_DECL
  80475. struct internal_state {int dummy;}; /* for buggy compilers */
  80476. #endif
  80477. const char * const z_errmsg[10] = {
  80478. "need dictionary", /* Z_NEED_DICT 2 */
  80479. "stream end", /* Z_STREAM_END 1 */
  80480. "", /* Z_OK 0 */
  80481. "file error", /* Z_ERRNO (-1) */
  80482. "stream error", /* Z_STREAM_ERROR (-2) */
  80483. "data error", /* Z_DATA_ERROR (-3) */
  80484. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80485. "buffer error", /* Z_BUF_ERROR (-5) */
  80486. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80487. ""};
  80488. #ifdef DEBUG
  80489. # ifndef verbose
  80490. # define verbose 0
  80491. # endif
  80492. int z_verbose = verbose;
  80493. void z_error (const char *m)
  80494. {
  80495. fprintf(stderr, "%s\n", m);
  80496. exit(1);
  80497. }
  80498. #endif
  80499. const char * ZEXPORT zError(int err)
  80500. {
  80501. return ERR_MSG(err);
  80502. }
  80503. #if defined(_WIN32_WCE)
  80504. int errno = 0;
  80505. #endif
  80506. #ifndef HAVE_MEMCPY
  80507. void zmemcpy(dest, source, len)
  80508. Bytef* dest;
  80509. const Bytef* source;
  80510. uInt len;
  80511. {
  80512. if (len == 0) return;
  80513. do {
  80514. *dest++ = *source++; /* ??? to be unrolled */
  80515. } while (--len != 0);
  80516. }
  80517. int zmemcmp(s1, s2, len)
  80518. const Bytef* s1;
  80519. const Bytef* s2;
  80520. uInt len;
  80521. {
  80522. uInt j;
  80523. for (j = 0; j < len; j++) {
  80524. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80525. }
  80526. return 0;
  80527. }
  80528. void zmemzero(dest, len)
  80529. Bytef* dest;
  80530. uInt len;
  80531. {
  80532. if (len == 0) return;
  80533. do {
  80534. *dest++ = 0; /* ??? to be unrolled */
  80535. } while (--len != 0);
  80536. }
  80537. #endif
  80538. #ifdef SYS16BIT
  80539. #ifdef __TURBOC__
  80540. # define MY_ZCALLOC
  80541. #define MAX_PTR 10
  80542. local int next_ptr = 0;
  80543. typedef struct ptr_table_s {
  80544. voidpf org_ptr;
  80545. voidpf new_ptr;
  80546. } ptr_table;
  80547. local ptr_table table[MAX_PTR];
  80548. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80549. {
  80550. voidpf buf = opaque; /* just to make some compilers happy */
  80551. ulg bsize = (ulg)items*size;
  80552. if (bsize < 65520L) {
  80553. buf = farmalloc(bsize);
  80554. if (*(ush*)&buf != 0) return buf;
  80555. } else {
  80556. buf = farmalloc(bsize + 16L);
  80557. }
  80558. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80559. table[next_ptr].org_ptr = buf;
  80560. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80561. *(ush*)&buf = 0;
  80562. table[next_ptr++].new_ptr = buf;
  80563. return buf;
  80564. }
  80565. void zcfree (voidpf opaque, voidpf ptr)
  80566. {
  80567. int n;
  80568. if (*(ush*)&ptr != 0) { /* object < 64K */
  80569. farfree(ptr);
  80570. return;
  80571. }
  80572. for (n = 0; n < next_ptr; n++) {
  80573. if (ptr != table[n].new_ptr) continue;
  80574. farfree(table[n].org_ptr);
  80575. while (++n < next_ptr) {
  80576. table[n-1] = table[n];
  80577. }
  80578. next_ptr--;
  80579. return;
  80580. }
  80581. ptr = opaque; /* just to make some compilers happy */
  80582. Assert(0, "zcfree: ptr not found");
  80583. }
  80584. #endif /* __TURBOC__ */
  80585. #ifdef M_I86
  80586. # define MY_ZCALLOC
  80587. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80588. # define _halloc halloc
  80589. # define _hfree hfree
  80590. #endif
  80591. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80592. {
  80593. if (opaque) opaque = 0; /* to make compiler happy */
  80594. return _halloc((long)items, size);
  80595. }
  80596. void zcfree (voidpf opaque, voidpf ptr)
  80597. {
  80598. if (opaque) opaque = 0; /* to make compiler happy */
  80599. _hfree(ptr);
  80600. }
  80601. #endif /* M_I86 */
  80602. #endif /* SYS16BIT */
  80603. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80604. #ifndef STDC
  80605. extern voidp malloc OF((uInt size));
  80606. extern voidp calloc OF((uInt items, uInt size));
  80607. extern void free OF((voidpf ptr));
  80608. #endif
  80609. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80610. {
  80611. if (opaque) items += size - size; /* make compiler happy */
  80612. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80613. (voidpf)calloc(items, size);
  80614. }
  80615. void zcfree (voidpf opaque, voidpf ptr)
  80616. {
  80617. free(ptr);
  80618. if (opaque) return; /* make compiler happy */
  80619. }
  80620. #endif /* MY_ZCALLOC */
  80621. /*** End of inlined file: zutil.c ***/
  80622. #undef Byte
  80623. }
  80624. #else
  80625. #include <zlib.h>
  80626. #endif
  80627. }
  80628. #if JUCE_MSVC
  80629. #pragma warning (pop)
  80630. #endif
  80631. BEGIN_JUCE_NAMESPACE
  80632. using namespace zlibNamespace;
  80633. // internal helper object that holds the zlib structures so they don't have to be
  80634. // included publicly.
  80635. class GZIPDecompressHelper
  80636. {
  80637. public:
  80638. GZIPDecompressHelper (const bool noWrap) throw()
  80639. : data (0),
  80640. dataSize (0),
  80641. finished (true),
  80642. needsDictionary (false),
  80643. error (true),
  80644. streamIsValid (false)
  80645. {
  80646. zerostruct (stream);
  80647. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80648. finished = error = ! streamIsValid;
  80649. }
  80650. ~GZIPDecompressHelper() throw()
  80651. {
  80652. if (streamIsValid)
  80653. inflateEnd (&stream);
  80654. }
  80655. bool needsInput() const throw() { return dataSize <= 0; }
  80656. void setInput (uint8* const data_, const int size) throw()
  80657. {
  80658. data = data_;
  80659. dataSize = size;
  80660. }
  80661. int doNextBlock (uint8* const dest, const int destSize) throw()
  80662. {
  80663. if (streamIsValid && data != 0 && ! finished)
  80664. {
  80665. stream.next_in = data;
  80666. stream.next_out = dest;
  80667. stream.avail_in = dataSize;
  80668. stream.avail_out = destSize;
  80669. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80670. {
  80671. case Z_STREAM_END:
  80672. finished = true;
  80673. // deliberate fall-through
  80674. case Z_OK:
  80675. data += dataSize - stream.avail_in;
  80676. dataSize = stream.avail_in;
  80677. return destSize - stream.avail_out;
  80678. case Z_NEED_DICT:
  80679. needsDictionary = true;
  80680. data += dataSize - stream.avail_in;
  80681. dataSize = stream.avail_in;
  80682. break;
  80683. case Z_DATA_ERROR:
  80684. case Z_MEM_ERROR:
  80685. error = true;
  80686. default:
  80687. break;
  80688. }
  80689. }
  80690. return 0;
  80691. }
  80692. private:
  80693. z_stream stream;
  80694. uint8* data;
  80695. int dataSize;
  80696. public:
  80697. bool finished, needsDictionary, error, streamIsValid;
  80698. };
  80699. const int gzipDecompBufferSize = 32768;
  80700. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80701. const bool deleteSourceWhenDestroyed,
  80702. const bool noWrap_,
  80703. const int64 uncompressedStreamLength_)
  80704. : sourceStream (sourceStream_),
  80705. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80706. uncompressedStreamLength (uncompressedStreamLength_),
  80707. noWrap (noWrap_),
  80708. isEof (false),
  80709. activeBufferSize (0),
  80710. originalSourcePos (sourceStream_->getPosition()),
  80711. currentPos (0),
  80712. buffer (gzipDecompBufferSize),
  80713. helper (new GZIPDecompressHelper (noWrap_))
  80714. {
  80715. }
  80716. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80717. {
  80718. }
  80719. int64 GZIPDecompressorInputStream::getTotalLength()
  80720. {
  80721. return uncompressedStreamLength;
  80722. }
  80723. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80724. {
  80725. if ((howMany > 0) && ! isEof)
  80726. {
  80727. jassert (destBuffer != 0);
  80728. if (destBuffer != 0)
  80729. {
  80730. int numRead = 0;
  80731. uint8* d = (uint8*) destBuffer;
  80732. while (! helper->error)
  80733. {
  80734. const int n = helper->doNextBlock (d, howMany);
  80735. currentPos += n;
  80736. if (n == 0)
  80737. {
  80738. if (helper->finished || helper->needsDictionary)
  80739. {
  80740. isEof = true;
  80741. return numRead;
  80742. }
  80743. if (helper->needsInput())
  80744. {
  80745. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80746. if (activeBufferSize > 0)
  80747. {
  80748. helper->setInput ((uint8*) buffer, activeBufferSize);
  80749. }
  80750. else
  80751. {
  80752. isEof = true;
  80753. return numRead;
  80754. }
  80755. }
  80756. }
  80757. else
  80758. {
  80759. numRead += n;
  80760. howMany -= n;
  80761. d += n;
  80762. if (howMany <= 0)
  80763. return numRead;
  80764. }
  80765. }
  80766. }
  80767. }
  80768. return 0;
  80769. }
  80770. bool GZIPDecompressorInputStream::isExhausted()
  80771. {
  80772. return helper->error || isEof;
  80773. }
  80774. int64 GZIPDecompressorInputStream::getPosition()
  80775. {
  80776. return currentPos;
  80777. }
  80778. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80779. {
  80780. if (newPos < currentPos)
  80781. {
  80782. // to go backwards, reset the stream and start again..
  80783. isEof = false;
  80784. activeBufferSize = 0;
  80785. currentPos = 0;
  80786. helper = new GZIPDecompressHelper (noWrap);
  80787. sourceStream->setPosition (originalSourcePos);
  80788. }
  80789. skipNextBytes (newPos - currentPos);
  80790. return true;
  80791. }
  80792. END_JUCE_NAMESPACE
  80793. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80794. #endif
  80795. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80796. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80797. #if JUCE_USE_FLAC
  80798. #if JUCE_WINDOWS
  80799. #include <windows.h>
  80800. #endif
  80801. #ifdef _MSC_VER
  80802. #pragma warning (disable : 4505)
  80803. #pragma warning (push)
  80804. #endif
  80805. namespace FlacNamespace
  80806. {
  80807. #if JUCE_INCLUDE_FLAC_CODE
  80808. #define FLAC__NO_DLL 1
  80809. #if ! defined (SIZE_MAX)
  80810. #define SIZE_MAX 0xffffffff
  80811. #endif
  80812. #define __STDC_LIMIT_MACROS 1
  80813. /*** Start of inlined file: all.h ***/
  80814. #ifndef FLAC__ALL_H
  80815. #define FLAC__ALL_H
  80816. /*** Start of inlined file: export.h ***/
  80817. #ifndef FLAC__EXPORT_H
  80818. #define FLAC__EXPORT_H
  80819. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80820. #define FLAC_API
  80821. #else
  80822. #ifdef FLAC_API_EXPORTS
  80823. #define FLAC_API _declspec(dllexport)
  80824. #else
  80825. #define FLAC_API _declspec(dllimport)
  80826. #endif
  80827. #endif
  80828. #define FLAC_API_VERSION_CURRENT 10
  80829. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80830. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80831. #ifdef __cplusplus
  80832. extern "C" {
  80833. #endif
  80834. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80835. #ifdef __cplusplus
  80836. }
  80837. #endif
  80838. #endif
  80839. /*** End of inlined file: export.h ***/
  80840. /*** Start of inlined file: assert.h ***/
  80841. #ifndef FLAC__ASSERT_H
  80842. #define FLAC__ASSERT_H
  80843. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80844. #ifdef DEBUG
  80845. #include <assert.h>
  80846. #define FLAC__ASSERT(x) assert(x)
  80847. #define FLAC__ASSERT_DECLARATION(x) x
  80848. #else
  80849. #define FLAC__ASSERT(x)
  80850. #define FLAC__ASSERT_DECLARATION(x)
  80851. #endif
  80852. #endif
  80853. /*** End of inlined file: assert.h ***/
  80854. /*** Start of inlined file: callback.h ***/
  80855. #ifndef FLAC__CALLBACK_H
  80856. #define FLAC__CALLBACK_H
  80857. /*** Start of inlined file: ordinals.h ***/
  80858. #ifndef FLAC__ORDINALS_H
  80859. #define FLAC__ORDINALS_H
  80860. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80861. #include <inttypes.h>
  80862. #endif
  80863. typedef signed char FLAC__int8;
  80864. typedef unsigned char FLAC__uint8;
  80865. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80866. typedef __int16 FLAC__int16;
  80867. typedef __int32 FLAC__int32;
  80868. typedef __int64 FLAC__int64;
  80869. typedef unsigned __int16 FLAC__uint16;
  80870. typedef unsigned __int32 FLAC__uint32;
  80871. typedef unsigned __int64 FLAC__uint64;
  80872. #elif defined(__EMX__)
  80873. typedef short FLAC__int16;
  80874. typedef long FLAC__int32;
  80875. typedef long long FLAC__int64;
  80876. typedef unsigned short FLAC__uint16;
  80877. typedef unsigned long FLAC__uint32;
  80878. typedef unsigned long long FLAC__uint64;
  80879. #else
  80880. typedef int16_t FLAC__int16;
  80881. typedef int32_t FLAC__int32;
  80882. typedef int64_t FLAC__int64;
  80883. typedef uint16_t FLAC__uint16;
  80884. typedef uint32_t FLAC__uint32;
  80885. typedef uint64_t FLAC__uint64;
  80886. #endif
  80887. typedef int FLAC__bool;
  80888. typedef FLAC__uint8 FLAC__byte;
  80889. #ifdef true
  80890. #undef true
  80891. #endif
  80892. #ifdef false
  80893. #undef false
  80894. #endif
  80895. #ifndef __cplusplus
  80896. #define true 1
  80897. #define false 0
  80898. #endif
  80899. #endif
  80900. /*** End of inlined file: ordinals.h ***/
  80901. #include <stdlib.h> /* for size_t */
  80902. #ifdef __cplusplus
  80903. extern "C" {
  80904. #endif
  80905. typedef void* FLAC__IOHandle;
  80906. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80907. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80908. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80909. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80910. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80911. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80912. typedef struct {
  80913. FLAC__IOCallback_Read read;
  80914. FLAC__IOCallback_Write write;
  80915. FLAC__IOCallback_Seek seek;
  80916. FLAC__IOCallback_Tell tell;
  80917. FLAC__IOCallback_Eof eof;
  80918. FLAC__IOCallback_Close close;
  80919. } FLAC__IOCallbacks;
  80920. #ifdef __cplusplus
  80921. }
  80922. #endif
  80923. #endif
  80924. /*** End of inlined file: callback.h ***/
  80925. /*** Start of inlined file: format.h ***/
  80926. #ifndef FLAC__FORMAT_H
  80927. #define FLAC__FORMAT_H
  80928. #ifdef __cplusplus
  80929. extern "C" {
  80930. #endif
  80931. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80932. #define FLAC__MIN_BLOCK_SIZE (16u)
  80933. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80934. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80935. #define FLAC__MAX_CHANNELS (8u)
  80936. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80937. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80938. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80939. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80940. #define FLAC__MAX_LPC_ORDER (32u)
  80941. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80942. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80943. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80944. #define FLAC__MAX_FIXED_ORDER (4u)
  80945. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80946. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80947. extern FLAC_API const char *FLAC__VERSION_STRING;
  80948. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80949. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80950. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80951. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80952. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80953. typedef enum {
  80954. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80955. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80956. } FLAC__EntropyCodingMethodType;
  80957. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80958. typedef struct {
  80959. unsigned *parameters;
  80960. unsigned *raw_bits;
  80961. unsigned capacity_by_order;
  80962. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80963. typedef struct {
  80964. unsigned order;
  80965. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80966. } FLAC__EntropyCodingMethod_PartitionedRice;
  80967. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80968. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80969. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80970. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80971. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80972. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80973. typedef struct {
  80974. FLAC__EntropyCodingMethodType type;
  80975. union {
  80976. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80977. } data;
  80978. } FLAC__EntropyCodingMethod;
  80979. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80980. typedef enum {
  80981. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80982. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80983. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80984. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80985. } FLAC__SubframeType;
  80986. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80987. typedef struct {
  80988. FLAC__int32 value; /**< The constant signal value. */
  80989. } FLAC__Subframe_Constant;
  80990. typedef struct {
  80991. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80992. } FLAC__Subframe_Verbatim;
  80993. typedef struct {
  80994. FLAC__EntropyCodingMethod entropy_coding_method;
  80995. unsigned order;
  80996. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80997. const FLAC__int32 *residual;
  80998. } FLAC__Subframe_Fixed;
  80999. typedef struct {
  81000. FLAC__EntropyCodingMethod entropy_coding_method;
  81001. unsigned order;
  81002. unsigned qlp_coeff_precision;
  81003. int quantization_level;
  81004. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  81005. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  81006. const FLAC__int32 *residual;
  81007. } FLAC__Subframe_LPC;
  81008. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  81009. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  81010. typedef struct {
  81011. FLAC__SubframeType type;
  81012. union {
  81013. FLAC__Subframe_Constant constant;
  81014. FLAC__Subframe_Fixed fixed;
  81015. FLAC__Subframe_LPC lpc;
  81016. FLAC__Subframe_Verbatim verbatim;
  81017. } data;
  81018. unsigned wasted_bits;
  81019. } FLAC__Subframe;
  81020. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  81021. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  81022. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  81023. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  81024. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  81025. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  81026. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  81027. typedef enum {
  81028. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  81029. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  81030. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  81031. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  81032. } FLAC__ChannelAssignment;
  81033. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  81034. typedef enum {
  81035. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  81036. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  81037. } FLAC__FrameNumberType;
  81038. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  81039. typedef struct {
  81040. unsigned blocksize;
  81041. unsigned sample_rate;
  81042. unsigned channels;
  81043. FLAC__ChannelAssignment channel_assignment;
  81044. unsigned bits_per_sample;
  81045. FLAC__FrameNumberType number_type;
  81046. union {
  81047. FLAC__uint32 frame_number;
  81048. FLAC__uint64 sample_number;
  81049. } number;
  81050. FLAC__uint8 crc;
  81051. } FLAC__FrameHeader;
  81052. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  81053. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  81054. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  81055. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  81056. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  81057. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  81058. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  81059. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  81060. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  81061. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  81062. typedef struct {
  81063. FLAC__uint16 crc;
  81064. } FLAC__FrameFooter;
  81065. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  81066. typedef struct {
  81067. FLAC__FrameHeader header;
  81068. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  81069. FLAC__FrameFooter footer;
  81070. } FLAC__Frame;
  81071. typedef enum {
  81072. FLAC__METADATA_TYPE_STREAMINFO = 0,
  81073. FLAC__METADATA_TYPE_PADDING = 1,
  81074. FLAC__METADATA_TYPE_APPLICATION = 2,
  81075. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  81076. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  81077. FLAC__METADATA_TYPE_CUESHEET = 5,
  81078. FLAC__METADATA_TYPE_PICTURE = 6,
  81079. FLAC__METADATA_TYPE_UNDEFINED = 7
  81080. } FLAC__MetadataType;
  81081. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  81082. typedef struct {
  81083. unsigned min_blocksize, max_blocksize;
  81084. unsigned min_framesize, max_framesize;
  81085. unsigned sample_rate;
  81086. unsigned channels;
  81087. unsigned bits_per_sample;
  81088. FLAC__uint64 total_samples;
  81089. FLAC__byte md5sum[16];
  81090. } FLAC__StreamMetadata_StreamInfo;
  81091. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81092. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81093. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81094. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81095. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  81096. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  81097. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  81098. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  81099. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  81100. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  81101. typedef struct {
  81102. int dummy;
  81103. } FLAC__StreamMetadata_Padding;
  81104. typedef struct {
  81105. FLAC__byte id[4];
  81106. FLAC__byte *data;
  81107. } FLAC__StreamMetadata_Application;
  81108. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  81109. typedef struct {
  81110. FLAC__uint64 sample_number;
  81111. FLAC__uint64 stream_offset;
  81112. unsigned frame_samples;
  81113. } FLAC__StreamMetadata_SeekPoint;
  81114. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  81115. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  81116. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  81117. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  81118. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  81119. typedef struct {
  81120. unsigned num_points;
  81121. FLAC__StreamMetadata_SeekPoint *points;
  81122. } FLAC__StreamMetadata_SeekTable;
  81123. typedef struct {
  81124. FLAC__uint32 length;
  81125. FLAC__byte *entry;
  81126. } FLAC__StreamMetadata_VorbisComment_Entry;
  81127. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  81128. typedef struct {
  81129. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  81130. FLAC__uint32 num_comments;
  81131. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  81132. } FLAC__StreamMetadata_VorbisComment;
  81133. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  81134. typedef struct {
  81135. FLAC__uint64 offset;
  81136. FLAC__byte number;
  81137. } FLAC__StreamMetadata_CueSheet_Index;
  81138. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  81139. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  81140. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  81141. typedef struct {
  81142. FLAC__uint64 offset;
  81143. FLAC__byte number;
  81144. char isrc[13];
  81145. unsigned type:1;
  81146. unsigned pre_emphasis:1;
  81147. FLAC__byte num_indices;
  81148. FLAC__StreamMetadata_CueSheet_Index *indices;
  81149. } FLAC__StreamMetadata_CueSheet_Track;
  81150. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  81151. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  81152. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  81153. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  81154. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  81155. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  81156. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  81157. typedef struct {
  81158. char media_catalog_number[129];
  81159. FLAC__uint64 lead_in;
  81160. FLAC__bool is_cd;
  81161. unsigned num_tracks;
  81162. FLAC__StreamMetadata_CueSheet_Track *tracks;
  81163. } FLAC__StreamMetadata_CueSheet;
  81164. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  81165. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  81166. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  81167. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  81168. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  81169. typedef enum {
  81170. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  81171. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  81172. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  81173. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  81174. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  81175. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  81176. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  81177. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  81178. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  81179. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  81180. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  81181. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  81182. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  81183. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  81184. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  81185. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  81186. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  81187. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  81188. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  81189. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  81190. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  81191. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  81192. } FLAC__StreamMetadata_Picture_Type;
  81193. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  81194. typedef struct {
  81195. FLAC__StreamMetadata_Picture_Type type;
  81196. char *mime_type;
  81197. FLAC__byte *description;
  81198. FLAC__uint32 width;
  81199. FLAC__uint32 height;
  81200. FLAC__uint32 depth;
  81201. FLAC__uint32 colors;
  81202. FLAC__uint32 data_length;
  81203. FLAC__byte *data;
  81204. } FLAC__StreamMetadata_Picture;
  81205. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  81206. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  81207. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  81208. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  81209. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  81210. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  81211. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  81212. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  81213. typedef struct {
  81214. FLAC__byte *data;
  81215. } FLAC__StreamMetadata_Unknown;
  81216. typedef struct {
  81217. FLAC__MetadataType type;
  81218. FLAC__bool is_last;
  81219. unsigned length;
  81220. union {
  81221. FLAC__StreamMetadata_StreamInfo stream_info;
  81222. FLAC__StreamMetadata_Padding padding;
  81223. FLAC__StreamMetadata_Application application;
  81224. FLAC__StreamMetadata_SeekTable seek_table;
  81225. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  81226. FLAC__StreamMetadata_CueSheet cue_sheet;
  81227. FLAC__StreamMetadata_Picture picture;
  81228. FLAC__StreamMetadata_Unknown unknown;
  81229. } data;
  81230. } FLAC__StreamMetadata;
  81231. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  81232. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  81233. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  81234. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  81235. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  81236. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  81237. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  81238. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  81239. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  81240. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  81241. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  81242. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  81243. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  81244. #ifdef __cplusplus
  81245. }
  81246. #endif
  81247. #endif
  81248. /*** End of inlined file: format.h ***/
  81249. /*** Start of inlined file: metadata.h ***/
  81250. #ifndef FLAC__METADATA_H
  81251. #define FLAC__METADATA_H
  81252. #include <sys/types.h> /* for off_t */
  81253. #ifdef __cplusplus
  81254. extern "C" {
  81255. #endif
  81256. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  81257. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  81258. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  81259. 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);
  81260. struct FLAC__Metadata_SimpleIterator;
  81261. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  81262. typedef enum {
  81263. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  81264. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  81265. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  81266. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  81267. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  81268. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  81269. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  81270. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  81271. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  81272. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  81273. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  81274. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  81275. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  81276. } FLAC__Metadata_SimpleIteratorStatus;
  81277. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  81278. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  81279. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  81280. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  81281. 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);
  81282. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  81283. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  81284. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81285. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81286. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81287. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81288. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81289. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81290. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81291. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81292. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81293. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81294. struct FLAC__Metadata_Chain;
  81295. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81296. struct FLAC__Metadata_Iterator;
  81297. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81298. typedef enum {
  81299. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81300. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81301. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81302. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81303. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81304. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81305. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81306. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81307. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81308. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81309. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81310. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81311. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81312. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81313. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81314. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81315. } FLAC__Metadata_ChainStatus;
  81316. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81317. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81318. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81319. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81320. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81321. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81322. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81323. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81324. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81325. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81326. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81327. 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);
  81328. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81329. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81330. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81331. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81332. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81333. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81334. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81335. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81336. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81337. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81338. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81339. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81340. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81341. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81342. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81343. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81344. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81345. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81346. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81347. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81348. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81349. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81350. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81351. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81352. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81353. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81354. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81355. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81356. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81357. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81358. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81359. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81360. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81361. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81362. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81363. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81364. 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);
  81365. 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);
  81366. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81367. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81368. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81369. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81370. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81371. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81372. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81373. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81374. 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);
  81375. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81376. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81377. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81378. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81379. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81380. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81381. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81382. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81383. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81384. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81385. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81386. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81387. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81388. #ifdef __cplusplus
  81389. }
  81390. #endif
  81391. #endif
  81392. /*** End of inlined file: metadata.h ***/
  81393. /*** Start of inlined file: stream_decoder.h ***/
  81394. #ifndef FLAC__STREAM_DECODER_H
  81395. #define FLAC__STREAM_DECODER_H
  81396. #include <stdio.h> /* for FILE */
  81397. #ifdef __cplusplus
  81398. extern "C" {
  81399. #endif
  81400. typedef enum {
  81401. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81402. FLAC__STREAM_DECODER_READ_METADATA,
  81403. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81404. FLAC__STREAM_DECODER_READ_FRAME,
  81405. FLAC__STREAM_DECODER_END_OF_STREAM,
  81406. FLAC__STREAM_DECODER_OGG_ERROR,
  81407. FLAC__STREAM_DECODER_SEEK_ERROR,
  81408. FLAC__STREAM_DECODER_ABORTED,
  81409. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81410. FLAC__STREAM_DECODER_UNINITIALIZED
  81411. } FLAC__StreamDecoderState;
  81412. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81413. typedef enum {
  81414. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81415. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81416. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81417. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81418. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81419. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81420. } FLAC__StreamDecoderInitStatus;
  81421. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81422. typedef enum {
  81423. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81424. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81425. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81426. } FLAC__StreamDecoderReadStatus;
  81427. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81428. typedef enum {
  81429. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81430. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81431. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81432. } FLAC__StreamDecoderSeekStatus;
  81433. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81434. typedef enum {
  81435. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81436. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81437. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81438. } FLAC__StreamDecoderTellStatus;
  81439. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81440. typedef enum {
  81441. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81442. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81443. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81444. } FLAC__StreamDecoderLengthStatus;
  81445. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81446. typedef enum {
  81447. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81448. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81449. } FLAC__StreamDecoderWriteStatus;
  81450. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81451. typedef enum {
  81452. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81453. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81454. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81455. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81456. } FLAC__StreamDecoderErrorStatus;
  81457. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81458. struct FLAC__StreamDecoderProtected;
  81459. struct FLAC__StreamDecoderPrivate;
  81460. typedef struct {
  81461. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81462. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81463. } FLAC__StreamDecoder;
  81464. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81465. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81466. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81467. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81468. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81469. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81470. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81471. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81472. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81473. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81474. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81475. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81476. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81477. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81478. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81479. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81480. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81481. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81482. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81483. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81484. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81485. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81486. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81487. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81488. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81489. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81490. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81491. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81492. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81493. FLAC__StreamDecoder *decoder,
  81494. FLAC__StreamDecoderReadCallback read_callback,
  81495. FLAC__StreamDecoderSeekCallback seek_callback,
  81496. FLAC__StreamDecoderTellCallback tell_callback,
  81497. FLAC__StreamDecoderLengthCallback length_callback,
  81498. FLAC__StreamDecoderEofCallback eof_callback,
  81499. FLAC__StreamDecoderWriteCallback write_callback,
  81500. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81501. FLAC__StreamDecoderErrorCallback error_callback,
  81502. void *client_data
  81503. );
  81504. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81505. FLAC__StreamDecoder *decoder,
  81506. FLAC__StreamDecoderReadCallback read_callback,
  81507. FLAC__StreamDecoderSeekCallback seek_callback,
  81508. FLAC__StreamDecoderTellCallback tell_callback,
  81509. FLAC__StreamDecoderLengthCallback length_callback,
  81510. FLAC__StreamDecoderEofCallback eof_callback,
  81511. FLAC__StreamDecoderWriteCallback write_callback,
  81512. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81513. FLAC__StreamDecoderErrorCallback error_callback,
  81514. void *client_data
  81515. );
  81516. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81517. FLAC__StreamDecoder *decoder,
  81518. FILE *file,
  81519. FLAC__StreamDecoderWriteCallback write_callback,
  81520. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81521. FLAC__StreamDecoderErrorCallback error_callback,
  81522. void *client_data
  81523. );
  81524. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81525. FLAC__StreamDecoder *decoder,
  81526. FILE *file,
  81527. FLAC__StreamDecoderWriteCallback write_callback,
  81528. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81529. FLAC__StreamDecoderErrorCallback error_callback,
  81530. void *client_data
  81531. );
  81532. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81533. FLAC__StreamDecoder *decoder,
  81534. const char *filename,
  81535. FLAC__StreamDecoderWriteCallback write_callback,
  81536. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81537. FLAC__StreamDecoderErrorCallback error_callback,
  81538. void *client_data
  81539. );
  81540. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81541. FLAC__StreamDecoder *decoder,
  81542. const char *filename,
  81543. FLAC__StreamDecoderWriteCallback write_callback,
  81544. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81545. FLAC__StreamDecoderErrorCallback error_callback,
  81546. void *client_data
  81547. );
  81548. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81549. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81550. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81551. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81552. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81553. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81554. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81555. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81556. #ifdef __cplusplus
  81557. }
  81558. #endif
  81559. #endif
  81560. /*** End of inlined file: stream_decoder.h ***/
  81561. /*** Start of inlined file: stream_encoder.h ***/
  81562. #ifndef FLAC__STREAM_ENCODER_H
  81563. #define FLAC__STREAM_ENCODER_H
  81564. #include <stdio.h> /* for FILE */
  81565. #ifdef __cplusplus
  81566. extern "C" {
  81567. #endif
  81568. typedef enum {
  81569. FLAC__STREAM_ENCODER_OK = 0,
  81570. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81571. FLAC__STREAM_ENCODER_OGG_ERROR,
  81572. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81573. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81574. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81575. FLAC__STREAM_ENCODER_IO_ERROR,
  81576. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81577. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81578. } FLAC__StreamEncoderState;
  81579. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81580. typedef enum {
  81581. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81582. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81583. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81584. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81585. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81586. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81587. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81588. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81589. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81590. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81591. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81592. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81593. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81594. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81595. } FLAC__StreamEncoderInitStatus;
  81596. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81597. typedef enum {
  81598. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81599. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81600. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81601. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81602. } FLAC__StreamEncoderReadStatus;
  81603. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81604. typedef enum {
  81605. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81606. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81607. } FLAC__StreamEncoderWriteStatus;
  81608. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81609. typedef enum {
  81610. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81611. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81612. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81613. } FLAC__StreamEncoderSeekStatus;
  81614. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81615. typedef enum {
  81616. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81617. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81618. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81619. } FLAC__StreamEncoderTellStatus;
  81620. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81621. struct FLAC__StreamEncoderProtected;
  81622. struct FLAC__StreamEncoderPrivate;
  81623. typedef struct {
  81624. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81625. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81626. } FLAC__StreamEncoder;
  81627. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81628. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81629. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81630. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81631. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81632. 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);
  81633. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81634. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81635. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81636. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81637. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81638. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81639. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81640. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81641. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81642. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81643. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81644. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81645. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81646. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81647. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81648. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81649. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81650. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81651. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81652. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81653. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81654. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81655. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81656. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81657. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81658. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81659. 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);
  81660. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81661. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81662. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81663. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81664. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81665. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81666. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81667. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81668. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81669. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81670. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81671. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81672. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81673. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81674. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81675. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81676. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81677. 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);
  81678. 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);
  81679. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81680. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81681. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81682. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81683. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81684. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81685. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81686. #ifdef __cplusplus
  81687. }
  81688. #endif
  81689. #endif
  81690. /*** End of inlined file: stream_encoder.h ***/
  81691. #ifdef _MSC_VER
  81692. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81693. {
  81694. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81695. return (x>>16) | (x<<16);
  81696. }
  81697. #endif
  81698. #if defined(_MSC_VER) && defined(_X86_)
  81699. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81700. {
  81701. __asm {
  81702. mov edx, start
  81703. mov ecx, len
  81704. test ecx, ecx
  81705. loop1:
  81706. jz done1
  81707. mov eax, [edx]
  81708. bswap eax
  81709. mov [edx], eax
  81710. add edx, 4
  81711. dec ecx
  81712. jmp short loop1
  81713. done1:
  81714. }
  81715. }
  81716. #endif
  81717. #endif
  81718. /*** End of inlined file: all.h ***/
  81719. /*** Start of inlined file: bitmath.c ***/
  81720. /*** Start of inlined file: juce_FlacHeader.h ***/
  81721. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81722. // tasks..
  81723. #define VERSION "1.2.1"
  81724. #define FLAC__NO_DLL 1
  81725. #if JUCE_MSVC
  81726. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81727. #endif
  81728. #if JUCE_MAC
  81729. #define FLAC__SYS_DARWIN 1
  81730. #endif
  81731. /*** End of inlined file: juce_FlacHeader.h ***/
  81732. #if JUCE_USE_FLAC
  81733. #if HAVE_CONFIG_H
  81734. # include <config.h>
  81735. #endif
  81736. /*** Start of inlined file: bitmath.h ***/
  81737. #ifndef FLAC__PRIVATE__BITMATH_H
  81738. #define FLAC__PRIVATE__BITMATH_H
  81739. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81740. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81741. unsigned FLAC__bitmath_silog2(int v);
  81742. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81743. #endif
  81744. /*** End of inlined file: bitmath.h ***/
  81745. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81746. {
  81747. unsigned l = 0;
  81748. FLAC__ASSERT(v > 0);
  81749. while(v >>= 1)
  81750. l++;
  81751. return l;
  81752. }
  81753. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81754. {
  81755. unsigned l = 0;
  81756. FLAC__ASSERT(v > 0);
  81757. while(v >>= 1)
  81758. l++;
  81759. return l;
  81760. }
  81761. unsigned FLAC__bitmath_silog2(int v)
  81762. {
  81763. while(1) {
  81764. if(v == 0) {
  81765. return 0;
  81766. }
  81767. else if(v > 0) {
  81768. unsigned l = 0;
  81769. while(v) {
  81770. l++;
  81771. v >>= 1;
  81772. }
  81773. return l+1;
  81774. }
  81775. else if(v == -1) {
  81776. return 2;
  81777. }
  81778. else {
  81779. v++;
  81780. v = -v;
  81781. }
  81782. }
  81783. }
  81784. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81785. {
  81786. while(1) {
  81787. if(v == 0) {
  81788. return 0;
  81789. }
  81790. else if(v > 0) {
  81791. unsigned l = 0;
  81792. while(v) {
  81793. l++;
  81794. v >>= 1;
  81795. }
  81796. return l+1;
  81797. }
  81798. else if(v == -1) {
  81799. return 2;
  81800. }
  81801. else {
  81802. v++;
  81803. v = -v;
  81804. }
  81805. }
  81806. }
  81807. #endif
  81808. /*** End of inlined file: bitmath.c ***/
  81809. /*** Start of inlined file: bitreader.c ***/
  81810. /*** Start of inlined file: juce_FlacHeader.h ***/
  81811. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81812. // tasks..
  81813. #define VERSION "1.2.1"
  81814. #define FLAC__NO_DLL 1
  81815. #if JUCE_MSVC
  81816. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81817. #endif
  81818. #if JUCE_MAC
  81819. #define FLAC__SYS_DARWIN 1
  81820. #endif
  81821. /*** End of inlined file: juce_FlacHeader.h ***/
  81822. #if JUCE_USE_FLAC
  81823. #if HAVE_CONFIG_H
  81824. # include <config.h>
  81825. #endif
  81826. #include <stdlib.h> /* for malloc() */
  81827. #include <string.h> /* for memcpy(), memset() */
  81828. #ifdef _MSC_VER
  81829. #include <winsock.h> /* for ntohl() */
  81830. #elif defined FLAC__SYS_DARWIN
  81831. #include <machine/endian.h> /* for ntohl() */
  81832. #elif defined __MINGW32__
  81833. #include <winsock.h> /* for ntohl() */
  81834. #else
  81835. #include <netinet/in.h> /* for ntohl() */
  81836. #endif
  81837. /*** Start of inlined file: bitreader.h ***/
  81838. #ifndef FLAC__PRIVATE__BITREADER_H
  81839. #define FLAC__PRIVATE__BITREADER_H
  81840. #include <stdio.h> /* for FILE */
  81841. /*** Start of inlined file: cpu.h ***/
  81842. #ifndef FLAC__PRIVATE__CPU_H
  81843. #define FLAC__PRIVATE__CPU_H
  81844. #ifdef HAVE_CONFIG_H
  81845. #include <config.h>
  81846. #endif
  81847. typedef enum {
  81848. FLAC__CPUINFO_TYPE_IA32,
  81849. FLAC__CPUINFO_TYPE_PPC,
  81850. FLAC__CPUINFO_TYPE_UNKNOWN
  81851. } FLAC__CPUInfo_Type;
  81852. typedef struct {
  81853. FLAC__bool cpuid;
  81854. FLAC__bool bswap;
  81855. FLAC__bool cmov;
  81856. FLAC__bool mmx;
  81857. FLAC__bool fxsr;
  81858. FLAC__bool sse;
  81859. FLAC__bool sse2;
  81860. FLAC__bool sse3;
  81861. FLAC__bool ssse3;
  81862. FLAC__bool _3dnow;
  81863. FLAC__bool ext3dnow;
  81864. FLAC__bool extmmx;
  81865. } FLAC__CPUInfo_IA32;
  81866. typedef struct {
  81867. FLAC__bool altivec;
  81868. FLAC__bool ppc64;
  81869. } FLAC__CPUInfo_PPC;
  81870. typedef struct {
  81871. FLAC__bool use_asm;
  81872. FLAC__CPUInfo_Type type;
  81873. union {
  81874. FLAC__CPUInfo_IA32 ia32;
  81875. FLAC__CPUInfo_PPC ppc;
  81876. } data;
  81877. } FLAC__CPUInfo;
  81878. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81879. #ifndef FLAC__NO_ASM
  81880. #ifdef FLAC__CPU_IA32
  81881. #ifdef FLAC__HAS_NASM
  81882. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81883. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81884. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81885. #endif
  81886. #endif
  81887. #endif
  81888. #endif
  81889. /*** End of inlined file: cpu.h ***/
  81890. struct FLAC__BitReader;
  81891. typedef struct FLAC__BitReader FLAC__BitReader;
  81892. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81893. FLAC__BitReader *FLAC__bitreader_new(void);
  81894. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81895. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81896. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81897. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81898. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81899. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81900. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81901. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81902. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81903. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81904. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81905. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81906. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81907. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81908. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81909. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81910. 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! */
  81911. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81912. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81913. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81914. #ifndef FLAC__NO_ASM
  81915. # ifdef FLAC__CPU_IA32
  81916. # ifdef FLAC__HAS_NASM
  81917. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81918. # endif
  81919. # endif
  81920. #endif
  81921. #if 0 /* UNUSED */
  81922. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81923. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81924. #endif
  81925. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81926. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81927. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81928. #endif
  81929. /*** End of inlined file: bitreader.h ***/
  81930. /*** Start of inlined file: crc.h ***/
  81931. #ifndef FLAC__PRIVATE__CRC_H
  81932. #define FLAC__PRIVATE__CRC_H
  81933. extern FLAC__byte const FLAC__crc8_table[256];
  81934. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81935. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81936. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81937. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81938. extern unsigned FLAC__crc16_table[256];
  81939. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81940. #if 0
  81941. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81942. #endif
  81943. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81944. #endif
  81945. /*** End of inlined file: crc.h ***/
  81946. typedef FLAC__uint32 brword;
  81947. #define FLAC__BYTES_PER_WORD 4
  81948. #define FLAC__BITS_PER_WORD 32
  81949. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81950. #if WORDS_BIGENDIAN
  81951. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81952. #else
  81953. #if defined (_MSC_VER) && defined (_X86_)
  81954. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81955. #else
  81956. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81957. #endif
  81958. #endif
  81959. #define COUNT_ZERO_MSBS(word) ( \
  81960. (word) <= 0xffff ? \
  81961. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81962. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81963. )
  81964. #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])) )
  81965. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81966. static const unsigned char byte_to_unary_table[] = {
  81967. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81968. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81969. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81970. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81971. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81972. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81973. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81974. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81983. };
  81984. #ifdef min
  81985. #undef min
  81986. #endif
  81987. #define min(x,y) ((x)<(y)?(x):(y))
  81988. #ifdef max
  81989. #undef max
  81990. #endif
  81991. #define max(x,y) ((x)>(y)?(x):(y))
  81992. #ifdef _MSC_VER
  81993. #define FLAC__U64L(x) x
  81994. #else
  81995. #define FLAC__U64L(x) x##LLU
  81996. #endif
  81997. #ifndef FLaC__INLINE
  81998. #define FLaC__INLINE
  81999. #endif
  82000. struct FLAC__BitReader {
  82001. brword *buffer;
  82002. unsigned capacity; /* in words */
  82003. unsigned words; /* # of completed words in buffer */
  82004. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  82005. unsigned consumed_words; /* #words ... */
  82006. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  82007. unsigned read_crc16; /* the running frame CRC */
  82008. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  82009. FLAC__BitReaderReadCallback read_callback;
  82010. void *client_data;
  82011. FLAC__CPUInfo cpu_info;
  82012. };
  82013. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  82014. {
  82015. register unsigned crc = br->read_crc16;
  82016. #if FLAC__BYTES_PER_WORD == 4
  82017. switch(br->crc16_align) {
  82018. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  82019. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82020. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82021. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82022. }
  82023. #elif FLAC__BYTES_PER_WORD == 8
  82024. switch(br->crc16_align) {
  82025. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  82026. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  82027. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  82028. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  82029. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  82030. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82031. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82032. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82033. }
  82034. #else
  82035. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  82036. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  82037. br->read_crc16 = crc;
  82038. #endif
  82039. br->crc16_align = 0;
  82040. }
  82041. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  82042. {
  82043. unsigned start, end;
  82044. size_t bytes;
  82045. FLAC__byte *target;
  82046. if(br->consumed_words > 0) {
  82047. start = br->consumed_words;
  82048. end = br->words + (br->bytes? 1:0);
  82049. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  82050. br->words -= start;
  82051. br->consumed_words = 0;
  82052. }
  82053. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  82054. if(bytes == 0)
  82055. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  82056. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  82057. #if WORDS_BIGENDIAN
  82058. #else
  82059. if(br->bytes)
  82060. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  82061. #endif
  82062. if(!br->read_callback(target, &bytes, br->client_data))
  82063. return false;
  82064. #if WORDS_BIGENDIAN
  82065. #else
  82066. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  82067. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  82068. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  82069. start = br->words;
  82070. local_swap32_block_(br->buffer + start, end - start);
  82071. }
  82072. else
  82073. # endif
  82074. for(start = br->words; start < end; start++)
  82075. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  82076. #endif
  82077. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  82078. br->words = end / FLAC__BYTES_PER_WORD;
  82079. br->bytes = end % FLAC__BYTES_PER_WORD;
  82080. return true;
  82081. }
  82082. FLAC__BitReader *FLAC__bitreader_new(void)
  82083. {
  82084. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  82085. return br;
  82086. }
  82087. void FLAC__bitreader_delete(FLAC__BitReader *br)
  82088. {
  82089. FLAC__ASSERT(0 != br);
  82090. FLAC__bitreader_free(br);
  82091. free(br);
  82092. }
  82093. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  82094. {
  82095. FLAC__ASSERT(0 != br);
  82096. br->words = br->bytes = 0;
  82097. br->consumed_words = br->consumed_bits = 0;
  82098. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  82099. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  82100. if(br->buffer == 0)
  82101. return false;
  82102. br->read_callback = rcb;
  82103. br->client_data = cd;
  82104. br->cpu_info = cpu;
  82105. return true;
  82106. }
  82107. void FLAC__bitreader_free(FLAC__BitReader *br)
  82108. {
  82109. FLAC__ASSERT(0 != br);
  82110. if(0 != br->buffer)
  82111. free(br->buffer);
  82112. br->buffer = 0;
  82113. br->capacity = 0;
  82114. br->words = br->bytes = 0;
  82115. br->consumed_words = br->consumed_bits = 0;
  82116. br->read_callback = 0;
  82117. br->client_data = 0;
  82118. }
  82119. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  82120. {
  82121. br->words = br->bytes = 0;
  82122. br->consumed_words = br->consumed_bits = 0;
  82123. return true;
  82124. }
  82125. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  82126. {
  82127. unsigned i, j;
  82128. if(br == 0) {
  82129. fprintf(out, "bitreader is NULL\n");
  82130. }
  82131. else {
  82132. 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);
  82133. for(i = 0; i < br->words; i++) {
  82134. fprintf(out, "%08X: ", i);
  82135. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82136. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82137. fprintf(out, ".");
  82138. else
  82139. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82140. fprintf(out, "\n");
  82141. }
  82142. if(br->bytes > 0) {
  82143. fprintf(out, "%08X: ", i);
  82144. for(j = 0; j < br->bytes*8; j++)
  82145. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82146. fprintf(out, ".");
  82147. else
  82148. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  82149. fprintf(out, "\n");
  82150. }
  82151. }
  82152. }
  82153. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  82154. {
  82155. FLAC__ASSERT(0 != br);
  82156. FLAC__ASSERT(0 != br->buffer);
  82157. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82158. br->read_crc16 = (unsigned)seed;
  82159. br->crc16_align = br->consumed_bits;
  82160. }
  82161. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  82162. {
  82163. FLAC__ASSERT(0 != br);
  82164. FLAC__ASSERT(0 != br->buffer);
  82165. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82166. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  82167. if(br->consumed_bits) {
  82168. const brword tail = br->buffer[br->consumed_words];
  82169. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  82170. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  82171. }
  82172. return br->read_crc16;
  82173. }
  82174. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  82175. {
  82176. return ((br->consumed_bits & 7) == 0);
  82177. }
  82178. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  82179. {
  82180. return 8 - (br->consumed_bits & 7);
  82181. }
  82182. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  82183. {
  82184. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  82185. }
  82186. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  82187. {
  82188. FLAC__ASSERT(0 != br);
  82189. FLAC__ASSERT(0 != br->buffer);
  82190. FLAC__ASSERT(bits <= 32);
  82191. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  82192. FLAC__ASSERT(br->consumed_words <= br->words);
  82193. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82194. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  82195. *val = 0;
  82196. return true;
  82197. }
  82198. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  82199. if(!bitreader_read_from_client_(br))
  82200. return false;
  82201. }
  82202. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82203. if(br->consumed_bits) {
  82204. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  82205. const brword word = br->buffer[br->consumed_words];
  82206. if(bits < n) {
  82207. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  82208. br->consumed_bits += bits;
  82209. return true;
  82210. }
  82211. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  82212. bits -= n;
  82213. crc16_update_word_(br, word);
  82214. br->consumed_words++;
  82215. br->consumed_bits = 0;
  82216. 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 */
  82217. *val <<= bits;
  82218. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  82219. br->consumed_bits = bits;
  82220. }
  82221. return true;
  82222. }
  82223. else {
  82224. const brword word = br->buffer[br->consumed_words];
  82225. if(bits < FLAC__BITS_PER_WORD) {
  82226. *val = word >> (FLAC__BITS_PER_WORD-bits);
  82227. br->consumed_bits = bits;
  82228. return true;
  82229. }
  82230. *val = word;
  82231. crc16_update_word_(br, word);
  82232. br->consumed_words++;
  82233. return true;
  82234. }
  82235. }
  82236. else {
  82237. if(br->consumed_bits) {
  82238. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  82239. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  82240. br->consumed_bits += bits;
  82241. return true;
  82242. }
  82243. else {
  82244. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  82245. br->consumed_bits += bits;
  82246. return true;
  82247. }
  82248. }
  82249. }
  82250. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  82251. {
  82252. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  82253. return false;
  82254. *val <<= (32-bits);
  82255. *val >>= (32-bits);
  82256. return true;
  82257. }
  82258. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  82259. {
  82260. FLAC__uint32 hi, lo;
  82261. if(bits > 32) {
  82262. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  82263. return false;
  82264. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  82265. return false;
  82266. *val = hi;
  82267. *val <<= 32;
  82268. *val |= lo;
  82269. }
  82270. else {
  82271. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  82272. return false;
  82273. *val = lo;
  82274. }
  82275. return true;
  82276. }
  82277. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  82278. {
  82279. FLAC__uint32 x8, x32 = 0;
  82280. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  82281. return false;
  82282. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82283. return false;
  82284. x32 |= (x8 << 8);
  82285. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82286. return false;
  82287. x32 |= (x8 << 16);
  82288. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82289. return false;
  82290. x32 |= (x8 << 24);
  82291. *val = x32;
  82292. return true;
  82293. }
  82294. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82295. {
  82296. FLAC__ASSERT(0 != br);
  82297. FLAC__ASSERT(0 != br->buffer);
  82298. if(bits > 0) {
  82299. const unsigned n = br->consumed_bits & 7;
  82300. unsigned m;
  82301. FLAC__uint32 x;
  82302. if(n != 0) {
  82303. m = min(8-n, bits);
  82304. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82305. return false;
  82306. bits -= m;
  82307. }
  82308. m = bits / 8;
  82309. if(m > 0) {
  82310. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82311. return false;
  82312. bits %= 8;
  82313. }
  82314. if(bits > 0) {
  82315. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82316. return false;
  82317. }
  82318. }
  82319. return true;
  82320. }
  82321. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82322. {
  82323. FLAC__uint32 x;
  82324. FLAC__ASSERT(0 != br);
  82325. FLAC__ASSERT(0 != br->buffer);
  82326. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82327. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82328. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82329. return false;
  82330. nvals--;
  82331. }
  82332. if(0 == nvals)
  82333. return true;
  82334. while(nvals >= FLAC__BYTES_PER_WORD) {
  82335. if(br->consumed_words < br->words) {
  82336. br->consumed_words++;
  82337. nvals -= FLAC__BYTES_PER_WORD;
  82338. }
  82339. else if(!bitreader_read_from_client_(br))
  82340. return false;
  82341. }
  82342. while(nvals) {
  82343. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82344. return false;
  82345. nvals--;
  82346. }
  82347. return true;
  82348. }
  82349. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82350. {
  82351. FLAC__uint32 x;
  82352. FLAC__ASSERT(0 != br);
  82353. FLAC__ASSERT(0 != br->buffer);
  82354. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82355. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82356. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82357. return false;
  82358. *val++ = (FLAC__byte)x;
  82359. nvals--;
  82360. }
  82361. if(0 == nvals)
  82362. return true;
  82363. while(nvals >= FLAC__BYTES_PER_WORD) {
  82364. if(br->consumed_words < br->words) {
  82365. const brword word = br->buffer[br->consumed_words++];
  82366. #if FLAC__BYTES_PER_WORD == 4
  82367. val[0] = (FLAC__byte)(word >> 24);
  82368. val[1] = (FLAC__byte)(word >> 16);
  82369. val[2] = (FLAC__byte)(word >> 8);
  82370. val[3] = (FLAC__byte)word;
  82371. #elif FLAC__BYTES_PER_WORD == 8
  82372. val[0] = (FLAC__byte)(word >> 56);
  82373. val[1] = (FLAC__byte)(word >> 48);
  82374. val[2] = (FLAC__byte)(word >> 40);
  82375. val[3] = (FLAC__byte)(word >> 32);
  82376. val[4] = (FLAC__byte)(word >> 24);
  82377. val[5] = (FLAC__byte)(word >> 16);
  82378. val[6] = (FLAC__byte)(word >> 8);
  82379. val[7] = (FLAC__byte)word;
  82380. #else
  82381. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82382. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82383. #endif
  82384. val += FLAC__BYTES_PER_WORD;
  82385. nvals -= FLAC__BYTES_PER_WORD;
  82386. }
  82387. else if(!bitreader_read_from_client_(br))
  82388. return false;
  82389. }
  82390. while(nvals) {
  82391. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82392. return false;
  82393. *val++ = (FLAC__byte)x;
  82394. nvals--;
  82395. }
  82396. return true;
  82397. }
  82398. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82399. #if 0 /* slow but readable version */
  82400. {
  82401. unsigned bit;
  82402. FLAC__ASSERT(0 != br);
  82403. FLAC__ASSERT(0 != br->buffer);
  82404. *val = 0;
  82405. while(1) {
  82406. if(!FLAC__bitreader_read_bit(br, &bit))
  82407. return false;
  82408. if(bit)
  82409. break;
  82410. else
  82411. *val++;
  82412. }
  82413. return true;
  82414. }
  82415. #else
  82416. {
  82417. unsigned i;
  82418. FLAC__ASSERT(0 != br);
  82419. FLAC__ASSERT(0 != br->buffer);
  82420. *val = 0;
  82421. while(1) {
  82422. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82423. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82424. if(b) {
  82425. i = COUNT_ZERO_MSBS(b);
  82426. *val += i;
  82427. i++;
  82428. br->consumed_bits += i;
  82429. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82430. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82431. br->consumed_words++;
  82432. br->consumed_bits = 0;
  82433. }
  82434. return true;
  82435. }
  82436. else {
  82437. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82438. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82439. br->consumed_words++;
  82440. br->consumed_bits = 0;
  82441. }
  82442. }
  82443. if(br->bytes) {
  82444. const unsigned end = br->bytes * 8;
  82445. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82446. if(b) {
  82447. i = COUNT_ZERO_MSBS(b);
  82448. *val += i;
  82449. i++;
  82450. br->consumed_bits += i;
  82451. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82452. return true;
  82453. }
  82454. else {
  82455. *val += end - br->consumed_bits;
  82456. br->consumed_bits += end;
  82457. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82458. }
  82459. }
  82460. if(!bitreader_read_from_client_(br))
  82461. return false;
  82462. }
  82463. }
  82464. #endif
  82465. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82466. {
  82467. FLAC__uint32 lsbs = 0, msbs = 0;
  82468. unsigned uval;
  82469. FLAC__ASSERT(0 != br);
  82470. FLAC__ASSERT(0 != br->buffer);
  82471. FLAC__ASSERT(parameter <= 31);
  82472. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82473. return false;
  82474. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82475. return false;
  82476. uval = (msbs << parameter) | lsbs;
  82477. if(uval & 1)
  82478. *val = -((int)(uval >> 1)) - 1;
  82479. else
  82480. *val = (int)(uval >> 1);
  82481. return true;
  82482. }
  82483. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82484. #ifdef _MSC_VER
  82485. {
  82486. unsigned i;
  82487. unsigned uval = 0;
  82488. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82489. register unsigned cwords;
  82490. register unsigned cbits;
  82491. FLAC__ASSERT(0 != br);
  82492. FLAC__ASSERT(0 != br->buffer);
  82493. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82494. FLAC__ASSERT(parameter < 32);
  82495. if(nvals == 0)
  82496. return true;
  82497. cbits = br->consumed_bits;
  82498. cwords = br->consumed_words;
  82499. while(1) {
  82500. while(1) {
  82501. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82502. brword b = br->buffer[cwords] << cbits;
  82503. if(b) {
  82504. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82505. __asm {
  82506. bsr eax, b
  82507. not eax
  82508. and eax, 31
  82509. mov i, eax
  82510. }
  82511. #else
  82512. i = COUNT_ZERO_MSBS(b);
  82513. #endif
  82514. uval += i;
  82515. bits = parameter;
  82516. i++;
  82517. cbits += i;
  82518. if(cbits == FLAC__BITS_PER_WORD) {
  82519. crc16_update_word_(br, br->buffer[cwords]);
  82520. cwords++;
  82521. cbits = 0;
  82522. }
  82523. goto break1;
  82524. }
  82525. else {
  82526. uval += FLAC__BITS_PER_WORD - cbits;
  82527. crc16_update_word_(br, br->buffer[cwords]);
  82528. cwords++;
  82529. cbits = 0;
  82530. }
  82531. }
  82532. if(br->bytes) {
  82533. const unsigned end = br->bytes * 8;
  82534. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82535. if(b) {
  82536. i = COUNT_ZERO_MSBS(b);
  82537. uval += i;
  82538. bits = parameter;
  82539. i++;
  82540. cbits += i;
  82541. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82542. goto break1;
  82543. }
  82544. else {
  82545. uval += end - cbits;
  82546. cbits += end;
  82547. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82548. }
  82549. }
  82550. br->consumed_bits = cbits;
  82551. br->consumed_words = cwords;
  82552. if(!bitreader_read_from_client_(br))
  82553. return false;
  82554. cwords = br->consumed_words;
  82555. }
  82556. break1:
  82557. FLAC__ASSERT(cwords <= br->words);
  82558. if(bits) {
  82559. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  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. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82567. if(cbits) {
  82568. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82569. const brword word = br->buffer[cwords];
  82570. if(bits < n) {
  82571. uval <<= bits;
  82572. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82573. cbits += bits;
  82574. goto break2;
  82575. }
  82576. uval <<= n;
  82577. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82578. bits -= n;
  82579. crc16_update_word_(br, word);
  82580. cwords++;
  82581. cbits = 0;
  82582. 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 */
  82583. uval <<= bits;
  82584. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82585. cbits = bits;
  82586. }
  82587. goto break2;
  82588. }
  82589. else {
  82590. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82591. uval <<= bits;
  82592. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82593. cbits = bits;
  82594. goto break2;
  82595. }
  82596. }
  82597. else {
  82598. uval <<= bits;
  82599. if(cbits) {
  82600. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82601. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82602. cbits += bits;
  82603. goto break2;
  82604. }
  82605. else {
  82606. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82607. cbits += bits;
  82608. goto break2;
  82609. }
  82610. }
  82611. }
  82612. break2:
  82613. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82614. --nvals;
  82615. if(nvals == 0) {
  82616. br->consumed_bits = cbits;
  82617. br->consumed_words = cwords;
  82618. return true;
  82619. }
  82620. uval = 0;
  82621. ++vals;
  82622. }
  82623. }
  82624. #else
  82625. {
  82626. unsigned i;
  82627. unsigned uval = 0;
  82628. register unsigned cwords;
  82629. register unsigned cbits;
  82630. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82631. FLAC__ASSERT(0 != br);
  82632. FLAC__ASSERT(0 != br->buffer);
  82633. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82634. FLAC__ASSERT(parameter < 32);
  82635. if(nvals == 0)
  82636. return true;
  82637. cbits = br->consumed_bits;
  82638. cwords = br->consumed_words;
  82639. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82640. while(1) {
  82641. while(1) {
  82642. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82643. brword b = br->buffer[cwords] << cbits;
  82644. if(b) {
  82645. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82646. asm volatile (
  82647. "bsrl %1, %0;"
  82648. "notl %0;"
  82649. "andl $31, %0;"
  82650. : "=r"(i)
  82651. : "r"(b)
  82652. );
  82653. #else
  82654. i = COUNT_ZERO_MSBS(b);
  82655. #endif
  82656. uval += i;
  82657. cbits += i;
  82658. cbits++; /* skip over stop bit */
  82659. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82660. crc16_update_word_(br, br->buffer[cwords]);
  82661. cwords++;
  82662. cbits = 0;
  82663. }
  82664. goto break1;
  82665. }
  82666. else {
  82667. uval += FLAC__BITS_PER_WORD - cbits;
  82668. crc16_update_word_(br, br->buffer[cwords]);
  82669. cwords++;
  82670. cbits = 0;
  82671. }
  82672. }
  82673. if(br->bytes) {
  82674. const unsigned end = br->bytes * 8;
  82675. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82676. if(b) {
  82677. i = COUNT_ZERO_MSBS(b);
  82678. uval += i;
  82679. cbits += i;
  82680. cbits++; /* skip over stop bit */
  82681. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82682. goto break1;
  82683. }
  82684. else {
  82685. uval += end - cbits;
  82686. cbits += end;
  82687. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82688. }
  82689. }
  82690. br->consumed_bits = cbits;
  82691. br->consumed_words = cwords;
  82692. if(!bitreader_read_from_client_(br))
  82693. return false;
  82694. cwords = br->consumed_words;
  82695. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82696. }
  82697. break1:
  82698. ucbits -= uval;
  82699. ucbits--; /* account for stop bit */
  82700. FLAC__ASSERT(cwords <= br->words);
  82701. if(parameter) {
  82702. while(ucbits < parameter) {
  82703. br->consumed_bits = cbits;
  82704. br->consumed_words = cwords;
  82705. if(!bitreader_read_from_client_(br))
  82706. return false;
  82707. cwords = br->consumed_words;
  82708. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82709. }
  82710. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82711. if(cbits) {
  82712. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82713. const brword word = br->buffer[cwords];
  82714. if(parameter < n) {
  82715. uval <<= parameter;
  82716. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82717. cbits += parameter;
  82718. }
  82719. else {
  82720. uval <<= n;
  82721. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82722. crc16_update_word_(br, word);
  82723. cwords++;
  82724. cbits = parameter - n;
  82725. 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 */
  82726. uval <<= cbits;
  82727. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82728. }
  82729. }
  82730. }
  82731. else {
  82732. cbits = parameter;
  82733. uval <<= parameter;
  82734. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82735. }
  82736. }
  82737. else {
  82738. uval <<= parameter;
  82739. if(cbits) {
  82740. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82741. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82742. cbits += parameter;
  82743. }
  82744. else {
  82745. cbits = parameter;
  82746. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82747. }
  82748. }
  82749. }
  82750. ucbits -= parameter;
  82751. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82752. --nvals;
  82753. if(nvals == 0) {
  82754. br->consumed_bits = cbits;
  82755. br->consumed_words = cwords;
  82756. return true;
  82757. }
  82758. uval = 0;
  82759. ++vals;
  82760. }
  82761. }
  82762. #endif
  82763. #if 0 /* UNUSED */
  82764. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82765. {
  82766. FLAC__uint32 lsbs = 0, msbs = 0;
  82767. unsigned bit, uval, k;
  82768. FLAC__ASSERT(0 != br);
  82769. FLAC__ASSERT(0 != br->buffer);
  82770. k = FLAC__bitmath_ilog2(parameter);
  82771. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82772. return false;
  82773. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82774. return false;
  82775. if(parameter == 1u<<k) {
  82776. uval = (msbs << k) | lsbs;
  82777. }
  82778. else {
  82779. unsigned d = (1 << (k+1)) - parameter;
  82780. if(lsbs >= d) {
  82781. if(!FLAC__bitreader_read_bit(br, &bit))
  82782. return false;
  82783. lsbs <<= 1;
  82784. lsbs |= bit;
  82785. lsbs -= d;
  82786. }
  82787. uval = msbs * parameter + lsbs;
  82788. }
  82789. if(uval & 1)
  82790. *val = -((int)(uval >> 1)) - 1;
  82791. else
  82792. *val = (int)(uval >> 1);
  82793. return true;
  82794. }
  82795. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82796. {
  82797. FLAC__uint32 lsbs, msbs = 0;
  82798. unsigned bit, k;
  82799. FLAC__ASSERT(0 != br);
  82800. FLAC__ASSERT(0 != br->buffer);
  82801. k = FLAC__bitmath_ilog2(parameter);
  82802. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82803. return false;
  82804. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82805. return false;
  82806. if(parameter == 1u<<k) {
  82807. *val = (msbs << k) | lsbs;
  82808. }
  82809. else {
  82810. unsigned d = (1 << (k+1)) - parameter;
  82811. if(lsbs >= d) {
  82812. if(!FLAC__bitreader_read_bit(br, &bit))
  82813. return false;
  82814. lsbs <<= 1;
  82815. lsbs |= bit;
  82816. lsbs -= d;
  82817. }
  82818. *val = msbs * parameter + lsbs;
  82819. }
  82820. return true;
  82821. }
  82822. #endif /* UNUSED */
  82823. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82824. {
  82825. FLAC__uint32 v = 0;
  82826. FLAC__uint32 x;
  82827. unsigned i;
  82828. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82829. return false;
  82830. if(raw)
  82831. raw[(*rawlen)++] = (FLAC__byte)x;
  82832. if(!(x & 0x80)) { /* 0xxxxxxx */
  82833. v = x;
  82834. i = 0;
  82835. }
  82836. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82837. v = x & 0x1F;
  82838. i = 1;
  82839. }
  82840. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82841. v = x & 0x0F;
  82842. i = 2;
  82843. }
  82844. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82845. v = x & 0x07;
  82846. i = 3;
  82847. }
  82848. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82849. v = x & 0x03;
  82850. i = 4;
  82851. }
  82852. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82853. v = x & 0x01;
  82854. i = 5;
  82855. }
  82856. else {
  82857. *val = 0xffffffff;
  82858. return true;
  82859. }
  82860. for( ; i; i--) {
  82861. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82862. return false;
  82863. if(raw)
  82864. raw[(*rawlen)++] = (FLAC__byte)x;
  82865. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82866. *val = 0xffffffff;
  82867. return true;
  82868. }
  82869. v <<= 6;
  82870. v |= (x & 0x3F);
  82871. }
  82872. *val = v;
  82873. return true;
  82874. }
  82875. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82876. {
  82877. FLAC__uint64 v = 0;
  82878. FLAC__uint32 x;
  82879. unsigned i;
  82880. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82881. return false;
  82882. if(raw)
  82883. raw[(*rawlen)++] = (FLAC__byte)x;
  82884. if(!(x & 0x80)) { /* 0xxxxxxx */
  82885. v = x;
  82886. i = 0;
  82887. }
  82888. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82889. v = x & 0x1F;
  82890. i = 1;
  82891. }
  82892. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82893. v = x & 0x0F;
  82894. i = 2;
  82895. }
  82896. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82897. v = x & 0x07;
  82898. i = 3;
  82899. }
  82900. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82901. v = x & 0x03;
  82902. i = 4;
  82903. }
  82904. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82905. v = x & 0x01;
  82906. i = 5;
  82907. }
  82908. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82909. v = 0;
  82910. i = 6;
  82911. }
  82912. else {
  82913. *val = FLAC__U64L(0xffffffffffffffff);
  82914. return true;
  82915. }
  82916. for( ; i; i--) {
  82917. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82918. return false;
  82919. if(raw)
  82920. raw[(*rawlen)++] = (FLAC__byte)x;
  82921. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82922. *val = FLAC__U64L(0xffffffffffffffff);
  82923. return true;
  82924. }
  82925. v <<= 6;
  82926. v |= (x & 0x3F);
  82927. }
  82928. *val = v;
  82929. return true;
  82930. }
  82931. #endif
  82932. /*** End of inlined file: bitreader.c ***/
  82933. /*** Start of inlined file: bitwriter.c ***/
  82934. /*** Start of inlined file: juce_FlacHeader.h ***/
  82935. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82936. // tasks..
  82937. #define VERSION "1.2.1"
  82938. #define FLAC__NO_DLL 1
  82939. #if JUCE_MSVC
  82940. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82941. #endif
  82942. #if JUCE_MAC
  82943. #define FLAC__SYS_DARWIN 1
  82944. #endif
  82945. /*** End of inlined file: juce_FlacHeader.h ***/
  82946. #if JUCE_USE_FLAC
  82947. #if HAVE_CONFIG_H
  82948. # include <config.h>
  82949. #endif
  82950. #include <stdlib.h> /* for malloc() */
  82951. #include <string.h> /* for memcpy(), memset() */
  82952. #ifdef _MSC_VER
  82953. #include <winsock.h> /* for ntohl() */
  82954. #elif defined FLAC__SYS_DARWIN
  82955. #include <machine/endian.h> /* for ntohl() */
  82956. #elif defined __MINGW32__
  82957. #include <winsock.h> /* for ntohl() */
  82958. #else
  82959. #include <netinet/in.h> /* for ntohl() */
  82960. #endif
  82961. #if 0 /* UNUSED */
  82962. #endif
  82963. /*** Start of inlined file: bitwriter.h ***/
  82964. #ifndef FLAC__PRIVATE__BITWRITER_H
  82965. #define FLAC__PRIVATE__BITWRITER_H
  82966. #include <stdio.h> /* for FILE */
  82967. struct FLAC__BitWriter;
  82968. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82969. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82970. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82971. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82972. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82973. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82974. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82975. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82976. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82977. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82978. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82979. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82980. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82981. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82982. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82983. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82984. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82985. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82986. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82987. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82988. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82989. #if 0 /* UNUSED */
  82990. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82991. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82992. #endif
  82993. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82994. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82995. #if 0 /* UNUSED */
  82996. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82997. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82998. #endif
  82999. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  83000. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  83001. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  83002. #endif
  83003. /*** End of inlined file: bitwriter.h ***/
  83004. /*** Start of inlined file: alloc.h ***/
  83005. #ifndef FLAC__SHARE__ALLOC_H
  83006. #define FLAC__SHARE__ALLOC_H
  83007. #if HAVE_CONFIG_H
  83008. # include <config.h>
  83009. #endif
  83010. #include <limits.h> /* for SIZE_MAX */
  83011. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  83012. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  83013. #endif
  83014. #include <stdlib.h> /* for size_t, malloc(), etc */
  83015. #ifndef SIZE_MAX
  83016. # ifndef SIZE_T_MAX
  83017. # ifdef _MSC_VER
  83018. # define SIZE_T_MAX UINT_MAX
  83019. # else
  83020. # error
  83021. # endif
  83022. # endif
  83023. # define SIZE_MAX SIZE_T_MAX
  83024. #endif
  83025. #ifndef FLaC__INLINE
  83026. #define FLaC__INLINE
  83027. #endif
  83028. static FLaC__INLINE void *safe_malloc_(size_t size)
  83029. {
  83030. if(!size)
  83031. size++;
  83032. return malloc(size);
  83033. }
  83034. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  83035. {
  83036. if(!nmemb || !size)
  83037. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83038. return calloc(nmemb, size);
  83039. }
  83040. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  83041. {
  83042. size2 += size1;
  83043. if(size2 < size1)
  83044. return 0;
  83045. return safe_malloc_(size2);
  83046. }
  83047. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  83048. {
  83049. size2 += size1;
  83050. if(size2 < size1)
  83051. return 0;
  83052. size3 += size2;
  83053. if(size3 < size2)
  83054. return 0;
  83055. return safe_malloc_(size3);
  83056. }
  83057. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  83058. {
  83059. size2 += size1;
  83060. if(size2 < size1)
  83061. return 0;
  83062. size3 += size2;
  83063. if(size3 < size2)
  83064. return 0;
  83065. size4 += size3;
  83066. if(size4 < size3)
  83067. return 0;
  83068. return safe_malloc_(size4);
  83069. }
  83070. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  83071. #if 0
  83072. needs support for cases where sizeof(size_t) != 4
  83073. {
  83074. if(sizeof(size_t) == 4) {
  83075. if ((double)size1 * (double)size2 < 4294967296.0)
  83076. return malloc(size1*size2);
  83077. }
  83078. return 0;
  83079. }
  83080. #else
  83081. {
  83082. if(!size1 || !size2)
  83083. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83084. if(size1 > SIZE_MAX / size2)
  83085. return 0;
  83086. return malloc(size1*size2);
  83087. }
  83088. #endif
  83089. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  83090. {
  83091. if(!size1 || !size2 || !size3)
  83092. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83093. if(size1 > SIZE_MAX / size2)
  83094. return 0;
  83095. size1 *= size2;
  83096. if(size1 > SIZE_MAX / size3)
  83097. return 0;
  83098. return malloc(size1*size3);
  83099. }
  83100. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  83101. {
  83102. if(!size1 || !size2)
  83103. return safe_malloc_(size3);
  83104. if(size1 > SIZE_MAX / size2)
  83105. return 0;
  83106. return safe_malloc_add_2op_(size1*size2, size3);
  83107. }
  83108. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  83109. {
  83110. if(!size1 || (!size2 && !size3))
  83111. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83112. size2 += size3;
  83113. if(size2 < size3)
  83114. return 0;
  83115. return safe_malloc_mul_2op_(size1, size2);
  83116. }
  83117. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  83118. {
  83119. size2 += size1;
  83120. if(size2 < size1)
  83121. return 0;
  83122. return realloc(ptr, size2);
  83123. }
  83124. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  83125. {
  83126. size2 += size1;
  83127. if(size2 < size1)
  83128. return 0;
  83129. size3 += size2;
  83130. if(size3 < size2)
  83131. return 0;
  83132. return realloc(ptr, size3);
  83133. }
  83134. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  83135. {
  83136. size2 += size1;
  83137. if(size2 < size1)
  83138. return 0;
  83139. size3 += size2;
  83140. if(size3 < size2)
  83141. return 0;
  83142. size4 += size3;
  83143. if(size4 < size3)
  83144. return 0;
  83145. return realloc(ptr, size4);
  83146. }
  83147. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  83148. {
  83149. if(!size1 || !size2)
  83150. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83151. if(size1 > SIZE_MAX / size2)
  83152. return 0;
  83153. return realloc(ptr, size1*size2);
  83154. }
  83155. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  83156. {
  83157. if(!size1 || (!size2 && !size3))
  83158. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83159. size2 += size3;
  83160. if(size2 < size3)
  83161. return 0;
  83162. return safe_realloc_mul_2op_(ptr, size1, size2);
  83163. }
  83164. #endif
  83165. /*** End of inlined file: alloc.h ***/
  83166. typedef FLAC__uint32 bwword;
  83167. #define FLAC__BYTES_PER_WORD 4
  83168. #define FLAC__BITS_PER_WORD 32
  83169. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  83170. #if WORDS_BIGENDIAN
  83171. #define SWAP_BE_WORD_TO_HOST(x) (x)
  83172. #else
  83173. #ifdef _MSC_VER
  83174. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  83175. #else
  83176. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  83177. #endif
  83178. #endif
  83179. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  83180. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  83181. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  83182. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  83183. #ifdef min
  83184. #undef min
  83185. #endif
  83186. #define min(x,y) ((x)<(y)?(x):(y))
  83187. #ifdef _MSC_VER
  83188. #define FLAC__U64L(x) x
  83189. #else
  83190. #define FLAC__U64L(x) x##LLU
  83191. #endif
  83192. #ifndef FLaC__INLINE
  83193. #define FLaC__INLINE
  83194. #endif
  83195. struct FLAC__BitWriter {
  83196. bwword *buffer;
  83197. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  83198. unsigned capacity; /* capacity of buffer in words */
  83199. unsigned words; /* # of complete words in buffer */
  83200. unsigned bits; /* # of used bits in accum */
  83201. };
  83202. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  83203. {
  83204. unsigned new_capacity;
  83205. bwword *new_buffer;
  83206. FLAC__ASSERT(0 != bw);
  83207. FLAC__ASSERT(0 != bw->buffer);
  83208. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  83209. if(bw->capacity >= new_capacity)
  83210. return true;
  83211. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  83212. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83213. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83214. FLAC__ASSERT(new_capacity > bw->capacity);
  83215. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  83216. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  83217. if(new_buffer == 0)
  83218. return false;
  83219. bw->buffer = new_buffer;
  83220. bw->capacity = new_capacity;
  83221. return true;
  83222. }
  83223. FLAC__BitWriter *FLAC__bitwriter_new(void)
  83224. {
  83225. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  83226. return bw;
  83227. }
  83228. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  83229. {
  83230. FLAC__ASSERT(0 != bw);
  83231. FLAC__bitwriter_free(bw);
  83232. free(bw);
  83233. }
  83234. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  83235. {
  83236. FLAC__ASSERT(0 != bw);
  83237. bw->words = bw->bits = 0;
  83238. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  83239. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  83240. if(bw->buffer == 0)
  83241. return false;
  83242. return true;
  83243. }
  83244. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  83245. {
  83246. FLAC__ASSERT(0 != bw);
  83247. if(0 != bw->buffer)
  83248. free(bw->buffer);
  83249. bw->buffer = 0;
  83250. bw->capacity = 0;
  83251. bw->words = bw->bits = 0;
  83252. }
  83253. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  83254. {
  83255. bw->words = bw->bits = 0;
  83256. }
  83257. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  83258. {
  83259. unsigned i, j;
  83260. if(bw == 0) {
  83261. fprintf(out, "bitwriter is NULL\n");
  83262. }
  83263. else {
  83264. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  83265. for(i = 0; i < bw->words; i++) {
  83266. fprintf(out, "%08X: ", i);
  83267. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  83268. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  83269. fprintf(out, "\n");
  83270. }
  83271. if(bw->bits > 0) {
  83272. fprintf(out, "%08X: ", i);
  83273. for(j = 0; j < bw->bits; j++)
  83274. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  83275. fprintf(out, "\n");
  83276. }
  83277. }
  83278. }
  83279. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  83280. {
  83281. const FLAC__byte *buffer;
  83282. size_t bytes;
  83283. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83284. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83285. return false;
  83286. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83287. FLAC__bitwriter_release_buffer(bw);
  83288. return true;
  83289. }
  83290. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  83291. {
  83292. const FLAC__byte *buffer;
  83293. size_t bytes;
  83294. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83295. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83296. return false;
  83297. *crc = FLAC__crc8(buffer, bytes);
  83298. FLAC__bitwriter_release_buffer(bw);
  83299. return true;
  83300. }
  83301. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83302. {
  83303. return ((bw->bits & 7) == 0);
  83304. }
  83305. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83306. {
  83307. return FLAC__TOTAL_BITS(bw);
  83308. }
  83309. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83310. {
  83311. FLAC__ASSERT((bw->bits & 7) == 0);
  83312. if(bw->bits & 7)
  83313. return false;
  83314. if(bw->bits) {
  83315. FLAC__ASSERT(bw->words <= bw->capacity);
  83316. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83317. return false;
  83318. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83319. }
  83320. *buffer = (FLAC__byte*)bw->buffer;
  83321. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83322. return true;
  83323. }
  83324. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83325. {
  83326. (void)bw;
  83327. }
  83328. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83329. {
  83330. unsigned n;
  83331. FLAC__ASSERT(0 != bw);
  83332. FLAC__ASSERT(0 != bw->buffer);
  83333. if(bits == 0)
  83334. return true;
  83335. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83336. return false;
  83337. if(bw->bits) {
  83338. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83339. bw->accum <<= n;
  83340. bits -= n;
  83341. bw->bits += n;
  83342. if(bw->bits == FLAC__BITS_PER_WORD) {
  83343. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83344. bw->bits = 0;
  83345. }
  83346. else
  83347. return true;
  83348. }
  83349. while(bits >= FLAC__BITS_PER_WORD) {
  83350. bw->buffer[bw->words++] = 0;
  83351. bits -= FLAC__BITS_PER_WORD;
  83352. }
  83353. if(bits > 0) {
  83354. bw->accum = 0;
  83355. bw->bits = bits;
  83356. }
  83357. return true;
  83358. }
  83359. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83360. {
  83361. register unsigned left;
  83362. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83363. FLAC__ASSERT(0 != bw);
  83364. FLAC__ASSERT(0 != bw->buffer);
  83365. FLAC__ASSERT(bits <= 32);
  83366. if(bits == 0)
  83367. return true;
  83368. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83369. return false;
  83370. left = FLAC__BITS_PER_WORD - bw->bits;
  83371. if(bits < left) {
  83372. bw->accum <<= bits;
  83373. bw->accum |= val;
  83374. bw->bits += bits;
  83375. }
  83376. 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 */
  83377. bw->accum <<= left;
  83378. bw->accum |= val >> (bw->bits = bits - left);
  83379. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83380. bw->accum = val;
  83381. }
  83382. else {
  83383. bw->accum = val;
  83384. bw->bits = 0;
  83385. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83386. }
  83387. return true;
  83388. }
  83389. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83390. {
  83391. if(bits < 32)
  83392. val &= (~(0xffffffff << bits));
  83393. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83394. }
  83395. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83396. {
  83397. if(bits > 32) {
  83398. return
  83399. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83400. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83401. }
  83402. else
  83403. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83404. }
  83405. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83406. {
  83407. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83408. return false;
  83409. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83410. return false;
  83411. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83412. return false;
  83413. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83414. return false;
  83415. return true;
  83416. }
  83417. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83418. {
  83419. unsigned i;
  83420. for(i = 0; i < nvals; i++) {
  83421. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83422. return false;
  83423. }
  83424. return true;
  83425. }
  83426. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83427. {
  83428. if(val < 32)
  83429. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83430. else
  83431. return
  83432. FLAC__bitwriter_write_zeroes(bw, val) &&
  83433. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83434. }
  83435. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83436. {
  83437. FLAC__uint32 uval;
  83438. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83439. uval = (val<<1) ^ (val>>31);
  83440. return 1 + parameter + (uval >> parameter);
  83441. }
  83442. #if 0 /* UNUSED */
  83443. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83444. {
  83445. unsigned bits, msbs, uval;
  83446. unsigned k;
  83447. FLAC__ASSERT(parameter > 0);
  83448. if(val < 0)
  83449. uval = (unsigned)(((-(++val)) << 1) + 1);
  83450. else
  83451. uval = (unsigned)(val << 1);
  83452. k = FLAC__bitmath_ilog2(parameter);
  83453. if(parameter == 1u<<k) {
  83454. FLAC__ASSERT(k <= 30);
  83455. msbs = uval >> k;
  83456. bits = 1 + k + msbs;
  83457. }
  83458. else {
  83459. unsigned q, r, d;
  83460. d = (1 << (k+1)) - parameter;
  83461. q = uval / parameter;
  83462. r = uval - (q * parameter);
  83463. bits = 1 + q + k;
  83464. if(r >= d)
  83465. bits++;
  83466. }
  83467. return bits;
  83468. }
  83469. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83470. {
  83471. unsigned bits, msbs;
  83472. unsigned k;
  83473. FLAC__ASSERT(parameter > 0);
  83474. k = FLAC__bitmath_ilog2(parameter);
  83475. if(parameter == 1u<<k) {
  83476. FLAC__ASSERT(k <= 30);
  83477. msbs = uval >> k;
  83478. bits = 1 + k + msbs;
  83479. }
  83480. else {
  83481. unsigned q, r, d;
  83482. d = (1 << (k+1)) - parameter;
  83483. q = uval / parameter;
  83484. r = uval - (q * parameter);
  83485. bits = 1 + q + k;
  83486. if(r >= d)
  83487. bits++;
  83488. }
  83489. return bits;
  83490. }
  83491. #endif /* UNUSED */
  83492. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83493. {
  83494. unsigned total_bits, interesting_bits, msbs;
  83495. FLAC__uint32 uval, pattern;
  83496. FLAC__ASSERT(0 != bw);
  83497. FLAC__ASSERT(0 != bw->buffer);
  83498. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83499. uval = (val<<1) ^ (val>>31);
  83500. msbs = uval >> parameter;
  83501. interesting_bits = 1 + parameter;
  83502. total_bits = interesting_bits + msbs;
  83503. pattern = 1 << parameter; /* the unary end bit */
  83504. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83505. if(total_bits <= 32)
  83506. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83507. else
  83508. return
  83509. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83510. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83511. }
  83512. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83513. {
  83514. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83515. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83516. FLAC__uint32 uval;
  83517. unsigned left;
  83518. const unsigned lsbits = 1 + parameter;
  83519. unsigned msbits;
  83520. FLAC__ASSERT(0 != bw);
  83521. FLAC__ASSERT(0 != bw->buffer);
  83522. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83523. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83524. while(nvals) {
  83525. uval = (*vals<<1) ^ (*vals>>31);
  83526. msbits = uval >> parameter;
  83527. #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) */
  83528. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83529. bw->bits = bw->bits + msbits + lsbits;
  83530. uval |= mask1; /* set stop bit */
  83531. uval &= mask2; /* mask off unused top bits */
  83532. bw->accum <<= msbits;
  83533. bw->accum <<= lsbits;
  83534. bw->accum |= uval;
  83535. if(bw->bits == FLAC__BITS_PER_WORD) {
  83536. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83537. bw->bits = 0;
  83538. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83539. FLAC__ASSERT(bw->capacity == bw->words);
  83540. return false;
  83541. }
  83542. }
  83543. }
  83544. else {
  83545. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83546. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83547. bw->bits = bw->bits + msbits + lsbits;
  83548. uval |= mask1; /* set stop bit */
  83549. uval &= mask2; /* mask off unused top bits */
  83550. bw->accum <<= msbits + lsbits;
  83551. bw->accum |= uval;
  83552. }
  83553. else {
  83554. #endif
  83555. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83556. return false;
  83557. if(msbits) {
  83558. if(bw->bits) {
  83559. left = FLAC__BITS_PER_WORD - bw->bits;
  83560. if(msbits < left) {
  83561. bw->accum <<= msbits;
  83562. bw->bits += msbits;
  83563. goto break1;
  83564. }
  83565. else {
  83566. bw->accum <<= left;
  83567. msbits -= left;
  83568. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83569. bw->bits = 0;
  83570. }
  83571. }
  83572. while(msbits >= FLAC__BITS_PER_WORD) {
  83573. bw->buffer[bw->words++] = 0;
  83574. msbits -= FLAC__BITS_PER_WORD;
  83575. }
  83576. if(msbits > 0) {
  83577. bw->accum = 0;
  83578. bw->bits = msbits;
  83579. }
  83580. }
  83581. break1:
  83582. uval |= mask1; /* set stop bit */
  83583. uval &= mask2; /* mask off unused top bits */
  83584. left = FLAC__BITS_PER_WORD - bw->bits;
  83585. if(lsbits < left) {
  83586. bw->accum <<= lsbits;
  83587. bw->accum |= uval;
  83588. bw->bits += lsbits;
  83589. }
  83590. else {
  83591. FLAC__ASSERT(bw->bits);
  83592. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83593. bw->accum <<= left;
  83594. bw->accum |= uval >> (bw->bits = lsbits - left);
  83595. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83596. bw->accum = uval;
  83597. }
  83598. #if 1
  83599. }
  83600. #endif
  83601. vals++;
  83602. nvals--;
  83603. }
  83604. return true;
  83605. }
  83606. #if 0 /* UNUSED */
  83607. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83608. {
  83609. unsigned total_bits, msbs, uval;
  83610. unsigned k;
  83611. FLAC__ASSERT(0 != bw);
  83612. FLAC__ASSERT(0 != bw->buffer);
  83613. FLAC__ASSERT(parameter > 0);
  83614. if(val < 0)
  83615. uval = (unsigned)(((-(++val)) << 1) + 1);
  83616. else
  83617. uval = (unsigned)(val << 1);
  83618. k = FLAC__bitmath_ilog2(parameter);
  83619. if(parameter == 1u<<k) {
  83620. unsigned pattern;
  83621. FLAC__ASSERT(k <= 30);
  83622. msbs = uval >> k;
  83623. total_bits = 1 + k + msbs;
  83624. pattern = 1 << k; /* the unary end bit */
  83625. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83626. if(total_bits <= 32) {
  83627. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83628. return false;
  83629. }
  83630. else {
  83631. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83632. return false;
  83633. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83634. return false;
  83635. }
  83636. }
  83637. else {
  83638. unsigned q, r, d;
  83639. d = (1 << (k+1)) - parameter;
  83640. q = uval / parameter;
  83641. r = uval - (q * parameter);
  83642. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83643. return false;
  83644. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83645. return false;
  83646. if(r >= d) {
  83647. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83648. return false;
  83649. }
  83650. else {
  83651. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83652. return false;
  83653. }
  83654. }
  83655. return true;
  83656. }
  83657. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83658. {
  83659. unsigned total_bits, msbs;
  83660. unsigned k;
  83661. FLAC__ASSERT(0 != bw);
  83662. FLAC__ASSERT(0 != bw->buffer);
  83663. FLAC__ASSERT(parameter > 0);
  83664. k = FLAC__bitmath_ilog2(parameter);
  83665. if(parameter == 1u<<k) {
  83666. unsigned pattern;
  83667. FLAC__ASSERT(k <= 30);
  83668. msbs = uval >> k;
  83669. total_bits = 1 + k + msbs;
  83670. pattern = 1 << k; /* the unary end bit */
  83671. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83672. if(total_bits <= 32) {
  83673. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83674. return false;
  83675. }
  83676. else {
  83677. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83678. return false;
  83679. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83680. return false;
  83681. }
  83682. }
  83683. else {
  83684. unsigned q, r, d;
  83685. d = (1 << (k+1)) - parameter;
  83686. q = uval / parameter;
  83687. r = uval - (q * parameter);
  83688. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83689. return false;
  83690. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83691. return false;
  83692. if(r >= d) {
  83693. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83694. return false;
  83695. }
  83696. else {
  83697. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83698. return false;
  83699. }
  83700. }
  83701. return true;
  83702. }
  83703. #endif /* UNUSED */
  83704. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83705. {
  83706. FLAC__bool ok = 1;
  83707. FLAC__ASSERT(0 != bw);
  83708. FLAC__ASSERT(0 != bw->buffer);
  83709. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83710. if(val < 0x80) {
  83711. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83712. }
  83713. else if(val < 0x800) {
  83714. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83715. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83716. }
  83717. else if(val < 0x10000) {
  83718. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83719. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83720. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83721. }
  83722. else if(val < 0x200000) {
  83723. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83724. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83725. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83726. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83727. }
  83728. else if(val < 0x4000000) {
  83729. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83730. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83731. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83732. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83733. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83734. }
  83735. else {
  83736. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83737. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83738. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83739. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83740. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83741. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83742. }
  83743. return ok;
  83744. }
  83745. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83746. {
  83747. FLAC__bool ok = 1;
  83748. FLAC__ASSERT(0 != bw);
  83749. FLAC__ASSERT(0 != bw->buffer);
  83750. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83751. if(val < 0x80) {
  83752. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83753. }
  83754. else if(val < 0x800) {
  83755. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83756. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83757. }
  83758. else if(val < 0x10000) {
  83759. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83760. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83761. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83762. }
  83763. else if(val < 0x200000) {
  83764. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83765. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83766. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83767. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83768. }
  83769. else if(val < 0x4000000) {
  83770. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83771. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83772. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83773. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83774. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83775. }
  83776. else if(val < 0x80000000) {
  83777. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83778. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83779. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83780. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83781. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83782. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83783. }
  83784. else {
  83785. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83786. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83787. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83788. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83789. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83790. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83791. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83792. }
  83793. return ok;
  83794. }
  83795. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83796. {
  83797. if(bw->bits & 7u)
  83798. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83799. else
  83800. return true;
  83801. }
  83802. #endif
  83803. /*** End of inlined file: bitwriter.c ***/
  83804. /*** Start of inlined file: cpu.c ***/
  83805. /*** Start of inlined file: juce_FlacHeader.h ***/
  83806. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83807. // tasks..
  83808. #define VERSION "1.2.1"
  83809. #define FLAC__NO_DLL 1
  83810. #if JUCE_MSVC
  83811. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83812. #endif
  83813. #if JUCE_MAC
  83814. #define FLAC__SYS_DARWIN 1
  83815. #endif
  83816. /*** End of inlined file: juce_FlacHeader.h ***/
  83817. #if JUCE_USE_FLAC
  83818. #if HAVE_CONFIG_H
  83819. # include <config.h>
  83820. #endif
  83821. #include <stdlib.h>
  83822. #include <stdio.h>
  83823. #if defined FLAC__CPU_IA32
  83824. # include <signal.h>
  83825. #elif defined FLAC__CPU_PPC
  83826. # if !defined FLAC__NO_ASM
  83827. # if defined FLAC__SYS_DARWIN
  83828. # include <sys/sysctl.h>
  83829. # include <mach/mach.h>
  83830. # include <mach/mach_host.h>
  83831. # include <mach/host_info.h>
  83832. # include <mach/machine.h>
  83833. # ifndef CPU_SUBTYPE_POWERPC_970
  83834. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83835. # endif
  83836. # else /* FLAC__SYS_DARWIN */
  83837. # include <signal.h>
  83838. # include <setjmp.h>
  83839. static sigjmp_buf jmpbuf;
  83840. static volatile sig_atomic_t canjump = 0;
  83841. static void sigill_handler (int sig)
  83842. {
  83843. if (!canjump) {
  83844. signal (sig, SIG_DFL);
  83845. raise (sig);
  83846. }
  83847. canjump = 0;
  83848. siglongjmp (jmpbuf, 1);
  83849. }
  83850. # endif /* FLAC__SYS_DARWIN */
  83851. # endif /* FLAC__NO_ASM */
  83852. #endif /* FLAC__CPU_PPC */
  83853. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83854. #include <sys/param.h>
  83855. #include <sys/sysctl.h>
  83856. #include <machine/cpu.h>
  83857. #endif
  83858. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83859. #include <sys/types.h>
  83860. #include <sys/sysctl.h>
  83861. #endif
  83862. #if defined(__APPLE__)
  83863. #endif
  83864. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83865. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83866. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83867. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83868. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83869. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83870. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83871. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83872. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83873. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83874. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83875. # if defined(__linux__)
  83876. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83877. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83878. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83879. {
  83880. (void)signal;
  83881. sc.eip += 3 + 3 + 6;
  83882. }
  83883. # else
  83884. # include <sys/ucontext.h>
  83885. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83886. {
  83887. (void)signal, (void)si;
  83888. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83889. }
  83890. # endif
  83891. # elif defined(_MSC_VER)
  83892. # include <windows.h>
  83893. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83894. # ifdef USE_TRY_CATCH_FLAVOR
  83895. # else
  83896. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83897. {
  83898. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83899. ep->ContextRecord->Eip += 3 + 3 + 6;
  83900. return EXCEPTION_CONTINUE_EXECUTION;
  83901. }
  83902. return EXCEPTION_CONTINUE_SEARCH;
  83903. }
  83904. # endif
  83905. # endif
  83906. #endif
  83907. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83908. {
  83909. #ifdef FLAC__CPU_IA32
  83910. info->type = FLAC__CPUINFO_TYPE_IA32;
  83911. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83912. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83913. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83914. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83915. info->data.ia32.cmov = false;
  83916. info->data.ia32.mmx = false;
  83917. info->data.ia32.fxsr = false;
  83918. info->data.ia32.sse = false;
  83919. info->data.ia32.sse2 = false;
  83920. info->data.ia32.sse3 = false;
  83921. info->data.ia32.ssse3 = false;
  83922. info->data.ia32._3dnow = false;
  83923. info->data.ia32.ext3dnow = false;
  83924. info->data.ia32.extmmx = false;
  83925. if(info->data.ia32.cpuid) {
  83926. FLAC__uint32 flags_edx, flags_ecx;
  83927. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83928. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83929. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83930. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83931. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83932. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83933. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83934. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83935. #ifdef FLAC__USE_3DNOW
  83936. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83937. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83938. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83939. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83940. #else
  83941. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83942. #endif
  83943. #ifdef DEBUG
  83944. fprintf(stderr, "CPU info (IA-32):\n");
  83945. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83946. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83947. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83948. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83949. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83950. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83951. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83952. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83953. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83954. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83955. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83956. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83957. #endif
  83958. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83959. #if defined FLAC__NO_SSE_OS
  83960. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83961. #elif defined FLAC__SSE_OS
  83962. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83963. int sse = 0;
  83964. size_t len;
  83965. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83966. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83967. if(!sse)
  83968. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83969. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83970. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83971. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83972. size_t len = sizeof(val);
  83973. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83974. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83975. else { /* double-check SSE2 */
  83976. mib[1] = CPU_SSE2;
  83977. len = sizeof(val);
  83978. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83979. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83980. }
  83981. # else
  83982. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83983. # endif
  83984. #elif defined(__linux__)
  83985. int sse = 0;
  83986. struct sigaction sigill_save;
  83987. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83988. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83989. #else
  83990. struct sigaction sigill_sse;
  83991. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83992. __sigemptyset(&sigill_sse.sa_mask);
  83993. 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 */
  83994. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83995. #endif
  83996. {
  83997. asm volatile (
  83998. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83999. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  84000. "incl %0\n\t" /* SIGILL handler will jump over this */
  84001. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  84002. "nop\n\t"
  84003. "nop\n\t"
  84004. "nop\n\t"
  84005. "nop\n\t"
  84006. "nop\n\t"
  84007. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  84008. "nop\n\t"
  84009. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  84010. : "=r"(sse)
  84011. : "r"(sse)
  84012. );
  84013. sigaction(SIGILL, &sigill_save, NULL);
  84014. }
  84015. if(!sse)
  84016. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84017. #elif defined(_MSC_VER)
  84018. # ifdef USE_TRY_CATCH_FLAVOR
  84019. _try {
  84020. __asm {
  84021. # if _MSC_VER <= 1200
  84022. _emit 0x0F
  84023. _emit 0x57
  84024. _emit 0xC0
  84025. # else
  84026. xorps xmm0,xmm0
  84027. # endif
  84028. }
  84029. }
  84030. _except(EXCEPTION_EXECUTE_HANDLER) {
  84031. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  84032. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84033. }
  84034. # else
  84035. int sse = 0;
  84036. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  84037. __asm {
  84038. # if _MSC_VER <= 1200
  84039. _emit 0x0F
  84040. _emit 0x57
  84041. _emit 0xC0
  84042. # else
  84043. xorps xmm0,xmm0
  84044. # endif
  84045. inc sse
  84046. nop
  84047. nop
  84048. nop
  84049. nop
  84050. nop
  84051. nop
  84052. nop
  84053. nop
  84054. nop
  84055. }
  84056. SetUnhandledExceptionFilter(save);
  84057. if(!sse)
  84058. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84059. # endif
  84060. #else
  84061. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84062. #endif
  84063. #ifdef DEBUG
  84064. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84065. #endif
  84066. }
  84067. }
  84068. #else
  84069. info->use_asm = false;
  84070. #endif
  84071. #elif defined FLAC__CPU_PPC
  84072. info->type = FLAC__CPUINFO_TYPE_PPC;
  84073. # if !defined FLAC__NO_ASM
  84074. info->use_asm = true;
  84075. # ifdef FLAC__USE_ALTIVEC
  84076. # if defined FLAC__SYS_DARWIN
  84077. {
  84078. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  84079. size_t len = sizeof(val);
  84080. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  84081. }
  84082. {
  84083. host_basic_info_data_t hostInfo;
  84084. mach_msg_type_number_t infoCount;
  84085. infoCount = HOST_BASIC_INFO_COUNT;
  84086. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  84087. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  84088. }
  84089. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  84090. {
  84091. info->data.ppc.altivec = 0;
  84092. info->data.ppc.ppc64 = 0;
  84093. signal (SIGILL, sigill_handler);
  84094. canjump = 0;
  84095. if (!sigsetjmp (jmpbuf, 1)) {
  84096. canjump = 1;
  84097. asm volatile (
  84098. "mtspr 256, %0\n\t"
  84099. "vand %%v0, %%v0, %%v0"
  84100. :
  84101. : "r" (-1)
  84102. );
  84103. info->data.ppc.altivec = 1;
  84104. }
  84105. canjump = 0;
  84106. if (!sigsetjmp (jmpbuf, 1)) {
  84107. int x = 0;
  84108. canjump = 1;
  84109. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  84110. info->data.ppc.ppc64 = 1;
  84111. }
  84112. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  84113. }
  84114. # endif
  84115. # else /* !FLAC__USE_ALTIVEC */
  84116. info->data.ppc.altivec = 0;
  84117. info->data.ppc.ppc64 = 0;
  84118. # endif
  84119. # else
  84120. info->use_asm = false;
  84121. # endif
  84122. #else
  84123. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  84124. info->use_asm = false;
  84125. #endif
  84126. }
  84127. #endif
  84128. /*** End of inlined file: cpu.c ***/
  84129. /*** Start of inlined file: crc.c ***/
  84130. /*** Start of inlined file: juce_FlacHeader.h ***/
  84131. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84132. // tasks..
  84133. #define VERSION "1.2.1"
  84134. #define FLAC__NO_DLL 1
  84135. #if JUCE_MSVC
  84136. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84137. #endif
  84138. #if JUCE_MAC
  84139. #define FLAC__SYS_DARWIN 1
  84140. #endif
  84141. /*** End of inlined file: juce_FlacHeader.h ***/
  84142. #if JUCE_USE_FLAC
  84143. #if HAVE_CONFIG_H
  84144. # include <config.h>
  84145. #endif
  84146. FLAC__byte const FLAC__crc8_table[256] = {
  84147. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  84148. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  84149. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  84150. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  84151. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  84152. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  84153. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  84154. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  84155. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  84156. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  84157. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  84158. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  84159. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  84160. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  84161. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  84162. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  84163. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  84164. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  84165. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  84166. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  84167. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  84168. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  84169. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  84170. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  84171. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  84172. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  84173. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  84174. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  84175. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  84176. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  84177. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  84178. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  84179. };
  84180. unsigned FLAC__crc16_table[256] = {
  84181. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  84182. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  84183. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  84184. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  84185. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  84186. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  84187. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  84188. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  84189. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  84190. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  84191. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  84192. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  84193. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  84194. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  84195. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  84196. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  84197. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  84198. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  84199. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  84200. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  84201. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  84202. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  84203. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  84204. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  84205. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  84206. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  84207. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  84208. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  84209. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  84210. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  84211. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  84212. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  84213. };
  84214. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  84215. {
  84216. *crc = FLAC__crc8_table[*crc ^ data];
  84217. }
  84218. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  84219. {
  84220. while(len--)
  84221. *crc = FLAC__crc8_table[*crc ^ *data++];
  84222. }
  84223. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  84224. {
  84225. FLAC__uint8 crc = 0;
  84226. while(len--)
  84227. crc = FLAC__crc8_table[crc ^ *data++];
  84228. return crc;
  84229. }
  84230. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  84231. {
  84232. unsigned crc = 0;
  84233. while(len--)
  84234. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  84235. return crc;
  84236. }
  84237. #endif
  84238. /*** End of inlined file: crc.c ***/
  84239. /*** Start of inlined file: fixed.c ***/
  84240. /*** Start of inlined file: juce_FlacHeader.h ***/
  84241. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84242. // tasks..
  84243. #define VERSION "1.2.1"
  84244. #define FLAC__NO_DLL 1
  84245. #if JUCE_MSVC
  84246. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84247. #endif
  84248. #if JUCE_MAC
  84249. #define FLAC__SYS_DARWIN 1
  84250. #endif
  84251. /*** End of inlined file: juce_FlacHeader.h ***/
  84252. #if JUCE_USE_FLAC
  84253. #if HAVE_CONFIG_H
  84254. # include <config.h>
  84255. #endif
  84256. #include <math.h>
  84257. #include <string.h>
  84258. /*** Start of inlined file: fixed.h ***/
  84259. #ifndef FLAC__PRIVATE__FIXED_H
  84260. #define FLAC__PRIVATE__FIXED_H
  84261. #ifdef HAVE_CONFIG_H
  84262. #include <config.h>
  84263. #endif
  84264. /*** Start of inlined file: float.h ***/
  84265. #ifndef FLAC__PRIVATE__FLOAT_H
  84266. #define FLAC__PRIVATE__FLOAT_H
  84267. #ifdef HAVE_CONFIG_H
  84268. #include <config.h>
  84269. #endif
  84270. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84271. typedef double FLAC__double;
  84272. typedef float FLAC__float;
  84273. typedef float FLAC__real;
  84274. #else
  84275. typedef FLAC__int32 FLAC__fixedpoint;
  84276. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  84277. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  84278. extern const FLAC__fixedpoint FLAC__FP_ONE;
  84279. extern const FLAC__fixedpoint FLAC__FP_LN2;
  84280. extern const FLAC__fixedpoint FLAC__FP_E;
  84281. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  84282. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  84283. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  84284. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84285. #endif
  84286. #endif
  84287. /*** End of inlined file: float.h ***/
  84288. /*** Start of inlined file: format.h ***/
  84289. #ifndef FLAC__PRIVATE__FORMAT_H
  84290. #define FLAC__PRIVATE__FORMAT_H
  84291. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84292. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84293. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84294. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84295. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84296. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84297. #endif
  84298. /*** End of inlined file: format.h ***/
  84299. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84300. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84301. # ifndef FLAC__NO_ASM
  84302. # ifdef FLAC__CPU_IA32
  84303. # ifdef FLAC__HAS_NASM
  84304. 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]);
  84305. # endif
  84306. # endif
  84307. # endif
  84308. 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]);
  84309. #else
  84310. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84311. 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]);
  84312. #endif
  84313. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84314. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84315. #endif
  84316. /*** End of inlined file: fixed.h ***/
  84317. #ifndef M_LN2
  84318. #define M_LN2 0.69314718055994530942
  84319. #endif
  84320. #ifdef min
  84321. #undef min
  84322. #endif
  84323. #define min(x,y) ((x) < (y)? (x) : (y))
  84324. #ifdef local_abs
  84325. #undef local_abs
  84326. #endif
  84327. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84328. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84329. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84330. {
  84331. FLAC__uint32 rbps;
  84332. unsigned bits; /* the number of bits required to represent a number */
  84333. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84334. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84335. FLAC__ASSERT(err > 0);
  84336. FLAC__ASSERT(n > 0);
  84337. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84338. if(err <= n)
  84339. return 0;
  84340. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84341. err <<= fracbits;
  84342. err /= n;
  84343. FLAC__ASSERT(err > 0);
  84344. bits = FLAC__bitmath_ilog2(err)+1;
  84345. if(bits > 16) {
  84346. err >>= (bits-16);
  84347. fracbits -= (bits-16);
  84348. }
  84349. rbps = (FLAC__uint32)err;
  84350. rbps *= FLAC__FP_LN2;
  84351. fracbits += 16;
  84352. FLAC__ASSERT(fracbits >= 0);
  84353. {
  84354. const int f = fracbits & 3;
  84355. if(f) {
  84356. rbps >>= f;
  84357. fracbits -= f;
  84358. }
  84359. }
  84360. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84361. if(rbps == 0)
  84362. return 0;
  84363. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84364. FLAC__ASSERT(fracbits >= -3);
  84365. if(fracbits < 16)
  84366. return rbps << (16-fracbits);
  84367. else if(fracbits > 16)
  84368. return rbps >> (fracbits-16);
  84369. else
  84370. return rbps;
  84371. }
  84372. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84373. {
  84374. FLAC__uint32 rbps;
  84375. unsigned bits; /* the number of bits required to represent a number */
  84376. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84377. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84378. FLAC__ASSERT(err > 0);
  84379. FLAC__ASSERT(n > 0);
  84380. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84381. if(err <= n)
  84382. return 0;
  84383. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84384. err <<= fracbits;
  84385. err /= n;
  84386. FLAC__ASSERT(err > 0);
  84387. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84388. if(bits > 16) {
  84389. err >>= (bits-16);
  84390. fracbits -= (bits-16);
  84391. }
  84392. rbps = (FLAC__uint32)err;
  84393. rbps *= FLAC__FP_LN2;
  84394. fracbits += 16;
  84395. FLAC__ASSERT(fracbits >= 0);
  84396. {
  84397. const int f = fracbits & 3;
  84398. if(f) {
  84399. rbps >>= f;
  84400. fracbits -= f;
  84401. }
  84402. }
  84403. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84404. if(rbps == 0)
  84405. return 0;
  84406. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84407. FLAC__ASSERT(fracbits >= -3);
  84408. if(fracbits < 16)
  84409. return rbps << (16-fracbits);
  84410. else if(fracbits > 16)
  84411. return rbps >> (fracbits-16);
  84412. else
  84413. return rbps;
  84414. }
  84415. #endif
  84416. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84417. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84418. #else
  84419. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84420. #endif
  84421. {
  84422. FLAC__int32 last_error_0 = data[-1];
  84423. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84424. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84425. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84426. FLAC__int32 error, save;
  84427. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84428. unsigned i, order;
  84429. for(i = 0; i < data_len; i++) {
  84430. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84431. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84432. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84433. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84434. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84435. }
  84436. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84437. order = 0;
  84438. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84439. order = 1;
  84440. else if(total_error_2 < min(total_error_3, total_error_4))
  84441. order = 2;
  84442. else if(total_error_3 < total_error_4)
  84443. order = 3;
  84444. else
  84445. order = 4;
  84446. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84447. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84448. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84449. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84450. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84451. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84452. 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);
  84453. 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);
  84454. 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);
  84455. 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);
  84456. 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);
  84457. #else
  84458. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84459. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84460. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84461. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84462. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84463. #endif
  84464. return order;
  84465. }
  84466. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84467. 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])
  84468. #else
  84469. 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])
  84470. #endif
  84471. {
  84472. FLAC__int32 last_error_0 = data[-1];
  84473. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84474. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84475. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84476. FLAC__int32 error, save;
  84477. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84478. unsigned i, order;
  84479. for(i = 0; i < data_len; i++) {
  84480. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84481. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84482. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84483. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84484. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84485. }
  84486. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84487. order = 0;
  84488. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84489. order = 1;
  84490. else if(total_error_2 < min(total_error_3, total_error_4))
  84491. order = 2;
  84492. else if(total_error_3 < total_error_4)
  84493. order = 3;
  84494. else
  84495. order = 4;
  84496. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84497. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84498. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84499. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84500. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84501. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84502. #if defined _MSC_VER || defined __MINGW32__
  84503. 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);
  84504. 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);
  84505. 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);
  84506. 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);
  84507. 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);
  84508. #else
  84509. 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);
  84510. 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);
  84511. 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);
  84512. 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);
  84513. 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);
  84514. #endif
  84515. #else
  84516. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84517. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84518. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84519. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84520. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84521. #endif
  84522. return order;
  84523. }
  84524. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84525. {
  84526. const int idata_len = (int)data_len;
  84527. int i;
  84528. switch(order) {
  84529. case 0:
  84530. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84531. memcpy(residual, data, sizeof(residual[0])*data_len);
  84532. break;
  84533. case 1:
  84534. for(i = 0; i < idata_len; i++)
  84535. residual[i] = data[i] - data[i-1];
  84536. break;
  84537. case 2:
  84538. for(i = 0; i < idata_len; i++)
  84539. #if 1 /* OPT: may be faster with some compilers on some systems */
  84540. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84541. #else
  84542. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84543. #endif
  84544. break;
  84545. case 3:
  84546. for(i = 0; i < idata_len; i++)
  84547. #if 1 /* OPT: may be faster with some compilers on some systems */
  84548. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84549. #else
  84550. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84551. #endif
  84552. break;
  84553. case 4:
  84554. for(i = 0; i < idata_len; i++)
  84555. #if 1 /* OPT: may be faster with some compilers on some systems */
  84556. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84557. #else
  84558. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84559. #endif
  84560. break;
  84561. default:
  84562. FLAC__ASSERT(0);
  84563. }
  84564. }
  84565. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84566. {
  84567. int i, idata_len = (int)data_len;
  84568. switch(order) {
  84569. case 0:
  84570. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84571. memcpy(data, residual, sizeof(residual[0])*data_len);
  84572. break;
  84573. case 1:
  84574. for(i = 0; i < idata_len; i++)
  84575. data[i] = residual[i] + data[i-1];
  84576. break;
  84577. case 2:
  84578. for(i = 0; i < idata_len; i++)
  84579. #if 1 /* OPT: may be faster with some compilers on some systems */
  84580. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84581. #else
  84582. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84583. #endif
  84584. break;
  84585. case 3:
  84586. for(i = 0; i < idata_len; i++)
  84587. #if 1 /* OPT: may be faster with some compilers on some systems */
  84588. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84589. #else
  84590. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84591. #endif
  84592. break;
  84593. case 4:
  84594. for(i = 0; i < idata_len; i++)
  84595. #if 1 /* OPT: may be faster with some compilers on some systems */
  84596. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84597. #else
  84598. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84599. #endif
  84600. break;
  84601. default:
  84602. FLAC__ASSERT(0);
  84603. }
  84604. }
  84605. #endif
  84606. /*** End of inlined file: fixed.c ***/
  84607. /*** Start of inlined file: float.c ***/
  84608. /*** Start of inlined file: juce_FlacHeader.h ***/
  84609. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84610. // tasks..
  84611. #define VERSION "1.2.1"
  84612. #define FLAC__NO_DLL 1
  84613. #if JUCE_MSVC
  84614. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84615. #endif
  84616. #if JUCE_MAC
  84617. #define FLAC__SYS_DARWIN 1
  84618. #endif
  84619. /*** End of inlined file: juce_FlacHeader.h ***/
  84620. #if JUCE_USE_FLAC
  84621. #if HAVE_CONFIG_H
  84622. # include <config.h>
  84623. #endif
  84624. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84625. #ifdef _MSC_VER
  84626. #define FLAC__U64L(x) x
  84627. #else
  84628. #define FLAC__U64L(x) x##LLU
  84629. #endif
  84630. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84631. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84632. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84633. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84634. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84635. #define LOG2_LOOKUP_PRECISION 16
  84636. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84637. {
  84638. 0x00000000,
  84639. 0x00000001,
  84640. 0x00000000,
  84641. 0x00000000,
  84642. 0x00000000,
  84643. 0x00000000,
  84644. 0x00000000,
  84645. 0x00000000,
  84646. 0x00000000,
  84647. 0x00000000,
  84648. 0x00000000,
  84649. 0x00000000,
  84650. 0x00000000,
  84651. 0x00000000,
  84652. 0x00000000,
  84653. 0x00000000
  84654. },
  84655. {
  84656. 0x00000000,
  84657. 0x00000010,
  84658. 0x00000007,
  84659. 0x00000003,
  84660. 0x00000001,
  84661. 0x00000001,
  84662. 0x00000000,
  84663. 0x00000000,
  84664. 0x00000000,
  84665. 0x00000000,
  84666. 0x00000000,
  84667. 0x00000000,
  84668. 0x00000000,
  84669. 0x00000000,
  84670. 0x00000000,
  84671. 0x00000000
  84672. },
  84673. {
  84674. 0x00000000,
  84675. 0x00000100,
  84676. 0x0000006a,
  84677. 0x00000031,
  84678. 0x00000018,
  84679. 0x0000000c,
  84680. 0x00000006,
  84681. 0x00000003,
  84682. 0x00000001,
  84683. 0x00000001,
  84684. 0x00000000,
  84685. 0x00000000,
  84686. 0x00000000,
  84687. 0x00000000,
  84688. 0x00000000,
  84689. 0x00000000
  84690. },
  84691. {
  84692. 0x00000000,
  84693. 0x00001000,
  84694. 0x000006a4,
  84695. 0x00000315,
  84696. 0x0000017d,
  84697. 0x000000bc,
  84698. 0x0000005d,
  84699. 0x0000002e,
  84700. 0x00000017,
  84701. 0x0000000c,
  84702. 0x00000006,
  84703. 0x00000003,
  84704. 0x00000001,
  84705. 0x00000001,
  84706. 0x00000000,
  84707. 0x00000000
  84708. },
  84709. {
  84710. 0x00000000,
  84711. 0x00010000,
  84712. 0x00006a40,
  84713. 0x00003151,
  84714. 0x000017d6,
  84715. 0x00000bba,
  84716. 0x000005d1,
  84717. 0x000002e6,
  84718. 0x00000172,
  84719. 0x000000b9,
  84720. 0x0000005c,
  84721. 0x0000002e,
  84722. 0x00000017,
  84723. 0x0000000c,
  84724. 0x00000006,
  84725. 0x00000003
  84726. },
  84727. {
  84728. 0x00000000,
  84729. 0x00100000,
  84730. 0x0006a3fe,
  84731. 0x00031513,
  84732. 0x00017d60,
  84733. 0x0000bb9d,
  84734. 0x00005d10,
  84735. 0x00002e59,
  84736. 0x00001721,
  84737. 0x00000b8e,
  84738. 0x000005c6,
  84739. 0x000002e3,
  84740. 0x00000171,
  84741. 0x000000b9,
  84742. 0x0000005c,
  84743. 0x0000002e
  84744. },
  84745. {
  84746. 0x00000000,
  84747. 0x01000000,
  84748. 0x006a3fe6,
  84749. 0x00315130,
  84750. 0x0017d605,
  84751. 0x000bb9ca,
  84752. 0x0005d0fc,
  84753. 0x0002e58f,
  84754. 0x0001720e,
  84755. 0x0000b8d8,
  84756. 0x00005c61,
  84757. 0x00002e2d,
  84758. 0x00001716,
  84759. 0x00000b8b,
  84760. 0x000005c5,
  84761. 0x000002e3
  84762. },
  84763. {
  84764. 0x00000000,
  84765. 0x10000000,
  84766. 0x06a3fe5c,
  84767. 0x03151301,
  84768. 0x017d6049,
  84769. 0x00bb9ca6,
  84770. 0x005d0fba,
  84771. 0x002e58f7,
  84772. 0x001720da,
  84773. 0x000b8d87,
  84774. 0x0005c60b,
  84775. 0x0002e2d7,
  84776. 0x00017160,
  84777. 0x0000b8ad,
  84778. 0x00005c56,
  84779. 0x00002e2b
  84780. }
  84781. };
  84782. #if 0
  84783. static const FLAC__uint64 log2_lookup_wide[] = {
  84784. {
  84785. 0x00000000,
  84786. FLAC__U64L(0x100000000),
  84787. FLAC__U64L(0x6a3fe5c6),
  84788. FLAC__U64L(0x31513015),
  84789. FLAC__U64L(0x17d60497),
  84790. FLAC__U64L(0x0bb9ca65),
  84791. FLAC__U64L(0x05d0fba2),
  84792. FLAC__U64L(0x02e58f74),
  84793. FLAC__U64L(0x01720d9c),
  84794. FLAC__U64L(0x00b8d875),
  84795. FLAC__U64L(0x005c60aa),
  84796. FLAC__U64L(0x002e2d72),
  84797. FLAC__U64L(0x00171600),
  84798. FLAC__U64L(0x000b8ad2),
  84799. FLAC__U64L(0x0005c55d),
  84800. FLAC__U64L(0x0002e2ac)
  84801. },
  84802. {
  84803. 0x00000000,
  84804. FLAC__U64L(0x1000000000000),
  84805. FLAC__U64L(0x6a3fe5c60429),
  84806. FLAC__U64L(0x315130157f7a),
  84807. FLAC__U64L(0x17d60496cfbb),
  84808. FLAC__U64L(0xbb9ca64ecac),
  84809. FLAC__U64L(0x5d0fba187cd),
  84810. FLAC__U64L(0x2e58f7441ee),
  84811. FLAC__U64L(0x1720d9c06a8),
  84812. FLAC__U64L(0xb8d8752173),
  84813. FLAC__U64L(0x5c60aa252e),
  84814. FLAC__U64L(0x2e2d71b0d8),
  84815. FLAC__U64L(0x1716001719),
  84816. FLAC__U64L(0xb8ad1de1b),
  84817. FLAC__U64L(0x5c55d640d),
  84818. FLAC__U64L(0x2e2abcf52)
  84819. }
  84820. };
  84821. #endif
  84822. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84823. {
  84824. const FLAC__uint32 ONE = (1u << fracbits);
  84825. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84826. FLAC__ASSERT(fracbits < 32);
  84827. FLAC__ASSERT((fracbits & 0x3) == 0);
  84828. if(x < ONE)
  84829. return 0;
  84830. if(precision > LOG2_LOOKUP_PRECISION)
  84831. precision = LOG2_LOOKUP_PRECISION;
  84832. {
  84833. FLAC__uint32 y = 0;
  84834. FLAC__uint32 z = x >> 1, k = 1;
  84835. while (x > ONE && k < precision) {
  84836. if (x - z >= ONE) {
  84837. x -= z;
  84838. z = x >> k;
  84839. y += table[k];
  84840. }
  84841. else {
  84842. z >>= 1;
  84843. k++;
  84844. }
  84845. }
  84846. return y;
  84847. }
  84848. }
  84849. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84850. #endif
  84851. /*** End of inlined file: float.c ***/
  84852. /*** Start of inlined file: format.c ***/
  84853. /*** Start of inlined file: juce_FlacHeader.h ***/
  84854. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84855. // tasks..
  84856. #define VERSION "1.2.1"
  84857. #define FLAC__NO_DLL 1
  84858. #if JUCE_MSVC
  84859. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84860. #endif
  84861. #if JUCE_MAC
  84862. #define FLAC__SYS_DARWIN 1
  84863. #endif
  84864. /*** End of inlined file: juce_FlacHeader.h ***/
  84865. #if JUCE_USE_FLAC
  84866. #if HAVE_CONFIG_H
  84867. # include <config.h>
  84868. #endif
  84869. #include <stdio.h>
  84870. #include <stdlib.h> /* for qsort() */
  84871. #include <string.h> /* for memset() */
  84872. #ifndef FLaC__INLINE
  84873. #define FLaC__INLINE
  84874. #endif
  84875. #ifdef min
  84876. #undef min
  84877. #endif
  84878. #define min(a,b) ((a)<(b)?(a):(b))
  84879. #ifdef _MSC_VER
  84880. #define FLAC__U64L(x) x
  84881. #else
  84882. #define FLAC__U64L(x) x##LLU
  84883. #endif
  84884. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84885. ;
  84886. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84887. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84888. #else
  84889. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84890. #endif
  84891. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84892. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84893. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84894. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84895. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84896. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84897. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84898. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84899. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84900. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84901. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84902. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84903. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84904. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84905. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84906. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84907. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84908. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84909. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84910. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84911. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84912. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84913. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84914. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84915. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84916. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84917. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84918. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84919. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84920. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84921. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84922. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84923. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84924. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84925. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84926. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84927. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84928. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84929. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84930. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84931. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84932. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84933. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84934. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84935. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84936. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84937. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84938. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84939. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84940. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84941. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84942. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84943. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84944. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84945. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84946. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84947. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84948. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84949. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84950. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84951. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84952. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84953. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84954. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84955. "PARTITIONED_RICE",
  84956. "PARTITIONED_RICE2"
  84957. };
  84958. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84959. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84960. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84961. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84962. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84963. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84964. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84965. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84966. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84967. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84968. "CONSTANT",
  84969. "VERBATIM",
  84970. "FIXED",
  84971. "LPC"
  84972. };
  84973. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84974. "INDEPENDENT",
  84975. "LEFT_SIDE",
  84976. "RIGHT_SIDE",
  84977. "MID_SIDE"
  84978. };
  84979. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84980. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84981. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84982. };
  84983. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84984. "STREAMINFO",
  84985. "PADDING",
  84986. "APPLICATION",
  84987. "SEEKTABLE",
  84988. "VORBIS_COMMENT",
  84989. "CUESHEET",
  84990. "PICTURE"
  84991. };
  84992. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84993. "Other",
  84994. "32x32 pixels 'file icon' (PNG only)",
  84995. "Other file icon",
  84996. "Cover (front)",
  84997. "Cover (back)",
  84998. "Leaflet page",
  84999. "Media (e.g. label side of CD)",
  85000. "Lead artist/lead performer/soloist",
  85001. "Artist/performer",
  85002. "Conductor",
  85003. "Band/Orchestra",
  85004. "Composer",
  85005. "Lyricist/text writer",
  85006. "Recording Location",
  85007. "During recording",
  85008. "During performance",
  85009. "Movie/video screen capture",
  85010. "A bright coloured fish",
  85011. "Illustration",
  85012. "Band/artist logotype",
  85013. "Publisher/Studio logotype"
  85014. };
  85015. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  85016. {
  85017. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  85018. return false;
  85019. }
  85020. else
  85021. return true;
  85022. }
  85023. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  85024. {
  85025. if(
  85026. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  85027. (
  85028. sample_rate >= (1u << 16) &&
  85029. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  85030. )
  85031. ) {
  85032. return false;
  85033. }
  85034. else
  85035. return true;
  85036. }
  85037. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  85038. {
  85039. unsigned i;
  85040. FLAC__uint64 prev_sample_number = 0;
  85041. FLAC__bool got_prev = false;
  85042. FLAC__ASSERT(0 != seek_table);
  85043. for(i = 0; i < seek_table->num_points; i++) {
  85044. if(got_prev) {
  85045. if(
  85046. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  85047. seek_table->points[i].sample_number <= prev_sample_number
  85048. )
  85049. return false;
  85050. }
  85051. prev_sample_number = seek_table->points[i].sample_number;
  85052. got_prev = true;
  85053. }
  85054. return true;
  85055. }
  85056. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  85057. {
  85058. if(l->sample_number == r->sample_number)
  85059. return 0;
  85060. else if(l->sample_number < r->sample_number)
  85061. return -1;
  85062. else
  85063. return 1;
  85064. }
  85065. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  85066. {
  85067. unsigned i, j;
  85068. FLAC__bool first;
  85069. FLAC__ASSERT(0 != seek_table);
  85070. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  85071. first = true;
  85072. for(i = j = 0; i < seek_table->num_points; i++) {
  85073. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  85074. if(!first) {
  85075. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  85076. continue;
  85077. }
  85078. }
  85079. first = false;
  85080. seek_table->points[j++] = seek_table->points[i];
  85081. }
  85082. for(i = j; i < seek_table->num_points; i++) {
  85083. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  85084. seek_table->points[i].stream_offset = 0;
  85085. seek_table->points[i].frame_samples = 0;
  85086. }
  85087. return j;
  85088. }
  85089. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  85090. {
  85091. FLAC__ASSERT(0 != utf8);
  85092. if ((utf8[0] & 0x80) == 0) {
  85093. return 1;
  85094. }
  85095. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  85096. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  85097. return 0;
  85098. return 2;
  85099. }
  85100. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  85101. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  85102. return 0;
  85103. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  85104. return 0;
  85105. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  85106. return 0;
  85107. return 3;
  85108. }
  85109. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  85110. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  85111. return 0;
  85112. return 4;
  85113. }
  85114. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  85115. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  85116. return 0;
  85117. return 5;
  85118. }
  85119. 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) {
  85120. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  85121. return 0;
  85122. return 6;
  85123. }
  85124. else {
  85125. return 0;
  85126. }
  85127. }
  85128. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  85129. {
  85130. char c;
  85131. for(c = *name; c; c = *(++name))
  85132. if(c < 0x20 || c == 0x3d || c > 0x7d)
  85133. return false;
  85134. return true;
  85135. }
  85136. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  85137. {
  85138. if(length == (unsigned)(-1)) {
  85139. while(*value) {
  85140. unsigned n = utf8len_(value);
  85141. if(n == 0)
  85142. return false;
  85143. value += n;
  85144. }
  85145. }
  85146. else {
  85147. const FLAC__byte *end = value + length;
  85148. while(value < end) {
  85149. unsigned n = utf8len_(value);
  85150. if(n == 0)
  85151. return false;
  85152. value += n;
  85153. }
  85154. if(value != end)
  85155. return false;
  85156. }
  85157. return true;
  85158. }
  85159. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  85160. {
  85161. const FLAC__byte *s, *end;
  85162. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  85163. if(*s < 0x20 || *s > 0x7D)
  85164. return false;
  85165. }
  85166. if(s == end)
  85167. return false;
  85168. s++; /* skip '=' */
  85169. while(s < end) {
  85170. unsigned n = utf8len_(s);
  85171. if(n == 0)
  85172. return false;
  85173. s += n;
  85174. }
  85175. if(s != end)
  85176. return false;
  85177. return true;
  85178. }
  85179. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  85180. {
  85181. unsigned i, j;
  85182. if(check_cd_da_subset) {
  85183. if(cue_sheet->lead_in < 2 * 44100) {
  85184. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  85185. return false;
  85186. }
  85187. if(cue_sheet->lead_in % 588 != 0) {
  85188. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  85189. return false;
  85190. }
  85191. }
  85192. if(cue_sheet->num_tracks == 0) {
  85193. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  85194. return false;
  85195. }
  85196. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  85197. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  85198. return false;
  85199. }
  85200. for(i = 0; i < cue_sheet->num_tracks; i++) {
  85201. if(cue_sheet->tracks[i].number == 0) {
  85202. if(violation) *violation = "cue sheet may not have a track number 0";
  85203. return false;
  85204. }
  85205. if(check_cd_da_subset) {
  85206. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  85207. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  85208. return false;
  85209. }
  85210. }
  85211. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  85212. if(violation) {
  85213. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  85214. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  85215. else
  85216. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  85217. }
  85218. return false;
  85219. }
  85220. if(i < cue_sheet->num_tracks - 1) {
  85221. if(cue_sheet->tracks[i].num_indices == 0) {
  85222. if(violation) *violation = "cue sheet track must have at least one index point";
  85223. return false;
  85224. }
  85225. if(cue_sheet->tracks[i].indices[0].number > 1) {
  85226. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  85227. return false;
  85228. }
  85229. }
  85230. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  85231. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  85232. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  85233. return false;
  85234. }
  85235. if(j > 0) {
  85236. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  85237. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  85238. return false;
  85239. }
  85240. }
  85241. }
  85242. }
  85243. return true;
  85244. }
  85245. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  85246. {
  85247. char *p;
  85248. FLAC__byte *b;
  85249. for(p = picture->mime_type; *p; p++) {
  85250. if(*p < 0x20 || *p > 0x7e) {
  85251. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  85252. return false;
  85253. }
  85254. }
  85255. for(b = picture->description; *b; ) {
  85256. unsigned n = utf8len_(b);
  85257. if(n == 0) {
  85258. if(violation) *violation = "description string must be valid UTF-8";
  85259. return false;
  85260. }
  85261. b += n;
  85262. }
  85263. return true;
  85264. }
  85265. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  85266. {
  85267. return
  85268. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  85269. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  85270. blocksize,
  85271. predictor_order
  85272. );
  85273. }
  85274. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  85275. {
  85276. unsigned max_rice_partition_order = 0;
  85277. while(!(blocksize & 1)) {
  85278. max_rice_partition_order++;
  85279. blocksize >>= 1;
  85280. }
  85281. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  85282. }
  85283. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  85284. {
  85285. unsigned max_rice_partition_order = limit;
  85286. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85287. max_rice_partition_order--;
  85288. FLAC__ASSERT(
  85289. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85290. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85291. );
  85292. return max_rice_partition_order;
  85293. }
  85294. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85295. {
  85296. FLAC__ASSERT(0 != object);
  85297. object->parameters = 0;
  85298. object->raw_bits = 0;
  85299. object->capacity_by_order = 0;
  85300. }
  85301. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85302. {
  85303. FLAC__ASSERT(0 != object);
  85304. if(0 != object->parameters)
  85305. free(object->parameters);
  85306. if(0 != object->raw_bits)
  85307. free(object->raw_bits);
  85308. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85309. }
  85310. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85311. {
  85312. FLAC__ASSERT(0 != object);
  85313. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85314. if(object->capacity_by_order < max_partition_order) {
  85315. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85316. return false;
  85317. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85318. return false;
  85319. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85320. object->capacity_by_order = max_partition_order;
  85321. }
  85322. return true;
  85323. }
  85324. #endif
  85325. /*** End of inlined file: format.c ***/
  85326. /*** Start of inlined file: lpc_flac.c ***/
  85327. /*** Start of inlined file: juce_FlacHeader.h ***/
  85328. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85329. // tasks..
  85330. #define VERSION "1.2.1"
  85331. #define FLAC__NO_DLL 1
  85332. #if JUCE_MSVC
  85333. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85334. #endif
  85335. #if JUCE_MAC
  85336. #define FLAC__SYS_DARWIN 1
  85337. #endif
  85338. /*** End of inlined file: juce_FlacHeader.h ***/
  85339. #if JUCE_USE_FLAC
  85340. #if HAVE_CONFIG_H
  85341. # include <config.h>
  85342. #endif
  85343. #include <math.h>
  85344. /*** Start of inlined file: lpc.h ***/
  85345. #ifndef FLAC__PRIVATE__LPC_H
  85346. #define FLAC__PRIVATE__LPC_H
  85347. #ifdef HAVE_CONFIG_H
  85348. #include <config.h>
  85349. #endif
  85350. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85351. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85352. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85353. #ifndef FLAC__NO_ASM
  85354. # ifdef FLAC__CPU_IA32
  85355. # ifdef FLAC__HAS_NASM
  85356. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85357. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85358. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85359. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85360. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85361. # endif
  85362. # endif
  85363. #endif
  85364. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85365. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85366. 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[]);
  85367. 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[]);
  85368. #ifndef FLAC__NO_ASM
  85369. # ifdef FLAC__CPU_IA32
  85370. # ifdef FLAC__HAS_NASM
  85371. 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[]);
  85372. 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[]);
  85373. # endif
  85374. # endif
  85375. #endif
  85376. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85377. 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[]);
  85378. 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[]);
  85379. #ifndef FLAC__NO_ASM
  85380. # ifdef FLAC__CPU_IA32
  85381. # ifdef FLAC__HAS_NASM
  85382. 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[]);
  85383. 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[]);
  85384. # endif /* FLAC__HAS_NASM */
  85385. # elif defined FLAC__CPU_PPC
  85386. 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[]);
  85387. 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[]);
  85388. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85389. #endif /* FLAC__NO_ASM */
  85390. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85391. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85392. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85393. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85394. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85395. #endif
  85396. /*** End of inlined file: lpc.h ***/
  85397. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85398. #include <stdio.h>
  85399. #endif
  85400. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85401. #ifndef M_LN2
  85402. #define M_LN2 0.69314718055994530942
  85403. #endif
  85404. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85405. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85406. {
  85407. unsigned i;
  85408. for(i = 0; i < data_len; i++)
  85409. out[i] = in[i] * window[i];
  85410. }
  85411. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85412. {
  85413. #if 0
  85414. FLAC__real d;
  85415. unsigned i;
  85416. FLAC__ASSERT(lag > 0);
  85417. FLAC__ASSERT(lag <= data_len);
  85418. while(lag--) {
  85419. for(i = lag, d = 0.0; i < data_len; i++)
  85420. d += data[i] * data[i - lag];
  85421. autoc[lag] = d;
  85422. }
  85423. #endif
  85424. FLAC__real d;
  85425. unsigned sample, coeff;
  85426. const unsigned limit = data_len - lag;
  85427. FLAC__ASSERT(lag > 0);
  85428. FLAC__ASSERT(lag <= data_len);
  85429. for(coeff = 0; coeff < lag; coeff++)
  85430. autoc[coeff] = 0.0;
  85431. for(sample = 0; sample <= limit; sample++) {
  85432. d = data[sample];
  85433. for(coeff = 0; coeff < lag; coeff++)
  85434. autoc[coeff] += d * data[sample+coeff];
  85435. }
  85436. for(; sample < data_len; sample++) {
  85437. d = data[sample];
  85438. for(coeff = 0; coeff < data_len - sample; coeff++)
  85439. autoc[coeff] += d * data[sample+coeff];
  85440. }
  85441. }
  85442. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85443. {
  85444. unsigned i, j;
  85445. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85446. FLAC__ASSERT(0 != max_order);
  85447. FLAC__ASSERT(0 < *max_order);
  85448. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85449. FLAC__ASSERT(autoc[0] != 0.0);
  85450. err = autoc[0];
  85451. for(i = 0; i < *max_order; i++) {
  85452. r = -autoc[i+1];
  85453. for(j = 0; j < i; j++)
  85454. r -= lpc[j] * autoc[i-j];
  85455. ref[i] = (r/=err);
  85456. lpc[i]=r;
  85457. for(j = 0; j < (i>>1); j++) {
  85458. FLAC__double tmp = lpc[j];
  85459. lpc[j] += r * lpc[i-1-j];
  85460. lpc[i-1-j] += r * tmp;
  85461. }
  85462. if(i & 1)
  85463. lpc[j] += lpc[j] * r;
  85464. err *= (1.0 - r * r);
  85465. for(j = 0; j <= i; j++)
  85466. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85467. error[i] = err;
  85468. if(err == 0.0) {
  85469. *max_order = i+1;
  85470. return;
  85471. }
  85472. }
  85473. }
  85474. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85475. {
  85476. unsigned i;
  85477. FLAC__double cmax;
  85478. FLAC__int32 qmax, qmin;
  85479. FLAC__ASSERT(precision > 0);
  85480. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85481. precision--;
  85482. qmax = 1 << precision;
  85483. qmin = -qmax;
  85484. qmax--;
  85485. cmax = 0.0;
  85486. for(i = 0; i < order; i++) {
  85487. const FLAC__double d = fabs(lp_coeff[i]);
  85488. if(d > cmax)
  85489. cmax = d;
  85490. }
  85491. if(cmax <= 0.0) {
  85492. return 2;
  85493. }
  85494. else {
  85495. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85496. const int min_shiftlimit = -max_shiftlimit - 1;
  85497. int log2cmax;
  85498. (void)frexp(cmax, &log2cmax);
  85499. log2cmax--;
  85500. *shift = (int)precision - log2cmax - 1;
  85501. if(*shift > max_shiftlimit)
  85502. *shift = max_shiftlimit;
  85503. else if(*shift < min_shiftlimit)
  85504. return 1;
  85505. }
  85506. if(*shift >= 0) {
  85507. FLAC__double error = 0.0;
  85508. FLAC__int32 q;
  85509. for(i = 0; i < order; i++) {
  85510. error += lp_coeff[i] * (1 << *shift);
  85511. #if 1 /* unfortunately lround() is C99 */
  85512. if(error >= 0.0)
  85513. q = (FLAC__int32)(error + 0.5);
  85514. else
  85515. q = (FLAC__int32)(error - 0.5);
  85516. #else
  85517. q = lround(error);
  85518. #endif
  85519. #ifdef FLAC__OVERFLOW_DETECT
  85520. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85521. 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]);
  85522. else if(q < qmin)
  85523. 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]);
  85524. #endif
  85525. if(q > qmax)
  85526. q = qmax;
  85527. else if(q < qmin)
  85528. q = qmin;
  85529. error -= q;
  85530. qlp_coeff[i] = q;
  85531. }
  85532. }
  85533. else {
  85534. const int nshift = -(*shift);
  85535. FLAC__double error = 0.0;
  85536. FLAC__int32 q;
  85537. #ifdef DEBUG
  85538. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85539. #endif
  85540. for(i = 0; i < order; i++) {
  85541. error += lp_coeff[i] / (1 << nshift);
  85542. #if 1 /* unfortunately lround() is C99 */
  85543. if(error >= 0.0)
  85544. q = (FLAC__int32)(error + 0.5);
  85545. else
  85546. q = (FLAC__int32)(error - 0.5);
  85547. #else
  85548. q = lround(error);
  85549. #endif
  85550. #ifdef FLAC__OVERFLOW_DETECT
  85551. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85552. 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]);
  85553. else if(q < qmin)
  85554. 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]);
  85555. #endif
  85556. if(q > qmax)
  85557. q = qmax;
  85558. else if(q < qmin)
  85559. q = qmin;
  85560. error -= q;
  85561. qlp_coeff[i] = q;
  85562. }
  85563. *shift = 0;
  85564. }
  85565. return 0;
  85566. }
  85567. 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[])
  85568. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85569. {
  85570. FLAC__int64 sumo;
  85571. unsigned i, j;
  85572. FLAC__int32 sum;
  85573. const FLAC__int32 *history;
  85574. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85575. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85576. for(i=0;i<order;i++)
  85577. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85578. fprintf(stderr,"\n");
  85579. #endif
  85580. FLAC__ASSERT(order > 0);
  85581. for(i = 0; i < data_len; i++) {
  85582. sumo = 0;
  85583. sum = 0;
  85584. history = data;
  85585. for(j = 0; j < order; j++) {
  85586. sum += qlp_coeff[j] * (*(--history));
  85587. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85588. #if defined _MSC_VER
  85589. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85590. 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);
  85591. #else
  85592. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85593. 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);
  85594. #endif
  85595. }
  85596. *(residual++) = *(data++) - (sum >> lp_quantization);
  85597. }
  85598. }
  85599. #else /* fully unrolled version for normal use */
  85600. {
  85601. int i;
  85602. FLAC__int32 sum;
  85603. FLAC__ASSERT(order > 0);
  85604. FLAC__ASSERT(order <= 32);
  85605. if(order <= 12) {
  85606. if(order > 8) {
  85607. if(order > 10) {
  85608. if(order == 12) {
  85609. for(i = 0; i < (int)data_len; i++) {
  85610. sum = 0;
  85611. sum += qlp_coeff[11] * data[i-12];
  85612. sum += qlp_coeff[10] * data[i-11];
  85613. sum += qlp_coeff[9] * data[i-10];
  85614. sum += qlp_coeff[8] * data[i-9];
  85615. sum += qlp_coeff[7] * data[i-8];
  85616. sum += qlp_coeff[6] * data[i-7];
  85617. sum += qlp_coeff[5] * data[i-6];
  85618. sum += qlp_coeff[4] * data[i-5];
  85619. sum += qlp_coeff[3] * data[i-4];
  85620. sum += qlp_coeff[2] * data[i-3];
  85621. sum += qlp_coeff[1] * data[i-2];
  85622. sum += qlp_coeff[0] * data[i-1];
  85623. residual[i] = data[i] - (sum >> lp_quantization);
  85624. }
  85625. }
  85626. else { /* order == 11 */
  85627. for(i = 0; i < (int)data_len; i++) {
  85628. sum = 0;
  85629. sum += qlp_coeff[10] * data[i-11];
  85630. sum += qlp_coeff[9] * data[i-10];
  85631. sum += qlp_coeff[8] * data[i-9];
  85632. sum += qlp_coeff[7] * data[i-8];
  85633. sum += qlp_coeff[6] * data[i-7];
  85634. sum += qlp_coeff[5] * data[i-6];
  85635. sum += qlp_coeff[4] * data[i-5];
  85636. sum += qlp_coeff[3] * data[i-4];
  85637. sum += qlp_coeff[2] * data[i-3];
  85638. sum += qlp_coeff[1] * data[i-2];
  85639. sum += qlp_coeff[0] * data[i-1];
  85640. residual[i] = data[i] - (sum >> lp_quantization);
  85641. }
  85642. }
  85643. }
  85644. else {
  85645. if(order == 10) {
  85646. for(i = 0; i < (int)data_len; i++) {
  85647. sum = 0;
  85648. sum += qlp_coeff[9] * data[i-10];
  85649. sum += qlp_coeff[8] * data[i-9];
  85650. sum += qlp_coeff[7] * data[i-8];
  85651. sum += qlp_coeff[6] * data[i-7];
  85652. sum += qlp_coeff[5] * data[i-6];
  85653. sum += qlp_coeff[4] * data[i-5];
  85654. sum += qlp_coeff[3] * data[i-4];
  85655. sum += qlp_coeff[2] * data[i-3];
  85656. sum += qlp_coeff[1] * data[i-2];
  85657. sum += qlp_coeff[0] * data[i-1];
  85658. residual[i] = data[i] - (sum >> lp_quantization);
  85659. }
  85660. }
  85661. else { /* order == 9 */
  85662. for(i = 0; i < (int)data_len; i++) {
  85663. sum = 0;
  85664. sum += qlp_coeff[8] * data[i-9];
  85665. sum += qlp_coeff[7] * data[i-8];
  85666. sum += qlp_coeff[6] * data[i-7];
  85667. sum += qlp_coeff[5] * data[i-6];
  85668. sum += qlp_coeff[4] * data[i-5];
  85669. sum += qlp_coeff[3] * data[i-4];
  85670. sum += qlp_coeff[2] * data[i-3];
  85671. sum += qlp_coeff[1] * data[i-2];
  85672. sum += qlp_coeff[0] * data[i-1];
  85673. residual[i] = data[i] - (sum >> lp_quantization);
  85674. }
  85675. }
  85676. }
  85677. }
  85678. else if(order > 4) {
  85679. if(order > 6) {
  85680. if(order == 8) {
  85681. for(i = 0; i < (int)data_len; i++) {
  85682. sum = 0;
  85683. sum += qlp_coeff[7] * data[i-8];
  85684. sum += qlp_coeff[6] * data[i-7];
  85685. sum += qlp_coeff[5] * data[i-6];
  85686. sum += qlp_coeff[4] * data[i-5];
  85687. sum += qlp_coeff[3] * data[i-4];
  85688. sum += qlp_coeff[2] * data[i-3];
  85689. sum += qlp_coeff[1] * data[i-2];
  85690. sum += qlp_coeff[0] * data[i-1];
  85691. residual[i] = data[i] - (sum >> lp_quantization);
  85692. }
  85693. }
  85694. else { /* order == 7 */
  85695. for(i = 0; i < (int)data_len; i++) {
  85696. sum = 0;
  85697. sum += qlp_coeff[6] * data[i-7];
  85698. sum += qlp_coeff[5] * data[i-6];
  85699. sum += qlp_coeff[4] * data[i-5];
  85700. sum += qlp_coeff[3] * data[i-4];
  85701. sum += qlp_coeff[2] * data[i-3];
  85702. sum += qlp_coeff[1] * data[i-2];
  85703. sum += qlp_coeff[0] * data[i-1];
  85704. residual[i] = data[i] - (sum >> lp_quantization);
  85705. }
  85706. }
  85707. }
  85708. else {
  85709. if(order == 6) {
  85710. for(i = 0; i < (int)data_len; i++) {
  85711. sum = 0;
  85712. sum += qlp_coeff[5] * data[i-6];
  85713. sum += qlp_coeff[4] * data[i-5];
  85714. sum += qlp_coeff[3] * data[i-4];
  85715. sum += qlp_coeff[2] * data[i-3];
  85716. sum += qlp_coeff[1] * data[i-2];
  85717. sum += qlp_coeff[0] * data[i-1];
  85718. residual[i] = data[i] - (sum >> lp_quantization);
  85719. }
  85720. }
  85721. else { /* order == 5 */
  85722. for(i = 0; i < (int)data_len; i++) {
  85723. sum = 0;
  85724. sum += qlp_coeff[4] * data[i-5];
  85725. sum += qlp_coeff[3] * data[i-4];
  85726. sum += qlp_coeff[2] * data[i-3];
  85727. sum += qlp_coeff[1] * data[i-2];
  85728. sum += qlp_coeff[0] * data[i-1];
  85729. residual[i] = data[i] - (sum >> lp_quantization);
  85730. }
  85731. }
  85732. }
  85733. }
  85734. else {
  85735. if(order > 2) {
  85736. if(order == 4) {
  85737. for(i = 0; i < (int)data_len; i++) {
  85738. sum = 0;
  85739. sum += qlp_coeff[3] * data[i-4];
  85740. sum += qlp_coeff[2] * data[i-3];
  85741. sum += qlp_coeff[1] * data[i-2];
  85742. sum += qlp_coeff[0] * data[i-1];
  85743. residual[i] = data[i] - (sum >> lp_quantization);
  85744. }
  85745. }
  85746. else { /* order == 3 */
  85747. for(i = 0; i < (int)data_len; i++) {
  85748. sum = 0;
  85749. sum += qlp_coeff[2] * data[i-3];
  85750. sum += qlp_coeff[1] * data[i-2];
  85751. sum += qlp_coeff[0] * data[i-1];
  85752. residual[i] = data[i] - (sum >> lp_quantization);
  85753. }
  85754. }
  85755. }
  85756. else {
  85757. if(order == 2) {
  85758. for(i = 0; i < (int)data_len; i++) {
  85759. sum = 0;
  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. else { /* order == 1 */
  85766. for(i = 0; i < (int)data_len; i++)
  85767. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85768. }
  85769. }
  85770. }
  85771. }
  85772. else { /* order > 12 */
  85773. for(i = 0; i < (int)data_len; i++) {
  85774. sum = 0;
  85775. switch(order) {
  85776. case 32: sum += qlp_coeff[31] * data[i-32];
  85777. case 31: sum += qlp_coeff[30] * data[i-31];
  85778. case 30: sum += qlp_coeff[29] * data[i-30];
  85779. case 29: sum += qlp_coeff[28] * data[i-29];
  85780. case 28: sum += qlp_coeff[27] * data[i-28];
  85781. case 27: sum += qlp_coeff[26] * data[i-27];
  85782. case 26: sum += qlp_coeff[25] * data[i-26];
  85783. case 25: sum += qlp_coeff[24] * data[i-25];
  85784. case 24: sum += qlp_coeff[23] * data[i-24];
  85785. case 23: sum += qlp_coeff[22] * data[i-23];
  85786. case 22: sum += qlp_coeff[21] * data[i-22];
  85787. case 21: sum += qlp_coeff[20] * data[i-21];
  85788. case 20: sum += qlp_coeff[19] * data[i-20];
  85789. case 19: sum += qlp_coeff[18] * data[i-19];
  85790. case 18: sum += qlp_coeff[17] * data[i-18];
  85791. case 17: sum += qlp_coeff[16] * data[i-17];
  85792. case 16: sum += qlp_coeff[15] * data[i-16];
  85793. case 15: sum += qlp_coeff[14] * data[i-15];
  85794. case 14: sum += qlp_coeff[13] * data[i-14];
  85795. case 13: sum += qlp_coeff[12] * data[i-13];
  85796. sum += qlp_coeff[11] * data[i-12];
  85797. sum += qlp_coeff[10] * data[i-11];
  85798. sum += qlp_coeff[ 9] * data[i-10];
  85799. sum += qlp_coeff[ 8] * data[i- 9];
  85800. sum += qlp_coeff[ 7] * data[i- 8];
  85801. sum += qlp_coeff[ 6] * data[i- 7];
  85802. sum += qlp_coeff[ 5] * data[i- 6];
  85803. sum += qlp_coeff[ 4] * data[i- 5];
  85804. sum += qlp_coeff[ 3] * data[i- 4];
  85805. sum += qlp_coeff[ 2] * data[i- 3];
  85806. sum += qlp_coeff[ 1] * data[i- 2];
  85807. sum += qlp_coeff[ 0] * data[i- 1];
  85808. }
  85809. residual[i] = data[i] - (sum >> lp_quantization);
  85810. }
  85811. }
  85812. }
  85813. #endif
  85814. 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[])
  85815. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85816. {
  85817. unsigned i, j;
  85818. FLAC__int64 sum;
  85819. const FLAC__int32 *history;
  85820. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85821. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85822. for(i=0;i<order;i++)
  85823. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85824. fprintf(stderr,"\n");
  85825. #endif
  85826. FLAC__ASSERT(order > 0);
  85827. for(i = 0; i < data_len; i++) {
  85828. sum = 0;
  85829. history = data;
  85830. for(j = 0; j < order; j++)
  85831. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85832. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85833. #if defined _MSC_VER
  85834. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85835. #else
  85836. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85837. #endif
  85838. break;
  85839. }
  85840. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85841. #if defined _MSC_VER
  85842. 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));
  85843. #else
  85844. 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)));
  85845. #endif
  85846. break;
  85847. }
  85848. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85849. }
  85850. }
  85851. #else /* fully unrolled version for normal use */
  85852. {
  85853. int i;
  85854. FLAC__int64 sum;
  85855. FLAC__ASSERT(order > 0);
  85856. FLAC__ASSERT(order <= 32);
  85857. if(order <= 12) {
  85858. if(order > 8) {
  85859. if(order > 10) {
  85860. if(order == 12) {
  85861. for(i = 0; i < (int)data_len; i++) {
  85862. sum = 0;
  85863. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85864. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85865. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85866. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85867. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85868. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85869. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85870. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85871. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85872. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85873. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85874. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85875. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85876. }
  85877. }
  85878. else { /* order == 11 */
  85879. for(i = 0; i < (int)data_len; i++) {
  85880. sum = 0;
  85881. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85882. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85883. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85884. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85885. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85886. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85887. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85888. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85889. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85890. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85891. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85892. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85893. }
  85894. }
  85895. }
  85896. else {
  85897. if(order == 10) {
  85898. for(i = 0; i < (int)data_len; i++) {
  85899. sum = 0;
  85900. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85901. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85902. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85903. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85904. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85905. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85906. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85907. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85908. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85909. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85910. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85911. }
  85912. }
  85913. else { /* order == 9 */
  85914. for(i = 0; i < (int)data_len; i++) {
  85915. sum = 0;
  85916. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85917. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85918. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85919. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85920. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85921. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85922. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85923. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85924. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85925. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85926. }
  85927. }
  85928. }
  85929. }
  85930. else if(order > 4) {
  85931. if(order > 6) {
  85932. if(order == 8) {
  85933. for(i = 0; i < (int)data_len; i++) {
  85934. sum = 0;
  85935. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85936. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85937. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85938. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85939. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85940. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85941. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85942. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85943. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85944. }
  85945. }
  85946. else { /* order == 7 */
  85947. for(i = 0; i < (int)data_len; i++) {
  85948. sum = 0;
  85949. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85950. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85951. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85952. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85953. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85954. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85955. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85956. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85957. }
  85958. }
  85959. }
  85960. else {
  85961. if(order == 6) {
  85962. for(i = 0; i < (int)data_len; i++) {
  85963. sum = 0;
  85964. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85965. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85966. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85967. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85968. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85969. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85970. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85971. }
  85972. }
  85973. else { /* order == 5 */
  85974. for(i = 0; i < (int)data_len; i++) {
  85975. sum = 0;
  85976. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85977. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85978. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85979. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85980. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85981. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85982. }
  85983. }
  85984. }
  85985. }
  85986. else {
  85987. if(order > 2) {
  85988. if(order == 4) {
  85989. for(i = 0; i < (int)data_len; i++) {
  85990. sum = 0;
  85991. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85992. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85993. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85994. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85995. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85996. }
  85997. }
  85998. else { /* order == 3 */
  85999. for(i = 0; i < (int)data_len; i++) {
  86000. sum = 0;
  86001. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86002. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86003. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86004. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86005. }
  86006. }
  86007. }
  86008. else {
  86009. if(order == 2) {
  86010. for(i = 0; i < (int)data_len; i++) {
  86011. sum = 0;
  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. else { /* order == 1 */
  86018. for(i = 0; i < (int)data_len; i++)
  86019. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86020. }
  86021. }
  86022. }
  86023. }
  86024. else { /* order > 12 */
  86025. for(i = 0; i < (int)data_len; i++) {
  86026. sum = 0;
  86027. switch(order) {
  86028. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86029. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86030. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86031. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86032. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86033. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86034. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86035. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86036. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86037. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86038. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86039. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86040. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86041. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86042. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86043. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86044. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86045. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86046. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86047. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86048. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86049. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86050. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86051. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86052. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86053. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86054. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86055. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86056. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86057. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86058. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86059. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86060. }
  86061. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86062. }
  86063. }
  86064. }
  86065. #endif
  86066. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86067. 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[])
  86068. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86069. {
  86070. FLAC__int64 sumo;
  86071. unsigned i, j;
  86072. FLAC__int32 sum;
  86073. const FLAC__int32 *r = residual, *history;
  86074. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86075. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86076. for(i=0;i<order;i++)
  86077. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86078. fprintf(stderr,"\n");
  86079. #endif
  86080. FLAC__ASSERT(order > 0);
  86081. for(i = 0; i < data_len; i++) {
  86082. sumo = 0;
  86083. sum = 0;
  86084. history = data;
  86085. for(j = 0; j < order; j++) {
  86086. sum += qlp_coeff[j] * (*(--history));
  86087. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  86088. #if defined _MSC_VER
  86089. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  86090. 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);
  86091. #else
  86092. if(sumo > 2147483647ll || sumo < -2147483648ll)
  86093. 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);
  86094. #endif
  86095. }
  86096. *(data++) = *(r++) + (sum >> lp_quantization);
  86097. }
  86098. }
  86099. #else /* fully unrolled version for normal use */
  86100. {
  86101. int i;
  86102. FLAC__int32 sum;
  86103. FLAC__ASSERT(order > 0);
  86104. FLAC__ASSERT(order <= 32);
  86105. if(order <= 12) {
  86106. if(order > 8) {
  86107. if(order > 10) {
  86108. if(order == 12) {
  86109. for(i = 0; i < (int)data_len; i++) {
  86110. sum = 0;
  86111. sum += qlp_coeff[11] * data[i-12];
  86112. sum += qlp_coeff[10] * data[i-11];
  86113. sum += qlp_coeff[9] * data[i-10];
  86114. sum += qlp_coeff[8] * data[i-9];
  86115. sum += qlp_coeff[7] * data[i-8];
  86116. sum += qlp_coeff[6] * data[i-7];
  86117. sum += qlp_coeff[5] * data[i-6];
  86118. sum += qlp_coeff[4] * data[i-5];
  86119. sum += qlp_coeff[3] * data[i-4];
  86120. sum += qlp_coeff[2] * data[i-3];
  86121. sum += qlp_coeff[1] * data[i-2];
  86122. sum += qlp_coeff[0] * data[i-1];
  86123. data[i] = residual[i] + (sum >> lp_quantization);
  86124. }
  86125. }
  86126. else { /* order == 11 */
  86127. for(i = 0; i < (int)data_len; i++) {
  86128. sum = 0;
  86129. sum += qlp_coeff[10] * data[i-11];
  86130. sum += qlp_coeff[9] * data[i-10];
  86131. sum += qlp_coeff[8] * data[i-9];
  86132. sum += qlp_coeff[7] * data[i-8];
  86133. sum += qlp_coeff[6] * data[i-7];
  86134. sum += qlp_coeff[5] * data[i-6];
  86135. sum += qlp_coeff[4] * data[i-5];
  86136. sum += qlp_coeff[3] * data[i-4];
  86137. sum += qlp_coeff[2] * data[i-3];
  86138. sum += qlp_coeff[1] * data[i-2];
  86139. sum += qlp_coeff[0] * data[i-1];
  86140. data[i] = residual[i] + (sum >> lp_quantization);
  86141. }
  86142. }
  86143. }
  86144. else {
  86145. if(order == 10) {
  86146. for(i = 0; i < (int)data_len; i++) {
  86147. sum = 0;
  86148. sum += qlp_coeff[9] * data[i-10];
  86149. sum += qlp_coeff[8] * data[i-9];
  86150. sum += qlp_coeff[7] * data[i-8];
  86151. sum += qlp_coeff[6] * data[i-7];
  86152. sum += qlp_coeff[5] * data[i-6];
  86153. sum += qlp_coeff[4] * data[i-5];
  86154. sum += qlp_coeff[3] * data[i-4];
  86155. sum += qlp_coeff[2] * data[i-3];
  86156. sum += qlp_coeff[1] * data[i-2];
  86157. sum += qlp_coeff[0] * data[i-1];
  86158. data[i] = residual[i] + (sum >> lp_quantization);
  86159. }
  86160. }
  86161. else { /* order == 9 */
  86162. for(i = 0; i < (int)data_len; i++) {
  86163. sum = 0;
  86164. sum += qlp_coeff[8] * data[i-9];
  86165. sum += qlp_coeff[7] * data[i-8];
  86166. sum += qlp_coeff[6] * data[i-7];
  86167. sum += qlp_coeff[5] * data[i-6];
  86168. sum += qlp_coeff[4] * data[i-5];
  86169. sum += qlp_coeff[3] * data[i-4];
  86170. sum += qlp_coeff[2] * data[i-3];
  86171. sum += qlp_coeff[1] * data[i-2];
  86172. sum += qlp_coeff[0] * data[i-1];
  86173. data[i] = residual[i] + (sum >> lp_quantization);
  86174. }
  86175. }
  86176. }
  86177. }
  86178. else if(order > 4) {
  86179. if(order > 6) {
  86180. if(order == 8) {
  86181. for(i = 0; i < (int)data_len; i++) {
  86182. sum = 0;
  86183. sum += qlp_coeff[7] * data[i-8];
  86184. sum += qlp_coeff[6] * data[i-7];
  86185. sum += qlp_coeff[5] * data[i-6];
  86186. sum += qlp_coeff[4] * data[i-5];
  86187. sum += qlp_coeff[3] * data[i-4];
  86188. sum += qlp_coeff[2] * data[i-3];
  86189. sum += qlp_coeff[1] * data[i-2];
  86190. sum += qlp_coeff[0] * data[i-1];
  86191. data[i] = residual[i] + (sum >> lp_quantization);
  86192. }
  86193. }
  86194. else { /* order == 7 */
  86195. for(i = 0; i < (int)data_len; i++) {
  86196. sum = 0;
  86197. sum += qlp_coeff[6] * data[i-7];
  86198. sum += qlp_coeff[5] * data[i-6];
  86199. sum += qlp_coeff[4] * data[i-5];
  86200. sum += qlp_coeff[3] * data[i-4];
  86201. sum += qlp_coeff[2] * data[i-3];
  86202. sum += qlp_coeff[1] * data[i-2];
  86203. sum += qlp_coeff[0] * data[i-1];
  86204. data[i] = residual[i] + (sum >> lp_quantization);
  86205. }
  86206. }
  86207. }
  86208. else {
  86209. if(order == 6) {
  86210. for(i = 0; i < (int)data_len; i++) {
  86211. sum = 0;
  86212. sum += qlp_coeff[5] * data[i-6];
  86213. sum += qlp_coeff[4] * data[i-5];
  86214. sum += qlp_coeff[3] * data[i-4];
  86215. sum += qlp_coeff[2] * data[i-3];
  86216. sum += qlp_coeff[1] * data[i-2];
  86217. sum += qlp_coeff[0] * data[i-1];
  86218. data[i] = residual[i] + (sum >> lp_quantization);
  86219. }
  86220. }
  86221. else { /* order == 5 */
  86222. for(i = 0; i < (int)data_len; i++) {
  86223. sum = 0;
  86224. sum += qlp_coeff[4] * data[i-5];
  86225. sum += qlp_coeff[3] * data[i-4];
  86226. sum += qlp_coeff[2] * data[i-3];
  86227. sum += qlp_coeff[1] * data[i-2];
  86228. sum += qlp_coeff[0] * data[i-1];
  86229. data[i] = residual[i] + (sum >> lp_quantization);
  86230. }
  86231. }
  86232. }
  86233. }
  86234. else {
  86235. if(order > 2) {
  86236. if(order == 4) {
  86237. for(i = 0; i < (int)data_len; i++) {
  86238. sum = 0;
  86239. sum += qlp_coeff[3] * data[i-4];
  86240. sum += qlp_coeff[2] * data[i-3];
  86241. sum += qlp_coeff[1] * data[i-2];
  86242. sum += qlp_coeff[0] * data[i-1];
  86243. data[i] = residual[i] + (sum >> lp_quantization);
  86244. }
  86245. }
  86246. else { /* order == 3 */
  86247. for(i = 0; i < (int)data_len; i++) {
  86248. sum = 0;
  86249. sum += qlp_coeff[2] * data[i-3];
  86250. sum += qlp_coeff[1] * data[i-2];
  86251. sum += qlp_coeff[0] * data[i-1];
  86252. data[i] = residual[i] + (sum >> lp_quantization);
  86253. }
  86254. }
  86255. }
  86256. else {
  86257. if(order == 2) {
  86258. for(i = 0; i < (int)data_len; i++) {
  86259. sum = 0;
  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. else { /* order == 1 */
  86266. for(i = 0; i < (int)data_len; i++)
  86267. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86268. }
  86269. }
  86270. }
  86271. }
  86272. else { /* order > 12 */
  86273. for(i = 0; i < (int)data_len; i++) {
  86274. sum = 0;
  86275. switch(order) {
  86276. case 32: sum += qlp_coeff[31] * data[i-32];
  86277. case 31: sum += qlp_coeff[30] * data[i-31];
  86278. case 30: sum += qlp_coeff[29] * data[i-30];
  86279. case 29: sum += qlp_coeff[28] * data[i-29];
  86280. case 28: sum += qlp_coeff[27] * data[i-28];
  86281. case 27: sum += qlp_coeff[26] * data[i-27];
  86282. case 26: sum += qlp_coeff[25] * data[i-26];
  86283. case 25: sum += qlp_coeff[24] * data[i-25];
  86284. case 24: sum += qlp_coeff[23] * data[i-24];
  86285. case 23: sum += qlp_coeff[22] * data[i-23];
  86286. case 22: sum += qlp_coeff[21] * data[i-22];
  86287. case 21: sum += qlp_coeff[20] * data[i-21];
  86288. case 20: sum += qlp_coeff[19] * data[i-20];
  86289. case 19: sum += qlp_coeff[18] * data[i-19];
  86290. case 18: sum += qlp_coeff[17] * data[i-18];
  86291. case 17: sum += qlp_coeff[16] * data[i-17];
  86292. case 16: sum += qlp_coeff[15] * data[i-16];
  86293. case 15: sum += qlp_coeff[14] * data[i-15];
  86294. case 14: sum += qlp_coeff[13] * data[i-14];
  86295. case 13: sum += qlp_coeff[12] * data[i-13];
  86296. sum += qlp_coeff[11] * data[i-12];
  86297. sum += qlp_coeff[10] * data[i-11];
  86298. sum += qlp_coeff[ 9] * data[i-10];
  86299. sum += qlp_coeff[ 8] * data[i- 9];
  86300. sum += qlp_coeff[ 7] * data[i- 8];
  86301. sum += qlp_coeff[ 6] * data[i- 7];
  86302. sum += qlp_coeff[ 5] * data[i- 6];
  86303. sum += qlp_coeff[ 4] * data[i- 5];
  86304. sum += qlp_coeff[ 3] * data[i- 4];
  86305. sum += qlp_coeff[ 2] * data[i- 3];
  86306. sum += qlp_coeff[ 1] * data[i- 2];
  86307. sum += qlp_coeff[ 0] * data[i- 1];
  86308. }
  86309. data[i] = residual[i] + (sum >> lp_quantization);
  86310. }
  86311. }
  86312. }
  86313. #endif
  86314. 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[])
  86315. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86316. {
  86317. unsigned i, j;
  86318. FLAC__int64 sum;
  86319. const FLAC__int32 *r = residual, *history;
  86320. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86321. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86322. for(i=0;i<order;i++)
  86323. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86324. fprintf(stderr,"\n");
  86325. #endif
  86326. FLAC__ASSERT(order > 0);
  86327. for(i = 0; i < data_len; i++) {
  86328. sum = 0;
  86329. history = data;
  86330. for(j = 0; j < order; j++)
  86331. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86332. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86333. #ifdef _MSC_VER
  86334. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86335. #else
  86336. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86337. #endif
  86338. break;
  86339. }
  86340. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86341. #ifdef _MSC_VER
  86342. 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));
  86343. #else
  86344. 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)));
  86345. #endif
  86346. break;
  86347. }
  86348. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86349. }
  86350. }
  86351. #else /* fully unrolled version for normal use */
  86352. {
  86353. int i;
  86354. FLAC__int64 sum;
  86355. FLAC__ASSERT(order > 0);
  86356. FLAC__ASSERT(order <= 32);
  86357. if(order <= 12) {
  86358. if(order > 8) {
  86359. if(order > 10) {
  86360. if(order == 12) {
  86361. for(i = 0; i < (int)data_len; i++) {
  86362. sum = 0;
  86363. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86364. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86365. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86366. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86367. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86368. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86369. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86370. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86371. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86372. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86373. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86374. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86375. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86376. }
  86377. }
  86378. else { /* order == 11 */
  86379. for(i = 0; i < (int)data_len; i++) {
  86380. sum = 0;
  86381. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86382. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86383. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86384. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86385. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86386. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86387. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86388. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86389. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86390. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86391. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86392. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86393. }
  86394. }
  86395. }
  86396. else {
  86397. if(order == 10) {
  86398. for(i = 0; i < (int)data_len; i++) {
  86399. sum = 0;
  86400. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86401. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86402. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86403. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86404. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86405. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86406. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86407. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86408. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86409. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86410. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86411. }
  86412. }
  86413. else { /* order == 9 */
  86414. for(i = 0; i < (int)data_len; i++) {
  86415. sum = 0;
  86416. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86417. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86418. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86419. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86420. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86421. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86422. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86423. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86424. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86425. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86426. }
  86427. }
  86428. }
  86429. }
  86430. else if(order > 4) {
  86431. if(order > 6) {
  86432. if(order == 8) {
  86433. for(i = 0; i < (int)data_len; i++) {
  86434. sum = 0;
  86435. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86436. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86437. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86438. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86439. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86440. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86441. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86442. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86443. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86444. }
  86445. }
  86446. else { /* order == 7 */
  86447. for(i = 0; i < (int)data_len; i++) {
  86448. sum = 0;
  86449. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86450. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86451. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86452. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86453. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86454. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86455. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86456. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86457. }
  86458. }
  86459. }
  86460. else {
  86461. if(order == 6) {
  86462. for(i = 0; i < (int)data_len; i++) {
  86463. sum = 0;
  86464. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86465. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86466. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86467. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86468. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86469. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86470. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86471. }
  86472. }
  86473. else { /* order == 5 */
  86474. for(i = 0; i < (int)data_len; i++) {
  86475. sum = 0;
  86476. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86477. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86478. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86479. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86480. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86481. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86482. }
  86483. }
  86484. }
  86485. }
  86486. else {
  86487. if(order > 2) {
  86488. if(order == 4) {
  86489. for(i = 0; i < (int)data_len; i++) {
  86490. sum = 0;
  86491. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86492. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86493. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86494. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86495. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86496. }
  86497. }
  86498. else { /* order == 3 */
  86499. for(i = 0; i < (int)data_len; i++) {
  86500. sum = 0;
  86501. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86502. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86503. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86504. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86505. }
  86506. }
  86507. }
  86508. else {
  86509. if(order == 2) {
  86510. for(i = 0; i < (int)data_len; i++) {
  86511. sum = 0;
  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. else { /* order == 1 */
  86518. for(i = 0; i < (int)data_len; i++)
  86519. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86520. }
  86521. }
  86522. }
  86523. }
  86524. else { /* order > 12 */
  86525. for(i = 0; i < (int)data_len; i++) {
  86526. sum = 0;
  86527. switch(order) {
  86528. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86529. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86530. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86531. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86532. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86533. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86534. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86535. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86536. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86537. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86538. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86539. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86540. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86541. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86542. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86543. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86544. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86545. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86546. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86547. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86548. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86549. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86550. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86551. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86552. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86553. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86554. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86555. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86556. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86557. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86558. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86559. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86560. }
  86561. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86562. }
  86563. }
  86564. }
  86565. #endif
  86566. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86567. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86568. {
  86569. FLAC__double error_scale;
  86570. FLAC__ASSERT(total_samples > 0);
  86571. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86572. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86573. }
  86574. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86575. {
  86576. if(lpc_error > 0.0) {
  86577. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86578. if(bps >= 0.0)
  86579. return bps;
  86580. else
  86581. return 0.0;
  86582. }
  86583. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86584. return 1e32;
  86585. }
  86586. else {
  86587. return 0.0;
  86588. }
  86589. }
  86590. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86591. {
  86592. 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 */
  86593. FLAC__double bits, best_bits, error_scale;
  86594. FLAC__ASSERT(max_order > 0);
  86595. FLAC__ASSERT(total_samples > 0);
  86596. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86597. best_index = 0;
  86598. best_bits = (unsigned)(-1);
  86599. for(index = 0, order = 1; index < max_order; index++, order++) {
  86600. 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);
  86601. if(bits < best_bits) {
  86602. best_index = index;
  86603. best_bits = bits;
  86604. }
  86605. }
  86606. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86607. }
  86608. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86609. #endif
  86610. /*** End of inlined file: lpc_flac.c ***/
  86611. /*** Start of inlined file: md5.c ***/
  86612. /*** Start of inlined file: juce_FlacHeader.h ***/
  86613. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86614. // tasks..
  86615. #define VERSION "1.2.1"
  86616. #define FLAC__NO_DLL 1
  86617. #if JUCE_MSVC
  86618. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86619. #endif
  86620. #if JUCE_MAC
  86621. #define FLAC__SYS_DARWIN 1
  86622. #endif
  86623. /*** End of inlined file: juce_FlacHeader.h ***/
  86624. #if JUCE_USE_FLAC
  86625. #if HAVE_CONFIG_H
  86626. # include <config.h>
  86627. #endif
  86628. #include <stdlib.h> /* for malloc() */
  86629. #include <string.h> /* for memcpy() */
  86630. /*** Start of inlined file: md5.h ***/
  86631. #ifndef FLAC__PRIVATE__MD5_H
  86632. #define FLAC__PRIVATE__MD5_H
  86633. typedef struct {
  86634. FLAC__uint32 in[16];
  86635. FLAC__uint32 buf[4];
  86636. FLAC__uint32 bytes[2];
  86637. FLAC__byte *internal_buf;
  86638. size_t capacity;
  86639. } FLAC__MD5Context;
  86640. void FLAC__MD5Init(FLAC__MD5Context *context);
  86641. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86642. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86643. #endif
  86644. /*** End of inlined file: md5.h ***/
  86645. #ifndef FLaC__INLINE
  86646. #define FLaC__INLINE
  86647. #endif
  86648. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86649. #define F2(x, y, z) F1(z, x, y)
  86650. #define F3(x, y, z) (x ^ y ^ z)
  86651. #define F4(x, y, z) (y ^ (x | ~z))
  86652. #define MD5STEP(f,w,x,y,z,in,s) \
  86653. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86654. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86655. {
  86656. register FLAC__uint32 a, b, c, d;
  86657. a = buf[0];
  86658. b = buf[1];
  86659. c = buf[2];
  86660. d = buf[3];
  86661. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86662. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86663. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86664. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86665. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86666. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86667. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86668. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86669. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86670. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86671. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86672. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86673. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86674. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86675. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86676. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86677. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86678. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86679. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86680. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86681. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86682. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86683. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86684. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86685. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86686. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86687. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86688. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86689. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86690. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86691. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86692. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86693. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86694. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86695. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86696. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86697. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86698. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86699. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86700. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86701. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86702. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86703. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86704. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86705. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86706. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86707. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86708. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86709. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86710. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86711. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86712. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86713. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86714. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86715. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86716. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86717. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86718. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86719. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86720. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86721. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86722. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86723. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86724. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86725. buf[0] += a;
  86726. buf[1] += b;
  86727. buf[2] += c;
  86728. buf[3] += d;
  86729. }
  86730. #if WORDS_BIGENDIAN
  86731. //@@@@@@ OPT: use bswap/intrinsics
  86732. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86733. {
  86734. register FLAC__uint32 x;
  86735. do {
  86736. x = *buf;
  86737. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86738. *buf++ = (x >> 16) | (x << 16);
  86739. } while (--words);
  86740. }
  86741. static void byteSwapX16(FLAC__uint32 *buf)
  86742. {
  86743. register FLAC__uint32 x;
  86744. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86745. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86746. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86747. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86748. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86749. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86750. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86751. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86752. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86753. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  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. }
  86761. #else
  86762. #define byteSwap(buf, words)
  86763. #define byteSwapX16(buf)
  86764. #endif
  86765. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86766. {
  86767. FLAC__uint32 t;
  86768. t = ctx->bytes[0];
  86769. if ((ctx->bytes[0] = t + len) < t)
  86770. ctx->bytes[1]++; /* Carry from low to high */
  86771. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86772. if (t > len) {
  86773. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86774. return;
  86775. }
  86776. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86777. byteSwapX16(ctx->in);
  86778. FLAC__MD5Transform(ctx->buf, ctx->in);
  86779. buf += t;
  86780. len -= t;
  86781. while (len >= 64) {
  86782. memcpy(ctx->in, buf, 64);
  86783. byteSwapX16(ctx->in);
  86784. FLAC__MD5Transform(ctx->buf, ctx->in);
  86785. buf += 64;
  86786. len -= 64;
  86787. }
  86788. memcpy(ctx->in, buf, len);
  86789. }
  86790. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86791. {
  86792. ctx->buf[0] = 0x67452301;
  86793. ctx->buf[1] = 0xefcdab89;
  86794. ctx->buf[2] = 0x98badcfe;
  86795. ctx->buf[3] = 0x10325476;
  86796. ctx->bytes[0] = 0;
  86797. ctx->bytes[1] = 0;
  86798. ctx->internal_buf = 0;
  86799. ctx->capacity = 0;
  86800. }
  86801. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86802. {
  86803. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86804. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86805. *p++ = 0x80;
  86806. count = 56 - 1 - count;
  86807. if (count < 0) { /* Padding forces an extra block */
  86808. memset(p, 0, count + 8);
  86809. byteSwapX16(ctx->in);
  86810. FLAC__MD5Transform(ctx->buf, ctx->in);
  86811. p = (FLAC__byte *)ctx->in;
  86812. count = 56;
  86813. }
  86814. memset(p, 0, count);
  86815. byteSwap(ctx->in, 14);
  86816. ctx->in[14] = ctx->bytes[0] << 3;
  86817. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86818. FLAC__MD5Transform(ctx->buf, ctx->in);
  86819. byteSwap(ctx->buf, 4);
  86820. memcpy(digest, ctx->buf, 16);
  86821. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86822. if(0 != ctx->internal_buf) {
  86823. free(ctx->internal_buf);
  86824. ctx->internal_buf = 0;
  86825. ctx->capacity = 0;
  86826. }
  86827. }
  86828. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86829. {
  86830. unsigned channel, sample;
  86831. register FLAC__int32 a_word;
  86832. register FLAC__byte *buf_ = buf;
  86833. #if WORDS_BIGENDIAN
  86834. #else
  86835. if(channels == 2 && bytes_per_sample == 2) {
  86836. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86837. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86838. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86839. *buf1_ = (FLAC__int16)signal[1][sample];
  86840. }
  86841. else if(channels == 1 && bytes_per_sample == 2) {
  86842. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86843. for(sample = 0; sample < samples; sample++)
  86844. *buf1_++ = (FLAC__int16)signal[0][sample];
  86845. }
  86846. else
  86847. #endif
  86848. if(bytes_per_sample == 2) {
  86849. if(channels == 2) {
  86850. for(sample = 0; sample < samples; sample++) {
  86851. a_word = signal[0][sample];
  86852. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86853. *buf_++ = (FLAC__byte)a_word;
  86854. a_word = signal[1][sample];
  86855. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86856. *buf_++ = (FLAC__byte)a_word;
  86857. }
  86858. }
  86859. else if(channels == 1) {
  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. }
  86865. }
  86866. else {
  86867. for(sample = 0; sample < samples; sample++) {
  86868. for(channel = 0; channel < channels; channel++) {
  86869. a_word = signal[channel][sample];
  86870. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86871. *buf_++ = (FLAC__byte)a_word;
  86872. }
  86873. }
  86874. }
  86875. }
  86876. else if(bytes_per_sample == 3) {
  86877. if(channels == 2) {
  86878. for(sample = 0; sample < samples; sample++) {
  86879. a_word = signal[0][sample];
  86880. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86881. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86882. *buf_++ = (FLAC__byte)a_word;
  86883. a_word = signal[1][sample];
  86884. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86885. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86886. *buf_++ = (FLAC__byte)a_word;
  86887. }
  86888. }
  86889. else if(channels == 1) {
  86890. for(sample = 0; sample < samples; sample++) {
  86891. a_word = signal[0][sample];
  86892. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86893. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86894. *buf_++ = (FLAC__byte)a_word;
  86895. }
  86896. }
  86897. else {
  86898. for(sample = 0; sample < samples; sample++) {
  86899. for(channel = 0; channel < channels; channel++) {
  86900. a_word = signal[channel][sample];
  86901. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86902. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86903. *buf_++ = (FLAC__byte)a_word;
  86904. }
  86905. }
  86906. }
  86907. }
  86908. else if(bytes_per_sample == 1) {
  86909. if(channels == 2) {
  86910. for(sample = 0; sample < samples; sample++) {
  86911. a_word = signal[0][sample];
  86912. *buf_++ = (FLAC__byte)a_word;
  86913. a_word = signal[1][sample];
  86914. *buf_++ = (FLAC__byte)a_word;
  86915. }
  86916. }
  86917. else if(channels == 1) {
  86918. for(sample = 0; sample < samples; sample++) {
  86919. a_word = signal[0][sample];
  86920. *buf_++ = (FLAC__byte)a_word;
  86921. }
  86922. }
  86923. else {
  86924. for(sample = 0; sample < samples; sample++) {
  86925. for(channel = 0; channel < channels; channel++) {
  86926. a_word = signal[channel][sample];
  86927. *buf_++ = (FLAC__byte)a_word;
  86928. }
  86929. }
  86930. }
  86931. }
  86932. else { /* bytes_per_sample == 4, maybe optimize more later */
  86933. for(sample = 0; sample < samples; sample++) {
  86934. for(channel = 0; channel < channels; channel++) {
  86935. a_word = signal[channel][sample];
  86936. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86937. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86938. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86939. *buf_++ = (FLAC__byte)a_word;
  86940. }
  86941. }
  86942. }
  86943. }
  86944. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86945. {
  86946. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86947. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86948. return false;
  86949. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86950. return false;
  86951. if(ctx->capacity < bytes_needed) {
  86952. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86953. if(0 == tmp) {
  86954. free(ctx->internal_buf);
  86955. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86956. return false;
  86957. }
  86958. ctx->internal_buf = tmp;
  86959. ctx->capacity = bytes_needed;
  86960. }
  86961. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86962. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86963. return true;
  86964. }
  86965. #endif
  86966. /*** End of inlined file: md5.c ***/
  86967. /*** Start of inlined file: memory.c ***/
  86968. /*** Start of inlined file: juce_FlacHeader.h ***/
  86969. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86970. // tasks..
  86971. #define VERSION "1.2.1"
  86972. #define FLAC__NO_DLL 1
  86973. #if JUCE_MSVC
  86974. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86975. #endif
  86976. #if JUCE_MAC
  86977. #define FLAC__SYS_DARWIN 1
  86978. #endif
  86979. /*** End of inlined file: juce_FlacHeader.h ***/
  86980. #if JUCE_USE_FLAC
  86981. #if HAVE_CONFIG_H
  86982. # include <config.h>
  86983. #endif
  86984. /*** Start of inlined file: memory.h ***/
  86985. #ifndef FLAC__PRIVATE__MEMORY_H
  86986. #define FLAC__PRIVATE__MEMORY_H
  86987. #ifdef HAVE_CONFIG_H
  86988. #include <config.h>
  86989. #endif
  86990. #include <stdlib.h> /* for size_t */
  86991. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86992. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86993. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86994. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86995. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86996. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86997. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86998. #endif
  86999. #endif
  87000. /*** End of inlined file: memory.h ***/
  87001. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  87002. {
  87003. void *x;
  87004. FLAC__ASSERT(0 != aligned_address);
  87005. #ifdef FLAC__ALIGN_MALLOC_DATA
  87006. x = safe_malloc_add_2op_(bytes, /*+*/31);
  87007. #ifdef SIZEOF_VOIDP
  87008. #if SIZEOF_VOIDP == 4
  87009. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87010. #elif SIZEOF_VOIDP == 8
  87011. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87012. #else
  87013. # error Unsupported sizeof(void*)
  87014. #endif
  87015. #else
  87016. if(sizeof(void*) == sizeof(unsigned))
  87017. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87018. else if(sizeof(void*) == sizeof(FLAC__uint64))
  87019. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87020. else
  87021. return 0;
  87022. #endif
  87023. #else
  87024. x = safe_malloc_(bytes);
  87025. *aligned_address = x;
  87026. #endif
  87027. return x;
  87028. }
  87029. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  87030. {
  87031. FLAC__int32 *pu; /* unaligned pointer */
  87032. union { /* union needed to comply with C99 pointer aliasing rules */
  87033. FLAC__int32 *pa; /* aligned pointer */
  87034. void *pv; /* aligned pointer alias */
  87035. } u;
  87036. FLAC__ASSERT(elements > 0);
  87037. FLAC__ASSERT(0 != unaligned_pointer);
  87038. FLAC__ASSERT(0 != aligned_pointer);
  87039. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87040. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  87041. if(0 == pu) {
  87042. return false;
  87043. }
  87044. else {
  87045. if(*unaligned_pointer != 0)
  87046. free(*unaligned_pointer);
  87047. *unaligned_pointer = pu;
  87048. *aligned_pointer = u.pa;
  87049. return true;
  87050. }
  87051. }
  87052. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  87053. {
  87054. FLAC__uint32 *pu; /* unaligned pointer */
  87055. union { /* union needed to comply with C99 pointer aliasing rules */
  87056. FLAC__uint32 *pa; /* aligned pointer */
  87057. void *pv; /* aligned pointer alias */
  87058. } u;
  87059. FLAC__ASSERT(elements > 0);
  87060. FLAC__ASSERT(0 != unaligned_pointer);
  87061. FLAC__ASSERT(0 != aligned_pointer);
  87062. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87063. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87064. if(0 == pu) {
  87065. return false;
  87066. }
  87067. else {
  87068. if(*unaligned_pointer != 0)
  87069. free(*unaligned_pointer);
  87070. *unaligned_pointer = pu;
  87071. *aligned_pointer = u.pa;
  87072. return true;
  87073. }
  87074. }
  87075. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  87076. {
  87077. FLAC__uint64 *pu; /* unaligned pointer */
  87078. union { /* union needed to comply with C99 pointer aliasing rules */
  87079. FLAC__uint64 *pa; /* aligned pointer */
  87080. void *pv; /* aligned pointer alias */
  87081. } u;
  87082. FLAC__ASSERT(elements > 0);
  87083. FLAC__ASSERT(0 != unaligned_pointer);
  87084. FLAC__ASSERT(0 != aligned_pointer);
  87085. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87086. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87087. if(0 == pu) {
  87088. return false;
  87089. }
  87090. else {
  87091. if(*unaligned_pointer != 0)
  87092. free(*unaligned_pointer);
  87093. *unaligned_pointer = pu;
  87094. *aligned_pointer = u.pa;
  87095. return true;
  87096. }
  87097. }
  87098. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  87099. {
  87100. unsigned *pu; /* unaligned pointer */
  87101. union { /* union needed to comply with C99 pointer aliasing rules */
  87102. unsigned *pa; /* aligned pointer */
  87103. void *pv; /* aligned pointer alias */
  87104. } u;
  87105. FLAC__ASSERT(elements > 0);
  87106. FLAC__ASSERT(0 != unaligned_pointer);
  87107. FLAC__ASSERT(0 != aligned_pointer);
  87108. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87109. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87110. if(0 == pu) {
  87111. return false;
  87112. }
  87113. else {
  87114. if(*unaligned_pointer != 0)
  87115. free(*unaligned_pointer);
  87116. *unaligned_pointer = pu;
  87117. *aligned_pointer = u.pa;
  87118. return true;
  87119. }
  87120. }
  87121. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87122. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  87123. {
  87124. FLAC__real *pu; /* unaligned pointer */
  87125. union { /* union needed to comply with C99 pointer aliasing rules */
  87126. FLAC__real *pa; /* aligned pointer */
  87127. void *pv; /* aligned pointer alias */
  87128. } u;
  87129. FLAC__ASSERT(elements > 0);
  87130. FLAC__ASSERT(0 != unaligned_pointer);
  87131. FLAC__ASSERT(0 != aligned_pointer);
  87132. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87133. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87134. if(0 == pu) {
  87135. return false;
  87136. }
  87137. else {
  87138. if(*unaligned_pointer != 0)
  87139. free(*unaligned_pointer);
  87140. *unaligned_pointer = pu;
  87141. *aligned_pointer = u.pa;
  87142. return true;
  87143. }
  87144. }
  87145. #endif
  87146. #endif
  87147. /*** End of inlined file: memory.c ***/
  87148. /*** Start of inlined file: stream_decoder.c ***/
  87149. /*** Start of inlined file: juce_FlacHeader.h ***/
  87150. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87151. // tasks..
  87152. #define VERSION "1.2.1"
  87153. #define FLAC__NO_DLL 1
  87154. #if JUCE_MSVC
  87155. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87156. #endif
  87157. #if JUCE_MAC
  87158. #define FLAC__SYS_DARWIN 1
  87159. #endif
  87160. /*** End of inlined file: juce_FlacHeader.h ***/
  87161. #if JUCE_USE_FLAC
  87162. #if HAVE_CONFIG_H
  87163. # include <config.h>
  87164. #endif
  87165. #if defined _MSC_VER || defined __MINGW32__
  87166. #include <io.h> /* for _setmode() */
  87167. #include <fcntl.h> /* for _O_BINARY */
  87168. #endif
  87169. #if defined __CYGWIN__ || defined __EMX__
  87170. #include <io.h> /* for setmode(), O_BINARY */
  87171. #include <fcntl.h> /* for _O_BINARY */
  87172. #endif
  87173. #include <stdio.h>
  87174. #include <stdlib.h> /* for malloc() */
  87175. #include <string.h> /* for memset/memcpy() */
  87176. #include <sys/stat.h> /* for stat() */
  87177. #include <sys/types.h> /* for off_t */
  87178. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  87179. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  87180. #define fseeko fseek
  87181. #define ftello ftell
  87182. #endif
  87183. #endif
  87184. /*** Start of inlined file: stream_decoder.h ***/
  87185. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  87186. #define FLAC__PROTECTED__STREAM_DECODER_H
  87187. #if FLAC__HAS_OGG
  87188. #include "include/private/ogg_decoder_aspect.h"
  87189. #endif
  87190. typedef struct FLAC__StreamDecoderProtected {
  87191. FLAC__StreamDecoderState state;
  87192. unsigned channels;
  87193. FLAC__ChannelAssignment channel_assignment;
  87194. unsigned bits_per_sample;
  87195. unsigned sample_rate; /* in Hz */
  87196. unsigned blocksize; /* in samples (per channel) */
  87197. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  87198. #if FLAC__HAS_OGG
  87199. FLAC__OggDecoderAspect ogg_decoder_aspect;
  87200. #endif
  87201. } FLAC__StreamDecoderProtected;
  87202. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  87203. #endif
  87204. /*** End of inlined file: stream_decoder.h ***/
  87205. #ifdef max
  87206. #undef max
  87207. #endif
  87208. #define max(a,b) ((a)>(b)?(a):(b))
  87209. #ifdef _MSC_VER
  87210. #define FLAC__U64L(x) x
  87211. #else
  87212. #define FLAC__U64L(x) x##LLU
  87213. #endif
  87214. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  87215. #if FLAC__HAS_OGG
  87216. 1
  87217. #else
  87218. 0
  87219. #endif
  87220. ;
  87221. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  87222. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  87223. static FILE *get_binary_stdin_(void);
  87224. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  87225. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  87226. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  87227. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  87228. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87229. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87230. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  87231. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  87232. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  87233. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  87234. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  87235. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  87236. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  87237. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87238. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87239. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87240. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87241. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87242. 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);
  87243. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  87244. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  87245. #if FLAC__HAS_OGG
  87246. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  87247. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87248. #endif
  87249. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  87250. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  87251. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87252. #if FLAC__HAS_OGG
  87253. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87254. #endif
  87255. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87256. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  87257. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  87258. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  87259. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  87260. typedef struct FLAC__StreamDecoderPrivate {
  87261. #if FLAC__HAS_OGG
  87262. FLAC__bool is_ogg;
  87263. #endif
  87264. FLAC__StreamDecoderReadCallback read_callback;
  87265. FLAC__StreamDecoderSeekCallback seek_callback;
  87266. FLAC__StreamDecoderTellCallback tell_callback;
  87267. FLAC__StreamDecoderLengthCallback length_callback;
  87268. FLAC__StreamDecoderEofCallback eof_callback;
  87269. FLAC__StreamDecoderWriteCallback write_callback;
  87270. FLAC__StreamDecoderMetadataCallback metadata_callback;
  87271. FLAC__StreamDecoderErrorCallback error_callback;
  87272. 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[]);
  87273. 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[]);
  87274. 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[]);
  87275. 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[]);
  87276. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  87277. void *client_data;
  87278. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  87279. FLAC__BitReader *input;
  87280. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  87281. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  87282. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  87283. unsigned output_capacity, output_channels;
  87284. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87285. FLAC__uint64 samples_decoded;
  87286. FLAC__bool has_stream_info, has_seek_table;
  87287. FLAC__StreamMetadata stream_info;
  87288. FLAC__StreamMetadata seek_table;
  87289. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87290. FLAC__byte *metadata_filter_ids;
  87291. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87292. FLAC__Frame frame;
  87293. FLAC__bool cached; /* true if there is a byte in lookahead */
  87294. FLAC__CPUInfo cpuinfo;
  87295. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87296. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87297. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87298. 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 */
  87299. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87300. FLAC__bool is_seeking;
  87301. FLAC__MD5Context md5context;
  87302. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87303. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87304. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87305. FLAC__uint64 target_sample;
  87306. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87307. #if FLAC__HAS_OGG
  87308. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87309. #endif
  87310. } FLAC__StreamDecoderPrivate;
  87311. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87312. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87313. "FLAC__STREAM_DECODER_READ_METADATA",
  87314. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87315. "FLAC__STREAM_DECODER_READ_FRAME",
  87316. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87317. "FLAC__STREAM_DECODER_OGG_ERROR",
  87318. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87319. "FLAC__STREAM_DECODER_ABORTED",
  87320. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87321. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87322. };
  87323. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87324. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87325. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87326. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87327. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87328. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87329. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87330. };
  87331. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87332. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87333. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87334. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87335. };
  87336. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87337. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87338. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87339. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87340. };
  87341. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87342. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87343. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87344. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87345. };
  87346. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87347. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87348. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87349. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87350. };
  87351. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87352. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87353. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87354. };
  87355. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87356. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87357. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87358. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87359. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87360. };
  87361. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87362. {
  87363. FLAC__StreamDecoder *decoder;
  87364. unsigned i;
  87365. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87366. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87367. if(decoder == 0) {
  87368. return 0;
  87369. }
  87370. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87371. if(decoder->protected_ == 0) {
  87372. free(decoder);
  87373. return 0;
  87374. }
  87375. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87376. if(decoder->private_ == 0) {
  87377. free(decoder->protected_);
  87378. free(decoder);
  87379. return 0;
  87380. }
  87381. decoder->private_->input = FLAC__bitreader_new();
  87382. if(decoder->private_->input == 0) {
  87383. free(decoder->private_);
  87384. free(decoder->protected_);
  87385. free(decoder);
  87386. return 0;
  87387. }
  87388. decoder->private_->metadata_filter_ids_capacity = 16;
  87389. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87390. FLAC__bitreader_delete(decoder->private_->input);
  87391. free(decoder->private_);
  87392. free(decoder->protected_);
  87393. free(decoder);
  87394. return 0;
  87395. }
  87396. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87397. decoder->private_->output[i] = 0;
  87398. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87399. }
  87400. decoder->private_->output_capacity = 0;
  87401. decoder->private_->output_channels = 0;
  87402. decoder->private_->has_seek_table = false;
  87403. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87404. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87405. decoder->private_->file = 0;
  87406. set_defaults_dec(decoder);
  87407. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87408. return decoder;
  87409. }
  87410. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87411. {
  87412. unsigned i;
  87413. FLAC__ASSERT(0 != decoder);
  87414. FLAC__ASSERT(0 != decoder->protected_);
  87415. FLAC__ASSERT(0 != decoder->private_);
  87416. FLAC__ASSERT(0 != decoder->private_->input);
  87417. (void)FLAC__stream_decoder_finish(decoder);
  87418. if(0 != decoder->private_->metadata_filter_ids)
  87419. free(decoder->private_->metadata_filter_ids);
  87420. FLAC__bitreader_delete(decoder->private_->input);
  87421. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87422. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87423. free(decoder->private_);
  87424. free(decoder->protected_);
  87425. free(decoder);
  87426. }
  87427. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87428. FLAC__StreamDecoder *decoder,
  87429. FLAC__StreamDecoderReadCallback read_callback,
  87430. FLAC__StreamDecoderSeekCallback seek_callback,
  87431. FLAC__StreamDecoderTellCallback tell_callback,
  87432. FLAC__StreamDecoderLengthCallback length_callback,
  87433. FLAC__StreamDecoderEofCallback eof_callback,
  87434. FLAC__StreamDecoderWriteCallback write_callback,
  87435. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87436. FLAC__StreamDecoderErrorCallback error_callback,
  87437. void *client_data,
  87438. FLAC__bool is_ogg
  87439. )
  87440. {
  87441. FLAC__ASSERT(0 != decoder);
  87442. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87443. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87444. #if !FLAC__HAS_OGG
  87445. if(is_ogg)
  87446. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87447. #endif
  87448. if(
  87449. 0 == read_callback ||
  87450. 0 == write_callback ||
  87451. 0 == error_callback ||
  87452. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87453. )
  87454. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87455. #if FLAC__HAS_OGG
  87456. decoder->private_->is_ogg = is_ogg;
  87457. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87458. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87459. #endif
  87460. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87461. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87462. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87463. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87464. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87465. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87466. #ifndef FLAC__NO_ASM
  87467. if(decoder->private_->cpuinfo.use_asm) {
  87468. #ifdef FLAC__CPU_IA32
  87469. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87470. #ifdef FLAC__HAS_NASM
  87471. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87472. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87473. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87474. #endif
  87475. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87476. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87477. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87478. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87479. }
  87480. else {
  87481. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87482. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87483. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87484. }
  87485. #endif
  87486. #elif defined FLAC__CPU_PPC
  87487. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87488. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87489. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87490. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87491. }
  87492. #endif
  87493. }
  87494. #endif
  87495. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87496. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87497. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87498. }
  87499. decoder->private_->read_callback = read_callback;
  87500. decoder->private_->seek_callback = seek_callback;
  87501. decoder->private_->tell_callback = tell_callback;
  87502. decoder->private_->length_callback = length_callback;
  87503. decoder->private_->eof_callback = eof_callback;
  87504. decoder->private_->write_callback = write_callback;
  87505. decoder->private_->metadata_callback = metadata_callback;
  87506. decoder->private_->error_callback = error_callback;
  87507. decoder->private_->client_data = client_data;
  87508. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87509. decoder->private_->samples_decoded = 0;
  87510. decoder->private_->has_stream_info = false;
  87511. decoder->private_->cached = false;
  87512. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87513. decoder->private_->is_seeking = false;
  87514. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87515. if(!FLAC__stream_decoder_reset(decoder)) {
  87516. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87517. }
  87518. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87519. }
  87520. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87521. FLAC__StreamDecoder *decoder,
  87522. FLAC__StreamDecoderReadCallback read_callback,
  87523. FLAC__StreamDecoderSeekCallback seek_callback,
  87524. FLAC__StreamDecoderTellCallback tell_callback,
  87525. FLAC__StreamDecoderLengthCallback length_callback,
  87526. FLAC__StreamDecoderEofCallback eof_callback,
  87527. FLAC__StreamDecoderWriteCallback write_callback,
  87528. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87529. FLAC__StreamDecoderErrorCallback error_callback,
  87530. void *client_data
  87531. )
  87532. {
  87533. return init_stream_internal_dec(
  87534. decoder,
  87535. read_callback,
  87536. seek_callback,
  87537. tell_callback,
  87538. length_callback,
  87539. eof_callback,
  87540. write_callback,
  87541. metadata_callback,
  87542. error_callback,
  87543. client_data,
  87544. false
  87545. );
  87546. }
  87547. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87548. FLAC__StreamDecoder *decoder,
  87549. FLAC__StreamDecoderReadCallback read_callback,
  87550. FLAC__StreamDecoderSeekCallback seek_callback,
  87551. FLAC__StreamDecoderTellCallback tell_callback,
  87552. FLAC__StreamDecoderLengthCallback length_callback,
  87553. FLAC__StreamDecoderEofCallback eof_callback,
  87554. FLAC__StreamDecoderWriteCallback write_callback,
  87555. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87556. FLAC__StreamDecoderErrorCallback error_callback,
  87557. void *client_data
  87558. )
  87559. {
  87560. return init_stream_internal_dec(
  87561. decoder,
  87562. read_callback,
  87563. seek_callback,
  87564. tell_callback,
  87565. length_callback,
  87566. eof_callback,
  87567. write_callback,
  87568. metadata_callback,
  87569. error_callback,
  87570. client_data,
  87571. true
  87572. );
  87573. }
  87574. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87575. FLAC__StreamDecoder *decoder,
  87576. FILE *file,
  87577. FLAC__StreamDecoderWriteCallback write_callback,
  87578. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87579. FLAC__StreamDecoderErrorCallback error_callback,
  87580. void *client_data,
  87581. FLAC__bool is_ogg
  87582. )
  87583. {
  87584. FLAC__ASSERT(0 != decoder);
  87585. FLAC__ASSERT(0 != file);
  87586. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87587. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87588. if(0 == write_callback || 0 == error_callback)
  87589. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87590. if(file == stdin)
  87591. file = get_binary_stdin_(); /* just to be safe */
  87592. decoder->private_->file = file;
  87593. return init_stream_internal_dec(
  87594. decoder,
  87595. file_read_callback_dec,
  87596. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87597. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87598. decoder->private_->file == stdin? 0: file_length_callback_,
  87599. file_eof_callback_,
  87600. write_callback,
  87601. metadata_callback,
  87602. error_callback,
  87603. client_data,
  87604. is_ogg
  87605. );
  87606. }
  87607. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87608. FLAC__StreamDecoder *decoder,
  87609. FILE *file,
  87610. FLAC__StreamDecoderWriteCallback write_callback,
  87611. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87612. FLAC__StreamDecoderErrorCallback error_callback,
  87613. void *client_data
  87614. )
  87615. {
  87616. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87617. }
  87618. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87619. FLAC__StreamDecoder *decoder,
  87620. FILE *file,
  87621. FLAC__StreamDecoderWriteCallback write_callback,
  87622. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87623. FLAC__StreamDecoderErrorCallback error_callback,
  87624. void *client_data
  87625. )
  87626. {
  87627. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87628. }
  87629. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87630. FLAC__StreamDecoder *decoder,
  87631. const char *filename,
  87632. FLAC__StreamDecoderWriteCallback write_callback,
  87633. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87634. FLAC__StreamDecoderErrorCallback error_callback,
  87635. void *client_data,
  87636. FLAC__bool is_ogg
  87637. )
  87638. {
  87639. FILE *file;
  87640. FLAC__ASSERT(0 != decoder);
  87641. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87642. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87643. if(0 == write_callback || 0 == error_callback)
  87644. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87645. file = filename? fopen(filename, "rb") : stdin;
  87646. if(0 == file)
  87647. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87648. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87649. }
  87650. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87651. FLAC__StreamDecoder *decoder,
  87652. const char *filename,
  87653. FLAC__StreamDecoderWriteCallback write_callback,
  87654. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87655. FLAC__StreamDecoderErrorCallback error_callback,
  87656. void *client_data
  87657. )
  87658. {
  87659. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87660. }
  87661. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87662. FLAC__StreamDecoder *decoder,
  87663. const char *filename,
  87664. FLAC__StreamDecoderWriteCallback write_callback,
  87665. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87666. FLAC__StreamDecoderErrorCallback error_callback,
  87667. void *client_data
  87668. )
  87669. {
  87670. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87671. }
  87672. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87673. {
  87674. FLAC__bool md5_failed = false;
  87675. unsigned i;
  87676. FLAC__ASSERT(0 != decoder);
  87677. FLAC__ASSERT(0 != decoder->private_);
  87678. FLAC__ASSERT(0 != decoder->protected_);
  87679. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87680. return true;
  87681. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87682. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87683. free(decoder->private_->seek_table.data.seek_table.points);
  87684. decoder->private_->seek_table.data.seek_table.points = 0;
  87685. decoder->private_->has_seek_table = false;
  87686. }
  87687. FLAC__bitreader_free(decoder->private_->input);
  87688. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87689. if(0 != decoder->private_->output[i]) {
  87690. free(decoder->private_->output[i]-4);
  87691. decoder->private_->output[i] = 0;
  87692. }
  87693. if(0 != decoder->private_->residual_unaligned[i]) {
  87694. free(decoder->private_->residual_unaligned[i]);
  87695. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87696. }
  87697. }
  87698. decoder->private_->output_capacity = 0;
  87699. decoder->private_->output_channels = 0;
  87700. #if FLAC__HAS_OGG
  87701. if(decoder->private_->is_ogg)
  87702. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87703. #endif
  87704. if(0 != decoder->private_->file) {
  87705. if(decoder->private_->file != stdin)
  87706. fclose(decoder->private_->file);
  87707. decoder->private_->file = 0;
  87708. }
  87709. if(decoder->private_->do_md5_checking) {
  87710. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87711. md5_failed = true;
  87712. }
  87713. decoder->private_->is_seeking = false;
  87714. set_defaults_dec(decoder);
  87715. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87716. return !md5_failed;
  87717. }
  87718. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87719. {
  87720. FLAC__ASSERT(0 != decoder);
  87721. FLAC__ASSERT(0 != decoder->private_);
  87722. FLAC__ASSERT(0 != decoder->protected_);
  87723. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87724. return false;
  87725. #if FLAC__HAS_OGG
  87726. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87727. return true;
  87728. #else
  87729. (void)value;
  87730. return false;
  87731. #endif
  87732. }
  87733. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87734. {
  87735. FLAC__ASSERT(0 != decoder);
  87736. FLAC__ASSERT(0 != decoder->protected_);
  87737. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87738. return false;
  87739. decoder->protected_->md5_checking = value;
  87740. return true;
  87741. }
  87742. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87743. {
  87744. FLAC__ASSERT(0 != decoder);
  87745. FLAC__ASSERT(0 != decoder->private_);
  87746. FLAC__ASSERT(0 != decoder->protected_);
  87747. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87748. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87749. return false;
  87750. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87751. return false;
  87752. decoder->private_->metadata_filter[type] = true;
  87753. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87754. decoder->private_->metadata_filter_ids_count = 0;
  87755. return true;
  87756. }
  87757. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87758. {
  87759. FLAC__ASSERT(0 != decoder);
  87760. FLAC__ASSERT(0 != decoder->private_);
  87761. FLAC__ASSERT(0 != decoder->protected_);
  87762. FLAC__ASSERT(0 != id);
  87763. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87764. return false;
  87765. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87766. return true;
  87767. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87768. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87769. 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))) {
  87770. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87771. return false;
  87772. }
  87773. decoder->private_->metadata_filter_ids_capacity *= 2;
  87774. }
  87775. 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));
  87776. decoder->private_->metadata_filter_ids_count++;
  87777. return true;
  87778. }
  87779. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87780. {
  87781. unsigned i;
  87782. FLAC__ASSERT(0 != decoder);
  87783. FLAC__ASSERT(0 != decoder->private_);
  87784. FLAC__ASSERT(0 != decoder->protected_);
  87785. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87786. return false;
  87787. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87788. decoder->private_->metadata_filter[i] = true;
  87789. decoder->private_->metadata_filter_ids_count = 0;
  87790. return true;
  87791. }
  87792. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87793. {
  87794. FLAC__ASSERT(0 != decoder);
  87795. FLAC__ASSERT(0 != decoder->private_);
  87796. FLAC__ASSERT(0 != decoder->protected_);
  87797. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87798. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87799. return false;
  87800. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87801. return false;
  87802. decoder->private_->metadata_filter[type] = false;
  87803. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87804. decoder->private_->metadata_filter_ids_count = 0;
  87805. return true;
  87806. }
  87807. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87808. {
  87809. FLAC__ASSERT(0 != decoder);
  87810. FLAC__ASSERT(0 != decoder->private_);
  87811. FLAC__ASSERT(0 != decoder->protected_);
  87812. FLAC__ASSERT(0 != id);
  87813. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87814. return false;
  87815. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87816. return true;
  87817. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87818. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87819. 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))) {
  87820. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87821. return false;
  87822. }
  87823. decoder->private_->metadata_filter_ids_capacity *= 2;
  87824. }
  87825. 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));
  87826. decoder->private_->metadata_filter_ids_count++;
  87827. return true;
  87828. }
  87829. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87830. {
  87831. FLAC__ASSERT(0 != decoder);
  87832. FLAC__ASSERT(0 != decoder->private_);
  87833. FLAC__ASSERT(0 != decoder->protected_);
  87834. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87835. return false;
  87836. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87837. decoder->private_->metadata_filter_ids_count = 0;
  87838. return true;
  87839. }
  87840. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87841. {
  87842. FLAC__ASSERT(0 != decoder);
  87843. FLAC__ASSERT(0 != decoder->protected_);
  87844. return decoder->protected_->state;
  87845. }
  87846. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87847. {
  87848. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87849. }
  87850. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87851. {
  87852. FLAC__ASSERT(0 != decoder);
  87853. FLAC__ASSERT(0 != decoder->protected_);
  87854. return decoder->protected_->md5_checking;
  87855. }
  87856. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87857. {
  87858. FLAC__ASSERT(0 != decoder);
  87859. FLAC__ASSERT(0 != decoder->protected_);
  87860. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87861. }
  87862. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87863. {
  87864. FLAC__ASSERT(0 != decoder);
  87865. FLAC__ASSERT(0 != decoder->protected_);
  87866. return decoder->protected_->channels;
  87867. }
  87868. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87869. {
  87870. FLAC__ASSERT(0 != decoder);
  87871. FLAC__ASSERT(0 != decoder->protected_);
  87872. return decoder->protected_->channel_assignment;
  87873. }
  87874. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87875. {
  87876. FLAC__ASSERT(0 != decoder);
  87877. FLAC__ASSERT(0 != decoder->protected_);
  87878. return decoder->protected_->bits_per_sample;
  87879. }
  87880. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87881. {
  87882. FLAC__ASSERT(0 != decoder);
  87883. FLAC__ASSERT(0 != decoder->protected_);
  87884. return decoder->protected_->sample_rate;
  87885. }
  87886. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87887. {
  87888. FLAC__ASSERT(0 != decoder);
  87889. FLAC__ASSERT(0 != decoder->protected_);
  87890. return decoder->protected_->blocksize;
  87891. }
  87892. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87893. {
  87894. FLAC__ASSERT(0 != decoder);
  87895. FLAC__ASSERT(0 != decoder->private_);
  87896. FLAC__ASSERT(0 != position);
  87897. #if FLAC__HAS_OGG
  87898. if(decoder->private_->is_ogg)
  87899. return false;
  87900. #endif
  87901. if(0 == decoder->private_->tell_callback)
  87902. return false;
  87903. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87904. return false;
  87905. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87906. return false;
  87907. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87908. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87909. return true;
  87910. }
  87911. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87912. {
  87913. FLAC__ASSERT(0 != decoder);
  87914. FLAC__ASSERT(0 != decoder->private_);
  87915. FLAC__ASSERT(0 != decoder->protected_);
  87916. decoder->private_->samples_decoded = 0;
  87917. decoder->private_->do_md5_checking = false;
  87918. #if FLAC__HAS_OGG
  87919. if(decoder->private_->is_ogg)
  87920. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87921. #endif
  87922. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87923. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87924. return false;
  87925. }
  87926. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87927. return true;
  87928. }
  87929. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87930. {
  87931. FLAC__ASSERT(0 != decoder);
  87932. FLAC__ASSERT(0 != decoder->private_);
  87933. FLAC__ASSERT(0 != decoder->protected_);
  87934. if(!FLAC__stream_decoder_flush(decoder)) {
  87935. return false;
  87936. }
  87937. #if FLAC__HAS_OGG
  87938. if(decoder->private_->is_ogg)
  87939. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87940. #endif
  87941. if(!decoder->private_->internal_reset_hack) {
  87942. if(decoder->private_->file == stdin)
  87943. return false; /* can't rewind stdin, reset fails */
  87944. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87945. return false; /* seekable and seek fails, reset fails */
  87946. }
  87947. else
  87948. decoder->private_->internal_reset_hack = false;
  87949. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87950. decoder->private_->has_stream_info = false;
  87951. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87952. free(decoder->private_->seek_table.data.seek_table.points);
  87953. decoder->private_->seek_table.data.seek_table.points = 0;
  87954. decoder->private_->has_seek_table = false;
  87955. }
  87956. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87957. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87958. FLAC__MD5Init(&decoder->private_->md5context);
  87959. decoder->private_->first_frame_offset = 0;
  87960. decoder->private_->unparseable_frame_count = 0;
  87961. return true;
  87962. }
  87963. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87964. {
  87965. FLAC__bool got_a_frame;
  87966. FLAC__ASSERT(0 != decoder);
  87967. FLAC__ASSERT(0 != decoder->protected_);
  87968. while(1) {
  87969. switch(decoder->protected_->state) {
  87970. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87971. if(!find_metadata_(decoder))
  87972. return false; /* above function sets the status for us */
  87973. break;
  87974. case FLAC__STREAM_DECODER_READ_METADATA:
  87975. if(!read_metadata_(decoder))
  87976. return false; /* above function sets the status for us */
  87977. else
  87978. return true;
  87979. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87980. if(!frame_sync_(decoder))
  87981. return true; /* above function sets the status for us */
  87982. break;
  87983. case FLAC__STREAM_DECODER_READ_FRAME:
  87984. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87985. return false; /* above function sets the status for us */
  87986. if(got_a_frame)
  87987. return true; /* above function sets the status for us */
  87988. break;
  87989. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87990. case FLAC__STREAM_DECODER_ABORTED:
  87991. return true;
  87992. default:
  87993. FLAC__ASSERT(0);
  87994. return false;
  87995. }
  87996. }
  87997. }
  87998. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87999. {
  88000. FLAC__ASSERT(0 != decoder);
  88001. FLAC__ASSERT(0 != decoder->protected_);
  88002. while(1) {
  88003. switch(decoder->protected_->state) {
  88004. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88005. if(!find_metadata_(decoder))
  88006. return false; /* above function sets the status for us */
  88007. break;
  88008. case FLAC__STREAM_DECODER_READ_METADATA:
  88009. if(!read_metadata_(decoder))
  88010. return false; /* above function sets the status for us */
  88011. break;
  88012. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88013. case FLAC__STREAM_DECODER_READ_FRAME:
  88014. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88015. case FLAC__STREAM_DECODER_ABORTED:
  88016. return true;
  88017. default:
  88018. FLAC__ASSERT(0);
  88019. return false;
  88020. }
  88021. }
  88022. }
  88023. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  88024. {
  88025. FLAC__bool dummy;
  88026. FLAC__ASSERT(0 != decoder);
  88027. FLAC__ASSERT(0 != decoder->protected_);
  88028. while(1) {
  88029. switch(decoder->protected_->state) {
  88030. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88031. if(!find_metadata_(decoder))
  88032. return false; /* above function sets the status for us */
  88033. break;
  88034. case FLAC__STREAM_DECODER_READ_METADATA:
  88035. if(!read_metadata_(decoder))
  88036. return false; /* above function sets the status for us */
  88037. break;
  88038. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88039. if(!frame_sync_(decoder))
  88040. return true; /* above function sets the status for us */
  88041. break;
  88042. case FLAC__STREAM_DECODER_READ_FRAME:
  88043. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  88044. return false; /* above function sets the status for us */
  88045. break;
  88046. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88047. case FLAC__STREAM_DECODER_ABORTED:
  88048. return true;
  88049. default:
  88050. FLAC__ASSERT(0);
  88051. return false;
  88052. }
  88053. }
  88054. }
  88055. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  88056. {
  88057. FLAC__bool got_a_frame;
  88058. FLAC__ASSERT(0 != decoder);
  88059. FLAC__ASSERT(0 != decoder->protected_);
  88060. while(1) {
  88061. switch(decoder->protected_->state) {
  88062. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88063. case FLAC__STREAM_DECODER_READ_METADATA:
  88064. return false; /* above function sets the status for us */
  88065. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88066. if(!frame_sync_(decoder))
  88067. return true; /* above function sets the status for us */
  88068. break;
  88069. case FLAC__STREAM_DECODER_READ_FRAME:
  88070. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  88071. return false; /* above function sets the status for us */
  88072. if(got_a_frame)
  88073. return true; /* above function sets the status for us */
  88074. break;
  88075. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88076. case FLAC__STREAM_DECODER_ABORTED:
  88077. return true;
  88078. default:
  88079. FLAC__ASSERT(0);
  88080. return false;
  88081. }
  88082. }
  88083. }
  88084. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  88085. {
  88086. FLAC__uint64 length;
  88087. FLAC__ASSERT(0 != decoder);
  88088. if(
  88089. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  88090. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  88091. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  88092. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  88093. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  88094. )
  88095. return false;
  88096. if(0 == decoder->private_->seek_callback)
  88097. return false;
  88098. FLAC__ASSERT(decoder->private_->seek_callback);
  88099. FLAC__ASSERT(decoder->private_->tell_callback);
  88100. FLAC__ASSERT(decoder->private_->length_callback);
  88101. FLAC__ASSERT(decoder->private_->eof_callback);
  88102. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  88103. return false;
  88104. decoder->private_->is_seeking = true;
  88105. decoder->private_->do_md5_checking = false;
  88106. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  88107. decoder->private_->is_seeking = false;
  88108. return false;
  88109. }
  88110. if(
  88111. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  88112. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  88113. ) {
  88114. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  88115. decoder->private_->is_seeking = false;
  88116. return false;
  88117. }
  88118. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88119. decoder->private_->is_seeking = false;
  88120. return false;
  88121. }
  88122. }
  88123. {
  88124. const FLAC__bool ok =
  88125. #if FLAC__HAS_OGG
  88126. decoder->private_->is_ogg?
  88127. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  88128. #endif
  88129. seek_to_absolute_sample_(decoder, length, sample)
  88130. ;
  88131. decoder->private_->is_seeking = false;
  88132. return ok;
  88133. }
  88134. }
  88135. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  88136. {
  88137. FLAC__ASSERT(0 != decoder);
  88138. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88139. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  88140. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  88141. }
  88142. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  88143. {
  88144. #if FLAC__HAS_OGG
  88145. decoder->private_->is_ogg = false;
  88146. #endif
  88147. decoder->private_->read_callback = 0;
  88148. decoder->private_->seek_callback = 0;
  88149. decoder->private_->tell_callback = 0;
  88150. decoder->private_->length_callback = 0;
  88151. decoder->private_->eof_callback = 0;
  88152. decoder->private_->write_callback = 0;
  88153. decoder->private_->metadata_callback = 0;
  88154. decoder->private_->error_callback = 0;
  88155. decoder->private_->client_data = 0;
  88156. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  88157. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  88158. decoder->private_->metadata_filter_ids_count = 0;
  88159. decoder->protected_->md5_checking = false;
  88160. #if FLAC__HAS_OGG
  88161. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  88162. #endif
  88163. }
  88164. FILE *get_binary_stdin_(void)
  88165. {
  88166. #if defined _MSC_VER || defined __MINGW32__
  88167. _setmode(_fileno(stdin), _O_BINARY);
  88168. #elif defined __CYGWIN__
  88169. setmode(_fileno(stdin), _O_BINARY);
  88170. #elif defined __EMX__
  88171. setmode(fileno(stdin), O_BINARY);
  88172. #endif
  88173. return stdin;
  88174. }
  88175. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  88176. {
  88177. unsigned i;
  88178. FLAC__int32 *tmp;
  88179. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  88180. return true;
  88181. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  88182. if(0 != decoder->private_->output[i]) {
  88183. free(decoder->private_->output[i]-4);
  88184. decoder->private_->output[i] = 0;
  88185. }
  88186. if(0 != decoder->private_->residual_unaligned[i]) {
  88187. free(decoder->private_->residual_unaligned[i]);
  88188. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  88189. }
  88190. }
  88191. for(i = 0; i < channels; i++) {
  88192. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  88193. if(tmp == 0) {
  88194. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88195. return false;
  88196. }
  88197. memset(tmp, 0, sizeof(FLAC__int32)*4);
  88198. decoder->private_->output[i] = tmp + 4;
  88199. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  88200. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88201. return false;
  88202. }
  88203. }
  88204. decoder->private_->output_capacity = size;
  88205. decoder->private_->output_channels = channels;
  88206. return true;
  88207. }
  88208. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  88209. {
  88210. size_t i;
  88211. FLAC__ASSERT(0 != decoder);
  88212. FLAC__ASSERT(0 != decoder->private_);
  88213. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  88214. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  88215. return true;
  88216. return false;
  88217. }
  88218. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  88219. {
  88220. FLAC__uint32 x;
  88221. unsigned i, id_;
  88222. FLAC__bool first = true;
  88223. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88224. for(i = id_ = 0; i < 4; ) {
  88225. if(decoder->private_->cached) {
  88226. x = (FLAC__uint32)decoder->private_->lookahead;
  88227. decoder->private_->cached = false;
  88228. }
  88229. else {
  88230. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88231. return false; /* read_callback_ sets the state for us */
  88232. }
  88233. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  88234. first = true;
  88235. i++;
  88236. id_ = 0;
  88237. continue;
  88238. }
  88239. if(x == ID3V2_TAG_[id_]) {
  88240. id_++;
  88241. i = 0;
  88242. if(id_ == 3) {
  88243. if(!skip_id3v2_tag_(decoder))
  88244. return false; /* skip_id3v2_tag_ sets the state for us */
  88245. }
  88246. continue;
  88247. }
  88248. id_ = 0;
  88249. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88250. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88251. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88252. return false; /* read_callback_ sets the state for us */
  88253. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88254. decoder->private_->lookahead = (FLAC__byte)x;
  88255. decoder->private_->cached = true;
  88256. }
  88257. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88258. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88259. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88260. return true;
  88261. }
  88262. }
  88263. i = 0;
  88264. if(first) {
  88265. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88266. first = false;
  88267. }
  88268. }
  88269. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  88270. return true;
  88271. }
  88272. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  88273. {
  88274. FLAC__bool is_last;
  88275. FLAC__uint32 i, x, type, length;
  88276. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88277. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  88278. return false; /* read_callback_ sets the state for us */
  88279. is_last = x? true : false;
  88280. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  88281. return false; /* read_callback_ sets the state for us */
  88282. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  88283. return false; /* read_callback_ sets the state for us */
  88284. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88285. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88286. return false;
  88287. decoder->private_->has_stream_info = true;
  88288. 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))
  88289. decoder->private_->do_md5_checking = false;
  88290. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88291. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88292. }
  88293. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88294. if(!read_metadata_seektable_(decoder, is_last, length))
  88295. return false;
  88296. decoder->private_->has_seek_table = true;
  88297. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88298. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88299. }
  88300. else {
  88301. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88302. unsigned real_length = length;
  88303. FLAC__StreamMetadata block;
  88304. block.is_last = is_last;
  88305. block.type = (FLAC__MetadataType)type;
  88306. block.length = length;
  88307. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88308. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88309. return false; /* read_callback_ sets the state for us */
  88310. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88311. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88312. return false;
  88313. }
  88314. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88315. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88316. skip_it = !skip_it;
  88317. }
  88318. if(skip_it) {
  88319. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88320. return false; /* read_callback_ sets the state for us */
  88321. }
  88322. else {
  88323. switch(type) {
  88324. case FLAC__METADATA_TYPE_PADDING:
  88325. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88326. return false; /* read_callback_ sets the state for us */
  88327. break;
  88328. case FLAC__METADATA_TYPE_APPLICATION:
  88329. if(real_length > 0) {
  88330. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88331. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88332. return false;
  88333. }
  88334. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88335. return false; /* read_callback_ sets the state for us */
  88336. }
  88337. else
  88338. block.data.application.data = 0;
  88339. break;
  88340. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88341. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88342. return false;
  88343. break;
  88344. case FLAC__METADATA_TYPE_CUESHEET:
  88345. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88346. return false;
  88347. break;
  88348. case FLAC__METADATA_TYPE_PICTURE:
  88349. if(!read_metadata_picture_(decoder, &block.data.picture))
  88350. return false;
  88351. break;
  88352. case FLAC__METADATA_TYPE_STREAMINFO:
  88353. case FLAC__METADATA_TYPE_SEEKTABLE:
  88354. FLAC__ASSERT(0);
  88355. break;
  88356. default:
  88357. if(real_length > 0) {
  88358. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88359. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88360. return false;
  88361. }
  88362. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88363. return false; /* read_callback_ sets the state for us */
  88364. }
  88365. else
  88366. block.data.unknown.data = 0;
  88367. break;
  88368. }
  88369. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88370. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88371. switch(type) {
  88372. case FLAC__METADATA_TYPE_PADDING:
  88373. break;
  88374. case FLAC__METADATA_TYPE_APPLICATION:
  88375. if(0 != block.data.application.data)
  88376. free(block.data.application.data);
  88377. break;
  88378. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88379. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88380. free(block.data.vorbis_comment.vendor_string.entry);
  88381. if(block.data.vorbis_comment.num_comments > 0)
  88382. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88383. if(0 != block.data.vorbis_comment.comments[i].entry)
  88384. free(block.data.vorbis_comment.comments[i].entry);
  88385. if(0 != block.data.vorbis_comment.comments)
  88386. free(block.data.vorbis_comment.comments);
  88387. break;
  88388. case FLAC__METADATA_TYPE_CUESHEET:
  88389. if(block.data.cue_sheet.num_tracks > 0)
  88390. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88391. if(0 != block.data.cue_sheet.tracks[i].indices)
  88392. free(block.data.cue_sheet.tracks[i].indices);
  88393. if(0 != block.data.cue_sheet.tracks)
  88394. free(block.data.cue_sheet.tracks);
  88395. break;
  88396. case FLAC__METADATA_TYPE_PICTURE:
  88397. if(0 != block.data.picture.mime_type)
  88398. free(block.data.picture.mime_type);
  88399. if(0 != block.data.picture.description)
  88400. free(block.data.picture.description);
  88401. if(0 != block.data.picture.data)
  88402. free(block.data.picture.data);
  88403. break;
  88404. case FLAC__METADATA_TYPE_STREAMINFO:
  88405. case FLAC__METADATA_TYPE_SEEKTABLE:
  88406. FLAC__ASSERT(0);
  88407. default:
  88408. if(0 != block.data.unknown.data)
  88409. free(block.data.unknown.data);
  88410. break;
  88411. }
  88412. }
  88413. }
  88414. if(is_last) {
  88415. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88416. decoder->private_->first_frame_offset = 0;
  88417. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88418. }
  88419. return true;
  88420. }
  88421. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88422. {
  88423. FLAC__uint32 x;
  88424. unsigned bits, used_bits = 0;
  88425. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88426. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88427. decoder->private_->stream_info.is_last = is_last;
  88428. decoder->private_->stream_info.length = length;
  88429. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88430. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88431. return false; /* read_callback_ sets the state for us */
  88432. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88433. used_bits += bits;
  88434. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88435. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88436. return false; /* read_callback_ sets the state for us */
  88437. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88438. used_bits += bits;
  88439. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88440. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88441. return false; /* read_callback_ sets the state for us */
  88442. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88443. used_bits += bits;
  88444. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88445. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88446. return false; /* read_callback_ sets the state for us */
  88447. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88448. used_bits += bits;
  88449. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88450. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88451. return false; /* read_callback_ sets the state for us */
  88452. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88453. used_bits += bits;
  88454. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88455. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88456. return false; /* read_callback_ sets the state for us */
  88457. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88458. used_bits += bits;
  88459. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88460. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88461. return false; /* read_callback_ sets the state for us */
  88462. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88463. used_bits += bits;
  88464. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88465. 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))
  88466. return false; /* read_callback_ sets the state for us */
  88467. used_bits += bits;
  88468. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88469. return false; /* read_callback_ sets the state for us */
  88470. used_bits += 16*8;
  88471. FLAC__ASSERT(used_bits % 8 == 0);
  88472. length -= (used_bits / 8);
  88473. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88474. return false; /* read_callback_ sets the state for us */
  88475. return true;
  88476. }
  88477. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88478. {
  88479. FLAC__uint32 i, x;
  88480. FLAC__uint64 xx;
  88481. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88482. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88483. decoder->private_->seek_table.is_last = is_last;
  88484. decoder->private_->seek_table.length = length;
  88485. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88486. 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)))) {
  88487. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88488. return false;
  88489. }
  88490. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88491. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88492. return false; /* read_callback_ sets the state for us */
  88493. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88494. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88495. return false; /* read_callback_ sets the state for us */
  88496. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88497. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88498. return false; /* read_callback_ sets the state for us */
  88499. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88500. }
  88501. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88502. if(length > 0) {
  88503. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88504. return false; /* read_callback_ sets the state for us */
  88505. }
  88506. return true;
  88507. }
  88508. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88509. {
  88510. FLAC__uint32 i;
  88511. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88512. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88513. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88514. return false; /* read_callback_ sets the state for us */
  88515. if(obj->vendor_string.length > 0) {
  88516. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88517. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88518. return false;
  88519. }
  88520. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88521. return false; /* read_callback_ sets the state for us */
  88522. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88523. }
  88524. else
  88525. obj->vendor_string.entry = 0;
  88526. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88527. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88528. return false; /* read_callback_ sets the state for us */
  88529. if(obj->num_comments > 0) {
  88530. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88531. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88532. return false;
  88533. }
  88534. for(i = 0; i < obj->num_comments; i++) {
  88535. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88536. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88537. return false; /* read_callback_ sets the state for us */
  88538. if(obj->comments[i].length > 0) {
  88539. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88540. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88541. return false;
  88542. }
  88543. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88544. return false; /* read_callback_ sets the state for us */
  88545. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88546. }
  88547. else
  88548. obj->comments[i].entry = 0;
  88549. }
  88550. }
  88551. else {
  88552. obj->comments = 0;
  88553. }
  88554. return true;
  88555. }
  88556. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88557. {
  88558. FLAC__uint32 i, j, x;
  88559. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88560. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88561. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88562. 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))
  88563. return false; /* read_callback_ sets the state for us */
  88564. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88565. return false; /* read_callback_ sets the state for us */
  88566. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88567. return false; /* read_callback_ sets the state for us */
  88568. obj->is_cd = x? true : false;
  88569. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88570. return false; /* read_callback_ sets the state for us */
  88571. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88572. return false; /* read_callback_ sets the state for us */
  88573. obj->num_tracks = x;
  88574. if(obj->num_tracks > 0) {
  88575. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88576. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88577. return false;
  88578. }
  88579. for(i = 0; i < obj->num_tracks; i++) {
  88580. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88581. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88582. return false; /* read_callback_ sets the state for us */
  88583. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88584. return false; /* read_callback_ sets the state for us */
  88585. track->number = (FLAC__byte)x;
  88586. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88587. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88588. return false; /* read_callback_ sets the state for us */
  88589. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88590. return false; /* read_callback_ sets the state for us */
  88591. track->type = x;
  88592. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88593. return false; /* read_callback_ sets the state for us */
  88594. track->pre_emphasis = x;
  88595. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88596. return false; /* read_callback_ sets the state for us */
  88597. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88598. return false; /* read_callback_ sets the state for us */
  88599. track->num_indices = (FLAC__byte)x;
  88600. if(track->num_indices > 0) {
  88601. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88602. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88603. return false;
  88604. }
  88605. for(j = 0; j < track->num_indices; j++) {
  88606. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88607. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88608. return false; /* read_callback_ sets the state for us */
  88609. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88610. return false; /* read_callback_ sets the state for us */
  88611. index->number = (FLAC__byte)x;
  88612. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88613. return false; /* read_callback_ sets the state for us */
  88614. }
  88615. }
  88616. }
  88617. }
  88618. return true;
  88619. }
  88620. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88621. {
  88622. FLAC__uint32 x;
  88623. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88624. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88625. return false; /* read_callback_ sets the state for us */
  88626. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88627. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88628. return false; /* read_callback_ sets the state for us */
  88629. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88630. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88631. return false;
  88632. }
  88633. if(x > 0) {
  88634. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88635. return false; /* read_callback_ sets the state for us */
  88636. }
  88637. obj->mime_type[x] = '\0';
  88638. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88639. return false; /* read_callback_ sets the state for us */
  88640. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88641. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88642. return false;
  88643. }
  88644. if(x > 0) {
  88645. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88646. return false; /* read_callback_ sets the state for us */
  88647. }
  88648. obj->description[x] = '\0';
  88649. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88650. return false; /* read_callback_ sets the state for us */
  88651. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88652. return false; /* read_callback_ sets the state for us */
  88653. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88654. return false; /* read_callback_ sets the state for us */
  88655. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88656. return false; /* read_callback_ sets the state for us */
  88657. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88658. return false; /* read_callback_ sets the state for us */
  88659. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88660. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88661. return false;
  88662. }
  88663. if(obj->data_length > 0) {
  88664. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88665. return false; /* read_callback_ sets the state for us */
  88666. }
  88667. return true;
  88668. }
  88669. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88670. {
  88671. FLAC__uint32 x;
  88672. unsigned i, skip;
  88673. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88674. return false; /* read_callback_ sets the state for us */
  88675. skip = 0;
  88676. for(i = 0; i < 4; i++) {
  88677. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88678. return false; /* read_callback_ sets the state for us */
  88679. skip <<= 7;
  88680. skip |= (x & 0x7f);
  88681. }
  88682. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88683. return false; /* read_callback_ sets the state for us */
  88684. return true;
  88685. }
  88686. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88687. {
  88688. FLAC__uint32 x;
  88689. FLAC__bool first = true;
  88690. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88691. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88692. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88693. return true;
  88694. }
  88695. }
  88696. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88697. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88698. return false; /* read_callback_ sets the state for us */
  88699. }
  88700. while(1) {
  88701. if(decoder->private_->cached) {
  88702. x = (FLAC__uint32)decoder->private_->lookahead;
  88703. decoder->private_->cached = false;
  88704. }
  88705. else {
  88706. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88707. return false; /* read_callback_ sets the state for us */
  88708. }
  88709. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88710. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88711. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88712. return false; /* read_callback_ sets the state for us */
  88713. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88714. decoder->private_->lookahead = (FLAC__byte)x;
  88715. decoder->private_->cached = true;
  88716. }
  88717. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88718. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88719. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88720. return true;
  88721. }
  88722. }
  88723. if(first) {
  88724. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88725. first = false;
  88726. }
  88727. }
  88728. return true;
  88729. }
  88730. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88731. {
  88732. unsigned channel;
  88733. unsigned i;
  88734. FLAC__int32 mid, side;
  88735. unsigned frame_crc; /* the one we calculate from the input stream */
  88736. FLAC__uint32 x;
  88737. *got_a_frame = false;
  88738. frame_crc = 0;
  88739. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88740. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88741. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88742. if(!read_frame_header_(decoder))
  88743. return false;
  88744. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88745. return true;
  88746. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88747. return false;
  88748. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88749. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88750. switch(decoder->private_->frame.header.channel_assignment) {
  88751. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88752. break;
  88753. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88754. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88755. if(channel == 1)
  88756. bps++;
  88757. break;
  88758. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88759. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88760. if(channel == 0)
  88761. bps++;
  88762. break;
  88763. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88764. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88765. if(channel == 1)
  88766. bps++;
  88767. break;
  88768. default:
  88769. FLAC__ASSERT(0);
  88770. }
  88771. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88772. return false;
  88773. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88774. return true;
  88775. }
  88776. if(!read_zero_padding_(decoder))
  88777. return false;
  88778. 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) */
  88779. return true;
  88780. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88781. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88782. return false; /* read_callback_ sets the state for us */
  88783. if(frame_crc == x) {
  88784. if(do_full_decode) {
  88785. switch(decoder->private_->frame.header.channel_assignment) {
  88786. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88787. break;
  88788. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88789. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88790. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88791. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88792. break;
  88793. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88794. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88795. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88796. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88797. break;
  88798. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88799. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88800. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88801. #if 1
  88802. mid = decoder->private_->output[0][i];
  88803. side = decoder->private_->output[1][i];
  88804. mid <<= 1;
  88805. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88806. decoder->private_->output[0][i] = (mid + side) >> 1;
  88807. decoder->private_->output[1][i] = (mid - side) >> 1;
  88808. #else
  88809. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88810. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88811. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88812. #endif
  88813. }
  88814. break;
  88815. default:
  88816. FLAC__ASSERT(0);
  88817. break;
  88818. }
  88819. }
  88820. }
  88821. else {
  88822. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88823. if(do_full_decode) {
  88824. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88825. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88826. }
  88827. }
  88828. }
  88829. *got_a_frame = true;
  88830. if(decoder->private_->next_fixed_block_size)
  88831. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88832. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88833. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88834. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88835. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88836. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88837. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88838. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88839. if(do_full_decode) {
  88840. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88841. return false;
  88842. }
  88843. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88844. return true;
  88845. }
  88846. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88847. {
  88848. FLAC__uint32 x;
  88849. FLAC__uint64 xx;
  88850. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88851. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88852. unsigned raw_header_len;
  88853. FLAC__bool is_unparseable = false;
  88854. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88855. raw_header[0] = decoder->private_->header_warmup[0];
  88856. raw_header[1] = decoder->private_->header_warmup[1];
  88857. raw_header_len = 2;
  88858. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88859. is_unparseable = true;
  88860. for(i = 0; i < 2; i++) {
  88861. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88862. return false; /* read_callback_ sets the state for us */
  88863. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88864. decoder->private_->lookahead = (FLAC__byte)x;
  88865. decoder->private_->cached = true;
  88866. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88867. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88868. return true;
  88869. }
  88870. raw_header[raw_header_len++] = (FLAC__byte)x;
  88871. }
  88872. switch(x = raw_header[2] >> 4) {
  88873. case 0:
  88874. is_unparseable = true;
  88875. break;
  88876. case 1:
  88877. decoder->private_->frame.header.blocksize = 192;
  88878. break;
  88879. case 2:
  88880. case 3:
  88881. case 4:
  88882. case 5:
  88883. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88884. break;
  88885. case 6:
  88886. case 7:
  88887. blocksize_hint = x;
  88888. break;
  88889. case 8:
  88890. case 9:
  88891. case 10:
  88892. case 11:
  88893. case 12:
  88894. case 13:
  88895. case 14:
  88896. case 15:
  88897. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88898. break;
  88899. default:
  88900. FLAC__ASSERT(0);
  88901. break;
  88902. }
  88903. switch(x = raw_header[2] & 0x0f) {
  88904. case 0:
  88905. if(decoder->private_->has_stream_info)
  88906. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88907. else
  88908. is_unparseable = true;
  88909. break;
  88910. case 1:
  88911. decoder->private_->frame.header.sample_rate = 88200;
  88912. break;
  88913. case 2:
  88914. decoder->private_->frame.header.sample_rate = 176400;
  88915. break;
  88916. case 3:
  88917. decoder->private_->frame.header.sample_rate = 192000;
  88918. break;
  88919. case 4:
  88920. decoder->private_->frame.header.sample_rate = 8000;
  88921. break;
  88922. case 5:
  88923. decoder->private_->frame.header.sample_rate = 16000;
  88924. break;
  88925. case 6:
  88926. decoder->private_->frame.header.sample_rate = 22050;
  88927. break;
  88928. case 7:
  88929. decoder->private_->frame.header.sample_rate = 24000;
  88930. break;
  88931. case 8:
  88932. decoder->private_->frame.header.sample_rate = 32000;
  88933. break;
  88934. case 9:
  88935. decoder->private_->frame.header.sample_rate = 44100;
  88936. break;
  88937. case 10:
  88938. decoder->private_->frame.header.sample_rate = 48000;
  88939. break;
  88940. case 11:
  88941. decoder->private_->frame.header.sample_rate = 96000;
  88942. break;
  88943. case 12:
  88944. case 13:
  88945. case 14:
  88946. sample_rate_hint = x;
  88947. break;
  88948. case 15:
  88949. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88950. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88951. return true;
  88952. default:
  88953. FLAC__ASSERT(0);
  88954. }
  88955. x = (unsigned)(raw_header[3] >> 4);
  88956. if(x & 8) {
  88957. decoder->private_->frame.header.channels = 2;
  88958. switch(x & 7) {
  88959. case 0:
  88960. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88961. break;
  88962. case 1:
  88963. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88964. break;
  88965. case 2:
  88966. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88967. break;
  88968. default:
  88969. is_unparseable = true;
  88970. break;
  88971. }
  88972. }
  88973. else {
  88974. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88975. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88976. }
  88977. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88978. case 0:
  88979. if(decoder->private_->has_stream_info)
  88980. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88981. else
  88982. is_unparseable = true;
  88983. break;
  88984. case 1:
  88985. decoder->private_->frame.header.bits_per_sample = 8;
  88986. break;
  88987. case 2:
  88988. decoder->private_->frame.header.bits_per_sample = 12;
  88989. break;
  88990. case 4:
  88991. decoder->private_->frame.header.bits_per_sample = 16;
  88992. break;
  88993. case 5:
  88994. decoder->private_->frame.header.bits_per_sample = 20;
  88995. break;
  88996. case 6:
  88997. decoder->private_->frame.header.bits_per_sample = 24;
  88998. break;
  88999. case 3:
  89000. case 7:
  89001. is_unparseable = true;
  89002. break;
  89003. default:
  89004. FLAC__ASSERT(0);
  89005. break;
  89006. }
  89007. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  89008. is_unparseable = true;
  89009. if(
  89010. raw_header[1] & 0x01 ||
  89011. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  89012. ) { /* variable blocksize */
  89013. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  89014. return false; /* read_callback_ sets the state for us */
  89015. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  89016. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89017. decoder->private_->cached = true;
  89018. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89019. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89020. return true;
  89021. }
  89022. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89023. decoder->private_->frame.header.number.sample_number = xx;
  89024. }
  89025. else { /* fixed blocksize */
  89026. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  89027. return false; /* read_callback_ sets the state for us */
  89028. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  89029. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89030. decoder->private_->cached = true;
  89031. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89032. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89033. return true;
  89034. }
  89035. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  89036. decoder->private_->frame.header.number.frame_number = x;
  89037. }
  89038. if(blocksize_hint) {
  89039. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89040. return false; /* read_callback_ sets the state for us */
  89041. raw_header[raw_header_len++] = (FLAC__byte)x;
  89042. if(blocksize_hint == 7) {
  89043. FLAC__uint32 _x;
  89044. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89045. return false; /* read_callback_ sets the state for us */
  89046. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89047. x = (x << 8) | _x;
  89048. }
  89049. decoder->private_->frame.header.blocksize = x+1;
  89050. }
  89051. if(sample_rate_hint) {
  89052. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89053. return false; /* read_callback_ sets the state for us */
  89054. raw_header[raw_header_len++] = (FLAC__byte)x;
  89055. if(sample_rate_hint != 12) {
  89056. FLAC__uint32 _x;
  89057. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89058. return false; /* read_callback_ sets the state for us */
  89059. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89060. x = (x << 8) | _x;
  89061. }
  89062. if(sample_rate_hint == 12)
  89063. decoder->private_->frame.header.sample_rate = x*1000;
  89064. else if(sample_rate_hint == 13)
  89065. decoder->private_->frame.header.sample_rate = x;
  89066. else
  89067. decoder->private_->frame.header.sample_rate = x*10;
  89068. }
  89069. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89070. return false; /* read_callback_ sets the state for us */
  89071. crc8 = (FLAC__byte)x;
  89072. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  89073. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89074. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89075. return true;
  89076. }
  89077. decoder->private_->next_fixed_block_size = 0;
  89078. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  89079. x = decoder->private_->frame.header.number.frame_number;
  89080. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89081. if(decoder->private_->fixed_block_size)
  89082. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  89083. else if(decoder->private_->has_stream_info) {
  89084. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  89085. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  89086. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89087. }
  89088. else
  89089. is_unparseable = true;
  89090. }
  89091. else if(x == 0) {
  89092. decoder->private_->frame.header.number.sample_number = 0;
  89093. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  89094. }
  89095. else {
  89096. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  89097. }
  89098. }
  89099. if(is_unparseable) {
  89100. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89101. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89102. return true;
  89103. }
  89104. return true;
  89105. }
  89106. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89107. {
  89108. FLAC__uint32 x;
  89109. FLAC__bool wasted_bits;
  89110. unsigned i;
  89111. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  89112. return false; /* read_callback_ sets the state for us */
  89113. wasted_bits = (x & 1);
  89114. x &= 0xfe;
  89115. if(wasted_bits) {
  89116. unsigned u;
  89117. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  89118. return false; /* read_callback_ sets the state for us */
  89119. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  89120. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  89121. }
  89122. else
  89123. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  89124. if(x & 0x80) {
  89125. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89126. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89127. return true;
  89128. }
  89129. else if(x == 0) {
  89130. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  89131. return false;
  89132. }
  89133. else if(x == 2) {
  89134. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  89135. return false;
  89136. }
  89137. else if(x < 16) {
  89138. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89139. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89140. return true;
  89141. }
  89142. else if(x <= 24) {
  89143. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  89144. return false;
  89145. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89146. return true;
  89147. }
  89148. else if(x < 64) {
  89149. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89150. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89151. return true;
  89152. }
  89153. else {
  89154. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  89155. return false;
  89156. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89157. return true;
  89158. }
  89159. if(wasted_bits && do_full_decode) {
  89160. x = decoder->private_->frame.subframes[channel].wasted_bits;
  89161. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89162. decoder->private_->output[channel][i] <<= x;
  89163. }
  89164. return true;
  89165. }
  89166. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89167. {
  89168. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  89169. FLAC__int32 x;
  89170. unsigned i;
  89171. FLAC__int32 *output = decoder->private_->output[channel];
  89172. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  89173. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89174. return false; /* read_callback_ sets the state for us */
  89175. subframe->value = x;
  89176. if(do_full_decode) {
  89177. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89178. output[i] = x;
  89179. }
  89180. return true;
  89181. }
  89182. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89183. {
  89184. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  89185. FLAC__int32 i32;
  89186. FLAC__uint32 u32;
  89187. unsigned u;
  89188. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  89189. subframe->residual = decoder->private_->residual[channel];
  89190. subframe->order = order;
  89191. for(u = 0; u < order; u++) {
  89192. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89193. return false; /* read_callback_ sets the state for us */
  89194. subframe->warmup[u] = i32;
  89195. }
  89196. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89197. return false; /* read_callback_ sets the state for us */
  89198. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89199. switch(subframe->entropy_coding_method.type) {
  89200. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89201. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89202. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89203. return false; /* read_callback_ sets the state for us */
  89204. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89205. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89206. break;
  89207. default:
  89208. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89209. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89210. return true;
  89211. }
  89212. switch(subframe->entropy_coding_method.type) {
  89213. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89214. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89215. 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))
  89216. return false;
  89217. break;
  89218. default:
  89219. FLAC__ASSERT(0);
  89220. }
  89221. if(do_full_decode) {
  89222. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89223. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  89224. }
  89225. return true;
  89226. }
  89227. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89228. {
  89229. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  89230. FLAC__int32 i32;
  89231. FLAC__uint32 u32;
  89232. unsigned u;
  89233. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  89234. subframe->residual = decoder->private_->residual[channel];
  89235. subframe->order = order;
  89236. for(u = 0; u < order; u++) {
  89237. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89238. return false; /* read_callback_ sets the state for us */
  89239. subframe->warmup[u] = i32;
  89240. }
  89241. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  89242. return false; /* read_callback_ sets the state for us */
  89243. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  89244. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89245. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89246. return true;
  89247. }
  89248. subframe->qlp_coeff_precision = u32+1;
  89249. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  89250. return false; /* read_callback_ sets the state for us */
  89251. subframe->quantization_level = i32;
  89252. for(u = 0; u < order; u++) {
  89253. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  89254. return false; /* read_callback_ sets the state for us */
  89255. subframe->qlp_coeff[u] = i32;
  89256. }
  89257. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89258. return false; /* read_callback_ sets the state for us */
  89259. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89260. switch(subframe->entropy_coding_method.type) {
  89261. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89262. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89263. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89264. return false; /* read_callback_ sets the state for us */
  89265. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89266. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89267. break;
  89268. default:
  89269. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89270. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89271. return true;
  89272. }
  89273. switch(subframe->entropy_coding_method.type) {
  89274. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89275. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89276. 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))
  89277. return false;
  89278. break;
  89279. default:
  89280. FLAC__ASSERT(0);
  89281. }
  89282. if(do_full_decode) {
  89283. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89284. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89285. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89286. if(order <= 8)
  89287. 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);
  89288. else
  89289. 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);
  89290. }
  89291. else
  89292. 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);
  89293. else
  89294. 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);
  89295. }
  89296. return true;
  89297. }
  89298. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89299. {
  89300. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89301. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89302. unsigned i;
  89303. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89304. subframe->data = residual;
  89305. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89306. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89307. return false; /* read_callback_ sets the state for us */
  89308. residual[i] = x;
  89309. }
  89310. if(do_full_decode)
  89311. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89312. return true;
  89313. }
  89314. 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)
  89315. {
  89316. FLAC__uint32 rice_parameter;
  89317. int i;
  89318. unsigned partition, sample, u;
  89319. const unsigned partitions = 1u << partition_order;
  89320. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89321. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89322. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89323. if(partition_order == 0) {
  89324. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89325. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89326. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89327. return true;
  89328. }
  89329. }
  89330. else {
  89331. if(partition_samples < predictor_order) {
  89332. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89333. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89334. return true;
  89335. }
  89336. }
  89337. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89338. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89339. return false;
  89340. }
  89341. sample = 0;
  89342. for(partition = 0; partition < partitions; partition++) {
  89343. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89344. return false; /* read_callback_ sets the state for us */
  89345. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89346. if(rice_parameter < pesc) {
  89347. partitioned_rice_contents->raw_bits[partition] = 0;
  89348. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89349. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89350. return false; /* read_callback_ sets the state for us */
  89351. sample += u;
  89352. }
  89353. else {
  89354. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89355. return false; /* read_callback_ sets the state for us */
  89356. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89357. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89358. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89359. return false; /* read_callback_ sets the state for us */
  89360. residual[sample] = i;
  89361. }
  89362. }
  89363. }
  89364. return true;
  89365. }
  89366. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89367. {
  89368. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89369. FLAC__uint32 zero = 0;
  89370. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89371. return false; /* read_callback_ sets the state for us */
  89372. if(zero != 0) {
  89373. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89374. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89375. }
  89376. }
  89377. return true;
  89378. }
  89379. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89380. {
  89381. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89382. if(
  89383. #if FLAC__HAS_OGG
  89384. !decoder->private_->is_ogg &&
  89385. #endif
  89386. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89387. ) {
  89388. *bytes = 0;
  89389. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89390. return false;
  89391. }
  89392. else if(*bytes > 0) {
  89393. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89394. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89395. return false;
  89396. }
  89397. else {
  89398. const FLAC__StreamDecoderReadStatus status =
  89399. #if FLAC__HAS_OGG
  89400. decoder->private_->is_ogg?
  89401. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89402. #endif
  89403. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89404. ;
  89405. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89406. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89407. return false;
  89408. }
  89409. else if(*bytes == 0) {
  89410. if(
  89411. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89412. (
  89413. #if FLAC__HAS_OGG
  89414. !decoder->private_->is_ogg &&
  89415. #endif
  89416. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89417. )
  89418. ) {
  89419. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89420. return false;
  89421. }
  89422. else
  89423. return true;
  89424. }
  89425. else
  89426. return true;
  89427. }
  89428. }
  89429. else {
  89430. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89431. return false;
  89432. }
  89433. }
  89434. #if FLAC__HAS_OGG
  89435. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89436. {
  89437. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89438. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89439. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89440. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89441. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89442. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89443. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89444. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89445. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89446. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89447. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89448. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89449. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89450. default:
  89451. FLAC__ASSERT(0);
  89452. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89453. }
  89454. }
  89455. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89456. {
  89457. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89458. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89459. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89460. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89461. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89462. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89463. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89464. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89465. default:
  89466. FLAC__ASSERT(0);
  89467. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89468. }
  89469. }
  89470. #endif
  89471. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89472. {
  89473. if(decoder->private_->is_seeking) {
  89474. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89475. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89476. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89477. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89478. #if FLAC__HAS_OGG
  89479. decoder->private_->got_a_frame = true;
  89480. #endif
  89481. decoder->private_->last_frame = *frame; /* save the frame */
  89482. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89483. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89484. decoder->private_->is_seeking = false;
  89485. if(delta > 0) {
  89486. unsigned channel;
  89487. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89488. for(channel = 0; channel < frame->header.channels; channel++)
  89489. newbuffer[channel] = buffer[channel] + delta;
  89490. decoder->private_->last_frame.header.blocksize -= delta;
  89491. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89492. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89493. }
  89494. else {
  89495. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89496. }
  89497. }
  89498. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89499. }
  89500. if(!decoder->private_->has_stream_info)
  89501. decoder->private_->do_md5_checking = false;
  89502. if(decoder->private_->do_md5_checking) {
  89503. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89504. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89505. }
  89506. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89507. }
  89508. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89509. {
  89510. if(!decoder->private_->is_seeking)
  89511. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89512. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89513. decoder->private_->unparseable_frame_count++;
  89514. }
  89515. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89516. {
  89517. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89518. FLAC__int64 pos = -1;
  89519. int i;
  89520. unsigned approx_bytes_per_frame;
  89521. FLAC__bool first_seek = true;
  89522. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89523. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89524. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89525. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89526. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89527. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89528. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89529. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89530. if(channels == 0)
  89531. channels = decoder->private_->stream_info.data.stream_info.channels;
  89532. if(bps == 0)
  89533. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89534. if(max_framesize > 0)
  89535. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89536. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89537. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89538. }
  89539. else
  89540. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89541. lower_bound = first_frame_offset;
  89542. lower_bound_sample = 0;
  89543. upper_bound = stream_length;
  89544. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89545. if(seek_table) {
  89546. FLAC__uint64 new_lower_bound = lower_bound;
  89547. FLAC__uint64 new_upper_bound = upper_bound;
  89548. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89549. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89550. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89551. if(
  89552. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89553. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89554. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89555. seek_table->points[i].sample_number <= target_sample
  89556. )
  89557. break;
  89558. }
  89559. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89560. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89561. new_lower_bound_sample = seek_table->points[i].sample_number;
  89562. }
  89563. for(i = 0; i < (int)seek_table->num_points; i++) {
  89564. if(
  89565. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89566. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89567. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89568. seek_table->points[i].sample_number > target_sample
  89569. )
  89570. break;
  89571. }
  89572. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89573. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89574. new_upper_bound_sample = seek_table->points[i].sample_number;
  89575. }
  89576. if(new_upper_bound >= new_lower_bound) {
  89577. lower_bound = new_lower_bound;
  89578. upper_bound = new_upper_bound;
  89579. lower_bound_sample = new_lower_bound_sample;
  89580. upper_bound_sample = new_upper_bound_sample;
  89581. }
  89582. }
  89583. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89584. if(upper_bound_sample == lower_bound_sample)
  89585. upper_bound_sample++;
  89586. decoder->private_->target_sample = target_sample;
  89587. while(1) {
  89588. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89589. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89590. return false;
  89591. }
  89592. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89593. #if defined _MSC_VER || defined __MINGW32__
  89594. 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;
  89595. #else
  89596. 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;
  89597. #endif
  89598. #else
  89599. if(upper_bound - lower_bound < 0xffffffff)
  89600. 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;
  89601. else /* @@@ WATCHOUT, ~2TB limit */
  89602. 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;
  89603. #endif
  89604. if(pos >= (FLAC__int64)upper_bound)
  89605. pos = (FLAC__int64)upper_bound - 1;
  89606. if(pos < (FLAC__int64)lower_bound)
  89607. pos = (FLAC__int64)lower_bound;
  89608. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89609. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89610. return false;
  89611. }
  89612. if(!FLAC__stream_decoder_flush(decoder)) {
  89613. return false;
  89614. }
  89615. decoder->private_->unparseable_frame_count = 0;
  89616. if(!FLAC__stream_decoder_process_single(decoder)) {
  89617. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89618. return false;
  89619. }
  89620. #if 0
  89621. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89622. break;
  89623. #endif
  89624. if(!decoder->private_->is_seeking)
  89625. break;
  89626. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89627. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89628. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89629. if (pos == (FLAC__int64)lower_bound) {
  89630. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89631. return false;
  89632. }
  89633. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89634. continue;
  89635. }
  89636. first_seek = false;
  89637. if (this_frame_sample < lower_bound_sample) {
  89638. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89639. return false;
  89640. }
  89641. if(target_sample < this_frame_sample) {
  89642. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89643. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89644. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89645. return false;
  89646. }
  89647. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89648. }
  89649. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89650. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89651. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89652. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89653. return false;
  89654. }
  89655. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89656. }
  89657. }
  89658. return true;
  89659. }
  89660. #if FLAC__HAS_OGG
  89661. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89662. {
  89663. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89664. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89665. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89666. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89667. FLAC__bool did_a_seek;
  89668. unsigned iteration = 0;
  89669. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89670. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89671. if(right_sample == 0) {
  89672. right_sample = (FLAC__uint64)(-1);
  89673. BINARY_SEARCH_AFTER_ITERATION = 0;
  89674. }
  89675. decoder->private_->target_sample = target_sample;
  89676. for( ; ; iteration++) {
  89677. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89678. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89679. pos = (right_pos + left_pos) / 2;
  89680. }
  89681. else {
  89682. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89683. #if defined _MSC_VER || defined __MINGW32__
  89684. 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));
  89685. #else
  89686. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89687. #endif
  89688. #else
  89689. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89690. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89691. else /* @@@ WATCHOUT, ~2TB limit */
  89692. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89693. #endif
  89694. }
  89695. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89696. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89697. return false;
  89698. }
  89699. if(!FLAC__stream_decoder_flush(decoder)) {
  89700. return false;
  89701. }
  89702. did_a_seek = true;
  89703. }
  89704. else
  89705. did_a_seek = false;
  89706. decoder->private_->got_a_frame = false;
  89707. if(!FLAC__stream_decoder_process_single(decoder)) {
  89708. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89709. return false;
  89710. }
  89711. if(!decoder->private_->got_a_frame) {
  89712. if(did_a_seek) {
  89713. right_pos = pos;
  89714. BINARY_SEARCH_AFTER_ITERATION = 0;
  89715. }
  89716. else {
  89717. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89718. return false;
  89719. }
  89720. }
  89721. else if(!decoder->private_->is_seeking) {
  89722. break;
  89723. }
  89724. else {
  89725. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89726. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89727. if (did_a_seek) {
  89728. if (this_frame_sample <= target_sample) {
  89729. FLAC__ASSERT(this_frame_sample != target_sample);
  89730. left_sample = this_frame_sample;
  89731. if (left_pos == pos) {
  89732. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89733. return false;
  89734. }
  89735. left_pos = pos;
  89736. }
  89737. else if(this_frame_sample > target_sample) {
  89738. right_sample = this_frame_sample;
  89739. if (right_pos == pos) {
  89740. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89741. return false;
  89742. }
  89743. right_pos = pos;
  89744. }
  89745. }
  89746. }
  89747. }
  89748. return true;
  89749. }
  89750. #endif
  89751. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89752. {
  89753. (void)client_data;
  89754. if(*bytes > 0) {
  89755. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89756. if(ferror(decoder->private_->file))
  89757. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89758. else if(*bytes == 0)
  89759. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89760. else
  89761. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89762. }
  89763. else
  89764. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89765. }
  89766. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89767. {
  89768. (void)client_data;
  89769. if(decoder->private_->file == stdin)
  89770. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89771. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89772. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89773. else
  89774. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89775. }
  89776. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89777. {
  89778. off_t pos;
  89779. (void)client_data;
  89780. if(decoder->private_->file == stdin)
  89781. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89782. else if((pos = ftello(decoder->private_->file)) < 0)
  89783. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89784. else {
  89785. *absolute_byte_offset = (FLAC__uint64)pos;
  89786. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89787. }
  89788. }
  89789. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89790. {
  89791. struct stat filestats;
  89792. (void)client_data;
  89793. if(decoder->private_->file == stdin)
  89794. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89795. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89796. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89797. else {
  89798. *stream_length = (FLAC__uint64)filestats.st_size;
  89799. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89800. }
  89801. }
  89802. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89803. {
  89804. (void)client_data;
  89805. return feof(decoder->private_->file)? true : false;
  89806. }
  89807. #endif
  89808. /*** End of inlined file: stream_decoder.c ***/
  89809. /*** Start of inlined file: stream_encoder.c ***/
  89810. /*** Start of inlined file: juce_FlacHeader.h ***/
  89811. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89812. // tasks..
  89813. #define VERSION "1.2.1"
  89814. #define FLAC__NO_DLL 1
  89815. #if JUCE_MSVC
  89816. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89817. #endif
  89818. #if JUCE_MAC
  89819. #define FLAC__SYS_DARWIN 1
  89820. #endif
  89821. /*** End of inlined file: juce_FlacHeader.h ***/
  89822. #if JUCE_USE_FLAC
  89823. #if HAVE_CONFIG_H
  89824. # include <config.h>
  89825. #endif
  89826. #if defined _MSC_VER || defined __MINGW32__
  89827. #include <io.h> /* for _setmode() */
  89828. #include <fcntl.h> /* for _O_BINARY */
  89829. #endif
  89830. #if defined __CYGWIN__ || defined __EMX__
  89831. #include <io.h> /* for setmode(), O_BINARY */
  89832. #include <fcntl.h> /* for _O_BINARY */
  89833. #endif
  89834. #include <limits.h>
  89835. #include <stdio.h>
  89836. #include <stdlib.h> /* for malloc() */
  89837. #include <string.h> /* for memcpy() */
  89838. #include <sys/types.h> /* for off_t */
  89839. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89840. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89841. #define fseeko fseek
  89842. #define ftello ftell
  89843. #endif
  89844. #endif
  89845. /*** Start of inlined file: stream_encoder.h ***/
  89846. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89847. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89848. #if FLAC__HAS_OGG
  89849. #include "private/ogg_encoder_aspect.h"
  89850. #endif
  89851. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89852. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89853. typedef enum {
  89854. FLAC__APODIZATION_BARTLETT,
  89855. FLAC__APODIZATION_BARTLETT_HANN,
  89856. FLAC__APODIZATION_BLACKMAN,
  89857. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89858. FLAC__APODIZATION_CONNES,
  89859. FLAC__APODIZATION_FLATTOP,
  89860. FLAC__APODIZATION_GAUSS,
  89861. FLAC__APODIZATION_HAMMING,
  89862. FLAC__APODIZATION_HANN,
  89863. FLAC__APODIZATION_KAISER_BESSEL,
  89864. FLAC__APODIZATION_NUTTALL,
  89865. FLAC__APODIZATION_RECTANGLE,
  89866. FLAC__APODIZATION_TRIANGLE,
  89867. FLAC__APODIZATION_TUKEY,
  89868. FLAC__APODIZATION_WELCH
  89869. } FLAC__ApodizationFunction;
  89870. typedef struct {
  89871. FLAC__ApodizationFunction type;
  89872. union {
  89873. struct {
  89874. FLAC__real stddev;
  89875. } gauss;
  89876. struct {
  89877. FLAC__real p;
  89878. } tukey;
  89879. } parameters;
  89880. } FLAC__ApodizationSpecification;
  89881. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89882. typedef struct FLAC__StreamEncoderProtected {
  89883. FLAC__StreamEncoderState state;
  89884. FLAC__bool verify;
  89885. FLAC__bool streamable_subset;
  89886. FLAC__bool do_md5;
  89887. FLAC__bool do_mid_side_stereo;
  89888. FLAC__bool loose_mid_side_stereo;
  89889. unsigned channels;
  89890. unsigned bits_per_sample;
  89891. unsigned sample_rate;
  89892. unsigned blocksize;
  89893. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89894. unsigned num_apodizations;
  89895. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89896. #endif
  89897. unsigned max_lpc_order;
  89898. unsigned qlp_coeff_precision;
  89899. FLAC__bool do_qlp_coeff_prec_search;
  89900. FLAC__bool do_exhaustive_model_search;
  89901. FLAC__bool do_escape_coding;
  89902. unsigned min_residual_partition_order;
  89903. unsigned max_residual_partition_order;
  89904. unsigned rice_parameter_search_dist;
  89905. FLAC__uint64 total_samples_estimate;
  89906. FLAC__StreamMetadata **metadata;
  89907. unsigned num_metadata_blocks;
  89908. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89909. #if FLAC__HAS_OGG
  89910. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89911. #endif
  89912. } FLAC__StreamEncoderProtected;
  89913. #endif
  89914. /*** End of inlined file: stream_encoder.h ***/
  89915. #if FLAC__HAS_OGG
  89916. #include "include/private/ogg_helper.h"
  89917. #include "include/private/ogg_mapping.h"
  89918. #endif
  89919. /*** Start of inlined file: stream_encoder_framing.h ***/
  89920. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89921. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89922. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89923. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89924. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89925. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89926. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89927. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89928. #endif
  89929. /*** End of inlined file: stream_encoder_framing.h ***/
  89930. /*** Start of inlined file: window.h ***/
  89931. #ifndef FLAC__PRIVATE__WINDOW_H
  89932. #define FLAC__PRIVATE__WINDOW_H
  89933. #ifdef HAVE_CONFIG_H
  89934. #include <config.h>
  89935. #endif
  89936. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89937. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89938. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89939. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89940. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89941. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89942. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89943. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89944. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89945. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89946. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89947. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89948. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89949. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89950. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89951. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89952. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89953. #endif
  89954. /*** End of inlined file: window.h ***/
  89955. #ifndef FLaC__INLINE
  89956. #define FLaC__INLINE
  89957. #endif
  89958. #ifdef min
  89959. #undef min
  89960. #endif
  89961. #define min(x,y) ((x)<(y)?(x):(y))
  89962. #ifdef max
  89963. #undef max
  89964. #endif
  89965. #define max(x,y) ((x)>(y)?(x):(y))
  89966. #undef EXACT_RICE_BITS_CALCULATION
  89967. #undef ENABLE_RICE_PARAMETER_SEARCH
  89968. typedef struct {
  89969. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89970. unsigned size; /* of each data[] in samples */
  89971. unsigned tail;
  89972. } verify_input_fifo;
  89973. typedef struct {
  89974. const FLAC__byte *data;
  89975. unsigned capacity;
  89976. unsigned bytes;
  89977. } verify_output;
  89978. typedef enum {
  89979. ENCODER_IN_MAGIC = 0,
  89980. ENCODER_IN_METADATA = 1,
  89981. ENCODER_IN_AUDIO = 2
  89982. } EncoderStateHint;
  89983. static struct CompressionLevels {
  89984. FLAC__bool do_mid_side_stereo;
  89985. FLAC__bool loose_mid_side_stereo;
  89986. unsigned max_lpc_order;
  89987. unsigned qlp_coeff_precision;
  89988. FLAC__bool do_qlp_coeff_prec_search;
  89989. FLAC__bool do_escape_coding;
  89990. FLAC__bool do_exhaustive_model_search;
  89991. unsigned min_residual_partition_order;
  89992. unsigned max_residual_partition_order;
  89993. unsigned rice_parameter_search_dist;
  89994. } compression_levels_[] = {
  89995. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89996. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89997. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89998. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89999. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  90000. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  90001. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  90002. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  90003. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  90004. };
  90005. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  90006. static void free_(FLAC__StreamEncoder *encoder);
  90007. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  90008. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  90009. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  90010. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  90011. #if FLAC__HAS_OGG
  90012. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  90013. #endif
  90014. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  90015. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  90016. static FLAC__bool process_subframe_(
  90017. FLAC__StreamEncoder *encoder,
  90018. unsigned min_partition_order,
  90019. unsigned max_partition_order,
  90020. const FLAC__FrameHeader *frame_header,
  90021. unsigned subframe_bps,
  90022. const FLAC__int32 integer_signal[],
  90023. FLAC__Subframe *subframe[2],
  90024. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  90025. FLAC__int32 *residual[2],
  90026. unsigned *best_subframe,
  90027. unsigned *best_bits
  90028. );
  90029. static FLAC__bool add_subframe_(
  90030. FLAC__StreamEncoder *encoder,
  90031. unsigned blocksize,
  90032. unsigned subframe_bps,
  90033. const FLAC__Subframe *subframe,
  90034. FLAC__BitWriter *frame
  90035. );
  90036. static unsigned evaluate_constant_subframe_(
  90037. FLAC__StreamEncoder *encoder,
  90038. const FLAC__int32 signal,
  90039. unsigned blocksize,
  90040. unsigned subframe_bps,
  90041. FLAC__Subframe *subframe
  90042. );
  90043. static unsigned evaluate_fixed_subframe_(
  90044. FLAC__StreamEncoder *encoder,
  90045. const FLAC__int32 signal[],
  90046. FLAC__int32 residual[],
  90047. FLAC__uint64 abs_residual_partition_sums[],
  90048. unsigned raw_bits_per_partition[],
  90049. unsigned blocksize,
  90050. unsigned subframe_bps,
  90051. unsigned order,
  90052. unsigned rice_parameter,
  90053. unsigned rice_parameter_limit,
  90054. unsigned min_partition_order,
  90055. unsigned max_partition_order,
  90056. FLAC__bool do_escape_coding,
  90057. unsigned rice_parameter_search_dist,
  90058. FLAC__Subframe *subframe,
  90059. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90060. );
  90061. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90062. static unsigned evaluate_lpc_subframe_(
  90063. FLAC__StreamEncoder *encoder,
  90064. const FLAC__int32 signal[],
  90065. FLAC__int32 residual[],
  90066. FLAC__uint64 abs_residual_partition_sums[],
  90067. unsigned raw_bits_per_partition[],
  90068. const FLAC__real lp_coeff[],
  90069. unsigned blocksize,
  90070. unsigned subframe_bps,
  90071. unsigned order,
  90072. unsigned qlp_coeff_precision,
  90073. unsigned rice_parameter,
  90074. unsigned rice_parameter_limit,
  90075. unsigned min_partition_order,
  90076. unsigned max_partition_order,
  90077. FLAC__bool do_escape_coding,
  90078. unsigned rice_parameter_search_dist,
  90079. FLAC__Subframe *subframe,
  90080. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90081. );
  90082. #endif
  90083. static unsigned evaluate_verbatim_subframe_(
  90084. FLAC__StreamEncoder *encoder,
  90085. const FLAC__int32 signal[],
  90086. unsigned blocksize,
  90087. unsigned subframe_bps,
  90088. FLAC__Subframe *subframe
  90089. );
  90090. static unsigned find_best_partition_order_(
  90091. struct FLAC__StreamEncoderPrivate *private_,
  90092. const FLAC__int32 residual[],
  90093. FLAC__uint64 abs_residual_partition_sums[],
  90094. unsigned raw_bits_per_partition[],
  90095. unsigned residual_samples,
  90096. unsigned predictor_order,
  90097. unsigned rice_parameter,
  90098. unsigned rice_parameter_limit,
  90099. unsigned min_partition_order,
  90100. unsigned max_partition_order,
  90101. unsigned bps,
  90102. FLAC__bool do_escape_coding,
  90103. unsigned rice_parameter_search_dist,
  90104. FLAC__EntropyCodingMethod *best_ecm
  90105. );
  90106. static void precompute_partition_info_sums_(
  90107. const FLAC__int32 residual[],
  90108. FLAC__uint64 abs_residual_partition_sums[],
  90109. unsigned residual_samples,
  90110. unsigned predictor_order,
  90111. unsigned min_partition_order,
  90112. unsigned max_partition_order,
  90113. unsigned bps
  90114. );
  90115. static void precompute_partition_info_escapes_(
  90116. const FLAC__int32 residual[],
  90117. unsigned raw_bits_per_partition[],
  90118. unsigned residual_samples,
  90119. unsigned predictor_order,
  90120. unsigned min_partition_order,
  90121. unsigned max_partition_order
  90122. );
  90123. static FLAC__bool set_partitioned_rice_(
  90124. #ifdef EXACT_RICE_BITS_CALCULATION
  90125. const FLAC__int32 residual[],
  90126. #endif
  90127. const FLAC__uint64 abs_residual_partition_sums[],
  90128. const unsigned raw_bits_per_partition[],
  90129. const unsigned residual_samples,
  90130. const unsigned predictor_order,
  90131. const unsigned suggested_rice_parameter,
  90132. const unsigned rice_parameter_limit,
  90133. const unsigned rice_parameter_search_dist,
  90134. const unsigned partition_order,
  90135. const FLAC__bool search_for_escapes,
  90136. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  90137. unsigned *bits
  90138. );
  90139. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  90140. static void append_to_verify_fifo_(
  90141. verify_input_fifo *fifo,
  90142. const FLAC__int32 * const input[],
  90143. unsigned input_offset,
  90144. unsigned channels,
  90145. unsigned wide_samples
  90146. );
  90147. static void append_to_verify_fifo_interleaved_(
  90148. verify_input_fifo *fifo,
  90149. const FLAC__int32 input[],
  90150. unsigned input_offset,
  90151. unsigned channels,
  90152. unsigned wide_samples
  90153. );
  90154. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90155. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  90156. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  90157. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  90158. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90159. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  90160. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  90161. 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);
  90162. static FILE *get_binary_stdout_(void);
  90163. typedef struct FLAC__StreamEncoderPrivate {
  90164. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  90165. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  90166. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  90167. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90168. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  90169. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  90170. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  90171. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  90172. #endif
  90173. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  90174. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  90175. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  90176. FLAC__int32 *residual_workspace_mid_side[2][2];
  90177. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  90178. FLAC__Subframe subframe_workspace_mid_side[2][2];
  90179. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90180. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  90181. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  90182. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  90183. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90184. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  90185. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  90186. unsigned best_subframe_mid_side[2];
  90187. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  90188. unsigned best_subframe_bits_mid_side[2];
  90189. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  90190. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  90191. FLAC__BitWriter *frame; /* the current frame being worked on */
  90192. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  90193. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  90194. FLAC__ChannelAssignment last_channel_assignment;
  90195. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  90196. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  90197. unsigned current_sample_number;
  90198. unsigned current_frame_number;
  90199. FLAC__MD5Context md5context;
  90200. FLAC__CPUInfo cpuinfo;
  90201. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90202. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90203. #else
  90204. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90205. #endif
  90206. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90207. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  90208. 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[]);
  90209. 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[]);
  90210. 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[]);
  90211. #endif
  90212. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  90213. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  90214. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  90215. FLAC__bool disable_constant_subframes;
  90216. FLAC__bool disable_fixed_subframes;
  90217. FLAC__bool disable_verbatim_subframes;
  90218. #if FLAC__HAS_OGG
  90219. FLAC__bool is_ogg;
  90220. #endif
  90221. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  90222. FLAC__StreamEncoderSeekCallback seek_callback;
  90223. FLAC__StreamEncoderTellCallback tell_callback;
  90224. FLAC__StreamEncoderWriteCallback write_callback;
  90225. FLAC__StreamEncoderMetadataCallback metadata_callback;
  90226. FLAC__StreamEncoderProgressCallback progress_callback;
  90227. void *client_data;
  90228. unsigned first_seekpoint_to_check;
  90229. FILE *file; /* only used when encoding to a file */
  90230. FLAC__uint64 bytes_written;
  90231. FLAC__uint64 samples_written;
  90232. unsigned frames_written;
  90233. unsigned total_frames_estimate;
  90234. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  90235. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  90236. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90237. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  90238. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  90239. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  90240. FLAC__real *windowed_signal_unaligned;
  90241. #endif
  90242. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  90243. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  90244. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  90245. unsigned *raw_bits_per_partition_unaligned;
  90246. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90247. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  90248. #endif
  90249. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  90250. struct {
  90251. FLAC__StreamDecoder *decoder;
  90252. EncoderStateHint state_hint;
  90253. FLAC__bool needs_magic_hack;
  90254. verify_input_fifo input_fifo;
  90255. verify_output output;
  90256. struct {
  90257. FLAC__uint64 absolute_sample;
  90258. unsigned frame_number;
  90259. unsigned channel;
  90260. unsigned sample;
  90261. FLAC__int32 expected;
  90262. FLAC__int32 got;
  90263. } error_stats;
  90264. } verify;
  90265. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  90266. } FLAC__StreamEncoderPrivate;
  90267. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  90268. "FLAC__STREAM_ENCODER_OK",
  90269. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  90270. "FLAC__STREAM_ENCODER_OGG_ERROR",
  90271. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  90272. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  90273. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  90274. "FLAC__STREAM_ENCODER_IO_ERROR",
  90275. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  90276. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  90277. };
  90278. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  90279. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  90280. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  90281. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  90282. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  90283. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  90284. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90285. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90286. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90287. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90288. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90289. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90290. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90291. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90292. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90293. };
  90294. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90295. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90296. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90297. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90298. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90299. };
  90300. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90301. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90302. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90303. };
  90304. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90305. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90306. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90307. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90308. };
  90309. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90310. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90311. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90312. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90313. };
  90314. static const unsigned OVERREAD_ = 1;
  90315. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90316. {
  90317. FLAC__StreamEncoder *encoder;
  90318. unsigned i;
  90319. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90320. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90321. if(encoder == 0) {
  90322. return 0;
  90323. }
  90324. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90325. if(encoder->protected_ == 0) {
  90326. free(encoder);
  90327. return 0;
  90328. }
  90329. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90330. if(encoder->private_ == 0) {
  90331. free(encoder->protected_);
  90332. free(encoder);
  90333. return 0;
  90334. }
  90335. encoder->private_->frame = FLAC__bitwriter_new();
  90336. if(encoder->private_->frame == 0) {
  90337. free(encoder->private_);
  90338. free(encoder->protected_);
  90339. free(encoder);
  90340. return 0;
  90341. }
  90342. encoder->private_->file = 0;
  90343. set_defaults_enc(encoder);
  90344. encoder->private_->is_being_deleted = false;
  90345. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90346. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90347. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90348. }
  90349. for(i = 0; i < 2; i++) {
  90350. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90351. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90352. }
  90353. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90354. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90355. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90356. }
  90357. for(i = 0; i < 2; i++) {
  90358. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90359. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90360. }
  90361. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90362. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90363. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90364. }
  90365. for(i = 0; i < 2; i++) {
  90366. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90367. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90368. }
  90369. for(i = 0; i < 2; i++)
  90370. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90371. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90372. return encoder;
  90373. }
  90374. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90375. {
  90376. unsigned i;
  90377. FLAC__ASSERT(0 != encoder);
  90378. FLAC__ASSERT(0 != encoder->protected_);
  90379. FLAC__ASSERT(0 != encoder->private_);
  90380. FLAC__ASSERT(0 != encoder->private_->frame);
  90381. encoder->private_->is_being_deleted = true;
  90382. (void)FLAC__stream_encoder_finish(encoder);
  90383. if(0 != encoder->private_->verify.decoder)
  90384. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90385. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90386. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90387. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90388. }
  90389. for(i = 0; i < 2; i++) {
  90390. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90391. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90392. }
  90393. for(i = 0; i < 2; i++)
  90394. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90395. FLAC__bitwriter_delete(encoder->private_->frame);
  90396. free(encoder->private_);
  90397. free(encoder->protected_);
  90398. free(encoder);
  90399. }
  90400. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90401. FLAC__StreamEncoder *encoder,
  90402. FLAC__StreamEncoderReadCallback read_callback,
  90403. FLAC__StreamEncoderWriteCallback write_callback,
  90404. FLAC__StreamEncoderSeekCallback seek_callback,
  90405. FLAC__StreamEncoderTellCallback tell_callback,
  90406. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90407. void *client_data,
  90408. FLAC__bool is_ogg
  90409. )
  90410. {
  90411. unsigned i;
  90412. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90413. FLAC__ASSERT(0 != encoder);
  90414. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90415. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90416. #if !FLAC__HAS_OGG
  90417. if(is_ogg)
  90418. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90419. #endif
  90420. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90421. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90422. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90423. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90424. if(encoder->protected_->channels != 2) {
  90425. encoder->protected_->do_mid_side_stereo = false;
  90426. encoder->protected_->loose_mid_side_stereo = false;
  90427. }
  90428. else if(!encoder->protected_->do_mid_side_stereo)
  90429. encoder->protected_->loose_mid_side_stereo = false;
  90430. if(encoder->protected_->bits_per_sample >= 32)
  90431. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90432. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90433. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90434. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90435. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90436. if(encoder->protected_->blocksize == 0) {
  90437. if(encoder->protected_->max_lpc_order == 0)
  90438. encoder->protected_->blocksize = 1152;
  90439. else
  90440. encoder->protected_->blocksize = 4096;
  90441. }
  90442. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90443. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90444. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90445. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90446. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90447. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90448. if(encoder->protected_->qlp_coeff_precision == 0) {
  90449. if(encoder->protected_->bits_per_sample < 16) {
  90450. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90451. }
  90452. else if(encoder->protected_->bits_per_sample == 16) {
  90453. if(encoder->protected_->blocksize <= 192)
  90454. encoder->protected_->qlp_coeff_precision = 7;
  90455. else if(encoder->protected_->blocksize <= 384)
  90456. encoder->protected_->qlp_coeff_precision = 8;
  90457. else if(encoder->protected_->blocksize <= 576)
  90458. encoder->protected_->qlp_coeff_precision = 9;
  90459. else if(encoder->protected_->blocksize <= 1152)
  90460. encoder->protected_->qlp_coeff_precision = 10;
  90461. else if(encoder->protected_->blocksize <= 2304)
  90462. encoder->protected_->qlp_coeff_precision = 11;
  90463. else if(encoder->protected_->blocksize <= 4608)
  90464. encoder->protected_->qlp_coeff_precision = 12;
  90465. else
  90466. encoder->protected_->qlp_coeff_precision = 13;
  90467. }
  90468. else {
  90469. if(encoder->protected_->blocksize <= 384)
  90470. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90471. else if(encoder->protected_->blocksize <= 1152)
  90472. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90473. else
  90474. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90475. }
  90476. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90477. }
  90478. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90479. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90480. if(encoder->protected_->streamable_subset) {
  90481. if(
  90482. encoder->protected_->blocksize != 192 &&
  90483. encoder->protected_->blocksize != 576 &&
  90484. encoder->protected_->blocksize != 1152 &&
  90485. encoder->protected_->blocksize != 2304 &&
  90486. encoder->protected_->blocksize != 4608 &&
  90487. encoder->protected_->blocksize != 256 &&
  90488. encoder->protected_->blocksize != 512 &&
  90489. encoder->protected_->blocksize != 1024 &&
  90490. encoder->protected_->blocksize != 2048 &&
  90491. encoder->protected_->blocksize != 4096 &&
  90492. encoder->protected_->blocksize != 8192 &&
  90493. encoder->protected_->blocksize != 16384
  90494. )
  90495. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90496. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90497. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90498. if(
  90499. encoder->protected_->bits_per_sample != 8 &&
  90500. encoder->protected_->bits_per_sample != 12 &&
  90501. encoder->protected_->bits_per_sample != 16 &&
  90502. encoder->protected_->bits_per_sample != 20 &&
  90503. encoder->protected_->bits_per_sample != 24
  90504. )
  90505. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90506. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90507. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90508. if(
  90509. encoder->protected_->sample_rate <= 48000 &&
  90510. (
  90511. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90512. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90513. )
  90514. ) {
  90515. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90516. }
  90517. }
  90518. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90519. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90520. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90521. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90522. #if FLAC__HAS_OGG
  90523. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90524. unsigned i;
  90525. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90526. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90527. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90528. for( ; i > 0; i--)
  90529. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90530. encoder->protected_->metadata[0] = vc;
  90531. break;
  90532. }
  90533. }
  90534. }
  90535. #endif
  90536. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90537. unsigned i;
  90538. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90539. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90540. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90541. break; /* take only the first one */
  90542. }
  90543. }
  90544. }
  90545. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90546. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90547. metadata_has_seektable = false;
  90548. metadata_has_vorbis_comment = false;
  90549. metadata_picture_has_type1 = false;
  90550. metadata_picture_has_type2 = false;
  90551. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90552. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90553. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90554. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90555. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90556. if(metadata_has_seektable) /* only one is allowed */
  90557. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90558. metadata_has_seektable = true;
  90559. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90560. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90561. }
  90562. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90563. if(metadata_has_vorbis_comment) /* only one is allowed */
  90564. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90565. metadata_has_vorbis_comment = true;
  90566. }
  90567. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90568. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90569. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90570. }
  90571. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90572. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90573. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90574. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90575. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90576. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90577. metadata_picture_has_type1 = true;
  90578. if(
  90579. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90580. (
  90581. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90582. m->data.picture.width != 32 ||
  90583. m->data.picture.height != 32
  90584. )
  90585. )
  90586. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90587. }
  90588. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90589. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90590. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90591. metadata_picture_has_type2 = true;
  90592. }
  90593. }
  90594. }
  90595. encoder->private_->input_capacity = 0;
  90596. for(i = 0; i < encoder->protected_->channels; i++) {
  90597. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90598. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90599. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90600. #endif
  90601. }
  90602. for(i = 0; i < 2; i++) {
  90603. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90604. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90605. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90606. #endif
  90607. }
  90608. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90609. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90610. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90611. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90612. #endif
  90613. for(i = 0; i < encoder->protected_->channels; i++) {
  90614. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90615. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90616. encoder->private_->best_subframe[i] = 0;
  90617. }
  90618. for(i = 0; i < 2; i++) {
  90619. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90620. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90621. encoder->private_->best_subframe_mid_side[i] = 0;
  90622. }
  90623. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90624. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90625. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90626. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90627. #else
  90628. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90629. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90630. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90631. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90632. 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);
  90633. #endif
  90634. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90635. encoder->private_->loose_mid_side_stereo_frames = 1;
  90636. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90637. encoder->private_->current_sample_number = 0;
  90638. encoder->private_->current_frame_number = 0;
  90639. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90640. 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? */
  90641. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90642. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90643. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90644. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90645. #endif
  90646. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90647. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90648. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90649. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90650. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90651. #endif
  90652. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90653. # ifndef FLAC__NO_ASM
  90654. if(encoder->private_->cpuinfo.use_asm) {
  90655. # ifdef FLAC__CPU_IA32
  90656. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90657. # ifdef FLAC__HAS_NASM
  90658. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90659. if(encoder->protected_->max_lpc_order < 4)
  90660. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90661. else if(encoder->protected_->max_lpc_order < 8)
  90662. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90663. else if(encoder->protected_->max_lpc_order < 12)
  90664. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90665. else
  90666. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90667. }
  90668. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90669. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90670. else
  90671. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90672. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90673. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90674. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90675. }
  90676. else {
  90677. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90678. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90679. }
  90680. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90681. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90682. # endif /* FLAC__HAS_NASM */
  90683. # endif /* FLAC__CPU_IA32 */
  90684. }
  90685. # endif /* !FLAC__NO_ASM */
  90686. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90687. if(encoder->private_->use_wide_by_block) {
  90688. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90689. }
  90690. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90691. #if FLAC__HAS_OGG
  90692. encoder->private_->is_ogg = is_ogg;
  90693. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90694. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90695. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90696. }
  90697. #endif
  90698. encoder->private_->read_callback = read_callback;
  90699. encoder->private_->write_callback = write_callback;
  90700. encoder->private_->seek_callback = seek_callback;
  90701. encoder->private_->tell_callback = tell_callback;
  90702. encoder->private_->metadata_callback = metadata_callback;
  90703. encoder->private_->client_data = client_data;
  90704. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90705. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90706. }
  90707. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90708. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90709. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90710. }
  90711. if(encoder->protected_->verify) {
  90712. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90713. for(i = 0; i < encoder->protected_->channels; i++) {
  90714. 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))) {
  90715. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90716. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90717. }
  90718. }
  90719. encoder->private_->verify.input_fifo.tail = 0;
  90720. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90721. if(0 == encoder->private_->verify.decoder) {
  90722. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90723. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90724. }
  90725. 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) {
  90726. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90727. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90728. }
  90729. }
  90730. encoder->private_->verify.error_stats.absolute_sample = 0;
  90731. encoder->private_->verify.error_stats.frame_number = 0;
  90732. encoder->private_->verify.error_stats.channel = 0;
  90733. encoder->private_->verify.error_stats.sample = 0;
  90734. encoder->private_->verify.error_stats.expected = 0;
  90735. encoder->private_->verify.error_stats.got = 0;
  90736. encoder->private_->first_seekpoint_to_check = 0;
  90737. encoder->private_->samples_written = 0;
  90738. encoder->protected_->streaminfo_offset = 0;
  90739. encoder->protected_->seektable_offset = 0;
  90740. encoder->protected_->audio_offset = 0;
  90741. if(encoder->protected_->verify)
  90742. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90743. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90744. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90745. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90746. }
  90747. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90748. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90749. }
  90750. if(encoder->protected_->verify)
  90751. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90752. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90753. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90754. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90755. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90756. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90757. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90758. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90759. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90760. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90761. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90762. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90763. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90764. if(encoder->protected_->do_md5)
  90765. FLAC__MD5Init(&encoder->private_->md5context);
  90766. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90767. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90768. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90769. }
  90770. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90771. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90772. }
  90773. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90774. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90775. if(!metadata_has_vorbis_comment) {
  90776. FLAC__StreamMetadata vorbis_comment;
  90777. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90778. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90779. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90780. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90781. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90782. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90783. vorbis_comment.data.vorbis_comment.comments = 0;
  90784. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90785. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90786. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90787. }
  90788. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90789. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90790. }
  90791. }
  90792. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90793. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90794. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], 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. 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 */
  90803. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90804. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90805. }
  90806. if(encoder->protected_->verify)
  90807. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90808. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90809. }
  90810. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90811. FLAC__StreamEncoder *encoder,
  90812. FLAC__StreamEncoderWriteCallback write_callback,
  90813. FLAC__StreamEncoderSeekCallback seek_callback,
  90814. FLAC__StreamEncoderTellCallback tell_callback,
  90815. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90816. void *client_data
  90817. )
  90818. {
  90819. return init_stream_internal_enc(
  90820. encoder,
  90821. 0,
  90822. write_callback,
  90823. seek_callback,
  90824. tell_callback,
  90825. metadata_callback,
  90826. client_data,
  90827. false
  90828. );
  90829. }
  90830. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90831. FLAC__StreamEncoder *encoder,
  90832. FLAC__StreamEncoderReadCallback read_callback,
  90833. FLAC__StreamEncoderWriteCallback write_callback,
  90834. FLAC__StreamEncoderSeekCallback seek_callback,
  90835. FLAC__StreamEncoderTellCallback tell_callback,
  90836. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90837. void *client_data
  90838. )
  90839. {
  90840. return init_stream_internal_enc(
  90841. encoder,
  90842. read_callback,
  90843. write_callback,
  90844. seek_callback,
  90845. tell_callback,
  90846. metadata_callback,
  90847. client_data,
  90848. true
  90849. );
  90850. }
  90851. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90852. FLAC__StreamEncoder *encoder,
  90853. FILE *file,
  90854. FLAC__StreamEncoderProgressCallback progress_callback,
  90855. void *client_data,
  90856. FLAC__bool is_ogg
  90857. )
  90858. {
  90859. FLAC__StreamEncoderInitStatus init_status;
  90860. FLAC__ASSERT(0 != encoder);
  90861. FLAC__ASSERT(0 != file);
  90862. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90863. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90864. if(file == 0) {
  90865. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90866. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90867. }
  90868. if(file == stdout)
  90869. file = get_binary_stdout_(); /* just to be safe */
  90870. encoder->private_->file = file;
  90871. encoder->private_->progress_callback = progress_callback;
  90872. encoder->private_->bytes_written = 0;
  90873. encoder->private_->samples_written = 0;
  90874. encoder->private_->frames_written = 0;
  90875. init_status = init_stream_internal_enc(
  90876. encoder,
  90877. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90878. file_write_callback_,
  90879. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90880. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90881. 0,
  90882. client_data,
  90883. is_ogg
  90884. );
  90885. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90886. return init_status;
  90887. }
  90888. {
  90889. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90890. FLAC__ASSERT(blocksize != 0);
  90891. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90892. }
  90893. return init_status;
  90894. }
  90895. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90896. FLAC__StreamEncoder *encoder,
  90897. FILE *file,
  90898. FLAC__StreamEncoderProgressCallback progress_callback,
  90899. void *client_data
  90900. )
  90901. {
  90902. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90903. }
  90904. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90905. FLAC__StreamEncoder *encoder,
  90906. FILE *file,
  90907. FLAC__StreamEncoderProgressCallback progress_callback,
  90908. void *client_data
  90909. )
  90910. {
  90911. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90912. }
  90913. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90914. FLAC__StreamEncoder *encoder,
  90915. const char *filename,
  90916. FLAC__StreamEncoderProgressCallback progress_callback,
  90917. void *client_data,
  90918. FLAC__bool is_ogg
  90919. )
  90920. {
  90921. FILE *file;
  90922. FLAC__ASSERT(0 != encoder);
  90923. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90924. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90925. file = filename? fopen(filename, "w+b") : stdout;
  90926. if(file == 0) {
  90927. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90928. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90929. }
  90930. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90931. }
  90932. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90933. FLAC__StreamEncoder *encoder,
  90934. const char *filename,
  90935. FLAC__StreamEncoderProgressCallback progress_callback,
  90936. void *client_data
  90937. )
  90938. {
  90939. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90940. }
  90941. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90942. FLAC__StreamEncoder *encoder,
  90943. const char *filename,
  90944. FLAC__StreamEncoderProgressCallback progress_callback,
  90945. void *client_data
  90946. )
  90947. {
  90948. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90949. }
  90950. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90951. {
  90952. FLAC__bool error = false;
  90953. FLAC__ASSERT(0 != encoder);
  90954. FLAC__ASSERT(0 != encoder->private_);
  90955. FLAC__ASSERT(0 != encoder->protected_);
  90956. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90957. return true;
  90958. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90959. if(encoder->private_->current_sample_number != 0) {
  90960. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90961. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90962. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90963. error = true;
  90964. }
  90965. }
  90966. if(encoder->protected_->do_md5)
  90967. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90968. if(!encoder->private_->is_being_deleted) {
  90969. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90970. if(encoder->private_->seek_callback) {
  90971. #if FLAC__HAS_OGG
  90972. if(encoder->private_->is_ogg)
  90973. update_ogg_metadata_(encoder);
  90974. else
  90975. #endif
  90976. update_metadata_(encoder);
  90977. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90978. error = true;
  90979. }
  90980. if(encoder->private_->metadata_callback)
  90981. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90982. }
  90983. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90984. if(!error)
  90985. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90986. error = true;
  90987. }
  90988. }
  90989. if(0 != encoder->private_->file) {
  90990. if(encoder->private_->file != stdout)
  90991. fclose(encoder->private_->file);
  90992. encoder->private_->file = 0;
  90993. }
  90994. #if FLAC__HAS_OGG
  90995. if(encoder->private_->is_ogg)
  90996. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90997. #endif
  90998. free_(encoder);
  90999. set_defaults_enc(encoder);
  91000. if(!error)
  91001. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  91002. return !error;
  91003. }
  91004. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  91005. {
  91006. FLAC__ASSERT(0 != encoder);
  91007. FLAC__ASSERT(0 != encoder->private_);
  91008. FLAC__ASSERT(0 != encoder->protected_);
  91009. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91010. return false;
  91011. #if FLAC__HAS_OGG
  91012. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  91013. return true;
  91014. #else
  91015. (void)value;
  91016. return false;
  91017. #endif
  91018. }
  91019. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91020. {
  91021. FLAC__ASSERT(0 != encoder);
  91022. FLAC__ASSERT(0 != encoder->private_);
  91023. FLAC__ASSERT(0 != encoder->protected_);
  91024. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91025. return false;
  91026. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91027. encoder->protected_->verify = value;
  91028. #endif
  91029. return true;
  91030. }
  91031. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91032. {
  91033. FLAC__ASSERT(0 != encoder);
  91034. FLAC__ASSERT(0 != encoder->private_);
  91035. FLAC__ASSERT(0 != encoder->protected_);
  91036. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91037. return false;
  91038. encoder->protected_->streamable_subset = value;
  91039. return true;
  91040. }
  91041. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(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_->do_md5 = value;
  91049. return true;
  91050. }
  91051. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned 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_->channels = value;
  91059. return true;
  91060. }
  91061. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(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_->bits_per_sample = value;
  91069. return true;
  91070. }
  91071. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(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_->sample_rate = value;
  91079. return true;
  91080. }
  91081. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  91082. {
  91083. FLAC__bool ok = true;
  91084. FLAC__ASSERT(0 != encoder);
  91085. FLAC__ASSERT(0 != encoder->private_);
  91086. FLAC__ASSERT(0 != encoder->protected_);
  91087. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91088. return false;
  91089. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  91090. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  91091. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  91092. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  91093. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91094. #if 0
  91095. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  91096. #else
  91097. encoder->protected_->num_apodizations = 1;
  91098. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91099. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91100. #endif
  91101. #endif
  91102. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  91103. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  91104. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  91105. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  91106. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  91107. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  91108. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  91109. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  91110. return ok;
  91111. }
  91112. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  91113. {
  91114. FLAC__ASSERT(0 != encoder);
  91115. FLAC__ASSERT(0 != encoder->private_);
  91116. FLAC__ASSERT(0 != encoder->protected_);
  91117. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91118. return false;
  91119. encoder->protected_->blocksize = value;
  91120. return true;
  91121. }
  91122. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool 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_->do_mid_side_stereo = value;
  91130. return true;
  91131. }
  91132. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_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_->loose_mid_side_stereo = value;
  91140. return true;
  91141. }
  91142. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  91143. {
  91144. FLAC__ASSERT(0 != encoder);
  91145. FLAC__ASSERT(0 != encoder->private_);
  91146. FLAC__ASSERT(0 != encoder->protected_);
  91147. FLAC__ASSERT(0 != specification);
  91148. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91149. return false;
  91150. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  91151. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  91152. #else
  91153. encoder->protected_->num_apodizations = 0;
  91154. while(1) {
  91155. const char *s = strchr(specification, ';');
  91156. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  91157. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  91158. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  91159. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  91160. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  91161. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  91162. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  91163. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  91164. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  91165. else if(n==6 && 0 == strncmp("connes" , specification, n))
  91166. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  91167. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  91168. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  91169. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  91170. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  91171. if (stddev > 0.0 && stddev <= 0.5) {
  91172. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  91173. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  91174. }
  91175. }
  91176. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  91177. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  91178. else if(n==4 && 0 == strncmp("hann" , specification, n))
  91179. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  91180. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  91181. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  91182. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  91183. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  91184. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  91185. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  91186. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  91187. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  91188. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  91189. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  91190. if (p >= 0.0 && p <= 1.0) {
  91191. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  91192. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  91193. }
  91194. }
  91195. else if(n==5 && 0 == strncmp("welch" , specification, n))
  91196. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  91197. if (encoder->protected_->num_apodizations == 32)
  91198. break;
  91199. if (s)
  91200. specification = s+1;
  91201. else
  91202. break;
  91203. }
  91204. if(encoder->protected_->num_apodizations == 0) {
  91205. encoder->protected_->num_apodizations = 1;
  91206. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91207. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91208. }
  91209. #endif
  91210. return true;
  91211. }
  91212. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  91213. {
  91214. FLAC__ASSERT(0 != encoder);
  91215. FLAC__ASSERT(0 != encoder->private_);
  91216. FLAC__ASSERT(0 != encoder->protected_);
  91217. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91218. return false;
  91219. encoder->protected_->max_lpc_order = value;
  91220. return true;
  91221. }
  91222. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(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_->qlp_coeff_precision = value;
  91230. return true;
  91231. }
  91232. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool 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_->do_qlp_coeff_prec_search = value;
  91240. return true;
  91241. }
  91242. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(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. #if 0
  91250. encoder->protected_->do_escape_coding = value;
  91251. #else
  91252. (void)value;
  91253. #endif
  91254. return true;
  91255. }
  91256. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91257. {
  91258. FLAC__ASSERT(0 != encoder);
  91259. FLAC__ASSERT(0 != encoder->private_);
  91260. FLAC__ASSERT(0 != encoder->protected_);
  91261. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91262. return false;
  91263. encoder->protected_->do_exhaustive_model_search = value;
  91264. return true;
  91265. }
  91266. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned 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_->min_residual_partition_order = value;
  91274. return true;
  91275. }
  91276. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_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_->max_residual_partition_order = value;
  91284. return true;
  91285. }
  91286. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(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. #if 0
  91294. encoder->protected_->rice_parameter_search_dist = value;
  91295. #else
  91296. (void)value;
  91297. #endif
  91298. return true;
  91299. }
  91300. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91301. {
  91302. FLAC__ASSERT(0 != encoder);
  91303. FLAC__ASSERT(0 != encoder->private_);
  91304. FLAC__ASSERT(0 != encoder->protected_);
  91305. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91306. return false;
  91307. encoder->protected_->total_samples_estimate = value;
  91308. return true;
  91309. }
  91310. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  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. if(0 == metadata)
  91318. num_blocks = 0;
  91319. if(0 == num_blocks)
  91320. metadata = 0;
  91321. if(encoder->protected_->metadata) {
  91322. free(encoder->protected_->metadata);
  91323. encoder->protected_->metadata = 0;
  91324. encoder->protected_->num_metadata_blocks = 0;
  91325. }
  91326. if(num_blocks) {
  91327. FLAC__StreamMetadata **m;
  91328. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91329. return false;
  91330. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91331. encoder->protected_->metadata = m;
  91332. encoder->protected_->num_metadata_blocks = num_blocks;
  91333. }
  91334. #if FLAC__HAS_OGG
  91335. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91336. return false;
  91337. #endif
  91338. return true;
  91339. }
  91340. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91341. {
  91342. FLAC__ASSERT(0 != encoder);
  91343. FLAC__ASSERT(0 != encoder->private_);
  91344. FLAC__ASSERT(0 != encoder->protected_);
  91345. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91346. return false;
  91347. encoder->private_->disable_constant_subframes = value;
  91348. return true;
  91349. }
  91350. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_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_fixed_subframes = value;
  91358. return true;
  91359. }
  91360. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_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_verbatim_subframes = value;
  91368. return true;
  91369. }
  91370. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91371. {
  91372. FLAC__ASSERT(0 != encoder);
  91373. FLAC__ASSERT(0 != encoder->private_);
  91374. FLAC__ASSERT(0 != encoder->protected_);
  91375. return encoder->protected_->state;
  91376. }
  91377. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91378. {
  91379. FLAC__ASSERT(0 != encoder);
  91380. FLAC__ASSERT(0 != encoder->private_);
  91381. FLAC__ASSERT(0 != encoder->protected_);
  91382. if(encoder->protected_->verify)
  91383. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91384. else
  91385. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91386. }
  91387. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(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_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91393. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91394. else
  91395. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91396. }
  91397. 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)
  91398. {
  91399. FLAC__ASSERT(0 != encoder);
  91400. FLAC__ASSERT(0 != encoder->private_);
  91401. FLAC__ASSERT(0 != encoder->protected_);
  91402. if(0 != absolute_sample)
  91403. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91404. if(0 != frame_number)
  91405. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91406. if(0 != channel)
  91407. *channel = encoder->private_->verify.error_stats.channel;
  91408. if(0 != sample)
  91409. *sample = encoder->private_->verify.error_stats.sample;
  91410. if(0 != expected)
  91411. *expected = encoder->private_->verify.error_stats.expected;
  91412. if(0 != got)
  91413. *got = encoder->private_->verify.error_stats.got;
  91414. }
  91415. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91416. {
  91417. FLAC__ASSERT(0 != encoder);
  91418. FLAC__ASSERT(0 != encoder->private_);
  91419. FLAC__ASSERT(0 != encoder->protected_);
  91420. return encoder->protected_->verify;
  91421. }
  91422. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91423. {
  91424. FLAC__ASSERT(0 != encoder);
  91425. FLAC__ASSERT(0 != encoder->private_);
  91426. FLAC__ASSERT(0 != encoder->protected_);
  91427. return encoder->protected_->streamable_subset;
  91428. }
  91429. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91430. {
  91431. FLAC__ASSERT(0 != encoder);
  91432. FLAC__ASSERT(0 != encoder->private_);
  91433. FLAC__ASSERT(0 != encoder->protected_);
  91434. return encoder->protected_->do_md5;
  91435. }
  91436. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91437. {
  91438. FLAC__ASSERT(0 != encoder);
  91439. FLAC__ASSERT(0 != encoder->private_);
  91440. FLAC__ASSERT(0 != encoder->protected_);
  91441. return encoder->protected_->channels;
  91442. }
  91443. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91444. {
  91445. FLAC__ASSERT(0 != encoder);
  91446. FLAC__ASSERT(0 != encoder->private_);
  91447. FLAC__ASSERT(0 != encoder->protected_);
  91448. return encoder->protected_->bits_per_sample;
  91449. }
  91450. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91451. {
  91452. FLAC__ASSERT(0 != encoder);
  91453. FLAC__ASSERT(0 != encoder->private_);
  91454. FLAC__ASSERT(0 != encoder->protected_);
  91455. return encoder->protected_->sample_rate;
  91456. }
  91457. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91458. {
  91459. FLAC__ASSERT(0 != encoder);
  91460. FLAC__ASSERT(0 != encoder->private_);
  91461. FLAC__ASSERT(0 != encoder->protected_);
  91462. return encoder->protected_->blocksize;
  91463. }
  91464. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91465. {
  91466. FLAC__ASSERT(0 != encoder);
  91467. FLAC__ASSERT(0 != encoder->private_);
  91468. FLAC__ASSERT(0 != encoder->protected_);
  91469. return encoder->protected_->do_mid_side_stereo;
  91470. }
  91471. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91472. {
  91473. FLAC__ASSERT(0 != encoder);
  91474. FLAC__ASSERT(0 != encoder->private_);
  91475. FLAC__ASSERT(0 != encoder->protected_);
  91476. return encoder->protected_->loose_mid_side_stereo;
  91477. }
  91478. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91479. {
  91480. FLAC__ASSERT(0 != encoder);
  91481. FLAC__ASSERT(0 != encoder->private_);
  91482. FLAC__ASSERT(0 != encoder->protected_);
  91483. return encoder->protected_->max_lpc_order;
  91484. }
  91485. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91486. {
  91487. FLAC__ASSERT(0 != encoder);
  91488. FLAC__ASSERT(0 != encoder->private_);
  91489. FLAC__ASSERT(0 != encoder->protected_);
  91490. return encoder->protected_->qlp_coeff_precision;
  91491. }
  91492. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91493. {
  91494. FLAC__ASSERT(0 != encoder);
  91495. FLAC__ASSERT(0 != encoder->private_);
  91496. FLAC__ASSERT(0 != encoder->protected_);
  91497. return encoder->protected_->do_qlp_coeff_prec_search;
  91498. }
  91499. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91500. {
  91501. FLAC__ASSERT(0 != encoder);
  91502. FLAC__ASSERT(0 != encoder->private_);
  91503. FLAC__ASSERT(0 != encoder->protected_);
  91504. return encoder->protected_->do_escape_coding;
  91505. }
  91506. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91507. {
  91508. FLAC__ASSERT(0 != encoder);
  91509. FLAC__ASSERT(0 != encoder->private_);
  91510. FLAC__ASSERT(0 != encoder->protected_);
  91511. return encoder->protected_->do_exhaustive_model_search;
  91512. }
  91513. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91514. {
  91515. FLAC__ASSERT(0 != encoder);
  91516. FLAC__ASSERT(0 != encoder->private_);
  91517. FLAC__ASSERT(0 != encoder->protected_);
  91518. return encoder->protected_->min_residual_partition_order;
  91519. }
  91520. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91521. {
  91522. FLAC__ASSERT(0 != encoder);
  91523. FLAC__ASSERT(0 != encoder->private_);
  91524. FLAC__ASSERT(0 != encoder->protected_);
  91525. return encoder->protected_->max_residual_partition_order;
  91526. }
  91527. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91528. {
  91529. FLAC__ASSERT(0 != encoder);
  91530. FLAC__ASSERT(0 != encoder->private_);
  91531. FLAC__ASSERT(0 != encoder->protected_);
  91532. return encoder->protected_->rice_parameter_search_dist;
  91533. }
  91534. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91535. {
  91536. FLAC__ASSERT(0 != encoder);
  91537. FLAC__ASSERT(0 != encoder->private_);
  91538. FLAC__ASSERT(0 != encoder->protected_);
  91539. return encoder->protected_->total_samples_estimate;
  91540. }
  91541. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91542. {
  91543. unsigned i, j = 0, channel;
  91544. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91545. FLAC__ASSERT(0 != encoder);
  91546. FLAC__ASSERT(0 != encoder->private_);
  91547. FLAC__ASSERT(0 != encoder->protected_);
  91548. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91549. do {
  91550. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91551. if(encoder->protected_->verify)
  91552. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91553. for(channel = 0; channel < channels; channel++)
  91554. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91555. if(encoder->protected_->do_mid_side_stereo) {
  91556. FLAC__ASSERT(channels == 2);
  91557. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91558. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91559. 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' ! */
  91560. }
  91561. }
  91562. else
  91563. j += n;
  91564. encoder->private_->current_sample_number += n;
  91565. if(encoder->private_->current_sample_number > blocksize) {
  91566. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91567. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91568. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91569. return false;
  91570. for(channel = 0; channel < channels; channel++)
  91571. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91572. if(encoder->protected_->do_mid_side_stereo) {
  91573. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91574. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91575. }
  91576. encoder->private_->current_sample_number = 1;
  91577. }
  91578. } while(j < samples);
  91579. return true;
  91580. }
  91581. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91582. {
  91583. unsigned i, j, k, channel;
  91584. FLAC__int32 x, mid, side;
  91585. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91586. FLAC__ASSERT(0 != encoder);
  91587. FLAC__ASSERT(0 != encoder->private_);
  91588. FLAC__ASSERT(0 != encoder->protected_);
  91589. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91590. j = k = 0;
  91591. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91592. do {
  91593. if(encoder->protected_->verify)
  91594. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91595. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91596. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91597. x = buffer[k++];
  91598. encoder->private_->integer_signal[1][i] = x;
  91599. mid += x;
  91600. side -= x;
  91601. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91602. encoder->private_->integer_signal_mid_side[1][i] = side;
  91603. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91604. }
  91605. encoder->private_->current_sample_number = i;
  91606. if(i > blocksize) {
  91607. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91608. return false;
  91609. /* move unprocessed overread samples to beginnings of arrays */
  91610. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91611. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91612. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91613. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91614. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91615. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91616. encoder->private_->current_sample_number = 1;
  91617. }
  91618. } while(j < samples);
  91619. }
  91620. else {
  91621. do {
  91622. if(encoder->protected_->verify)
  91623. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91624. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91625. for(channel = 0; channel < channels; channel++)
  91626. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91627. }
  91628. encoder->private_->current_sample_number = i;
  91629. if(i > blocksize) {
  91630. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91631. return false;
  91632. /* move unprocessed overread samples to beginnings of arrays */
  91633. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91634. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91635. for(channel = 0; channel < channels; channel++)
  91636. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91637. encoder->private_->current_sample_number = 1;
  91638. }
  91639. } while(j < samples);
  91640. }
  91641. return true;
  91642. }
  91643. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91644. {
  91645. FLAC__ASSERT(0 != encoder);
  91646. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91647. encoder->protected_->verify = true;
  91648. #else
  91649. encoder->protected_->verify = false;
  91650. #endif
  91651. encoder->protected_->streamable_subset = true;
  91652. encoder->protected_->do_md5 = true;
  91653. encoder->protected_->do_mid_side_stereo = false;
  91654. encoder->protected_->loose_mid_side_stereo = false;
  91655. encoder->protected_->channels = 2;
  91656. encoder->protected_->bits_per_sample = 16;
  91657. encoder->protected_->sample_rate = 44100;
  91658. encoder->protected_->blocksize = 0;
  91659. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91660. encoder->protected_->num_apodizations = 1;
  91661. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91662. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91663. #endif
  91664. encoder->protected_->max_lpc_order = 0;
  91665. encoder->protected_->qlp_coeff_precision = 0;
  91666. encoder->protected_->do_qlp_coeff_prec_search = false;
  91667. encoder->protected_->do_exhaustive_model_search = false;
  91668. encoder->protected_->do_escape_coding = false;
  91669. encoder->protected_->min_residual_partition_order = 0;
  91670. encoder->protected_->max_residual_partition_order = 0;
  91671. encoder->protected_->rice_parameter_search_dist = 0;
  91672. encoder->protected_->total_samples_estimate = 0;
  91673. encoder->protected_->metadata = 0;
  91674. encoder->protected_->num_metadata_blocks = 0;
  91675. encoder->private_->seek_table = 0;
  91676. encoder->private_->disable_constant_subframes = false;
  91677. encoder->private_->disable_fixed_subframes = false;
  91678. encoder->private_->disable_verbatim_subframes = false;
  91679. #if FLAC__HAS_OGG
  91680. encoder->private_->is_ogg = false;
  91681. #endif
  91682. encoder->private_->read_callback = 0;
  91683. encoder->private_->write_callback = 0;
  91684. encoder->private_->seek_callback = 0;
  91685. encoder->private_->tell_callback = 0;
  91686. encoder->private_->metadata_callback = 0;
  91687. encoder->private_->progress_callback = 0;
  91688. encoder->private_->client_data = 0;
  91689. #if FLAC__HAS_OGG
  91690. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91691. #endif
  91692. }
  91693. void free_(FLAC__StreamEncoder *encoder)
  91694. {
  91695. unsigned i, channel;
  91696. FLAC__ASSERT(0 != encoder);
  91697. if(encoder->protected_->metadata) {
  91698. free(encoder->protected_->metadata);
  91699. encoder->protected_->metadata = 0;
  91700. encoder->protected_->num_metadata_blocks = 0;
  91701. }
  91702. for(i = 0; i < encoder->protected_->channels; i++) {
  91703. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91704. free(encoder->private_->integer_signal_unaligned[i]);
  91705. encoder->private_->integer_signal_unaligned[i] = 0;
  91706. }
  91707. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91708. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91709. free(encoder->private_->real_signal_unaligned[i]);
  91710. encoder->private_->real_signal_unaligned[i] = 0;
  91711. }
  91712. #endif
  91713. }
  91714. for(i = 0; i < 2; i++) {
  91715. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91716. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91717. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91718. }
  91719. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91720. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91721. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91722. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91723. }
  91724. #endif
  91725. }
  91726. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91727. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91728. if(0 != encoder->private_->window_unaligned[i]) {
  91729. free(encoder->private_->window_unaligned[i]);
  91730. encoder->private_->window_unaligned[i] = 0;
  91731. }
  91732. }
  91733. if(0 != encoder->private_->windowed_signal_unaligned) {
  91734. free(encoder->private_->windowed_signal_unaligned);
  91735. encoder->private_->windowed_signal_unaligned = 0;
  91736. }
  91737. #endif
  91738. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91739. for(i = 0; i < 2; i++) {
  91740. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91741. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91742. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91743. }
  91744. }
  91745. }
  91746. for(channel = 0; channel < 2; channel++) {
  91747. for(i = 0; i < 2; i++) {
  91748. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91749. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91750. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91751. }
  91752. }
  91753. }
  91754. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91755. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91756. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91757. }
  91758. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91759. free(encoder->private_->raw_bits_per_partition_unaligned);
  91760. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91761. }
  91762. if(encoder->protected_->verify) {
  91763. for(i = 0; i < encoder->protected_->channels; i++) {
  91764. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91765. free(encoder->private_->verify.input_fifo.data[i]);
  91766. encoder->private_->verify.input_fifo.data[i] = 0;
  91767. }
  91768. }
  91769. }
  91770. FLAC__bitwriter_free(encoder->private_->frame);
  91771. }
  91772. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91773. {
  91774. FLAC__bool ok;
  91775. unsigned i, channel;
  91776. FLAC__ASSERT(new_blocksize > 0);
  91777. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91778. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91779. if(new_blocksize <= encoder->private_->input_capacity)
  91780. return true;
  91781. ok = true;
  91782. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91783. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91784. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91785. encoder->private_->integer_signal[i] += 4;
  91786. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91787. #if 0 /* @@@ currently unused */
  91788. if(encoder->protected_->max_lpc_order > 0)
  91789. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91790. #endif
  91791. #endif
  91792. }
  91793. for(i = 0; ok && i < 2; i++) {
  91794. 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]);
  91795. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91796. encoder->private_->integer_signal_mid_side[i] += 4;
  91797. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91798. #if 0 /* @@@ currently unused */
  91799. if(encoder->protected_->max_lpc_order > 0)
  91800. 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]);
  91801. #endif
  91802. #endif
  91803. }
  91804. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91805. if(ok && encoder->protected_->max_lpc_order > 0) {
  91806. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91807. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91808. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91809. }
  91810. #endif
  91811. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91812. for(i = 0; ok && i < 2; i++) {
  91813. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91814. }
  91815. }
  91816. for(channel = 0; ok && channel < 2; channel++) {
  91817. for(i = 0; ok && i < 2; i++) {
  91818. 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]);
  91819. }
  91820. }
  91821. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91822. if(encoder->protected_->do_escape_coding)
  91823. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91824. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91825. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91826. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91827. switch(encoder->protected_->apodizations[i].type) {
  91828. case FLAC__APODIZATION_BARTLETT:
  91829. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91830. break;
  91831. case FLAC__APODIZATION_BARTLETT_HANN:
  91832. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91833. break;
  91834. case FLAC__APODIZATION_BLACKMAN:
  91835. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91836. break;
  91837. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91838. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91839. break;
  91840. case FLAC__APODIZATION_CONNES:
  91841. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91842. break;
  91843. case FLAC__APODIZATION_FLATTOP:
  91844. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91845. break;
  91846. case FLAC__APODIZATION_GAUSS:
  91847. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91848. break;
  91849. case FLAC__APODIZATION_HAMMING:
  91850. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91851. break;
  91852. case FLAC__APODIZATION_HANN:
  91853. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91854. break;
  91855. case FLAC__APODIZATION_KAISER_BESSEL:
  91856. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91857. break;
  91858. case FLAC__APODIZATION_NUTTALL:
  91859. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91860. break;
  91861. case FLAC__APODIZATION_RECTANGLE:
  91862. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91863. break;
  91864. case FLAC__APODIZATION_TRIANGLE:
  91865. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91866. break;
  91867. case FLAC__APODIZATION_TUKEY:
  91868. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91869. break;
  91870. case FLAC__APODIZATION_WELCH:
  91871. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91872. break;
  91873. default:
  91874. FLAC__ASSERT(0);
  91875. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91876. break;
  91877. }
  91878. }
  91879. }
  91880. #endif
  91881. if(ok)
  91882. encoder->private_->input_capacity = new_blocksize;
  91883. else
  91884. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91885. return ok;
  91886. }
  91887. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91888. {
  91889. const FLAC__byte *buffer;
  91890. size_t bytes;
  91891. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91892. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91893. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91894. return false;
  91895. }
  91896. if(encoder->protected_->verify) {
  91897. encoder->private_->verify.output.data = buffer;
  91898. encoder->private_->verify.output.bytes = bytes;
  91899. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91900. encoder->private_->verify.needs_magic_hack = true;
  91901. }
  91902. else {
  91903. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91904. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91905. FLAC__bitwriter_clear(encoder->private_->frame);
  91906. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91907. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91908. return false;
  91909. }
  91910. }
  91911. }
  91912. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91913. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91914. FLAC__bitwriter_clear(encoder->private_->frame);
  91915. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91916. return false;
  91917. }
  91918. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91919. FLAC__bitwriter_clear(encoder->private_->frame);
  91920. if(samples > 0) {
  91921. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91922. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91923. }
  91924. return true;
  91925. }
  91926. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91927. {
  91928. FLAC__StreamEncoderWriteStatus status;
  91929. FLAC__uint64 output_position = 0;
  91930. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91931. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91932. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91933. }
  91934. if(samples == 0) {
  91935. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91936. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91937. encoder->protected_->streaminfo_offset = output_position;
  91938. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91939. encoder->protected_->seektable_offset = output_position;
  91940. }
  91941. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91942. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91943. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91944. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91945. FLAC__uint64 test_sample;
  91946. unsigned i;
  91947. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91948. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91949. if(test_sample > frame_last_sample) {
  91950. break;
  91951. }
  91952. else if(test_sample >= frame_first_sample) {
  91953. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91954. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91955. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91956. encoder->private_->first_seekpoint_to_check++;
  91957. }
  91958. else {
  91959. encoder->private_->first_seekpoint_to_check++;
  91960. }
  91961. }
  91962. }
  91963. #if FLAC__HAS_OGG
  91964. if(encoder->private_->is_ogg) {
  91965. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91966. &encoder->protected_->ogg_encoder_aspect,
  91967. buffer,
  91968. bytes,
  91969. samples,
  91970. encoder->private_->current_frame_number,
  91971. is_last_block,
  91972. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91973. encoder,
  91974. encoder->private_->client_data
  91975. );
  91976. }
  91977. else
  91978. #endif
  91979. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91980. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91981. encoder->private_->bytes_written += bytes;
  91982. encoder->private_->samples_written += samples;
  91983. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91984. }
  91985. else
  91986. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91987. return status;
  91988. }
  91989. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91990. {
  91991. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91992. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91993. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91994. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91995. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91996. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91997. FLAC__StreamEncoderSeekStatus seek_status;
  91998. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91999. {
  92000. const unsigned md5_offset =
  92001. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92002. (
  92003. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92004. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92005. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92006. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92007. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92008. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92009. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92010. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92011. ) / 8;
  92012. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92013. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92014. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92015. return;
  92016. }
  92017. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92018. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92019. return;
  92020. }
  92021. }
  92022. {
  92023. const unsigned total_samples_byte_offset =
  92024. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92025. (
  92026. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92027. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92028. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92029. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92030. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92031. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92032. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92033. - 4
  92034. ) / 8;
  92035. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  92036. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92037. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92038. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92039. b[4] = (FLAC__byte)(samples & 0xFF);
  92040. 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) {
  92041. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92042. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92043. return;
  92044. }
  92045. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92046. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92047. return;
  92048. }
  92049. }
  92050. {
  92051. const unsigned min_framesize_offset =
  92052. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92053. (
  92054. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92055. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92056. ) / 8;
  92057. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92058. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92059. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92060. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92061. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92062. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92063. 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) {
  92064. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92065. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92066. return;
  92067. }
  92068. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92069. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92070. return;
  92071. }
  92072. }
  92073. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92074. unsigned i;
  92075. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92076. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92077. 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) {
  92078. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92079. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92080. return;
  92081. }
  92082. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  92083. FLAC__uint64 xx;
  92084. unsigned x;
  92085. xx = encoder->private_->seek_table->points[i].sample_number;
  92086. b[7] = (FLAC__byte)xx; xx >>= 8;
  92087. b[6] = (FLAC__byte)xx; xx >>= 8;
  92088. b[5] = (FLAC__byte)xx; xx >>= 8;
  92089. b[4] = (FLAC__byte)xx; xx >>= 8;
  92090. b[3] = (FLAC__byte)xx; xx >>= 8;
  92091. b[2] = (FLAC__byte)xx; xx >>= 8;
  92092. b[1] = (FLAC__byte)xx; xx >>= 8;
  92093. b[0] = (FLAC__byte)xx; xx >>= 8;
  92094. xx = encoder->private_->seek_table->points[i].stream_offset;
  92095. b[15] = (FLAC__byte)xx; xx >>= 8;
  92096. b[14] = (FLAC__byte)xx; xx >>= 8;
  92097. b[13] = (FLAC__byte)xx; xx >>= 8;
  92098. b[12] = (FLAC__byte)xx; xx >>= 8;
  92099. b[11] = (FLAC__byte)xx; xx >>= 8;
  92100. b[10] = (FLAC__byte)xx; xx >>= 8;
  92101. b[9] = (FLAC__byte)xx; xx >>= 8;
  92102. b[8] = (FLAC__byte)xx; xx >>= 8;
  92103. x = encoder->private_->seek_table->points[i].frame_samples;
  92104. b[17] = (FLAC__byte)x; x >>= 8;
  92105. b[16] = (FLAC__byte)x; x >>= 8;
  92106. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92107. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92108. return;
  92109. }
  92110. }
  92111. }
  92112. }
  92113. #if FLAC__HAS_OGG
  92114. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  92115. {
  92116. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  92117. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  92118. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  92119. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  92120. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  92121. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  92122. FLAC__STREAM_SYNC_LENGTH
  92123. ;
  92124. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92125. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92126. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92127. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92128. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92129. ogg_page page;
  92130. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92131. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  92132. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  92133. return;
  92134. simple_ogg_page__init(&page);
  92135. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92136. simple_ogg_page__clear(&page);
  92137. return; /* state already set */
  92138. }
  92139. {
  92140. const unsigned md5_offset =
  92141. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92142. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92143. (
  92144. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92145. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92146. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92147. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92148. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92149. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92150. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92151. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92152. ) / 8;
  92153. if(md5_offset + 16 > (unsigned)page.body_len) {
  92154. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92155. simple_ogg_page__clear(&page);
  92156. return;
  92157. }
  92158. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  92159. }
  92160. {
  92161. const unsigned total_samples_byte_offset =
  92162. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92163. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92164. (
  92165. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92166. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92167. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92168. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92169. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92170. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92171. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92172. - 4
  92173. ) / 8;
  92174. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  92175. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92176. simple_ogg_page__clear(&page);
  92177. return;
  92178. }
  92179. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  92180. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  92181. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92182. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92183. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92184. b[4] = (FLAC__byte)(samples & 0xFF);
  92185. memcpy(page.body + total_samples_byte_offset, b, 5);
  92186. }
  92187. {
  92188. const unsigned min_framesize_offset =
  92189. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92190. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92191. (
  92192. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92193. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92194. ) / 8;
  92195. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  92196. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92197. simple_ogg_page__clear(&page);
  92198. return;
  92199. }
  92200. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92201. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92202. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92203. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92204. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92205. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92206. memcpy(page.body + min_framesize_offset, b, 6);
  92207. }
  92208. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92209. simple_ogg_page__clear(&page);
  92210. return; /* state already set */
  92211. }
  92212. simple_ogg_page__clear(&page);
  92213. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92214. unsigned i;
  92215. FLAC__byte *p;
  92216. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92217. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92218. simple_ogg_page__init(&page);
  92219. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92220. simple_ogg_page__clear(&page);
  92221. return; /* state already set */
  92222. }
  92223. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  92224. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92225. simple_ogg_page__clear(&page);
  92226. return;
  92227. }
  92228. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  92229. FLAC__uint64 xx;
  92230. unsigned x;
  92231. xx = encoder->private_->seek_table->points[i].sample_number;
  92232. b[7] = (FLAC__byte)xx; xx >>= 8;
  92233. b[6] = (FLAC__byte)xx; xx >>= 8;
  92234. b[5] = (FLAC__byte)xx; xx >>= 8;
  92235. b[4] = (FLAC__byte)xx; xx >>= 8;
  92236. b[3] = (FLAC__byte)xx; xx >>= 8;
  92237. b[2] = (FLAC__byte)xx; xx >>= 8;
  92238. b[1] = (FLAC__byte)xx; xx >>= 8;
  92239. b[0] = (FLAC__byte)xx; xx >>= 8;
  92240. xx = encoder->private_->seek_table->points[i].stream_offset;
  92241. b[15] = (FLAC__byte)xx; xx >>= 8;
  92242. b[14] = (FLAC__byte)xx; xx >>= 8;
  92243. b[13] = (FLAC__byte)xx; xx >>= 8;
  92244. b[12] = (FLAC__byte)xx; xx >>= 8;
  92245. b[11] = (FLAC__byte)xx; xx >>= 8;
  92246. b[10] = (FLAC__byte)xx; xx >>= 8;
  92247. b[9] = (FLAC__byte)xx; xx >>= 8;
  92248. b[8] = (FLAC__byte)xx; xx >>= 8;
  92249. x = encoder->private_->seek_table->points[i].frame_samples;
  92250. b[17] = (FLAC__byte)x; x >>= 8;
  92251. b[16] = (FLAC__byte)x; x >>= 8;
  92252. memcpy(p, b, 18);
  92253. }
  92254. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92255. simple_ogg_page__clear(&page);
  92256. return; /* state already set */
  92257. }
  92258. simple_ogg_page__clear(&page);
  92259. }
  92260. }
  92261. #endif
  92262. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  92263. {
  92264. FLAC__uint16 crc;
  92265. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92266. 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)) {
  92267. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92268. return false;
  92269. }
  92270. if(!process_subframes_(encoder, is_fractional_block)) {
  92271. return false;
  92272. }
  92273. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  92274. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92275. return false;
  92276. }
  92277. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92278. if(
  92279. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  92280. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  92281. ) {
  92282. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92283. return false;
  92284. }
  92285. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92286. return false;
  92287. }
  92288. encoder->private_->current_sample_number = 0;
  92289. encoder->private_->current_frame_number++;
  92290. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92291. return true;
  92292. }
  92293. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92294. {
  92295. FLAC__FrameHeader frame_header;
  92296. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92297. FLAC__bool do_independent, do_mid_side;
  92298. if(is_fractional_block) {
  92299. max_partition_order = 0;
  92300. }
  92301. else {
  92302. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92303. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92304. }
  92305. min_partition_order = min(min_partition_order, max_partition_order);
  92306. frame_header.blocksize = encoder->protected_->blocksize;
  92307. frame_header.sample_rate = encoder->protected_->sample_rate;
  92308. frame_header.channels = encoder->protected_->channels;
  92309. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92310. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92311. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92312. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92313. if(encoder->protected_->do_mid_side_stereo) {
  92314. if(encoder->protected_->loose_mid_side_stereo) {
  92315. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92316. do_independent = true;
  92317. do_mid_side = true;
  92318. }
  92319. else {
  92320. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92321. do_mid_side = !do_independent;
  92322. }
  92323. }
  92324. else {
  92325. do_independent = true;
  92326. do_mid_side = true;
  92327. }
  92328. }
  92329. else {
  92330. do_independent = true;
  92331. do_mid_side = false;
  92332. }
  92333. FLAC__ASSERT(do_independent || do_mid_side);
  92334. if(do_independent) {
  92335. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92336. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92337. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92338. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92339. }
  92340. }
  92341. if(do_mid_side) {
  92342. FLAC__ASSERT(encoder->protected_->channels == 2);
  92343. for(channel = 0; channel < 2; channel++) {
  92344. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92345. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92346. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92347. }
  92348. }
  92349. if(do_independent) {
  92350. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92351. if(!
  92352. process_subframe_(
  92353. encoder,
  92354. min_partition_order,
  92355. max_partition_order,
  92356. &frame_header,
  92357. encoder->private_->subframe_bps[channel],
  92358. encoder->private_->integer_signal[channel],
  92359. encoder->private_->subframe_workspace_ptr[channel],
  92360. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92361. encoder->private_->residual_workspace[channel],
  92362. encoder->private_->best_subframe+channel,
  92363. encoder->private_->best_subframe_bits+channel
  92364. )
  92365. )
  92366. return false;
  92367. }
  92368. }
  92369. if(do_mid_side) {
  92370. FLAC__ASSERT(encoder->protected_->channels == 2);
  92371. for(channel = 0; channel < 2; channel++) {
  92372. if(!
  92373. process_subframe_(
  92374. encoder,
  92375. min_partition_order,
  92376. max_partition_order,
  92377. &frame_header,
  92378. encoder->private_->subframe_bps_mid_side[channel],
  92379. encoder->private_->integer_signal_mid_side[channel],
  92380. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92381. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92382. encoder->private_->residual_workspace_mid_side[channel],
  92383. encoder->private_->best_subframe_mid_side+channel,
  92384. encoder->private_->best_subframe_bits_mid_side+channel
  92385. )
  92386. )
  92387. return false;
  92388. }
  92389. }
  92390. if(do_mid_side) {
  92391. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92392. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92393. FLAC__ChannelAssignment channel_assignment;
  92394. FLAC__ASSERT(encoder->protected_->channels == 2);
  92395. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92396. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92397. }
  92398. else {
  92399. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92400. unsigned min_bits;
  92401. int ca;
  92402. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92403. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92404. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92405. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92406. FLAC__ASSERT(do_independent && do_mid_side);
  92407. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92408. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92409. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92410. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92411. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92412. min_bits = bits[channel_assignment];
  92413. for(ca = 1; ca <= 3; ca++) {
  92414. if(bits[ca] < min_bits) {
  92415. min_bits = bits[ca];
  92416. channel_assignment = (FLAC__ChannelAssignment)ca;
  92417. }
  92418. }
  92419. }
  92420. frame_header.channel_assignment = channel_assignment;
  92421. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92422. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92423. return false;
  92424. }
  92425. switch(channel_assignment) {
  92426. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92427. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92428. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92429. break;
  92430. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92431. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92432. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92433. break;
  92434. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92435. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92436. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92437. break;
  92438. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92439. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92440. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92441. break;
  92442. default:
  92443. FLAC__ASSERT(0);
  92444. }
  92445. switch(channel_assignment) {
  92446. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92447. left_bps = encoder->private_->subframe_bps [0];
  92448. right_bps = encoder->private_->subframe_bps [1];
  92449. break;
  92450. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92451. left_bps = encoder->private_->subframe_bps [0];
  92452. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92453. break;
  92454. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92455. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92456. right_bps = encoder->private_->subframe_bps [1];
  92457. break;
  92458. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92459. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92460. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92461. break;
  92462. default:
  92463. FLAC__ASSERT(0);
  92464. }
  92465. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92466. return false;
  92467. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92468. return false;
  92469. }
  92470. else {
  92471. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92472. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92473. return false;
  92474. }
  92475. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92476. 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)) {
  92477. return false;
  92478. }
  92479. }
  92480. }
  92481. if(encoder->protected_->loose_mid_side_stereo) {
  92482. encoder->private_->loose_mid_side_stereo_frame_count++;
  92483. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92484. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92485. }
  92486. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92487. return true;
  92488. }
  92489. FLAC__bool process_subframe_(
  92490. FLAC__StreamEncoder *encoder,
  92491. unsigned min_partition_order,
  92492. unsigned max_partition_order,
  92493. const FLAC__FrameHeader *frame_header,
  92494. unsigned subframe_bps,
  92495. const FLAC__int32 integer_signal[],
  92496. FLAC__Subframe *subframe[2],
  92497. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92498. FLAC__int32 *residual[2],
  92499. unsigned *best_subframe,
  92500. unsigned *best_bits
  92501. )
  92502. {
  92503. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92504. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92505. #else
  92506. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92507. #endif
  92508. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92509. FLAC__double lpc_residual_bits_per_sample;
  92510. 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 */
  92511. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92512. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92513. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92514. #endif
  92515. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92516. unsigned rice_parameter;
  92517. unsigned _candidate_bits, _best_bits;
  92518. unsigned _best_subframe;
  92519. 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;
  92520. FLAC__ASSERT(frame_header->blocksize > 0);
  92521. _best_subframe = 0;
  92522. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92523. _best_bits = UINT_MAX;
  92524. else
  92525. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92526. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92527. unsigned signal_is_constant = false;
  92528. 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);
  92529. if(
  92530. !encoder->private_->disable_constant_subframes &&
  92531. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92532. fixed_residual_bits_per_sample[1] == 0.0
  92533. #else
  92534. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92535. #endif
  92536. ) {
  92537. unsigned i;
  92538. signal_is_constant = true;
  92539. for(i = 1; i < frame_header->blocksize; i++) {
  92540. if(integer_signal[0] != integer_signal[i]) {
  92541. signal_is_constant = false;
  92542. break;
  92543. }
  92544. }
  92545. }
  92546. if(signal_is_constant) {
  92547. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92548. if(_candidate_bits < _best_bits) {
  92549. _best_subframe = !_best_subframe;
  92550. _best_bits = _candidate_bits;
  92551. }
  92552. }
  92553. else {
  92554. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92555. if(encoder->protected_->do_exhaustive_model_search) {
  92556. min_fixed_order = 0;
  92557. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92558. }
  92559. else {
  92560. min_fixed_order = max_fixed_order = guess_fixed_order;
  92561. }
  92562. if(max_fixed_order >= frame_header->blocksize)
  92563. max_fixed_order = frame_header->blocksize - 1;
  92564. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92565. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92566. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92567. continue; /* don't even try */
  92568. 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 */
  92569. #else
  92570. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92571. continue; /* don't even try */
  92572. 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 */
  92573. #endif
  92574. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92575. if(rice_parameter >= rice_parameter_limit) {
  92576. #ifdef DEBUG_VERBOSE
  92577. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92578. #endif
  92579. rice_parameter = rice_parameter_limit - 1;
  92580. }
  92581. _candidate_bits =
  92582. evaluate_fixed_subframe_(
  92583. encoder,
  92584. integer_signal,
  92585. residual[!_best_subframe],
  92586. encoder->private_->abs_residual_partition_sums,
  92587. encoder->private_->raw_bits_per_partition,
  92588. frame_header->blocksize,
  92589. subframe_bps,
  92590. fixed_order,
  92591. rice_parameter,
  92592. rice_parameter_limit,
  92593. min_partition_order,
  92594. max_partition_order,
  92595. encoder->protected_->do_escape_coding,
  92596. encoder->protected_->rice_parameter_search_dist,
  92597. subframe[!_best_subframe],
  92598. partitioned_rice_contents[!_best_subframe]
  92599. );
  92600. if(_candidate_bits < _best_bits) {
  92601. _best_subframe = !_best_subframe;
  92602. _best_bits = _candidate_bits;
  92603. }
  92604. }
  92605. }
  92606. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92607. if(encoder->protected_->max_lpc_order > 0) {
  92608. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92609. max_lpc_order = frame_header->blocksize-1;
  92610. else
  92611. max_lpc_order = encoder->protected_->max_lpc_order;
  92612. if(max_lpc_order > 0) {
  92613. unsigned a;
  92614. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92615. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92616. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92617. if(autoc[0] != 0.0) {
  92618. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92619. if(encoder->protected_->do_exhaustive_model_search) {
  92620. min_lpc_order = 1;
  92621. }
  92622. else {
  92623. const unsigned guess_lpc_order =
  92624. FLAC__lpc_compute_best_order(
  92625. lpc_error,
  92626. max_lpc_order,
  92627. frame_header->blocksize,
  92628. subframe_bps + (
  92629. encoder->protected_->do_qlp_coeff_prec_search?
  92630. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92631. encoder->protected_->qlp_coeff_precision
  92632. )
  92633. );
  92634. min_lpc_order = max_lpc_order = guess_lpc_order;
  92635. }
  92636. if(max_lpc_order >= frame_header->blocksize)
  92637. max_lpc_order = frame_header->blocksize - 1;
  92638. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92639. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92640. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92641. continue; /* don't even try */
  92642. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92643. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92644. if(rice_parameter >= rice_parameter_limit) {
  92645. #ifdef DEBUG_VERBOSE
  92646. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92647. #endif
  92648. rice_parameter = rice_parameter_limit - 1;
  92649. }
  92650. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92651. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92652. if(subframe_bps <= 17) {
  92653. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92654. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92655. }
  92656. else
  92657. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92658. }
  92659. else {
  92660. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92661. }
  92662. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92663. _candidate_bits =
  92664. evaluate_lpc_subframe_(
  92665. encoder,
  92666. integer_signal,
  92667. residual[!_best_subframe],
  92668. encoder->private_->abs_residual_partition_sums,
  92669. encoder->private_->raw_bits_per_partition,
  92670. encoder->private_->lp_coeff[lpc_order-1],
  92671. frame_header->blocksize,
  92672. subframe_bps,
  92673. lpc_order,
  92674. qlp_coeff_precision,
  92675. rice_parameter,
  92676. rice_parameter_limit,
  92677. min_partition_order,
  92678. max_partition_order,
  92679. encoder->protected_->do_escape_coding,
  92680. encoder->protected_->rice_parameter_search_dist,
  92681. subframe[!_best_subframe],
  92682. partitioned_rice_contents[!_best_subframe]
  92683. );
  92684. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92685. if(_candidate_bits < _best_bits) {
  92686. _best_subframe = !_best_subframe;
  92687. _best_bits = _candidate_bits;
  92688. }
  92689. }
  92690. }
  92691. }
  92692. }
  92693. }
  92694. }
  92695. }
  92696. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92697. }
  92698. }
  92699. if(_best_bits == UINT_MAX) {
  92700. FLAC__ASSERT(_best_subframe == 0);
  92701. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92702. }
  92703. *best_subframe = _best_subframe;
  92704. *best_bits = _best_bits;
  92705. return true;
  92706. }
  92707. FLAC__bool add_subframe_(
  92708. FLAC__StreamEncoder *encoder,
  92709. unsigned blocksize,
  92710. unsigned subframe_bps,
  92711. const FLAC__Subframe *subframe,
  92712. FLAC__BitWriter *frame
  92713. )
  92714. {
  92715. switch(subframe->type) {
  92716. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92717. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92718. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92719. return false;
  92720. }
  92721. break;
  92722. case FLAC__SUBFRAME_TYPE_FIXED:
  92723. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92724. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92725. return false;
  92726. }
  92727. break;
  92728. case FLAC__SUBFRAME_TYPE_LPC:
  92729. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92730. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92731. return false;
  92732. }
  92733. break;
  92734. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92735. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92736. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92737. return false;
  92738. }
  92739. break;
  92740. default:
  92741. FLAC__ASSERT(0);
  92742. }
  92743. return true;
  92744. }
  92745. #define SPOTCHECK_ESTIMATE 0
  92746. #if SPOTCHECK_ESTIMATE
  92747. static void spotcheck_subframe_estimate_(
  92748. FLAC__StreamEncoder *encoder,
  92749. unsigned blocksize,
  92750. unsigned subframe_bps,
  92751. const FLAC__Subframe *subframe,
  92752. unsigned estimate
  92753. )
  92754. {
  92755. FLAC__bool ret;
  92756. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92757. if(frame == 0) {
  92758. fprintf(stderr, "EST: can't allocate frame\n");
  92759. return;
  92760. }
  92761. if(!FLAC__bitwriter_init(frame)) {
  92762. fprintf(stderr, "EST: can't init frame\n");
  92763. return;
  92764. }
  92765. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92766. FLAC__ASSERT(ret);
  92767. {
  92768. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92769. if(estimate != actual)
  92770. 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);
  92771. }
  92772. FLAC__bitwriter_delete(frame);
  92773. }
  92774. #endif
  92775. unsigned evaluate_constant_subframe_(
  92776. FLAC__StreamEncoder *encoder,
  92777. const FLAC__int32 signal,
  92778. unsigned blocksize,
  92779. unsigned subframe_bps,
  92780. FLAC__Subframe *subframe
  92781. )
  92782. {
  92783. unsigned estimate;
  92784. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92785. subframe->data.constant.value = signal;
  92786. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92787. #if SPOTCHECK_ESTIMATE
  92788. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92789. #else
  92790. (void)encoder, (void)blocksize;
  92791. #endif
  92792. return estimate;
  92793. }
  92794. unsigned evaluate_fixed_subframe_(
  92795. FLAC__StreamEncoder *encoder,
  92796. const FLAC__int32 signal[],
  92797. FLAC__int32 residual[],
  92798. FLAC__uint64 abs_residual_partition_sums[],
  92799. unsigned raw_bits_per_partition[],
  92800. unsigned blocksize,
  92801. unsigned subframe_bps,
  92802. unsigned order,
  92803. unsigned rice_parameter,
  92804. unsigned rice_parameter_limit,
  92805. unsigned min_partition_order,
  92806. unsigned max_partition_order,
  92807. FLAC__bool do_escape_coding,
  92808. unsigned rice_parameter_search_dist,
  92809. FLAC__Subframe *subframe,
  92810. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92811. )
  92812. {
  92813. unsigned i, residual_bits, estimate;
  92814. const unsigned residual_samples = blocksize - order;
  92815. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92816. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92817. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92818. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92819. subframe->data.fixed.residual = residual;
  92820. residual_bits =
  92821. find_best_partition_order_(
  92822. encoder->private_,
  92823. residual,
  92824. abs_residual_partition_sums,
  92825. raw_bits_per_partition,
  92826. residual_samples,
  92827. order,
  92828. rice_parameter,
  92829. rice_parameter_limit,
  92830. min_partition_order,
  92831. max_partition_order,
  92832. subframe_bps,
  92833. do_escape_coding,
  92834. rice_parameter_search_dist,
  92835. &subframe->data.fixed.entropy_coding_method
  92836. );
  92837. subframe->data.fixed.order = order;
  92838. for(i = 0; i < order; i++)
  92839. subframe->data.fixed.warmup[i] = signal[i];
  92840. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92841. #if SPOTCHECK_ESTIMATE
  92842. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92843. #endif
  92844. return estimate;
  92845. }
  92846. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92847. unsigned evaluate_lpc_subframe_(
  92848. FLAC__StreamEncoder *encoder,
  92849. const FLAC__int32 signal[],
  92850. FLAC__int32 residual[],
  92851. FLAC__uint64 abs_residual_partition_sums[],
  92852. unsigned raw_bits_per_partition[],
  92853. const FLAC__real lp_coeff[],
  92854. unsigned blocksize,
  92855. unsigned subframe_bps,
  92856. unsigned order,
  92857. unsigned qlp_coeff_precision,
  92858. unsigned rice_parameter,
  92859. unsigned rice_parameter_limit,
  92860. unsigned min_partition_order,
  92861. unsigned max_partition_order,
  92862. FLAC__bool do_escape_coding,
  92863. unsigned rice_parameter_search_dist,
  92864. FLAC__Subframe *subframe,
  92865. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92866. )
  92867. {
  92868. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92869. unsigned i, residual_bits, estimate;
  92870. int quantization, ret;
  92871. const unsigned residual_samples = blocksize - order;
  92872. if(subframe_bps <= 16) {
  92873. FLAC__ASSERT(order > 0);
  92874. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92875. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92876. }
  92877. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92878. if(ret != 0)
  92879. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92880. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92881. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92882. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92883. else
  92884. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92885. else
  92886. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92887. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92888. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92889. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92890. subframe->data.lpc.residual = residual;
  92891. residual_bits =
  92892. find_best_partition_order_(
  92893. encoder->private_,
  92894. residual,
  92895. abs_residual_partition_sums,
  92896. raw_bits_per_partition,
  92897. residual_samples,
  92898. order,
  92899. rice_parameter,
  92900. rice_parameter_limit,
  92901. min_partition_order,
  92902. max_partition_order,
  92903. subframe_bps,
  92904. do_escape_coding,
  92905. rice_parameter_search_dist,
  92906. &subframe->data.lpc.entropy_coding_method
  92907. );
  92908. subframe->data.lpc.order = order;
  92909. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92910. subframe->data.lpc.quantization_level = quantization;
  92911. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92912. for(i = 0; i < order; i++)
  92913. subframe->data.lpc.warmup[i] = signal[i];
  92914. 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;
  92915. #if SPOTCHECK_ESTIMATE
  92916. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92917. #endif
  92918. return estimate;
  92919. }
  92920. #endif
  92921. unsigned evaluate_verbatim_subframe_(
  92922. FLAC__StreamEncoder *encoder,
  92923. const FLAC__int32 signal[],
  92924. unsigned blocksize,
  92925. unsigned subframe_bps,
  92926. FLAC__Subframe *subframe
  92927. )
  92928. {
  92929. unsigned estimate;
  92930. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92931. subframe->data.verbatim.data = signal;
  92932. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92933. #if SPOTCHECK_ESTIMATE
  92934. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92935. #else
  92936. (void)encoder;
  92937. #endif
  92938. return estimate;
  92939. }
  92940. unsigned find_best_partition_order_(
  92941. FLAC__StreamEncoderPrivate *private_,
  92942. const FLAC__int32 residual[],
  92943. FLAC__uint64 abs_residual_partition_sums[],
  92944. unsigned raw_bits_per_partition[],
  92945. unsigned residual_samples,
  92946. unsigned predictor_order,
  92947. unsigned rice_parameter,
  92948. unsigned rice_parameter_limit,
  92949. unsigned min_partition_order,
  92950. unsigned max_partition_order,
  92951. unsigned bps,
  92952. FLAC__bool do_escape_coding,
  92953. unsigned rice_parameter_search_dist,
  92954. FLAC__EntropyCodingMethod *best_ecm
  92955. )
  92956. {
  92957. unsigned residual_bits, best_residual_bits = 0;
  92958. unsigned best_parameters_index = 0;
  92959. unsigned best_partition_order = 0;
  92960. const unsigned blocksize = residual_samples + predictor_order;
  92961. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92962. min_partition_order = min(min_partition_order, max_partition_order);
  92963. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92964. if(do_escape_coding)
  92965. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92966. {
  92967. int partition_order;
  92968. unsigned sum;
  92969. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92970. if(!
  92971. set_partitioned_rice_(
  92972. #ifdef EXACT_RICE_BITS_CALCULATION
  92973. residual,
  92974. #endif
  92975. abs_residual_partition_sums+sum,
  92976. raw_bits_per_partition+sum,
  92977. residual_samples,
  92978. predictor_order,
  92979. rice_parameter,
  92980. rice_parameter_limit,
  92981. rice_parameter_search_dist,
  92982. (unsigned)partition_order,
  92983. do_escape_coding,
  92984. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92985. &residual_bits
  92986. )
  92987. )
  92988. {
  92989. FLAC__ASSERT(best_residual_bits != 0);
  92990. break;
  92991. }
  92992. sum += 1u << partition_order;
  92993. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92994. best_residual_bits = residual_bits;
  92995. best_parameters_index = !best_parameters_index;
  92996. best_partition_order = partition_order;
  92997. }
  92998. }
  92999. }
  93000. best_ecm->data.partitioned_rice.order = best_partition_order;
  93001. {
  93002. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  93003. unsigned partition;
  93004. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  93005. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  93006. if(do_escape_coding)
  93007. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  93008. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  93009. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  93010. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  93011. break;
  93012. }
  93013. }
  93014. }
  93015. return best_residual_bits;
  93016. }
  93017. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93018. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  93019. const FLAC__int32 residual[],
  93020. FLAC__uint64 abs_residual_partition_sums[],
  93021. unsigned blocksize,
  93022. unsigned predictor_order,
  93023. unsigned min_partition_order,
  93024. unsigned max_partition_order
  93025. );
  93026. #endif
  93027. void precompute_partition_info_sums_(
  93028. const FLAC__int32 residual[],
  93029. FLAC__uint64 abs_residual_partition_sums[],
  93030. unsigned residual_samples,
  93031. unsigned predictor_order,
  93032. unsigned min_partition_order,
  93033. unsigned max_partition_order,
  93034. unsigned bps
  93035. )
  93036. {
  93037. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  93038. unsigned partitions = 1u << max_partition_order;
  93039. FLAC__ASSERT(default_partition_samples > predictor_order);
  93040. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93041. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93042. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  93043. return;
  93044. }
  93045. #endif
  93046. {
  93047. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  93048. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93049. FLAC__uint32 abs_residual_partition_sum;
  93050. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93051. end += default_partition_samples;
  93052. abs_residual_partition_sum = 0;
  93053. for( ; residual_sample < end; residual_sample++)
  93054. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93055. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93056. }
  93057. }
  93058. else { /* have to pessimistically use 64 bits for accumulator */
  93059. FLAC__uint64 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. }
  93069. {
  93070. unsigned from_partition = 0, to_partition = partitions;
  93071. int partition_order;
  93072. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  93073. unsigned i;
  93074. partitions >>= 1;
  93075. for(i = 0; i < partitions; i++) {
  93076. abs_residual_partition_sums[to_partition++] =
  93077. abs_residual_partition_sums[from_partition ] +
  93078. abs_residual_partition_sums[from_partition+1];
  93079. from_partition += 2;
  93080. }
  93081. }
  93082. }
  93083. }
  93084. void precompute_partition_info_escapes_(
  93085. const FLAC__int32 residual[],
  93086. unsigned raw_bits_per_partition[],
  93087. unsigned residual_samples,
  93088. unsigned predictor_order,
  93089. unsigned min_partition_order,
  93090. unsigned max_partition_order
  93091. )
  93092. {
  93093. int partition_order;
  93094. unsigned from_partition, to_partition = 0;
  93095. const unsigned blocksize = residual_samples + predictor_order;
  93096. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  93097. FLAC__int32 r;
  93098. FLAC__uint32 rmax;
  93099. unsigned partition, partition_sample, partition_samples, residual_sample;
  93100. const unsigned partitions = 1u << partition_order;
  93101. const unsigned default_partition_samples = blocksize >> partition_order;
  93102. FLAC__ASSERT(default_partition_samples > predictor_order);
  93103. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93104. partition_samples = default_partition_samples;
  93105. if(partition == 0)
  93106. partition_samples -= predictor_order;
  93107. rmax = 0;
  93108. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  93109. r = residual[residual_sample++];
  93110. if(r < 0)
  93111. rmax |= ~r;
  93112. else
  93113. rmax |= r;
  93114. }
  93115. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  93116. }
  93117. to_partition = partitions;
  93118. break; /*@@@ yuck, should remove the 'for' loop instead */
  93119. }
  93120. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  93121. unsigned m;
  93122. unsigned i;
  93123. const unsigned partitions = 1u << partition_order;
  93124. for(i = 0; i < partitions; i++) {
  93125. m = raw_bits_per_partition[from_partition];
  93126. from_partition++;
  93127. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  93128. from_partition++;
  93129. to_partition++;
  93130. }
  93131. }
  93132. }
  93133. #ifdef EXACT_RICE_BITS_CALCULATION
  93134. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93135. const unsigned rice_parameter,
  93136. const unsigned partition_samples,
  93137. const FLAC__int32 *residual
  93138. )
  93139. {
  93140. unsigned i, partition_bits =
  93141. 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 */
  93142. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  93143. ;
  93144. for(i = 0; i < partition_samples; i++)
  93145. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  93146. return partition_bits;
  93147. }
  93148. #else
  93149. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93150. const unsigned rice_parameter,
  93151. const unsigned partition_samples,
  93152. const FLAC__uint64 abs_residual_partition_sum
  93153. )
  93154. {
  93155. return
  93156. 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 */
  93157. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  93158. (
  93159. rice_parameter?
  93160. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  93161. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  93162. )
  93163. - (partition_samples >> 1)
  93164. ;
  93165. }
  93166. #endif
  93167. FLAC__bool set_partitioned_rice_(
  93168. #ifdef EXACT_RICE_BITS_CALCULATION
  93169. const FLAC__int32 residual[],
  93170. #endif
  93171. const FLAC__uint64 abs_residual_partition_sums[],
  93172. const unsigned raw_bits_per_partition[],
  93173. const unsigned residual_samples,
  93174. const unsigned predictor_order,
  93175. const unsigned suggested_rice_parameter,
  93176. const unsigned rice_parameter_limit,
  93177. const unsigned rice_parameter_search_dist,
  93178. const unsigned partition_order,
  93179. const FLAC__bool search_for_escapes,
  93180. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  93181. unsigned *bits
  93182. )
  93183. {
  93184. unsigned rice_parameter, partition_bits;
  93185. unsigned best_partition_bits, best_rice_parameter = 0;
  93186. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  93187. unsigned *parameters, *raw_bits;
  93188. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93189. unsigned min_rice_parameter, max_rice_parameter;
  93190. #else
  93191. (void)rice_parameter_search_dist;
  93192. #endif
  93193. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93194. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93195. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  93196. parameters = partitioned_rice_contents->parameters;
  93197. raw_bits = partitioned_rice_contents->raw_bits;
  93198. if(partition_order == 0) {
  93199. best_partition_bits = (unsigned)(-1);
  93200. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93201. if(rice_parameter_search_dist) {
  93202. if(suggested_rice_parameter < rice_parameter_search_dist)
  93203. min_rice_parameter = 0;
  93204. else
  93205. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  93206. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  93207. if(max_rice_parameter >= rice_parameter_limit) {
  93208. #ifdef DEBUG_VERBOSE
  93209. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  93210. #endif
  93211. max_rice_parameter = rice_parameter_limit - 1;
  93212. }
  93213. }
  93214. else
  93215. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  93216. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93217. #else
  93218. rice_parameter = suggested_rice_parameter;
  93219. #endif
  93220. #ifdef EXACT_RICE_BITS_CALCULATION
  93221. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  93222. #else
  93223. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  93224. #endif
  93225. if(partition_bits < best_partition_bits) {
  93226. best_rice_parameter = rice_parameter;
  93227. best_partition_bits = partition_bits;
  93228. }
  93229. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93230. }
  93231. #endif
  93232. if(search_for_escapes) {
  93233. 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;
  93234. if(partition_bits <= best_partition_bits) {
  93235. raw_bits[0] = raw_bits_per_partition[0];
  93236. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93237. best_partition_bits = partition_bits;
  93238. }
  93239. else
  93240. raw_bits[0] = 0;
  93241. }
  93242. parameters[0] = best_rice_parameter;
  93243. bits_ += best_partition_bits;
  93244. }
  93245. else {
  93246. unsigned partition, residual_sample;
  93247. unsigned partition_samples;
  93248. FLAC__uint64 mean, k;
  93249. const unsigned partitions = 1u << partition_order;
  93250. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93251. partition_samples = (residual_samples+predictor_order) >> partition_order;
  93252. if(partition == 0) {
  93253. if(partition_samples <= predictor_order)
  93254. return false;
  93255. else
  93256. partition_samples -= predictor_order;
  93257. }
  93258. mean = abs_residual_partition_sums[partition];
  93259. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  93260. ;
  93261. if(rice_parameter >= rice_parameter_limit) {
  93262. #ifdef DEBUG_VERBOSE
  93263. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  93264. #endif
  93265. rice_parameter = rice_parameter_limit - 1;
  93266. }
  93267. best_partition_bits = (unsigned)(-1);
  93268. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93269. if(rice_parameter_search_dist) {
  93270. if(rice_parameter < rice_parameter_search_dist)
  93271. min_rice_parameter = 0;
  93272. else
  93273. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  93274. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  93275. if(max_rice_parameter >= rice_parameter_limit) {
  93276. #ifdef DEBUG_VERBOSE
  93277. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  93278. #endif
  93279. max_rice_parameter = rice_parameter_limit - 1;
  93280. }
  93281. }
  93282. else
  93283. min_rice_parameter = max_rice_parameter = rice_parameter;
  93284. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93285. #endif
  93286. #ifdef EXACT_RICE_BITS_CALCULATION
  93287. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93288. #else
  93289. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93290. #endif
  93291. if(partition_bits < best_partition_bits) {
  93292. best_rice_parameter = rice_parameter;
  93293. best_partition_bits = partition_bits;
  93294. }
  93295. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93296. }
  93297. #endif
  93298. if(search_for_escapes) {
  93299. 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;
  93300. if(partition_bits <= best_partition_bits) {
  93301. raw_bits[partition] = raw_bits_per_partition[partition];
  93302. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93303. best_partition_bits = partition_bits;
  93304. }
  93305. else
  93306. raw_bits[partition] = 0;
  93307. }
  93308. parameters[partition] = best_rice_parameter;
  93309. bits_ += best_partition_bits;
  93310. residual_sample += partition_samples;
  93311. }
  93312. }
  93313. *bits = bits_;
  93314. return true;
  93315. }
  93316. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93317. {
  93318. unsigned i, shift;
  93319. FLAC__int32 x = 0;
  93320. for(i = 0; i < samples && !(x&1); i++)
  93321. x |= signal[i];
  93322. if(x == 0) {
  93323. shift = 0;
  93324. }
  93325. else {
  93326. for(shift = 0; !(x&1); shift++)
  93327. x >>= 1;
  93328. }
  93329. if(shift > 0) {
  93330. for(i = 0; i < samples; i++)
  93331. signal[i] >>= shift;
  93332. }
  93333. return shift;
  93334. }
  93335. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93336. {
  93337. unsigned channel;
  93338. for(channel = 0; channel < channels; channel++)
  93339. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93340. fifo->tail += wide_samples;
  93341. FLAC__ASSERT(fifo->tail <= fifo->size);
  93342. }
  93343. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93344. {
  93345. unsigned channel;
  93346. unsigned sample, wide_sample;
  93347. unsigned tail = fifo->tail;
  93348. sample = input_offset * channels;
  93349. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93350. for(channel = 0; channel < channels; channel++)
  93351. fifo->data[channel][tail] = input[sample++];
  93352. tail++;
  93353. }
  93354. fifo->tail = tail;
  93355. FLAC__ASSERT(fifo->tail <= fifo->size);
  93356. }
  93357. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93358. {
  93359. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93360. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93361. (void)decoder;
  93362. if(encoder->private_->verify.needs_magic_hack) {
  93363. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93364. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93365. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93366. encoder->private_->verify.needs_magic_hack = false;
  93367. }
  93368. else {
  93369. if(encoded_bytes == 0) {
  93370. FLAC__ASSERT(0);
  93371. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93372. }
  93373. else if(encoded_bytes < *bytes)
  93374. *bytes = encoded_bytes;
  93375. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93376. encoder->private_->verify.output.data += *bytes;
  93377. encoder->private_->verify.output.bytes -= *bytes;
  93378. }
  93379. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93380. }
  93381. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93382. {
  93383. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93384. unsigned channel;
  93385. const unsigned channels = frame->header.channels;
  93386. const unsigned blocksize = frame->header.blocksize;
  93387. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93388. (void)decoder;
  93389. for(channel = 0; channel < channels; channel++) {
  93390. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93391. unsigned i, sample = 0;
  93392. FLAC__int32 expect = 0, got = 0;
  93393. for(i = 0; i < blocksize; i++) {
  93394. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93395. sample = i;
  93396. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93397. got = (FLAC__int32)buffer[channel][i];
  93398. break;
  93399. }
  93400. }
  93401. FLAC__ASSERT(i < blocksize);
  93402. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93403. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93404. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93405. encoder->private_->verify.error_stats.channel = channel;
  93406. encoder->private_->verify.error_stats.sample = sample;
  93407. encoder->private_->verify.error_stats.expected = expect;
  93408. encoder->private_->verify.error_stats.got = got;
  93409. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93410. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93411. }
  93412. }
  93413. encoder->private_->verify.input_fifo.tail -= blocksize;
  93414. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93415. for(channel = 0; channel < channels; channel++)
  93416. 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]));
  93417. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93418. }
  93419. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93420. {
  93421. (void)decoder, (void)metadata, (void)client_data;
  93422. }
  93423. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93424. {
  93425. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93426. (void)decoder, (void)status;
  93427. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93428. }
  93429. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93430. {
  93431. (void)client_data;
  93432. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93433. if (*bytes == 0) {
  93434. if (feof(encoder->private_->file))
  93435. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93436. else if (ferror(encoder->private_->file))
  93437. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93438. }
  93439. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93440. }
  93441. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93442. {
  93443. (void)client_data;
  93444. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93445. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93446. else
  93447. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93448. }
  93449. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93450. {
  93451. off_t offset;
  93452. (void)client_data;
  93453. offset = ftello(encoder->private_->file);
  93454. if(offset < 0) {
  93455. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93456. }
  93457. else {
  93458. *absolute_byte_offset = (FLAC__uint64)offset;
  93459. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93460. }
  93461. }
  93462. #ifdef FLAC__VALGRIND_TESTING
  93463. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93464. {
  93465. size_t ret = fwrite(ptr, size, nmemb, stream);
  93466. if(!ferror(stream))
  93467. fflush(stream);
  93468. return ret;
  93469. }
  93470. #else
  93471. #define local__fwrite fwrite
  93472. #endif
  93473. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93474. {
  93475. (void)client_data, (void)current_frame;
  93476. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93477. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93478. #if FLAC__HAS_OGG
  93479. encoder->private_->is_ogg? true :
  93480. #endif
  93481. samples > 0
  93482. );
  93483. if(call_it) {
  93484. 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);
  93485. }
  93486. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93487. }
  93488. else
  93489. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93490. }
  93491. FILE *get_binary_stdout_(void)
  93492. {
  93493. #if defined _MSC_VER || defined __MINGW32__
  93494. _setmode(_fileno(stdout), _O_BINARY);
  93495. #elif defined __CYGWIN__
  93496. setmode(_fileno(stdout), _O_BINARY);
  93497. #elif defined __EMX__
  93498. setmode(fileno(stdout), O_BINARY);
  93499. #endif
  93500. return stdout;
  93501. }
  93502. #endif
  93503. /*** End of inlined file: stream_encoder.c ***/
  93504. /*** Start of inlined file: stream_encoder_framing.c ***/
  93505. /*** Start of inlined file: juce_FlacHeader.h ***/
  93506. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93507. // tasks..
  93508. #define VERSION "1.2.1"
  93509. #define FLAC__NO_DLL 1
  93510. #if JUCE_MSVC
  93511. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93512. #endif
  93513. #if JUCE_MAC
  93514. #define FLAC__SYS_DARWIN 1
  93515. #endif
  93516. /*** End of inlined file: juce_FlacHeader.h ***/
  93517. #if JUCE_USE_FLAC
  93518. #if HAVE_CONFIG_H
  93519. # include <config.h>
  93520. #endif
  93521. #include <stdio.h>
  93522. #include <string.h> /* for strlen() */
  93523. #ifdef max
  93524. #undef max
  93525. #endif
  93526. #define max(x,y) ((x)>(y)?(x):(y))
  93527. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93528. 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);
  93529. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93530. {
  93531. unsigned i, j;
  93532. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93533. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93534. return false;
  93535. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93536. return false;
  93537. i = metadata->length;
  93538. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93539. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93540. i -= metadata->data.vorbis_comment.vendor_string.length;
  93541. i += vendor_string_length;
  93542. }
  93543. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93544. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93545. return false;
  93546. switch(metadata->type) {
  93547. case FLAC__METADATA_TYPE_STREAMINFO:
  93548. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93549. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93550. return false;
  93551. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93552. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93553. return false;
  93554. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93555. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93556. return false;
  93557. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93558. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93559. return false;
  93560. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93561. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93562. return false;
  93563. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93564. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93565. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93566. return false;
  93567. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93568. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93569. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93570. return false;
  93571. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93572. return false;
  93573. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93574. return false;
  93575. break;
  93576. case FLAC__METADATA_TYPE_PADDING:
  93577. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93578. return false;
  93579. break;
  93580. case FLAC__METADATA_TYPE_APPLICATION:
  93581. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93582. return false;
  93583. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93584. return false;
  93585. break;
  93586. case FLAC__METADATA_TYPE_SEEKTABLE:
  93587. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93588. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93589. return false;
  93590. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93591. return false;
  93592. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93593. return false;
  93594. }
  93595. break;
  93596. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93597. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93598. return false;
  93599. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93600. return false;
  93601. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93602. return false;
  93603. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93604. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93605. return false;
  93606. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93607. return false;
  93608. }
  93609. break;
  93610. case FLAC__METADATA_TYPE_CUESHEET:
  93611. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93612. 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))
  93613. return false;
  93614. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93615. return false;
  93616. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93617. return false;
  93618. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93619. return false;
  93620. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93621. return false;
  93622. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93623. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93624. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93625. return false;
  93626. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93627. return false;
  93628. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93629. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93630. return false;
  93631. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93632. return false;
  93633. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93634. return false;
  93635. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93636. return false;
  93637. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93638. return false;
  93639. for(j = 0; j < track->num_indices; j++) {
  93640. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93641. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93642. return false;
  93643. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93644. return false;
  93645. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93646. return false;
  93647. }
  93648. }
  93649. break;
  93650. case FLAC__METADATA_TYPE_PICTURE:
  93651. {
  93652. size_t len;
  93653. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93654. return false;
  93655. len = strlen(metadata->data.picture.mime_type);
  93656. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93657. return false;
  93658. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93659. return false;
  93660. len = strlen((const char *)metadata->data.picture.description);
  93661. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93662. return false;
  93663. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93664. return false;
  93665. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93666. return false;
  93667. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93668. return false;
  93669. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93670. return false;
  93671. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93672. return false;
  93673. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93674. return false;
  93675. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93676. return false;
  93677. }
  93678. break;
  93679. default:
  93680. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93681. return false;
  93682. break;
  93683. }
  93684. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93685. return true;
  93686. }
  93687. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93688. {
  93689. unsigned u, blocksize_hint, sample_rate_hint;
  93690. FLAC__byte crc;
  93691. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93692. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93693. return false;
  93694. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93695. return false;
  93696. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93697. return false;
  93698. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93699. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93700. blocksize_hint = 0;
  93701. switch(header->blocksize) {
  93702. case 192: u = 1; break;
  93703. case 576: u = 2; break;
  93704. case 1152: u = 3; break;
  93705. case 2304: u = 4; break;
  93706. case 4608: u = 5; break;
  93707. case 256: u = 8; break;
  93708. case 512: u = 9; break;
  93709. case 1024: u = 10; break;
  93710. case 2048: u = 11; break;
  93711. case 4096: u = 12; break;
  93712. case 8192: u = 13; break;
  93713. case 16384: u = 14; break;
  93714. case 32768: u = 15; break;
  93715. default:
  93716. if(header->blocksize <= 0x100)
  93717. blocksize_hint = u = 6;
  93718. else
  93719. blocksize_hint = u = 7;
  93720. break;
  93721. }
  93722. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93723. return false;
  93724. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93725. sample_rate_hint = 0;
  93726. switch(header->sample_rate) {
  93727. case 88200: u = 1; break;
  93728. case 176400: u = 2; break;
  93729. case 192000: u = 3; break;
  93730. case 8000: u = 4; break;
  93731. case 16000: u = 5; break;
  93732. case 22050: u = 6; break;
  93733. case 24000: u = 7; break;
  93734. case 32000: u = 8; break;
  93735. case 44100: u = 9; break;
  93736. case 48000: u = 10; break;
  93737. case 96000: u = 11; break;
  93738. default:
  93739. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93740. sample_rate_hint = u = 12;
  93741. else if(header->sample_rate % 10 == 0)
  93742. sample_rate_hint = u = 14;
  93743. else if(header->sample_rate <= 0xffff)
  93744. sample_rate_hint = u = 13;
  93745. else
  93746. u = 0;
  93747. break;
  93748. }
  93749. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93750. return false;
  93751. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93752. switch(header->channel_assignment) {
  93753. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93754. u = header->channels - 1;
  93755. break;
  93756. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93757. FLAC__ASSERT(header->channels == 2);
  93758. u = 8;
  93759. break;
  93760. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93761. FLAC__ASSERT(header->channels == 2);
  93762. u = 9;
  93763. break;
  93764. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93765. FLAC__ASSERT(header->channels == 2);
  93766. u = 10;
  93767. break;
  93768. default:
  93769. FLAC__ASSERT(0);
  93770. }
  93771. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93772. return false;
  93773. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93774. switch(header->bits_per_sample) {
  93775. case 8 : u = 1; break;
  93776. case 12: u = 2; break;
  93777. case 16: u = 4; break;
  93778. case 20: u = 5; break;
  93779. case 24: u = 6; break;
  93780. default: u = 0; break;
  93781. }
  93782. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93783. return false;
  93784. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93785. return false;
  93786. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93787. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93788. return false;
  93789. }
  93790. else {
  93791. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93792. return false;
  93793. }
  93794. if(blocksize_hint)
  93795. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93796. return false;
  93797. switch(sample_rate_hint) {
  93798. case 12:
  93799. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93800. return false;
  93801. break;
  93802. case 13:
  93803. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93804. return false;
  93805. break;
  93806. case 14:
  93807. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93808. return false;
  93809. break;
  93810. }
  93811. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93812. return false;
  93813. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93814. return false;
  93815. return true;
  93816. }
  93817. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93818. {
  93819. FLAC__bool ok;
  93820. ok =
  93821. 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) &&
  93822. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93823. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93824. ;
  93825. return ok;
  93826. }
  93827. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93828. {
  93829. unsigned i;
  93830. 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))
  93831. return false;
  93832. if(wasted_bits)
  93833. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93834. return false;
  93835. for(i = 0; i < subframe->order; i++)
  93836. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93837. return false;
  93838. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93839. return false;
  93840. switch(subframe->entropy_coding_method.type) {
  93841. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93842. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93843. if(!add_residual_partitioned_rice_(
  93844. bw,
  93845. subframe->residual,
  93846. residual_samples,
  93847. subframe->order,
  93848. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93849. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93850. subframe->entropy_coding_method.data.partitioned_rice.order,
  93851. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93852. ))
  93853. return false;
  93854. break;
  93855. default:
  93856. FLAC__ASSERT(0);
  93857. }
  93858. return true;
  93859. }
  93860. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93861. {
  93862. unsigned i;
  93863. 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))
  93864. return false;
  93865. if(wasted_bits)
  93866. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93867. return false;
  93868. for(i = 0; i < subframe->order; i++)
  93869. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93870. return false;
  93871. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93872. return false;
  93873. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93874. return false;
  93875. for(i = 0; i < subframe->order; i++)
  93876. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93877. return false;
  93878. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93879. return false;
  93880. switch(subframe->entropy_coding_method.type) {
  93881. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93882. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93883. if(!add_residual_partitioned_rice_(
  93884. bw,
  93885. subframe->residual,
  93886. residual_samples,
  93887. subframe->order,
  93888. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93889. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93890. subframe->entropy_coding_method.data.partitioned_rice.order,
  93891. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93892. ))
  93893. return false;
  93894. break;
  93895. default:
  93896. FLAC__ASSERT(0);
  93897. }
  93898. return true;
  93899. }
  93900. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93901. {
  93902. unsigned i;
  93903. const FLAC__int32 *signal = subframe->data;
  93904. 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))
  93905. return false;
  93906. if(wasted_bits)
  93907. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93908. return false;
  93909. for(i = 0; i < samples; i++)
  93910. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93911. return false;
  93912. return true;
  93913. }
  93914. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93915. {
  93916. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93917. return false;
  93918. switch(method->type) {
  93919. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93920. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93921. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93922. return false;
  93923. break;
  93924. default:
  93925. FLAC__ASSERT(0);
  93926. }
  93927. return true;
  93928. }
  93929. 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)
  93930. {
  93931. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93932. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93933. if(partition_order == 0) {
  93934. unsigned i;
  93935. if(raw_bits[0] == 0) {
  93936. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93937. return false;
  93938. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93939. return false;
  93940. }
  93941. else {
  93942. FLAC__ASSERT(rice_parameters[0] == 0);
  93943. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93944. return false;
  93945. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93946. return false;
  93947. for(i = 0; i < residual_samples; i++) {
  93948. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93949. return false;
  93950. }
  93951. }
  93952. return true;
  93953. }
  93954. else {
  93955. unsigned i, j, k = 0, k_last = 0;
  93956. unsigned partition_samples;
  93957. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93958. for(i = 0; i < (1u<<partition_order); i++) {
  93959. partition_samples = default_partition_samples;
  93960. if(i == 0)
  93961. partition_samples -= predictor_order;
  93962. k += partition_samples;
  93963. if(raw_bits[i] == 0) {
  93964. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93965. return false;
  93966. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93967. return false;
  93968. }
  93969. else {
  93970. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93971. return false;
  93972. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93973. return false;
  93974. for(j = k_last; j < k; j++) {
  93975. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93976. return false;
  93977. }
  93978. }
  93979. k_last = k;
  93980. }
  93981. return true;
  93982. }
  93983. }
  93984. #endif
  93985. /*** End of inlined file: stream_encoder_framing.c ***/
  93986. /*** Start of inlined file: window_flac.c ***/
  93987. /*** Start of inlined file: juce_FlacHeader.h ***/
  93988. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93989. // tasks..
  93990. #define VERSION "1.2.1"
  93991. #define FLAC__NO_DLL 1
  93992. #if JUCE_MSVC
  93993. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93994. #endif
  93995. #if JUCE_MAC
  93996. #define FLAC__SYS_DARWIN 1
  93997. #endif
  93998. /*** End of inlined file: juce_FlacHeader.h ***/
  93999. #if JUCE_USE_FLAC
  94000. #if HAVE_CONFIG_H
  94001. # include <config.h>
  94002. #endif
  94003. #include <math.h>
  94004. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  94005. #ifndef M_PI
  94006. #define M_PI 3.14159265358979323846
  94007. #endif
  94008. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  94009. {
  94010. const FLAC__int32 N = L - 1;
  94011. FLAC__int32 n;
  94012. if (L & 1) {
  94013. for (n = 0; n <= N/2; n++)
  94014. window[n] = 2.0f * n / (float)N;
  94015. for (; n <= N; n++)
  94016. window[n] = 2.0f - 2.0f * n / (float)N;
  94017. }
  94018. else {
  94019. for (n = 0; n <= L/2-1; n++)
  94020. window[n] = 2.0f * n / (float)N;
  94021. for (; n <= N; n++)
  94022. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  94023. }
  94024. }
  94025. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  94026. {
  94027. const FLAC__int32 N = L - 1;
  94028. FLAC__int32 n;
  94029. for (n = 0; n < L; n++)
  94030. 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)));
  94031. }
  94032. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  94033. {
  94034. const FLAC__int32 N = L - 1;
  94035. FLAC__int32 n;
  94036. for (n = 0; n < L; n++)
  94037. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  94038. }
  94039. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  94040. {
  94041. const FLAC__int32 N = L - 1;
  94042. FLAC__int32 n;
  94043. for (n = 0; n <= N; n++)
  94044. 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));
  94045. }
  94046. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  94047. {
  94048. const FLAC__int32 N = L - 1;
  94049. const double N2 = (double)N / 2.;
  94050. FLAC__int32 n;
  94051. for (n = 0; n <= N; n++) {
  94052. double k = ((double)n - N2) / N2;
  94053. k = 1.0f - k * k;
  94054. window[n] = (FLAC__real)(k * k);
  94055. }
  94056. }
  94057. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  94058. {
  94059. const FLAC__int32 N = L - 1;
  94060. FLAC__int32 n;
  94061. for (n = 0; n < L; n++)
  94062. 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));
  94063. }
  94064. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  94065. {
  94066. const FLAC__int32 N = L - 1;
  94067. const double N2 = (double)N / 2.;
  94068. FLAC__int32 n;
  94069. for (n = 0; n <= N; n++) {
  94070. const double k = ((double)n - N2) / (stddev * N2);
  94071. window[n] = (FLAC__real)exp(-0.5f * k * k);
  94072. }
  94073. }
  94074. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  94075. {
  94076. const FLAC__int32 N = L - 1;
  94077. FLAC__int32 n;
  94078. for (n = 0; n < L; n++)
  94079. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  94080. }
  94081. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  94082. {
  94083. const FLAC__int32 N = L - 1;
  94084. FLAC__int32 n;
  94085. for (n = 0; n < L; n++)
  94086. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  94087. }
  94088. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  94089. {
  94090. const FLAC__int32 N = L - 1;
  94091. FLAC__int32 n;
  94092. for (n = 0; n < L; n++)
  94093. 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));
  94094. }
  94095. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  94096. {
  94097. const FLAC__int32 N = L - 1;
  94098. FLAC__int32 n;
  94099. for (n = 0; n < L; n++)
  94100. 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));
  94101. }
  94102. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  94103. {
  94104. FLAC__int32 n;
  94105. for (n = 0; n < L; n++)
  94106. window[n] = 1.0f;
  94107. }
  94108. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  94109. {
  94110. FLAC__int32 n;
  94111. if (L & 1) {
  94112. for (n = 1; n <= L+1/2; n++)
  94113. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  94114. for (; n <= L; n++)
  94115. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  94116. }
  94117. else {
  94118. for (n = 1; n <= L/2; n++)
  94119. window[n-1] = 2.0f * n / (float)L;
  94120. for (; n <= L; n++)
  94121. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  94122. }
  94123. }
  94124. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  94125. {
  94126. if (p <= 0.0)
  94127. FLAC__window_rectangle(window, L);
  94128. else if (p >= 1.0)
  94129. FLAC__window_hann(window, L);
  94130. else {
  94131. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  94132. FLAC__int32 n;
  94133. FLAC__window_rectangle(window, L);
  94134. if (Np > 0) {
  94135. for (n = 0; n <= Np; n++) {
  94136. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  94137. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  94138. }
  94139. }
  94140. }
  94141. }
  94142. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  94143. {
  94144. const FLAC__int32 N = L - 1;
  94145. const double N2 = (double)N / 2.;
  94146. FLAC__int32 n;
  94147. for (n = 0; n <= N; n++) {
  94148. const double k = ((double)n - N2) / N2;
  94149. window[n] = (FLAC__real)(1.0f - k * k);
  94150. }
  94151. }
  94152. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  94153. #endif
  94154. /*** End of inlined file: window_flac.c ***/
  94155. #else
  94156. #include <FLAC/all.h>
  94157. #endif
  94158. }
  94159. #ifdef _MSC_VER
  94160. #pragma warning (pop)
  94161. #endif
  94162. BEGIN_JUCE_NAMESPACE
  94163. using namespace FlacNamespace;
  94164. static const char* const flacFormatName = "FLAC file";
  94165. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  94166. class FlacReader : public AudioFormatReader
  94167. {
  94168. FLAC__StreamDecoder* decoder;
  94169. AudioSampleBuffer reservoir;
  94170. int reservoirStart, samplesInReservoir;
  94171. bool ok, scanningForLength;
  94172. public:
  94173. FlacReader (InputStream* const in)
  94174. : AudioFormatReader (in, TRANS (flacFormatName)),
  94175. reservoir (2, 0),
  94176. reservoirStart (0),
  94177. samplesInReservoir (0),
  94178. scanningForLength (false)
  94179. {
  94180. using namespace FlacNamespace;
  94181. lengthInSamples = 0;
  94182. decoder = FLAC__stream_decoder_new();
  94183. ok = FLAC__stream_decoder_init_stream (decoder,
  94184. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  94185. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  94186. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  94187. if (ok)
  94188. {
  94189. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94190. if (lengthInSamples == 0 && sampleRate > 0)
  94191. {
  94192. // the length hasn't been stored in the metadata, so we'll need to
  94193. // work it out the length the hard way, by scanning the whole file..
  94194. scanningForLength = true;
  94195. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  94196. scanningForLength = false;
  94197. const int64 tempLength = lengthInSamples;
  94198. FLAC__stream_decoder_reset (decoder);
  94199. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94200. lengthInSamples = tempLength;
  94201. }
  94202. }
  94203. }
  94204. ~FlacReader()
  94205. {
  94206. FLAC__stream_decoder_delete (decoder);
  94207. }
  94208. void useMetadata (const FLAC__StreamMetadata_StreamInfo& info)
  94209. {
  94210. sampleRate = info.sample_rate;
  94211. bitsPerSample = info.bits_per_sample;
  94212. lengthInSamples = (unsigned int) info.total_samples;
  94213. numChannels = info.channels;
  94214. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  94215. }
  94216. // returns the number of samples read
  94217. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  94218. int64 startSampleInFile, int numSamples)
  94219. {
  94220. using namespace FlacNamespace;
  94221. if (! ok)
  94222. return false;
  94223. while (numSamples > 0)
  94224. {
  94225. if (startSampleInFile >= reservoirStart
  94226. && startSampleInFile < reservoirStart + samplesInReservoir)
  94227. {
  94228. const int num = (int) jmin ((int64) numSamples,
  94229. reservoirStart + samplesInReservoir - startSampleInFile);
  94230. jassert (num > 0);
  94231. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  94232. if (destSamples[i] != 0)
  94233. memcpy (destSamples[i] + startOffsetInDestBuffer,
  94234. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  94235. sizeof (int) * num);
  94236. startOffsetInDestBuffer += num;
  94237. startSampleInFile += num;
  94238. numSamples -= num;
  94239. }
  94240. else
  94241. {
  94242. if (startSampleInFile >= (int) lengthInSamples)
  94243. {
  94244. samplesInReservoir = 0;
  94245. }
  94246. else if (startSampleInFile < reservoirStart
  94247. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  94248. {
  94249. // had some problems with flac crashing if the read pos is aligned more
  94250. // accurately than this. Probably fixed in newer versions of the library, though.
  94251. reservoirStart = (int) (startSampleInFile & ~511);
  94252. samplesInReservoir = 0;
  94253. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  94254. }
  94255. else
  94256. {
  94257. reservoirStart += samplesInReservoir;
  94258. samplesInReservoir = 0;
  94259. FLAC__stream_decoder_process_single (decoder);
  94260. }
  94261. if (samplesInReservoir == 0)
  94262. break;
  94263. }
  94264. }
  94265. if (numSamples > 0)
  94266. {
  94267. for (int i = numDestChannels; --i >= 0;)
  94268. if (destSamples[i] != 0)
  94269. zeromem (destSamples[i] + startOffsetInDestBuffer,
  94270. sizeof (int) * numSamples);
  94271. }
  94272. return true;
  94273. }
  94274. void useSamples (const FLAC__int32* const buffer[], int numSamples)
  94275. {
  94276. if (scanningForLength)
  94277. {
  94278. lengthInSamples += numSamples;
  94279. }
  94280. else
  94281. {
  94282. if (numSamples > reservoir.getNumSamples())
  94283. reservoir.setSize (numChannels, numSamples, false, false, true);
  94284. const int bitsToShift = 32 - bitsPerSample;
  94285. for (int i = 0; i < (int) numChannels; ++i)
  94286. {
  94287. const FLAC__int32* src = buffer[i];
  94288. int n = i;
  94289. while (src == 0 && n > 0)
  94290. src = buffer [--n];
  94291. if (src != 0)
  94292. {
  94293. int* dest = (int*) reservoir.getSampleData(i);
  94294. for (int j = 0; j < numSamples; ++j)
  94295. dest[j] = src[j] << bitsToShift;
  94296. }
  94297. }
  94298. samplesInReservoir = numSamples;
  94299. }
  94300. }
  94301. static FLAC__StreamDecoderReadStatus readCallback_ (const FLAC__StreamDecoder*, FLAC__byte buffer[], size_t* bytes, void* client_data)
  94302. {
  94303. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94304. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94305. }
  94306. static FLAC__StreamDecoderSeekStatus seekCallback_ (const FLAC__StreamDecoder*, FLAC__uint64 absolute_byte_offset, void* client_data)
  94307. {
  94308. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94309. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94310. }
  94311. static FLAC__StreamDecoderTellStatus tellCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94312. {
  94313. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94314. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94315. }
  94316. static FLAC__StreamDecoderLengthStatus lengthCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* stream_length, void* client_data)
  94317. {
  94318. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94319. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94320. }
  94321. static FLAC__bool eofCallback_ (const FLAC__StreamDecoder*, void* client_data)
  94322. {
  94323. return ((const FlacReader*) client_data)->input->isExhausted();
  94324. }
  94325. static FLAC__StreamDecoderWriteStatus writeCallback_ (const FLAC__StreamDecoder*,
  94326. const FLAC__Frame* frame,
  94327. const FLAC__int32* const buffer[],
  94328. void* client_data)
  94329. {
  94330. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94331. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94332. }
  94333. static void metadataCallback_ (const FLAC__StreamDecoder*,
  94334. const FLAC__StreamMetadata* metadata,
  94335. void* client_data)
  94336. {
  94337. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94338. }
  94339. static void errorCallback_ (const FLAC__StreamDecoder*, FLAC__StreamDecoderErrorStatus, void*)
  94340. {
  94341. }
  94342. juce_UseDebuggingNewOperator
  94343. };
  94344. class FlacWriter : public AudioFormatWriter
  94345. {
  94346. FLAC__StreamEncoder* encoder;
  94347. MemoryBlock temp;
  94348. public:
  94349. bool ok;
  94350. FlacWriter (OutputStream* const out,
  94351. const double sampleRate_,
  94352. const int numChannels_,
  94353. const int bitsPerSample_)
  94354. : AudioFormatWriter (out, TRANS (flacFormatName),
  94355. sampleRate_,
  94356. numChannels_,
  94357. bitsPerSample_)
  94358. {
  94359. using namespace FlacNamespace;
  94360. encoder = FLAC__stream_encoder_new();
  94361. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94362. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94363. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94364. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94365. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94366. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94367. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94368. ok = FLAC__stream_encoder_init_stream (encoder,
  94369. encodeWriteCallback, encodeSeekCallback,
  94370. encodeTellCallback, encodeMetadataCallback,
  94371. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94372. }
  94373. ~FlacWriter()
  94374. {
  94375. if (ok)
  94376. {
  94377. FLAC__stream_encoder_finish (encoder);
  94378. output->flush();
  94379. }
  94380. else
  94381. {
  94382. output = 0; // to stop the base class deleting this, as it needs to be returned
  94383. // to the caller of createWriter()
  94384. }
  94385. FLAC__stream_encoder_delete (encoder);
  94386. }
  94387. bool write (const int** samplesToWrite, int numSamples)
  94388. {
  94389. if (! ok)
  94390. return false;
  94391. int* buf[3];
  94392. const int bitsToShift = 32 - bitsPerSample;
  94393. if (bitsToShift > 0)
  94394. {
  94395. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94396. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94397. buf[0] = (int*) temp.getData();
  94398. buf[1] = buf[0] + numSamples;
  94399. buf[2] = 0;
  94400. for (int i = numChannelsToWrite; --i >= 0;)
  94401. {
  94402. if (samplesToWrite[i] != 0)
  94403. {
  94404. for (int j = 0; j < numSamples; ++j)
  94405. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94406. }
  94407. }
  94408. samplesToWrite = (const int**) buf;
  94409. }
  94410. return FLAC__stream_encoder_process (encoder,
  94411. (const FLAC__int32**) samplesToWrite,
  94412. numSamples) != 0;
  94413. }
  94414. bool writeData (const void* const data, const int size) const
  94415. {
  94416. return output->write (data, size);
  94417. }
  94418. static void packUint32 (FLAC__uint32 val, FLAC__byte* b, const int bytes)
  94419. {
  94420. b += bytes;
  94421. for (int i = 0; i < bytes; ++i)
  94422. {
  94423. *(--b) = (FLAC__byte) (val & 0xff);
  94424. val >>= 8;
  94425. }
  94426. }
  94427. void writeMetaData (const FLAC__StreamMetadata* metadata)
  94428. {
  94429. using namespace FlacNamespace;
  94430. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94431. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94432. const unsigned int channelsMinus1 = info.channels - 1;
  94433. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94434. packUint32 (info.min_blocksize, buffer, 2);
  94435. packUint32 (info.max_blocksize, buffer + 2, 2);
  94436. packUint32 (info.min_framesize, buffer + 4, 3);
  94437. packUint32 (info.max_framesize, buffer + 7, 3);
  94438. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94439. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94440. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94441. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94442. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94443. memcpy (buffer + 18, info.md5sum, 16);
  94444. const bool seekOk = output->setPosition (4);
  94445. (void) seekOk;
  94446. // if this fails, you've given it an output stream that can't seek! It needs
  94447. // to be able to seek back to write the header
  94448. jassert (seekOk);
  94449. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94450. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94451. }
  94452. static FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FLAC__StreamEncoder*,
  94453. const FLAC__byte buffer[],
  94454. size_t bytes,
  94455. unsigned int /*samples*/,
  94456. unsigned int /*current_frame*/,
  94457. void* client_data)
  94458. {
  94459. using namespace FlacNamespace;
  94460. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94461. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94462. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94463. }
  94464. static FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FLAC__StreamEncoder*, FLAC__uint64, void*)
  94465. {
  94466. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94467. }
  94468. static FLAC__StreamEncoderTellStatus encodeTellCallback (const FLAC__StreamEncoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94469. {
  94470. if (client_data == 0)
  94471. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94472. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94473. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94474. }
  94475. static void encodeMetadataCallback (const FLAC__StreamEncoder*,
  94476. const FLAC__StreamMetadata* metadata,
  94477. void* client_data)
  94478. {
  94479. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94480. }
  94481. juce_UseDebuggingNewOperator
  94482. };
  94483. FlacAudioFormat::FlacAudioFormat()
  94484. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94485. {
  94486. }
  94487. FlacAudioFormat::~FlacAudioFormat()
  94488. {
  94489. }
  94490. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94491. {
  94492. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94493. return Array <int> (rates);
  94494. }
  94495. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94496. {
  94497. const int depths[] = { 16, 24, 0 };
  94498. return Array <int> (depths);
  94499. }
  94500. bool FlacAudioFormat::canDoStereo()
  94501. {
  94502. return true;
  94503. }
  94504. bool FlacAudioFormat::canDoMono()
  94505. {
  94506. return true;
  94507. }
  94508. bool FlacAudioFormat::isCompressed()
  94509. {
  94510. return true;
  94511. }
  94512. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94513. const bool deleteStreamIfOpeningFails)
  94514. {
  94515. ScopedPointer <FlacReader> r (new FlacReader (in));
  94516. if (r->sampleRate != 0)
  94517. return r.release();
  94518. if (! deleteStreamIfOpeningFails)
  94519. r->input = 0;
  94520. return 0;
  94521. }
  94522. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94523. double sampleRate,
  94524. unsigned int numberOfChannels,
  94525. int bitsPerSample,
  94526. const StringPairArray& /*metadataValues*/,
  94527. int /*qualityOptionIndex*/)
  94528. {
  94529. if (getPossibleBitDepths().contains (bitsPerSample))
  94530. {
  94531. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94532. sampleRate,
  94533. numberOfChannels,
  94534. bitsPerSample));
  94535. if (w->ok)
  94536. return w.release();
  94537. }
  94538. return 0;
  94539. }
  94540. END_JUCE_NAMESPACE
  94541. #endif
  94542. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94543. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94544. #if JUCE_USE_OGGVORBIS
  94545. #if JUCE_MAC
  94546. #define __MACOSX__ 1
  94547. #endif
  94548. namespace OggVorbisNamespace
  94549. {
  94550. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94551. /*** Start of inlined file: vorbisenc.h ***/
  94552. #ifndef _OV_ENC_H_
  94553. #define _OV_ENC_H_
  94554. #ifdef __cplusplus
  94555. extern "C"
  94556. {
  94557. #endif /* __cplusplus */
  94558. /*** Start of inlined file: codec.h ***/
  94559. #ifndef _vorbis_codec_h_
  94560. #define _vorbis_codec_h_
  94561. #ifdef __cplusplus
  94562. extern "C"
  94563. {
  94564. #endif /* __cplusplus */
  94565. /*** Start of inlined file: ogg.h ***/
  94566. #ifndef _OGG_H
  94567. #define _OGG_H
  94568. #ifdef __cplusplus
  94569. extern "C" {
  94570. #endif
  94571. /*** Start of inlined file: os_types.h ***/
  94572. #ifndef _OS_TYPES_H
  94573. #define _OS_TYPES_H
  94574. #define _ogg_malloc malloc
  94575. #define _ogg_calloc calloc
  94576. #define _ogg_realloc realloc
  94577. #define _ogg_free free
  94578. #if defined(_WIN32)
  94579. # if defined(__CYGWIN__)
  94580. # include <_G_config.h>
  94581. typedef _G_int64_t ogg_int64_t;
  94582. typedef _G_int32_t ogg_int32_t;
  94583. typedef _G_uint32_t ogg_uint32_t;
  94584. typedef _G_int16_t ogg_int16_t;
  94585. typedef _G_uint16_t ogg_uint16_t;
  94586. # elif defined(__MINGW32__)
  94587. typedef short ogg_int16_t;
  94588. typedef unsigned short ogg_uint16_t;
  94589. typedef int ogg_int32_t;
  94590. typedef unsigned int ogg_uint32_t;
  94591. typedef long long ogg_int64_t;
  94592. typedef unsigned long long ogg_uint64_t;
  94593. # elif defined(__MWERKS__)
  94594. typedef long long ogg_int64_t;
  94595. typedef int ogg_int32_t;
  94596. typedef unsigned int ogg_uint32_t;
  94597. typedef short ogg_int16_t;
  94598. typedef unsigned short ogg_uint16_t;
  94599. # else
  94600. typedef __int64 ogg_int64_t;
  94601. typedef __int32 ogg_int32_t;
  94602. typedef unsigned __int32 ogg_uint32_t;
  94603. typedef __int16 ogg_int16_t;
  94604. typedef unsigned __int16 ogg_uint16_t;
  94605. # endif
  94606. #elif defined(__MACOS__)
  94607. # include <sys/types.h>
  94608. typedef SInt16 ogg_int16_t;
  94609. typedef UInt16 ogg_uint16_t;
  94610. typedef SInt32 ogg_int32_t;
  94611. typedef UInt32 ogg_uint32_t;
  94612. typedef SInt64 ogg_int64_t;
  94613. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94614. # include <sys/types.h>
  94615. typedef int16_t ogg_int16_t;
  94616. typedef u_int16_t ogg_uint16_t;
  94617. typedef int32_t ogg_int32_t;
  94618. typedef u_int32_t ogg_uint32_t;
  94619. typedef int64_t ogg_int64_t;
  94620. #elif defined(__BEOS__)
  94621. # include <inttypes.h>
  94622. typedef int16_t ogg_int16_t;
  94623. typedef u_int16_t ogg_uint16_t;
  94624. typedef int32_t ogg_int32_t;
  94625. typedef u_int32_t ogg_uint32_t;
  94626. typedef int64_t ogg_int64_t;
  94627. #elif defined (__EMX__)
  94628. typedef short ogg_int16_t;
  94629. typedef unsigned short ogg_uint16_t;
  94630. typedef int ogg_int32_t;
  94631. typedef unsigned int ogg_uint32_t;
  94632. typedef long long ogg_int64_t;
  94633. #elif defined (DJGPP)
  94634. typedef short ogg_int16_t;
  94635. typedef int ogg_int32_t;
  94636. typedef unsigned int ogg_uint32_t;
  94637. typedef long long ogg_int64_t;
  94638. #elif defined(R5900)
  94639. typedef long ogg_int64_t;
  94640. typedef int ogg_int32_t;
  94641. typedef unsigned ogg_uint32_t;
  94642. typedef short ogg_int16_t;
  94643. #elif defined(__SYMBIAN32__)
  94644. typedef signed short ogg_int16_t;
  94645. typedef unsigned short ogg_uint16_t;
  94646. typedef signed int ogg_int32_t;
  94647. typedef unsigned int ogg_uint32_t;
  94648. typedef long long int ogg_int64_t;
  94649. #else
  94650. # include <sys/types.h>
  94651. /*** Start of inlined file: config_types.h ***/
  94652. #ifndef __CONFIG_TYPES_H__
  94653. #define __CONFIG_TYPES_H__
  94654. typedef int16_t ogg_int16_t;
  94655. typedef unsigned short ogg_uint16_t;
  94656. typedef int32_t ogg_int32_t;
  94657. typedef unsigned int ogg_uint32_t;
  94658. typedef int64_t ogg_int64_t;
  94659. #endif
  94660. /*** End of inlined file: config_types.h ***/
  94661. #endif
  94662. #endif /* _OS_TYPES_H */
  94663. /*** End of inlined file: os_types.h ***/
  94664. typedef struct {
  94665. long endbyte;
  94666. int endbit;
  94667. unsigned char *buffer;
  94668. unsigned char *ptr;
  94669. long storage;
  94670. } oggpack_buffer;
  94671. typedef struct {
  94672. unsigned char *header;
  94673. long header_len;
  94674. unsigned char *body;
  94675. long body_len;
  94676. } ogg_page;
  94677. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94678. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94679. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94680. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94681. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94682. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94683. }
  94684. typedef struct {
  94685. unsigned char *body_data; /* bytes from packet bodies */
  94686. long body_storage; /* storage elements allocated */
  94687. long body_fill; /* elements stored; fill mark */
  94688. long body_returned; /* elements of fill returned */
  94689. int *lacing_vals; /* The values that will go to the segment table */
  94690. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94691. this way, but it is simple coupled to the
  94692. lacing fifo */
  94693. long lacing_storage;
  94694. long lacing_fill;
  94695. long lacing_packet;
  94696. long lacing_returned;
  94697. unsigned char header[282]; /* working space for header encode */
  94698. int header_fill;
  94699. int e_o_s; /* set when we have buffered the last packet in the
  94700. logical bitstream */
  94701. int b_o_s; /* set after we've written the initial page
  94702. of a logical bitstream */
  94703. long serialno;
  94704. long pageno;
  94705. ogg_int64_t packetno; /* sequence number for decode; the framing
  94706. knows where there's a hole in the data,
  94707. but we need coupling so that the codec
  94708. (which is in a seperate abstraction
  94709. layer) also knows about the gap */
  94710. ogg_int64_t granulepos;
  94711. } ogg_stream_state;
  94712. typedef struct {
  94713. unsigned char *packet;
  94714. long bytes;
  94715. long b_o_s;
  94716. long e_o_s;
  94717. ogg_int64_t granulepos;
  94718. ogg_int64_t packetno; /* sequence number for decode; the framing
  94719. knows where there's a hole in the data,
  94720. but we need coupling so that the codec
  94721. (which is in a seperate abstraction
  94722. layer) also knows about the gap */
  94723. } ogg_packet;
  94724. typedef struct {
  94725. unsigned char *data;
  94726. int storage;
  94727. int fill;
  94728. int returned;
  94729. int unsynced;
  94730. int headerbytes;
  94731. int bodybytes;
  94732. } ogg_sync_state;
  94733. extern void oggpack_writeinit(oggpack_buffer *b);
  94734. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94735. extern void oggpack_writealign(oggpack_buffer *b);
  94736. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94737. extern void oggpack_reset(oggpack_buffer *b);
  94738. extern void oggpack_writeclear(oggpack_buffer *b);
  94739. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94740. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94741. extern long oggpack_look(oggpack_buffer *b,int bits);
  94742. extern long oggpack_look1(oggpack_buffer *b);
  94743. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94744. extern void oggpack_adv1(oggpack_buffer *b);
  94745. extern long oggpack_read(oggpack_buffer *b,int bits);
  94746. extern long oggpack_read1(oggpack_buffer *b);
  94747. extern long oggpack_bytes(oggpack_buffer *b);
  94748. extern long oggpack_bits(oggpack_buffer *b);
  94749. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94750. extern void oggpackB_writeinit(oggpack_buffer *b);
  94751. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94752. extern void oggpackB_writealign(oggpack_buffer *b);
  94753. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94754. extern void oggpackB_reset(oggpack_buffer *b);
  94755. extern void oggpackB_writeclear(oggpack_buffer *b);
  94756. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94757. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94758. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94759. extern long oggpackB_look1(oggpack_buffer *b);
  94760. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94761. extern void oggpackB_adv1(oggpack_buffer *b);
  94762. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94763. extern long oggpackB_read1(oggpack_buffer *b);
  94764. extern long oggpackB_bytes(oggpack_buffer *b);
  94765. extern long oggpackB_bits(oggpack_buffer *b);
  94766. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94767. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94768. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94769. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94770. extern int ogg_sync_init(ogg_sync_state *oy);
  94771. extern int ogg_sync_clear(ogg_sync_state *oy);
  94772. extern int ogg_sync_reset(ogg_sync_state *oy);
  94773. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94774. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94775. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94776. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94777. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94778. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94779. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94780. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94781. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94782. extern int ogg_stream_clear(ogg_stream_state *os);
  94783. extern int ogg_stream_reset(ogg_stream_state *os);
  94784. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94785. extern int ogg_stream_destroy(ogg_stream_state *os);
  94786. extern int ogg_stream_eos(ogg_stream_state *os);
  94787. extern void ogg_page_checksum_set(ogg_page *og);
  94788. extern int ogg_page_version(ogg_page *og);
  94789. extern int ogg_page_continued(ogg_page *og);
  94790. extern int ogg_page_bos(ogg_page *og);
  94791. extern int ogg_page_eos(ogg_page *og);
  94792. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94793. extern int ogg_page_serialno(ogg_page *og);
  94794. extern long ogg_page_pageno(ogg_page *og);
  94795. extern int ogg_page_packets(ogg_page *og);
  94796. extern void ogg_packet_clear(ogg_packet *op);
  94797. #ifdef __cplusplus
  94798. }
  94799. #endif
  94800. #endif /* _OGG_H */
  94801. /*** End of inlined file: ogg.h ***/
  94802. typedef struct vorbis_info{
  94803. int version;
  94804. int channels;
  94805. long rate;
  94806. long bitrate_upper;
  94807. long bitrate_nominal;
  94808. long bitrate_lower;
  94809. long bitrate_window;
  94810. void *codec_setup;
  94811. } vorbis_info;
  94812. typedef struct vorbis_dsp_state{
  94813. int analysisp;
  94814. vorbis_info *vi;
  94815. float **pcm;
  94816. float **pcmret;
  94817. int pcm_storage;
  94818. int pcm_current;
  94819. int pcm_returned;
  94820. int preextrapolate;
  94821. int eofflag;
  94822. long lW;
  94823. long W;
  94824. long nW;
  94825. long centerW;
  94826. ogg_int64_t granulepos;
  94827. ogg_int64_t sequence;
  94828. ogg_int64_t glue_bits;
  94829. ogg_int64_t time_bits;
  94830. ogg_int64_t floor_bits;
  94831. ogg_int64_t res_bits;
  94832. void *backend_state;
  94833. } vorbis_dsp_state;
  94834. typedef struct vorbis_block{
  94835. float **pcm; /* this is a pointer into local storage */
  94836. oggpack_buffer opb;
  94837. long lW;
  94838. long W;
  94839. long nW;
  94840. int pcmend;
  94841. int mode;
  94842. int eofflag;
  94843. ogg_int64_t granulepos;
  94844. ogg_int64_t sequence;
  94845. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94846. void *localstore;
  94847. long localtop;
  94848. long localalloc;
  94849. long totaluse;
  94850. struct alloc_chain *reap;
  94851. long glue_bits;
  94852. long time_bits;
  94853. long floor_bits;
  94854. long res_bits;
  94855. void *internal;
  94856. } vorbis_block;
  94857. struct alloc_chain{
  94858. void *ptr;
  94859. struct alloc_chain *next;
  94860. };
  94861. typedef struct vorbis_comment{
  94862. char **user_comments;
  94863. int *comment_lengths;
  94864. int comments;
  94865. char *vendor;
  94866. } vorbis_comment;
  94867. extern void vorbis_info_init(vorbis_info *vi);
  94868. extern void vorbis_info_clear(vorbis_info *vi);
  94869. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94870. extern void vorbis_comment_init(vorbis_comment *vc);
  94871. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94872. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94873. const char *tag, char *contents);
  94874. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94875. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94876. extern void vorbis_comment_clear(vorbis_comment *vc);
  94877. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94878. extern int vorbis_block_clear(vorbis_block *vb);
  94879. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94880. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94881. ogg_int64_t granulepos);
  94882. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94883. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94884. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94885. vorbis_comment *vc,
  94886. ogg_packet *op,
  94887. ogg_packet *op_comm,
  94888. ogg_packet *op_code);
  94889. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94890. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94891. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94892. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94893. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94894. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94895. ogg_packet *op);
  94896. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94897. ogg_packet *op);
  94898. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94899. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94900. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94901. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94902. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94903. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94904. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94905. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94906. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94907. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94908. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94909. #define OV_FALSE -1
  94910. #define OV_EOF -2
  94911. #define OV_HOLE -3
  94912. #define OV_EREAD -128
  94913. #define OV_EFAULT -129
  94914. #define OV_EIMPL -130
  94915. #define OV_EINVAL -131
  94916. #define OV_ENOTVORBIS -132
  94917. #define OV_EBADHEADER -133
  94918. #define OV_EVERSION -134
  94919. #define OV_ENOTAUDIO -135
  94920. #define OV_EBADPACKET -136
  94921. #define OV_EBADLINK -137
  94922. #define OV_ENOSEEK -138
  94923. #ifdef __cplusplus
  94924. }
  94925. #endif /* __cplusplus */
  94926. #endif
  94927. /*** End of inlined file: codec.h ***/
  94928. extern int vorbis_encode_init(vorbis_info *vi,
  94929. long channels,
  94930. long rate,
  94931. long max_bitrate,
  94932. long nominal_bitrate,
  94933. long min_bitrate);
  94934. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94935. long channels,
  94936. long rate,
  94937. long max_bitrate,
  94938. long nominal_bitrate,
  94939. long min_bitrate);
  94940. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94941. long channels,
  94942. long rate,
  94943. float quality /* quality level from 0. (lo) to 1. (hi) */
  94944. );
  94945. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94946. long channels,
  94947. long rate,
  94948. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94949. );
  94950. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94951. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94952. #define OV_ECTL_RATEMANAGE_GET 0x10
  94953. #define OV_ECTL_RATEMANAGE_SET 0x11
  94954. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94955. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94956. struct ovectl_ratemanage_arg {
  94957. int management_active;
  94958. long bitrate_hard_min;
  94959. long bitrate_hard_max;
  94960. double bitrate_hard_window;
  94961. long bitrate_av_lo;
  94962. long bitrate_av_hi;
  94963. double bitrate_av_window;
  94964. double bitrate_av_window_center;
  94965. };
  94966. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94967. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94968. struct ovectl_ratemanage2_arg {
  94969. int management_active;
  94970. long bitrate_limit_min_kbps;
  94971. long bitrate_limit_max_kbps;
  94972. long bitrate_limit_reservoir_bits;
  94973. double bitrate_limit_reservoir_bias;
  94974. long bitrate_average_kbps;
  94975. double bitrate_average_damping;
  94976. };
  94977. #define OV_ECTL_LOWPASS_GET 0x20
  94978. #define OV_ECTL_LOWPASS_SET 0x21
  94979. #define OV_ECTL_IBLOCK_GET 0x30
  94980. #define OV_ECTL_IBLOCK_SET 0x31
  94981. #ifdef __cplusplus
  94982. }
  94983. #endif /* __cplusplus */
  94984. #endif
  94985. /*** End of inlined file: vorbisenc.h ***/
  94986. /*** Start of inlined file: vorbisfile.h ***/
  94987. #ifndef _OV_FILE_H_
  94988. #define _OV_FILE_H_
  94989. #ifdef __cplusplus
  94990. extern "C"
  94991. {
  94992. #endif /* __cplusplus */
  94993. #include <stdio.h>
  94994. typedef struct {
  94995. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94996. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94997. int (*close_func) (void *datasource);
  94998. long (*tell_func) (void *datasource);
  94999. } ov_callbacks;
  95000. #define NOTOPEN 0
  95001. #define PARTOPEN 1
  95002. #define OPENED 2
  95003. #define STREAMSET 3
  95004. #define INITSET 4
  95005. typedef struct OggVorbis_File {
  95006. void *datasource; /* Pointer to a FILE *, etc. */
  95007. int seekable;
  95008. ogg_int64_t offset;
  95009. ogg_int64_t end;
  95010. ogg_sync_state oy;
  95011. int links;
  95012. ogg_int64_t *offsets;
  95013. ogg_int64_t *dataoffsets;
  95014. long *serialnos;
  95015. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  95016. compatability; x2 size, stores both
  95017. beginning and end values */
  95018. vorbis_info *vi;
  95019. vorbis_comment *vc;
  95020. ogg_int64_t pcm_offset;
  95021. int ready_state;
  95022. long current_serialno;
  95023. int current_link;
  95024. double bittrack;
  95025. double samptrack;
  95026. ogg_stream_state os; /* take physical pages, weld into a logical
  95027. stream of packets */
  95028. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  95029. vorbis_block vb; /* local working space for packet->PCM decode */
  95030. ov_callbacks callbacks;
  95031. } OggVorbis_File;
  95032. extern int ov_clear(OggVorbis_File *vf);
  95033. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95034. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  95035. char *initial, long ibytes, ov_callbacks callbacks);
  95036. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95037. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  95038. char *initial, long ibytes, ov_callbacks callbacks);
  95039. extern int ov_test_open(OggVorbis_File *vf);
  95040. extern long ov_bitrate(OggVorbis_File *vf,int i);
  95041. extern long ov_bitrate_instant(OggVorbis_File *vf);
  95042. extern long ov_streams(OggVorbis_File *vf);
  95043. extern long ov_seekable(OggVorbis_File *vf);
  95044. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  95045. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  95046. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  95047. extern double ov_time_total(OggVorbis_File *vf,int i);
  95048. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95049. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95050. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  95051. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  95052. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  95053. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95054. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95055. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95056. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  95057. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  95058. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  95059. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  95060. extern double ov_time_tell(OggVorbis_File *vf);
  95061. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  95062. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  95063. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  95064. int *bitstream);
  95065. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  95066. int bigendianp,int word,int sgned,int *bitstream);
  95067. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  95068. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  95069. extern int ov_halfrate_p(OggVorbis_File *vf);
  95070. #ifdef __cplusplus
  95071. }
  95072. #endif /* __cplusplus */
  95073. #endif
  95074. /*** End of inlined file: vorbisfile.h ***/
  95075. /*** Start of inlined file: bitwise.c ***/
  95076. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95077. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95078. // tasks..
  95079. #if JUCE_MSVC
  95080. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95081. #endif
  95082. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95083. #if JUCE_USE_OGGVORBIS
  95084. #include <string.h>
  95085. #include <stdlib.h>
  95086. #define BUFFER_INCREMENT 256
  95087. static const unsigned long mask[]=
  95088. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  95089. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  95090. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  95091. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  95092. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  95093. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  95094. 0x3fffffff,0x7fffffff,0xffffffff };
  95095. static const unsigned int mask8B[]=
  95096. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  95097. void oggpack_writeinit(oggpack_buffer *b){
  95098. memset(b,0,sizeof(*b));
  95099. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  95100. b->buffer[0]='\0';
  95101. b->storage=BUFFER_INCREMENT;
  95102. }
  95103. void oggpackB_writeinit(oggpack_buffer *b){
  95104. oggpack_writeinit(b);
  95105. }
  95106. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  95107. long bytes=bits>>3;
  95108. bits-=bytes*8;
  95109. b->ptr=b->buffer+bytes;
  95110. b->endbit=bits;
  95111. b->endbyte=bytes;
  95112. *b->ptr&=mask[bits];
  95113. }
  95114. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  95115. long bytes=bits>>3;
  95116. bits-=bytes*8;
  95117. b->ptr=b->buffer+bytes;
  95118. b->endbit=bits;
  95119. b->endbyte=bytes;
  95120. *b->ptr&=mask8B[bits];
  95121. }
  95122. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  95123. if(b->endbyte+4>=b->storage){
  95124. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95125. b->storage+=BUFFER_INCREMENT;
  95126. b->ptr=b->buffer+b->endbyte;
  95127. }
  95128. value&=mask[bits];
  95129. bits+=b->endbit;
  95130. b->ptr[0]|=value<<b->endbit;
  95131. if(bits>=8){
  95132. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  95133. if(bits>=16){
  95134. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  95135. if(bits>=24){
  95136. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  95137. if(bits>=32){
  95138. if(b->endbit)
  95139. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  95140. else
  95141. b->ptr[4]=0;
  95142. }
  95143. }
  95144. }
  95145. }
  95146. b->endbyte+=bits/8;
  95147. b->ptr+=bits/8;
  95148. b->endbit=bits&7;
  95149. }
  95150. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  95151. if(b->endbyte+4>=b->storage){
  95152. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95153. b->storage+=BUFFER_INCREMENT;
  95154. b->ptr=b->buffer+b->endbyte;
  95155. }
  95156. value=(value&mask[bits])<<(32-bits);
  95157. bits+=b->endbit;
  95158. b->ptr[0]|=value>>(24+b->endbit);
  95159. if(bits>=8){
  95160. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  95161. if(bits>=16){
  95162. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  95163. if(bits>=24){
  95164. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  95165. if(bits>=32){
  95166. if(b->endbit)
  95167. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  95168. else
  95169. b->ptr[4]=0;
  95170. }
  95171. }
  95172. }
  95173. }
  95174. b->endbyte+=bits/8;
  95175. b->ptr+=bits/8;
  95176. b->endbit=bits&7;
  95177. }
  95178. void oggpack_writealign(oggpack_buffer *b){
  95179. int bits=8-b->endbit;
  95180. if(bits<8)
  95181. oggpack_write(b,0,bits);
  95182. }
  95183. void oggpackB_writealign(oggpack_buffer *b){
  95184. int bits=8-b->endbit;
  95185. if(bits<8)
  95186. oggpackB_write(b,0,bits);
  95187. }
  95188. static void oggpack_writecopy_helper(oggpack_buffer *b,
  95189. void *source,
  95190. long bits,
  95191. void (*w)(oggpack_buffer *,
  95192. unsigned long,
  95193. int),
  95194. int msb){
  95195. unsigned char *ptr=(unsigned char *)source;
  95196. long bytes=bits/8;
  95197. bits-=bytes*8;
  95198. if(b->endbit){
  95199. int i;
  95200. for(i=0;i<bytes;i++)
  95201. w(b,(unsigned long)(ptr[i]),8);
  95202. }else{
  95203. if(b->endbyte+bytes+1>=b->storage){
  95204. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  95205. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  95206. b->ptr=b->buffer+b->endbyte;
  95207. }
  95208. memmove(b->ptr,source,bytes);
  95209. b->ptr+=bytes;
  95210. b->endbyte+=bytes;
  95211. *b->ptr=0;
  95212. }
  95213. if(bits){
  95214. if(msb)
  95215. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  95216. else
  95217. w(b,(unsigned long)(ptr[bytes]),bits);
  95218. }
  95219. }
  95220. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  95221. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  95222. }
  95223. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  95224. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  95225. }
  95226. void oggpack_reset(oggpack_buffer *b){
  95227. b->ptr=b->buffer;
  95228. b->buffer[0]=0;
  95229. b->endbit=b->endbyte=0;
  95230. }
  95231. void oggpackB_reset(oggpack_buffer *b){
  95232. oggpack_reset(b);
  95233. }
  95234. void oggpack_writeclear(oggpack_buffer *b){
  95235. _ogg_free(b->buffer);
  95236. memset(b,0,sizeof(*b));
  95237. }
  95238. void oggpackB_writeclear(oggpack_buffer *b){
  95239. oggpack_writeclear(b);
  95240. }
  95241. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95242. memset(b,0,sizeof(*b));
  95243. b->buffer=b->ptr=buf;
  95244. b->storage=bytes;
  95245. }
  95246. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95247. oggpack_readinit(b,buf,bytes);
  95248. }
  95249. long oggpack_look(oggpack_buffer *b,int bits){
  95250. unsigned long ret;
  95251. unsigned long m=mask[bits];
  95252. bits+=b->endbit;
  95253. if(b->endbyte+4>=b->storage){
  95254. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95255. }
  95256. ret=b->ptr[0]>>b->endbit;
  95257. if(bits>8){
  95258. ret|=b->ptr[1]<<(8-b->endbit);
  95259. if(bits>16){
  95260. ret|=b->ptr[2]<<(16-b->endbit);
  95261. if(bits>24){
  95262. ret|=b->ptr[3]<<(24-b->endbit);
  95263. if(bits>32 && b->endbit)
  95264. ret|=b->ptr[4]<<(32-b->endbit);
  95265. }
  95266. }
  95267. }
  95268. return(m&ret);
  95269. }
  95270. long oggpackB_look(oggpack_buffer *b,int bits){
  95271. unsigned long ret;
  95272. int m=32-bits;
  95273. bits+=b->endbit;
  95274. if(b->endbyte+4>=b->storage){
  95275. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95276. }
  95277. ret=b->ptr[0]<<(24+b->endbit);
  95278. if(bits>8){
  95279. ret|=b->ptr[1]<<(16+b->endbit);
  95280. if(bits>16){
  95281. ret|=b->ptr[2]<<(8+b->endbit);
  95282. if(bits>24){
  95283. ret|=b->ptr[3]<<(b->endbit);
  95284. if(bits>32 && b->endbit)
  95285. ret|=b->ptr[4]>>(8-b->endbit);
  95286. }
  95287. }
  95288. }
  95289. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95290. }
  95291. long oggpack_look1(oggpack_buffer *b){
  95292. if(b->endbyte>=b->storage)return(-1);
  95293. return((b->ptr[0]>>b->endbit)&1);
  95294. }
  95295. long oggpackB_look1(oggpack_buffer *b){
  95296. if(b->endbyte>=b->storage)return(-1);
  95297. return((b->ptr[0]>>(7-b->endbit))&1);
  95298. }
  95299. void oggpack_adv(oggpack_buffer *b,int bits){
  95300. bits+=b->endbit;
  95301. b->ptr+=bits/8;
  95302. b->endbyte+=bits/8;
  95303. b->endbit=bits&7;
  95304. }
  95305. void oggpackB_adv(oggpack_buffer *b,int bits){
  95306. oggpack_adv(b,bits);
  95307. }
  95308. void oggpack_adv1(oggpack_buffer *b){
  95309. if(++(b->endbit)>7){
  95310. b->endbit=0;
  95311. b->ptr++;
  95312. b->endbyte++;
  95313. }
  95314. }
  95315. void oggpackB_adv1(oggpack_buffer *b){
  95316. oggpack_adv1(b);
  95317. }
  95318. long oggpack_read(oggpack_buffer *b,int bits){
  95319. long ret;
  95320. unsigned long m=mask[bits];
  95321. bits+=b->endbit;
  95322. if(b->endbyte+4>=b->storage){
  95323. ret=-1L;
  95324. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95325. }
  95326. ret=b->ptr[0]>>b->endbit;
  95327. if(bits>8){
  95328. ret|=b->ptr[1]<<(8-b->endbit);
  95329. if(bits>16){
  95330. ret|=b->ptr[2]<<(16-b->endbit);
  95331. if(bits>24){
  95332. ret|=b->ptr[3]<<(24-b->endbit);
  95333. if(bits>32 && b->endbit){
  95334. ret|=b->ptr[4]<<(32-b->endbit);
  95335. }
  95336. }
  95337. }
  95338. }
  95339. ret&=m;
  95340. overflow:
  95341. b->ptr+=bits/8;
  95342. b->endbyte+=bits/8;
  95343. b->endbit=bits&7;
  95344. return(ret);
  95345. }
  95346. long oggpackB_read(oggpack_buffer *b,int bits){
  95347. long ret;
  95348. long m=32-bits;
  95349. bits+=b->endbit;
  95350. if(b->endbyte+4>=b->storage){
  95351. ret=-1L;
  95352. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95353. }
  95354. ret=b->ptr[0]<<(24+b->endbit);
  95355. if(bits>8){
  95356. ret|=b->ptr[1]<<(16+b->endbit);
  95357. if(bits>16){
  95358. ret|=b->ptr[2]<<(8+b->endbit);
  95359. if(bits>24){
  95360. ret|=b->ptr[3]<<(b->endbit);
  95361. if(bits>32 && b->endbit)
  95362. ret|=b->ptr[4]>>(8-b->endbit);
  95363. }
  95364. }
  95365. }
  95366. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95367. overflow:
  95368. b->ptr+=bits/8;
  95369. b->endbyte+=bits/8;
  95370. b->endbit=bits&7;
  95371. return(ret);
  95372. }
  95373. long oggpack_read1(oggpack_buffer *b){
  95374. long ret;
  95375. if(b->endbyte>=b->storage){
  95376. ret=-1L;
  95377. goto overflow;
  95378. }
  95379. ret=(b->ptr[0]>>b->endbit)&1;
  95380. overflow:
  95381. b->endbit++;
  95382. if(b->endbit>7){
  95383. b->endbit=0;
  95384. b->ptr++;
  95385. b->endbyte++;
  95386. }
  95387. return(ret);
  95388. }
  95389. long oggpackB_read1(oggpack_buffer *b){
  95390. long ret;
  95391. if(b->endbyte>=b->storage){
  95392. ret=-1L;
  95393. goto overflow;
  95394. }
  95395. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95396. overflow:
  95397. b->endbit++;
  95398. if(b->endbit>7){
  95399. b->endbit=0;
  95400. b->ptr++;
  95401. b->endbyte++;
  95402. }
  95403. return(ret);
  95404. }
  95405. long oggpack_bytes(oggpack_buffer *b){
  95406. return(b->endbyte+(b->endbit+7)/8);
  95407. }
  95408. long oggpack_bits(oggpack_buffer *b){
  95409. return(b->endbyte*8+b->endbit);
  95410. }
  95411. long oggpackB_bytes(oggpack_buffer *b){
  95412. return oggpack_bytes(b);
  95413. }
  95414. long oggpackB_bits(oggpack_buffer *b){
  95415. return oggpack_bits(b);
  95416. }
  95417. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95418. return(b->buffer);
  95419. }
  95420. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95421. return oggpack_get_buffer(b);
  95422. }
  95423. #ifdef _V_SELFTEST
  95424. #include <stdio.h>
  95425. static int ilog(unsigned int v){
  95426. int ret=0;
  95427. while(v){
  95428. ret++;
  95429. v>>=1;
  95430. }
  95431. return(ret);
  95432. }
  95433. oggpack_buffer o;
  95434. oggpack_buffer r;
  95435. void report(char *in){
  95436. fprintf(stderr,"%s",in);
  95437. exit(1);
  95438. }
  95439. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95440. long bytes,i;
  95441. unsigned char *buffer;
  95442. oggpack_reset(&o);
  95443. for(i=0;i<vals;i++)
  95444. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95445. buffer=oggpack_get_buffer(&o);
  95446. bytes=oggpack_bytes(&o);
  95447. if(bytes!=compsize)report("wrong number of bytes!\n");
  95448. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95449. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95450. report("wrote incorrect value!\n");
  95451. }
  95452. oggpack_readinit(&r,buffer,bytes);
  95453. for(i=0;i<vals;i++){
  95454. int tbit=bits?bits:ilog(b[i]);
  95455. if(oggpack_look(&r,tbit)==-1)
  95456. report("out of data!\n");
  95457. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95458. report("looked at incorrect value!\n");
  95459. if(tbit==1)
  95460. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95461. report("looked at single bit incorrect value!\n");
  95462. if(tbit==1){
  95463. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95464. report("read incorrect single bit value!\n");
  95465. }else{
  95466. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95467. report("read incorrect value!\n");
  95468. }
  95469. }
  95470. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95471. }
  95472. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95473. long bytes,i;
  95474. unsigned char *buffer;
  95475. oggpackB_reset(&o);
  95476. for(i=0;i<vals;i++)
  95477. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95478. buffer=oggpackB_get_buffer(&o);
  95479. bytes=oggpackB_bytes(&o);
  95480. if(bytes!=compsize)report("wrong number of bytes!\n");
  95481. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95482. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95483. report("wrote incorrect value!\n");
  95484. }
  95485. oggpackB_readinit(&r,buffer,bytes);
  95486. for(i=0;i<vals;i++){
  95487. int tbit=bits?bits:ilog(b[i]);
  95488. if(oggpackB_look(&r,tbit)==-1)
  95489. report("out of data!\n");
  95490. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95491. report("looked at incorrect value!\n");
  95492. if(tbit==1)
  95493. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95494. report("looked at single bit incorrect value!\n");
  95495. if(tbit==1){
  95496. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95497. report("read incorrect single bit value!\n");
  95498. }else{
  95499. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95500. report("read incorrect value!\n");
  95501. }
  95502. }
  95503. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95504. }
  95505. int main(void){
  95506. unsigned char *buffer;
  95507. long bytes,i;
  95508. static unsigned long testbuffer1[]=
  95509. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95510. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95511. int test1size=43;
  95512. static unsigned long testbuffer2[]=
  95513. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95514. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95515. 85525151,0,12321,1,349528352};
  95516. int test2size=21;
  95517. static unsigned long testbuffer3[]=
  95518. {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,
  95519. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95520. int test3size=56;
  95521. static unsigned long large[]=
  95522. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95523. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95524. 85525151,0,12321,1,2146528352};
  95525. int onesize=33;
  95526. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95527. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95528. 223,4};
  95529. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95530. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95531. 245,251,128};
  95532. int twosize=6;
  95533. static int two[6]={61,255,255,251,231,29};
  95534. static int twoB[6]={247,63,255,253,249,120};
  95535. int threesize=54;
  95536. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95537. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95538. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95539. 100,52,4,14,18,86,77,1};
  95540. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95541. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95542. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95543. 200,20,254,4,58,106,176,144,0};
  95544. int foursize=38;
  95545. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95546. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95547. 28,2,133,0,1};
  95548. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95549. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95550. 129,10,4,32};
  95551. int fivesize=45;
  95552. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95553. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95554. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95555. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95556. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95557. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95558. int sixsize=7;
  95559. static int six[7]={17,177,170,242,169,19,148};
  95560. static int sixB[7]={136,141,85,79,149,200,41};
  95561. oggpack_writeinit(&o);
  95562. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95563. cliptest(testbuffer1,test1size,0,one,onesize);
  95564. fprintf(stderr,"ok.");
  95565. fprintf(stderr,"\nNull bit call (LSb): ");
  95566. cliptest(testbuffer3,test3size,0,two,twosize);
  95567. fprintf(stderr,"ok.");
  95568. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95569. cliptest(testbuffer2,test2size,0,three,threesize);
  95570. fprintf(stderr,"ok.");
  95571. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95572. oggpack_reset(&o);
  95573. for(i=0;i<test2size;i++)
  95574. oggpack_write(&o,large[i],32);
  95575. buffer=oggpack_get_buffer(&o);
  95576. bytes=oggpack_bytes(&o);
  95577. oggpack_readinit(&r,buffer,bytes);
  95578. for(i=0;i<test2size;i++){
  95579. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95580. if(oggpack_look(&r,32)!=large[i]){
  95581. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95582. oggpack_look(&r,32),large[i]);
  95583. report("read incorrect value!\n");
  95584. }
  95585. oggpack_adv(&r,32);
  95586. }
  95587. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95588. fprintf(stderr,"ok.");
  95589. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95590. cliptest(testbuffer1,test1size,7,four,foursize);
  95591. fprintf(stderr,"ok.");
  95592. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95593. cliptest(testbuffer2,test2size,17,five,fivesize);
  95594. fprintf(stderr,"ok.");
  95595. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95596. cliptest(testbuffer3,test3size,1,six,sixsize);
  95597. fprintf(stderr,"ok.");
  95598. fprintf(stderr,"\nTesting read past end (LSb): ");
  95599. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95600. for(i=0;i<64;i++){
  95601. if(oggpack_read(&r,1)!=0){
  95602. fprintf(stderr,"failed; got -1 prematurely.\n");
  95603. exit(1);
  95604. }
  95605. }
  95606. if(oggpack_look(&r,1)!=-1 ||
  95607. oggpack_read(&r,1)!=-1){
  95608. fprintf(stderr,"failed; read past end without -1.\n");
  95609. exit(1);
  95610. }
  95611. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95612. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95613. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95614. exit(1);
  95615. }
  95616. if(oggpack_look(&r,18)!=0 ||
  95617. oggpack_look(&r,18)!=0){
  95618. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95619. exit(1);
  95620. }
  95621. if(oggpack_look(&r,19)!=-1 ||
  95622. oggpack_look(&r,19)!=-1){
  95623. fprintf(stderr,"failed; read past end without -1.\n");
  95624. exit(1);
  95625. }
  95626. if(oggpack_look(&r,32)!=-1 ||
  95627. oggpack_look(&r,32)!=-1){
  95628. fprintf(stderr,"failed; read past end without -1.\n");
  95629. exit(1);
  95630. }
  95631. oggpack_writeclear(&o);
  95632. fprintf(stderr,"ok.\n");
  95633. oggpackB_writeinit(&o);
  95634. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95635. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95636. fprintf(stderr,"ok.");
  95637. fprintf(stderr,"\nNull bit call (MSb): ");
  95638. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95639. fprintf(stderr,"ok.");
  95640. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95641. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95642. fprintf(stderr,"ok.");
  95643. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95644. oggpackB_reset(&o);
  95645. for(i=0;i<test2size;i++)
  95646. oggpackB_write(&o,large[i],32);
  95647. buffer=oggpackB_get_buffer(&o);
  95648. bytes=oggpackB_bytes(&o);
  95649. oggpackB_readinit(&r,buffer,bytes);
  95650. for(i=0;i<test2size;i++){
  95651. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95652. if(oggpackB_look(&r,32)!=large[i]){
  95653. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95654. oggpackB_look(&r,32),large[i]);
  95655. report("read incorrect value!\n");
  95656. }
  95657. oggpackB_adv(&r,32);
  95658. }
  95659. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95660. fprintf(stderr,"ok.");
  95661. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95662. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95663. fprintf(stderr,"ok.");
  95664. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95665. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95666. fprintf(stderr,"ok.");
  95667. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95668. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95669. fprintf(stderr,"ok.");
  95670. fprintf(stderr,"\nTesting read past end (MSb): ");
  95671. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95672. for(i=0;i<64;i++){
  95673. if(oggpackB_read(&r,1)!=0){
  95674. fprintf(stderr,"failed; got -1 prematurely.\n");
  95675. exit(1);
  95676. }
  95677. }
  95678. if(oggpackB_look(&r,1)!=-1 ||
  95679. oggpackB_read(&r,1)!=-1){
  95680. fprintf(stderr,"failed; read past end without -1.\n");
  95681. exit(1);
  95682. }
  95683. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95684. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95685. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95686. exit(1);
  95687. }
  95688. if(oggpackB_look(&r,18)!=0 ||
  95689. oggpackB_look(&r,18)!=0){
  95690. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95691. exit(1);
  95692. }
  95693. if(oggpackB_look(&r,19)!=-1 ||
  95694. oggpackB_look(&r,19)!=-1){
  95695. fprintf(stderr,"failed; read past end without -1.\n");
  95696. exit(1);
  95697. }
  95698. if(oggpackB_look(&r,32)!=-1 ||
  95699. oggpackB_look(&r,32)!=-1){
  95700. fprintf(stderr,"failed; read past end without -1.\n");
  95701. exit(1);
  95702. }
  95703. oggpackB_writeclear(&o);
  95704. fprintf(stderr,"ok.\n\n");
  95705. return(0);
  95706. }
  95707. #endif /* _V_SELFTEST */
  95708. #undef BUFFER_INCREMENT
  95709. #endif
  95710. /*** End of inlined file: bitwise.c ***/
  95711. /*** Start of inlined file: framing.c ***/
  95712. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95713. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95714. // tasks..
  95715. #if JUCE_MSVC
  95716. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95717. #endif
  95718. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95719. #if JUCE_USE_OGGVORBIS
  95720. #include <stdlib.h>
  95721. #include <string.h>
  95722. int ogg_page_version(ogg_page *og){
  95723. return((int)(og->header[4]));
  95724. }
  95725. int ogg_page_continued(ogg_page *og){
  95726. return((int)(og->header[5]&0x01));
  95727. }
  95728. int ogg_page_bos(ogg_page *og){
  95729. return((int)(og->header[5]&0x02));
  95730. }
  95731. int ogg_page_eos(ogg_page *og){
  95732. return((int)(og->header[5]&0x04));
  95733. }
  95734. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95735. unsigned char *page=og->header;
  95736. ogg_int64_t granulepos=page[13]&(0xff);
  95737. granulepos= (granulepos<<8)|(page[12]&0xff);
  95738. granulepos= (granulepos<<8)|(page[11]&0xff);
  95739. granulepos= (granulepos<<8)|(page[10]&0xff);
  95740. granulepos= (granulepos<<8)|(page[9]&0xff);
  95741. granulepos= (granulepos<<8)|(page[8]&0xff);
  95742. granulepos= (granulepos<<8)|(page[7]&0xff);
  95743. granulepos= (granulepos<<8)|(page[6]&0xff);
  95744. return(granulepos);
  95745. }
  95746. int ogg_page_serialno(ogg_page *og){
  95747. return(og->header[14] |
  95748. (og->header[15]<<8) |
  95749. (og->header[16]<<16) |
  95750. (og->header[17]<<24));
  95751. }
  95752. long ogg_page_pageno(ogg_page *og){
  95753. return(og->header[18] |
  95754. (og->header[19]<<8) |
  95755. (og->header[20]<<16) |
  95756. (og->header[21]<<24));
  95757. }
  95758. int ogg_page_packets(ogg_page *og){
  95759. int i,n=og->header[26],count=0;
  95760. for(i=0;i<n;i++)
  95761. if(og->header[27+i]<255)count++;
  95762. return(count);
  95763. }
  95764. #if 0
  95765. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95766. int i;
  95767. unsigned long r;
  95768. r = index << 24;
  95769. for (i=0; i<8; i++)
  95770. if (r & 0x80000000UL)
  95771. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95772. polynomial, although we use an
  95773. unreflected alg and an init/final
  95774. of 0, not 0xffffffff */
  95775. else
  95776. r<<=1;
  95777. return (r & 0xffffffffUL);
  95778. }
  95779. #endif
  95780. static const ogg_uint32_t crc_lookup[256]={
  95781. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95782. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95783. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95784. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95785. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95786. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95787. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95788. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95789. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95790. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95791. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95792. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95793. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95794. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95795. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95796. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95797. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95798. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95799. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95800. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95801. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95802. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95803. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95804. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95805. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95806. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95807. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95808. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95809. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95810. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95811. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95812. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95813. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95814. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95815. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95816. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95817. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95818. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95819. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95820. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95821. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95822. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95823. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95824. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95825. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95826. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95827. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95828. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95829. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95830. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95831. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95832. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95833. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95834. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95835. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95836. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95837. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95838. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95839. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95840. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95841. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95842. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95843. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95844. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95845. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95846. if(os){
  95847. memset(os,0,sizeof(*os));
  95848. os->body_storage=16*1024;
  95849. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95850. os->lacing_storage=1024;
  95851. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95852. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95853. os->serialno=serialno;
  95854. return(0);
  95855. }
  95856. return(-1);
  95857. }
  95858. int ogg_stream_clear(ogg_stream_state *os){
  95859. if(os){
  95860. if(os->body_data)_ogg_free(os->body_data);
  95861. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95862. if(os->granule_vals)_ogg_free(os->granule_vals);
  95863. memset(os,0,sizeof(*os));
  95864. }
  95865. return(0);
  95866. }
  95867. int ogg_stream_destroy(ogg_stream_state *os){
  95868. if(os){
  95869. ogg_stream_clear(os);
  95870. _ogg_free(os);
  95871. }
  95872. return(0);
  95873. }
  95874. static void _os_body_expand(ogg_stream_state *os,int needed){
  95875. if(os->body_storage<=os->body_fill+needed){
  95876. os->body_storage+=(needed+1024);
  95877. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95878. }
  95879. }
  95880. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95881. if(os->lacing_storage<=os->lacing_fill+needed){
  95882. os->lacing_storage+=(needed+32);
  95883. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95884. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95885. }
  95886. }
  95887. void ogg_page_checksum_set(ogg_page *og){
  95888. if(og){
  95889. ogg_uint32_t crc_reg=0;
  95890. int i;
  95891. og->header[22]=0;
  95892. og->header[23]=0;
  95893. og->header[24]=0;
  95894. og->header[25]=0;
  95895. for(i=0;i<og->header_len;i++)
  95896. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95897. for(i=0;i<og->body_len;i++)
  95898. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95899. og->header[22]=(unsigned char)(crc_reg&0xff);
  95900. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95901. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95902. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95903. }
  95904. }
  95905. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95906. int lacing_vals=op->bytes/255+1,i;
  95907. if(os->body_returned){
  95908. os->body_fill-=os->body_returned;
  95909. if(os->body_fill)
  95910. memmove(os->body_data,os->body_data+os->body_returned,
  95911. os->body_fill);
  95912. os->body_returned=0;
  95913. }
  95914. _os_body_expand(os,op->bytes);
  95915. _os_lacing_expand(os,lacing_vals);
  95916. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95917. os->body_fill+=op->bytes;
  95918. for(i=0;i<lacing_vals-1;i++){
  95919. os->lacing_vals[os->lacing_fill+i]=255;
  95920. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95921. }
  95922. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95923. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95924. os->lacing_vals[os->lacing_fill]|= 0x100;
  95925. os->lacing_fill+=lacing_vals;
  95926. os->packetno++;
  95927. if(op->e_o_s)os->e_o_s=1;
  95928. return(0);
  95929. }
  95930. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95931. int i;
  95932. int vals=0;
  95933. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95934. int bytes=0;
  95935. long acc=0;
  95936. ogg_int64_t granule_pos=-1;
  95937. if(maxvals==0)return(0);
  95938. if(os->b_o_s==0){ /* 'initial header page' case */
  95939. granule_pos=0;
  95940. for(vals=0;vals<maxvals;vals++){
  95941. if((os->lacing_vals[vals]&0x0ff)<255){
  95942. vals++;
  95943. break;
  95944. }
  95945. }
  95946. }else{
  95947. for(vals=0;vals<maxvals;vals++){
  95948. if(acc>4096)break;
  95949. acc+=os->lacing_vals[vals]&0x0ff;
  95950. if((os->lacing_vals[vals]&0xff)<255)
  95951. granule_pos=os->granule_vals[vals];
  95952. }
  95953. }
  95954. memcpy(os->header,"OggS",4);
  95955. os->header[4]=0x00;
  95956. os->header[5]=0x00;
  95957. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95958. if(os->b_o_s==0)os->header[5]|=0x02;
  95959. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95960. os->b_o_s=1;
  95961. for(i=6;i<14;i++){
  95962. os->header[i]=(unsigned char)(granule_pos&0xff);
  95963. granule_pos>>=8;
  95964. }
  95965. {
  95966. long serialno=os->serialno;
  95967. for(i=14;i<18;i++){
  95968. os->header[i]=(unsigned char)(serialno&0xff);
  95969. serialno>>=8;
  95970. }
  95971. }
  95972. if(os->pageno==-1)os->pageno=0; /* because someone called
  95973. stream_reset; this would be a
  95974. strange thing to do in an
  95975. encode stream, but it has
  95976. plausible uses */
  95977. {
  95978. long pageno=os->pageno++;
  95979. for(i=18;i<22;i++){
  95980. os->header[i]=(unsigned char)(pageno&0xff);
  95981. pageno>>=8;
  95982. }
  95983. }
  95984. os->header[22]=0;
  95985. os->header[23]=0;
  95986. os->header[24]=0;
  95987. os->header[25]=0;
  95988. os->header[26]=(unsigned char)(vals&0xff);
  95989. for(i=0;i<vals;i++)
  95990. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95991. og->header=os->header;
  95992. og->header_len=os->header_fill=vals+27;
  95993. og->body=os->body_data+os->body_returned;
  95994. og->body_len=bytes;
  95995. os->lacing_fill-=vals;
  95996. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95997. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95998. os->body_returned+=bytes;
  95999. ogg_page_checksum_set(og);
  96000. return(1);
  96001. }
  96002. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  96003. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  96004. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  96005. os->lacing_fill>=255 || /* 'segment table full' case */
  96006. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  96007. return(ogg_stream_flush(os,og));
  96008. }
  96009. return(0);
  96010. }
  96011. int ogg_stream_eos(ogg_stream_state *os){
  96012. return os->e_o_s;
  96013. }
  96014. int ogg_sync_init(ogg_sync_state *oy){
  96015. if(oy){
  96016. memset(oy,0,sizeof(*oy));
  96017. }
  96018. return(0);
  96019. }
  96020. int ogg_sync_clear(ogg_sync_state *oy){
  96021. if(oy){
  96022. if(oy->data)_ogg_free(oy->data);
  96023. ogg_sync_init(oy);
  96024. }
  96025. return(0);
  96026. }
  96027. int ogg_sync_destroy(ogg_sync_state *oy){
  96028. if(oy){
  96029. ogg_sync_clear(oy);
  96030. _ogg_free(oy);
  96031. }
  96032. return(0);
  96033. }
  96034. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  96035. if(oy->returned){
  96036. oy->fill-=oy->returned;
  96037. if(oy->fill>0)
  96038. memmove(oy->data,oy->data+oy->returned,oy->fill);
  96039. oy->returned=0;
  96040. }
  96041. if(size>oy->storage-oy->fill){
  96042. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  96043. if(oy->data)
  96044. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  96045. else
  96046. oy->data=(unsigned char*) _ogg_malloc(newsize);
  96047. oy->storage=newsize;
  96048. }
  96049. return((char *)oy->data+oy->fill);
  96050. }
  96051. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  96052. if(oy->fill+bytes>oy->storage)return(-1);
  96053. oy->fill+=bytes;
  96054. return(0);
  96055. }
  96056. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  96057. unsigned char *page=oy->data+oy->returned;
  96058. unsigned char *next;
  96059. long bytes=oy->fill-oy->returned;
  96060. if(oy->headerbytes==0){
  96061. int headerbytes,i;
  96062. if(bytes<27)return(0); /* not enough for a header */
  96063. if(memcmp(page,"OggS",4))goto sync_fail;
  96064. headerbytes=page[26]+27;
  96065. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  96066. for(i=0;i<page[26];i++)
  96067. oy->bodybytes+=page[27+i];
  96068. oy->headerbytes=headerbytes;
  96069. }
  96070. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  96071. {
  96072. char chksum[4];
  96073. ogg_page log;
  96074. memcpy(chksum,page+22,4);
  96075. memset(page+22,0,4);
  96076. log.header=page;
  96077. log.header_len=oy->headerbytes;
  96078. log.body=page+oy->headerbytes;
  96079. log.body_len=oy->bodybytes;
  96080. ogg_page_checksum_set(&log);
  96081. if(memcmp(chksum,page+22,4)){
  96082. memcpy(page+22,chksum,4);
  96083. goto sync_fail;
  96084. }
  96085. }
  96086. {
  96087. unsigned char *page=oy->data+oy->returned;
  96088. long bytes;
  96089. if(og){
  96090. og->header=page;
  96091. og->header_len=oy->headerbytes;
  96092. og->body=page+oy->headerbytes;
  96093. og->body_len=oy->bodybytes;
  96094. }
  96095. oy->unsynced=0;
  96096. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  96097. oy->headerbytes=0;
  96098. oy->bodybytes=0;
  96099. return(bytes);
  96100. }
  96101. sync_fail:
  96102. oy->headerbytes=0;
  96103. oy->bodybytes=0;
  96104. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  96105. if(!next)
  96106. next=oy->data+oy->fill;
  96107. oy->returned=next-oy->data;
  96108. return(-(next-page));
  96109. }
  96110. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  96111. for(;;){
  96112. long ret=ogg_sync_pageseek(oy,og);
  96113. if(ret>0){
  96114. return(1);
  96115. }
  96116. if(ret==0){
  96117. return(0);
  96118. }
  96119. if(!oy->unsynced){
  96120. oy->unsynced=1;
  96121. return(-1);
  96122. }
  96123. }
  96124. }
  96125. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  96126. unsigned char *header=og->header;
  96127. unsigned char *body=og->body;
  96128. long bodysize=og->body_len;
  96129. int segptr=0;
  96130. int version=ogg_page_version(og);
  96131. int continued=ogg_page_continued(og);
  96132. int bos=ogg_page_bos(og);
  96133. int eos=ogg_page_eos(og);
  96134. ogg_int64_t granulepos=ogg_page_granulepos(og);
  96135. int serialno=ogg_page_serialno(og);
  96136. long pageno=ogg_page_pageno(og);
  96137. int segments=header[26];
  96138. {
  96139. long lr=os->lacing_returned;
  96140. long br=os->body_returned;
  96141. if(br){
  96142. os->body_fill-=br;
  96143. if(os->body_fill)
  96144. memmove(os->body_data,os->body_data+br,os->body_fill);
  96145. os->body_returned=0;
  96146. }
  96147. if(lr){
  96148. if(os->lacing_fill-lr){
  96149. memmove(os->lacing_vals,os->lacing_vals+lr,
  96150. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  96151. memmove(os->granule_vals,os->granule_vals+lr,
  96152. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  96153. }
  96154. os->lacing_fill-=lr;
  96155. os->lacing_packet-=lr;
  96156. os->lacing_returned=0;
  96157. }
  96158. }
  96159. if(serialno!=os->serialno)return(-1);
  96160. if(version>0)return(-1);
  96161. _os_lacing_expand(os,segments+1);
  96162. if(pageno!=os->pageno){
  96163. int i;
  96164. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  96165. os->body_fill-=os->lacing_vals[i]&0xff;
  96166. os->lacing_fill=os->lacing_packet;
  96167. if(os->pageno!=-1){
  96168. os->lacing_vals[os->lacing_fill++]=0x400;
  96169. os->lacing_packet++;
  96170. }
  96171. }
  96172. if(continued){
  96173. if(os->lacing_fill<1 ||
  96174. os->lacing_vals[os->lacing_fill-1]==0x400){
  96175. bos=0;
  96176. for(;segptr<segments;segptr++){
  96177. int val=header[27+segptr];
  96178. body+=val;
  96179. bodysize-=val;
  96180. if(val<255){
  96181. segptr++;
  96182. break;
  96183. }
  96184. }
  96185. }
  96186. }
  96187. if(bodysize){
  96188. _os_body_expand(os,bodysize);
  96189. memcpy(os->body_data+os->body_fill,body,bodysize);
  96190. os->body_fill+=bodysize;
  96191. }
  96192. {
  96193. int saved=-1;
  96194. while(segptr<segments){
  96195. int val=header[27+segptr];
  96196. os->lacing_vals[os->lacing_fill]=val;
  96197. os->granule_vals[os->lacing_fill]=-1;
  96198. if(bos){
  96199. os->lacing_vals[os->lacing_fill]|=0x100;
  96200. bos=0;
  96201. }
  96202. if(val<255)saved=os->lacing_fill;
  96203. os->lacing_fill++;
  96204. segptr++;
  96205. if(val<255)os->lacing_packet=os->lacing_fill;
  96206. }
  96207. if(saved!=-1){
  96208. os->granule_vals[saved]=granulepos;
  96209. }
  96210. }
  96211. if(eos){
  96212. os->e_o_s=1;
  96213. if(os->lacing_fill>0)
  96214. os->lacing_vals[os->lacing_fill-1]|=0x200;
  96215. }
  96216. os->pageno=pageno+1;
  96217. return(0);
  96218. }
  96219. int ogg_sync_reset(ogg_sync_state *oy){
  96220. oy->fill=0;
  96221. oy->returned=0;
  96222. oy->unsynced=0;
  96223. oy->headerbytes=0;
  96224. oy->bodybytes=0;
  96225. return(0);
  96226. }
  96227. int ogg_stream_reset(ogg_stream_state *os){
  96228. os->body_fill=0;
  96229. os->body_returned=0;
  96230. os->lacing_fill=0;
  96231. os->lacing_packet=0;
  96232. os->lacing_returned=0;
  96233. os->header_fill=0;
  96234. os->e_o_s=0;
  96235. os->b_o_s=0;
  96236. os->pageno=-1;
  96237. os->packetno=0;
  96238. os->granulepos=0;
  96239. return(0);
  96240. }
  96241. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  96242. ogg_stream_reset(os);
  96243. os->serialno=serialno;
  96244. return(0);
  96245. }
  96246. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  96247. int ptr=os->lacing_returned;
  96248. if(os->lacing_packet<=ptr)return(0);
  96249. if(os->lacing_vals[ptr]&0x400){
  96250. os->lacing_returned++;
  96251. os->packetno++;
  96252. return(-1);
  96253. }
  96254. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  96255. to ask if there's a whole packet
  96256. waiting */
  96257. {
  96258. int size=os->lacing_vals[ptr]&0xff;
  96259. int bytes=size;
  96260. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  96261. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  96262. while(size==255){
  96263. int val=os->lacing_vals[++ptr];
  96264. size=val&0xff;
  96265. if(val&0x200)eos=0x200;
  96266. bytes+=size;
  96267. }
  96268. if(op){
  96269. op->e_o_s=eos;
  96270. op->b_o_s=bos;
  96271. op->packet=os->body_data+os->body_returned;
  96272. op->packetno=os->packetno;
  96273. op->granulepos=os->granule_vals[ptr];
  96274. op->bytes=bytes;
  96275. }
  96276. if(adv){
  96277. os->body_returned+=bytes;
  96278. os->lacing_returned=ptr+1;
  96279. os->packetno++;
  96280. }
  96281. }
  96282. return(1);
  96283. }
  96284. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96285. return _packetout(os,op,1);
  96286. }
  96287. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96288. return _packetout(os,op,0);
  96289. }
  96290. void ogg_packet_clear(ogg_packet *op) {
  96291. _ogg_free(op->packet);
  96292. memset(op, 0, sizeof(*op));
  96293. }
  96294. #ifdef _V_SELFTEST
  96295. #include <stdio.h>
  96296. ogg_stream_state os_en, os_de;
  96297. ogg_sync_state oy;
  96298. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96299. long j;
  96300. static int sequence=0;
  96301. static int lastno=0;
  96302. if(op->bytes!=len){
  96303. fprintf(stderr,"incorrect packet length!\n");
  96304. exit(1);
  96305. }
  96306. if(op->granulepos!=pos){
  96307. fprintf(stderr,"incorrect packet position!\n");
  96308. exit(1);
  96309. }
  96310. if(no==0){
  96311. sequence=0;
  96312. }else{
  96313. sequence++;
  96314. if(no>lastno+1)
  96315. sequence++;
  96316. }
  96317. lastno=no;
  96318. if(op->packetno!=sequence){
  96319. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96320. (long)(op->packetno),sequence);
  96321. exit(1);
  96322. }
  96323. for(j=0;j<op->bytes;j++)
  96324. if(op->packet[j]!=((j+no)&0xff)){
  96325. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96326. j,op->packet[j],(j+no)&0xff);
  96327. exit(1);
  96328. }
  96329. }
  96330. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96331. long j;
  96332. for(j=0;j<og->body_len;j++)
  96333. if(og->body[j]!=data[j]){
  96334. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96335. j,data[j],og->body[j]);
  96336. exit(1);
  96337. }
  96338. for(j=0;j<og->header_len;j++){
  96339. if(og->header[j]!=header[j]){
  96340. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96341. for(j=0;j<header[26]+27;j++)
  96342. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96343. fprintf(stderr,"\n");
  96344. exit(1);
  96345. }
  96346. }
  96347. if(og->header_len!=header[26]+27){
  96348. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96349. og->header_len,header[26]+27);
  96350. exit(1);
  96351. }
  96352. }
  96353. void print_header(ogg_page *og){
  96354. int j;
  96355. fprintf(stderr,"\nHEADER:\n");
  96356. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96357. og->header[0],og->header[1],og->header[2],og->header[3],
  96358. (int)og->header[4],(int)og->header[5]);
  96359. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96360. (og->header[9]<<24)|(og->header[8]<<16)|
  96361. (og->header[7]<<8)|og->header[6],
  96362. (og->header[17]<<24)|(og->header[16]<<16)|
  96363. (og->header[15]<<8)|og->header[14],
  96364. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96365. (og->header[19]<<8)|og->header[18]);
  96366. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96367. (int)og->header[22],(int)og->header[23],
  96368. (int)og->header[24],(int)og->header[25],
  96369. (int)og->header[26]);
  96370. for(j=27;j<og->header_len;j++)
  96371. fprintf(stderr,"%d ",(int)og->header[j]);
  96372. fprintf(stderr,")\n\n");
  96373. }
  96374. void copy_page(ogg_page *og){
  96375. unsigned char *temp=_ogg_malloc(og->header_len);
  96376. memcpy(temp,og->header,og->header_len);
  96377. og->header=temp;
  96378. temp=_ogg_malloc(og->body_len);
  96379. memcpy(temp,og->body,og->body_len);
  96380. og->body=temp;
  96381. }
  96382. void free_page(ogg_page *og){
  96383. _ogg_free (og->header);
  96384. _ogg_free (og->body);
  96385. }
  96386. void error(void){
  96387. fprintf(stderr,"error!\n");
  96388. exit(1);
  96389. }
  96390. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96391. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96392. 0x01,0x02,0x03,0x04,0,0,0,0,
  96393. 0x15,0xed,0xec,0x91,
  96394. 1,
  96395. 17};
  96396. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96397. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96398. 0x01,0x02,0x03,0x04,0,0,0,0,
  96399. 0x59,0x10,0x6c,0x2c,
  96400. 1,
  96401. 17};
  96402. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96403. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96404. 0x01,0x02,0x03,0x04,1,0,0,0,
  96405. 0x89,0x33,0x85,0xce,
  96406. 13,
  96407. 254,255,0,255,1,255,245,255,255,0,
  96408. 255,255,90};
  96409. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96410. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96411. 0x01,0x02,0x03,0x04,0,0,0,0,
  96412. 0xff,0x7b,0x23,0x17,
  96413. 1,
  96414. 0};
  96415. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96416. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96417. 0x01,0x02,0x03,0x04,1,0,0,0,
  96418. 0x5c,0x3f,0x66,0xcb,
  96419. 17,
  96420. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96421. 255,255,90,0};
  96422. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96423. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96424. 0x01,0x02,0x03,0x04,0,0,0,0,
  96425. 0x01,0x27,0x31,0xaa,
  96426. 18,
  96427. 255,255,255,255,255,255,255,255,
  96428. 255,255,255,255,255,255,255,255,255,10};
  96429. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96430. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96431. 0x01,0x02,0x03,0x04,1,0,0,0,
  96432. 0x7f,0x4e,0x8a,0xd2,
  96433. 4,
  96434. 255,4,255,0};
  96435. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96436. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96437. 0x01,0x02,0x03,0x04,0,0,0,0,
  96438. 0xff,0x7b,0x23,0x17,
  96439. 1,
  96440. 0};
  96441. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96442. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96443. 0x01,0x02,0x03,0x04,1,0,0,0,
  96444. 0x54,0x05,0x51,0xc8,
  96445. 17,
  96446. 255,255,255,255,255,255,255,255,
  96447. 255,255,255,255,255,255,255,255,255};
  96448. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96449. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96450. 0x01,0x02,0x03,0x04,2,0,0,0,
  96451. 0xc8,0xc3,0xcb,0xed,
  96452. 5,
  96453. 10,255,4,255,0};
  96454. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96455. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96456. 0x01,0x02,0x03,0x04,0,0,0,0,
  96457. 0xff,0x7b,0x23,0x17,
  96458. 1,
  96459. 0};
  96460. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96461. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96462. 0x01,0x02,0x03,0x04,1,0,0,0,
  96463. 0xed,0x2a,0x2e,0xa7,
  96464. 255,
  96465. 10,10,10,10,10,10,10,10,
  96466. 10,10,10,10,10,10,10,10,
  96467. 10,10,10,10,10,10,10,10,
  96468. 10,10,10,10,10,10,10,10,
  96469. 10,10,10,10,10,10,10,10,
  96470. 10,10,10,10,10,10,10,10,
  96471. 10,10,10,10,10,10,10,10,
  96472. 10,10,10,10,10,10,10,10,
  96473. 10,10,10,10,10,10,10,10,
  96474. 10,10,10,10,10,10,10,10,
  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};
  96497. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96498. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96499. 0x01,0x02,0x03,0x04,2,0,0,0,
  96500. 0x6c,0x3b,0x82,0x3d,
  96501. 1,
  96502. 50};
  96503. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96504. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96505. 0x01,0x02,0x03,0x04,0,0,0,0,
  96506. 0xff,0x7b,0x23,0x17,
  96507. 1,
  96508. 0};
  96509. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96510. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96511. 0x01,0x02,0x03,0x04,1,0,0,0,
  96512. 0x3c,0xd9,0x4d,0x3f,
  96513. 17,
  96514. 100,255,255,255,255,255,255,255,255,
  96515. 255,255,255,255,255,255,255,255};
  96516. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96517. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96518. 0x01,0x02,0x03,0x04,2,0,0,0,
  96519. 0x01,0xd2,0xe5,0xe5,
  96520. 17,
  96521. 255,255,255,255,255,255,255,255,
  96522. 255,255,255,255,255,255,255,255,255};
  96523. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96524. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96525. 0x01,0x02,0x03,0x04,3,0,0,0,
  96526. 0xef,0xdd,0x88,0xde,
  96527. 7,
  96528. 255,255,75,255,4,255,0};
  96529. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96530. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96531. 0x01,0x02,0x03,0x04,0,0,0,0,
  96532. 0xff,0x7b,0x23,0x17,
  96533. 1,
  96534. 0};
  96535. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96536. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96537. 0x01,0x02,0x03,0x04,1,0,0,0,
  96538. 0x3c,0xd9,0x4d,0x3f,
  96539. 17,
  96540. 100,255,255,255,255,255,255,255,255,
  96541. 255,255,255,255,255,255,255,255};
  96542. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96543. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96544. 0x01,0x02,0x03,0x04,2,0,0,0,
  96545. 0xd4,0xe0,0x60,0xe5,
  96546. 1,0};
  96547. void test_pack(const int *pl, const int **headers, int byteskip,
  96548. int pageskip, int packetskip){
  96549. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96550. long inptr=0;
  96551. long outptr=0;
  96552. long deptr=0;
  96553. long depacket=0;
  96554. long granule_pos=7,pageno=0;
  96555. int i,j,packets,pageout=pageskip;
  96556. int eosflag=0;
  96557. int bosflag=0;
  96558. int byteskipcount=0;
  96559. ogg_stream_reset(&os_en);
  96560. ogg_stream_reset(&os_de);
  96561. ogg_sync_reset(&oy);
  96562. for(packets=0;packets<packetskip;packets++)
  96563. depacket+=pl[packets];
  96564. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96565. for(i=0;i<packets;i++){
  96566. ogg_packet op;
  96567. int len=pl[i];
  96568. op.packet=data+inptr;
  96569. op.bytes=len;
  96570. op.e_o_s=(pl[i+1]<0?1:0);
  96571. op.granulepos=granule_pos;
  96572. granule_pos+=1024;
  96573. for(j=0;j<len;j++)data[inptr++]=i+j;
  96574. ogg_stream_packetin(&os_en,&op);
  96575. {
  96576. ogg_page og;
  96577. while(ogg_stream_pageout(&os_en,&og)){
  96578. fprintf(stderr,"%ld, ",pageno);
  96579. if(headers[pageno]==NULL){
  96580. fprintf(stderr,"coded too many pages!\n");
  96581. exit(1);
  96582. }
  96583. check_page(data+outptr,headers[pageno],&og);
  96584. outptr+=og.body_len;
  96585. pageno++;
  96586. if(pageskip){
  96587. bosflag=1;
  96588. pageskip--;
  96589. deptr+=og.body_len;
  96590. }
  96591. {
  96592. ogg_page og_de;
  96593. ogg_packet op_de,op_de2;
  96594. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96595. char *next=buf;
  96596. byteskipcount+=og.header_len;
  96597. if(byteskipcount>byteskip){
  96598. memcpy(next,og.header,byteskipcount-byteskip);
  96599. next+=byteskipcount-byteskip;
  96600. byteskipcount=byteskip;
  96601. }
  96602. byteskipcount+=og.body_len;
  96603. if(byteskipcount>byteskip){
  96604. memcpy(next,og.body,byteskipcount-byteskip);
  96605. next+=byteskipcount-byteskip;
  96606. byteskipcount=byteskip;
  96607. }
  96608. ogg_sync_wrote(&oy,next-buf);
  96609. while(1){
  96610. int ret=ogg_sync_pageout(&oy,&og_de);
  96611. if(ret==0)break;
  96612. if(ret<0)continue;
  96613. fprintf(stderr,"(%ld), ",pageout);
  96614. check_page(data+deptr,headers[pageout],&og_de);
  96615. deptr+=og_de.body_len;
  96616. pageout++;
  96617. ogg_stream_pagein(&os_de,&og_de);
  96618. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96619. ogg_stream_packetpeek(&os_de,NULL);
  96620. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96621. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96622. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96623. depacket);
  96624. exit(1);
  96625. }
  96626. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96627. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96628. depacket);
  96629. exit(1);
  96630. }
  96631. if(bosflag==0 && op_de.b_o_s==0){
  96632. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96633. exit(1);
  96634. }
  96635. if(bosflag && op_de.b_o_s){
  96636. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96637. exit(1);
  96638. }
  96639. bosflag=1;
  96640. depacket+=op_de.bytes;
  96641. if(eosflag){
  96642. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96643. exit(1);
  96644. }
  96645. if(op_de.e_o_s)eosflag=1;
  96646. if(op_de.granulepos!=-1){
  96647. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96648. }
  96649. }
  96650. }
  96651. }
  96652. }
  96653. }
  96654. }
  96655. _ogg_free(data);
  96656. if(headers[pageno]!=NULL){
  96657. fprintf(stderr,"did not write last page!\n");
  96658. exit(1);
  96659. }
  96660. if(headers[pageout]!=NULL){
  96661. fprintf(stderr,"did not decode last page!\n");
  96662. exit(1);
  96663. }
  96664. if(inptr!=outptr){
  96665. fprintf(stderr,"encoded page data incomplete!\n");
  96666. exit(1);
  96667. }
  96668. if(inptr!=deptr){
  96669. fprintf(stderr,"decoded page data incomplete!\n");
  96670. exit(1);
  96671. }
  96672. if(inptr!=depacket){
  96673. fprintf(stderr,"decoded packet data incomplete!\n");
  96674. exit(1);
  96675. }
  96676. if(!eosflag){
  96677. fprintf(stderr,"Never got a packet with EOS set!\n");
  96678. exit(1);
  96679. }
  96680. fprintf(stderr,"ok.\n");
  96681. }
  96682. int main(void){
  96683. ogg_stream_init(&os_en,0x04030201);
  96684. ogg_stream_init(&os_de,0x04030201);
  96685. ogg_sync_init(&oy);
  96686. {
  96687. const int packets[]={17, -1};
  96688. const int *headret[]={head1_0,NULL};
  96689. fprintf(stderr,"testing single page encoding... ");
  96690. test_pack(packets,headret,0,0,0);
  96691. }
  96692. {
  96693. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96694. const int *headret[]={head1_1,head2_1,NULL};
  96695. fprintf(stderr,"testing basic page encoding... ");
  96696. test_pack(packets,headret,0,0,0);
  96697. }
  96698. {
  96699. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96700. const int *headret[]={head1_2,head2_2,NULL};
  96701. fprintf(stderr,"testing basic nil packets... ");
  96702. test_pack(packets,headret,0,0,0);
  96703. }
  96704. {
  96705. const int packets[]={4345,259,255,-1};
  96706. const int *headret[]={head1_3,head2_3,NULL};
  96707. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96708. test_pack(packets,headret,0,0,0);
  96709. }
  96710. {
  96711. const int packets[]={0,4345,259,255,-1};
  96712. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96713. fprintf(stderr,"testing single packet page span... ");
  96714. test_pack(packets,headret,0,0,0);
  96715. }
  96716. {
  96717. const int packets[]={0,10,10,10,10,10,10,10,10,
  96718. 10,10,10,10,10,10,10,10,
  96719. 10,10,10,10,10,10,10,10,
  96720. 10,10,10,10,10,10,10,10,
  96721. 10,10,10,10,10,10,10,10,
  96722. 10,10,10,10,10,10,10,10,
  96723. 10,10,10,10,10,10,10,10,
  96724. 10,10,10,10,10,10,10,10,
  96725. 10,10,10,10,10,10,10,10,
  96726. 10,10,10,10,10,10,10,10,
  96727. 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,50,-1};
  96749. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96750. fprintf(stderr,"testing max packet segments... ");
  96751. test_pack(packets,headret,0,0,0);
  96752. }
  96753. {
  96754. const int packets[]={0,100,9000,259,255,-1};
  96755. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96756. fprintf(stderr,"testing very large packets... ");
  96757. test_pack(packets,headret,0,0,0);
  96758. }
  96759. {
  96760. const int packets[]={0,100,9000,259,255,-1};
  96761. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96762. fprintf(stderr,"testing continuation resync in very large packets... ");
  96763. test_pack(packets,headret,100,2,3);
  96764. }
  96765. {
  96766. const int packets[]={0,100,4080,-1};
  96767. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96768. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96769. test_pack(packets,headret,0,0,0);
  96770. }
  96771. {
  96772. unsigned char *data=_ogg_malloc(1024*1024);
  96773. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96774. int inptr=0,i,j;
  96775. ogg_page og[5];
  96776. ogg_stream_reset(&os_en);
  96777. for(i=0;pl[i]!=-1;i++){
  96778. ogg_packet op;
  96779. int len=pl[i];
  96780. op.packet=data+inptr;
  96781. op.bytes=len;
  96782. op.e_o_s=(pl[i+1]<0?1:0);
  96783. op.granulepos=(i+1)*1000;
  96784. for(j=0;j<len;j++)data[inptr++]=i+j;
  96785. ogg_stream_packetin(&os_en,&op);
  96786. }
  96787. _ogg_free(data);
  96788. for(i=0;i<5;i++){
  96789. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96790. fprintf(stderr,"Too few pages output building sync tests!\n");
  96791. exit(1);
  96792. }
  96793. copy_page(&og[i]);
  96794. }
  96795. {
  96796. ogg_page temp;
  96797. ogg_packet test;
  96798. fprintf(stderr,"Testing loss of pages... ");
  96799. ogg_sync_reset(&oy);
  96800. ogg_stream_reset(&os_de);
  96801. for(i=0;i<5;i++){
  96802. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96803. og[i].header_len);
  96804. ogg_sync_wrote(&oy,og[i].header_len);
  96805. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96806. ogg_sync_wrote(&oy,og[i].body_len);
  96807. }
  96808. ogg_sync_pageout(&oy,&temp);
  96809. ogg_stream_pagein(&os_de,&temp);
  96810. ogg_sync_pageout(&oy,&temp);
  96811. ogg_stream_pagein(&os_de,&temp);
  96812. ogg_sync_pageout(&oy,&temp);
  96813. ogg_sync_pageout(&oy,&temp);
  96814. ogg_stream_pagein(&os_de,&temp);
  96815. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96816. checkpacket(&test,0,0,0);
  96817. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96818. checkpacket(&test,100,1,-1);
  96819. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96820. checkpacket(&test,4079,2,3000);
  96821. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96822. fprintf(stderr,"Error: loss of page did not return error\n");
  96823. exit(1);
  96824. }
  96825. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96826. checkpacket(&test,76,5,-1);
  96827. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96828. checkpacket(&test,34,6,-1);
  96829. fprintf(stderr,"ok.\n");
  96830. }
  96831. {
  96832. ogg_page temp;
  96833. ogg_packet test;
  96834. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96835. ogg_sync_reset(&oy);
  96836. ogg_stream_reset(&os_de);
  96837. for(i=0;i<5;i++){
  96838. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96839. og[i].header_len);
  96840. ogg_sync_wrote(&oy,og[i].header_len);
  96841. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96842. ogg_sync_wrote(&oy,og[i].body_len);
  96843. }
  96844. ogg_sync_pageout(&oy,&temp);
  96845. ogg_stream_pagein(&os_de,&temp);
  96846. ogg_sync_pageout(&oy,&temp);
  96847. ogg_stream_pagein(&os_de,&temp);
  96848. ogg_sync_pageout(&oy,&temp);
  96849. ogg_stream_pagein(&os_de,&temp);
  96850. ogg_sync_pageout(&oy,&temp);
  96851. ogg_sync_pageout(&oy,&temp);
  96852. ogg_stream_pagein(&os_de,&temp);
  96853. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96854. checkpacket(&test,0,0,0);
  96855. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96856. checkpacket(&test,100,1,-1);
  96857. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96858. checkpacket(&test,4079,2,3000);
  96859. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96860. checkpacket(&test,2956,3,4000);
  96861. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96862. fprintf(stderr,"Error: loss of page did not return error\n");
  96863. exit(1);
  96864. }
  96865. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96866. checkpacket(&test,300,13,14000);
  96867. fprintf(stderr,"ok.\n");
  96868. }
  96869. {
  96870. ogg_page og_de;
  96871. fprintf(stderr,"Testing sync on partial inputs... ");
  96872. ogg_sync_reset(&oy);
  96873. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96874. 3);
  96875. ogg_sync_wrote(&oy,3);
  96876. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96877. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96878. 20);
  96879. ogg_sync_wrote(&oy,20);
  96880. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96881. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96882. 5);
  96883. ogg_sync_wrote(&oy,5);
  96884. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96885. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96886. og[1].header_len-28);
  96887. ogg_sync_wrote(&oy,og[1].header_len-28);
  96888. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96889. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96890. ogg_sync_wrote(&oy,1000);
  96891. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96892. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96893. og[1].body_len-1000);
  96894. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96895. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96896. fprintf(stderr,"ok.\n");
  96897. }
  96898. {
  96899. ogg_page og_de;
  96900. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96901. ogg_sync_reset(&oy);
  96902. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96903. og[1].header_len);
  96904. ogg_sync_wrote(&oy,og[1].header_len);
  96905. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96906. og[1].body_len);
  96907. ogg_sync_wrote(&oy,og[1].body_len);
  96908. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96909. 20);
  96910. ogg_sync_wrote(&oy,20);
  96911. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96912. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96913. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96914. og[1].header_len-20);
  96915. ogg_sync_wrote(&oy,og[1].header_len-20);
  96916. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96917. og[1].body_len);
  96918. ogg_sync_wrote(&oy,og[1].body_len);
  96919. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96920. fprintf(stderr,"ok.\n");
  96921. }
  96922. {
  96923. ogg_page og_de;
  96924. fprintf(stderr,"Testing search for capture... ");
  96925. ogg_sync_reset(&oy);
  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. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96930. og[1].header_len);
  96931. ogg_sync_wrote(&oy,og[1].header_len);
  96932. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96933. og[1].body_len);
  96934. ogg_sync_wrote(&oy,og[1].body_len);
  96935. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96936. 20);
  96937. ogg_sync_wrote(&oy,20);
  96938. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96939. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96940. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96941. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96942. og[2].header_len-20);
  96943. ogg_sync_wrote(&oy,og[2].header_len-20);
  96944. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96945. og[2].body_len);
  96946. ogg_sync_wrote(&oy,og[2].body_len);
  96947. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96948. fprintf(stderr,"ok.\n");
  96949. }
  96950. {
  96951. ogg_page og_de;
  96952. fprintf(stderr,"Testing recapture... ");
  96953. ogg_sync_reset(&oy);
  96954. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96955. og[1].header_len);
  96956. ogg_sync_wrote(&oy,og[1].header_len);
  96957. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96958. og[1].body_len);
  96959. ogg_sync_wrote(&oy,og[1].body_len);
  96960. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96961. og[2].header_len);
  96962. ogg_sync_wrote(&oy,og[2].header_len);
  96963. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96964. og[2].header_len);
  96965. ogg_sync_wrote(&oy,og[2].header_len);
  96966. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96967. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96968. og[2].body_len-5);
  96969. ogg_sync_wrote(&oy,og[2].body_len-5);
  96970. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96971. og[3].header_len);
  96972. ogg_sync_wrote(&oy,og[3].header_len);
  96973. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96974. og[3].body_len);
  96975. ogg_sync_wrote(&oy,og[3].body_len);
  96976. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96977. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96978. fprintf(stderr,"ok.\n");
  96979. }
  96980. {
  96981. for(i=0;i<5;i++){
  96982. free_page(&og[i]);
  96983. }
  96984. }
  96985. }
  96986. return(0);
  96987. }
  96988. #endif
  96989. #endif
  96990. /*** End of inlined file: framing.c ***/
  96991. /*** Start of inlined file: analysis.c ***/
  96992. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96993. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96994. // tasks..
  96995. #if JUCE_MSVC
  96996. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96997. #endif
  96998. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96999. #if JUCE_USE_OGGVORBIS
  97000. #include <stdio.h>
  97001. #include <string.h>
  97002. #include <math.h>
  97003. /*** Start of inlined file: codec_internal.h ***/
  97004. #ifndef _V_CODECI_H_
  97005. #define _V_CODECI_H_
  97006. /*** Start of inlined file: envelope.h ***/
  97007. #ifndef _V_ENVELOPE_
  97008. #define _V_ENVELOPE_
  97009. /*** Start of inlined file: mdct.h ***/
  97010. #ifndef _OGG_mdct_H_
  97011. #define _OGG_mdct_H_
  97012. #ifdef MDCT_INTEGERIZED
  97013. #define DATA_TYPE int
  97014. #define REG_TYPE register int
  97015. #define TRIGBITS 14
  97016. #define cPI3_8 6270
  97017. #define cPI2_8 11585
  97018. #define cPI1_8 15137
  97019. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  97020. #define MULT_NORM(x) ((x)>>TRIGBITS)
  97021. #define HALVE(x) ((x)>>1)
  97022. #else
  97023. #define DATA_TYPE float
  97024. #define REG_TYPE float
  97025. #define cPI3_8 .38268343236508977175F
  97026. #define cPI2_8 .70710678118654752441F
  97027. #define cPI1_8 .92387953251128675613F
  97028. #define FLOAT_CONV(x) (x)
  97029. #define MULT_NORM(x) (x)
  97030. #define HALVE(x) ((x)*.5f)
  97031. #endif
  97032. typedef struct {
  97033. int n;
  97034. int log2n;
  97035. DATA_TYPE *trig;
  97036. int *bitrev;
  97037. DATA_TYPE scale;
  97038. } mdct_lookup;
  97039. extern void mdct_init(mdct_lookup *lookup,int n);
  97040. extern void mdct_clear(mdct_lookup *l);
  97041. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97042. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97043. #endif
  97044. /*** End of inlined file: mdct.h ***/
  97045. #define VE_PRE 16
  97046. #define VE_WIN 4
  97047. #define VE_POST 2
  97048. #define VE_AMP (VE_PRE+VE_POST-1)
  97049. #define VE_BANDS 7
  97050. #define VE_NEARDC 15
  97051. #define VE_MINSTRETCH 2 /* a bit less than short block */
  97052. #define VE_MAXSTRETCH 12 /* one-third full block */
  97053. typedef struct {
  97054. float ampbuf[VE_AMP];
  97055. int ampptr;
  97056. float nearDC[VE_NEARDC];
  97057. float nearDC_acc;
  97058. float nearDC_partialacc;
  97059. int nearptr;
  97060. } envelope_filter_state;
  97061. typedef struct {
  97062. int begin;
  97063. int end;
  97064. float *window;
  97065. float total;
  97066. } envelope_band;
  97067. typedef struct {
  97068. int ch;
  97069. int winlength;
  97070. int searchstep;
  97071. float minenergy;
  97072. mdct_lookup mdct;
  97073. float *mdct_win;
  97074. envelope_band band[VE_BANDS];
  97075. envelope_filter_state *filter;
  97076. int stretch;
  97077. int *mark;
  97078. long storage;
  97079. long current;
  97080. long curmark;
  97081. long cursor;
  97082. } envelope_lookup;
  97083. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  97084. extern void _ve_envelope_clear(envelope_lookup *e);
  97085. extern long _ve_envelope_search(vorbis_dsp_state *v);
  97086. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  97087. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  97088. #endif
  97089. /*** End of inlined file: envelope.h ***/
  97090. /*** Start of inlined file: codebook.h ***/
  97091. #ifndef _V_CODEBOOK_H_
  97092. #define _V_CODEBOOK_H_
  97093. typedef struct static_codebook{
  97094. long dim; /* codebook dimensions (elements per vector) */
  97095. long entries; /* codebook entries */
  97096. long *lengthlist; /* codeword lengths in bits */
  97097. int maptype; /* 0=none
  97098. 1=implicitly populated values from map column
  97099. 2=listed arbitrary values */
  97100. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  97101. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  97102. int q_quant; /* bits: 0 < quant <= 16 */
  97103. int q_sequencep; /* bitflag */
  97104. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  97105. map == 2: list of dim*entries quantized entry vals
  97106. */
  97107. struct encode_aux_nearestmatch *nearest_tree;
  97108. struct encode_aux_threshmatch *thresh_tree;
  97109. struct encode_aux_pigeonhole *pigeon_tree;
  97110. int allocedp;
  97111. } static_codebook;
  97112. typedef struct encode_aux_nearestmatch{
  97113. long *ptr0;
  97114. long *ptr1;
  97115. long *p; /* decision points (each is an entry) */
  97116. long *q; /* decision points (each is an entry) */
  97117. long aux; /* number of tree entries */
  97118. long alloc;
  97119. } encode_aux_nearestmatch;
  97120. typedef struct encode_aux_threshmatch{
  97121. float *quantthresh;
  97122. long *quantmap;
  97123. int quantvals;
  97124. int threshvals;
  97125. } encode_aux_threshmatch;
  97126. typedef struct encode_aux_pigeonhole{
  97127. float min;
  97128. float del;
  97129. int mapentries;
  97130. int quantvals;
  97131. long *pigeonmap;
  97132. long fittotal;
  97133. long *fitlist;
  97134. long *fitmap;
  97135. long *fitlength;
  97136. } encode_aux_pigeonhole;
  97137. typedef struct codebook{
  97138. long dim; /* codebook dimensions (elements per vector) */
  97139. long entries; /* codebook entries */
  97140. long used_entries; /* populated codebook entries */
  97141. const static_codebook *c;
  97142. float *valuelist; /* list of dim*entries actual entry values */
  97143. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  97144. int *dec_index; /* only used if sparseness collapsed */
  97145. char *dec_codelengths;
  97146. ogg_uint32_t *dec_firsttable;
  97147. int dec_firsttablen;
  97148. int dec_maxlength;
  97149. } codebook;
  97150. extern void vorbis_staticbook_clear(static_codebook *b);
  97151. extern void vorbis_staticbook_destroy(static_codebook *b);
  97152. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  97153. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  97154. extern void vorbis_book_clear(codebook *b);
  97155. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  97156. extern float *_book_logdist(const static_codebook *b,float *vals);
  97157. extern float _float32_unpack(long val);
  97158. extern long _float32_pack(float val);
  97159. extern int _best(codebook *book, float *a, int step);
  97160. extern int _ilog(unsigned int v);
  97161. extern long _book_maptype1_quantvals(const static_codebook *b);
  97162. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  97163. extern long vorbis_book_codeword(codebook *book,int entry);
  97164. extern long vorbis_book_codelen(codebook *book,int entry);
  97165. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  97166. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  97167. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  97168. extern int vorbis_book_errorv(codebook *book, float *a);
  97169. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  97170. oggpack_buffer *b);
  97171. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  97172. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  97173. oggpack_buffer *b,int n);
  97174. extern long vorbis_book_decodev_set(codebook *book, float *a,
  97175. oggpack_buffer *b,int n);
  97176. extern long vorbis_book_decodev_add(codebook *book, float *a,
  97177. oggpack_buffer *b,int n);
  97178. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  97179. long off,int ch,
  97180. oggpack_buffer *b,int n);
  97181. #endif
  97182. /*** End of inlined file: codebook.h ***/
  97183. #define BLOCKTYPE_IMPULSE 0
  97184. #define BLOCKTYPE_PADDING 1
  97185. #define BLOCKTYPE_TRANSITION 0
  97186. #define BLOCKTYPE_LONG 1
  97187. #define PACKETBLOBS 15
  97188. typedef struct vorbis_block_internal{
  97189. float **pcmdelay; /* this is a pointer into local storage */
  97190. float ampmax;
  97191. int blocktype;
  97192. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  97193. blob [PACKETBLOBS/2] points to
  97194. the oggpack_buffer in the
  97195. main vorbis_block */
  97196. } vorbis_block_internal;
  97197. typedef void vorbis_look_floor;
  97198. typedef void vorbis_look_residue;
  97199. typedef void vorbis_look_transform;
  97200. typedef struct {
  97201. int blockflag;
  97202. int windowtype;
  97203. int transformtype;
  97204. int mapping;
  97205. } vorbis_info_mode;
  97206. typedef void vorbis_info_floor;
  97207. typedef void vorbis_info_residue;
  97208. typedef void vorbis_info_mapping;
  97209. /*** Start of inlined file: psy.h ***/
  97210. #ifndef _V_PSY_H_
  97211. #define _V_PSY_H_
  97212. /*** Start of inlined file: smallft.h ***/
  97213. #ifndef _V_SMFT_H_
  97214. #define _V_SMFT_H_
  97215. typedef struct {
  97216. int n;
  97217. float *trigcache;
  97218. int *splitcache;
  97219. } drft_lookup;
  97220. extern void drft_forward(drft_lookup *l,float *data);
  97221. extern void drft_backward(drft_lookup *l,float *data);
  97222. extern void drft_init(drft_lookup *l,int n);
  97223. extern void drft_clear(drft_lookup *l);
  97224. #endif
  97225. /*** End of inlined file: smallft.h ***/
  97226. /*** Start of inlined file: backends.h ***/
  97227. #ifndef _vorbis_backend_h_
  97228. #define _vorbis_backend_h_
  97229. typedef struct{
  97230. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  97231. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  97232. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  97233. void (*free_info) (vorbis_info_floor *);
  97234. void (*free_look) (vorbis_look_floor *);
  97235. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  97236. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  97237. void *buffer,float *);
  97238. } vorbis_func_floor;
  97239. typedef struct{
  97240. int order;
  97241. long rate;
  97242. long barkmap;
  97243. int ampbits;
  97244. int ampdB;
  97245. int numbooks; /* <= 16 */
  97246. int books[16];
  97247. float lessthan; /* encode-only config setting hacks for libvorbis */
  97248. float greaterthan; /* encode-only config setting hacks for libvorbis */
  97249. } vorbis_info_floor0;
  97250. #define VIF_POSIT 63
  97251. #define VIF_CLASS 16
  97252. #define VIF_PARTS 31
  97253. typedef struct{
  97254. int partitions; /* 0 to 31 */
  97255. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  97256. int class_dim[VIF_CLASS]; /* 1 to 8 */
  97257. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  97258. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  97259. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  97260. int mult; /* 1 2 3 or 4 */
  97261. int postlist[VIF_POSIT+2]; /* first two implicit */
  97262. float maxover;
  97263. float maxunder;
  97264. float maxerr;
  97265. float twofitweight;
  97266. float twofitatten;
  97267. int n;
  97268. } vorbis_info_floor1;
  97269. typedef struct{
  97270. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  97271. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  97272. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  97273. vorbis_info_residue *);
  97274. void (*free_info) (vorbis_info_residue *);
  97275. void (*free_look) (vorbis_look_residue *);
  97276. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  97277. float **,int *,int);
  97278. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  97279. vorbis_look_residue *,
  97280. float **,float **,int *,int,long **);
  97281. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  97282. float **,int *,int);
  97283. } vorbis_func_residue;
  97284. typedef struct vorbis_info_residue0{
  97285. long begin;
  97286. long end;
  97287. int grouping; /* group n vectors per partition */
  97288. int partitions; /* possible codebooks for a partition */
  97289. int groupbook; /* huffbook for partitioning */
  97290. int secondstages[64]; /* expanded out to pointers in lookup */
  97291. int booklist[256]; /* list of second stage books */
  97292. float classmetric1[64];
  97293. float classmetric2[64];
  97294. } vorbis_info_residue0;
  97295. typedef struct{
  97296. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97297. oggpack_buffer *);
  97298. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97299. void (*free_info) (vorbis_info_mapping *);
  97300. int (*forward) (struct vorbis_block *vb);
  97301. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97302. } vorbis_func_mapping;
  97303. typedef struct vorbis_info_mapping0{
  97304. int submaps; /* <= 16 */
  97305. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97306. int floorsubmap[16]; /* [mux] submap to floors */
  97307. int residuesubmap[16]; /* [mux] submap to residue */
  97308. int coupling_steps;
  97309. int coupling_mag[256];
  97310. int coupling_ang[256];
  97311. } vorbis_info_mapping0;
  97312. #endif
  97313. /*** End of inlined file: backends.h ***/
  97314. #ifndef EHMER_MAX
  97315. #define EHMER_MAX 56
  97316. #endif
  97317. #define P_BANDS 17 /* 62Hz to 16kHz */
  97318. #define P_LEVELS 8 /* 30dB to 100dB */
  97319. #define P_LEVEL_0 30. /* 30 dB */
  97320. #define P_NOISECURVES 3
  97321. #define NOISE_COMPAND_LEVELS 40
  97322. typedef struct vorbis_info_psy{
  97323. int blockflag;
  97324. float ath_adjatt;
  97325. float ath_maxatt;
  97326. float tone_masteratt[P_NOISECURVES];
  97327. float tone_centerboost;
  97328. float tone_decay;
  97329. float tone_abs_limit;
  97330. float toneatt[P_BANDS];
  97331. int noisemaskp;
  97332. float noisemaxsupp;
  97333. float noisewindowlo;
  97334. float noisewindowhi;
  97335. int noisewindowlomin;
  97336. int noisewindowhimin;
  97337. int noisewindowfixed;
  97338. float noiseoff[P_NOISECURVES][P_BANDS];
  97339. float noisecompand[NOISE_COMPAND_LEVELS];
  97340. float max_curve_dB;
  97341. int normal_channel_p;
  97342. int normal_point_p;
  97343. int normal_start;
  97344. int normal_partition;
  97345. double normal_thresh;
  97346. } vorbis_info_psy;
  97347. typedef struct{
  97348. int eighth_octave_lines;
  97349. float preecho_thresh[VE_BANDS];
  97350. float postecho_thresh[VE_BANDS];
  97351. float stretch_penalty;
  97352. float preecho_minenergy;
  97353. float ampmax_att_per_sec;
  97354. int coupling_pkHz[PACKETBLOBS];
  97355. int coupling_pointlimit[2][PACKETBLOBS];
  97356. int coupling_prepointamp[PACKETBLOBS];
  97357. int coupling_postpointamp[PACKETBLOBS];
  97358. int sliding_lowpass[2][PACKETBLOBS];
  97359. } vorbis_info_psy_global;
  97360. typedef struct {
  97361. float ampmax;
  97362. int channels;
  97363. vorbis_info_psy_global *gi;
  97364. int coupling_pointlimit[2][P_NOISECURVES];
  97365. } vorbis_look_psy_global;
  97366. typedef struct {
  97367. int n;
  97368. struct vorbis_info_psy *vi;
  97369. float ***tonecurves;
  97370. float **noiseoffset;
  97371. float *ath;
  97372. long *octave; /* in n.ocshift format */
  97373. long *bark;
  97374. long firstoc;
  97375. long shiftoc;
  97376. int eighth_octave_lines; /* power of two, please */
  97377. int total_octave_lines;
  97378. long rate; /* cache it */
  97379. float m_val; /* Masking compensation value */
  97380. } vorbis_look_psy;
  97381. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97382. vorbis_info_psy_global *gi,int n,long rate);
  97383. extern void _vp_psy_clear(vorbis_look_psy *p);
  97384. extern void *_vi_psy_dup(void *source);
  97385. extern void _vi_psy_free(vorbis_info_psy *i);
  97386. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97387. extern void _vp_remove_floor(vorbis_look_psy *p,
  97388. float *mdct,
  97389. int *icodedflr,
  97390. float *residue,
  97391. int sliding_lowpass);
  97392. extern void _vp_noisemask(vorbis_look_psy *p,
  97393. float *logmdct,
  97394. float *logmask);
  97395. extern void _vp_tonemask(vorbis_look_psy *p,
  97396. float *logfft,
  97397. float *logmask,
  97398. float global_specmax,
  97399. float local_specmax);
  97400. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97401. float *noise,
  97402. float *tone,
  97403. int offset_select,
  97404. float *logmask,
  97405. float *mdct,
  97406. float *logmdct);
  97407. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97408. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97409. vorbis_info_psy_global *g,
  97410. vorbis_look_psy *p,
  97411. vorbis_info_mapping0 *vi,
  97412. float **mdct);
  97413. extern void _vp_couple(int blobno,
  97414. vorbis_info_psy_global *g,
  97415. vorbis_look_psy *p,
  97416. vorbis_info_mapping0 *vi,
  97417. float **res,
  97418. float **mag_memo,
  97419. int **mag_sort,
  97420. int **ifloor,
  97421. int *nonzero,
  97422. int sliding_lowpass);
  97423. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97424. float *in,float *out,int *sortedindex);
  97425. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97426. float *magnitudes,int *sortedindex);
  97427. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97428. vorbis_look_psy *p,
  97429. vorbis_info_mapping0 *vi,
  97430. float **mags);
  97431. extern void hf_reduction(vorbis_info_psy_global *g,
  97432. vorbis_look_psy *p,
  97433. vorbis_info_mapping0 *vi,
  97434. float **mdct);
  97435. #endif
  97436. /*** End of inlined file: psy.h ***/
  97437. /*** Start of inlined file: bitrate.h ***/
  97438. #ifndef _V_BITRATE_H_
  97439. #define _V_BITRATE_H_
  97440. /*** Start of inlined file: os.h ***/
  97441. #ifndef _OS_H
  97442. #define _OS_H
  97443. #ifdef HAVE_CONFIG_H
  97444. #include "config.h"
  97445. #endif
  97446. #include <math.h>
  97447. /*** Start of inlined file: misc.h ***/
  97448. #ifndef _V_RANDOM_H_
  97449. #define _V_RANDOM_H_
  97450. extern int analysis_noisy;
  97451. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97452. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97453. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97454. ogg_int64_t off);
  97455. #ifdef DEBUG_MALLOC
  97456. #define _VDBG_GRAPHFILE "malloc.m"
  97457. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97458. extern void _VDBG_free(void *ptr,char *file,long line);
  97459. #ifndef MISC_C
  97460. #undef _ogg_malloc
  97461. #undef _ogg_calloc
  97462. #undef _ogg_realloc
  97463. #undef _ogg_free
  97464. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97465. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97466. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97467. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97468. #endif
  97469. #endif
  97470. #endif
  97471. /*** End of inlined file: misc.h ***/
  97472. #ifndef _V_IFDEFJAIL_H_
  97473. # define _V_IFDEFJAIL_H_
  97474. # ifdef __GNUC__
  97475. # define STIN static __inline__
  97476. # elif _WIN32
  97477. # define STIN static __inline
  97478. # else
  97479. # define STIN static
  97480. # endif
  97481. #ifdef DJGPP
  97482. # define rint(x) (floor((x)+0.5f))
  97483. #endif
  97484. #ifndef M_PI
  97485. # define M_PI (3.1415926536f)
  97486. #endif
  97487. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97488. # include <malloc.h>
  97489. # define rint(x) (floor((x)+0.5f))
  97490. # define NO_FLOAT_MATH_LIB
  97491. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97492. #endif
  97493. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97494. void *_alloca(size_t size);
  97495. # define alloca _alloca
  97496. #endif
  97497. #ifndef FAST_HYPOT
  97498. # define FAST_HYPOT hypot
  97499. #endif
  97500. #endif
  97501. #ifdef HAVE_ALLOCA_H
  97502. # include <alloca.h>
  97503. #endif
  97504. #ifdef USE_MEMORY_H
  97505. # include <memory.h>
  97506. #endif
  97507. #ifndef min
  97508. # define min(x,y) ((x)>(y)?(y):(x))
  97509. #endif
  97510. #ifndef max
  97511. # define max(x,y) ((x)<(y)?(y):(x))
  97512. #endif
  97513. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97514. # define VORBIS_FPU_CONTROL
  97515. typedef ogg_int16_t vorbis_fpu_control;
  97516. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97517. ogg_int16_t ret;
  97518. ogg_int16_t temp;
  97519. __asm__ __volatile__("fnstcw %0\n\t"
  97520. "movw %0,%%dx\n\t"
  97521. "orw $62463,%%dx\n\t"
  97522. "movw %%dx,%1\n\t"
  97523. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97524. *fpu=ret;
  97525. }
  97526. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97527. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97528. }
  97529. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97530. we get extra fst/fld to
  97531. truncate precision */
  97532. int i;
  97533. __asm__("fistl %0": "=m"(i) : "t"(f));
  97534. return(i);
  97535. }
  97536. #endif
  97537. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97538. # define VORBIS_FPU_CONTROL
  97539. typedef ogg_int16_t vorbis_fpu_control;
  97540. static __inline int vorbis_ftoi(double f){
  97541. int i;
  97542. __asm{
  97543. fld f
  97544. fistp i
  97545. }
  97546. return i;
  97547. }
  97548. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97549. }
  97550. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97551. }
  97552. #endif
  97553. #ifndef VORBIS_FPU_CONTROL
  97554. typedef int vorbis_fpu_control;
  97555. static int vorbis_ftoi(double f){
  97556. return (int)(f+.5);
  97557. }
  97558. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97559. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97560. #endif
  97561. #endif /* _OS_H */
  97562. /*** End of inlined file: os.h ***/
  97563. typedef struct bitrate_manager_state {
  97564. int managed;
  97565. long avg_reservoir;
  97566. long minmax_reservoir;
  97567. long avg_bitsper;
  97568. long min_bitsper;
  97569. long max_bitsper;
  97570. long short_per_long;
  97571. double avgfloat;
  97572. vorbis_block *vb;
  97573. int choice;
  97574. } bitrate_manager_state;
  97575. typedef struct bitrate_manager_info{
  97576. long avg_rate;
  97577. long min_rate;
  97578. long max_rate;
  97579. long reservoir_bits;
  97580. double reservoir_bias;
  97581. double slew_damp;
  97582. } bitrate_manager_info;
  97583. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97584. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97585. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97586. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97587. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97588. #endif
  97589. /*** End of inlined file: bitrate.h ***/
  97590. static int ilog(unsigned int v){
  97591. int ret=0;
  97592. while(v){
  97593. ret++;
  97594. v>>=1;
  97595. }
  97596. return(ret);
  97597. }
  97598. static int ilog2(unsigned int v){
  97599. int ret=0;
  97600. if(v)--v;
  97601. while(v){
  97602. ret++;
  97603. v>>=1;
  97604. }
  97605. return(ret);
  97606. }
  97607. typedef struct private_state {
  97608. envelope_lookup *ve; /* envelope lookup */
  97609. int window[2];
  97610. vorbis_look_transform **transform[2]; /* block, type */
  97611. drft_lookup fft_look[2];
  97612. int modebits;
  97613. vorbis_look_floor **flr;
  97614. vorbis_look_residue **residue;
  97615. vorbis_look_psy *psy;
  97616. vorbis_look_psy_global *psy_g_look;
  97617. unsigned char *header;
  97618. unsigned char *header1;
  97619. unsigned char *header2;
  97620. bitrate_manager_state bms;
  97621. ogg_int64_t sample_count;
  97622. } private_state;
  97623. /*** Start of inlined file: highlevel.h ***/
  97624. typedef struct highlevel_byblocktype {
  97625. double tone_mask_setting;
  97626. double tone_peaklimit_setting;
  97627. double noise_bias_setting;
  97628. double noise_compand_setting;
  97629. } highlevel_byblocktype;
  97630. typedef struct highlevel_encode_setup {
  97631. void *setup;
  97632. int set_in_stone;
  97633. double base_setting;
  97634. double long_setting;
  97635. double short_setting;
  97636. double impulse_noisetune;
  97637. int managed;
  97638. long bitrate_min;
  97639. long bitrate_av;
  97640. double bitrate_av_damp;
  97641. long bitrate_max;
  97642. long bitrate_reservoir;
  97643. double bitrate_reservoir_bias;
  97644. int impulse_block_p;
  97645. int noise_normalize_p;
  97646. double stereo_point_setting;
  97647. double lowpass_kHz;
  97648. double ath_floating_dB;
  97649. double ath_absolute_dB;
  97650. double amplitude_track_dBpersec;
  97651. double trigger_setting;
  97652. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97653. } highlevel_encode_setup;
  97654. /*** End of inlined file: highlevel.h ***/
  97655. typedef struct codec_setup_info {
  97656. long blocksizes[2];
  97657. int modes;
  97658. int maps;
  97659. int floors;
  97660. int residues;
  97661. int books;
  97662. int psys; /* encode only */
  97663. vorbis_info_mode *mode_param[64];
  97664. int map_type[64];
  97665. vorbis_info_mapping *map_param[64];
  97666. int floor_type[64];
  97667. vorbis_info_floor *floor_param[64];
  97668. int residue_type[64];
  97669. vorbis_info_residue *residue_param[64];
  97670. static_codebook *book_param[256];
  97671. codebook *fullbooks;
  97672. vorbis_info_psy *psy_param[4]; /* encode only */
  97673. vorbis_info_psy_global psy_g_param;
  97674. bitrate_manager_info bi;
  97675. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97676. highly redundant structure, but
  97677. improves clarity of program flow. */
  97678. int halfrate_flag; /* painless downsample for decode */
  97679. } codec_setup_info;
  97680. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97681. extern void _vp_global_free(vorbis_look_psy_global *look);
  97682. #endif
  97683. /*** End of inlined file: codec_internal.h ***/
  97684. /*** Start of inlined file: registry.h ***/
  97685. #ifndef _V_REG_H_
  97686. #define _V_REG_H_
  97687. #define VI_TRANSFORMB 1
  97688. #define VI_WINDOWB 1
  97689. #define VI_TIMEB 1
  97690. #define VI_FLOORB 2
  97691. #define VI_RESB 3
  97692. #define VI_MAPB 1
  97693. extern vorbis_func_floor *_floor_P[];
  97694. extern vorbis_func_residue *_residue_P[];
  97695. extern vorbis_func_mapping *_mapping_P[];
  97696. #endif
  97697. /*** End of inlined file: registry.h ***/
  97698. /*** Start of inlined file: scales.h ***/
  97699. #ifndef _V_SCALES_H_
  97700. #define _V_SCALES_H_
  97701. #include <math.h>
  97702. #define VORBIS_IEEE_FLOAT32 1
  97703. #ifdef VORBIS_IEEE_FLOAT32
  97704. static float unitnorm(float x){
  97705. union {
  97706. ogg_uint32_t i;
  97707. float f;
  97708. } ix;
  97709. ix.f = x;
  97710. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97711. return ix.f;
  97712. }
  97713. static float todB(const float *x){
  97714. union {
  97715. ogg_uint32_t i;
  97716. float f;
  97717. } ix;
  97718. ix.f = *x;
  97719. ix.i = ix.i&0x7fffffff;
  97720. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97721. }
  97722. #define todB_nn(x) todB(x)
  97723. #else
  97724. static float unitnorm(float x){
  97725. if(x<0)return(-1.f);
  97726. return(1.f);
  97727. }
  97728. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97729. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97730. #endif
  97731. #define fromdB(x) (exp((x)*.11512925f))
  97732. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97733. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97734. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97735. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97736. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97737. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97738. #endif
  97739. /*** End of inlined file: scales.h ***/
  97740. int analysis_noisy=1;
  97741. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97742. int ret,i;
  97743. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97744. vb->glue_bits=0;
  97745. vb->time_bits=0;
  97746. vb->floor_bits=0;
  97747. vb->res_bits=0;
  97748. for(i=0;i<PACKETBLOBS;i++)
  97749. oggpack_reset(vbi->packetblob[i]);
  97750. if((ret=_mapping_P[0]->forward(vb)))
  97751. return(ret);
  97752. if(op){
  97753. if(vorbis_bitrate_managed(vb))
  97754. return(OV_EINVAL);
  97755. op->packet=oggpack_get_buffer(&vb->opb);
  97756. op->bytes=oggpack_bytes(&vb->opb);
  97757. op->b_o_s=0;
  97758. op->e_o_s=vb->eofflag;
  97759. op->granulepos=vb->granulepos;
  97760. op->packetno=vb->sequence; /* for sake of completeness */
  97761. }
  97762. return(0);
  97763. }
  97764. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97765. int j;
  97766. FILE *of;
  97767. char buffer[80];
  97768. sprintf(buffer,"%s_%d.m",base,i);
  97769. of=fopen(buffer,"w");
  97770. if(!of)perror("failed to open data dump file");
  97771. for(j=0;j<n;j++){
  97772. if(bark){
  97773. float b=toBARK((4000.f*j/n)+.25);
  97774. fprintf(of,"%f ",b);
  97775. }else
  97776. if(off!=0)
  97777. fprintf(of,"%f ",(double)(j+off)/8000.);
  97778. else
  97779. fprintf(of,"%f ",(double)j);
  97780. if(dB){
  97781. float val;
  97782. if(v[j]==0.)
  97783. val=-140.;
  97784. else
  97785. val=todB(v+j);
  97786. fprintf(of,"%f\n",val);
  97787. }else{
  97788. fprintf(of,"%f\n",v[j]);
  97789. }
  97790. }
  97791. fclose(of);
  97792. }
  97793. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97794. ogg_int64_t off){
  97795. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97796. }
  97797. #endif
  97798. /*** End of inlined file: analysis.c ***/
  97799. /*** Start of inlined file: bitrate.c ***/
  97800. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97801. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97802. // tasks..
  97803. #if JUCE_MSVC
  97804. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97805. #endif
  97806. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97807. #if JUCE_USE_OGGVORBIS
  97808. #include <stdlib.h>
  97809. #include <string.h>
  97810. #include <math.h>
  97811. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97812. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97813. bitrate_manager_info *bi=&ci->bi;
  97814. memset(bm,0,sizeof(*bm));
  97815. if(bi && (bi->reservoir_bits>0)){
  97816. long ratesamples=vi->rate;
  97817. int halfsamples=ci->blocksizes[0]>>1;
  97818. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97819. bm->managed=1;
  97820. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97821. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97822. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97823. bm->avgfloat=PACKETBLOBS/2;
  97824. {
  97825. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97826. bm->minmax_reservoir=desired_fill;
  97827. bm->avg_reservoir=desired_fill;
  97828. }
  97829. }
  97830. }
  97831. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97832. memset(bm,0,sizeof(*bm));
  97833. return;
  97834. }
  97835. int vorbis_bitrate_managed(vorbis_block *vb){
  97836. vorbis_dsp_state *vd=vb->vd;
  97837. private_state *b=(private_state*)vd->backend_state;
  97838. bitrate_manager_state *bm=&b->bms;
  97839. if(bm && bm->managed)return(1);
  97840. return(0);
  97841. }
  97842. int vorbis_bitrate_addblock(vorbis_block *vb){
  97843. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97844. vorbis_dsp_state *vd=vb->vd;
  97845. private_state *b=(private_state*)vd->backend_state;
  97846. bitrate_manager_state *bm=&b->bms;
  97847. vorbis_info *vi=vd->vi;
  97848. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97849. bitrate_manager_info *bi=&ci->bi;
  97850. int choice=rint(bm->avgfloat);
  97851. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97852. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97853. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97854. int samples=ci->blocksizes[vb->W]>>1;
  97855. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97856. if(!bm->managed){
  97857. if(bm->vb)return(-1); /* one has been submitted without
  97858. being claimed */
  97859. bm->vb=vb;
  97860. return(0);
  97861. }
  97862. bm->vb=vb;
  97863. if(bm->avg_bitsper>0){
  97864. double slew=0.;
  97865. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97866. double slewlimit= 15./bi->slew_damp;
  97867. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97868. while(choice>0 && this_bits>avg_target_bits &&
  97869. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97870. choice--;
  97871. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97872. }
  97873. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97874. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97875. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97876. choice++;
  97877. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97878. }
  97879. }
  97880. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97881. if(slew<-slewlimit)slew=-slewlimit;
  97882. if(slew>slewlimit)slew=slewlimit;
  97883. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97884. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97885. }
  97886. if(bm->min_bitsper>0){
  97887. if(this_bits<min_target_bits){
  97888. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97889. choice++;
  97890. if(choice>=PACKETBLOBS)break;
  97891. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97892. }
  97893. }
  97894. }
  97895. if(bm->max_bitsper>0){
  97896. if(this_bits>max_target_bits){
  97897. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97898. choice--;
  97899. if(choice<0)break;
  97900. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97901. }
  97902. }
  97903. }
  97904. if(choice<0){
  97905. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97906. bm->choice=choice=0;
  97907. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97908. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97909. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97910. }
  97911. }else{
  97912. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97913. if(choice>=PACKETBLOBS)
  97914. choice=PACKETBLOBS-1;
  97915. bm->choice=choice;
  97916. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97917. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97918. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97919. }
  97920. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97921. if(max_target_bits>0 && this_bits>max_target_bits){
  97922. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97923. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97924. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97925. }else{
  97926. if(bm->minmax_reservoir>desired_fill){
  97927. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97928. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97929. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97930. }else{
  97931. bm->minmax_reservoir=desired_fill;
  97932. }
  97933. }else{
  97934. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97935. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97936. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97937. }else{
  97938. bm->minmax_reservoir=desired_fill;
  97939. }
  97940. }
  97941. }
  97942. }
  97943. if(bm->avg_bitsper>0){
  97944. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97945. bm->avg_reservoir+=this_bits-avg_target_bits;
  97946. }
  97947. return(0);
  97948. }
  97949. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97950. private_state *b=(private_state*)vd->backend_state;
  97951. bitrate_manager_state *bm=&b->bms;
  97952. vorbis_block *vb=bm->vb;
  97953. int choice=PACKETBLOBS/2;
  97954. if(!vb)return 0;
  97955. if(op){
  97956. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97957. if(vorbis_bitrate_managed(vb))
  97958. choice=bm->choice;
  97959. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97960. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97961. op->b_o_s=0;
  97962. op->e_o_s=vb->eofflag;
  97963. op->granulepos=vb->granulepos;
  97964. op->packetno=vb->sequence; /* for sake of completeness */
  97965. }
  97966. bm->vb=0;
  97967. return(1);
  97968. }
  97969. #endif
  97970. /*** End of inlined file: bitrate.c ***/
  97971. /*** Start of inlined file: block.c ***/
  97972. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97973. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97974. // tasks..
  97975. #if JUCE_MSVC
  97976. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97977. #endif
  97978. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97979. #if JUCE_USE_OGGVORBIS
  97980. #include <stdio.h>
  97981. #include <stdlib.h>
  97982. #include <string.h>
  97983. /*** Start of inlined file: window.h ***/
  97984. #ifndef _V_WINDOW_
  97985. #define _V_WINDOW_
  97986. extern float *_vorbis_window_get(int n);
  97987. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97988. int lW,int W,int nW);
  97989. #endif
  97990. /*** End of inlined file: window.h ***/
  97991. /*** Start of inlined file: lpc.h ***/
  97992. #ifndef _V_LPC_H_
  97993. #define _V_LPC_H_
  97994. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97995. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97996. float *data,long n);
  97997. #endif
  97998. /*** End of inlined file: lpc.h ***/
  97999. #ifndef WORD_ALIGN
  98000. #define WORD_ALIGN 8
  98001. #endif
  98002. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  98003. int i;
  98004. memset(vb,0,sizeof(*vb));
  98005. vb->vd=v;
  98006. vb->localalloc=0;
  98007. vb->localstore=NULL;
  98008. if(v->analysisp){
  98009. vorbis_block_internal *vbi=(vorbis_block_internal*)
  98010. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  98011. vbi->ampmax=-9999;
  98012. for(i=0;i<PACKETBLOBS;i++){
  98013. if(i==PACKETBLOBS/2){
  98014. vbi->packetblob[i]=&vb->opb;
  98015. }else{
  98016. vbi->packetblob[i]=
  98017. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  98018. }
  98019. oggpack_writeinit(vbi->packetblob[i]);
  98020. }
  98021. }
  98022. return(0);
  98023. }
  98024. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  98025. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  98026. if(bytes+vb->localtop>vb->localalloc){
  98027. if(vb->localstore){
  98028. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  98029. vb->totaluse+=vb->localtop;
  98030. link->next=vb->reap;
  98031. link->ptr=vb->localstore;
  98032. vb->reap=link;
  98033. }
  98034. vb->localalloc=bytes;
  98035. vb->localstore=_ogg_malloc(vb->localalloc);
  98036. vb->localtop=0;
  98037. }
  98038. {
  98039. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  98040. vb->localtop+=bytes;
  98041. return ret;
  98042. }
  98043. }
  98044. void _vorbis_block_ripcord(vorbis_block *vb){
  98045. struct alloc_chain *reap=vb->reap;
  98046. while(reap){
  98047. struct alloc_chain *next=reap->next;
  98048. _ogg_free(reap->ptr);
  98049. memset(reap,0,sizeof(*reap));
  98050. _ogg_free(reap);
  98051. reap=next;
  98052. }
  98053. if(vb->totaluse){
  98054. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  98055. vb->localalloc+=vb->totaluse;
  98056. vb->totaluse=0;
  98057. }
  98058. vb->localtop=0;
  98059. vb->reap=NULL;
  98060. }
  98061. int vorbis_block_clear(vorbis_block *vb){
  98062. int i;
  98063. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98064. _vorbis_block_ripcord(vb);
  98065. if(vb->localstore)_ogg_free(vb->localstore);
  98066. if(vbi){
  98067. for(i=0;i<PACKETBLOBS;i++){
  98068. oggpack_writeclear(vbi->packetblob[i]);
  98069. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  98070. }
  98071. _ogg_free(vbi);
  98072. }
  98073. memset(vb,0,sizeof(*vb));
  98074. return(0);
  98075. }
  98076. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  98077. int i;
  98078. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98079. private_state *b=NULL;
  98080. int hs;
  98081. if(ci==NULL) return 1;
  98082. hs=ci->halfrate_flag;
  98083. memset(v,0,sizeof(*v));
  98084. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  98085. v->vi=vi;
  98086. b->modebits=ilog2(ci->modes);
  98087. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  98088. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  98089. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98090. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98091. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  98092. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  98093. b->window[0]=ilog2(ci->blocksizes[0])-6;
  98094. b->window[1]=ilog2(ci->blocksizes[1])-6;
  98095. if(encp){ /* encode/decode differ here */
  98096. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  98097. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  98098. if(!ci->fullbooks){
  98099. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98100. for(i=0;i<ci->books;i++)
  98101. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  98102. }
  98103. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  98104. for(i=0;i<ci->psys;i++){
  98105. _vp_psy_init(b->psy+i,
  98106. ci->psy_param[i],
  98107. &ci->psy_g_param,
  98108. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  98109. vi->rate);
  98110. }
  98111. v->analysisp=1;
  98112. }else{
  98113. if(!ci->fullbooks){
  98114. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98115. for(i=0;i<ci->books;i++){
  98116. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  98117. vorbis_staticbook_destroy(ci->book_param[i]);
  98118. ci->book_param[i]=NULL;
  98119. }
  98120. }
  98121. }
  98122. v->pcm_storage=ci->blocksizes[1];
  98123. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  98124. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  98125. {
  98126. int i;
  98127. for(i=0;i<vi->channels;i++)
  98128. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  98129. }
  98130. v->lW=0; /* previous window size */
  98131. v->W=0; /* current window size */
  98132. v->centerW=ci->blocksizes[1]/2;
  98133. v->pcm_current=v->centerW;
  98134. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  98135. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  98136. for(i=0;i<ci->floors;i++)
  98137. b->flr[i]=_floor_P[ci->floor_type[i]]->
  98138. look(v,ci->floor_param[i]);
  98139. for(i=0;i<ci->residues;i++)
  98140. b->residue[i]=_residue_P[ci->residue_type[i]]->
  98141. look(v,ci->residue_param[i]);
  98142. return 0;
  98143. }
  98144. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98145. private_state *b=NULL;
  98146. if(_vds_shared_init(v,vi,1))return 1;
  98147. b=(private_state*)v->backend_state;
  98148. b->psy_g_look=_vp_global_look(vi);
  98149. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  98150. _ve_envelope_init(b->ve,vi);
  98151. vorbis_bitrate_init(vi,&b->bms);
  98152. v->sequence=3;
  98153. return(0);
  98154. }
  98155. void vorbis_dsp_clear(vorbis_dsp_state *v){
  98156. int i;
  98157. if(v){
  98158. vorbis_info *vi=v->vi;
  98159. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  98160. private_state *b=(private_state*)v->backend_state;
  98161. if(b){
  98162. if(b->ve){
  98163. _ve_envelope_clear(b->ve);
  98164. _ogg_free(b->ve);
  98165. }
  98166. if(b->transform[0]){
  98167. mdct_clear((mdct_lookup*) b->transform[0][0]);
  98168. _ogg_free(b->transform[0][0]);
  98169. _ogg_free(b->transform[0]);
  98170. }
  98171. if(b->transform[1]){
  98172. mdct_clear((mdct_lookup*) b->transform[1][0]);
  98173. _ogg_free(b->transform[1][0]);
  98174. _ogg_free(b->transform[1]);
  98175. }
  98176. if(b->flr){
  98177. for(i=0;i<ci->floors;i++)
  98178. _floor_P[ci->floor_type[i]]->
  98179. free_look(b->flr[i]);
  98180. _ogg_free(b->flr);
  98181. }
  98182. if(b->residue){
  98183. for(i=0;i<ci->residues;i++)
  98184. _residue_P[ci->residue_type[i]]->
  98185. free_look(b->residue[i]);
  98186. _ogg_free(b->residue);
  98187. }
  98188. if(b->psy){
  98189. for(i=0;i<ci->psys;i++)
  98190. _vp_psy_clear(b->psy+i);
  98191. _ogg_free(b->psy);
  98192. }
  98193. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  98194. vorbis_bitrate_clear(&b->bms);
  98195. drft_clear(&b->fft_look[0]);
  98196. drft_clear(&b->fft_look[1]);
  98197. }
  98198. if(v->pcm){
  98199. for(i=0;i<vi->channels;i++)
  98200. if(v->pcm[i])_ogg_free(v->pcm[i]);
  98201. _ogg_free(v->pcm);
  98202. if(v->pcmret)_ogg_free(v->pcmret);
  98203. }
  98204. if(b){
  98205. if(b->header)_ogg_free(b->header);
  98206. if(b->header1)_ogg_free(b->header1);
  98207. if(b->header2)_ogg_free(b->header2);
  98208. _ogg_free(b);
  98209. }
  98210. memset(v,0,sizeof(*v));
  98211. }
  98212. }
  98213. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  98214. int i;
  98215. vorbis_info *vi=v->vi;
  98216. private_state *b=(private_state*)v->backend_state;
  98217. if(b->header)_ogg_free(b->header);b->header=NULL;
  98218. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  98219. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  98220. if(v->pcm_current+vals>=v->pcm_storage){
  98221. v->pcm_storage=v->pcm_current+vals*2;
  98222. for(i=0;i<vi->channels;i++){
  98223. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  98224. }
  98225. }
  98226. for(i=0;i<vi->channels;i++)
  98227. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  98228. return(v->pcmret);
  98229. }
  98230. static void _preextrapolate_helper(vorbis_dsp_state *v){
  98231. int i;
  98232. int order=32;
  98233. float *lpc=(float*)alloca(order*sizeof(*lpc));
  98234. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  98235. long j;
  98236. v->preextrapolate=1;
  98237. if(v->pcm_current-v->centerW>order*2){ /* safety */
  98238. for(i=0;i<v->vi->channels;i++){
  98239. for(j=0;j<v->pcm_current;j++)
  98240. work[j]=v->pcm[i][v->pcm_current-j-1];
  98241. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  98242. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  98243. order,
  98244. work+v->pcm_current-v->centerW,
  98245. v->centerW);
  98246. for(j=0;j<v->pcm_current;j++)
  98247. v->pcm[i][v->pcm_current-j-1]=work[j];
  98248. }
  98249. }
  98250. }
  98251. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  98252. vorbis_info *vi=v->vi;
  98253. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98254. if(vals<=0){
  98255. int order=32;
  98256. int i;
  98257. float *lpc=(float*) alloca(order*sizeof(*lpc));
  98258. if(!v->preextrapolate)
  98259. _preextrapolate_helper(v);
  98260. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  98261. v->eofflag=v->pcm_current;
  98262. v->pcm_current+=ci->blocksizes[1]*3;
  98263. for(i=0;i<vi->channels;i++){
  98264. if(v->eofflag>order*2){
  98265. long n;
  98266. n=v->eofflag;
  98267. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  98268. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  98269. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  98270. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  98271. }else{
  98272. memset(v->pcm[i]+v->eofflag,0,
  98273. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  98274. }
  98275. }
  98276. }else{
  98277. if(v->pcm_current+vals>v->pcm_storage)
  98278. return(OV_EINVAL);
  98279. v->pcm_current+=vals;
  98280. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  98281. _preextrapolate_helper(v);
  98282. }
  98283. return(0);
  98284. }
  98285. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98286. int i;
  98287. vorbis_info *vi=v->vi;
  98288. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98289. private_state *b=(private_state*)v->backend_state;
  98290. vorbis_look_psy_global *g=b->psy_g_look;
  98291. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98292. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98293. if(!v->preextrapolate)return(0);
  98294. if(v->eofflag==-1)return(0);
  98295. {
  98296. long bp=_ve_envelope_search(v);
  98297. if(bp==-1){
  98298. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98299. full long block */
  98300. v->nW=0;
  98301. }else{
  98302. if(ci->blocksizes[0]==ci->blocksizes[1])
  98303. v->nW=0;
  98304. else
  98305. v->nW=bp;
  98306. }
  98307. }
  98308. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98309. {
  98310. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98311. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98312. although this check is
  98313. less strict that the
  98314. _ve_envelope_search,
  98315. the search is not run
  98316. if we only use one
  98317. block size */
  98318. }
  98319. _vorbis_block_ripcord(vb);
  98320. vb->lW=v->lW;
  98321. vb->W=v->W;
  98322. vb->nW=v->nW;
  98323. if(v->W){
  98324. if(!v->lW || !v->nW){
  98325. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98326. }else{
  98327. vbi->blocktype=BLOCKTYPE_LONG;
  98328. }
  98329. }else{
  98330. if(_ve_envelope_mark(v)){
  98331. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98332. }else{
  98333. vbi->blocktype=BLOCKTYPE_PADDING;
  98334. }
  98335. }
  98336. vb->vd=v;
  98337. vb->sequence=v->sequence++;
  98338. vb->granulepos=v->granulepos;
  98339. vb->pcmend=ci->blocksizes[v->W];
  98340. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98341. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98342. vbi->ampmax=g->ampmax;
  98343. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98344. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98345. for(i=0;i<vi->channels;i++){
  98346. vbi->pcmdelay[i]=
  98347. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98348. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98349. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98350. }
  98351. if(v->eofflag){
  98352. if(v->centerW>=v->eofflag){
  98353. v->eofflag=-1;
  98354. vb->eofflag=1;
  98355. return(1);
  98356. }
  98357. }
  98358. {
  98359. int new_centerNext=ci->blocksizes[1]/2;
  98360. int movementW=centerNext-new_centerNext;
  98361. if(movementW>0){
  98362. _ve_envelope_shift(b->ve,movementW);
  98363. v->pcm_current-=movementW;
  98364. for(i=0;i<vi->channels;i++)
  98365. memmove(v->pcm[i],v->pcm[i]+movementW,
  98366. v->pcm_current*sizeof(*v->pcm[i]));
  98367. v->lW=v->W;
  98368. v->W=v->nW;
  98369. v->centerW=new_centerNext;
  98370. if(v->eofflag){
  98371. v->eofflag-=movementW;
  98372. if(v->eofflag<=0)v->eofflag=-1;
  98373. if(v->centerW>=v->eofflag){
  98374. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98375. }else{
  98376. v->granulepos+=movementW;
  98377. }
  98378. }else{
  98379. v->granulepos+=movementW;
  98380. }
  98381. }
  98382. }
  98383. return(1);
  98384. }
  98385. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98386. vorbis_info *vi=v->vi;
  98387. codec_setup_info *ci;
  98388. int hs;
  98389. if(!v->backend_state)return -1;
  98390. if(!vi)return -1;
  98391. ci=(codec_setup_info*) vi->codec_setup;
  98392. if(!ci)return -1;
  98393. hs=ci->halfrate_flag;
  98394. v->centerW=ci->blocksizes[1]>>(hs+1);
  98395. v->pcm_current=v->centerW>>hs;
  98396. v->pcm_returned=-1;
  98397. v->granulepos=-1;
  98398. v->sequence=-1;
  98399. v->eofflag=0;
  98400. ((private_state *)(v->backend_state))->sample_count=-1;
  98401. return(0);
  98402. }
  98403. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98404. if(_vds_shared_init(v,vi,0)) return 1;
  98405. vorbis_synthesis_restart(v);
  98406. return 0;
  98407. }
  98408. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98409. vorbis_info *vi=v->vi;
  98410. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98411. private_state *b=(private_state*)v->backend_state;
  98412. int hs=ci->halfrate_flag;
  98413. int i,j;
  98414. if(!vb)return(OV_EINVAL);
  98415. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98416. v->lW=v->W;
  98417. v->W=vb->W;
  98418. v->nW=-1;
  98419. if((v->sequence==-1)||
  98420. (v->sequence+1 != vb->sequence)){
  98421. v->granulepos=-1; /* out of sequence; lose count */
  98422. b->sample_count=-1;
  98423. }
  98424. v->sequence=vb->sequence;
  98425. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98426. was called on block */
  98427. int n=ci->blocksizes[v->W]>>(hs+1);
  98428. int n0=ci->blocksizes[0]>>(hs+1);
  98429. int n1=ci->blocksizes[1]>>(hs+1);
  98430. int thisCenter;
  98431. int prevCenter;
  98432. v->glue_bits+=vb->glue_bits;
  98433. v->time_bits+=vb->time_bits;
  98434. v->floor_bits+=vb->floor_bits;
  98435. v->res_bits+=vb->res_bits;
  98436. if(v->centerW){
  98437. thisCenter=n1;
  98438. prevCenter=0;
  98439. }else{
  98440. thisCenter=0;
  98441. prevCenter=n1;
  98442. }
  98443. for(j=0;j<vi->channels;j++){
  98444. if(v->lW){
  98445. if(v->W){
  98446. float *w=_vorbis_window_get(b->window[1]-hs);
  98447. float *pcm=v->pcm[j]+prevCenter;
  98448. float *p=vb->pcm[j];
  98449. for(i=0;i<n1;i++)
  98450. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98451. }else{
  98452. float *w=_vorbis_window_get(b->window[0]-hs);
  98453. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98454. float *p=vb->pcm[j];
  98455. for(i=0;i<n0;i++)
  98456. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98457. }
  98458. }else{
  98459. if(v->W){
  98460. float *w=_vorbis_window_get(b->window[0]-hs);
  98461. float *pcm=v->pcm[j]+prevCenter;
  98462. float *p=vb->pcm[j]+n1/2-n0/2;
  98463. for(i=0;i<n0;i++)
  98464. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98465. for(;i<n1/2+n0/2;i++)
  98466. pcm[i]=p[i];
  98467. }else{
  98468. float *w=_vorbis_window_get(b->window[0]-hs);
  98469. float *pcm=v->pcm[j]+prevCenter;
  98470. float *p=vb->pcm[j];
  98471. for(i=0;i<n0;i++)
  98472. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98473. }
  98474. }
  98475. {
  98476. float *pcm=v->pcm[j]+thisCenter;
  98477. float *p=vb->pcm[j]+n;
  98478. for(i=0;i<n;i++)
  98479. pcm[i]=p[i];
  98480. }
  98481. }
  98482. if(v->centerW)
  98483. v->centerW=0;
  98484. else
  98485. v->centerW=n1;
  98486. if(v->pcm_returned==-1){
  98487. v->pcm_returned=thisCenter;
  98488. v->pcm_current=thisCenter;
  98489. }else{
  98490. v->pcm_returned=prevCenter;
  98491. v->pcm_current=prevCenter+
  98492. ((ci->blocksizes[v->lW]/4+
  98493. ci->blocksizes[v->W]/4)>>hs);
  98494. }
  98495. }
  98496. if(b->sample_count==-1){
  98497. b->sample_count=0;
  98498. }else{
  98499. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98500. }
  98501. if(v->granulepos==-1){
  98502. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98503. v->granulepos=vb->granulepos;
  98504. if(b->sample_count>v->granulepos){
  98505. if(vb->eofflag){
  98506. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98507. }else{
  98508. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98509. if(v->pcm_returned>v->pcm_current)
  98510. v->pcm_returned=v->pcm_current;
  98511. }
  98512. }
  98513. }
  98514. }else{
  98515. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98516. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98517. if(v->granulepos>vb->granulepos){
  98518. long extra=v->granulepos-vb->granulepos;
  98519. if(extra)
  98520. if(vb->eofflag){
  98521. v->pcm_current-=extra>>hs;
  98522. } /* else {Shouldn't happen *unless* the bitstream is out of
  98523. spec. Either way, believe the bitstream } */
  98524. } /* else {Shouldn't happen *unless* the bitstream is out of
  98525. spec. Either way, believe the bitstream } */
  98526. v->granulepos=vb->granulepos;
  98527. }
  98528. }
  98529. if(vb->eofflag)v->eofflag=1;
  98530. return(0);
  98531. }
  98532. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98533. vorbis_info *vi=v->vi;
  98534. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98535. if(pcm){
  98536. int i;
  98537. for(i=0;i<vi->channels;i++)
  98538. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98539. *pcm=v->pcmret;
  98540. }
  98541. return(v->pcm_current-v->pcm_returned);
  98542. }
  98543. return(0);
  98544. }
  98545. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98546. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98547. v->pcm_returned+=n;
  98548. return(0);
  98549. }
  98550. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98551. vorbis_info *vi=v->vi;
  98552. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98553. int hs=ci->halfrate_flag;
  98554. int n=ci->blocksizes[v->W]>>(hs+1);
  98555. int n0=ci->blocksizes[0]>>(hs+1);
  98556. int n1=ci->blocksizes[1]>>(hs+1);
  98557. int i,j;
  98558. if(v->pcm_returned<0)return 0;
  98559. if(v->centerW==n1){
  98560. for(j=0;j<vi->channels;j++){
  98561. float *p=v->pcm[j];
  98562. for(i=0;i<n1;i++){
  98563. float temp=p[i];
  98564. p[i]=p[i+n1];
  98565. p[i+n1]=temp;
  98566. }
  98567. }
  98568. v->pcm_current-=n1;
  98569. v->pcm_returned-=n1;
  98570. v->centerW=0;
  98571. }
  98572. if((v->lW^v->W)==1){
  98573. for(j=0;j<vi->channels;j++){
  98574. float *s=v->pcm[j];
  98575. float *d=v->pcm[j]+(n1-n0)/2;
  98576. for(i=(n1+n0)/2-1;i>=0;--i)
  98577. d[i]=s[i];
  98578. }
  98579. v->pcm_returned+=(n1-n0)/2;
  98580. v->pcm_current+=(n1-n0)/2;
  98581. }else{
  98582. if(v->lW==0){
  98583. for(j=0;j<vi->channels;j++){
  98584. float *s=v->pcm[j];
  98585. float *d=v->pcm[j]+n1-n0;
  98586. for(i=n0-1;i>=0;--i)
  98587. d[i]=s[i];
  98588. }
  98589. v->pcm_returned+=n1-n0;
  98590. v->pcm_current+=n1-n0;
  98591. }
  98592. }
  98593. if(pcm){
  98594. int i;
  98595. for(i=0;i<vi->channels;i++)
  98596. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98597. *pcm=v->pcmret;
  98598. }
  98599. return(n1+n-v->pcm_returned);
  98600. }
  98601. float *vorbis_window(vorbis_dsp_state *v,int W){
  98602. vorbis_info *vi=v->vi;
  98603. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98604. int hs=ci->halfrate_flag;
  98605. private_state *b=(private_state*)v->backend_state;
  98606. if(b->window[W]-1<0)return NULL;
  98607. return _vorbis_window_get(b->window[W]-hs);
  98608. }
  98609. #endif
  98610. /*** End of inlined file: block.c ***/
  98611. /*** Start of inlined file: codebook.c ***/
  98612. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98613. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98614. // tasks..
  98615. #if JUCE_MSVC
  98616. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98617. #endif
  98618. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98619. #if JUCE_USE_OGGVORBIS
  98620. #include <stdlib.h>
  98621. #include <string.h>
  98622. #include <math.h>
  98623. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98624. long i,j;
  98625. int ordered=0;
  98626. oggpack_write(opb,0x564342,24);
  98627. oggpack_write(opb,c->dim,16);
  98628. oggpack_write(opb,c->entries,24);
  98629. for(i=1;i<c->entries;i++)
  98630. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98631. if(i==c->entries)ordered=1;
  98632. if(ordered){
  98633. long count=0;
  98634. oggpack_write(opb,1,1); /* ordered */
  98635. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98636. for(i=1;i<c->entries;i++){
  98637. long thisx=c->lengthlist[i];
  98638. long last=c->lengthlist[i-1];
  98639. if(thisx>last){
  98640. for(j=last;j<thisx;j++){
  98641. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98642. count=i;
  98643. }
  98644. }
  98645. }
  98646. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98647. }else{
  98648. oggpack_write(opb,0,1); /* unordered */
  98649. for(i=0;i<c->entries;i++)
  98650. if(c->lengthlist[i]==0)break;
  98651. if(i==c->entries){
  98652. oggpack_write(opb,0,1); /* no unused entries */
  98653. for(i=0;i<c->entries;i++)
  98654. oggpack_write(opb,c->lengthlist[i]-1,5);
  98655. }else{
  98656. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98657. for(i=0;i<c->entries;i++){
  98658. if(c->lengthlist[i]==0){
  98659. oggpack_write(opb,0,1);
  98660. }else{
  98661. oggpack_write(opb,1,1);
  98662. oggpack_write(opb,c->lengthlist[i]-1,5);
  98663. }
  98664. }
  98665. }
  98666. }
  98667. oggpack_write(opb,c->maptype,4);
  98668. switch(c->maptype){
  98669. case 0:
  98670. break;
  98671. case 1:case 2:
  98672. if(!c->quantlist){
  98673. return(-1);
  98674. }
  98675. oggpack_write(opb,c->q_min,32);
  98676. oggpack_write(opb,c->q_delta,32);
  98677. oggpack_write(opb,c->q_quant-1,4);
  98678. oggpack_write(opb,c->q_sequencep,1);
  98679. {
  98680. int quantvals;
  98681. switch(c->maptype){
  98682. case 1:
  98683. quantvals=_book_maptype1_quantvals(c);
  98684. break;
  98685. case 2:
  98686. quantvals=c->entries*c->dim;
  98687. break;
  98688. default: /* NOT_REACHABLE */
  98689. quantvals=-1;
  98690. }
  98691. for(i=0;i<quantvals;i++)
  98692. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98693. }
  98694. break;
  98695. default:
  98696. return(-1);
  98697. }
  98698. return(0);
  98699. }
  98700. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98701. long i,j;
  98702. memset(s,0,sizeof(*s));
  98703. s->allocedp=1;
  98704. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98705. s->dim=oggpack_read(opb,16);
  98706. s->entries=oggpack_read(opb,24);
  98707. if(s->entries==-1)goto _eofout;
  98708. switch((int)oggpack_read(opb,1)){
  98709. case 0:
  98710. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98711. if(oggpack_read(opb,1)){
  98712. for(i=0;i<s->entries;i++){
  98713. if(oggpack_read(opb,1)){
  98714. long num=oggpack_read(opb,5);
  98715. if(num==-1)goto _eofout;
  98716. s->lengthlist[i]=num+1;
  98717. }else
  98718. s->lengthlist[i]=0;
  98719. }
  98720. }else{
  98721. for(i=0;i<s->entries;i++){
  98722. long num=oggpack_read(opb,5);
  98723. if(num==-1)goto _eofout;
  98724. s->lengthlist[i]=num+1;
  98725. }
  98726. }
  98727. break;
  98728. case 1:
  98729. {
  98730. long length=oggpack_read(opb,5)+1;
  98731. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98732. for(i=0;i<s->entries;){
  98733. long num=oggpack_read(opb,_ilog(s->entries-i));
  98734. if(num==-1)goto _eofout;
  98735. for(j=0;j<num && i<s->entries;j++,i++)
  98736. s->lengthlist[i]=length;
  98737. length++;
  98738. }
  98739. }
  98740. break;
  98741. default:
  98742. return(-1);
  98743. }
  98744. switch((s->maptype=oggpack_read(opb,4))){
  98745. case 0:
  98746. break;
  98747. case 1: case 2:
  98748. s->q_min=oggpack_read(opb,32);
  98749. s->q_delta=oggpack_read(opb,32);
  98750. s->q_quant=oggpack_read(opb,4)+1;
  98751. s->q_sequencep=oggpack_read(opb,1);
  98752. {
  98753. int quantvals=0;
  98754. switch(s->maptype){
  98755. case 1:
  98756. quantvals=_book_maptype1_quantvals(s);
  98757. break;
  98758. case 2:
  98759. quantvals=s->entries*s->dim;
  98760. break;
  98761. }
  98762. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98763. for(i=0;i<quantvals;i++)
  98764. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98765. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98766. }
  98767. break;
  98768. default:
  98769. goto _errout;
  98770. }
  98771. return(0);
  98772. _errout:
  98773. _eofout:
  98774. vorbis_staticbook_clear(s);
  98775. return(-1);
  98776. }
  98777. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98778. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98779. return(book->c->lengthlist[a]);
  98780. }
  98781. int vorbis_book_errorv(codebook *book,float *a){
  98782. int dim=book->dim,k;
  98783. int best=_best(book,a,1);
  98784. for(k=0;k<dim;k++)
  98785. a[k]=(book->valuelist+best*dim)[k];
  98786. return(best);
  98787. }
  98788. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98789. int k,dim=book->dim;
  98790. for(k=0;k<dim;k++)
  98791. a[k]=(book->valuelist+best*dim)[k];
  98792. return(vorbis_book_encode(book,best,b));
  98793. }
  98794. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98795. int read=book->dec_maxlength;
  98796. long lo,hi;
  98797. long lok = oggpack_look(b,book->dec_firsttablen);
  98798. if (lok >= 0) {
  98799. long entry = book->dec_firsttable[lok];
  98800. if(entry&0x80000000UL){
  98801. lo=(entry>>15)&0x7fff;
  98802. hi=book->used_entries-(entry&0x7fff);
  98803. }else{
  98804. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98805. return(entry-1);
  98806. }
  98807. }else{
  98808. lo=0;
  98809. hi=book->used_entries;
  98810. }
  98811. lok = oggpack_look(b, read);
  98812. while(lok<0 && read>1)
  98813. lok = oggpack_look(b, --read);
  98814. if(lok<0)return -1;
  98815. {
  98816. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98817. while(hi-lo>1){
  98818. long p=(hi-lo)>>1;
  98819. long test=book->codelist[lo+p]>testword;
  98820. lo+=p&(test-1);
  98821. hi-=p&(-test);
  98822. }
  98823. if(book->dec_codelengths[lo]<=read){
  98824. oggpack_adv(b, book->dec_codelengths[lo]);
  98825. return(lo);
  98826. }
  98827. }
  98828. oggpack_adv(b, read);
  98829. return(-1);
  98830. }
  98831. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98832. long packed_entry=decode_packed_entry_number(book,b);
  98833. if(packed_entry>=0)
  98834. return(book->dec_index[packed_entry]);
  98835. return(packed_entry);
  98836. }
  98837. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98838. int step=n/book->dim;
  98839. long *entry = (long*)alloca(sizeof(*entry)*step);
  98840. float **t = (float**)alloca(sizeof(*t)*step);
  98841. int i,j,o;
  98842. for (i = 0; i < step; i++) {
  98843. entry[i]=decode_packed_entry_number(book,b);
  98844. if(entry[i]==-1)return(-1);
  98845. t[i] = book->valuelist+entry[i]*book->dim;
  98846. }
  98847. for(i=0,o=0;i<book->dim;i++,o+=step)
  98848. for (j=0;j<step;j++)
  98849. a[o+j]+=t[j][i];
  98850. return(0);
  98851. }
  98852. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98853. int i,j,entry;
  98854. float *t;
  98855. if(book->dim>8){
  98856. for(i=0;i<n;){
  98857. entry = decode_packed_entry_number(book,b);
  98858. if(entry==-1)return(-1);
  98859. t = book->valuelist+entry*book->dim;
  98860. for (j=0;j<book->dim;)
  98861. a[i++]+=t[j++];
  98862. }
  98863. }else{
  98864. for(i=0;i<n;){
  98865. entry = decode_packed_entry_number(book,b);
  98866. if(entry==-1)return(-1);
  98867. t = book->valuelist+entry*book->dim;
  98868. j=0;
  98869. switch((int)book->dim){
  98870. case 8:
  98871. a[i++]+=t[j++];
  98872. case 7:
  98873. a[i++]+=t[j++];
  98874. case 6:
  98875. a[i++]+=t[j++];
  98876. case 5:
  98877. a[i++]+=t[j++];
  98878. case 4:
  98879. a[i++]+=t[j++];
  98880. case 3:
  98881. a[i++]+=t[j++];
  98882. case 2:
  98883. a[i++]+=t[j++];
  98884. case 1:
  98885. a[i++]+=t[j++];
  98886. case 0:
  98887. break;
  98888. }
  98889. }
  98890. }
  98891. return(0);
  98892. }
  98893. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98894. int i,j,entry;
  98895. float *t;
  98896. for(i=0;i<n;){
  98897. entry = decode_packed_entry_number(book,b);
  98898. if(entry==-1)return(-1);
  98899. t = book->valuelist+entry*book->dim;
  98900. for (j=0;j<book->dim;)
  98901. a[i++]=t[j++];
  98902. }
  98903. return(0);
  98904. }
  98905. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98906. oggpack_buffer *b,int n){
  98907. long i,j,entry;
  98908. int chptr=0;
  98909. for(i=offset/ch;i<(offset+n)/ch;){
  98910. entry = decode_packed_entry_number(book,b);
  98911. if(entry==-1)return(-1);
  98912. {
  98913. const float *t = book->valuelist+entry*book->dim;
  98914. for (j=0;j<book->dim;j++){
  98915. a[chptr++][i]+=t[j];
  98916. if(chptr==ch){
  98917. chptr=0;
  98918. i++;
  98919. }
  98920. }
  98921. }
  98922. }
  98923. return(0);
  98924. }
  98925. #ifdef _V_SELFTEST
  98926. #include <stdio.h>
  98927. #include "vorbis/book/lsp20_0.vqh"
  98928. #include "vorbis/book/res0a_13.vqh"
  98929. #define TESTSIZE 40
  98930. float test1[TESTSIZE]={
  98931. 0.105939f,
  98932. 0.215373f,
  98933. 0.429117f,
  98934. 0.587974f,
  98935. 0.181173f,
  98936. 0.296583f,
  98937. 0.515707f,
  98938. 0.715261f,
  98939. 0.162327f,
  98940. 0.263834f,
  98941. 0.342876f,
  98942. 0.406025f,
  98943. 0.103571f,
  98944. 0.223561f,
  98945. 0.368513f,
  98946. 0.540313f,
  98947. 0.136672f,
  98948. 0.395882f,
  98949. 0.587183f,
  98950. 0.652476f,
  98951. 0.114338f,
  98952. 0.417300f,
  98953. 0.525486f,
  98954. 0.698679f,
  98955. 0.147492f,
  98956. 0.324481f,
  98957. 0.643089f,
  98958. 0.757582f,
  98959. 0.139556f,
  98960. 0.215795f,
  98961. 0.324559f,
  98962. 0.399387f,
  98963. 0.120236f,
  98964. 0.267420f,
  98965. 0.446940f,
  98966. 0.608760f,
  98967. 0.115587f,
  98968. 0.287234f,
  98969. 0.571081f,
  98970. 0.708603f,
  98971. };
  98972. float test3[TESTSIZE]={
  98973. 0,1,-2,3,4,-5,6,7,8,9,
  98974. 8,-2,7,-1,4,6,8,3,1,-9,
  98975. 10,11,12,13,14,15,26,17,18,19,
  98976. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98977. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98978. &_vq_book_res0a_13,NULL};
  98979. float *testvec[]={test1,test3};
  98980. int main(){
  98981. oggpack_buffer write;
  98982. oggpack_buffer read;
  98983. long ptr=0,i;
  98984. oggpack_writeinit(&write);
  98985. fprintf(stderr,"Testing codebook abstraction...:\n");
  98986. while(testlist[ptr]){
  98987. codebook c;
  98988. static_codebook s;
  98989. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98990. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98991. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98992. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98993. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98994. oggpack_reset(&write);
  98995. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98996. we can write */
  98997. vorbis_staticbook_pack(testlist[ptr],&write);
  98998. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98999. for(i=0;i<TESTSIZE;i+=c.dim){
  99000. int best=_best(&c,qv+i,1);
  99001. vorbis_book_encodev(&c,best,qv+i,&write);
  99002. }
  99003. vorbis_book_clear(&c);
  99004. fprintf(stderr,"OK.\n");
  99005. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  99006. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  99007. if(vorbis_staticbook_unpack(&read,&s)){
  99008. fprintf(stderr,"Error unpacking codebook.\n");
  99009. exit(1);
  99010. }
  99011. if(vorbis_book_init_decode(&c,&s)){
  99012. fprintf(stderr,"Error initializing codebook.\n");
  99013. exit(1);
  99014. }
  99015. for(i=0;i<TESTSIZE;i+=c.dim)
  99016. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  99017. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  99018. exit(1);
  99019. }
  99020. for(i=0;i<TESTSIZE;i++)
  99021. if(fabs(qv[i]-iv[i])>.000001){
  99022. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  99023. iv[i],qv[i],i);
  99024. exit(1);
  99025. }
  99026. fprintf(stderr,"OK\n");
  99027. ptr++;
  99028. }
  99029. exit(0);
  99030. }
  99031. #endif
  99032. #endif
  99033. /*** End of inlined file: codebook.c ***/
  99034. /*** Start of inlined file: envelope.c ***/
  99035. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99036. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99037. // tasks..
  99038. #if JUCE_MSVC
  99039. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99040. #endif
  99041. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99042. #if JUCE_USE_OGGVORBIS
  99043. #include <stdlib.h>
  99044. #include <string.h>
  99045. #include <stdio.h>
  99046. #include <math.h>
  99047. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  99048. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99049. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99050. int ch=vi->channels;
  99051. int i,j;
  99052. int n=e->winlength=128;
  99053. e->searchstep=64; /* not random */
  99054. e->minenergy=gi->preecho_minenergy;
  99055. e->ch=ch;
  99056. e->storage=128;
  99057. e->cursor=ci->blocksizes[1]/2;
  99058. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  99059. mdct_init(&e->mdct,n);
  99060. for(i=0;i<n;i++){
  99061. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  99062. e->mdct_win[i]*=e->mdct_win[i];
  99063. }
  99064. e->band[0].begin=2; e->band[0].end=4;
  99065. e->band[1].begin=4; e->band[1].end=5;
  99066. e->band[2].begin=6; e->band[2].end=6;
  99067. e->band[3].begin=9; e->band[3].end=8;
  99068. e->band[4].begin=13; e->band[4].end=8;
  99069. e->band[5].begin=17; e->band[5].end=8;
  99070. e->band[6].begin=22; e->band[6].end=8;
  99071. for(j=0;j<VE_BANDS;j++){
  99072. n=e->band[j].end;
  99073. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  99074. for(i=0;i<n;i++){
  99075. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  99076. e->band[j].total+=e->band[j].window[i];
  99077. }
  99078. e->band[j].total=1./e->band[j].total;
  99079. }
  99080. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  99081. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  99082. }
  99083. void _ve_envelope_clear(envelope_lookup *e){
  99084. int i;
  99085. mdct_clear(&e->mdct);
  99086. for(i=0;i<VE_BANDS;i++)
  99087. _ogg_free(e->band[i].window);
  99088. _ogg_free(e->mdct_win);
  99089. _ogg_free(e->filter);
  99090. _ogg_free(e->mark);
  99091. memset(e,0,sizeof(*e));
  99092. }
  99093. static int _ve_amp(envelope_lookup *ve,
  99094. vorbis_info_psy_global *gi,
  99095. float *data,
  99096. envelope_band *bands,
  99097. envelope_filter_state *filters,
  99098. long pos){
  99099. long n=ve->winlength;
  99100. int ret=0;
  99101. long i,j;
  99102. float decay;
  99103. float minV=ve->minenergy;
  99104. float *vec=(float*) alloca(n*sizeof(*vec));
  99105. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  99106. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  99107. if(penalty<0.f)penalty=0.f;
  99108. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  99109. for(i=0;i<n;i++)
  99110. vec[i]=data[i]*ve->mdct_win[i];
  99111. mdct_forward(&ve->mdct,vec,vec);
  99112. {
  99113. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  99114. int ptr=filters->nearptr;
  99115. if(ptr==0){
  99116. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  99117. filters->nearDC_partialacc=temp;
  99118. }else{
  99119. decay=filters->nearDC_acc+=temp;
  99120. filters->nearDC_partialacc+=temp;
  99121. }
  99122. filters->nearDC_acc-=filters->nearDC[ptr];
  99123. filters->nearDC[ptr]=temp;
  99124. decay*=(1./(VE_NEARDC+1));
  99125. filters->nearptr++;
  99126. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  99127. decay=todB(&decay)*.5-15.f;
  99128. }
  99129. for(i=0;i<n/2;i+=2){
  99130. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  99131. val=todB(&val)*.5f;
  99132. if(val<decay)val=decay;
  99133. if(val<minV)val=minV;
  99134. vec[i>>1]=val;
  99135. decay-=8.;
  99136. }
  99137. for(j=0;j<VE_BANDS;j++){
  99138. float acc=0.;
  99139. float valmax,valmin;
  99140. for(i=0;i<bands[j].end;i++)
  99141. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  99142. acc*=bands[j].total;
  99143. {
  99144. int p,thisx=filters[j].ampptr;
  99145. float postmax,postmin,premax=-99999.f,premin=99999.f;
  99146. p=thisx;
  99147. p--;
  99148. if(p<0)p+=VE_AMP;
  99149. postmax=max(acc,filters[j].ampbuf[p]);
  99150. postmin=min(acc,filters[j].ampbuf[p]);
  99151. for(i=0;i<stretch;i++){
  99152. p--;
  99153. if(p<0)p+=VE_AMP;
  99154. premax=max(premax,filters[j].ampbuf[p]);
  99155. premin=min(premin,filters[j].ampbuf[p]);
  99156. }
  99157. valmin=postmin-premin;
  99158. valmax=postmax-premax;
  99159. filters[j].ampbuf[thisx]=acc;
  99160. filters[j].ampptr++;
  99161. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  99162. }
  99163. if(valmax>gi->preecho_thresh[j]+penalty){
  99164. ret|=1;
  99165. ret|=4;
  99166. }
  99167. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  99168. }
  99169. return(ret);
  99170. }
  99171. #if 0
  99172. static int seq=0;
  99173. static ogg_int64_t totalshift=-1024;
  99174. #endif
  99175. long _ve_envelope_search(vorbis_dsp_state *v){
  99176. vorbis_info *vi=v->vi;
  99177. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  99178. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99179. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99180. long i,j;
  99181. int first=ve->current/ve->searchstep;
  99182. int last=v->pcm_current/ve->searchstep-VE_WIN;
  99183. if(first<0)first=0;
  99184. if(last+VE_WIN+VE_POST>ve->storage){
  99185. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  99186. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  99187. }
  99188. for(j=first;j<last;j++){
  99189. int ret=0;
  99190. ve->stretch++;
  99191. if(ve->stretch>VE_MAXSTRETCH*2)
  99192. ve->stretch=VE_MAXSTRETCH*2;
  99193. for(i=0;i<ve->ch;i++){
  99194. float *pcm=v->pcm[i]+ve->searchstep*(j);
  99195. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  99196. }
  99197. ve->mark[j+VE_POST]=0;
  99198. if(ret&1){
  99199. ve->mark[j]=1;
  99200. ve->mark[j+1]=1;
  99201. }
  99202. if(ret&2){
  99203. ve->mark[j]=1;
  99204. if(j>0)ve->mark[j-1]=1;
  99205. }
  99206. if(ret&4)ve->stretch=-1;
  99207. }
  99208. ve->current=last*ve->searchstep;
  99209. {
  99210. long centerW=v->centerW;
  99211. long testW=
  99212. centerW+
  99213. ci->blocksizes[v->W]/4+
  99214. ci->blocksizes[1]/2+
  99215. ci->blocksizes[0]/4;
  99216. j=ve->cursor;
  99217. while(j<ve->current-(ve->searchstep)){/* account for postecho
  99218. working back one window */
  99219. if(j>=testW)return(1);
  99220. ve->cursor=j;
  99221. if(ve->mark[j/ve->searchstep]){
  99222. if(j>centerW){
  99223. #if 0
  99224. if(j>ve->curmark){
  99225. float *marker=alloca(v->pcm_current*sizeof(*marker));
  99226. int l,m;
  99227. memset(marker,0,sizeof(*marker)*v->pcm_current);
  99228. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  99229. seq,
  99230. (totalshift+ve->cursor)/44100.,
  99231. (totalshift+j)/44100.);
  99232. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  99233. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  99234. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  99235. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  99236. for(m=0;m<VE_BANDS;m++){
  99237. char buf[80];
  99238. sprintf(buf,"delL%d",m);
  99239. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  99240. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99241. }
  99242. for(m=0;m<VE_BANDS;m++){
  99243. char buf[80];
  99244. sprintf(buf,"delR%d",m);
  99245. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  99246. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99247. }
  99248. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  99249. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  99250. seq++;
  99251. }
  99252. #endif
  99253. ve->curmark=j;
  99254. if(j>=testW)return(1);
  99255. return(0);
  99256. }
  99257. }
  99258. j+=ve->searchstep;
  99259. }
  99260. }
  99261. return(-1);
  99262. }
  99263. int _ve_envelope_mark(vorbis_dsp_state *v){
  99264. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99265. vorbis_info *vi=v->vi;
  99266. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99267. long centerW=v->centerW;
  99268. long beginW=centerW-ci->blocksizes[v->W]/4;
  99269. long endW=centerW+ci->blocksizes[v->W]/4;
  99270. if(v->W){
  99271. beginW-=ci->blocksizes[v->lW]/4;
  99272. endW+=ci->blocksizes[v->nW]/4;
  99273. }else{
  99274. beginW-=ci->blocksizes[0]/4;
  99275. endW+=ci->blocksizes[0]/4;
  99276. }
  99277. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  99278. {
  99279. long first=beginW/ve->searchstep;
  99280. long last=endW/ve->searchstep;
  99281. long i;
  99282. for(i=first;i<last;i++)
  99283. if(ve->mark[i])return(1);
  99284. }
  99285. return(0);
  99286. }
  99287. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99288. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99289. ahead of ve->current */
  99290. int smallshift=shift/e->searchstep;
  99291. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99292. #if 0
  99293. for(i=0;i<VE_BANDS*e->ch;i++)
  99294. memmove(e->filter[i].markers,
  99295. e->filter[i].markers+smallshift,
  99296. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99297. totalshift+=shift;
  99298. #endif
  99299. e->current-=shift;
  99300. if(e->curmark>=0)
  99301. e->curmark-=shift;
  99302. e->cursor-=shift;
  99303. }
  99304. #endif
  99305. /*** End of inlined file: envelope.c ***/
  99306. /*** Start of inlined file: floor0.c ***/
  99307. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99308. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99309. // tasks..
  99310. #if JUCE_MSVC
  99311. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99312. #endif
  99313. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99314. #if JUCE_USE_OGGVORBIS
  99315. #include <stdlib.h>
  99316. #include <string.h>
  99317. #include <math.h>
  99318. /*** Start of inlined file: lsp.h ***/
  99319. #ifndef _V_LSP_H_
  99320. #define _V_LSP_H_
  99321. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99322. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99323. float *lsp,int m,
  99324. float amp,float ampoffset);
  99325. #endif
  99326. /*** End of inlined file: lsp.h ***/
  99327. #include <stdio.h>
  99328. typedef struct {
  99329. int ln;
  99330. int m;
  99331. int **linearmap;
  99332. int n[2];
  99333. vorbis_info_floor0 *vi;
  99334. long bits;
  99335. long frames;
  99336. } vorbis_look_floor0;
  99337. static void floor0_free_info(vorbis_info_floor *i){
  99338. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99339. if(info){
  99340. memset(info,0,sizeof(*info));
  99341. _ogg_free(info);
  99342. }
  99343. }
  99344. static void floor0_free_look(vorbis_look_floor *i){
  99345. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99346. if(look){
  99347. if(look->linearmap){
  99348. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99349. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99350. _ogg_free(look->linearmap);
  99351. }
  99352. memset(look,0,sizeof(*look));
  99353. _ogg_free(look);
  99354. }
  99355. }
  99356. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99357. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99358. int j;
  99359. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99360. info->order=oggpack_read(opb,8);
  99361. info->rate=oggpack_read(opb,16);
  99362. info->barkmap=oggpack_read(opb,16);
  99363. info->ampbits=oggpack_read(opb,6);
  99364. info->ampdB=oggpack_read(opb,8);
  99365. info->numbooks=oggpack_read(opb,4)+1;
  99366. if(info->order<1)goto err_out;
  99367. if(info->rate<1)goto err_out;
  99368. if(info->barkmap<1)goto err_out;
  99369. if(info->numbooks<1)goto err_out;
  99370. for(j=0;j<info->numbooks;j++){
  99371. info->books[j]=oggpack_read(opb,8);
  99372. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99373. }
  99374. return(info);
  99375. err_out:
  99376. floor0_free_info(info);
  99377. return(NULL);
  99378. }
  99379. static void floor0_map_lazy_init(vorbis_block *vb,
  99380. vorbis_info_floor *infoX,
  99381. vorbis_look_floor0 *look){
  99382. if(!look->linearmap[vb->W]){
  99383. vorbis_dsp_state *vd=vb->vd;
  99384. vorbis_info *vi=vd->vi;
  99385. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99386. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99387. int W=vb->W;
  99388. int n=ci->blocksizes[W]/2,j;
  99389. float scale=look->ln/toBARK(info->rate/2.f);
  99390. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99391. for(j=0;j<n;j++){
  99392. int val=floor( toBARK((info->rate/2.f)/n*j)
  99393. *scale); /* bark numbers represent band edges */
  99394. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99395. look->linearmap[W][j]=val;
  99396. }
  99397. look->linearmap[W][j]=-1;
  99398. look->n[W]=n;
  99399. }
  99400. }
  99401. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99402. vorbis_info_floor *i){
  99403. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99404. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99405. look->m=info->order;
  99406. look->ln=info->barkmap;
  99407. look->vi=info;
  99408. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99409. return look;
  99410. }
  99411. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99412. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99413. vorbis_info_floor0 *info=look->vi;
  99414. int j,k;
  99415. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99416. if(ampraw>0){ /* also handles the -1 out of data case */
  99417. long maxval=(1<<info->ampbits)-1;
  99418. float amp=(float)ampraw/maxval*info->ampdB;
  99419. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99420. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99421. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99422. codebook *b=ci->fullbooks+info->books[booknum];
  99423. float last=0.f;
  99424. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99425. for(j=0;j<look->m;j+=b->dim)
  99426. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99427. for(j=0;j<look->m;){
  99428. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99429. last=lsp[j-1];
  99430. }
  99431. lsp[look->m]=amp;
  99432. return(lsp);
  99433. }
  99434. }
  99435. eop:
  99436. return(NULL);
  99437. }
  99438. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99439. void *memo,float *out){
  99440. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99441. vorbis_info_floor0 *info=look->vi;
  99442. floor0_map_lazy_init(vb,info,look);
  99443. if(memo){
  99444. float *lsp=(float *)memo;
  99445. float amp=lsp[look->m];
  99446. vorbis_lsp_to_curve(out,
  99447. look->linearmap[vb->W],
  99448. look->n[vb->W],
  99449. look->ln,
  99450. lsp,look->m,amp,(float)info->ampdB);
  99451. return(1);
  99452. }
  99453. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99454. return(0);
  99455. }
  99456. vorbis_func_floor floor0_exportbundle={
  99457. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99458. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99459. };
  99460. #endif
  99461. /*** End of inlined file: floor0.c ***/
  99462. /*** Start of inlined file: floor1.c ***/
  99463. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99464. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99465. // tasks..
  99466. #if JUCE_MSVC
  99467. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99468. #endif
  99469. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99470. #if JUCE_USE_OGGVORBIS
  99471. #include <stdlib.h>
  99472. #include <string.h>
  99473. #include <math.h>
  99474. #include <stdio.h>
  99475. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99476. typedef struct {
  99477. int sorted_index[VIF_POSIT+2];
  99478. int forward_index[VIF_POSIT+2];
  99479. int reverse_index[VIF_POSIT+2];
  99480. int hineighbor[VIF_POSIT];
  99481. int loneighbor[VIF_POSIT];
  99482. int posts;
  99483. int n;
  99484. int quant_q;
  99485. vorbis_info_floor1 *vi;
  99486. long phrasebits;
  99487. long postbits;
  99488. long frames;
  99489. } vorbis_look_floor1;
  99490. typedef struct lsfit_acc{
  99491. long x0;
  99492. long x1;
  99493. long xa;
  99494. long ya;
  99495. long x2a;
  99496. long y2a;
  99497. long xya;
  99498. long an;
  99499. } lsfit_acc;
  99500. static void floor1_free_info(vorbis_info_floor *i){
  99501. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99502. if(info){
  99503. memset(info,0,sizeof(*info));
  99504. _ogg_free(info);
  99505. }
  99506. }
  99507. static void floor1_free_look(vorbis_look_floor *i){
  99508. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99509. if(look){
  99510. memset(look,0,sizeof(*look));
  99511. _ogg_free(look);
  99512. }
  99513. }
  99514. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99515. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99516. int j,k;
  99517. int count=0;
  99518. int rangebits;
  99519. int maxposit=info->postlist[1];
  99520. int maxclass=-1;
  99521. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99522. for(j=0;j<info->partitions;j++){
  99523. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99524. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99525. }
  99526. for(j=0;j<maxclass+1;j++){
  99527. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99528. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99529. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99530. for(k=0;k<(1<<info->class_subs[j]);k++)
  99531. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99532. }
  99533. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99534. oggpack_write(opb,ilog2(maxposit),4);
  99535. rangebits=ilog2(maxposit);
  99536. for(j=0,k=0;j<info->partitions;j++){
  99537. count+=info->class_dim[info->partitionclass[j]];
  99538. for(;k<count;k++)
  99539. oggpack_write(opb,info->postlist[k+2],rangebits);
  99540. }
  99541. }
  99542. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99543. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99544. int j,k,count=0,maxclass=-1,rangebits;
  99545. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99546. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99547. for(j=0;j<info->partitions;j++){
  99548. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99549. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99550. }
  99551. for(j=0;j<maxclass+1;j++){
  99552. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99553. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99554. if(info->class_subs[j]<0)
  99555. goto err_out;
  99556. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99557. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99558. goto err_out;
  99559. for(k=0;k<(1<<info->class_subs[j]);k++){
  99560. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99561. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99562. goto err_out;
  99563. }
  99564. }
  99565. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99566. rangebits=oggpack_read(opb,4);
  99567. for(j=0,k=0;j<info->partitions;j++){
  99568. count+=info->class_dim[info->partitionclass[j]];
  99569. for(;k<count;k++){
  99570. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99571. if(t<0 || t>=(1<<rangebits))
  99572. goto err_out;
  99573. }
  99574. }
  99575. info->postlist[0]=0;
  99576. info->postlist[1]=1<<rangebits;
  99577. return(info);
  99578. err_out:
  99579. floor1_free_info(info);
  99580. return(NULL);
  99581. }
  99582. static int icomp(const void *a,const void *b){
  99583. return(**(int **)a-**(int **)b);
  99584. }
  99585. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99586. vorbis_info_floor *in){
  99587. int *sortpointer[VIF_POSIT+2];
  99588. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99589. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99590. int i,j,n=0;
  99591. look->vi=info;
  99592. look->n=info->postlist[1];
  99593. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99594. n+=2;
  99595. look->posts=n;
  99596. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99597. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99598. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99599. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99600. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99601. switch(info->mult){
  99602. case 1: /* 1024 -> 256 */
  99603. look->quant_q=256;
  99604. break;
  99605. case 2: /* 1024 -> 128 */
  99606. look->quant_q=128;
  99607. break;
  99608. case 3: /* 1024 -> 86 */
  99609. look->quant_q=86;
  99610. break;
  99611. case 4: /* 1024 -> 64 */
  99612. look->quant_q=64;
  99613. break;
  99614. }
  99615. for(i=0;i<n-2;i++){
  99616. int lo=0;
  99617. int hi=1;
  99618. int lx=0;
  99619. int hx=look->n;
  99620. int currentx=info->postlist[i+2];
  99621. for(j=0;j<i+2;j++){
  99622. int x=info->postlist[j];
  99623. if(x>lx && x<currentx){
  99624. lo=j;
  99625. lx=x;
  99626. }
  99627. if(x<hx && x>currentx){
  99628. hi=j;
  99629. hx=x;
  99630. }
  99631. }
  99632. look->loneighbor[i]=lo;
  99633. look->hineighbor[i]=hi;
  99634. }
  99635. return(look);
  99636. }
  99637. static int render_point(int x0,int x1,int y0,int y1,int x){
  99638. y0&=0x7fff; /* mask off flag */
  99639. y1&=0x7fff;
  99640. {
  99641. int dy=y1-y0;
  99642. int adx=x1-x0;
  99643. int ady=abs(dy);
  99644. int err=ady*(x-x0);
  99645. int off=err/adx;
  99646. if(dy<0)return(y0-off);
  99647. return(y0+off);
  99648. }
  99649. }
  99650. static int vorbis_dBquant(const float *x){
  99651. int i= *x*7.3142857f+1023.5f;
  99652. if(i>1023)return(1023);
  99653. if(i<0)return(0);
  99654. return i;
  99655. }
  99656. static float FLOOR1_fromdB_LOOKUP[256]={
  99657. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99658. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99659. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99660. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99661. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99662. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99663. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99664. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99665. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99666. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99667. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99668. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99669. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99670. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99671. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99672. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99673. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99674. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99675. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99676. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99677. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99678. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99679. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99680. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99681. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99682. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99683. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99684. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99685. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99686. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99687. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99688. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99689. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99690. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99691. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99692. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99693. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99694. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99695. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99696. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99697. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99698. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99699. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99700. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99701. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99702. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99703. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99704. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99705. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99706. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99707. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99708. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99709. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99710. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99711. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99712. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99713. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99714. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99715. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99716. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99717. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99718. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99719. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99720. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99721. };
  99722. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99723. int dy=y1-y0;
  99724. int adx=x1-x0;
  99725. int ady=abs(dy);
  99726. int base=dy/adx;
  99727. int sy=(dy<0?base-1:base+1);
  99728. int x=x0;
  99729. int y=y0;
  99730. int err=0;
  99731. ady-=abs(base*adx);
  99732. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99733. while(++x<x1){
  99734. err=err+ady;
  99735. if(err>=adx){
  99736. err-=adx;
  99737. y+=sy;
  99738. }else{
  99739. y+=base;
  99740. }
  99741. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99742. }
  99743. }
  99744. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99745. int dy=y1-y0;
  99746. int adx=x1-x0;
  99747. int ady=abs(dy);
  99748. int base=dy/adx;
  99749. int sy=(dy<0?base-1:base+1);
  99750. int x=x0;
  99751. int y=y0;
  99752. int err=0;
  99753. ady-=abs(base*adx);
  99754. d[x]=y;
  99755. while(++x<x1){
  99756. err=err+ady;
  99757. if(err>=adx){
  99758. err-=adx;
  99759. y+=sy;
  99760. }else{
  99761. y+=base;
  99762. }
  99763. d[x]=y;
  99764. }
  99765. }
  99766. static int accumulate_fit(const float *flr,const float *mdct,
  99767. int x0, int x1,lsfit_acc *a,
  99768. int n,vorbis_info_floor1 *info){
  99769. long i;
  99770. 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;
  99771. memset(a,0,sizeof(*a));
  99772. a->x0=x0;
  99773. a->x1=x1;
  99774. if(x1>=n)x1=n-1;
  99775. for(i=x0;i<=x1;i++){
  99776. int quantized=vorbis_dBquant(flr+i);
  99777. if(quantized){
  99778. if(mdct[i]+info->twofitatten>=flr[i]){
  99779. xa += i;
  99780. ya += quantized;
  99781. x2a += i*i;
  99782. y2a += quantized*quantized;
  99783. xya += i*quantized;
  99784. na++;
  99785. }else{
  99786. xb += i;
  99787. yb += quantized;
  99788. x2b += i*i;
  99789. y2b += quantized*quantized;
  99790. xyb += i*quantized;
  99791. nb++;
  99792. }
  99793. }
  99794. }
  99795. xb+=xa;
  99796. yb+=ya;
  99797. x2b+=x2a;
  99798. y2b+=y2a;
  99799. xyb+=xya;
  99800. nb+=na;
  99801. {
  99802. int weight=nb*info->twofitweight/(na+1);
  99803. a->xa=xa*weight+xb;
  99804. a->ya=ya*weight+yb;
  99805. a->x2a=x2a*weight+x2b;
  99806. a->y2a=y2a*weight+y2b;
  99807. a->xya=xya*weight+xyb;
  99808. a->an=na*weight+nb;
  99809. }
  99810. return(na);
  99811. }
  99812. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99813. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99814. long x0=a[0].x0;
  99815. long x1=a[fits-1].x1;
  99816. for(i=0;i<fits;i++){
  99817. x+=a[i].xa;
  99818. y+=a[i].ya;
  99819. x2+=a[i].x2a;
  99820. y2+=a[i].y2a;
  99821. xy+=a[i].xya;
  99822. an+=a[i].an;
  99823. }
  99824. if(*y0>=0){
  99825. x+= x0;
  99826. y+= *y0;
  99827. x2+= x0 * x0;
  99828. y2+= *y0 * *y0;
  99829. xy+= *y0 * x0;
  99830. an++;
  99831. }
  99832. if(*y1>=0){
  99833. x+= x1;
  99834. y+= *y1;
  99835. x2+= x1 * x1;
  99836. y2+= *y1 * *y1;
  99837. xy+= *y1 * x1;
  99838. an++;
  99839. }
  99840. if(an){
  99841. double fx=x;
  99842. double fy=y;
  99843. double fx2=x2;
  99844. double fxy=xy;
  99845. double denom=1./(an*fx2-fx*fx);
  99846. double a=(fy*fx2-fxy*fx)*denom;
  99847. double b=(an*fxy-fx*fy)*denom;
  99848. *y0=rint(a+b*x0);
  99849. *y1=rint(a+b*x1);
  99850. if(*y0>1023)*y0=1023;
  99851. if(*y1>1023)*y1=1023;
  99852. if(*y0<0)*y0=0;
  99853. if(*y1<0)*y1=0;
  99854. }else{
  99855. *y0=0;
  99856. *y1=0;
  99857. }
  99858. }
  99859. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99860. const float *mdct,
  99861. vorbis_info_floor1 *info){
  99862. int dy=y1-y0;
  99863. int adx=x1-x0;
  99864. int ady=abs(dy);
  99865. int base=dy/adx;
  99866. int sy=(dy<0?base-1:base+1);
  99867. int x=x0;
  99868. int y=y0;
  99869. int err=0;
  99870. int val=vorbis_dBquant(mask+x);
  99871. int mse=0;
  99872. int n=0;
  99873. ady-=abs(base*adx);
  99874. mse=(y-val);
  99875. mse*=mse;
  99876. n++;
  99877. if(mdct[x]+info->twofitatten>=mask[x]){
  99878. if(y+info->maxover<val)return(1);
  99879. if(y-info->maxunder>val)return(1);
  99880. }
  99881. while(++x<x1){
  99882. err=err+ady;
  99883. if(err>=adx){
  99884. err-=adx;
  99885. y+=sy;
  99886. }else{
  99887. y+=base;
  99888. }
  99889. val=vorbis_dBquant(mask+x);
  99890. mse+=((y-val)*(y-val));
  99891. n++;
  99892. if(mdct[x]+info->twofitatten>=mask[x]){
  99893. if(val){
  99894. if(y+info->maxover<val)return(1);
  99895. if(y-info->maxunder>val)return(1);
  99896. }
  99897. }
  99898. }
  99899. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99900. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99901. if(mse/n>info->maxerr)return(1);
  99902. return(0);
  99903. }
  99904. static int post_Y(int *A,int *B,int pos){
  99905. if(A[pos]<0)
  99906. return B[pos];
  99907. if(B[pos]<0)
  99908. return A[pos];
  99909. return (A[pos]+B[pos])>>1;
  99910. }
  99911. int *floor1_fit(vorbis_block *vb,void *look_,
  99912. const float *logmdct, /* in */
  99913. const float *logmask){
  99914. long i,j;
  99915. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99916. vorbis_info_floor1 *info=look->vi;
  99917. long n=look->n;
  99918. long posts=look->posts;
  99919. long nonzero=0;
  99920. lsfit_acc fits[VIF_POSIT+1];
  99921. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99922. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99923. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99924. int hineighbor[VIF_POSIT+2];
  99925. int *output=NULL;
  99926. int memo[VIF_POSIT+2];
  99927. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99928. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99929. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99930. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99931. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99932. if(posts==0){
  99933. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99934. }else{
  99935. for(i=0;i<posts-1;i++)
  99936. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99937. look->sorted_index[i+1],fits+i,
  99938. n,info);
  99939. }
  99940. if(nonzero){
  99941. int y0=-200;
  99942. int y1=-200;
  99943. fit_line(fits,posts-1,&y0,&y1);
  99944. fit_valueA[0]=y0;
  99945. fit_valueB[0]=y0;
  99946. fit_valueB[1]=y1;
  99947. fit_valueA[1]=y1;
  99948. for(i=2;i<posts;i++){
  99949. int sortpos=look->reverse_index[i];
  99950. int ln=loneighbor[sortpos];
  99951. int hn=hineighbor[sortpos];
  99952. if(memo[ln]!=hn){
  99953. int lsortpos=look->reverse_index[ln];
  99954. int hsortpos=look->reverse_index[hn];
  99955. memo[ln]=hn;
  99956. {
  99957. int lx=info->postlist[ln];
  99958. int hx=info->postlist[hn];
  99959. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99960. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99961. if(ly==-1 || hy==-1){
  99962. exit(1);
  99963. }
  99964. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99965. int ly0=-200;
  99966. int ly1=-200;
  99967. int hy0=-200;
  99968. int hy1=-200;
  99969. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99970. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99971. fit_valueB[ln]=ly0;
  99972. if(ln==0)fit_valueA[ln]=ly0;
  99973. fit_valueA[i]=ly1;
  99974. fit_valueB[i]=hy0;
  99975. fit_valueA[hn]=hy1;
  99976. if(hn==1)fit_valueB[hn]=hy1;
  99977. if(ly1>=0 || hy0>=0){
  99978. for(j=sortpos-1;j>=0;j--)
  99979. if(hineighbor[j]==hn)
  99980. hineighbor[j]=i;
  99981. else
  99982. break;
  99983. for(j=sortpos+1;j<posts;j++)
  99984. if(loneighbor[j]==ln)
  99985. loneighbor[j]=i;
  99986. else
  99987. break;
  99988. }
  99989. }else{
  99990. fit_valueA[i]=-200;
  99991. fit_valueB[i]=-200;
  99992. }
  99993. }
  99994. }
  99995. }
  99996. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99997. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99998. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99999. for(i=2;i<posts;i++){
  100000. int ln=look->loneighbor[i-2];
  100001. int hn=look->hineighbor[i-2];
  100002. int x0=info->postlist[ln];
  100003. int x1=info->postlist[hn];
  100004. int y0=output[ln];
  100005. int y1=output[hn];
  100006. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100007. int vx=post_Y(fit_valueA,fit_valueB,i);
  100008. if(vx>=0 && predicted!=vx){
  100009. output[i]=vx;
  100010. }else{
  100011. output[i]= predicted|0x8000;
  100012. }
  100013. }
  100014. }
  100015. return(output);
  100016. }
  100017. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  100018. int *A,int *B,
  100019. int del){
  100020. long i;
  100021. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  100022. long posts=look->posts;
  100023. int *output=NULL;
  100024. if(A && B){
  100025. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100026. for(i=0;i<posts;i++){
  100027. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  100028. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  100029. }
  100030. }
  100031. return(output);
  100032. }
  100033. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  100034. void*look_,
  100035. int *post,int *ilogmask){
  100036. long i,j;
  100037. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  100038. vorbis_info_floor1 *info=look->vi;
  100039. long posts=look->posts;
  100040. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100041. int out[VIF_POSIT+2];
  100042. static_codebook **sbooks=ci->book_param;
  100043. codebook *books=ci->fullbooks;
  100044. static long seq=0;
  100045. if(post){
  100046. for(i=0;i<posts;i++){
  100047. int val=post[i]&0x7fff;
  100048. switch(info->mult){
  100049. case 1: /* 1024 -> 256 */
  100050. val>>=2;
  100051. break;
  100052. case 2: /* 1024 -> 128 */
  100053. val>>=3;
  100054. break;
  100055. case 3: /* 1024 -> 86 */
  100056. val/=12;
  100057. break;
  100058. case 4: /* 1024 -> 64 */
  100059. val>>=4;
  100060. break;
  100061. }
  100062. post[i]=val | (post[i]&0x8000);
  100063. }
  100064. out[0]=post[0];
  100065. out[1]=post[1];
  100066. for(i=2;i<posts;i++){
  100067. int ln=look->loneighbor[i-2];
  100068. int hn=look->hineighbor[i-2];
  100069. int x0=info->postlist[ln];
  100070. int x1=info->postlist[hn];
  100071. int y0=post[ln];
  100072. int y1=post[hn];
  100073. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100074. if((post[i]&0x8000) || (predicted==post[i])){
  100075. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  100076. in interpolation */
  100077. out[i]=0;
  100078. }else{
  100079. int headroom=(look->quant_q-predicted<predicted?
  100080. look->quant_q-predicted:predicted);
  100081. int val=post[i]-predicted;
  100082. if(val<0)
  100083. if(val<-headroom)
  100084. val=headroom-val-1;
  100085. else
  100086. val=-1-(val<<1);
  100087. else
  100088. if(val>=headroom)
  100089. val= val+headroom;
  100090. else
  100091. val<<=1;
  100092. out[i]=val;
  100093. post[ln]&=0x7fff;
  100094. post[hn]&=0x7fff;
  100095. }
  100096. }
  100097. oggpack_write(opb,1,1);
  100098. look->frames++;
  100099. look->postbits+=ilog(look->quant_q-1)*2;
  100100. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  100101. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  100102. for(i=0,j=2;i<info->partitions;i++){
  100103. int classx=info->partitionclass[i];
  100104. int cdim=info->class_dim[classx];
  100105. int csubbits=info->class_subs[classx];
  100106. int csub=1<<csubbits;
  100107. int bookas[8]={0,0,0,0,0,0,0,0};
  100108. int cval=0;
  100109. int cshift=0;
  100110. int k,l;
  100111. if(csubbits){
  100112. int maxval[8];
  100113. for(k=0;k<csub;k++){
  100114. int booknum=info->class_subbook[classx][k];
  100115. if(booknum<0){
  100116. maxval[k]=1;
  100117. }else{
  100118. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  100119. }
  100120. }
  100121. for(k=0;k<cdim;k++){
  100122. for(l=0;l<csub;l++){
  100123. int val=out[j+k];
  100124. if(val<maxval[l]){
  100125. bookas[k]=l;
  100126. break;
  100127. }
  100128. }
  100129. cval|= bookas[k]<<cshift;
  100130. cshift+=csubbits;
  100131. }
  100132. look->phrasebits+=
  100133. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  100134. #ifdef TRAIN_FLOOR1
  100135. {
  100136. FILE *of;
  100137. char buffer[80];
  100138. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  100139. vb->pcmend/2,posts-2,class);
  100140. of=fopen(buffer,"a");
  100141. fprintf(of,"%d\n",cval);
  100142. fclose(of);
  100143. }
  100144. #endif
  100145. }
  100146. for(k=0;k<cdim;k++){
  100147. int book=info->class_subbook[classx][bookas[k]];
  100148. if(book>=0){
  100149. if(out[j+k]<(books+book)->entries)
  100150. look->postbits+=vorbis_book_encode(books+book,
  100151. out[j+k],opb);
  100152. #ifdef TRAIN_FLOOR1
  100153. {
  100154. FILE *of;
  100155. char buffer[80];
  100156. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  100157. vb->pcmend/2,posts-2,class,bookas[k]);
  100158. of=fopen(buffer,"a");
  100159. fprintf(of,"%d\n",out[j+k]);
  100160. fclose(of);
  100161. }
  100162. #endif
  100163. }
  100164. }
  100165. j+=cdim;
  100166. }
  100167. {
  100168. int hx=0;
  100169. int lx=0;
  100170. int ly=post[0]*info->mult;
  100171. for(j=1;j<look->posts;j++){
  100172. int current=look->forward_index[j];
  100173. int hy=post[current]&0x7fff;
  100174. if(hy==post[current]){
  100175. hy*=info->mult;
  100176. hx=info->postlist[current];
  100177. render_line0(lx,hx,ly,hy,ilogmask);
  100178. lx=hx;
  100179. ly=hy;
  100180. }
  100181. }
  100182. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  100183. seq++;
  100184. return(1);
  100185. }
  100186. }else{
  100187. oggpack_write(opb,0,1);
  100188. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  100189. seq++;
  100190. return(0);
  100191. }
  100192. }
  100193. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  100194. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100195. vorbis_info_floor1 *info=look->vi;
  100196. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100197. int i,j,k;
  100198. codebook *books=ci->fullbooks;
  100199. if(oggpack_read(&vb->opb,1)==1){
  100200. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  100201. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100202. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100203. for(i=0,j=2;i<info->partitions;i++){
  100204. int classx=info->partitionclass[i];
  100205. int cdim=info->class_dim[classx];
  100206. int csubbits=info->class_subs[classx];
  100207. int csub=1<<csubbits;
  100208. int cval=0;
  100209. if(csubbits){
  100210. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  100211. if(cval==-1)goto eop;
  100212. }
  100213. for(k=0;k<cdim;k++){
  100214. int book=info->class_subbook[classx][cval&(csub-1)];
  100215. cval>>=csubbits;
  100216. if(book>=0){
  100217. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  100218. goto eop;
  100219. }else{
  100220. fit_value[j+k]=0;
  100221. }
  100222. }
  100223. j+=cdim;
  100224. }
  100225. for(i=2;i<look->posts;i++){
  100226. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  100227. info->postlist[look->hineighbor[i-2]],
  100228. fit_value[look->loneighbor[i-2]],
  100229. fit_value[look->hineighbor[i-2]],
  100230. info->postlist[i]);
  100231. int hiroom=look->quant_q-predicted;
  100232. int loroom=predicted;
  100233. int room=(hiroom<loroom?hiroom:loroom)<<1;
  100234. int val=fit_value[i];
  100235. if(val){
  100236. if(val>=room){
  100237. if(hiroom>loroom){
  100238. val = val-loroom;
  100239. }else{
  100240. val = -1-(val-hiroom);
  100241. }
  100242. }else{
  100243. if(val&1){
  100244. val= -((val+1)>>1);
  100245. }else{
  100246. val>>=1;
  100247. }
  100248. }
  100249. fit_value[i]=val+predicted;
  100250. fit_value[look->loneighbor[i-2]]&=0x7fff;
  100251. fit_value[look->hineighbor[i-2]]&=0x7fff;
  100252. }else{
  100253. fit_value[i]=predicted|0x8000;
  100254. }
  100255. }
  100256. return(fit_value);
  100257. }
  100258. eop:
  100259. return(NULL);
  100260. }
  100261. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  100262. float *out){
  100263. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100264. vorbis_info_floor1 *info=look->vi;
  100265. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100266. int n=ci->blocksizes[vb->W]/2;
  100267. int j;
  100268. if(memo){
  100269. int *fit_value=(int *)memo;
  100270. int hx=0;
  100271. int lx=0;
  100272. int ly=fit_value[0]*info->mult;
  100273. for(j=1;j<look->posts;j++){
  100274. int current=look->forward_index[j];
  100275. int hy=fit_value[current]&0x7fff;
  100276. if(hy==fit_value[current]){
  100277. hy*=info->mult;
  100278. hx=info->postlist[current];
  100279. render_line(lx,hx,ly,hy,out);
  100280. lx=hx;
  100281. ly=hy;
  100282. }
  100283. }
  100284. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100285. return(1);
  100286. }
  100287. memset(out,0,sizeof(*out)*n);
  100288. return(0);
  100289. }
  100290. vorbis_func_floor floor1_exportbundle={
  100291. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100292. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100293. };
  100294. #endif
  100295. /*** End of inlined file: floor1.c ***/
  100296. /*** Start of inlined file: info.c ***/
  100297. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100298. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100299. // tasks..
  100300. #if JUCE_MSVC
  100301. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100302. #endif
  100303. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100304. #if JUCE_USE_OGGVORBIS
  100305. #include <stdlib.h>
  100306. #include <string.h>
  100307. #include <ctype.h>
  100308. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100309. while(bytes--){
  100310. oggpack_write(o,*s++,8);
  100311. }
  100312. }
  100313. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100314. while(bytes--){
  100315. *buf++=oggpack_read(o,8);
  100316. }
  100317. }
  100318. void vorbis_comment_init(vorbis_comment *vc){
  100319. memset(vc,0,sizeof(*vc));
  100320. }
  100321. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100322. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100323. (vc->comments+2)*sizeof(*vc->user_comments));
  100324. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100325. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100326. vc->comment_lengths[vc->comments]=strlen(comment);
  100327. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100328. strcpy(vc->user_comments[vc->comments], comment);
  100329. vc->comments++;
  100330. vc->user_comments[vc->comments]=NULL;
  100331. }
  100332. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100333. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100334. strcpy(comment, tag);
  100335. strcat(comment, "=");
  100336. strcat(comment, contents);
  100337. vorbis_comment_add(vc, comment);
  100338. }
  100339. static int tagcompare(const char *s1, const char *s2, int n){
  100340. int c=0;
  100341. while(c < n){
  100342. if(toupper(s1[c]) != toupper(s2[c]))
  100343. return !0;
  100344. c++;
  100345. }
  100346. return 0;
  100347. }
  100348. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100349. long i;
  100350. int found = 0;
  100351. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100352. char *fulltag = (char*)alloca(taglen+ 1);
  100353. strcpy(fulltag, tag);
  100354. strcat(fulltag, "=");
  100355. for(i=0;i<vc->comments;i++){
  100356. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100357. if(count == found)
  100358. return vc->user_comments[i] + taglen;
  100359. else
  100360. found++;
  100361. }
  100362. }
  100363. return NULL; /* didn't find anything */
  100364. }
  100365. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100366. int i,count=0;
  100367. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100368. char *fulltag = (char*)alloca(taglen+1);
  100369. strcpy(fulltag,tag);
  100370. strcat(fulltag, "=");
  100371. for(i=0;i<vc->comments;i++){
  100372. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100373. count++;
  100374. }
  100375. return count;
  100376. }
  100377. void vorbis_comment_clear(vorbis_comment *vc){
  100378. if(vc){
  100379. long i;
  100380. for(i=0;i<vc->comments;i++)
  100381. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100382. if(vc->user_comments)_ogg_free(vc->user_comments);
  100383. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100384. if(vc->vendor)_ogg_free(vc->vendor);
  100385. }
  100386. memset(vc,0,sizeof(*vc));
  100387. }
  100388. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100389. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100390. return ci ? ci->blocksizes[zo] : -1;
  100391. }
  100392. void vorbis_info_init(vorbis_info *vi){
  100393. memset(vi,0,sizeof(*vi));
  100394. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100395. }
  100396. void vorbis_info_clear(vorbis_info *vi){
  100397. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100398. int i;
  100399. if(ci){
  100400. for(i=0;i<ci->modes;i++)
  100401. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100402. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100403. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100404. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100405. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100406. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100407. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100408. for(i=0;i<ci->books;i++){
  100409. if(ci->book_param[i]){
  100410. vorbis_staticbook_destroy(ci->book_param[i]);
  100411. }
  100412. if(ci->fullbooks)
  100413. vorbis_book_clear(ci->fullbooks+i);
  100414. }
  100415. if(ci->fullbooks)
  100416. _ogg_free(ci->fullbooks);
  100417. for(i=0;i<ci->psys;i++)
  100418. _vi_psy_free(ci->psy_param[i]);
  100419. _ogg_free(ci);
  100420. }
  100421. memset(vi,0,sizeof(*vi));
  100422. }
  100423. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100424. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100425. if(!ci)return(OV_EFAULT);
  100426. vi->version=oggpack_read(opb,32);
  100427. if(vi->version!=0)return(OV_EVERSION);
  100428. vi->channels=oggpack_read(opb,8);
  100429. vi->rate=oggpack_read(opb,32);
  100430. vi->bitrate_upper=oggpack_read(opb,32);
  100431. vi->bitrate_nominal=oggpack_read(opb,32);
  100432. vi->bitrate_lower=oggpack_read(opb,32);
  100433. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100434. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100435. if(vi->rate<1)goto err_out;
  100436. if(vi->channels<1)goto err_out;
  100437. if(ci->blocksizes[0]<8)goto err_out;
  100438. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100439. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100440. return(0);
  100441. err_out:
  100442. vorbis_info_clear(vi);
  100443. return(OV_EBADHEADER);
  100444. }
  100445. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100446. int i;
  100447. int vendorlen=oggpack_read(opb,32);
  100448. if(vendorlen<0)goto err_out;
  100449. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100450. _v_readstring(opb,vc->vendor,vendorlen);
  100451. vc->comments=oggpack_read(opb,32);
  100452. if(vc->comments<0)goto err_out;
  100453. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100454. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100455. for(i=0;i<vc->comments;i++){
  100456. int len=oggpack_read(opb,32);
  100457. if(len<0)goto err_out;
  100458. vc->comment_lengths[i]=len;
  100459. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100460. _v_readstring(opb,vc->user_comments[i],len);
  100461. }
  100462. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100463. return(0);
  100464. err_out:
  100465. vorbis_comment_clear(vc);
  100466. return(OV_EBADHEADER);
  100467. }
  100468. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100469. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100470. int i;
  100471. if(!ci)return(OV_EFAULT);
  100472. ci->books=oggpack_read(opb,8)+1;
  100473. for(i=0;i<ci->books;i++){
  100474. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100475. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100476. }
  100477. {
  100478. int times=oggpack_read(opb,6)+1;
  100479. for(i=0;i<times;i++){
  100480. int test=oggpack_read(opb,16);
  100481. if(test<0 || test>=VI_TIMEB)goto err_out;
  100482. }
  100483. }
  100484. ci->floors=oggpack_read(opb,6)+1;
  100485. for(i=0;i<ci->floors;i++){
  100486. ci->floor_type[i]=oggpack_read(opb,16);
  100487. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100488. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100489. if(!ci->floor_param[i])goto err_out;
  100490. }
  100491. ci->residues=oggpack_read(opb,6)+1;
  100492. for(i=0;i<ci->residues;i++){
  100493. ci->residue_type[i]=oggpack_read(opb,16);
  100494. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100495. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100496. if(!ci->residue_param[i])goto err_out;
  100497. }
  100498. ci->maps=oggpack_read(opb,6)+1;
  100499. for(i=0;i<ci->maps;i++){
  100500. ci->map_type[i]=oggpack_read(opb,16);
  100501. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100502. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100503. if(!ci->map_param[i])goto err_out;
  100504. }
  100505. ci->modes=oggpack_read(opb,6)+1;
  100506. for(i=0;i<ci->modes;i++){
  100507. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100508. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100509. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100510. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100511. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100512. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100513. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100514. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100515. }
  100516. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100517. return(0);
  100518. err_out:
  100519. vorbis_info_clear(vi);
  100520. return(OV_EBADHEADER);
  100521. }
  100522. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100523. oggpack_buffer opb;
  100524. if(op){
  100525. oggpack_readinit(&opb,op->packet,op->bytes);
  100526. {
  100527. char buffer[6];
  100528. int packtype=oggpack_read(&opb,8);
  100529. memset(buffer,0,6);
  100530. _v_readstring(&opb,buffer,6);
  100531. if(memcmp(buffer,"vorbis",6)){
  100532. return(OV_ENOTVORBIS);
  100533. }
  100534. switch(packtype){
  100535. case 0x01: /* least significant *bit* is read first */
  100536. if(!op->b_o_s){
  100537. return(OV_EBADHEADER);
  100538. }
  100539. if(vi->rate!=0){
  100540. return(OV_EBADHEADER);
  100541. }
  100542. return(_vorbis_unpack_info(vi,&opb));
  100543. case 0x03: /* least significant *bit* is read first */
  100544. if(vi->rate==0){
  100545. return(OV_EBADHEADER);
  100546. }
  100547. return(_vorbis_unpack_comment(vc,&opb));
  100548. case 0x05: /* least significant *bit* is read first */
  100549. if(vi->rate==0 || vc->vendor==NULL){
  100550. return(OV_EBADHEADER);
  100551. }
  100552. return(_vorbis_unpack_books(vi,&opb));
  100553. default:
  100554. return(OV_EBADHEADER);
  100555. break;
  100556. }
  100557. }
  100558. }
  100559. return(OV_EBADHEADER);
  100560. }
  100561. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100562. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100563. if(!ci)return(OV_EFAULT);
  100564. oggpack_write(opb,0x01,8);
  100565. _v_writestring(opb,"vorbis", 6);
  100566. oggpack_write(opb,0x00,32);
  100567. oggpack_write(opb,vi->channels,8);
  100568. oggpack_write(opb,vi->rate,32);
  100569. oggpack_write(opb,vi->bitrate_upper,32);
  100570. oggpack_write(opb,vi->bitrate_nominal,32);
  100571. oggpack_write(opb,vi->bitrate_lower,32);
  100572. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100573. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100574. oggpack_write(opb,1,1);
  100575. return(0);
  100576. }
  100577. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100578. char temp[]="Xiph.Org libVorbis I 20050304";
  100579. int bytes = strlen(temp);
  100580. oggpack_write(opb,0x03,8);
  100581. _v_writestring(opb,"vorbis", 6);
  100582. oggpack_write(opb,bytes,32);
  100583. _v_writestring(opb,temp, bytes);
  100584. oggpack_write(opb,vc->comments,32);
  100585. if(vc->comments){
  100586. int i;
  100587. for(i=0;i<vc->comments;i++){
  100588. if(vc->user_comments[i]){
  100589. oggpack_write(opb,vc->comment_lengths[i],32);
  100590. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100591. }else{
  100592. oggpack_write(opb,0,32);
  100593. }
  100594. }
  100595. }
  100596. oggpack_write(opb,1,1);
  100597. return(0);
  100598. }
  100599. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100600. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100601. int i;
  100602. if(!ci)return(OV_EFAULT);
  100603. oggpack_write(opb,0x05,8);
  100604. _v_writestring(opb,"vorbis", 6);
  100605. oggpack_write(opb,ci->books-1,8);
  100606. for(i=0;i<ci->books;i++)
  100607. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100608. oggpack_write(opb,0,6);
  100609. oggpack_write(opb,0,16);
  100610. oggpack_write(opb,ci->floors-1,6);
  100611. for(i=0;i<ci->floors;i++){
  100612. oggpack_write(opb,ci->floor_type[i],16);
  100613. if(_floor_P[ci->floor_type[i]]->pack)
  100614. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100615. else
  100616. goto err_out;
  100617. }
  100618. oggpack_write(opb,ci->residues-1,6);
  100619. for(i=0;i<ci->residues;i++){
  100620. oggpack_write(opb,ci->residue_type[i],16);
  100621. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100622. }
  100623. oggpack_write(opb,ci->maps-1,6);
  100624. for(i=0;i<ci->maps;i++){
  100625. oggpack_write(opb,ci->map_type[i],16);
  100626. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100627. }
  100628. oggpack_write(opb,ci->modes-1,6);
  100629. for(i=0;i<ci->modes;i++){
  100630. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100631. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100632. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100633. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100634. }
  100635. oggpack_write(opb,1,1);
  100636. return(0);
  100637. err_out:
  100638. return(-1);
  100639. }
  100640. int vorbis_commentheader_out(vorbis_comment *vc,
  100641. ogg_packet *op){
  100642. oggpack_buffer opb;
  100643. oggpack_writeinit(&opb);
  100644. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100645. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100646. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100647. op->bytes=oggpack_bytes(&opb);
  100648. op->b_o_s=0;
  100649. op->e_o_s=0;
  100650. op->granulepos=0;
  100651. op->packetno=1;
  100652. return 0;
  100653. }
  100654. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100655. vorbis_comment *vc,
  100656. ogg_packet *op,
  100657. ogg_packet *op_comm,
  100658. ogg_packet *op_code){
  100659. int ret=OV_EIMPL;
  100660. vorbis_info *vi=v->vi;
  100661. oggpack_buffer opb;
  100662. private_state *b=(private_state*)v->backend_state;
  100663. if(!b){
  100664. ret=OV_EFAULT;
  100665. goto err_out;
  100666. }
  100667. oggpack_writeinit(&opb);
  100668. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100669. if(b->header)_ogg_free(b->header);
  100670. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100671. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100672. op->packet=b->header;
  100673. op->bytes=oggpack_bytes(&opb);
  100674. op->b_o_s=1;
  100675. op->e_o_s=0;
  100676. op->granulepos=0;
  100677. op->packetno=0;
  100678. oggpack_reset(&opb);
  100679. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100680. if(b->header1)_ogg_free(b->header1);
  100681. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100682. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100683. op_comm->packet=b->header1;
  100684. op_comm->bytes=oggpack_bytes(&opb);
  100685. op_comm->b_o_s=0;
  100686. op_comm->e_o_s=0;
  100687. op_comm->granulepos=0;
  100688. op_comm->packetno=1;
  100689. oggpack_reset(&opb);
  100690. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100691. if(b->header2)_ogg_free(b->header2);
  100692. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100693. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100694. op_code->packet=b->header2;
  100695. op_code->bytes=oggpack_bytes(&opb);
  100696. op_code->b_o_s=0;
  100697. op_code->e_o_s=0;
  100698. op_code->granulepos=0;
  100699. op_code->packetno=2;
  100700. oggpack_writeclear(&opb);
  100701. return(0);
  100702. err_out:
  100703. oggpack_writeclear(&opb);
  100704. memset(op,0,sizeof(*op));
  100705. memset(op_comm,0,sizeof(*op_comm));
  100706. memset(op_code,0,sizeof(*op_code));
  100707. if(b->header)_ogg_free(b->header);
  100708. if(b->header1)_ogg_free(b->header1);
  100709. if(b->header2)_ogg_free(b->header2);
  100710. b->header=NULL;
  100711. b->header1=NULL;
  100712. b->header2=NULL;
  100713. return(ret);
  100714. }
  100715. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100716. if(granulepos>=0)
  100717. return((double)granulepos/v->vi->rate);
  100718. return(-1);
  100719. }
  100720. #endif
  100721. /*** End of inlined file: info.c ***/
  100722. /*** Start of inlined file: lpc.c ***/
  100723. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100724. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100725. // tasks..
  100726. #if JUCE_MSVC
  100727. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100728. #endif
  100729. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100730. #if JUCE_USE_OGGVORBIS
  100731. #include <stdlib.h>
  100732. #include <string.h>
  100733. #include <math.h>
  100734. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100735. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100736. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100737. double error;
  100738. int i,j;
  100739. j=m+1;
  100740. while(j--){
  100741. double d=0; /* double needed for accumulator depth */
  100742. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100743. aut[j]=d;
  100744. }
  100745. error=aut[0];
  100746. for(i=0;i<m;i++){
  100747. double r= -aut[i+1];
  100748. if(error==0){
  100749. memset(lpci,0,m*sizeof(*lpci));
  100750. return 0;
  100751. }
  100752. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100753. r/=error;
  100754. lpc[i]=r;
  100755. for(j=0;j<i/2;j++){
  100756. double tmp=lpc[j];
  100757. lpc[j]+=r*lpc[i-1-j];
  100758. lpc[i-1-j]+=r*tmp;
  100759. }
  100760. if(i%2)lpc[j]+=lpc[j]*r;
  100761. error*=1.f-r*r;
  100762. }
  100763. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100764. return error;
  100765. }
  100766. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100767. float *data,long n){
  100768. long i,j,o,p;
  100769. float y;
  100770. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100771. if(!prime)
  100772. for(i=0;i<m;i++)
  100773. work[i]=0.f;
  100774. else
  100775. for(i=0;i<m;i++)
  100776. work[i]=prime[i];
  100777. for(i=0;i<n;i++){
  100778. y=0;
  100779. o=i;
  100780. p=m;
  100781. for(j=0;j<m;j++)
  100782. y-=work[o++]*coeff[--p];
  100783. data[i]=work[o]=y;
  100784. }
  100785. }
  100786. #endif
  100787. /*** End of inlined file: lpc.c ***/
  100788. /*** Start of inlined file: lsp.c ***/
  100789. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100790. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100791. // tasks..
  100792. #if JUCE_MSVC
  100793. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100794. #endif
  100795. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100796. #if JUCE_USE_OGGVORBIS
  100797. #include <math.h>
  100798. #include <string.h>
  100799. #include <stdlib.h>
  100800. /*** Start of inlined file: lookup.h ***/
  100801. #ifndef _V_LOOKUP_H_
  100802. #ifdef FLOAT_LOOKUP
  100803. extern float vorbis_coslook(float a);
  100804. extern float vorbis_invsqlook(float a);
  100805. extern float vorbis_invsq2explook(int a);
  100806. extern float vorbis_fromdBlook(float a);
  100807. #endif
  100808. #ifdef INT_LOOKUP
  100809. extern long vorbis_invsqlook_i(long a,long e);
  100810. extern long vorbis_coslook_i(long a);
  100811. extern float vorbis_fromdBlook_i(long a);
  100812. #endif
  100813. #endif
  100814. /*** End of inlined file: lookup.h ***/
  100815. #define FLOAT_LOOKUP
  100816. #undef INT_LOOKUP
  100817. #ifdef FLOAT_LOOKUP
  100818. /*** Start of inlined file: lookup.c ***/
  100819. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100820. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100821. // tasks..
  100822. #if JUCE_MSVC
  100823. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100824. #endif
  100825. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100826. #if JUCE_USE_OGGVORBIS
  100827. #include <math.h>
  100828. /*** Start of inlined file: lookup.h ***/
  100829. #ifndef _V_LOOKUP_H_
  100830. #ifdef FLOAT_LOOKUP
  100831. extern float vorbis_coslook(float a);
  100832. extern float vorbis_invsqlook(float a);
  100833. extern float vorbis_invsq2explook(int a);
  100834. extern float vorbis_fromdBlook(float a);
  100835. #endif
  100836. #ifdef INT_LOOKUP
  100837. extern long vorbis_invsqlook_i(long a,long e);
  100838. extern long vorbis_coslook_i(long a);
  100839. extern float vorbis_fromdBlook_i(long a);
  100840. #endif
  100841. #endif
  100842. /*** End of inlined file: lookup.h ***/
  100843. /*** Start of inlined file: lookup_data.h ***/
  100844. #ifndef _V_LOOKUP_DATA_H_
  100845. #ifdef FLOAT_LOOKUP
  100846. #define COS_LOOKUP_SZ 128
  100847. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100848. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100849. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100850. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100851. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100852. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100853. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100854. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100855. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100856. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100857. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100858. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100859. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100860. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100861. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100862. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100863. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100864. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100865. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100866. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100867. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100868. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100869. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100870. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100871. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100872. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100873. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100874. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100875. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100876. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100877. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100878. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100879. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100880. -1.0000000000000f,
  100881. };
  100882. #define INVSQ_LOOKUP_SZ 32
  100883. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100884. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100885. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100886. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100887. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100888. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100889. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100890. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100891. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100892. 1.000000000000f,
  100893. };
  100894. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100895. #define INVSQ2EXP_LOOKUP_MAX 32
  100896. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100897. INVSQ2EXP_LOOKUP_MIN+1]={
  100898. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100899. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100900. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100901. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100902. 256.f, 181.019336f, 128.f, 90.50966799f,
  100903. 64.f, 45.254834f, 32.f, 22.627417f,
  100904. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100905. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100906. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100907. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100908. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100909. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100910. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100911. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100912. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100913. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100914. 1.525878906e-05f,
  100915. };
  100916. #endif
  100917. #define FROMdB_LOOKUP_SZ 35
  100918. #define FROMdB2_LOOKUP_SZ 32
  100919. #define FROMdB_SHIFT 5
  100920. #define FROMdB2_SHIFT 3
  100921. #define FROMdB2_MASK 31
  100922. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100923. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100924. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100925. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100926. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100927. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100928. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100929. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100930. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100931. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100932. };
  100933. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100934. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100935. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100936. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100937. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100938. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100939. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100940. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100941. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100942. };
  100943. #ifdef INT_LOOKUP
  100944. #define INVSQ_LOOKUP_I_SHIFT 10
  100945. #define INVSQ_LOOKUP_I_MASK 1023
  100946. static long INVSQ_LOOKUP_I[64+1]={
  100947. 92682l, 91966l, 91267l, 90583l,
  100948. 89915l, 89261l, 88621l, 87995l,
  100949. 87381l, 86781l, 86192l, 85616l,
  100950. 85051l, 84497l, 83953l, 83420l,
  100951. 82897l, 82384l, 81880l, 81385l,
  100952. 80899l, 80422l, 79953l, 79492l,
  100953. 79039l, 78594l, 78156l, 77726l,
  100954. 77302l, 76885l, 76475l, 76072l,
  100955. 75674l, 75283l, 74898l, 74519l,
  100956. 74146l, 73778l, 73415l, 73058l,
  100957. 72706l, 72359l, 72016l, 71679l,
  100958. 71347l, 71019l, 70695l, 70376l,
  100959. 70061l, 69750l, 69444l, 69141l,
  100960. 68842l, 68548l, 68256l, 67969l,
  100961. 67685l, 67405l, 67128l, 66855l,
  100962. 66585l, 66318l, 66054l, 65794l,
  100963. 65536l,
  100964. };
  100965. #define COS_LOOKUP_I_SHIFT 9
  100966. #define COS_LOOKUP_I_MASK 511
  100967. #define COS_LOOKUP_I_SZ 128
  100968. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100969. 16384l, 16379l, 16364l, 16340l,
  100970. 16305l, 16261l, 16207l, 16143l,
  100971. 16069l, 15986l, 15893l, 15791l,
  100972. 15679l, 15557l, 15426l, 15286l,
  100973. 15137l, 14978l, 14811l, 14635l,
  100974. 14449l, 14256l, 14053l, 13842l,
  100975. 13623l, 13395l, 13160l, 12916l,
  100976. 12665l, 12406l, 12140l, 11866l,
  100977. 11585l, 11297l, 11003l, 10702l,
  100978. 10394l, 10080l, 9760l, 9434l,
  100979. 9102l, 8765l, 8423l, 8076l,
  100980. 7723l, 7366l, 7005l, 6639l,
  100981. 6270l, 5897l, 5520l, 5139l,
  100982. 4756l, 4370l, 3981l, 3590l,
  100983. 3196l, 2801l, 2404l, 2006l,
  100984. 1606l, 1205l, 804l, 402l,
  100985. 0l, -401l, -803l, -1204l,
  100986. -1605l, -2005l, -2403l, -2800l,
  100987. -3195l, -3589l, -3980l, -4369l,
  100988. -4755l, -5138l, -5519l, -5896l,
  100989. -6269l, -6638l, -7004l, -7365l,
  100990. -7722l, -8075l, -8422l, -8764l,
  100991. -9101l, -9433l, -9759l, -10079l,
  100992. -10393l, -10701l, -11002l, -11296l,
  100993. -11584l, -11865l, -12139l, -12405l,
  100994. -12664l, -12915l, -13159l, -13394l,
  100995. -13622l, -13841l, -14052l, -14255l,
  100996. -14448l, -14634l, -14810l, -14977l,
  100997. -15136l, -15285l, -15425l, -15556l,
  100998. -15678l, -15790l, -15892l, -15985l,
  100999. -16068l, -16142l, -16206l, -16260l,
  101000. -16304l, -16339l, -16363l, -16378l,
  101001. -16383l,
  101002. };
  101003. #endif
  101004. #endif
  101005. /*** End of inlined file: lookup_data.h ***/
  101006. #ifdef FLOAT_LOOKUP
  101007. float vorbis_coslook(float a){
  101008. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101009. int i=vorbis_ftoi(d-.5);
  101010. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101011. }
  101012. float vorbis_invsqlook(float a){
  101013. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101014. int i=vorbis_ftoi(d-.5f);
  101015. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101016. }
  101017. float vorbis_invsq2explook(int a){
  101018. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101019. }
  101020. #include <stdio.h>
  101021. float vorbis_fromdBlook(float a){
  101022. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101023. return (i<0)?1.f:
  101024. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101025. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101026. }
  101027. #endif
  101028. #ifdef INT_LOOKUP
  101029. long vorbis_invsqlook_i(long a,long e){
  101030. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101031. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101032. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101033. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101034. d)>>16); /* result 1.16 */
  101035. e+=32;
  101036. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101037. e=(e>>1)-8;
  101038. return(val>>e);
  101039. }
  101040. float vorbis_fromdBlook_i(long a){
  101041. int i=(-a)>>(12-FROMdB2_SHIFT);
  101042. return (i<0)?1.f:
  101043. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101044. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101045. }
  101046. long vorbis_coslook_i(long a){
  101047. int i=a>>COS_LOOKUP_I_SHIFT;
  101048. int d=a&COS_LOOKUP_I_MASK;
  101049. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101050. COS_LOOKUP_I_SHIFT);
  101051. }
  101052. #endif
  101053. #endif
  101054. /*** End of inlined file: lookup.c ***/
  101055. /* catch this in the build system; we #include for
  101056. compilers (like gcc) that can't inline across
  101057. modules */
  101058. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101059. float amp,float ampoffset){
  101060. int i;
  101061. float wdel=M_PI/ln;
  101062. vorbis_fpu_control fpu;
  101063. (void) fpu; // to avoid an unused variable warning
  101064. vorbis_fpu_setround(&fpu);
  101065. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  101066. i=0;
  101067. while(i<n){
  101068. int k=map[i];
  101069. int qexp;
  101070. float p=.7071067812f;
  101071. float q=.7071067812f;
  101072. float w=vorbis_coslook(wdel*k);
  101073. float *ftmp=lsp;
  101074. int c=m>>1;
  101075. do{
  101076. q*=ftmp[0]-w;
  101077. p*=ftmp[1]-w;
  101078. ftmp+=2;
  101079. }while(--c);
  101080. if(m&1){
  101081. q*=ftmp[0]-w;
  101082. q*=q;
  101083. p*=p*(1.f-w*w);
  101084. }else{
  101085. q*=q*(1.f+w);
  101086. p*=p*(1.f-w);
  101087. }
  101088. q=frexp(p+q,&qexp);
  101089. q=vorbis_fromdBlook(amp*
  101090. vorbis_invsqlook(q)*
  101091. vorbis_invsq2explook(qexp+m)-
  101092. ampoffset);
  101093. do{
  101094. curve[i++]*=q;
  101095. }while(map[i]==k);
  101096. }
  101097. vorbis_fpu_restore(fpu);
  101098. }
  101099. #else
  101100. #ifdef INT_LOOKUP
  101101. /*** Start of inlined file: lookup.c ***/
  101102. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101103. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101104. // tasks..
  101105. #if JUCE_MSVC
  101106. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101107. #endif
  101108. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101109. #if JUCE_USE_OGGVORBIS
  101110. #include <math.h>
  101111. /*** Start of inlined file: lookup.h ***/
  101112. #ifndef _V_LOOKUP_H_
  101113. #ifdef FLOAT_LOOKUP
  101114. extern float vorbis_coslook(float a);
  101115. extern float vorbis_invsqlook(float a);
  101116. extern float vorbis_invsq2explook(int a);
  101117. extern float vorbis_fromdBlook(float a);
  101118. #endif
  101119. #ifdef INT_LOOKUP
  101120. extern long vorbis_invsqlook_i(long a,long e);
  101121. extern long vorbis_coslook_i(long a);
  101122. extern float vorbis_fromdBlook_i(long a);
  101123. #endif
  101124. #endif
  101125. /*** End of inlined file: lookup.h ***/
  101126. /*** Start of inlined file: lookup_data.h ***/
  101127. #ifndef _V_LOOKUP_DATA_H_
  101128. #ifdef FLOAT_LOOKUP
  101129. #define COS_LOOKUP_SZ 128
  101130. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  101131. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  101132. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  101133. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  101134. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  101135. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  101136. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  101137. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  101138. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  101139. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  101140. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  101141. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  101142. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  101143. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  101144. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  101145. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  101146. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  101147. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  101148. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  101149. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  101150. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101151. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101152. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101153. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101154. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101155. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101156. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101157. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101158. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101159. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101160. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101161. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101162. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101163. -1.0000000000000f,
  101164. };
  101165. #define INVSQ_LOOKUP_SZ 32
  101166. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101167. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101168. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101169. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101170. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101171. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101172. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101173. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101174. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101175. 1.000000000000f,
  101176. };
  101177. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101178. #define INVSQ2EXP_LOOKUP_MAX 32
  101179. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101180. INVSQ2EXP_LOOKUP_MIN+1]={
  101181. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101182. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101183. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101184. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101185. 256.f, 181.019336f, 128.f, 90.50966799f,
  101186. 64.f, 45.254834f, 32.f, 22.627417f,
  101187. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101188. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101189. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101190. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101191. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101192. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101193. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101194. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101195. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101196. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101197. 1.525878906e-05f,
  101198. };
  101199. #endif
  101200. #define FROMdB_LOOKUP_SZ 35
  101201. #define FROMdB2_LOOKUP_SZ 32
  101202. #define FROMdB_SHIFT 5
  101203. #define FROMdB2_SHIFT 3
  101204. #define FROMdB2_MASK 31
  101205. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101206. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101207. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101208. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101209. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101210. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101211. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101212. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101213. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101214. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101215. };
  101216. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101217. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101218. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101219. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101220. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101221. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101222. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101223. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101224. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101225. };
  101226. #ifdef INT_LOOKUP
  101227. #define INVSQ_LOOKUP_I_SHIFT 10
  101228. #define INVSQ_LOOKUP_I_MASK 1023
  101229. static long INVSQ_LOOKUP_I[64+1]={
  101230. 92682l, 91966l, 91267l, 90583l,
  101231. 89915l, 89261l, 88621l, 87995l,
  101232. 87381l, 86781l, 86192l, 85616l,
  101233. 85051l, 84497l, 83953l, 83420l,
  101234. 82897l, 82384l, 81880l, 81385l,
  101235. 80899l, 80422l, 79953l, 79492l,
  101236. 79039l, 78594l, 78156l, 77726l,
  101237. 77302l, 76885l, 76475l, 76072l,
  101238. 75674l, 75283l, 74898l, 74519l,
  101239. 74146l, 73778l, 73415l, 73058l,
  101240. 72706l, 72359l, 72016l, 71679l,
  101241. 71347l, 71019l, 70695l, 70376l,
  101242. 70061l, 69750l, 69444l, 69141l,
  101243. 68842l, 68548l, 68256l, 67969l,
  101244. 67685l, 67405l, 67128l, 66855l,
  101245. 66585l, 66318l, 66054l, 65794l,
  101246. 65536l,
  101247. };
  101248. #define COS_LOOKUP_I_SHIFT 9
  101249. #define COS_LOOKUP_I_MASK 511
  101250. #define COS_LOOKUP_I_SZ 128
  101251. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101252. 16384l, 16379l, 16364l, 16340l,
  101253. 16305l, 16261l, 16207l, 16143l,
  101254. 16069l, 15986l, 15893l, 15791l,
  101255. 15679l, 15557l, 15426l, 15286l,
  101256. 15137l, 14978l, 14811l, 14635l,
  101257. 14449l, 14256l, 14053l, 13842l,
  101258. 13623l, 13395l, 13160l, 12916l,
  101259. 12665l, 12406l, 12140l, 11866l,
  101260. 11585l, 11297l, 11003l, 10702l,
  101261. 10394l, 10080l, 9760l, 9434l,
  101262. 9102l, 8765l, 8423l, 8076l,
  101263. 7723l, 7366l, 7005l, 6639l,
  101264. 6270l, 5897l, 5520l, 5139l,
  101265. 4756l, 4370l, 3981l, 3590l,
  101266. 3196l, 2801l, 2404l, 2006l,
  101267. 1606l, 1205l, 804l, 402l,
  101268. 0l, -401l, -803l, -1204l,
  101269. -1605l, -2005l, -2403l, -2800l,
  101270. -3195l, -3589l, -3980l, -4369l,
  101271. -4755l, -5138l, -5519l, -5896l,
  101272. -6269l, -6638l, -7004l, -7365l,
  101273. -7722l, -8075l, -8422l, -8764l,
  101274. -9101l, -9433l, -9759l, -10079l,
  101275. -10393l, -10701l, -11002l, -11296l,
  101276. -11584l, -11865l, -12139l, -12405l,
  101277. -12664l, -12915l, -13159l, -13394l,
  101278. -13622l, -13841l, -14052l, -14255l,
  101279. -14448l, -14634l, -14810l, -14977l,
  101280. -15136l, -15285l, -15425l, -15556l,
  101281. -15678l, -15790l, -15892l, -15985l,
  101282. -16068l, -16142l, -16206l, -16260l,
  101283. -16304l, -16339l, -16363l, -16378l,
  101284. -16383l,
  101285. };
  101286. #endif
  101287. #endif
  101288. /*** End of inlined file: lookup_data.h ***/
  101289. #ifdef FLOAT_LOOKUP
  101290. float vorbis_coslook(float a){
  101291. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101292. int i=vorbis_ftoi(d-.5);
  101293. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101294. }
  101295. float vorbis_invsqlook(float a){
  101296. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101297. int i=vorbis_ftoi(d-.5f);
  101298. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101299. }
  101300. float vorbis_invsq2explook(int a){
  101301. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101302. }
  101303. #include <stdio.h>
  101304. float vorbis_fromdBlook(float a){
  101305. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101306. return (i<0)?1.f:
  101307. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101308. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101309. }
  101310. #endif
  101311. #ifdef INT_LOOKUP
  101312. long vorbis_invsqlook_i(long a,long e){
  101313. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101314. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101315. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101316. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101317. d)>>16); /* result 1.16 */
  101318. e+=32;
  101319. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101320. e=(e>>1)-8;
  101321. return(val>>e);
  101322. }
  101323. float vorbis_fromdBlook_i(long a){
  101324. int i=(-a)>>(12-FROMdB2_SHIFT);
  101325. return (i<0)?1.f:
  101326. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101327. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101328. }
  101329. long vorbis_coslook_i(long a){
  101330. int i=a>>COS_LOOKUP_I_SHIFT;
  101331. int d=a&COS_LOOKUP_I_MASK;
  101332. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101333. COS_LOOKUP_I_SHIFT);
  101334. }
  101335. #endif
  101336. #endif
  101337. /*** End of inlined file: lookup.c ***/
  101338. /* catch this in the build system; we #include for
  101339. compilers (like gcc) that can't inline across
  101340. modules */
  101341. static int MLOOP_1[64]={
  101342. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101343. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101344. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101345. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101346. };
  101347. static int MLOOP_2[64]={
  101348. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101349. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101350. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101351. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101352. };
  101353. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101354. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101355. float amp,float ampoffset){
  101356. int i;
  101357. int ampoffseti=rint(ampoffset*4096.f);
  101358. int ampi=rint(amp*16.f);
  101359. long *ilsp=alloca(m*sizeof(*ilsp));
  101360. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101361. i=0;
  101362. while(i<n){
  101363. int j,k=map[i];
  101364. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101365. unsigned long qi=46341;
  101366. int qexp=0,shift;
  101367. long wi=vorbis_coslook_i(k*65536/ln);
  101368. qi*=labs(ilsp[0]-wi);
  101369. pi*=labs(ilsp[1]-wi);
  101370. for(j=3;j<m;j+=2){
  101371. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101372. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101373. shift=MLOOP_3[(pi|qi)>>16];
  101374. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101375. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101376. qexp+=shift;
  101377. }
  101378. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101379. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101380. shift=MLOOP_3[(pi|qi)>>16];
  101381. if(m&1){
  101382. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101383. pi=(pi>>shift)<<14;
  101384. qexp+=shift;
  101385. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101386. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101387. shift=MLOOP_3[(pi|qi)>>16];
  101388. pi>>=shift;
  101389. qi>>=shift;
  101390. qexp+=shift-14*((m+1)>>1);
  101391. pi=((pi*pi)>>16);
  101392. qi=((qi*qi)>>16);
  101393. qexp=qexp*2+m;
  101394. pi*=(1<<14)-((wi*wi)>>14);
  101395. qi+=pi>>14;
  101396. }else{
  101397. pi>>=shift;
  101398. qi>>=shift;
  101399. qexp+=shift-7*m;
  101400. pi=((pi*pi)>>16);
  101401. qi=((qi*qi)>>16);
  101402. qexp=qexp*2+m;
  101403. pi*=(1<<14)-wi;
  101404. qi*=(1<<14)+wi;
  101405. qi=(qi+pi)>>14;
  101406. }
  101407. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101408. qi>>=1; qexp++;
  101409. }else
  101410. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101411. qi<<=1; qexp--;
  101412. }
  101413. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101414. vorbis_invsqlook_i(qi,qexp)-
  101415. ampoffseti); /* 8.12[0] */
  101416. curve[i]*=amp;
  101417. while(map[++i]==k)curve[i]*=amp;
  101418. }
  101419. }
  101420. #else
  101421. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101422. float amp,float ampoffset){
  101423. int i;
  101424. float wdel=M_PI/ln;
  101425. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101426. i=0;
  101427. while(i<n){
  101428. int j,k=map[i];
  101429. float p=.5f;
  101430. float q=.5f;
  101431. float w=2.f*cos(wdel*k);
  101432. for(j=1;j<m;j+=2){
  101433. q *= w-lsp[j-1];
  101434. p *= w-lsp[j];
  101435. }
  101436. if(j==m){
  101437. q*=w-lsp[j-1];
  101438. p*=p*(4.f-w*w);
  101439. q*=q;
  101440. }else{
  101441. p*=p*(2.f-w);
  101442. q*=q*(2.f+w);
  101443. }
  101444. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101445. curve[i]*=q;
  101446. while(map[++i]==k)curve[i]*=q;
  101447. }
  101448. }
  101449. #endif
  101450. #endif
  101451. static void cheby(float *g, int ord) {
  101452. int i, j;
  101453. g[0] *= .5f;
  101454. for(i=2; i<= ord; i++) {
  101455. for(j=ord; j >= i; j--) {
  101456. g[j-2] -= g[j];
  101457. g[j] += g[j];
  101458. }
  101459. }
  101460. }
  101461. static int comp(const void *a,const void *b){
  101462. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101463. }
  101464. #define EPSILON 10e-7
  101465. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101466. int i,m;
  101467. double lastdelta=0.f;
  101468. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101469. for(i=0;i<=ord;i++)defl[i]=a[i];
  101470. for(m=ord;m>0;m--){
  101471. double newx=0.f,delta;
  101472. while(1){
  101473. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101474. for(i=m;i>0;i--){
  101475. ppp = newx*ppp + pp;
  101476. pp = newx*pp + p;
  101477. p = newx*p + defl[i-1];
  101478. }
  101479. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101480. if(denom<0)
  101481. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101482. if(pp>0){
  101483. denom = pp + sqrt(denom);
  101484. if(denom<EPSILON)denom=EPSILON;
  101485. }else{
  101486. denom = pp - sqrt(denom);
  101487. if(denom>-(EPSILON))denom=-(EPSILON);
  101488. }
  101489. delta = m*p/denom;
  101490. newx -= delta;
  101491. if(delta<0.f)delta*=-1;
  101492. if(fabs(delta/newx)<10e-12)break;
  101493. lastdelta=delta;
  101494. }
  101495. r[m-1]=newx;
  101496. for(i=m;i>0;i--)
  101497. defl[i-1]+=newx*defl[i];
  101498. defl++;
  101499. }
  101500. return(0);
  101501. }
  101502. static int Newton_Raphson(float *a,int ord,float *r){
  101503. int i, k, count=0;
  101504. double error=1.f;
  101505. double *root=(double*)alloca(ord*sizeof(*root));
  101506. for(i=0; i<ord;i++) root[i] = r[i];
  101507. while(error>1e-20){
  101508. error=0;
  101509. for(i=0; i<ord; i++) { /* Update each point. */
  101510. double pp=0.,delta;
  101511. double rooti=root[i];
  101512. double p=a[ord];
  101513. for(k=ord-1; k>= 0; k--) {
  101514. pp= pp* rooti + p;
  101515. p = p * rooti + a[k];
  101516. }
  101517. delta = p/pp;
  101518. root[i] -= delta;
  101519. error+= delta*delta;
  101520. }
  101521. if(count>40)return(-1);
  101522. count++;
  101523. }
  101524. for(i=0; i<ord;i++) r[i] = root[i];
  101525. return(0);
  101526. }
  101527. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101528. int order2=(m+1)>>1;
  101529. int g1_order,g2_order;
  101530. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101531. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101532. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101533. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101534. int i;
  101535. g1_order=(m+1)>>1;
  101536. g2_order=(m) >>1;
  101537. g1[g1_order] = 1.f;
  101538. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101539. g2[g2_order] = 1.f;
  101540. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101541. if(g1_order>g2_order){
  101542. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101543. }else{
  101544. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101545. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101546. }
  101547. cheby(g1,g1_order);
  101548. cheby(g2,g2_order);
  101549. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101550. Laguerre_With_Deflation(g2,g2_order,g2r))
  101551. return(-1);
  101552. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101553. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101554. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101555. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101556. for(i=0;i<g1_order;i++)
  101557. lsp[i*2] = acos(g1r[i]);
  101558. for(i=0;i<g2_order;i++)
  101559. lsp[i*2+1] = acos(g2r[i]);
  101560. return(0);
  101561. }
  101562. #endif
  101563. /*** End of inlined file: lsp.c ***/
  101564. /*** Start of inlined file: mapping0.c ***/
  101565. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101566. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101567. // tasks..
  101568. #if JUCE_MSVC
  101569. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101570. #endif
  101571. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101572. #if JUCE_USE_OGGVORBIS
  101573. #include <stdlib.h>
  101574. #include <stdio.h>
  101575. #include <string.h>
  101576. #include <math.h>
  101577. static void mapping0_free_info(vorbis_info_mapping *i){
  101578. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101579. if(info){
  101580. memset(info,0,sizeof(*info));
  101581. _ogg_free(info);
  101582. }
  101583. }
  101584. static int ilog3(unsigned int v){
  101585. int ret=0;
  101586. if(v)--v;
  101587. while(v){
  101588. ret++;
  101589. v>>=1;
  101590. }
  101591. return(ret);
  101592. }
  101593. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101594. oggpack_buffer *opb){
  101595. int i;
  101596. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101597. if(info->submaps>1){
  101598. oggpack_write(opb,1,1);
  101599. oggpack_write(opb,info->submaps-1,4);
  101600. }else
  101601. oggpack_write(opb,0,1);
  101602. if(info->coupling_steps>0){
  101603. oggpack_write(opb,1,1);
  101604. oggpack_write(opb,info->coupling_steps-1,8);
  101605. for(i=0;i<info->coupling_steps;i++){
  101606. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101607. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101608. }
  101609. }else
  101610. oggpack_write(opb,0,1);
  101611. oggpack_write(opb,0,2); /* 2,3:reserved */
  101612. if(info->submaps>1){
  101613. for(i=0;i<vi->channels;i++)
  101614. oggpack_write(opb,info->chmuxlist[i],4);
  101615. }
  101616. for(i=0;i<info->submaps;i++){
  101617. oggpack_write(opb,0,8); /* time submap unused */
  101618. oggpack_write(opb,info->floorsubmap[i],8);
  101619. oggpack_write(opb,info->residuesubmap[i],8);
  101620. }
  101621. }
  101622. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101623. int i;
  101624. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101625. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101626. memset(info,0,sizeof(*info));
  101627. if(oggpack_read(opb,1))
  101628. info->submaps=oggpack_read(opb,4)+1;
  101629. else
  101630. info->submaps=1;
  101631. if(oggpack_read(opb,1)){
  101632. info->coupling_steps=oggpack_read(opb,8)+1;
  101633. for(i=0;i<info->coupling_steps;i++){
  101634. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101635. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101636. if(testM<0 ||
  101637. testA<0 ||
  101638. testM==testA ||
  101639. testM>=vi->channels ||
  101640. testA>=vi->channels) goto err_out;
  101641. }
  101642. }
  101643. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101644. if(info->submaps>1){
  101645. for(i=0;i<vi->channels;i++){
  101646. info->chmuxlist[i]=oggpack_read(opb,4);
  101647. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101648. }
  101649. }
  101650. for(i=0;i<info->submaps;i++){
  101651. oggpack_read(opb,8); /* time submap unused */
  101652. info->floorsubmap[i]=oggpack_read(opb,8);
  101653. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101654. info->residuesubmap[i]=oggpack_read(opb,8);
  101655. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101656. }
  101657. return info;
  101658. err_out:
  101659. mapping0_free_info(info);
  101660. return(NULL);
  101661. }
  101662. #if 0
  101663. static long seq=0;
  101664. static ogg_int64_t total=0;
  101665. static float FLOOR1_fromdB_LOOKUP[256]={
  101666. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101667. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101668. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101669. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101670. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101671. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101672. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101673. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101674. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101675. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101676. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101677. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101678. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101679. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101680. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101681. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101682. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101683. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101684. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101685. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101686. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101687. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101688. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101689. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101690. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101691. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101692. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101693. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101694. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101695. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101696. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101697. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101698. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101699. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101700. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101701. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101702. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101703. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101704. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101705. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101706. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101707. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101708. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101709. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101710. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101711. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101712. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101713. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101714. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101715. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101716. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101717. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101718. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101719. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101720. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101721. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101722. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101723. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101724. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101725. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101726. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101727. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101728. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101729. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101730. };
  101731. #endif
  101732. extern int *floor1_fit(vorbis_block *vb,void *look,
  101733. const float *logmdct, /* in */
  101734. const float *logmask);
  101735. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101736. int *A,int *B,
  101737. int del);
  101738. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101739. void*look,
  101740. int *post,int *ilogmask);
  101741. static int mapping0_forward(vorbis_block *vb){
  101742. vorbis_dsp_state *vd=vb->vd;
  101743. vorbis_info *vi=vd->vi;
  101744. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101745. private_state *b=(private_state*)vb->vd->backend_state;
  101746. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101747. int n=vb->pcmend;
  101748. int i,j,k;
  101749. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101750. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101751. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101752. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101753. float global_ampmax=vbi->ampmax;
  101754. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101755. int blocktype=vbi->blocktype;
  101756. int modenumber=vb->W;
  101757. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101758. vorbis_look_psy *psy_look=
  101759. b->psy+blocktype+(vb->W?2:0);
  101760. vb->mode=modenumber;
  101761. for(i=0;i<vi->channels;i++){
  101762. float scale=4.f/n;
  101763. float scale_dB;
  101764. float *pcm =vb->pcm[i];
  101765. float *logfft =pcm;
  101766. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101767. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101768. todB estimation used on IEEE 754
  101769. compliant machines had a bug that
  101770. returned dB values about a third
  101771. of a decibel too high. The bug
  101772. was harmless because tunings
  101773. implicitly took that into
  101774. account. However, fixing the bug
  101775. in the estimator requires
  101776. changing all the tunings as well.
  101777. For now, it's easier to sync
  101778. things back up here, and
  101779. recalibrate the tunings in the
  101780. next major model upgrade. */
  101781. #if 0
  101782. if(vi->channels==2)
  101783. if(i==0)
  101784. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101785. else
  101786. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101787. #endif
  101788. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101789. #if 0
  101790. if(vi->channels==2)
  101791. if(i==0)
  101792. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101793. else
  101794. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101795. #endif
  101796. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101797. drft_forward(&b->fft_look[vb->W],pcm);
  101798. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101799. original todB estimation used on
  101800. IEEE 754 compliant machines had a
  101801. bug that returned dB values about
  101802. a third of a decibel too high.
  101803. The bug was harmless because
  101804. tunings implicitly took that into
  101805. account. However, fixing the bug
  101806. in the estimator requires
  101807. changing all the tunings as well.
  101808. For now, it's easier to sync
  101809. things back up here, and
  101810. recalibrate the tunings in the
  101811. next major model upgrade. */
  101812. local_ampmax[i]=logfft[0];
  101813. for(j=1;j<n-1;j+=2){
  101814. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101815. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101816. .345 is a hack; the original todB
  101817. estimation used on IEEE 754
  101818. compliant machines had a bug that
  101819. returned dB values about a third
  101820. of a decibel too high. The bug
  101821. was harmless because tunings
  101822. implicitly took that into
  101823. account. However, fixing the bug
  101824. in the estimator requires
  101825. changing all the tunings as well.
  101826. For now, it's easier to sync
  101827. things back up here, and
  101828. recalibrate the tunings in the
  101829. next major model upgrade. */
  101830. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101831. }
  101832. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101833. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101834. #if 0
  101835. if(vi->channels==2){
  101836. if(i==0){
  101837. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101838. }else{
  101839. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101840. }
  101841. }
  101842. #endif
  101843. }
  101844. {
  101845. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101846. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101847. for(i=0;i<vi->channels;i++){
  101848. int submap=info->chmuxlist[i];
  101849. float *mdct =gmdct[i];
  101850. float *logfft =vb->pcm[i];
  101851. float *logmdct =logfft+n/2;
  101852. float *logmask =logfft;
  101853. vb->mode=modenumber;
  101854. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101855. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101856. for(j=0;j<n/2;j++)
  101857. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101858. todB estimation used on IEEE 754
  101859. compliant machines had a bug that
  101860. returned dB values about a third
  101861. of a decibel too high. The bug
  101862. was harmless because tunings
  101863. implicitly took that into
  101864. account. However, fixing the bug
  101865. in the estimator requires
  101866. changing all the tunings as well.
  101867. For now, it's easier to sync
  101868. things back up here, and
  101869. recalibrate the tunings in the
  101870. next major model upgrade. */
  101871. #if 0
  101872. if(vi->channels==2){
  101873. if(i==0)
  101874. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101875. else
  101876. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101877. }else{
  101878. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101879. }
  101880. #endif
  101881. _vp_noisemask(psy_look,
  101882. logmdct,
  101883. noise); /* noise does not have by-frequency offset
  101884. bias applied yet */
  101885. #if 0
  101886. if(vi->channels==2){
  101887. if(i==0)
  101888. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101889. else
  101890. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101891. }
  101892. #endif
  101893. _vp_tonemask(psy_look,
  101894. logfft,
  101895. tone,
  101896. global_ampmax,
  101897. local_ampmax[i]);
  101898. #if 0
  101899. if(vi->channels==2){
  101900. if(i==0)
  101901. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101902. else
  101903. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101904. }
  101905. #endif
  101906. #if 0
  101907. {
  101908. float aotuv[psy_look->n];
  101909. #endif
  101910. _vp_offset_and_mix(psy_look,
  101911. noise,
  101912. tone,
  101913. 1,
  101914. logmask,
  101915. mdct,
  101916. logmdct);
  101917. #if 0
  101918. if(vi->channels==2){
  101919. if(i==0)
  101920. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101921. else
  101922. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101923. }
  101924. }
  101925. #endif
  101926. #if 0
  101927. if(vi->channels==2){
  101928. if(i==0)
  101929. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101930. else
  101931. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101932. }
  101933. #endif
  101934. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101935. floor_posts[i][PACKETBLOBS/2]=
  101936. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101937. logmdct,
  101938. logmask);
  101939. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101940. _vp_offset_and_mix(psy_look,
  101941. noise,
  101942. tone,
  101943. 2,
  101944. logmask,
  101945. mdct,
  101946. logmdct);
  101947. #if 0
  101948. if(vi->channels==2){
  101949. if(i==0)
  101950. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101951. else
  101952. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101953. }
  101954. #endif
  101955. floor_posts[i][PACKETBLOBS-1]=
  101956. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101957. logmdct,
  101958. logmask);
  101959. _vp_offset_and_mix(psy_look,
  101960. noise,
  101961. tone,
  101962. 0,
  101963. logmask,
  101964. mdct,
  101965. logmdct);
  101966. #if 0
  101967. if(vi->channels==2)
  101968. if(i==0)
  101969. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101970. else
  101971. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101972. #endif
  101973. floor_posts[i][0]=
  101974. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101975. logmdct,
  101976. logmask);
  101977. for(k=1;k<PACKETBLOBS/2;k++)
  101978. floor_posts[i][k]=
  101979. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101980. floor_posts[i][0],
  101981. floor_posts[i][PACKETBLOBS/2],
  101982. k*65536/(PACKETBLOBS/2));
  101983. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101984. floor_posts[i][k]=
  101985. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101986. floor_posts[i][PACKETBLOBS/2],
  101987. floor_posts[i][PACKETBLOBS-1],
  101988. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101989. }
  101990. }
  101991. }
  101992. vbi->ampmax=global_ampmax;
  101993. {
  101994. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101995. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101996. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101997. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101998. float **mag_memo;
  101999. int **mag_sort;
  102000. if(info->coupling_steps){
  102001. mag_memo=_vp_quantize_couple_memo(vb,
  102002. &ci->psy_g_param,
  102003. psy_look,
  102004. info,
  102005. gmdct);
  102006. mag_sort=_vp_quantize_couple_sort(vb,
  102007. psy_look,
  102008. info,
  102009. mag_memo);
  102010. hf_reduction(&ci->psy_g_param,
  102011. psy_look,
  102012. info,
  102013. mag_memo);
  102014. }
  102015. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  102016. if(psy_look->vi->normal_channel_p){
  102017. for(i=0;i<vi->channels;i++){
  102018. float *mdct =gmdct[i];
  102019. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  102020. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  102021. }
  102022. }
  102023. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  102024. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  102025. k++){
  102026. oggpack_buffer *opb=vbi->packetblob[k];
  102027. oggpack_write(opb,0,1);
  102028. oggpack_write(opb,modenumber,b->modebits);
  102029. if(vb->W){
  102030. oggpack_write(opb,vb->lW,1);
  102031. oggpack_write(opb,vb->nW,1);
  102032. }
  102033. for(i=0;i<vi->channels;i++){
  102034. int submap=info->chmuxlist[i];
  102035. float *mdct =gmdct[i];
  102036. float *res =vb->pcm[i];
  102037. int *ilogmask=ilogmaskch[i]=
  102038. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  102039. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  102040. floor_posts[i][k],
  102041. ilogmask);
  102042. #if 0
  102043. {
  102044. char buf[80];
  102045. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  102046. float work[n/2];
  102047. for(j=0;j<n/2;j++)
  102048. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  102049. _analysis_output(buf,seq,work,n/2,1,1,0);
  102050. }
  102051. #endif
  102052. _vp_remove_floor(psy_look,
  102053. mdct,
  102054. ilogmask,
  102055. res,
  102056. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102057. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  102058. #if 0
  102059. {
  102060. char buf[80];
  102061. float work[n/2];
  102062. for(j=0;j<n/2;j++)
  102063. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  102064. sprintf(buf,"resI%c%d",i?'R':'L',k);
  102065. _analysis_output(buf,seq,work,n/2,1,1,0);
  102066. }
  102067. #endif
  102068. }
  102069. if(info->coupling_steps){
  102070. _vp_couple(k,
  102071. &ci->psy_g_param,
  102072. psy_look,
  102073. info,
  102074. vb->pcm,
  102075. mag_memo,
  102076. mag_sort,
  102077. ilogmaskch,
  102078. nonzero,
  102079. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102080. }
  102081. for(i=0;i<info->submaps;i++){
  102082. int ch_in_bundle=0;
  102083. long **classifications;
  102084. int resnum=info->residuesubmap[i];
  102085. for(j=0;j<vi->channels;j++){
  102086. if(info->chmuxlist[j]==i){
  102087. zerobundle[ch_in_bundle]=0;
  102088. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  102089. res_bundle[ch_in_bundle]=vb->pcm[j];
  102090. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  102091. }
  102092. }
  102093. classifications=_residue_P[ci->residue_type[resnum]]->
  102094. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  102095. _residue_P[ci->residue_type[resnum]]->
  102096. forward(opb,vb,b->residue[resnum],
  102097. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  102098. }
  102099. }
  102100. }
  102101. #if 0
  102102. seq++;
  102103. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  102104. #endif
  102105. return(0);
  102106. }
  102107. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  102108. vorbis_dsp_state *vd=vb->vd;
  102109. vorbis_info *vi=vd->vi;
  102110. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  102111. private_state *b=(private_state*)vd->backend_state;
  102112. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  102113. int i,j;
  102114. long n=vb->pcmend=ci->blocksizes[vb->W];
  102115. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  102116. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102117. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  102118. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  102119. for(i=0;i<vi->channels;i++){
  102120. int submap=info->chmuxlist[i];
  102121. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102122. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  102123. if(floormemo[i])
  102124. nonzero[i]=1;
  102125. else
  102126. nonzero[i]=0;
  102127. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  102128. }
  102129. for(i=0;i<info->coupling_steps;i++){
  102130. if(nonzero[info->coupling_mag[i]] ||
  102131. nonzero[info->coupling_ang[i]]){
  102132. nonzero[info->coupling_mag[i]]=1;
  102133. nonzero[info->coupling_ang[i]]=1;
  102134. }
  102135. }
  102136. for(i=0;i<info->submaps;i++){
  102137. int ch_in_bundle=0;
  102138. for(j=0;j<vi->channels;j++){
  102139. if(info->chmuxlist[j]==i){
  102140. if(nonzero[j])
  102141. zerobundle[ch_in_bundle]=1;
  102142. else
  102143. zerobundle[ch_in_bundle]=0;
  102144. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  102145. }
  102146. }
  102147. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  102148. inverse(vb,b->residue[info->residuesubmap[i]],
  102149. pcmbundle,zerobundle,ch_in_bundle);
  102150. }
  102151. for(i=info->coupling_steps-1;i>=0;i--){
  102152. float *pcmM=vb->pcm[info->coupling_mag[i]];
  102153. float *pcmA=vb->pcm[info->coupling_ang[i]];
  102154. for(j=0;j<n/2;j++){
  102155. float mag=pcmM[j];
  102156. float ang=pcmA[j];
  102157. if(mag>0)
  102158. if(ang>0){
  102159. pcmM[j]=mag;
  102160. pcmA[j]=mag-ang;
  102161. }else{
  102162. pcmA[j]=mag;
  102163. pcmM[j]=mag+ang;
  102164. }
  102165. else
  102166. if(ang>0){
  102167. pcmM[j]=mag;
  102168. pcmA[j]=mag+ang;
  102169. }else{
  102170. pcmA[j]=mag;
  102171. pcmM[j]=mag-ang;
  102172. }
  102173. }
  102174. }
  102175. for(i=0;i<vi->channels;i++){
  102176. float *pcm=vb->pcm[i];
  102177. int submap=info->chmuxlist[i];
  102178. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102179. inverse2(vb,b->flr[info->floorsubmap[submap]],
  102180. floormemo[i],pcm);
  102181. }
  102182. for(i=0;i<vi->channels;i++){
  102183. float *pcm=vb->pcm[i];
  102184. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  102185. }
  102186. return(0);
  102187. }
  102188. vorbis_func_mapping mapping0_exportbundle={
  102189. &mapping0_pack,
  102190. &mapping0_unpack,
  102191. &mapping0_free_info,
  102192. &mapping0_forward,
  102193. &mapping0_inverse
  102194. };
  102195. #endif
  102196. /*** End of inlined file: mapping0.c ***/
  102197. /*** Start of inlined file: mdct.c ***/
  102198. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102199. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102200. // tasks..
  102201. #if JUCE_MSVC
  102202. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102203. #endif
  102204. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102205. #if JUCE_USE_OGGVORBIS
  102206. #include <stdio.h>
  102207. #include <stdlib.h>
  102208. #include <string.h>
  102209. #include <math.h>
  102210. void mdct_init(mdct_lookup *lookup,int n){
  102211. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  102212. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  102213. int i;
  102214. int n2=n>>1;
  102215. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  102216. lookup->n=n;
  102217. lookup->trig=T;
  102218. lookup->bitrev=bitrev;
  102219. for(i=0;i<n/4;i++){
  102220. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  102221. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  102222. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  102223. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  102224. }
  102225. for(i=0;i<n/8;i++){
  102226. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  102227. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  102228. }
  102229. {
  102230. int mask=(1<<(log2n-1))-1,i,j;
  102231. int msb=1<<(log2n-2);
  102232. for(i=0;i<n/8;i++){
  102233. int acc=0;
  102234. for(j=0;msb>>j;j++)
  102235. if((msb>>j)&i)acc|=1<<j;
  102236. bitrev[i*2]=((~acc)&mask)-1;
  102237. bitrev[i*2+1]=acc;
  102238. }
  102239. }
  102240. lookup->scale=FLOAT_CONV(4.f/n);
  102241. }
  102242. STIN void mdct_butterfly_8(DATA_TYPE *x){
  102243. REG_TYPE r0 = x[6] + x[2];
  102244. REG_TYPE r1 = x[6] - x[2];
  102245. REG_TYPE r2 = x[4] + x[0];
  102246. REG_TYPE r3 = x[4] - x[0];
  102247. x[6] = r0 + r2;
  102248. x[4] = r0 - r2;
  102249. r0 = x[5] - x[1];
  102250. r2 = x[7] - x[3];
  102251. x[0] = r1 + r0;
  102252. x[2] = r1 - r0;
  102253. r0 = x[5] + x[1];
  102254. r1 = x[7] + x[3];
  102255. x[3] = r2 + r3;
  102256. x[1] = r2 - r3;
  102257. x[7] = r1 + r0;
  102258. x[5] = r1 - r0;
  102259. }
  102260. STIN void mdct_butterfly_16(DATA_TYPE *x){
  102261. REG_TYPE r0 = x[1] - x[9];
  102262. REG_TYPE r1 = x[0] - x[8];
  102263. x[8] += x[0];
  102264. x[9] += x[1];
  102265. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  102266. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  102267. r0 = x[3] - x[11];
  102268. r1 = x[10] - x[2];
  102269. x[10] += x[2];
  102270. x[11] += x[3];
  102271. x[2] = r0;
  102272. x[3] = r1;
  102273. r0 = x[12] - x[4];
  102274. r1 = x[13] - x[5];
  102275. x[12] += x[4];
  102276. x[13] += x[5];
  102277. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  102278. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  102279. r0 = x[14] - x[6];
  102280. r1 = x[15] - x[7];
  102281. x[14] += x[6];
  102282. x[15] += x[7];
  102283. x[6] = r0;
  102284. x[7] = r1;
  102285. mdct_butterfly_8(x);
  102286. mdct_butterfly_8(x+8);
  102287. }
  102288. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102289. REG_TYPE r0 = x[30] - x[14];
  102290. REG_TYPE r1 = x[31] - x[15];
  102291. x[30] += x[14];
  102292. x[31] += x[15];
  102293. x[14] = r0;
  102294. x[15] = r1;
  102295. r0 = x[28] - x[12];
  102296. r1 = x[29] - x[13];
  102297. x[28] += x[12];
  102298. x[29] += x[13];
  102299. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102300. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102301. r0 = x[26] - x[10];
  102302. r1 = x[27] - x[11];
  102303. x[26] += x[10];
  102304. x[27] += x[11];
  102305. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102306. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102307. r0 = x[24] - x[8];
  102308. r1 = x[25] - x[9];
  102309. x[24] += x[8];
  102310. x[25] += x[9];
  102311. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102312. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102313. r0 = x[22] - x[6];
  102314. r1 = x[7] - x[23];
  102315. x[22] += x[6];
  102316. x[23] += x[7];
  102317. x[6] = r1;
  102318. x[7] = r0;
  102319. r0 = x[4] - x[20];
  102320. r1 = x[5] - x[21];
  102321. x[20] += x[4];
  102322. x[21] += x[5];
  102323. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102324. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102325. r0 = x[2] - x[18];
  102326. r1 = x[3] - x[19];
  102327. x[18] += x[2];
  102328. x[19] += x[3];
  102329. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102330. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102331. r0 = x[0] - x[16];
  102332. r1 = x[1] - x[17];
  102333. x[16] += x[0];
  102334. x[17] += x[1];
  102335. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102336. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102337. mdct_butterfly_16(x);
  102338. mdct_butterfly_16(x+16);
  102339. }
  102340. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102341. DATA_TYPE *x,
  102342. int points){
  102343. DATA_TYPE *x1 = x + points - 8;
  102344. DATA_TYPE *x2 = x + (points>>1) - 8;
  102345. REG_TYPE r0;
  102346. REG_TYPE r1;
  102347. do{
  102348. r0 = x1[6] - x2[6];
  102349. r1 = x1[7] - x2[7];
  102350. x1[6] += x2[6];
  102351. x1[7] += x2[7];
  102352. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102353. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102354. r0 = x1[4] - x2[4];
  102355. r1 = x1[5] - x2[5];
  102356. x1[4] += x2[4];
  102357. x1[5] += x2[5];
  102358. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102359. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102360. r0 = x1[2] - x2[2];
  102361. r1 = x1[3] - x2[3];
  102362. x1[2] += x2[2];
  102363. x1[3] += x2[3];
  102364. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102365. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102366. r0 = x1[0] - x2[0];
  102367. r1 = x1[1] - x2[1];
  102368. x1[0] += x2[0];
  102369. x1[1] += x2[1];
  102370. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102371. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102372. x1-=8;
  102373. x2-=8;
  102374. T+=16;
  102375. }while(x2>=x);
  102376. }
  102377. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102378. DATA_TYPE *x,
  102379. int points,
  102380. int trigint){
  102381. DATA_TYPE *x1 = x + points - 8;
  102382. DATA_TYPE *x2 = x + (points>>1) - 8;
  102383. REG_TYPE r0;
  102384. REG_TYPE r1;
  102385. do{
  102386. r0 = x1[6] - x2[6];
  102387. r1 = x1[7] - x2[7];
  102388. x1[6] += x2[6];
  102389. x1[7] += x2[7];
  102390. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102391. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102392. T+=trigint;
  102393. r0 = x1[4] - x2[4];
  102394. r1 = x1[5] - x2[5];
  102395. x1[4] += x2[4];
  102396. x1[5] += x2[5];
  102397. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102398. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102399. T+=trigint;
  102400. r0 = x1[2] - x2[2];
  102401. r1 = x1[3] - x2[3];
  102402. x1[2] += x2[2];
  102403. x1[3] += x2[3];
  102404. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102405. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102406. T+=trigint;
  102407. r0 = x1[0] - x2[0];
  102408. r1 = x1[1] - x2[1];
  102409. x1[0] += x2[0];
  102410. x1[1] += x2[1];
  102411. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102412. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102413. T+=trigint;
  102414. x1-=8;
  102415. x2-=8;
  102416. }while(x2>=x);
  102417. }
  102418. STIN void mdct_butterflies(mdct_lookup *init,
  102419. DATA_TYPE *x,
  102420. int points){
  102421. DATA_TYPE *T=init->trig;
  102422. int stages=init->log2n-5;
  102423. int i,j;
  102424. if(--stages>0){
  102425. mdct_butterfly_first(T,x,points);
  102426. }
  102427. for(i=1;--stages>0;i++){
  102428. for(j=0;j<(1<<i);j++)
  102429. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102430. }
  102431. for(j=0;j<points;j+=32)
  102432. mdct_butterfly_32(x+j);
  102433. }
  102434. void mdct_clear(mdct_lookup *l){
  102435. if(l){
  102436. if(l->trig)_ogg_free(l->trig);
  102437. if(l->bitrev)_ogg_free(l->bitrev);
  102438. memset(l,0,sizeof(*l));
  102439. }
  102440. }
  102441. STIN void mdct_bitreverse(mdct_lookup *init,
  102442. DATA_TYPE *x){
  102443. int n = init->n;
  102444. int *bit = init->bitrev;
  102445. DATA_TYPE *w0 = x;
  102446. DATA_TYPE *w1 = x = w0+(n>>1);
  102447. DATA_TYPE *T = init->trig+n;
  102448. do{
  102449. DATA_TYPE *x0 = x+bit[0];
  102450. DATA_TYPE *x1 = x+bit[1];
  102451. REG_TYPE r0 = x0[1] - x1[1];
  102452. REG_TYPE r1 = x0[0] + x1[0];
  102453. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102454. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102455. w1 -= 4;
  102456. r0 = HALVE(x0[1] + x1[1]);
  102457. r1 = HALVE(x0[0] - x1[0]);
  102458. w0[0] = r0 + r2;
  102459. w1[2] = r0 - r2;
  102460. w0[1] = r1 + r3;
  102461. w1[3] = r3 - r1;
  102462. x0 = x+bit[2];
  102463. x1 = x+bit[3];
  102464. r0 = x0[1] - x1[1];
  102465. r1 = x0[0] + x1[0];
  102466. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102467. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102468. r0 = HALVE(x0[1] + x1[1]);
  102469. r1 = HALVE(x0[0] - x1[0]);
  102470. w0[2] = r0 + r2;
  102471. w1[0] = r0 - r2;
  102472. w0[3] = r1 + r3;
  102473. w1[1] = r3 - r1;
  102474. T += 4;
  102475. bit += 4;
  102476. w0 += 4;
  102477. }while(w0<w1);
  102478. }
  102479. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102480. int n=init->n;
  102481. int n2=n>>1;
  102482. int n4=n>>2;
  102483. DATA_TYPE *iX = in+n2-7;
  102484. DATA_TYPE *oX = out+n2+n4;
  102485. DATA_TYPE *T = init->trig+n4;
  102486. do{
  102487. oX -= 4;
  102488. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102489. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102490. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102491. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102492. iX -= 8;
  102493. T += 4;
  102494. }while(iX>=in);
  102495. iX = in+n2-8;
  102496. oX = out+n2+n4;
  102497. T = init->trig+n4;
  102498. do{
  102499. T -= 4;
  102500. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102501. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102502. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102503. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102504. iX -= 8;
  102505. oX += 4;
  102506. }while(iX>=in);
  102507. mdct_butterflies(init,out+n2,n2);
  102508. mdct_bitreverse(init,out);
  102509. {
  102510. DATA_TYPE *oX1=out+n2+n4;
  102511. DATA_TYPE *oX2=out+n2+n4;
  102512. DATA_TYPE *iX =out;
  102513. T =init->trig+n2;
  102514. do{
  102515. oX1-=4;
  102516. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102517. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102518. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102519. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102520. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102521. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102522. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102523. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102524. oX2+=4;
  102525. iX += 8;
  102526. T += 8;
  102527. }while(iX<oX1);
  102528. iX=out+n2+n4;
  102529. oX1=out+n4;
  102530. oX2=oX1;
  102531. do{
  102532. oX1-=4;
  102533. iX-=4;
  102534. oX2[0] = -(oX1[3] = iX[3]);
  102535. oX2[1] = -(oX1[2] = iX[2]);
  102536. oX2[2] = -(oX1[1] = iX[1]);
  102537. oX2[3] = -(oX1[0] = iX[0]);
  102538. oX2+=4;
  102539. }while(oX2<iX);
  102540. iX=out+n2+n4;
  102541. oX1=out+n2+n4;
  102542. oX2=out+n2;
  102543. do{
  102544. oX1-=4;
  102545. oX1[0]= iX[3];
  102546. oX1[1]= iX[2];
  102547. oX1[2]= iX[1];
  102548. oX1[3]= iX[0];
  102549. iX+=4;
  102550. }while(oX1>oX2);
  102551. }
  102552. }
  102553. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102554. int n=init->n;
  102555. int n2=n>>1;
  102556. int n4=n>>2;
  102557. int n8=n>>3;
  102558. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102559. DATA_TYPE *w2=w+n2;
  102560. REG_TYPE r0;
  102561. REG_TYPE r1;
  102562. DATA_TYPE *x0=in+n2+n4;
  102563. DATA_TYPE *x1=x0+1;
  102564. DATA_TYPE *T=init->trig+n2;
  102565. int i=0;
  102566. for(i=0;i<n8;i+=2){
  102567. x0 -=4;
  102568. T-=2;
  102569. r0= x0[2] + x1[0];
  102570. r1= x0[0] + x1[2];
  102571. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102572. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102573. x1 +=4;
  102574. }
  102575. x1=in+1;
  102576. for(;i<n2-n8;i+=2){
  102577. T-=2;
  102578. x0 -=4;
  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. x0=in+n;
  102586. for(;i<n2;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. mdct_butterflies(init,w+n2,n2);
  102596. mdct_bitreverse(init,w);
  102597. T=init->trig+n2;
  102598. x0=out+n2;
  102599. for(i=0;i<n4;i++){
  102600. x0--;
  102601. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102602. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102603. w+=2;
  102604. T+=2;
  102605. }
  102606. }
  102607. #endif
  102608. /*** End of inlined file: mdct.c ***/
  102609. /*** Start of inlined file: psy.c ***/
  102610. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102611. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102612. // tasks..
  102613. #if JUCE_MSVC
  102614. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102615. #endif
  102616. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102617. #if JUCE_USE_OGGVORBIS
  102618. #include <stdlib.h>
  102619. #include <math.h>
  102620. #include <string.h>
  102621. /*** Start of inlined file: masking.h ***/
  102622. #ifndef _V_MASKING_H_
  102623. #define _V_MASKING_H_
  102624. #define MAX_ATH 88
  102625. static float ATH[]={
  102626. -51, -52, -53, -54, -55, -56, -57, -58,
  102627. -59, -60, -61, -62, -63, -64, -65, -66,
  102628. -67, -68, -69, -70, -71, -72, -73, -74,
  102629. -75, -76, -77, -78, -80, -81, -82, -83,
  102630. -84, -85, -86, -87, -88, -88, -89, -89,
  102631. -90, -91, -91, -92, -93, -94, -95, -96,
  102632. -96, -97, -98, -98, -99, -99,-100,-100,
  102633. -101,-102,-103,-104,-106,-107,-107,-107,
  102634. -107,-105,-103,-102,-101, -99, -98, -96,
  102635. -95, -95, -96, -97, -96, -95, -93, -90,
  102636. -80, -70, -50, -40, -30, -30, -30, -30
  102637. };
  102638. #define EHMER_OFFSET 16
  102639. #define EHMER_MAX 56
  102640. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102641. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102642. -60, -60, -60, -60, -62, -62, -65, -73,
  102643. -69, -68, -68, -67, -70, -70, -72, -74,
  102644. -75, -79, -79, -80, -83, -88, -93, -100,
  102645. -110, -999, -999, -999, -999, -999, -999, -999,
  102646. -999, -999, -999, -999, -999, -999, -999, -999,
  102647. -999, -999, -999, -999, -999, -999, -999, -999},
  102648. { -48, -48, -48, -48, -48, -48, -48, -48,
  102649. -48, -48, -48, -48, -48, -53, -61, -66,
  102650. -66, -68, -67, -70, -76, -76, -72, -73,
  102651. -75, -76, -78, -79, -83, -88, -93, -100,
  102652. -110, -999, -999, -999, -999, -999, -999, -999,
  102653. -999, -999, -999, -999, -999, -999, -999, -999,
  102654. -999, -999, -999, -999, -999, -999, -999, -999},
  102655. { -37, -37, -37, -37, -37, -37, -37, -37,
  102656. -38, -40, -42, -46, -48, -53, -55, -62,
  102657. -65, -58, -56, -56, -61, -60, -65, -67,
  102658. -69, -71, -77, -77, -78, -80, -82, -84,
  102659. -88, -93, -98, -106, -112, -999, -999, -999,
  102660. -999, -999, -999, -999, -999, -999, -999, -999,
  102661. -999, -999, -999, -999, -999, -999, -999, -999},
  102662. { -25, -25, -25, -25, -25, -25, -25, -25,
  102663. -25, -26, -27, -29, -32, -38, -48, -52,
  102664. -52, -50, -48, -48, -51, -52, -54, -60,
  102665. -67, -67, -66, -68, -69, -73, -73, -76,
  102666. -80, -81, -81, -85, -85, -86, -88, -93,
  102667. -100, -110, -999, -999, -999, -999, -999, -999,
  102668. -999, -999, -999, -999, -999, -999, -999, -999},
  102669. { -16, -16, -16, -16, -16, -16, -16, -16,
  102670. -17, -19, -20, -22, -26, -28, -31, -40,
  102671. -47, -39, -39, -40, -42, -43, -47, -51,
  102672. -57, -52, -55, -55, -60, -58, -62, -63,
  102673. -70, -67, -69, -72, -73, -77, -80, -82,
  102674. -83, -87, -90, -94, -98, -104, -115, -999,
  102675. -999, -999, -999, -999, -999, -999, -999, -999},
  102676. { -8, -8, -8, -8, -8, -8, -8, -8,
  102677. -8, -8, -10, -11, -15, -19, -25, -30,
  102678. -34, -31, -30, -31, -29, -32, -35, -42,
  102679. -48, -42, -44, -46, -50, -50, -51, -52,
  102680. -59, -54, -55, -55, -58, -62, -63, -66,
  102681. -72, -73, -76, -75, -78, -80, -80, -81,
  102682. -84, -88, -90, -94, -98, -101, -106, -110}},
  102683. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102684. -66, -66, -66, -66, -66, -67, -67, -67,
  102685. -76, -72, -71, -74, -76, -76, -75, -78,
  102686. -79, -79, -81, -83, -86, -89, -93, -97,
  102687. -100, -105, -110, -999, -999, -999, -999, -999,
  102688. -999, -999, -999, -999, -999, -999, -999, -999,
  102689. -999, -999, -999, -999, -999, -999, -999, -999},
  102690. { -47, -47, -47, -47, -47, -47, -47, -47,
  102691. -47, -47, -47, -48, -51, -55, -59, -66,
  102692. -66, -66, -67, -66, -68, -69, -70, -74,
  102693. -79, -77, -77, -78, -80, -81, -82, -84,
  102694. -86, -88, -91, -95, -100, -108, -116, -999,
  102695. -999, -999, -999, -999, -999, -999, -999, -999,
  102696. -999, -999, -999, -999, -999, -999, -999, -999},
  102697. { -36, -36, -36, -36, -36, -36, -36, -36,
  102698. -36, -37, -37, -41, -44, -48, -51, -58,
  102699. -62, -60, -57, -59, -59, -60, -63, -65,
  102700. -72, -71, -70, -72, -74, -77, -76, -78,
  102701. -81, -81, -80, -83, -86, -91, -96, -100,
  102702. -105, -110, -999, -999, -999, -999, -999, -999,
  102703. -999, -999, -999, -999, -999, -999, -999, -999},
  102704. { -28, -28, -28, -28, -28, -28, -28, -28,
  102705. -28, -30, -32, -32, -33, -35, -41, -49,
  102706. -50, -49, -47, -48, -48, -52, -51, -57,
  102707. -65, -61, -59, -61, -64, -69, -70, -74,
  102708. -77, -77, -78, -81, -84, -85, -87, -90,
  102709. -92, -96, -100, -107, -112, -999, -999, -999,
  102710. -999, -999, -999, -999, -999, -999, -999, -999},
  102711. { -19, -19, -19, -19, -19, -19, -19, -19,
  102712. -20, -21, -23, -27, -30, -35, -36, -41,
  102713. -46, -44, -42, -40, -41, -41, -43, -48,
  102714. -55, -53, -52, -53, -56, -59, -58, -60,
  102715. -67, -66, -69, -71, -72, -75, -79, -81,
  102716. -84, -87, -90, -93, -97, -101, -107, -114,
  102717. -999, -999, -999, -999, -999, -999, -999, -999},
  102718. { -9, -9, -9, -9, -9, -9, -9, -9,
  102719. -11, -12, -12, -15, -16, -20, -23, -30,
  102720. -37, -34, -33, -34, -31, -32, -32, -38,
  102721. -47, -44, -41, -40, -47, -49, -46, -46,
  102722. -58, -50, -50, -54, -58, -62, -64, -67,
  102723. -67, -70, -72, -76, -79, -83, -87, -91,
  102724. -96, -100, -104, -110, -999, -999, -999, -999}},
  102725. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102726. -62, -62, -63, -64, -66, -67, -66, -68,
  102727. -75, -72, -76, -75, -76, -78, -79, -82,
  102728. -84, -85, -90, -94, -101, -110, -999, -999,
  102729. -999, -999, -999, -999, -999, -999, -999, -999,
  102730. -999, -999, -999, -999, -999, -999, -999, -999,
  102731. -999, -999, -999, -999, -999, -999, -999, -999},
  102732. { -59, -59, -59, -59, -59, -59, -59, -59,
  102733. -59, -59, -59, -60, -60, -61, -63, -66,
  102734. -71, -68, -70, -70, -71, -72, -72, -75,
  102735. -81, -78, -79, -82, -83, -86, -90, -97,
  102736. -103, -113, -999, -999, -999, -999, -999, -999,
  102737. -999, -999, -999, -999, -999, -999, -999, -999,
  102738. -999, -999, -999, -999, -999, -999, -999, -999},
  102739. { -53, -53, -53, -53, -53, -53, -53, -53,
  102740. -53, -54, -55, -57, -56, -57, -55, -61,
  102741. -65, -60, -60, -62, -63, -63, -66, -68,
  102742. -74, -73, -75, -75, -78, -80, -80, -82,
  102743. -85, -90, -96, -101, -108, -999, -999, -999,
  102744. -999, -999, -999, -999, -999, -999, -999, -999,
  102745. -999, -999, -999, -999, -999, -999, -999, -999},
  102746. { -46, -46, -46, -46, -46, -46, -46, -46,
  102747. -46, -46, -47, -47, -47, -47, -48, -51,
  102748. -57, -51, -49, -50, -51, -53, -54, -59,
  102749. -66, -60, -62, -67, -67, -70, -72, -75,
  102750. -76, -78, -81, -85, -88, -94, -97, -104,
  102751. -112, -999, -999, -999, -999, -999, -999, -999,
  102752. -999, -999, -999, -999, -999, -999, -999, -999},
  102753. { -36, -36, -36, -36, -36, -36, -36, -36,
  102754. -39, -41, -42, -42, -39, -38, -41, -43,
  102755. -52, -44, -40, -39, -37, -37, -40, -47,
  102756. -54, -50, -48, -50, -55, -61, -59, -62,
  102757. -66, -66, -66, -69, -69, -73, -74, -74,
  102758. -75, -77, -79, -82, -87, -91, -95, -100,
  102759. -108, -115, -999, -999, -999, -999, -999, -999},
  102760. { -28, -26, -24, -22, -20, -20, -23, -29,
  102761. -30, -31, -28, -27, -28, -28, -28, -35,
  102762. -40, -33, -32, -29, -30, -30, -30, -37,
  102763. -45, -41, -37, -38, -45, -47, -47, -48,
  102764. -53, -49, -48, -50, -49, -49, -51, -52,
  102765. -58, -56, -57, -56, -60, -61, -62, -70,
  102766. -72, -74, -78, -83, -88, -93, -100, -106}},
  102767. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102768. -999, -110, -105, -100, -95, -91, -87, -83,
  102769. -80, -78, -76, -78, -78, -81, -83, -85,
  102770. -86, -85, -86, -87, -90, -97, -107, -999,
  102771. -999, -999, -999, -999, -999, -999, -999, -999,
  102772. -999, -999, -999, -999, -999, -999, -999, -999,
  102773. -999, -999, -999, -999, -999, -999, -999, -999},
  102774. {-999, -999, -999, -110, -105, -100, -95, -90,
  102775. -85, -81, -77, -73, -70, -67, -67, -68,
  102776. -75, -73, -70, -69, -70, -72, -75, -79,
  102777. -84, -83, -84, -86, -88, -89, -89, -93,
  102778. -98, -105, -112, -999, -999, -999, -999, -999,
  102779. -999, -999, -999, -999, -999, -999, -999, -999,
  102780. -999, -999, -999, -999, -999, -999, -999, -999},
  102781. {-105, -100, -95, -90, -85, -80, -76, -71,
  102782. -68, -68, -65, -63, -63, -62, -62, -64,
  102783. -65, -64, -61, -62, -63, -64, -66, -68,
  102784. -73, -73, -74, -75, -76, -81, -83, -85,
  102785. -88, -89, -92, -95, -100, -108, -999, -999,
  102786. -999, -999, -999, -999, -999, -999, -999, -999,
  102787. -999, -999, -999, -999, -999, -999, -999, -999},
  102788. { -80, -75, -71, -68, -65, -63, -62, -61,
  102789. -61, -61, -61, -59, -56, -57, -53, -50,
  102790. -58, -52, -50, -50, -52, -53, -54, -58,
  102791. -67, -63, -67, -68, -72, -75, -78, -80,
  102792. -81, -81, -82, -85, -89, -90, -93, -97,
  102793. -101, -107, -114, -999, -999, -999, -999, -999,
  102794. -999, -999, -999, -999, -999, -999, -999, -999},
  102795. { -65, -61, -59, -57, -56, -55, -55, -56,
  102796. -56, -57, -55, -53, -52, -47, -44, -44,
  102797. -50, -44, -41, -39, -39, -42, -40, -46,
  102798. -51, -49, -50, -53, -54, -63, -60, -61,
  102799. -62, -66, -66, -66, -70, -73, -74, -75,
  102800. -76, -75, -79, -85, -89, -91, -96, -102,
  102801. -110, -999, -999, -999, -999, -999, -999, -999},
  102802. { -52, -50, -49, -49, -48, -48, -48, -49,
  102803. -50, -50, -49, -46, -43, -39, -35, -33,
  102804. -38, -36, -32, -29, -32, -32, -32, -35,
  102805. -44, -39, -38, -38, -46, -50, -45, -46,
  102806. -53, -50, -50, -50, -54, -54, -53, -53,
  102807. -56, -57, -59, -66, -70, -72, -74, -79,
  102808. -83, -85, -90, -97, -114, -999, -999, -999}},
  102809. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102810. -100, -95, -90, -86, -80, -75, -75, -79,
  102811. -80, -79, -80, -81, -82, -88, -95, -103,
  102812. -110, -999, -999, -999, -999, -999, -999, -999,
  102813. -999, -999, -999, -999, -999, -999, -999, -999,
  102814. -999, -999, -999, -999, -999, -999, -999, -999,
  102815. -999, -999, -999, -999, -999, -999, -999, -999},
  102816. {-999, -999, -999, -999, -108, -103, -98, -93,
  102817. -88, -83, -79, -78, -75, -71, -67, -68,
  102818. -73, -73, -72, -73, -75, -77, -80, -82,
  102819. -88, -93, -100, -107, -114, -999, -999, -999,
  102820. -999, -999, -999, -999, -999, -999, -999, -999,
  102821. -999, -999, -999, -999, -999, -999, -999, -999,
  102822. -999, -999, -999, -999, -999, -999, -999, -999},
  102823. {-999, -999, -999, -110, -105, -101, -96, -90,
  102824. -86, -81, -77, -73, -69, -66, -61, -62,
  102825. -66, -64, -62, -65, -66, -70, -72, -76,
  102826. -81, -80, -84, -90, -95, -102, -110, -999,
  102827. -999, -999, -999, -999, -999, -999, -999, -999,
  102828. -999, -999, -999, -999, -999, -999, -999, -999,
  102829. -999, -999, -999, -999, -999, -999, -999, -999},
  102830. {-999, -999, -999, -107, -103, -97, -92, -88,
  102831. -83, -79, -74, -70, -66, -59, -53, -58,
  102832. -62, -55, -54, -54, -54, -58, -61, -62,
  102833. -72, -70, -72, -75, -78, -80, -81, -80,
  102834. -83, -83, -88, -93, -100, -107, -115, -999,
  102835. -999, -999, -999, -999, -999, -999, -999, -999,
  102836. -999, -999, -999, -999, -999, -999, -999, -999},
  102837. {-999, -999, -999, -105, -100, -95, -90, -85,
  102838. -80, -75, -70, -66, -62, -56, -48, -44,
  102839. -48, -46, -46, -43, -46, -48, -48, -51,
  102840. -58, -58, -59, -60, -62, -62, -61, -61,
  102841. -65, -64, -65, -68, -70, -74, -75, -78,
  102842. -81, -86, -95, -110, -999, -999, -999, -999,
  102843. -999, -999, -999, -999, -999, -999, -999, -999},
  102844. {-999, -999, -105, -100, -95, -90, -85, -80,
  102845. -75, -70, -65, -61, -55, -49, -39, -33,
  102846. -40, -35, -32, -38, -40, -33, -35, -37,
  102847. -46, -41, -45, -44, -46, -42, -45, -46,
  102848. -52, -50, -50, -50, -54, -54, -55, -57,
  102849. -62, -64, -66, -68, -70, -76, -81, -90,
  102850. -100, -110, -999, -999, -999, -999, -999, -999}},
  102851. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102852. -105, -98, -90, -85, -82, -83, -80, -78,
  102853. -84, -79, -80, -83, -87, -89, -91, -93,
  102854. -99, -106, -117, -999, -999, -999, -999, -999,
  102855. -999, -999, -999, -999, -999, -999, -999, -999,
  102856. -999, -999, -999, -999, -999, -999, -999, -999,
  102857. -999, -999, -999, -999, -999, -999, -999, -999},
  102858. {-999, -999, -999, -999, -999, -999, -999, -999,
  102859. -105, -98, -90, -85, -80, -75, -70, -68,
  102860. -74, -72, -74, -77, -80, -82, -85, -87,
  102861. -92, -89, -91, -95, -100, -106, -112, -999,
  102862. -999, -999, -999, -999, -999, -999, -999, -999,
  102863. -999, -999, -999, -999, -999, -999, -999, -999,
  102864. -999, -999, -999, -999, -999, -999, -999, -999},
  102865. {-999, -999, -999, -999, -999, -999, -999, -999,
  102866. -105, -98, -90, -83, -75, -71, -63, -64,
  102867. -67, -62, -64, -67, -70, -73, -77, -81,
  102868. -84, -83, -85, -89, -90, -93, -98, -104,
  102869. -109, -114, -999, -999, -999, -999, -999, -999,
  102870. -999, -999, -999, -999, -999, -999, -999, -999,
  102871. -999, -999, -999, -999, -999, -999, -999, -999},
  102872. {-999, -999, -999, -999, -999, -999, -999, -999,
  102873. -103, -96, -88, -81, -75, -68, -58, -54,
  102874. -56, -54, -56, -56, -58, -60, -63, -66,
  102875. -74, -69, -72, -72, -75, -74, -77, -81,
  102876. -81, -82, -84, -87, -93, -96, -99, -104,
  102877. -110, -999, -999, -999, -999, -999, -999, -999,
  102878. -999, -999, -999, -999, -999, -999, -999, -999},
  102879. {-999, -999, -999, -999, -999, -108, -102, -96,
  102880. -91, -85, -80, -74, -68, -60, -51, -46,
  102881. -48, -46, -43, -45, -47, -47, -49, -48,
  102882. -56, -53, -55, -58, -57, -63, -58, -60,
  102883. -66, -64, -67, -70, -70, -74, -77, -84,
  102884. -86, -89, -91, -93, -94, -101, -109, -118,
  102885. -999, -999, -999, -999, -999, -999, -999, -999},
  102886. {-999, -999, -999, -108, -103, -98, -93, -88,
  102887. -83, -78, -73, -68, -60, -53, -44, -35,
  102888. -38, -38, -34, -34, -36, -40, -41, -44,
  102889. -51, -45, -46, -47, -46, -54, -50, -49,
  102890. -50, -50, -50, -51, -54, -57, -58, -60,
  102891. -66, -66, -66, -64, -65, -68, -77, -82,
  102892. -87, -95, -110, -999, -999, -999, -999, -999}},
  102893. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102894. -107, -102, -97, -92, -87, -83, -78, -75,
  102895. -82, -79, -83, -85, -89, -92, -95, -98,
  102896. -101, -105, -109, -113, -999, -999, -999, -999,
  102897. -999, -999, -999, -999, -999, -999, -999, -999,
  102898. -999, -999, -999, -999, -999, -999, -999, -999,
  102899. -999, -999, -999, -999, -999, -999, -999, -999},
  102900. {-999, -999, -999, -999, -999, -999, -999, -106,
  102901. -100, -95, -90, -86, -81, -78, -74, -69,
  102902. -74, -74, -76, -79, -83, -84, -86, -89,
  102903. -92, -97, -93, -100, -103, -107, -110, -999,
  102904. -999, -999, -999, -999, -999, -999, -999, -999,
  102905. -999, -999, -999, -999, -999, -999, -999, -999,
  102906. -999, -999, -999, -999, -999, -999, -999, -999},
  102907. {-999, -999, -999, -999, -999, -999, -106, -100,
  102908. -95, -90, -87, -83, -80, -75, -69, -60,
  102909. -66, -66, -68, -70, -74, -78, -79, -81,
  102910. -81, -83, -84, -87, -93, -96, -99, -103,
  102911. -107, -110, -999, -999, -999, -999, -999, -999,
  102912. -999, -999, -999, -999, -999, -999, -999, -999,
  102913. -999, -999, -999, -999, -999, -999, -999, -999},
  102914. {-999, -999, -999, -999, -999, -108, -103, -98,
  102915. -93, -89, -85, -82, -78, -71, -62, -55,
  102916. -58, -58, -54, -54, -55, -59, -61, -62,
  102917. -70, -66, -66, -67, -70, -72, -75, -78,
  102918. -84, -84, -84, -88, -91, -90, -95, -98,
  102919. -102, -103, -106, -110, -999, -999, -999, -999,
  102920. -999, -999, -999, -999, -999, -999, -999, -999},
  102921. {-999, -999, -999, -999, -108, -103, -98, -94,
  102922. -90, -87, -82, -79, -73, -67, -58, -47,
  102923. -50, -45, -41, -45, -48, -44, -44, -49,
  102924. -54, -51, -48, -47, -49, -50, -51, -57,
  102925. -58, -60, -63, -69, -70, -69, -71, -74,
  102926. -78, -82, -90, -95, -101, -105, -110, -999,
  102927. -999, -999, -999, -999, -999, -999, -999, -999},
  102928. {-999, -999, -999, -105, -101, -97, -93, -90,
  102929. -85, -80, -77, -72, -65, -56, -48, -37,
  102930. -40, -36, -34, -40, -50, -47, -38, -41,
  102931. -47, -38, -35, -39, -38, -43, -40, -45,
  102932. -50, -45, -44, -47, -50, -55, -48, -48,
  102933. -52, -66, -70, -76, -82, -90, -97, -105,
  102934. -110, -999, -999, -999, -999, -999, -999, -999}},
  102935. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102936. -999, -108, -103, -98, -93, -86, -79, -76,
  102937. -83, -81, -85, -87, -89, -93, -98, -102,
  102938. -107, -112, -999, -999, -999, -999, -999, -999,
  102939. -999, -999, -999, -999, -999, -999, -999, -999,
  102940. -999, -999, -999, -999, -999, -999, -999, -999,
  102941. -999, -999, -999, -999, -999, -999, -999, -999},
  102942. {-999, -999, -999, -999, -999, -999, -999, -999,
  102943. -999, -108, -103, -98, -93, -86, -79, -71,
  102944. -77, -74, -77, -79, -81, -84, -85, -90,
  102945. -92, -93, -92, -98, -101, -108, -112, -999,
  102946. -999, -999, -999, -999, -999, -999, -999, -999,
  102947. -999, -999, -999, -999, -999, -999, -999, -999,
  102948. -999, -999, -999, -999, -999, -999, -999, -999},
  102949. {-999, -999, -999, -999, -999, -999, -999, -999,
  102950. -108, -103, -98, -93, -87, -78, -68, -65,
  102951. -66, -62, -65, -67, -70, -73, -75, -78,
  102952. -82, -82, -83, -84, -91, -93, -98, -102,
  102953. -106, -110, -999, -999, -999, -999, -999, -999,
  102954. -999, -999, -999, -999, -999, -999, -999, -999,
  102955. -999, -999, -999, -999, -999, -999, -999, -999},
  102956. {-999, -999, -999, -999, -999, -999, -999, -999,
  102957. -105, -100, -95, -90, -82, -74, -62, -57,
  102958. -58, -56, -51, -52, -52, -54, -54, -58,
  102959. -66, -59, -60, -63, -66, -69, -73, -79,
  102960. -83, -84, -80, -81, -81, -82, -88, -92,
  102961. -98, -105, -113, -999, -999, -999, -999, -999,
  102962. -999, -999, -999, -999, -999, -999, -999, -999},
  102963. {-999, -999, -999, -999, -999, -999, -999, -107,
  102964. -102, -97, -92, -84, -79, -69, -57, -47,
  102965. -52, -47, -44, -45, -50, -52, -42, -42,
  102966. -53, -43, -43, -48, -51, -56, -55, -52,
  102967. -57, -59, -61, -62, -67, -71, -78, -83,
  102968. -86, -94, -98, -103, -110, -999, -999, -999,
  102969. -999, -999, -999, -999, -999, -999, -999, -999},
  102970. {-999, -999, -999, -999, -999, -999, -105, -100,
  102971. -95, -90, -84, -78, -70, -61, -51, -41,
  102972. -40, -38, -40, -46, -52, -51, -41, -40,
  102973. -46, -40, -38, -38, -41, -46, -41, -46,
  102974. -47, -43, -43, -45, -41, -45, -56, -67,
  102975. -68, -83, -87, -90, -95, -102, -107, -113,
  102976. -999, -999, -999, -999, -999, -999, -999, -999}},
  102977. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102978. -999, -109, -105, -101, -96, -91, -84, -77,
  102979. -82, -82, -85, -89, -94, -100, -106, -110,
  102980. -999, -999, -999, -999, -999, -999, -999, -999,
  102981. -999, -999, -999, -999, -999, -999, -999, -999,
  102982. -999, -999, -999, -999, -999, -999, -999, -999,
  102983. -999, -999, -999, -999, -999, -999, -999, -999},
  102984. {-999, -999, -999, -999, -999, -999, -999, -999,
  102985. -999, -106, -103, -98, -92, -85, -80, -71,
  102986. -75, -72, -76, -80, -84, -86, -89, -93,
  102987. -100, -107, -113, -999, -999, -999, -999, -999,
  102988. -999, -999, -999, -999, -999, -999, -999, -999,
  102989. -999, -999, -999, -999, -999, -999, -999, -999,
  102990. -999, -999, -999, -999, -999, -999, -999, -999},
  102991. {-999, -999, -999, -999, -999, -999, -999, -107,
  102992. -104, -101, -97, -92, -88, -84, -80, -64,
  102993. -66, -63, -64, -66, -69, -73, -77, -83,
  102994. -83, -86, -91, -98, -104, -111, -999, -999,
  102995. -999, -999, -999, -999, -999, -999, -999, -999,
  102996. -999, -999, -999, -999, -999, -999, -999, -999,
  102997. -999, -999, -999, -999, -999, -999, -999, -999},
  102998. {-999, -999, -999, -999, -999, -999, -999, -107,
  102999. -104, -101, -97, -92, -90, -84, -74, -57,
  103000. -58, -52, -55, -54, -50, -52, -50, -52,
  103001. -63, -62, -69, -76, -77, -78, -78, -79,
  103002. -82, -88, -94, -100, -106, -111, -999, -999,
  103003. -999, -999, -999, -999, -999, -999, -999, -999,
  103004. -999, -999, -999, -999, -999, -999, -999, -999},
  103005. {-999, -999, -999, -999, -999, -999, -106, -102,
  103006. -98, -95, -90, -85, -83, -78, -70, -50,
  103007. -50, -41, -44, -49, -47, -50, -50, -44,
  103008. -55, -46, -47, -48, -48, -54, -49, -49,
  103009. -58, -62, -71, -81, -87, -92, -97, -102,
  103010. -108, -114, -999, -999, -999, -999, -999, -999,
  103011. -999, -999, -999, -999, -999, -999, -999, -999},
  103012. {-999, -999, -999, -999, -999, -999, -106, -102,
  103013. -98, -95, -90, -85, -83, -78, -70, -45,
  103014. -43, -41, -47, -50, -51, -50, -49, -45,
  103015. -47, -41, -44, -41, -39, -43, -38, -37,
  103016. -40, -41, -44, -50, -58, -65, -73, -79,
  103017. -85, -92, -97, -101, -105, -109, -113, -999,
  103018. -999, -999, -999, -999, -999, -999, -999, -999}},
  103019. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103020. -999, -999, -999, -107, -100, -95, -87, -81,
  103021. -85, -83, -88, -93, -100, -107, -114, -999,
  103022. -999, -999, -999, -999, -999, -999, -999, -999,
  103023. -999, -999, -999, -999, -999, -999, -999, -999,
  103024. -999, -999, -999, -999, -999, -999, -999, -999,
  103025. -999, -999, -999, -999, -999, -999, -999, -999},
  103026. {-999, -999, -999, -999, -999, -999, -999, -999,
  103027. -999, -999, -107, -101, -95, -88, -83, -76,
  103028. -73, -72, -79, -84, -90, -95, -100, -105,
  103029. -110, -115, -999, -999, -999, -999, -999, -999,
  103030. -999, -999, -999, -999, -999, -999, -999, -999,
  103031. -999, -999, -999, -999, -999, -999, -999, -999,
  103032. -999, -999, -999, -999, -999, -999, -999, -999},
  103033. {-999, -999, -999, -999, -999, -999, -999, -999,
  103034. -999, -999, -104, -98, -92, -87, -81, -70,
  103035. -65, -62, -67, -71, -74, -80, -85, -91,
  103036. -95, -99, -103, -108, -111, -114, -999, -999,
  103037. -999, -999, -999, -999, -999, -999, -999, -999,
  103038. -999, -999, -999, -999, -999, -999, -999, -999,
  103039. -999, -999, -999, -999, -999, -999, -999, -999},
  103040. {-999, -999, -999, -999, -999, -999, -999, -999,
  103041. -999, -999, -103, -97, -90, -85, -76, -60,
  103042. -56, -54, -60, -62, -61, -56, -63, -65,
  103043. -73, -74, -77, -75, -78, -81, -86, -87,
  103044. -88, -91, -94, -98, -103, -110, -999, -999,
  103045. -999, -999, -999, -999, -999, -999, -999, -999,
  103046. -999, -999, -999, -999, -999, -999, -999, -999},
  103047. {-999, -999, -999, -999, -999, -999, -999, -105,
  103048. -100, -97, -92, -86, -81, -79, -70, -57,
  103049. -51, -47, -51, -58, -60, -56, -53, -50,
  103050. -58, -52, -50, -50, -53, -55, -64, -69,
  103051. -71, -85, -82, -78, -81, -85, -95, -102,
  103052. -112, -999, -999, -999, -999, -999, -999, -999,
  103053. -999, -999, -999, -999, -999, -999, -999, -999},
  103054. {-999, -999, -999, -999, -999, -999, -999, -105,
  103055. -100, -97, -92, -85, -83, -79, -72, -49,
  103056. -40, -43, -43, -54, -56, -51, -50, -40,
  103057. -43, -38, -36, -35, -37, -38, -37, -44,
  103058. -54, -60, -57, -60, -70, -75, -84, -92,
  103059. -103, -112, -999, -999, -999, -999, -999, -999,
  103060. -999, -999, -999, -999, -999, -999, -999, -999}},
  103061. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103062. -999, -999, -999, -110, -102, -95, -89, -82,
  103063. -83, -84, -90, -92, -99, -107, -113, -999,
  103064. -999, -999, -999, -999, -999, -999, -999, -999,
  103065. -999, -999, -999, -999, -999, -999, -999, -999,
  103066. -999, -999, -999, -999, -999, -999, -999, -999,
  103067. -999, -999, -999, -999, -999, -999, -999, -999},
  103068. {-999, -999, -999, -999, -999, -999, -999, -999,
  103069. -999, -999, -107, -101, -95, -89, -83, -72,
  103070. -74, -78, -85, -88, -88, -90, -92, -98,
  103071. -105, -111, -999, -999, -999, -999, -999, -999,
  103072. -999, -999, -999, -999, -999, -999, -999, -999,
  103073. -999, -999, -999, -999, -999, -999, -999, -999,
  103074. -999, -999, -999, -999, -999, -999, -999, -999},
  103075. {-999, -999, -999, -999, -999, -999, -999, -999,
  103076. -999, -109, -103, -97, -93, -87, -81, -70,
  103077. -70, -67, -75, -73, -76, -79, -81, -83,
  103078. -88, -89, -97, -103, -110, -999, -999, -999,
  103079. -999, -999, -999, -999, -999, -999, -999, -999,
  103080. -999, -999, -999, -999, -999, -999, -999, -999,
  103081. -999, -999, -999, -999, -999, -999, -999, -999},
  103082. {-999, -999, -999, -999, -999, -999, -999, -999,
  103083. -999, -107, -100, -94, -88, -83, -75, -63,
  103084. -59, -59, -63, -66, -60, -62, -67, -67,
  103085. -77, -76, -81, -88, -86, -92, -96, -102,
  103086. -109, -116, -999, -999, -999, -999, -999, -999,
  103087. -999, -999, -999, -999, -999, -999, -999, -999,
  103088. -999, -999, -999, -999, -999, -999, -999, -999},
  103089. {-999, -999, -999, -999, -999, -999, -999, -999,
  103090. -999, -105, -98, -92, -86, -81, -73, -56,
  103091. -52, -47, -55, -60, -58, -52, -51, -45,
  103092. -49, -50, -53, -54, -61, -71, -70, -69,
  103093. -78, -79, -87, -90, -96, -104, -112, -999,
  103094. -999, -999, -999, -999, -999, -999, -999, -999,
  103095. -999, -999, -999, -999, -999, -999, -999, -999},
  103096. {-999, -999, -999, -999, -999, -999, -999, -999,
  103097. -999, -103, -96, -90, -86, -78, -70, -51,
  103098. -42, -47, -48, -55, -54, -54, -53, -42,
  103099. -35, -28, -33, -38, -37, -44, -47, -49,
  103100. -54, -63, -68, -78, -82, -89, -94, -99,
  103101. -104, -109, -114, -999, -999, -999, -999, -999,
  103102. -999, -999, -999, -999, -999, -999, -999, -999}},
  103103. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103104. -999, -999, -999, -999, -110, -100, -90, -79,
  103105. -85, -81, -82, -82, -89, -94, -99, -103,
  103106. -109, -115, -999, -999, -999, -999, -999, -999,
  103107. -999, -999, -999, -999, -999, -999, -999, -999,
  103108. -999, -999, -999, -999, -999, -999, -999, -999,
  103109. -999, -999, -999, -999, -999, -999, -999, -999},
  103110. {-999, -999, -999, -999, -999, -999, -999, -999,
  103111. -999, -999, -999, -999, -105, -97, -85, -72,
  103112. -74, -70, -70, -70, -76, -85, -91, -93,
  103113. -97, -103, -109, -115, -999, -999, -999, -999,
  103114. -999, -999, -999, -999, -999, -999, -999, -999,
  103115. -999, -999, -999, -999, -999, -999, -999, -999,
  103116. -999, -999, -999, -999, -999, -999, -999, -999},
  103117. {-999, -999, -999, -999, -999, -999, -999, -999,
  103118. -999, -999, -999, -999, -112, -93, -81, -68,
  103119. -62, -60, -60, -57, -63, -70, -77, -82,
  103120. -90, -93, -98, -104, -109, -113, -999, -999,
  103121. -999, -999, -999, -999, -999, -999, -999, -999,
  103122. -999, -999, -999, -999, -999, -999, -999, -999,
  103123. -999, -999, -999, -999, -999, -999, -999, -999},
  103124. {-999, -999, -999, -999, -999, -999, -999, -999,
  103125. -999, -999, -999, -113, -100, -93, -84, -63,
  103126. -58, -48, -53, -54, -52, -52, -57, -64,
  103127. -66, -76, -83, -81, -85, -85, -90, -95,
  103128. -98, -101, -103, -106, -108, -111, -999, -999,
  103129. -999, -999, -999, -999, -999, -999, -999, -999,
  103130. -999, -999, -999, -999, -999, -999, -999, -999},
  103131. {-999, -999, -999, -999, -999, -999, -999, -999,
  103132. -999, -999, -999, -105, -95, -86, -74, -53,
  103133. -50, -38, -43, -49, -43, -42, -39, -39,
  103134. -46, -52, -57, -56, -72, -69, -74, -81,
  103135. -87, -92, -94, -97, -99, -102, -105, -108,
  103136. -999, -999, -999, -999, -999, -999, -999, -999,
  103137. -999, -999, -999, -999, -999, -999, -999, -999},
  103138. {-999, -999, -999, -999, -999, -999, -999, -999,
  103139. -999, -999, -108, -99, -90, -76, -66, -45,
  103140. -43, -41, -44, -47, -43, -47, -40, -30,
  103141. -31, -31, -39, -33, -40, -41, -43, -53,
  103142. -59, -70, -73, -77, -79, -82, -84, -87,
  103143. -999, -999, -999, -999, -999, -999, -999, -999,
  103144. -999, -999, -999, -999, -999, -999, -999, -999}},
  103145. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103146. -999, -999, -999, -999, -999, -110, -91, -76,
  103147. -75, -85, -93, -98, -104, -110, -999, -999,
  103148. -999, -999, -999, -999, -999, -999, -999, -999,
  103149. -999, -999, -999, -999, -999, -999, -999, -999,
  103150. -999, -999, -999, -999, -999, -999, -999, -999,
  103151. -999, -999, -999, -999, -999, -999, -999, -999},
  103152. {-999, -999, -999, -999, -999, -999, -999, -999,
  103153. -999, -999, -999, -999, -999, -110, -91, -70,
  103154. -70, -75, -86, -89, -94, -98, -101, -106,
  103155. -110, -999, -999, -999, -999, -999, -999, -999,
  103156. -999, -999, -999, -999, -999, -999, -999, -999,
  103157. -999, -999, -999, -999, -999, -999, -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, -110, -95, -80, -60,
  103161. -65, -64, -74, -83, -88, -91, -95, -99,
  103162. -103, -107, -110, -999, -999, -999, -999, -999,
  103163. -999, -999, -999, -999, -999, -999, -999, -999,
  103164. -999, -999, -999, -999, -999, -999, -999, -999,
  103165. -999, -999, -999, -999, -999, -999, -999, -999},
  103166. {-999, -999, -999, -999, -999, -999, -999, -999,
  103167. -999, -999, -999, -999, -110, -95, -80, -58,
  103168. -55, -49, -66, -68, -71, -78, -78, -80,
  103169. -88, -85, -89, -97, -100, -105, -110, -999,
  103170. -999, -999, -999, -999, -999, -999, -999, -999,
  103171. -999, -999, -999, -999, -999, -999, -999, -999,
  103172. -999, -999, -999, -999, -999, -999, -999, -999},
  103173. {-999, -999, -999, -999, -999, -999, -999, -999,
  103174. -999, -999, -999, -999, -110, -95, -80, -53,
  103175. -52, -41, -59, -59, -49, -58, -56, -63,
  103176. -86, -79, -90, -93, -98, -103, -107, -112,
  103177. -999, -999, -999, -999, -999, -999, -999, -999,
  103178. -999, -999, -999, -999, -999, -999, -999, -999,
  103179. -999, -999, -999, -999, -999, -999, -999, -999},
  103180. {-999, -999, -999, -999, -999, -999, -999, -999,
  103181. -999, -999, -999, -110, -97, -91, -73, -45,
  103182. -40, -33, -53, -61, -49, -54, -50, -50,
  103183. -60, -52, -67, -74, -81, -92, -96, -100,
  103184. -105, -110, -999, -999, -999, -999, -999, -999,
  103185. -999, -999, -999, -999, -999, -999, -999, -999,
  103186. -999, -999, -999, -999, -999, -999, -999, -999}},
  103187. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103188. -999, -999, -999, -113, -106, -99, -92, -77,
  103189. -80, -88, -97, -106, -115, -999, -999, -999,
  103190. -999, -999, -999, -999, -999, -999, -999, -999,
  103191. -999, -999, -999, -999, -999, -999, -999, -999,
  103192. -999, -999, -999, -999, -999, -999, -999, -999,
  103193. -999, -999, -999, -999, -999, -999, -999, -999},
  103194. {-999, -999, -999, -999, -999, -999, -999, -999,
  103195. -999, -999, -116, -109, -102, -95, -89, -74,
  103196. -72, -88, -87, -95, -102, -109, -116, -999,
  103197. -999, -999, -999, -999, -999, -999, -999, -999,
  103198. -999, -999, -999, -999, -999, -999, -999, -999,
  103199. -999, -999, -999, -999, -999, -999, -999, -999,
  103200. -999, -999, -999, -999, -999, -999, -999, -999},
  103201. {-999, -999, -999, -999, -999, -999, -999, -999,
  103202. -999, -999, -116, -109, -102, -95, -89, -75,
  103203. -66, -74, -77, -78, -86, -87, -90, -96,
  103204. -105, -115, -999, -999, -999, -999, -999, -999,
  103205. -999, -999, -999, -999, -999, -999, -999, -999,
  103206. -999, -999, -999, -999, -999, -999, -999, -999,
  103207. -999, -999, -999, -999, -999, -999, -999, -999},
  103208. {-999, -999, -999, -999, -999, -999, -999, -999,
  103209. -999, -999, -115, -108, -101, -94, -88, -66,
  103210. -56, -61, -70, -65, -78, -72, -83, -84,
  103211. -93, -98, -105, -110, -999, -999, -999, -999,
  103212. -999, -999, -999, -999, -999, -999, -999, -999,
  103213. -999, -999, -999, -999, -999, -999, -999, -999,
  103214. -999, -999, -999, -999, -999, -999, -999, -999},
  103215. {-999, -999, -999, -999, -999, -999, -999, -999,
  103216. -999, -999, -110, -105, -95, -89, -82, -57,
  103217. -52, -52, -59, -56, -59, -58, -69, -67,
  103218. -88, -82, -82, -89, -94, -100, -108, -999,
  103219. -999, -999, -999, -999, -999, -999, -999, -999,
  103220. -999, -999, -999, -999, -999, -999, -999, -999,
  103221. -999, -999, -999, -999, -999, -999, -999, -999},
  103222. {-999, -999, -999, -999, -999, -999, -999, -999,
  103223. -999, -110, -101, -96, -90, -83, -77, -54,
  103224. -43, -38, -50, -48, -52, -48, -42, -42,
  103225. -51, -52, -53, -59, -65, -71, -78, -85,
  103226. -95, -999, -999, -999, -999, -999, -999, -999,
  103227. -999, -999, -999, -999, -999, -999, -999, -999,
  103228. -999, -999, -999, -999, -999, -999, -999, -999}},
  103229. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103230. -999, -999, -999, -999, -120, -105, -86, -68,
  103231. -78, -79, -90, -100, -110, -999, -999, -999,
  103232. -999, -999, -999, -999, -999, -999, -999, -999,
  103233. -999, -999, -999, -999, -999, -999, -999, -999,
  103234. -999, -999, -999, -999, -999, -999, -999, -999,
  103235. -999, -999, -999, -999, -999, -999, -999, -999},
  103236. {-999, -999, -999, -999, -999, -999, -999, -999,
  103237. -999, -999, -999, -999, -120, -105, -86, -66,
  103238. -73, -77, -88, -96, -105, -115, -999, -999,
  103239. -999, -999, -999, -999, -999, -999, -999, -999,
  103240. -999, -999, -999, -999, -999, -999, -999, -999,
  103241. -999, -999, -999, -999, -999, -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, -120, -105, -92, -80, -61,
  103245. -64, -68, -80, -87, -92, -100, -110, -999,
  103246. -999, -999, -999, -999, -999, -999, -999, -999,
  103247. -999, -999, -999, -999, -999, -999, -999, -999,
  103248. -999, -999, -999, -999, -999, -999, -999, -999,
  103249. -999, -999, -999, -999, -999, -999, -999, -999},
  103250. {-999, -999, -999, -999, -999, -999, -999, -999,
  103251. -999, -999, -999, -120, -104, -91, -79, -52,
  103252. -60, -54, -64, -69, -77, -80, -82, -84,
  103253. -85, -87, -88, -90, -999, -999, -999, -999,
  103254. -999, -999, -999, -999, -999, -999, -999, -999,
  103255. -999, -999, -999, -999, -999, -999, -999, -999,
  103256. -999, -999, -999, -999, -999, -999, -999, -999},
  103257. {-999, -999, -999, -999, -999, -999, -999, -999,
  103258. -999, -999, -999, -118, -100, -87, -77, -49,
  103259. -50, -44, -58, -61, -61, -67, -65, -62,
  103260. -62, -62, -65, -68, -999, -999, -999, -999,
  103261. -999, -999, -999, -999, -999, -999, -999, -999,
  103262. -999, -999, -999, -999, -999, -999, -999, -999,
  103263. -999, -999, -999, -999, -999, -999, -999, -999},
  103264. {-999, -999, -999, -999, -999, -999, -999, -999,
  103265. -999, -999, -999, -115, -98, -84, -62, -49,
  103266. -44, -38, -46, -49, -49, -46, -39, -37,
  103267. -39, -40, -42, -43, -999, -999, -999, -999,
  103268. -999, -999, -999, -999, -999, -999, -999, -999,
  103269. -999, -999, -999, -999, -999, -999, -999, -999,
  103270. -999, -999, -999, -999, -999, -999, -999, -999}},
  103271. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103272. -999, -999, -999, -999, -999, -110, -88, -74,
  103273. -77, -82, -82, -85, -90, -94, -99, -104,
  103274. -999, -999, -999, -999, -999, -999, -999, -999,
  103275. -999, -999, -999, -999, -999, -999, -999, -999,
  103276. -999, -999, -999, -999, -999, -999, -999, -999,
  103277. -999, -999, -999, -999, -999, -999, -999, -999},
  103278. {-999, -999, -999, -999, -999, -999, -999, -999,
  103279. -999, -999, -999, -999, -999, -110, -88, -66,
  103280. -70, -81, -80, -81, -84, -88, -91, -93,
  103281. -999, -999, -999, -999, -999, -999, -999, -999,
  103282. -999, -999, -999, -999, -999, -999, -999, -999,
  103283. -999, -999, -999, -999, -999, -999, -999, -999,
  103284. -999, -999, -999, -999, -999, -999, -999, -999},
  103285. {-999, -999, -999, -999, -999, -999, -999, -999,
  103286. -999, -999, -999, -999, -999, -110, -88, -61,
  103287. -63, -70, -71, -74, -77, -80, -83, -85,
  103288. -999, -999, -999, -999, -999, -999, -999, -999,
  103289. -999, -999, -999, -999, -999, -999, -999, -999,
  103290. -999, -999, -999, -999, -999, -999, -999, -999,
  103291. -999, -999, -999, -999, -999, -999, -999, -999},
  103292. {-999, -999, -999, -999, -999, -999, -999, -999,
  103293. -999, -999, -999, -999, -999, -110, -86, -62,
  103294. -63, -62, -62, -58, -52, -50, -50, -52,
  103295. -54, -999, -999, -999, -999, -999, -999, -999,
  103296. -999, -999, -999, -999, -999, -999, -999, -999,
  103297. -999, -999, -999, -999, -999, -999, -999, -999,
  103298. -999, -999, -999, -999, -999, -999, -999, -999},
  103299. {-999, -999, -999, -999, -999, -999, -999, -999,
  103300. -999, -999, -999, -999, -118, -108, -84, -53,
  103301. -50, -50, -50, -55, -47, -45, -40, -40,
  103302. -40, -999, -999, -999, -999, -999, -999, -999,
  103303. -999, -999, -999, -999, -999, -999, -999, -999,
  103304. -999, -999, -999, -999, -999, -999, -999, -999,
  103305. -999, -999, -999, -999, -999, -999, -999, -999},
  103306. {-999, -999, -999, -999, -999, -999, -999, -999,
  103307. -999, -999, -999, -999, -118, -100, -73, -43,
  103308. -37, -42, -43, -53, -38, -37, -35, -35,
  103309. -38, -999, -999, -999, -999, -999, -999, -999,
  103310. -999, -999, -999, -999, -999, -999, -999, -999,
  103311. -999, -999, -999, -999, -999, -999, -999, -999,
  103312. -999, -999, -999, -999, -999, -999, -999, -999}},
  103313. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103314. -999, -999, -999, -110, -100, -91, -84, -74,
  103315. -80, -80, -80, -80, -80, -999, -999, -999,
  103316. -999, -999, -999, -999, -999, -999, -999, -999,
  103317. -999, -999, -999, -999, -999, -999, -999, -999,
  103318. -999, -999, -999, -999, -999, -999, -999, -999,
  103319. -999, -999, -999, -999, -999, -999, -999, -999},
  103320. {-999, -999, -999, -999, -999, -999, -999, -999,
  103321. -999, -999, -999, -110, -100, -91, -84, -74,
  103322. -68, -68, -68, -68, -68, -999, -999, -999,
  103323. -999, -999, -999, -999, -999, -999, -999, -999,
  103324. -999, -999, -999, -999, -999, -999, -999, -999,
  103325. -999, -999, -999, -999, -999, -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, -110, -100, -86, -78, -70,
  103329. -60, -45, -30, -21, -999, -999, -999, -999,
  103330. -999, -999, -999, -999, -999, -999, -999, -999,
  103331. -999, -999, -999, -999, -999, -999, -999, -999,
  103332. -999, -999, -999, -999, -999, -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, -110, -100, -87, -78, -67,
  103336. -48, -38, -29, -21, -999, -999, -999, -999,
  103337. -999, -999, -999, -999, -999, -999, -999, -999,
  103338. -999, -999, -999, -999, -999, -999, -999, -999,
  103339. -999, -999, -999, -999, -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, -110, -100, -86, -69, -56,
  103343. -45, -35, -33, -29, -999, -999, -999, -999,
  103344. -999, -999, -999, -999, -999, -999, -999, -999,
  103345. -999, -999, -999, -999, -999, -999, -999, -999,
  103346. -999, -999, -999, -999, -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, -110, -100, -83, -71, -48,
  103350. -27, -38, -37, -34, -999, -999, -999, -999,
  103351. -999, -999, -999, -999, -999, -999, -999, -999,
  103352. -999, -999, -999, -999, -999, -999, -999, -999,
  103353. -999, -999, -999, -999, -999, -999, -999, -999,
  103354. -999, -999, -999, -999, -999, -999, -999, -999}}
  103355. };
  103356. #endif
  103357. /*** End of inlined file: masking.h ***/
  103358. #define NEGINF -9999.f
  103359. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103360. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103361. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103362. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103363. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103364. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103365. look->channels=vi->channels;
  103366. look->ampmax=-9999.;
  103367. look->gi=gi;
  103368. return(look);
  103369. }
  103370. void _vp_global_free(vorbis_look_psy_global *look){
  103371. if(look){
  103372. memset(look,0,sizeof(*look));
  103373. _ogg_free(look);
  103374. }
  103375. }
  103376. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103377. if(i){
  103378. memset(i,0,sizeof(*i));
  103379. _ogg_free(i);
  103380. }
  103381. }
  103382. void _vi_psy_free(vorbis_info_psy *i){
  103383. if(i){
  103384. memset(i,0,sizeof(*i));
  103385. _ogg_free(i);
  103386. }
  103387. }
  103388. static void min_curve(float *c,
  103389. float *c2){
  103390. int i;
  103391. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103392. }
  103393. static void max_curve(float *c,
  103394. float *c2){
  103395. int i;
  103396. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103397. }
  103398. static void attenuate_curve(float *c,float att){
  103399. int i;
  103400. for(i=0;i<EHMER_MAX;i++)
  103401. c[i]+=att;
  103402. }
  103403. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103404. float center_boost, float center_decay_rate){
  103405. int i,j,k,m;
  103406. float ath[EHMER_MAX];
  103407. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103408. float athc[P_LEVELS][EHMER_MAX];
  103409. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103410. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103411. memset(workc,0,sizeof(workc));
  103412. for(i=0;i<P_BANDS;i++){
  103413. int ath_offset=i*4;
  103414. for(j=0;j<EHMER_MAX;j++){
  103415. float min=999.;
  103416. for(k=0;k<4;k++)
  103417. if(j+k+ath_offset<MAX_ATH){
  103418. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103419. }else{
  103420. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103421. }
  103422. ath[j]=min;
  103423. }
  103424. for(j=0;j<6;j++)
  103425. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103426. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103427. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103428. for(j=0;j<P_LEVELS;j++){
  103429. for(k=0;k<EHMER_MAX;k++){
  103430. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103431. if(adj<0. && center_boost>0)adj=0.;
  103432. if(adj>0. && center_boost<0)adj=0.;
  103433. workc[i][j][k]+=adj;
  103434. }
  103435. }
  103436. for(j=0;j<P_LEVELS;j++){
  103437. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103438. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103439. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103440. max_curve(athc[j],workc[i][j]);
  103441. }
  103442. for(j=1;j<P_LEVELS;j++){
  103443. min_curve(athc[j],athc[j-1]);
  103444. min_curve(workc[i][j],athc[j]);
  103445. }
  103446. }
  103447. for(i=0;i<P_BANDS;i++){
  103448. int hi_curve,lo_curve,bin;
  103449. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103450. bin=floor(fromOC(i*.5)/binHz);
  103451. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103452. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103453. if(lo_curve>i)lo_curve=i;
  103454. if(lo_curve<0)lo_curve=0;
  103455. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103456. for(m=0;m<P_LEVELS;m++){
  103457. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103458. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103459. for(k=lo_curve;k<=hi_curve;k++){
  103460. int l=0;
  103461. for(j=0;j<EHMER_MAX;j++){
  103462. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103463. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103464. if(lo_bin<0)lo_bin=0;
  103465. if(lo_bin>n)lo_bin=n;
  103466. if(lo_bin<l)l=lo_bin;
  103467. if(hi_bin<0)hi_bin=0;
  103468. if(hi_bin>n)hi_bin=n;
  103469. for(;l<hi_bin && l<n;l++)
  103470. if(brute_buffer[l]>workc[k][m][j])
  103471. brute_buffer[l]=workc[k][m][j];
  103472. }
  103473. for(;l<n;l++)
  103474. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103475. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103476. }
  103477. if(i+1<P_BANDS){
  103478. int l=0;
  103479. k=i+1;
  103480. for(j=0;j<EHMER_MAX;j++){
  103481. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103482. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103483. if(lo_bin<0)lo_bin=0;
  103484. if(lo_bin>n)lo_bin=n;
  103485. if(lo_bin<l)l=lo_bin;
  103486. if(hi_bin<0)hi_bin=0;
  103487. if(hi_bin>n)hi_bin=n;
  103488. for(;l<hi_bin && l<n;l++)
  103489. if(brute_buffer[l]>workc[k][m][j])
  103490. brute_buffer[l]=workc[k][m][j];
  103491. }
  103492. for(;l<n;l++)
  103493. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103494. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103495. }
  103496. for(j=0;j<EHMER_MAX;j++){
  103497. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103498. if(bin<0){
  103499. ret[i][m][j+2]=-999.;
  103500. }else{
  103501. if(bin>=n){
  103502. ret[i][m][j+2]=-999.;
  103503. }else{
  103504. ret[i][m][j+2]=brute_buffer[bin];
  103505. }
  103506. }
  103507. }
  103508. for(j=0;j<EHMER_OFFSET;j++)
  103509. if(ret[i][m][j+2]>-200.f)break;
  103510. ret[i][m][0]=j;
  103511. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103512. if(ret[i][m][j+2]>-200.f)
  103513. break;
  103514. ret[i][m][1]=j;
  103515. }
  103516. }
  103517. return(ret);
  103518. }
  103519. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103520. vorbis_info_psy_global *gi,int n,long rate){
  103521. long i,j,lo=-99,hi=1;
  103522. long maxoc;
  103523. memset(p,0,sizeof(*p));
  103524. p->eighth_octave_lines=gi->eighth_octave_lines;
  103525. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103526. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103527. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103528. p->total_octave_lines=maxoc-p->firstoc+1;
  103529. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103530. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103531. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103532. p->vi=vi;
  103533. p->n=n;
  103534. p->rate=rate;
  103535. p->m_val = 1.;
  103536. if(rate < 26000) p->m_val = 0;
  103537. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103538. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103539. for(i=0,j=0;i<MAX_ATH-1;i++){
  103540. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103541. float base=ATH[i];
  103542. if(j<endpos){
  103543. float delta=(ATH[i+1]-base)/(endpos-j);
  103544. for(;j<endpos && j<n;j++){
  103545. p->ath[j]=base+100.;
  103546. base+=delta;
  103547. }
  103548. }
  103549. }
  103550. for(i=0;i<n;i++){
  103551. float bark=toBARK(rate/(2*n)*i);
  103552. for(;lo+vi->noisewindowlomin<i &&
  103553. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103554. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103555. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103556. p->bark[i]=((lo-1)<<16)+(hi-1);
  103557. }
  103558. for(i=0;i<n;i++)
  103559. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103560. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103561. vi->tone_centerboost,vi->tone_decay);
  103562. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103563. for(i=0;i<P_NOISECURVES;i++)
  103564. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103565. for(i=0;i<n;i++){
  103566. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103567. int inthalfoc;
  103568. float del;
  103569. if(halfoc<0)halfoc=0;
  103570. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103571. inthalfoc=(int)halfoc;
  103572. del=halfoc-inthalfoc;
  103573. for(j=0;j<P_NOISECURVES;j++)
  103574. p->noiseoffset[j][i]=
  103575. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103576. p->vi->noiseoff[j][inthalfoc+1]*del;
  103577. }
  103578. #if 0
  103579. {
  103580. static int ls=0;
  103581. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103582. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103583. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103584. }
  103585. #endif
  103586. }
  103587. void _vp_psy_clear(vorbis_look_psy *p){
  103588. int i,j;
  103589. if(p){
  103590. if(p->ath)_ogg_free(p->ath);
  103591. if(p->octave)_ogg_free(p->octave);
  103592. if(p->bark)_ogg_free(p->bark);
  103593. if(p->tonecurves){
  103594. for(i=0;i<P_BANDS;i++){
  103595. for(j=0;j<P_LEVELS;j++){
  103596. _ogg_free(p->tonecurves[i][j]);
  103597. }
  103598. _ogg_free(p->tonecurves[i]);
  103599. }
  103600. _ogg_free(p->tonecurves);
  103601. }
  103602. if(p->noiseoffset){
  103603. for(i=0;i<P_NOISECURVES;i++){
  103604. _ogg_free(p->noiseoffset[i]);
  103605. }
  103606. _ogg_free(p->noiseoffset);
  103607. }
  103608. memset(p,0,sizeof(*p));
  103609. }
  103610. }
  103611. static void seed_curve(float *seed,
  103612. const float **curves,
  103613. float amp,
  103614. int oc, int n,
  103615. int linesper,float dBoffset){
  103616. int i,post1;
  103617. int seedptr;
  103618. const float *posts,*curve;
  103619. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103620. choice=max(choice,0);
  103621. choice=min(choice,P_LEVELS-1);
  103622. posts=curves[choice];
  103623. curve=posts+2;
  103624. post1=(int)posts[1];
  103625. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103626. for(i=posts[0];i<post1;i++){
  103627. if(seedptr>0){
  103628. float lin=amp+curve[i];
  103629. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103630. }
  103631. seedptr+=linesper;
  103632. if(seedptr>=n)break;
  103633. }
  103634. }
  103635. static void seed_loop(vorbis_look_psy *p,
  103636. const float ***curves,
  103637. const float *f,
  103638. const float *flr,
  103639. float *seed,
  103640. float specmax){
  103641. vorbis_info_psy *vi=p->vi;
  103642. long n=p->n,i;
  103643. float dBoffset=vi->max_curve_dB-specmax;
  103644. for(i=0;i<n;i++){
  103645. float max=f[i];
  103646. long oc=p->octave[i];
  103647. while(i+1<n && p->octave[i+1]==oc){
  103648. i++;
  103649. if(f[i]>max)max=f[i];
  103650. }
  103651. if(max+6.f>flr[i]){
  103652. oc=oc>>p->shiftoc;
  103653. if(oc>=P_BANDS)oc=P_BANDS-1;
  103654. if(oc<0)oc=0;
  103655. seed_curve(seed,
  103656. curves[oc],
  103657. max,
  103658. p->octave[i]-p->firstoc,
  103659. p->total_octave_lines,
  103660. p->eighth_octave_lines,
  103661. dBoffset);
  103662. }
  103663. }
  103664. }
  103665. static void seed_chase(float *seeds, int linesper, long n){
  103666. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103667. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103668. long stack=0;
  103669. long pos=0;
  103670. long i;
  103671. for(i=0;i<n;i++){
  103672. if(stack<2){
  103673. posstack[stack]=i;
  103674. ampstack[stack++]=seeds[i];
  103675. }else{
  103676. while(1){
  103677. if(seeds[i]<ampstack[stack-1]){
  103678. posstack[stack]=i;
  103679. ampstack[stack++]=seeds[i];
  103680. break;
  103681. }else{
  103682. if(i<posstack[stack-1]+linesper){
  103683. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103684. i<posstack[stack-2]+linesper){
  103685. stack--;
  103686. continue;
  103687. }
  103688. }
  103689. posstack[stack]=i;
  103690. ampstack[stack++]=seeds[i];
  103691. break;
  103692. }
  103693. }
  103694. }
  103695. }
  103696. for(i=0;i<stack;i++){
  103697. long endpos;
  103698. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103699. endpos=posstack[i+1];
  103700. }else{
  103701. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103702. discarded in short frames */
  103703. }
  103704. if(endpos>n)endpos=n;
  103705. for(;pos<endpos;pos++)
  103706. seeds[pos]=ampstack[i];
  103707. }
  103708. }
  103709. #include<stdio.h>
  103710. static void max_seeds(vorbis_look_psy *p,
  103711. float *seed,
  103712. float *flr){
  103713. long n=p->total_octave_lines;
  103714. int linesper=p->eighth_octave_lines;
  103715. long linpos=0;
  103716. long pos;
  103717. seed_chase(seed,linesper,n); /* for masking */
  103718. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103719. while(linpos+1<p->n){
  103720. float minV=seed[pos];
  103721. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103722. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103723. while(pos+1<=end){
  103724. pos++;
  103725. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103726. minV=seed[pos];
  103727. }
  103728. end=pos+p->firstoc;
  103729. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103730. if(flr[linpos]<minV)flr[linpos]=minV;
  103731. }
  103732. {
  103733. float minV=seed[p->total_octave_lines-1];
  103734. for(;linpos<p->n;linpos++)
  103735. if(flr[linpos]<minV)flr[linpos]=minV;
  103736. }
  103737. }
  103738. static void bark_noise_hybridmp(int n,const long *b,
  103739. const float *f,
  103740. float *noise,
  103741. const float offset,
  103742. const int fixed){
  103743. float *N=(float*) alloca(n*sizeof(*N));
  103744. float *X=(float*) alloca(n*sizeof(*N));
  103745. float *XX=(float*) alloca(n*sizeof(*N));
  103746. float *Y=(float*) alloca(n*sizeof(*N));
  103747. float *XY=(float*) alloca(n*sizeof(*N));
  103748. float tN, tX, tXX, tY, tXY;
  103749. int i;
  103750. int lo, hi;
  103751. float R, A, B, D;
  103752. float w, x, y;
  103753. tN = tX = tXX = tY = tXY = 0.f;
  103754. y = f[0] + offset;
  103755. if (y < 1.f) y = 1.f;
  103756. w = y * y * .5;
  103757. tN += w;
  103758. tX += w;
  103759. tY += w * y;
  103760. N[0] = tN;
  103761. X[0] = tX;
  103762. XX[0] = tXX;
  103763. Y[0] = tY;
  103764. XY[0] = tXY;
  103765. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103766. y = f[i] + offset;
  103767. if (y < 1.f) y = 1.f;
  103768. w = y * y;
  103769. tN += w;
  103770. tX += w * x;
  103771. tXX += w * x * x;
  103772. tY += w * y;
  103773. tXY += w * x * y;
  103774. N[i] = tN;
  103775. X[i] = tX;
  103776. XX[i] = tXX;
  103777. Y[i] = tY;
  103778. XY[i] = tXY;
  103779. }
  103780. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103781. lo = b[i] >> 16;
  103782. if( lo>=0 ) break;
  103783. hi = b[i] & 0xffff;
  103784. tN = N[hi] + N[-lo];
  103785. tX = X[hi] - X[-lo];
  103786. tXX = XX[hi] + XX[-lo];
  103787. tY = Y[hi] + Y[-lo];
  103788. tXY = XY[hi] - XY[-lo];
  103789. A = tY * tXX - tX * tXY;
  103790. B = tN * tXY - tX * tY;
  103791. D = tN * tXX - tX * tX;
  103792. R = (A + x * B) / D;
  103793. if (R < 0.f)
  103794. R = 0.f;
  103795. noise[i] = R - offset;
  103796. }
  103797. for ( ;; i++, x += 1.f) {
  103798. lo = b[i] >> 16;
  103799. hi = b[i] & 0xffff;
  103800. if(hi>=n)break;
  103801. tN = N[hi] - N[lo];
  103802. tX = X[hi] - X[lo];
  103803. tXX = XX[hi] - XX[lo];
  103804. tY = Y[hi] - Y[lo];
  103805. tXY = XY[hi] - XY[lo];
  103806. A = tY * tXX - tX * tXY;
  103807. B = tN * tXY - tX * tY;
  103808. D = tN * tXX - tX * tX;
  103809. R = (A + x * B) / D;
  103810. if (R < 0.f) R = 0.f;
  103811. noise[i] = R - offset;
  103812. }
  103813. for ( ; i < n; i++, x += 1.f) {
  103814. R = (A + x * B) / D;
  103815. if (R < 0.f) R = 0.f;
  103816. noise[i] = R - offset;
  103817. }
  103818. if (fixed <= 0) return;
  103819. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103820. hi = i + fixed / 2;
  103821. lo = hi - fixed;
  103822. if(lo>=0)break;
  103823. tN = N[hi] + N[-lo];
  103824. tX = X[hi] - X[-lo];
  103825. tXX = XX[hi] + XX[-lo];
  103826. tY = Y[hi] + Y[-lo];
  103827. tXY = XY[hi] - XY[-lo];
  103828. A = tY * tXX - tX * tXY;
  103829. B = tN * tXY - tX * tY;
  103830. D = tN * tXX - tX * tX;
  103831. R = (A + x * B) / D;
  103832. if (R - offset < noise[i]) noise[i] = R - offset;
  103833. }
  103834. for ( ;; i++, x += 1.f) {
  103835. hi = i + fixed / 2;
  103836. lo = hi - fixed;
  103837. if(hi>=n)break;
  103838. tN = N[hi] - N[lo];
  103839. tX = X[hi] - X[lo];
  103840. tXX = XX[hi] - XX[lo];
  103841. tY = Y[hi] - Y[lo];
  103842. tXY = XY[hi] - XY[lo];
  103843. A = tY * tXX - tX * tXY;
  103844. B = tN * tXY - tX * tY;
  103845. D = tN * tXX - tX * tX;
  103846. R = (A + x * B) / D;
  103847. if (R - offset < noise[i]) noise[i] = R - offset;
  103848. }
  103849. for ( ; i < n; i++, x += 1.f) {
  103850. R = (A + x * B) / D;
  103851. if (R - offset < noise[i]) noise[i] = R - offset;
  103852. }
  103853. }
  103854. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103855. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103856. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103857. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103858. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103859. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103860. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103861. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103862. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103863. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103864. 973377.F, 913981.F, 858210.F, 805842.F,
  103865. 756669.F, 710497.F, 667142.F, 626433.F,
  103866. 588208.F, 552316.F, 518613.F, 486967.F,
  103867. 457252.F, 429351.F, 403152.F, 378551.F,
  103868. 355452.F, 333762.F, 313396.F, 294273.F,
  103869. 276316.F, 259455.F, 243623.F, 228757.F,
  103870. 214798.F, 201691.F, 189384.F, 177828.F,
  103871. 166977.F, 156788.F, 147221.F, 138237.F,
  103872. 129802.F, 121881.F, 114444.F, 107461.F,
  103873. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103874. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103875. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103876. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103877. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103878. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103879. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103880. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103881. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103882. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103883. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103884. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103885. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103886. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103887. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103888. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103889. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103890. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103891. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103892. 842.910F, 791.475F, 743.179F, 697.830F,
  103893. 655.249F, 615.265F, 577.722F, 542.469F,
  103894. 509.367F, 478.286F, 449.101F, 421.696F,
  103895. 395.964F, 371.803F, 349.115F, 327.812F,
  103896. 307.809F, 289.026F, 271.390F, 254.830F,
  103897. 239.280F, 224.679F, 210.969F, 198.096F,
  103898. 186.008F, 174.658F, 164.000F, 153.993F,
  103899. 144.596F, 135.773F, 127.488F, 119.708F,
  103900. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103901. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103902. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103903. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103904. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103905. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103906. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103907. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103908. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103909. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103910. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103911. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103912. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103913. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103914. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103915. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103916. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103917. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103918. 1.20790F, 1.13419F, 1.06499F, 1.F
  103919. };
  103920. void _vp_remove_floor(vorbis_look_psy *p,
  103921. float *mdct,
  103922. int *codedflr,
  103923. float *residue,
  103924. int sliding_lowpass){
  103925. int i,n=p->n;
  103926. if(sliding_lowpass>n)sliding_lowpass=n;
  103927. for(i=0;i<sliding_lowpass;i++){
  103928. residue[i]=
  103929. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103930. }
  103931. for(;i<n;i++)
  103932. residue[i]=0.;
  103933. }
  103934. void _vp_noisemask(vorbis_look_psy *p,
  103935. float *logmdct,
  103936. float *logmask){
  103937. int i,n=p->n;
  103938. float *work=(float*) alloca(n*sizeof(*work));
  103939. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103940. 140.,-1);
  103941. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103942. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103943. p->vi->noisewindowfixed);
  103944. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103945. #if 0
  103946. {
  103947. static int seq=0;
  103948. float work2[n];
  103949. for(i=0;i<n;i++){
  103950. work2[i]=logmask[i]+work[i];
  103951. }
  103952. if(seq&1)
  103953. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103954. else
  103955. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103956. if(seq&1)
  103957. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103958. else
  103959. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103960. seq++;
  103961. }
  103962. #endif
  103963. for(i=0;i<n;i++){
  103964. int dB=logmask[i]+.5;
  103965. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103966. if(dB<0)dB=0;
  103967. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103968. }
  103969. }
  103970. void _vp_tonemask(vorbis_look_psy *p,
  103971. float *logfft,
  103972. float *logmask,
  103973. float global_specmax,
  103974. float local_specmax){
  103975. int i,n=p->n;
  103976. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103977. float att=local_specmax+p->vi->ath_adjatt;
  103978. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103979. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103980. for(i=0;i<n;i++)
  103981. logmask[i]=p->ath[i]+att;
  103982. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103983. max_seeds(p,seed,logmask);
  103984. }
  103985. void _vp_offset_and_mix(vorbis_look_psy *p,
  103986. float *noise,
  103987. float *tone,
  103988. int offset_select,
  103989. float *logmask,
  103990. float *mdct,
  103991. float *logmdct){
  103992. int i,n=p->n;
  103993. float de, coeffi, cx;/* AoTuV */
  103994. float toneatt=p->vi->tone_masteratt[offset_select];
  103995. cx = p->m_val;
  103996. for(i=0;i<n;i++){
  103997. float val= noise[i]+p->noiseoffset[offset_select][i];
  103998. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103999. logmask[i]=max(val,tone[i]+toneatt);
  104000. if(offset_select == 1) {
  104001. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  104002. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  104003. if(val > coeffi){
  104004. de = 1.0-((val-coeffi)*0.005*cx);
  104005. if(de < 0) de = 0.0001;
  104006. }else
  104007. de = 1.0-((val-coeffi)*0.0003*cx);
  104008. mdct[i] *= de;
  104009. }
  104010. }
  104011. }
  104012. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  104013. vorbis_info *vi=vd->vi;
  104014. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  104015. vorbis_info_psy_global *gi=&ci->psy_g_param;
  104016. int n=ci->blocksizes[vd->W]/2;
  104017. float secs=(float)n/vi->rate;
  104018. amp+=secs*gi->ampmax_att_per_sec;
  104019. if(amp<-9999)amp=-9999;
  104020. return(amp);
  104021. }
  104022. static void couple_lossless(float A, float B,
  104023. float *qA, float *qB){
  104024. int test1=fabs(*qA)>fabs(*qB);
  104025. test1-= fabs(*qA)<fabs(*qB);
  104026. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  104027. if(test1==1){
  104028. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  104029. }else{
  104030. float temp=*qB;
  104031. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  104032. *qA=temp;
  104033. }
  104034. if(*qB>fabs(*qA)*1.9999f){
  104035. *qB= -fabs(*qA)*2.f;
  104036. *qA= -*qA;
  104037. }
  104038. }
  104039. static float hypot_lookup[32]={
  104040. -0.009935, -0.011245, -0.012726, -0.014397,
  104041. -0.016282, -0.018407, -0.020800, -0.023494,
  104042. -0.026522, -0.029923, -0.033737, -0.038010,
  104043. -0.042787, -0.048121, -0.054064, -0.060671,
  104044. -0.068000, -0.076109, -0.085054, -0.094892,
  104045. -0.105675, -0.117451, -0.130260, -0.144134,
  104046. -0.159093, -0.175146, -0.192286, -0.210490,
  104047. -0.229718, -0.249913, -0.271001, -0.292893};
  104048. static void precomputed_couple_point(float premag,
  104049. int floorA,int floorB,
  104050. float *mag, float *ang){
  104051. int test=(floorA>floorB)-1;
  104052. int offset=31-abs(floorA-floorB);
  104053. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  104054. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  104055. *mag=premag*floormag;
  104056. *ang=0.f;
  104057. }
  104058. static float dipole_hypot(float a, float b){
  104059. if(a>0.){
  104060. if(b>0.)return sqrt(a*a+b*b);
  104061. if(a>-b)return sqrt(a*a-b*b);
  104062. return -sqrt(b*b-a*a);
  104063. }
  104064. if(b<0.)return -sqrt(a*a+b*b);
  104065. if(-a>b)return -sqrt(a*a-b*b);
  104066. return sqrt(b*b-a*a);
  104067. }
  104068. static float round_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. float **_vp_quantize_couple_memo(vorbis_block *vb,
  104079. vorbis_info_psy_global *g,
  104080. vorbis_look_psy *p,
  104081. vorbis_info_mapping0 *vi,
  104082. float **mdct){
  104083. int i,j,n=p->n;
  104084. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104085. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104086. for(i=0;i<vi->coupling_steps;i++){
  104087. float *mdctM=mdct[vi->coupling_mag[i]];
  104088. float *mdctA=mdct[vi->coupling_ang[i]];
  104089. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104090. for(j=0;j<limit;j++)
  104091. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  104092. for(;j<n;j++)
  104093. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  104094. }
  104095. return(ret);
  104096. }
  104097. static int apsort(const void *a, const void *b){
  104098. float f1=fabs(**(float**)a);
  104099. float f2=fabs(**(float**)b);
  104100. return (f1<f2)-(f1>f2);
  104101. }
  104102. int **_vp_quantize_couple_sort(vorbis_block *vb,
  104103. vorbis_look_psy *p,
  104104. vorbis_info_mapping0 *vi,
  104105. float **mags){
  104106. if(p->vi->normal_point_p){
  104107. int i,j,k,n=p->n;
  104108. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104109. int partition=p->vi->normal_partition;
  104110. float **work=(float**) alloca(sizeof(*work)*partition);
  104111. for(i=0;i<vi->coupling_steps;i++){
  104112. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104113. for(j=0;j<n;j+=partition){
  104114. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  104115. qsort(work,partition,sizeof(*work),apsort);
  104116. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  104117. }
  104118. }
  104119. return(ret);
  104120. }
  104121. return(NULL);
  104122. }
  104123. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  104124. float *magnitudes,int *sortedindex){
  104125. int i,j,n=p->n;
  104126. vorbis_info_psy *vi=p->vi;
  104127. int partition=vi->normal_partition;
  104128. float **work=(float**) alloca(sizeof(*work)*partition);
  104129. int start=vi->normal_start;
  104130. for(j=start;j<n;j+=partition){
  104131. if(j+partition>n)partition=n-j;
  104132. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  104133. qsort(work,partition,sizeof(*work),apsort);
  104134. for(i=0;i<partition;i++){
  104135. sortedindex[i+j-start]=work[i]-magnitudes;
  104136. }
  104137. }
  104138. }
  104139. void _vp_noise_normalize(vorbis_look_psy *p,
  104140. float *in,float *out,int *sortedindex){
  104141. int flag=0,i,j=0,n=p->n;
  104142. vorbis_info_psy *vi=p->vi;
  104143. int partition=vi->normal_partition;
  104144. int start=vi->normal_start;
  104145. if(start>n)start=n;
  104146. if(vi->normal_channel_p){
  104147. for(;j<start;j++)
  104148. out[j]=rint(in[j]);
  104149. for(;j+partition<=n;j+=partition){
  104150. float acc=0.;
  104151. int k;
  104152. for(i=j;i<j+partition;i++)
  104153. acc+=in[i]*in[i];
  104154. for(i=0;i<partition;i++){
  104155. k=sortedindex[i+j-start];
  104156. if(in[k]*in[k]>=.25f){
  104157. out[k]=rint(in[k]);
  104158. acc-=in[k]*in[k];
  104159. flag=1;
  104160. }else{
  104161. if(acc<vi->normal_thresh)break;
  104162. out[k]=unitnorm(in[k]);
  104163. acc-=1.;
  104164. }
  104165. }
  104166. for(;i<partition;i++){
  104167. k=sortedindex[i+j-start];
  104168. out[k]=0.;
  104169. }
  104170. }
  104171. }
  104172. for(;j<n;j++)
  104173. out[j]=rint(in[j]);
  104174. }
  104175. void _vp_couple(int blobno,
  104176. vorbis_info_psy_global *g,
  104177. vorbis_look_psy *p,
  104178. vorbis_info_mapping0 *vi,
  104179. float **res,
  104180. float **mag_memo,
  104181. int **mag_sort,
  104182. int **ifloor,
  104183. int *nonzero,
  104184. int sliding_lowpass){
  104185. int i,j,k,n=p->n;
  104186. for(i=0;i<vi->coupling_steps;i++){
  104187. if(nonzero[vi->coupling_mag[i]] ||
  104188. nonzero[vi->coupling_ang[i]]){
  104189. float *rM=res[vi->coupling_mag[i]];
  104190. float *rA=res[vi->coupling_ang[i]];
  104191. float *qM=rM+n;
  104192. float *qA=rA+n;
  104193. int *floorM=ifloor[vi->coupling_mag[i]];
  104194. int *floorA=ifloor[vi->coupling_ang[i]];
  104195. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  104196. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  104197. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  104198. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  104199. int pointlimit=limit;
  104200. nonzero[vi->coupling_mag[i]]=1;
  104201. nonzero[vi->coupling_ang[i]]=1;
  104202. if(n > 1000)
  104203. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  104204. for(j=0;j<p->n;j+=partition){
  104205. float acc=0.f;
  104206. for(k=0;k<partition;k++){
  104207. int l=k+j;
  104208. if(l<sliding_lowpass){
  104209. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  104210. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  104211. precomputed_couple_point(mag_memo[i][l],
  104212. floorM[l],floorA[l],
  104213. qM+l,qA+l);
  104214. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  104215. }else{
  104216. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  104217. }
  104218. }else{
  104219. qM[l]=0.;
  104220. qA[l]=0.;
  104221. }
  104222. }
  104223. if(p->vi->normal_point_p){
  104224. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  104225. int l=mag_sort[i][j+k];
  104226. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  104227. qM[l]=unitnorm(qM[l]);
  104228. acc-=1.f;
  104229. }
  104230. }
  104231. }
  104232. }
  104233. }
  104234. }
  104235. }
  104236. void hf_reduction(vorbis_info_psy_global *g,
  104237. vorbis_look_psy *p,
  104238. vorbis_info_mapping0 *vi,
  104239. float **mdct){
  104240. int i,j,n=p->n, de=0.3*p->m_val;
  104241. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104242. for(i=0; i<vi->coupling_steps; i++){
  104243. for(j=limit; j<n; j++)
  104244. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  104245. }
  104246. }
  104247. #endif
  104248. /*** End of inlined file: psy.c ***/
  104249. /*** Start of inlined file: registry.c ***/
  104250. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104251. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104252. // tasks..
  104253. #if JUCE_MSVC
  104254. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104255. #endif
  104256. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104257. #if JUCE_USE_OGGVORBIS
  104258. extern vorbis_func_floor floor0_exportbundle;
  104259. extern vorbis_func_floor floor1_exportbundle;
  104260. extern vorbis_func_residue residue0_exportbundle;
  104261. extern vorbis_func_residue residue1_exportbundle;
  104262. extern vorbis_func_residue residue2_exportbundle;
  104263. extern vorbis_func_mapping mapping0_exportbundle;
  104264. vorbis_func_floor *_floor_P[]={
  104265. &floor0_exportbundle,
  104266. &floor1_exportbundle,
  104267. };
  104268. vorbis_func_residue *_residue_P[]={
  104269. &residue0_exportbundle,
  104270. &residue1_exportbundle,
  104271. &residue2_exportbundle,
  104272. };
  104273. vorbis_func_mapping *_mapping_P[]={
  104274. &mapping0_exportbundle,
  104275. };
  104276. #endif
  104277. /*** End of inlined file: registry.c ***/
  104278. /*** Start of inlined file: res0.c ***/
  104279. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104280. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104281. // tasks..
  104282. #if JUCE_MSVC
  104283. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104284. #endif
  104285. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104286. #if JUCE_USE_OGGVORBIS
  104287. #include <stdlib.h>
  104288. #include <string.h>
  104289. #include <math.h>
  104290. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104291. #include <stdio.h>
  104292. #endif
  104293. typedef struct {
  104294. vorbis_info_residue0 *info;
  104295. int parts;
  104296. int stages;
  104297. codebook *fullbooks;
  104298. codebook *phrasebook;
  104299. codebook ***partbooks;
  104300. int partvals;
  104301. int **decodemap;
  104302. long postbits;
  104303. long phrasebits;
  104304. long frames;
  104305. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104306. int train_seq;
  104307. long *training_data[8][64];
  104308. float training_max[8][64];
  104309. float training_min[8][64];
  104310. float tmin;
  104311. float tmax;
  104312. #endif
  104313. } vorbis_look_residue0;
  104314. void res0_free_info(vorbis_info_residue *i){
  104315. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104316. if(info){
  104317. memset(info,0,sizeof(*info));
  104318. _ogg_free(info);
  104319. }
  104320. }
  104321. void res0_free_look(vorbis_look_residue *i){
  104322. int j;
  104323. if(i){
  104324. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104325. #ifdef TRAIN_RES
  104326. {
  104327. int j,k,l;
  104328. for(j=0;j<look->parts;j++){
  104329. for(k=0;k<8;k++)
  104330. if(look->training_data[k][j]){
  104331. char buffer[80];
  104332. FILE *of;
  104333. codebook *statebook=look->partbooks[j][k];
  104334. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104335. of=fopen(buffer,"a");
  104336. for(l=0;l<statebook->entries;l++)
  104337. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104338. fclose(of);
  104339. _ogg_free(look->training_data[k][j]);
  104340. look->training_data[k][j]=NULL;
  104341. }
  104342. }
  104343. }
  104344. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104345. #endif
  104346. for(j=0;j<look->parts;j++)
  104347. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104348. _ogg_free(look->partbooks);
  104349. for(j=0;j<look->partvals;j++)
  104350. _ogg_free(look->decodemap[j]);
  104351. _ogg_free(look->decodemap);
  104352. memset(look,0,sizeof(*look));
  104353. _ogg_free(look);
  104354. }
  104355. }
  104356. static int icount(unsigned int v){
  104357. int ret=0;
  104358. while(v){
  104359. ret+=v&1;
  104360. v>>=1;
  104361. }
  104362. return(ret);
  104363. }
  104364. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104365. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104366. int j,acc=0;
  104367. oggpack_write(opb,info->begin,24);
  104368. oggpack_write(opb,info->end,24);
  104369. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104370. code with a partitioned book */
  104371. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104372. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104373. for(j=0;j<info->partitions;j++){
  104374. if(ilog(info->secondstages[j])>3){
  104375. oggpack_write(opb,info->secondstages[j],3);
  104376. oggpack_write(opb,1,1);
  104377. oggpack_write(opb,info->secondstages[j]>>3,5);
  104378. }else
  104379. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104380. acc+=icount(info->secondstages[j]);
  104381. }
  104382. for(j=0;j<acc;j++)
  104383. oggpack_write(opb,info->booklist[j],8);
  104384. }
  104385. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104386. int j,acc=0;
  104387. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104388. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104389. info->begin=oggpack_read(opb,24);
  104390. info->end=oggpack_read(opb,24);
  104391. info->grouping=oggpack_read(opb,24)+1;
  104392. info->partitions=oggpack_read(opb,6)+1;
  104393. info->groupbook=oggpack_read(opb,8);
  104394. for(j=0;j<info->partitions;j++){
  104395. int cascade=oggpack_read(opb,3);
  104396. if(oggpack_read(opb,1))
  104397. cascade|=(oggpack_read(opb,5)<<3);
  104398. info->secondstages[j]=cascade;
  104399. acc+=icount(cascade);
  104400. }
  104401. for(j=0;j<acc;j++)
  104402. info->booklist[j]=oggpack_read(opb,8);
  104403. if(info->groupbook>=ci->books)goto errout;
  104404. for(j=0;j<acc;j++)
  104405. if(info->booklist[j]>=ci->books)goto errout;
  104406. return(info);
  104407. errout:
  104408. res0_free_info(info);
  104409. return(NULL);
  104410. }
  104411. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104412. vorbis_info_residue *vr){
  104413. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104414. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104415. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104416. int j,k,acc=0;
  104417. int dim;
  104418. int maxstage=0;
  104419. look->info=info;
  104420. look->parts=info->partitions;
  104421. look->fullbooks=ci->fullbooks;
  104422. look->phrasebook=ci->fullbooks+info->groupbook;
  104423. dim=look->phrasebook->dim;
  104424. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104425. for(j=0;j<look->parts;j++){
  104426. int stages=ilog(info->secondstages[j]);
  104427. if(stages){
  104428. if(stages>maxstage)maxstage=stages;
  104429. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104430. for(k=0;k<stages;k++)
  104431. if(info->secondstages[j]&(1<<k)){
  104432. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104433. #ifdef TRAIN_RES
  104434. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104435. sizeof(***look->training_data));
  104436. #endif
  104437. }
  104438. }
  104439. }
  104440. look->partvals=rint(pow((float)look->parts,(float)dim));
  104441. look->stages=maxstage;
  104442. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104443. for(j=0;j<look->partvals;j++){
  104444. long val=j;
  104445. long mult=look->partvals/look->parts;
  104446. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104447. for(k=0;k<dim;k++){
  104448. long deco=val/mult;
  104449. val-=deco*mult;
  104450. mult/=look->parts;
  104451. look->decodemap[j][k]=deco;
  104452. }
  104453. }
  104454. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104455. {
  104456. static int train_seq=0;
  104457. look->train_seq=train_seq++;
  104458. }
  104459. #endif
  104460. return(look);
  104461. }
  104462. static int local_book_besterror(codebook *book,float *a){
  104463. int dim=book->dim,i,k,o;
  104464. int best=0;
  104465. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104466. for(k=0,o=dim;k<dim;++k){
  104467. float val=a[--o];
  104468. i=tt->threshvals>>1;
  104469. if(val<tt->quantthresh[i]){
  104470. if(val<tt->quantthresh[i-1]){
  104471. for(--i;i>0;--i)
  104472. if(val>=tt->quantthresh[i-1])
  104473. break;
  104474. }
  104475. }else{
  104476. for(++i;i<tt->threshvals-1;++i)
  104477. if(val<tt->quantthresh[i])break;
  104478. }
  104479. best=(best*tt->quantvals)+tt->quantmap[i];
  104480. }
  104481. if(book->c->lengthlist[best]<=0){
  104482. const static_codebook *c=book->c;
  104483. int i,j;
  104484. float bestf=0.f;
  104485. float *e=book->valuelist;
  104486. best=-1;
  104487. for(i=0;i<book->entries;i++){
  104488. if(c->lengthlist[i]>0){
  104489. float thisx=0.f;
  104490. for(j=0;j<dim;j++){
  104491. float val=(e[j]-a[j]);
  104492. thisx+=val*val;
  104493. }
  104494. if(best==-1 || thisx<bestf){
  104495. bestf=thisx;
  104496. best=i;
  104497. }
  104498. }
  104499. e+=dim;
  104500. }
  104501. }
  104502. {
  104503. float *ptr=book->valuelist+best*dim;
  104504. for(i=0;i<dim;i++)
  104505. *a++ -= *ptr++;
  104506. }
  104507. return(best);
  104508. }
  104509. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104510. codebook *book,long *acc){
  104511. int i,bits=0;
  104512. int dim=book->dim;
  104513. int step=n/dim;
  104514. for(i=0;i<step;i++){
  104515. int entry=local_book_besterror(book,vec+i*dim);
  104516. #ifdef TRAIN_RES
  104517. acc[entry]++;
  104518. #endif
  104519. bits+=vorbis_book_encode(book,entry,opb);
  104520. }
  104521. return(bits);
  104522. }
  104523. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104524. float **in,int ch){
  104525. long i,j,k;
  104526. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104527. vorbis_info_residue0 *info=look->info;
  104528. int samples_per_partition=info->grouping;
  104529. int possible_partitions=info->partitions;
  104530. int n=info->end-info->begin;
  104531. int partvals=n/samples_per_partition;
  104532. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104533. float scale=100./samples_per_partition;
  104534. for(i=0;i<ch;i++){
  104535. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104536. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104537. }
  104538. for(i=0;i<partvals;i++){
  104539. int offset=i*samples_per_partition+info->begin;
  104540. for(j=0;j<ch;j++){
  104541. float max=0.;
  104542. float ent=0.;
  104543. for(k=0;k<samples_per_partition;k++){
  104544. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104545. ent+=fabs(rint(in[j][offset+k]));
  104546. }
  104547. ent*=scale;
  104548. for(k=0;k<possible_partitions-1;k++)
  104549. if(max<=info->classmetric1[k] &&
  104550. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104551. break;
  104552. partword[j][i]=k;
  104553. }
  104554. }
  104555. #ifdef TRAIN_RESAUX
  104556. {
  104557. FILE *of;
  104558. char buffer[80];
  104559. for(i=0;i<ch;i++){
  104560. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104561. of=fopen(buffer,"a");
  104562. for(j=0;j<partvals;j++)
  104563. fprintf(of,"%ld, ",partword[i][j]);
  104564. fprintf(of,"\n");
  104565. fclose(of);
  104566. }
  104567. }
  104568. #endif
  104569. look->frames++;
  104570. return(partword);
  104571. }
  104572. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104573. int ch){
  104574. long i,j,k,l;
  104575. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104576. vorbis_info_residue0 *info=look->info;
  104577. int samples_per_partition=info->grouping;
  104578. int possible_partitions=info->partitions;
  104579. int n=info->end-info->begin;
  104580. int partvals=n/samples_per_partition;
  104581. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104582. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104583. FILE *of;
  104584. char buffer[80];
  104585. #endif
  104586. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104587. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104588. for(i=0,l=info->begin/ch;i<partvals;i++){
  104589. float magmax=0.f;
  104590. float angmax=0.f;
  104591. for(j=0;j<samples_per_partition;j+=ch){
  104592. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104593. for(k=1;k<ch;k++)
  104594. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104595. l++;
  104596. }
  104597. for(j=0;j<possible_partitions-1;j++)
  104598. if(magmax<=info->classmetric1[j] &&
  104599. angmax<=info->classmetric2[j])
  104600. break;
  104601. partword[0][i]=j;
  104602. }
  104603. #ifdef TRAIN_RESAUX
  104604. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104605. of=fopen(buffer,"a");
  104606. for(i=0;i<partvals;i++)
  104607. fprintf(of,"%ld, ",partword[0][i]);
  104608. fprintf(of,"\n");
  104609. fclose(of);
  104610. #endif
  104611. look->frames++;
  104612. return(partword);
  104613. }
  104614. static int _01forward(oggpack_buffer *opb,
  104615. vorbis_block *vb,vorbis_look_residue *vl,
  104616. float **in,int ch,
  104617. long **partword,
  104618. int (*encode)(oggpack_buffer *,float *,int,
  104619. codebook *,long *)){
  104620. long i,j,k,s;
  104621. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104622. vorbis_info_residue0 *info=look->info;
  104623. int samples_per_partition=info->grouping;
  104624. int possible_partitions=info->partitions;
  104625. int partitions_per_word=look->phrasebook->dim;
  104626. int n=info->end-info->begin;
  104627. int partvals=n/samples_per_partition;
  104628. long resbits[128];
  104629. long resvals[128];
  104630. #ifdef TRAIN_RES
  104631. for(i=0;i<ch;i++)
  104632. for(j=info->begin;j<info->end;j++){
  104633. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104634. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104635. }
  104636. #endif
  104637. memset(resbits,0,sizeof(resbits));
  104638. memset(resvals,0,sizeof(resvals));
  104639. for(s=0;s<look->stages;s++){
  104640. for(i=0;i<partvals;){
  104641. if(s==0){
  104642. for(j=0;j<ch;j++){
  104643. long val=partword[j][i];
  104644. for(k=1;k<partitions_per_word;k++){
  104645. val*=possible_partitions;
  104646. if(i+k<partvals)
  104647. val+=partword[j][i+k];
  104648. }
  104649. if(val<look->phrasebook->entries)
  104650. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104651. #if 0 /*def TRAIN_RES*/
  104652. else
  104653. fprintf(stderr,"!");
  104654. #endif
  104655. }
  104656. }
  104657. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104658. long offset=i*samples_per_partition+info->begin;
  104659. for(j=0;j<ch;j++){
  104660. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104661. if(info->secondstages[partword[j][i]]&(1<<s)){
  104662. codebook *statebook=look->partbooks[partword[j][i]][s];
  104663. if(statebook){
  104664. int ret;
  104665. long *accumulator=NULL;
  104666. #ifdef TRAIN_RES
  104667. accumulator=look->training_data[s][partword[j][i]];
  104668. {
  104669. int l;
  104670. float *samples=in[j]+offset;
  104671. for(l=0;l<samples_per_partition;l++){
  104672. if(samples[l]<look->training_min[s][partword[j][i]])
  104673. look->training_min[s][partword[j][i]]=samples[l];
  104674. if(samples[l]>look->training_max[s][partword[j][i]])
  104675. look->training_max[s][partword[j][i]]=samples[l];
  104676. }
  104677. }
  104678. #endif
  104679. ret=encode(opb,in[j]+offset,samples_per_partition,
  104680. statebook,accumulator);
  104681. look->postbits+=ret;
  104682. resbits[partword[j][i]]+=ret;
  104683. }
  104684. }
  104685. }
  104686. }
  104687. }
  104688. }
  104689. return(0);
  104690. }
  104691. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104692. float **in,int ch,
  104693. long (*decodepart)(codebook *, float *,
  104694. oggpack_buffer *,int)){
  104695. long i,j,k,l,s;
  104696. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104697. vorbis_info_residue0 *info=look->info;
  104698. int samples_per_partition=info->grouping;
  104699. int partitions_per_word=look->phrasebook->dim;
  104700. int n=info->end-info->begin;
  104701. int partvals=n/samples_per_partition;
  104702. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104703. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104704. for(j=0;j<ch;j++)
  104705. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104706. for(s=0;s<look->stages;s++){
  104707. for(i=0,l=0;i<partvals;l++){
  104708. if(s==0){
  104709. for(j=0;j<ch;j++){
  104710. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104711. if(temp==-1)goto eopbreak;
  104712. partword[j][l]=look->decodemap[temp];
  104713. if(partword[j][l]==NULL)goto errout;
  104714. }
  104715. }
  104716. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104717. for(j=0;j<ch;j++){
  104718. long offset=info->begin+i*samples_per_partition;
  104719. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104720. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104721. if(stagebook){
  104722. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104723. samples_per_partition)==-1)goto eopbreak;
  104724. }
  104725. }
  104726. }
  104727. }
  104728. }
  104729. errout:
  104730. eopbreak:
  104731. return(0);
  104732. }
  104733. #if 0
  104734. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104735. float **in,int *nonzero,int ch){
  104736. int i,used=0;
  104737. for(i=0;i<ch;i++)
  104738. if(nonzero[i])
  104739. in[used++]=in[i];
  104740. if(used)
  104741. return(_01class(vb,vl,in,used));
  104742. else
  104743. return(0);
  104744. }
  104745. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104746. float **in,float **out,int *nonzero,int ch,
  104747. long **partword){
  104748. int i,j,used=0,n=vb->pcmend/2;
  104749. for(i=0;i<ch;i++)
  104750. if(nonzero[i]){
  104751. if(out)
  104752. for(j=0;j<n;j++)
  104753. out[i][j]+=in[i][j];
  104754. in[used++]=in[i];
  104755. }
  104756. if(used){
  104757. int ret=_01forward(vb,vl,in,used,partword,
  104758. _interleaved_encodepart);
  104759. if(out){
  104760. used=0;
  104761. for(i=0;i<ch;i++)
  104762. if(nonzero[i]){
  104763. for(j=0;j<n;j++)
  104764. out[i][j]-=in[used][j];
  104765. used++;
  104766. }
  104767. }
  104768. return(ret);
  104769. }else{
  104770. return(0);
  104771. }
  104772. }
  104773. #endif
  104774. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104775. float **in,int *nonzero,int ch){
  104776. int i,used=0;
  104777. for(i=0;i<ch;i++)
  104778. if(nonzero[i])
  104779. in[used++]=in[i];
  104780. if(used)
  104781. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104782. else
  104783. return(0);
  104784. }
  104785. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104786. float **in,float **out,int *nonzero,int ch,
  104787. long **partword){
  104788. int i,j,used=0,n=vb->pcmend/2;
  104789. for(i=0;i<ch;i++)
  104790. if(nonzero[i]){
  104791. if(out)
  104792. for(j=0;j<n;j++)
  104793. out[i][j]+=in[i][j];
  104794. in[used++]=in[i];
  104795. }
  104796. if(used){
  104797. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104798. if(out){
  104799. used=0;
  104800. for(i=0;i<ch;i++)
  104801. if(nonzero[i]){
  104802. for(j=0;j<n;j++)
  104803. out[i][j]-=in[used][j];
  104804. used++;
  104805. }
  104806. }
  104807. return(ret);
  104808. }else{
  104809. return(0);
  104810. }
  104811. }
  104812. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104813. float **in,int *nonzero,int ch){
  104814. int i,used=0;
  104815. for(i=0;i<ch;i++)
  104816. if(nonzero[i])
  104817. in[used++]=in[i];
  104818. if(used)
  104819. return(_01class(vb,vl,in,used));
  104820. else
  104821. return(0);
  104822. }
  104823. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104824. float **in,int *nonzero,int ch){
  104825. int i,used=0;
  104826. for(i=0;i<ch;i++)
  104827. if(nonzero[i])
  104828. in[used++]=in[i];
  104829. if(used)
  104830. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104831. else
  104832. return(0);
  104833. }
  104834. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104835. float **in,int *nonzero,int ch){
  104836. int i,used=0;
  104837. for(i=0;i<ch;i++)
  104838. if(nonzero[i])used++;
  104839. if(used)
  104840. return(_2class(vb,vl,in,ch));
  104841. else
  104842. return(0);
  104843. }
  104844. int res2_forward(oggpack_buffer *opb,
  104845. vorbis_block *vb,vorbis_look_residue *vl,
  104846. float **in,float **out,int *nonzero,int ch,
  104847. long **partword){
  104848. long i,j,k,n=vb->pcmend/2,used=0;
  104849. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104850. for(i=0;i<ch;i++){
  104851. float *pcm=in[i];
  104852. if(nonzero[i])used++;
  104853. for(j=0,k=i;j<n;j++,k+=ch)
  104854. work[k]=pcm[j];
  104855. }
  104856. if(used){
  104857. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104858. if(out){
  104859. for(i=0;i<ch;i++){
  104860. float *pcm=in[i];
  104861. float *sofar=out[i];
  104862. for(j=0,k=i;j<n;j++,k+=ch)
  104863. sofar[j]+=pcm[j]-work[k];
  104864. }
  104865. }
  104866. return(ret);
  104867. }else{
  104868. return(0);
  104869. }
  104870. }
  104871. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104872. float **in,int *nonzero,int ch){
  104873. long i,k,l,s;
  104874. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104875. vorbis_info_residue0 *info=look->info;
  104876. int samples_per_partition=info->grouping;
  104877. int partitions_per_word=look->phrasebook->dim;
  104878. int n=info->end-info->begin;
  104879. int partvals=n/samples_per_partition;
  104880. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104881. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104882. for(i=0;i<ch;i++)if(nonzero[i])break;
  104883. if(i==ch)return(0); /* no nonzero vectors */
  104884. for(s=0;s<look->stages;s++){
  104885. for(i=0,l=0;i<partvals;l++){
  104886. if(s==0){
  104887. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104888. if(temp==-1)goto eopbreak;
  104889. partword[l]=look->decodemap[temp];
  104890. if(partword[l]==NULL)goto errout;
  104891. }
  104892. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104893. if(info->secondstages[partword[l][k]]&(1<<s)){
  104894. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104895. if(stagebook){
  104896. if(vorbis_book_decodevv_add(stagebook,in,
  104897. i*samples_per_partition+info->begin,ch,
  104898. &vb->opb,samples_per_partition)==-1)
  104899. goto eopbreak;
  104900. }
  104901. }
  104902. }
  104903. }
  104904. errout:
  104905. eopbreak:
  104906. return(0);
  104907. }
  104908. vorbis_func_residue residue0_exportbundle={
  104909. NULL,
  104910. &res0_unpack,
  104911. &res0_look,
  104912. &res0_free_info,
  104913. &res0_free_look,
  104914. NULL,
  104915. NULL,
  104916. &res0_inverse
  104917. };
  104918. vorbis_func_residue residue1_exportbundle={
  104919. &res0_pack,
  104920. &res0_unpack,
  104921. &res0_look,
  104922. &res0_free_info,
  104923. &res0_free_look,
  104924. &res1_class,
  104925. &res1_forward,
  104926. &res1_inverse
  104927. };
  104928. vorbis_func_residue residue2_exportbundle={
  104929. &res0_pack,
  104930. &res0_unpack,
  104931. &res0_look,
  104932. &res0_free_info,
  104933. &res0_free_look,
  104934. &res2_class,
  104935. &res2_forward,
  104936. &res2_inverse
  104937. };
  104938. #endif
  104939. /*** End of inlined file: res0.c ***/
  104940. /*** Start of inlined file: sharedbook.c ***/
  104941. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104942. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104943. // tasks..
  104944. #if JUCE_MSVC
  104945. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104946. #endif
  104947. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104948. #if JUCE_USE_OGGVORBIS
  104949. #include <stdlib.h>
  104950. #include <math.h>
  104951. #include <string.h>
  104952. int _ilog(unsigned int v){
  104953. int ret=0;
  104954. while(v){
  104955. ret++;
  104956. v>>=1;
  104957. }
  104958. return(ret);
  104959. }
  104960. #define VQ_FEXP 10
  104961. #define VQ_FMAN 21
  104962. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104963. long _float32_pack(float val){
  104964. int sign=0;
  104965. long exp;
  104966. long mant;
  104967. if(val<0){
  104968. sign=0x80000000;
  104969. val= -val;
  104970. }
  104971. exp= floor(log(val)/log(2.f));
  104972. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104973. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104974. return(sign|exp|mant);
  104975. }
  104976. float _float32_unpack(long val){
  104977. double mant=val&0x1fffff;
  104978. int sign=val&0x80000000;
  104979. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104980. if(sign)mant= -mant;
  104981. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104982. }
  104983. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104984. long i,j,count=0;
  104985. ogg_uint32_t marker[33];
  104986. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104987. memset(marker,0,sizeof(marker));
  104988. for(i=0;i<n;i++){
  104989. long length=l[i];
  104990. if(length>0){
  104991. ogg_uint32_t entry=marker[length];
  104992. if(length<32 && (entry>>length)){
  104993. _ogg_free(r);
  104994. return(NULL);
  104995. }
  104996. r[count++]=entry;
  104997. {
  104998. for(j=length;j>0;j--){
  104999. if(marker[j]&1){
  105000. if(j==1)
  105001. marker[1]++;
  105002. else
  105003. marker[j]=marker[j-1]<<1;
  105004. break; /* invariant says next upper marker would already
  105005. have been moved if it was on the same path */
  105006. }
  105007. marker[j]++;
  105008. }
  105009. }
  105010. for(j=length+1;j<33;j++)
  105011. if((marker[j]>>1) == entry){
  105012. entry=marker[j];
  105013. marker[j]=marker[j-1]<<1;
  105014. }else
  105015. break;
  105016. }else
  105017. if(sparsecount==0)count++;
  105018. }
  105019. for(i=0,count=0;i<n;i++){
  105020. ogg_uint32_t temp=0;
  105021. for(j=0;j<l[i];j++){
  105022. temp<<=1;
  105023. temp|=(r[count]>>j)&1;
  105024. }
  105025. if(sparsecount){
  105026. if(l[i])
  105027. r[count++]=temp;
  105028. }else
  105029. r[count++]=temp;
  105030. }
  105031. return(r);
  105032. }
  105033. long _book_maptype1_quantvals(const static_codebook *b){
  105034. long vals=floor(pow((float)b->entries,1.f/b->dim));
  105035. while(1){
  105036. long acc=1;
  105037. long acc1=1;
  105038. int i;
  105039. for(i=0;i<b->dim;i++){
  105040. acc*=vals;
  105041. acc1*=vals+1;
  105042. }
  105043. if(acc<=b->entries && acc1>b->entries){
  105044. return(vals);
  105045. }else{
  105046. if(acc>b->entries){
  105047. vals--;
  105048. }else{
  105049. vals++;
  105050. }
  105051. }
  105052. }
  105053. }
  105054. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  105055. long j,k,count=0;
  105056. if(b->maptype==1 || b->maptype==2){
  105057. int quantvals;
  105058. float mindel=_float32_unpack(b->q_min);
  105059. float delta=_float32_unpack(b->q_delta);
  105060. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  105061. switch(b->maptype){
  105062. case 1:
  105063. quantvals=_book_maptype1_quantvals(b);
  105064. for(j=0;j<b->entries;j++){
  105065. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105066. float last=0.f;
  105067. int indexdiv=1;
  105068. for(k=0;k<b->dim;k++){
  105069. int index= (j/indexdiv)%quantvals;
  105070. float val=b->quantlist[index];
  105071. val=fabs(val)*delta+mindel+last;
  105072. if(b->q_sequencep)last=val;
  105073. if(sparsemap)
  105074. r[sparsemap[count]*b->dim+k]=val;
  105075. else
  105076. r[count*b->dim+k]=val;
  105077. indexdiv*=quantvals;
  105078. }
  105079. count++;
  105080. }
  105081. }
  105082. break;
  105083. case 2:
  105084. for(j=0;j<b->entries;j++){
  105085. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105086. float last=0.f;
  105087. for(k=0;k<b->dim;k++){
  105088. float val=b->quantlist[j*b->dim+k];
  105089. val=fabs(val)*delta+mindel+last;
  105090. if(b->q_sequencep)last=val;
  105091. if(sparsemap)
  105092. r[sparsemap[count]*b->dim+k]=val;
  105093. else
  105094. r[count*b->dim+k]=val;
  105095. }
  105096. count++;
  105097. }
  105098. }
  105099. break;
  105100. }
  105101. return(r);
  105102. }
  105103. return(NULL);
  105104. }
  105105. void vorbis_staticbook_clear(static_codebook *b){
  105106. if(b->allocedp){
  105107. if(b->quantlist)_ogg_free(b->quantlist);
  105108. if(b->lengthlist)_ogg_free(b->lengthlist);
  105109. if(b->nearest_tree){
  105110. _ogg_free(b->nearest_tree->ptr0);
  105111. _ogg_free(b->nearest_tree->ptr1);
  105112. _ogg_free(b->nearest_tree->p);
  105113. _ogg_free(b->nearest_tree->q);
  105114. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  105115. _ogg_free(b->nearest_tree);
  105116. }
  105117. if(b->thresh_tree){
  105118. _ogg_free(b->thresh_tree->quantthresh);
  105119. _ogg_free(b->thresh_tree->quantmap);
  105120. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  105121. _ogg_free(b->thresh_tree);
  105122. }
  105123. memset(b,0,sizeof(*b));
  105124. }
  105125. }
  105126. void vorbis_staticbook_destroy(static_codebook *b){
  105127. if(b->allocedp){
  105128. vorbis_staticbook_clear(b);
  105129. _ogg_free(b);
  105130. }
  105131. }
  105132. void vorbis_book_clear(codebook *b){
  105133. if(b->valuelist)_ogg_free(b->valuelist);
  105134. if(b->codelist)_ogg_free(b->codelist);
  105135. if(b->dec_index)_ogg_free(b->dec_index);
  105136. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  105137. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  105138. memset(b,0,sizeof(*b));
  105139. }
  105140. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  105141. memset(c,0,sizeof(*c));
  105142. c->c=s;
  105143. c->entries=s->entries;
  105144. c->used_entries=s->entries;
  105145. c->dim=s->dim;
  105146. c->codelist=_make_words(s->lengthlist,s->entries,0);
  105147. c->valuelist=_book_unquantize(s,s->entries,NULL);
  105148. return(0);
  105149. }
  105150. static int sort32a(const void *a,const void *b){
  105151. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  105152. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  105153. }
  105154. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  105155. int i,j,n=0,tabn;
  105156. int *sortindex;
  105157. memset(c,0,sizeof(*c));
  105158. for(i=0;i<s->entries;i++)
  105159. if(s->lengthlist[i]>0)
  105160. n++;
  105161. c->entries=s->entries;
  105162. c->used_entries=n;
  105163. c->dim=s->dim;
  105164. {
  105165. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  105166. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  105167. if(codes==NULL)goto err_out;
  105168. for(i=0;i<n;i++){
  105169. codes[i]=ogg_bitreverse(codes[i]);
  105170. codep[i]=codes+i;
  105171. }
  105172. qsort(codep,n,sizeof(*codep),sort32a);
  105173. sortindex=(int*)alloca(n*sizeof(*sortindex));
  105174. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  105175. for(i=0;i<n;i++){
  105176. int position=codep[i]-codes;
  105177. sortindex[position]=i;
  105178. }
  105179. for(i=0;i<n;i++)
  105180. c->codelist[sortindex[i]]=codes[i];
  105181. _ogg_free(codes);
  105182. }
  105183. c->valuelist=_book_unquantize(s,n,sortindex);
  105184. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  105185. for(n=0,i=0;i<s->entries;i++)
  105186. if(s->lengthlist[i]>0)
  105187. c->dec_index[sortindex[n++]]=i;
  105188. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  105189. for(n=0,i=0;i<s->entries;i++)
  105190. if(s->lengthlist[i]>0)
  105191. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  105192. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  105193. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  105194. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  105195. tabn=1<<c->dec_firsttablen;
  105196. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  105197. c->dec_maxlength=0;
  105198. for(i=0;i<n;i++){
  105199. if(c->dec_maxlength<c->dec_codelengths[i])
  105200. c->dec_maxlength=c->dec_codelengths[i];
  105201. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  105202. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  105203. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  105204. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  105205. }
  105206. }
  105207. {
  105208. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  105209. long lo=0,hi=0;
  105210. for(i=0;i<tabn;i++){
  105211. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  105212. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  105213. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  105214. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  105215. {
  105216. unsigned long loval=lo;
  105217. unsigned long hival=n-hi;
  105218. if(loval>0x7fff)loval=0x7fff;
  105219. if(hival>0x7fff)hival=0x7fff;
  105220. c->dec_firsttable[ogg_bitreverse(word)]=
  105221. 0x80000000UL | (loval<<15) | hival;
  105222. }
  105223. }
  105224. }
  105225. }
  105226. return(0);
  105227. err_out:
  105228. vorbis_book_clear(c);
  105229. return(-1);
  105230. }
  105231. static float _dist(int el,float *ref, float *b,int step){
  105232. int i;
  105233. float acc=0.f;
  105234. for(i=0;i<el;i++){
  105235. float val=(ref[i]-b[i*step]);
  105236. acc+=val*val;
  105237. }
  105238. return(acc);
  105239. }
  105240. int _best(codebook *book, float *a, int step){
  105241. encode_aux_threshmatch *tt=book->c->thresh_tree;
  105242. #if 0
  105243. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  105244. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  105245. #endif
  105246. int dim=book->dim;
  105247. int k,o;
  105248. if(tt){
  105249. int index=0,i;
  105250. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105251. i=tt->threshvals>>1;
  105252. if(a[o]<tt->quantthresh[i]){
  105253. for(;i>0;i--)
  105254. if(a[o]>=tt->quantthresh[i-1])
  105255. break;
  105256. }else{
  105257. for(i++;i<tt->threshvals-1;i++)
  105258. if(a[o]<tt->quantthresh[i])break;
  105259. }
  105260. index=(index*tt->quantvals)+tt->quantmap[i];
  105261. }
  105262. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  105263. use a decision tree after all
  105264. and fall through*/
  105265. return(index);
  105266. }
  105267. #if 0
  105268. if(pt){
  105269. const static_codebook *c=book->c;
  105270. int i,besti=-1;
  105271. float best=0.f;
  105272. int entry=0;
  105273. if(c->q_sequencep){
  105274. int pv;
  105275. long mul=1;
  105276. float qlast=0;
  105277. for(k=0,o=0;k<dim;k++,o+=step){
  105278. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  105279. if(pv<0 || pv>=pt->mapentries)break;
  105280. entry+=pt->pigeonmap[pv]*mul;
  105281. mul*=pt->quantvals;
  105282. qlast+=pv*pt->del+pt->min;
  105283. }
  105284. }else{
  105285. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105286. int pv=(int)((a[o]-pt->min)/pt->del);
  105287. if(pv<0 || pv>=pt->mapentries)break;
  105288. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105289. }
  105290. }
  105291. if(k==dim && pt->fitlength[entry]){
  105292. long *list=pt->fitlist+pt->fitmap[entry];
  105293. for(i=0;i<pt->fitlength[entry];i++){
  105294. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105295. if(besti==-1 || this<best){
  105296. best=this;
  105297. besti=list[i];
  105298. }
  105299. }
  105300. return(besti);
  105301. }
  105302. }
  105303. if(nt){
  105304. while(1){
  105305. float c=0.f;
  105306. float *p=book->valuelist+nt->p[ptr];
  105307. float *q=book->valuelist+nt->q[ptr];
  105308. for(k=0,o=0;k<dim;k++,o+=step)
  105309. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105310. if(c>0.f) /* in A */
  105311. ptr= -nt->ptr0[ptr];
  105312. else /* in B */
  105313. ptr= -nt->ptr1[ptr];
  105314. if(ptr<=0)break;
  105315. }
  105316. return(-ptr);
  105317. }
  105318. #endif
  105319. {
  105320. const static_codebook *c=book->c;
  105321. int i,besti=-1;
  105322. float best=0.f;
  105323. float *e=book->valuelist;
  105324. for(i=0;i<book->entries;i++){
  105325. if(c->lengthlist[i]>0){
  105326. float thisx=_dist(dim,e,a,step);
  105327. if(besti==-1 || thisx<best){
  105328. best=thisx;
  105329. besti=i;
  105330. }
  105331. }
  105332. e+=dim;
  105333. }
  105334. return(besti);
  105335. }
  105336. }
  105337. long vorbis_book_codeword(codebook *book,int entry){
  105338. if(book->c) /* only use with encode; decode optimizations are
  105339. allowed to break this */
  105340. return book->codelist[entry];
  105341. return -1;
  105342. }
  105343. long vorbis_book_codelen(codebook *book,int entry){
  105344. if(book->c) /* only use with encode; decode optimizations are
  105345. allowed to break this */
  105346. return book->c->lengthlist[entry];
  105347. return -1;
  105348. }
  105349. #ifdef _V_SELFTEST
  105350. #include <stdio.h>
  105351. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105352. static long partial_quantlist1[]={0,7,2};
  105353. static_codebook test1={
  105354. 4,16,
  105355. NULL,
  105356. 0,
  105357. 0,0,0,0,
  105358. NULL,
  105359. NULL,NULL
  105360. };
  105361. static float *test1_result=NULL;
  105362. static_codebook test2={
  105363. 4,3,
  105364. NULL,
  105365. 2,
  105366. -533200896,1611661312,4,0,
  105367. full_quantlist1,
  105368. NULL,NULL
  105369. };
  105370. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105371. static_codebook test3={
  105372. 4,3,
  105373. NULL,
  105374. 2,
  105375. -533200896,1611661312,4,1,
  105376. full_quantlist1,
  105377. NULL,NULL
  105378. };
  105379. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105380. static_codebook test4={
  105381. 3,27,
  105382. NULL,
  105383. 1,
  105384. -533200896,1611661312,4,0,
  105385. partial_quantlist1,
  105386. NULL,NULL
  105387. };
  105388. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105389. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105390. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105391. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105392. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105393. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105394. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105395. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105396. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105397. static_codebook test5={
  105398. 3,27,
  105399. NULL,
  105400. 1,
  105401. -533200896,1611661312,4,1,
  105402. partial_quantlist1,
  105403. NULL,NULL
  105404. };
  105405. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105406. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105407. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105408. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105409. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105410. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105411. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105412. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105413. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105414. void run_test(static_codebook *b,float *comp){
  105415. float *out=_book_unquantize(b,b->entries,NULL);
  105416. int i;
  105417. if(comp){
  105418. if(!out){
  105419. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105420. exit(1);
  105421. }
  105422. for(i=0;i<b->entries*b->dim;i++)
  105423. if(fabs(out[i]-comp[i])>.0001){
  105424. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105425. "position %d, %g != %g\n",i,out[i],comp[i]);
  105426. exit(1);
  105427. }
  105428. }else{
  105429. if(out){
  105430. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105431. " correct result should have been NULL\n");
  105432. exit(1);
  105433. }
  105434. }
  105435. }
  105436. int main(){
  105437. fprintf(stderr,"Dequant test 1... ");
  105438. run_test(&test1,test1_result);
  105439. fprintf(stderr,"OK\nDequant test 2... ");
  105440. run_test(&test2,test2_result);
  105441. fprintf(stderr,"OK\nDequant test 3... ");
  105442. run_test(&test3,test3_result);
  105443. fprintf(stderr,"OK\nDequant test 4... ");
  105444. run_test(&test4,test4_result);
  105445. fprintf(stderr,"OK\nDequant test 5... ");
  105446. run_test(&test5,test5_result);
  105447. fprintf(stderr,"OK\n\n");
  105448. return(0);
  105449. }
  105450. #endif
  105451. #endif
  105452. /*** End of inlined file: sharedbook.c ***/
  105453. /*** Start of inlined file: smallft.c ***/
  105454. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105455. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105456. // tasks..
  105457. #if JUCE_MSVC
  105458. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105459. #endif
  105460. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105461. #if JUCE_USE_OGGVORBIS
  105462. #include <stdlib.h>
  105463. #include <string.h>
  105464. #include <math.h>
  105465. static void drfti1(int n, float *wa, int *ifac){
  105466. static int ntryh[4] = { 4,2,3,5 };
  105467. static float tpi = 6.28318530717958648f;
  105468. float arg,argh,argld,fi;
  105469. int ntry=0,i,j=-1;
  105470. int k1, l1, l2, ib;
  105471. int ld, ii, ip, is, nq, nr;
  105472. int ido, ipm, nfm1;
  105473. int nl=n;
  105474. int nf=0;
  105475. L101:
  105476. j++;
  105477. if (j < 4)
  105478. ntry=ntryh[j];
  105479. else
  105480. ntry+=2;
  105481. L104:
  105482. nq=nl/ntry;
  105483. nr=nl-ntry*nq;
  105484. if (nr!=0) goto L101;
  105485. nf++;
  105486. ifac[nf+1]=ntry;
  105487. nl=nq;
  105488. if(ntry!=2)goto L107;
  105489. if(nf==1)goto L107;
  105490. for (i=1;i<nf;i++){
  105491. ib=nf-i+1;
  105492. ifac[ib+1]=ifac[ib];
  105493. }
  105494. ifac[2] = 2;
  105495. L107:
  105496. if(nl!=1)goto L104;
  105497. ifac[0]=n;
  105498. ifac[1]=nf;
  105499. argh=tpi/n;
  105500. is=0;
  105501. nfm1=nf-1;
  105502. l1=1;
  105503. if(nfm1==0)return;
  105504. for (k1=0;k1<nfm1;k1++){
  105505. ip=ifac[k1+2];
  105506. ld=0;
  105507. l2=l1*ip;
  105508. ido=n/l2;
  105509. ipm=ip-1;
  105510. for (j=0;j<ipm;j++){
  105511. ld+=l1;
  105512. i=is;
  105513. argld=(float)ld*argh;
  105514. fi=0.f;
  105515. for (ii=2;ii<ido;ii+=2){
  105516. fi+=1.f;
  105517. arg=fi*argld;
  105518. wa[i++]=cos(arg);
  105519. wa[i++]=sin(arg);
  105520. }
  105521. is+=ido;
  105522. }
  105523. l1=l2;
  105524. }
  105525. }
  105526. static void fdrffti(int n, float *wsave, int *ifac){
  105527. if (n == 1) return;
  105528. drfti1(n, wsave+n, ifac);
  105529. }
  105530. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105531. int i,k;
  105532. float ti2,tr2;
  105533. int t0,t1,t2,t3,t4,t5,t6;
  105534. t1=0;
  105535. t0=(t2=l1*ido);
  105536. t3=ido<<1;
  105537. for(k=0;k<l1;k++){
  105538. ch[t1<<1]=cc[t1]+cc[t2];
  105539. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105540. t1+=ido;
  105541. t2+=ido;
  105542. }
  105543. if(ido<2)return;
  105544. if(ido==2)goto L105;
  105545. t1=0;
  105546. t2=t0;
  105547. for(k=0;k<l1;k++){
  105548. t3=t2;
  105549. t4=(t1<<1)+(ido<<1);
  105550. t5=t1;
  105551. t6=t1+t1;
  105552. for(i=2;i<ido;i+=2){
  105553. t3+=2;
  105554. t4-=2;
  105555. t5+=2;
  105556. t6+=2;
  105557. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105558. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105559. ch[t6]=cc[t5]+ti2;
  105560. ch[t4]=ti2-cc[t5];
  105561. ch[t6-1]=cc[t5-1]+tr2;
  105562. ch[t4-1]=cc[t5-1]-tr2;
  105563. }
  105564. t1+=ido;
  105565. t2+=ido;
  105566. }
  105567. if(ido%2==1)return;
  105568. L105:
  105569. t3=(t2=(t1=ido)-1);
  105570. t2+=t0;
  105571. for(k=0;k<l1;k++){
  105572. ch[t1]=-cc[t2];
  105573. ch[t1-1]=cc[t3];
  105574. t1+=ido<<1;
  105575. t2+=ido;
  105576. t3+=ido;
  105577. }
  105578. }
  105579. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105580. float *wa2,float *wa3){
  105581. static float hsqt2 = .70710678118654752f;
  105582. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105583. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105584. t0=l1*ido;
  105585. t1=t0;
  105586. t4=t1<<1;
  105587. t2=t1+(t1<<1);
  105588. t3=0;
  105589. for(k=0;k<l1;k++){
  105590. tr1=cc[t1]+cc[t2];
  105591. tr2=cc[t3]+cc[t4];
  105592. ch[t5=t3<<2]=tr1+tr2;
  105593. ch[(ido<<2)+t5-1]=tr2-tr1;
  105594. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105595. ch[t5]=cc[t2]-cc[t1];
  105596. t1+=ido;
  105597. t2+=ido;
  105598. t3+=ido;
  105599. t4+=ido;
  105600. }
  105601. if(ido<2)return;
  105602. if(ido==2)goto L105;
  105603. t1=0;
  105604. for(k=0;k<l1;k++){
  105605. t2=t1;
  105606. t4=t1<<2;
  105607. t5=(t6=ido<<1)+t4;
  105608. for(i=2;i<ido;i+=2){
  105609. t3=(t2+=2);
  105610. t4+=2;
  105611. t5-=2;
  105612. t3+=t0;
  105613. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105614. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105615. t3+=t0;
  105616. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105617. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105618. t3+=t0;
  105619. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105620. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105621. tr1=cr2+cr4;
  105622. tr4=cr4-cr2;
  105623. ti1=ci2+ci4;
  105624. ti4=ci2-ci4;
  105625. ti2=cc[t2]+ci3;
  105626. ti3=cc[t2]-ci3;
  105627. tr2=cc[t2-1]+cr3;
  105628. tr3=cc[t2-1]-cr3;
  105629. ch[t4-1]=tr1+tr2;
  105630. ch[t4]=ti1+ti2;
  105631. ch[t5-1]=tr3-ti4;
  105632. ch[t5]=tr4-ti3;
  105633. ch[t4+t6-1]=ti4+tr3;
  105634. ch[t4+t6]=tr4+ti3;
  105635. ch[t5+t6-1]=tr2-tr1;
  105636. ch[t5+t6]=ti1-ti2;
  105637. }
  105638. t1+=ido;
  105639. }
  105640. if(ido&1)return;
  105641. L105:
  105642. t2=(t1=t0+ido-1)+(t0<<1);
  105643. t3=ido<<2;
  105644. t4=ido;
  105645. t5=ido<<1;
  105646. t6=ido;
  105647. for(k=0;k<l1;k++){
  105648. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105649. tr1=hsqt2*(cc[t1]-cc[t2]);
  105650. ch[t4-1]=tr1+cc[t6-1];
  105651. ch[t4+t5-1]=cc[t6-1]-tr1;
  105652. ch[t4]=ti1-cc[t1+t0];
  105653. ch[t4+t5]=ti1+cc[t1+t0];
  105654. t1+=ido;
  105655. t2+=ido;
  105656. t4+=t3;
  105657. t6+=ido;
  105658. }
  105659. }
  105660. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105661. float *c2,float *ch,float *ch2,float *wa){
  105662. static float tpi=6.283185307179586f;
  105663. int idij,ipph,i,j,k,l,ic,ik,is;
  105664. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105665. float dc2,ai1,ai2,ar1,ar2,ds2;
  105666. int nbd;
  105667. float dcp,arg,dsp,ar1h,ar2h;
  105668. int idp2,ipp2;
  105669. arg=tpi/(float)ip;
  105670. dcp=cos(arg);
  105671. dsp=sin(arg);
  105672. ipph=(ip+1)>>1;
  105673. ipp2=ip;
  105674. idp2=ido;
  105675. nbd=(ido-1)>>1;
  105676. t0=l1*ido;
  105677. t10=ip*ido;
  105678. if(ido==1)goto L119;
  105679. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105680. t1=0;
  105681. for(j=1;j<ip;j++){
  105682. t1+=t0;
  105683. t2=t1;
  105684. for(k=0;k<l1;k++){
  105685. ch[t2]=c1[t2];
  105686. t2+=ido;
  105687. }
  105688. }
  105689. is=-ido;
  105690. t1=0;
  105691. if(nbd>l1){
  105692. for(j=1;j<ip;j++){
  105693. t1+=t0;
  105694. is+=ido;
  105695. t2= -ido+t1;
  105696. for(k=0;k<l1;k++){
  105697. idij=is-1;
  105698. t2+=ido;
  105699. t3=t2;
  105700. for(i=2;i<ido;i+=2){
  105701. idij+=2;
  105702. t3+=2;
  105703. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105704. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105705. }
  105706. }
  105707. }
  105708. }else{
  105709. for(j=1;j<ip;j++){
  105710. is+=ido;
  105711. idij=is-1;
  105712. t1+=t0;
  105713. t2=t1;
  105714. for(i=2;i<ido;i+=2){
  105715. idij+=2;
  105716. t2+=2;
  105717. t3=t2;
  105718. for(k=0;k<l1;k++){
  105719. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105720. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105721. t3+=ido;
  105722. }
  105723. }
  105724. }
  105725. }
  105726. t1=0;
  105727. t2=ipp2*t0;
  105728. if(nbd<l1){
  105729. for(j=1;j<ipph;j++){
  105730. t1+=t0;
  105731. t2-=t0;
  105732. t3=t1;
  105733. t4=t2;
  105734. for(i=2;i<ido;i+=2){
  105735. t3+=2;
  105736. t4+=2;
  105737. t5=t3-ido;
  105738. t6=t4-ido;
  105739. for(k=0;k<l1;k++){
  105740. t5+=ido;
  105741. t6+=ido;
  105742. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105743. c1[t6-1]=ch[t5]-ch[t6];
  105744. c1[t5]=ch[t5]+ch[t6];
  105745. c1[t6]=ch[t6-1]-ch[t5-1];
  105746. }
  105747. }
  105748. }
  105749. }else{
  105750. for(j=1;j<ipph;j++){
  105751. t1+=t0;
  105752. t2-=t0;
  105753. t3=t1;
  105754. t4=t2;
  105755. for(k=0;k<l1;k++){
  105756. t5=t3;
  105757. t6=t4;
  105758. for(i=2;i<ido;i+=2){
  105759. t5+=2;
  105760. t6+=2;
  105761. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105762. c1[t6-1]=ch[t5]-ch[t6];
  105763. c1[t5]=ch[t5]+ch[t6];
  105764. c1[t6]=ch[t6-1]-ch[t5-1];
  105765. }
  105766. t3+=ido;
  105767. t4+=ido;
  105768. }
  105769. }
  105770. }
  105771. L119:
  105772. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105773. t1=0;
  105774. t2=ipp2*idl1;
  105775. for(j=1;j<ipph;j++){
  105776. t1+=t0;
  105777. t2-=t0;
  105778. t3=t1-ido;
  105779. t4=t2-ido;
  105780. for(k=0;k<l1;k++){
  105781. t3+=ido;
  105782. t4+=ido;
  105783. c1[t3]=ch[t3]+ch[t4];
  105784. c1[t4]=ch[t4]-ch[t3];
  105785. }
  105786. }
  105787. ar1=1.f;
  105788. ai1=0.f;
  105789. t1=0;
  105790. t2=ipp2*idl1;
  105791. t3=(ip-1)*idl1;
  105792. for(l=1;l<ipph;l++){
  105793. t1+=idl1;
  105794. t2-=idl1;
  105795. ar1h=dcp*ar1-dsp*ai1;
  105796. ai1=dcp*ai1+dsp*ar1;
  105797. ar1=ar1h;
  105798. t4=t1;
  105799. t5=t2;
  105800. t6=t3;
  105801. t7=idl1;
  105802. for(ik=0;ik<idl1;ik++){
  105803. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105804. ch2[t5++]=ai1*c2[t6++];
  105805. }
  105806. dc2=ar1;
  105807. ds2=ai1;
  105808. ar2=ar1;
  105809. ai2=ai1;
  105810. t4=idl1;
  105811. t5=(ipp2-1)*idl1;
  105812. for(j=2;j<ipph;j++){
  105813. t4+=idl1;
  105814. t5-=idl1;
  105815. ar2h=dc2*ar2-ds2*ai2;
  105816. ai2=dc2*ai2+ds2*ar2;
  105817. ar2=ar2h;
  105818. t6=t1;
  105819. t7=t2;
  105820. t8=t4;
  105821. t9=t5;
  105822. for(ik=0;ik<idl1;ik++){
  105823. ch2[t6++]+=ar2*c2[t8++];
  105824. ch2[t7++]+=ai2*c2[t9++];
  105825. }
  105826. }
  105827. }
  105828. t1=0;
  105829. for(j=1;j<ipph;j++){
  105830. t1+=idl1;
  105831. t2=t1;
  105832. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105833. }
  105834. if(ido<l1)goto L132;
  105835. t1=0;
  105836. t2=0;
  105837. for(k=0;k<l1;k++){
  105838. t3=t1;
  105839. t4=t2;
  105840. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105841. t1+=ido;
  105842. t2+=t10;
  105843. }
  105844. goto L135;
  105845. L132:
  105846. for(i=0;i<ido;i++){
  105847. t1=i;
  105848. t2=i;
  105849. for(k=0;k<l1;k++){
  105850. cc[t2]=ch[t1];
  105851. t1+=ido;
  105852. t2+=t10;
  105853. }
  105854. }
  105855. L135:
  105856. t1=0;
  105857. t2=ido<<1;
  105858. t3=0;
  105859. t4=ipp2*t0;
  105860. for(j=1;j<ipph;j++){
  105861. t1+=t2;
  105862. t3+=t0;
  105863. t4-=t0;
  105864. t5=t1;
  105865. t6=t3;
  105866. t7=t4;
  105867. for(k=0;k<l1;k++){
  105868. cc[t5-1]=ch[t6];
  105869. cc[t5]=ch[t7];
  105870. t5+=t10;
  105871. t6+=ido;
  105872. t7+=ido;
  105873. }
  105874. }
  105875. if(ido==1)return;
  105876. if(nbd<l1)goto L141;
  105877. t1=-ido;
  105878. t3=0;
  105879. t4=0;
  105880. t5=ipp2*t0;
  105881. for(j=1;j<ipph;j++){
  105882. t1+=t2;
  105883. t3+=t2;
  105884. t4+=t0;
  105885. t5-=t0;
  105886. t6=t1;
  105887. t7=t3;
  105888. t8=t4;
  105889. t9=t5;
  105890. for(k=0;k<l1;k++){
  105891. for(i=2;i<ido;i+=2){
  105892. ic=idp2-i;
  105893. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105894. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105895. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105896. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105897. }
  105898. t6+=t10;
  105899. t7+=t10;
  105900. t8+=ido;
  105901. t9+=ido;
  105902. }
  105903. }
  105904. return;
  105905. L141:
  105906. t1=-ido;
  105907. t3=0;
  105908. t4=0;
  105909. t5=ipp2*t0;
  105910. for(j=1;j<ipph;j++){
  105911. t1+=t2;
  105912. t3+=t2;
  105913. t4+=t0;
  105914. t5-=t0;
  105915. for(i=2;i<ido;i+=2){
  105916. t6=idp2+t1-i;
  105917. t7=i+t3;
  105918. t8=i+t4;
  105919. t9=i+t5;
  105920. for(k=0;k<l1;k++){
  105921. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105922. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105923. cc[t7]=ch[t8]+ch[t9];
  105924. cc[t6]=ch[t9]-ch[t8];
  105925. t6+=t10;
  105926. t7+=t10;
  105927. t8+=ido;
  105928. t9+=ido;
  105929. }
  105930. }
  105931. }
  105932. }
  105933. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105934. int i,k1,l1,l2;
  105935. int na,kh,nf;
  105936. int ip,iw,ido,idl1,ix2,ix3;
  105937. nf=ifac[1];
  105938. na=1;
  105939. l2=n;
  105940. iw=n;
  105941. for(k1=0;k1<nf;k1++){
  105942. kh=nf-k1;
  105943. ip=ifac[kh+1];
  105944. l1=l2/ip;
  105945. ido=n/l2;
  105946. idl1=ido*l1;
  105947. iw-=(ip-1)*ido;
  105948. na=1-na;
  105949. if(ip!=4)goto L102;
  105950. ix2=iw+ido;
  105951. ix3=ix2+ido;
  105952. if(na!=0)
  105953. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105954. else
  105955. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105956. goto L110;
  105957. L102:
  105958. if(ip!=2)goto L104;
  105959. if(na!=0)goto L103;
  105960. dradf2(ido,l1,c,ch,wa+iw-1);
  105961. goto L110;
  105962. L103:
  105963. dradf2(ido,l1,ch,c,wa+iw-1);
  105964. goto L110;
  105965. L104:
  105966. if(ido==1)na=1-na;
  105967. if(na!=0)goto L109;
  105968. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105969. na=1;
  105970. goto L110;
  105971. L109:
  105972. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105973. na=0;
  105974. L110:
  105975. l2=l1;
  105976. }
  105977. if(na==1)return;
  105978. for(i=0;i<n;i++)c[i]=ch[i];
  105979. }
  105980. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105981. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105982. float ti2,tr2;
  105983. t0=l1*ido;
  105984. t1=0;
  105985. t2=0;
  105986. t3=(ido<<1)-1;
  105987. for(k=0;k<l1;k++){
  105988. ch[t1]=cc[t2]+cc[t3+t2];
  105989. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105990. t2=(t1+=ido)<<1;
  105991. }
  105992. if(ido<2)return;
  105993. if(ido==2)goto L105;
  105994. t1=0;
  105995. t2=0;
  105996. for(k=0;k<l1;k++){
  105997. t3=t1;
  105998. t5=(t4=t2)+(ido<<1);
  105999. t6=t0+t1;
  106000. for(i=2;i<ido;i+=2){
  106001. t3+=2;
  106002. t4+=2;
  106003. t5-=2;
  106004. t6+=2;
  106005. ch[t3-1]=cc[t4-1]+cc[t5-1];
  106006. tr2=cc[t4-1]-cc[t5-1];
  106007. ch[t3]=cc[t4]-cc[t5];
  106008. ti2=cc[t4]+cc[t5];
  106009. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  106010. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  106011. }
  106012. t2=(t1+=ido)<<1;
  106013. }
  106014. if(ido%2==1)return;
  106015. L105:
  106016. t1=ido-1;
  106017. t2=ido-1;
  106018. for(k=0;k<l1;k++){
  106019. ch[t1]=cc[t2]+cc[t2];
  106020. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  106021. t1+=ido;
  106022. t2+=ido<<1;
  106023. }
  106024. }
  106025. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  106026. float *wa2){
  106027. static float taur = -.5f;
  106028. static float taui = .8660254037844386f;
  106029. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  106030. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  106031. t0=l1*ido;
  106032. t1=0;
  106033. t2=t0<<1;
  106034. t3=ido<<1;
  106035. t4=ido+(ido<<1);
  106036. t5=0;
  106037. for(k=0;k<l1;k++){
  106038. tr2=cc[t3-1]+cc[t3-1];
  106039. cr2=cc[t5]+(taur*tr2);
  106040. ch[t1]=cc[t5]+tr2;
  106041. ci3=taui*(cc[t3]+cc[t3]);
  106042. ch[t1+t0]=cr2-ci3;
  106043. ch[t1+t2]=cr2+ci3;
  106044. t1+=ido;
  106045. t3+=t4;
  106046. t5+=t4;
  106047. }
  106048. if(ido==1)return;
  106049. t1=0;
  106050. t3=ido<<1;
  106051. for(k=0;k<l1;k++){
  106052. t7=t1+(t1<<1);
  106053. t6=(t5=t7+t3);
  106054. t8=t1;
  106055. t10=(t9=t1+t0)+t0;
  106056. for(i=2;i<ido;i+=2){
  106057. t5+=2;
  106058. t6-=2;
  106059. t7+=2;
  106060. t8+=2;
  106061. t9+=2;
  106062. t10+=2;
  106063. tr2=cc[t5-1]+cc[t6-1];
  106064. cr2=cc[t7-1]+(taur*tr2);
  106065. ch[t8-1]=cc[t7-1]+tr2;
  106066. ti2=cc[t5]-cc[t6];
  106067. ci2=cc[t7]+(taur*ti2);
  106068. ch[t8]=cc[t7]+ti2;
  106069. cr3=taui*(cc[t5-1]-cc[t6-1]);
  106070. ci3=taui*(cc[t5]+cc[t6]);
  106071. dr2=cr2-ci3;
  106072. dr3=cr2+ci3;
  106073. di2=ci2+cr3;
  106074. di3=ci2-cr3;
  106075. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  106076. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  106077. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  106078. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  106079. }
  106080. t1+=ido;
  106081. }
  106082. }
  106083. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  106084. float *wa2,float *wa3){
  106085. static float sqrt2=1.414213562373095f;
  106086. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  106087. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  106088. t0=l1*ido;
  106089. t1=0;
  106090. t2=ido<<2;
  106091. t3=0;
  106092. t6=ido<<1;
  106093. for(k=0;k<l1;k++){
  106094. t4=t3+t6;
  106095. t5=t1;
  106096. tr3=cc[t4-1]+cc[t4-1];
  106097. tr4=cc[t4]+cc[t4];
  106098. tr1=cc[t3]-cc[(t4+=t6)-1];
  106099. tr2=cc[t3]+cc[t4-1];
  106100. ch[t5]=tr2+tr3;
  106101. ch[t5+=t0]=tr1-tr4;
  106102. ch[t5+=t0]=tr2-tr3;
  106103. ch[t5+=t0]=tr1+tr4;
  106104. t1+=ido;
  106105. t3+=t2;
  106106. }
  106107. if(ido<2)return;
  106108. if(ido==2)goto L105;
  106109. t1=0;
  106110. for(k=0;k<l1;k++){
  106111. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  106112. t7=t1;
  106113. for(i=2;i<ido;i+=2){
  106114. t2+=2;
  106115. t3+=2;
  106116. t4-=2;
  106117. t5-=2;
  106118. t7+=2;
  106119. ti1=cc[t2]+cc[t5];
  106120. ti2=cc[t2]-cc[t5];
  106121. ti3=cc[t3]-cc[t4];
  106122. tr4=cc[t3]+cc[t4];
  106123. tr1=cc[t2-1]-cc[t5-1];
  106124. tr2=cc[t2-1]+cc[t5-1];
  106125. ti4=cc[t3-1]-cc[t4-1];
  106126. tr3=cc[t3-1]+cc[t4-1];
  106127. ch[t7-1]=tr2+tr3;
  106128. cr3=tr2-tr3;
  106129. ch[t7]=ti2+ti3;
  106130. ci3=ti2-ti3;
  106131. cr2=tr1-tr4;
  106132. cr4=tr1+tr4;
  106133. ci2=ti1+ti4;
  106134. ci4=ti1-ti4;
  106135. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  106136. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  106137. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  106138. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  106139. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  106140. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  106141. }
  106142. t1+=ido;
  106143. }
  106144. if(ido%2 == 1)return;
  106145. L105:
  106146. t1=ido;
  106147. t2=ido<<2;
  106148. t3=ido-1;
  106149. t4=ido+(ido<<1);
  106150. for(k=0;k<l1;k++){
  106151. t5=t3;
  106152. ti1=cc[t1]+cc[t4];
  106153. ti2=cc[t4]-cc[t1];
  106154. tr1=cc[t1-1]-cc[t4-1];
  106155. tr2=cc[t1-1]+cc[t4-1];
  106156. ch[t5]=tr2+tr2;
  106157. ch[t5+=t0]=sqrt2*(tr1-ti1);
  106158. ch[t5+=t0]=ti2+ti2;
  106159. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  106160. t3+=ido;
  106161. t1+=t2;
  106162. t4+=t2;
  106163. }
  106164. }
  106165. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  106166. float *c2,float *ch,float *ch2,float *wa){
  106167. static float tpi=6.283185307179586f;
  106168. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  106169. t11,t12;
  106170. float dc2,ai1,ai2,ar1,ar2,ds2;
  106171. int nbd;
  106172. float dcp,arg,dsp,ar1h,ar2h;
  106173. int ipp2;
  106174. t10=ip*ido;
  106175. t0=l1*ido;
  106176. arg=tpi/(float)ip;
  106177. dcp=cos(arg);
  106178. dsp=sin(arg);
  106179. nbd=(ido-1)>>1;
  106180. ipp2=ip;
  106181. ipph=(ip+1)>>1;
  106182. if(ido<l1)goto L103;
  106183. t1=0;
  106184. t2=0;
  106185. for(k=0;k<l1;k++){
  106186. t3=t1;
  106187. t4=t2;
  106188. for(i=0;i<ido;i++){
  106189. ch[t3]=cc[t4];
  106190. t3++;
  106191. t4++;
  106192. }
  106193. t1+=ido;
  106194. t2+=t10;
  106195. }
  106196. goto L106;
  106197. L103:
  106198. t1=0;
  106199. for(i=0;i<ido;i++){
  106200. t2=t1;
  106201. t3=t1;
  106202. for(k=0;k<l1;k++){
  106203. ch[t2]=cc[t3];
  106204. t2+=ido;
  106205. t3+=t10;
  106206. }
  106207. t1++;
  106208. }
  106209. L106:
  106210. t1=0;
  106211. t2=ipp2*t0;
  106212. t7=(t5=ido<<1);
  106213. for(j=1;j<ipph;j++){
  106214. t1+=t0;
  106215. t2-=t0;
  106216. t3=t1;
  106217. t4=t2;
  106218. t6=t5;
  106219. for(k=0;k<l1;k++){
  106220. ch[t3]=cc[t6-1]+cc[t6-1];
  106221. ch[t4]=cc[t6]+cc[t6];
  106222. t3+=ido;
  106223. t4+=ido;
  106224. t6+=t10;
  106225. }
  106226. t5+=t7;
  106227. }
  106228. if (ido == 1)goto L116;
  106229. if(nbd<l1)goto L112;
  106230. t1=0;
  106231. t2=ipp2*t0;
  106232. t7=0;
  106233. for(j=1;j<ipph;j++){
  106234. t1+=t0;
  106235. t2-=t0;
  106236. t3=t1;
  106237. t4=t2;
  106238. t7+=(ido<<1);
  106239. t8=t7;
  106240. for(k=0;k<l1;k++){
  106241. t5=t3;
  106242. t6=t4;
  106243. t9=t8;
  106244. t11=t8;
  106245. for(i=2;i<ido;i+=2){
  106246. t5+=2;
  106247. t6+=2;
  106248. t9+=2;
  106249. t11-=2;
  106250. ch[t5-1]=cc[t9-1]+cc[t11-1];
  106251. ch[t6-1]=cc[t9-1]-cc[t11-1];
  106252. ch[t5]=cc[t9]-cc[t11];
  106253. ch[t6]=cc[t9]+cc[t11];
  106254. }
  106255. t3+=ido;
  106256. t4+=ido;
  106257. t8+=t10;
  106258. }
  106259. }
  106260. goto L116;
  106261. L112:
  106262. t1=0;
  106263. t2=ipp2*t0;
  106264. t7=0;
  106265. for(j=1;j<ipph;j++){
  106266. t1+=t0;
  106267. t2-=t0;
  106268. t3=t1;
  106269. t4=t2;
  106270. t7+=(ido<<1);
  106271. t8=t7;
  106272. t9=t7;
  106273. for(i=2;i<ido;i+=2){
  106274. t3+=2;
  106275. t4+=2;
  106276. t8+=2;
  106277. t9-=2;
  106278. t5=t3;
  106279. t6=t4;
  106280. t11=t8;
  106281. t12=t9;
  106282. for(k=0;k<l1;k++){
  106283. ch[t5-1]=cc[t11-1]+cc[t12-1];
  106284. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106285. ch[t5]=cc[t11]-cc[t12];
  106286. ch[t6]=cc[t11]+cc[t12];
  106287. t5+=ido;
  106288. t6+=ido;
  106289. t11+=t10;
  106290. t12+=t10;
  106291. }
  106292. }
  106293. }
  106294. L116:
  106295. ar1=1.f;
  106296. ai1=0.f;
  106297. t1=0;
  106298. t9=(t2=ipp2*idl1);
  106299. t3=(ip-1)*idl1;
  106300. for(l=1;l<ipph;l++){
  106301. t1+=idl1;
  106302. t2-=idl1;
  106303. ar1h=dcp*ar1-dsp*ai1;
  106304. ai1=dcp*ai1+dsp*ar1;
  106305. ar1=ar1h;
  106306. t4=t1;
  106307. t5=t2;
  106308. t6=0;
  106309. t7=idl1;
  106310. t8=t3;
  106311. for(ik=0;ik<idl1;ik++){
  106312. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106313. c2[t5++]=ai1*ch2[t8++];
  106314. }
  106315. dc2=ar1;
  106316. ds2=ai1;
  106317. ar2=ar1;
  106318. ai2=ai1;
  106319. t6=idl1;
  106320. t7=t9-idl1;
  106321. for(j=2;j<ipph;j++){
  106322. t6+=idl1;
  106323. t7-=idl1;
  106324. ar2h=dc2*ar2-ds2*ai2;
  106325. ai2=dc2*ai2+ds2*ar2;
  106326. ar2=ar2h;
  106327. t4=t1;
  106328. t5=t2;
  106329. t11=t6;
  106330. t12=t7;
  106331. for(ik=0;ik<idl1;ik++){
  106332. c2[t4++]+=ar2*ch2[t11++];
  106333. c2[t5++]+=ai2*ch2[t12++];
  106334. }
  106335. }
  106336. }
  106337. t1=0;
  106338. for(j=1;j<ipph;j++){
  106339. t1+=idl1;
  106340. t2=t1;
  106341. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106342. }
  106343. t1=0;
  106344. t2=ipp2*t0;
  106345. for(j=1;j<ipph;j++){
  106346. t1+=t0;
  106347. t2-=t0;
  106348. t3=t1;
  106349. t4=t2;
  106350. for(k=0;k<l1;k++){
  106351. ch[t3]=c1[t3]-c1[t4];
  106352. ch[t4]=c1[t3]+c1[t4];
  106353. t3+=ido;
  106354. t4+=ido;
  106355. }
  106356. }
  106357. if(ido==1)goto L132;
  106358. if(nbd<l1)goto L128;
  106359. t1=0;
  106360. t2=ipp2*t0;
  106361. for(j=1;j<ipph;j++){
  106362. t1+=t0;
  106363. t2-=t0;
  106364. t3=t1;
  106365. t4=t2;
  106366. for(k=0;k<l1;k++){
  106367. t5=t3;
  106368. t6=t4;
  106369. for(i=2;i<ido;i+=2){
  106370. t5+=2;
  106371. t6+=2;
  106372. ch[t5-1]=c1[t5-1]-c1[t6];
  106373. ch[t6-1]=c1[t5-1]+c1[t6];
  106374. ch[t5]=c1[t5]+c1[t6-1];
  106375. ch[t6]=c1[t5]-c1[t6-1];
  106376. }
  106377. t3+=ido;
  106378. t4+=ido;
  106379. }
  106380. }
  106381. goto L132;
  106382. L128:
  106383. t1=0;
  106384. t2=ipp2*t0;
  106385. for(j=1;j<ipph;j++){
  106386. t1+=t0;
  106387. t2-=t0;
  106388. t3=t1;
  106389. t4=t2;
  106390. for(i=2;i<ido;i+=2){
  106391. t3+=2;
  106392. t4+=2;
  106393. t5=t3;
  106394. t6=t4;
  106395. for(k=0;k<l1;k++){
  106396. ch[t5-1]=c1[t5-1]-c1[t6];
  106397. ch[t6-1]=c1[t5-1]+c1[t6];
  106398. ch[t5]=c1[t5]+c1[t6-1];
  106399. ch[t6]=c1[t5]-c1[t6-1];
  106400. t5+=ido;
  106401. t6+=ido;
  106402. }
  106403. }
  106404. }
  106405. L132:
  106406. if(ido==1)return;
  106407. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106408. t1=0;
  106409. for(j=1;j<ip;j++){
  106410. t2=(t1+=t0);
  106411. for(k=0;k<l1;k++){
  106412. c1[t2]=ch[t2];
  106413. t2+=ido;
  106414. }
  106415. }
  106416. if(nbd>l1)goto L139;
  106417. is= -ido-1;
  106418. t1=0;
  106419. for(j=1;j<ip;j++){
  106420. is+=ido;
  106421. t1+=t0;
  106422. idij=is;
  106423. t2=t1;
  106424. for(i=2;i<ido;i+=2){
  106425. t2+=2;
  106426. idij+=2;
  106427. t3=t2;
  106428. for(k=0;k<l1;k++){
  106429. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106430. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106431. t3+=ido;
  106432. }
  106433. }
  106434. }
  106435. return;
  106436. L139:
  106437. is= -ido-1;
  106438. t1=0;
  106439. for(j=1;j<ip;j++){
  106440. is+=ido;
  106441. t1+=t0;
  106442. t2=t1;
  106443. for(k=0;k<l1;k++){
  106444. idij=is;
  106445. t3=t2;
  106446. for(i=2;i<ido;i+=2){
  106447. idij+=2;
  106448. t3+=2;
  106449. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106450. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106451. }
  106452. t2+=ido;
  106453. }
  106454. }
  106455. }
  106456. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106457. int i,k1,l1,l2;
  106458. int na;
  106459. int nf,ip,iw,ix2,ix3,ido,idl1;
  106460. nf=ifac[1];
  106461. na=0;
  106462. l1=1;
  106463. iw=1;
  106464. for(k1=0;k1<nf;k1++){
  106465. ip=ifac[k1 + 2];
  106466. l2=ip*l1;
  106467. ido=n/l2;
  106468. idl1=ido*l1;
  106469. if(ip!=4)goto L103;
  106470. ix2=iw+ido;
  106471. ix3=ix2+ido;
  106472. if(na!=0)
  106473. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106474. else
  106475. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106476. na=1-na;
  106477. goto L115;
  106478. L103:
  106479. if(ip!=2)goto L106;
  106480. if(na!=0)
  106481. dradb2(ido,l1,ch,c,wa+iw-1);
  106482. else
  106483. dradb2(ido,l1,c,ch,wa+iw-1);
  106484. na=1-na;
  106485. goto L115;
  106486. L106:
  106487. if(ip!=3)goto L109;
  106488. ix2=iw+ido;
  106489. if(na!=0)
  106490. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106491. else
  106492. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106493. na=1-na;
  106494. goto L115;
  106495. L109:
  106496. if(na!=0)
  106497. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106498. else
  106499. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106500. if(ido==1)na=1-na;
  106501. L115:
  106502. l1=l2;
  106503. iw+=(ip-1)*ido;
  106504. }
  106505. if(na==0)return;
  106506. for(i=0;i<n;i++)c[i]=ch[i];
  106507. }
  106508. void drft_forward(drft_lookup *l,float *data){
  106509. if(l->n==1)return;
  106510. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106511. }
  106512. void drft_backward(drft_lookup *l,float *data){
  106513. if (l->n==1)return;
  106514. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106515. }
  106516. void drft_init(drft_lookup *l,int n){
  106517. l->n=n;
  106518. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106519. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106520. fdrffti(n, l->trigcache, l->splitcache);
  106521. }
  106522. void drft_clear(drft_lookup *l){
  106523. if(l){
  106524. if(l->trigcache)_ogg_free(l->trigcache);
  106525. if(l->splitcache)_ogg_free(l->splitcache);
  106526. memset(l,0,sizeof(*l));
  106527. }
  106528. }
  106529. #endif
  106530. /*** End of inlined file: smallft.c ***/
  106531. /*** Start of inlined file: synthesis.c ***/
  106532. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106533. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106534. // tasks..
  106535. #if JUCE_MSVC
  106536. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106537. #endif
  106538. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106539. #if JUCE_USE_OGGVORBIS
  106540. #include <stdio.h>
  106541. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106542. vorbis_dsp_state *vd=vb->vd;
  106543. private_state *b=(private_state*)vd->backend_state;
  106544. vorbis_info *vi=vd->vi;
  106545. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106546. oggpack_buffer *opb=&vb->opb;
  106547. int type,mode,i;
  106548. _vorbis_block_ripcord(vb);
  106549. oggpack_readinit(opb,op->packet,op->bytes);
  106550. if(oggpack_read(opb,1)!=0){
  106551. return(OV_ENOTAUDIO);
  106552. }
  106553. mode=oggpack_read(opb,b->modebits);
  106554. if(mode==-1)return(OV_EBADPACKET);
  106555. vb->mode=mode;
  106556. vb->W=ci->mode_param[mode]->blockflag;
  106557. if(vb->W){
  106558. vb->lW=oggpack_read(opb,1);
  106559. vb->nW=oggpack_read(opb,1);
  106560. if(vb->nW==-1) return(OV_EBADPACKET);
  106561. }else{
  106562. vb->lW=0;
  106563. vb->nW=0;
  106564. }
  106565. vb->granulepos=op->granulepos;
  106566. vb->sequence=op->packetno;
  106567. vb->eofflag=op->e_o_s;
  106568. vb->pcmend=ci->blocksizes[vb->W];
  106569. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106570. for(i=0;i<vi->channels;i++)
  106571. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106572. type=ci->map_type[ci->mode_param[mode]->mapping];
  106573. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106574. mapping]));
  106575. }
  106576. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106577. vorbis_dsp_state *vd=vb->vd;
  106578. private_state *b=(private_state*)vd->backend_state;
  106579. vorbis_info *vi=vd->vi;
  106580. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106581. oggpack_buffer *opb=&vb->opb;
  106582. int mode;
  106583. _vorbis_block_ripcord(vb);
  106584. oggpack_readinit(opb,op->packet,op->bytes);
  106585. if(oggpack_read(opb,1)!=0){
  106586. return(OV_ENOTAUDIO);
  106587. }
  106588. mode=oggpack_read(opb,b->modebits);
  106589. if(mode==-1)return(OV_EBADPACKET);
  106590. vb->mode=mode;
  106591. vb->W=ci->mode_param[mode]->blockflag;
  106592. if(vb->W){
  106593. vb->lW=oggpack_read(opb,1);
  106594. vb->nW=oggpack_read(opb,1);
  106595. if(vb->nW==-1) return(OV_EBADPACKET);
  106596. }else{
  106597. vb->lW=0;
  106598. vb->nW=0;
  106599. }
  106600. vb->granulepos=op->granulepos;
  106601. vb->sequence=op->packetno;
  106602. vb->eofflag=op->e_o_s;
  106603. vb->pcmend=0;
  106604. vb->pcm=NULL;
  106605. return(0);
  106606. }
  106607. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106608. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106609. oggpack_buffer opb;
  106610. int mode;
  106611. oggpack_readinit(&opb,op->packet,op->bytes);
  106612. if(oggpack_read(&opb,1)!=0){
  106613. return(OV_ENOTAUDIO);
  106614. }
  106615. {
  106616. int modebits=0;
  106617. int v=ci->modes;
  106618. while(v>1){
  106619. modebits++;
  106620. v>>=1;
  106621. }
  106622. mode=oggpack_read(&opb,modebits);
  106623. }
  106624. if(mode==-1)return(OV_EBADPACKET);
  106625. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106626. }
  106627. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106628. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106629. if(ci->blocksizes[0]<=64 && flag)return -1;
  106630. ci->halfrate_flag=(flag?1:0);
  106631. return 0;
  106632. }
  106633. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106634. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106635. return ci->halfrate_flag;
  106636. }
  106637. #endif
  106638. /*** End of inlined file: synthesis.c ***/
  106639. /*** Start of inlined file: vorbisenc.c ***/
  106640. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106641. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106642. // tasks..
  106643. #if JUCE_MSVC
  106644. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106645. #endif
  106646. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106647. #if JUCE_USE_OGGVORBIS
  106648. #include <stdlib.h>
  106649. #include <string.h>
  106650. #include <math.h>
  106651. typedef struct {
  106652. static_codebook *books[12][3];
  106653. } static_bookblock;
  106654. typedef struct {
  106655. int res_type;
  106656. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106657. vorbis_info_residue0 *res;
  106658. static_codebook *book_aux;
  106659. static_codebook *book_aux_managed;
  106660. static_bookblock *books_base;
  106661. static_bookblock *books_base_managed;
  106662. } vorbis_residue_template;
  106663. typedef struct {
  106664. vorbis_info_mapping0 *map;
  106665. vorbis_residue_template *res;
  106666. } vorbis_mapping_template;
  106667. typedef struct vp_adjblock{
  106668. int block[P_BANDS];
  106669. } vp_adjblock;
  106670. typedef struct {
  106671. int data[NOISE_COMPAND_LEVELS];
  106672. } compandblock;
  106673. typedef struct {
  106674. int att[P_NOISECURVES];
  106675. float boost;
  106676. float decay;
  106677. } att3;
  106678. typedef struct { int data[P_NOISECURVES]; } adj3;
  106679. typedef struct {
  106680. int pre[PACKETBLOBS];
  106681. int post[PACKETBLOBS];
  106682. float kHz[PACKETBLOBS];
  106683. float lowpasskHz[PACKETBLOBS];
  106684. } adj_stereo;
  106685. typedef struct {
  106686. int lo;
  106687. int hi;
  106688. int fixed;
  106689. } noiseguard;
  106690. typedef struct {
  106691. int data[P_NOISECURVES][17];
  106692. } noise3;
  106693. typedef struct {
  106694. int mappings;
  106695. double *rate_mapping;
  106696. double *quality_mapping;
  106697. int coupling_restriction;
  106698. long samplerate_min_restriction;
  106699. long samplerate_max_restriction;
  106700. int *blocksize_short;
  106701. int *blocksize_long;
  106702. att3 *psy_tone_masteratt;
  106703. int *psy_tone_0dB;
  106704. int *psy_tone_dBsuppress;
  106705. vp_adjblock *psy_tone_adj_impulse;
  106706. vp_adjblock *psy_tone_adj_long;
  106707. vp_adjblock *psy_tone_adj_other;
  106708. noiseguard *psy_noiseguards;
  106709. noise3 *psy_noise_bias_impulse;
  106710. noise3 *psy_noise_bias_padding;
  106711. noise3 *psy_noise_bias_trans;
  106712. noise3 *psy_noise_bias_long;
  106713. int *psy_noise_dBsuppress;
  106714. compandblock *psy_noise_compand;
  106715. double *psy_noise_compand_short_mapping;
  106716. double *psy_noise_compand_long_mapping;
  106717. int *psy_noise_normal_start[2];
  106718. int *psy_noise_normal_partition[2];
  106719. double *psy_noise_normal_thresh;
  106720. int *psy_ath_float;
  106721. int *psy_ath_abs;
  106722. double *psy_lowpass;
  106723. vorbis_info_psy_global *global_params;
  106724. double *global_mapping;
  106725. adj_stereo *stereo_modes;
  106726. static_codebook ***floor_books;
  106727. vorbis_info_floor1 *floor_params;
  106728. int *floor_short_mapping;
  106729. int *floor_long_mapping;
  106730. vorbis_mapping_template *maps;
  106731. } ve_setup_data_template;
  106732. static vorbis_info_mode _mode_template[2]={
  106733. {0,0,0,0},
  106734. {1,0,0,1}
  106735. };
  106736. static vorbis_info_mapping0 _map_nominal[2]={
  106737. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106738. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106739. };
  106740. /*** Start of inlined file: setup_44.h ***/
  106741. /*** Start of inlined file: floor_all.h ***/
  106742. /*** Start of inlined file: floor_books.h ***/
  106743. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106744. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106745. };
  106746. static static_codebook _huff_book_line_256x7_0sub1 = {
  106747. 1, 9,
  106748. _huff_lengthlist_line_256x7_0sub1,
  106749. 0, 0, 0, 0, 0,
  106750. NULL,
  106751. NULL,
  106752. NULL,
  106753. NULL,
  106754. 0
  106755. };
  106756. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106758. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106759. };
  106760. static static_codebook _huff_book_line_256x7_0sub2 = {
  106761. 1, 25,
  106762. _huff_lengthlist_line_256x7_0sub2,
  106763. 0, 0, 0, 0, 0,
  106764. NULL,
  106765. NULL,
  106766. NULL,
  106767. NULL,
  106768. 0
  106769. };
  106770. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106773. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106774. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106775. };
  106776. static static_codebook _huff_book_line_256x7_0sub3 = {
  106777. 1, 64,
  106778. _huff_lengthlist_line_256x7_0sub3,
  106779. 0, 0, 0, 0, 0,
  106780. NULL,
  106781. NULL,
  106782. NULL,
  106783. NULL,
  106784. 0
  106785. };
  106786. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106787. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106788. };
  106789. static static_codebook _huff_book_line_256x7_1sub1 = {
  106790. 1, 9,
  106791. _huff_lengthlist_line_256x7_1sub1,
  106792. 0, 0, 0, 0, 0,
  106793. NULL,
  106794. NULL,
  106795. NULL,
  106796. NULL,
  106797. 0
  106798. };
  106799. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106801. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106802. };
  106803. static static_codebook _huff_book_line_256x7_1sub2 = {
  106804. 1, 25,
  106805. _huff_lengthlist_line_256x7_1sub2,
  106806. 0, 0, 0, 0, 0,
  106807. NULL,
  106808. NULL,
  106809. NULL,
  106810. NULL,
  106811. 0
  106812. };
  106813. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106816. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106817. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106818. };
  106819. static static_codebook _huff_book_line_256x7_1sub3 = {
  106820. 1, 64,
  106821. _huff_lengthlist_line_256x7_1sub3,
  106822. 0, 0, 0, 0, 0,
  106823. NULL,
  106824. NULL,
  106825. NULL,
  106826. NULL,
  106827. 0
  106828. };
  106829. static long _huff_lengthlist_line_256x7_class0[] = {
  106830. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106831. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106832. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106833. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106834. };
  106835. static static_codebook _huff_book_line_256x7_class0 = {
  106836. 1, 64,
  106837. _huff_lengthlist_line_256x7_class0,
  106838. 0, 0, 0, 0, 0,
  106839. NULL,
  106840. NULL,
  106841. NULL,
  106842. NULL,
  106843. 0
  106844. };
  106845. static long _huff_lengthlist_line_256x7_class1[] = {
  106846. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106847. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106848. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106849. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106850. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106851. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106852. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106853. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106854. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106855. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106856. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106857. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106858. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106859. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106860. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106861. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106862. };
  106863. static static_codebook _huff_book_line_256x7_class1 = {
  106864. 1, 256,
  106865. _huff_lengthlist_line_256x7_class1,
  106866. 0, 0, 0, 0, 0,
  106867. NULL,
  106868. NULL,
  106869. NULL,
  106870. NULL,
  106871. 0
  106872. };
  106873. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106874. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106875. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106876. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106877. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106878. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106879. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106880. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106881. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106882. };
  106883. static static_codebook _huff_book_line_512x17_0sub0 = {
  106884. 1, 128,
  106885. _huff_lengthlist_line_512x17_0sub0,
  106886. 0, 0, 0, 0, 0,
  106887. NULL,
  106888. NULL,
  106889. NULL,
  106890. NULL,
  106891. 0
  106892. };
  106893. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106894. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106895. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106896. };
  106897. static static_codebook _huff_book_line_512x17_1sub0 = {
  106898. 1, 32,
  106899. _huff_lengthlist_line_512x17_1sub0,
  106900. 0, 0, 0, 0, 0,
  106901. NULL,
  106902. NULL,
  106903. NULL,
  106904. NULL,
  106905. 0
  106906. };
  106907. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106910. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106911. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106912. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106913. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106914. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106915. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106916. };
  106917. static static_codebook _huff_book_line_512x17_1sub1 = {
  106918. 1, 128,
  106919. _huff_lengthlist_line_512x17_1sub1,
  106920. 0, 0, 0, 0, 0,
  106921. NULL,
  106922. NULL,
  106923. NULL,
  106924. NULL,
  106925. 0
  106926. };
  106927. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106928. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106929. 5, 3,
  106930. };
  106931. static static_codebook _huff_book_line_512x17_2sub1 = {
  106932. 1, 18,
  106933. _huff_lengthlist_line_512x17_2sub1,
  106934. 0, 0, 0, 0, 0,
  106935. NULL,
  106936. NULL,
  106937. NULL,
  106938. NULL,
  106939. 0
  106940. };
  106941. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106943. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106944. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106945. 9, 8,
  106946. };
  106947. static static_codebook _huff_book_line_512x17_2sub2 = {
  106948. 1, 50,
  106949. _huff_lengthlist_line_512x17_2sub2,
  106950. 0, 0, 0, 0, 0,
  106951. NULL,
  106952. NULL,
  106953. NULL,
  106954. NULL,
  106955. 0
  106956. };
  106957. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106961. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106962. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106963. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106964. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106965. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106966. };
  106967. static static_codebook _huff_book_line_512x17_2sub3 = {
  106968. 1, 128,
  106969. _huff_lengthlist_line_512x17_2sub3,
  106970. 0, 0, 0, 0, 0,
  106971. NULL,
  106972. NULL,
  106973. NULL,
  106974. NULL,
  106975. 0
  106976. };
  106977. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106978. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106979. 5, 5,
  106980. };
  106981. static static_codebook _huff_book_line_512x17_3sub1 = {
  106982. 1, 18,
  106983. _huff_lengthlist_line_512x17_3sub1,
  106984. 0, 0, 0, 0, 0,
  106985. NULL,
  106986. NULL,
  106987. NULL,
  106988. NULL,
  106989. 0
  106990. };
  106991. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106993. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106994. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106995. 11,14,
  106996. };
  106997. static static_codebook _huff_book_line_512x17_3sub2 = {
  106998. 1, 50,
  106999. _huff_lengthlist_line_512x17_3sub2,
  107000. 0, 0, 0, 0, 0,
  107001. NULL,
  107002. NULL,
  107003. NULL,
  107004. NULL,
  107005. 0
  107006. };
  107007. static long _huff_lengthlist_line_512x17_3sub3[] = {
  107008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107011. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  107012. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107013. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107014. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107015. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107016. };
  107017. static static_codebook _huff_book_line_512x17_3sub3 = {
  107018. 1, 128,
  107019. _huff_lengthlist_line_512x17_3sub3,
  107020. 0, 0, 0, 0, 0,
  107021. NULL,
  107022. NULL,
  107023. NULL,
  107024. NULL,
  107025. 0
  107026. };
  107027. static long _huff_lengthlist_line_512x17_class1[] = {
  107028. 1, 2, 3, 6, 5, 4, 7, 7,
  107029. };
  107030. static static_codebook _huff_book_line_512x17_class1 = {
  107031. 1, 8,
  107032. _huff_lengthlist_line_512x17_class1,
  107033. 0, 0, 0, 0, 0,
  107034. NULL,
  107035. NULL,
  107036. NULL,
  107037. NULL,
  107038. 0
  107039. };
  107040. static long _huff_lengthlist_line_512x17_class2[] = {
  107041. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  107042. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  107043. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  107044. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  107045. };
  107046. static static_codebook _huff_book_line_512x17_class2 = {
  107047. 1, 64,
  107048. _huff_lengthlist_line_512x17_class2,
  107049. 0, 0, 0, 0, 0,
  107050. NULL,
  107051. NULL,
  107052. NULL,
  107053. NULL,
  107054. 0
  107055. };
  107056. static long _huff_lengthlist_line_512x17_class3[] = {
  107057. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  107058. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  107059. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  107060. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  107061. };
  107062. static static_codebook _huff_book_line_512x17_class3 = {
  107063. 1, 64,
  107064. _huff_lengthlist_line_512x17_class3,
  107065. 0, 0, 0, 0, 0,
  107066. NULL,
  107067. NULL,
  107068. NULL,
  107069. NULL,
  107070. 0
  107071. };
  107072. static long _huff_lengthlist_line_128x4_class0[] = {
  107073. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  107074. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  107075. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  107076. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  107077. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  107078. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  107079. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  107080. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  107081. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  107082. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  107083. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  107084. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  107085. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  107086. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  107087. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  107088. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  107089. };
  107090. static static_codebook _huff_book_line_128x4_class0 = {
  107091. 1, 256,
  107092. _huff_lengthlist_line_128x4_class0,
  107093. 0, 0, 0, 0, 0,
  107094. NULL,
  107095. NULL,
  107096. NULL,
  107097. NULL,
  107098. 0
  107099. };
  107100. static long _huff_lengthlist_line_128x4_0sub0[] = {
  107101. 2, 2, 2, 2,
  107102. };
  107103. static static_codebook _huff_book_line_128x4_0sub0 = {
  107104. 1, 4,
  107105. _huff_lengthlist_line_128x4_0sub0,
  107106. 0, 0, 0, 0, 0,
  107107. NULL,
  107108. NULL,
  107109. NULL,
  107110. NULL,
  107111. 0
  107112. };
  107113. static long _huff_lengthlist_line_128x4_0sub1[] = {
  107114. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  107115. };
  107116. static static_codebook _huff_book_line_128x4_0sub1 = {
  107117. 1, 10,
  107118. _huff_lengthlist_line_128x4_0sub1,
  107119. 0, 0, 0, 0, 0,
  107120. NULL,
  107121. NULL,
  107122. NULL,
  107123. NULL,
  107124. 0
  107125. };
  107126. static long _huff_lengthlist_line_128x4_0sub2[] = {
  107127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  107128. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  107129. };
  107130. static static_codebook _huff_book_line_128x4_0sub2 = {
  107131. 1, 25,
  107132. _huff_lengthlist_line_128x4_0sub2,
  107133. 0, 0, 0, 0, 0,
  107134. NULL,
  107135. NULL,
  107136. NULL,
  107137. NULL,
  107138. 0
  107139. };
  107140. static long _huff_lengthlist_line_128x4_0sub3[] = {
  107141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107143. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  107144. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  107145. };
  107146. static static_codebook _huff_book_line_128x4_0sub3 = {
  107147. 1, 64,
  107148. _huff_lengthlist_line_128x4_0sub3,
  107149. 0, 0, 0, 0, 0,
  107150. NULL,
  107151. NULL,
  107152. NULL,
  107153. NULL,
  107154. 0
  107155. };
  107156. static long _huff_lengthlist_line_256x4_class0[] = {
  107157. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  107158. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  107159. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  107160. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  107161. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  107162. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  107163. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  107164. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  107165. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  107166. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  107167. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  107168. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  107169. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  107170. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  107171. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  107172. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  107173. };
  107174. static static_codebook _huff_book_line_256x4_class0 = {
  107175. 1, 256,
  107176. _huff_lengthlist_line_256x4_class0,
  107177. 0, 0, 0, 0, 0,
  107178. NULL,
  107179. NULL,
  107180. NULL,
  107181. NULL,
  107182. 0
  107183. };
  107184. static long _huff_lengthlist_line_256x4_0sub0[] = {
  107185. 2, 2, 2, 2,
  107186. };
  107187. static static_codebook _huff_book_line_256x4_0sub0 = {
  107188. 1, 4,
  107189. _huff_lengthlist_line_256x4_0sub0,
  107190. 0, 0, 0, 0, 0,
  107191. NULL,
  107192. NULL,
  107193. NULL,
  107194. NULL,
  107195. 0
  107196. };
  107197. static long _huff_lengthlist_line_256x4_0sub1[] = {
  107198. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  107199. };
  107200. static static_codebook _huff_book_line_256x4_0sub1 = {
  107201. 1, 10,
  107202. _huff_lengthlist_line_256x4_0sub1,
  107203. 0, 0, 0, 0, 0,
  107204. NULL,
  107205. NULL,
  107206. NULL,
  107207. NULL,
  107208. 0
  107209. };
  107210. static long _huff_lengthlist_line_256x4_0sub2[] = {
  107211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  107212. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  107213. };
  107214. static static_codebook _huff_book_line_256x4_0sub2 = {
  107215. 1, 25,
  107216. _huff_lengthlist_line_256x4_0sub2,
  107217. 0, 0, 0, 0, 0,
  107218. NULL,
  107219. NULL,
  107220. NULL,
  107221. NULL,
  107222. 0
  107223. };
  107224. static long _huff_lengthlist_line_256x4_0sub3[] = {
  107225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107227. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  107228. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  107229. };
  107230. static static_codebook _huff_book_line_256x4_0sub3 = {
  107231. 1, 64,
  107232. _huff_lengthlist_line_256x4_0sub3,
  107233. 0, 0, 0, 0, 0,
  107234. NULL,
  107235. NULL,
  107236. NULL,
  107237. NULL,
  107238. 0
  107239. };
  107240. static long _huff_lengthlist_line_128x7_class0[] = {
  107241. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  107242. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  107243. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  107244. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  107245. };
  107246. static static_codebook _huff_book_line_128x7_class0 = {
  107247. 1, 64,
  107248. _huff_lengthlist_line_128x7_class0,
  107249. 0, 0, 0, 0, 0,
  107250. NULL,
  107251. NULL,
  107252. NULL,
  107253. NULL,
  107254. 0
  107255. };
  107256. static long _huff_lengthlist_line_128x7_class1[] = {
  107257. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  107258. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  107259. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  107260. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107261. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  107262. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  107263. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  107264. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  107265. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  107266. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  107267. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  107268. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  107269. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  107270. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  107271. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  107272. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  107273. };
  107274. static static_codebook _huff_book_line_128x7_class1 = {
  107275. 1, 256,
  107276. _huff_lengthlist_line_128x7_class1,
  107277. 0, 0, 0, 0, 0,
  107278. NULL,
  107279. NULL,
  107280. NULL,
  107281. NULL,
  107282. 0
  107283. };
  107284. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107285. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107286. };
  107287. static static_codebook _huff_book_line_128x7_0sub1 = {
  107288. 1, 9,
  107289. _huff_lengthlist_line_128x7_0sub1,
  107290. 0, 0, 0, 0, 0,
  107291. NULL,
  107292. NULL,
  107293. NULL,
  107294. NULL,
  107295. 0
  107296. };
  107297. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107299. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107300. };
  107301. static static_codebook _huff_book_line_128x7_0sub2 = {
  107302. 1, 25,
  107303. _huff_lengthlist_line_128x7_0sub2,
  107304. 0, 0, 0, 0, 0,
  107305. NULL,
  107306. NULL,
  107307. NULL,
  107308. NULL,
  107309. 0
  107310. };
  107311. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107314. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107315. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107316. };
  107317. static static_codebook _huff_book_line_128x7_0sub3 = {
  107318. 1, 64,
  107319. _huff_lengthlist_line_128x7_0sub3,
  107320. 0, 0, 0, 0, 0,
  107321. NULL,
  107322. NULL,
  107323. NULL,
  107324. NULL,
  107325. 0
  107326. };
  107327. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107328. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107329. };
  107330. static static_codebook _huff_book_line_128x7_1sub1 = {
  107331. 1, 9,
  107332. _huff_lengthlist_line_128x7_1sub1,
  107333. 0, 0, 0, 0, 0,
  107334. NULL,
  107335. NULL,
  107336. NULL,
  107337. NULL,
  107338. 0
  107339. };
  107340. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107342. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107343. };
  107344. static static_codebook _huff_book_line_128x7_1sub2 = {
  107345. 1, 25,
  107346. _huff_lengthlist_line_128x7_1sub2,
  107347. 0, 0, 0, 0, 0,
  107348. NULL,
  107349. NULL,
  107350. NULL,
  107351. NULL,
  107352. 0
  107353. };
  107354. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107357. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107358. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107359. };
  107360. static static_codebook _huff_book_line_128x7_1sub3 = {
  107361. 1, 64,
  107362. _huff_lengthlist_line_128x7_1sub3,
  107363. 0, 0, 0, 0, 0,
  107364. NULL,
  107365. NULL,
  107366. NULL,
  107367. NULL,
  107368. 0
  107369. };
  107370. static long _huff_lengthlist_line_128x11_class1[] = {
  107371. 1, 6, 3, 7, 2, 4, 5, 7,
  107372. };
  107373. static static_codebook _huff_book_line_128x11_class1 = {
  107374. 1, 8,
  107375. _huff_lengthlist_line_128x11_class1,
  107376. 0, 0, 0, 0, 0,
  107377. NULL,
  107378. NULL,
  107379. NULL,
  107380. NULL,
  107381. 0
  107382. };
  107383. static long _huff_lengthlist_line_128x11_class2[] = {
  107384. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107385. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107386. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107387. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107388. };
  107389. static static_codebook _huff_book_line_128x11_class2 = {
  107390. 1, 64,
  107391. _huff_lengthlist_line_128x11_class2,
  107392. 0, 0, 0, 0, 0,
  107393. NULL,
  107394. NULL,
  107395. NULL,
  107396. NULL,
  107397. 0
  107398. };
  107399. static long _huff_lengthlist_line_128x11_class3[] = {
  107400. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107401. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107402. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107403. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107404. };
  107405. static static_codebook _huff_book_line_128x11_class3 = {
  107406. 1, 64,
  107407. _huff_lengthlist_line_128x11_class3,
  107408. 0, 0, 0, 0, 0,
  107409. NULL,
  107410. NULL,
  107411. NULL,
  107412. NULL,
  107413. 0
  107414. };
  107415. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107416. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107417. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107418. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107419. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107420. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107421. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107422. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107423. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107424. };
  107425. static static_codebook _huff_book_line_128x11_0sub0 = {
  107426. 1, 128,
  107427. _huff_lengthlist_line_128x11_0sub0,
  107428. 0, 0, 0, 0, 0,
  107429. NULL,
  107430. NULL,
  107431. NULL,
  107432. NULL,
  107433. 0
  107434. };
  107435. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107436. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107437. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107438. };
  107439. static static_codebook _huff_book_line_128x11_1sub0 = {
  107440. 1, 32,
  107441. _huff_lengthlist_line_128x11_1sub0,
  107442. 0, 0, 0, 0, 0,
  107443. NULL,
  107444. NULL,
  107445. NULL,
  107446. NULL,
  107447. 0
  107448. };
  107449. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107452. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107453. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107454. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107455. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107456. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107457. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107458. };
  107459. static static_codebook _huff_book_line_128x11_1sub1 = {
  107460. 1, 128,
  107461. _huff_lengthlist_line_128x11_1sub1,
  107462. 0, 0, 0, 0, 0,
  107463. NULL,
  107464. NULL,
  107465. NULL,
  107466. NULL,
  107467. 0
  107468. };
  107469. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107470. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107471. 5, 5,
  107472. };
  107473. static static_codebook _huff_book_line_128x11_2sub1 = {
  107474. 1, 18,
  107475. _huff_lengthlist_line_128x11_2sub1,
  107476. 0, 0, 0, 0, 0,
  107477. NULL,
  107478. NULL,
  107479. NULL,
  107480. NULL,
  107481. 0
  107482. };
  107483. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107485. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107486. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107487. 8,11,
  107488. };
  107489. static static_codebook _huff_book_line_128x11_2sub2 = {
  107490. 1, 50,
  107491. _huff_lengthlist_line_128x11_2sub2,
  107492. 0, 0, 0, 0, 0,
  107493. NULL,
  107494. NULL,
  107495. NULL,
  107496. NULL,
  107497. 0
  107498. };
  107499. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107503. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107504. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107505. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107506. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107507. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107508. };
  107509. static static_codebook _huff_book_line_128x11_2sub3 = {
  107510. 1, 128,
  107511. _huff_lengthlist_line_128x11_2sub3,
  107512. 0, 0, 0, 0, 0,
  107513. NULL,
  107514. NULL,
  107515. NULL,
  107516. NULL,
  107517. 0
  107518. };
  107519. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107520. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107521. 5, 4,
  107522. };
  107523. static static_codebook _huff_book_line_128x11_3sub1 = {
  107524. 1, 18,
  107525. _huff_lengthlist_line_128x11_3sub1,
  107526. 0, 0, 0, 0, 0,
  107527. NULL,
  107528. NULL,
  107529. NULL,
  107530. NULL,
  107531. 0
  107532. };
  107533. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107535. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107536. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107537. 12, 6,
  107538. };
  107539. static static_codebook _huff_book_line_128x11_3sub2 = {
  107540. 1, 50,
  107541. _huff_lengthlist_line_128x11_3sub2,
  107542. 0, 0, 0, 0, 0,
  107543. NULL,
  107544. NULL,
  107545. NULL,
  107546. NULL,
  107547. 0
  107548. };
  107549. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107553. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107554. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107555. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107556. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107557. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107558. };
  107559. static static_codebook _huff_book_line_128x11_3sub3 = {
  107560. 1, 128,
  107561. _huff_lengthlist_line_128x11_3sub3,
  107562. 0, 0, 0, 0, 0,
  107563. NULL,
  107564. NULL,
  107565. NULL,
  107566. NULL,
  107567. 0
  107568. };
  107569. static long _huff_lengthlist_line_128x17_class1[] = {
  107570. 1, 3, 4, 7, 2, 5, 6, 7,
  107571. };
  107572. static static_codebook _huff_book_line_128x17_class1 = {
  107573. 1, 8,
  107574. _huff_lengthlist_line_128x17_class1,
  107575. 0, 0, 0, 0, 0,
  107576. NULL,
  107577. NULL,
  107578. NULL,
  107579. NULL,
  107580. 0
  107581. };
  107582. static long _huff_lengthlist_line_128x17_class2[] = {
  107583. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107584. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107585. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107586. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107587. };
  107588. static static_codebook _huff_book_line_128x17_class2 = {
  107589. 1, 64,
  107590. _huff_lengthlist_line_128x17_class2,
  107591. 0, 0, 0, 0, 0,
  107592. NULL,
  107593. NULL,
  107594. NULL,
  107595. NULL,
  107596. 0
  107597. };
  107598. static long _huff_lengthlist_line_128x17_class3[] = {
  107599. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107600. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107601. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107602. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107603. };
  107604. static static_codebook _huff_book_line_128x17_class3 = {
  107605. 1, 64,
  107606. _huff_lengthlist_line_128x17_class3,
  107607. 0, 0, 0, 0, 0,
  107608. NULL,
  107609. NULL,
  107610. NULL,
  107611. NULL,
  107612. 0
  107613. };
  107614. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107615. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107616. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107617. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107618. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107619. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107620. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107621. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107622. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107623. };
  107624. static static_codebook _huff_book_line_128x17_0sub0 = {
  107625. 1, 128,
  107626. _huff_lengthlist_line_128x17_0sub0,
  107627. 0, 0, 0, 0, 0,
  107628. NULL,
  107629. NULL,
  107630. NULL,
  107631. NULL,
  107632. 0
  107633. };
  107634. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107635. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107636. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107637. };
  107638. static static_codebook _huff_book_line_128x17_1sub0 = {
  107639. 1, 32,
  107640. _huff_lengthlist_line_128x17_1sub0,
  107641. 0, 0, 0, 0, 0,
  107642. NULL,
  107643. NULL,
  107644. NULL,
  107645. NULL,
  107646. 0
  107647. };
  107648. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107651. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107652. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107653. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107654. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107655. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107656. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107657. };
  107658. static static_codebook _huff_book_line_128x17_1sub1 = {
  107659. 1, 128,
  107660. _huff_lengthlist_line_128x17_1sub1,
  107661. 0, 0, 0, 0, 0,
  107662. NULL,
  107663. NULL,
  107664. NULL,
  107665. NULL,
  107666. 0
  107667. };
  107668. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107669. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107670. 9, 4,
  107671. };
  107672. static static_codebook _huff_book_line_128x17_2sub1 = {
  107673. 1, 18,
  107674. _huff_lengthlist_line_128x17_2sub1,
  107675. 0, 0, 0, 0, 0,
  107676. NULL,
  107677. NULL,
  107678. NULL,
  107679. NULL,
  107680. 0
  107681. };
  107682. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107684. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107685. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107686. 13,13,
  107687. };
  107688. static static_codebook _huff_book_line_128x17_2sub2 = {
  107689. 1, 50,
  107690. _huff_lengthlist_line_128x17_2sub2,
  107691. 0, 0, 0, 0, 0,
  107692. NULL,
  107693. NULL,
  107694. NULL,
  107695. NULL,
  107696. 0
  107697. };
  107698. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107702. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107703. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107704. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107705. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107706. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107707. };
  107708. static static_codebook _huff_book_line_128x17_2sub3 = {
  107709. 1, 128,
  107710. _huff_lengthlist_line_128x17_2sub3,
  107711. 0, 0, 0, 0, 0,
  107712. NULL,
  107713. NULL,
  107714. NULL,
  107715. NULL,
  107716. 0
  107717. };
  107718. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107719. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107720. 6, 4,
  107721. };
  107722. static static_codebook _huff_book_line_128x17_3sub1 = {
  107723. 1, 18,
  107724. _huff_lengthlist_line_128x17_3sub1,
  107725. 0, 0, 0, 0, 0,
  107726. NULL,
  107727. NULL,
  107728. NULL,
  107729. NULL,
  107730. 0
  107731. };
  107732. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107734. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107735. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107736. 10, 8,
  107737. };
  107738. static static_codebook _huff_book_line_128x17_3sub2 = {
  107739. 1, 50,
  107740. _huff_lengthlist_line_128x17_3sub2,
  107741. 0, 0, 0, 0, 0,
  107742. NULL,
  107743. NULL,
  107744. NULL,
  107745. NULL,
  107746. 0
  107747. };
  107748. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107752. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107753. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107754. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107755. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107756. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107757. };
  107758. static static_codebook _huff_book_line_128x17_3sub3 = {
  107759. 1, 128,
  107760. _huff_lengthlist_line_128x17_3sub3,
  107761. 0, 0, 0, 0, 0,
  107762. NULL,
  107763. NULL,
  107764. NULL,
  107765. NULL,
  107766. 0
  107767. };
  107768. static long _huff_lengthlist_line_1024x27_class1[] = {
  107769. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107770. };
  107771. static static_codebook _huff_book_line_1024x27_class1 = {
  107772. 1, 16,
  107773. _huff_lengthlist_line_1024x27_class1,
  107774. 0, 0, 0, 0, 0,
  107775. NULL,
  107776. NULL,
  107777. NULL,
  107778. NULL,
  107779. 0
  107780. };
  107781. static long _huff_lengthlist_line_1024x27_class2[] = {
  107782. 1, 4, 2, 6, 3, 7, 5, 7,
  107783. };
  107784. static static_codebook _huff_book_line_1024x27_class2 = {
  107785. 1, 8,
  107786. _huff_lengthlist_line_1024x27_class2,
  107787. 0, 0, 0, 0, 0,
  107788. NULL,
  107789. NULL,
  107790. NULL,
  107791. NULL,
  107792. 0
  107793. };
  107794. static long _huff_lengthlist_line_1024x27_class3[] = {
  107795. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107796. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107797. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107798. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107799. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107800. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107801. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107802. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107803. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107804. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107805. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107806. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107807. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107808. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107809. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107810. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107811. };
  107812. static static_codebook _huff_book_line_1024x27_class3 = {
  107813. 1, 256,
  107814. _huff_lengthlist_line_1024x27_class3,
  107815. 0, 0, 0, 0, 0,
  107816. NULL,
  107817. NULL,
  107818. NULL,
  107819. NULL,
  107820. 0
  107821. };
  107822. static long _huff_lengthlist_line_1024x27_class4[] = {
  107823. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107824. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107825. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107826. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107827. };
  107828. static static_codebook _huff_book_line_1024x27_class4 = {
  107829. 1, 64,
  107830. _huff_lengthlist_line_1024x27_class4,
  107831. 0, 0, 0, 0, 0,
  107832. NULL,
  107833. NULL,
  107834. NULL,
  107835. NULL,
  107836. 0
  107837. };
  107838. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107839. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107840. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107841. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107842. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107843. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107844. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107845. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107846. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107847. };
  107848. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107849. 1, 128,
  107850. _huff_lengthlist_line_1024x27_0sub0,
  107851. 0, 0, 0, 0, 0,
  107852. NULL,
  107853. NULL,
  107854. NULL,
  107855. NULL,
  107856. 0
  107857. };
  107858. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107859. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107860. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107861. };
  107862. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107863. 1, 32,
  107864. _huff_lengthlist_line_1024x27_1sub0,
  107865. 0, 0, 0, 0, 0,
  107866. NULL,
  107867. NULL,
  107868. NULL,
  107869. NULL,
  107870. 0
  107871. };
  107872. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107875. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107876. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107877. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107878. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107879. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107880. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107881. };
  107882. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107883. 1, 128,
  107884. _huff_lengthlist_line_1024x27_1sub1,
  107885. 0, 0, 0, 0, 0,
  107886. NULL,
  107887. NULL,
  107888. NULL,
  107889. NULL,
  107890. 0
  107891. };
  107892. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107893. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107894. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107895. };
  107896. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107897. 1, 32,
  107898. _huff_lengthlist_line_1024x27_2sub0,
  107899. 0, 0, 0, 0, 0,
  107900. NULL,
  107901. NULL,
  107902. NULL,
  107903. NULL,
  107904. 0
  107905. };
  107906. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107909. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107910. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107911. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107912. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107913. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107914. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107915. };
  107916. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107917. 1, 128,
  107918. _huff_lengthlist_line_1024x27_2sub1,
  107919. 0, 0, 0, 0, 0,
  107920. NULL,
  107921. NULL,
  107922. NULL,
  107923. NULL,
  107924. 0
  107925. };
  107926. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107927. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107928. 5, 5,
  107929. };
  107930. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107931. 1, 18,
  107932. _huff_lengthlist_line_1024x27_3sub1,
  107933. 0, 0, 0, 0, 0,
  107934. NULL,
  107935. NULL,
  107936. NULL,
  107937. NULL,
  107938. 0
  107939. };
  107940. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107942. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107943. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107944. 9,11,
  107945. };
  107946. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107947. 1, 50,
  107948. _huff_lengthlist_line_1024x27_3sub2,
  107949. 0, 0, 0, 0, 0,
  107950. NULL,
  107951. NULL,
  107952. NULL,
  107953. NULL,
  107954. 0
  107955. };
  107956. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107960. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107961. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107962. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107963. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107964. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107965. };
  107966. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107967. 1, 128,
  107968. _huff_lengthlist_line_1024x27_3sub3,
  107969. 0, 0, 0, 0, 0,
  107970. NULL,
  107971. NULL,
  107972. NULL,
  107973. NULL,
  107974. 0
  107975. };
  107976. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107977. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107978. 5, 4,
  107979. };
  107980. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107981. 1, 18,
  107982. _huff_lengthlist_line_1024x27_4sub1,
  107983. 0, 0, 0, 0, 0,
  107984. NULL,
  107985. NULL,
  107986. NULL,
  107987. NULL,
  107988. 0
  107989. };
  107990. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107992. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107993. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107994. 9,12,
  107995. };
  107996. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107997. 1, 50,
  107998. _huff_lengthlist_line_1024x27_4sub2,
  107999. 0, 0, 0, 0, 0,
  108000. NULL,
  108001. NULL,
  108002. NULL,
  108003. NULL,
  108004. 0
  108005. };
  108006. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  108007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108010. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  108011. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  108012. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108013. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108014. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  108015. };
  108016. static static_codebook _huff_book_line_1024x27_4sub3 = {
  108017. 1, 128,
  108018. _huff_lengthlist_line_1024x27_4sub3,
  108019. 0, 0, 0, 0, 0,
  108020. NULL,
  108021. NULL,
  108022. NULL,
  108023. NULL,
  108024. 0
  108025. };
  108026. static long _huff_lengthlist_line_2048x27_class1[] = {
  108027. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  108028. };
  108029. static static_codebook _huff_book_line_2048x27_class1 = {
  108030. 1, 16,
  108031. _huff_lengthlist_line_2048x27_class1,
  108032. 0, 0, 0, 0, 0,
  108033. NULL,
  108034. NULL,
  108035. NULL,
  108036. NULL,
  108037. 0
  108038. };
  108039. static long _huff_lengthlist_line_2048x27_class2[] = {
  108040. 1, 2, 3, 6, 4, 7, 5, 7,
  108041. };
  108042. static static_codebook _huff_book_line_2048x27_class2 = {
  108043. 1, 8,
  108044. _huff_lengthlist_line_2048x27_class2,
  108045. 0, 0, 0, 0, 0,
  108046. NULL,
  108047. NULL,
  108048. NULL,
  108049. NULL,
  108050. 0
  108051. };
  108052. static long _huff_lengthlist_line_2048x27_class3[] = {
  108053. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  108054. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  108055. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  108056. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  108057. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  108058. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  108059. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  108060. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  108061. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  108062. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  108063. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  108064. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108065. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  108066. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  108067. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108068. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108069. };
  108070. static static_codebook _huff_book_line_2048x27_class3 = {
  108071. 1, 256,
  108072. _huff_lengthlist_line_2048x27_class3,
  108073. 0, 0, 0, 0, 0,
  108074. NULL,
  108075. NULL,
  108076. NULL,
  108077. NULL,
  108078. 0
  108079. };
  108080. static long _huff_lengthlist_line_2048x27_class4[] = {
  108081. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  108082. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  108083. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  108084. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  108085. };
  108086. static static_codebook _huff_book_line_2048x27_class4 = {
  108087. 1, 64,
  108088. _huff_lengthlist_line_2048x27_class4,
  108089. 0, 0, 0, 0, 0,
  108090. NULL,
  108091. NULL,
  108092. NULL,
  108093. NULL,
  108094. 0
  108095. };
  108096. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  108097. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108098. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  108099. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  108100. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  108101. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  108102. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  108103. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  108104. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  108105. };
  108106. static static_codebook _huff_book_line_2048x27_0sub0 = {
  108107. 1, 128,
  108108. _huff_lengthlist_line_2048x27_0sub0,
  108109. 0, 0, 0, 0, 0,
  108110. NULL,
  108111. NULL,
  108112. NULL,
  108113. NULL,
  108114. 0
  108115. };
  108116. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  108117. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  108118. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  108119. };
  108120. static static_codebook _huff_book_line_2048x27_1sub0 = {
  108121. 1, 32,
  108122. _huff_lengthlist_line_2048x27_1sub0,
  108123. 0, 0, 0, 0, 0,
  108124. NULL,
  108125. NULL,
  108126. NULL,
  108127. NULL,
  108128. 0
  108129. };
  108130. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  108131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108133. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  108134. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  108135. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  108136. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  108137. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  108138. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  108139. };
  108140. static static_codebook _huff_book_line_2048x27_1sub1 = {
  108141. 1, 128,
  108142. _huff_lengthlist_line_2048x27_1sub1,
  108143. 0, 0, 0, 0, 0,
  108144. NULL,
  108145. NULL,
  108146. NULL,
  108147. NULL,
  108148. 0
  108149. };
  108150. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  108151. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  108152. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  108153. };
  108154. static static_codebook _huff_book_line_2048x27_2sub0 = {
  108155. 1, 32,
  108156. _huff_lengthlist_line_2048x27_2sub0,
  108157. 0, 0, 0, 0, 0,
  108158. NULL,
  108159. NULL,
  108160. NULL,
  108161. NULL,
  108162. 0
  108163. };
  108164. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  108165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108167. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  108168. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  108169. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  108170. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  108171. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  108172. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108173. };
  108174. static static_codebook _huff_book_line_2048x27_2sub1 = {
  108175. 1, 128,
  108176. _huff_lengthlist_line_2048x27_2sub1,
  108177. 0, 0, 0, 0, 0,
  108178. NULL,
  108179. NULL,
  108180. NULL,
  108181. NULL,
  108182. 0
  108183. };
  108184. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  108185. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  108186. 5, 5,
  108187. };
  108188. static static_codebook _huff_book_line_2048x27_3sub1 = {
  108189. 1, 18,
  108190. _huff_lengthlist_line_2048x27_3sub1,
  108191. 0, 0, 0, 0, 0,
  108192. NULL,
  108193. NULL,
  108194. NULL,
  108195. NULL,
  108196. 0
  108197. };
  108198. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  108199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108200. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  108201. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  108202. 10,12,
  108203. };
  108204. static static_codebook _huff_book_line_2048x27_3sub2 = {
  108205. 1, 50,
  108206. _huff_lengthlist_line_2048x27_3sub2,
  108207. 0, 0, 0, 0, 0,
  108208. NULL,
  108209. NULL,
  108210. NULL,
  108211. NULL,
  108212. 0
  108213. };
  108214. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  108215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108218. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  108219. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108220. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108221. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108222. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108223. };
  108224. static static_codebook _huff_book_line_2048x27_3sub3 = {
  108225. 1, 128,
  108226. _huff_lengthlist_line_2048x27_3sub3,
  108227. 0, 0, 0, 0, 0,
  108228. NULL,
  108229. NULL,
  108230. NULL,
  108231. NULL,
  108232. 0
  108233. };
  108234. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  108235. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  108236. 4, 5,
  108237. };
  108238. static static_codebook _huff_book_line_2048x27_4sub1 = {
  108239. 1, 18,
  108240. _huff_lengthlist_line_2048x27_4sub1,
  108241. 0, 0, 0, 0, 0,
  108242. NULL,
  108243. NULL,
  108244. NULL,
  108245. NULL,
  108246. 0
  108247. };
  108248. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  108249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108250. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  108251. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  108252. 10,10,
  108253. };
  108254. static static_codebook _huff_book_line_2048x27_4sub2 = {
  108255. 1, 50,
  108256. _huff_lengthlist_line_2048x27_4sub2,
  108257. 0, 0, 0, 0, 0,
  108258. NULL,
  108259. NULL,
  108260. NULL,
  108261. NULL,
  108262. 0
  108263. };
  108264. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  108265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108268. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  108269. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  108270. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108271. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108272. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108273. };
  108274. static static_codebook _huff_book_line_2048x27_4sub3 = {
  108275. 1, 128,
  108276. _huff_lengthlist_line_2048x27_4sub3,
  108277. 0, 0, 0, 0, 0,
  108278. NULL,
  108279. NULL,
  108280. NULL,
  108281. NULL,
  108282. 0
  108283. };
  108284. static long _huff_lengthlist_line_256x4low_class0[] = {
  108285. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108286. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108287. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108288. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108289. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108290. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108291. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108292. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108293. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108294. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108295. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108296. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108297. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108298. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108299. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108300. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108301. };
  108302. static static_codebook _huff_book_line_256x4low_class0 = {
  108303. 1, 256,
  108304. _huff_lengthlist_line_256x4low_class0,
  108305. 0, 0, 0, 0, 0,
  108306. NULL,
  108307. NULL,
  108308. NULL,
  108309. NULL,
  108310. 0
  108311. };
  108312. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108313. 1, 3, 2, 3,
  108314. };
  108315. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108316. 1, 4,
  108317. _huff_lengthlist_line_256x4low_0sub0,
  108318. 0, 0, 0, 0, 0,
  108319. NULL,
  108320. NULL,
  108321. NULL,
  108322. NULL,
  108323. 0
  108324. };
  108325. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108326. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108327. };
  108328. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108329. 1, 10,
  108330. _huff_lengthlist_line_256x4low_0sub1,
  108331. 0, 0, 0, 0, 0,
  108332. NULL,
  108333. NULL,
  108334. NULL,
  108335. NULL,
  108336. 0
  108337. };
  108338. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108340. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108341. };
  108342. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108343. 1, 25,
  108344. _huff_lengthlist_line_256x4low_0sub2,
  108345. 0, 0, 0, 0, 0,
  108346. NULL,
  108347. NULL,
  108348. NULL,
  108349. NULL,
  108350. 0
  108351. };
  108352. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  108353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  108355. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108356. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108357. };
  108358. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108359. 1, 64,
  108360. _huff_lengthlist_line_256x4low_0sub3,
  108361. 0, 0, 0, 0, 0,
  108362. NULL,
  108363. NULL,
  108364. NULL,
  108365. NULL,
  108366. 0
  108367. };
  108368. /*** End of inlined file: floor_books.h ***/
  108369. static static_codebook *_floor_128x4_books[]={
  108370. &_huff_book_line_128x4_class0,
  108371. &_huff_book_line_128x4_0sub0,
  108372. &_huff_book_line_128x4_0sub1,
  108373. &_huff_book_line_128x4_0sub2,
  108374. &_huff_book_line_128x4_0sub3,
  108375. };
  108376. static static_codebook *_floor_256x4_books[]={
  108377. &_huff_book_line_256x4_class0,
  108378. &_huff_book_line_256x4_0sub0,
  108379. &_huff_book_line_256x4_0sub1,
  108380. &_huff_book_line_256x4_0sub2,
  108381. &_huff_book_line_256x4_0sub3,
  108382. };
  108383. static static_codebook *_floor_128x7_books[]={
  108384. &_huff_book_line_128x7_class0,
  108385. &_huff_book_line_128x7_class1,
  108386. &_huff_book_line_128x7_0sub1,
  108387. &_huff_book_line_128x7_0sub2,
  108388. &_huff_book_line_128x7_0sub3,
  108389. &_huff_book_line_128x7_1sub1,
  108390. &_huff_book_line_128x7_1sub2,
  108391. &_huff_book_line_128x7_1sub3,
  108392. };
  108393. static static_codebook *_floor_256x7_books[]={
  108394. &_huff_book_line_256x7_class0,
  108395. &_huff_book_line_256x7_class1,
  108396. &_huff_book_line_256x7_0sub1,
  108397. &_huff_book_line_256x7_0sub2,
  108398. &_huff_book_line_256x7_0sub3,
  108399. &_huff_book_line_256x7_1sub1,
  108400. &_huff_book_line_256x7_1sub2,
  108401. &_huff_book_line_256x7_1sub3,
  108402. };
  108403. static static_codebook *_floor_128x11_books[]={
  108404. &_huff_book_line_128x11_class1,
  108405. &_huff_book_line_128x11_class2,
  108406. &_huff_book_line_128x11_class3,
  108407. &_huff_book_line_128x11_0sub0,
  108408. &_huff_book_line_128x11_1sub0,
  108409. &_huff_book_line_128x11_1sub1,
  108410. &_huff_book_line_128x11_2sub1,
  108411. &_huff_book_line_128x11_2sub2,
  108412. &_huff_book_line_128x11_2sub3,
  108413. &_huff_book_line_128x11_3sub1,
  108414. &_huff_book_line_128x11_3sub2,
  108415. &_huff_book_line_128x11_3sub3,
  108416. };
  108417. static static_codebook *_floor_128x17_books[]={
  108418. &_huff_book_line_128x17_class1,
  108419. &_huff_book_line_128x17_class2,
  108420. &_huff_book_line_128x17_class3,
  108421. &_huff_book_line_128x17_0sub0,
  108422. &_huff_book_line_128x17_1sub0,
  108423. &_huff_book_line_128x17_1sub1,
  108424. &_huff_book_line_128x17_2sub1,
  108425. &_huff_book_line_128x17_2sub2,
  108426. &_huff_book_line_128x17_2sub3,
  108427. &_huff_book_line_128x17_3sub1,
  108428. &_huff_book_line_128x17_3sub2,
  108429. &_huff_book_line_128x17_3sub3,
  108430. };
  108431. static static_codebook *_floor_256x4low_books[]={
  108432. &_huff_book_line_256x4low_class0,
  108433. &_huff_book_line_256x4low_0sub0,
  108434. &_huff_book_line_256x4low_0sub1,
  108435. &_huff_book_line_256x4low_0sub2,
  108436. &_huff_book_line_256x4low_0sub3,
  108437. };
  108438. static static_codebook *_floor_1024x27_books[]={
  108439. &_huff_book_line_1024x27_class1,
  108440. &_huff_book_line_1024x27_class2,
  108441. &_huff_book_line_1024x27_class3,
  108442. &_huff_book_line_1024x27_class4,
  108443. &_huff_book_line_1024x27_0sub0,
  108444. &_huff_book_line_1024x27_1sub0,
  108445. &_huff_book_line_1024x27_1sub1,
  108446. &_huff_book_line_1024x27_2sub0,
  108447. &_huff_book_line_1024x27_2sub1,
  108448. &_huff_book_line_1024x27_3sub1,
  108449. &_huff_book_line_1024x27_3sub2,
  108450. &_huff_book_line_1024x27_3sub3,
  108451. &_huff_book_line_1024x27_4sub1,
  108452. &_huff_book_line_1024x27_4sub2,
  108453. &_huff_book_line_1024x27_4sub3,
  108454. };
  108455. static static_codebook *_floor_2048x27_books[]={
  108456. &_huff_book_line_2048x27_class1,
  108457. &_huff_book_line_2048x27_class2,
  108458. &_huff_book_line_2048x27_class3,
  108459. &_huff_book_line_2048x27_class4,
  108460. &_huff_book_line_2048x27_0sub0,
  108461. &_huff_book_line_2048x27_1sub0,
  108462. &_huff_book_line_2048x27_1sub1,
  108463. &_huff_book_line_2048x27_2sub0,
  108464. &_huff_book_line_2048x27_2sub1,
  108465. &_huff_book_line_2048x27_3sub1,
  108466. &_huff_book_line_2048x27_3sub2,
  108467. &_huff_book_line_2048x27_3sub3,
  108468. &_huff_book_line_2048x27_4sub1,
  108469. &_huff_book_line_2048x27_4sub2,
  108470. &_huff_book_line_2048x27_4sub3,
  108471. };
  108472. static static_codebook *_floor_512x17_books[]={
  108473. &_huff_book_line_512x17_class1,
  108474. &_huff_book_line_512x17_class2,
  108475. &_huff_book_line_512x17_class3,
  108476. &_huff_book_line_512x17_0sub0,
  108477. &_huff_book_line_512x17_1sub0,
  108478. &_huff_book_line_512x17_1sub1,
  108479. &_huff_book_line_512x17_2sub1,
  108480. &_huff_book_line_512x17_2sub2,
  108481. &_huff_book_line_512x17_2sub3,
  108482. &_huff_book_line_512x17_3sub1,
  108483. &_huff_book_line_512x17_3sub2,
  108484. &_huff_book_line_512x17_3sub3,
  108485. };
  108486. static static_codebook **_floor_books[10]={
  108487. _floor_128x4_books,
  108488. _floor_256x4_books,
  108489. _floor_128x7_books,
  108490. _floor_256x7_books,
  108491. _floor_128x11_books,
  108492. _floor_128x17_books,
  108493. _floor_256x4low_books,
  108494. _floor_1024x27_books,
  108495. _floor_2048x27_books,
  108496. _floor_512x17_books,
  108497. };
  108498. static vorbis_info_floor1 _floor[10]={
  108499. {
  108500. 1,{0},{4},{2},{0},
  108501. {{1,2,3,4}},
  108502. 4,{0,128, 33,8,16,70},
  108503. 60,30,500, 1.,18., -1
  108504. },
  108505. {
  108506. 1,{0},{4},{2},{0},
  108507. {{1,2,3,4}},
  108508. 4,{0,256, 66,16,32,140},
  108509. 60,30,500, 1.,18., -1
  108510. },
  108511. {
  108512. 2,{0,1},{3,4},{2,2},{0,1},
  108513. {{-1,2,3,4},{-1,5,6,7}},
  108514. 4,{0,128, 14,4,58, 2,8,28,90},
  108515. 60,30,500, 1.,18., -1
  108516. },
  108517. {
  108518. 2,{0,1},{3,4},{2,2},{0,1},
  108519. {{-1,2,3,4},{-1,5,6,7}},
  108520. 4,{0,256, 28,8,116, 4,16,56,180},
  108521. 60,30,500, 1.,18., -1
  108522. },
  108523. {
  108524. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108525. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108526. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108527. 60,30,500, 1,18., -1
  108528. },
  108529. {
  108530. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108531. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108532. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108533. 60,30,500, 1,18., -1
  108534. },
  108535. {
  108536. 1,{0},{4},{2},{0},
  108537. {{1,2,3,4}},
  108538. 4,{0,256, 66,16,32,140},
  108539. 60,30,500, 1.,18., -1
  108540. },
  108541. {
  108542. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108543. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108544. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108545. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108546. 60,30,500, 3,18., -1 /* lowpass */
  108547. },
  108548. {
  108549. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108550. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108551. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108552. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108553. 60,30,500, 3,18., -1 /* lowpass */
  108554. },
  108555. {
  108556. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108557. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108558. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108559. 7,23,39, 55,79,110, 156,232,360},
  108560. 60,30,500, 1,18., -1 /* lowpass! */
  108561. },
  108562. };
  108563. /*** End of inlined file: floor_all.h ***/
  108564. /*** Start of inlined file: residue_44.h ***/
  108565. /*** Start of inlined file: res_books_stereo.h ***/
  108566. static long _vq_quantlist__16c0_s_p1_0[] = {
  108567. 1,
  108568. 0,
  108569. 2,
  108570. };
  108571. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108572. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108573. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108577. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108578. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108582. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108583. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108614. 0, 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, 5, 8, 8, 0, 0, 0, 0,
  108618. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0,
  108623. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  108628. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108643. 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108664. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108669. 0, 0, 0, 0, 0, 9,10,12, 0, 0, 0, 0, 0, 0, 0, 0,
  108670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108673. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108674. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108685. 0, 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,
  108983. };
  108984. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108985. -0.5, 0.5,
  108986. };
  108987. static long _vq_quantmap__16c0_s_p1_0[] = {
  108988. 1, 0, 2,
  108989. };
  108990. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108991. _vq_quantthresh__16c0_s_p1_0,
  108992. _vq_quantmap__16c0_s_p1_0,
  108993. 3,
  108994. 3
  108995. };
  108996. static static_codebook _16c0_s_p1_0 = {
  108997. 8, 6561,
  108998. _vq_lengthlist__16c0_s_p1_0,
  108999. 1, -535822336, 1611661312, 2, 0,
  109000. _vq_quantlist__16c0_s_p1_0,
  109001. NULL,
  109002. &_vq_auxt__16c0_s_p1_0,
  109003. NULL,
  109004. 0
  109005. };
  109006. static long _vq_quantlist__16c0_s_p2_0[] = {
  109007. 2,
  109008. 1,
  109009. 3,
  109010. 0,
  109011. 4,
  109012. };
  109013. static long _vq_lengthlist__16c0_s_p2_0[] = {
  109014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  109054. };
  109055. static float _vq_quantthresh__16c0_s_p2_0[] = {
  109056. -1.5, -0.5, 0.5, 1.5,
  109057. };
  109058. static long _vq_quantmap__16c0_s_p2_0[] = {
  109059. 3, 1, 0, 2, 4,
  109060. };
  109061. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  109062. _vq_quantthresh__16c0_s_p2_0,
  109063. _vq_quantmap__16c0_s_p2_0,
  109064. 5,
  109065. 5
  109066. };
  109067. static static_codebook _16c0_s_p2_0 = {
  109068. 4, 625,
  109069. _vq_lengthlist__16c0_s_p2_0,
  109070. 1, -533725184, 1611661312, 3, 0,
  109071. _vq_quantlist__16c0_s_p2_0,
  109072. NULL,
  109073. &_vq_auxt__16c0_s_p2_0,
  109074. NULL,
  109075. 0
  109076. };
  109077. static long _vq_quantlist__16c0_s_p3_0[] = {
  109078. 2,
  109079. 1,
  109080. 3,
  109081. 0,
  109082. 4,
  109083. };
  109084. static long _vq_lengthlist__16c0_s_p3_0[] = {
  109085. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  109087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109088. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  109090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109091. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  109125. };
  109126. static float _vq_quantthresh__16c0_s_p3_0[] = {
  109127. -1.5, -0.5, 0.5, 1.5,
  109128. };
  109129. static long _vq_quantmap__16c0_s_p3_0[] = {
  109130. 3, 1, 0, 2, 4,
  109131. };
  109132. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  109133. _vq_quantthresh__16c0_s_p3_0,
  109134. _vq_quantmap__16c0_s_p3_0,
  109135. 5,
  109136. 5
  109137. };
  109138. static static_codebook _16c0_s_p3_0 = {
  109139. 4, 625,
  109140. _vq_lengthlist__16c0_s_p3_0,
  109141. 1, -533725184, 1611661312, 3, 0,
  109142. _vq_quantlist__16c0_s_p3_0,
  109143. NULL,
  109144. &_vq_auxt__16c0_s_p3_0,
  109145. NULL,
  109146. 0
  109147. };
  109148. static long _vq_quantlist__16c0_s_p4_0[] = {
  109149. 4,
  109150. 3,
  109151. 5,
  109152. 2,
  109153. 6,
  109154. 1,
  109155. 7,
  109156. 0,
  109157. 8,
  109158. };
  109159. static long _vq_lengthlist__16c0_s_p4_0[] = {
  109160. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109161. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109162. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109163. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  109164. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109165. 0,
  109166. };
  109167. static float _vq_quantthresh__16c0_s_p4_0[] = {
  109168. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109169. };
  109170. static long _vq_quantmap__16c0_s_p4_0[] = {
  109171. 7, 5, 3, 1, 0, 2, 4, 6,
  109172. 8,
  109173. };
  109174. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  109175. _vq_quantthresh__16c0_s_p4_0,
  109176. _vq_quantmap__16c0_s_p4_0,
  109177. 9,
  109178. 9
  109179. };
  109180. static static_codebook _16c0_s_p4_0 = {
  109181. 2, 81,
  109182. _vq_lengthlist__16c0_s_p4_0,
  109183. 1, -531628032, 1611661312, 4, 0,
  109184. _vq_quantlist__16c0_s_p4_0,
  109185. NULL,
  109186. &_vq_auxt__16c0_s_p4_0,
  109187. NULL,
  109188. 0
  109189. };
  109190. static long _vq_quantlist__16c0_s_p5_0[] = {
  109191. 4,
  109192. 3,
  109193. 5,
  109194. 2,
  109195. 6,
  109196. 1,
  109197. 7,
  109198. 0,
  109199. 8,
  109200. };
  109201. static long _vq_lengthlist__16c0_s_p5_0[] = {
  109202. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109203. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  109204. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  109205. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  109206. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109207. 10,
  109208. };
  109209. static float _vq_quantthresh__16c0_s_p5_0[] = {
  109210. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109211. };
  109212. static long _vq_quantmap__16c0_s_p5_0[] = {
  109213. 7, 5, 3, 1, 0, 2, 4, 6,
  109214. 8,
  109215. };
  109216. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  109217. _vq_quantthresh__16c0_s_p5_0,
  109218. _vq_quantmap__16c0_s_p5_0,
  109219. 9,
  109220. 9
  109221. };
  109222. static static_codebook _16c0_s_p5_0 = {
  109223. 2, 81,
  109224. _vq_lengthlist__16c0_s_p5_0,
  109225. 1, -531628032, 1611661312, 4, 0,
  109226. _vq_quantlist__16c0_s_p5_0,
  109227. NULL,
  109228. &_vq_auxt__16c0_s_p5_0,
  109229. NULL,
  109230. 0
  109231. };
  109232. static long _vq_quantlist__16c0_s_p6_0[] = {
  109233. 8,
  109234. 7,
  109235. 9,
  109236. 6,
  109237. 10,
  109238. 5,
  109239. 11,
  109240. 4,
  109241. 12,
  109242. 3,
  109243. 13,
  109244. 2,
  109245. 14,
  109246. 1,
  109247. 15,
  109248. 0,
  109249. 16,
  109250. };
  109251. static long _vq_lengthlist__16c0_s_p6_0[] = {
  109252. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  109253. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  109254. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  109255. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  109256. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  109257. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109258. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109259. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109260. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  109261. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109262. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  109263. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  109264. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  109265. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  109266. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  109267. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  109268. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  109269. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  109270. 14,
  109271. };
  109272. static float _vq_quantthresh__16c0_s_p6_0[] = {
  109273. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109274. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109275. };
  109276. static long _vq_quantmap__16c0_s_p6_0[] = {
  109277. 15, 13, 11, 9, 7, 5, 3, 1,
  109278. 0, 2, 4, 6, 8, 10, 12, 14,
  109279. 16,
  109280. };
  109281. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  109282. _vq_quantthresh__16c0_s_p6_0,
  109283. _vq_quantmap__16c0_s_p6_0,
  109284. 17,
  109285. 17
  109286. };
  109287. static static_codebook _16c0_s_p6_0 = {
  109288. 2, 289,
  109289. _vq_lengthlist__16c0_s_p6_0,
  109290. 1, -529530880, 1611661312, 5, 0,
  109291. _vq_quantlist__16c0_s_p6_0,
  109292. NULL,
  109293. &_vq_auxt__16c0_s_p6_0,
  109294. NULL,
  109295. 0
  109296. };
  109297. static long _vq_quantlist__16c0_s_p7_0[] = {
  109298. 1,
  109299. 0,
  109300. 2,
  109301. };
  109302. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109303. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109304. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109305. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109306. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109307. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109308. 13,
  109309. };
  109310. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109311. -5.5, 5.5,
  109312. };
  109313. static long _vq_quantmap__16c0_s_p7_0[] = {
  109314. 1, 0, 2,
  109315. };
  109316. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109317. _vq_quantthresh__16c0_s_p7_0,
  109318. _vq_quantmap__16c0_s_p7_0,
  109319. 3,
  109320. 3
  109321. };
  109322. static static_codebook _16c0_s_p7_0 = {
  109323. 4, 81,
  109324. _vq_lengthlist__16c0_s_p7_0,
  109325. 1, -529137664, 1618345984, 2, 0,
  109326. _vq_quantlist__16c0_s_p7_0,
  109327. NULL,
  109328. &_vq_auxt__16c0_s_p7_0,
  109329. NULL,
  109330. 0
  109331. };
  109332. static long _vq_quantlist__16c0_s_p7_1[] = {
  109333. 5,
  109334. 4,
  109335. 6,
  109336. 3,
  109337. 7,
  109338. 2,
  109339. 8,
  109340. 1,
  109341. 9,
  109342. 0,
  109343. 10,
  109344. };
  109345. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109346. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109347. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109348. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109349. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109350. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109351. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109352. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109353. 11,11,11, 9, 9, 9, 9,10,10,
  109354. };
  109355. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109356. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109357. 3.5, 4.5,
  109358. };
  109359. static long _vq_quantmap__16c0_s_p7_1[] = {
  109360. 9, 7, 5, 3, 1, 0, 2, 4,
  109361. 6, 8, 10,
  109362. };
  109363. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109364. _vq_quantthresh__16c0_s_p7_1,
  109365. _vq_quantmap__16c0_s_p7_1,
  109366. 11,
  109367. 11
  109368. };
  109369. static static_codebook _16c0_s_p7_1 = {
  109370. 2, 121,
  109371. _vq_lengthlist__16c0_s_p7_1,
  109372. 1, -531365888, 1611661312, 4, 0,
  109373. _vq_quantlist__16c0_s_p7_1,
  109374. NULL,
  109375. &_vq_auxt__16c0_s_p7_1,
  109376. NULL,
  109377. 0
  109378. };
  109379. static long _vq_quantlist__16c0_s_p8_0[] = {
  109380. 6,
  109381. 5,
  109382. 7,
  109383. 4,
  109384. 8,
  109385. 3,
  109386. 9,
  109387. 2,
  109388. 10,
  109389. 1,
  109390. 11,
  109391. 0,
  109392. 12,
  109393. };
  109394. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109395. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109396. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109397. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109398. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109399. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109400. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109401. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109402. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109403. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109404. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109405. 0,12,13,13,12,13,14,14,14,
  109406. };
  109407. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109408. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109409. 12.5, 17.5, 22.5, 27.5,
  109410. };
  109411. static long _vq_quantmap__16c0_s_p8_0[] = {
  109412. 11, 9, 7, 5, 3, 1, 0, 2,
  109413. 4, 6, 8, 10, 12,
  109414. };
  109415. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109416. _vq_quantthresh__16c0_s_p8_0,
  109417. _vq_quantmap__16c0_s_p8_0,
  109418. 13,
  109419. 13
  109420. };
  109421. static static_codebook _16c0_s_p8_0 = {
  109422. 2, 169,
  109423. _vq_lengthlist__16c0_s_p8_0,
  109424. 1, -526516224, 1616117760, 4, 0,
  109425. _vq_quantlist__16c0_s_p8_0,
  109426. NULL,
  109427. &_vq_auxt__16c0_s_p8_0,
  109428. NULL,
  109429. 0
  109430. };
  109431. static long _vq_quantlist__16c0_s_p8_1[] = {
  109432. 2,
  109433. 1,
  109434. 3,
  109435. 0,
  109436. 4,
  109437. };
  109438. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109439. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109440. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109441. };
  109442. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109443. -1.5, -0.5, 0.5, 1.5,
  109444. };
  109445. static long _vq_quantmap__16c0_s_p8_1[] = {
  109446. 3, 1, 0, 2, 4,
  109447. };
  109448. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109449. _vq_quantthresh__16c0_s_p8_1,
  109450. _vq_quantmap__16c0_s_p8_1,
  109451. 5,
  109452. 5
  109453. };
  109454. static static_codebook _16c0_s_p8_1 = {
  109455. 2, 25,
  109456. _vq_lengthlist__16c0_s_p8_1,
  109457. 1, -533725184, 1611661312, 3, 0,
  109458. _vq_quantlist__16c0_s_p8_1,
  109459. NULL,
  109460. &_vq_auxt__16c0_s_p8_1,
  109461. NULL,
  109462. 0
  109463. };
  109464. static long _vq_quantlist__16c0_s_p9_0[] = {
  109465. 1,
  109466. 0,
  109467. 2,
  109468. };
  109469. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109470. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109471. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109472. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109473. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109474. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109475. 7,
  109476. };
  109477. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109478. -157.5, 157.5,
  109479. };
  109480. static long _vq_quantmap__16c0_s_p9_0[] = {
  109481. 1, 0, 2,
  109482. };
  109483. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109484. _vq_quantthresh__16c0_s_p9_0,
  109485. _vq_quantmap__16c0_s_p9_0,
  109486. 3,
  109487. 3
  109488. };
  109489. static static_codebook _16c0_s_p9_0 = {
  109490. 4, 81,
  109491. _vq_lengthlist__16c0_s_p9_0,
  109492. 1, -518803456, 1628680192, 2, 0,
  109493. _vq_quantlist__16c0_s_p9_0,
  109494. NULL,
  109495. &_vq_auxt__16c0_s_p9_0,
  109496. NULL,
  109497. 0
  109498. };
  109499. static long _vq_quantlist__16c0_s_p9_1[] = {
  109500. 7,
  109501. 6,
  109502. 8,
  109503. 5,
  109504. 9,
  109505. 4,
  109506. 10,
  109507. 3,
  109508. 11,
  109509. 2,
  109510. 12,
  109511. 1,
  109512. 13,
  109513. 0,
  109514. 14,
  109515. };
  109516. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109517. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109518. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109519. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109520. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109521. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109522. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109523. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109524. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109525. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109526. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109527. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109528. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109529. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109530. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109531. 10,
  109532. };
  109533. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109534. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109535. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109536. };
  109537. static long _vq_quantmap__16c0_s_p9_1[] = {
  109538. 13, 11, 9, 7, 5, 3, 1, 0,
  109539. 2, 4, 6, 8, 10, 12, 14,
  109540. };
  109541. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109542. _vq_quantthresh__16c0_s_p9_1,
  109543. _vq_quantmap__16c0_s_p9_1,
  109544. 15,
  109545. 15
  109546. };
  109547. static static_codebook _16c0_s_p9_1 = {
  109548. 2, 225,
  109549. _vq_lengthlist__16c0_s_p9_1,
  109550. 1, -520986624, 1620377600, 4, 0,
  109551. _vq_quantlist__16c0_s_p9_1,
  109552. NULL,
  109553. &_vq_auxt__16c0_s_p9_1,
  109554. NULL,
  109555. 0
  109556. };
  109557. static long _vq_quantlist__16c0_s_p9_2[] = {
  109558. 10,
  109559. 9,
  109560. 11,
  109561. 8,
  109562. 12,
  109563. 7,
  109564. 13,
  109565. 6,
  109566. 14,
  109567. 5,
  109568. 15,
  109569. 4,
  109570. 16,
  109571. 3,
  109572. 17,
  109573. 2,
  109574. 18,
  109575. 1,
  109576. 19,
  109577. 0,
  109578. 20,
  109579. };
  109580. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109581. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109582. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109583. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109584. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109585. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109586. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109587. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109588. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109589. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109590. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109591. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109592. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109593. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109594. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109595. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109596. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109597. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109598. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109599. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109600. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109601. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109602. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109603. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109604. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109605. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109606. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109607. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109608. 10,11,10,10,11, 9,10,10,10,
  109609. };
  109610. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109611. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109612. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109613. 6.5, 7.5, 8.5, 9.5,
  109614. };
  109615. static long _vq_quantmap__16c0_s_p9_2[] = {
  109616. 19, 17, 15, 13, 11, 9, 7, 5,
  109617. 3, 1, 0, 2, 4, 6, 8, 10,
  109618. 12, 14, 16, 18, 20,
  109619. };
  109620. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109621. _vq_quantthresh__16c0_s_p9_2,
  109622. _vq_quantmap__16c0_s_p9_2,
  109623. 21,
  109624. 21
  109625. };
  109626. static static_codebook _16c0_s_p9_2 = {
  109627. 2, 441,
  109628. _vq_lengthlist__16c0_s_p9_2,
  109629. 1, -529268736, 1611661312, 5, 0,
  109630. _vq_quantlist__16c0_s_p9_2,
  109631. NULL,
  109632. &_vq_auxt__16c0_s_p9_2,
  109633. NULL,
  109634. 0
  109635. };
  109636. static long _huff_lengthlist__16c0_s_single[] = {
  109637. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109638. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109639. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109640. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109641. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109642. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109643. 16,16,18,18,
  109644. };
  109645. static static_codebook _huff_book__16c0_s_single = {
  109646. 2, 100,
  109647. _huff_lengthlist__16c0_s_single,
  109648. 0, 0, 0, 0, 0,
  109649. NULL,
  109650. NULL,
  109651. NULL,
  109652. NULL,
  109653. 0
  109654. };
  109655. static long _huff_lengthlist__16c1_s_long[] = {
  109656. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109657. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109658. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109659. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109660. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109661. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109662. 12,11,11,13,
  109663. };
  109664. static static_codebook _huff_book__16c1_s_long = {
  109665. 2, 100,
  109666. _huff_lengthlist__16c1_s_long,
  109667. 0, 0, 0, 0, 0,
  109668. NULL,
  109669. NULL,
  109670. NULL,
  109671. NULL,
  109672. 0
  109673. };
  109674. static long _vq_quantlist__16c1_s_p1_0[] = {
  109675. 1,
  109676. 0,
  109677. 2,
  109678. };
  109679. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109680. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109681. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109685. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109686. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109690. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109691. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109722. 0, 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, 5, 8, 7, 0, 0, 0, 0,
  109726. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  109731. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109736. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109751. 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109772. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109777. 0, 0, 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  109778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109781. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109782. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109793. 0, 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,
  110091. };
  110092. static float _vq_quantthresh__16c1_s_p1_0[] = {
  110093. -0.5, 0.5,
  110094. };
  110095. static long _vq_quantmap__16c1_s_p1_0[] = {
  110096. 1, 0, 2,
  110097. };
  110098. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  110099. _vq_quantthresh__16c1_s_p1_0,
  110100. _vq_quantmap__16c1_s_p1_0,
  110101. 3,
  110102. 3
  110103. };
  110104. static static_codebook _16c1_s_p1_0 = {
  110105. 8, 6561,
  110106. _vq_lengthlist__16c1_s_p1_0,
  110107. 1, -535822336, 1611661312, 2, 0,
  110108. _vq_quantlist__16c1_s_p1_0,
  110109. NULL,
  110110. &_vq_auxt__16c1_s_p1_0,
  110111. NULL,
  110112. 0
  110113. };
  110114. static long _vq_quantlist__16c1_s_p2_0[] = {
  110115. 2,
  110116. 1,
  110117. 3,
  110118. 0,
  110119. 4,
  110120. };
  110121. static long _vq_lengthlist__16c1_s_p2_0[] = {
  110122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  110162. };
  110163. static float _vq_quantthresh__16c1_s_p2_0[] = {
  110164. -1.5, -0.5, 0.5, 1.5,
  110165. };
  110166. static long _vq_quantmap__16c1_s_p2_0[] = {
  110167. 3, 1, 0, 2, 4,
  110168. };
  110169. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  110170. _vq_quantthresh__16c1_s_p2_0,
  110171. _vq_quantmap__16c1_s_p2_0,
  110172. 5,
  110173. 5
  110174. };
  110175. static static_codebook _16c1_s_p2_0 = {
  110176. 4, 625,
  110177. _vq_lengthlist__16c1_s_p2_0,
  110178. 1, -533725184, 1611661312, 3, 0,
  110179. _vq_quantlist__16c1_s_p2_0,
  110180. NULL,
  110181. &_vq_auxt__16c1_s_p2_0,
  110182. NULL,
  110183. 0
  110184. };
  110185. static long _vq_quantlist__16c1_s_p3_0[] = {
  110186. 2,
  110187. 1,
  110188. 3,
  110189. 0,
  110190. 4,
  110191. };
  110192. static long _vq_lengthlist__16c1_s_p3_0[] = {
  110193. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  110195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110196. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  110198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110199. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  110200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  110233. };
  110234. static float _vq_quantthresh__16c1_s_p3_0[] = {
  110235. -1.5, -0.5, 0.5, 1.5,
  110236. };
  110237. static long _vq_quantmap__16c1_s_p3_0[] = {
  110238. 3, 1, 0, 2, 4,
  110239. };
  110240. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  110241. _vq_quantthresh__16c1_s_p3_0,
  110242. _vq_quantmap__16c1_s_p3_0,
  110243. 5,
  110244. 5
  110245. };
  110246. static static_codebook _16c1_s_p3_0 = {
  110247. 4, 625,
  110248. _vq_lengthlist__16c1_s_p3_0,
  110249. 1, -533725184, 1611661312, 3, 0,
  110250. _vq_quantlist__16c1_s_p3_0,
  110251. NULL,
  110252. &_vq_auxt__16c1_s_p3_0,
  110253. NULL,
  110254. 0
  110255. };
  110256. static long _vq_quantlist__16c1_s_p4_0[] = {
  110257. 4,
  110258. 3,
  110259. 5,
  110260. 2,
  110261. 6,
  110262. 1,
  110263. 7,
  110264. 0,
  110265. 8,
  110266. };
  110267. static long _vq_lengthlist__16c1_s_p4_0[] = {
  110268. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  110269. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  110270. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  110271. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  110272. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110273. 0,
  110274. };
  110275. static float _vq_quantthresh__16c1_s_p4_0[] = {
  110276. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110277. };
  110278. static long _vq_quantmap__16c1_s_p4_0[] = {
  110279. 7, 5, 3, 1, 0, 2, 4, 6,
  110280. 8,
  110281. };
  110282. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  110283. _vq_quantthresh__16c1_s_p4_0,
  110284. _vq_quantmap__16c1_s_p4_0,
  110285. 9,
  110286. 9
  110287. };
  110288. static static_codebook _16c1_s_p4_0 = {
  110289. 2, 81,
  110290. _vq_lengthlist__16c1_s_p4_0,
  110291. 1, -531628032, 1611661312, 4, 0,
  110292. _vq_quantlist__16c1_s_p4_0,
  110293. NULL,
  110294. &_vq_auxt__16c1_s_p4_0,
  110295. NULL,
  110296. 0
  110297. };
  110298. static long _vq_quantlist__16c1_s_p5_0[] = {
  110299. 4,
  110300. 3,
  110301. 5,
  110302. 2,
  110303. 6,
  110304. 1,
  110305. 7,
  110306. 0,
  110307. 8,
  110308. };
  110309. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110310. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110311. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110312. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110313. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110314. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110315. 10,
  110316. };
  110317. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110318. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110319. };
  110320. static long _vq_quantmap__16c1_s_p5_0[] = {
  110321. 7, 5, 3, 1, 0, 2, 4, 6,
  110322. 8,
  110323. };
  110324. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110325. _vq_quantthresh__16c1_s_p5_0,
  110326. _vq_quantmap__16c1_s_p5_0,
  110327. 9,
  110328. 9
  110329. };
  110330. static static_codebook _16c1_s_p5_0 = {
  110331. 2, 81,
  110332. _vq_lengthlist__16c1_s_p5_0,
  110333. 1, -531628032, 1611661312, 4, 0,
  110334. _vq_quantlist__16c1_s_p5_0,
  110335. NULL,
  110336. &_vq_auxt__16c1_s_p5_0,
  110337. NULL,
  110338. 0
  110339. };
  110340. static long _vq_quantlist__16c1_s_p6_0[] = {
  110341. 8,
  110342. 7,
  110343. 9,
  110344. 6,
  110345. 10,
  110346. 5,
  110347. 11,
  110348. 4,
  110349. 12,
  110350. 3,
  110351. 13,
  110352. 2,
  110353. 14,
  110354. 1,
  110355. 15,
  110356. 0,
  110357. 16,
  110358. };
  110359. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110360. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110361. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110362. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110363. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110364. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110365. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110366. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110367. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110368. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110369. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110370. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110371. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110372. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110373. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110374. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110375. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110376. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110377. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110378. 14,
  110379. };
  110380. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110381. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110382. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110383. };
  110384. static long _vq_quantmap__16c1_s_p6_0[] = {
  110385. 15, 13, 11, 9, 7, 5, 3, 1,
  110386. 0, 2, 4, 6, 8, 10, 12, 14,
  110387. 16,
  110388. };
  110389. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110390. _vq_quantthresh__16c1_s_p6_0,
  110391. _vq_quantmap__16c1_s_p6_0,
  110392. 17,
  110393. 17
  110394. };
  110395. static static_codebook _16c1_s_p6_0 = {
  110396. 2, 289,
  110397. _vq_lengthlist__16c1_s_p6_0,
  110398. 1, -529530880, 1611661312, 5, 0,
  110399. _vq_quantlist__16c1_s_p6_0,
  110400. NULL,
  110401. &_vq_auxt__16c1_s_p6_0,
  110402. NULL,
  110403. 0
  110404. };
  110405. static long _vq_quantlist__16c1_s_p7_0[] = {
  110406. 1,
  110407. 0,
  110408. 2,
  110409. };
  110410. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110411. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110412. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110413. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110414. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110415. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110416. 11,
  110417. };
  110418. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110419. -5.5, 5.5,
  110420. };
  110421. static long _vq_quantmap__16c1_s_p7_0[] = {
  110422. 1, 0, 2,
  110423. };
  110424. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110425. _vq_quantthresh__16c1_s_p7_0,
  110426. _vq_quantmap__16c1_s_p7_0,
  110427. 3,
  110428. 3
  110429. };
  110430. static static_codebook _16c1_s_p7_0 = {
  110431. 4, 81,
  110432. _vq_lengthlist__16c1_s_p7_0,
  110433. 1, -529137664, 1618345984, 2, 0,
  110434. _vq_quantlist__16c1_s_p7_0,
  110435. NULL,
  110436. &_vq_auxt__16c1_s_p7_0,
  110437. NULL,
  110438. 0
  110439. };
  110440. static long _vq_quantlist__16c1_s_p7_1[] = {
  110441. 5,
  110442. 4,
  110443. 6,
  110444. 3,
  110445. 7,
  110446. 2,
  110447. 8,
  110448. 1,
  110449. 9,
  110450. 0,
  110451. 10,
  110452. };
  110453. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110454. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110455. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110456. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110457. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110458. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110459. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110460. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110461. 10,10,10, 8, 8, 8, 8, 9, 9,
  110462. };
  110463. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110464. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110465. 3.5, 4.5,
  110466. };
  110467. static long _vq_quantmap__16c1_s_p7_1[] = {
  110468. 9, 7, 5, 3, 1, 0, 2, 4,
  110469. 6, 8, 10,
  110470. };
  110471. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110472. _vq_quantthresh__16c1_s_p7_1,
  110473. _vq_quantmap__16c1_s_p7_1,
  110474. 11,
  110475. 11
  110476. };
  110477. static static_codebook _16c1_s_p7_1 = {
  110478. 2, 121,
  110479. _vq_lengthlist__16c1_s_p7_1,
  110480. 1, -531365888, 1611661312, 4, 0,
  110481. _vq_quantlist__16c1_s_p7_1,
  110482. NULL,
  110483. &_vq_auxt__16c1_s_p7_1,
  110484. NULL,
  110485. 0
  110486. };
  110487. static long _vq_quantlist__16c1_s_p8_0[] = {
  110488. 6,
  110489. 5,
  110490. 7,
  110491. 4,
  110492. 8,
  110493. 3,
  110494. 9,
  110495. 2,
  110496. 10,
  110497. 1,
  110498. 11,
  110499. 0,
  110500. 12,
  110501. };
  110502. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110503. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110504. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110505. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110506. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110507. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110508. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110509. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110510. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110511. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110512. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110513. 0,12,12,12,12,13,13,14,15,
  110514. };
  110515. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110516. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110517. 12.5, 17.5, 22.5, 27.5,
  110518. };
  110519. static long _vq_quantmap__16c1_s_p8_0[] = {
  110520. 11, 9, 7, 5, 3, 1, 0, 2,
  110521. 4, 6, 8, 10, 12,
  110522. };
  110523. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110524. _vq_quantthresh__16c1_s_p8_0,
  110525. _vq_quantmap__16c1_s_p8_0,
  110526. 13,
  110527. 13
  110528. };
  110529. static static_codebook _16c1_s_p8_0 = {
  110530. 2, 169,
  110531. _vq_lengthlist__16c1_s_p8_0,
  110532. 1, -526516224, 1616117760, 4, 0,
  110533. _vq_quantlist__16c1_s_p8_0,
  110534. NULL,
  110535. &_vq_auxt__16c1_s_p8_0,
  110536. NULL,
  110537. 0
  110538. };
  110539. static long _vq_quantlist__16c1_s_p8_1[] = {
  110540. 2,
  110541. 1,
  110542. 3,
  110543. 0,
  110544. 4,
  110545. };
  110546. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110547. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110548. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110549. };
  110550. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110551. -1.5, -0.5, 0.5, 1.5,
  110552. };
  110553. static long _vq_quantmap__16c1_s_p8_1[] = {
  110554. 3, 1, 0, 2, 4,
  110555. };
  110556. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110557. _vq_quantthresh__16c1_s_p8_1,
  110558. _vq_quantmap__16c1_s_p8_1,
  110559. 5,
  110560. 5
  110561. };
  110562. static static_codebook _16c1_s_p8_1 = {
  110563. 2, 25,
  110564. _vq_lengthlist__16c1_s_p8_1,
  110565. 1, -533725184, 1611661312, 3, 0,
  110566. _vq_quantlist__16c1_s_p8_1,
  110567. NULL,
  110568. &_vq_auxt__16c1_s_p8_1,
  110569. NULL,
  110570. 0
  110571. };
  110572. static long _vq_quantlist__16c1_s_p9_0[] = {
  110573. 6,
  110574. 5,
  110575. 7,
  110576. 4,
  110577. 8,
  110578. 3,
  110579. 9,
  110580. 2,
  110581. 10,
  110582. 1,
  110583. 11,
  110584. 0,
  110585. 12,
  110586. };
  110587. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110588. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110589. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110590. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110591. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110592. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110593. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110594. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110595. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110596. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110597. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110598. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110599. };
  110600. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110601. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110602. 787.5, 1102.5, 1417.5, 1732.5,
  110603. };
  110604. static long _vq_quantmap__16c1_s_p9_0[] = {
  110605. 11, 9, 7, 5, 3, 1, 0, 2,
  110606. 4, 6, 8, 10, 12,
  110607. };
  110608. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110609. _vq_quantthresh__16c1_s_p9_0,
  110610. _vq_quantmap__16c1_s_p9_0,
  110611. 13,
  110612. 13
  110613. };
  110614. static static_codebook _16c1_s_p9_0 = {
  110615. 2, 169,
  110616. _vq_lengthlist__16c1_s_p9_0,
  110617. 1, -513964032, 1628680192, 4, 0,
  110618. _vq_quantlist__16c1_s_p9_0,
  110619. NULL,
  110620. &_vq_auxt__16c1_s_p9_0,
  110621. NULL,
  110622. 0
  110623. };
  110624. static long _vq_quantlist__16c1_s_p9_1[] = {
  110625. 7,
  110626. 6,
  110627. 8,
  110628. 5,
  110629. 9,
  110630. 4,
  110631. 10,
  110632. 3,
  110633. 11,
  110634. 2,
  110635. 12,
  110636. 1,
  110637. 13,
  110638. 0,
  110639. 14,
  110640. };
  110641. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110642. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110643. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110644. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110645. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110646. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110647. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110648. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110649. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110650. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110651. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110652. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110653. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110654. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110655. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110656. 13,
  110657. };
  110658. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110659. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110660. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110661. };
  110662. static long _vq_quantmap__16c1_s_p9_1[] = {
  110663. 13, 11, 9, 7, 5, 3, 1, 0,
  110664. 2, 4, 6, 8, 10, 12, 14,
  110665. };
  110666. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110667. _vq_quantthresh__16c1_s_p9_1,
  110668. _vq_quantmap__16c1_s_p9_1,
  110669. 15,
  110670. 15
  110671. };
  110672. static static_codebook _16c1_s_p9_1 = {
  110673. 2, 225,
  110674. _vq_lengthlist__16c1_s_p9_1,
  110675. 1, -520986624, 1620377600, 4, 0,
  110676. _vq_quantlist__16c1_s_p9_1,
  110677. NULL,
  110678. &_vq_auxt__16c1_s_p9_1,
  110679. NULL,
  110680. 0
  110681. };
  110682. static long _vq_quantlist__16c1_s_p9_2[] = {
  110683. 10,
  110684. 9,
  110685. 11,
  110686. 8,
  110687. 12,
  110688. 7,
  110689. 13,
  110690. 6,
  110691. 14,
  110692. 5,
  110693. 15,
  110694. 4,
  110695. 16,
  110696. 3,
  110697. 17,
  110698. 2,
  110699. 18,
  110700. 1,
  110701. 19,
  110702. 0,
  110703. 20,
  110704. };
  110705. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110706. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110707. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110708. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110709. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110710. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110711. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110712. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110713. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110714. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110715. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110716. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110717. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110718. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110719. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110720. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110721. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110722. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110723. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110724. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110725. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110726. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110727. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110728. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110729. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110730. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110731. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110732. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110733. 11,11,11,11,12,11,11,12,11,
  110734. };
  110735. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110736. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110737. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110738. 6.5, 7.5, 8.5, 9.5,
  110739. };
  110740. static long _vq_quantmap__16c1_s_p9_2[] = {
  110741. 19, 17, 15, 13, 11, 9, 7, 5,
  110742. 3, 1, 0, 2, 4, 6, 8, 10,
  110743. 12, 14, 16, 18, 20,
  110744. };
  110745. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110746. _vq_quantthresh__16c1_s_p9_2,
  110747. _vq_quantmap__16c1_s_p9_2,
  110748. 21,
  110749. 21
  110750. };
  110751. static static_codebook _16c1_s_p9_2 = {
  110752. 2, 441,
  110753. _vq_lengthlist__16c1_s_p9_2,
  110754. 1, -529268736, 1611661312, 5, 0,
  110755. _vq_quantlist__16c1_s_p9_2,
  110756. NULL,
  110757. &_vq_auxt__16c1_s_p9_2,
  110758. NULL,
  110759. 0
  110760. };
  110761. static long _huff_lengthlist__16c1_s_short[] = {
  110762. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110763. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110764. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110765. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110766. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110767. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110768. 9, 9,10,13,
  110769. };
  110770. static static_codebook _huff_book__16c1_s_short = {
  110771. 2, 100,
  110772. _huff_lengthlist__16c1_s_short,
  110773. 0, 0, 0, 0, 0,
  110774. NULL,
  110775. NULL,
  110776. NULL,
  110777. NULL,
  110778. 0
  110779. };
  110780. static long _huff_lengthlist__16c2_s_long[] = {
  110781. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110782. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110783. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110784. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110785. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110786. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110787. 14,14,16,18,
  110788. };
  110789. static static_codebook _huff_book__16c2_s_long = {
  110790. 2, 100,
  110791. _huff_lengthlist__16c2_s_long,
  110792. 0, 0, 0, 0, 0,
  110793. NULL,
  110794. NULL,
  110795. NULL,
  110796. NULL,
  110797. 0
  110798. };
  110799. static long _vq_quantlist__16c2_s_p1_0[] = {
  110800. 1,
  110801. 0,
  110802. 2,
  110803. };
  110804. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110805. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110806. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110810. 0,
  110811. };
  110812. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110813. -0.5, 0.5,
  110814. };
  110815. static long _vq_quantmap__16c2_s_p1_0[] = {
  110816. 1, 0, 2,
  110817. };
  110818. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110819. _vq_quantthresh__16c2_s_p1_0,
  110820. _vq_quantmap__16c2_s_p1_0,
  110821. 3,
  110822. 3
  110823. };
  110824. static static_codebook _16c2_s_p1_0 = {
  110825. 4, 81,
  110826. _vq_lengthlist__16c2_s_p1_0,
  110827. 1, -535822336, 1611661312, 2, 0,
  110828. _vq_quantlist__16c2_s_p1_0,
  110829. NULL,
  110830. &_vq_auxt__16c2_s_p1_0,
  110831. NULL,
  110832. 0
  110833. };
  110834. static long _vq_quantlist__16c2_s_p2_0[] = {
  110835. 2,
  110836. 1,
  110837. 3,
  110838. 0,
  110839. 4,
  110840. };
  110841. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110842. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110843. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110844. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110845. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110846. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110847. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110848. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110849. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110854. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110855. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110856. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110857. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110863. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110864. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110865. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110871. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110872. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110873. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110875. 0, 0, 0, 0, 0, 0, 0, 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, 8,
  110878. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110879. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110880. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110881. 13,
  110882. };
  110883. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110884. -1.5, -0.5, 0.5, 1.5,
  110885. };
  110886. static long _vq_quantmap__16c2_s_p2_0[] = {
  110887. 3, 1, 0, 2, 4,
  110888. };
  110889. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110890. _vq_quantthresh__16c2_s_p2_0,
  110891. _vq_quantmap__16c2_s_p2_0,
  110892. 5,
  110893. 5
  110894. };
  110895. static static_codebook _16c2_s_p2_0 = {
  110896. 4, 625,
  110897. _vq_lengthlist__16c2_s_p2_0,
  110898. 1, -533725184, 1611661312, 3, 0,
  110899. _vq_quantlist__16c2_s_p2_0,
  110900. NULL,
  110901. &_vq_auxt__16c2_s_p2_0,
  110902. NULL,
  110903. 0
  110904. };
  110905. static long _vq_quantlist__16c2_s_p3_0[] = {
  110906. 4,
  110907. 3,
  110908. 5,
  110909. 2,
  110910. 6,
  110911. 1,
  110912. 7,
  110913. 0,
  110914. 8,
  110915. };
  110916. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110917. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110918. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110919. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110920. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110922. 0,
  110923. };
  110924. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110925. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110926. };
  110927. static long _vq_quantmap__16c2_s_p3_0[] = {
  110928. 7, 5, 3, 1, 0, 2, 4, 6,
  110929. 8,
  110930. };
  110931. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110932. _vq_quantthresh__16c2_s_p3_0,
  110933. _vq_quantmap__16c2_s_p3_0,
  110934. 9,
  110935. 9
  110936. };
  110937. static static_codebook _16c2_s_p3_0 = {
  110938. 2, 81,
  110939. _vq_lengthlist__16c2_s_p3_0,
  110940. 1, -531628032, 1611661312, 4, 0,
  110941. _vq_quantlist__16c2_s_p3_0,
  110942. NULL,
  110943. &_vq_auxt__16c2_s_p3_0,
  110944. NULL,
  110945. 0
  110946. };
  110947. static long _vq_quantlist__16c2_s_p4_0[] = {
  110948. 8,
  110949. 7,
  110950. 9,
  110951. 6,
  110952. 10,
  110953. 5,
  110954. 11,
  110955. 4,
  110956. 12,
  110957. 3,
  110958. 13,
  110959. 2,
  110960. 14,
  110961. 1,
  110962. 15,
  110963. 0,
  110964. 16,
  110965. };
  110966. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110967. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110968. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110969. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110970. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110971. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110972. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110973. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110974. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110975. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110976. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110985. 0,
  110986. };
  110987. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110988. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110989. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110990. };
  110991. static long _vq_quantmap__16c2_s_p4_0[] = {
  110992. 15, 13, 11, 9, 7, 5, 3, 1,
  110993. 0, 2, 4, 6, 8, 10, 12, 14,
  110994. 16,
  110995. };
  110996. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110997. _vq_quantthresh__16c2_s_p4_0,
  110998. _vq_quantmap__16c2_s_p4_0,
  110999. 17,
  111000. 17
  111001. };
  111002. static static_codebook _16c2_s_p4_0 = {
  111003. 2, 289,
  111004. _vq_lengthlist__16c2_s_p4_0,
  111005. 1, -529530880, 1611661312, 5, 0,
  111006. _vq_quantlist__16c2_s_p4_0,
  111007. NULL,
  111008. &_vq_auxt__16c2_s_p4_0,
  111009. NULL,
  111010. 0
  111011. };
  111012. static long _vq_quantlist__16c2_s_p5_0[] = {
  111013. 1,
  111014. 0,
  111015. 2,
  111016. };
  111017. static long _vq_lengthlist__16c2_s_p5_0[] = {
  111018. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  111019. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  111020. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  111021. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  111022. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  111023. 12,
  111024. };
  111025. static float _vq_quantthresh__16c2_s_p5_0[] = {
  111026. -5.5, 5.5,
  111027. };
  111028. static long _vq_quantmap__16c2_s_p5_0[] = {
  111029. 1, 0, 2,
  111030. };
  111031. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  111032. _vq_quantthresh__16c2_s_p5_0,
  111033. _vq_quantmap__16c2_s_p5_0,
  111034. 3,
  111035. 3
  111036. };
  111037. static static_codebook _16c2_s_p5_0 = {
  111038. 4, 81,
  111039. _vq_lengthlist__16c2_s_p5_0,
  111040. 1, -529137664, 1618345984, 2, 0,
  111041. _vq_quantlist__16c2_s_p5_0,
  111042. NULL,
  111043. &_vq_auxt__16c2_s_p5_0,
  111044. NULL,
  111045. 0
  111046. };
  111047. static long _vq_quantlist__16c2_s_p5_1[] = {
  111048. 5,
  111049. 4,
  111050. 6,
  111051. 3,
  111052. 7,
  111053. 2,
  111054. 8,
  111055. 1,
  111056. 9,
  111057. 0,
  111058. 10,
  111059. };
  111060. static long _vq_lengthlist__16c2_s_p5_1[] = {
  111061. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  111062. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  111063. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  111064. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  111065. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  111066. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  111067. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  111068. 11,11,11, 7, 7, 8, 8, 8, 8,
  111069. };
  111070. static float _vq_quantthresh__16c2_s_p5_1[] = {
  111071. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111072. 3.5, 4.5,
  111073. };
  111074. static long _vq_quantmap__16c2_s_p5_1[] = {
  111075. 9, 7, 5, 3, 1, 0, 2, 4,
  111076. 6, 8, 10,
  111077. };
  111078. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  111079. _vq_quantthresh__16c2_s_p5_1,
  111080. _vq_quantmap__16c2_s_p5_1,
  111081. 11,
  111082. 11
  111083. };
  111084. static static_codebook _16c2_s_p5_1 = {
  111085. 2, 121,
  111086. _vq_lengthlist__16c2_s_p5_1,
  111087. 1, -531365888, 1611661312, 4, 0,
  111088. _vq_quantlist__16c2_s_p5_1,
  111089. NULL,
  111090. &_vq_auxt__16c2_s_p5_1,
  111091. NULL,
  111092. 0
  111093. };
  111094. static long _vq_quantlist__16c2_s_p6_0[] = {
  111095. 6,
  111096. 5,
  111097. 7,
  111098. 4,
  111099. 8,
  111100. 3,
  111101. 9,
  111102. 2,
  111103. 10,
  111104. 1,
  111105. 11,
  111106. 0,
  111107. 12,
  111108. };
  111109. static long _vq_lengthlist__16c2_s_p6_0[] = {
  111110. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111111. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  111112. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  111113. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  111114. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  111115. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  111116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111120. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111121. };
  111122. static float _vq_quantthresh__16c2_s_p6_0[] = {
  111123. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111124. 12.5, 17.5, 22.5, 27.5,
  111125. };
  111126. static long _vq_quantmap__16c2_s_p6_0[] = {
  111127. 11, 9, 7, 5, 3, 1, 0, 2,
  111128. 4, 6, 8, 10, 12,
  111129. };
  111130. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  111131. _vq_quantthresh__16c2_s_p6_0,
  111132. _vq_quantmap__16c2_s_p6_0,
  111133. 13,
  111134. 13
  111135. };
  111136. static static_codebook _16c2_s_p6_0 = {
  111137. 2, 169,
  111138. _vq_lengthlist__16c2_s_p6_0,
  111139. 1, -526516224, 1616117760, 4, 0,
  111140. _vq_quantlist__16c2_s_p6_0,
  111141. NULL,
  111142. &_vq_auxt__16c2_s_p6_0,
  111143. NULL,
  111144. 0
  111145. };
  111146. static long _vq_quantlist__16c2_s_p6_1[] = {
  111147. 2,
  111148. 1,
  111149. 3,
  111150. 0,
  111151. 4,
  111152. };
  111153. static long _vq_lengthlist__16c2_s_p6_1[] = {
  111154. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  111155. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  111156. };
  111157. static float _vq_quantthresh__16c2_s_p6_1[] = {
  111158. -1.5, -0.5, 0.5, 1.5,
  111159. };
  111160. static long _vq_quantmap__16c2_s_p6_1[] = {
  111161. 3, 1, 0, 2, 4,
  111162. };
  111163. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  111164. _vq_quantthresh__16c2_s_p6_1,
  111165. _vq_quantmap__16c2_s_p6_1,
  111166. 5,
  111167. 5
  111168. };
  111169. static static_codebook _16c2_s_p6_1 = {
  111170. 2, 25,
  111171. _vq_lengthlist__16c2_s_p6_1,
  111172. 1, -533725184, 1611661312, 3, 0,
  111173. _vq_quantlist__16c2_s_p6_1,
  111174. NULL,
  111175. &_vq_auxt__16c2_s_p6_1,
  111176. NULL,
  111177. 0
  111178. };
  111179. static long _vq_quantlist__16c2_s_p7_0[] = {
  111180. 6,
  111181. 5,
  111182. 7,
  111183. 4,
  111184. 8,
  111185. 3,
  111186. 9,
  111187. 2,
  111188. 10,
  111189. 1,
  111190. 11,
  111191. 0,
  111192. 12,
  111193. };
  111194. static long _vq_lengthlist__16c2_s_p7_0[] = {
  111195. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111196. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  111197. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  111198. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  111199. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  111200. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  111201. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  111202. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  111203. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  111204. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  111205. 18,13,14,13,13,14,13,15,14,
  111206. };
  111207. static float _vq_quantthresh__16c2_s_p7_0[] = {
  111208. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  111209. 27.5, 38.5, 49.5, 60.5,
  111210. };
  111211. static long _vq_quantmap__16c2_s_p7_0[] = {
  111212. 11, 9, 7, 5, 3, 1, 0, 2,
  111213. 4, 6, 8, 10, 12,
  111214. };
  111215. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  111216. _vq_quantthresh__16c2_s_p7_0,
  111217. _vq_quantmap__16c2_s_p7_0,
  111218. 13,
  111219. 13
  111220. };
  111221. static static_codebook _16c2_s_p7_0 = {
  111222. 2, 169,
  111223. _vq_lengthlist__16c2_s_p7_0,
  111224. 1, -523206656, 1618345984, 4, 0,
  111225. _vq_quantlist__16c2_s_p7_0,
  111226. NULL,
  111227. &_vq_auxt__16c2_s_p7_0,
  111228. NULL,
  111229. 0
  111230. };
  111231. static long _vq_quantlist__16c2_s_p7_1[] = {
  111232. 5,
  111233. 4,
  111234. 6,
  111235. 3,
  111236. 7,
  111237. 2,
  111238. 8,
  111239. 1,
  111240. 9,
  111241. 0,
  111242. 10,
  111243. };
  111244. static long _vq_lengthlist__16c2_s_p7_1[] = {
  111245. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  111246. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  111247. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  111248. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111249. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  111250. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  111251. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  111252. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111253. };
  111254. static float _vq_quantthresh__16c2_s_p7_1[] = {
  111255. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111256. 3.5, 4.5,
  111257. };
  111258. static long _vq_quantmap__16c2_s_p7_1[] = {
  111259. 9, 7, 5, 3, 1, 0, 2, 4,
  111260. 6, 8, 10,
  111261. };
  111262. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  111263. _vq_quantthresh__16c2_s_p7_1,
  111264. _vq_quantmap__16c2_s_p7_1,
  111265. 11,
  111266. 11
  111267. };
  111268. static static_codebook _16c2_s_p7_1 = {
  111269. 2, 121,
  111270. _vq_lengthlist__16c2_s_p7_1,
  111271. 1, -531365888, 1611661312, 4, 0,
  111272. _vq_quantlist__16c2_s_p7_1,
  111273. NULL,
  111274. &_vq_auxt__16c2_s_p7_1,
  111275. NULL,
  111276. 0
  111277. };
  111278. static long _vq_quantlist__16c2_s_p8_0[] = {
  111279. 7,
  111280. 6,
  111281. 8,
  111282. 5,
  111283. 9,
  111284. 4,
  111285. 10,
  111286. 3,
  111287. 11,
  111288. 2,
  111289. 12,
  111290. 1,
  111291. 13,
  111292. 0,
  111293. 14,
  111294. };
  111295. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111296. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111297. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111298. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111299. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111300. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111301. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111302. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111303. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111304. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111305. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111306. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111307. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111308. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111309. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111310. 13,
  111311. };
  111312. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111313. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111314. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111315. };
  111316. static long _vq_quantmap__16c2_s_p8_0[] = {
  111317. 13, 11, 9, 7, 5, 3, 1, 0,
  111318. 2, 4, 6, 8, 10, 12, 14,
  111319. };
  111320. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111321. _vq_quantthresh__16c2_s_p8_0,
  111322. _vq_quantmap__16c2_s_p8_0,
  111323. 15,
  111324. 15
  111325. };
  111326. static static_codebook _16c2_s_p8_0 = {
  111327. 2, 225,
  111328. _vq_lengthlist__16c2_s_p8_0,
  111329. 1, -520986624, 1620377600, 4, 0,
  111330. _vq_quantlist__16c2_s_p8_0,
  111331. NULL,
  111332. &_vq_auxt__16c2_s_p8_0,
  111333. NULL,
  111334. 0
  111335. };
  111336. static long _vq_quantlist__16c2_s_p8_1[] = {
  111337. 10,
  111338. 9,
  111339. 11,
  111340. 8,
  111341. 12,
  111342. 7,
  111343. 13,
  111344. 6,
  111345. 14,
  111346. 5,
  111347. 15,
  111348. 4,
  111349. 16,
  111350. 3,
  111351. 17,
  111352. 2,
  111353. 18,
  111354. 1,
  111355. 19,
  111356. 0,
  111357. 20,
  111358. };
  111359. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111360. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111361. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111362. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111363. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111364. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111365. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111366. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111367. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111368. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111369. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111370. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111371. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111372. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111373. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111374. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111375. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111376. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111377. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111378. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111379. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111380. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111381. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111382. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111383. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111384. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111385. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111386. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111387. 10,11,10,10,10,10,10,10,10,
  111388. };
  111389. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111390. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111391. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111392. 6.5, 7.5, 8.5, 9.5,
  111393. };
  111394. static long _vq_quantmap__16c2_s_p8_1[] = {
  111395. 19, 17, 15, 13, 11, 9, 7, 5,
  111396. 3, 1, 0, 2, 4, 6, 8, 10,
  111397. 12, 14, 16, 18, 20,
  111398. };
  111399. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111400. _vq_quantthresh__16c2_s_p8_1,
  111401. _vq_quantmap__16c2_s_p8_1,
  111402. 21,
  111403. 21
  111404. };
  111405. static static_codebook _16c2_s_p8_1 = {
  111406. 2, 441,
  111407. _vq_lengthlist__16c2_s_p8_1,
  111408. 1, -529268736, 1611661312, 5, 0,
  111409. _vq_quantlist__16c2_s_p8_1,
  111410. NULL,
  111411. &_vq_auxt__16c2_s_p8_1,
  111412. NULL,
  111413. 0
  111414. };
  111415. static long _vq_quantlist__16c2_s_p9_0[] = {
  111416. 6,
  111417. 5,
  111418. 7,
  111419. 4,
  111420. 8,
  111421. 3,
  111422. 9,
  111423. 2,
  111424. 10,
  111425. 1,
  111426. 11,
  111427. 0,
  111428. 12,
  111429. };
  111430. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111431. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111432. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111433. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111434. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111435. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111436. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111437. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111438. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111439. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111440. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111441. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111442. };
  111443. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111444. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111445. 2327.5, 3258.5, 4189.5, 5120.5,
  111446. };
  111447. static long _vq_quantmap__16c2_s_p9_0[] = {
  111448. 11, 9, 7, 5, 3, 1, 0, 2,
  111449. 4, 6, 8, 10, 12,
  111450. };
  111451. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111452. _vq_quantthresh__16c2_s_p9_0,
  111453. _vq_quantmap__16c2_s_p9_0,
  111454. 13,
  111455. 13
  111456. };
  111457. static static_codebook _16c2_s_p9_0 = {
  111458. 2, 169,
  111459. _vq_lengthlist__16c2_s_p9_0,
  111460. 1, -510275072, 1631393792, 4, 0,
  111461. _vq_quantlist__16c2_s_p9_0,
  111462. NULL,
  111463. &_vq_auxt__16c2_s_p9_0,
  111464. NULL,
  111465. 0
  111466. };
  111467. static long _vq_quantlist__16c2_s_p9_1[] = {
  111468. 8,
  111469. 7,
  111470. 9,
  111471. 6,
  111472. 10,
  111473. 5,
  111474. 11,
  111475. 4,
  111476. 12,
  111477. 3,
  111478. 13,
  111479. 2,
  111480. 14,
  111481. 1,
  111482. 15,
  111483. 0,
  111484. 16,
  111485. };
  111486. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111487. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111488. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111489. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111490. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111491. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111492. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111493. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111494. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111495. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111496. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111497. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111498. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111499. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111500. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111501. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111502. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111503. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111504. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111505. 10,
  111506. };
  111507. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111508. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111509. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111510. };
  111511. static long _vq_quantmap__16c2_s_p9_1[] = {
  111512. 15, 13, 11, 9, 7, 5, 3, 1,
  111513. 0, 2, 4, 6, 8, 10, 12, 14,
  111514. 16,
  111515. };
  111516. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111517. _vq_quantthresh__16c2_s_p9_1,
  111518. _vq_quantmap__16c2_s_p9_1,
  111519. 17,
  111520. 17
  111521. };
  111522. static static_codebook _16c2_s_p9_1 = {
  111523. 2, 289,
  111524. _vq_lengthlist__16c2_s_p9_1,
  111525. 1, -518488064, 1622704128, 5, 0,
  111526. _vq_quantlist__16c2_s_p9_1,
  111527. NULL,
  111528. &_vq_auxt__16c2_s_p9_1,
  111529. NULL,
  111530. 0
  111531. };
  111532. static long _vq_quantlist__16c2_s_p9_2[] = {
  111533. 13,
  111534. 12,
  111535. 14,
  111536. 11,
  111537. 15,
  111538. 10,
  111539. 16,
  111540. 9,
  111541. 17,
  111542. 8,
  111543. 18,
  111544. 7,
  111545. 19,
  111546. 6,
  111547. 20,
  111548. 5,
  111549. 21,
  111550. 4,
  111551. 22,
  111552. 3,
  111553. 23,
  111554. 2,
  111555. 24,
  111556. 1,
  111557. 25,
  111558. 0,
  111559. 26,
  111560. };
  111561. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111562. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111563. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111564. };
  111565. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111566. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111567. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111568. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111569. 11.5, 12.5,
  111570. };
  111571. static long _vq_quantmap__16c2_s_p9_2[] = {
  111572. 25, 23, 21, 19, 17, 15, 13, 11,
  111573. 9, 7, 5, 3, 1, 0, 2, 4,
  111574. 6, 8, 10, 12, 14, 16, 18, 20,
  111575. 22, 24, 26,
  111576. };
  111577. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111578. _vq_quantthresh__16c2_s_p9_2,
  111579. _vq_quantmap__16c2_s_p9_2,
  111580. 27,
  111581. 27
  111582. };
  111583. static static_codebook _16c2_s_p9_2 = {
  111584. 1, 27,
  111585. _vq_lengthlist__16c2_s_p9_2,
  111586. 1, -528875520, 1611661312, 5, 0,
  111587. _vq_quantlist__16c2_s_p9_2,
  111588. NULL,
  111589. &_vq_auxt__16c2_s_p9_2,
  111590. NULL,
  111591. 0
  111592. };
  111593. static long _huff_lengthlist__16c2_s_short[] = {
  111594. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111595. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111596. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111597. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111598. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111599. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111600. 15,12,14,14,
  111601. };
  111602. static static_codebook _huff_book__16c2_s_short = {
  111603. 2, 100,
  111604. _huff_lengthlist__16c2_s_short,
  111605. 0, 0, 0, 0, 0,
  111606. NULL,
  111607. NULL,
  111608. NULL,
  111609. NULL,
  111610. 0
  111611. };
  111612. static long _vq_quantlist__8c0_s_p1_0[] = {
  111613. 1,
  111614. 0,
  111615. 2,
  111616. };
  111617. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111618. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111619. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111623. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111624. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111628. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111629. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111660. 0, 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, 5, 8, 8, 0, 0, 0, 0,
  111664. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  111669. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9,10, 0, 0,
  111674. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111689. 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111710. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111715. 0, 0, 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 0, 0,
  111716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111719. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111720. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111731. 0, 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,
  112029. };
  112030. static float _vq_quantthresh__8c0_s_p1_0[] = {
  112031. -0.5, 0.5,
  112032. };
  112033. static long _vq_quantmap__8c0_s_p1_0[] = {
  112034. 1, 0, 2,
  112035. };
  112036. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  112037. _vq_quantthresh__8c0_s_p1_0,
  112038. _vq_quantmap__8c0_s_p1_0,
  112039. 3,
  112040. 3
  112041. };
  112042. static static_codebook _8c0_s_p1_0 = {
  112043. 8, 6561,
  112044. _vq_lengthlist__8c0_s_p1_0,
  112045. 1, -535822336, 1611661312, 2, 0,
  112046. _vq_quantlist__8c0_s_p1_0,
  112047. NULL,
  112048. &_vq_auxt__8c0_s_p1_0,
  112049. NULL,
  112050. 0
  112051. };
  112052. static long _vq_quantlist__8c0_s_p2_0[] = {
  112053. 2,
  112054. 1,
  112055. 3,
  112056. 0,
  112057. 4,
  112058. };
  112059. static long _vq_lengthlist__8c0_s_p2_0[] = {
  112060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  112100. };
  112101. static float _vq_quantthresh__8c0_s_p2_0[] = {
  112102. -1.5, -0.5, 0.5, 1.5,
  112103. };
  112104. static long _vq_quantmap__8c0_s_p2_0[] = {
  112105. 3, 1, 0, 2, 4,
  112106. };
  112107. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  112108. _vq_quantthresh__8c0_s_p2_0,
  112109. _vq_quantmap__8c0_s_p2_0,
  112110. 5,
  112111. 5
  112112. };
  112113. static static_codebook _8c0_s_p2_0 = {
  112114. 4, 625,
  112115. _vq_lengthlist__8c0_s_p2_0,
  112116. 1, -533725184, 1611661312, 3, 0,
  112117. _vq_quantlist__8c0_s_p2_0,
  112118. NULL,
  112119. &_vq_auxt__8c0_s_p2_0,
  112120. NULL,
  112121. 0
  112122. };
  112123. static long _vq_quantlist__8c0_s_p3_0[] = {
  112124. 2,
  112125. 1,
  112126. 3,
  112127. 0,
  112128. 4,
  112129. };
  112130. static long _vq_lengthlist__8c0_s_p3_0[] = {
  112131. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  112133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112134. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  112136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112137. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  112138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  112171. };
  112172. static float _vq_quantthresh__8c0_s_p3_0[] = {
  112173. -1.5, -0.5, 0.5, 1.5,
  112174. };
  112175. static long _vq_quantmap__8c0_s_p3_0[] = {
  112176. 3, 1, 0, 2, 4,
  112177. };
  112178. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  112179. _vq_quantthresh__8c0_s_p3_0,
  112180. _vq_quantmap__8c0_s_p3_0,
  112181. 5,
  112182. 5
  112183. };
  112184. static static_codebook _8c0_s_p3_0 = {
  112185. 4, 625,
  112186. _vq_lengthlist__8c0_s_p3_0,
  112187. 1, -533725184, 1611661312, 3, 0,
  112188. _vq_quantlist__8c0_s_p3_0,
  112189. NULL,
  112190. &_vq_auxt__8c0_s_p3_0,
  112191. NULL,
  112192. 0
  112193. };
  112194. static long _vq_quantlist__8c0_s_p4_0[] = {
  112195. 4,
  112196. 3,
  112197. 5,
  112198. 2,
  112199. 6,
  112200. 1,
  112201. 7,
  112202. 0,
  112203. 8,
  112204. };
  112205. static long _vq_lengthlist__8c0_s_p4_0[] = {
  112206. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112207. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112208. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112209. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112210. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112211. 0,
  112212. };
  112213. static float _vq_quantthresh__8c0_s_p4_0[] = {
  112214. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112215. };
  112216. static long _vq_quantmap__8c0_s_p4_0[] = {
  112217. 7, 5, 3, 1, 0, 2, 4, 6,
  112218. 8,
  112219. };
  112220. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  112221. _vq_quantthresh__8c0_s_p4_0,
  112222. _vq_quantmap__8c0_s_p4_0,
  112223. 9,
  112224. 9
  112225. };
  112226. static static_codebook _8c0_s_p4_0 = {
  112227. 2, 81,
  112228. _vq_lengthlist__8c0_s_p4_0,
  112229. 1, -531628032, 1611661312, 4, 0,
  112230. _vq_quantlist__8c0_s_p4_0,
  112231. NULL,
  112232. &_vq_auxt__8c0_s_p4_0,
  112233. NULL,
  112234. 0
  112235. };
  112236. static long _vq_quantlist__8c0_s_p5_0[] = {
  112237. 4,
  112238. 3,
  112239. 5,
  112240. 2,
  112241. 6,
  112242. 1,
  112243. 7,
  112244. 0,
  112245. 8,
  112246. };
  112247. static long _vq_lengthlist__8c0_s_p5_0[] = {
  112248. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  112249. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  112250. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  112251. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  112252. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112253. 10,
  112254. };
  112255. static float _vq_quantthresh__8c0_s_p5_0[] = {
  112256. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112257. };
  112258. static long _vq_quantmap__8c0_s_p5_0[] = {
  112259. 7, 5, 3, 1, 0, 2, 4, 6,
  112260. 8,
  112261. };
  112262. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  112263. _vq_quantthresh__8c0_s_p5_0,
  112264. _vq_quantmap__8c0_s_p5_0,
  112265. 9,
  112266. 9
  112267. };
  112268. static static_codebook _8c0_s_p5_0 = {
  112269. 2, 81,
  112270. _vq_lengthlist__8c0_s_p5_0,
  112271. 1, -531628032, 1611661312, 4, 0,
  112272. _vq_quantlist__8c0_s_p5_0,
  112273. NULL,
  112274. &_vq_auxt__8c0_s_p5_0,
  112275. NULL,
  112276. 0
  112277. };
  112278. static long _vq_quantlist__8c0_s_p6_0[] = {
  112279. 8,
  112280. 7,
  112281. 9,
  112282. 6,
  112283. 10,
  112284. 5,
  112285. 11,
  112286. 4,
  112287. 12,
  112288. 3,
  112289. 13,
  112290. 2,
  112291. 14,
  112292. 1,
  112293. 15,
  112294. 0,
  112295. 16,
  112296. };
  112297. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112298. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112299. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112300. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112301. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112302. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112303. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112304. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112305. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112306. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112307. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112308. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112309. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112310. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112311. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112312. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112313. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112314. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112315. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112316. 14,
  112317. };
  112318. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112319. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112320. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112321. };
  112322. static long _vq_quantmap__8c0_s_p6_0[] = {
  112323. 15, 13, 11, 9, 7, 5, 3, 1,
  112324. 0, 2, 4, 6, 8, 10, 12, 14,
  112325. 16,
  112326. };
  112327. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112328. _vq_quantthresh__8c0_s_p6_0,
  112329. _vq_quantmap__8c0_s_p6_0,
  112330. 17,
  112331. 17
  112332. };
  112333. static static_codebook _8c0_s_p6_0 = {
  112334. 2, 289,
  112335. _vq_lengthlist__8c0_s_p6_0,
  112336. 1, -529530880, 1611661312, 5, 0,
  112337. _vq_quantlist__8c0_s_p6_0,
  112338. NULL,
  112339. &_vq_auxt__8c0_s_p6_0,
  112340. NULL,
  112341. 0
  112342. };
  112343. static long _vq_quantlist__8c0_s_p7_0[] = {
  112344. 1,
  112345. 0,
  112346. 2,
  112347. };
  112348. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112349. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112350. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112351. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112352. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112353. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112354. 10,
  112355. };
  112356. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112357. -5.5, 5.5,
  112358. };
  112359. static long _vq_quantmap__8c0_s_p7_0[] = {
  112360. 1, 0, 2,
  112361. };
  112362. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112363. _vq_quantthresh__8c0_s_p7_0,
  112364. _vq_quantmap__8c0_s_p7_0,
  112365. 3,
  112366. 3
  112367. };
  112368. static static_codebook _8c0_s_p7_0 = {
  112369. 4, 81,
  112370. _vq_lengthlist__8c0_s_p7_0,
  112371. 1, -529137664, 1618345984, 2, 0,
  112372. _vq_quantlist__8c0_s_p7_0,
  112373. NULL,
  112374. &_vq_auxt__8c0_s_p7_0,
  112375. NULL,
  112376. 0
  112377. };
  112378. static long _vq_quantlist__8c0_s_p7_1[] = {
  112379. 5,
  112380. 4,
  112381. 6,
  112382. 3,
  112383. 7,
  112384. 2,
  112385. 8,
  112386. 1,
  112387. 9,
  112388. 0,
  112389. 10,
  112390. };
  112391. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112392. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112393. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112394. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112395. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112396. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112397. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112398. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112399. 10,10,10, 9, 9, 9,10,10,10,
  112400. };
  112401. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112402. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112403. 3.5, 4.5,
  112404. };
  112405. static long _vq_quantmap__8c0_s_p7_1[] = {
  112406. 9, 7, 5, 3, 1, 0, 2, 4,
  112407. 6, 8, 10,
  112408. };
  112409. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112410. _vq_quantthresh__8c0_s_p7_1,
  112411. _vq_quantmap__8c0_s_p7_1,
  112412. 11,
  112413. 11
  112414. };
  112415. static static_codebook _8c0_s_p7_1 = {
  112416. 2, 121,
  112417. _vq_lengthlist__8c0_s_p7_1,
  112418. 1, -531365888, 1611661312, 4, 0,
  112419. _vq_quantlist__8c0_s_p7_1,
  112420. NULL,
  112421. &_vq_auxt__8c0_s_p7_1,
  112422. NULL,
  112423. 0
  112424. };
  112425. static long _vq_quantlist__8c0_s_p8_0[] = {
  112426. 6,
  112427. 5,
  112428. 7,
  112429. 4,
  112430. 8,
  112431. 3,
  112432. 9,
  112433. 2,
  112434. 10,
  112435. 1,
  112436. 11,
  112437. 0,
  112438. 12,
  112439. };
  112440. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112441. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112442. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112443. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112444. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112445. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112446. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112447. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112448. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112449. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112450. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112451. 0, 0,13,13,11,13,13,11,12,
  112452. };
  112453. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112454. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112455. 12.5, 17.5, 22.5, 27.5,
  112456. };
  112457. static long _vq_quantmap__8c0_s_p8_0[] = {
  112458. 11, 9, 7, 5, 3, 1, 0, 2,
  112459. 4, 6, 8, 10, 12,
  112460. };
  112461. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112462. _vq_quantthresh__8c0_s_p8_0,
  112463. _vq_quantmap__8c0_s_p8_0,
  112464. 13,
  112465. 13
  112466. };
  112467. static static_codebook _8c0_s_p8_0 = {
  112468. 2, 169,
  112469. _vq_lengthlist__8c0_s_p8_0,
  112470. 1, -526516224, 1616117760, 4, 0,
  112471. _vq_quantlist__8c0_s_p8_0,
  112472. NULL,
  112473. &_vq_auxt__8c0_s_p8_0,
  112474. NULL,
  112475. 0
  112476. };
  112477. static long _vq_quantlist__8c0_s_p8_1[] = {
  112478. 2,
  112479. 1,
  112480. 3,
  112481. 0,
  112482. 4,
  112483. };
  112484. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112485. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112486. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112487. };
  112488. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112489. -1.5, -0.5, 0.5, 1.5,
  112490. };
  112491. static long _vq_quantmap__8c0_s_p8_1[] = {
  112492. 3, 1, 0, 2, 4,
  112493. };
  112494. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112495. _vq_quantthresh__8c0_s_p8_1,
  112496. _vq_quantmap__8c0_s_p8_1,
  112497. 5,
  112498. 5
  112499. };
  112500. static static_codebook _8c0_s_p8_1 = {
  112501. 2, 25,
  112502. _vq_lengthlist__8c0_s_p8_1,
  112503. 1, -533725184, 1611661312, 3, 0,
  112504. _vq_quantlist__8c0_s_p8_1,
  112505. NULL,
  112506. &_vq_auxt__8c0_s_p8_1,
  112507. NULL,
  112508. 0
  112509. };
  112510. static long _vq_quantlist__8c0_s_p9_0[] = {
  112511. 1,
  112512. 0,
  112513. 2,
  112514. };
  112515. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112516. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112517. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112518. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112519. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112520. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112521. 7,
  112522. };
  112523. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112524. -157.5, 157.5,
  112525. };
  112526. static long _vq_quantmap__8c0_s_p9_0[] = {
  112527. 1, 0, 2,
  112528. };
  112529. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112530. _vq_quantthresh__8c0_s_p9_0,
  112531. _vq_quantmap__8c0_s_p9_0,
  112532. 3,
  112533. 3
  112534. };
  112535. static static_codebook _8c0_s_p9_0 = {
  112536. 4, 81,
  112537. _vq_lengthlist__8c0_s_p9_0,
  112538. 1, -518803456, 1628680192, 2, 0,
  112539. _vq_quantlist__8c0_s_p9_0,
  112540. NULL,
  112541. &_vq_auxt__8c0_s_p9_0,
  112542. NULL,
  112543. 0
  112544. };
  112545. static long _vq_quantlist__8c0_s_p9_1[] = {
  112546. 7,
  112547. 6,
  112548. 8,
  112549. 5,
  112550. 9,
  112551. 4,
  112552. 10,
  112553. 3,
  112554. 11,
  112555. 2,
  112556. 12,
  112557. 1,
  112558. 13,
  112559. 0,
  112560. 14,
  112561. };
  112562. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112563. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112564. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112565. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112566. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112567. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112568. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112569. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112570. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112571. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112572. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112573. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112574. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112575. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112576. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112577. 11,
  112578. };
  112579. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112580. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112581. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112582. };
  112583. static long _vq_quantmap__8c0_s_p9_1[] = {
  112584. 13, 11, 9, 7, 5, 3, 1, 0,
  112585. 2, 4, 6, 8, 10, 12, 14,
  112586. };
  112587. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112588. _vq_quantthresh__8c0_s_p9_1,
  112589. _vq_quantmap__8c0_s_p9_1,
  112590. 15,
  112591. 15
  112592. };
  112593. static static_codebook _8c0_s_p9_1 = {
  112594. 2, 225,
  112595. _vq_lengthlist__8c0_s_p9_1,
  112596. 1, -520986624, 1620377600, 4, 0,
  112597. _vq_quantlist__8c0_s_p9_1,
  112598. NULL,
  112599. &_vq_auxt__8c0_s_p9_1,
  112600. NULL,
  112601. 0
  112602. };
  112603. static long _vq_quantlist__8c0_s_p9_2[] = {
  112604. 10,
  112605. 9,
  112606. 11,
  112607. 8,
  112608. 12,
  112609. 7,
  112610. 13,
  112611. 6,
  112612. 14,
  112613. 5,
  112614. 15,
  112615. 4,
  112616. 16,
  112617. 3,
  112618. 17,
  112619. 2,
  112620. 18,
  112621. 1,
  112622. 19,
  112623. 0,
  112624. 20,
  112625. };
  112626. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112627. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112628. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112629. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112630. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112631. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112632. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112633. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112634. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112635. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112636. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112637. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112638. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112639. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112640. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112641. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112642. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112643. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112644. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112645. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112646. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112647. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112648. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112649. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112650. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112651. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112652. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112653. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112654. 10,11, 9,11,10, 9,10, 9,10,
  112655. };
  112656. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112657. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112658. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112659. 6.5, 7.5, 8.5, 9.5,
  112660. };
  112661. static long _vq_quantmap__8c0_s_p9_2[] = {
  112662. 19, 17, 15, 13, 11, 9, 7, 5,
  112663. 3, 1, 0, 2, 4, 6, 8, 10,
  112664. 12, 14, 16, 18, 20,
  112665. };
  112666. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112667. _vq_quantthresh__8c0_s_p9_2,
  112668. _vq_quantmap__8c0_s_p9_2,
  112669. 21,
  112670. 21
  112671. };
  112672. static static_codebook _8c0_s_p9_2 = {
  112673. 2, 441,
  112674. _vq_lengthlist__8c0_s_p9_2,
  112675. 1, -529268736, 1611661312, 5, 0,
  112676. _vq_quantlist__8c0_s_p9_2,
  112677. NULL,
  112678. &_vq_auxt__8c0_s_p9_2,
  112679. NULL,
  112680. 0
  112681. };
  112682. static long _huff_lengthlist__8c0_s_single[] = {
  112683. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112684. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112685. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112686. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112687. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112688. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112689. 17,16,17,17,
  112690. };
  112691. static static_codebook _huff_book__8c0_s_single = {
  112692. 2, 100,
  112693. _huff_lengthlist__8c0_s_single,
  112694. 0, 0, 0, 0, 0,
  112695. NULL,
  112696. NULL,
  112697. NULL,
  112698. NULL,
  112699. 0
  112700. };
  112701. static long _vq_quantlist__8c1_s_p1_0[] = {
  112702. 1,
  112703. 0,
  112704. 2,
  112705. };
  112706. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112707. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112708. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112712. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112713. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112717. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112718. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112749. 0, 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, 5, 8, 8, 0, 0, 0, 0,
  112753. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  112758. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112763. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112778. 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112799. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112804. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  112805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112808. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112809. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112820. 0, 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,
  113118. };
  113119. static float _vq_quantthresh__8c1_s_p1_0[] = {
  113120. -0.5, 0.5,
  113121. };
  113122. static long _vq_quantmap__8c1_s_p1_0[] = {
  113123. 1, 0, 2,
  113124. };
  113125. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  113126. _vq_quantthresh__8c1_s_p1_0,
  113127. _vq_quantmap__8c1_s_p1_0,
  113128. 3,
  113129. 3
  113130. };
  113131. static static_codebook _8c1_s_p1_0 = {
  113132. 8, 6561,
  113133. _vq_lengthlist__8c1_s_p1_0,
  113134. 1, -535822336, 1611661312, 2, 0,
  113135. _vq_quantlist__8c1_s_p1_0,
  113136. NULL,
  113137. &_vq_auxt__8c1_s_p1_0,
  113138. NULL,
  113139. 0
  113140. };
  113141. static long _vq_quantlist__8c1_s_p2_0[] = {
  113142. 2,
  113143. 1,
  113144. 3,
  113145. 0,
  113146. 4,
  113147. };
  113148. static long _vq_lengthlist__8c1_s_p2_0[] = {
  113149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  113189. };
  113190. static float _vq_quantthresh__8c1_s_p2_0[] = {
  113191. -1.5, -0.5, 0.5, 1.5,
  113192. };
  113193. static long _vq_quantmap__8c1_s_p2_0[] = {
  113194. 3, 1, 0, 2, 4,
  113195. };
  113196. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  113197. _vq_quantthresh__8c1_s_p2_0,
  113198. _vq_quantmap__8c1_s_p2_0,
  113199. 5,
  113200. 5
  113201. };
  113202. static static_codebook _8c1_s_p2_0 = {
  113203. 4, 625,
  113204. _vq_lengthlist__8c1_s_p2_0,
  113205. 1, -533725184, 1611661312, 3, 0,
  113206. _vq_quantlist__8c1_s_p2_0,
  113207. NULL,
  113208. &_vq_auxt__8c1_s_p2_0,
  113209. NULL,
  113210. 0
  113211. };
  113212. static long _vq_quantlist__8c1_s_p3_0[] = {
  113213. 2,
  113214. 1,
  113215. 3,
  113216. 0,
  113217. 4,
  113218. };
  113219. static long _vq_lengthlist__8c1_s_p3_0[] = {
  113220. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113223. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  113225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113226. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  113260. };
  113261. static float _vq_quantthresh__8c1_s_p3_0[] = {
  113262. -1.5, -0.5, 0.5, 1.5,
  113263. };
  113264. static long _vq_quantmap__8c1_s_p3_0[] = {
  113265. 3, 1, 0, 2, 4,
  113266. };
  113267. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  113268. _vq_quantthresh__8c1_s_p3_0,
  113269. _vq_quantmap__8c1_s_p3_0,
  113270. 5,
  113271. 5
  113272. };
  113273. static static_codebook _8c1_s_p3_0 = {
  113274. 4, 625,
  113275. _vq_lengthlist__8c1_s_p3_0,
  113276. 1, -533725184, 1611661312, 3, 0,
  113277. _vq_quantlist__8c1_s_p3_0,
  113278. NULL,
  113279. &_vq_auxt__8c1_s_p3_0,
  113280. NULL,
  113281. 0
  113282. };
  113283. static long _vq_quantlist__8c1_s_p4_0[] = {
  113284. 4,
  113285. 3,
  113286. 5,
  113287. 2,
  113288. 6,
  113289. 1,
  113290. 7,
  113291. 0,
  113292. 8,
  113293. };
  113294. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113295. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113296. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113297. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113298. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113299. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113300. 0,
  113301. };
  113302. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113303. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113304. };
  113305. static long _vq_quantmap__8c1_s_p4_0[] = {
  113306. 7, 5, 3, 1, 0, 2, 4, 6,
  113307. 8,
  113308. };
  113309. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113310. _vq_quantthresh__8c1_s_p4_0,
  113311. _vq_quantmap__8c1_s_p4_0,
  113312. 9,
  113313. 9
  113314. };
  113315. static static_codebook _8c1_s_p4_0 = {
  113316. 2, 81,
  113317. _vq_lengthlist__8c1_s_p4_0,
  113318. 1, -531628032, 1611661312, 4, 0,
  113319. _vq_quantlist__8c1_s_p4_0,
  113320. NULL,
  113321. &_vq_auxt__8c1_s_p4_0,
  113322. NULL,
  113323. 0
  113324. };
  113325. static long _vq_quantlist__8c1_s_p5_0[] = {
  113326. 4,
  113327. 3,
  113328. 5,
  113329. 2,
  113330. 6,
  113331. 1,
  113332. 7,
  113333. 0,
  113334. 8,
  113335. };
  113336. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113337. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113338. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113339. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113340. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113341. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113342. 10,
  113343. };
  113344. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113345. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113346. };
  113347. static long _vq_quantmap__8c1_s_p5_0[] = {
  113348. 7, 5, 3, 1, 0, 2, 4, 6,
  113349. 8,
  113350. };
  113351. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113352. _vq_quantthresh__8c1_s_p5_0,
  113353. _vq_quantmap__8c1_s_p5_0,
  113354. 9,
  113355. 9
  113356. };
  113357. static static_codebook _8c1_s_p5_0 = {
  113358. 2, 81,
  113359. _vq_lengthlist__8c1_s_p5_0,
  113360. 1, -531628032, 1611661312, 4, 0,
  113361. _vq_quantlist__8c1_s_p5_0,
  113362. NULL,
  113363. &_vq_auxt__8c1_s_p5_0,
  113364. NULL,
  113365. 0
  113366. };
  113367. static long _vq_quantlist__8c1_s_p6_0[] = {
  113368. 8,
  113369. 7,
  113370. 9,
  113371. 6,
  113372. 10,
  113373. 5,
  113374. 11,
  113375. 4,
  113376. 12,
  113377. 3,
  113378. 13,
  113379. 2,
  113380. 14,
  113381. 1,
  113382. 15,
  113383. 0,
  113384. 16,
  113385. };
  113386. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113387. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113388. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113389. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113390. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113391. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113392. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113393. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113394. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113395. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113396. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113397. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113398. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113399. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113400. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113401. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113402. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113403. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113404. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113405. 14,
  113406. };
  113407. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113408. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113409. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113410. };
  113411. static long _vq_quantmap__8c1_s_p6_0[] = {
  113412. 15, 13, 11, 9, 7, 5, 3, 1,
  113413. 0, 2, 4, 6, 8, 10, 12, 14,
  113414. 16,
  113415. };
  113416. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113417. _vq_quantthresh__8c1_s_p6_0,
  113418. _vq_quantmap__8c1_s_p6_0,
  113419. 17,
  113420. 17
  113421. };
  113422. static static_codebook _8c1_s_p6_0 = {
  113423. 2, 289,
  113424. _vq_lengthlist__8c1_s_p6_0,
  113425. 1, -529530880, 1611661312, 5, 0,
  113426. _vq_quantlist__8c1_s_p6_0,
  113427. NULL,
  113428. &_vq_auxt__8c1_s_p6_0,
  113429. NULL,
  113430. 0
  113431. };
  113432. static long _vq_quantlist__8c1_s_p7_0[] = {
  113433. 1,
  113434. 0,
  113435. 2,
  113436. };
  113437. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113438. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113439. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113440. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113441. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113442. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113443. 9,
  113444. };
  113445. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113446. -5.5, 5.5,
  113447. };
  113448. static long _vq_quantmap__8c1_s_p7_0[] = {
  113449. 1, 0, 2,
  113450. };
  113451. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113452. _vq_quantthresh__8c1_s_p7_0,
  113453. _vq_quantmap__8c1_s_p7_0,
  113454. 3,
  113455. 3
  113456. };
  113457. static static_codebook _8c1_s_p7_0 = {
  113458. 4, 81,
  113459. _vq_lengthlist__8c1_s_p7_0,
  113460. 1, -529137664, 1618345984, 2, 0,
  113461. _vq_quantlist__8c1_s_p7_0,
  113462. NULL,
  113463. &_vq_auxt__8c1_s_p7_0,
  113464. NULL,
  113465. 0
  113466. };
  113467. static long _vq_quantlist__8c1_s_p7_1[] = {
  113468. 5,
  113469. 4,
  113470. 6,
  113471. 3,
  113472. 7,
  113473. 2,
  113474. 8,
  113475. 1,
  113476. 9,
  113477. 0,
  113478. 10,
  113479. };
  113480. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113481. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113482. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113483. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113484. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113485. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113486. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113487. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113488. 10,10,10, 8, 8, 8, 8, 8, 8,
  113489. };
  113490. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113491. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113492. 3.5, 4.5,
  113493. };
  113494. static long _vq_quantmap__8c1_s_p7_1[] = {
  113495. 9, 7, 5, 3, 1, 0, 2, 4,
  113496. 6, 8, 10,
  113497. };
  113498. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113499. _vq_quantthresh__8c1_s_p7_1,
  113500. _vq_quantmap__8c1_s_p7_1,
  113501. 11,
  113502. 11
  113503. };
  113504. static static_codebook _8c1_s_p7_1 = {
  113505. 2, 121,
  113506. _vq_lengthlist__8c1_s_p7_1,
  113507. 1, -531365888, 1611661312, 4, 0,
  113508. _vq_quantlist__8c1_s_p7_1,
  113509. NULL,
  113510. &_vq_auxt__8c1_s_p7_1,
  113511. NULL,
  113512. 0
  113513. };
  113514. static long _vq_quantlist__8c1_s_p8_0[] = {
  113515. 6,
  113516. 5,
  113517. 7,
  113518. 4,
  113519. 8,
  113520. 3,
  113521. 9,
  113522. 2,
  113523. 10,
  113524. 1,
  113525. 11,
  113526. 0,
  113527. 12,
  113528. };
  113529. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113530. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113531. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113532. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113533. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113534. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113535. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113536. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113537. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113538. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113539. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113540. 0,12,12,11,10,12,11,13,12,
  113541. };
  113542. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113543. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113544. 12.5, 17.5, 22.5, 27.5,
  113545. };
  113546. static long _vq_quantmap__8c1_s_p8_0[] = {
  113547. 11, 9, 7, 5, 3, 1, 0, 2,
  113548. 4, 6, 8, 10, 12,
  113549. };
  113550. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113551. _vq_quantthresh__8c1_s_p8_0,
  113552. _vq_quantmap__8c1_s_p8_0,
  113553. 13,
  113554. 13
  113555. };
  113556. static static_codebook _8c1_s_p8_0 = {
  113557. 2, 169,
  113558. _vq_lengthlist__8c1_s_p8_0,
  113559. 1, -526516224, 1616117760, 4, 0,
  113560. _vq_quantlist__8c1_s_p8_0,
  113561. NULL,
  113562. &_vq_auxt__8c1_s_p8_0,
  113563. NULL,
  113564. 0
  113565. };
  113566. static long _vq_quantlist__8c1_s_p8_1[] = {
  113567. 2,
  113568. 1,
  113569. 3,
  113570. 0,
  113571. 4,
  113572. };
  113573. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113574. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113575. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113576. };
  113577. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113578. -1.5, -0.5, 0.5, 1.5,
  113579. };
  113580. static long _vq_quantmap__8c1_s_p8_1[] = {
  113581. 3, 1, 0, 2, 4,
  113582. };
  113583. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113584. _vq_quantthresh__8c1_s_p8_1,
  113585. _vq_quantmap__8c1_s_p8_1,
  113586. 5,
  113587. 5
  113588. };
  113589. static static_codebook _8c1_s_p8_1 = {
  113590. 2, 25,
  113591. _vq_lengthlist__8c1_s_p8_1,
  113592. 1, -533725184, 1611661312, 3, 0,
  113593. _vq_quantlist__8c1_s_p8_1,
  113594. NULL,
  113595. &_vq_auxt__8c1_s_p8_1,
  113596. NULL,
  113597. 0
  113598. };
  113599. static long _vq_quantlist__8c1_s_p9_0[] = {
  113600. 6,
  113601. 5,
  113602. 7,
  113603. 4,
  113604. 8,
  113605. 3,
  113606. 9,
  113607. 2,
  113608. 10,
  113609. 1,
  113610. 11,
  113611. 0,
  113612. 12,
  113613. };
  113614. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113615. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113616. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113617. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113618. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113619. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113620. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113621. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113622. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113623. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113624. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113625. 10,10,10,10,10, 9, 9, 9, 9,
  113626. };
  113627. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113628. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113629. 787.5, 1102.5, 1417.5, 1732.5,
  113630. };
  113631. static long _vq_quantmap__8c1_s_p9_0[] = {
  113632. 11, 9, 7, 5, 3, 1, 0, 2,
  113633. 4, 6, 8, 10, 12,
  113634. };
  113635. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113636. _vq_quantthresh__8c1_s_p9_0,
  113637. _vq_quantmap__8c1_s_p9_0,
  113638. 13,
  113639. 13
  113640. };
  113641. static static_codebook _8c1_s_p9_0 = {
  113642. 2, 169,
  113643. _vq_lengthlist__8c1_s_p9_0,
  113644. 1, -513964032, 1628680192, 4, 0,
  113645. _vq_quantlist__8c1_s_p9_0,
  113646. NULL,
  113647. &_vq_auxt__8c1_s_p9_0,
  113648. NULL,
  113649. 0
  113650. };
  113651. static long _vq_quantlist__8c1_s_p9_1[] = {
  113652. 7,
  113653. 6,
  113654. 8,
  113655. 5,
  113656. 9,
  113657. 4,
  113658. 10,
  113659. 3,
  113660. 11,
  113661. 2,
  113662. 12,
  113663. 1,
  113664. 13,
  113665. 0,
  113666. 14,
  113667. };
  113668. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113669. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113670. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113671. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113672. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113673. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113674. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113675. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113676. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113677. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113678. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113679. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113680. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113681. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113682. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113683. 15,
  113684. };
  113685. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113686. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113687. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113688. };
  113689. static long _vq_quantmap__8c1_s_p9_1[] = {
  113690. 13, 11, 9, 7, 5, 3, 1, 0,
  113691. 2, 4, 6, 8, 10, 12, 14,
  113692. };
  113693. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113694. _vq_quantthresh__8c1_s_p9_1,
  113695. _vq_quantmap__8c1_s_p9_1,
  113696. 15,
  113697. 15
  113698. };
  113699. static static_codebook _8c1_s_p9_1 = {
  113700. 2, 225,
  113701. _vq_lengthlist__8c1_s_p9_1,
  113702. 1, -520986624, 1620377600, 4, 0,
  113703. _vq_quantlist__8c1_s_p9_1,
  113704. NULL,
  113705. &_vq_auxt__8c1_s_p9_1,
  113706. NULL,
  113707. 0
  113708. };
  113709. static long _vq_quantlist__8c1_s_p9_2[] = {
  113710. 10,
  113711. 9,
  113712. 11,
  113713. 8,
  113714. 12,
  113715. 7,
  113716. 13,
  113717. 6,
  113718. 14,
  113719. 5,
  113720. 15,
  113721. 4,
  113722. 16,
  113723. 3,
  113724. 17,
  113725. 2,
  113726. 18,
  113727. 1,
  113728. 19,
  113729. 0,
  113730. 20,
  113731. };
  113732. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113733. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113734. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113735. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113736. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113737. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113738. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113739. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113740. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113741. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113742. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113743. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113744. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113745. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113746. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113747. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113748. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113749. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113750. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113751. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113752. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113753. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113754. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113755. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113756. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113757. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113758. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113759. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113760. 10,10,10,10,10,10,10,10,10,
  113761. };
  113762. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113763. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113764. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113765. 6.5, 7.5, 8.5, 9.5,
  113766. };
  113767. static long _vq_quantmap__8c1_s_p9_2[] = {
  113768. 19, 17, 15, 13, 11, 9, 7, 5,
  113769. 3, 1, 0, 2, 4, 6, 8, 10,
  113770. 12, 14, 16, 18, 20,
  113771. };
  113772. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113773. _vq_quantthresh__8c1_s_p9_2,
  113774. _vq_quantmap__8c1_s_p9_2,
  113775. 21,
  113776. 21
  113777. };
  113778. static static_codebook _8c1_s_p9_2 = {
  113779. 2, 441,
  113780. _vq_lengthlist__8c1_s_p9_2,
  113781. 1, -529268736, 1611661312, 5, 0,
  113782. _vq_quantlist__8c1_s_p9_2,
  113783. NULL,
  113784. &_vq_auxt__8c1_s_p9_2,
  113785. NULL,
  113786. 0
  113787. };
  113788. static long _huff_lengthlist__8c1_s_single[] = {
  113789. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113790. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113791. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113792. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113793. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113794. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113795. 9, 7, 7, 8,
  113796. };
  113797. static static_codebook _huff_book__8c1_s_single = {
  113798. 2, 100,
  113799. _huff_lengthlist__8c1_s_single,
  113800. 0, 0, 0, 0, 0,
  113801. NULL,
  113802. NULL,
  113803. NULL,
  113804. NULL,
  113805. 0
  113806. };
  113807. static long _huff_lengthlist__44c2_s_long[] = {
  113808. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113809. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113810. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113811. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113812. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113813. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113814. 10, 8, 8, 9,
  113815. };
  113816. static static_codebook _huff_book__44c2_s_long = {
  113817. 2, 100,
  113818. _huff_lengthlist__44c2_s_long,
  113819. 0, 0, 0, 0, 0,
  113820. NULL,
  113821. NULL,
  113822. NULL,
  113823. NULL,
  113824. 0
  113825. };
  113826. static long _vq_quantlist__44c2_s_p1_0[] = {
  113827. 1,
  113828. 0,
  113829. 2,
  113830. };
  113831. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113832. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113833. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113837. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113838. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113842. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113843. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113874. 0, 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, 5, 7, 7, 0, 0, 0, 0,
  113878. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  113883. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  113888. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113903. 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113924. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113929. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  113930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113933. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113934. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113945. 0, 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,
  114243. };
  114244. static float _vq_quantthresh__44c2_s_p1_0[] = {
  114245. -0.5, 0.5,
  114246. };
  114247. static long _vq_quantmap__44c2_s_p1_0[] = {
  114248. 1, 0, 2,
  114249. };
  114250. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  114251. _vq_quantthresh__44c2_s_p1_0,
  114252. _vq_quantmap__44c2_s_p1_0,
  114253. 3,
  114254. 3
  114255. };
  114256. static static_codebook _44c2_s_p1_0 = {
  114257. 8, 6561,
  114258. _vq_lengthlist__44c2_s_p1_0,
  114259. 1, -535822336, 1611661312, 2, 0,
  114260. _vq_quantlist__44c2_s_p1_0,
  114261. NULL,
  114262. &_vq_auxt__44c2_s_p1_0,
  114263. NULL,
  114264. 0
  114265. };
  114266. static long _vq_quantlist__44c2_s_p2_0[] = {
  114267. 2,
  114268. 1,
  114269. 3,
  114270. 0,
  114271. 4,
  114272. };
  114273. static long _vq_lengthlist__44c2_s_p2_0[] = {
  114274. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  114275. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  114276. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  114277. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  114278. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114283. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  114284. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114285. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114286. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114288. 0, 0, 0, 0, 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, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114292. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114293. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  114294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114296. 0, 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. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114300. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114301. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  114302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114313. 0,
  114314. };
  114315. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114316. -1.5, -0.5, 0.5, 1.5,
  114317. };
  114318. static long _vq_quantmap__44c2_s_p2_0[] = {
  114319. 3, 1, 0, 2, 4,
  114320. };
  114321. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114322. _vq_quantthresh__44c2_s_p2_0,
  114323. _vq_quantmap__44c2_s_p2_0,
  114324. 5,
  114325. 5
  114326. };
  114327. static static_codebook _44c2_s_p2_0 = {
  114328. 4, 625,
  114329. _vq_lengthlist__44c2_s_p2_0,
  114330. 1, -533725184, 1611661312, 3, 0,
  114331. _vq_quantlist__44c2_s_p2_0,
  114332. NULL,
  114333. &_vq_auxt__44c2_s_p2_0,
  114334. NULL,
  114335. 0
  114336. };
  114337. static long _vq_quantlist__44c2_s_p3_0[] = {
  114338. 2,
  114339. 1,
  114340. 3,
  114341. 0,
  114342. 4,
  114343. };
  114344. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114345. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114348. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114351. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  114385. };
  114386. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114387. -1.5, -0.5, 0.5, 1.5,
  114388. };
  114389. static long _vq_quantmap__44c2_s_p3_0[] = {
  114390. 3, 1, 0, 2, 4,
  114391. };
  114392. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114393. _vq_quantthresh__44c2_s_p3_0,
  114394. _vq_quantmap__44c2_s_p3_0,
  114395. 5,
  114396. 5
  114397. };
  114398. static static_codebook _44c2_s_p3_0 = {
  114399. 4, 625,
  114400. _vq_lengthlist__44c2_s_p3_0,
  114401. 1, -533725184, 1611661312, 3, 0,
  114402. _vq_quantlist__44c2_s_p3_0,
  114403. NULL,
  114404. &_vq_auxt__44c2_s_p3_0,
  114405. NULL,
  114406. 0
  114407. };
  114408. static long _vq_quantlist__44c2_s_p4_0[] = {
  114409. 4,
  114410. 3,
  114411. 5,
  114412. 2,
  114413. 6,
  114414. 1,
  114415. 7,
  114416. 0,
  114417. 8,
  114418. };
  114419. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114420. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114421. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114422. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114423. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114424. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114425. 0,
  114426. };
  114427. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114428. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114429. };
  114430. static long _vq_quantmap__44c2_s_p4_0[] = {
  114431. 7, 5, 3, 1, 0, 2, 4, 6,
  114432. 8,
  114433. };
  114434. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114435. _vq_quantthresh__44c2_s_p4_0,
  114436. _vq_quantmap__44c2_s_p4_0,
  114437. 9,
  114438. 9
  114439. };
  114440. static static_codebook _44c2_s_p4_0 = {
  114441. 2, 81,
  114442. _vq_lengthlist__44c2_s_p4_0,
  114443. 1, -531628032, 1611661312, 4, 0,
  114444. _vq_quantlist__44c2_s_p4_0,
  114445. NULL,
  114446. &_vq_auxt__44c2_s_p4_0,
  114447. NULL,
  114448. 0
  114449. };
  114450. static long _vq_quantlist__44c2_s_p5_0[] = {
  114451. 4,
  114452. 3,
  114453. 5,
  114454. 2,
  114455. 6,
  114456. 1,
  114457. 7,
  114458. 0,
  114459. 8,
  114460. };
  114461. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114462. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114463. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114464. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114465. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114466. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114467. 11,
  114468. };
  114469. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114470. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114471. };
  114472. static long _vq_quantmap__44c2_s_p5_0[] = {
  114473. 7, 5, 3, 1, 0, 2, 4, 6,
  114474. 8,
  114475. };
  114476. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114477. _vq_quantthresh__44c2_s_p5_0,
  114478. _vq_quantmap__44c2_s_p5_0,
  114479. 9,
  114480. 9
  114481. };
  114482. static static_codebook _44c2_s_p5_0 = {
  114483. 2, 81,
  114484. _vq_lengthlist__44c2_s_p5_0,
  114485. 1, -531628032, 1611661312, 4, 0,
  114486. _vq_quantlist__44c2_s_p5_0,
  114487. NULL,
  114488. &_vq_auxt__44c2_s_p5_0,
  114489. NULL,
  114490. 0
  114491. };
  114492. static long _vq_quantlist__44c2_s_p6_0[] = {
  114493. 8,
  114494. 7,
  114495. 9,
  114496. 6,
  114497. 10,
  114498. 5,
  114499. 11,
  114500. 4,
  114501. 12,
  114502. 3,
  114503. 13,
  114504. 2,
  114505. 14,
  114506. 1,
  114507. 15,
  114508. 0,
  114509. 16,
  114510. };
  114511. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114512. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114513. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114514. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114515. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114516. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114517. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114518. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114519. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114520. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114521. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114522. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114523. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114524. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114525. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114526. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114527. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114528. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114529. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114530. 14,
  114531. };
  114532. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114533. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114534. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114535. };
  114536. static long _vq_quantmap__44c2_s_p6_0[] = {
  114537. 15, 13, 11, 9, 7, 5, 3, 1,
  114538. 0, 2, 4, 6, 8, 10, 12, 14,
  114539. 16,
  114540. };
  114541. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114542. _vq_quantthresh__44c2_s_p6_0,
  114543. _vq_quantmap__44c2_s_p6_0,
  114544. 17,
  114545. 17
  114546. };
  114547. static static_codebook _44c2_s_p6_0 = {
  114548. 2, 289,
  114549. _vq_lengthlist__44c2_s_p6_0,
  114550. 1, -529530880, 1611661312, 5, 0,
  114551. _vq_quantlist__44c2_s_p6_0,
  114552. NULL,
  114553. &_vq_auxt__44c2_s_p6_0,
  114554. NULL,
  114555. 0
  114556. };
  114557. static long _vq_quantlist__44c2_s_p7_0[] = {
  114558. 1,
  114559. 0,
  114560. 2,
  114561. };
  114562. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114563. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114564. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114565. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114566. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114567. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114568. 11,
  114569. };
  114570. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114571. -5.5, 5.5,
  114572. };
  114573. static long _vq_quantmap__44c2_s_p7_0[] = {
  114574. 1, 0, 2,
  114575. };
  114576. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114577. _vq_quantthresh__44c2_s_p7_0,
  114578. _vq_quantmap__44c2_s_p7_0,
  114579. 3,
  114580. 3
  114581. };
  114582. static static_codebook _44c2_s_p7_0 = {
  114583. 4, 81,
  114584. _vq_lengthlist__44c2_s_p7_0,
  114585. 1, -529137664, 1618345984, 2, 0,
  114586. _vq_quantlist__44c2_s_p7_0,
  114587. NULL,
  114588. &_vq_auxt__44c2_s_p7_0,
  114589. NULL,
  114590. 0
  114591. };
  114592. static long _vq_quantlist__44c2_s_p7_1[] = {
  114593. 5,
  114594. 4,
  114595. 6,
  114596. 3,
  114597. 7,
  114598. 2,
  114599. 8,
  114600. 1,
  114601. 9,
  114602. 0,
  114603. 10,
  114604. };
  114605. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114606. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114607. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114608. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114609. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114610. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114611. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114612. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114613. 10,10,10, 8, 8, 8, 8, 8, 8,
  114614. };
  114615. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114616. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114617. 3.5, 4.5,
  114618. };
  114619. static long _vq_quantmap__44c2_s_p7_1[] = {
  114620. 9, 7, 5, 3, 1, 0, 2, 4,
  114621. 6, 8, 10,
  114622. };
  114623. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114624. _vq_quantthresh__44c2_s_p7_1,
  114625. _vq_quantmap__44c2_s_p7_1,
  114626. 11,
  114627. 11
  114628. };
  114629. static static_codebook _44c2_s_p7_1 = {
  114630. 2, 121,
  114631. _vq_lengthlist__44c2_s_p7_1,
  114632. 1, -531365888, 1611661312, 4, 0,
  114633. _vq_quantlist__44c2_s_p7_1,
  114634. NULL,
  114635. &_vq_auxt__44c2_s_p7_1,
  114636. NULL,
  114637. 0
  114638. };
  114639. static long _vq_quantlist__44c2_s_p8_0[] = {
  114640. 6,
  114641. 5,
  114642. 7,
  114643. 4,
  114644. 8,
  114645. 3,
  114646. 9,
  114647. 2,
  114648. 10,
  114649. 1,
  114650. 11,
  114651. 0,
  114652. 12,
  114653. };
  114654. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114655. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114656. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114657. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114658. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114659. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114660. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114661. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114662. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114663. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114664. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114665. 0,12,12,12,12,13,12,14,14,
  114666. };
  114667. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114668. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114669. 12.5, 17.5, 22.5, 27.5,
  114670. };
  114671. static long _vq_quantmap__44c2_s_p8_0[] = {
  114672. 11, 9, 7, 5, 3, 1, 0, 2,
  114673. 4, 6, 8, 10, 12,
  114674. };
  114675. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114676. _vq_quantthresh__44c2_s_p8_0,
  114677. _vq_quantmap__44c2_s_p8_0,
  114678. 13,
  114679. 13
  114680. };
  114681. static static_codebook _44c2_s_p8_0 = {
  114682. 2, 169,
  114683. _vq_lengthlist__44c2_s_p8_0,
  114684. 1, -526516224, 1616117760, 4, 0,
  114685. _vq_quantlist__44c2_s_p8_0,
  114686. NULL,
  114687. &_vq_auxt__44c2_s_p8_0,
  114688. NULL,
  114689. 0
  114690. };
  114691. static long _vq_quantlist__44c2_s_p8_1[] = {
  114692. 2,
  114693. 1,
  114694. 3,
  114695. 0,
  114696. 4,
  114697. };
  114698. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114699. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114700. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114701. };
  114702. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114703. -1.5, -0.5, 0.5, 1.5,
  114704. };
  114705. static long _vq_quantmap__44c2_s_p8_1[] = {
  114706. 3, 1, 0, 2, 4,
  114707. };
  114708. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114709. _vq_quantthresh__44c2_s_p8_1,
  114710. _vq_quantmap__44c2_s_p8_1,
  114711. 5,
  114712. 5
  114713. };
  114714. static static_codebook _44c2_s_p8_1 = {
  114715. 2, 25,
  114716. _vq_lengthlist__44c2_s_p8_1,
  114717. 1, -533725184, 1611661312, 3, 0,
  114718. _vq_quantlist__44c2_s_p8_1,
  114719. NULL,
  114720. &_vq_auxt__44c2_s_p8_1,
  114721. NULL,
  114722. 0
  114723. };
  114724. static long _vq_quantlist__44c2_s_p9_0[] = {
  114725. 6,
  114726. 5,
  114727. 7,
  114728. 4,
  114729. 8,
  114730. 3,
  114731. 9,
  114732. 2,
  114733. 10,
  114734. 1,
  114735. 11,
  114736. 0,
  114737. 12,
  114738. };
  114739. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114740. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114741. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114742. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114743. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114744. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114745. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114746. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114747. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114748. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114749. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114750. 11,11,11,11,11,11,11,11,11,
  114751. };
  114752. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114753. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114754. 552.5, 773.5, 994.5, 1215.5,
  114755. };
  114756. static long _vq_quantmap__44c2_s_p9_0[] = {
  114757. 11, 9, 7, 5, 3, 1, 0, 2,
  114758. 4, 6, 8, 10, 12,
  114759. };
  114760. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114761. _vq_quantthresh__44c2_s_p9_0,
  114762. _vq_quantmap__44c2_s_p9_0,
  114763. 13,
  114764. 13
  114765. };
  114766. static static_codebook _44c2_s_p9_0 = {
  114767. 2, 169,
  114768. _vq_lengthlist__44c2_s_p9_0,
  114769. 1, -514541568, 1627103232, 4, 0,
  114770. _vq_quantlist__44c2_s_p9_0,
  114771. NULL,
  114772. &_vq_auxt__44c2_s_p9_0,
  114773. NULL,
  114774. 0
  114775. };
  114776. static long _vq_quantlist__44c2_s_p9_1[] = {
  114777. 6,
  114778. 5,
  114779. 7,
  114780. 4,
  114781. 8,
  114782. 3,
  114783. 9,
  114784. 2,
  114785. 10,
  114786. 1,
  114787. 11,
  114788. 0,
  114789. 12,
  114790. };
  114791. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114792. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114793. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114794. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114795. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114796. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114797. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114798. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114799. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114800. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114801. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114802. 17,13,12,12,10,13,11,14,14,
  114803. };
  114804. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114805. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114806. 42.5, 59.5, 76.5, 93.5,
  114807. };
  114808. static long _vq_quantmap__44c2_s_p9_1[] = {
  114809. 11, 9, 7, 5, 3, 1, 0, 2,
  114810. 4, 6, 8, 10, 12,
  114811. };
  114812. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114813. _vq_quantthresh__44c2_s_p9_1,
  114814. _vq_quantmap__44c2_s_p9_1,
  114815. 13,
  114816. 13
  114817. };
  114818. static static_codebook _44c2_s_p9_1 = {
  114819. 2, 169,
  114820. _vq_lengthlist__44c2_s_p9_1,
  114821. 1, -522616832, 1620115456, 4, 0,
  114822. _vq_quantlist__44c2_s_p9_1,
  114823. NULL,
  114824. &_vq_auxt__44c2_s_p9_1,
  114825. NULL,
  114826. 0
  114827. };
  114828. static long _vq_quantlist__44c2_s_p9_2[] = {
  114829. 8,
  114830. 7,
  114831. 9,
  114832. 6,
  114833. 10,
  114834. 5,
  114835. 11,
  114836. 4,
  114837. 12,
  114838. 3,
  114839. 13,
  114840. 2,
  114841. 14,
  114842. 1,
  114843. 15,
  114844. 0,
  114845. 16,
  114846. };
  114847. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114848. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114849. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114850. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114851. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114852. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114853. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114854. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114855. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114856. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114857. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114858. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114859. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114860. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114861. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114862. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114863. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114864. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114865. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114866. 10,
  114867. };
  114868. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114869. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114870. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114871. };
  114872. static long _vq_quantmap__44c2_s_p9_2[] = {
  114873. 15, 13, 11, 9, 7, 5, 3, 1,
  114874. 0, 2, 4, 6, 8, 10, 12, 14,
  114875. 16,
  114876. };
  114877. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114878. _vq_quantthresh__44c2_s_p9_2,
  114879. _vq_quantmap__44c2_s_p9_2,
  114880. 17,
  114881. 17
  114882. };
  114883. static static_codebook _44c2_s_p9_2 = {
  114884. 2, 289,
  114885. _vq_lengthlist__44c2_s_p9_2,
  114886. 1, -529530880, 1611661312, 5, 0,
  114887. _vq_quantlist__44c2_s_p9_2,
  114888. NULL,
  114889. &_vq_auxt__44c2_s_p9_2,
  114890. NULL,
  114891. 0
  114892. };
  114893. static long _huff_lengthlist__44c2_s_short[] = {
  114894. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114895. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114896. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114897. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114898. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114899. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114900. 6, 8, 9,12,
  114901. };
  114902. static static_codebook _huff_book__44c2_s_short = {
  114903. 2, 100,
  114904. _huff_lengthlist__44c2_s_short,
  114905. 0, 0, 0, 0, 0,
  114906. NULL,
  114907. NULL,
  114908. NULL,
  114909. NULL,
  114910. 0
  114911. };
  114912. static long _huff_lengthlist__44c3_s_long[] = {
  114913. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114914. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114915. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114916. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114917. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114918. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114919. 9, 8, 8, 8,
  114920. };
  114921. static static_codebook _huff_book__44c3_s_long = {
  114922. 2, 100,
  114923. _huff_lengthlist__44c3_s_long,
  114924. 0, 0, 0, 0, 0,
  114925. NULL,
  114926. NULL,
  114927. NULL,
  114928. NULL,
  114929. 0
  114930. };
  114931. static long _vq_quantlist__44c3_s_p1_0[] = {
  114932. 1,
  114933. 0,
  114934. 2,
  114935. };
  114936. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114937. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114938. 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114942. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114943. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114947. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114948. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114979. 0, 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, 5, 7, 7, 0, 0, 0, 0,
  114983. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  114988. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  114993. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115008. 0, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115029. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115034. 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  115035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115038. 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115039. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  115040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115050. 0, 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,
  115348. };
  115349. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115350. -0.5, 0.5,
  115351. };
  115352. static long _vq_quantmap__44c3_s_p1_0[] = {
  115353. 1, 0, 2,
  115354. };
  115355. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115356. _vq_quantthresh__44c3_s_p1_0,
  115357. _vq_quantmap__44c3_s_p1_0,
  115358. 3,
  115359. 3
  115360. };
  115361. static static_codebook _44c3_s_p1_0 = {
  115362. 8, 6561,
  115363. _vq_lengthlist__44c3_s_p1_0,
  115364. 1, -535822336, 1611661312, 2, 0,
  115365. _vq_quantlist__44c3_s_p1_0,
  115366. NULL,
  115367. &_vq_auxt__44c3_s_p1_0,
  115368. NULL,
  115369. 0
  115370. };
  115371. static long _vq_quantlist__44c3_s_p2_0[] = {
  115372. 2,
  115373. 1,
  115374. 3,
  115375. 0,
  115376. 4,
  115377. };
  115378. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115379. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115380. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115381. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115382. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115383. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115388. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115389. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115390. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115391. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115393. 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115397. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115398. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115401. 0, 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. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115405. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115406. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115418. 0,
  115419. };
  115420. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115421. -1.5, -0.5, 0.5, 1.5,
  115422. };
  115423. static long _vq_quantmap__44c3_s_p2_0[] = {
  115424. 3, 1, 0, 2, 4,
  115425. };
  115426. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115427. _vq_quantthresh__44c3_s_p2_0,
  115428. _vq_quantmap__44c3_s_p2_0,
  115429. 5,
  115430. 5
  115431. };
  115432. static static_codebook _44c3_s_p2_0 = {
  115433. 4, 625,
  115434. _vq_lengthlist__44c3_s_p2_0,
  115435. 1, -533725184, 1611661312, 3, 0,
  115436. _vq_quantlist__44c3_s_p2_0,
  115437. NULL,
  115438. &_vq_auxt__44c3_s_p2_0,
  115439. NULL,
  115440. 0
  115441. };
  115442. static long _vq_quantlist__44c3_s_p3_0[] = {
  115443. 2,
  115444. 1,
  115445. 3,
  115446. 0,
  115447. 4,
  115448. };
  115449. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115450. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115453. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115456. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  115490. };
  115491. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115492. -1.5, -0.5, 0.5, 1.5,
  115493. };
  115494. static long _vq_quantmap__44c3_s_p3_0[] = {
  115495. 3, 1, 0, 2, 4,
  115496. };
  115497. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115498. _vq_quantthresh__44c3_s_p3_0,
  115499. _vq_quantmap__44c3_s_p3_0,
  115500. 5,
  115501. 5
  115502. };
  115503. static static_codebook _44c3_s_p3_0 = {
  115504. 4, 625,
  115505. _vq_lengthlist__44c3_s_p3_0,
  115506. 1, -533725184, 1611661312, 3, 0,
  115507. _vq_quantlist__44c3_s_p3_0,
  115508. NULL,
  115509. &_vq_auxt__44c3_s_p3_0,
  115510. NULL,
  115511. 0
  115512. };
  115513. static long _vq_quantlist__44c3_s_p4_0[] = {
  115514. 4,
  115515. 3,
  115516. 5,
  115517. 2,
  115518. 6,
  115519. 1,
  115520. 7,
  115521. 0,
  115522. 8,
  115523. };
  115524. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115525. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115526. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115527. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115528. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115529. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115530. 0,
  115531. };
  115532. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115533. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115534. };
  115535. static long _vq_quantmap__44c3_s_p4_0[] = {
  115536. 7, 5, 3, 1, 0, 2, 4, 6,
  115537. 8,
  115538. };
  115539. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115540. _vq_quantthresh__44c3_s_p4_0,
  115541. _vq_quantmap__44c3_s_p4_0,
  115542. 9,
  115543. 9
  115544. };
  115545. static static_codebook _44c3_s_p4_0 = {
  115546. 2, 81,
  115547. _vq_lengthlist__44c3_s_p4_0,
  115548. 1, -531628032, 1611661312, 4, 0,
  115549. _vq_quantlist__44c3_s_p4_0,
  115550. NULL,
  115551. &_vq_auxt__44c3_s_p4_0,
  115552. NULL,
  115553. 0
  115554. };
  115555. static long _vq_quantlist__44c3_s_p5_0[] = {
  115556. 4,
  115557. 3,
  115558. 5,
  115559. 2,
  115560. 6,
  115561. 1,
  115562. 7,
  115563. 0,
  115564. 8,
  115565. };
  115566. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115567. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115568. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115569. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115570. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115571. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115572. 11,
  115573. };
  115574. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115575. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115576. };
  115577. static long _vq_quantmap__44c3_s_p5_0[] = {
  115578. 7, 5, 3, 1, 0, 2, 4, 6,
  115579. 8,
  115580. };
  115581. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115582. _vq_quantthresh__44c3_s_p5_0,
  115583. _vq_quantmap__44c3_s_p5_0,
  115584. 9,
  115585. 9
  115586. };
  115587. static static_codebook _44c3_s_p5_0 = {
  115588. 2, 81,
  115589. _vq_lengthlist__44c3_s_p5_0,
  115590. 1, -531628032, 1611661312, 4, 0,
  115591. _vq_quantlist__44c3_s_p5_0,
  115592. NULL,
  115593. &_vq_auxt__44c3_s_p5_0,
  115594. NULL,
  115595. 0
  115596. };
  115597. static long _vq_quantlist__44c3_s_p6_0[] = {
  115598. 8,
  115599. 7,
  115600. 9,
  115601. 6,
  115602. 10,
  115603. 5,
  115604. 11,
  115605. 4,
  115606. 12,
  115607. 3,
  115608. 13,
  115609. 2,
  115610. 14,
  115611. 1,
  115612. 15,
  115613. 0,
  115614. 16,
  115615. };
  115616. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115617. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115618. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115619. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115620. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115621. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115622. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115623. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115624. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115625. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115626. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115627. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115628. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115629. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115630. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115631. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115632. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115633. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115634. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115635. 13,
  115636. };
  115637. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115638. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115639. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115640. };
  115641. static long _vq_quantmap__44c3_s_p6_0[] = {
  115642. 15, 13, 11, 9, 7, 5, 3, 1,
  115643. 0, 2, 4, 6, 8, 10, 12, 14,
  115644. 16,
  115645. };
  115646. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115647. _vq_quantthresh__44c3_s_p6_0,
  115648. _vq_quantmap__44c3_s_p6_0,
  115649. 17,
  115650. 17
  115651. };
  115652. static static_codebook _44c3_s_p6_0 = {
  115653. 2, 289,
  115654. _vq_lengthlist__44c3_s_p6_0,
  115655. 1, -529530880, 1611661312, 5, 0,
  115656. _vq_quantlist__44c3_s_p6_0,
  115657. NULL,
  115658. &_vq_auxt__44c3_s_p6_0,
  115659. NULL,
  115660. 0
  115661. };
  115662. static long _vq_quantlist__44c3_s_p7_0[] = {
  115663. 1,
  115664. 0,
  115665. 2,
  115666. };
  115667. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115668. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115669. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115670. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115671. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115672. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115673. 10,
  115674. };
  115675. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115676. -5.5, 5.5,
  115677. };
  115678. static long _vq_quantmap__44c3_s_p7_0[] = {
  115679. 1, 0, 2,
  115680. };
  115681. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115682. _vq_quantthresh__44c3_s_p7_0,
  115683. _vq_quantmap__44c3_s_p7_0,
  115684. 3,
  115685. 3
  115686. };
  115687. static static_codebook _44c3_s_p7_0 = {
  115688. 4, 81,
  115689. _vq_lengthlist__44c3_s_p7_0,
  115690. 1, -529137664, 1618345984, 2, 0,
  115691. _vq_quantlist__44c3_s_p7_0,
  115692. NULL,
  115693. &_vq_auxt__44c3_s_p7_0,
  115694. NULL,
  115695. 0
  115696. };
  115697. static long _vq_quantlist__44c3_s_p7_1[] = {
  115698. 5,
  115699. 4,
  115700. 6,
  115701. 3,
  115702. 7,
  115703. 2,
  115704. 8,
  115705. 1,
  115706. 9,
  115707. 0,
  115708. 10,
  115709. };
  115710. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115711. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115712. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115713. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115714. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115715. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115716. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115717. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115718. 10,10,10, 8, 8, 8, 8, 8, 8,
  115719. };
  115720. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115721. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115722. 3.5, 4.5,
  115723. };
  115724. static long _vq_quantmap__44c3_s_p7_1[] = {
  115725. 9, 7, 5, 3, 1, 0, 2, 4,
  115726. 6, 8, 10,
  115727. };
  115728. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115729. _vq_quantthresh__44c3_s_p7_1,
  115730. _vq_quantmap__44c3_s_p7_1,
  115731. 11,
  115732. 11
  115733. };
  115734. static static_codebook _44c3_s_p7_1 = {
  115735. 2, 121,
  115736. _vq_lengthlist__44c3_s_p7_1,
  115737. 1, -531365888, 1611661312, 4, 0,
  115738. _vq_quantlist__44c3_s_p7_1,
  115739. NULL,
  115740. &_vq_auxt__44c3_s_p7_1,
  115741. NULL,
  115742. 0
  115743. };
  115744. static long _vq_quantlist__44c3_s_p8_0[] = {
  115745. 6,
  115746. 5,
  115747. 7,
  115748. 4,
  115749. 8,
  115750. 3,
  115751. 9,
  115752. 2,
  115753. 10,
  115754. 1,
  115755. 11,
  115756. 0,
  115757. 12,
  115758. };
  115759. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115760. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115761. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115762. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115763. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115764. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115765. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115766. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115767. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115768. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115769. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115770. 0,13,13,12,12,13,12,14,13,
  115771. };
  115772. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115773. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115774. 12.5, 17.5, 22.5, 27.5,
  115775. };
  115776. static long _vq_quantmap__44c3_s_p8_0[] = {
  115777. 11, 9, 7, 5, 3, 1, 0, 2,
  115778. 4, 6, 8, 10, 12,
  115779. };
  115780. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115781. _vq_quantthresh__44c3_s_p8_0,
  115782. _vq_quantmap__44c3_s_p8_0,
  115783. 13,
  115784. 13
  115785. };
  115786. static static_codebook _44c3_s_p8_0 = {
  115787. 2, 169,
  115788. _vq_lengthlist__44c3_s_p8_0,
  115789. 1, -526516224, 1616117760, 4, 0,
  115790. _vq_quantlist__44c3_s_p8_0,
  115791. NULL,
  115792. &_vq_auxt__44c3_s_p8_0,
  115793. NULL,
  115794. 0
  115795. };
  115796. static long _vq_quantlist__44c3_s_p8_1[] = {
  115797. 2,
  115798. 1,
  115799. 3,
  115800. 0,
  115801. 4,
  115802. };
  115803. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115804. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115805. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115806. };
  115807. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115808. -1.5, -0.5, 0.5, 1.5,
  115809. };
  115810. static long _vq_quantmap__44c3_s_p8_1[] = {
  115811. 3, 1, 0, 2, 4,
  115812. };
  115813. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115814. _vq_quantthresh__44c3_s_p8_1,
  115815. _vq_quantmap__44c3_s_p8_1,
  115816. 5,
  115817. 5
  115818. };
  115819. static static_codebook _44c3_s_p8_1 = {
  115820. 2, 25,
  115821. _vq_lengthlist__44c3_s_p8_1,
  115822. 1, -533725184, 1611661312, 3, 0,
  115823. _vq_quantlist__44c3_s_p8_1,
  115824. NULL,
  115825. &_vq_auxt__44c3_s_p8_1,
  115826. NULL,
  115827. 0
  115828. };
  115829. static long _vq_quantlist__44c3_s_p9_0[] = {
  115830. 6,
  115831. 5,
  115832. 7,
  115833. 4,
  115834. 8,
  115835. 3,
  115836. 9,
  115837. 2,
  115838. 10,
  115839. 1,
  115840. 11,
  115841. 0,
  115842. 12,
  115843. };
  115844. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115845. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115846. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115847. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115848. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115849. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115850. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115851. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115852. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115853. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115854. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115855. 11,11,11,11,11,11,11,11,11,
  115856. };
  115857. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115858. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115859. 637.5, 892.5, 1147.5, 1402.5,
  115860. };
  115861. static long _vq_quantmap__44c3_s_p9_0[] = {
  115862. 11, 9, 7, 5, 3, 1, 0, 2,
  115863. 4, 6, 8, 10, 12,
  115864. };
  115865. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115866. _vq_quantthresh__44c3_s_p9_0,
  115867. _vq_quantmap__44c3_s_p9_0,
  115868. 13,
  115869. 13
  115870. };
  115871. static static_codebook _44c3_s_p9_0 = {
  115872. 2, 169,
  115873. _vq_lengthlist__44c3_s_p9_0,
  115874. 1, -514332672, 1627381760, 4, 0,
  115875. _vq_quantlist__44c3_s_p9_0,
  115876. NULL,
  115877. &_vq_auxt__44c3_s_p9_0,
  115878. NULL,
  115879. 0
  115880. };
  115881. static long _vq_quantlist__44c3_s_p9_1[] = {
  115882. 7,
  115883. 6,
  115884. 8,
  115885. 5,
  115886. 9,
  115887. 4,
  115888. 10,
  115889. 3,
  115890. 11,
  115891. 2,
  115892. 12,
  115893. 1,
  115894. 13,
  115895. 0,
  115896. 14,
  115897. };
  115898. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115899. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115900. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115901. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115902. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115903. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115904. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115905. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115906. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115907. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115908. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115909. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115910. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115911. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115912. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115913. 15,
  115914. };
  115915. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115916. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115917. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115918. };
  115919. static long _vq_quantmap__44c3_s_p9_1[] = {
  115920. 13, 11, 9, 7, 5, 3, 1, 0,
  115921. 2, 4, 6, 8, 10, 12, 14,
  115922. };
  115923. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115924. _vq_quantthresh__44c3_s_p9_1,
  115925. _vq_quantmap__44c3_s_p9_1,
  115926. 15,
  115927. 15
  115928. };
  115929. static static_codebook _44c3_s_p9_1 = {
  115930. 2, 225,
  115931. _vq_lengthlist__44c3_s_p9_1,
  115932. 1, -522338304, 1620115456, 4, 0,
  115933. _vq_quantlist__44c3_s_p9_1,
  115934. NULL,
  115935. &_vq_auxt__44c3_s_p9_1,
  115936. NULL,
  115937. 0
  115938. };
  115939. static long _vq_quantlist__44c3_s_p9_2[] = {
  115940. 8,
  115941. 7,
  115942. 9,
  115943. 6,
  115944. 10,
  115945. 5,
  115946. 11,
  115947. 4,
  115948. 12,
  115949. 3,
  115950. 13,
  115951. 2,
  115952. 14,
  115953. 1,
  115954. 15,
  115955. 0,
  115956. 16,
  115957. };
  115958. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115959. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115960. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115961. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115962. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115963. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115964. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115965. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115966. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115967. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115968. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115969. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115970. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115971. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115972. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115973. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115974. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115975. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115976. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115977. 10,
  115978. };
  115979. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115980. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115981. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115982. };
  115983. static long _vq_quantmap__44c3_s_p9_2[] = {
  115984. 15, 13, 11, 9, 7, 5, 3, 1,
  115985. 0, 2, 4, 6, 8, 10, 12, 14,
  115986. 16,
  115987. };
  115988. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115989. _vq_quantthresh__44c3_s_p9_2,
  115990. _vq_quantmap__44c3_s_p9_2,
  115991. 17,
  115992. 17
  115993. };
  115994. static static_codebook _44c3_s_p9_2 = {
  115995. 2, 289,
  115996. _vq_lengthlist__44c3_s_p9_2,
  115997. 1, -529530880, 1611661312, 5, 0,
  115998. _vq_quantlist__44c3_s_p9_2,
  115999. NULL,
  116000. &_vq_auxt__44c3_s_p9_2,
  116001. NULL,
  116002. 0
  116003. };
  116004. static long _huff_lengthlist__44c3_s_short[] = {
  116005. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  116006. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  116007. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  116008. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  116009. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  116010. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  116011. 6, 8, 9,11,
  116012. };
  116013. static static_codebook _huff_book__44c3_s_short = {
  116014. 2, 100,
  116015. _huff_lengthlist__44c3_s_short,
  116016. 0, 0, 0, 0, 0,
  116017. NULL,
  116018. NULL,
  116019. NULL,
  116020. NULL,
  116021. 0
  116022. };
  116023. static long _huff_lengthlist__44c4_s_long[] = {
  116024. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  116025. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  116026. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  116027. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  116028. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  116029. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  116030. 9, 8, 7, 7,
  116031. };
  116032. static static_codebook _huff_book__44c4_s_long = {
  116033. 2, 100,
  116034. _huff_lengthlist__44c4_s_long,
  116035. 0, 0, 0, 0, 0,
  116036. NULL,
  116037. NULL,
  116038. NULL,
  116039. NULL,
  116040. 0
  116041. };
  116042. static long _vq_quantlist__44c4_s_p1_0[] = {
  116043. 1,
  116044. 0,
  116045. 2,
  116046. };
  116047. static long _vq_lengthlist__44c4_s_p1_0[] = {
  116048. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  116049. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116053. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116054. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116058. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  116059. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116090. 0, 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, 5, 7, 7, 0, 0, 0, 0,
  116094. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  116099. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  116104. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116119. 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116140. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116145. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  116146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116149. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116150. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116161. 0, 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,
  116459. };
  116460. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116461. -0.5, 0.5,
  116462. };
  116463. static long _vq_quantmap__44c4_s_p1_0[] = {
  116464. 1, 0, 2,
  116465. };
  116466. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116467. _vq_quantthresh__44c4_s_p1_0,
  116468. _vq_quantmap__44c4_s_p1_0,
  116469. 3,
  116470. 3
  116471. };
  116472. static static_codebook _44c4_s_p1_0 = {
  116473. 8, 6561,
  116474. _vq_lengthlist__44c4_s_p1_0,
  116475. 1, -535822336, 1611661312, 2, 0,
  116476. _vq_quantlist__44c4_s_p1_0,
  116477. NULL,
  116478. &_vq_auxt__44c4_s_p1_0,
  116479. NULL,
  116480. 0
  116481. };
  116482. static long _vq_quantlist__44c4_s_p2_0[] = {
  116483. 2,
  116484. 1,
  116485. 3,
  116486. 0,
  116487. 4,
  116488. };
  116489. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116490. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116491. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116492. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116493. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116494. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116499. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116500. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116501. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116502. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116504. 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116508. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116509. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116512. 0, 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. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116516. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116517. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116529. 0,
  116530. };
  116531. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116532. -1.5, -0.5, 0.5, 1.5,
  116533. };
  116534. static long _vq_quantmap__44c4_s_p2_0[] = {
  116535. 3, 1, 0, 2, 4,
  116536. };
  116537. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116538. _vq_quantthresh__44c4_s_p2_0,
  116539. _vq_quantmap__44c4_s_p2_0,
  116540. 5,
  116541. 5
  116542. };
  116543. static static_codebook _44c4_s_p2_0 = {
  116544. 4, 625,
  116545. _vq_lengthlist__44c4_s_p2_0,
  116546. 1, -533725184, 1611661312, 3, 0,
  116547. _vq_quantlist__44c4_s_p2_0,
  116548. NULL,
  116549. &_vq_auxt__44c4_s_p2_0,
  116550. NULL,
  116551. 0
  116552. };
  116553. static long _vq_quantlist__44c4_s_p3_0[] = {
  116554. 2,
  116555. 1,
  116556. 3,
  116557. 0,
  116558. 4,
  116559. };
  116560. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116561. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116564. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116567. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  116601. };
  116602. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116603. -1.5, -0.5, 0.5, 1.5,
  116604. };
  116605. static long _vq_quantmap__44c4_s_p3_0[] = {
  116606. 3, 1, 0, 2, 4,
  116607. };
  116608. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116609. _vq_quantthresh__44c4_s_p3_0,
  116610. _vq_quantmap__44c4_s_p3_0,
  116611. 5,
  116612. 5
  116613. };
  116614. static static_codebook _44c4_s_p3_0 = {
  116615. 4, 625,
  116616. _vq_lengthlist__44c4_s_p3_0,
  116617. 1, -533725184, 1611661312, 3, 0,
  116618. _vq_quantlist__44c4_s_p3_0,
  116619. NULL,
  116620. &_vq_auxt__44c4_s_p3_0,
  116621. NULL,
  116622. 0
  116623. };
  116624. static long _vq_quantlist__44c4_s_p4_0[] = {
  116625. 4,
  116626. 3,
  116627. 5,
  116628. 2,
  116629. 6,
  116630. 1,
  116631. 7,
  116632. 0,
  116633. 8,
  116634. };
  116635. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116636. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116637. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116638. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116639. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116640. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116641. 0,
  116642. };
  116643. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116644. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116645. };
  116646. static long _vq_quantmap__44c4_s_p4_0[] = {
  116647. 7, 5, 3, 1, 0, 2, 4, 6,
  116648. 8,
  116649. };
  116650. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116651. _vq_quantthresh__44c4_s_p4_0,
  116652. _vq_quantmap__44c4_s_p4_0,
  116653. 9,
  116654. 9
  116655. };
  116656. static static_codebook _44c4_s_p4_0 = {
  116657. 2, 81,
  116658. _vq_lengthlist__44c4_s_p4_0,
  116659. 1, -531628032, 1611661312, 4, 0,
  116660. _vq_quantlist__44c4_s_p4_0,
  116661. NULL,
  116662. &_vq_auxt__44c4_s_p4_0,
  116663. NULL,
  116664. 0
  116665. };
  116666. static long _vq_quantlist__44c4_s_p5_0[] = {
  116667. 4,
  116668. 3,
  116669. 5,
  116670. 2,
  116671. 6,
  116672. 1,
  116673. 7,
  116674. 0,
  116675. 8,
  116676. };
  116677. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116678. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116679. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116680. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116681. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116682. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116683. 10,
  116684. };
  116685. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116686. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116687. };
  116688. static long _vq_quantmap__44c4_s_p5_0[] = {
  116689. 7, 5, 3, 1, 0, 2, 4, 6,
  116690. 8,
  116691. };
  116692. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116693. _vq_quantthresh__44c4_s_p5_0,
  116694. _vq_quantmap__44c4_s_p5_0,
  116695. 9,
  116696. 9
  116697. };
  116698. static static_codebook _44c4_s_p5_0 = {
  116699. 2, 81,
  116700. _vq_lengthlist__44c4_s_p5_0,
  116701. 1, -531628032, 1611661312, 4, 0,
  116702. _vq_quantlist__44c4_s_p5_0,
  116703. NULL,
  116704. &_vq_auxt__44c4_s_p5_0,
  116705. NULL,
  116706. 0
  116707. };
  116708. static long _vq_quantlist__44c4_s_p6_0[] = {
  116709. 8,
  116710. 7,
  116711. 9,
  116712. 6,
  116713. 10,
  116714. 5,
  116715. 11,
  116716. 4,
  116717. 12,
  116718. 3,
  116719. 13,
  116720. 2,
  116721. 14,
  116722. 1,
  116723. 15,
  116724. 0,
  116725. 16,
  116726. };
  116727. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116728. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116729. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116730. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116731. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116732. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116733. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116734. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116735. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116736. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116737. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116738. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116739. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116740. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116741. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116742. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116743. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116744. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116745. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116746. 13,
  116747. };
  116748. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116749. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116750. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116751. };
  116752. static long _vq_quantmap__44c4_s_p6_0[] = {
  116753. 15, 13, 11, 9, 7, 5, 3, 1,
  116754. 0, 2, 4, 6, 8, 10, 12, 14,
  116755. 16,
  116756. };
  116757. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116758. _vq_quantthresh__44c4_s_p6_0,
  116759. _vq_quantmap__44c4_s_p6_0,
  116760. 17,
  116761. 17
  116762. };
  116763. static static_codebook _44c4_s_p6_0 = {
  116764. 2, 289,
  116765. _vq_lengthlist__44c4_s_p6_0,
  116766. 1, -529530880, 1611661312, 5, 0,
  116767. _vq_quantlist__44c4_s_p6_0,
  116768. NULL,
  116769. &_vq_auxt__44c4_s_p6_0,
  116770. NULL,
  116771. 0
  116772. };
  116773. static long _vq_quantlist__44c4_s_p7_0[] = {
  116774. 1,
  116775. 0,
  116776. 2,
  116777. };
  116778. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116779. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116780. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116781. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116782. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116783. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116784. 10,
  116785. };
  116786. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116787. -5.5, 5.5,
  116788. };
  116789. static long _vq_quantmap__44c4_s_p7_0[] = {
  116790. 1, 0, 2,
  116791. };
  116792. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116793. _vq_quantthresh__44c4_s_p7_0,
  116794. _vq_quantmap__44c4_s_p7_0,
  116795. 3,
  116796. 3
  116797. };
  116798. static static_codebook _44c4_s_p7_0 = {
  116799. 4, 81,
  116800. _vq_lengthlist__44c4_s_p7_0,
  116801. 1, -529137664, 1618345984, 2, 0,
  116802. _vq_quantlist__44c4_s_p7_0,
  116803. NULL,
  116804. &_vq_auxt__44c4_s_p7_0,
  116805. NULL,
  116806. 0
  116807. };
  116808. static long _vq_quantlist__44c4_s_p7_1[] = {
  116809. 5,
  116810. 4,
  116811. 6,
  116812. 3,
  116813. 7,
  116814. 2,
  116815. 8,
  116816. 1,
  116817. 9,
  116818. 0,
  116819. 10,
  116820. };
  116821. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116822. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116823. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116824. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116825. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116826. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116827. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116828. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116829. 10,10,10, 8, 8, 8, 8, 9, 9,
  116830. };
  116831. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116832. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116833. 3.5, 4.5,
  116834. };
  116835. static long _vq_quantmap__44c4_s_p7_1[] = {
  116836. 9, 7, 5, 3, 1, 0, 2, 4,
  116837. 6, 8, 10,
  116838. };
  116839. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116840. _vq_quantthresh__44c4_s_p7_1,
  116841. _vq_quantmap__44c4_s_p7_1,
  116842. 11,
  116843. 11
  116844. };
  116845. static static_codebook _44c4_s_p7_1 = {
  116846. 2, 121,
  116847. _vq_lengthlist__44c4_s_p7_1,
  116848. 1, -531365888, 1611661312, 4, 0,
  116849. _vq_quantlist__44c4_s_p7_1,
  116850. NULL,
  116851. &_vq_auxt__44c4_s_p7_1,
  116852. NULL,
  116853. 0
  116854. };
  116855. static long _vq_quantlist__44c4_s_p8_0[] = {
  116856. 6,
  116857. 5,
  116858. 7,
  116859. 4,
  116860. 8,
  116861. 3,
  116862. 9,
  116863. 2,
  116864. 10,
  116865. 1,
  116866. 11,
  116867. 0,
  116868. 12,
  116869. };
  116870. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116871. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116872. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116873. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116874. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116875. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116876. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116877. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116878. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116879. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116880. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116881. 0,13,12,12,12,12,12,13,13,
  116882. };
  116883. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116884. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116885. 12.5, 17.5, 22.5, 27.5,
  116886. };
  116887. static long _vq_quantmap__44c4_s_p8_0[] = {
  116888. 11, 9, 7, 5, 3, 1, 0, 2,
  116889. 4, 6, 8, 10, 12,
  116890. };
  116891. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116892. _vq_quantthresh__44c4_s_p8_0,
  116893. _vq_quantmap__44c4_s_p8_0,
  116894. 13,
  116895. 13
  116896. };
  116897. static static_codebook _44c4_s_p8_0 = {
  116898. 2, 169,
  116899. _vq_lengthlist__44c4_s_p8_0,
  116900. 1, -526516224, 1616117760, 4, 0,
  116901. _vq_quantlist__44c4_s_p8_0,
  116902. NULL,
  116903. &_vq_auxt__44c4_s_p8_0,
  116904. NULL,
  116905. 0
  116906. };
  116907. static long _vq_quantlist__44c4_s_p8_1[] = {
  116908. 2,
  116909. 1,
  116910. 3,
  116911. 0,
  116912. 4,
  116913. };
  116914. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116915. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116916. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116917. };
  116918. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116919. -1.5, -0.5, 0.5, 1.5,
  116920. };
  116921. static long _vq_quantmap__44c4_s_p8_1[] = {
  116922. 3, 1, 0, 2, 4,
  116923. };
  116924. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116925. _vq_quantthresh__44c4_s_p8_1,
  116926. _vq_quantmap__44c4_s_p8_1,
  116927. 5,
  116928. 5
  116929. };
  116930. static static_codebook _44c4_s_p8_1 = {
  116931. 2, 25,
  116932. _vq_lengthlist__44c4_s_p8_1,
  116933. 1, -533725184, 1611661312, 3, 0,
  116934. _vq_quantlist__44c4_s_p8_1,
  116935. NULL,
  116936. &_vq_auxt__44c4_s_p8_1,
  116937. NULL,
  116938. 0
  116939. };
  116940. static long _vq_quantlist__44c4_s_p9_0[] = {
  116941. 6,
  116942. 5,
  116943. 7,
  116944. 4,
  116945. 8,
  116946. 3,
  116947. 9,
  116948. 2,
  116949. 10,
  116950. 1,
  116951. 11,
  116952. 0,
  116953. 12,
  116954. };
  116955. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116956. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116957. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116958. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116959. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116960. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116961. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116962. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116963. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116964. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116965. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116966. 12,12,12,12,12,12,12,12,12,
  116967. };
  116968. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116969. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116970. 787.5, 1102.5, 1417.5, 1732.5,
  116971. };
  116972. static long _vq_quantmap__44c4_s_p9_0[] = {
  116973. 11, 9, 7, 5, 3, 1, 0, 2,
  116974. 4, 6, 8, 10, 12,
  116975. };
  116976. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116977. _vq_quantthresh__44c4_s_p9_0,
  116978. _vq_quantmap__44c4_s_p9_0,
  116979. 13,
  116980. 13
  116981. };
  116982. static static_codebook _44c4_s_p9_0 = {
  116983. 2, 169,
  116984. _vq_lengthlist__44c4_s_p9_0,
  116985. 1, -513964032, 1628680192, 4, 0,
  116986. _vq_quantlist__44c4_s_p9_0,
  116987. NULL,
  116988. &_vq_auxt__44c4_s_p9_0,
  116989. NULL,
  116990. 0
  116991. };
  116992. static long _vq_quantlist__44c4_s_p9_1[] = {
  116993. 7,
  116994. 6,
  116995. 8,
  116996. 5,
  116997. 9,
  116998. 4,
  116999. 10,
  117000. 3,
  117001. 11,
  117002. 2,
  117003. 12,
  117004. 1,
  117005. 13,
  117006. 0,
  117007. 14,
  117008. };
  117009. static long _vq_lengthlist__44c4_s_p9_1[] = {
  117010. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  117011. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  117012. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  117013. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  117014. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  117015. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  117016. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  117017. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  117018. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  117019. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  117020. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  117021. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  117022. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  117023. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  117024. 15,
  117025. };
  117026. static float _vq_quantthresh__44c4_s_p9_1[] = {
  117027. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  117028. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  117029. };
  117030. static long _vq_quantmap__44c4_s_p9_1[] = {
  117031. 13, 11, 9, 7, 5, 3, 1, 0,
  117032. 2, 4, 6, 8, 10, 12, 14,
  117033. };
  117034. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  117035. _vq_quantthresh__44c4_s_p9_1,
  117036. _vq_quantmap__44c4_s_p9_1,
  117037. 15,
  117038. 15
  117039. };
  117040. static static_codebook _44c4_s_p9_1 = {
  117041. 2, 225,
  117042. _vq_lengthlist__44c4_s_p9_1,
  117043. 1, -520986624, 1620377600, 4, 0,
  117044. _vq_quantlist__44c4_s_p9_1,
  117045. NULL,
  117046. &_vq_auxt__44c4_s_p9_1,
  117047. NULL,
  117048. 0
  117049. };
  117050. static long _vq_quantlist__44c4_s_p9_2[] = {
  117051. 10,
  117052. 9,
  117053. 11,
  117054. 8,
  117055. 12,
  117056. 7,
  117057. 13,
  117058. 6,
  117059. 14,
  117060. 5,
  117061. 15,
  117062. 4,
  117063. 16,
  117064. 3,
  117065. 17,
  117066. 2,
  117067. 18,
  117068. 1,
  117069. 19,
  117070. 0,
  117071. 20,
  117072. };
  117073. static long _vq_lengthlist__44c4_s_p9_2[] = {
  117074. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117075. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  117076. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  117077. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  117078. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  117079. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  117080. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  117081. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  117082. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  117083. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  117084. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117085. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  117086. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117087. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  117088. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  117089. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  117090. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  117091. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117092. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  117093. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  117094. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117095. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117096. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  117097. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  117098. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  117099. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  117100. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  117101. 10,10,10,10,10,10,10,10,10,
  117102. };
  117103. static float _vq_quantthresh__44c4_s_p9_2[] = {
  117104. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117105. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117106. 6.5, 7.5, 8.5, 9.5,
  117107. };
  117108. static long _vq_quantmap__44c4_s_p9_2[] = {
  117109. 19, 17, 15, 13, 11, 9, 7, 5,
  117110. 3, 1, 0, 2, 4, 6, 8, 10,
  117111. 12, 14, 16, 18, 20,
  117112. };
  117113. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  117114. _vq_quantthresh__44c4_s_p9_2,
  117115. _vq_quantmap__44c4_s_p9_2,
  117116. 21,
  117117. 21
  117118. };
  117119. static static_codebook _44c4_s_p9_2 = {
  117120. 2, 441,
  117121. _vq_lengthlist__44c4_s_p9_2,
  117122. 1, -529268736, 1611661312, 5, 0,
  117123. _vq_quantlist__44c4_s_p9_2,
  117124. NULL,
  117125. &_vq_auxt__44c4_s_p9_2,
  117126. NULL,
  117127. 0
  117128. };
  117129. static long _huff_lengthlist__44c4_s_short[] = {
  117130. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  117131. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  117132. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  117133. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  117134. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  117135. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  117136. 7, 9,12,17,
  117137. };
  117138. static static_codebook _huff_book__44c4_s_short = {
  117139. 2, 100,
  117140. _huff_lengthlist__44c4_s_short,
  117141. 0, 0, 0, 0, 0,
  117142. NULL,
  117143. NULL,
  117144. NULL,
  117145. NULL,
  117146. 0
  117147. };
  117148. static long _huff_lengthlist__44c5_s_long[] = {
  117149. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  117150. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  117151. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  117152. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  117153. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  117154. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  117155. 9, 8, 7, 7,
  117156. };
  117157. static static_codebook _huff_book__44c5_s_long = {
  117158. 2, 100,
  117159. _huff_lengthlist__44c5_s_long,
  117160. 0, 0, 0, 0, 0,
  117161. NULL,
  117162. NULL,
  117163. NULL,
  117164. NULL,
  117165. 0
  117166. };
  117167. static long _vq_quantlist__44c5_s_p1_0[] = {
  117168. 1,
  117169. 0,
  117170. 2,
  117171. };
  117172. static long _vq_lengthlist__44c5_s_p1_0[] = {
  117173. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117174. 0, 0, 4, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117178. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117179. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117183. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  117184. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117215. 0, 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, 4, 7, 7, 0, 0, 0, 0,
  117219. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  117224. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  117225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117229. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  117230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117244. 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117265. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  117270. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  117271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117274. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  117275. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  117276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117286. 0, 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,
  117584. };
  117585. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117586. -0.5, 0.5,
  117587. };
  117588. static long _vq_quantmap__44c5_s_p1_0[] = {
  117589. 1, 0, 2,
  117590. };
  117591. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117592. _vq_quantthresh__44c5_s_p1_0,
  117593. _vq_quantmap__44c5_s_p1_0,
  117594. 3,
  117595. 3
  117596. };
  117597. static static_codebook _44c5_s_p1_0 = {
  117598. 8, 6561,
  117599. _vq_lengthlist__44c5_s_p1_0,
  117600. 1, -535822336, 1611661312, 2, 0,
  117601. _vq_quantlist__44c5_s_p1_0,
  117602. NULL,
  117603. &_vq_auxt__44c5_s_p1_0,
  117604. NULL,
  117605. 0
  117606. };
  117607. static long _vq_quantlist__44c5_s_p2_0[] = {
  117608. 2,
  117609. 1,
  117610. 3,
  117611. 0,
  117612. 4,
  117613. };
  117614. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117615. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117616. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117617. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117618. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117619. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117624. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117625. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117626. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117627. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117629. 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117633. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117634. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117637. 0, 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. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117641. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117642. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117654. 0,
  117655. };
  117656. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117657. -1.5, -0.5, 0.5, 1.5,
  117658. };
  117659. static long _vq_quantmap__44c5_s_p2_0[] = {
  117660. 3, 1, 0, 2, 4,
  117661. };
  117662. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117663. _vq_quantthresh__44c5_s_p2_0,
  117664. _vq_quantmap__44c5_s_p2_0,
  117665. 5,
  117666. 5
  117667. };
  117668. static static_codebook _44c5_s_p2_0 = {
  117669. 4, 625,
  117670. _vq_lengthlist__44c5_s_p2_0,
  117671. 1, -533725184, 1611661312, 3, 0,
  117672. _vq_quantlist__44c5_s_p2_0,
  117673. NULL,
  117674. &_vq_auxt__44c5_s_p2_0,
  117675. NULL,
  117676. 0
  117677. };
  117678. static long _vq_quantlist__44c5_s_p3_0[] = {
  117679. 2,
  117680. 1,
  117681. 3,
  117682. 0,
  117683. 4,
  117684. };
  117685. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117686. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117689. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117692. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  117726. };
  117727. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117728. -1.5, -0.5, 0.5, 1.5,
  117729. };
  117730. static long _vq_quantmap__44c5_s_p3_0[] = {
  117731. 3, 1, 0, 2, 4,
  117732. };
  117733. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117734. _vq_quantthresh__44c5_s_p3_0,
  117735. _vq_quantmap__44c5_s_p3_0,
  117736. 5,
  117737. 5
  117738. };
  117739. static static_codebook _44c5_s_p3_0 = {
  117740. 4, 625,
  117741. _vq_lengthlist__44c5_s_p3_0,
  117742. 1, -533725184, 1611661312, 3, 0,
  117743. _vq_quantlist__44c5_s_p3_0,
  117744. NULL,
  117745. &_vq_auxt__44c5_s_p3_0,
  117746. NULL,
  117747. 0
  117748. };
  117749. static long _vq_quantlist__44c5_s_p4_0[] = {
  117750. 4,
  117751. 3,
  117752. 5,
  117753. 2,
  117754. 6,
  117755. 1,
  117756. 7,
  117757. 0,
  117758. 8,
  117759. };
  117760. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117761. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117762. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117763. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117764. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117765. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117766. 0,
  117767. };
  117768. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117769. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117770. };
  117771. static long _vq_quantmap__44c5_s_p4_0[] = {
  117772. 7, 5, 3, 1, 0, 2, 4, 6,
  117773. 8,
  117774. };
  117775. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117776. _vq_quantthresh__44c5_s_p4_0,
  117777. _vq_quantmap__44c5_s_p4_0,
  117778. 9,
  117779. 9
  117780. };
  117781. static static_codebook _44c5_s_p4_0 = {
  117782. 2, 81,
  117783. _vq_lengthlist__44c5_s_p4_0,
  117784. 1, -531628032, 1611661312, 4, 0,
  117785. _vq_quantlist__44c5_s_p4_0,
  117786. NULL,
  117787. &_vq_auxt__44c5_s_p4_0,
  117788. NULL,
  117789. 0
  117790. };
  117791. static long _vq_quantlist__44c5_s_p5_0[] = {
  117792. 4,
  117793. 3,
  117794. 5,
  117795. 2,
  117796. 6,
  117797. 1,
  117798. 7,
  117799. 0,
  117800. 8,
  117801. };
  117802. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117803. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117804. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117805. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117806. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117807. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117808. 10,
  117809. };
  117810. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117811. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117812. };
  117813. static long _vq_quantmap__44c5_s_p5_0[] = {
  117814. 7, 5, 3, 1, 0, 2, 4, 6,
  117815. 8,
  117816. };
  117817. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117818. _vq_quantthresh__44c5_s_p5_0,
  117819. _vq_quantmap__44c5_s_p5_0,
  117820. 9,
  117821. 9
  117822. };
  117823. static static_codebook _44c5_s_p5_0 = {
  117824. 2, 81,
  117825. _vq_lengthlist__44c5_s_p5_0,
  117826. 1, -531628032, 1611661312, 4, 0,
  117827. _vq_quantlist__44c5_s_p5_0,
  117828. NULL,
  117829. &_vq_auxt__44c5_s_p5_0,
  117830. NULL,
  117831. 0
  117832. };
  117833. static long _vq_quantlist__44c5_s_p6_0[] = {
  117834. 8,
  117835. 7,
  117836. 9,
  117837. 6,
  117838. 10,
  117839. 5,
  117840. 11,
  117841. 4,
  117842. 12,
  117843. 3,
  117844. 13,
  117845. 2,
  117846. 14,
  117847. 1,
  117848. 15,
  117849. 0,
  117850. 16,
  117851. };
  117852. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117853. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117854. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117855. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117856. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117857. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117858. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117859. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117860. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117861. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117862. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117863. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117864. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117865. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117866. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117867. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117868. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117869. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117870. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117871. 13,
  117872. };
  117873. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117874. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117875. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117876. };
  117877. static long _vq_quantmap__44c5_s_p6_0[] = {
  117878. 15, 13, 11, 9, 7, 5, 3, 1,
  117879. 0, 2, 4, 6, 8, 10, 12, 14,
  117880. 16,
  117881. };
  117882. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117883. _vq_quantthresh__44c5_s_p6_0,
  117884. _vq_quantmap__44c5_s_p6_0,
  117885. 17,
  117886. 17
  117887. };
  117888. static static_codebook _44c5_s_p6_0 = {
  117889. 2, 289,
  117890. _vq_lengthlist__44c5_s_p6_0,
  117891. 1, -529530880, 1611661312, 5, 0,
  117892. _vq_quantlist__44c5_s_p6_0,
  117893. NULL,
  117894. &_vq_auxt__44c5_s_p6_0,
  117895. NULL,
  117896. 0
  117897. };
  117898. static long _vq_quantlist__44c5_s_p7_0[] = {
  117899. 1,
  117900. 0,
  117901. 2,
  117902. };
  117903. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117904. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117905. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117906. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117907. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117908. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117909. 10,
  117910. };
  117911. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117912. -5.5, 5.5,
  117913. };
  117914. static long _vq_quantmap__44c5_s_p7_0[] = {
  117915. 1, 0, 2,
  117916. };
  117917. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117918. _vq_quantthresh__44c5_s_p7_0,
  117919. _vq_quantmap__44c5_s_p7_0,
  117920. 3,
  117921. 3
  117922. };
  117923. static static_codebook _44c5_s_p7_0 = {
  117924. 4, 81,
  117925. _vq_lengthlist__44c5_s_p7_0,
  117926. 1, -529137664, 1618345984, 2, 0,
  117927. _vq_quantlist__44c5_s_p7_0,
  117928. NULL,
  117929. &_vq_auxt__44c5_s_p7_0,
  117930. NULL,
  117931. 0
  117932. };
  117933. static long _vq_quantlist__44c5_s_p7_1[] = {
  117934. 5,
  117935. 4,
  117936. 6,
  117937. 3,
  117938. 7,
  117939. 2,
  117940. 8,
  117941. 1,
  117942. 9,
  117943. 0,
  117944. 10,
  117945. };
  117946. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117947. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117948. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117949. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117950. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117951. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117952. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117953. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117954. 10,10,10, 8, 8, 8, 8, 8, 8,
  117955. };
  117956. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117957. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117958. 3.5, 4.5,
  117959. };
  117960. static long _vq_quantmap__44c5_s_p7_1[] = {
  117961. 9, 7, 5, 3, 1, 0, 2, 4,
  117962. 6, 8, 10,
  117963. };
  117964. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117965. _vq_quantthresh__44c5_s_p7_1,
  117966. _vq_quantmap__44c5_s_p7_1,
  117967. 11,
  117968. 11
  117969. };
  117970. static static_codebook _44c5_s_p7_1 = {
  117971. 2, 121,
  117972. _vq_lengthlist__44c5_s_p7_1,
  117973. 1, -531365888, 1611661312, 4, 0,
  117974. _vq_quantlist__44c5_s_p7_1,
  117975. NULL,
  117976. &_vq_auxt__44c5_s_p7_1,
  117977. NULL,
  117978. 0
  117979. };
  117980. static long _vq_quantlist__44c5_s_p8_0[] = {
  117981. 6,
  117982. 5,
  117983. 7,
  117984. 4,
  117985. 8,
  117986. 3,
  117987. 9,
  117988. 2,
  117989. 10,
  117990. 1,
  117991. 11,
  117992. 0,
  117993. 12,
  117994. };
  117995. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117996. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117997. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117998. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117999. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  118000. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  118001. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  118002. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  118003. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  118004. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  118005. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  118006. 0,12,12,12,12,12,12,13,13,
  118007. };
  118008. static float _vq_quantthresh__44c5_s_p8_0[] = {
  118009. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118010. 12.5, 17.5, 22.5, 27.5,
  118011. };
  118012. static long _vq_quantmap__44c5_s_p8_0[] = {
  118013. 11, 9, 7, 5, 3, 1, 0, 2,
  118014. 4, 6, 8, 10, 12,
  118015. };
  118016. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  118017. _vq_quantthresh__44c5_s_p8_0,
  118018. _vq_quantmap__44c5_s_p8_0,
  118019. 13,
  118020. 13
  118021. };
  118022. static static_codebook _44c5_s_p8_0 = {
  118023. 2, 169,
  118024. _vq_lengthlist__44c5_s_p8_0,
  118025. 1, -526516224, 1616117760, 4, 0,
  118026. _vq_quantlist__44c5_s_p8_0,
  118027. NULL,
  118028. &_vq_auxt__44c5_s_p8_0,
  118029. NULL,
  118030. 0
  118031. };
  118032. static long _vq_quantlist__44c5_s_p8_1[] = {
  118033. 2,
  118034. 1,
  118035. 3,
  118036. 0,
  118037. 4,
  118038. };
  118039. static long _vq_lengthlist__44c5_s_p8_1[] = {
  118040. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  118041. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118042. };
  118043. static float _vq_quantthresh__44c5_s_p8_1[] = {
  118044. -1.5, -0.5, 0.5, 1.5,
  118045. };
  118046. static long _vq_quantmap__44c5_s_p8_1[] = {
  118047. 3, 1, 0, 2, 4,
  118048. };
  118049. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  118050. _vq_quantthresh__44c5_s_p8_1,
  118051. _vq_quantmap__44c5_s_p8_1,
  118052. 5,
  118053. 5
  118054. };
  118055. static static_codebook _44c5_s_p8_1 = {
  118056. 2, 25,
  118057. _vq_lengthlist__44c5_s_p8_1,
  118058. 1, -533725184, 1611661312, 3, 0,
  118059. _vq_quantlist__44c5_s_p8_1,
  118060. NULL,
  118061. &_vq_auxt__44c5_s_p8_1,
  118062. NULL,
  118063. 0
  118064. };
  118065. static long _vq_quantlist__44c5_s_p9_0[] = {
  118066. 7,
  118067. 6,
  118068. 8,
  118069. 5,
  118070. 9,
  118071. 4,
  118072. 10,
  118073. 3,
  118074. 11,
  118075. 2,
  118076. 12,
  118077. 1,
  118078. 13,
  118079. 0,
  118080. 14,
  118081. };
  118082. static long _vq_lengthlist__44c5_s_p9_0[] = {
  118083. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  118084. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  118085. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118086. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118087. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118088. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118089. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118090. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118091. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118092. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118093. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118094. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118095. 13,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,12,12,12,12,12,12,12,
  118097. 12,
  118098. };
  118099. static float _vq_quantthresh__44c5_s_p9_0[] = {
  118100. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  118101. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  118102. };
  118103. static long _vq_quantmap__44c5_s_p9_0[] = {
  118104. 13, 11, 9, 7, 5, 3, 1, 0,
  118105. 2, 4, 6, 8, 10, 12, 14,
  118106. };
  118107. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  118108. _vq_quantthresh__44c5_s_p9_0,
  118109. _vq_quantmap__44c5_s_p9_0,
  118110. 15,
  118111. 15
  118112. };
  118113. static static_codebook _44c5_s_p9_0 = {
  118114. 2, 225,
  118115. _vq_lengthlist__44c5_s_p9_0,
  118116. 1, -512522752, 1628852224, 4, 0,
  118117. _vq_quantlist__44c5_s_p9_0,
  118118. NULL,
  118119. &_vq_auxt__44c5_s_p9_0,
  118120. NULL,
  118121. 0
  118122. };
  118123. static long _vq_quantlist__44c5_s_p9_1[] = {
  118124. 8,
  118125. 7,
  118126. 9,
  118127. 6,
  118128. 10,
  118129. 5,
  118130. 11,
  118131. 4,
  118132. 12,
  118133. 3,
  118134. 13,
  118135. 2,
  118136. 14,
  118137. 1,
  118138. 15,
  118139. 0,
  118140. 16,
  118141. };
  118142. static long _vq_lengthlist__44c5_s_p9_1[] = {
  118143. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  118144. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  118145. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  118146. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  118147. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  118148. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  118149. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  118150. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  118151. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  118152. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  118153. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  118154. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  118155. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  118156. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  118157. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  118158. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  118159. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  118160. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  118161. 15,
  118162. };
  118163. static float _vq_quantthresh__44c5_s_p9_1[] = {
  118164. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  118165. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  118166. };
  118167. static long _vq_quantmap__44c5_s_p9_1[] = {
  118168. 15, 13, 11, 9, 7, 5, 3, 1,
  118169. 0, 2, 4, 6, 8, 10, 12, 14,
  118170. 16,
  118171. };
  118172. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  118173. _vq_quantthresh__44c5_s_p9_1,
  118174. _vq_quantmap__44c5_s_p9_1,
  118175. 17,
  118176. 17
  118177. };
  118178. static static_codebook _44c5_s_p9_1 = {
  118179. 2, 289,
  118180. _vq_lengthlist__44c5_s_p9_1,
  118181. 1, -520814592, 1620377600, 5, 0,
  118182. _vq_quantlist__44c5_s_p9_1,
  118183. NULL,
  118184. &_vq_auxt__44c5_s_p9_1,
  118185. NULL,
  118186. 0
  118187. };
  118188. static long _vq_quantlist__44c5_s_p9_2[] = {
  118189. 10,
  118190. 9,
  118191. 11,
  118192. 8,
  118193. 12,
  118194. 7,
  118195. 13,
  118196. 6,
  118197. 14,
  118198. 5,
  118199. 15,
  118200. 4,
  118201. 16,
  118202. 3,
  118203. 17,
  118204. 2,
  118205. 18,
  118206. 1,
  118207. 19,
  118208. 0,
  118209. 20,
  118210. };
  118211. static long _vq_lengthlist__44c5_s_p9_2[] = {
  118212. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  118213. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  118214. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  118215. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  118216. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  118217. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  118218. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  118219. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  118220. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  118221. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118222. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  118223. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  118224. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  118225. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  118226. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  118227. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  118228. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  118229. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118230. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  118231. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  118232. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118233. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118234. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118235. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118236. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  118237. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118238. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  118239. 10,10,10,10,10,10,10,10,10,
  118240. };
  118241. static float _vq_quantthresh__44c5_s_p9_2[] = {
  118242. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118243. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118244. 6.5, 7.5, 8.5, 9.5,
  118245. };
  118246. static long _vq_quantmap__44c5_s_p9_2[] = {
  118247. 19, 17, 15, 13, 11, 9, 7, 5,
  118248. 3, 1, 0, 2, 4, 6, 8, 10,
  118249. 12, 14, 16, 18, 20,
  118250. };
  118251. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  118252. _vq_quantthresh__44c5_s_p9_2,
  118253. _vq_quantmap__44c5_s_p9_2,
  118254. 21,
  118255. 21
  118256. };
  118257. static static_codebook _44c5_s_p9_2 = {
  118258. 2, 441,
  118259. _vq_lengthlist__44c5_s_p9_2,
  118260. 1, -529268736, 1611661312, 5, 0,
  118261. _vq_quantlist__44c5_s_p9_2,
  118262. NULL,
  118263. &_vq_auxt__44c5_s_p9_2,
  118264. NULL,
  118265. 0
  118266. };
  118267. static long _huff_lengthlist__44c5_s_short[] = {
  118268. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  118269. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  118270. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  118271. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  118272. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  118273. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  118274. 6, 8,11,16,
  118275. };
  118276. static static_codebook _huff_book__44c5_s_short = {
  118277. 2, 100,
  118278. _huff_lengthlist__44c5_s_short,
  118279. 0, 0, 0, 0, 0,
  118280. NULL,
  118281. NULL,
  118282. NULL,
  118283. NULL,
  118284. 0
  118285. };
  118286. static long _huff_lengthlist__44c6_s_long[] = {
  118287. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118288. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118289. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118290. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118291. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118292. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118293. 11,10,10,12,
  118294. };
  118295. static static_codebook _huff_book__44c6_s_long = {
  118296. 2, 100,
  118297. _huff_lengthlist__44c6_s_long,
  118298. 0, 0, 0, 0, 0,
  118299. NULL,
  118300. NULL,
  118301. NULL,
  118302. NULL,
  118303. 0
  118304. };
  118305. static long _vq_quantlist__44c6_s_p1_0[] = {
  118306. 1,
  118307. 0,
  118308. 2,
  118309. };
  118310. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118311. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118312. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118313. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118314. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118315. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118316. 8,
  118317. };
  118318. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118319. -0.5, 0.5,
  118320. };
  118321. static long _vq_quantmap__44c6_s_p1_0[] = {
  118322. 1, 0, 2,
  118323. };
  118324. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118325. _vq_quantthresh__44c6_s_p1_0,
  118326. _vq_quantmap__44c6_s_p1_0,
  118327. 3,
  118328. 3
  118329. };
  118330. static static_codebook _44c6_s_p1_0 = {
  118331. 4, 81,
  118332. _vq_lengthlist__44c6_s_p1_0,
  118333. 1, -535822336, 1611661312, 2, 0,
  118334. _vq_quantlist__44c6_s_p1_0,
  118335. NULL,
  118336. &_vq_auxt__44c6_s_p1_0,
  118337. NULL,
  118338. 0
  118339. };
  118340. static long _vq_quantlist__44c6_s_p2_0[] = {
  118341. 2,
  118342. 1,
  118343. 3,
  118344. 0,
  118345. 4,
  118346. };
  118347. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118348. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118349. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118350. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118351. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118352. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118353. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118354. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118355. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118357. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118358. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118359. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118360. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118361. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118362. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118363. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118365. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118366. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118367. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118368. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118369. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118370. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118371. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118373. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118374. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118375. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118376. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118377. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118378. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118379. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118381. 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118384. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118385. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118386. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118387. 13,
  118388. };
  118389. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118390. -1.5, -0.5, 0.5, 1.5,
  118391. };
  118392. static long _vq_quantmap__44c6_s_p2_0[] = {
  118393. 3, 1, 0, 2, 4,
  118394. };
  118395. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118396. _vq_quantthresh__44c6_s_p2_0,
  118397. _vq_quantmap__44c6_s_p2_0,
  118398. 5,
  118399. 5
  118400. };
  118401. static static_codebook _44c6_s_p2_0 = {
  118402. 4, 625,
  118403. _vq_lengthlist__44c6_s_p2_0,
  118404. 1, -533725184, 1611661312, 3, 0,
  118405. _vq_quantlist__44c6_s_p2_0,
  118406. NULL,
  118407. &_vq_auxt__44c6_s_p2_0,
  118408. NULL,
  118409. 0
  118410. };
  118411. static long _vq_quantlist__44c6_s_p3_0[] = {
  118412. 4,
  118413. 3,
  118414. 5,
  118415. 2,
  118416. 6,
  118417. 1,
  118418. 7,
  118419. 0,
  118420. 8,
  118421. };
  118422. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118423. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118424. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118425. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118426. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118428. 0,
  118429. };
  118430. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118431. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118432. };
  118433. static long _vq_quantmap__44c6_s_p3_0[] = {
  118434. 7, 5, 3, 1, 0, 2, 4, 6,
  118435. 8,
  118436. };
  118437. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118438. _vq_quantthresh__44c6_s_p3_0,
  118439. _vq_quantmap__44c6_s_p3_0,
  118440. 9,
  118441. 9
  118442. };
  118443. static static_codebook _44c6_s_p3_0 = {
  118444. 2, 81,
  118445. _vq_lengthlist__44c6_s_p3_0,
  118446. 1, -531628032, 1611661312, 4, 0,
  118447. _vq_quantlist__44c6_s_p3_0,
  118448. NULL,
  118449. &_vq_auxt__44c6_s_p3_0,
  118450. NULL,
  118451. 0
  118452. };
  118453. static long _vq_quantlist__44c6_s_p4_0[] = {
  118454. 8,
  118455. 7,
  118456. 9,
  118457. 6,
  118458. 10,
  118459. 5,
  118460. 11,
  118461. 4,
  118462. 12,
  118463. 3,
  118464. 13,
  118465. 2,
  118466. 14,
  118467. 1,
  118468. 15,
  118469. 0,
  118470. 16,
  118471. };
  118472. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118473. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118474. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118475. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118476. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118477. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118478. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118479. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118480. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118481. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118482. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118491. 0,
  118492. };
  118493. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118494. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118495. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118496. };
  118497. static long _vq_quantmap__44c6_s_p4_0[] = {
  118498. 15, 13, 11, 9, 7, 5, 3, 1,
  118499. 0, 2, 4, 6, 8, 10, 12, 14,
  118500. 16,
  118501. };
  118502. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118503. _vq_quantthresh__44c6_s_p4_0,
  118504. _vq_quantmap__44c6_s_p4_0,
  118505. 17,
  118506. 17
  118507. };
  118508. static static_codebook _44c6_s_p4_0 = {
  118509. 2, 289,
  118510. _vq_lengthlist__44c6_s_p4_0,
  118511. 1, -529530880, 1611661312, 5, 0,
  118512. _vq_quantlist__44c6_s_p4_0,
  118513. NULL,
  118514. &_vq_auxt__44c6_s_p4_0,
  118515. NULL,
  118516. 0
  118517. };
  118518. static long _vq_quantlist__44c6_s_p5_0[] = {
  118519. 1,
  118520. 0,
  118521. 2,
  118522. };
  118523. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118524. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118525. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118526. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118527. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118528. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118529. 12,
  118530. };
  118531. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118532. -5.5, 5.5,
  118533. };
  118534. static long _vq_quantmap__44c6_s_p5_0[] = {
  118535. 1, 0, 2,
  118536. };
  118537. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118538. _vq_quantthresh__44c6_s_p5_0,
  118539. _vq_quantmap__44c6_s_p5_0,
  118540. 3,
  118541. 3
  118542. };
  118543. static static_codebook _44c6_s_p5_0 = {
  118544. 4, 81,
  118545. _vq_lengthlist__44c6_s_p5_0,
  118546. 1, -529137664, 1618345984, 2, 0,
  118547. _vq_quantlist__44c6_s_p5_0,
  118548. NULL,
  118549. &_vq_auxt__44c6_s_p5_0,
  118550. NULL,
  118551. 0
  118552. };
  118553. static long _vq_quantlist__44c6_s_p5_1[] = {
  118554. 5,
  118555. 4,
  118556. 6,
  118557. 3,
  118558. 7,
  118559. 2,
  118560. 8,
  118561. 1,
  118562. 9,
  118563. 0,
  118564. 10,
  118565. };
  118566. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118567. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118568. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118569. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118570. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118571. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118572. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118573. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118574. 11,10,10, 7, 7, 8, 8, 8, 8,
  118575. };
  118576. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118577. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118578. 3.5, 4.5,
  118579. };
  118580. static long _vq_quantmap__44c6_s_p5_1[] = {
  118581. 9, 7, 5, 3, 1, 0, 2, 4,
  118582. 6, 8, 10,
  118583. };
  118584. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118585. _vq_quantthresh__44c6_s_p5_1,
  118586. _vq_quantmap__44c6_s_p5_1,
  118587. 11,
  118588. 11
  118589. };
  118590. static static_codebook _44c6_s_p5_1 = {
  118591. 2, 121,
  118592. _vq_lengthlist__44c6_s_p5_1,
  118593. 1, -531365888, 1611661312, 4, 0,
  118594. _vq_quantlist__44c6_s_p5_1,
  118595. NULL,
  118596. &_vq_auxt__44c6_s_p5_1,
  118597. NULL,
  118598. 0
  118599. };
  118600. static long _vq_quantlist__44c6_s_p6_0[] = {
  118601. 6,
  118602. 5,
  118603. 7,
  118604. 4,
  118605. 8,
  118606. 3,
  118607. 9,
  118608. 2,
  118609. 10,
  118610. 1,
  118611. 11,
  118612. 0,
  118613. 12,
  118614. };
  118615. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118616. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118617. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118618. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118619. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118620. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118621. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118626. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118627. };
  118628. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118629. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118630. 12.5, 17.5, 22.5, 27.5,
  118631. };
  118632. static long _vq_quantmap__44c6_s_p6_0[] = {
  118633. 11, 9, 7, 5, 3, 1, 0, 2,
  118634. 4, 6, 8, 10, 12,
  118635. };
  118636. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118637. _vq_quantthresh__44c6_s_p6_0,
  118638. _vq_quantmap__44c6_s_p6_0,
  118639. 13,
  118640. 13
  118641. };
  118642. static static_codebook _44c6_s_p6_0 = {
  118643. 2, 169,
  118644. _vq_lengthlist__44c6_s_p6_0,
  118645. 1, -526516224, 1616117760, 4, 0,
  118646. _vq_quantlist__44c6_s_p6_0,
  118647. NULL,
  118648. &_vq_auxt__44c6_s_p6_0,
  118649. NULL,
  118650. 0
  118651. };
  118652. static long _vq_quantlist__44c6_s_p6_1[] = {
  118653. 2,
  118654. 1,
  118655. 3,
  118656. 0,
  118657. 4,
  118658. };
  118659. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118660. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118661. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118662. };
  118663. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118664. -1.5, -0.5, 0.5, 1.5,
  118665. };
  118666. static long _vq_quantmap__44c6_s_p6_1[] = {
  118667. 3, 1, 0, 2, 4,
  118668. };
  118669. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118670. _vq_quantthresh__44c6_s_p6_1,
  118671. _vq_quantmap__44c6_s_p6_1,
  118672. 5,
  118673. 5
  118674. };
  118675. static static_codebook _44c6_s_p6_1 = {
  118676. 2, 25,
  118677. _vq_lengthlist__44c6_s_p6_1,
  118678. 1, -533725184, 1611661312, 3, 0,
  118679. _vq_quantlist__44c6_s_p6_1,
  118680. NULL,
  118681. &_vq_auxt__44c6_s_p6_1,
  118682. NULL,
  118683. 0
  118684. };
  118685. static long _vq_quantlist__44c6_s_p7_0[] = {
  118686. 6,
  118687. 5,
  118688. 7,
  118689. 4,
  118690. 8,
  118691. 3,
  118692. 9,
  118693. 2,
  118694. 10,
  118695. 1,
  118696. 11,
  118697. 0,
  118698. 12,
  118699. };
  118700. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118701. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118702. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118703. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118704. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118705. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118706. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118707. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118708. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118709. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118710. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118711. 20,13,13,13,13,13,13,14,14,
  118712. };
  118713. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118714. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118715. 27.5, 38.5, 49.5, 60.5,
  118716. };
  118717. static long _vq_quantmap__44c6_s_p7_0[] = {
  118718. 11, 9, 7, 5, 3, 1, 0, 2,
  118719. 4, 6, 8, 10, 12,
  118720. };
  118721. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118722. _vq_quantthresh__44c6_s_p7_0,
  118723. _vq_quantmap__44c6_s_p7_0,
  118724. 13,
  118725. 13
  118726. };
  118727. static static_codebook _44c6_s_p7_0 = {
  118728. 2, 169,
  118729. _vq_lengthlist__44c6_s_p7_0,
  118730. 1, -523206656, 1618345984, 4, 0,
  118731. _vq_quantlist__44c6_s_p7_0,
  118732. NULL,
  118733. &_vq_auxt__44c6_s_p7_0,
  118734. NULL,
  118735. 0
  118736. };
  118737. static long _vq_quantlist__44c6_s_p7_1[] = {
  118738. 5,
  118739. 4,
  118740. 6,
  118741. 3,
  118742. 7,
  118743. 2,
  118744. 8,
  118745. 1,
  118746. 9,
  118747. 0,
  118748. 10,
  118749. };
  118750. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118751. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118752. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118753. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118754. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118755. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118756. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118757. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118758. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118759. };
  118760. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118761. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118762. 3.5, 4.5,
  118763. };
  118764. static long _vq_quantmap__44c6_s_p7_1[] = {
  118765. 9, 7, 5, 3, 1, 0, 2, 4,
  118766. 6, 8, 10,
  118767. };
  118768. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118769. _vq_quantthresh__44c6_s_p7_1,
  118770. _vq_quantmap__44c6_s_p7_1,
  118771. 11,
  118772. 11
  118773. };
  118774. static static_codebook _44c6_s_p7_1 = {
  118775. 2, 121,
  118776. _vq_lengthlist__44c6_s_p7_1,
  118777. 1, -531365888, 1611661312, 4, 0,
  118778. _vq_quantlist__44c6_s_p7_1,
  118779. NULL,
  118780. &_vq_auxt__44c6_s_p7_1,
  118781. NULL,
  118782. 0
  118783. };
  118784. static long _vq_quantlist__44c6_s_p8_0[] = {
  118785. 7,
  118786. 6,
  118787. 8,
  118788. 5,
  118789. 9,
  118790. 4,
  118791. 10,
  118792. 3,
  118793. 11,
  118794. 2,
  118795. 12,
  118796. 1,
  118797. 13,
  118798. 0,
  118799. 14,
  118800. };
  118801. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118802. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118803. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118804. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118805. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118806. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118807. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118808. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118809. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118810. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118811. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118812. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118813. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118814. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118815. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118816. 14,
  118817. };
  118818. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118819. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118820. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118821. };
  118822. static long _vq_quantmap__44c6_s_p8_0[] = {
  118823. 13, 11, 9, 7, 5, 3, 1, 0,
  118824. 2, 4, 6, 8, 10, 12, 14,
  118825. };
  118826. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118827. _vq_quantthresh__44c6_s_p8_0,
  118828. _vq_quantmap__44c6_s_p8_0,
  118829. 15,
  118830. 15
  118831. };
  118832. static static_codebook _44c6_s_p8_0 = {
  118833. 2, 225,
  118834. _vq_lengthlist__44c6_s_p8_0,
  118835. 1, -520986624, 1620377600, 4, 0,
  118836. _vq_quantlist__44c6_s_p8_0,
  118837. NULL,
  118838. &_vq_auxt__44c6_s_p8_0,
  118839. NULL,
  118840. 0
  118841. };
  118842. static long _vq_quantlist__44c6_s_p8_1[] = {
  118843. 10,
  118844. 9,
  118845. 11,
  118846. 8,
  118847. 12,
  118848. 7,
  118849. 13,
  118850. 6,
  118851. 14,
  118852. 5,
  118853. 15,
  118854. 4,
  118855. 16,
  118856. 3,
  118857. 17,
  118858. 2,
  118859. 18,
  118860. 1,
  118861. 19,
  118862. 0,
  118863. 20,
  118864. };
  118865. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118866. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118867. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118868. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118869. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118870. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118871. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118872. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118873. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118874. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118875. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118876. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118877. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118878. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118879. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118880. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118881. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118882. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118883. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118884. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118885. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118886. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118887. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118888. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118889. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118890. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118891. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118892. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118893. 10,10,10,10,10,10,10,10,10,
  118894. };
  118895. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118896. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118897. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118898. 6.5, 7.5, 8.5, 9.5,
  118899. };
  118900. static long _vq_quantmap__44c6_s_p8_1[] = {
  118901. 19, 17, 15, 13, 11, 9, 7, 5,
  118902. 3, 1, 0, 2, 4, 6, 8, 10,
  118903. 12, 14, 16, 18, 20,
  118904. };
  118905. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118906. _vq_quantthresh__44c6_s_p8_1,
  118907. _vq_quantmap__44c6_s_p8_1,
  118908. 21,
  118909. 21
  118910. };
  118911. static static_codebook _44c6_s_p8_1 = {
  118912. 2, 441,
  118913. _vq_lengthlist__44c6_s_p8_1,
  118914. 1, -529268736, 1611661312, 5, 0,
  118915. _vq_quantlist__44c6_s_p8_1,
  118916. NULL,
  118917. &_vq_auxt__44c6_s_p8_1,
  118918. NULL,
  118919. 0
  118920. };
  118921. static long _vq_quantlist__44c6_s_p9_0[] = {
  118922. 6,
  118923. 5,
  118924. 7,
  118925. 4,
  118926. 8,
  118927. 3,
  118928. 9,
  118929. 2,
  118930. 10,
  118931. 1,
  118932. 11,
  118933. 0,
  118934. 12,
  118935. };
  118936. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118937. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118938. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118939. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118940. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118941. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118942. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118943. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118944. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118945. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118946. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118947. 10,10,10,10,10,10,10,10,10,
  118948. };
  118949. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118950. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118951. 1592.5, 2229.5, 2866.5, 3503.5,
  118952. };
  118953. static long _vq_quantmap__44c6_s_p9_0[] = {
  118954. 11, 9, 7, 5, 3, 1, 0, 2,
  118955. 4, 6, 8, 10, 12,
  118956. };
  118957. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118958. _vq_quantthresh__44c6_s_p9_0,
  118959. _vq_quantmap__44c6_s_p9_0,
  118960. 13,
  118961. 13
  118962. };
  118963. static static_codebook _44c6_s_p9_0 = {
  118964. 2, 169,
  118965. _vq_lengthlist__44c6_s_p9_0,
  118966. 1, -511845376, 1630791680, 4, 0,
  118967. _vq_quantlist__44c6_s_p9_0,
  118968. NULL,
  118969. &_vq_auxt__44c6_s_p9_0,
  118970. NULL,
  118971. 0
  118972. };
  118973. static long _vq_quantlist__44c6_s_p9_1[] = {
  118974. 6,
  118975. 5,
  118976. 7,
  118977. 4,
  118978. 8,
  118979. 3,
  118980. 9,
  118981. 2,
  118982. 10,
  118983. 1,
  118984. 11,
  118985. 0,
  118986. 12,
  118987. };
  118988. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118989. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118990. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118991. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118992. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118993. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118994. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118995. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118996. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118997. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118998. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118999. 15,12,10,11,11,13,11,12,13,
  119000. };
  119001. static float _vq_quantthresh__44c6_s_p9_1[] = {
  119002. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119003. 122.5, 171.5, 220.5, 269.5,
  119004. };
  119005. static long _vq_quantmap__44c6_s_p9_1[] = {
  119006. 11, 9, 7, 5, 3, 1, 0, 2,
  119007. 4, 6, 8, 10, 12,
  119008. };
  119009. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  119010. _vq_quantthresh__44c6_s_p9_1,
  119011. _vq_quantmap__44c6_s_p9_1,
  119012. 13,
  119013. 13
  119014. };
  119015. static static_codebook _44c6_s_p9_1 = {
  119016. 2, 169,
  119017. _vq_lengthlist__44c6_s_p9_1,
  119018. 1, -518889472, 1622704128, 4, 0,
  119019. _vq_quantlist__44c6_s_p9_1,
  119020. NULL,
  119021. &_vq_auxt__44c6_s_p9_1,
  119022. NULL,
  119023. 0
  119024. };
  119025. static long _vq_quantlist__44c6_s_p9_2[] = {
  119026. 24,
  119027. 23,
  119028. 25,
  119029. 22,
  119030. 26,
  119031. 21,
  119032. 27,
  119033. 20,
  119034. 28,
  119035. 19,
  119036. 29,
  119037. 18,
  119038. 30,
  119039. 17,
  119040. 31,
  119041. 16,
  119042. 32,
  119043. 15,
  119044. 33,
  119045. 14,
  119046. 34,
  119047. 13,
  119048. 35,
  119049. 12,
  119050. 36,
  119051. 11,
  119052. 37,
  119053. 10,
  119054. 38,
  119055. 9,
  119056. 39,
  119057. 8,
  119058. 40,
  119059. 7,
  119060. 41,
  119061. 6,
  119062. 42,
  119063. 5,
  119064. 43,
  119065. 4,
  119066. 44,
  119067. 3,
  119068. 45,
  119069. 2,
  119070. 46,
  119071. 1,
  119072. 47,
  119073. 0,
  119074. 48,
  119075. };
  119076. static long _vq_lengthlist__44c6_s_p9_2[] = {
  119077. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119078. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119079. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119080. 7,
  119081. };
  119082. static float _vq_quantthresh__44c6_s_p9_2[] = {
  119083. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119084. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119085. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119086. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119087. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119088. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119089. };
  119090. static long _vq_quantmap__44c6_s_p9_2[] = {
  119091. 47, 45, 43, 41, 39, 37, 35, 33,
  119092. 31, 29, 27, 25, 23, 21, 19, 17,
  119093. 15, 13, 11, 9, 7, 5, 3, 1,
  119094. 0, 2, 4, 6, 8, 10, 12, 14,
  119095. 16, 18, 20, 22, 24, 26, 28, 30,
  119096. 32, 34, 36, 38, 40, 42, 44, 46,
  119097. 48,
  119098. };
  119099. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  119100. _vq_quantthresh__44c6_s_p9_2,
  119101. _vq_quantmap__44c6_s_p9_2,
  119102. 49,
  119103. 49
  119104. };
  119105. static static_codebook _44c6_s_p9_2 = {
  119106. 1, 49,
  119107. _vq_lengthlist__44c6_s_p9_2,
  119108. 1, -526909440, 1611661312, 6, 0,
  119109. _vq_quantlist__44c6_s_p9_2,
  119110. NULL,
  119111. &_vq_auxt__44c6_s_p9_2,
  119112. NULL,
  119113. 0
  119114. };
  119115. static long _huff_lengthlist__44c6_s_short[] = {
  119116. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  119117. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  119118. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  119119. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  119120. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  119121. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  119122. 9,10,17,18,
  119123. };
  119124. static static_codebook _huff_book__44c6_s_short = {
  119125. 2, 100,
  119126. _huff_lengthlist__44c6_s_short,
  119127. 0, 0, 0, 0, 0,
  119128. NULL,
  119129. NULL,
  119130. NULL,
  119131. NULL,
  119132. 0
  119133. };
  119134. static long _huff_lengthlist__44c7_s_long[] = {
  119135. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  119136. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  119137. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  119138. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  119139. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  119140. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  119141. 11,10,10,12,
  119142. };
  119143. static static_codebook _huff_book__44c7_s_long = {
  119144. 2, 100,
  119145. _huff_lengthlist__44c7_s_long,
  119146. 0, 0, 0, 0, 0,
  119147. NULL,
  119148. NULL,
  119149. NULL,
  119150. NULL,
  119151. 0
  119152. };
  119153. static long _vq_quantlist__44c7_s_p1_0[] = {
  119154. 1,
  119155. 0,
  119156. 2,
  119157. };
  119158. static long _vq_lengthlist__44c7_s_p1_0[] = {
  119159. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  119160. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119161. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119162. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119163. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119164. 8,
  119165. };
  119166. static float _vq_quantthresh__44c7_s_p1_0[] = {
  119167. -0.5, 0.5,
  119168. };
  119169. static long _vq_quantmap__44c7_s_p1_0[] = {
  119170. 1, 0, 2,
  119171. };
  119172. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  119173. _vq_quantthresh__44c7_s_p1_0,
  119174. _vq_quantmap__44c7_s_p1_0,
  119175. 3,
  119176. 3
  119177. };
  119178. static static_codebook _44c7_s_p1_0 = {
  119179. 4, 81,
  119180. _vq_lengthlist__44c7_s_p1_0,
  119181. 1, -535822336, 1611661312, 2, 0,
  119182. _vq_quantlist__44c7_s_p1_0,
  119183. NULL,
  119184. &_vq_auxt__44c7_s_p1_0,
  119185. NULL,
  119186. 0
  119187. };
  119188. static long _vq_quantlist__44c7_s_p2_0[] = {
  119189. 2,
  119190. 1,
  119191. 3,
  119192. 0,
  119193. 4,
  119194. };
  119195. static long _vq_lengthlist__44c7_s_p2_0[] = {
  119196. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119197. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119198. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119199. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  119200. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119201. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  119202. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  119203. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119205. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119206. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  119207. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119208. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  119209. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  119210. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  119211. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  119212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119213. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  119214. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  119215. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  119216. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  119217. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  119218. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  119219. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119221. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119222. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  119223. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119224. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  119225. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  119226. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  119227. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119229. 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119232. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  119233. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119234. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  119235. 13,
  119236. };
  119237. static float _vq_quantthresh__44c7_s_p2_0[] = {
  119238. -1.5, -0.5, 0.5, 1.5,
  119239. };
  119240. static long _vq_quantmap__44c7_s_p2_0[] = {
  119241. 3, 1, 0, 2, 4,
  119242. };
  119243. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  119244. _vq_quantthresh__44c7_s_p2_0,
  119245. _vq_quantmap__44c7_s_p2_0,
  119246. 5,
  119247. 5
  119248. };
  119249. static static_codebook _44c7_s_p2_0 = {
  119250. 4, 625,
  119251. _vq_lengthlist__44c7_s_p2_0,
  119252. 1, -533725184, 1611661312, 3, 0,
  119253. _vq_quantlist__44c7_s_p2_0,
  119254. NULL,
  119255. &_vq_auxt__44c7_s_p2_0,
  119256. NULL,
  119257. 0
  119258. };
  119259. static long _vq_quantlist__44c7_s_p3_0[] = {
  119260. 4,
  119261. 3,
  119262. 5,
  119263. 2,
  119264. 6,
  119265. 1,
  119266. 7,
  119267. 0,
  119268. 8,
  119269. };
  119270. static long _vq_lengthlist__44c7_s_p3_0[] = {
  119271. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119272. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119273. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119274. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119276. 0,
  119277. };
  119278. static float _vq_quantthresh__44c7_s_p3_0[] = {
  119279. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119280. };
  119281. static long _vq_quantmap__44c7_s_p3_0[] = {
  119282. 7, 5, 3, 1, 0, 2, 4, 6,
  119283. 8,
  119284. };
  119285. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119286. _vq_quantthresh__44c7_s_p3_0,
  119287. _vq_quantmap__44c7_s_p3_0,
  119288. 9,
  119289. 9
  119290. };
  119291. static static_codebook _44c7_s_p3_0 = {
  119292. 2, 81,
  119293. _vq_lengthlist__44c7_s_p3_0,
  119294. 1, -531628032, 1611661312, 4, 0,
  119295. _vq_quantlist__44c7_s_p3_0,
  119296. NULL,
  119297. &_vq_auxt__44c7_s_p3_0,
  119298. NULL,
  119299. 0
  119300. };
  119301. static long _vq_quantlist__44c7_s_p4_0[] = {
  119302. 8,
  119303. 7,
  119304. 9,
  119305. 6,
  119306. 10,
  119307. 5,
  119308. 11,
  119309. 4,
  119310. 12,
  119311. 3,
  119312. 13,
  119313. 2,
  119314. 14,
  119315. 1,
  119316. 15,
  119317. 0,
  119318. 16,
  119319. };
  119320. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119321. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119322. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119323. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119324. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119325. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119326. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119327. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119328. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119329. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119330. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119339. 0,
  119340. };
  119341. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119342. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119343. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119344. };
  119345. static long _vq_quantmap__44c7_s_p4_0[] = {
  119346. 15, 13, 11, 9, 7, 5, 3, 1,
  119347. 0, 2, 4, 6, 8, 10, 12, 14,
  119348. 16,
  119349. };
  119350. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119351. _vq_quantthresh__44c7_s_p4_0,
  119352. _vq_quantmap__44c7_s_p4_0,
  119353. 17,
  119354. 17
  119355. };
  119356. static static_codebook _44c7_s_p4_0 = {
  119357. 2, 289,
  119358. _vq_lengthlist__44c7_s_p4_0,
  119359. 1, -529530880, 1611661312, 5, 0,
  119360. _vq_quantlist__44c7_s_p4_0,
  119361. NULL,
  119362. &_vq_auxt__44c7_s_p4_0,
  119363. NULL,
  119364. 0
  119365. };
  119366. static long _vq_quantlist__44c7_s_p5_0[] = {
  119367. 1,
  119368. 0,
  119369. 2,
  119370. };
  119371. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119372. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119373. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119374. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119375. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119376. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119377. 12,
  119378. };
  119379. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119380. -5.5, 5.5,
  119381. };
  119382. static long _vq_quantmap__44c7_s_p5_0[] = {
  119383. 1, 0, 2,
  119384. };
  119385. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119386. _vq_quantthresh__44c7_s_p5_0,
  119387. _vq_quantmap__44c7_s_p5_0,
  119388. 3,
  119389. 3
  119390. };
  119391. static static_codebook _44c7_s_p5_0 = {
  119392. 4, 81,
  119393. _vq_lengthlist__44c7_s_p5_0,
  119394. 1, -529137664, 1618345984, 2, 0,
  119395. _vq_quantlist__44c7_s_p5_0,
  119396. NULL,
  119397. &_vq_auxt__44c7_s_p5_0,
  119398. NULL,
  119399. 0
  119400. };
  119401. static long _vq_quantlist__44c7_s_p5_1[] = {
  119402. 5,
  119403. 4,
  119404. 6,
  119405. 3,
  119406. 7,
  119407. 2,
  119408. 8,
  119409. 1,
  119410. 9,
  119411. 0,
  119412. 10,
  119413. };
  119414. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119415. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119416. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119417. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119418. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119419. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119420. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119421. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119422. 11,11,11, 7, 7, 8, 8, 8, 8,
  119423. };
  119424. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119425. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119426. 3.5, 4.5,
  119427. };
  119428. static long _vq_quantmap__44c7_s_p5_1[] = {
  119429. 9, 7, 5, 3, 1, 0, 2, 4,
  119430. 6, 8, 10,
  119431. };
  119432. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119433. _vq_quantthresh__44c7_s_p5_1,
  119434. _vq_quantmap__44c7_s_p5_1,
  119435. 11,
  119436. 11
  119437. };
  119438. static static_codebook _44c7_s_p5_1 = {
  119439. 2, 121,
  119440. _vq_lengthlist__44c7_s_p5_1,
  119441. 1, -531365888, 1611661312, 4, 0,
  119442. _vq_quantlist__44c7_s_p5_1,
  119443. NULL,
  119444. &_vq_auxt__44c7_s_p5_1,
  119445. NULL,
  119446. 0
  119447. };
  119448. static long _vq_quantlist__44c7_s_p6_0[] = {
  119449. 6,
  119450. 5,
  119451. 7,
  119452. 4,
  119453. 8,
  119454. 3,
  119455. 9,
  119456. 2,
  119457. 10,
  119458. 1,
  119459. 11,
  119460. 0,
  119461. 12,
  119462. };
  119463. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119464. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119465. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119466. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119467. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119468. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119469. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119474. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119475. };
  119476. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119477. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119478. 12.5, 17.5, 22.5, 27.5,
  119479. };
  119480. static long _vq_quantmap__44c7_s_p6_0[] = {
  119481. 11, 9, 7, 5, 3, 1, 0, 2,
  119482. 4, 6, 8, 10, 12,
  119483. };
  119484. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119485. _vq_quantthresh__44c7_s_p6_0,
  119486. _vq_quantmap__44c7_s_p6_0,
  119487. 13,
  119488. 13
  119489. };
  119490. static static_codebook _44c7_s_p6_0 = {
  119491. 2, 169,
  119492. _vq_lengthlist__44c7_s_p6_0,
  119493. 1, -526516224, 1616117760, 4, 0,
  119494. _vq_quantlist__44c7_s_p6_0,
  119495. NULL,
  119496. &_vq_auxt__44c7_s_p6_0,
  119497. NULL,
  119498. 0
  119499. };
  119500. static long _vq_quantlist__44c7_s_p6_1[] = {
  119501. 2,
  119502. 1,
  119503. 3,
  119504. 0,
  119505. 4,
  119506. };
  119507. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119508. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119509. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119510. };
  119511. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119512. -1.5, -0.5, 0.5, 1.5,
  119513. };
  119514. static long _vq_quantmap__44c7_s_p6_1[] = {
  119515. 3, 1, 0, 2, 4,
  119516. };
  119517. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119518. _vq_quantthresh__44c7_s_p6_1,
  119519. _vq_quantmap__44c7_s_p6_1,
  119520. 5,
  119521. 5
  119522. };
  119523. static static_codebook _44c7_s_p6_1 = {
  119524. 2, 25,
  119525. _vq_lengthlist__44c7_s_p6_1,
  119526. 1, -533725184, 1611661312, 3, 0,
  119527. _vq_quantlist__44c7_s_p6_1,
  119528. NULL,
  119529. &_vq_auxt__44c7_s_p6_1,
  119530. NULL,
  119531. 0
  119532. };
  119533. static long _vq_quantlist__44c7_s_p7_0[] = {
  119534. 6,
  119535. 5,
  119536. 7,
  119537. 4,
  119538. 8,
  119539. 3,
  119540. 9,
  119541. 2,
  119542. 10,
  119543. 1,
  119544. 11,
  119545. 0,
  119546. 12,
  119547. };
  119548. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119549. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119550. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119551. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119552. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119553. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119554. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119555. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119556. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119557. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119558. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119559. 19,13,13,13,13,14,14,15,15,
  119560. };
  119561. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119562. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119563. 27.5, 38.5, 49.5, 60.5,
  119564. };
  119565. static long _vq_quantmap__44c7_s_p7_0[] = {
  119566. 11, 9, 7, 5, 3, 1, 0, 2,
  119567. 4, 6, 8, 10, 12,
  119568. };
  119569. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119570. _vq_quantthresh__44c7_s_p7_0,
  119571. _vq_quantmap__44c7_s_p7_0,
  119572. 13,
  119573. 13
  119574. };
  119575. static static_codebook _44c7_s_p7_0 = {
  119576. 2, 169,
  119577. _vq_lengthlist__44c7_s_p7_0,
  119578. 1, -523206656, 1618345984, 4, 0,
  119579. _vq_quantlist__44c7_s_p7_0,
  119580. NULL,
  119581. &_vq_auxt__44c7_s_p7_0,
  119582. NULL,
  119583. 0
  119584. };
  119585. static long _vq_quantlist__44c7_s_p7_1[] = {
  119586. 5,
  119587. 4,
  119588. 6,
  119589. 3,
  119590. 7,
  119591. 2,
  119592. 8,
  119593. 1,
  119594. 9,
  119595. 0,
  119596. 10,
  119597. };
  119598. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119599. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119600. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119601. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119602. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119603. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119604. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119605. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119606. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119607. };
  119608. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119609. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119610. 3.5, 4.5,
  119611. };
  119612. static long _vq_quantmap__44c7_s_p7_1[] = {
  119613. 9, 7, 5, 3, 1, 0, 2, 4,
  119614. 6, 8, 10,
  119615. };
  119616. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119617. _vq_quantthresh__44c7_s_p7_1,
  119618. _vq_quantmap__44c7_s_p7_1,
  119619. 11,
  119620. 11
  119621. };
  119622. static static_codebook _44c7_s_p7_1 = {
  119623. 2, 121,
  119624. _vq_lengthlist__44c7_s_p7_1,
  119625. 1, -531365888, 1611661312, 4, 0,
  119626. _vq_quantlist__44c7_s_p7_1,
  119627. NULL,
  119628. &_vq_auxt__44c7_s_p7_1,
  119629. NULL,
  119630. 0
  119631. };
  119632. static long _vq_quantlist__44c7_s_p8_0[] = {
  119633. 7,
  119634. 6,
  119635. 8,
  119636. 5,
  119637. 9,
  119638. 4,
  119639. 10,
  119640. 3,
  119641. 11,
  119642. 2,
  119643. 12,
  119644. 1,
  119645. 13,
  119646. 0,
  119647. 14,
  119648. };
  119649. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119650. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119651. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119652. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119653. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119654. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119655. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119656. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119657. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119658. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119659. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119660. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119661. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119662. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119663. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119664. 14,
  119665. };
  119666. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119667. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119668. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119669. };
  119670. static long _vq_quantmap__44c7_s_p8_0[] = {
  119671. 13, 11, 9, 7, 5, 3, 1, 0,
  119672. 2, 4, 6, 8, 10, 12, 14,
  119673. };
  119674. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119675. _vq_quantthresh__44c7_s_p8_0,
  119676. _vq_quantmap__44c7_s_p8_0,
  119677. 15,
  119678. 15
  119679. };
  119680. static static_codebook _44c7_s_p8_0 = {
  119681. 2, 225,
  119682. _vq_lengthlist__44c7_s_p8_0,
  119683. 1, -520986624, 1620377600, 4, 0,
  119684. _vq_quantlist__44c7_s_p8_0,
  119685. NULL,
  119686. &_vq_auxt__44c7_s_p8_0,
  119687. NULL,
  119688. 0
  119689. };
  119690. static long _vq_quantlist__44c7_s_p8_1[] = {
  119691. 10,
  119692. 9,
  119693. 11,
  119694. 8,
  119695. 12,
  119696. 7,
  119697. 13,
  119698. 6,
  119699. 14,
  119700. 5,
  119701. 15,
  119702. 4,
  119703. 16,
  119704. 3,
  119705. 17,
  119706. 2,
  119707. 18,
  119708. 1,
  119709. 19,
  119710. 0,
  119711. 20,
  119712. };
  119713. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119714. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119715. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119716. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119717. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119718. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119719. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119720. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119721. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119722. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119723. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119724. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119725. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119726. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119727. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119728. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119729. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119730. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119731. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119732. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119733. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119734. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119735. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119736. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119737. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119738. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119739. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119740. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119741. 10,10,10,10,10,10,10,10,10,
  119742. };
  119743. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119744. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119745. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119746. 6.5, 7.5, 8.5, 9.5,
  119747. };
  119748. static long _vq_quantmap__44c7_s_p8_1[] = {
  119749. 19, 17, 15, 13, 11, 9, 7, 5,
  119750. 3, 1, 0, 2, 4, 6, 8, 10,
  119751. 12, 14, 16, 18, 20,
  119752. };
  119753. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119754. _vq_quantthresh__44c7_s_p8_1,
  119755. _vq_quantmap__44c7_s_p8_1,
  119756. 21,
  119757. 21
  119758. };
  119759. static static_codebook _44c7_s_p8_1 = {
  119760. 2, 441,
  119761. _vq_lengthlist__44c7_s_p8_1,
  119762. 1, -529268736, 1611661312, 5, 0,
  119763. _vq_quantlist__44c7_s_p8_1,
  119764. NULL,
  119765. &_vq_auxt__44c7_s_p8_1,
  119766. NULL,
  119767. 0
  119768. };
  119769. static long _vq_quantlist__44c7_s_p9_0[] = {
  119770. 6,
  119771. 5,
  119772. 7,
  119773. 4,
  119774. 8,
  119775. 3,
  119776. 9,
  119777. 2,
  119778. 10,
  119779. 1,
  119780. 11,
  119781. 0,
  119782. 12,
  119783. };
  119784. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119785. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119786. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119787. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119788. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119789. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119790. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119791. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119792. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119793. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119794. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119795. 11,11,11,11,11,11,11,11,11,
  119796. };
  119797. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119798. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119799. 1592.5, 2229.5, 2866.5, 3503.5,
  119800. };
  119801. static long _vq_quantmap__44c7_s_p9_0[] = {
  119802. 11, 9, 7, 5, 3, 1, 0, 2,
  119803. 4, 6, 8, 10, 12,
  119804. };
  119805. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119806. _vq_quantthresh__44c7_s_p9_0,
  119807. _vq_quantmap__44c7_s_p9_0,
  119808. 13,
  119809. 13
  119810. };
  119811. static static_codebook _44c7_s_p9_0 = {
  119812. 2, 169,
  119813. _vq_lengthlist__44c7_s_p9_0,
  119814. 1, -511845376, 1630791680, 4, 0,
  119815. _vq_quantlist__44c7_s_p9_0,
  119816. NULL,
  119817. &_vq_auxt__44c7_s_p9_0,
  119818. NULL,
  119819. 0
  119820. };
  119821. static long _vq_quantlist__44c7_s_p9_1[] = {
  119822. 6,
  119823. 5,
  119824. 7,
  119825. 4,
  119826. 8,
  119827. 3,
  119828. 9,
  119829. 2,
  119830. 10,
  119831. 1,
  119832. 11,
  119833. 0,
  119834. 12,
  119835. };
  119836. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119837. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119838. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119839. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119840. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119841. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119842. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119843. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119844. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119845. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119846. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119847. 15,11,11,10,10,12,12,12,12,
  119848. };
  119849. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119850. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119851. 122.5, 171.5, 220.5, 269.5,
  119852. };
  119853. static long _vq_quantmap__44c7_s_p9_1[] = {
  119854. 11, 9, 7, 5, 3, 1, 0, 2,
  119855. 4, 6, 8, 10, 12,
  119856. };
  119857. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119858. _vq_quantthresh__44c7_s_p9_1,
  119859. _vq_quantmap__44c7_s_p9_1,
  119860. 13,
  119861. 13
  119862. };
  119863. static static_codebook _44c7_s_p9_1 = {
  119864. 2, 169,
  119865. _vq_lengthlist__44c7_s_p9_1,
  119866. 1, -518889472, 1622704128, 4, 0,
  119867. _vq_quantlist__44c7_s_p9_1,
  119868. NULL,
  119869. &_vq_auxt__44c7_s_p9_1,
  119870. NULL,
  119871. 0
  119872. };
  119873. static long _vq_quantlist__44c7_s_p9_2[] = {
  119874. 24,
  119875. 23,
  119876. 25,
  119877. 22,
  119878. 26,
  119879. 21,
  119880. 27,
  119881. 20,
  119882. 28,
  119883. 19,
  119884. 29,
  119885. 18,
  119886. 30,
  119887. 17,
  119888. 31,
  119889. 16,
  119890. 32,
  119891. 15,
  119892. 33,
  119893. 14,
  119894. 34,
  119895. 13,
  119896. 35,
  119897. 12,
  119898. 36,
  119899. 11,
  119900. 37,
  119901. 10,
  119902. 38,
  119903. 9,
  119904. 39,
  119905. 8,
  119906. 40,
  119907. 7,
  119908. 41,
  119909. 6,
  119910. 42,
  119911. 5,
  119912. 43,
  119913. 4,
  119914. 44,
  119915. 3,
  119916. 45,
  119917. 2,
  119918. 46,
  119919. 1,
  119920. 47,
  119921. 0,
  119922. 48,
  119923. };
  119924. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119925. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119926. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119927. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119928. 7,
  119929. };
  119930. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119931. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119932. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119933. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119934. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119935. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119936. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119937. };
  119938. static long _vq_quantmap__44c7_s_p9_2[] = {
  119939. 47, 45, 43, 41, 39, 37, 35, 33,
  119940. 31, 29, 27, 25, 23, 21, 19, 17,
  119941. 15, 13, 11, 9, 7, 5, 3, 1,
  119942. 0, 2, 4, 6, 8, 10, 12, 14,
  119943. 16, 18, 20, 22, 24, 26, 28, 30,
  119944. 32, 34, 36, 38, 40, 42, 44, 46,
  119945. 48,
  119946. };
  119947. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119948. _vq_quantthresh__44c7_s_p9_2,
  119949. _vq_quantmap__44c7_s_p9_2,
  119950. 49,
  119951. 49
  119952. };
  119953. static static_codebook _44c7_s_p9_2 = {
  119954. 1, 49,
  119955. _vq_lengthlist__44c7_s_p9_2,
  119956. 1, -526909440, 1611661312, 6, 0,
  119957. _vq_quantlist__44c7_s_p9_2,
  119958. NULL,
  119959. &_vq_auxt__44c7_s_p9_2,
  119960. NULL,
  119961. 0
  119962. };
  119963. static long _huff_lengthlist__44c7_s_short[] = {
  119964. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119965. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119966. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119967. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119968. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119969. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119970. 10, 9,11,14,
  119971. };
  119972. static static_codebook _huff_book__44c7_s_short = {
  119973. 2, 100,
  119974. _huff_lengthlist__44c7_s_short,
  119975. 0, 0, 0, 0, 0,
  119976. NULL,
  119977. NULL,
  119978. NULL,
  119979. NULL,
  119980. 0
  119981. };
  119982. static long _huff_lengthlist__44c8_s_long[] = {
  119983. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119984. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119985. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119986. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119987. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119988. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119989. 11, 9, 9,10,
  119990. };
  119991. static static_codebook _huff_book__44c8_s_long = {
  119992. 2, 100,
  119993. _huff_lengthlist__44c8_s_long,
  119994. 0, 0, 0, 0, 0,
  119995. NULL,
  119996. NULL,
  119997. NULL,
  119998. NULL,
  119999. 0
  120000. };
  120001. static long _vq_quantlist__44c8_s_p1_0[] = {
  120002. 1,
  120003. 0,
  120004. 2,
  120005. };
  120006. static long _vq_lengthlist__44c8_s_p1_0[] = {
  120007. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  120008. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120009. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  120010. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120011. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  120012. 8,
  120013. };
  120014. static float _vq_quantthresh__44c8_s_p1_0[] = {
  120015. -0.5, 0.5,
  120016. };
  120017. static long _vq_quantmap__44c8_s_p1_0[] = {
  120018. 1, 0, 2,
  120019. };
  120020. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  120021. _vq_quantthresh__44c8_s_p1_0,
  120022. _vq_quantmap__44c8_s_p1_0,
  120023. 3,
  120024. 3
  120025. };
  120026. static static_codebook _44c8_s_p1_0 = {
  120027. 4, 81,
  120028. _vq_lengthlist__44c8_s_p1_0,
  120029. 1, -535822336, 1611661312, 2, 0,
  120030. _vq_quantlist__44c8_s_p1_0,
  120031. NULL,
  120032. &_vq_auxt__44c8_s_p1_0,
  120033. NULL,
  120034. 0
  120035. };
  120036. static long _vq_quantlist__44c8_s_p2_0[] = {
  120037. 2,
  120038. 1,
  120039. 3,
  120040. 0,
  120041. 4,
  120042. };
  120043. static long _vq_lengthlist__44c8_s_p2_0[] = {
  120044. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120045. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  120046. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  120047. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  120048. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  120049. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  120050. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  120051. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  120052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120053. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  120054. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  120055. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  120056. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  120057. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  120058. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  120059. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  120060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120061. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  120062. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  120063. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  120064. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  120065. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  120066. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  120067. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120069. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  120070. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  120071. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  120072. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  120073. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  120074. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  120075. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120077. 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120080. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  120081. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  120082. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  120083. 13,
  120084. };
  120085. static float _vq_quantthresh__44c8_s_p2_0[] = {
  120086. -1.5, -0.5, 0.5, 1.5,
  120087. };
  120088. static long _vq_quantmap__44c8_s_p2_0[] = {
  120089. 3, 1, 0, 2, 4,
  120090. };
  120091. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  120092. _vq_quantthresh__44c8_s_p2_0,
  120093. _vq_quantmap__44c8_s_p2_0,
  120094. 5,
  120095. 5
  120096. };
  120097. static static_codebook _44c8_s_p2_0 = {
  120098. 4, 625,
  120099. _vq_lengthlist__44c8_s_p2_0,
  120100. 1, -533725184, 1611661312, 3, 0,
  120101. _vq_quantlist__44c8_s_p2_0,
  120102. NULL,
  120103. &_vq_auxt__44c8_s_p2_0,
  120104. NULL,
  120105. 0
  120106. };
  120107. static long _vq_quantlist__44c8_s_p3_0[] = {
  120108. 4,
  120109. 3,
  120110. 5,
  120111. 2,
  120112. 6,
  120113. 1,
  120114. 7,
  120115. 0,
  120116. 8,
  120117. };
  120118. static long _vq_lengthlist__44c8_s_p3_0[] = {
  120119. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  120120. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  120121. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  120122. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  120123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120124. 0,
  120125. };
  120126. static float _vq_quantthresh__44c8_s_p3_0[] = {
  120127. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120128. };
  120129. static long _vq_quantmap__44c8_s_p3_0[] = {
  120130. 7, 5, 3, 1, 0, 2, 4, 6,
  120131. 8,
  120132. };
  120133. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  120134. _vq_quantthresh__44c8_s_p3_0,
  120135. _vq_quantmap__44c8_s_p3_0,
  120136. 9,
  120137. 9
  120138. };
  120139. static static_codebook _44c8_s_p3_0 = {
  120140. 2, 81,
  120141. _vq_lengthlist__44c8_s_p3_0,
  120142. 1, -531628032, 1611661312, 4, 0,
  120143. _vq_quantlist__44c8_s_p3_0,
  120144. NULL,
  120145. &_vq_auxt__44c8_s_p3_0,
  120146. NULL,
  120147. 0
  120148. };
  120149. static long _vq_quantlist__44c8_s_p4_0[] = {
  120150. 8,
  120151. 7,
  120152. 9,
  120153. 6,
  120154. 10,
  120155. 5,
  120156. 11,
  120157. 4,
  120158. 12,
  120159. 3,
  120160. 13,
  120161. 2,
  120162. 14,
  120163. 1,
  120164. 15,
  120165. 0,
  120166. 16,
  120167. };
  120168. static long _vq_lengthlist__44c8_s_p4_0[] = {
  120169. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  120170. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  120171. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120172. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  120173. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  120174. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  120175. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  120176. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120177. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120178. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  120179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120187. 0,
  120188. };
  120189. static float _vq_quantthresh__44c8_s_p4_0[] = {
  120190. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120191. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120192. };
  120193. static long _vq_quantmap__44c8_s_p4_0[] = {
  120194. 15, 13, 11, 9, 7, 5, 3, 1,
  120195. 0, 2, 4, 6, 8, 10, 12, 14,
  120196. 16,
  120197. };
  120198. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  120199. _vq_quantthresh__44c8_s_p4_0,
  120200. _vq_quantmap__44c8_s_p4_0,
  120201. 17,
  120202. 17
  120203. };
  120204. static static_codebook _44c8_s_p4_0 = {
  120205. 2, 289,
  120206. _vq_lengthlist__44c8_s_p4_0,
  120207. 1, -529530880, 1611661312, 5, 0,
  120208. _vq_quantlist__44c8_s_p4_0,
  120209. NULL,
  120210. &_vq_auxt__44c8_s_p4_0,
  120211. NULL,
  120212. 0
  120213. };
  120214. static long _vq_quantlist__44c8_s_p5_0[] = {
  120215. 1,
  120216. 0,
  120217. 2,
  120218. };
  120219. static long _vq_lengthlist__44c8_s_p5_0[] = {
  120220. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  120221. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  120222. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  120223. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  120224. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  120225. 12,
  120226. };
  120227. static float _vq_quantthresh__44c8_s_p5_0[] = {
  120228. -5.5, 5.5,
  120229. };
  120230. static long _vq_quantmap__44c8_s_p5_0[] = {
  120231. 1, 0, 2,
  120232. };
  120233. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  120234. _vq_quantthresh__44c8_s_p5_0,
  120235. _vq_quantmap__44c8_s_p5_0,
  120236. 3,
  120237. 3
  120238. };
  120239. static static_codebook _44c8_s_p5_0 = {
  120240. 4, 81,
  120241. _vq_lengthlist__44c8_s_p5_0,
  120242. 1, -529137664, 1618345984, 2, 0,
  120243. _vq_quantlist__44c8_s_p5_0,
  120244. NULL,
  120245. &_vq_auxt__44c8_s_p5_0,
  120246. NULL,
  120247. 0
  120248. };
  120249. static long _vq_quantlist__44c8_s_p5_1[] = {
  120250. 5,
  120251. 4,
  120252. 6,
  120253. 3,
  120254. 7,
  120255. 2,
  120256. 8,
  120257. 1,
  120258. 9,
  120259. 0,
  120260. 10,
  120261. };
  120262. static long _vq_lengthlist__44c8_s_p5_1[] = {
  120263. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  120264. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  120265. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  120266. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  120267. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  120268. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  120269. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  120270. 11,11,11, 7, 7, 7, 7, 8, 8,
  120271. };
  120272. static float _vq_quantthresh__44c8_s_p5_1[] = {
  120273. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120274. 3.5, 4.5,
  120275. };
  120276. static long _vq_quantmap__44c8_s_p5_1[] = {
  120277. 9, 7, 5, 3, 1, 0, 2, 4,
  120278. 6, 8, 10,
  120279. };
  120280. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  120281. _vq_quantthresh__44c8_s_p5_1,
  120282. _vq_quantmap__44c8_s_p5_1,
  120283. 11,
  120284. 11
  120285. };
  120286. static static_codebook _44c8_s_p5_1 = {
  120287. 2, 121,
  120288. _vq_lengthlist__44c8_s_p5_1,
  120289. 1, -531365888, 1611661312, 4, 0,
  120290. _vq_quantlist__44c8_s_p5_1,
  120291. NULL,
  120292. &_vq_auxt__44c8_s_p5_1,
  120293. NULL,
  120294. 0
  120295. };
  120296. static long _vq_quantlist__44c8_s_p6_0[] = {
  120297. 6,
  120298. 5,
  120299. 7,
  120300. 4,
  120301. 8,
  120302. 3,
  120303. 9,
  120304. 2,
  120305. 10,
  120306. 1,
  120307. 11,
  120308. 0,
  120309. 12,
  120310. };
  120311. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120312. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120313. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120314. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120315. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120316. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120317. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120322. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120323. };
  120324. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120325. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120326. 12.5, 17.5, 22.5, 27.5,
  120327. };
  120328. static long _vq_quantmap__44c8_s_p6_0[] = {
  120329. 11, 9, 7, 5, 3, 1, 0, 2,
  120330. 4, 6, 8, 10, 12,
  120331. };
  120332. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120333. _vq_quantthresh__44c8_s_p6_0,
  120334. _vq_quantmap__44c8_s_p6_0,
  120335. 13,
  120336. 13
  120337. };
  120338. static static_codebook _44c8_s_p6_0 = {
  120339. 2, 169,
  120340. _vq_lengthlist__44c8_s_p6_0,
  120341. 1, -526516224, 1616117760, 4, 0,
  120342. _vq_quantlist__44c8_s_p6_0,
  120343. NULL,
  120344. &_vq_auxt__44c8_s_p6_0,
  120345. NULL,
  120346. 0
  120347. };
  120348. static long _vq_quantlist__44c8_s_p6_1[] = {
  120349. 2,
  120350. 1,
  120351. 3,
  120352. 0,
  120353. 4,
  120354. };
  120355. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120356. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120357. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120358. };
  120359. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120360. -1.5, -0.5, 0.5, 1.5,
  120361. };
  120362. static long _vq_quantmap__44c8_s_p6_1[] = {
  120363. 3, 1, 0, 2, 4,
  120364. };
  120365. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120366. _vq_quantthresh__44c8_s_p6_1,
  120367. _vq_quantmap__44c8_s_p6_1,
  120368. 5,
  120369. 5
  120370. };
  120371. static static_codebook _44c8_s_p6_1 = {
  120372. 2, 25,
  120373. _vq_lengthlist__44c8_s_p6_1,
  120374. 1, -533725184, 1611661312, 3, 0,
  120375. _vq_quantlist__44c8_s_p6_1,
  120376. NULL,
  120377. &_vq_auxt__44c8_s_p6_1,
  120378. NULL,
  120379. 0
  120380. };
  120381. static long _vq_quantlist__44c8_s_p7_0[] = {
  120382. 6,
  120383. 5,
  120384. 7,
  120385. 4,
  120386. 8,
  120387. 3,
  120388. 9,
  120389. 2,
  120390. 10,
  120391. 1,
  120392. 11,
  120393. 0,
  120394. 12,
  120395. };
  120396. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120397. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120398. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120399. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120400. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120401. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120402. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120403. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120404. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120405. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120406. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120407. 20,13,13,13,13,14,13,15,15,
  120408. };
  120409. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120410. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120411. 27.5, 38.5, 49.5, 60.5,
  120412. };
  120413. static long _vq_quantmap__44c8_s_p7_0[] = {
  120414. 11, 9, 7, 5, 3, 1, 0, 2,
  120415. 4, 6, 8, 10, 12,
  120416. };
  120417. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120418. _vq_quantthresh__44c8_s_p7_0,
  120419. _vq_quantmap__44c8_s_p7_0,
  120420. 13,
  120421. 13
  120422. };
  120423. static static_codebook _44c8_s_p7_0 = {
  120424. 2, 169,
  120425. _vq_lengthlist__44c8_s_p7_0,
  120426. 1, -523206656, 1618345984, 4, 0,
  120427. _vq_quantlist__44c8_s_p7_0,
  120428. NULL,
  120429. &_vq_auxt__44c8_s_p7_0,
  120430. NULL,
  120431. 0
  120432. };
  120433. static long _vq_quantlist__44c8_s_p7_1[] = {
  120434. 5,
  120435. 4,
  120436. 6,
  120437. 3,
  120438. 7,
  120439. 2,
  120440. 8,
  120441. 1,
  120442. 9,
  120443. 0,
  120444. 10,
  120445. };
  120446. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120447. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120448. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120449. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120450. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120451. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120452. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120453. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120454. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120455. };
  120456. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120457. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120458. 3.5, 4.5,
  120459. };
  120460. static long _vq_quantmap__44c8_s_p7_1[] = {
  120461. 9, 7, 5, 3, 1, 0, 2, 4,
  120462. 6, 8, 10,
  120463. };
  120464. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120465. _vq_quantthresh__44c8_s_p7_1,
  120466. _vq_quantmap__44c8_s_p7_1,
  120467. 11,
  120468. 11
  120469. };
  120470. static static_codebook _44c8_s_p7_1 = {
  120471. 2, 121,
  120472. _vq_lengthlist__44c8_s_p7_1,
  120473. 1, -531365888, 1611661312, 4, 0,
  120474. _vq_quantlist__44c8_s_p7_1,
  120475. NULL,
  120476. &_vq_auxt__44c8_s_p7_1,
  120477. NULL,
  120478. 0
  120479. };
  120480. static long _vq_quantlist__44c8_s_p8_0[] = {
  120481. 7,
  120482. 6,
  120483. 8,
  120484. 5,
  120485. 9,
  120486. 4,
  120487. 10,
  120488. 3,
  120489. 11,
  120490. 2,
  120491. 12,
  120492. 1,
  120493. 13,
  120494. 0,
  120495. 14,
  120496. };
  120497. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120498. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120499. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120500. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120501. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120502. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120503. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120504. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120505. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120506. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120507. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120508. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120509. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120510. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120511. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120512. 15,
  120513. };
  120514. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120515. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120516. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120517. };
  120518. static long _vq_quantmap__44c8_s_p8_0[] = {
  120519. 13, 11, 9, 7, 5, 3, 1, 0,
  120520. 2, 4, 6, 8, 10, 12, 14,
  120521. };
  120522. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120523. _vq_quantthresh__44c8_s_p8_0,
  120524. _vq_quantmap__44c8_s_p8_0,
  120525. 15,
  120526. 15
  120527. };
  120528. static static_codebook _44c8_s_p8_0 = {
  120529. 2, 225,
  120530. _vq_lengthlist__44c8_s_p8_0,
  120531. 1, -520986624, 1620377600, 4, 0,
  120532. _vq_quantlist__44c8_s_p8_0,
  120533. NULL,
  120534. &_vq_auxt__44c8_s_p8_0,
  120535. NULL,
  120536. 0
  120537. };
  120538. static long _vq_quantlist__44c8_s_p8_1[] = {
  120539. 10,
  120540. 9,
  120541. 11,
  120542. 8,
  120543. 12,
  120544. 7,
  120545. 13,
  120546. 6,
  120547. 14,
  120548. 5,
  120549. 15,
  120550. 4,
  120551. 16,
  120552. 3,
  120553. 17,
  120554. 2,
  120555. 18,
  120556. 1,
  120557. 19,
  120558. 0,
  120559. 20,
  120560. };
  120561. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120562. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120563. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120564. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120565. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120566. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120567. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120568. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120569. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120570. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120571. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120572. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120573. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120574. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120575. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120576. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120577. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120578. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120579. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120580. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120581. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120582. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120583. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120584. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120585. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120586. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120587. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120588. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120589. 10, 9, 9,10,10, 9,10, 9, 9,
  120590. };
  120591. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120592. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120593. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120594. 6.5, 7.5, 8.5, 9.5,
  120595. };
  120596. static long _vq_quantmap__44c8_s_p8_1[] = {
  120597. 19, 17, 15, 13, 11, 9, 7, 5,
  120598. 3, 1, 0, 2, 4, 6, 8, 10,
  120599. 12, 14, 16, 18, 20,
  120600. };
  120601. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120602. _vq_quantthresh__44c8_s_p8_1,
  120603. _vq_quantmap__44c8_s_p8_1,
  120604. 21,
  120605. 21
  120606. };
  120607. static static_codebook _44c8_s_p8_1 = {
  120608. 2, 441,
  120609. _vq_lengthlist__44c8_s_p8_1,
  120610. 1, -529268736, 1611661312, 5, 0,
  120611. _vq_quantlist__44c8_s_p8_1,
  120612. NULL,
  120613. &_vq_auxt__44c8_s_p8_1,
  120614. NULL,
  120615. 0
  120616. };
  120617. static long _vq_quantlist__44c8_s_p9_0[] = {
  120618. 8,
  120619. 7,
  120620. 9,
  120621. 6,
  120622. 10,
  120623. 5,
  120624. 11,
  120625. 4,
  120626. 12,
  120627. 3,
  120628. 13,
  120629. 2,
  120630. 14,
  120631. 1,
  120632. 15,
  120633. 0,
  120634. 16,
  120635. };
  120636. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120637. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120638. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120639. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120640. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120641. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120642. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120643. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120644. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120645. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120646. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120647. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120648. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120649. 11,11,11,11,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,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120652. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120653. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120654. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120655. 10,
  120656. };
  120657. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120658. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120659. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120660. };
  120661. static long _vq_quantmap__44c8_s_p9_0[] = {
  120662. 15, 13, 11, 9, 7, 5, 3, 1,
  120663. 0, 2, 4, 6, 8, 10, 12, 14,
  120664. 16,
  120665. };
  120666. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120667. _vq_quantthresh__44c8_s_p9_0,
  120668. _vq_quantmap__44c8_s_p9_0,
  120669. 17,
  120670. 17
  120671. };
  120672. static static_codebook _44c8_s_p9_0 = {
  120673. 2, 289,
  120674. _vq_lengthlist__44c8_s_p9_0,
  120675. 1, -509798400, 1631393792, 5, 0,
  120676. _vq_quantlist__44c8_s_p9_0,
  120677. NULL,
  120678. &_vq_auxt__44c8_s_p9_0,
  120679. NULL,
  120680. 0
  120681. };
  120682. static long _vq_quantlist__44c8_s_p9_1[] = {
  120683. 9,
  120684. 8,
  120685. 10,
  120686. 7,
  120687. 11,
  120688. 6,
  120689. 12,
  120690. 5,
  120691. 13,
  120692. 4,
  120693. 14,
  120694. 3,
  120695. 15,
  120696. 2,
  120697. 16,
  120698. 1,
  120699. 17,
  120700. 0,
  120701. 18,
  120702. };
  120703. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120704. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120705. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120706. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120707. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120708. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120709. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120710. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120711. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120712. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120713. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120714. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120715. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120716. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120717. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120718. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120719. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120720. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120721. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120722. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120723. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120724. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120725. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120726. 14,13,13,14,14,15,14,15,14,
  120727. };
  120728. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120729. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120730. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120731. 367.5, 416.5,
  120732. };
  120733. static long _vq_quantmap__44c8_s_p9_1[] = {
  120734. 17, 15, 13, 11, 9, 7, 5, 3,
  120735. 1, 0, 2, 4, 6, 8, 10, 12,
  120736. 14, 16, 18,
  120737. };
  120738. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120739. _vq_quantthresh__44c8_s_p9_1,
  120740. _vq_quantmap__44c8_s_p9_1,
  120741. 19,
  120742. 19
  120743. };
  120744. static static_codebook _44c8_s_p9_1 = {
  120745. 2, 361,
  120746. _vq_lengthlist__44c8_s_p9_1,
  120747. 1, -518287360, 1622704128, 5, 0,
  120748. _vq_quantlist__44c8_s_p9_1,
  120749. NULL,
  120750. &_vq_auxt__44c8_s_p9_1,
  120751. NULL,
  120752. 0
  120753. };
  120754. static long _vq_quantlist__44c8_s_p9_2[] = {
  120755. 24,
  120756. 23,
  120757. 25,
  120758. 22,
  120759. 26,
  120760. 21,
  120761. 27,
  120762. 20,
  120763. 28,
  120764. 19,
  120765. 29,
  120766. 18,
  120767. 30,
  120768. 17,
  120769. 31,
  120770. 16,
  120771. 32,
  120772. 15,
  120773. 33,
  120774. 14,
  120775. 34,
  120776. 13,
  120777. 35,
  120778. 12,
  120779. 36,
  120780. 11,
  120781. 37,
  120782. 10,
  120783. 38,
  120784. 9,
  120785. 39,
  120786. 8,
  120787. 40,
  120788. 7,
  120789. 41,
  120790. 6,
  120791. 42,
  120792. 5,
  120793. 43,
  120794. 4,
  120795. 44,
  120796. 3,
  120797. 45,
  120798. 2,
  120799. 46,
  120800. 1,
  120801. 47,
  120802. 0,
  120803. 48,
  120804. };
  120805. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120806. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120807. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120808. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120809. 7,
  120810. };
  120811. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120812. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120813. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120814. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120815. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120816. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120817. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120818. };
  120819. static long _vq_quantmap__44c8_s_p9_2[] = {
  120820. 47, 45, 43, 41, 39, 37, 35, 33,
  120821. 31, 29, 27, 25, 23, 21, 19, 17,
  120822. 15, 13, 11, 9, 7, 5, 3, 1,
  120823. 0, 2, 4, 6, 8, 10, 12, 14,
  120824. 16, 18, 20, 22, 24, 26, 28, 30,
  120825. 32, 34, 36, 38, 40, 42, 44, 46,
  120826. 48,
  120827. };
  120828. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120829. _vq_quantthresh__44c8_s_p9_2,
  120830. _vq_quantmap__44c8_s_p9_2,
  120831. 49,
  120832. 49
  120833. };
  120834. static static_codebook _44c8_s_p9_2 = {
  120835. 1, 49,
  120836. _vq_lengthlist__44c8_s_p9_2,
  120837. 1, -526909440, 1611661312, 6, 0,
  120838. _vq_quantlist__44c8_s_p9_2,
  120839. NULL,
  120840. &_vq_auxt__44c8_s_p9_2,
  120841. NULL,
  120842. 0
  120843. };
  120844. static long _huff_lengthlist__44c8_s_short[] = {
  120845. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120846. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120847. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120848. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120849. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120850. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120851. 10, 9,11,14,
  120852. };
  120853. static static_codebook _huff_book__44c8_s_short = {
  120854. 2, 100,
  120855. _huff_lengthlist__44c8_s_short,
  120856. 0, 0, 0, 0, 0,
  120857. NULL,
  120858. NULL,
  120859. NULL,
  120860. NULL,
  120861. 0
  120862. };
  120863. static long _huff_lengthlist__44c9_s_long[] = {
  120864. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120865. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120866. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120867. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120868. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120869. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120870. 10, 9, 8, 9,
  120871. };
  120872. static static_codebook _huff_book__44c9_s_long = {
  120873. 2, 100,
  120874. _huff_lengthlist__44c9_s_long,
  120875. 0, 0, 0, 0, 0,
  120876. NULL,
  120877. NULL,
  120878. NULL,
  120879. NULL,
  120880. 0
  120881. };
  120882. static long _vq_quantlist__44c9_s_p1_0[] = {
  120883. 1,
  120884. 0,
  120885. 2,
  120886. };
  120887. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120888. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120889. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120890. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120891. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120892. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120893. 7,
  120894. };
  120895. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120896. -0.5, 0.5,
  120897. };
  120898. static long _vq_quantmap__44c9_s_p1_0[] = {
  120899. 1, 0, 2,
  120900. };
  120901. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120902. _vq_quantthresh__44c9_s_p1_0,
  120903. _vq_quantmap__44c9_s_p1_0,
  120904. 3,
  120905. 3
  120906. };
  120907. static static_codebook _44c9_s_p1_0 = {
  120908. 4, 81,
  120909. _vq_lengthlist__44c9_s_p1_0,
  120910. 1, -535822336, 1611661312, 2, 0,
  120911. _vq_quantlist__44c9_s_p1_0,
  120912. NULL,
  120913. &_vq_auxt__44c9_s_p1_0,
  120914. NULL,
  120915. 0
  120916. };
  120917. static long _vq_quantlist__44c9_s_p2_0[] = {
  120918. 2,
  120919. 1,
  120920. 3,
  120921. 0,
  120922. 4,
  120923. };
  120924. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120925. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120926. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120927. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120928. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120929. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120930. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120931. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120932. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120934. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120935. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120936. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120937. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120938. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120939. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120940. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120942. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120943. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120944. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120945. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120946. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120947. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120948. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120950. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120951. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120952. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120953. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120954. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120955. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120956. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120958. 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120961. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120962. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120963. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120964. 12,
  120965. };
  120966. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120967. -1.5, -0.5, 0.5, 1.5,
  120968. };
  120969. static long _vq_quantmap__44c9_s_p2_0[] = {
  120970. 3, 1, 0, 2, 4,
  120971. };
  120972. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120973. _vq_quantthresh__44c9_s_p2_0,
  120974. _vq_quantmap__44c9_s_p2_0,
  120975. 5,
  120976. 5
  120977. };
  120978. static static_codebook _44c9_s_p2_0 = {
  120979. 4, 625,
  120980. _vq_lengthlist__44c9_s_p2_0,
  120981. 1, -533725184, 1611661312, 3, 0,
  120982. _vq_quantlist__44c9_s_p2_0,
  120983. NULL,
  120984. &_vq_auxt__44c9_s_p2_0,
  120985. NULL,
  120986. 0
  120987. };
  120988. static long _vq_quantlist__44c9_s_p3_0[] = {
  120989. 4,
  120990. 3,
  120991. 5,
  120992. 2,
  120993. 6,
  120994. 1,
  120995. 7,
  120996. 0,
  120997. 8,
  120998. };
  120999. static long _vq_lengthlist__44c9_s_p3_0[] = {
  121000. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  121001. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  121002. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  121003. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  121004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121005. 0,
  121006. };
  121007. static float _vq_quantthresh__44c9_s_p3_0[] = {
  121008. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121009. };
  121010. static long _vq_quantmap__44c9_s_p3_0[] = {
  121011. 7, 5, 3, 1, 0, 2, 4, 6,
  121012. 8,
  121013. };
  121014. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  121015. _vq_quantthresh__44c9_s_p3_0,
  121016. _vq_quantmap__44c9_s_p3_0,
  121017. 9,
  121018. 9
  121019. };
  121020. static static_codebook _44c9_s_p3_0 = {
  121021. 2, 81,
  121022. _vq_lengthlist__44c9_s_p3_0,
  121023. 1, -531628032, 1611661312, 4, 0,
  121024. _vq_quantlist__44c9_s_p3_0,
  121025. NULL,
  121026. &_vq_auxt__44c9_s_p3_0,
  121027. NULL,
  121028. 0
  121029. };
  121030. static long _vq_quantlist__44c9_s_p4_0[] = {
  121031. 8,
  121032. 7,
  121033. 9,
  121034. 6,
  121035. 10,
  121036. 5,
  121037. 11,
  121038. 4,
  121039. 12,
  121040. 3,
  121041. 13,
  121042. 2,
  121043. 14,
  121044. 1,
  121045. 15,
  121046. 0,
  121047. 16,
  121048. };
  121049. static long _vq_lengthlist__44c9_s_p4_0[] = {
  121050. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  121051. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  121052. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  121053. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  121054. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  121055. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  121056. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  121057. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  121058. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  121059. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  121060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121068. 0,
  121069. };
  121070. static float _vq_quantthresh__44c9_s_p4_0[] = {
  121071. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121072. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121073. };
  121074. static long _vq_quantmap__44c9_s_p4_0[] = {
  121075. 15, 13, 11, 9, 7, 5, 3, 1,
  121076. 0, 2, 4, 6, 8, 10, 12, 14,
  121077. 16,
  121078. };
  121079. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  121080. _vq_quantthresh__44c9_s_p4_0,
  121081. _vq_quantmap__44c9_s_p4_0,
  121082. 17,
  121083. 17
  121084. };
  121085. static static_codebook _44c9_s_p4_0 = {
  121086. 2, 289,
  121087. _vq_lengthlist__44c9_s_p4_0,
  121088. 1, -529530880, 1611661312, 5, 0,
  121089. _vq_quantlist__44c9_s_p4_0,
  121090. NULL,
  121091. &_vq_auxt__44c9_s_p4_0,
  121092. NULL,
  121093. 0
  121094. };
  121095. static long _vq_quantlist__44c9_s_p5_0[] = {
  121096. 1,
  121097. 0,
  121098. 2,
  121099. };
  121100. static long _vq_lengthlist__44c9_s_p5_0[] = {
  121101. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  121102. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  121103. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  121104. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  121105. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  121106. 12,
  121107. };
  121108. static float _vq_quantthresh__44c9_s_p5_0[] = {
  121109. -5.5, 5.5,
  121110. };
  121111. static long _vq_quantmap__44c9_s_p5_0[] = {
  121112. 1, 0, 2,
  121113. };
  121114. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  121115. _vq_quantthresh__44c9_s_p5_0,
  121116. _vq_quantmap__44c9_s_p5_0,
  121117. 3,
  121118. 3
  121119. };
  121120. static static_codebook _44c9_s_p5_0 = {
  121121. 4, 81,
  121122. _vq_lengthlist__44c9_s_p5_0,
  121123. 1, -529137664, 1618345984, 2, 0,
  121124. _vq_quantlist__44c9_s_p5_0,
  121125. NULL,
  121126. &_vq_auxt__44c9_s_p5_0,
  121127. NULL,
  121128. 0
  121129. };
  121130. static long _vq_quantlist__44c9_s_p5_1[] = {
  121131. 5,
  121132. 4,
  121133. 6,
  121134. 3,
  121135. 7,
  121136. 2,
  121137. 8,
  121138. 1,
  121139. 9,
  121140. 0,
  121141. 10,
  121142. };
  121143. static long _vq_lengthlist__44c9_s_p5_1[] = {
  121144. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  121145. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  121146. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  121147. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  121148. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  121149. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  121150. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  121151. 11,11,11, 7, 7, 7, 7, 7, 7,
  121152. };
  121153. static float _vq_quantthresh__44c9_s_p5_1[] = {
  121154. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121155. 3.5, 4.5,
  121156. };
  121157. static long _vq_quantmap__44c9_s_p5_1[] = {
  121158. 9, 7, 5, 3, 1, 0, 2, 4,
  121159. 6, 8, 10,
  121160. };
  121161. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  121162. _vq_quantthresh__44c9_s_p5_1,
  121163. _vq_quantmap__44c9_s_p5_1,
  121164. 11,
  121165. 11
  121166. };
  121167. static static_codebook _44c9_s_p5_1 = {
  121168. 2, 121,
  121169. _vq_lengthlist__44c9_s_p5_1,
  121170. 1, -531365888, 1611661312, 4, 0,
  121171. _vq_quantlist__44c9_s_p5_1,
  121172. NULL,
  121173. &_vq_auxt__44c9_s_p5_1,
  121174. NULL,
  121175. 0
  121176. };
  121177. static long _vq_quantlist__44c9_s_p6_0[] = {
  121178. 6,
  121179. 5,
  121180. 7,
  121181. 4,
  121182. 8,
  121183. 3,
  121184. 9,
  121185. 2,
  121186. 10,
  121187. 1,
  121188. 11,
  121189. 0,
  121190. 12,
  121191. };
  121192. static long _vq_lengthlist__44c9_s_p6_0[] = {
  121193. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  121194. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  121195. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  121196. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  121197. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  121198. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  121199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121203. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121204. };
  121205. static float _vq_quantthresh__44c9_s_p6_0[] = {
  121206. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  121207. 12.5, 17.5, 22.5, 27.5,
  121208. };
  121209. static long _vq_quantmap__44c9_s_p6_0[] = {
  121210. 11, 9, 7, 5, 3, 1, 0, 2,
  121211. 4, 6, 8, 10, 12,
  121212. };
  121213. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  121214. _vq_quantthresh__44c9_s_p6_0,
  121215. _vq_quantmap__44c9_s_p6_0,
  121216. 13,
  121217. 13
  121218. };
  121219. static static_codebook _44c9_s_p6_0 = {
  121220. 2, 169,
  121221. _vq_lengthlist__44c9_s_p6_0,
  121222. 1, -526516224, 1616117760, 4, 0,
  121223. _vq_quantlist__44c9_s_p6_0,
  121224. NULL,
  121225. &_vq_auxt__44c9_s_p6_0,
  121226. NULL,
  121227. 0
  121228. };
  121229. static long _vq_quantlist__44c9_s_p6_1[] = {
  121230. 2,
  121231. 1,
  121232. 3,
  121233. 0,
  121234. 4,
  121235. };
  121236. static long _vq_lengthlist__44c9_s_p6_1[] = {
  121237. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  121238. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  121239. };
  121240. static float _vq_quantthresh__44c9_s_p6_1[] = {
  121241. -1.5, -0.5, 0.5, 1.5,
  121242. };
  121243. static long _vq_quantmap__44c9_s_p6_1[] = {
  121244. 3, 1, 0, 2, 4,
  121245. };
  121246. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  121247. _vq_quantthresh__44c9_s_p6_1,
  121248. _vq_quantmap__44c9_s_p6_1,
  121249. 5,
  121250. 5
  121251. };
  121252. static static_codebook _44c9_s_p6_1 = {
  121253. 2, 25,
  121254. _vq_lengthlist__44c9_s_p6_1,
  121255. 1, -533725184, 1611661312, 3, 0,
  121256. _vq_quantlist__44c9_s_p6_1,
  121257. NULL,
  121258. &_vq_auxt__44c9_s_p6_1,
  121259. NULL,
  121260. 0
  121261. };
  121262. static long _vq_quantlist__44c9_s_p7_0[] = {
  121263. 6,
  121264. 5,
  121265. 7,
  121266. 4,
  121267. 8,
  121268. 3,
  121269. 9,
  121270. 2,
  121271. 10,
  121272. 1,
  121273. 11,
  121274. 0,
  121275. 12,
  121276. };
  121277. static long _vq_lengthlist__44c9_s_p7_0[] = {
  121278. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  121279. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  121280. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  121281. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  121282. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  121283. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  121284. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121285. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121286. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121287. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121288. 19,12,12,12,12,13,13,14,14,
  121289. };
  121290. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121291. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121292. 27.5, 38.5, 49.5, 60.5,
  121293. };
  121294. static long _vq_quantmap__44c9_s_p7_0[] = {
  121295. 11, 9, 7, 5, 3, 1, 0, 2,
  121296. 4, 6, 8, 10, 12,
  121297. };
  121298. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121299. _vq_quantthresh__44c9_s_p7_0,
  121300. _vq_quantmap__44c9_s_p7_0,
  121301. 13,
  121302. 13
  121303. };
  121304. static static_codebook _44c9_s_p7_0 = {
  121305. 2, 169,
  121306. _vq_lengthlist__44c9_s_p7_0,
  121307. 1, -523206656, 1618345984, 4, 0,
  121308. _vq_quantlist__44c9_s_p7_0,
  121309. NULL,
  121310. &_vq_auxt__44c9_s_p7_0,
  121311. NULL,
  121312. 0
  121313. };
  121314. static long _vq_quantlist__44c9_s_p7_1[] = {
  121315. 5,
  121316. 4,
  121317. 6,
  121318. 3,
  121319. 7,
  121320. 2,
  121321. 8,
  121322. 1,
  121323. 9,
  121324. 0,
  121325. 10,
  121326. };
  121327. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121328. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121329. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121330. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121331. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121332. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121333. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121334. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121335. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121336. };
  121337. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121338. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121339. 3.5, 4.5,
  121340. };
  121341. static long _vq_quantmap__44c9_s_p7_1[] = {
  121342. 9, 7, 5, 3, 1, 0, 2, 4,
  121343. 6, 8, 10,
  121344. };
  121345. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121346. _vq_quantthresh__44c9_s_p7_1,
  121347. _vq_quantmap__44c9_s_p7_1,
  121348. 11,
  121349. 11
  121350. };
  121351. static static_codebook _44c9_s_p7_1 = {
  121352. 2, 121,
  121353. _vq_lengthlist__44c9_s_p7_1,
  121354. 1, -531365888, 1611661312, 4, 0,
  121355. _vq_quantlist__44c9_s_p7_1,
  121356. NULL,
  121357. &_vq_auxt__44c9_s_p7_1,
  121358. NULL,
  121359. 0
  121360. };
  121361. static long _vq_quantlist__44c9_s_p8_0[] = {
  121362. 7,
  121363. 6,
  121364. 8,
  121365. 5,
  121366. 9,
  121367. 4,
  121368. 10,
  121369. 3,
  121370. 11,
  121371. 2,
  121372. 12,
  121373. 1,
  121374. 13,
  121375. 0,
  121376. 14,
  121377. };
  121378. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121379. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121380. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121381. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121382. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121383. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121384. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121385. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121386. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121387. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121388. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121389. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121390. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121391. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121392. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121393. 14,
  121394. };
  121395. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121396. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121397. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121398. };
  121399. static long _vq_quantmap__44c9_s_p8_0[] = {
  121400. 13, 11, 9, 7, 5, 3, 1, 0,
  121401. 2, 4, 6, 8, 10, 12, 14,
  121402. };
  121403. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121404. _vq_quantthresh__44c9_s_p8_0,
  121405. _vq_quantmap__44c9_s_p8_0,
  121406. 15,
  121407. 15
  121408. };
  121409. static static_codebook _44c9_s_p8_0 = {
  121410. 2, 225,
  121411. _vq_lengthlist__44c9_s_p8_0,
  121412. 1, -520986624, 1620377600, 4, 0,
  121413. _vq_quantlist__44c9_s_p8_0,
  121414. NULL,
  121415. &_vq_auxt__44c9_s_p8_0,
  121416. NULL,
  121417. 0
  121418. };
  121419. static long _vq_quantlist__44c9_s_p8_1[] = {
  121420. 10,
  121421. 9,
  121422. 11,
  121423. 8,
  121424. 12,
  121425. 7,
  121426. 13,
  121427. 6,
  121428. 14,
  121429. 5,
  121430. 15,
  121431. 4,
  121432. 16,
  121433. 3,
  121434. 17,
  121435. 2,
  121436. 18,
  121437. 1,
  121438. 19,
  121439. 0,
  121440. 20,
  121441. };
  121442. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121443. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121444. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121445. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121446. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121447. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121448. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121449. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121450. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121451. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121452. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121453. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121454. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121455. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121456. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121457. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121458. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121459. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121460. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121461. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121462. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121463. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121464. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121465. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121466. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121467. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121468. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121469. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121470. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121471. };
  121472. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121473. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121474. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121475. 6.5, 7.5, 8.5, 9.5,
  121476. };
  121477. static long _vq_quantmap__44c9_s_p8_1[] = {
  121478. 19, 17, 15, 13, 11, 9, 7, 5,
  121479. 3, 1, 0, 2, 4, 6, 8, 10,
  121480. 12, 14, 16, 18, 20,
  121481. };
  121482. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121483. _vq_quantthresh__44c9_s_p8_1,
  121484. _vq_quantmap__44c9_s_p8_1,
  121485. 21,
  121486. 21
  121487. };
  121488. static static_codebook _44c9_s_p8_1 = {
  121489. 2, 441,
  121490. _vq_lengthlist__44c9_s_p8_1,
  121491. 1, -529268736, 1611661312, 5, 0,
  121492. _vq_quantlist__44c9_s_p8_1,
  121493. NULL,
  121494. &_vq_auxt__44c9_s_p8_1,
  121495. NULL,
  121496. 0
  121497. };
  121498. static long _vq_quantlist__44c9_s_p9_0[] = {
  121499. 9,
  121500. 8,
  121501. 10,
  121502. 7,
  121503. 11,
  121504. 6,
  121505. 12,
  121506. 5,
  121507. 13,
  121508. 4,
  121509. 14,
  121510. 3,
  121511. 15,
  121512. 2,
  121513. 16,
  121514. 1,
  121515. 17,
  121516. 0,
  121517. 18,
  121518. };
  121519. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121520. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121521. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121522. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121523. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121524. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121525. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121526. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121527. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121528. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121529. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121530. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121531. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121532. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121533. 12,12,12,12,12,12,12,12,12,12,12,12,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,11,11,11,11,11,11,
  121537. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121538. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121539. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121540. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121541. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121542. 11,11,11,11,11,11,11,11,11,
  121543. };
  121544. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121545. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121546. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121547. 6982.5, 7913.5,
  121548. };
  121549. static long _vq_quantmap__44c9_s_p9_0[] = {
  121550. 17, 15, 13, 11, 9, 7, 5, 3,
  121551. 1, 0, 2, 4, 6, 8, 10, 12,
  121552. 14, 16, 18,
  121553. };
  121554. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121555. _vq_quantthresh__44c9_s_p9_0,
  121556. _vq_quantmap__44c9_s_p9_0,
  121557. 19,
  121558. 19
  121559. };
  121560. static static_codebook _44c9_s_p9_0 = {
  121561. 2, 361,
  121562. _vq_lengthlist__44c9_s_p9_0,
  121563. 1, -508535424, 1631393792, 5, 0,
  121564. _vq_quantlist__44c9_s_p9_0,
  121565. NULL,
  121566. &_vq_auxt__44c9_s_p9_0,
  121567. NULL,
  121568. 0
  121569. };
  121570. static long _vq_quantlist__44c9_s_p9_1[] = {
  121571. 9,
  121572. 8,
  121573. 10,
  121574. 7,
  121575. 11,
  121576. 6,
  121577. 12,
  121578. 5,
  121579. 13,
  121580. 4,
  121581. 14,
  121582. 3,
  121583. 15,
  121584. 2,
  121585. 16,
  121586. 1,
  121587. 17,
  121588. 0,
  121589. 18,
  121590. };
  121591. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121592. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121593. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121594. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121595. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121596. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121597. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121598. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121599. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121600. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121601. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121602. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121603. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121604. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121605. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121606. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121607. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121608. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121609. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121610. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121611. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121612. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121613. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121614. 13,13,13,14,13,14,15,15,15,
  121615. };
  121616. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121617. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121618. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121619. 367.5, 416.5,
  121620. };
  121621. static long _vq_quantmap__44c9_s_p9_1[] = {
  121622. 17, 15, 13, 11, 9, 7, 5, 3,
  121623. 1, 0, 2, 4, 6, 8, 10, 12,
  121624. 14, 16, 18,
  121625. };
  121626. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121627. _vq_quantthresh__44c9_s_p9_1,
  121628. _vq_quantmap__44c9_s_p9_1,
  121629. 19,
  121630. 19
  121631. };
  121632. static static_codebook _44c9_s_p9_1 = {
  121633. 2, 361,
  121634. _vq_lengthlist__44c9_s_p9_1,
  121635. 1, -518287360, 1622704128, 5, 0,
  121636. _vq_quantlist__44c9_s_p9_1,
  121637. NULL,
  121638. &_vq_auxt__44c9_s_p9_1,
  121639. NULL,
  121640. 0
  121641. };
  121642. static long _vq_quantlist__44c9_s_p9_2[] = {
  121643. 24,
  121644. 23,
  121645. 25,
  121646. 22,
  121647. 26,
  121648. 21,
  121649. 27,
  121650. 20,
  121651. 28,
  121652. 19,
  121653. 29,
  121654. 18,
  121655. 30,
  121656. 17,
  121657. 31,
  121658. 16,
  121659. 32,
  121660. 15,
  121661. 33,
  121662. 14,
  121663. 34,
  121664. 13,
  121665. 35,
  121666. 12,
  121667. 36,
  121668. 11,
  121669. 37,
  121670. 10,
  121671. 38,
  121672. 9,
  121673. 39,
  121674. 8,
  121675. 40,
  121676. 7,
  121677. 41,
  121678. 6,
  121679. 42,
  121680. 5,
  121681. 43,
  121682. 4,
  121683. 44,
  121684. 3,
  121685. 45,
  121686. 2,
  121687. 46,
  121688. 1,
  121689. 47,
  121690. 0,
  121691. 48,
  121692. };
  121693. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121694. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121695. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121696. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121697. 7,
  121698. };
  121699. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121700. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121701. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121702. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121703. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121704. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121705. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121706. };
  121707. static long _vq_quantmap__44c9_s_p9_2[] = {
  121708. 47, 45, 43, 41, 39, 37, 35, 33,
  121709. 31, 29, 27, 25, 23, 21, 19, 17,
  121710. 15, 13, 11, 9, 7, 5, 3, 1,
  121711. 0, 2, 4, 6, 8, 10, 12, 14,
  121712. 16, 18, 20, 22, 24, 26, 28, 30,
  121713. 32, 34, 36, 38, 40, 42, 44, 46,
  121714. 48,
  121715. };
  121716. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121717. _vq_quantthresh__44c9_s_p9_2,
  121718. _vq_quantmap__44c9_s_p9_2,
  121719. 49,
  121720. 49
  121721. };
  121722. static static_codebook _44c9_s_p9_2 = {
  121723. 1, 49,
  121724. _vq_lengthlist__44c9_s_p9_2,
  121725. 1, -526909440, 1611661312, 6, 0,
  121726. _vq_quantlist__44c9_s_p9_2,
  121727. NULL,
  121728. &_vq_auxt__44c9_s_p9_2,
  121729. NULL,
  121730. 0
  121731. };
  121732. static long _huff_lengthlist__44c9_s_short[] = {
  121733. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121734. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121735. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121736. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121737. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121738. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121739. 9, 8,10,13,
  121740. };
  121741. static static_codebook _huff_book__44c9_s_short = {
  121742. 2, 100,
  121743. _huff_lengthlist__44c9_s_short,
  121744. 0, 0, 0, 0, 0,
  121745. NULL,
  121746. NULL,
  121747. NULL,
  121748. NULL,
  121749. 0
  121750. };
  121751. static long _huff_lengthlist__44c0_s_long[] = {
  121752. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121753. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121754. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121755. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121756. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121757. 12,
  121758. };
  121759. static static_codebook _huff_book__44c0_s_long = {
  121760. 2, 81,
  121761. _huff_lengthlist__44c0_s_long,
  121762. 0, 0, 0, 0, 0,
  121763. NULL,
  121764. NULL,
  121765. NULL,
  121766. NULL,
  121767. 0
  121768. };
  121769. static long _vq_quantlist__44c0_s_p1_0[] = {
  121770. 1,
  121771. 0,
  121772. 2,
  121773. };
  121774. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121775. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121776. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121780. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121781. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121785. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121786. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121817. 0, 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, 5, 7, 7, 0, 0, 0, 0,
  121821. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  121826. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 7, 9, 9, 0, 0,
  121831. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 0, 0, 0, 0, 0, 0,
  121836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  121841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121867. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121872. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  121873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121876. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121877. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  121878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121888. 0, 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,
  122186. };
  122187. static float _vq_quantthresh__44c0_s_p1_0[] = {
  122188. -0.5, 0.5,
  122189. };
  122190. static long _vq_quantmap__44c0_s_p1_0[] = {
  122191. 1, 0, 2,
  122192. };
  122193. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  122194. _vq_quantthresh__44c0_s_p1_0,
  122195. _vq_quantmap__44c0_s_p1_0,
  122196. 3,
  122197. 3
  122198. };
  122199. static static_codebook _44c0_s_p1_0 = {
  122200. 8, 6561,
  122201. _vq_lengthlist__44c0_s_p1_0,
  122202. 1, -535822336, 1611661312, 2, 0,
  122203. _vq_quantlist__44c0_s_p1_0,
  122204. NULL,
  122205. &_vq_auxt__44c0_s_p1_0,
  122206. NULL,
  122207. 0
  122208. };
  122209. static long _vq_quantlist__44c0_s_p2_0[] = {
  122210. 2,
  122211. 1,
  122212. 3,
  122213. 0,
  122214. 4,
  122215. };
  122216. static long _vq_lengthlist__44c0_s_p2_0[] = {
  122217. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  122219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122220. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122223. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  122257. };
  122258. static float _vq_quantthresh__44c0_s_p2_0[] = {
  122259. -1.5, -0.5, 0.5, 1.5,
  122260. };
  122261. static long _vq_quantmap__44c0_s_p2_0[] = {
  122262. 3, 1, 0, 2, 4,
  122263. };
  122264. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  122265. _vq_quantthresh__44c0_s_p2_0,
  122266. _vq_quantmap__44c0_s_p2_0,
  122267. 5,
  122268. 5
  122269. };
  122270. static static_codebook _44c0_s_p2_0 = {
  122271. 4, 625,
  122272. _vq_lengthlist__44c0_s_p2_0,
  122273. 1, -533725184, 1611661312, 3, 0,
  122274. _vq_quantlist__44c0_s_p2_0,
  122275. NULL,
  122276. &_vq_auxt__44c0_s_p2_0,
  122277. NULL,
  122278. 0
  122279. };
  122280. static long _vq_quantlist__44c0_s_p3_0[] = {
  122281. 4,
  122282. 3,
  122283. 5,
  122284. 2,
  122285. 6,
  122286. 1,
  122287. 7,
  122288. 0,
  122289. 8,
  122290. };
  122291. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122292. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122293. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122294. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122295. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122296. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122297. 0,
  122298. };
  122299. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122300. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122301. };
  122302. static long _vq_quantmap__44c0_s_p3_0[] = {
  122303. 7, 5, 3, 1, 0, 2, 4, 6,
  122304. 8,
  122305. };
  122306. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122307. _vq_quantthresh__44c0_s_p3_0,
  122308. _vq_quantmap__44c0_s_p3_0,
  122309. 9,
  122310. 9
  122311. };
  122312. static static_codebook _44c0_s_p3_0 = {
  122313. 2, 81,
  122314. _vq_lengthlist__44c0_s_p3_0,
  122315. 1, -531628032, 1611661312, 4, 0,
  122316. _vq_quantlist__44c0_s_p3_0,
  122317. NULL,
  122318. &_vq_auxt__44c0_s_p3_0,
  122319. NULL,
  122320. 0
  122321. };
  122322. static long _vq_quantlist__44c0_s_p4_0[] = {
  122323. 4,
  122324. 3,
  122325. 5,
  122326. 2,
  122327. 6,
  122328. 1,
  122329. 7,
  122330. 0,
  122331. 8,
  122332. };
  122333. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122334. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122335. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122336. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122337. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122338. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122339. 10,
  122340. };
  122341. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122342. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122343. };
  122344. static long _vq_quantmap__44c0_s_p4_0[] = {
  122345. 7, 5, 3, 1, 0, 2, 4, 6,
  122346. 8,
  122347. };
  122348. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122349. _vq_quantthresh__44c0_s_p4_0,
  122350. _vq_quantmap__44c0_s_p4_0,
  122351. 9,
  122352. 9
  122353. };
  122354. static static_codebook _44c0_s_p4_0 = {
  122355. 2, 81,
  122356. _vq_lengthlist__44c0_s_p4_0,
  122357. 1, -531628032, 1611661312, 4, 0,
  122358. _vq_quantlist__44c0_s_p4_0,
  122359. NULL,
  122360. &_vq_auxt__44c0_s_p4_0,
  122361. NULL,
  122362. 0
  122363. };
  122364. static long _vq_quantlist__44c0_s_p5_0[] = {
  122365. 8,
  122366. 7,
  122367. 9,
  122368. 6,
  122369. 10,
  122370. 5,
  122371. 11,
  122372. 4,
  122373. 12,
  122374. 3,
  122375. 13,
  122376. 2,
  122377. 14,
  122378. 1,
  122379. 15,
  122380. 0,
  122381. 16,
  122382. };
  122383. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122384. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122385. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122386. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122387. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122388. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122389. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122390. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122391. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122392. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122393. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122394. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122395. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122396. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122397. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122398. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122399. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122400. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122401. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122402. 14,
  122403. };
  122404. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122405. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122406. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122407. };
  122408. static long _vq_quantmap__44c0_s_p5_0[] = {
  122409. 15, 13, 11, 9, 7, 5, 3, 1,
  122410. 0, 2, 4, 6, 8, 10, 12, 14,
  122411. 16,
  122412. };
  122413. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122414. _vq_quantthresh__44c0_s_p5_0,
  122415. _vq_quantmap__44c0_s_p5_0,
  122416. 17,
  122417. 17
  122418. };
  122419. static static_codebook _44c0_s_p5_0 = {
  122420. 2, 289,
  122421. _vq_lengthlist__44c0_s_p5_0,
  122422. 1, -529530880, 1611661312, 5, 0,
  122423. _vq_quantlist__44c0_s_p5_0,
  122424. NULL,
  122425. &_vq_auxt__44c0_s_p5_0,
  122426. NULL,
  122427. 0
  122428. };
  122429. static long _vq_quantlist__44c0_s_p6_0[] = {
  122430. 1,
  122431. 0,
  122432. 2,
  122433. };
  122434. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122435. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122436. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122437. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122438. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122439. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122440. 10,
  122441. };
  122442. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122443. -5.5, 5.5,
  122444. };
  122445. static long _vq_quantmap__44c0_s_p6_0[] = {
  122446. 1, 0, 2,
  122447. };
  122448. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122449. _vq_quantthresh__44c0_s_p6_0,
  122450. _vq_quantmap__44c0_s_p6_0,
  122451. 3,
  122452. 3
  122453. };
  122454. static static_codebook _44c0_s_p6_0 = {
  122455. 4, 81,
  122456. _vq_lengthlist__44c0_s_p6_0,
  122457. 1, -529137664, 1618345984, 2, 0,
  122458. _vq_quantlist__44c0_s_p6_0,
  122459. NULL,
  122460. &_vq_auxt__44c0_s_p6_0,
  122461. NULL,
  122462. 0
  122463. };
  122464. static long _vq_quantlist__44c0_s_p6_1[] = {
  122465. 5,
  122466. 4,
  122467. 6,
  122468. 3,
  122469. 7,
  122470. 2,
  122471. 8,
  122472. 1,
  122473. 9,
  122474. 0,
  122475. 10,
  122476. };
  122477. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122478. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122479. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122480. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122481. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122482. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122483. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122484. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122485. 10,10,10, 8, 8, 8, 8, 8, 8,
  122486. };
  122487. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122488. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122489. 3.5, 4.5,
  122490. };
  122491. static long _vq_quantmap__44c0_s_p6_1[] = {
  122492. 9, 7, 5, 3, 1, 0, 2, 4,
  122493. 6, 8, 10,
  122494. };
  122495. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122496. _vq_quantthresh__44c0_s_p6_1,
  122497. _vq_quantmap__44c0_s_p6_1,
  122498. 11,
  122499. 11
  122500. };
  122501. static static_codebook _44c0_s_p6_1 = {
  122502. 2, 121,
  122503. _vq_lengthlist__44c0_s_p6_1,
  122504. 1, -531365888, 1611661312, 4, 0,
  122505. _vq_quantlist__44c0_s_p6_1,
  122506. NULL,
  122507. &_vq_auxt__44c0_s_p6_1,
  122508. NULL,
  122509. 0
  122510. };
  122511. static long _vq_quantlist__44c0_s_p7_0[] = {
  122512. 6,
  122513. 5,
  122514. 7,
  122515. 4,
  122516. 8,
  122517. 3,
  122518. 9,
  122519. 2,
  122520. 10,
  122521. 1,
  122522. 11,
  122523. 0,
  122524. 12,
  122525. };
  122526. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122527. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122528. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122529. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122530. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122531. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122532. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122533. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122534. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122535. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122536. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122537. 0,12,12,11,11,12,12,13,13,
  122538. };
  122539. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122540. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122541. 12.5, 17.5, 22.5, 27.5,
  122542. };
  122543. static long _vq_quantmap__44c0_s_p7_0[] = {
  122544. 11, 9, 7, 5, 3, 1, 0, 2,
  122545. 4, 6, 8, 10, 12,
  122546. };
  122547. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122548. _vq_quantthresh__44c0_s_p7_0,
  122549. _vq_quantmap__44c0_s_p7_0,
  122550. 13,
  122551. 13
  122552. };
  122553. static static_codebook _44c0_s_p7_0 = {
  122554. 2, 169,
  122555. _vq_lengthlist__44c0_s_p7_0,
  122556. 1, -526516224, 1616117760, 4, 0,
  122557. _vq_quantlist__44c0_s_p7_0,
  122558. NULL,
  122559. &_vq_auxt__44c0_s_p7_0,
  122560. NULL,
  122561. 0
  122562. };
  122563. static long _vq_quantlist__44c0_s_p7_1[] = {
  122564. 2,
  122565. 1,
  122566. 3,
  122567. 0,
  122568. 4,
  122569. };
  122570. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122571. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122572. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122573. };
  122574. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122575. -1.5, -0.5, 0.5, 1.5,
  122576. };
  122577. static long _vq_quantmap__44c0_s_p7_1[] = {
  122578. 3, 1, 0, 2, 4,
  122579. };
  122580. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122581. _vq_quantthresh__44c0_s_p7_1,
  122582. _vq_quantmap__44c0_s_p7_1,
  122583. 5,
  122584. 5
  122585. };
  122586. static static_codebook _44c0_s_p7_1 = {
  122587. 2, 25,
  122588. _vq_lengthlist__44c0_s_p7_1,
  122589. 1, -533725184, 1611661312, 3, 0,
  122590. _vq_quantlist__44c0_s_p7_1,
  122591. NULL,
  122592. &_vq_auxt__44c0_s_p7_1,
  122593. NULL,
  122594. 0
  122595. };
  122596. static long _vq_quantlist__44c0_s_p8_0[] = {
  122597. 2,
  122598. 1,
  122599. 3,
  122600. 0,
  122601. 4,
  122602. };
  122603. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122604. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122605. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122606. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122607. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122608. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122609. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122610. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122611. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122612. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122613. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122614. 10,10,10,10,10,10,10,10,10,10,10,10,10,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,11,11,11,11,11,11,11,11,
  122617. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122618. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122619. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122620. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122621. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122622. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122623. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122624. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122625. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122626. 11,11,11,11,11,11,11,11,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,11,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,
  122644. };
  122645. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122646. -331.5, -110.5, 110.5, 331.5,
  122647. };
  122648. static long _vq_quantmap__44c0_s_p8_0[] = {
  122649. 3, 1, 0, 2, 4,
  122650. };
  122651. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122652. _vq_quantthresh__44c0_s_p8_0,
  122653. _vq_quantmap__44c0_s_p8_0,
  122654. 5,
  122655. 5
  122656. };
  122657. static static_codebook _44c0_s_p8_0 = {
  122658. 4, 625,
  122659. _vq_lengthlist__44c0_s_p8_0,
  122660. 1, -518283264, 1627103232, 3, 0,
  122661. _vq_quantlist__44c0_s_p8_0,
  122662. NULL,
  122663. &_vq_auxt__44c0_s_p8_0,
  122664. NULL,
  122665. 0
  122666. };
  122667. static long _vq_quantlist__44c0_s_p8_1[] = {
  122668. 6,
  122669. 5,
  122670. 7,
  122671. 4,
  122672. 8,
  122673. 3,
  122674. 9,
  122675. 2,
  122676. 10,
  122677. 1,
  122678. 11,
  122679. 0,
  122680. 12,
  122681. };
  122682. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122683. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122684. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122685. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122686. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122687. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122688. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122689. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122690. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122691. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122692. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122693. 16,13,13,12,12,14,14,15,13,
  122694. };
  122695. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122696. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122697. 42.5, 59.5, 76.5, 93.5,
  122698. };
  122699. static long _vq_quantmap__44c0_s_p8_1[] = {
  122700. 11, 9, 7, 5, 3, 1, 0, 2,
  122701. 4, 6, 8, 10, 12,
  122702. };
  122703. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122704. _vq_quantthresh__44c0_s_p8_1,
  122705. _vq_quantmap__44c0_s_p8_1,
  122706. 13,
  122707. 13
  122708. };
  122709. static static_codebook _44c0_s_p8_1 = {
  122710. 2, 169,
  122711. _vq_lengthlist__44c0_s_p8_1,
  122712. 1, -522616832, 1620115456, 4, 0,
  122713. _vq_quantlist__44c0_s_p8_1,
  122714. NULL,
  122715. &_vq_auxt__44c0_s_p8_1,
  122716. NULL,
  122717. 0
  122718. };
  122719. static long _vq_quantlist__44c0_s_p8_2[] = {
  122720. 8,
  122721. 7,
  122722. 9,
  122723. 6,
  122724. 10,
  122725. 5,
  122726. 11,
  122727. 4,
  122728. 12,
  122729. 3,
  122730. 13,
  122731. 2,
  122732. 14,
  122733. 1,
  122734. 15,
  122735. 0,
  122736. 16,
  122737. };
  122738. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122739. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122740. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122741. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122742. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122743. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122744. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122745. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122746. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122747. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122748. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122749. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122750. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122751. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122752. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122753. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122754. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122755. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122756. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122757. 10,
  122758. };
  122759. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122760. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122761. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122762. };
  122763. static long _vq_quantmap__44c0_s_p8_2[] = {
  122764. 15, 13, 11, 9, 7, 5, 3, 1,
  122765. 0, 2, 4, 6, 8, 10, 12, 14,
  122766. 16,
  122767. };
  122768. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122769. _vq_quantthresh__44c0_s_p8_2,
  122770. _vq_quantmap__44c0_s_p8_2,
  122771. 17,
  122772. 17
  122773. };
  122774. static static_codebook _44c0_s_p8_2 = {
  122775. 2, 289,
  122776. _vq_lengthlist__44c0_s_p8_2,
  122777. 1, -529530880, 1611661312, 5, 0,
  122778. _vq_quantlist__44c0_s_p8_2,
  122779. NULL,
  122780. &_vq_auxt__44c0_s_p8_2,
  122781. NULL,
  122782. 0
  122783. };
  122784. static long _huff_lengthlist__44c0_s_short[] = {
  122785. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122786. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122787. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122788. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122789. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122790. 12,
  122791. };
  122792. static static_codebook _huff_book__44c0_s_short = {
  122793. 2, 81,
  122794. _huff_lengthlist__44c0_s_short,
  122795. 0, 0, 0, 0, 0,
  122796. NULL,
  122797. NULL,
  122798. NULL,
  122799. NULL,
  122800. 0
  122801. };
  122802. static long _huff_lengthlist__44c0_sm_long[] = {
  122803. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122804. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122805. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122806. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122807. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122808. 13,
  122809. };
  122810. static static_codebook _huff_book__44c0_sm_long = {
  122811. 2, 81,
  122812. _huff_lengthlist__44c0_sm_long,
  122813. 0, 0, 0, 0, 0,
  122814. NULL,
  122815. NULL,
  122816. NULL,
  122817. NULL,
  122818. 0
  122819. };
  122820. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122821. 1,
  122822. 0,
  122823. 2,
  122824. };
  122825. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122826. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122827. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122831. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122832. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122836. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122837. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122868. 0, 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, 5, 8, 7, 0, 0, 0, 0,
  122872. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  122877. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 0, 0, 7, 9, 9, 0, 0,
  122882. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 0, 0, 0, 0, 0, 0,
  122887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  122892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122918. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122923. 0, 0, 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  122924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122927. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122928. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  122929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122939. 0, 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,
  123237. };
  123238. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  123239. -0.5, 0.5,
  123240. };
  123241. static long _vq_quantmap__44c0_sm_p1_0[] = {
  123242. 1, 0, 2,
  123243. };
  123244. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  123245. _vq_quantthresh__44c0_sm_p1_0,
  123246. _vq_quantmap__44c0_sm_p1_0,
  123247. 3,
  123248. 3
  123249. };
  123250. static static_codebook _44c0_sm_p1_0 = {
  123251. 8, 6561,
  123252. _vq_lengthlist__44c0_sm_p1_0,
  123253. 1, -535822336, 1611661312, 2, 0,
  123254. _vq_quantlist__44c0_sm_p1_0,
  123255. NULL,
  123256. &_vq_auxt__44c0_sm_p1_0,
  123257. NULL,
  123258. 0
  123259. };
  123260. static long _vq_quantlist__44c0_sm_p2_0[] = {
  123261. 2,
  123262. 1,
  123263. 3,
  123264. 0,
  123265. 4,
  123266. };
  123267. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  123268. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  123270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123271. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  123273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123274. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  123308. };
  123309. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123310. -1.5, -0.5, 0.5, 1.5,
  123311. };
  123312. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123313. 3, 1, 0, 2, 4,
  123314. };
  123315. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123316. _vq_quantthresh__44c0_sm_p2_0,
  123317. _vq_quantmap__44c0_sm_p2_0,
  123318. 5,
  123319. 5
  123320. };
  123321. static static_codebook _44c0_sm_p2_0 = {
  123322. 4, 625,
  123323. _vq_lengthlist__44c0_sm_p2_0,
  123324. 1, -533725184, 1611661312, 3, 0,
  123325. _vq_quantlist__44c0_sm_p2_0,
  123326. NULL,
  123327. &_vq_auxt__44c0_sm_p2_0,
  123328. NULL,
  123329. 0
  123330. };
  123331. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123332. 4,
  123333. 3,
  123334. 5,
  123335. 2,
  123336. 6,
  123337. 1,
  123338. 7,
  123339. 0,
  123340. 8,
  123341. };
  123342. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123343. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123344. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123345. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123346. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123347. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123348. 0,
  123349. };
  123350. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123351. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123352. };
  123353. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123354. 7, 5, 3, 1, 0, 2, 4, 6,
  123355. 8,
  123356. };
  123357. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123358. _vq_quantthresh__44c0_sm_p3_0,
  123359. _vq_quantmap__44c0_sm_p3_0,
  123360. 9,
  123361. 9
  123362. };
  123363. static static_codebook _44c0_sm_p3_0 = {
  123364. 2, 81,
  123365. _vq_lengthlist__44c0_sm_p3_0,
  123366. 1, -531628032, 1611661312, 4, 0,
  123367. _vq_quantlist__44c0_sm_p3_0,
  123368. NULL,
  123369. &_vq_auxt__44c0_sm_p3_0,
  123370. NULL,
  123371. 0
  123372. };
  123373. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123374. 4,
  123375. 3,
  123376. 5,
  123377. 2,
  123378. 6,
  123379. 1,
  123380. 7,
  123381. 0,
  123382. 8,
  123383. };
  123384. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123385. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123386. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123387. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123388. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123389. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123390. 11,
  123391. };
  123392. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123393. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123394. };
  123395. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123396. 7, 5, 3, 1, 0, 2, 4, 6,
  123397. 8,
  123398. };
  123399. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123400. _vq_quantthresh__44c0_sm_p4_0,
  123401. _vq_quantmap__44c0_sm_p4_0,
  123402. 9,
  123403. 9
  123404. };
  123405. static static_codebook _44c0_sm_p4_0 = {
  123406. 2, 81,
  123407. _vq_lengthlist__44c0_sm_p4_0,
  123408. 1, -531628032, 1611661312, 4, 0,
  123409. _vq_quantlist__44c0_sm_p4_0,
  123410. NULL,
  123411. &_vq_auxt__44c0_sm_p4_0,
  123412. NULL,
  123413. 0
  123414. };
  123415. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123416. 8,
  123417. 7,
  123418. 9,
  123419. 6,
  123420. 10,
  123421. 5,
  123422. 11,
  123423. 4,
  123424. 12,
  123425. 3,
  123426. 13,
  123427. 2,
  123428. 14,
  123429. 1,
  123430. 15,
  123431. 0,
  123432. 16,
  123433. };
  123434. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123435. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123436. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123437. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123438. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123439. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123440. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123441. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123442. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123443. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123444. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123445. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123446. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123447. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123448. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123449. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123450. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123451. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123452. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123453. 14,
  123454. };
  123455. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123456. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123457. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123458. };
  123459. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123460. 15, 13, 11, 9, 7, 5, 3, 1,
  123461. 0, 2, 4, 6, 8, 10, 12, 14,
  123462. 16,
  123463. };
  123464. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123465. _vq_quantthresh__44c0_sm_p5_0,
  123466. _vq_quantmap__44c0_sm_p5_0,
  123467. 17,
  123468. 17
  123469. };
  123470. static static_codebook _44c0_sm_p5_0 = {
  123471. 2, 289,
  123472. _vq_lengthlist__44c0_sm_p5_0,
  123473. 1, -529530880, 1611661312, 5, 0,
  123474. _vq_quantlist__44c0_sm_p5_0,
  123475. NULL,
  123476. &_vq_auxt__44c0_sm_p5_0,
  123477. NULL,
  123478. 0
  123479. };
  123480. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123481. 1,
  123482. 0,
  123483. 2,
  123484. };
  123485. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123486. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123487. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123488. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123489. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123490. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123491. 11,
  123492. };
  123493. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123494. -5.5, 5.5,
  123495. };
  123496. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123497. 1, 0, 2,
  123498. };
  123499. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123500. _vq_quantthresh__44c0_sm_p6_0,
  123501. _vq_quantmap__44c0_sm_p6_0,
  123502. 3,
  123503. 3
  123504. };
  123505. static static_codebook _44c0_sm_p6_0 = {
  123506. 4, 81,
  123507. _vq_lengthlist__44c0_sm_p6_0,
  123508. 1, -529137664, 1618345984, 2, 0,
  123509. _vq_quantlist__44c0_sm_p6_0,
  123510. NULL,
  123511. &_vq_auxt__44c0_sm_p6_0,
  123512. NULL,
  123513. 0
  123514. };
  123515. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123516. 5,
  123517. 4,
  123518. 6,
  123519. 3,
  123520. 7,
  123521. 2,
  123522. 8,
  123523. 1,
  123524. 9,
  123525. 0,
  123526. 10,
  123527. };
  123528. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123529. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123530. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123531. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123532. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123533. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123534. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123535. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123536. 10,10,10, 8, 8, 8, 8, 8, 8,
  123537. };
  123538. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123539. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123540. 3.5, 4.5,
  123541. };
  123542. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123543. 9, 7, 5, 3, 1, 0, 2, 4,
  123544. 6, 8, 10,
  123545. };
  123546. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123547. _vq_quantthresh__44c0_sm_p6_1,
  123548. _vq_quantmap__44c0_sm_p6_1,
  123549. 11,
  123550. 11
  123551. };
  123552. static static_codebook _44c0_sm_p6_1 = {
  123553. 2, 121,
  123554. _vq_lengthlist__44c0_sm_p6_1,
  123555. 1, -531365888, 1611661312, 4, 0,
  123556. _vq_quantlist__44c0_sm_p6_1,
  123557. NULL,
  123558. &_vq_auxt__44c0_sm_p6_1,
  123559. NULL,
  123560. 0
  123561. };
  123562. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123563. 6,
  123564. 5,
  123565. 7,
  123566. 4,
  123567. 8,
  123568. 3,
  123569. 9,
  123570. 2,
  123571. 10,
  123572. 1,
  123573. 11,
  123574. 0,
  123575. 12,
  123576. };
  123577. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123578. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123579. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123580. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123581. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123582. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123583. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123584. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123585. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123586. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123587. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123588. 0,12,12,11,11,13,12,14,14,
  123589. };
  123590. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123591. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123592. 12.5, 17.5, 22.5, 27.5,
  123593. };
  123594. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123595. 11, 9, 7, 5, 3, 1, 0, 2,
  123596. 4, 6, 8, 10, 12,
  123597. };
  123598. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123599. _vq_quantthresh__44c0_sm_p7_0,
  123600. _vq_quantmap__44c0_sm_p7_0,
  123601. 13,
  123602. 13
  123603. };
  123604. static static_codebook _44c0_sm_p7_0 = {
  123605. 2, 169,
  123606. _vq_lengthlist__44c0_sm_p7_0,
  123607. 1, -526516224, 1616117760, 4, 0,
  123608. _vq_quantlist__44c0_sm_p7_0,
  123609. NULL,
  123610. &_vq_auxt__44c0_sm_p7_0,
  123611. NULL,
  123612. 0
  123613. };
  123614. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123615. 2,
  123616. 1,
  123617. 3,
  123618. 0,
  123619. 4,
  123620. };
  123621. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123622. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123623. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123624. };
  123625. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123626. -1.5, -0.5, 0.5, 1.5,
  123627. };
  123628. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123629. 3, 1, 0, 2, 4,
  123630. };
  123631. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123632. _vq_quantthresh__44c0_sm_p7_1,
  123633. _vq_quantmap__44c0_sm_p7_1,
  123634. 5,
  123635. 5
  123636. };
  123637. static static_codebook _44c0_sm_p7_1 = {
  123638. 2, 25,
  123639. _vq_lengthlist__44c0_sm_p7_1,
  123640. 1, -533725184, 1611661312, 3, 0,
  123641. _vq_quantlist__44c0_sm_p7_1,
  123642. NULL,
  123643. &_vq_auxt__44c0_sm_p7_1,
  123644. NULL,
  123645. 0
  123646. };
  123647. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123648. 4,
  123649. 3,
  123650. 5,
  123651. 2,
  123652. 6,
  123653. 1,
  123654. 7,
  123655. 0,
  123656. 8,
  123657. };
  123658. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123659. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123660. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123661. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123662. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123663. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123664. 12,
  123665. };
  123666. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123667. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123668. };
  123669. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123670. 7, 5, 3, 1, 0, 2, 4, 6,
  123671. 8,
  123672. };
  123673. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123674. _vq_quantthresh__44c0_sm_p8_0,
  123675. _vq_quantmap__44c0_sm_p8_0,
  123676. 9,
  123677. 9
  123678. };
  123679. static static_codebook _44c0_sm_p8_0 = {
  123680. 2, 81,
  123681. _vq_lengthlist__44c0_sm_p8_0,
  123682. 1, -516186112, 1627103232, 4, 0,
  123683. _vq_quantlist__44c0_sm_p8_0,
  123684. NULL,
  123685. &_vq_auxt__44c0_sm_p8_0,
  123686. NULL,
  123687. 0
  123688. };
  123689. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123690. 6,
  123691. 5,
  123692. 7,
  123693. 4,
  123694. 8,
  123695. 3,
  123696. 9,
  123697. 2,
  123698. 10,
  123699. 1,
  123700. 11,
  123701. 0,
  123702. 12,
  123703. };
  123704. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123705. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123706. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123707. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123708. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123709. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123710. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123711. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123712. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123713. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123714. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123715. 20,13,13,12,12,16,13,15,13,
  123716. };
  123717. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123718. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123719. 42.5, 59.5, 76.5, 93.5,
  123720. };
  123721. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123722. 11, 9, 7, 5, 3, 1, 0, 2,
  123723. 4, 6, 8, 10, 12,
  123724. };
  123725. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123726. _vq_quantthresh__44c0_sm_p8_1,
  123727. _vq_quantmap__44c0_sm_p8_1,
  123728. 13,
  123729. 13
  123730. };
  123731. static static_codebook _44c0_sm_p8_1 = {
  123732. 2, 169,
  123733. _vq_lengthlist__44c0_sm_p8_1,
  123734. 1, -522616832, 1620115456, 4, 0,
  123735. _vq_quantlist__44c0_sm_p8_1,
  123736. NULL,
  123737. &_vq_auxt__44c0_sm_p8_1,
  123738. NULL,
  123739. 0
  123740. };
  123741. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123742. 8,
  123743. 7,
  123744. 9,
  123745. 6,
  123746. 10,
  123747. 5,
  123748. 11,
  123749. 4,
  123750. 12,
  123751. 3,
  123752. 13,
  123753. 2,
  123754. 14,
  123755. 1,
  123756. 15,
  123757. 0,
  123758. 16,
  123759. };
  123760. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123761. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123762. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123763. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123764. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123765. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123766. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123767. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123768. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123769. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123770. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123771. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123772. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123773. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123774. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123775. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123776. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123777. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123778. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123779. 9,
  123780. };
  123781. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123782. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123783. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123784. };
  123785. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123786. 15, 13, 11, 9, 7, 5, 3, 1,
  123787. 0, 2, 4, 6, 8, 10, 12, 14,
  123788. 16,
  123789. };
  123790. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123791. _vq_quantthresh__44c0_sm_p8_2,
  123792. _vq_quantmap__44c0_sm_p8_2,
  123793. 17,
  123794. 17
  123795. };
  123796. static static_codebook _44c0_sm_p8_2 = {
  123797. 2, 289,
  123798. _vq_lengthlist__44c0_sm_p8_2,
  123799. 1, -529530880, 1611661312, 5, 0,
  123800. _vq_quantlist__44c0_sm_p8_2,
  123801. NULL,
  123802. &_vq_auxt__44c0_sm_p8_2,
  123803. NULL,
  123804. 0
  123805. };
  123806. static long _huff_lengthlist__44c0_sm_short[] = {
  123807. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123808. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123809. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123810. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123811. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123812. 12,
  123813. };
  123814. static static_codebook _huff_book__44c0_sm_short = {
  123815. 2, 81,
  123816. _huff_lengthlist__44c0_sm_short,
  123817. 0, 0, 0, 0, 0,
  123818. NULL,
  123819. NULL,
  123820. NULL,
  123821. NULL,
  123822. 0
  123823. };
  123824. static long _huff_lengthlist__44c1_s_long[] = {
  123825. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123826. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123827. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123828. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123829. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123830. 11,
  123831. };
  123832. static static_codebook _huff_book__44c1_s_long = {
  123833. 2, 81,
  123834. _huff_lengthlist__44c1_s_long,
  123835. 0, 0, 0, 0, 0,
  123836. NULL,
  123837. NULL,
  123838. NULL,
  123839. NULL,
  123840. 0
  123841. };
  123842. static long _vq_quantlist__44c1_s_p1_0[] = {
  123843. 1,
  123844. 0,
  123845. 2,
  123846. };
  123847. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123848. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123849. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123853. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123854. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123858. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123859. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123890. 0, 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, 4, 7, 7, 0, 0, 0, 0,
  123894. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  123899. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 6, 8, 8, 0, 0,
  123904. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 0, 0, 0, 0, 0, 0,
  123909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  123914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123940. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123945. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  123946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123949. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123950. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123961. 0, 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,
  124259. };
  124260. static float _vq_quantthresh__44c1_s_p1_0[] = {
  124261. -0.5, 0.5,
  124262. };
  124263. static long _vq_quantmap__44c1_s_p1_0[] = {
  124264. 1, 0, 2,
  124265. };
  124266. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  124267. _vq_quantthresh__44c1_s_p1_0,
  124268. _vq_quantmap__44c1_s_p1_0,
  124269. 3,
  124270. 3
  124271. };
  124272. static static_codebook _44c1_s_p1_0 = {
  124273. 8, 6561,
  124274. _vq_lengthlist__44c1_s_p1_0,
  124275. 1, -535822336, 1611661312, 2, 0,
  124276. _vq_quantlist__44c1_s_p1_0,
  124277. NULL,
  124278. &_vq_auxt__44c1_s_p1_0,
  124279. NULL,
  124280. 0
  124281. };
  124282. static long _vq_quantlist__44c1_s_p2_0[] = {
  124283. 2,
  124284. 1,
  124285. 3,
  124286. 0,
  124287. 4,
  124288. };
  124289. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124290. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124293. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124296. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  124297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  124330. };
  124331. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124332. -1.5, -0.5, 0.5, 1.5,
  124333. };
  124334. static long _vq_quantmap__44c1_s_p2_0[] = {
  124335. 3, 1, 0, 2, 4,
  124336. };
  124337. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124338. _vq_quantthresh__44c1_s_p2_0,
  124339. _vq_quantmap__44c1_s_p2_0,
  124340. 5,
  124341. 5
  124342. };
  124343. static static_codebook _44c1_s_p2_0 = {
  124344. 4, 625,
  124345. _vq_lengthlist__44c1_s_p2_0,
  124346. 1, -533725184, 1611661312, 3, 0,
  124347. _vq_quantlist__44c1_s_p2_0,
  124348. NULL,
  124349. &_vq_auxt__44c1_s_p2_0,
  124350. NULL,
  124351. 0
  124352. };
  124353. static long _vq_quantlist__44c1_s_p3_0[] = {
  124354. 4,
  124355. 3,
  124356. 5,
  124357. 2,
  124358. 6,
  124359. 1,
  124360. 7,
  124361. 0,
  124362. 8,
  124363. };
  124364. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124365. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124366. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124367. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124368. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124369. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124370. 0,
  124371. };
  124372. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124373. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124374. };
  124375. static long _vq_quantmap__44c1_s_p3_0[] = {
  124376. 7, 5, 3, 1, 0, 2, 4, 6,
  124377. 8,
  124378. };
  124379. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124380. _vq_quantthresh__44c1_s_p3_0,
  124381. _vq_quantmap__44c1_s_p3_0,
  124382. 9,
  124383. 9
  124384. };
  124385. static static_codebook _44c1_s_p3_0 = {
  124386. 2, 81,
  124387. _vq_lengthlist__44c1_s_p3_0,
  124388. 1, -531628032, 1611661312, 4, 0,
  124389. _vq_quantlist__44c1_s_p3_0,
  124390. NULL,
  124391. &_vq_auxt__44c1_s_p3_0,
  124392. NULL,
  124393. 0
  124394. };
  124395. static long _vq_quantlist__44c1_s_p4_0[] = {
  124396. 4,
  124397. 3,
  124398. 5,
  124399. 2,
  124400. 6,
  124401. 1,
  124402. 7,
  124403. 0,
  124404. 8,
  124405. };
  124406. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124407. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124408. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124409. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124410. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124411. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124412. 11,
  124413. };
  124414. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124415. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124416. };
  124417. static long _vq_quantmap__44c1_s_p4_0[] = {
  124418. 7, 5, 3, 1, 0, 2, 4, 6,
  124419. 8,
  124420. };
  124421. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124422. _vq_quantthresh__44c1_s_p4_0,
  124423. _vq_quantmap__44c1_s_p4_0,
  124424. 9,
  124425. 9
  124426. };
  124427. static static_codebook _44c1_s_p4_0 = {
  124428. 2, 81,
  124429. _vq_lengthlist__44c1_s_p4_0,
  124430. 1, -531628032, 1611661312, 4, 0,
  124431. _vq_quantlist__44c1_s_p4_0,
  124432. NULL,
  124433. &_vq_auxt__44c1_s_p4_0,
  124434. NULL,
  124435. 0
  124436. };
  124437. static long _vq_quantlist__44c1_s_p5_0[] = {
  124438. 8,
  124439. 7,
  124440. 9,
  124441. 6,
  124442. 10,
  124443. 5,
  124444. 11,
  124445. 4,
  124446. 12,
  124447. 3,
  124448. 13,
  124449. 2,
  124450. 14,
  124451. 1,
  124452. 15,
  124453. 0,
  124454. 16,
  124455. };
  124456. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124457. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124458. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124459. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124460. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124461. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124462. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124463. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124464. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124465. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124466. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124467. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124468. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124469. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124470. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124471. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124472. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124473. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124474. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124475. 14,
  124476. };
  124477. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124478. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124479. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124480. };
  124481. static long _vq_quantmap__44c1_s_p5_0[] = {
  124482. 15, 13, 11, 9, 7, 5, 3, 1,
  124483. 0, 2, 4, 6, 8, 10, 12, 14,
  124484. 16,
  124485. };
  124486. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124487. _vq_quantthresh__44c1_s_p5_0,
  124488. _vq_quantmap__44c1_s_p5_0,
  124489. 17,
  124490. 17
  124491. };
  124492. static static_codebook _44c1_s_p5_0 = {
  124493. 2, 289,
  124494. _vq_lengthlist__44c1_s_p5_0,
  124495. 1, -529530880, 1611661312, 5, 0,
  124496. _vq_quantlist__44c1_s_p5_0,
  124497. NULL,
  124498. &_vq_auxt__44c1_s_p5_0,
  124499. NULL,
  124500. 0
  124501. };
  124502. static long _vq_quantlist__44c1_s_p6_0[] = {
  124503. 1,
  124504. 0,
  124505. 2,
  124506. };
  124507. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124508. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124509. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124510. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124511. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124512. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124513. 11,
  124514. };
  124515. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124516. -5.5, 5.5,
  124517. };
  124518. static long _vq_quantmap__44c1_s_p6_0[] = {
  124519. 1, 0, 2,
  124520. };
  124521. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124522. _vq_quantthresh__44c1_s_p6_0,
  124523. _vq_quantmap__44c1_s_p6_0,
  124524. 3,
  124525. 3
  124526. };
  124527. static static_codebook _44c1_s_p6_0 = {
  124528. 4, 81,
  124529. _vq_lengthlist__44c1_s_p6_0,
  124530. 1, -529137664, 1618345984, 2, 0,
  124531. _vq_quantlist__44c1_s_p6_0,
  124532. NULL,
  124533. &_vq_auxt__44c1_s_p6_0,
  124534. NULL,
  124535. 0
  124536. };
  124537. static long _vq_quantlist__44c1_s_p6_1[] = {
  124538. 5,
  124539. 4,
  124540. 6,
  124541. 3,
  124542. 7,
  124543. 2,
  124544. 8,
  124545. 1,
  124546. 9,
  124547. 0,
  124548. 10,
  124549. };
  124550. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124551. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124552. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124553. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124554. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124555. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124556. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124557. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124558. 10,10,10, 8, 8, 8, 8, 8, 8,
  124559. };
  124560. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124561. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124562. 3.5, 4.5,
  124563. };
  124564. static long _vq_quantmap__44c1_s_p6_1[] = {
  124565. 9, 7, 5, 3, 1, 0, 2, 4,
  124566. 6, 8, 10,
  124567. };
  124568. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124569. _vq_quantthresh__44c1_s_p6_1,
  124570. _vq_quantmap__44c1_s_p6_1,
  124571. 11,
  124572. 11
  124573. };
  124574. static static_codebook _44c1_s_p6_1 = {
  124575. 2, 121,
  124576. _vq_lengthlist__44c1_s_p6_1,
  124577. 1, -531365888, 1611661312, 4, 0,
  124578. _vq_quantlist__44c1_s_p6_1,
  124579. NULL,
  124580. &_vq_auxt__44c1_s_p6_1,
  124581. NULL,
  124582. 0
  124583. };
  124584. static long _vq_quantlist__44c1_s_p7_0[] = {
  124585. 6,
  124586. 5,
  124587. 7,
  124588. 4,
  124589. 8,
  124590. 3,
  124591. 9,
  124592. 2,
  124593. 10,
  124594. 1,
  124595. 11,
  124596. 0,
  124597. 12,
  124598. };
  124599. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124600. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124601. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124602. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124603. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124604. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124605. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124606. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124607. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124608. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124609. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124610. 0,12,11,11,11,13,10,14,13,
  124611. };
  124612. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124613. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124614. 12.5, 17.5, 22.5, 27.5,
  124615. };
  124616. static long _vq_quantmap__44c1_s_p7_0[] = {
  124617. 11, 9, 7, 5, 3, 1, 0, 2,
  124618. 4, 6, 8, 10, 12,
  124619. };
  124620. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124621. _vq_quantthresh__44c1_s_p7_0,
  124622. _vq_quantmap__44c1_s_p7_0,
  124623. 13,
  124624. 13
  124625. };
  124626. static static_codebook _44c1_s_p7_0 = {
  124627. 2, 169,
  124628. _vq_lengthlist__44c1_s_p7_0,
  124629. 1, -526516224, 1616117760, 4, 0,
  124630. _vq_quantlist__44c1_s_p7_0,
  124631. NULL,
  124632. &_vq_auxt__44c1_s_p7_0,
  124633. NULL,
  124634. 0
  124635. };
  124636. static long _vq_quantlist__44c1_s_p7_1[] = {
  124637. 2,
  124638. 1,
  124639. 3,
  124640. 0,
  124641. 4,
  124642. };
  124643. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124644. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124645. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124646. };
  124647. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124648. -1.5, -0.5, 0.5, 1.5,
  124649. };
  124650. static long _vq_quantmap__44c1_s_p7_1[] = {
  124651. 3, 1, 0, 2, 4,
  124652. };
  124653. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124654. _vq_quantthresh__44c1_s_p7_1,
  124655. _vq_quantmap__44c1_s_p7_1,
  124656. 5,
  124657. 5
  124658. };
  124659. static static_codebook _44c1_s_p7_1 = {
  124660. 2, 25,
  124661. _vq_lengthlist__44c1_s_p7_1,
  124662. 1, -533725184, 1611661312, 3, 0,
  124663. _vq_quantlist__44c1_s_p7_1,
  124664. NULL,
  124665. &_vq_auxt__44c1_s_p7_1,
  124666. NULL,
  124667. 0
  124668. };
  124669. static long _vq_quantlist__44c1_s_p8_0[] = {
  124670. 6,
  124671. 5,
  124672. 7,
  124673. 4,
  124674. 8,
  124675. 3,
  124676. 9,
  124677. 2,
  124678. 10,
  124679. 1,
  124680. 11,
  124681. 0,
  124682. 12,
  124683. };
  124684. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124685. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124686. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124687. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124688. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124689. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124690. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124691. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124692. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124693. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124694. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124695. 10,10,10,10,10,10,10,10,10,
  124696. };
  124697. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124698. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124699. 552.5, 773.5, 994.5, 1215.5,
  124700. };
  124701. static long _vq_quantmap__44c1_s_p8_0[] = {
  124702. 11, 9, 7, 5, 3, 1, 0, 2,
  124703. 4, 6, 8, 10, 12,
  124704. };
  124705. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124706. _vq_quantthresh__44c1_s_p8_0,
  124707. _vq_quantmap__44c1_s_p8_0,
  124708. 13,
  124709. 13
  124710. };
  124711. static static_codebook _44c1_s_p8_0 = {
  124712. 2, 169,
  124713. _vq_lengthlist__44c1_s_p8_0,
  124714. 1, -514541568, 1627103232, 4, 0,
  124715. _vq_quantlist__44c1_s_p8_0,
  124716. NULL,
  124717. &_vq_auxt__44c1_s_p8_0,
  124718. NULL,
  124719. 0
  124720. };
  124721. static long _vq_quantlist__44c1_s_p8_1[] = {
  124722. 6,
  124723. 5,
  124724. 7,
  124725. 4,
  124726. 8,
  124727. 3,
  124728. 9,
  124729. 2,
  124730. 10,
  124731. 1,
  124732. 11,
  124733. 0,
  124734. 12,
  124735. };
  124736. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124737. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124738. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124739. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124740. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124741. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124742. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124743. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124744. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124745. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124746. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124747. 16,13,12,12,11,14,12,15,13,
  124748. };
  124749. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124750. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124751. 42.5, 59.5, 76.5, 93.5,
  124752. };
  124753. static long _vq_quantmap__44c1_s_p8_1[] = {
  124754. 11, 9, 7, 5, 3, 1, 0, 2,
  124755. 4, 6, 8, 10, 12,
  124756. };
  124757. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124758. _vq_quantthresh__44c1_s_p8_1,
  124759. _vq_quantmap__44c1_s_p8_1,
  124760. 13,
  124761. 13
  124762. };
  124763. static static_codebook _44c1_s_p8_1 = {
  124764. 2, 169,
  124765. _vq_lengthlist__44c1_s_p8_1,
  124766. 1, -522616832, 1620115456, 4, 0,
  124767. _vq_quantlist__44c1_s_p8_1,
  124768. NULL,
  124769. &_vq_auxt__44c1_s_p8_1,
  124770. NULL,
  124771. 0
  124772. };
  124773. static long _vq_quantlist__44c1_s_p8_2[] = {
  124774. 8,
  124775. 7,
  124776. 9,
  124777. 6,
  124778. 10,
  124779. 5,
  124780. 11,
  124781. 4,
  124782. 12,
  124783. 3,
  124784. 13,
  124785. 2,
  124786. 14,
  124787. 1,
  124788. 15,
  124789. 0,
  124790. 16,
  124791. };
  124792. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124793. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124794. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124795. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124796. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124797. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124798. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124799. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124800. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124801. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124802. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124803. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124804. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124805. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124806. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124807. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124808. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124809. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124810. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124811. 9,
  124812. };
  124813. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124814. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124815. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124816. };
  124817. static long _vq_quantmap__44c1_s_p8_2[] = {
  124818. 15, 13, 11, 9, 7, 5, 3, 1,
  124819. 0, 2, 4, 6, 8, 10, 12, 14,
  124820. 16,
  124821. };
  124822. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124823. _vq_quantthresh__44c1_s_p8_2,
  124824. _vq_quantmap__44c1_s_p8_2,
  124825. 17,
  124826. 17
  124827. };
  124828. static static_codebook _44c1_s_p8_2 = {
  124829. 2, 289,
  124830. _vq_lengthlist__44c1_s_p8_2,
  124831. 1, -529530880, 1611661312, 5, 0,
  124832. _vq_quantlist__44c1_s_p8_2,
  124833. NULL,
  124834. &_vq_auxt__44c1_s_p8_2,
  124835. NULL,
  124836. 0
  124837. };
  124838. static long _huff_lengthlist__44c1_s_short[] = {
  124839. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124840. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124841. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124842. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124843. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124844. 11,
  124845. };
  124846. static static_codebook _huff_book__44c1_s_short = {
  124847. 2, 81,
  124848. _huff_lengthlist__44c1_s_short,
  124849. 0, 0, 0, 0, 0,
  124850. NULL,
  124851. NULL,
  124852. NULL,
  124853. NULL,
  124854. 0
  124855. };
  124856. static long _huff_lengthlist__44c1_sm_long[] = {
  124857. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124858. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124859. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124860. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124861. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124862. 11,
  124863. };
  124864. static static_codebook _huff_book__44c1_sm_long = {
  124865. 2, 81,
  124866. _huff_lengthlist__44c1_sm_long,
  124867. 0, 0, 0, 0, 0,
  124868. NULL,
  124869. NULL,
  124870. NULL,
  124871. NULL,
  124872. 0
  124873. };
  124874. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124875. 1,
  124876. 0,
  124877. 2,
  124878. };
  124879. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124880. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124881. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124885. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124886. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124890. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124891. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124922. 0, 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, 5, 8, 7, 0, 0, 0, 0,
  124926. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  124931. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 0, 0, 7, 9, 9, 0, 0,
  124936. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 0, 0, 0, 0, 0, 0,
  124941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  124946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124972. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124977. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  124978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124981. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124982. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  124983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124993. 0, 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,
  125291. };
  125292. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125293. -0.5, 0.5,
  125294. };
  125295. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125296. 1, 0, 2,
  125297. };
  125298. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125299. _vq_quantthresh__44c1_sm_p1_0,
  125300. _vq_quantmap__44c1_sm_p1_0,
  125301. 3,
  125302. 3
  125303. };
  125304. static static_codebook _44c1_sm_p1_0 = {
  125305. 8, 6561,
  125306. _vq_lengthlist__44c1_sm_p1_0,
  125307. 1, -535822336, 1611661312, 2, 0,
  125308. _vq_quantlist__44c1_sm_p1_0,
  125309. NULL,
  125310. &_vq_auxt__44c1_sm_p1_0,
  125311. NULL,
  125312. 0
  125313. };
  125314. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125315. 2,
  125316. 1,
  125317. 3,
  125318. 0,
  125319. 4,
  125320. };
  125321. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125322. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125325. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125328. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  125362. };
  125363. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125364. -1.5, -0.5, 0.5, 1.5,
  125365. };
  125366. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125367. 3, 1, 0, 2, 4,
  125368. };
  125369. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125370. _vq_quantthresh__44c1_sm_p2_0,
  125371. _vq_quantmap__44c1_sm_p2_0,
  125372. 5,
  125373. 5
  125374. };
  125375. static static_codebook _44c1_sm_p2_0 = {
  125376. 4, 625,
  125377. _vq_lengthlist__44c1_sm_p2_0,
  125378. 1, -533725184, 1611661312, 3, 0,
  125379. _vq_quantlist__44c1_sm_p2_0,
  125380. NULL,
  125381. &_vq_auxt__44c1_sm_p2_0,
  125382. NULL,
  125383. 0
  125384. };
  125385. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125386. 4,
  125387. 3,
  125388. 5,
  125389. 2,
  125390. 6,
  125391. 1,
  125392. 7,
  125393. 0,
  125394. 8,
  125395. };
  125396. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125397. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125398. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125399. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125400. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125401. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125402. 0,
  125403. };
  125404. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125405. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125406. };
  125407. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125408. 7, 5, 3, 1, 0, 2, 4, 6,
  125409. 8,
  125410. };
  125411. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125412. _vq_quantthresh__44c1_sm_p3_0,
  125413. _vq_quantmap__44c1_sm_p3_0,
  125414. 9,
  125415. 9
  125416. };
  125417. static static_codebook _44c1_sm_p3_0 = {
  125418. 2, 81,
  125419. _vq_lengthlist__44c1_sm_p3_0,
  125420. 1, -531628032, 1611661312, 4, 0,
  125421. _vq_quantlist__44c1_sm_p3_0,
  125422. NULL,
  125423. &_vq_auxt__44c1_sm_p3_0,
  125424. NULL,
  125425. 0
  125426. };
  125427. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125428. 4,
  125429. 3,
  125430. 5,
  125431. 2,
  125432. 6,
  125433. 1,
  125434. 7,
  125435. 0,
  125436. 8,
  125437. };
  125438. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125439. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125440. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125441. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125442. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125443. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125444. 11,
  125445. };
  125446. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125447. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125448. };
  125449. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125450. 7, 5, 3, 1, 0, 2, 4, 6,
  125451. 8,
  125452. };
  125453. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125454. _vq_quantthresh__44c1_sm_p4_0,
  125455. _vq_quantmap__44c1_sm_p4_0,
  125456. 9,
  125457. 9
  125458. };
  125459. static static_codebook _44c1_sm_p4_0 = {
  125460. 2, 81,
  125461. _vq_lengthlist__44c1_sm_p4_0,
  125462. 1, -531628032, 1611661312, 4, 0,
  125463. _vq_quantlist__44c1_sm_p4_0,
  125464. NULL,
  125465. &_vq_auxt__44c1_sm_p4_0,
  125466. NULL,
  125467. 0
  125468. };
  125469. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125470. 8,
  125471. 7,
  125472. 9,
  125473. 6,
  125474. 10,
  125475. 5,
  125476. 11,
  125477. 4,
  125478. 12,
  125479. 3,
  125480. 13,
  125481. 2,
  125482. 14,
  125483. 1,
  125484. 15,
  125485. 0,
  125486. 16,
  125487. };
  125488. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125489. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125490. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125491. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125492. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125493. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125494. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125495. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125496. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125497. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125498. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125499. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125500. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125501. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125502. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125503. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125504. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125505. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125506. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125507. 14,
  125508. };
  125509. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125510. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125511. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125512. };
  125513. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125514. 15, 13, 11, 9, 7, 5, 3, 1,
  125515. 0, 2, 4, 6, 8, 10, 12, 14,
  125516. 16,
  125517. };
  125518. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125519. _vq_quantthresh__44c1_sm_p5_0,
  125520. _vq_quantmap__44c1_sm_p5_0,
  125521. 17,
  125522. 17
  125523. };
  125524. static static_codebook _44c1_sm_p5_0 = {
  125525. 2, 289,
  125526. _vq_lengthlist__44c1_sm_p5_0,
  125527. 1, -529530880, 1611661312, 5, 0,
  125528. _vq_quantlist__44c1_sm_p5_0,
  125529. NULL,
  125530. &_vq_auxt__44c1_sm_p5_0,
  125531. NULL,
  125532. 0
  125533. };
  125534. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125535. 1,
  125536. 0,
  125537. 2,
  125538. };
  125539. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125540. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125541. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125542. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125543. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125544. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125545. 11,
  125546. };
  125547. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125548. -5.5, 5.5,
  125549. };
  125550. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125551. 1, 0, 2,
  125552. };
  125553. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125554. _vq_quantthresh__44c1_sm_p6_0,
  125555. _vq_quantmap__44c1_sm_p6_0,
  125556. 3,
  125557. 3
  125558. };
  125559. static static_codebook _44c1_sm_p6_0 = {
  125560. 4, 81,
  125561. _vq_lengthlist__44c1_sm_p6_0,
  125562. 1, -529137664, 1618345984, 2, 0,
  125563. _vq_quantlist__44c1_sm_p6_0,
  125564. NULL,
  125565. &_vq_auxt__44c1_sm_p6_0,
  125566. NULL,
  125567. 0
  125568. };
  125569. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125570. 5,
  125571. 4,
  125572. 6,
  125573. 3,
  125574. 7,
  125575. 2,
  125576. 8,
  125577. 1,
  125578. 9,
  125579. 0,
  125580. 10,
  125581. };
  125582. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125583. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125584. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125585. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125586. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125587. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125588. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125589. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125590. 10,10,10, 8, 8, 8, 8, 8, 8,
  125591. };
  125592. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125593. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125594. 3.5, 4.5,
  125595. };
  125596. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125597. 9, 7, 5, 3, 1, 0, 2, 4,
  125598. 6, 8, 10,
  125599. };
  125600. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125601. _vq_quantthresh__44c1_sm_p6_1,
  125602. _vq_quantmap__44c1_sm_p6_1,
  125603. 11,
  125604. 11
  125605. };
  125606. static static_codebook _44c1_sm_p6_1 = {
  125607. 2, 121,
  125608. _vq_lengthlist__44c1_sm_p6_1,
  125609. 1, -531365888, 1611661312, 4, 0,
  125610. _vq_quantlist__44c1_sm_p6_1,
  125611. NULL,
  125612. &_vq_auxt__44c1_sm_p6_1,
  125613. NULL,
  125614. 0
  125615. };
  125616. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125617. 6,
  125618. 5,
  125619. 7,
  125620. 4,
  125621. 8,
  125622. 3,
  125623. 9,
  125624. 2,
  125625. 10,
  125626. 1,
  125627. 11,
  125628. 0,
  125629. 12,
  125630. };
  125631. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125632. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125633. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125634. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125635. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125636. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125637. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125638. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125639. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125640. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125641. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125642. 0,12,12,11,11,13,12,14,13,
  125643. };
  125644. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125645. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125646. 12.5, 17.5, 22.5, 27.5,
  125647. };
  125648. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125649. 11, 9, 7, 5, 3, 1, 0, 2,
  125650. 4, 6, 8, 10, 12,
  125651. };
  125652. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125653. _vq_quantthresh__44c1_sm_p7_0,
  125654. _vq_quantmap__44c1_sm_p7_0,
  125655. 13,
  125656. 13
  125657. };
  125658. static static_codebook _44c1_sm_p7_0 = {
  125659. 2, 169,
  125660. _vq_lengthlist__44c1_sm_p7_0,
  125661. 1, -526516224, 1616117760, 4, 0,
  125662. _vq_quantlist__44c1_sm_p7_0,
  125663. NULL,
  125664. &_vq_auxt__44c1_sm_p7_0,
  125665. NULL,
  125666. 0
  125667. };
  125668. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125669. 2,
  125670. 1,
  125671. 3,
  125672. 0,
  125673. 4,
  125674. };
  125675. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125676. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125677. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125678. };
  125679. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125680. -1.5, -0.5, 0.5, 1.5,
  125681. };
  125682. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125683. 3, 1, 0, 2, 4,
  125684. };
  125685. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125686. _vq_quantthresh__44c1_sm_p7_1,
  125687. _vq_quantmap__44c1_sm_p7_1,
  125688. 5,
  125689. 5
  125690. };
  125691. static static_codebook _44c1_sm_p7_1 = {
  125692. 2, 25,
  125693. _vq_lengthlist__44c1_sm_p7_1,
  125694. 1, -533725184, 1611661312, 3, 0,
  125695. _vq_quantlist__44c1_sm_p7_1,
  125696. NULL,
  125697. &_vq_auxt__44c1_sm_p7_1,
  125698. NULL,
  125699. 0
  125700. };
  125701. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125702. 6,
  125703. 5,
  125704. 7,
  125705. 4,
  125706. 8,
  125707. 3,
  125708. 9,
  125709. 2,
  125710. 10,
  125711. 1,
  125712. 11,
  125713. 0,
  125714. 12,
  125715. };
  125716. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125717. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125718. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125719. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125720. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125721. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125722. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125723. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125724. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125725. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125726. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125727. 13,13,13,13,13,13,13,13,13,
  125728. };
  125729. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125730. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125731. 552.5, 773.5, 994.5, 1215.5,
  125732. };
  125733. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125734. 11, 9, 7, 5, 3, 1, 0, 2,
  125735. 4, 6, 8, 10, 12,
  125736. };
  125737. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125738. _vq_quantthresh__44c1_sm_p8_0,
  125739. _vq_quantmap__44c1_sm_p8_0,
  125740. 13,
  125741. 13
  125742. };
  125743. static static_codebook _44c1_sm_p8_0 = {
  125744. 2, 169,
  125745. _vq_lengthlist__44c1_sm_p8_0,
  125746. 1, -514541568, 1627103232, 4, 0,
  125747. _vq_quantlist__44c1_sm_p8_0,
  125748. NULL,
  125749. &_vq_auxt__44c1_sm_p8_0,
  125750. NULL,
  125751. 0
  125752. };
  125753. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125754. 6,
  125755. 5,
  125756. 7,
  125757. 4,
  125758. 8,
  125759. 3,
  125760. 9,
  125761. 2,
  125762. 10,
  125763. 1,
  125764. 11,
  125765. 0,
  125766. 12,
  125767. };
  125768. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125769. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125770. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125771. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125772. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125773. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125774. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125775. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125776. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125777. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125778. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125779. 20,13,12,12,12,14,12,14,13,
  125780. };
  125781. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125782. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125783. 42.5, 59.5, 76.5, 93.5,
  125784. };
  125785. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125786. 11, 9, 7, 5, 3, 1, 0, 2,
  125787. 4, 6, 8, 10, 12,
  125788. };
  125789. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125790. _vq_quantthresh__44c1_sm_p8_1,
  125791. _vq_quantmap__44c1_sm_p8_1,
  125792. 13,
  125793. 13
  125794. };
  125795. static static_codebook _44c1_sm_p8_1 = {
  125796. 2, 169,
  125797. _vq_lengthlist__44c1_sm_p8_1,
  125798. 1, -522616832, 1620115456, 4, 0,
  125799. _vq_quantlist__44c1_sm_p8_1,
  125800. NULL,
  125801. &_vq_auxt__44c1_sm_p8_1,
  125802. NULL,
  125803. 0
  125804. };
  125805. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125806. 8,
  125807. 7,
  125808. 9,
  125809. 6,
  125810. 10,
  125811. 5,
  125812. 11,
  125813. 4,
  125814. 12,
  125815. 3,
  125816. 13,
  125817. 2,
  125818. 14,
  125819. 1,
  125820. 15,
  125821. 0,
  125822. 16,
  125823. };
  125824. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125825. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125826. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125827. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125828. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125829. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125830. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125831. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125832. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125833. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125834. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125835. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125836. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125837. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125838. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125839. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125840. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125841. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125842. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125843. 9,
  125844. };
  125845. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125846. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125847. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125848. };
  125849. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125850. 15, 13, 11, 9, 7, 5, 3, 1,
  125851. 0, 2, 4, 6, 8, 10, 12, 14,
  125852. 16,
  125853. };
  125854. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125855. _vq_quantthresh__44c1_sm_p8_2,
  125856. _vq_quantmap__44c1_sm_p8_2,
  125857. 17,
  125858. 17
  125859. };
  125860. static static_codebook _44c1_sm_p8_2 = {
  125861. 2, 289,
  125862. _vq_lengthlist__44c1_sm_p8_2,
  125863. 1, -529530880, 1611661312, 5, 0,
  125864. _vq_quantlist__44c1_sm_p8_2,
  125865. NULL,
  125866. &_vq_auxt__44c1_sm_p8_2,
  125867. NULL,
  125868. 0
  125869. };
  125870. static long _huff_lengthlist__44c1_sm_short[] = {
  125871. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125872. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125873. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125874. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125875. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125876. 11,
  125877. };
  125878. static static_codebook _huff_book__44c1_sm_short = {
  125879. 2, 81,
  125880. _huff_lengthlist__44c1_sm_short,
  125881. 0, 0, 0, 0, 0,
  125882. NULL,
  125883. NULL,
  125884. NULL,
  125885. NULL,
  125886. 0
  125887. };
  125888. static long _huff_lengthlist__44cn1_s_long[] = {
  125889. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125890. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125891. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125892. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125893. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125894. 20,
  125895. };
  125896. static static_codebook _huff_book__44cn1_s_long = {
  125897. 2, 81,
  125898. _huff_lengthlist__44cn1_s_long,
  125899. 0, 0, 0, 0, 0,
  125900. NULL,
  125901. NULL,
  125902. NULL,
  125903. NULL,
  125904. 0
  125905. };
  125906. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125907. 1,
  125908. 0,
  125909. 2,
  125910. };
  125911. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125912. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125913. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125917. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125918. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125922. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125923. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125954. 0, 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, 5, 8, 8, 0, 0, 0, 0,
  125958. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 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, 7,10,10, 0, 0, 0,
  125963. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 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, 0, 0, 7,10,10, 0, 0,
  125968. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  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, 0, 0, 0, 0, 0, 0,
  125973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  125978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  126004. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126009. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  126010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126013. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  126014. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  126015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126025. 0, 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,
  126323. };
  126324. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126325. -0.5, 0.5,
  126326. };
  126327. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126328. 1, 0, 2,
  126329. };
  126330. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126331. _vq_quantthresh__44cn1_s_p1_0,
  126332. _vq_quantmap__44cn1_s_p1_0,
  126333. 3,
  126334. 3
  126335. };
  126336. static static_codebook _44cn1_s_p1_0 = {
  126337. 8, 6561,
  126338. _vq_lengthlist__44cn1_s_p1_0,
  126339. 1, -535822336, 1611661312, 2, 0,
  126340. _vq_quantlist__44cn1_s_p1_0,
  126341. NULL,
  126342. &_vq_auxt__44cn1_s_p1_0,
  126343. NULL,
  126344. 0
  126345. };
  126346. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126347. 2,
  126348. 1,
  126349. 3,
  126350. 0,
  126351. 4,
  126352. };
  126353. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126354. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126357. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126360. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  126394. };
  126395. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126396. -1.5, -0.5, 0.5, 1.5,
  126397. };
  126398. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126399. 3, 1, 0, 2, 4,
  126400. };
  126401. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126402. _vq_quantthresh__44cn1_s_p2_0,
  126403. _vq_quantmap__44cn1_s_p2_0,
  126404. 5,
  126405. 5
  126406. };
  126407. static static_codebook _44cn1_s_p2_0 = {
  126408. 4, 625,
  126409. _vq_lengthlist__44cn1_s_p2_0,
  126410. 1, -533725184, 1611661312, 3, 0,
  126411. _vq_quantlist__44cn1_s_p2_0,
  126412. NULL,
  126413. &_vq_auxt__44cn1_s_p2_0,
  126414. NULL,
  126415. 0
  126416. };
  126417. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126418. 4,
  126419. 3,
  126420. 5,
  126421. 2,
  126422. 6,
  126423. 1,
  126424. 7,
  126425. 0,
  126426. 8,
  126427. };
  126428. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126429. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126430. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126431. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126432. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126433. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126434. 0,
  126435. };
  126436. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126437. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126438. };
  126439. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126440. 7, 5, 3, 1, 0, 2, 4, 6,
  126441. 8,
  126442. };
  126443. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126444. _vq_quantthresh__44cn1_s_p3_0,
  126445. _vq_quantmap__44cn1_s_p3_0,
  126446. 9,
  126447. 9
  126448. };
  126449. static static_codebook _44cn1_s_p3_0 = {
  126450. 2, 81,
  126451. _vq_lengthlist__44cn1_s_p3_0,
  126452. 1, -531628032, 1611661312, 4, 0,
  126453. _vq_quantlist__44cn1_s_p3_0,
  126454. NULL,
  126455. &_vq_auxt__44cn1_s_p3_0,
  126456. NULL,
  126457. 0
  126458. };
  126459. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126460. 4,
  126461. 3,
  126462. 5,
  126463. 2,
  126464. 6,
  126465. 1,
  126466. 7,
  126467. 0,
  126468. 8,
  126469. };
  126470. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126471. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126472. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126473. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126474. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126475. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126476. 11,
  126477. };
  126478. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126479. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126480. };
  126481. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126482. 7, 5, 3, 1, 0, 2, 4, 6,
  126483. 8,
  126484. };
  126485. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126486. _vq_quantthresh__44cn1_s_p4_0,
  126487. _vq_quantmap__44cn1_s_p4_0,
  126488. 9,
  126489. 9
  126490. };
  126491. static static_codebook _44cn1_s_p4_0 = {
  126492. 2, 81,
  126493. _vq_lengthlist__44cn1_s_p4_0,
  126494. 1, -531628032, 1611661312, 4, 0,
  126495. _vq_quantlist__44cn1_s_p4_0,
  126496. NULL,
  126497. &_vq_auxt__44cn1_s_p4_0,
  126498. NULL,
  126499. 0
  126500. };
  126501. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126502. 8,
  126503. 7,
  126504. 9,
  126505. 6,
  126506. 10,
  126507. 5,
  126508. 11,
  126509. 4,
  126510. 12,
  126511. 3,
  126512. 13,
  126513. 2,
  126514. 14,
  126515. 1,
  126516. 15,
  126517. 0,
  126518. 16,
  126519. };
  126520. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126521. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126522. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126523. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126524. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126525. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126526. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126527. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126528. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126529. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126530. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126531. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126532. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126533. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126534. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126535. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126536. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126537. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126538. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126539. 14,
  126540. };
  126541. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126542. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126543. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126544. };
  126545. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126546. 15, 13, 11, 9, 7, 5, 3, 1,
  126547. 0, 2, 4, 6, 8, 10, 12, 14,
  126548. 16,
  126549. };
  126550. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126551. _vq_quantthresh__44cn1_s_p5_0,
  126552. _vq_quantmap__44cn1_s_p5_0,
  126553. 17,
  126554. 17
  126555. };
  126556. static static_codebook _44cn1_s_p5_0 = {
  126557. 2, 289,
  126558. _vq_lengthlist__44cn1_s_p5_0,
  126559. 1, -529530880, 1611661312, 5, 0,
  126560. _vq_quantlist__44cn1_s_p5_0,
  126561. NULL,
  126562. &_vq_auxt__44cn1_s_p5_0,
  126563. NULL,
  126564. 0
  126565. };
  126566. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126567. 1,
  126568. 0,
  126569. 2,
  126570. };
  126571. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126572. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126573. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126574. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126575. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126576. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126577. 10,
  126578. };
  126579. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126580. -5.5, 5.5,
  126581. };
  126582. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126583. 1, 0, 2,
  126584. };
  126585. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126586. _vq_quantthresh__44cn1_s_p6_0,
  126587. _vq_quantmap__44cn1_s_p6_0,
  126588. 3,
  126589. 3
  126590. };
  126591. static static_codebook _44cn1_s_p6_0 = {
  126592. 4, 81,
  126593. _vq_lengthlist__44cn1_s_p6_0,
  126594. 1, -529137664, 1618345984, 2, 0,
  126595. _vq_quantlist__44cn1_s_p6_0,
  126596. NULL,
  126597. &_vq_auxt__44cn1_s_p6_0,
  126598. NULL,
  126599. 0
  126600. };
  126601. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126602. 5,
  126603. 4,
  126604. 6,
  126605. 3,
  126606. 7,
  126607. 2,
  126608. 8,
  126609. 1,
  126610. 9,
  126611. 0,
  126612. 10,
  126613. };
  126614. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126615. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126616. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126617. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126618. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126619. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126620. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126621. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126622. 10,10,10, 9, 9, 9, 9, 9, 9,
  126623. };
  126624. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126625. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126626. 3.5, 4.5,
  126627. };
  126628. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126629. 9, 7, 5, 3, 1, 0, 2, 4,
  126630. 6, 8, 10,
  126631. };
  126632. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126633. _vq_quantthresh__44cn1_s_p6_1,
  126634. _vq_quantmap__44cn1_s_p6_1,
  126635. 11,
  126636. 11
  126637. };
  126638. static static_codebook _44cn1_s_p6_1 = {
  126639. 2, 121,
  126640. _vq_lengthlist__44cn1_s_p6_1,
  126641. 1, -531365888, 1611661312, 4, 0,
  126642. _vq_quantlist__44cn1_s_p6_1,
  126643. NULL,
  126644. &_vq_auxt__44cn1_s_p6_1,
  126645. NULL,
  126646. 0
  126647. };
  126648. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126649. 6,
  126650. 5,
  126651. 7,
  126652. 4,
  126653. 8,
  126654. 3,
  126655. 9,
  126656. 2,
  126657. 10,
  126658. 1,
  126659. 11,
  126660. 0,
  126661. 12,
  126662. };
  126663. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126664. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126665. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126666. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126667. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126668. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126669. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126670. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126671. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126672. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126673. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126674. 0,13,13,12,12,13,13,13,14,
  126675. };
  126676. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126677. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126678. 12.5, 17.5, 22.5, 27.5,
  126679. };
  126680. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126681. 11, 9, 7, 5, 3, 1, 0, 2,
  126682. 4, 6, 8, 10, 12,
  126683. };
  126684. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126685. _vq_quantthresh__44cn1_s_p7_0,
  126686. _vq_quantmap__44cn1_s_p7_0,
  126687. 13,
  126688. 13
  126689. };
  126690. static static_codebook _44cn1_s_p7_0 = {
  126691. 2, 169,
  126692. _vq_lengthlist__44cn1_s_p7_0,
  126693. 1, -526516224, 1616117760, 4, 0,
  126694. _vq_quantlist__44cn1_s_p7_0,
  126695. NULL,
  126696. &_vq_auxt__44cn1_s_p7_0,
  126697. NULL,
  126698. 0
  126699. };
  126700. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126701. 2,
  126702. 1,
  126703. 3,
  126704. 0,
  126705. 4,
  126706. };
  126707. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126708. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126709. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126710. };
  126711. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126712. -1.5, -0.5, 0.5, 1.5,
  126713. };
  126714. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126715. 3, 1, 0, 2, 4,
  126716. };
  126717. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126718. _vq_quantthresh__44cn1_s_p7_1,
  126719. _vq_quantmap__44cn1_s_p7_1,
  126720. 5,
  126721. 5
  126722. };
  126723. static static_codebook _44cn1_s_p7_1 = {
  126724. 2, 25,
  126725. _vq_lengthlist__44cn1_s_p7_1,
  126726. 1, -533725184, 1611661312, 3, 0,
  126727. _vq_quantlist__44cn1_s_p7_1,
  126728. NULL,
  126729. &_vq_auxt__44cn1_s_p7_1,
  126730. NULL,
  126731. 0
  126732. };
  126733. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126734. 2,
  126735. 1,
  126736. 3,
  126737. 0,
  126738. 4,
  126739. };
  126740. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126741. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126742. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126743. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126744. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126745. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126746. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126747. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126748. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126749. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126750. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126751. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126752. 11,11,11,11,11,11,11,11,11,11,11,11,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,11,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, 8,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,11,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,11,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,11,
  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,11,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,12,12,12,12,12,12,12,12,12,
  126775. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126776. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126777. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126778. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126779. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126780. 12,
  126781. };
  126782. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126783. -331.5, -110.5, 110.5, 331.5,
  126784. };
  126785. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126786. 3, 1, 0, 2, 4,
  126787. };
  126788. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126789. _vq_quantthresh__44cn1_s_p8_0,
  126790. _vq_quantmap__44cn1_s_p8_0,
  126791. 5,
  126792. 5
  126793. };
  126794. static static_codebook _44cn1_s_p8_0 = {
  126795. 4, 625,
  126796. _vq_lengthlist__44cn1_s_p8_0,
  126797. 1, -518283264, 1627103232, 3, 0,
  126798. _vq_quantlist__44cn1_s_p8_0,
  126799. NULL,
  126800. &_vq_auxt__44cn1_s_p8_0,
  126801. NULL,
  126802. 0
  126803. };
  126804. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126805. 6,
  126806. 5,
  126807. 7,
  126808. 4,
  126809. 8,
  126810. 3,
  126811. 9,
  126812. 2,
  126813. 10,
  126814. 1,
  126815. 11,
  126816. 0,
  126817. 12,
  126818. };
  126819. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126820. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126821. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126822. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126823. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126824. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126825. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126826. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126827. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126828. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126829. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126830. 15,12,12,11,11,14,12,13,14,
  126831. };
  126832. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126833. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126834. 42.5, 59.5, 76.5, 93.5,
  126835. };
  126836. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126837. 11, 9, 7, 5, 3, 1, 0, 2,
  126838. 4, 6, 8, 10, 12,
  126839. };
  126840. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126841. _vq_quantthresh__44cn1_s_p8_1,
  126842. _vq_quantmap__44cn1_s_p8_1,
  126843. 13,
  126844. 13
  126845. };
  126846. static static_codebook _44cn1_s_p8_1 = {
  126847. 2, 169,
  126848. _vq_lengthlist__44cn1_s_p8_1,
  126849. 1, -522616832, 1620115456, 4, 0,
  126850. _vq_quantlist__44cn1_s_p8_1,
  126851. NULL,
  126852. &_vq_auxt__44cn1_s_p8_1,
  126853. NULL,
  126854. 0
  126855. };
  126856. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126857. 8,
  126858. 7,
  126859. 9,
  126860. 6,
  126861. 10,
  126862. 5,
  126863. 11,
  126864. 4,
  126865. 12,
  126866. 3,
  126867. 13,
  126868. 2,
  126869. 14,
  126870. 1,
  126871. 15,
  126872. 0,
  126873. 16,
  126874. };
  126875. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126876. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126877. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126878. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126879. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126880. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126881. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126882. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126883. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126884. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126885. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126886. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126887. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126888. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126889. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126890. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126891. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126892. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126893. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126894. 9,
  126895. };
  126896. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126897. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126898. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126899. };
  126900. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126901. 15, 13, 11, 9, 7, 5, 3, 1,
  126902. 0, 2, 4, 6, 8, 10, 12, 14,
  126903. 16,
  126904. };
  126905. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126906. _vq_quantthresh__44cn1_s_p8_2,
  126907. _vq_quantmap__44cn1_s_p8_2,
  126908. 17,
  126909. 17
  126910. };
  126911. static static_codebook _44cn1_s_p8_2 = {
  126912. 2, 289,
  126913. _vq_lengthlist__44cn1_s_p8_2,
  126914. 1, -529530880, 1611661312, 5, 0,
  126915. _vq_quantlist__44cn1_s_p8_2,
  126916. NULL,
  126917. &_vq_auxt__44cn1_s_p8_2,
  126918. NULL,
  126919. 0
  126920. };
  126921. static long _huff_lengthlist__44cn1_s_short[] = {
  126922. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126923. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126924. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126925. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126926. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126927. 10,
  126928. };
  126929. static static_codebook _huff_book__44cn1_s_short = {
  126930. 2, 81,
  126931. _huff_lengthlist__44cn1_s_short,
  126932. 0, 0, 0, 0, 0,
  126933. NULL,
  126934. NULL,
  126935. NULL,
  126936. NULL,
  126937. 0
  126938. };
  126939. static long _huff_lengthlist__44cn1_sm_long[] = {
  126940. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126941. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126942. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126943. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126944. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126945. 17,
  126946. };
  126947. static static_codebook _huff_book__44cn1_sm_long = {
  126948. 2, 81,
  126949. _huff_lengthlist__44cn1_sm_long,
  126950. 0, 0, 0, 0, 0,
  126951. NULL,
  126952. NULL,
  126953. NULL,
  126954. NULL,
  126955. 0
  126956. };
  126957. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126958. 1,
  126959. 0,
  126960. 2,
  126961. };
  126962. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126963. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126964. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126968. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126969. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126973. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126974. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127005. 0, 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, 5, 8, 8, 0, 0, 0, 0,
  127009. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  127014. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 0, 0, 7, 9, 9, 0, 0,
  127019. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 0, 0, 0, 0, 0, 0,
  127024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  127029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127055. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127060. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  127061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127064. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  127065. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  127066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127076. 0, 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,
  127374. };
  127375. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127376. -0.5, 0.5,
  127377. };
  127378. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127379. 1, 0, 2,
  127380. };
  127381. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127382. _vq_quantthresh__44cn1_sm_p1_0,
  127383. _vq_quantmap__44cn1_sm_p1_0,
  127384. 3,
  127385. 3
  127386. };
  127387. static static_codebook _44cn1_sm_p1_0 = {
  127388. 8, 6561,
  127389. _vq_lengthlist__44cn1_sm_p1_0,
  127390. 1, -535822336, 1611661312, 2, 0,
  127391. _vq_quantlist__44cn1_sm_p1_0,
  127392. NULL,
  127393. &_vq_auxt__44cn1_sm_p1_0,
  127394. NULL,
  127395. 0
  127396. };
  127397. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127398. 2,
  127399. 1,
  127400. 3,
  127401. 0,
  127402. 4,
  127403. };
  127404. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127405. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127408. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127411. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  127445. };
  127446. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127447. -1.5, -0.5, 0.5, 1.5,
  127448. };
  127449. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127450. 3, 1, 0, 2, 4,
  127451. };
  127452. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127453. _vq_quantthresh__44cn1_sm_p2_0,
  127454. _vq_quantmap__44cn1_sm_p2_0,
  127455. 5,
  127456. 5
  127457. };
  127458. static static_codebook _44cn1_sm_p2_0 = {
  127459. 4, 625,
  127460. _vq_lengthlist__44cn1_sm_p2_0,
  127461. 1, -533725184, 1611661312, 3, 0,
  127462. _vq_quantlist__44cn1_sm_p2_0,
  127463. NULL,
  127464. &_vq_auxt__44cn1_sm_p2_0,
  127465. NULL,
  127466. 0
  127467. };
  127468. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127469. 4,
  127470. 3,
  127471. 5,
  127472. 2,
  127473. 6,
  127474. 1,
  127475. 7,
  127476. 0,
  127477. 8,
  127478. };
  127479. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127480. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127481. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127482. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127483. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127484. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127485. 0,
  127486. };
  127487. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127488. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127489. };
  127490. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127491. 7, 5, 3, 1, 0, 2, 4, 6,
  127492. 8,
  127493. };
  127494. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127495. _vq_quantthresh__44cn1_sm_p3_0,
  127496. _vq_quantmap__44cn1_sm_p3_0,
  127497. 9,
  127498. 9
  127499. };
  127500. static static_codebook _44cn1_sm_p3_0 = {
  127501. 2, 81,
  127502. _vq_lengthlist__44cn1_sm_p3_0,
  127503. 1, -531628032, 1611661312, 4, 0,
  127504. _vq_quantlist__44cn1_sm_p3_0,
  127505. NULL,
  127506. &_vq_auxt__44cn1_sm_p3_0,
  127507. NULL,
  127508. 0
  127509. };
  127510. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127511. 4,
  127512. 3,
  127513. 5,
  127514. 2,
  127515. 6,
  127516. 1,
  127517. 7,
  127518. 0,
  127519. 8,
  127520. };
  127521. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127522. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127523. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127524. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127525. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127526. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127527. 11,
  127528. };
  127529. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127530. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127531. };
  127532. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127533. 7, 5, 3, 1, 0, 2, 4, 6,
  127534. 8,
  127535. };
  127536. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127537. _vq_quantthresh__44cn1_sm_p4_0,
  127538. _vq_quantmap__44cn1_sm_p4_0,
  127539. 9,
  127540. 9
  127541. };
  127542. static static_codebook _44cn1_sm_p4_0 = {
  127543. 2, 81,
  127544. _vq_lengthlist__44cn1_sm_p4_0,
  127545. 1, -531628032, 1611661312, 4, 0,
  127546. _vq_quantlist__44cn1_sm_p4_0,
  127547. NULL,
  127548. &_vq_auxt__44cn1_sm_p4_0,
  127549. NULL,
  127550. 0
  127551. };
  127552. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127553. 8,
  127554. 7,
  127555. 9,
  127556. 6,
  127557. 10,
  127558. 5,
  127559. 11,
  127560. 4,
  127561. 12,
  127562. 3,
  127563. 13,
  127564. 2,
  127565. 14,
  127566. 1,
  127567. 15,
  127568. 0,
  127569. 16,
  127570. };
  127571. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127572. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127573. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127574. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127575. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127576. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127577. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127578. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127579. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127580. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127581. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127582. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127583. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127584. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127585. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127586. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127587. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127588. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127589. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127590. 14,
  127591. };
  127592. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127593. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127594. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127595. };
  127596. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127597. 15, 13, 11, 9, 7, 5, 3, 1,
  127598. 0, 2, 4, 6, 8, 10, 12, 14,
  127599. 16,
  127600. };
  127601. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127602. _vq_quantthresh__44cn1_sm_p5_0,
  127603. _vq_quantmap__44cn1_sm_p5_0,
  127604. 17,
  127605. 17
  127606. };
  127607. static static_codebook _44cn1_sm_p5_0 = {
  127608. 2, 289,
  127609. _vq_lengthlist__44cn1_sm_p5_0,
  127610. 1, -529530880, 1611661312, 5, 0,
  127611. _vq_quantlist__44cn1_sm_p5_0,
  127612. NULL,
  127613. &_vq_auxt__44cn1_sm_p5_0,
  127614. NULL,
  127615. 0
  127616. };
  127617. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127618. 1,
  127619. 0,
  127620. 2,
  127621. };
  127622. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127623. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127624. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127625. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127626. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127627. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127628. 10,
  127629. };
  127630. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127631. -5.5, 5.5,
  127632. };
  127633. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127634. 1, 0, 2,
  127635. };
  127636. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127637. _vq_quantthresh__44cn1_sm_p6_0,
  127638. _vq_quantmap__44cn1_sm_p6_0,
  127639. 3,
  127640. 3
  127641. };
  127642. static static_codebook _44cn1_sm_p6_0 = {
  127643. 4, 81,
  127644. _vq_lengthlist__44cn1_sm_p6_0,
  127645. 1, -529137664, 1618345984, 2, 0,
  127646. _vq_quantlist__44cn1_sm_p6_0,
  127647. NULL,
  127648. &_vq_auxt__44cn1_sm_p6_0,
  127649. NULL,
  127650. 0
  127651. };
  127652. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127653. 5,
  127654. 4,
  127655. 6,
  127656. 3,
  127657. 7,
  127658. 2,
  127659. 8,
  127660. 1,
  127661. 9,
  127662. 0,
  127663. 10,
  127664. };
  127665. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127666. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127667. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127668. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127669. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127670. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127671. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127672. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127673. 10,10,10, 8, 9, 8, 8, 9, 8,
  127674. };
  127675. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127676. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127677. 3.5, 4.5,
  127678. };
  127679. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127680. 9, 7, 5, 3, 1, 0, 2, 4,
  127681. 6, 8, 10,
  127682. };
  127683. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127684. _vq_quantthresh__44cn1_sm_p6_1,
  127685. _vq_quantmap__44cn1_sm_p6_1,
  127686. 11,
  127687. 11
  127688. };
  127689. static static_codebook _44cn1_sm_p6_1 = {
  127690. 2, 121,
  127691. _vq_lengthlist__44cn1_sm_p6_1,
  127692. 1, -531365888, 1611661312, 4, 0,
  127693. _vq_quantlist__44cn1_sm_p6_1,
  127694. NULL,
  127695. &_vq_auxt__44cn1_sm_p6_1,
  127696. NULL,
  127697. 0
  127698. };
  127699. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127700. 6,
  127701. 5,
  127702. 7,
  127703. 4,
  127704. 8,
  127705. 3,
  127706. 9,
  127707. 2,
  127708. 10,
  127709. 1,
  127710. 11,
  127711. 0,
  127712. 12,
  127713. };
  127714. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127715. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127716. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127717. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127718. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127719. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127720. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127721. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127722. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127723. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127724. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127725. 0,13,12,12,12,13,13,13,14,
  127726. };
  127727. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127728. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127729. 12.5, 17.5, 22.5, 27.5,
  127730. };
  127731. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127732. 11, 9, 7, 5, 3, 1, 0, 2,
  127733. 4, 6, 8, 10, 12,
  127734. };
  127735. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127736. _vq_quantthresh__44cn1_sm_p7_0,
  127737. _vq_quantmap__44cn1_sm_p7_0,
  127738. 13,
  127739. 13
  127740. };
  127741. static static_codebook _44cn1_sm_p7_0 = {
  127742. 2, 169,
  127743. _vq_lengthlist__44cn1_sm_p7_0,
  127744. 1, -526516224, 1616117760, 4, 0,
  127745. _vq_quantlist__44cn1_sm_p7_0,
  127746. NULL,
  127747. &_vq_auxt__44cn1_sm_p7_0,
  127748. NULL,
  127749. 0
  127750. };
  127751. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127752. 2,
  127753. 1,
  127754. 3,
  127755. 0,
  127756. 4,
  127757. };
  127758. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127759. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127760. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127761. };
  127762. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127763. -1.5, -0.5, 0.5, 1.5,
  127764. };
  127765. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127766. 3, 1, 0, 2, 4,
  127767. };
  127768. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127769. _vq_quantthresh__44cn1_sm_p7_1,
  127770. _vq_quantmap__44cn1_sm_p7_1,
  127771. 5,
  127772. 5
  127773. };
  127774. static static_codebook _44cn1_sm_p7_1 = {
  127775. 2, 25,
  127776. _vq_lengthlist__44cn1_sm_p7_1,
  127777. 1, -533725184, 1611661312, 3, 0,
  127778. _vq_quantlist__44cn1_sm_p7_1,
  127779. NULL,
  127780. &_vq_auxt__44cn1_sm_p7_1,
  127781. NULL,
  127782. 0
  127783. };
  127784. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127785. 4,
  127786. 3,
  127787. 5,
  127788. 2,
  127789. 6,
  127790. 1,
  127791. 7,
  127792. 0,
  127793. 8,
  127794. };
  127795. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127796. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127797. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127798. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127799. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127800. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127801. 14,
  127802. };
  127803. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127804. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127805. };
  127806. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127807. 7, 5, 3, 1, 0, 2, 4, 6,
  127808. 8,
  127809. };
  127810. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127811. _vq_quantthresh__44cn1_sm_p8_0,
  127812. _vq_quantmap__44cn1_sm_p8_0,
  127813. 9,
  127814. 9
  127815. };
  127816. static static_codebook _44cn1_sm_p8_0 = {
  127817. 2, 81,
  127818. _vq_lengthlist__44cn1_sm_p8_0,
  127819. 1, -516186112, 1627103232, 4, 0,
  127820. _vq_quantlist__44cn1_sm_p8_0,
  127821. NULL,
  127822. &_vq_auxt__44cn1_sm_p8_0,
  127823. NULL,
  127824. 0
  127825. };
  127826. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127827. 6,
  127828. 5,
  127829. 7,
  127830. 4,
  127831. 8,
  127832. 3,
  127833. 9,
  127834. 2,
  127835. 10,
  127836. 1,
  127837. 11,
  127838. 0,
  127839. 12,
  127840. };
  127841. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127842. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127843. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127844. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127845. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127846. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127847. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127848. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127849. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127850. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127851. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127852. 17,12,12,11,10,13,11,13,13,
  127853. };
  127854. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127855. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127856. 42.5, 59.5, 76.5, 93.5,
  127857. };
  127858. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127859. 11, 9, 7, 5, 3, 1, 0, 2,
  127860. 4, 6, 8, 10, 12,
  127861. };
  127862. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127863. _vq_quantthresh__44cn1_sm_p8_1,
  127864. _vq_quantmap__44cn1_sm_p8_1,
  127865. 13,
  127866. 13
  127867. };
  127868. static static_codebook _44cn1_sm_p8_1 = {
  127869. 2, 169,
  127870. _vq_lengthlist__44cn1_sm_p8_1,
  127871. 1, -522616832, 1620115456, 4, 0,
  127872. _vq_quantlist__44cn1_sm_p8_1,
  127873. NULL,
  127874. &_vq_auxt__44cn1_sm_p8_1,
  127875. NULL,
  127876. 0
  127877. };
  127878. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127879. 8,
  127880. 7,
  127881. 9,
  127882. 6,
  127883. 10,
  127884. 5,
  127885. 11,
  127886. 4,
  127887. 12,
  127888. 3,
  127889. 13,
  127890. 2,
  127891. 14,
  127892. 1,
  127893. 15,
  127894. 0,
  127895. 16,
  127896. };
  127897. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127898. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127899. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127900. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127901. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127902. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127903. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127904. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127905. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127906. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127907. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127908. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127909. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127910. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127911. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127912. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127913. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127914. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127915. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127916. 9,
  127917. };
  127918. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127919. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127920. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127921. };
  127922. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127923. 15, 13, 11, 9, 7, 5, 3, 1,
  127924. 0, 2, 4, 6, 8, 10, 12, 14,
  127925. 16,
  127926. };
  127927. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127928. _vq_quantthresh__44cn1_sm_p8_2,
  127929. _vq_quantmap__44cn1_sm_p8_2,
  127930. 17,
  127931. 17
  127932. };
  127933. static static_codebook _44cn1_sm_p8_2 = {
  127934. 2, 289,
  127935. _vq_lengthlist__44cn1_sm_p8_2,
  127936. 1, -529530880, 1611661312, 5, 0,
  127937. _vq_quantlist__44cn1_sm_p8_2,
  127938. NULL,
  127939. &_vq_auxt__44cn1_sm_p8_2,
  127940. NULL,
  127941. 0
  127942. };
  127943. static long _huff_lengthlist__44cn1_sm_short[] = {
  127944. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127945. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127946. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127947. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127948. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127949. 9,
  127950. };
  127951. static static_codebook _huff_book__44cn1_sm_short = {
  127952. 2, 81,
  127953. _huff_lengthlist__44cn1_sm_short,
  127954. 0, 0, 0, 0, 0,
  127955. NULL,
  127956. NULL,
  127957. NULL,
  127958. NULL,
  127959. 0
  127960. };
  127961. /*** End of inlined file: res_books_stereo.h ***/
  127962. static vorbis_info_residue0 _residue_44_low={
  127963. 0,-1, -1, 9,-1,
  127964. {0},
  127965. {-1},
  127966. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127967. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127968. };
  127969. static vorbis_info_residue0 _residue_44_mid={
  127970. 0,-1, -1, 10,-1,
  127971. {0},
  127972. {-1},
  127973. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127974. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127975. };
  127976. static vorbis_info_residue0 _residue_44_high={
  127977. 0,-1, -1, 10,-1,
  127978. {0},
  127979. {-1},
  127980. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127981. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127982. };
  127983. static static_bookblock _resbook_44s_n1={
  127984. {
  127985. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127986. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127987. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127988. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127989. }
  127990. };
  127991. static static_bookblock _resbook_44sm_n1={
  127992. {
  127993. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127994. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127995. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127996. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127997. }
  127998. };
  127999. static static_bookblock _resbook_44s_0={
  128000. {
  128001. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  128002. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  128003. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  128004. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  128005. }
  128006. };
  128007. static static_bookblock _resbook_44sm_0={
  128008. {
  128009. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  128010. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  128011. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  128012. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  128013. }
  128014. };
  128015. static static_bookblock _resbook_44s_1={
  128016. {
  128017. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  128018. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  128019. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  128020. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  128021. }
  128022. };
  128023. static static_bookblock _resbook_44sm_1={
  128024. {
  128025. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  128026. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  128027. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  128028. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  128029. }
  128030. };
  128031. static static_bookblock _resbook_44s_2={
  128032. {
  128033. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  128034. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  128035. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  128036. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  128037. }
  128038. };
  128039. static static_bookblock _resbook_44s_3={
  128040. {
  128041. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  128042. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  128043. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  128044. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  128045. }
  128046. };
  128047. static static_bookblock _resbook_44s_4={
  128048. {
  128049. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  128050. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  128051. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  128052. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  128053. }
  128054. };
  128055. static static_bookblock _resbook_44s_5={
  128056. {
  128057. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  128058. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  128059. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  128060. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  128061. }
  128062. };
  128063. static static_bookblock _resbook_44s_6={
  128064. {
  128065. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  128066. {0,0,&_44c6_s_p4_0},
  128067. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  128068. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  128069. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  128070. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  128071. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  128072. }
  128073. };
  128074. static static_bookblock _resbook_44s_7={
  128075. {
  128076. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  128077. {0,0,&_44c7_s_p4_0},
  128078. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  128079. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  128080. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  128081. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  128082. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  128083. }
  128084. };
  128085. static static_bookblock _resbook_44s_8={
  128086. {
  128087. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  128088. {0,0,&_44c8_s_p4_0},
  128089. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  128090. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  128091. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  128092. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  128093. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  128094. }
  128095. };
  128096. static static_bookblock _resbook_44s_9={
  128097. {
  128098. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  128099. {0,0,&_44c9_s_p4_0},
  128100. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  128101. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  128102. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  128103. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  128104. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  128105. }
  128106. };
  128107. static vorbis_residue_template _res_44s_n1[]={
  128108. {2,0, &_residue_44_low,
  128109. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  128110. &_resbook_44s_n1,&_resbook_44sm_n1},
  128111. {2,0, &_residue_44_low,
  128112. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  128113. &_resbook_44s_n1,&_resbook_44sm_n1}
  128114. };
  128115. static vorbis_residue_template _res_44s_0[]={
  128116. {2,0, &_residue_44_low,
  128117. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  128118. &_resbook_44s_0,&_resbook_44sm_0},
  128119. {2,0, &_residue_44_low,
  128120. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  128121. &_resbook_44s_0,&_resbook_44sm_0}
  128122. };
  128123. static vorbis_residue_template _res_44s_1[]={
  128124. {2,0, &_residue_44_low,
  128125. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  128126. &_resbook_44s_1,&_resbook_44sm_1},
  128127. {2,0, &_residue_44_low,
  128128. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  128129. &_resbook_44s_1,&_resbook_44sm_1}
  128130. };
  128131. static vorbis_residue_template _res_44s_2[]={
  128132. {2,0, &_residue_44_mid,
  128133. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  128134. &_resbook_44s_2,&_resbook_44s_2},
  128135. {2,0, &_residue_44_mid,
  128136. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  128137. &_resbook_44s_2,&_resbook_44s_2}
  128138. };
  128139. static vorbis_residue_template _res_44s_3[]={
  128140. {2,0, &_residue_44_mid,
  128141. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  128142. &_resbook_44s_3,&_resbook_44s_3},
  128143. {2,0, &_residue_44_mid,
  128144. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  128145. &_resbook_44s_3,&_resbook_44s_3}
  128146. };
  128147. static vorbis_residue_template _res_44s_4[]={
  128148. {2,0, &_residue_44_mid,
  128149. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  128150. &_resbook_44s_4,&_resbook_44s_4},
  128151. {2,0, &_residue_44_mid,
  128152. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  128153. &_resbook_44s_4,&_resbook_44s_4}
  128154. };
  128155. static vorbis_residue_template _res_44s_5[]={
  128156. {2,0, &_residue_44_mid,
  128157. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  128158. &_resbook_44s_5,&_resbook_44s_5},
  128159. {2,0, &_residue_44_mid,
  128160. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  128161. &_resbook_44s_5,&_resbook_44s_5}
  128162. };
  128163. static vorbis_residue_template _res_44s_6[]={
  128164. {2,0, &_residue_44_high,
  128165. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  128166. &_resbook_44s_6,&_resbook_44s_6},
  128167. {2,0, &_residue_44_high,
  128168. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  128169. &_resbook_44s_6,&_resbook_44s_6}
  128170. };
  128171. static vorbis_residue_template _res_44s_7[]={
  128172. {2,0, &_residue_44_high,
  128173. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  128174. &_resbook_44s_7,&_resbook_44s_7},
  128175. {2,0, &_residue_44_high,
  128176. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  128177. &_resbook_44s_7,&_resbook_44s_7}
  128178. };
  128179. static vorbis_residue_template _res_44s_8[]={
  128180. {2,0, &_residue_44_high,
  128181. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  128182. &_resbook_44s_8,&_resbook_44s_8},
  128183. {2,0, &_residue_44_high,
  128184. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  128185. &_resbook_44s_8,&_resbook_44s_8}
  128186. };
  128187. static vorbis_residue_template _res_44s_9[]={
  128188. {2,0, &_residue_44_high,
  128189. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  128190. &_resbook_44s_9,&_resbook_44s_9},
  128191. {2,0, &_residue_44_high,
  128192. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  128193. &_resbook_44s_9,&_resbook_44s_9}
  128194. };
  128195. static vorbis_mapping_template _mapres_template_44_stereo[]={
  128196. { _map_nominal, _res_44s_n1 }, /* -1 */
  128197. { _map_nominal, _res_44s_0 }, /* 0 */
  128198. { _map_nominal, _res_44s_1 }, /* 1 */
  128199. { _map_nominal, _res_44s_2 }, /* 2 */
  128200. { _map_nominal, _res_44s_3 }, /* 3 */
  128201. { _map_nominal, _res_44s_4 }, /* 4 */
  128202. { _map_nominal, _res_44s_5 }, /* 5 */
  128203. { _map_nominal, _res_44s_6 }, /* 6 */
  128204. { _map_nominal, _res_44s_7 }, /* 7 */
  128205. { _map_nominal, _res_44s_8 }, /* 8 */
  128206. { _map_nominal, _res_44s_9 }, /* 9 */
  128207. };
  128208. /*** End of inlined file: residue_44.h ***/
  128209. /*** Start of inlined file: psych_44.h ***/
  128210. static vorbis_info_psy_global _psy_global_44[5]={
  128211. {8, /* lines per eighth octave */
  128212. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  128213. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  128214. -6.f,
  128215. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128216. },
  128217. {8, /* lines per eighth octave */
  128218. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128219. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  128220. -6.f,
  128221. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128222. },
  128223. {8, /* lines per eighth octave */
  128224. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128225. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  128226. -6.f,
  128227. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128228. },
  128229. {8, /* lines per eighth octave */
  128230. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  128231. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  128232. -6.f,
  128233. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128234. },
  128235. {8, /* lines per eighth octave */
  128236. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  128237. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  128238. -6.f,
  128239. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128240. },
  128241. };
  128242. static compandblock _psy_compand_44[6]={
  128243. {{
  128244. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128245. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128246. 16,17,18,19,20,21,22, 23, /* 23dB */
  128247. 24,25,26,27,28,29,30, 31, /* 31dB */
  128248. 32,33,34,35,36,37,38, 39, /* 39dB */
  128249. }},
  128250. {{
  128251. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  128252. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  128253. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  128254. 15,16,17,17,17,18,18, 19, /* 31dB */
  128255. 19,19,20,21,22,23,24, 25, /* 39dB */
  128256. }},
  128257. {{
  128258. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  128259. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  128260. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128261. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128262. 11,12,13,14,15,16,17, 18, /* 39dB */
  128263. }},
  128264. {{
  128265. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128266. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128267. 16,17,18,19,20,21,22, 23, /* 23dB */
  128268. 24,25,26,27,28,29,30, 31, /* 31dB */
  128269. 32,33,34,35,36,37,38, 39, /* 39dB */
  128270. }},
  128271. {{
  128272. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128273. 8, 9,10,11,12,12,13, 13, /* 15dB */
  128274. 13,14,14,14,15,15,15, 15, /* 23dB */
  128275. 16,16,17,17,17,18,18, 19, /* 31dB */
  128276. 19,19,20,21,22,23,24, 25, /* 39dB */
  128277. }},
  128278. {{
  128279. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128280. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  128281. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128282. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128283. 11,12,13,14,15,16,17, 18, /* 39dB */
  128284. }}
  128285. };
  128286. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128287. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128288. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128289. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128290. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128291. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128292. /* 4 */
  128293. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128294. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128295. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128296. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128297. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128298. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128299. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128300. };
  128301. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128302. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128303. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128304. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128305. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128306. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128307. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128308. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128309. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128310. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128311. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128312. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128313. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128314. };
  128315. static noise3 _psy_noisebias_trans[12]={
  128316. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128317. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128318. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128319. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128320. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128321. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128322. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128323. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128324. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128325. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128326. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128327. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128328. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128329. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128330. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128331. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128332. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128333. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128334. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128335. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128336. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128337. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128338. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128339. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128340. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128341. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128342. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128343. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128344. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128345. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128346. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128347. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128348. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128349. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128350. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128351. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128352. };
  128353. static noise3 _psy_noisebias_long[12]={
  128354. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128355. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128356. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128357. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128358. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128359. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128360. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128361. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128362. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128363. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128364. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128365. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128366. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128367. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128368. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128369. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128370. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128371. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128372. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128373. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128374. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128375. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128376. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128377. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128378. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128379. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128380. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128381. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128382. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128383. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128384. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128385. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128386. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128387. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128388. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128389. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128390. };
  128391. static noise3 _psy_noisebias_impulse[12]={
  128392. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128393. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128394. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128395. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128396. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128397. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128398. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128399. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128400. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128401. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128402. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128403. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128404. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128405. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128406. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128407. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128408. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128409. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128410. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128411. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128412. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128413. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128414. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128415. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128416. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128417. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128418. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128419. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128420. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128421. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128422. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128423. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128424. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128425. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128426. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128427. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128428. };
  128429. static noise3 _psy_noisebias_padding[12]={
  128430. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128431. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128432. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128433. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128434. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128435. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128436. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128437. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128438. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128439. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128440. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128441. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128442. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128443. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128444. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128445. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128446. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128447. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128448. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128449. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128450. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128451. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128452. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128453. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128454. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128455. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128456. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128457. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128458. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128459. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128460. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128461. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128462. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128463. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128464. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128465. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128466. };
  128467. static noiseguard _psy_noiseguards_44[4]={
  128468. {3,3,15},
  128469. {3,3,15},
  128470. {10,10,100},
  128471. {10,10,100},
  128472. };
  128473. static int _psy_tone_suppress[12]={
  128474. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128475. };
  128476. static int _psy_tone_0dB[12]={
  128477. 90,90,95,95,95,95,105,105,105,105,105,105,
  128478. };
  128479. static int _psy_noise_suppress[12]={
  128480. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128481. };
  128482. static vorbis_info_psy _psy_info_template={
  128483. -1,
  128484. -140.,-140.,
  128485. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128486. 1, -0.f, .5f, .5f, 0,0,0,
  128487. {{-1},{-1},{-1}},{-1},105.f,
  128488. 0,0,-1,-1,0.,
  128489. };
  128490. static int _psy_ath_floater[12]={
  128491. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128492. };
  128493. static int _psy_ath_abs[12]={
  128494. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128495. };
  128496. static adj_stereo _psy_stereo_modes_44[12]={
  128497. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128498. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128499. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128500. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128501. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128502. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128503. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128504. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128505. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128506. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128507. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128508. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128509. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128510. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128511. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128512. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128513. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128514. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128515. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128516. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128517. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128518. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128519. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128520. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128521. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128522. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128523. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128524. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128525. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128526. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128527. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128528. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128529. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128530. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128531. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128532. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128533. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128534. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128535. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128536. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128537. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128538. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128539. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128540. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128541. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128542. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128543. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128544. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128545. };
  128546. static att3 _psy_tone_masteratt_44[12]={
  128547. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128548. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128549. /* 1 */
  128550. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128551. /* 2 */
  128552. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128553. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128554. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128555. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128556. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128557. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128558. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128559. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128560. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128561. };
  128562. static double _psy_lowpass_44[12]={
  128563. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128564. };
  128565. static int _noise_start_short_44[11]={
  128566. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128567. };
  128568. static int _noise_start_long_44[11]={
  128569. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128570. };
  128571. static int _noise_part_short_44[11]={
  128572. 8,8,8,8,8,8,8,8,8,8,8
  128573. };
  128574. static int _noise_part_long_44[11]={
  128575. 32,32,32,32,32,32,32,32,32,32,32
  128576. };
  128577. static double _noise_thresh_44[11]={
  128578. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128579. };
  128580. static double _noise_thresh_5only[2]={
  128581. .5,.5,
  128582. };
  128583. /*** End of inlined file: psych_44.h ***/
  128584. static double rate_mapping_44_stereo[12]={
  128585. 22500.,32000.,40000.,48000.,56000.,64000.,
  128586. 80000.,96000.,112000.,128000.,160000.,250001.
  128587. };
  128588. static double quality_mapping_44[12]={
  128589. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128590. };
  128591. static int blocksize_short_44[11]={
  128592. 512,256,256,256,256,256,256,256,256,256,256
  128593. };
  128594. static int blocksize_long_44[11]={
  128595. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128596. };
  128597. static double _psy_compand_short_mapping[12]={
  128598. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128599. };
  128600. static double _psy_compand_long_mapping[12]={
  128601. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128602. };
  128603. static double _global_mapping_44[12]={
  128604. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128605. };
  128606. static int _floor_short_mapping_44[11]={
  128607. 1,0,0,2,2,4,5,5,5,5,5
  128608. };
  128609. static int _floor_long_mapping_44[11]={
  128610. 8,7,7,7,7,7,7,7,7,7,7
  128611. };
  128612. ve_setup_data_template ve_setup_44_stereo={
  128613. 11,
  128614. rate_mapping_44_stereo,
  128615. quality_mapping_44,
  128616. 2,
  128617. 40000,
  128618. 50000,
  128619. blocksize_short_44,
  128620. blocksize_long_44,
  128621. _psy_tone_masteratt_44,
  128622. _psy_tone_0dB,
  128623. _psy_tone_suppress,
  128624. _vp_tonemask_adj_otherblock,
  128625. _vp_tonemask_adj_longblock,
  128626. _vp_tonemask_adj_otherblock,
  128627. _psy_noiseguards_44,
  128628. _psy_noisebias_impulse,
  128629. _psy_noisebias_padding,
  128630. _psy_noisebias_trans,
  128631. _psy_noisebias_long,
  128632. _psy_noise_suppress,
  128633. _psy_compand_44,
  128634. _psy_compand_short_mapping,
  128635. _psy_compand_long_mapping,
  128636. {_noise_start_short_44,_noise_start_long_44},
  128637. {_noise_part_short_44,_noise_part_long_44},
  128638. _noise_thresh_44,
  128639. _psy_ath_floater,
  128640. _psy_ath_abs,
  128641. _psy_lowpass_44,
  128642. _psy_global_44,
  128643. _global_mapping_44,
  128644. _psy_stereo_modes_44,
  128645. _floor_books,
  128646. _floor,
  128647. _floor_short_mapping_44,
  128648. _floor_long_mapping_44,
  128649. _mapres_template_44_stereo
  128650. };
  128651. /*** End of inlined file: setup_44.h ***/
  128652. /*** Start of inlined file: setup_44u.h ***/
  128653. /*** Start of inlined file: residue_44u.h ***/
  128654. /*** Start of inlined file: res_books_uncoupled.h ***/
  128655. static long _vq_quantlist__16u0__p1_0[] = {
  128656. 1,
  128657. 0,
  128658. 2,
  128659. };
  128660. static long _vq_lengthlist__16u0__p1_0[] = {
  128661. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128662. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128663. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128664. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128665. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128666. 12,
  128667. };
  128668. static float _vq_quantthresh__16u0__p1_0[] = {
  128669. -0.5, 0.5,
  128670. };
  128671. static long _vq_quantmap__16u0__p1_0[] = {
  128672. 1, 0, 2,
  128673. };
  128674. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128675. _vq_quantthresh__16u0__p1_0,
  128676. _vq_quantmap__16u0__p1_0,
  128677. 3,
  128678. 3
  128679. };
  128680. static static_codebook _16u0__p1_0 = {
  128681. 4, 81,
  128682. _vq_lengthlist__16u0__p1_0,
  128683. 1, -535822336, 1611661312, 2, 0,
  128684. _vq_quantlist__16u0__p1_0,
  128685. NULL,
  128686. &_vq_auxt__16u0__p1_0,
  128687. NULL,
  128688. 0
  128689. };
  128690. static long _vq_quantlist__16u0__p2_0[] = {
  128691. 1,
  128692. 0,
  128693. 2,
  128694. };
  128695. static long _vq_lengthlist__16u0__p2_0[] = {
  128696. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128697. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128698. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128699. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128700. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128701. 8,
  128702. };
  128703. static float _vq_quantthresh__16u0__p2_0[] = {
  128704. -0.5, 0.5,
  128705. };
  128706. static long _vq_quantmap__16u0__p2_0[] = {
  128707. 1, 0, 2,
  128708. };
  128709. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128710. _vq_quantthresh__16u0__p2_0,
  128711. _vq_quantmap__16u0__p2_0,
  128712. 3,
  128713. 3
  128714. };
  128715. static static_codebook _16u0__p2_0 = {
  128716. 4, 81,
  128717. _vq_lengthlist__16u0__p2_0,
  128718. 1, -535822336, 1611661312, 2, 0,
  128719. _vq_quantlist__16u0__p2_0,
  128720. NULL,
  128721. &_vq_auxt__16u0__p2_0,
  128722. NULL,
  128723. 0
  128724. };
  128725. static long _vq_quantlist__16u0__p3_0[] = {
  128726. 2,
  128727. 1,
  128728. 3,
  128729. 0,
  128730. 4,
  128731. };
  128732. static long _vq_lengthlist__16u0__p3_0[] = {
  128733. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128734. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128735. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128736. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128737. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128738. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128739. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128740. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128741. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128742. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128743. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128744. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128745. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128746. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128747. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128748. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128749. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128750. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128751. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128752. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128753. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128754. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128755. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128756. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128757. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128758. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128759. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128760. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128761. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128762. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128763. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128764. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128765. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128766. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128767. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128768. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128769. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128770. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128771. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128772. 18,
  128773. };
  128774. static float _vq_quantthresh__16u0__p3_0[] = {
  128775. -1.5, -0.5, 0.5, 1.5,
  128776. };
  128777. static long _vq_quantmap__16u0__p3_0[] = {
  128778. 3, 1, 0, 2, 4,
  128779. };
  128780. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128781. _vq_quantthresh__16u0__p3_0,
  128782. _vq_quantmap__16u0__p3_0,
  128783. 5,
  128784. 5
  128785. };
  128786. static static_codebook _16u0__p3_0 = {
  128787. 4, 625,
  128788. _vq_lengthlist__16u0__p3_0,
  128789. 1, -533725184, 1611661312, 3, 0,
  128790. _vq_quantlist__16u0__p3_0,
  128791. NULL,
  128792. &_vq_auxt__16u0__p3_0,
  128793. NULL,
  128794. 0
  128795. };
  128796. static long _vq_quantlist__16u0__p4_0[] = {
  128797. 2,
  128798. 1,
  128799. 3,
  128800. 0,
  128801. 4,
  128802. };
  128803. static long _vq_lengthlist__16u0__p4_0[] = {
  128804. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128805. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128806. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128807. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128808. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128809. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128810. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128811. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128812. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128813. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128814. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128815. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128816. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128817. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128818. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128819. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128820. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128821. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128822. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128823. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128824. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128825. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128826. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128827. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128828. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128829. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128830. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128831. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128832. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128833. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128834. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128835. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128836. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128837. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128838. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128839. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128840. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128841. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128842. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128843. 11,
  128844. };
  128845. static float _vq_quantthresh__16u0__p4_0[] = {
  128846. -1.5, -0.5, 0.5, 1.5,
  128847. };
  128848. static long _vq_quantmap__16u0__p4_0[] = {
  128849. 3, 1, 0, 2, 4,
  128850. };
  128851. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128852. _vq_quantthresh__16u0__p4_0,
  128853. _vq_quantmap__16u0__p4_0,
  128854. 5,
  128855. 5
  128856. };
  128857. static static_codebook _16u0__p4_0 = {
  128858. 4, 625,
  128859. _vq_lengthlist__16u0__p4_0,
  128860. 1, -533725184, 1611661312, 3, 0,
  128861. _vq_quantlist__16u0__p4_0,
  128862. NULL,
  128863. &_vq_auxt__16u0__p4_0,
  128864. NULL,
  128865. 0
  128866. };
  128867. static long _vq_quantlist__16u0__p5_0[] = {
  128868. 4,
  128869. 3,
  128870. 5,
  128871. 2,
  128872. 6,
  128873. 1,
  128874. 7,
  128875. 0,
  128876. 8,
  128877. };
  128878. static long _vq_lengthlist__16u0__p5_0[] = {
  128879. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128880. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128881. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128882. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128883. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128884. 12,
  128885. };
  128886. static float _vq_quantthresh__16u0__p5_0[] = {
  128887. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128888. };
  128889. static long _vq_quantmap__16u0__p5_0[] = {
  128890. 7, 5, 3, 1, 0, 2, 4, 6,
  128891. 8,
  128892. };
  128893. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128894. _vq_quantthresh__16u0__p5_0,
  128895. _vq_quantmap__16u0__p5_0,
  128896. 9,
  128897. 9
  128898. };
  128899. static static_codebook _16u0__p5_0 = {
  128900. 2, 81,
  128901. _vq_lengthlist__16u0__p5_0,
  128902. 1, -531628032, 1611661312, 4, 0,
  128903. _vq_quantlist__16u0__p5_0,
  128904. NULL,
  128905. &_vq_auxt__16u0__p5_0,
  128906. NULL,
  128907. 0
  128908. };
  128909. static long _vq_quantlist__16u0__p6_0[] = {
  128910. 6,
  128911. 5,
  128912. 7,
  128913. 4,
  128914. 8,
  128915. 3,
  128916. 9,
  128917. 2,
  128918. 10,
  128919. 1,
  128920. 11,
  128921. 0,
  128922. 12,
  128923. };
  128924. static long _vq_lengthlist__16u0__p6_0[] = {
  128925. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128926. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128927. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128928. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128929. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128930. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128931. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128932. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128933. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128934. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128935. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128936. };
  128937. static float _vq_quantthresh__16u0__p6_0[] = {
  128938. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128939. 12.5, 17.5, 22.5, 27.5,
  128940. };
  128941. static long _vq_quantmap__16u0__p6_0[] = {
  128942. 11, 9, 7, 5, 3, 1, 0, 2,
  128943. 4, 6, 8, 10, 12,
  128944. };
  128945. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128946. _vq_quantthresh__16u0__p6_0,
  128947. _vq_quantmap__16u0__p6_0,
  128948. 13,
  128949. 13
  128950. };
  128951. static static_codebook _16u0__p6_0 = {
  128952. 2, 169,
  128953. _vq_lengthlist__16u0__p6_0,
  128954. 1, -526516224, 1616117760, 4, 0,
  128955. _vq_quantlist__16u0__p6_0,
  128956. NULL,
  128957. &_vq_auxt__16u0__p6_0,
  128958. NULL,
  128959. 0
  128960. };
  128961. static long _vq_quantlist__16u0__p6_1[] = {
  128962. 2,
  128963. 1,
  128964. 3,
  128965. 0,
  128966. 4,
  128967. };
  128968. static long _vq_lengthlist__16u0__p6_1[] = {
  128969. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128970. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128971. };
  128972. static float _vq_quantthresh__16u0__p6_1[] = {
  128973. -1.5, -0.5, 0.5, 1.5,
  128974. };
  128975. static long _vq_quantmap__16u0__p6_1[] = {
  128976. 3, 1, 0, 2, 4,
  128977. };
  128978. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128979. _vq_quantthresh__16u0__p6_1,
  128980. _vq_quantmap__16u0__p6_1,
  128981. 5,
  128982. 5
  128983. };
  128984. static static_codebook _16u0__p6_1 = {
  128985. 2, 25,
  128986. _vq_lengthlist__16u0__p6_1,
  128987. 1, -533725184, 1611661312, 3, 0,
  128988. _vq_quantlist__16u0__p6_1,
  128989. NULL,
  128990. &_vq_auxt__16u0__p6_1,
  128991. NULL,
  128992. 0
  128993. };
  128994. static long _vq_quantlist__16u0__p7_0[] = {
  128995. 1,
  128996. 0,
  128997. 2,
  128998. };
  128999. static long _vq_lengthlist__16u0__p7_0[] = {
  129000. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129001. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129002. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129003. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129004. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129005. 7,
  129006. };
  129007. static float _vq_quantthresh__16u0__p7_0[] = {
  129008. -157.5, 157.5,
  129009. };
  129010. static long _vq_quantmap__16u0__p7_0[] = {
  129011. 1, 0, 2,
  129012. };
  129013. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  129014. _vq_quantthresh__16u0__p7_0,
  129015. _vq_quantmap__16u0__p7_0,
  129016. 3,
  129017. 3
  129018. };
  129019. static static_codebook _16u0__p7_0 = {
  129020. 4, 81,
  129021. _vq_lengthlist__16u0__p7_0,
  129022. 1, -518803456, 1628680192, 2, 0,
  129023. _vq_quantlist__16u0__p7_0,
  129024. NULL,
  129025. &_vq_auxt__16u0__p7_0,
  129026. NULL,
  129027. 0
  129028. };
  129029. static long _vq_quantlist__16u0__p7_1[] = {
  129030. 7,
  129031. 6,
  129032. 8,
  129033. 5,
  129034. 9,
  129035. 4,
  129036. 10,
  129037. 3,
  129038. 11,
  129039. 2,
  129040. 12,
  129041. 1,
  129042. 13,
  129043. 0,
  129044. 14,
  129045. };
  129046. static long _vq_lengthlist__16u0__p7_1[] = {
  129047. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  129048. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  129049. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  129050. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  129051. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  129052. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  129053. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129054. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129055. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129056. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129057. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129058. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129059. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129060. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129061. 10,
  129062. };
  129063. static float _vq_quantthresh__16u0__p7_1[] = {
  129064. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129065. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129066. };
  129067. static long _vq_quantmap__16u0__p7_1[] = {
  129068. 13, 11, 9, 7, 5, 3, 1, 0,
  129069. 2, 4, 6, 8, 10, 12, 14,
  129070. };
  129071. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  129072. _vq_quantthresh__16u0__p7_1,
  129073. _vq_quantmap__16u0__p7_1,
  129074. 15,
  129075. 15
  129076. };
  129077. static static_codebook _16u0__p7_1 = {
  129078. 2, 225,
  129079. _vq_lengthlist__16u0__p7_1,
  129080. 1, -520986624, 1620377600, 4, 0,
  129081. _vq_quantlist__16u0__p7_1,
  129082. NULL,
  129083. &_vq_auxt__16u0__p7_1,
  129084. NULL,
  129085. 0
  129086. };
  129087. static long _vq_quantlist__16u0__p7_2[] = {
  129088. 10,
  129089. 9,
  129090. 11,
  129091. 8,
  129092. 12,
  129093. 7,
  129094. 13,
  129095. 6,
  129096. 14,
  129097. 5,
  129098. 15,
  129099. 4,
  129100. 16,
  129101. 3,
  129102. 17,
  129103. 2,
  129104. 18,
  129105. 1,
  129106. 19,
  129107. 0,
  129108. 20,
  129109. };
  129110. static long _vq_lengthlist__16u0__p7_2[] = {
  129111. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  129112. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  129113. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  129114. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  129115. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  129116. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  129117. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  129118. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  129119. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  129120. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  129121. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  129122. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  129123. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  129124. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  129125. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  129126. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  129127. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  129128. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  129129. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  129130. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  129131. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  129132. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  129133. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  129134. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  129135. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  129136. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  129137. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  129138. 10,10,12,11,10,11,11,11,10,
  129139. };
  129140. static float _vq_quantthresh__16u0__p7_2[] = {
  129141. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  129142. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  129143. 6.5, 7.5, 8.5, 9.5,
  129144. };
  129145. static long _vq_quantmap__16u0__p7_2[] = {
  129146. 19, 17, 15, 13, 11, 9, 7, 5,
  129147. 3, 1, 0, 2, 4, 6, 8, 10,
  129148. 12, 14, 16, 18, 20,
  129149. };
  129150. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  129151. _vq_quantthresh__16u0__p7_2,
  129152. _vq_quantmap__16u0__p7_2,
  129153. 21,
  129154. 21
  129155. };
  129156. static static_codebook _16u0__p7_2 = {
  129157. 2, 441,
  129158. _vq_lengthlist__16u0__p7_2,
  129159. 1, -529268736, 1611661312, 5, 0,
  129160. _vq_quantlist__16u0__p7_2,
  129161. NULL,
  129162. &_vq_auxt__16u0__p7_2,
  129163. NULL,
  129164. 0
  129165. };
  129166. static long _huff_lengthlist__16u0__single[] = {
  129167. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  129168. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  129169. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  129170. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  129171. };
  129172. static static_codebook _huff_book__16u0__single = {
  129173. 2, 64,
  129174. _huff_lengthlist__16u0__single,
  129175. 0, 0, 0, 0, 0,
  129176. NULL,
  129177. NULL,
  129178. NULL,
  129179. NULL,
  129180. 0
  129181. };
  129182. static long _huff_lengthlist__16u1__long[] = {
  129183. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  129184. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  129185. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  129186. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  129187. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  129188. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  129189. 16,13,16,18,
  129190. };
  129191. static static_codebook _huff_book__16u1__long = {
  129192. 2, 100,
  129193. _huff_lengthlist__16u1__long,
  129194. 0, 0, 0, 0, 0,
  129195. NULL,
  129196. NULL,
  129197. NULL,
  129198. NULL,
  129199. 0
  129200. };
  129201. static long _vq_quantlist__16u1__p1_0[] = {
  129202. 1,
  129203. 0,
  129204. 2,
  129205. };
  129206. static long _vq_lengthlist__16u1__p1_0[] = {
  129207. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  129208. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  129209. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  129210. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  129211. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  129212. 11,
  129213. };
  129214. static float _vq_quantthresh__16u1__p1_0[] = {
  129215. -0.5, 0.5,
  129216. };
  129217. static long _vq_quantmap__16u1__p1_0[] = {
  129218. 1, 0, 2,
  129219. };
  129220. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  129221. _vq_quantthresh__16u1__p1_0,
  129222. _vq_quantmap__16u1__p1_0,
  129223. 3,
  129224. 3
  129225. };
  129226. static static_codebook _16u1__p1_0 = {
  129227. 4, 81,
  129228. _vq_lengthlist__16u1__p1_0,
  129229. 1, -535822336, 1611661312, 2, 0,
  129230. _vq_quantlist__16u1__p1_0,
  129231. NULL,
  129232. &_vq_auxt__16u1__p1_0,
  129233. NULL,
  129234. 0
  129235. };
  129236. static long _vq_quantlist__16u1__p2_0[] = {
  129237. 1,
  129238. 0,
  129239. 2,
  129240. };
  129241. static long _vq_lengthlist__16u1__p2_0[] = {
  129242. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  129243. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  129244. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  129245. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  129246. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  129247. 8,
  129248. };
  129249. static float _vq_quantthresh__16u1__p2_0[] = {
  129250. -0.5, 0.5,
  129251. };
  129252. static long _vq_quantmap__16u1__p2_0[] = {
  129253. 1, 0, 2,
  129254. };
  129255. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  129256. _vq_quantthresh__16u1__p2_0,
  129257. _vq_quantmap__16u1__p2_0,
  129258. 3,
  129259. 3
  129260. };
  129261. static static_codebook _16u1__p2_0 = {
  129262. 4, 81,
  129263. _vq_lengthlist__16u1__p2_0,
  129264. 1, -535822336, 1611661312, 2, 0,
  129265. _vq_quantlist__16u1__p2_0,
  129266. NULL,
  129267. &_vq_auxt__16u1__p2_0,
  129268. NULL,
  129269. 0
  129270. };
  129271. static long _vq_quantlist__16u1__p3_0[] = {
  129272. 2,
  129273. 1,
  129274. 3,
  129275. 0,
  129276. 4,
  129277. };
  129278. static long _vq_lengthlist__16u1__p3_0[] = {
  129279. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129280. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  129281. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  129282. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  129283. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  129284. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129285. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129286. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129287. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129288. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129289. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129290. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129291. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129292. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129293. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129294. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129295. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129296. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129297. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129298. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129299. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129300. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129301. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129302. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129303. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129304. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129305. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129306. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129307. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129308. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129309. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129310. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129311. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129312. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129313. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129314. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129315. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129316. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129317. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129318. 16,
  129319. };
  129320. static float _vq_quantthresh__16u1__p3_0[] = {
  129321. -1.5, -0.5, 0.5, 1.5,
  129322. };
  129323. static long _vq_quantmap__16u1__p3_0[] = {
  129324. 3, 1, 0, 2, 4,
  129325. };
  129326. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129327. _vq_quantthresh__16u1__p3_0,
  129328. _vq_quantmap__16u1__p3_0,
  129329. 5,
  129330. 5
  129331. };
  129332. static static_codebook _16u1__p3_0 = {
  129333. 4, 625,
  129334. _vq_lengthlist__16u1__p3_0,
  129335. 1, -533725184, 1611661312, 3, 0,
  129336. _vq_quantlist__16u1__p3_0,
  129337. NULL,
  129338. &_vq_auxt__16u1__p3_0,
  129339. NULL,
  129340. 0
  129341. };
  129342. static long _vq_quantlist__16u1__p4_0[] = {
  129343. 2,
  129344. 1,
  129345. 3,
  129346. 0,
  129347. 4,
  129348. };
  129349. static long _vq_lengthlist__16u1__p4_0[] = {
  129350. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129351. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129352. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129353. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129354. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129355. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129356. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129357. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129358. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129359. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129360. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129361. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129362. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129363. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129364. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129365. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129366. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129367. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129368. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129369. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129370. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129371. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129372. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129373. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129374. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129375. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129376. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129377. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129378. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129379. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129380. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129381. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129382. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129383. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129384. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129385. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129386. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129387. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129388. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129389. 11,
  129390. };
  129391. static float _vq_quantthresh__16u1__p4_0[] = {
  129392. -1.5, -0.5, 0.5, 1.5,
  129393. };
  129394. static long _vq_quantmap__16u1__p4_0[] = {
  129395. 3, 1, 0, 2, 4,
  129396. };
  129397. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129398. _vq_quantthresh__16u1__p4_0,
  129399. _vq_quantmap__16u1__p4_0,
  129400. 5,
  129401. 5
  129402. };
  129403. static static_codebook _16u1__p4_0 = {
  129404. 4, 625,
  129405. _vq_lengthlist__16u1__p4_0,
  129406. 1, -533725184, 1611661312, 3, 0,
  129407. _vq_quantlist__16u1__p4_0,
  129408. NULL,
  129409. &_vq_auxt__16u1__p4_0,
  129410. NULL,
  129411. 0
  129412. };
  129413. static long _vq_quantlist__16u1__p5_0[] = {
  129414. 4,
  129415. 3,
  129416. 5,
  129417. 2,
  129418. 6,
  129419. 1,
  129420. 7,
  129421. 0,
  129422. 8,
  129423. };
  129424. static long _vq_lengthlist__16u1__p5_0[] = {
  129425. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129426. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129427. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129428. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129429. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129430. 13,
  129431. };
  129432. static float _vq_quantthresh__16u1__p5_0[] = {
  129433. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129434. };
  129435. static long _vq_quantmap__16u1__p5_0[] = {
  129436. 7, 5, 3, 1, 0, 2, 4, 6,
  129437. 8,
  129438. };
  129439. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129440. _vq_quantthresh__16u1__p5_0,
  129441. _vq_quantmap__16u1__p5_0,
  129442. 9,
  129443. 9
  129444. };
  129445. static static_codebook _16u1__p5_0 = {
  129446. 2, 81,
  129447. _vq_lengthlist__16u1__p5_0,
  129448. 1, -531628032, 1611661312, 4, 0,
  129449. _vq_quantlist__16u1__p5_0,
  129450. NULL,
  129451. &_vq_auxt__16u1__p5_0,
  129452. NULL,
  129453. 0
  129454. };
  129455. static long _vq_quantlist__16u1__p6_0[] = {
  129456. 4,
  129457. 3,
  129458. 5,
  129459. 2,
  129460. 6,
  129461. 1,
  129462. 7,
  129463. 0,
  129464. 8,
  129465. };
  129466. static long _vq_lengthlist__16u1__p6_0[] = {
  129467. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129468. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129469. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129470. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129471. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129472. 11,
  129473. };
  129474. static float _vq_quantthresh__16u1__p6_0[] = {
  129475. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129476. };
  129477. static long _vq_quantmap__16u1__p6_0[] = {
  129478. 7, 5, 3, 1, 0, 2, 4, 6,
  129479. 8,
  129480. };
  129481. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129482. _vq_quantthresh__16u1__p6_0,
  129483. _vq_quantmap__16u1__p6_0,
  129484. 9,
  129485. 9
  129486. };
  129487. static static_codebook _16u1__p6_0 = {
  129488. 2, 81,
  129489. _vq_lengthlist__16u1__p6_0,
  129490. 1, -531628032, 1611661312, 4, 0,
  129491. _vq_quantlist__16u1__p6_0,
  129492. NULL,
  129493. &_vq_auxt__16u1__p6_0,
  129494. NULL,
  129495. 0
  129496. };
  129497. static long _vq_quantlist__16u1__p7_0[] = {
  129498. 1,
  129499. 0,
  129500. 2,
  129501. };
  129502. static long _vq_lengthlist__16u1__p7_0[] = {
  129503. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129504. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129505. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129506. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129507. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129508. 13,
  129509. };
  129510. static float _vq_quantthresh__16u1__p7_0[] = {
  129511. -5.5, 5.5,
  129512. };
  129513. static long _vq_quantmap__16u1__p7_0[] = {
  129514. 1, 0, 2,
  129515. };
  129516. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129517. _vq_quantthresh__16u1__p7_0,
  129518. _vq_quantmap__16u1__p7_0,
  129519. 3,
  129520. 3
  129521. };
  129522. static static_codebook _16u1__p7_0 = {
  129523. 4, 81,
  129524. _vq_lengthlist__16u1__p7_0,
  129525. 1, -529137664, 1618345984, 2, 0,
  129526. _vq_quantlist__16u1__p7_0,
  129527. NULL,
  129528. &_vq_auxt__16u1__p7_0,
  129529. NULL,
  129530. 0
  129531. };
  129532. static long _vq_quantlist__16u1__p7_1[] = {
  129533. 5,
  129534. 4,
  129535. 6,
  129536. 3,
  129537. 7,
  129538. 2,
  129539. 8,
  129540. 1,
  129541. 9,
  129542. 0,
  129543. 10,
  129544. };
  129545. static long _vq_lengthlist__16u1__p7_1[] = {
  129546. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129547. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129548. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129549. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129550. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129551. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129552. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129553. 8, 9, 9,10,10,10,10,10,10,
  129554. };
  129555. static float _vq_quantthresh__16u1__p7_1[] = {
  129556. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129557. 3.5, 4.5,
  129558. };
  129559. static long _vq_quantmap__16u1__p7_1[] = {
  129560. 9, 7, 5, 3, 1, 0, 2, 4,
  129561. 6, 8, 10,
  129562. };
  129563. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129564. _vq_quantthresh__16u1__p7_1,
  129565. _vq_quantmap__16u1__p7_1,
  129566. 11,
  129567. 11
  129568. };
  129569. static static_codebook _16u1__p7_1 = {
  129570. 2, 121,
  129571. _vq_lengthlist__16u1__p7_1,
  129572. 1, -531365888, 1611661312, 4, 0,
  129573. _vq_quantlist__16u1__p7_1,
  129574. NULL,
  129575. &_vq_auxt__16u1__p7_1,
  129576. NULL,
  129577. 0
  129578. };
  129579. static long _vq_quantlist__16u1__p8_0[] = {
  129580. 5,
  129581. 4,
  129582. 6,
  129583. 3,
  129584. 7,
  129585. 2,
  129586. 8,
  129587. 1,
  129588. 9,
  129589. 0,
  129590. 10,
  129591. };
  129592. static long _vq_lengthlist__16u1__p8_0[] = {
  129593. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129594. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129595. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129596. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129597. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129598. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129599. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129600. 13,14,14,15,15,16,16,15,16,
  129601. };
  129602. static float _vq_quantthresh__16u1__p8_0[] = {
  129603. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129604. 38.5, 49.5,
  129605. };
  129606. static long _vq_quantmap__16u1__p8_0[] = {
  129607. 9, 7, 5, 3, 1, 0, 2, 4,
  129608. 6, 8, 10,
  129609. };
  129610. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129611. _vq_quantthresh__16u1__p8_0,
  129612. _vq_quantmap__16u1__p8_0,
  129613. 11,
  129614. 11
  129615. };
  129616. static static_codebook _16u1__p8_0 = {
  129617. 2, 121,
  129618. _vq_lengthlist__16u1__p8_0,
  129619. 1, -524582912, 1618345984, 4, 0,
  129620. _vq_quantlist__16u1__p8_0,
  129621. NULL,
  129622. &_vq_auxt__16u1__p8_0,
  129623. NULL,
  129624. 0
  129625. };
  129626. static long _vq_quantlist__16u1__p8_1[] = {
  129627. 5,
  129628. 4,
  129629. 6,
  129630. 3,
  129631. 7,
  129632. 2,
  129633. 8,
  129634. 1,
  129635. 9,
  129636. 0,
  129637. 10,
  129638. };
  129639. static long _vq_lengthlist__16u1__p8_1[] = {
  129640. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129641. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129642. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129643. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129644. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129645. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129646. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129647. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129648. };
  129649. static float _vq_quantthresh__16u1__p8_1[] = {
  129650. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129651. 3.5, 4.5,
  129652. };
  129653. static long _vq_quantmap__16u1__p8_1[] = {
  129654. 9, 7, 5, 3, 1, 0, 2, 4,
  129655. 6, 8, 10,
  129656. };
  129657. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129658. _vq_quantthresh__16u1__p8_1,
  129659. _vq_quantmap__16u1__p8_1,
  129660. 11,
  129661. 11
  129662. };
  129663. static static_codebook _16u1__p8_1 = {
  129664. 2, 121,
  129665. _vq_lengthlist__16u1__p8_1,
  129666. 1, -531365888, 1611661312, 4, 0,
  129667. _vq_quantlist__16u1__p8_1,
  129668. NULL,
  129669. &_vq_auxt__16u1__p8_1,
  129670. NULL,
  129671. 0
  129672. };
  129673. static long _vq_quantlist__16u1__p9_0[] = {
  129674. 7,
  129675. 6,
  129676. 8,
  129677. 5,
  129678. 9,
  129679. 4,
  129680. 10,
  129681. 3,
  129682. 11,
  129683. 2,
  129684. 12,
  129685. 1,
  129686. 13,
  129687. 0,
  129688. 14,
  129689. };
  129690. static long _vq_lengthlist__16u1__p9_0[] = {
  129691. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129692. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129693. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129694. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129695. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129696. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129697. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129698. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129699. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129700. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129701. 9, 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, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129704. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129705. 8,
  129706. };
  129707. static float _vq_quantthresh__16u1__p9_0[] = {
  129708. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129709. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129710. };
  129711. static long _vq_quantmap__16u1__p9_0[] = {
  129712. 13, 11, 9, 7, 5, 3, 1, 0,
  129713. 2, 4, 6, 8, 10, 12, 14,
  129714. };
  129715. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129716. _vq_quantthresh__16u1__p9_0,
  129717. _vq_quantmap__16u1__p9_0,
  129718. 15,
  129719. 15
  129720. };
  129721. static static_codebook _16u1__p9_0 = {
  129722. 2, 225,
  129723. _vq_lengthlist__16u1__p9_0,
  129724. 1, -514071552, 1627381760, 4, 0,
  129725. _vq_quantlist__16u1__p9_0,
  129726. NULL,
  129727. &_vq_auxt__16u1__p9_0,
  129728. NULL,
  129729. 0
  129730. };
  129731. static long _vq_quantlist__16u1__p9_1[] = {
  129732. 7,
  129733. 6,
  129734. 8,
  129735. 5,
  129736. 9,
  129737. 4,
  129738. 10,
  129739. 3,
  129740. 11,
  129741. 2,
  129742. 12,
  129743. 1,
  129744. 13,
  129745. 0,
  129746. 14,
  129747. };
  129748. static long _vq_lengthlist__16u1__p9_1[] = {
  129749. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129750. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129751. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129752. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129753. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129754. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129755. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129756. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129757. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129758. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129759. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129760. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129761. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129762. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129763. 9,
  129764. };
  129765. static float _vq_quantthresh__16u1__p9_1[] = {
  129766. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129767. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129768. };
  129769. static long _vq_quantmap__16u1__p9_1[] = {
  129770. 13, 11, 9, 7, 5, 3, 1, 0,
  129771. 2, 4, 6, 8, 10, 12, 14,
  129772. };
  129773. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129774. _vq_quantthresh__16u1__p9_1,
  129775. _vq_quantmap__16u1__p9_1,
  129776. 15,
  129777. 15
  129778. };
  129779. static static_codebook _16u1__p9_1 = {
  129780. 2, 225,
  129781. _vq_lengthlist__16u1__p9_1,
  129782. 1, -522338304, 1620115456, 4, 0,
  129783. _vq_quantlist__16u1__p9_1,
  129784. NULL,
  129785. &_vq_auxt__16u1__p9_1,
  129786. NULL,
  129787. 0
  129788. };
  129789. static long _vq_quantlist__16u1__p9_2[] = {
  129790. 8,
  129791. 7,
  129792. 9,
  129793. 6,
  129794. 10,
  129795. 5,
  129796. 11,
  129797. 4,
  129798. 12,
  129799. 3,
  129800. 13,
  129801. 2,
  129802. 14,
  129803. 1,
  129804. 15,
  129805. 0,
  129806. 16,
  129807. };
  129808. static long _vq_lengthlist__16u1__p9_2[] = {
  129809. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129810. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129811. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129812. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129813. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129814. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129815. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129816. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129817. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129818. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129819. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129820. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129821. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129822. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129823. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129824. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129825. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129826. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129827. 10,
  129828. };
  129829. static float _vq_quantthresh__16u1__p9_2[] = {
  129830. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129831. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129832. };
  129833. static long _vq_quantmap__16u1__p9_2[] = {
  129834. 15, 13, 11, 9, 7, 5, 3, 1,
  129835. 0, 2, 4, 6, 8, 10, 12, 14,
  129836. 16,
  129837. };
  129838. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129839. _vq_quantthresh__16u1__p9_2,
  129840. _vq_quantmap__16u1__p9_2,
  129841. 17,
  129842. 17
  129843. };
  129844. static static_codebook _16u1__p9_2 = {
  129845. 2, 289,
  129846. _vq_lengthlist__16u1__p9_2,
  129847. 1, -529530880, 1611661312, 5, 0,
  129848. _vq_quantlist__16u1__p9_2,
  129849. NULL,
  129850. &_vq_auxt__16u1__p9_2,
  129851. NULL,
  129852. 0
  129853. };
  129854. static long _huff_lengthlist__16u1__short[] = {
  129855. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129856. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129857. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129858. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129859. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129860. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129861. 16,16,16,16,
  129862. };
  129863. static static_codebook _huff_book__16u1__short = {
  129864. 2, 100,
  129865. _huff_lengthlist__16u1__short,
  129866. 0, 0, 0, 0, 0,
  129867. NULL,
  129868. NULL,
  129869. NULL,
  129870. NULL,
  129871. 0
  129872. };
  129873. static long _huff_lengthlist__16u2__long[] = {
  129874. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129875. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129876. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129877. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129878. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129879. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129880. 13,14,18,18,
  129881. };
  129882. static static_codebook _huff_book__16u2__long = {
  129883. 2, 100,
  129884. _huff_lengthlist__16u2__long,
  129885. 0, 0, 0, 0, 0,
  129886. NULL,
  129887. NULL,
  129888. NULL,
  129889. NULL,
  129890. 0
  129891. };
  129892. static long _huff_lengthlist__16u2__short[] = {
  129893. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129894. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129895. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129896. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129897. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129898. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129899. 16,16,16,16,
  129900. };
  129901. static static_codebook _huff_book__16u2__short = {
  129902. 2, 100,
  129903. _huff_lengthlist__16u2__short,
  129904. 0, 0, 0, 0, 0,
  129905. NULL,
  129906. NULL,
  129907. NULL,
  129908. NULL,
  129909. 0
  129910. };
  129911. static long _vq_quantlist__16u2_p1_0[] = {
  129912. 1,
  129913. 0,
  129914. 2,
  129915. };
  129916. static long _vq_lengthlist__16u2_p1_0[] = {
  129917. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129918. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129919. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129920. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129921. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129922. 10,
  129923. };
  129924. static float _vq_quantthresh__16u2_p1_0[] = {
  129925. -0.5, 0.5,
  129926. };
  129927. static long _vq_quantmap__16u2_p1_0[] = {
  129928. 1, 0, 2,
  129929. };
  129930. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129931. _vq_quantthresh__16u2_p1_0,
  129932. _vq_quantmap__16u2_p1_0,
  129933. 3,
  129934. 3
  129935. };
  129936. static static_codebook _16u2_p1_0 = {
  129937. 4, 81,
  129938. _vq_lengthlist__16u2_p1_0,
  129939. 1, -535822336, 1611661312, 2, 0,
  129940. _vq_quantlist__16u2_p1_0,
  129941. NULL,
  129942. &_vq_auxt__16u2_p1_0,
  129943. NULL,
  129944. 0
  129945. };
  129946. static long _vq_quantlist__16u2_p2_0[] = {
  129947. 2,
  129948. 1,
  129949. 3,
  129950. 0,
  129951. 4,
  129952. };
  129953. static long _vq_lengthlist__16u2_p2_0[] = {
  129954. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129955. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129956. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129957. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129958. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129959. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129960. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129961. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129962. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129963. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129964. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129965. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129966. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129967. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129968. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129969. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129970. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129971. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129972. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129973. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129974. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129975. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129976. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129977. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129978. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129979. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129980. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129981. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129982. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129983. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129984. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129985. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129986. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129987. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129988. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129989. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129990. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129991. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129992. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129993. 13,
  129994. };
  129995. static float _vq_quantthresh__16u2_p2_0[] = {
  129996. -1.5, -0.5, 0.5, 1.5,
  129997. };
  129998. static long _vq_quantmap__16u2_p2_0[] = {
  129999. 3, 1, 0, 2, 4,
  130000. };
  130001. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  130002. _vq_quantthresh__16u2_p2_0,
  130003. _vq_quantmap__16u2_p2_0,
  130004. 5,
  130005. 5
  130006. };
  130007. static static_codebook _16u2_p2_0 = {
  130008. 4, 625,
  130009. _vq_lengthlist__16u2_p2_0,
  130010. 1, -533725184, 1611661312, 3, 0,
  130011. _vq_quantlist__16u2_p2_0,
  130012. NULL,
  130013. &_vq_auxt__16u2_p2_0,
  130014. NULL,
  130015. 0
  130016. };
  130017. static long _vq_quantlist__16u2_p3_0[] = {
  130018. 4,
  130019. 3,
  130020. 5,
  130021. 2,
  130022. 6,
  130023. 1,
  130024. 7,
  130025. 0,
  130026. 8,
  130027. };
  130028. static long _vq_lengthlist__16u2_p3_0[] = {
  130029. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  130030. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  130031. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  130032. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  130033. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  130034. 11,
  130035. };
  130036. static float _vq_quantthresh__16u2_p3_0[] = {
  130037. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130038. };
  130039. static long _vq_quantmap__16u2_p3_0[] = {
  130040. 7, 5, 3, 1, 0, 2, 4, 6,
  130041. 8,
  130042. };
  130043. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  130044. _vq_quantthresh__16u2_p3_0,
  130045. _vq_quantmap__16u2_p3_0,
  130046. 9,
  130047. 9
  130048. };
  130049. static static_codebook _16u2_p3_0 = {
  130050. 2, 81,
  130051. _vq_lengthlist__16u2_p3_0,
  130052. 1, -531628032, 1611661312, 4, 0,
  130053. _vq_quantlist__16u2_p3_0,
  130054. NULL,
  130055. &_vq_auxt__16u2_p3_0,
  130056. NULL,
  130057. 0
  130058. };
  130059. static long _vq_quantlist__16u2_p4_0[] = {
  130060. 8,
  130061. 7,
  130062. 9,
  130063. 6,
  130064. 10,
  130065. 5,
  130066. 11,
  130067. 4,
  130068. 12,
  130069. 3,
  130070. 13,
  130071. 2,
  130072. 14,
  130073. 1,
  130074. 15,
  130075. 0,
  130076. 16,
  130077. };
  130078. static long _vq_lengthlist__16u2_p4_0[] = {
  130079. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  130080. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  130081. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  130082. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  130083. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  130084. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  130085. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  130086. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  130087. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  130088. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  130089. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  130090. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  130091. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  130092. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  130093. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  130094. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  130095. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  130096. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  130097. 14,
  130098. };
  130099. static float _vq_quantthresh__16u2_p4_0[] = {
  130100. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130101. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130102. };
  130103. static long _vq_quantmap__16u2_p4_0[] = {
  130104. 15, 13, 11, 9, 7, 5, 3, 1,
  130105. 0, 2, 4, 6, 8, 10, 12, 14,
  130106. 16,
  130107. };
  130108. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  130109. _vq_quantthresh__16u2_p4_0,
  130110. _vq_quantmap__16u2_p4_0,
  130111. 17,
  130112. 17
  130113. };
  130114. static static_codebook _16u2_p4_0 = {
  130115. 2, 289,
  130116. _vq_lengthlist__16u2_p4_0,
  130117. 1, -529530880, 1611661312, 5, 0,
  130118. _vq_quantlist__16u2_p4_0,
  130119. NULL,
  130120. &_vq_auxt__16u2_p4_0,
  130121. NULL,
  130122. 0
  130123. };
  130124. static long _vq_quantlist__16u2_p5_0[] = {
  130125. 1,
  130126. 0,
  130127. 2,
  130128. };
  130129. static long _vq_lengthlist__16u2_p5_0[] = {
  130130. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  130131. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  130132. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  130133. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  130134. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  130135. 10,
  130136. };
  130137. static float _vq_quantthresh__16u2_p5_0[] = {
  130138. -5.5, 5.5,
  130139. };
  130140. static long _vq_quantmap__16u2_p5_0[] = {
  130141. 1, 0, 2,
  130142. };
  130143. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  130144. _vq_quantthresh__16u2_p5_0,
  130145. _vq_quantmap__16u2_p5_0,
  130146. 3,
  130147. 3
  130148. };
  130149. static static_codebook _16u2_p5_0 = {
  130150. 4, 81,
  130151. _vq_lengthlist__16u2_p5_0,
  130152. 1, -529137664, 1618345984, 2, 0,
  130153. _vq_quantlist__16u2_p5_0,
  130154. NULL,
  130155. &_vq_auxt__16u2_p5_0,
  130156. NULL,
  130157. 0
  130158. };
  130159. static long _vq_quantlist__16u2_p5_1[] = {
  130160. 5,
  130161. 4,
  130162. 6,
  130163. 3,
  130164. 7,
  130165. 2,
  130166. 8,
  130167. 1,
  130168. 9,
  130169. 0,
  130170. 10,
  130171. };
  130172. static long _vq_lengthlist__16u2_p5_1[] = {
  130173. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  130174. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  130175. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  130176. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  130177. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  130178. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  130179. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  130180. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  130181. };
  130182. static float _vq_quantthresh__16u2_p5_1[] = {
  130183. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130184. 3.5, 4.5,
  130185. };
  130186. static long _vq_quantmap__16u2_p5_1[] = {
  130187. 9, 7, 5, 3, 1, 0, 2, 4,
  130188. 6, 8, 10,
  130189. };
  130190. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  130191. _vq_quantthresh__16u2_p5_1,
  130192. _vq_quantmap__16u2_p5_1,
  130193. 11,
  130194. 11
  130195. };
  130196. static static_codebook _16u2_p5_1 = {
  130197. 2, 121,
  130198. _vq_lengthlist__16u2_p5_1,
  130199. 1, -531365888, 1611661312, 4, 0,
  130200. _vq_quantlist__16u2_p5_1,
  130201. NULL,
  130202. &_vq_auxt__16u2_p5_1,
  130203. NULL,
  130204. 0
  130205. };
  130206. static long _vq_quantlist__16u2_p6_0[] = {
  130207. 6,
  130208. 5,
  130209. 7,
  130210. 4,
  130211. 8,
  130212. 3,
  130213. 9,
  130214. 2,
  130215. 10,
  130216. 1,
  130217. 11,
  130218. 0,
  130219. 12,
  130220. };
  130221. static long _vq_lengthlist__16u2_p6_0[] = {
  130222. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  130223. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  130224. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  130225. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  130226. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  130227. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  130228. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  130229. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  130230. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  130231. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  130232. 12,13,13,14,14,14,14,15,15,
  130233. };
  130234. static float _vq_quantthresh__16u2_p6_0[] = {
  130235. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130236. 12.5, 17.5, 22.5, 27.5,
  130237. };
  130238. static long _vq_quantmap__16u2_p6_0[] = {
  130239. 11, 9, 7, 5, 3, 1, 0, 2,
  130240. 4, 6, 8, 10, 12,
  130241. };
  130242. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  130243. _vq_quantthresh__16u2_p6_0,
  130244. _vq_quantmap__16u2_p6_0,
  130245. 13,
  130246. 13
  130247. };
  130248. static static_codebook _16u2_p6_0 = {
  130249. 2, 169,
  130250. _vq_lengthlist__16u2_p6_0,
  130251. 1, -526516224, 1616117760, 4, 0,
  130252. _vq_quantlist__16u2_p6_0,
  130253. NULL,
  130254. &_vq_auxt__16u2_p6_0,
  130255. NULL,
  130256. 0
  130257. };
  130258. static long _vq_quantlist__16u2_p6_1[] = {
  130259. 2,
  130260. 1,
  130261. 3,
  130262. 0,
  130263. 4,
  130264. };
  130265. static long _vq_lengthlist__16u2_p6_1[] = {
  130266. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  130267. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  130268. };
  130269. static float _vq_quantthresh__16u2_p6_1[] = {
  130270. -1.5, -0.5, 0.5, 1.5,
  130271. };
  130272. static long _vq_quantmap__16u2_p6_1[] = {
  130273. 3, 1, 0, 2, 4,
  130274. };
  130275. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  130276. _vq_quantthresh__16u2_p6_1,
  130277. _vq_quantmap__16u2_p6_1,
  130278. 5,
  130279. 5
  130280. };
  130281. static static_codebook _16u2_p6_1 = {
  130282. 2, 25,
  130283. _vq_lengthlist__16u2_p6_1,
  130284. 1, -533725184, 1611661312, 3, 0,
  130285. _vq_quantlist__16u2_p6_1,
  130286. NULL,
  130287. &_vq_auxt__16u2_p6_1,
  130288. NULL,
  130289. 0
  130290. };
  130291. static long _vq_quantlist__16u2_p7_0[] = {
  130292. 6,
  130293. 5,
  130294. 7,
  130295. 4,
  130296. 8,
  130297. 3,
  130298. 9,
  130299. 2,
  130300. 10,
  130301. 1,
  130302. 11,
  130303. 0,
  130304. 12,
  130305. };
  130306. static long _vq_lengthlist__16u2_p7_0[] = {
  130307. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130308. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130309. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130310. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130311. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130312. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130313. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130314. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130315. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130316. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130317. 12,13,13,13,14,14,14,15,14,
  130318. };
  130319. static float _vq_quantthresh__16u2_p7_0[] = {
  130320. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130321. 27.5, 38.5, 49.5, 60.5,
  130322. };
  130323. static long _vq_quantmap__16u2_p7_0[] = {
  130324. 11, 9, 7, 5, 3, 1, 0, 2,
  130325. 4, 6, 8, 10, 12,
  130326. };
  130327. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130328. _vq_quantthresh__16u2_p7_0,
  130329. _vq_quantmap__16u2_p7_0,
  130330. 13,
  130331. 13
  130332. };
  130333. static static_codebook _16u2_p7_0 = {
  130334. 2, 169,
  130335. _vq_lengthlist__16u2_p7_0,
  130336. 1, -523206656, 1618345984, 4, 0,
  130337. _vq_quantlist__16u2_p7_0,
  130338. NULL,
  130339. &_vq_auxt__16u2_p7_0,
  130340. NULL,
  130341. 0
  130342. };
  130343. static long _vq_quantlist__16u2_p7_1[] = {
  130344. 5,
  130345. 4,
  130346. 6,
  130347. 3,
  130348. 7,
  130349. 2,
  130350. 8,
  130351. 1,
  130352. 9,
  130353. 0,
  130354. 10,
  130355. };
  130356. static long _vq_lengthlist__16u2_p7_1[] = {
  130357. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130358. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130359. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130360. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130361. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130362. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130363. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130364. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130365. };
  130366. static float _vq_quantthresh__16u2_p7_1[] = {
  130367. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130368. 3.5, 4.5,
  130369. };
  130370. static long _vq_quantmap__16u2_p7_1[] = {
  130371. 9, 7, 5, 3, 1, 0, 2, 4,
  130372. 6, 8, 10,
  130373. };
  130374. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130375. _vq_quantthresh__16u2_p7_1,
  130376. _vq_quantmap__16u2_p7_1,
  130377. 11,
  130378. 11
  130379. };
  130380. static static_codebook _16u2_p7_1 = {
  130381. 2, 121,
  130382. _vq_lengthlist__16u2_p7_1,
  130383. 1, -531365888, 1611661312, 4, 0,
  130384. _vq_quantlist__16u2_p7_1,
  130385. NULL,
  130386. &_vq_auxt__16u2_p7_1,
  130387. NULL,
  130388. 0
  130389. };
  130390. static long _vq_quantlist__16u2_p8_0[] = {
  130391. 7,
  130392. 6,
  130393. 8,
  130394. 5,
  130395. 9,
  130396. 4,
  130397. 10,
  130398. 3,
  130399. 11,
  130400. 2,
  130401. 12,
  130402. 1,
  130403. 13,
  130404. 0,
  130405. 14,
  130406. };
  130407. static long _vq_lengthlist__16u2_p8_0[] = {
  130408. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130409. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130410. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130411. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130412. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130413. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130414. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130415. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130416. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130417. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130418. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130419. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130420. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130421. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130422. 14,
  130423. };
  130424. static float _vq_quantthresh__16u2_p8_0[] = {
  130425. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130426. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130427. };
  130428. static long _vq_quantmap__16u2_p8_0[] = {
  130429. 13, 11, 9, 7, 5, 3, 1, 0,
  130430. 2, 4, 6, 8, 10, 12, 14,
  130431. };
  130432. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130433. _vq_quantthresh__16u2_p8_0,
  130434. _vq_quantmap__16u2_p8_0,
  130435. 15,
  130436. 15
  130437. };
  130438. static static_codebook _16u2_p8_0 = {
  130439. 2, 225,
  130440. _vq_lengthlist__16u2_p8_0,
  130441. 1, -520986624, 1620377600, 4, 0,
  130442. _vq_quantlist__16u2_p8_0,
  130443. NULL,
  130444. &_vq_auxt__16u2_p8_0,
  130445. NULL,
  130446. 0
  130447. };
  130448. static long _vq_quantlist__16u2_p8_1[] = {
  130449. 10,
  130450. 9,
  130451. 11,
  130452. 8,
  130453. 12,
  130454. 7,
  130455. 13,
  130456. 6,
  130457. 14,
  130458. 5,
  130459. 15,
  130460. 4,
  130461. 16,
  130462. 3,
  130463. 17,
  130464. 2,
  130465. 18,
  130466. 1,
  130467. 19,
  130468. 0,
  130469. 20,
  130470. };
  130471. static long _vq_lengthlist__16u2_p8_1[] = {
  130472. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130473. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130474. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130475. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130476. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130477. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130478. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130479. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130480. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130481. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130482. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130483. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130484. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130485. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130486. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130487. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130488. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130489. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130490. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130491. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130492. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130493. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130494. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130495. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130496. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130497. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130498. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130499. 11,11,10,11,11,11,10,11,11,
  130500. };
  130501. static float _vq_quantthresh__16u2_p8_1[] = {
  130502. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130503. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130504. 6.5, 7.5, 8.5, 9.5,
  130505. };
  130506. static long _vq_quantmap__16u2_p8_1[] = {
  130507. 19, 17, 15, 13, 11, 9, 7, 5,
  130508. 3, 1, 0, 2, 4, 6, 8, 10,
  130509. 12, 14, 16, 18, 20,
  130510. };
  130511. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130512. _vq_quantthresh__16u2_p8_1,
  130513. _vq_quantmap__16u2_p8_1,
  130514. 21,
  130515. 21
  130516. };
  130517. static static_codebook _16u2_p8_1 = {
  130518. 2, 441,
  130519. _vq_lengthlist__16u2_p8_1,
  130520. 1, -529268736, 1611661312, 5, 0,
  130521. _vq_quantlist__16u2_p8_1,
  130522. NULL,
  130523. &_vq_auxt__16u2_p8_1,
  130524. NULL,
  130525. 0
  130526. };
  130527. static long _vq_quantlist__16u2_p9_0[] = {
  130528. 5586,
  130529. 4655,
  130530. 6517,
  130531. 3724,
  130532. 7448,
  130533. 2793,
  130534. 8379,
  130535. 1862,
  130536. 9310,
  130537. 931,
  130538. 10241,
  130539. 0,
  130540. 11172,
  130541. 5521,
  130542. 5651,
  130543. };
  130544. static long _vq_lengthlist__16u2_p9_0[] = {
  130545. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130546. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130547. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130548. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130549. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130550. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130551. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130552. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130553. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130554. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130555. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130556. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130557. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130558. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130559. 5,
  130560. };
  130561. static float _vq_quantthresh__16u2_p9_0[] = {
  130562. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130563. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130564. };
  130565. static long _vq_quantmap__16u2_p9_0[] = {
  130566. 11, 9, 7, 5, 3, 1, 13, 0,
  130567. 14, 2, 4, 6, 8, 10, 12,
  130568. };
  130569. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130570. _vq_quantthresh__16u2_p9_0,
  130571. _vq_quantmap__16u2_p9_0,
  130572. 15,
  130573. 15
  130574. };
  130575. static static_codebook _16u2_p9_0 = {
  130576. 2, 225,
  130577. _vq_lengthlist__16u2_p9_0,
  130578. 1, -510275072, 1611661312, 14, 0,
  130579. _vq_quantlist__16u2_p9_0,
  130580. NULL,
  130581. &_vq_auxt__16u2_p9_0,
  130582. NULL,
  130583. 0
  130584. };
  130585. static long _vq_quantlist__16u2_p9_1[] = {
  130586. 392,
  130587. 343,
  130588. 441,
  130589. 294,
  130590. 490,
  130591. 245,
  130592. 539,
  130593. 196,
  130594. 588,
  130595. 147,
  130596. 637,
  130597. 98,
  130598. 686,
  130599. 49,
  130600. 735,
  130601. 0,
  130602. 784,
  130603. 388,
  130604. 396,
  130605. };
  130606. static long _vq_lengthlist__16u2_p9_1[] = {
  130607. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130608. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130609. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130610. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130611. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130612. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130613. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130614. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130615. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130616. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130617. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130618. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130619. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130620. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130621. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130622. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130623. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130624. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130625. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130626. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130627. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130628. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130629. 11,11,11,11,11,11,11, 5, 4,
  130630. };
  130631. static float _vq_quantthresh__16u2_p9_1[] = {
  130632. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130633. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130634. 318.5, 367.5,
  130635. };
  130636. static long _vq_quantmap__16u2_p9_1[] = {
  130637. 15, 13, 11, 9, 7, 5, 3, 1,
  130638. 17, 0, 18, 2, 4, 6, 8, 10,
  130639. 12, 14, 16,
  130640. };
  130641. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130642. _vq_quantthresh__16u2_p9_1,
  130643. _vq_quantmap__16u2_p9_1,
  130644. 19,
  130645. 19
  130646. };
  130647. static static_codebook _16u2_p9_1 = {
  130648. 2, 361,
  130649. _vq_lengthlist__16u2_p9_1,
  130650. 1, -518488064, 1611661312, 10, 0,
  130651. _vq_quantlist__16u2_p9_1,
  130652. NULL,
  130653. &_vq_auxt__16u2_p9_1,
  130654. NULL,
  130655. 0
  130656. };
  130657. static long _vq_quantlist__16u2_p9_2[] = {
  130658. 24,
  130659. 23,
  130660. 25,
  130661. 22,
  130662. 26,
  130663. 21,
  130664. 27,
  130665. 20,
  130666. 28,
  130667. 19,
  130668. 29,
  130669. 18,
  130670. 30,
  130671. 17,
  130672. 31,
  130673. 16,
  130674. 32,
  130675. 15,
  130676. 33,
  130677. 14,
  130678. 34,
  130679. 13,
  130680. 35,
  130681. 12,
  130682. 36,
  130683. 11,
  130684. 37,
  130685. 10,
  130686. 38,
  130687. 9,
  130688. 39,
  130689. 8,
  130690. 40,
  130691. 7,
  130692. 41,
  130693. 6,
  130694. 42,
  130695. 5,
  130696. 43,
  130697. 4,
  130698. 44,
  130699. 3,
  130700. 45,
  130701. 2,
  130702. 46,
  130703. 1,
  130704. 47,
  130705. 0,
  130706. 48,
  130707. };
  130708. static long _vq_lengthlist__16u2_p9_2[] = {
  130709. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130710. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130711. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130712. 11,
  130713. };
  130714. static float _vq_quantthresh__16u2_p9_2[] = {
  130715. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130716. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130717. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130718. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130719. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130720. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130721. };
  130722. static long _vq_quantmap__16u2_p9_2[] = {
  130723. 47, 45, 43, 41, 39, 37, 35, 33,
  130724. 31, 29, 27, 25, 23, 21, 19, 17,
  130725. 15, 13, 11, 9, 7, 5, 3, 1,
  130726. 0, 2, 4, 6, 8, 10, 12, 14,
  130727. 16, 18, 20, 22, 24, 26, 28, 30,
  130728. 32, 34, 36, 38, 40, 42, 44, 46,
  130729. 48,
  130730. };
  130731. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130732. _vq_quantthresh__16u2_p9_2,
  130733. _vq_quantmap__16u2_p9_2,
  130734. 49,
  130735. 49
  130736. };
  130737. static static_codebook _16u2_p9_2 = {
  130738. 1, 49,
  130739. _vq_lengthlist__16u2_p9_2,
  130740. 1, -526909440, 1611661312, 6, 0,
  130741. _vq_quantlist__16u2_p9_2,
  130742. NULL,
  130743. &_vq_auxt__16u2_p9_2,
  130744. NULL,
  130745. 0
  130746. };
  130747. static long _vq_quantlist__8u0__p1_0[] = {
  130748. 1,
  130749. 0,
  130750. 2,
  130751. };
  130752. static long _vq_lengthlist__8u0__p1_0[] = {
  130753. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130754. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130755. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130756. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130757. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130758. 11,
  130759. };
  130760. static float _vq_quantthresh__8u0__p1_0[] = {
  130761. -0.5, 0.5,
  130762. };
  130763. static long _vq_quantmap__8u0__p1_0[] = {
  130764. 1, 0, 2,
  130765. };
  130766. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130767. _vq_quantthresh__8u0__p1_0,
  130768. _vq_quantmap__8u0__p1_0,
  130769. 3,
  130770. 3
  130771. };
  130772. static static_codebook _8u0__p1_0 = {
  130773. 4, 81,
  130774. _vq_lengthlist__8u0__p1_0,
  130775. 1, -535822336, 1611661312, 2, 0,
  130776. _vq_quantlist__8u0__p1_0,
  130777. NULL,
  130778. &_vq_auxt__8u0__p1_0,
  130779. NULL,
  130780. 0
  130781. };
  130782. static long _vq_quantlist__8u0__p2_0[] = {
  130783. 1,
  130784. 0,
  130785. 2,
  130786. };
  130787. static long _vq_lengthlist__8u0__p2_0[] = {
  130788. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130789. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130790. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130791. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130792. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130793. 8,
  130794. };
  130795. static float _vq_quantthresh__8u0__p2_0[] = {
  130796. -0.5, 0.5,
  130797. };
  130798. static long _vq_quantmap__8u0__p2_0[] = {
  130799. 1, 0, 2,
  130800. };
  130801. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130802. _vq_quantthresh__8u0__p2_0,
  130803. _vq_quantmap__8u0__p2_0,
  130804. 3,
  130805. 3
  130806. };
  130807. static static_codebook _8u0__p2_0 = {
  130808. 4, 81,
  130809. _vq_lengthlist__8u0__p2_0,
  130810. 1, -535822336, 1611661312, 2, 0,
  130811. _vq_quantlist__8u0__p2_0,
  130812. NULL,
  130813. &_vq_auxt__8u0__p2_0,
  130814. NULL,
  130815. 0
  130816. };
  130817. static long _vq_quantlist__8u0__p3_0[] = {
  130818. 2,
  130819. 1,
  130820. 3,
  130821. 0,
  130822. 4,
  130823. };
  130824. static long _vq_lengthlist__8u0__p3_0[] = {
  130825. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130826. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130827. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130828. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130829. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130830. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130831. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130832. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130833. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130834. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130835. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130836. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130837. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130838. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130839. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130840. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130841. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130842. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130843. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130844. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130845. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130846. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130847. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130848. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130849. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130850. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130851. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130852. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130853. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130854. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130855. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130856. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130857. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130858. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130859. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130860. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130861. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130862. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130863. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130864. 16,
  130865. };
  130866. static float _vq_quantthresh__8u0__p3_0[] = {
  130867. -1.5, -0.5, 0.5, 1.5,
  130868. };
  130869. static long _vq_quantmap__8u0__p3_0[] = {
  130870. 3, 1, 0, 2, 4,
  130871. };
  130872. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130873. _vq_quantthresh__8u0__p3_0,
  130874. _vq_quantmap__8u0__p3_0,
  130875. 5,
  130876. 5
  130877. };
  130878. static static_codebook _8u0__p3_0 = {
  130879. 4, 625,
  130880. _vq_lengthlist__8u0__p3_0,
  130881. 1, -533725184, 1611661312, 3, 0,
  130882. _vq_quantlist__8u0__p3_0,
  130883. NULL,
  130884. &_vq_auxt__8u0__p3_0,
  130885. NULL,
  130886. 0
  130887. };
  130888. static long _vq_quantlist__8u0__p4_0[] = {
  130889. 2,
  130890. 1,
  130891. 3,
  130892. 0,
  130893. 4,
  130894. };
  130895. static long _vq_lengthlist__8u0__p4_0[] = {
  130896. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130897. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130898. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130899. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130900. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130901. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130902. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130903. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130904. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130905. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130906. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130907. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130908. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130909. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130910. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130911. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130912. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130913. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130914. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130915. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130916. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130917. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130918. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130919. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130920. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130921. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130922. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130923. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130924. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130925. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130926. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130927. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130928. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130929. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130930. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130931. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130932. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130933. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130934. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130935. 12,
  130936. };
  130937. static float _vq_quantthresh__8u0__p4_0[] = {
  130938. -1.5, -0.5, 0.5, 1.5,
  130939. };
  130940. static long _vq_quantmap__8u0__p4_0[] = {
  130941. 3, 1, 0, 2, 4,
  130942. };
  130943. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130944. _vq_quantthresh__8u0__p4_0,
  130945. _vq_quantmap__8u0__p4_0,
  130946. 5,
  130947. 5
  130948. };
  130949. static static_codebook _8u0__p4_0 = {
  130950. 4, 625,
  130951. _vq_lengthlist__8u0__p4_0,
  130952. 1, -533725184, 1611661312, 3, 0,
  130953. _vq_quantlist__8u0__p4_0,
  130954. NULL,
  130955. &_vq_auxt__8u0__p4_0,
  130956. NULL,
  130957. 0
  130958. };
  130959. static long _vq_quantlist__8u0__p5_0[] = {
  130960. 4,
  130961. 3,
  130962. 5,
  130963. 2,
  130964. 6,
  130965. 1,
  130966. 7,
  130967. 0,
  130968. 8,
  130969. };
  130970. static long _vq_lengthlist__8u0__p5_0[] = {
  130971. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130972. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130973. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130974. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130975. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130976. 12,
  130977. };
  130978. static float _vq_quantthresh__8u0__p5_0[] = {
  130979. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130980. };
  130981. static long _vq_quantmap__8u0__p5_0[] = {
  130982. 7, 5, 3, 1, 0, 2, 4, 6,
  130983. 8,
  130984. };
  130985. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130986. _vq_quantthresh__8u0__p5_0,
  130987. _vq_quantmap__8u0__p5_0,
  130988. 9,
  130989. 9
  130990. };
  130991. static static_codebook _8u0__p5_0 = {
  130992. 2, 81,
  130993. _vq_lengthlist__8u0__p5_0,
  130994. 1, -531628032, 1611661312, 4, 0,
  130995. _vq_quantlist__8u0__p5_0,
  130996. NULL,
  130997. &_vq_auxt__8u0__p5_0,
  130998. NULL,
  130999. 0
  131000. };
  131001. static long _vq_quantlist__8u0__p6_0[] = {
  131002. 6,
  131003. 5,
  131004. 7,
  131005. 4,
  131006. 8,
  131007. 3,
  131008. 9,
  131009. 2,
  131010. 10,
  131011. 1,
  131012. 11,
  131013. 0,
  131014. 12,
  131015. };
  131016. static long _vq_lengthlist__8u0__p6_0[] = {
  131017. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  131018. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  131019. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  131020. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  131021. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  131022. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  131023. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  131024. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  131025. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  131026. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  131027. 16, 0,15, 0,17, 0, 0, 0, 0,
  131028. };
  131029. static float _vq_quantthresh__8u0__p6_0[] = {
  131030. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131031. 12.5, 17.5, 22.5, 27.5,
  131032. };
  131033. static long _vq_quantmap__8u0__p6_0[] = {
  131034. 11, 9, 7, 5, 3, 1, 0, 2,
  131035. 4, 6, 8, 10, 12,
  131036. };
  131037. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  131038. _vq_quantthresh__8u0__p6_0,
  131039. _vq_quantmap__8u0__p6_0,
  131040. 13,
  131041. 13
  131042. };
  131043. static static_codebook _8u0__p6_0 = {
  131044. 2, 169,
  131045. _vq_lengthlist__8u0__p6_0,
  131046. 1, -526516224, 1616117760, 4, 0,
  131047. _vq_quantlist__8u0__p6_0,
  131048. NULL,
  131049. &_vq_auxt__8u0__p6_0,
  131050. NULL,
  131051. 0
  131052. };
  131053. static long _vq_quantlist__8u0__p6_1[] = {
  131054. 2,
  131055. 1,
  131056. 3,
  131057. 0,
  131058. 4,
  131059. };
  131060. static long _vq_lengthlist__8u0__p6_1[] = {
  131061. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  131062. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  131063. };
  131064. static float _vq_quantthresh__8u0__p6_1[] = {
  131065. -1.5, -0.5, 0.5, 1.5,
  131066. };
  131067. static long _vq_quantmap__8u0__p6_1[] = {
  131068. 3, 1, 0, 2, 4,
  131069. };
  131070. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  131071. _vq_quantthresh__8u0__p6_1,
  131072. _vq_quantmap__8u0__p6_1,
  131073. 5,
  131074. 5
  131075. };
  131076. static static_codebook _8u0__p6_1 = {
  131077. 2, 25,
  131078. _vq_lengthlist__8u0__p6_1,
  131079. 1, -533725184, 1611661312, 3, 0,
  131080. _vq_quantlist__8u0__p6_1,
  131081. NULL,
  131082. &_vq_auxt__8u0__p6_1,
  131083. NULL,
  131084. 0
  131085. };
  131086. static long _vq_quantlist__8u0__p7_0[] = {
  131087. 1,
  131088. 0,
  131089. 2,
  131090. };
  131091. static long _vq_lengthlist__8u0__p7_0[] = {
  131092. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131093. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131094. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131095. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131096. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131097. 7,
  131098. };
  131099. static float _vq_quantthresh__8u0__p7_0[] = {
  131100. -157.5, 157.5,
  131101. };
  131102. static long _vq_quantmap__8u0__p7_0[] = {
  131103. 1, 0, 2,
  131104. };
  131105. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  131106. _vq_quantthresh__8u0__p7_0,
  131107. _vq_quantmap__8u0__p7_0,
  131108. 3,
  131109. 3
  131110. };
  131111. static static_codebook _8u0__p7_0 = {
  131112. 4, 81,
  131113. _vq_lengthlist__8u0__p7_0,
  131114. 1, -518803456, 1628680192, 2, 0,
  131115. _vq_quantlist__8u0__p7_0,
  131116. NULL,
  131117. &_vq_auxt__8u0__p7_0,
  131118. NULL,
  131119. 0
  131120. };
  131121. static long _vq_quantlist__8u0__p7_1[] = {
  131122. 7,
  131123. 6,
  131124. 8,
  131125. 5,
  131126. 9,
  131127. 4,
  131128. 10,
  131129. 3,
  131130. 11,
  131131. 2,
  131132. 12,
  131133. 1,
  131134. 13,
  131135. 0,
  131136. 14,
  131137. };
  131138. static long _vq_lengthlist__8u0__p7_1[] = {
  131139. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  131140. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  131141. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  131142. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  131143. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  131144. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  131145. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131146. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131147. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131148. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131149. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131150. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131151. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  131152. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131153. 10,
  131154. };
  131155. static float _vq_quantthresh__8u0__p7_1[] = {
  131156. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  131157. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  131158. };
  131159. static long _vq_quantmap__8u0__p7_1[] = {
  131160. 13, 11, 9, 7, 5, 3, 1, 0,
  131161. 2, 4, 6, 8, 10, 12, 14,
  131162. };
  131163. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  131164. _vq_quantthresh__8u0__p7_1,
  131165. _vq_quantmap__8u0__p7_1,
  131166. 15,
  131167. 15
  131168. };
  131169. static static_codebook _8u0__p7_1 = {
  131170. 2, 225,
  131171. _vq_lengthlist__8u0__p7_1,
  131172. 1, -520986624, 1620377600, 4, 0,
  131173. _vq_quantlist__8u0__p7_1,
  131174. NULL,
  131175. &_vq_auxt__8u0__p7_1,
  131176. NULL,
  131177. 0
  131178. };
  131179. static long _vq_quantlist__8u0__p7_2[] = {
  131180. 10,
  131181. 9,
  131182. 11,
  131183. 8,
  131184. 12,
  131185. 7,
  131186. 13,
  131187. 6,
  131188. 14,
  131189. 5,
  131190. 15,
  131191. 4,
  131192. 16,
  131193. 3,
  131194. 17,
  131195. 2,
  131196. 18,
  131197. 1,
  131198. 19,
  131199. 0,
  131200. 20,
  131201. };
  131202. static long _vq_lengthlist__8u0__p7_2[] = {
  131203. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  131204. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  131205. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  131206. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  131207. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  131208. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  131209. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  131210. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  131211. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  131212. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  131213. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  131214. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  131215. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  131216. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  131217. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  131218. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  131219. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  131220. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  131221. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  131222. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  131223. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  131224. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  131225. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  131226. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  131227. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  131228. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  131229. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  131230. 11,12,11,11,11,10,10,11,11,
  131231. };
  131232. static float _vq_quantthresh__8u0__p7_2[] = {
  131233. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  131234. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  131235. 6.5, 7.5, 8.5, 9.5,
  131236. };
  131237. static long _vq_quantmap__8u0__p7_2[] = {
  131238. 19, 17, 15, 13, 11, 9, 7, 5,
  131239. 3, 1, 0, 2, 4, 6, 8, 10,
  131240. 12, 14, 16, 18, 20,
  131241. };
  131242. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  131243. _vq_quantthresh__8u0__p7_2,
  131244. _vq_quantmap__8u0__p7_2,
  131245. 21,
  131246. 21
  131247. };
  131248. static static_codebook _8u0__p7_2 = {
  131249. 2, 441,
  131250. _vq_lengthlist__8u0__p7_2,
  131251. 1, -529268736, 1611661312, 5, 0,
  131252. _vq_quantlist__8u0__p7_2,
  131253. NULL,
  131254. &_vq_auxt__8u0__p7_2,
  131255. NULL,
  131256. 0
  131257. };
  131258. static long _huff_lengthlist__8u0__single[] = {
  131259. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  131260. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  131261. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  131262. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  131263. };
  131264. static static_codebook _huff_book__8u0__single = {
  131265. 2, 64,
  131266. _huff_lengthlist__8u0__single,
  131267. 0, 0, 0, 0, 0,
  131268. NULL,
  131269. NULL,
  131270. NULL,
  131271. NULL,
  131272. 0
  131273. };
  131274. static long _vq_quantlist__8u1__p1_0[] = {
  131275. 1,
  131276. 0,
  131277. 2,
  131278. };
  131279. static long _vq_lengthlist__8u1__p1_0[] = {
  131280. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  131281. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  131282. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  131283. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  131284. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131285. 10,
  131286. };
  131287. static float _vq_quantthresh__8u1__p1_0[] = {
  131288. -0.5, 0.5,
  131289. };
  131290. static long _vq_quantmap__8u1__p1_0[] = {
  131291. 1, 0, 2,
  131292. };
  131293. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131294. _vq_quantthresh__8u1__p1_0,
  131295. _vq_quantmap__8u1__p1_0,
  131296. 3,
  131297. 3
  131298. };
  131299. static static_codebook _8u1__p1_0 = {
  131300. 4, 81,
  131301. _vq_lengthlist__8u1__p1_0,
  131302. 1, -535822336, 1611661312, 2, 0,
  131303. _vq_quantlist__8u1__p1_0,
  131304. NULL,
  131305. &_vq_auxt__8u1__p1_0,
  131306. NULL,
  131307. 0
  131308. };
  131309. static long _vq_quantlist__8u1__p2_0[] = {
  131310. 1,
  131311. 0,
  131312. 2,
  131313. };
  131314. static long _vq_lengthlist__8u1__p2_0[] = {
  131315. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131316. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131317. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131318. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131319. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131320. 7,
  131321. };
  131322. static float _vq_quantthresh__8u1__p2_0[] = {
  131323. -0.5, 0.5,
  131324. };
  131325. static long _vq_quantmap__8u1__p2_0[] = {
  131326. 1, 0, 2,
  131327. };
  131328. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131329. _vq_quantthresh__8u1__p2_0,
  131330. _vq_quantmap__8u1__p2_0,
  131331. 3,
  131332. 3
  131333. };
  131334. static static_codebook _8u1__p2_0 = {
  131335. 4, 81,
  131336. _vq_lengthlist__8u1__p2_0,
  131337. 1, -535822336, 1611661312, 2, 0,
  131338. _vq_quantlist__8u1__p2_0,
  131339. NULL,
  131340. &_vq_auxt__8u1__p2_0,
  131341. NULL,
  131342. 0
  131343. };
  131344. static long _vq_quantlist__8u1__p3_0[] = {
  131345. 2,
  131346. 1,
  131347. 3,
  131348. 0,
  131349. 4,
  131350. };
  131351. static long _vq_lengthlist__8u1__p3_0[] = {
  131352. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131353. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131354. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131355. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131356. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131357. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131358. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131359. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131360. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131361. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131362. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131363. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131364. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131365. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131366. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131367. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131368. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131369. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131370. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131371. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131372. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131373. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131374. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131375. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131376. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131377. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131378. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131379. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131380. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131381. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131382. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131383. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131384. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131385. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131386. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131387. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131388. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131389. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131390. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131391. 16,
  131392. };
  131393. static float _vq_quantthresh__8u1__p3_0[] = {
  131394. -1.5, -0.5, 0.5, 1.5,
  131395. };
  131396. static long _vq_quantmap__8u1__p3_0[] = {
  131397. 3, 1, 0, 2, 4,
  131398. };
  131399. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131400. _vq_quantthresh__8u1__p3_0,
  131401. _vq_quantmap__8u1__p3_0,
  131402. 5,
  131403. 5
  131404. };
  131405. static static_codebook _8u1__p3_0 = {
  131406. 4, 625,
  131407. _vq_lengthlist__8u1__p3_0,
  131408. 1, -533725184, 1611661312, 3, 0,
  131409. _vq_quantlist__8u1__p3_0,
  131410. NULL,
  131411. &_vq_auxt__8u1__p3_0,
  131412. NULL,
  131413. 0
  131414. };
  131415. static long _vq_quantlist__8u1__p4_0[] = {
  131416. 2,
  131417. 1,
  131418. 3,
  131419. 0,
  131420. 4,
  131421. };
  131422. static long _vq_lengthlist__8u1__p4_0[] = {
  131423. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131424. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131425. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131426. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131427. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131428. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131429. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131430. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131431. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131432. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131433. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131434. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131435. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131436. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131437. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131438. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131439. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131440. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131441. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131442. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131443. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131444. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131445. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131446. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131447. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131448. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131449. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131450. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131451. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131452. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131453. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131454. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131455. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131456. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131457. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131458. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131459. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131460. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131461. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131462. 10,
  131463. };
  131464. static float _vq_quantthresh__8u1__p4_0[] = {
  131465. -1.5, -0.5, 0.5, 1.5,
  131466. };
  131467. static long _vq_quantmap__8u1__p4_0[] = {
  131468. 3, 1, 0, 2, 4,
  131469. };
  131470. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131471. _vq_quantthresh__8u1__p4_0,
  131472. _vq_quantmap__8u1__p4_0,
  131473. 5,
  131474. 5
  131475. };
  131476. static static_codebook _8u1__p4_0 = {
  131477. 4, 625,
  131478. _vq_lengthlist__8u1__p4_0,
  131479. 1, -533725184, 1611661312, 3, 0,
  131480. _vq_quantlist__8u1__p4_0,
  131481. NULL,
  131482. &_vq_auxt__8u1__p4_0,
  131483. NULL,
  131484. 0
  131485. };
  131486. static long _vq_quantlist__8u1__p5_0[] = {
  131487. 4,
  131488. 3,
  131489. 5,
  131490. 2,
  131491. 6,
  131492. 1,
  131493. 7,
  131494. 0,
  131495. 8,
  131496. };
  131497. static long _vq_lengthlist__8u1__p5_0[] = {
  131498. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131499. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131500. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131501. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131502. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131503. 13,
  131504. };
  131505. static float _vq_quantthresh__8u1__p5_0[] = {
  131506. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131507. };
  131508. static long _vq_quantmap__8u1__p5_0[] = {
  131509. 7, 5, 3, 1, 0, 2, 4, 6,
  131510. 8,
  131511. };
  131512. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131513. _vq_quantthresh__8u1__p5_0,
  131514. _vq_quantmap__8u1__p5_0,
  131515. 9,
  131516. 9
  131517. };
  131518. static static_codebook _8u1__p5_0 = {
  131519. 2, 81,
  131520. _vq_lengthlist__8u1__p5_0,
  131521. 1, -531628032, 1611661312, 4, 0,
  131522. _vq_quantlist__8u1__p5_0,
  131523. NULL,
  131524. &_vq_auxt__8u1__p5_0,
  131525. NULL,
  131526. 0
  131527. };
  131528. static long _vq_quantlist__8u1__p6_0[] = {
  131529. 4,
  131530. 3,
  131531. 5,
  131532. 2,
  131533. 6,
  131534. 1,
  131535. 7,
  131536. 0,
  131537. 8,
  131538. };
  131539. static long _vq_lengthlist__8u1__p6_0[] = {
  131540. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131541. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131542. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131543. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131544. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131545. 10,
  131546. };
  131547. static float _vq_quantthresh__8u1__p6_0[] = {
  131548. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131549. };
  131550. static long _vq_quantmap__8u1__p6_0[] = {
  131551. 7, 5, 3, 1, 0, 2, 4, 6,
  131552. 8,
  131553. };
  131554. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131555. _vq_quantthresh__8u1__p6_0,
  131556. _vq_quantmap__8u1__p6_0,
  131557. 9,
  131558. 9
  131559. };
  131560. static static_codebook _8u1__p6_0 = {
  131561. 2, 81,
  131562. _vq_lengthlist__8u1__p6_0,
  131563. 1, -531628032, 1611661312, 4, 0,
  131564. _vq_quantlist__8u1__p6_0,
  131565. NULL,
  131566. &_vq_auxt__8u1__p6_0,
  131567. NULL,
  131568. 0
  131569. };
  131570. static long _vq_quantlist__8u1__p7_0[] = {
  131571. 1,
  131572. 0,
  131573. 2,
  131574. };
  131575. static long _vq_lengthlist__8u1__p7_0[] = {
  131576. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131577. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131578. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131579. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131580. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131581. 11,
  131582. };
  131583. static float _vq_quantthresh__8u1__p7_0[] = {
  131584. -5.5, 5.5,
  131585. };
  131586. static long _vq_quantmap__8u1__p7_0[] = {
  131587. 1, 0, 2,
  131588. };
  131589. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131590. _vq_quantthresh__8u1__p7_0,
  131591. _vq_quantmap__8u1__p7_0,
  131592. 3,
  131593. 3
  131594. };
  131595. static static_codebook _8u1__p7_0 = {
  131596. 4, 81,
  131597. _vq_lengthlist__8u1__p7_0,
  131598. 1, -529137664, 1618345984, 2, 0,
  131599. _vq_quantlist__8u1__p7_0,
  131600. NULL,
  131601. &_vq_auxt__8u1__p7_0,
  131602. NULL,
  131603. 0
  131604. };
  131605. static long _vq_quantlist__8u1__p7_1[] = {
  131606. 5,
  131607. 4,
  131608. 6,
  131609. 3,
  131610. 7,
  131611. 2,
  131612. 8,
  131613. 1,
  131614. 9,
  131615. 0,
  131616. 10,
  131617. };
  131618. static long _vq_lengthlist__8u1__p7_1[] = {
  131619. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131620. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131621. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131622. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131623. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131624. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131625. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131626. 9, 9, 9, 9, 9,10,10,10,10,
  131627. };
  131628. static float _vq_quantthresh__8u1__p7_1[] = {
  131629. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131630. 3.5, 4.5,
  131631. };
  131632. static long _vq_quantmap__8u1__p7_1[] = {
  131633. 9, 7, 5, 3, 1, 0, 2, 4,
  131634. 6, 8, 10,
  131635. };
  131636. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131637. _vq_quantthresh__8u1__p7_1,
  131638. _vq_quantmap__8u1__p7_1,
  131639. 11,
  131640. 11
  131641. };
  131642. static static_codebook _8u1__p7_1 = {
  131643. 2, 121,
  131644. _vq_lengthlist__8u1__p7_1,
  131645. 1, -531365888, 1611661312, 4, 0,
  131646. _vq_quantlist__8u1__p7_1,
  131647. NULL,
  131648. &_vq_auxt__8u1__p7_1,
  131649. NULL,
  131650. 0
  131651. };
  131652. static long _vq_quantlist__8u1__p8_0[] = {
  131653. 5,
  131654. 4,
  131655. 6,
  131656. 3,
  131657. 7,
  131658. 2,
  131659. 8,
  131660. 1,
  131661. 9,
  131662. 0,
  131663. 10,
  131664. };
  131665. static long _vq_lengthlist__8u1__p8_0[] = {
  131666. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131667. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131668. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131669. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131670. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131671. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131672. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131673. 12,13,13,14,14,15,15,15,15,
  131674. };
  131675. static float _vq_quantthresh__8u1__p8_0[] = {
  131676. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131677. 38.5, 49.5,
  131678. };
  131679. static long _vq_quantmap__8u1__p8_0[] = {
  131680. 9, 7, 5, 3, 1, 0, 2, 4,
  131681. 6, 8, 10,
  131682. };
  131683. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131684. _vq_quantthresh__8u1__p8_0,
  131685. _vq_quantmap__8u1__p8_0,
  131686. 11,
  131687. 11
  131688. };
  131689. static static_codebook _8u1__p8_0 = {
  131690. 2, 121,
  131691. _vq_lengthlist__8u1__p8_0,
  131692. 1, -524582912, 1618345984, 4, 0,
  131693. _vq_quantlist__8u1__p8_0,
  131694. NULL,
  131695. &_vq_auxt__8u1__p8_0,
  131696. NULL,
  131697. 0
  131698. };
  131699. static long _vq_quantlist__8u1__p8_1[] = {
  131700. 5,
  131701. 4,
  131702. 6,
  131703. 3,
  131704. 7,
  131705. 2,
  131706. 8,
  131707. 1,
  131708. 9,
  131709. 0,
  131710. 10,
  131711. };
  131712. static long _vq_lengthlist__8u1__p8_1[] = {
  131713. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131714. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131715. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131716. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131717. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131718. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131719. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131720. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131721. };
  131722. static float _vq_quantthresh__8u1__p8_1[] = {
  131723. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131724. 3.5, 4.5,
  131725. };
  131726. static long _vq_quantmap__8u1__p8_1[] = {
  131727. 9, 7, 5, 3, 1, 0, 2, 4,
  131728. 6, 8, 10,
  131729. };
  131730. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131731. _vq_quantthresh__8u1__p8_1,
  131732. _vq_quantmap__8u1__p8_1,
  131733. 11,
  131734. 11
  131735. };
  131736. static static_codebook _8u1__p8_1 = {
  131737. 2, 121,
  131738. _vq_lengthlist__8u1__p8_1,
  131739. 1, -531365888, 1611661312, 4, 0,
  131740. _vq_quantlist__8u1__p8_1,
  131741. NULL,
  131742. &_vq_auxt__8u1__p8_1,
  131743. NULL,
  131744. 0
  131745. };
  131746. static long _vq_quantlist__8u1__p9_0[] = {
  131747. 7,
  131748. 6,
  131749. 8,
  131750. 5,
  131751. 9,
  131752. 4,
  131753. 10,
  131754. 3,
  131755. 11,
  131756. 2,
  131757. 12,
  131758. 1,
  131759. 13,
  131760. 0,
  131761. 14,
  131762. };
  131763. static long _vq_lengthlist__8u1__p9_0[] = {
  131764. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131765. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131766. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131767. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131768. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131769. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131770. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131771. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131772. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131773. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131774. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131775. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131776. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131777. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131778. 10,
  131779. };
  131780. static float _vq_quantthresh__8u1__p9_0[] = {
  131781. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131782. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131783. };
  131784. static long _vq_quantmap__8u1__p9_0[] = {
  131785. 13, 11, 9, 7, 5, 3, 1, 0,
  131786. 2, 4, 6, 8, 10, 12, 14,
  131787. };
  131788. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131789. _vq_quantthresh__8u1__p9_0,
  131790. _vq_quantmap__8u1__p9_0,
  131791. 15,
  131792. 15
  131793. };
  131794. static static_codebook _8u1__p9_0 = {
  131795. 2, 225,
  131796. _vq_lengthlist__8u1__p9_0,
  131797. 1, -514071552, 1627381760, 4, 0,
  131798. _vq_quantlist__8u1__p9_0,
  131799. NULL,
  131800. &_vq_auxt__8u1__p9_0,
  131801. NULL,
  131802. 0
  131803. };
  131804. static long _vq_quantlist__8u1__p9_1[] = {
  131805. 7,
  131806. 6,
  131807. 8,
  131808. 5,
  131809. 9,
  131810. 4,
  131811. 10,
  131812. 3,
  131813. 11,
  131814. 2,
  131815. 12,
  131816. 1,
  131817. 13,
  131818. 0,
  131819. 14,
  131820. };
  131821. static long _vq_lengthlist__8u1__p9_1[] = {
  131822. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131823. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131824. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131825. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131826. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131827. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131828. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131829. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131830. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131831. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131832. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131833. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131834. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131835. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131836. 13,
  131837. };
  131838. static float _vq_quantthresh__8u1__p9_1[] = {
  131839. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131840. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131841. };
  131842. static long _vq_quantmap__8u1__p9_1[] = {
  131843. 13, 11, 9, 7, 5, 3, 1, 0,
  131844. 2, 4, 6, 8, 10, 12, 14,
  131845. };
  131846. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131847. _vq_quantthresh__8u1__p9_1,
  131848. _vq_quantmap__8u1__p9_1,
  131849. 15,
  131850. 15
  131851. };
  131852. static static_codebook _8u1__p9_1 = {
  131853. 2, 225,
  131854. _vq_lengthlist__8u1__p9_1,
  131855. 1, -522338304, 1620115456, 4, 0,
  131856. _vq_quantlist__8u1__p9_1,
  131857. NULL,
  131858. &_vq_auxt__8u1__p9_1,
  131859. NULL,
  131860. 0
  131861. };
  131862. static long _vq_quantlist__8u1__p9_2[] = {
  131863. 8,
  131864. 7,
  131865. 9,
  131866. 6,
  131867. 10,
  131868. 5,
  131869. 11,
  131870. 4,
  131871. 12,
  131872. 3,
  131873. 13,
  131874. 2,
  131875. 14,
  131876. 1,
  131877. 15,
  131878. 0,
  131879. 16,
  131880. };
  131881. static long _vq_lengthlist__8u1__p9_2[] = {
  131882. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131883. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131884. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131885. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131886. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131887. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131888. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131889. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131890. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131891. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131892. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131893. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131894. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131895. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131896. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131897. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131898. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131899. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131900. 10,
  131901. };
  131902. static float _vq_quantthresh__8u1__p9_2[] = {
  131903. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131904. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131905. };
  131906. static long _vq_quantmap__8u1__p9_2[] = {
  131907. 15, 13, 11, 9, 7, 5, 3, 1,
  131908. 0, 2, 4, 6, 8, 10, 12, 14,
  131909. 16,
  131910. };
  131911. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131912. _vq_quantthresh__8u1__p9_2,
  131913. _vq_quantmap__8u1__p9_2,
  131914. 17,
  131915. 17
  131916. };
  131917. static static_codebook _8u1__p9_2 = {
  131918. 2, 289,
  131919. _vq_lengthlist__8u1__p9_2,
  131920. 1, -529530880, 1611661312, 5, 0,
  131921. _vq_quantlist__8u1__p9_2,
  131922. NULL,
  131923. &_vq_auxt__8u1__p9_2,
  131924. NULL,
  131925. 0
  131926. };
  131927. static long _huff_lengthlist__8u1__single[] = {
  131928. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131929. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131930. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131931. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131932. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131933. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131934. 13, 8, 8,15,
  131935. };
  131936. static static_codebook _huff_book__8u1__single = {
  131937. 2, 100,
  131938. _huff_lengthlist__8u1__single,
  131939. 0, 0, 0, 0, 0,
  131940. NULL,
  131941. NULL,
  131942. NULL,
  131943. NULL,
  131944. 0
  131945. };
  131946. static long _huff_lengthlist__44u0__long[] = {
  131947. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131948. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131949. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131950. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131951. };
  131952. static static_codebook _huff_book__44u0__long = {
  131953. 2, 64,
  131954. _huff_lengthlist__44u0__long,
  131955. 0, 0, 0, 0, 0,
  131956. NULL,
  131957. NULL,
  131958. NULL,
  131959. NULL,
  131960. 0
  131961. };
  131962. static long _vq_quantlist__44u0__p1_0[] = {
  131963. 1,
  131964. 0,
  131965. 2,
  131966. };
  131967. static long _vq_lengthlist__44u0__p1_0[] = {
  131968. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131969. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131970. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131971. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131972. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131973. 13,
  131974. };
  131975. static float _vq_quantthresh__44u0__p1_0[] = {
  131976. -0.5, 0.5,
  131977. };
  131978. static long _vq_quantmap__44u0__p1_0[] = {
  131979. 1, 0, 2,
  131980. };
  131981. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131982. _vq_quantthresh__44u0__p1_0,
  131983. _vq_quantmap__44u0__p1_0,
  131984. 3,
  131985. 3
  131986. };
  131987. static static_codebook _44u0__p1_0 = {
  131988. 4, 81,
  131989. _vq_lengthlist__44u0__p1_0,
  131990. 1, -535822336, 1611661312, 2, 0,
  131991. _vq_quantlist__44u0__p1_0,
  131992. NULL,
  131993. &_vq_auxt__44u0__p1_0,
  131994. NULL,
  131995. 0
  131996. };
  131997. static long _vq_quantlist__44u0__p2_0[] = {
  131998. 1,
  131999. 0,
  132000. 2,
  132001. };
  132002. static long _vq_lengthlist__44u0__p2_0[] = {
  132003. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132004. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132005. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132006. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132007. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132008. 9,
  132009. };
  132010. static float _vq_quantthresh__44u0__p2_0[] = {
  132011. -0.5, 0.5,
  132012. };
  132013. static long _vq_quantmap__44u0__p2_0[] = {
  132014. 1, 0, 2,
  132015. };
  132016. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  132017. _vq_quantthresh__44u0__p2_0,
  132018. _vq_quantmap__44u0__p2_0,
  132019. 3,
  132020. 3
  132021. };
  132022. static static_codebook _44u0__p2_0 = {
  132023. 4, 81,
  132024. _vq_lengthlist__44u0__p2_0,
  132025. 1, -535822336, 1611661312, 2, 0,
  132026. _vq_quantlist__44u0__p2_0,
  132027. NULL,
  132028. &_vq_auxt__44u0__p2_0,
  132029. NULL,
  132030. 0
  132031. };
  132032. static long _vq_quantlist__44u0__p3_0[] = {
  132033. 2,
  132034. 1,
  132035. 3,
  132036. 0,
  132037. 4,
  132038. };
  132039. static long _vq_lengthlist__44u0__p3_0[] = {
  132040. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132041. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132042. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132043. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132044. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132045. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132046. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132047. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132048. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132049. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132050. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132051. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132052. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132053. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132054. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132055. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132056. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132057. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132058. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132059. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132060. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132061. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132062. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132063. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132064. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132065. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132066. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132067. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132068. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132069. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132070. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132071. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132072. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132073. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132074. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132075. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132076. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132077. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132078. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132079. 19,
  132080. };
  132081. static float _vq_quantthresh__44u0__p3_0[] = {
  132082. -1.5, -0.5, 0.5, 1.5,
  132083. };
  132084. static long _vq_quantmap__44u0__p3_0[] = {
  132085. 3, 1, 0, 2, 4,
  132086. };
  132087. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  132088. _vq_quantthresh__44u0__p3_0,
  132089. _vq_quantmap__44u0__p3_0,
  132090. 5,
  132091. 5
  132092. };
  132093. static static_codebook _44u0__p3_0 = {
  132094. 4, 625,
  132095. _vq_lengthlist__44u0__p3_0,
  132096. 1, -533725184, 1611661312, 3, 0,
  132097. _vq_quantlist__44u0__p3_0,
  132098. NULL,
  132099. &_vq_auxt__44u0__p3_0,
  132100. NULL,
  132101. 0
  132102. };
  132103. static long _vq_quantlist__44u0__p4_0[] = {
  132104. 2,
  132105. 1,
  132106. 3,
  132107. 0,
  132108. 4,
  132109. };
  132110. static long _vq_lengthlist__44u0__p4_0[] = {
  132111. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132112. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132113. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132114. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132115. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132116. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132117. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132118. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132119. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132120. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132121. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132122. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132123. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132124. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132125. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132126. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132127. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132128. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132129. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132130. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132131. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132132. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132133. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132134. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132135. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132136. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132137. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132138. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132139. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132140. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132141. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132142. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132143. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132144. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132145. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132146. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132147. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132148. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132149. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132150. 12,
  132151. };
  132152. static float _vq_quantthresh__44u0__p4_0[] = {
  132153. -1.5, -0.5, 0.5, 1.5,
  132154. };
  132155. static long _vq_quantmap__44u0__p4_0[] = {
  132156. 3, 1, 0, 2, 4,
  132157. };
  132158. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  132159. _vq_quantthresh__44u0__p4_0,
  132160. _vq_quantmap__44u0__p4_0,
  132161. 5,
  132162. 5
  132163. };
  132164. static static_codebook _44u0__p4_0 = {
  132165. 4, 625,
  132166. _vq_lengthlist__44u0__p4_0,
  132167. 1, -533725184, 1611661312, 3, 0,
  132168. _vq_quantlist__44u0__p4_0,
  132169. NULL,
  132170. &_vq_auxt__44u0__p4_0,
  132171. NULL,
  132172. 0
  132173. };
  132174. static long _vq_quantlist__44u0__p5_0[] = {
  132175. 4,
  132176. 3,
  132177. 5,
  132178. 2,
  132179. 6,
  132180. 1,
  132181. 7,
  132182. 0,
  132183. 8,
  132184. };
  132185. static long _vq_lengthlist__44u0__p5_0[] = {
  132186. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132187. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132188. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132189. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132190. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132191. 12,
  132192. };
  132193. static float _vq_quantthresh__44u0__p5_0[] = {
  132194. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132195. };
  132196. static long _vq_quantmap__44u0__p5_0[] = {
  132197. 7, 5, 3, 1, 0, 2, 4, 6,
  132198. 8,
  132199. };
  132200. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  132201. _vq_quantthresh__44u0__p5_0,
  132202. _vq_quantmap__44u0__p5_0,
  132203. 9,
  132204. 9
  132205. };
  132206. static static_codebook _44u0__p5_0 = {
  132207. 2, 81,
  132208. _vq_lengthlist__44u0__p5_0,
  132209. 1, -531628032, 1611661312, 4, 0,
  132210. _vq_quantlist__44u0__p5_0,
  132211. NULL,
  132212. &_vq_auxt__44u0__p5_0,
  132213. NULL,
  132214. 0
  132215. };
  132216. static long _vq_quantlist__44u0__p6_0[] = {
  132217. 6,
  132218. 5,
  132219. 7,
  132220. 4,
  132221. 8,
  132222. 3,
  132223. 9,
  132224. 2,
  132225. 10,
  132226. 1,
  132227. 11,
  132228. 0,
  132229. 12,
  132230. };
  132231. static long _vq_lengthlist__44u0__p6_0[] = {
  132232. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132233. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132234. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132235. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132236. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132237. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132238. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132239. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132240. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132241. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132242. 15,17,16,17,18,17,17,18, 0,
  132243. };
  132244. static float _vq_quantthresh__44u0__p6_0[] = {
  132245. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132246. 12.5, 17.5, 22.5, 27.5,
  132247. };
  132248. static long _vq_quantmap__44u0__p6_0[] = {
  132249. 11, 9, 7, 5, 3, 1, 0, 2,
  132250. 4, 6, 8, 10, 12,
  132251. };
  132252. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  132253. _vq_quantthresh__44u0__p6_0,
  132254. _vq_quantmap__44u0__p6_0,
  132255. 13,
  132256. 13
  132257. };
  132258. static static_codebook _44u0__p6_0 = {
  132259. 2, 169,
  132260. _vq_lengthlist__44u0__p6_0,
  132261. 1, -526516224, 1616117760, 4, 0,
  132262. _vq_quantlist__44u0__p6_0,
  132263. NULL,
  132264. &_vq_auxt__44u0__p6_0,
  132265. NULL,
  132266. 0
  132267. };
  132268. static long _vq_quantlist__44u0__p6_1[] = {
  132269. 2,
  132270. 1,
  132271. 3,
  132272. 0,
  132273. 4,
  132274. };
  132275. static long _vq_lengthlist__44u0__p6_1[] = {
  132276. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132277. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132278. };
  132279. static float _vq_quantthresh__44u0__p6_1[] = {
  132280. -1.5, -0.5, 0.5, 1.5,
  132281. };
  132282. static long _vq_quantmap__44u0__p6_1[] = {
  132283. 3, 1, 0, 2, 4,
  132284. };
  132285. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132286. _vq_quantthresh__44u0__p6_1,
  132287. _vq_quantmap__44u0__p6_1,
  132288. 5,
  132289. 5
  132290. };
  132291. static static_codebook _44u0__p6_1 = {
  132292. 2, 25,
  132293. _vq_lengthlist__44u0__p6_1,
  132294. 1, -533725184, 1611661312, 3, 0,
  132295. _vq_quantlist__44u0__p6_1,
  132296. NULL,
  132297. &_vq_auxt__44u0__p6_1,
  132298. NULL,
  132299. 0
  132300. };
  132301. static long _vq_quantlist__44u0__p7_0[] = {
  132302. 2,
  132303. 1,
  132304. 3,
  132305. 0,
  132306. 4,
  132307. };
  132308. static long _vq_lengthlist__44u0__p7_0[] = {
  132309. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132310. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132311. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132312. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132313. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132314. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132315. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132316. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132317. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132318. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132319. 11,11,11,11,11,11,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,11,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,11,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,10,10,10,10,10,10,10,10,10,10,
  132340. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132341. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132342. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132343. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132344. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132345. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132346. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132347. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132348. 10,
  132349. };
  132350. static float _vq_quantthresh__44u0__p7_0[] = {
  132351. -253.5, -84.5, 84.5, 253.5,
  132352. };
  132353. static long _vq_quantmap__44u0__p7_0[] = {
  132354. 3, 1, 0, 2, 4,
  132355. };
  132356. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132357. _vq_quantthresh__44u0__p7_0,
  132358. _vq_quantmap__44u0__p7_0,
  132359. 5,
  132360. 5
  132361. };
  132362. static static_codebook _44u0__p7_0 = {
  132363. 4, 625,
  132364. _vq_lengthlist__44u0__p7_0,
  132365. 1, -518709248, 1626677248, 3, 0,
  132366. _vq_quantlist__44u0__p7_0,
  132367. NULL,
  132368. &_vq_auxt__44u0__p7_0,
  132369. NULL,
  132370. 0
  132371. };
  132372. static long _vq_quantlist__44u0__p7_1[] = {
  132373. 6,
  132374. 5,
  132375. 7,
  132376. 4,
  132377. 8,
  132378. 3,
  132379. 9,
  132380. 2,
  132381. 10,
  132382. 1,
  132383. 11,
  132384. 0,
  132385. 12,
  132386. };
  132387. static long _vq_lengthlist__44u0__p7_1[] = {
  132388. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132389. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132390. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132391. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132392. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132393. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132394. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132395. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132396. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132397. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132398. 15,15,15,15,15,15,15,15,15,
  132399. };
  132400. static float _vq_quantthresh__44u0__p7_1[] = {
  132401. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132402. 32.5, 45.5, 58.5, 71.5,
  132403. };
  132404. static long _vq_quantmap__44u0__p7_1[] = {
  132405. 11, 9, 7, 5, 3, 1, 0, 2,
  132406. 4, 6, 8, 10, 12,
  132407. };
  132408. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132409. _vq_quantthresh__44u0__p7_1,
  132410. _vq_quantmap__44u0__p7_1,
  132411. 13,
  132412. 13
  132413. };
  132414. static static_codebook _44u0__p7_1 = {
  132415. 2, 169,
  132416. _vq_lengthlist__44u0__p7_1,
  132417. 1, -523010048, 1618608128, 4, 0,
  132418. _vq_quantlist__44u0__p7_1,
  132419. NULL,
  132420. &_vq_auxt__44u0__p7_1,
  132421. NULL,
  132422. 0
  132423. };
  132424. static long _vq_quantlist__44u0__p7_2[] = {
  132425. 6,
  132426. 5,
  132427. 7,
  132428. 4,
  132429. 8,
  132430. 3,
  132431. 9,
  132432. 2,
  132433. 10,
  132434. 1,
  132435. 11,
  132436. 0,
  132437. 12,
  132438. };
  132439. static long _vq_lengthlist__44u0__p7_2[] = {
  132440. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132441. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132442. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132443. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132444. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132445. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132446. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132447. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132448. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132449. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132450. 9, 9, 9,10, 9, 9,10,10, 9,
  132451. };
  132452. static float _vq_quantthresh__44u0__p7_2[] = {
  132453. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132454. 2.5, 3.5, 4.5, 5.5,
  132455. };
  132456. static long _vq_quantmap__44u0__p7_2[] = {
  132457. 11, 9, 7, 5, 3, 1, 0, 2,
  132458. 4, 6, 8, 10, 12,
  132459. };
  132460. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132461. _vq_quantthresh__44u0__p7_2,
  132462. _vq_quantmap__44u0__p7_2,
  132463. 13,
  132464. 13
  132465. };
  132466. static static_codebook _44u0__p7_2 = {
  132467. 2, 169,
  132468. _vq_lengthlist__44u0__p7_2,
  132469. 1, -531103744, 1611661312, 4, 0,
  132470. _vq_quantlist__44u0__p7_2,
  132471. NULL,
  132472. &_vq_auxt__44u0__p7_2,
  132473. NULL,
  132474. 0
  132475. };
  132476. static long _huff_lengthlist__44u0__short[] = {
  132477. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132478. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132479. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132480. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132481. };
  132482. static static_codebook _huff_book__44u0__short = {
  132483. 2, 64,
  132484. _huff_lengthlist__44u0__short,
  132485. 0, 0, 0, 0, 0,
  132486. NULL,
  132487. NULL,
  132488. NULL,
  132489. NULL,
  132490. 0
  132491. };
  132492. static long _huff_lengthlist__44u1__long[] = {
  132493. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132494. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132495. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132496. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132497. };
  132498. static static_codebook _huff_book__44u1__long = {
  132499. 2, 64,
  132500. _huff_lengthlist__44u1__long,
  132501. 0, 0, 0, 0, 0,
  132502. NULL,
  132503. NULL,
  132504. NULL,
  132505. NULL,
  132506. 0
  132507. };
  132508. static long _vq_quantlist__44u1__p1_0[] = {
  132509. 1,
  132510. 0,
  132511. 2,
  132512. };
  132513. static long _vq_lengthlist__44u1__p1_0[] = {
  132514. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132515. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132516. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132517. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132518. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132519. 13,
  132520. };
  132521. static float _vq_quantthresh__44u1__p1_0[] = {
  132522. -0.5, 0.5,
  132523. };
  132524. static long _vq_quantmap__44u1__p1_0[] = {
  132525. 1, 0, 2,
  132526. };
  132527. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132528. _vq_quantthresh__44u1__p1_0,
  132529. _vq_quantmap__44u1__p1_0,
  132530. 3,
  132531. 3
  132532. };
  132533. static static_codebook _44u1__p1_0 = {
  132534. 4, 81,
  132535. _vq_lengthlist__44u1__p1_0,
  132536. 1, -535822336, 1611661312, 2, 0,
  132537. _vq_quantlist__44u1__p1_0,
  132538. NULL,
  132539. &_vq_auxt__44u1__p1_0,
  132540. NULL,
  132541. 0
  132542. };
  132543. static long _vq_quantlist__44u1__p2_0[] = {
  132544. 1,
  132545. 0,
  132546. 2,
  132547. };
  132548. static long _vq_lengthlist__44u1__p2_0[] = {
  132549. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132550. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132551. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132552. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132553. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132554. 9,
  132555. };
  132556. static float _vq_quantthresh__44u1__p2_0[] = {
  132557. -0.5, 0.5,
  132558. };
  132559. static long _vq_quantmap__44u1__p2_0[] = {
  132560. 1, 0, 2,
  132561. };
  132562. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132563. _vq_quantthresh__44u1__p2_0,
  132564. _vq_quantmap__44u1__p2_0,
  132565. 3,
  132566. 3
  132567. };
  132568. static static_codebook _44u1__p2_0 = {
  132569. 4, 81,
  132570. _vq_lengthlist__44u1__p2_0,
  132571. 1, -535822336, 1611661312, 2, 0,
  132572. _vq_quantlist__44u1__p2_0,
  132573. NULL,
  132574. &_vq_auxt__44u1__p2_0,
  132575. NULL,
  132576. 0
  132577. };
  132578. static long _vq_quantlist__44u1__p3_0[] = {
  132579. 2,
  132580. 1,
  132581. 3,
  132582. 0,
  132583. 4,
  132584. };
  132585. static long _vq_lengthlist__44u1__p3_0[] = {
  132586. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132587. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132588. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132589. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132590. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132591. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132592. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132593. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132594. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132595. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132596. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132597. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132598. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132599. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132600. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132601. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132602. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132603. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132604. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132605. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132606. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132607. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132608. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132609. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132610. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132611. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132612. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132613. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132614. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132615. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132616. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132617. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132618. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132619. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132620. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132621. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132622. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132623. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132624. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132625. 19,
  132626. };
  132627. static float _vq_quantthresh__44u1__p3_0[] = {
  132628. -1.5, -0.5, 0.5, 1.5,
  132629. };
  132630. static long _vq_quantmap__44u1__p3_0[] = {
  132631. 3, 1, 0, 2, 4,
  132632. };
  132633. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132634. _vq_quantthresh__44u1__p3_0,
  132635. _vq_quantmap__44u1__p3_0,
  132636. 5,
  132637. 5
  132638. };
  132639. static static_codebook _44u1__p3_0 = {
  132640. 4, 625,
  132641. _vq_lengthlist__44u1__p3_0,
  132642. 1, -533725184, 1611661312, 3, 0,
  132643. _vq_quantlist__44u1__p3_0,
  132644. NULL,
  132645. &_vq_auxt__44u1__p3_0,
  132646. NULL,
  132647. 0
  132648. };
  132649. static long _vq_quantlist__44u1__p4_0[] = {
  132650. 2,
  132651. 1,
  132652. 3,
  132653. 0,
  132654. 4,
  132655. };
  132656. static long _vq_lengthlist__44u1__p4_0[] = {
  132657. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132658. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132659. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132660. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132661. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132662. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132663. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132664. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132665. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132666. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132667. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132668. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132669. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132670. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132671. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132672. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132673. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132674. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132675. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132676. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132677. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132678. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132679. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132680. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132681. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132682. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132683. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132684. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132685. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132686. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132687. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132688. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132689. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132690. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132691. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132692. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132693. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132694. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132695. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132696. 12,
  132697. };
  132698. static float _vq_quantthresh__44u1__p4_0[] = {
  132699. -1.5, -0.5, 0.5, 1.5,
  132700. };
  132701. static long _vq_quantmap__44u1__p4_0[] = {
  132702. 3, 1, 0, 2, 4,
  132703. };
  132704. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132705. _vq_quantthresh__44u1__p4_0,
  132706. _vq_quantmap__44u1__p4_0,
  132707. 5,
  132708. 5
  132709. };
  132710. static static_codebook _44u1__p4_0 = {
  132711. 4, 625,
  132712. _vq_lengthlist__44u1__p4_0,
  132713. 1, -533725184, 1611661312, 3, 0,
  132714. _vq_quantlist__44u1__p4_0,
  132715. NULL,
  132716. &_vq_auxt__44u1__p4_0,
  132717. NULL,
  132718. 0
  132719. };
  132720. static long _vq_quantlist__44u1__p5_0[] = {
  132721. 4,
  132722. 3,
  132723. 5,
  132724. 2,
  132725. 6,
  132726. 1,
  132727. 7,
  132728. 0,
  132729. 8,
  132730. };
  132731. static long _vq_lengthlist__44u1__p5_0[] = {
  132732. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132733. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132734. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132735. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132736. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132737. 12,
  132738. };
  132739. static float _vq_quantthresh__44u1__p5_0[] = {
  132740. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132741. };
  132742. static long _vq_quantmap__44u1__p5_0[] = {
  132743. 7, 5, 3, 1, 0, 2, 4, 6,
  132744. 8,
  132745. };
  132746. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132747. _vq_quantthresh__44u1__p5_0,
  132748. _vq_quantmap__44u1__p5_0,
  132749. 9,
  132750. 9
  132751. };
  132752. static static_codebook _44u1__p5_0 = {
  132753. 2, 81,
  132754. _vq_lengthlist__44u1__p5_0,
  132755. 1, -531628032, 1611661312, 4, 0,
  132756. _vq_quantlist__44u1__p5_0,
  132757. NULL,
  132758. &_vq_auxt__44u1__p5_0,
  132759. NULL,
  132760. 0
  132761. };
  132762. static long _vq_quantlist__44u1__p6_0[] = {
  132763. 6,
  132764. 5,
  132765. 7,
  132766. 4,
  132767. 8,
  132768. 3,
  132769. 9,
  132770. 2,
  132771. 10,
  132772. 1,
  132773. 11,
  132774. 0,
  132775. 12,
  132776. };
  132777. static long _vq_lengthlist__44u1__p6_0[] = {
  132778. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132779. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132780. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132781. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132782. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132783. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132784. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132785. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132786. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132787. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132788. 15,17,16,17,18,17,17,18, 0,
  132789. };
  132790. static float _vq_quantthresh__44u1__p6_0[] = {
  132791. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132792. 12.5, 17.5, 22.5, 27.5,
  132793. };
  132794. static long _vq_quantmap__44u1__p6_0[] = {
  132795. 11, 9, 7, 5, 3, 1, 0, 2,
  132796. 4, 6, 8, 10, 12,
  132797. };
  132798. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132799. _vq_quantthresh__44u1__p6_0,
  132800. _vq_quantmap__44u1__p6_0,
  132801. 13,
  132802. 13
  132803. };
  132804. static static_codebook _44u1__p6_0 = {
  132805. 2, 169,
  132806. _vq_lengthlist__44u1__p6_0,
  132807. 1, -526516224, 1616117760, 4, 0,
  132808. _vq_quantlist__44u1__p6_0,
  132809. NULL,
  132810. &_vq_auxt__44u1__p6_0,
  132811. NULL,
  132812. 0
  132813. };
  132814. static long _vq_quantlist__44u1__p6_1[] = {
  132815. 2,
  132816. 1,
  132817. 3,
  132818. 0,
  132819. 4,
  132820. };
  132821. static long _vq_lengthlist__44u1__p6_1[] = {
  132822. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132823. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132824. };
  132825. static float _vq_quantthresh__44u1__p6_1[] = {
  132826. -1.5, -0.5, 0.5, 1.5,
  132827. };
  132828. static long _vq_quantmap__44u1__p6_1[] = {
  132829. 3, 1, 0, 2, 4,
  132830. };
  132831. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132832. _vq_quantthresh__44u1__p6_1,
  132833. _vq_quantmap__44u1__p6_1,
  132834. 5,
  132835. 5
  132836. };
  132837. static static_codebook _44u1__p6_1 = {
  132838. 2, 25,
  132839. _vq_lengthlist__44u1__p6_1,
  132840. 1, -533725184, 1611661312, 3, 0,
  132841. _vq_quantlist__44u1__p6_1,
  132842. NULL,
  132843. &_vq_auxt__44u1__p6_1,
  132844. NULL,
  132845. 0
  132846. };
  132847. static long _vq_quantlist__44u1__p7_0[] = {
  132848. 3,
  132849. 2,
  132850. 4,
  132851. 1,
  132852. 5,
  132853. 0,
  132854. 6,
  132855. };
  132856. static long _vq_lengthlist__44u1__p7_0[] = {
  132857. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132858. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132859. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132860. 8,
  132861. };
  132862. static float _vq_quantthresh__44u1__p7_0[] = {
  132863. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132864. };
  132865. static long _vq_quantmap__44u1__p7_0[] = {
  132866. 5, 3, 1, 0, 2, 4, 6,
  132867. };
  132868. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132869. _vq_quantthresh__44u1__p7_0,
  132870. _vq_quantmap__44u1__p7_0,
  132871. 7,
  132872. 7
  132873. };
  132874. static static_codebook _44u1__p7_0 = {
  132875. 2, 49,
  132876. _vq_lengthlist__44u1__p7_0,
  132877. 1, -518017024, 1626677248, 3, 0,
  132878. _vq_quantlist__44u1__p7_0,
  132879. NULL,
  132880. &_vq_auxt__44u1__p7_0,
  132881. NULL,
  132882. 0
  132883. };
  132884. static long _vq_quantlist__44u1__p7_1[] = {
  132885. 6,
  132886. 5,
  132887. 7,
  132888. 4,
  132889. 8,
  132890. 3,
  132891. 9,
  132892. 2,
  132893. 10,
  132894. 1,
  132895. 11,
  132896. 0,
  132897. 12,
  132898. };
  132899. static long _vq_lengthlist__44u1__p7_1[] = {
  132900. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132901. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132902. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132903. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132904. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132905. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132906. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132907. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132908. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132909. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132910. 15,15,15,15,15,15,15,15,15,
  132911. };
  132912. static float _vq_quantthresh__44u1__p7_1[] = {
  132913. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132914. 32.5, 45.5, 58.5, 71.5,
  132915. };
  132916. static long _vq_quantmap__44u1__p7_1[] = {
  132917. 11, 9, 7, 5, 3, 1, 0, 2,
  132918. 4, 6, 8, 10, 12,
  132919. };
  132920. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132921. _vq_quantthresh__44u1__p7_1,
  132922. _vq_quantmap__44u1__p7_1,
  132923. 13,
  132924. 13
  132925. };
  132926. static static_codebook _44u1__p7_1 = {
  132927. 2, 169,
  132928. _vq_lengthlist__44u1__p7_1,
  132929. 1, -523010048, 1618608128, 4, 0,
  132930. _vq_quantlist__44u1__p7_1,
  132931. NULL,
  132932. &_vq_auxt__44u1__p7_1,
  132933. NULL,
  132934. 0
  132935. };
  132936. static long _vq_quantlist__44u1__p7_2[] = {
  132937. 6,
  132938. 5,
  132939. 7,
  132940. 4,
  132941. 8,
  132942. 3,
  132943. 9,
  132944. 2,
  132945. 10,
  132946. 1,
  132947. 11,
  132948. 0,
  132949. 12,
  132950. };
  132951. static long _vq_lengthlist__44u1__p7_2[] = {
  132952. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132953. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132954. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132955. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132956. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132957. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132958. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132959. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132960. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132961. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132962. 9, 9, 9,10, 9, 9,10,10, 9,
  132963. };
  132964. static float _vq_quantthresh__44u1__p7_2[] = {
  132965. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132966. 2.5, 3.5, 4.5, 5.5,
  132967. };
  132968. static long _vq_quantmap__44u1__p7_2[] = {
  132969. 11, 9, 7, 5, 3, 1, 0, 2,
  132970. 4, 6, 8, 10, 12,
  132971. };
  132972. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132973. _vq_quantthresh__44u1__p7_2,
  132974. _vq_quantmap__44u1__p7_2,
  132975. 13,
  132976. 13
  132977. };
  132978. static static_codebook _44u1__p7_2 = {
  132979. 2, 169,
  132980. _vq_lengthlist__44u1__p7_2,
  132981. 1, -531103744, 1611661312, 4, 0,
  132982. _vq_quantlist__44u1__p7_2,
  132983. NULL,
  132984. &_vq_auxt__44u1__p7_2,
  132985. NULL,
  132986. 0
  132987. };
  132988. static long _huff_lengthlist__44u1__short[] = {
  132989. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132990. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132991. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132992. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132993. };
  132994. static static_codebook _huff_book__44u1__short = {
  132995. 2, 64,
  132996. _huff_lengthlist__44u1__short,
  132997. 0, 0, 0, 0, 0,
  132998. NULL,
  132999. NULL,
  133000. NULL,
  133001. NULL,
  133002. 0
  133003. };
  133004. static long _huff_lengthlist__44u2__long[] = {
  133005. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  133006. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  133007. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  133008. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  133009. };
  133010. static static_codebook _huff_book__44u2__long = {
  133011. 2, 64,
  133012. _huff_lengthlist__44u2__long,
  133013. 0, 0, 0, 0, 0,
  133014. NULL,
  133015. NULL,
  133016. NULL,
  133017. NULL,
  133018. 0
  133019. };
  133020. static long _vq_quantlist__44u2__p1_0[] = {
  133021. 1,
  133022. 0,
  133023. 2,
  133024. };
  133025. static long _vq_lengthlist__44u2__p1_0[] = {
  133026. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  133027. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133028. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  133029. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  133030. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  133031. 13,
  133032. };
  133033. static float _vq_quantthresh__44u2__p1_0[] = {
  133034. -0.5, 0.5,
  133035. };
  133036. static long _vq_quantmap__44u2__p1_0[] = {
  133037. 1, 0, 2,
  133038. };
  133039. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  133040. _vq_quantthresh__44u2__p1_0,
  133041. _vq_quantmap__44u2__p1_0,
  133042. 3,
  133043. 3
  133044. };
  133045. static static_codebook _44u2__p1_0 = {
  133046. 4, 81,
  133047. _vq_lengthlist__44u2__p1_0,
  133048. 1, -535822336, 1611661312, 2, 0,
  133049. _vq_quantlist__44u2__p1_0,
  133050. NULL,
  133051. &_vq_auxt__44u2__p1_0,
  133052. NULL,
  133053. 0
  133054. };
  133055. static long _vq_quantlist__44u2__p2_0[] = {
  133056. 1,
  133057. 0,
  133058. 2,
  133059. };
  133060. static long _vq_lengthlist__44u2__p2_0[] = {
  133061. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133062. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  133063. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133064. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133065. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133066. 9,
  133067. };
  133068. static float _vq_quantthresh__44u2__p2_0[] = {
  133069. -0.5, 0.5,
  133070. };
  133071. static long _vq_quantmap__44u2__p2_0[] = {
  133072. 1, 0, 2,
  133073. };
  133074. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  133075. _vq_quantthresh__44u2__p2_0,
  133076. _vq_quantmap__44u2__p2_0,
  133077. 3,
  133078. 3
  133079. };
  133080. static static_codebook _44u2__p2_0 = {
  133081. 4, 81,
  133082. _vq_lengthlist__44u2__p2_0,
  133083. 1, -535822336, 1611661312, 2, 0,
  133084. _vq_quantlist__44u2__p2_0,
  133085. NULL,
  133086. &_vq_auxt__44u2__p2_0,
  133087. NULL,
  133088. 0
  133089. };
  133090. static long _vq_quantlist__44u2__p3_0[] = {
  133091. 2,
  133092. 1,
  133093. 3,
  133094. 0,
  133095. 4,
  133096. };
  133097. static long _vq_lengthlist__44u2__p3_0[] = {
  133098. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133099. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133100. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133101. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133102. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  133103. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  133104. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  133105. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  133106. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133107. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133108. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  133109. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133110. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  133111. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  133112. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  133113. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  133114. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  133115. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  133116. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  133117. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  133118. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  133119. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  133120. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  133121. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  133122. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  133123. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  133124. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  133125. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  133126. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  133127. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  133128. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  133129. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  133130. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  133131. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  133132. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  133133. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  133134. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  133135. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  133136. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  133137. 0,
  133138. };
  133139. static float _vq_quantthresh__44u2__p3_0[] = {
  133140. -1.5, -0.5, 0.5, 1.5,
  133141. };
  133142. static long _vq_quantmap__44u2__p3_0[] = {
  133143. 3, 1, 0, 2, 4,
  133144. };
  133145. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  133146. _vq_quantthresh__44u2__p3_0,
  133147. _vq_quantmap__44u2__p3_0,
  133148. 5,
  133149. 5
  133150. };
  133151. static static_codebook _44u2__p3_0 = {
  133152. 4, 625,
  133153. _vq_lengthlist__44u2__p3_0,
  133154. 1, -533725184, 1611661312, 3, 0,
  133155. _vq_quantlist__44u2__p3_0,
  133156. NULL,
  133157. &_vq_auxt__44u2__p3_0,
  133158. NULL,
  133159. 0
  133160. };
  133161. static long _vq_quantlist__44u2__p4_0[] = {
  133162. 2,
  133163. 1,
  133164. 3,
  133165. 0,
  133166. 4,
  133167. };
  133168. static long _vq_lengthlist__44u2__p4_0[] = {
  133169. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133170. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133171. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  133172. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  133173. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  133174. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133175. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  133176. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  133177. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133178. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133179. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  133180. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133181. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  133182. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  133183. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  133184. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  133185. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  133186. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133187. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133188. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133189. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133190. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  133191. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133192. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133193. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133194. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  133195. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  133196. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  133197. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133198. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  133199. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  133200. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  133201. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  133202. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133203. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133204. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  133205. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133206. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  133207. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  133208. 13,
  133209. };
  133210. static float _vq_quantthresh__44u2__p4_0[] = {
  133211. -1.5, -0.5, 0.5, 1.5,
  133212. };
  133213. static long _vq_quantmap__44u2__p4_0[] = {
  133214. 3, 1, 0, 2, 4,
  133215. };
  133216. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  133217. _vq_quantthresh__44u2__p4_0,
  133218. _vq_quantmap__44u2__p4_0,
  133219. 5,
  133220. 5
  133221. };
  133222. static static_codebook _44u2__p4_0 = {
  133223. 4, 625,
  133224. _vq_lengthlist__44u2__p4_0,
  133225. 1, -533725184, 1611661312, 3, 0,
  133226. _vq_quantlist__44u2__p4_0,
  133227. NULL,
  133228. &_vq_auxt__44u2__p4_0,
  133229. NULL,
  133230. 0
  133231. };
  133232. static long _vq_quantlist__44u2__p5_0[] = {
  133233. 4,
  133234. 3,
  133235. 5,
  133236. 2,
  133237. 6,
  133238. 1,
  133239. 7,
  133240. 0,
  133241. 8,
  133242. };
  133243. static long _vq_lengthlist__44u2__p5_0[] = {
  133244. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  133245. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  133246. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  133247. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  133248. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  133249. 13,
  133250. };
  133251. static float _vq_quantthresh__44u2__p5_0[] = {
  133252. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133253. };
  133254. static long _vq_quantmap__44u2__p5_0[] = {
  133255. 7, 5, 3, 1, 0, 2, 4, 6,
  133256. 8,
  133257. };
  133258. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  133259. _vq_quantthresh__44u2__p5_0,
  133260. _vq_quantmap__44u2__p5_0,
  133261. 9,
  133262. 9
  133263. };
  133264. static static_codebook _44u2__p5_0 = {
  133265. 2, 81,
  133266. _vq_lengthlist__44u2__p5_0,
  133267. 1, -531628032, 1611661312, 4, 0,
  133268. _vq_quantlist__44u2__p5_0,
  133269. NULL,
  133270. &_vq_auxt__44u2__p5_0,
  133271. NULL,
  133272. 0
  133273. };
  133274. static long _vq_quantlist__44u2__p6_0[] = {
  133275. 6,
  133276. 5,
  133277. 7,
  133278. 4,
  133279. 8,
  133280. 3,
  133281. 9,
  133282. 2,
  133283. 10,
  133284. 1,
  133285. 11,
  133286. 0,
  133287. 12,
  133288. };
  133289. static long _vq_lengthlist__44u2__p6_0[] = {
  133290. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133291. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133292. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133293. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133294. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133295. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133296. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133297. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133298. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133299. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133300. 15,17,17,16,18,17,18, 0, 0,
  133301. };
  133302. static float _vq_quantthresh__44u2__p6_0[] = {
  133303. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133304. 12.5, 17.5, 22.5, 27.5,
  133305. };
  133306. static long _vq_quantmap__44u2__p6_0[] = {
  133307. 11, 9, 7, 5, 3, 1, 0, 2,
  133308. 4, 6, 8, 10, 12,
  133309. };
  133310. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133311. _vq_quantthresh__44u2__p6_0,
  133312. _vq_quantmap__44u2__p6_0,
  133313. 13,
  133314. 13
  133315. };
  133316. static static_codebook _44u2__p6_0 = {
  133317. 2, 169,
  133318. _vq_lengthlist__44u2__p6_0,
  133319. 1, -526516224, 1616117760, 4, 0,
  133320. _vq_quantlist__44u2__p6_0,
  133321. NULL,
  133322. &_vq_auxt__44u2__p6_0,
  133323. NULL,
  133324. 0
  133325. };
  133326. static long _vq_quantlist__44u2__p6_1[] = {
  133327. 2,
  133328. 1,
  133329. 3,
  133330. 0,
  133331. 4,
  133332. };
  133333. static long _vq_lengthlist__44u2__p6_1[] = {
  133334. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133335. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133336. };
  133337. static float _vq_quantthresh__44u2__p6_1[] = {
  133338. -1.5, -0.5, 0.5, 1.5,
  133339. };
  133340. static long _vq_quantmap__44u2__p6_1[] = {
  133341. 3, 1, 0, 2, 4,
  133342. };
  133343. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133344. _vq_quantthresh__44u2__p6_1,
  133345. _vq_quantmap__44u2__p6_1,
  133346. 5,
  133347. 5
  133348. };
  133349. static static_codebook _44u2__p6_1 = {
  133350. 2, 25,
  133351. _vq_lengthlist__44u2__p6_1,
  133352. 1, -533725184, 1611661312, 3, 0,
  133353. _vq_quantlist__44u2__p6_1,
  133354. NULL,
  133355. &_vq_auxt__44u2__p6_1,
  133356. NULL,
  133357. 0
  133358. };
  133359. static long _vq_quantlist__44u2__p7_0[] = {
  133360. 4,
  133361. 3,
  133362. 5,
  133363. 2,
  133364. 6,
  133365. 1,
  133366. 7,
  133367. 0,
  133368. 8,
  133369. };
  133370. static long _vq_lengthlist__44u2__p7_0[] = {
  133371. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133372. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133373. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133374. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133375. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133376. 11,
  133377. };
  133378. static float _vq_quantthresh__44u2__p7_0[] = {
  133379. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133380. };
  133381. static long _vq_quantmap__44u2__p7_0[] = {
  133382. 7, 5, 3, 1, 0, 2, 4, 6,
  133383. 8,
  133384. };
  133385. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133386. _vq_quantthresh__44u2__p7_0,
  133387. _vq_quantmap__44u2__p7_0,
  133388. 9,
  133389. 9
  133390. };
  133391. static static_codebook _44u2__p7_0 = {
  133392. 2, 81,
  133393. _vq_lengthlist__44u2__p7_0,
  133394. 1, -516612096, 1626677248, 4, 0,
  133395. _vq_quantlist__44u2__p7_0,
  133396. NULL,
  133397. &_vq_auxt__44u2__p7_0,
  133398. NULL,
  133399. 0
  133400. };
  133401. static long _vq_quantlist__44u2__p7_1[] = {
  133402. 6,
  133403. 5,
  133404. 7,
  133405. 4,
  133406. 8,
  133407. 3,
  133408. 9,
  133409. 2,
  133410. 10,
  133411. 1,
  133412. 11,
  133413. 0,
  133414. 12,
  133415. };
  133416. static long _vq_lengthlist__44u2__p7_1[] = {
  133417. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133418. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133419. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133420. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133421. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133422. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133423. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133424. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133425. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133426. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133427. 14,14,14,17,15,17,17,17,17,
  133428. };
  133429. static float _vq_quantthresh__44u2__p7_1[] = {
  133430. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133431. 32.5, 45.5, 58.5, 71.5,
  133432. };
  133433. static long _vq_quantmap__44u2__p7_1[] = {
  133434. 11, 9, 7, 5, 3, 1, 0, 2,
  133435. 4, 6, 8, 10, 12,
  133436. };
  133437. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133438. _vq_quantthresh__44u2__p7_1,
  133439. _vq_quantmap__44u2__p7_1,
  133440. 13,
  133441. 13
  133442. };
  133443. static static_codebook _44u2__p7_1 = {
  133444. 2, 169,
  133445. _vq_lengthlist__44u2__p7_1,
  133446. 1, -523010048, 1618608128, 4, 0,
  133447. _vq_quantlist__44u2__p7_1,
  133448. NULL,
  133449. &_vq_auxt__44u2__p7_1,
  133450. NULL,
  133451. 0
  133452. };
  133453. static long _vq_quantlist__44u2__p7_2[] = {
  133454. 6,
  133455. 5,
  133456. 7,
  133457. 4,
  133458. 8,
  133459. 3,
  133460. 9,
  133461. 2,
  133462. 10,
  133463. 1,
  133464. 11,
  133465. 0,
  133466. 12,
  133467. };
  133468. static long _vq_lengthlist__44u2__p7_2[] = {
  133469. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133470. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133471. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133472. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133473. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133474. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133475. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133476. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133477. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133478. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133479. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133480. };
  133481. static float _vq_quantthresh__44u2__p7_2[] = {
  133482. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133483. 2.5, 3.5, 4.5, 5.5,
  133484. };
  133485. static long _vq_quantmap__44u2__p7_2[] = {
  133486. 11, 9, 7, 5, 3, 1, 0, 2,
  133487. 4, 6, 8, 10, 12,
  133488. };
  133489. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133490. _vq_quantthresh__44u2__p7_2,
  133491. _vq_quantmap__44u2__p7_2,
  133492. 13,
  133493. 13
  133494. };
  133495. static static_codebook _44u2__p7_2 = {
  133496. 2, 169,
  133497. _vq_lengthlist__44u2__p7_2,
  133498. 1, -531103744, 1611661312, 4, 0,
  133499. _vq_quantlist__44u2__p7_2,
  133500. NULL,
  133501. &_vq_auxt__44u2__p7_2,
  133502. NULL,
  133503. 0
  133504. };
  133505. static long _huff_lengthlist__44u2__short[] = {
  133506. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133507. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133508. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133509. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133510. };
  133511. static static_codebook _huff_book__44u2__short = {
  133512. 2, 64,
  133513. _huff_lengthlist__44u2__short,
  133514. 0, 0, 0, 0, 0,
  133515. NULL,
  133516. NULL,
  133517. NULL,
  133518. NULL,
  133519. 0
  133520. };
  133521. static long _huff_lengthlist__44u3__long[] = {
  133522. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133523. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133524. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133525. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133526. };
  133527. static static_codebook _huff_book__44u3__long = {
  133528. 2, 64,
  133529. _huff_lengthlist__44u3__long,
  133530. 0, 0, 0, 0, 0,
  133531. NULL,
  133532. NULL,
  133533. NULL,
  133534. NULL,
  133535. 0
  133536. };
  133537. static long _vq_quantlist__44u3__p1_0[] = {
  133538. 1,
  133539. 0,
  133540. 2,
  133541. };
  133542. static long _vq_lengthlist__44u3__p1_0[] = {
  133543. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133544. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133545. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133546. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133547. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133548. 13,
  133549. };
  133550. static float _vq_quantthresh__44u3__p1_0[] = {
  133551. -0.5, 0.5,
  133552. };
  133553. static long _vq_quantmap__44u3__p1_0[] = {
  133554. 1, 0, 2,
  133555. };
  133556. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133557. _vq_quantthresh__44u3__p1_0,
  133558. _vq_quantmap__44u3__p1_0,
  133559. 3,
  133560. 3
  133561. };
  133562. static static_codebook _44u3__p1_0 = {
  133563. 4, 81,
  133564. _vq_lengthlist__44u3__p1_0,
  133565. 1, -535822336, 1611661312, 2, 0,
  133566. _vq_quantlist__44u3__p1_0,
  133567. NULL,
  133568. &_vq_auxt__44u3__p1_0,
  133569. NULL,
  133570. 0
  133571. };
  133572. static long _vq_quantlist__44u3__p2_0[] = {
  133573. 1,
  133574. 0,
  133575. 2,
  133576. };
  133577. static long _vq_lengthlist__44u3__p2_0[] = {
  133578. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133579. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133580. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133581. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133582. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133583. 9,
  133584. };
  133585. static float _vq_quantthresh__44u3__p2_0[] = {
  133586. -0.5, 0.5,
  133587. };
  133588. static long _vq_quantmap__44u3__p2_0[] = {
  133589. 1, 0, 2,
  133590. };
  133591. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133592. _vq_quantthresh__44u3__p2_0,
  133593. _vq_quantmap__44u3__p2_0,
  133594. 3,
  133595. 3
  133596. };
  133597. static static_codebook _44u3__p2_0 = {
  133598. 4, 81,
  133599. _vq_lengthlist__44u3__p2_0,
  133600. 1, -535822336, 1611661312, 2, 0,
  133601. _vq_quantlist__44u3__p2_0,
  133602. NULL,
  133603. &_vq_auxt__44u3__p2_0,
  133604. NULL,
  133605. 0
  133606. };
  133607. static long _vq_quantlist__44u3__p3_0[] = {
  133608. 2,
  133609. 1,
  133610. 3,
  133611. 0,
  133612. 4,
  133613. };
  133614. static long _vq_lengthlist__44u3__p3_0[] = {
  133615. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133616. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133617. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133618. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133619. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133620. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133621. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133622. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133623. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133624. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133625. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133626. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133627. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133628. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133629. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133630. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133631. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133632. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133633. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133634. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133635. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133636. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133637. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133638. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133639. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133640. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133641. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133642. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133643. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133644. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133645. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133646. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133647. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133648. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133649. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133650. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133651. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133652. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133653. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133654. 0,
  133655. };
  133656. static float _vq_quantthresh__44u3__p3_0[] = {
  133657. -1.5, -0.5, 0.5, 1.5,
  133658. };
  133659. static long _vq_quantmap__44u3__p3_0[] = {
  133660. 3, 1, 0, 2, 4,
  133661. };
  133662. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133663. _vq_quantthresh__44u3__p3_0,
  133664. _vq_quantmap__44u3__p3_0,
  133665. 5,
  133666. 5
  133667. };
  133668. static static_codebook _44u3__p3_0 = {
  133669. 4, 625,
  133670. _vq_lengthlist__44u3__p3_0,
  133671. 1, -533725184, 1611661312, 3, 0,
  133672. _vq_quantlist__44u3__p3_0,
  133673. NULL,
  133674. &_vq_auxt__44u3__p3_0,
  133675. NULL,
  133676. 0
  133677. };
  133678. static long _vq_quantlist__44u3__p4_0[] = {
  133679. 2,
  133680. 1,
  133681. 3,
  133682. 0,
  133683. 4,
  133684. };
  133685. static long _vq_lengthlist__44u3__p4_0[] = {
  133686. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133687. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133688. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133689. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133690. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133691. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133692. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133693. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133694. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133695. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133696. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133697. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133698. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133699. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133700. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133701. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133702. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133703. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133704. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133705. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133706. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133707. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133708. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133709. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133710. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133711. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133712. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133713. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133714. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133715. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133716. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133717. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133718. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133719. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133720. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133721. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133722. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133723. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133724. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133725. 13,
  133726. };
  133727. static float _vq_quantthresh__44u3__p4_0[] = {
  133728. -1.5, -0.5, 0.5, 1.5,
  133729. };
  133730. static long _vq_quantmap__44u3__p4_0[] = {
  133731. 3, 1, 0, 2, 4,
  133732. };
  133733. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133734. _vq_quantthresh__44u3__p4_0,
  133735. _vq_quantmap__44u3__p4_0,
  133736. 5,
  133737. 5
  133738. };
  133739. static static_codebook _44u3__p4_0 = {
  133740. 4, 625,
  133741. _vq_lengthlist__44u3__p4_0,
  133742. 1, -533725184, 1611661312, 3, 0,
  133743. _vq_quantlist__44u3__p4_0,
  133744. NULL,
  133745. &_vq_auxt__44u3__p4_0,
  133746. NULL,
  133747. 0
  133748. };
  133749. static long _vq_quantlist__44u3__p5_0[] = {
  133750. 4,
  133751. 3,
  133752. 5,
  133753. 2,
  133754. 6,
  133755. 1,
  133756. 7,
  133757. 0,
  133758. 8,
  133759. };
  133760. static long _vq_lengthlist__44u3__p5_0[] = {
  133761. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133762. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133763. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133764. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133765. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133766. 12,
  133767. };
  133768. static float _vq_quantthresh__44u3__p5_0[] = {
  133769. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133770. };
  133771. static long _vq_quantmap__44u3__p5_0[] = {
  133772. 7, 5, 3, 1, 0, 2, 4, 6,
  133773. 8,
  133774. };
  133775. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133776. _vq_quantthresh__44u3__p5_0,
  133777. _vq_quantmap__44u3__p5_0,
  133778. 9,
  133779. 9
  133780. };
  133781. static static_codebook _44u3__p5_0 = {
  133782. 2, 81,
  133783. _vq_lengthlist__44u3__p5_0,
  133784. 1, -531628032, 1611661312, 4, 0,
  133785. _vq_quantlist__44u3__p5_0,
  133786. NULL,
  133787. &_vq_auxt__44u3__p5_0,
  133788. NULL,
  133789. 0
  133790. };
  133791. static long _vq_quantlist__44u3__p6_0[] = {
  133792. 6,
  133793. 5,
  133794. 7,
  133795. 4,
  133796. 8,
  133797. 3,
  133798. 9,
  133799. 2,
  133800. 10,
  133801. 1,
  133802. 11,
  133803. 0,
  133804. 12,
  133805. };
  133806. static long _vq_lengthlist__44u3__p6_0[] = {
  133807. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133808. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133809. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133810. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133811. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133812. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133813. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133814. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133815. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133816. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133817. 15,16,16,16,17,18,16,20,18,
  133818. };
  133819. static float _vq_quantthresh__44u3__p6_0[] = {
  133820. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133821. 12.5, 17.5, 22.5, 27.5,
  133822. };
  133823. static long _vq_quantmap__44u3__p6_0[] = {
  133824. 11, 9, 7, 5, 3, 1, 0, 2,
  133825. 4, 6, 8, 10, 12,
  133826. };
  133827. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133828. _vq_quantthresh__44u3__p6_0,
  133829. _vq_quantmap__44u3__p6_0,
  133830. 13,
  133831. 13
  133832. };
  133833. static static_codebook _44u3__p6_0 = {
  133834. 2, 169,
  133835. _vq_lengthlist__44u3__p6_0,
  133836. 1, -526516224, 1616117760, 4, 0,
  133837. _vq_quantlist__44u3__p6_0,
  133838. NULL,
  133839. &_vq_auxt__44u3__p6_0,
  133840. NULL,
  133841. 0
  133842. };
  133843. static long _vq_quantlist__44u3__p6_1[] = {
  133844. 2,
  133845. 1,
  133846. 3,
  133847. 0,
  133848. 4,
  133849. };
  133850. static long _vq_lengthlist__44u3__p6_1[] = {
  133851. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133852. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133853. };
  133854. static float _vq_quantthresh__44u3__p6_1[] = {
  133855. -1.5, -0.5, 0.5, 1.5,
  133856. };
  133857. static long _vq_quantmap__44u3__p6_1[] = {
  133858. 3, 1, 0, 2, 4,
  133859. };
  133860. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133861. _vq_quantthresh__44u3__p6_1,
  133862. _vq_quantmap__44u3__p6_1,
  133863. 5,
  133864. 5
  133865. };
  133866. static static_codebook _44u3__p6_1 = {
  133867. 2, 25,
  133868. _vq_lengthlist__44u3__p6_1,
  133869. 1, -533725184, 1611661312, 3, 0,
  133870. _vq_quantlist__44u3__p6_1,
  133871. NULL,
  133872. &_vq_auxt__44u3__p6_1,
  133873. NULL,
  133874. 0
  133875. };
  133876. static long _vq_quantlist__44u3__p7_0[] = {
  133877. 4,
  133878. 3,
  133879. 5,
  133880. 2,
  133881. 6,
  133882. 1,
  133883. 7,
  133884. 0,
  133885. 8,
  133886. };
  133887. static long _vq_lengthlist__44u3__p7_0[] = {
  133888. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133889. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133890. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133891. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133892. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133893. 9,
  133894. };
  133895. static float _vq_quantthresh__44u3__p7_0[] = {
  133896. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133897. };
  133898. static long _vq_quantmap__44u3__p7_0[] = {
  133899. 7, 5, 3, 1, 0, 2, 4, 6,
  133900. 8,
  133901. };
  133902. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133903. _vq_quantthresh__44u3__p7_0,
  133904. _vq_quantmap__44u3__p7_0,
  133905. 9,
  133906. 9
  133907. };
  133908. static static_codebook _44u3__p7_0 = {
  133909. 2, 81,
  133910. _vq_lengthlist__44u3__p7_0,
  133911. 1, -515907584, 1627381760, 4, 0,
  133912. _vq_quantlist__44u3__p7_0,
  133913. NULL,
  133914. &_vq_auxt__44u3__p7_0,
  133915. NULL,
  133916. 0
  133917. };
  133918. static long _vq_quantlist__44u3__p7_1[] = {
  133919. 7,
  133920. 6,
  133921. 8,
  133922. 5,
  133923. 9,
  133924. 4,
  133925. 10,
  133926. 3,
  133927. 11,
  133928. 2,
  133929. 12,
  133930. 1,
  133931. 13,
  133932. 0,
  133933. 14,
  133934. };
  133935. static long _vq_lengthlist__44u3__p7_1[] = {
  133936. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133937. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133938. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133939. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133940. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133941. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133942. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133943. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133944. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133945. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133946. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133947. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133948. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133949. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133950. 17,
  133951. };
  133952. static float _vq_quantthresh__44u3__p7_1[] = {
  133953. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133954. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133955. };
  133956. static long _vq_quantmap__44u3__p7_1[] = {
  133957. 13, 11, 9, 7, 5, 3, 1, 0,
  133958. 2, 4, 6, 8, 10, 12, 14,
  133959. };
  133960. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133961. _vq_quantthresh__44u3__p7_1,
  133962. _vq_quantmap__44u3__p7_1,
  133963. 15,
  133964. 15
  133965. };
  133966. static static_codebook _44u3__p7_1 = {
  133967. 2, 225,
  133968. _vq_lengthlist__44u3__p7_1,
  133969. 1, -522338304, 1620115456, 4, 0,
  133970. _vq_quantlist__44u3__p7_1,
  133971. NULL,
  133972. &_vq_auxt__44u3__p7_1,
  133973. NULL,
  133974. 0
  133975. };
  133976. static long _vq_quantlist__44u3__p7_2[] = {
  133977. 8,
  133978. 7,
  133979. 9,
  133980. 6,
  133981. 10,
  133982. 5,
  133983. 11,
  133984. 4,
  133985. 12,
  133986. 3,
  133987. 13,
  133988. 2,
  133989. 14,
  133990. 1,
  133991. 15,
  133992. 0,
  133993. 16,
  133994. };
  133995. static long _vq_lengthlist__44u3__p7_2[] = {
  133996. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133997. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133998. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133999. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134000. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134001. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134002. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  134003. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134004. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  134005. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  134006. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134007. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  134008. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  134009. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134010. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  134011. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  134012. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134013. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  134014. 11,
  134015. };
  134016. static float _vq_quantthresh__44u3__p7_2[] = {
  134017. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134018. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134019. };
  134020. static long _vq_quantmap__44u3__p7_2[] = {
  134021. 15, 13, 11, 9, 7, 5, 3, 1,
  134022. 0, 2, 4, 6, 8, 10, 12, 14,
  134023. 16,
  134024. };
  134025. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  134026. _vq_quantthresh__44u3__p7_2,
  134027. _vq_quantmap__44u3__p7_2,
  134028. 17,
  134029. 17
  134030. };
  134031. static static_codebook _44u3__p7_2 = {
  134032. 2, 289,
  134033. _vq_lengthlist__44u3__p7_2,
  134034. 1, -529530880, 1611661312, 5, 0,
  134035. _vq_quantlist__44u3__p7_2,
  134036. NULL,
  134037. &_vq_auxt__44u3__p7_2,
  134038. NULL,
  134039. 0
  134040. };
  134041. static long _huff_lengthlist__44u3__short[] = {
  134042. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  134043. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  134044. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  134045. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  134046. };
  134047. static static_codebook _huff_book__44u3__short = {
  134048. 2, 64,
  134049. _huff_lengthlist__44u3__short,
  134050. 0, 0, 0, 0, 0,
  134051. NULL,
  134052. NULL,
  134053. NULL,
  134054. NULL,
  134055. 0
  134056. };
  134057. static long _huff_lengthlist__44u4__long[] = {
  134058. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  134059. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  134060. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  134061. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  134062. };
  134063. static static_codebook _huff_book__44u4__long = {
  134064. 2, 64,
  134065. _huff_lengthlist__44u4__long,
  134066. 0, 0, 0, 0, 0,
  134067. NULL,
  134068. NULL,
  134069. NULL,
  134070. NULL,
  134071. 0
  134072. };
  134073. static long _vq_quantlist__44u4__p1_0[] = {
  134074. 1,
  134075. 0,
  134076. 2,
  134077. };
  134078. static long _vq_lengthlist__44u4__p1_0[] = {
  134079. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  134080. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  134081. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  134082. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  134083. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  134084. 13,
  134085. };
  134086. static float _vq_quantthresh__44u4__p1_0[] = {
  134087. -0.5, 0.5,
  134088. };
  134089. static long _vq_quantmap__44u4__p1_0[] = {
  134090. 1, 0, 2,
  134091. };
  134092. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  134093. _vq_quantthresh__44u4__p1_0,
  134094. _vq_quantmap__44u4__p1_0,
  134095. 3,
  134096. 3
  134097. };
  134098. static static_codebook _44u4__p1_0 = {
  134099. 4, 81,
  134100. _vq_lengthlist__44u4__p1_0,
  134101. 1, -535822336, 1611661312, 2, 0,
  134102. _vq_quantlist__44u4__p1_0,
  134103. NULL,
  134104. &_vq_auxt__44u4__p1_0,
  134105. NULL,
  134106. 0
  134107. };
  134108. static long _vq_quantlist__44u4__p2_0[] = {
  134109. 1,
  134110. 0,
  134111. 2,
  134112. };
  134113. static long _vq_lengthlist__44u4__p2_0[] = {
  134114. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  134115. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  134116. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  134117. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  134118. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  134119. 9,
  134120. };
  134121. static float _vq_quantthresh__44u4__p2_0[] = {
  134122. -0.5, 0.5,
  134123. };
  134124. static long _vq_quantmap__44u4__p2_0[] = {
  134125. 1, 0, 2,
  134126. };
  134127. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  134128. _vq_quantthresh__44u4__p2_0,
  134129. _vq_quantmap__44u4__p2_0,
  134130. 3,
  134131. 3
  134132. };
  134133. static static_codebook _44u4__p2_0 = {
  134134. 4, 81,
  134135. _vq_lengthlist__44u4__p2_0,
  134136. 1, -535822336, 1611661312, 2, 0,
  134137. _vq_quantlist__44u4__p2_0,
  134138. NULL,
  134139. &_vq_auxt__44u4__p2_0,
  134140. NULL,
  134141. 0
  134142. };
  134143. static long _vq_quantlist__44u4__p3_0[] = {
  134144. 2,
  134145. 1,
  134146. 3,
  134147. 0,
  134148. 4,
  134149. };
  134150. static long _vq_lengthlist__44u4__p3_0[] = {
  134151. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  134152. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134153. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  134154. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  134155. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  134156. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  134157. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  134158. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  134159. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  134160. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  134161. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  134162. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  134163. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  134164. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  134165. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  134166. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  134167. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  134168. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  134169. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  134170. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  134171. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  134172. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  134173. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  134174. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  134175. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  134176. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  134177. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  134178. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  134179. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  134180. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  134181. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  134182. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  134183. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  134184. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  134185. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  134186. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  134187. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  134188. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  134189. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  134190. 0,
  134191. };
  134192. static float _vq_quantthresh__44u4__p3_0[] = {
  134193. -1.5, -0.5, 0.5, 1.5,
  134194. };
  134195. static long _vq_quantmap__44u4__p3_0[] = {
  134196. 3, 1, 0, 2, 4,
  134197. };
  134198. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  134199. _vq_quantthresh__44u4__p3_0,
  134200. _vq_quantmap__44u4__p3_0,
  134201. 5,
  134202. 5
  134203. };
  134204. static static_codebook _44u4__p3_0 = {
  134205. 4, 625,
  134206. _vq_lengthlist__44u4__p3_0,
  134207. 1, -533725184, 1611661312, 3, 0,
  134208. _vq_quantlist__44u4__p3_0,
  134209. NULL,
  134210. &_vq_auxt__44u4__p3_0,
  134211. NULL,
  134212. 0
  134213. };
  134214. static long _vq_quantlist__44u4__p4_0[] = {
  134215. 2,
  134216. 1,
  134217. 3,
  134218. 0,
  134219. 4,
  134220. };
  134221. static long _vq_lengthlist__44u4__p4_0[] = {
  134222. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134223. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134224. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134225. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134226. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134227. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  134228. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  134229. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  134230. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134231. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134232. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134233. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134234. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134235. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  134236. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134237. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134238. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134239. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134240. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134241. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  134242. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134243. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134244. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  134245. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134246. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  134247. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  134248. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  134249. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  134250. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  134251. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  134252. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  134253. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134254. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134255. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  134256. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  134257. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  134258. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  134259. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  134260. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  134261. 13,
  134262. };
  134263. static float _vq_quantthresh__44u4__p4_0[] = {
  134264. -1.5, -0.5, 0.5, 1.5,
  134265. };
  134266. static long _vq_quantmap__44u4__p4_0[] = {
  134267. 3, 1, 0, 2, 4,
  134268. };
  134269. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  134270. _vq_quantthresh__44u4__p4_0,
  134271. _vq_quantmap__44u4__p4_0,
  134272. 5,
  134273. 5
  134274. };
  134275. static static_codebook _44u4__p4_0 = {
  134276. 4, 625,
  134277. _vq_lengthlist__44u4__p4_0,
  134278. 1, -533725184, 1611661312, 3, 0,
  134279. _vq_quantlist__44u4__p4_0,
  134280. NULL,
  134281. &_vq_auxt__44u4__p4_0,
  134282. NULL,
  134283. 0
  134284. };
  134285. static long _vq_quantlist__44u4__p5_0[] = {
  134286. 4,
  134287. 3,
  134288. 5,
  134289. 2,
  134290. 6,
  134291. 1,
  134292. 7,
  134293. 0,
  134294. 8,
  134295. };
  134296. static long _vq_lengthlist__44u4__p5_0[] = {
  134297. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134298. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134299. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134300. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134301. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134302. 12,
  134303. };
  134304. static float _vq_quantthresh__44u4__p5_0[] = {
  134305. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134306. };
  134307. static long _vq_quantmap__44u4__p5_0[] = {
  134308. 7, 5, 3, 1, 0, 2, 4, 6,
  134309. 8,
  134310. };
  134311. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134312. _vq_quantthresh__44u4__p5_0,
  134313. _vq_quantmap__44u4__p5_0,
  134314. 9,
  134315. 9
  134316. };
  134317. static static_codebook _44u4__p5_0 = {
  134318. 2, 81,
  134319. _vq_lengthlist__44u4__p5_0,
  134320. 1, -531628032, 1611661312, 4, 0,
  134321. _vq_quantlist__44u4__p5_0,
  134322. NULL,
  134323. &_vq_auxt__44u4__p5_0,
  134324. NULL,
  134325. 0
  134326. };
  134327. static long _vq_quantlist__44u4__p6_0[] = {
  134328. 6,
  134329. 5,
  134330. 7,
  134331. 4,
  134332. 8,
  134333. 3,
  134334. 9,
  134335. 2,
  134336. 10,
  134337. 1,
  134338. 11,
  134339. 0,
  134340. 12,
  134341. };
  134342. static long _vq_lengthlist__44u4__p6_0[] = {
  134343. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134344. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134345. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134346. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134347. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134348. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134349. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134350. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134351. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134352. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134353. 16,16,16,17,17,18,17,20,21,
  134354. };
  134355. static float _vq_quantthresh__44u4__p6_0[] = {
  134356. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134357. 12.5, 17.5, 22.5, 27.5,
  134358. };
  134359. static long _vq_quantmap__44u4__p6_0[] = {
  134360. 11, 9, 7, 5, 3, 1, 0, 2,
  134361. 4, 6, 8, 10, 12,
  134362. };
  134363. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134364. _vq_quantthresh__44u4__p6_0,
  134365. _vq_quantmap__44u4__p6_0,
  134366. 13,
  134367. 13
  134368. };
  134369. static static_codebook _44u4__p6_0 = {
  134370. 2, 169,
  134371. _vq_lengthlist__44u4__p6_0,
  134372. 1, -526516224, 1616117760, 4, 0,
  134373. _vq_quantlist__44u4__p6_0,
  134374. NULL,
  134375. &_vq_auxt__44u4__p6_0,
  134376. NULL,
  134377. 0
  134378. };
  134379. static long _vq_quantlist__44u4__p6_1[] = {
  134380. 2,
  134381. 1,
  134382. 3,
  134383. 0,
  134384. 4,
  134385. };
  134386. static long _vq_lengthlist__44u4__p6_1[] = {
  134387. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134388. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134389. };
  134390. static float _vq_quantthresh__44u4__p6_1[] = {
  134391. -1.5, -0.5, 0.5, 1.5,
  134392. };
  134393. static long _vq_quantmap__44u4__p6_1[] = {
  134394. 3, 1, 0, 2, 4,
  134395. };
  134396. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134397. _vq_quantthresh__44u4__p6_1,
  134398. _vq_quantmap__44u4__p6_1,
  134399. 5,
  134400. 5
  134401. };
  134402. static static_codebook _44u4__p6_1 = {
  134403. 2, 25,
  134404. _vq_lengthlist__44u4__p6_1,
  134405. 1, -533725184, 1611661312, 3, 0,
  134406. _vq_quantlist__44u4__p6_1,
  134407. NULL,
  134408. &_vq_auxt__44u4__p6_1,
  134409. NULL,
  134410. 0
  134411. };
  134412. static long _vq_quantlist__44u4__p7_0[] = {
  134413. 6,
  134414. 5,
  134415. 7,
  134416. 4,
  134417. 8,
  134418. 3,
  134419. 9,
  134420. 2,
  134421. 10,
  134422. 1,
  134423. 11,
  134424. 0,
  134425. 12,
  134426. };
  134427. static long _vq_lengthlist__44u4__p7_0[] = {
  134428. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134429. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134430. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134431. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134432. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134433. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134434. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134435. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134436. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134437. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134438. 11,11,11,11,11,11,11,11,11,
  134439. };
  134440. static float _vq_quantthresh__44u4__p7_0[] = {
  134441. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134442. 637.5, 892.5, 1147.5, 1402.5,
  134443. };
  134444. static long _vq_quantmap__44u4__p7_0[] = {
  134445. 11, 9, 7, 5, 3, 1, 0, 2,
  134446. 4, 6, 8, 10, 12,
  134447. };
  134448. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134449. _vq_quantthresh__44u4__p7_0,
  134450. _vq_quantmap__44u4__p7_0,
  134451. 13,
  134452. 13
  134453. };
  134454. static static_codebook _44u4__p7_0 = {
  134455. 2, 169,
  134456. _vq_lengthlist__44u4__p7_0,
  134457. 1, -514332672, 1627381760, 4, 0,
  134458. _vq_quantlist__44u4__p7_0,
  134459. NULL,
  134460. &_vq_auxt__44u4__p7_0,
  134461. NULL,
  134462. 0
  134463. };
  134464. static long _vq_quantlist__44u4__p7_1[] = {
  134465. 7,
  134466. 6,
  134467. 8,
  134468. 5,
  134469. 9,
  134470. 4,
  134471. 10,
  134472. 3,
  134473. 11,
  134474. 2,
  134475. 12,
  134476. 1,
  134477. 13,
  134478. 0,
  134479. 14,
  134480. };
  134481. static long _vq_lengthlist__44u4__p7_1[] = {
  134482. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134483. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134484. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134485. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134486. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134487. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134488. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134489. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134490. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134491. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134492. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134493. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134494. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134495. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134496. 16,
  134497. };
  134498. static float _vq_quantthresh__44u4__p7_1[] = {
  134499. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134500. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134501. };
  134502. static long _vq_quantmap__44u4__p7_1[] = {
  134503. 13, 11, 9, 7, 5, 3, 1, 0,
  134504. 2, 4, 6, 8, 10, 12, 14,
  134505. };
  134506. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134507. _vq_quantthresh__44u4__p7_1,
  134508. _vq_quantmap__44u4__p7_1,
  134509. 15,
  134510. 15
  134511. };
  134512. static static_codebook _44u4__p7_1 = {
  134513. 2, 225,
  134514. _vq_lengthlist__44u4__p7_1,
  134515. 1, -522338304, 1620115456, 4, 0,
  134516. _vq_quantlist__44u4__p7_1,
  134517. NULL,
  134518. &_vq_auxt__44u4__p7_1,
  134519. NULL,
  134520. 0
  134521. };
  134522. static long _vq_quantlist__44u4__p7_2[] = {
  134523. 8,
  134524. 7,
  134525. 9,
  134526. 6,
  134527. 10,
  134528. 5,
  134529. 11,
  134530. 4,
  134531. 12,
  134532. 3,
  134533. 13,
  134534. 2,
  134535. 14,
  134536. 1,
  134537. 15,
  134538. 0,
  134539. 16,
  134540. };
  134541. static long _vq_lengthlist__44u4__p7_2[] = {
  134542. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134543. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134544. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134545. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134546. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134547. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134548. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134549. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134550. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134551. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134552. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134553. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134554. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134555. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134556. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134557. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134558. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134559. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134560. 10,
  134561. };
  134562. static float _vq_quantthresh__44u4__p7_2[] = {
  134563. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134564. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134565. };
  134566. static long _vq_quantmap__44u4__p7_2[] = {
  134567. 15, 13, 11, 9, 7, 5, 3, 1,
  134568. 0, 2, 4, 6, 8, 10, 12, 14,
  134569. 16,
  134570. };
  134571. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134572. _vq_quantthresh__44u4__p7_2,
  134573. _vq_quantmap__44u4__p7_2,
  134574. 17,
  134575. 17
  134576. };
  134577. static static_codebook _44u4__p7_2 = {
  134578. 2, 289,
  134579. _vq_lengthlist__44u4__p7_2,
  134580. 1, -529530880, 1611661312, 5, 0,
  134581. _vq_quantlist__44u4__p7_2,
  134582. NULL,
  134583. &_vq_auxt__44u4__p7_2,
  134584. NULL,
  134585. 0
  134586. };
  134587. static long _huff_lengthlist__44u4__short[] = {
  134588. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134589. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134590. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134591. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134592. };
  134593. static static_codebook _huff_book__44u4__short = {
  134594. 2, 64,
  134595. _huff_lengthlist__44u4__short,
  134596. 0, 0, 0, 0, 0,
  134597. NULL,
  134598. NULL,
  134599. NULL,
  134600. NULL,
  134601. 0
  134602. };
  134603. static long _huff_lengthlist__44u5__long[] = {
  134604. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134605. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134606. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134607. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134608. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134609. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134610. 14, 8, 7, 8,
  134611. };
  134612. static static_codebook _huff_book__44u5__long = {
  134613. 2, 100,
  134614. _huff_lengthlist__44u5__long,
  134615. 0, 0, 0, 0, 0,
  134616. NULL,
  134617. NULL,
  134618. NULL,
  134619. NULL,
  134620. 0
  134621. };
  134622. static long _vq_quantlist__44u5__p1_0[] = {
  134623. 1,
  134624. 0,
  134625. 2,
  134626. };
  134627. static long _vq_lengthlist__44u5__p1_0[] = {
  134628. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134629. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134630. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134631. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134632. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134633. 12,
  134634. };
  134635. static float _vq_quantthresh__44u5__p1_0[] = {
  134636. -0.5, 0.5,
  134637. };
  134638. static long _vq_quantmap__44u5__p1_0[] = {
  134639. 1, 0, 2,
  134640. };
  134641. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134642. _vq_quantthresh__44u5__p1_0,
  134643. _vq_quantmap__44u5__p1_0,
  134644. 3,
  134645. 3
  134646. };
  134647. static static_codebook _44u5__p1_0 = {
  134648. 4, 81,
  134649. _vq_lengthlist__44u5__p1_0,
  134650. 1, -535822336, 1611661312, 2, 0,
  134651. _vq_quantlist__44u5__p1_0,
  134652. NULL,
  134653. &_vq_auxt__44u5__p1_0,
  134654. NULL,
  134655. 0
  134656. };
  134657. static long _vq_quantlist__44u5__p2_0[] = {
  134658. 1,
  134659. 0,
  134660. 2,
  134661. };
  134662. static long _vq_lengthlist__44u5__p2_0[] = {
  134663. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134664. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134665. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134666. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134667. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134668. 9,
  134669. };
  134670. static float _vq_quantthresh__44u5__p2_0[] = {
  134671. -0.5, 0.5,
  134672. };
  134673. static long _vq_quantmap__44u5__p2_0[] = {
  134674. 1, 0, 2,
  134675. };
  134676. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134677. _vq_quantthresh__44u5__p2_0,
  134678. _vq_quantmap__44u5__p2_0,
  134679. 3,
  134680. 3
  134681. };
  134682. static static_codebook _44u5__p2_0 = {
  134683. 4, 81,
  134684. _vq_lengthlist__44u5__p2_0,
  134685. 1, -535822336, 1611661312, 2, 0,
  134686. _vq_quantlist__44u5__p2_0,
  134687. NULL,
  134688. &_vq_auxt__44u5__p2_0,
  134689. NULL,
  134690. 0
  134691. };
  134692. static long _vq_quantlist__44u5__p3_0[] = {
  134693. 2,
  134694. 1,
  134695. 3,
  134696. 0,
  134697. 4,
  134698. };
  134699. static long _vq_lengthlist__44u5__p3_0[] = {
  134700. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134701. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134702. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134703. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134704. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134705. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134706. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134707. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134708. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134709. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134710. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134711. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134712. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134713. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134714. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134715. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134716. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134717. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134718. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134719. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134720. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134721. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134722. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134723. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134724. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134725. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134726. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134727. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134728. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134729. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134730. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134731. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134732. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134733. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134734. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134735. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134736. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134737. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134738. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134739. 0,
  134740. };
  134741. static float _vq_quantthresh__44u5__p3_0[] = {
  134742. -1.5, -0.5, 0.5, 1.5,
  134743. };
  134744. static long _vq_quantmap__44u5__p3_0[] = {
  134745. 3, 1, 0, 2, 4,
  134746. };
  134747. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134748. _vq_quantthresh__44u5__p3_0,
  134749. _vq_quantmap__44u5__p3_0,
  134750. 5,
  134751. 5
  134752. };
  134753. static static_codebook _44u5__p3_0 = {
  134754. 4, 625,
  134755. _vq_lengthlist__44u5__p3_0,
  134756. 1, -533725184, 1611661312, 3, 0,
  134757. _vq_quantlist__44u5__p3_0,
  134758. NULL,
  134759. &_vq_auxt__44u5__p3_0,
  134760. NULL,
  134761. 0
  134762. };
  134763. static long _vq_quantlist__44u5__p4_0[] = {
  134764. 2,
  134765. 1,
  134766. 3,
  134767. 0,
  134768. 4,
  134769. };
  134770. static long _vq_lengthlist__44u5__p4_0[] = {
  134771. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134772. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134773. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134774. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134775. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134776. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134777. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134778. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134779. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134780. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134781. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134782. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134783. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134784. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134785. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134786. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134787. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134788. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134789. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134790. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134791. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134792. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134793. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134794. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134795. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134796. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134797. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134798. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134799. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134800. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134801. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134802. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134803. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134804. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134805. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134806. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134807. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134808. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134809. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134810. 12,
  134811. };
  134812. static float _vq_quantthresh__44u5__p4_0[] = {
  134813. -1.5, -0.5, 0.5, 1.5,
  134814. };
  134815. static long _vq_quantmap__44u5__p4_0[] = {
  134816. 3, 1, 0, 2, 4,
  134817. };
  134818. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134819. _vq_quantthresh__44u5__p4_0,
  134820. _vq_quantmap__44u5__p4_0,
  134821. 5,
  134822. 5
  134823. };
  134824. static static_codebook _44u5__p4_0 = {
  134825. 4, 625,
  134826. _vq_lengthlist__44u5__p4_0,
  134827. 1, -533725184, 1611661312, 3, 0,
  134828. _vq_quantlist__44u5__p4_0,
  134829. NULL,
  134830. &_vq_auxt__44u5__p4_0,
  134831. NULL,
  134832. 0
  134833. };
  134834. static long _vq_quantlist__44u5__p5_0[] = {
  134835. 4,
  134836. 3,
  134837. 5,
  134838. 2,
  134839. 6,
  134840. 1,
  134841. 7,
  134842. 0,
  134843. 8,
  134844. };
  134845. static long _vq_lengthlist__44u5__p5_0[] = {
  134846. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134847. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134848. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134849. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134850. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134851. 14,
  134852. };
  134853. static float _vq_quantthresh__44u5__p5_0[] = {
  134854. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134855. };
  134856. static long _vq_quantmap__44u5__p5_0[] = {
  134857. 7, 5, 3, 1, 0, 2, 4, 6,
  134858. 8,
  134859. };
  134860. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134861. _vq_quantthresh__44u5__p5_0,
  134862. _vq_quantmap__44u5__p5_0,
  134863. 9,
  134864. 9
  134865. };
  134866. static static_codebook _44u5__p5_0 = {
  134867. 2, 81,
  134868. _vq_lengthlist__44u5__p5_0,
  134869. 1, -531628032, 1611661312, 4, 0,
  134870. _vq_quantlist__44u5__p5_0,
  134871. NULL,
  134872. &_vq_auxt__44u5__p5_0,
  134873. NULL,
  134874. 0
  134875. };
  134876. static long _vq_quantlist__44u5__p6_0[] = {
  134877. 4,
  134878. 3,
  134879. 5,
  134880. 2,
  134881. 6,
  134882. 1,
  134883. 7,
  134884. 0,
  134885. 8,
  134886. };
  134887. static long _vq_lengthlist__44u5__p6_0[] = {
  134888. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134889. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134890. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134891. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134892. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134893. 11,
  134894. };
  134895. static float _vq_quantthresh__44u5__p6_0[] = {
  134896. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134897. };
  134898. static long _vq_quantmap__44u5__p6_0[] = {
  134899. 7, 5, 3, 1, 0, 2, 4, 6,
  134900. 8,
  134901. };
  134902. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134903. _vq_quantthresh__44u5__p6_0,
  134904. _vq_quantmap__44u5__p6_0,
  134905. 9,
  134906. 9
  134907. };
  134908. static static_codebook _44u5__p6_0 = {
  134909. 2, 81,
  134910. _vq_lengthlist__44u5__p6_0,
  134911. 1, -531628032, 1611661312, 4, 0,
  134912. _vq_quantlist__44u5__p6_0,
  134913. NULL,
  134914. &_vq_auxt__44u5__p6_0,
  134915. NULL,
  134916. 0
  134917. };
  134918. static long _vq_quantlist__44u5__p7_0[] = {
  134919. 1,
  134920. 0,
  134921. 2,
  134922. };
  134923. static long _vq_lengthlist__44u5__p7_0[] = {
  134924. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134925. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134926. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134927. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134928. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134929. 12,
  134930. };
  134931. static float _vq_quantthresh__44u5__p7_0[] = {
  134932. -5.5, 5.5,
  134933. };
  134934. static long _vq_quantmap__44u5__p7_0[] = {
  134935. 1, 0, 2,
  134936. };
  134937. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134938. _vq_quantthresh__44u5__p7_0,
  134939. _vq_quantmap__44u5__p7_0,
  134940. 3,
  134941. 3
  134942. };
  134943. static static_codebook _44u5__p7_0 = {
  134944. 4, 81,
  134945. _vq_lengthlist__44u5__p7_0,
  134946. 1, -529137664, 1618345984, 2, 0,
  134947. _vq_quantlist__44u5__p7_0,
  134948. NULL,
  134949. &_vq_auxt__44u5__p7_0,
  134950. NULL,
  134951. 0
  134952. };
  134953. static long _vq_quantlist__44u5__p7_1[] = {
  134954. 5,
  134955. 4,
  134956. 6,
  134957. 3,
  134958. 7,
  134959. 2,
  134960. 8,
  134961. 1,
  134962. 9,
  134963. 0,
  134964. 10,
  134965. };
  134966. static long _vq_lengthlist__44u5__p7_1[] = {
  134967. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134968. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134969. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134970. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134971. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134972. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134973. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134974. 9, 9, 9, 9, 9,10,10,10,10,
  134975. };
  134976. static float _vq_quantthresh__44u5__p7_1[] = {
  134977. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134978. 3.5, 4.5,
  134979. };
  134980. static long _vq_quantmap__44u5__p7_1[] = {
  134981. 9, 7, 5, 3, 1, 0, 2, 4,
  134982. 6, 8, 10,
  134983. };
  134984. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134985. _vq_quantthresh__44u5__p7_1,
  134986. _vq_quantmap__44u5__p7_1,
  134987. 11,
  134988. 11
  134989. };
  134990. static static_codebook _44u5__p7_1 = {
  134991. 2, 121,
  134992. _vq_lengthlist__44u5__p7_1,
  134993. 1, -531365888, 1611661312, 4, 0,
  134994. _vq_quantlist__44u5__p7_1,
  134995. NULL,
  134996. &_vq_auxt__44u5__p7_1,
  134997. NULL,
  134998. 0
  134999. };
  135000. static long _vq_quantlist__44u5__p8_0[] = {
  135001. 5,
  135002. 4,
  135003. 6,
  135004. 3,
  135005. 7,
  135006. 2,
  135007. 8,
  135008. 1,
  135009. 9,
  135010. 0,
  135011. 10,
  135012. };
  135013. static long _vq_lengthlist__44u5__p8_0[] = {
  135014. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135015. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135016. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  135017. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  135018. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  135019. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  135020. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  135021. 12,13,13,14,14,14,14,15,15,
  135022. };
  135023. static float _vq_quantthresh__44u5__p8_0[] = {
  135024. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135025. 38.5, 49.5,
  135026. };
  135027. static long _vq_quantmap__44u5__p8_0[] = {
  135028. 9, 7, 5, 3, 1, 0, 2, 4,
  135029. 6, 8, 10,
  135030. };
  135031. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  135032. _vq_quantthresh__44u5__p8_0,
  135033. _vq_quantmap__44u5__p8_0,
  135034. 11,
  135035. 11
  135036. };
  135037. static static_codebook _44u5__p8_0 = {
  135038. 2, 121,
  135039. _vq_lengthlist__44u5__p8_0,
  135040. 1, -524582912, 1618345984, 4, 0,
  135041. _vq_quantlist__44u5__p8_0,
  135042. NULL,
  135043. &_vq_auxt__44u5__p8_0,
  135044. NULL,
  135045. 0
  135046. };
  135047. static long _vq_quantlist__44u5__p8_1[] = {
  135048. 5,
  135049. 4,
  135050. 6,
  135051. 3,
  135052. 7,
  135053. 2,
  135054. 8,
  135055. 1,
  135056. 9,
  135057. 0,
  135058. 10,
  135059. };
  135060. static long _vq_lengthlist__44u5__p8_1[] = {
  135061. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  135062. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  135063. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  135064. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135065. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  135066. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135067. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135068. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135069. };
  135070. static float _vq_quantthresh__44u5__p8_1[] = {
  135071. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135072. 3.5, 4.5,
  135073. };
  135074. static long _vq_quantmap__44u5__p8_1[] = {
  135075. 9, 7, 5, 3, 1, 0, 2, 4,
  135076. 6, 8, 10,
  135077. };
  135078. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  135079. _vq_quantthresh__44u5__p8_1,
  135080. _vq_quantmap__44u5__p8_1,
  135081. 11,
  135082. 11
  135083. };
  135084. static static_codebook _44u5__p8_1 = {
  135085. 2, 121,
  135086. _vq_lengthlist__44u5__p8_1,
  135087. 1, -531365888, 1611661312, 4, 0,
  135088. _vq_quantlist__44u5__p8_1,
  135089. NULL,
  135090. &_vq_auxt__44u5__p8_1,
  135091. NULL,
  135092. 0
  135093. };
  135094. static long _vq_quantlist__44u5__p9_0[] = {
  135095. 6,
  135096. 5,
  135097. 7,
  135098. 4,
  135099. 8,
  135100. 3,
  135101. 9,
  135102. 2,
  135103. 10,
  135104. 1,
  135105. 11,
  135106. 0,
  135107. 12,
  135108. };
  135109. static long _vq_lengthlist__44u5__p9_0[] = {
  135110. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  135111. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  135112. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  135113. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  135114. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135115. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135116. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135117. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135118. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  135119. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  135120. 12,12,12,12,12,12,12,12,12,
  135121. };
  135122. static float _vq_quantthresh__44u5__p9_0[] = {
  135123. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  135124. 637.5, 892.5, 1147.5, 1402.5,
  135125. };
  135126. static long _vq_quantmap__44u5__p9_0[] = {
  135127. 11, 9, 7, 5, 3, 1, 0, 2,
  135128. 4, 6, 8, 10, 12,
  135129. };
  135130. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  135131. _vq_quantthresh__44u5__p9_0,
  135132. _vq_quantmap__44u5__p9_0,
  135133. 13,
  135134. 13
  135135. };
  135136. static static_codebook _44u5__p9_0 = {
  135137. 2, 169,
  135138. _vq_lengthlist__44u5__p9_0,
  135139. 1, -514332672, 1627381760, 4, 0,
  135140. _vq_quantlist__44u5__p9_0,
  135141. NULL,
  135142. &_vq_auxt__44u5__p9_0,
  135143. NULL,
  135144. 0
  135145. };
  135146. static long _vq_quantlist__44u5__p9_1[] = {
  135147. 7,
  135148. 6,
  135149. 8,
  135150. 5,
  135151. 9,
  135152. 4,
  135153. 10,
  135154. 3,
  135155. 11,
  135156. 2,
  135157. 12,
  135158. 1,
  135159. 13,
  135160. 0,
  135161. 14,
  135162. };
  135163. static long _vq_lengthlist__44u5__p9_1[] = {
  135164. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  135165. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  135166. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  135167. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  135168. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  135169. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  135170. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  135171. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  135172. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  135173. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  135174. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  135175. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  135176. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  135177. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  135178. 14,
  135179. };
  135180. static float _vq_quantthresh__44u5__p9_1[] = {
  135181. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135182. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135183. };
  135184. static long _vq_quantmap__44u5__p9_1[] = {
  135185. 13, 11, 9, 7, 5, 3, 1, 0,
  135186. 2, 4, 6, 8, 10, 12, 14,
  135187. };
  135188. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  135189. _vq_quantthresh__44u5__p9_1,
  135190. _vq_quantmap__44u5__p9_1,
  135191. 15,
  135192. 15
  135193. };
  135194. static static_codebook _44u5__p9_1 = {
  135195. 2, 225,
  135196. _vq_lengthlist__44u5__p9_1,
  135197. 1, -522338304, 1620115456, 4, 0,
  135198. _vq_quantlist__44u5__p9_1,
  135199. NULL,
  135200. &_vq_auxt__44u5__p9_1,
  135201. NULL,
  135202. 0
  135203. };
  135204. static long _vq_quantlist__44u5__p9_2[] = {
  135205. 8,
  135206. 7,
  135207. 9,
  135208. 6,
  135209. 10,
  135210. 5,
  135211. 11,
  135212. 4,
  135213. 12,
  135214. 3,
  135215. 13,
  135216. 2,
  135217. 14,
  135218. 1,
  135219. 15,
  135220. 0,
  135221. 16,
  135222. };
  135223. static long _vq_lengthlist__44u5__p9_2[] = {
  135224. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135225. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135226. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135227. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135228. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135229. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  135230. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135231. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  135232. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135233. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  135234. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  135235. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  135236. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  135237. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135238. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  135239. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  135240. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  135241. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  135242. 10,
  135243. };
  135244. static float _vq_quantthresh__44u5__p9_2[] = {
  135245. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135246. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135247. };
  135248. static long _vq_quantmap__44u5__p9_2[] = {
  135249. 15, 13, 11, 9, 7, 5, 3, 1,
  135250. 0, 2, 4, 6, 8, 10, 12, 14,
  135251. 16,
  135252. };
  135253. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  135254. _vq_quantthresh__44u5__p9_2,
  135255. _vq_quantmap__44u5__p9_2,
  135256. 17,
  135257. 17
  135258. };
  135259. static static_codebook _44u5__p9_2 = {
  135260. 2, 289,
  135261. _vq_lengthlist__44u5__p9_2,
  135262. 1, -529530880, 1611661312, 5, 0,
  135263. _vq_quantlist__44u5__p9_2,
  135264. NULL,
  135265. &_vq_auxt__44u5__p9_2,
  135266. NULL,
  135267. 0
  135268. };
  135269. static long _huff_lengthlist__44u5__short[] = {
  135270. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  135271. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  135272. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  135273. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  135274. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  135275. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  135276. 6, 8,15,17,
  135277. };
  135278. static static_codebook _huff_book__44u5__short = {
  135279. 2, 100,
  135280. _huff_lengthlist__44u5__short,
  135281. 0, 0, 0, 0, 0,
  135282. NULL,
  135283. NULL,
  135284. NULL,
  135285. NULL,
  135286. 0
  135287. };
  135288. static long _huff_lengthlist__44u6__long[] = {
  135289. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135290. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135291. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135292. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135293. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135294. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135295. 13, 8, 7, 7,
  135296. };
  135297. static static_codebook _huff_book__44u6__long = {
  135298. 2, 100,
  135299. _huff_lengthlist__44u6__long,
  135300. 0, 0, 0, 0, 0,
  135301. NULL,
  135302. NULL,
  135303. NULL,
  135304. NULL,
  135305. 0
  135306. };
  135307. static long _vq_quantlist__44u6__p1_0[] = {
  135308. 1,
  135309. 0,
  135310. 2,
  135311. };
  135312. static long _vq_lengthlist__44u6__p1_0[] = {
  135313. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135314. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135315. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135316. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135317. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135318. 12,
  135319. };
  135320. static float _vq_quantthresh__44u6__p1_0[] = {
  135321. -0.5, 0.5,
  135322. };
  135323. static long _vq_quantmap__44u6__p1_0[] = {
  135324. 1, 0, 2,
  135325. };
  135326. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135327. _vq_quantthresh__44u6__p1_0,
  135328. _vq_quantmap__44u6__p1_0,
  135329. 3,
  135330. 3
  135331. };
  135332. static static_codebook _44u6__p1_0 = {
  135333. 4, 81,
  135334. _vq_lengthlist__44u6__p1_0,
  135335. 1, -535822336, 1611661312, 2, 0,
  135336. _vq_quantlist__44u6__p1_0,
  135337. NULL,
  135338. &_vq_auxt__44u6__p1_0,
  135339. NULL,
  135340. 0
  135341. };
  135342. static long _vq_quantlist__44u6__p2_0[] = {
  135343. 1,
  135344. 0,
  135345. 2,
  135346. };
  135347. static long _vq_lengthlist__44u6__p2_0[] = {
  135348. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135349. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135350. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135351. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135352. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135353. 9,
  135354. };
  135355. static float _vq_quantthresh__44u6__p2_0[] = {
  135356. -0.5, 0.5,
  135357. };
  135358. static long _vq_quantmap__44u6__p2_0[] = {
  135359. 1, 0, 2,
  135360. };
  135361. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135362. _vq_quantthresh__44u6__p2_0,
  135363. _vq_quantmap__44u6__p2_0,
  135364. 3,
  135365. 3
  135366. };
  135367. static static_codebook _44u6__p2_0 = {
  135368. 4, 81,
  135369. _vq_lengthlist__44u6__p2_0,
  135370. 1, -535822336, 1611661312, 2, 0,
  135371. _vq_quantlist__44u6__p2_0,
  135372. NULL,
  135373. &_vq_auxt__44u6__p2_0,
  135374. NULL,
  135375. 0
  135376. };
  135377. static long _vq_quantlist__44u6__p3_0[] = {
  135378. 2,
  135379. 1,
  135380. 3,
  135381. 0,
  135382. 4,
  135383. };
  135384. static long _vq_lengthlist__44u6__p3_0[] = {
  135385. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135386. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135387. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135388. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135389. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135390. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135391. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135392. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135393. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135394. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135395. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135396. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135397. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135398. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135399. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135400. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135401. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135402. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135403. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135404. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135405. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135406. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135407. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135408. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135409. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135410. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135411. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135412. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135413. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135414. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135415. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135416. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135417. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135418. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135419. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135420. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135421. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135422. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135423. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135424. 19,
  135425. };
  135426. static float _vq_quantthresh__44u6__p3_0[] = {
  135427. -1.5, -0.5, 0.5, 1.5,
  135428. };
  135429. static long _vq_quantmap__44u6__p3_0[] = {
  135430. 3, 1, 0, 2, 4,
  135431. };
  135432. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135433. _vq_quantthresh__44u6__p3_0,
  135434. _vq_quantmap__44u6__p3_0,
  135435. 5,
  135436. 5
  135437. };
  135438. static static_codebook _44u6__p3_0 = {
  135439. 4, 625,
  135440. _vq_lengthlist__44u6__p3_0,
  135441. 1, -533725184, 1611661312, 3, 0,
  135442. _vq_quantlist__44u6__p3_0,
  135443. NULL,
  135444. &_vq_auxt__44u6__p3_0,
  135445. NULL,
  135446. 0
  135447. };
  135448. static long _vq_quantlist__44u6__p4_0[] = {
  135449. 2,
  135450. 1,
  135451. 3,
  135452. 0,
  135453. 4,
  135454. };
  135455. static long _vq_lengthlist__44u6__p4_0[] = {
  135456. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135457. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135458. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135459. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135460. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135461. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135462. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135463. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135464. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135465. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135466. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135467. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135468. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135469. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135470. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135471. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135472. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135473. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135474. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135475. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135476. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135477. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135478. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135479. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135480. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135481. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135482. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135483. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135484. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135485. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135486. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135487. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135488. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135489. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135490. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135491. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135492. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135493. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135494. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135495. 13,
  135496. };
  135497. static float _vq_quantthresh__44u6__p4_0[] = {
  135498. -1.5, -0.5, 0.5, 1.5,
  135499. };
  135500. static long _vq_quantmap__44u6__p4_0[] = {
  135501. 3, 1, 0, 2, 4,
  135502. };
  135503. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135504. _vq_quantthresh__44u6__p4_0,
  135505. _vq_quantmap__44u6__p4_0,
  135506. 5,
  135507. 5
  135508. };
  135509. static static_codebook _44u6__p4_0 = {
  135510. 4, 625,
  135511. _vq_lengthlist__44u6__p4_0,
  135512. 1, -533725184, 1611661312, 3, 0,
  135513. _vq_quantlist__44u6__p4_0,
  135514. NULL,
  135515. &_vq_auxt__44u6__p4_0,
  135516. NULL,
  135517. 0
  135518. };
  135519. static long _vq_quantlist__44u6__p5_0[] = {
  135520. 4,
  135521. 3,
  135522. 5,
  135523. 2,
  135524. 6,
  135525. 1,
  135526. 7,
  135527. 0,
  135528. 8,
  135529. };
  135530. static long _vq_lengthlist__44u6__p5_0[] = {
  135531. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135532. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135533. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135534. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135535. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135536. 14,
  135537. };
  135538. static float _vq_quantthresh__44u6__p5_0[] = {
  135539. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135540. };
  135541. static long _vq_quantmap__44u6__p5_0[] = {
  135542. 7, 5, 3, 1, 0, 2, 4, 6,
  135543. 8,
  135544. };
  135545. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135546. _vq_quantthresh__44u6__p5_0,
  135547. _vq_quantmap__44u6__p5_0,
  135548. 9,
  135549. 9
  135550. };
  135551. static static_codebook _44u6__p5_0 = {
  135552. 2, 81,
  135553. _vq_lengthlist__44u6__p5_0,
  135554. 1, -531628032, 1611661312, 4, 0,
  135555. _vq_quantlist__44u6__p5_0,
  135556. NULL,
  135557. &_vq_auxt__44u6__p5_0,
  135558. NULL,
  135559. 0
  135560. };
  135561. static long _vq_quantlist__44u6__p6_0[] = {
  135562. 4,
  135563. 3,
  135564. 5,
  135565. 2,
  135566. 6,
  135567. 1,
  135568. 7,
  135569. 0,
  135570. 8,
  135571. };
  135572. static long _vq_lengthlist__44u6__p6_0[] = {
  135573. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135574. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135575. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135576. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135577. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135578. 12,
  135579. };
  135580. static float _vq_quantthresh__44u6__p6_0[] = {
  135581. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135582. };
  135583. static long _vq_quantmap__44u6__p6_0[] = {
  135584. 7, 5, 3, 1, 0, 2, 4, 6,
  135585. 8,
  135586. };
  135587. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135588. _vq_quantthresh__44u6__p6_0,
  135589. _vq_quantmap__44u6__p6_0,
  135590. 9,
  135591. 9
  135592. };
  135593. static static_codebook _44u6__p6_0 = {
  135594. 2, 81,
  135595. _vq_lengthlist__44u6__p6_0,
  135596. 1, -531628032, 1611661312, 4, 0,
  135597. _vq_quantlist__44u6__p6_0,
  135598. NULL,
  135599. &_vq_auxt__44u6__p6_0,
  135600. NULL,
  135601. 0
  135602. };
  135603. static long _vq_quantlist__44u6__p7_0[] = {
  135604. 1,
  135605. 0,
  135606. 2,
  135607. };
  135608. static long _vq_lengthlist__44u6__p7_0[] = {
  135609. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135610. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135611. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135612. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135613. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135614. 10,
  135615. };
  135616. static float _vq_quantthresh__44u6__p7_0[] = {
  135617. -5.5, 5.5,
  135618. };
  135619. static long _vq_quantmap__44u6__p7_0[] = {
  135620. 1, 0, 2,
  135621. };
  135622. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135623. _vq_quantthresh__44u6__p7_0,
  135624. _vq_quantmap__44u6__p7_0,
  135625. 3,
  135626. 3
  135627. };
  135628. static static_codebook _44u6__p7_0 = {
  135629. 4, 81,
  135630. _vq_lengthlist__44u6__p7_0,
  135631. 1, -529137664, 1618345984, 2, 0,
  135632. _vq_quantlist__44u6__p7_0,
  135633. NULL,
  135634. &_vq_auxt__44u6__p7_0,
  135635. NULL,
  135636. 0
  135637. };
  135638. static long _vq_quantlist__44u6__p7_1[] = {
  135639. 5,
  135640. 4,
  135641. 6,
  135642. 3,
  135643. 7,
  135644. 2,
  135645. 8,
  135646. 1,
  135647. 9,
  135648. 0,
  135649. 10,
  135650. };
  135651. static long _vq_lengthlist__44u6__p7_1[] = {
  135652. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135653. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135654. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135655. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135656. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135657. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135658. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135659. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135660. };
  135661. static float _vq_quantthresh__44u6__p7_1[] = {
  135662. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135663. 3.5, 4.5,
  135664. };
  135665. static long _vq_quantmap__44u6__p7_1[] = {
  135666. 9, 7, 5, 3, 1, 0, 2, 4,
  135667. 6, 8, 10,
  135668. };
  135669. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135670. _vq_quantthresh__44u6__p7_1,
  135671. _vq_quantmap__44u6__p7_1,
  135672. 11,
  135673. 11
  135674. };
  135675. static static_codebook _44u6__p7_1 = {
  135676. 2, 121,
  135677. _vq_lengthlist__44u6__p7_1,
  135678. 1, -531365888, 1611661312, 4, 0,
  135679. _vq_quantlist__44u6__p7_1,
  135680. NULL,
  135681. &_vq_auxt__44u6__p7_1,
  135682. NULL,
  135683. 0
  135684. };
  135685. static long _vq_quantlist__44u6__p8_0[] = {
  135686. 5,
  135687. 4,
  135688. 6,
  135689. 3,
  135690. 7,
  135691. 2,
  135692. 8,
  135693. 1,
  135694. 9,
  135695. 0,
  135696. 10,
  135697. };
  135698. static long _vq_lengthlist__44u6__p8_0[] = {
  135699. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135700. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135701. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135702. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135703. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135704. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135705. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135706. 12,13,13,14,14,14,15,15,15,
  135707. };
  135708. static float _vq_quantthresh__44u6__p8_0[] = {
  135709. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135710. 38.5, 49.5,
  135711. };
  135712. static long _vq_quantmap__44u6__p8_0[] = {
  135713. 9, 7, 5, 3, 1, 0, 2, 4,
  135714. 6, 8, 10,
  135715. };
  135716. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135717. _vq_quantthresh__44u6__p8_0,
  135718. _vq_quantmap__44u6__p8_0,
  135719. 11,
  135720. 11
  135721. };
  135722. static static_codebook _44u6__p8_0 = {
  135723. 2, 121,
  135724. _vq_lengthlist__44u6__p8_0,
  135725. 1, -524582912, 1618345984, 4, 0,
  135726. _vq_quantlist__44u6__p8_0,
  135727. NULL,
  135728. &_vq_auxt__44u6__p8_0,
  135729. NULL,
  135730. 0
  135731. };
  135732. static long _vq_quantlist__44u6__p8_1[] = {
  135733. 5,
  135734. 4,
  135735. 6,
  135736. 3,
  135737. 7,
  135738. 2,
  135739. 8,
  135740. 1,
  135741. 9,
  135742. 0,
  135743. 10,
  135744. };
  135745. static long _vq_lengthlist__44u6__p8_1[] = {
  135746. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135747. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135748. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135749. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135750. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135751. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135752. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135753. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135754. };
  135755. static float _vq_quantthresh__44u6__p8_1[] = {
  135756. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135757. 3.5, 4.5,
  135758. };
  135759. static long _vq_quantmap__44u6__p8_1[] = {
  135760. 9, 7, 5, 3, 1, 0, 2, 4,
  135761. 6, 8, 10,
  135762. };
  135763. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135764. _vq_quantthresh__44u6__p8_1,
  135765. _vq_quantmap__44u6__p8_1,
  135766. 11,
  135767. 11
  135768. };
  135769. static static_codebook _44u6__p8_1 = {
  135770. 2, 121,
  135771. _vq_lengthlist__44u6__p8_1,
  135772. 1, -531365888, 1611661312, 4, 0,
  135773. _vq_quantlist__44u6__p8_1,
  135774. NULL,
  135775. &_vq_auxt__44u6__p8_1,
  135776. NULL,
  135777. 0
  135778. };
  135779. static long _vq_quantlist__44u6__p9_0[] = {
  135780. 7,
  135781. 6,
  135782. 8,
  135783. 5,
  135784. 9,
  135785. 4,
  135786. 10,
  135787. 3,
  135788. 11,
  135789. 2,
  135790. 12,
  135791. 1,
  135792. 13,
  135793. 0,
  135794. 14,
  135795. };
  135796. static long _vq_lengthlist__44u6__p9_0[] = {
  135797. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135798. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135799. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135800. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135801. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135802. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135803. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135804. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135805. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135806. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135807. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135808. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135809. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135810. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135811. 14,
  135812. };
  135813. static float _vq_quantthresh__44u6__p9_0[] = {
  135814. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135815. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135816. };
  135817. static long _vq_quantmap__44u6__p9_0[] = {
  135818. 13, 11, 9, 7, 5, 3, 1, 0,
  135819. 2, 4, 6, 8, 10, 12, 14,
  135820. };
  135821. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135822. _vq_quantthresh__44u6__p9_0,
  135823. _vq_quantmap__44u6__p9_0,
  135824. 15,
  135825. 15
  135826. };
  135827. static static_codebook _44u6__p9_0 = {
  135828. 2, 225,
  135829. _vq_lengthlist__44u6__p9_0,
  135830. 1, -514071552, 1627381760, 4, 0,
  135831. _vq_quantlist__44u6__p9_0,
  135832. NULL,
  135833. &_vq_auxt__44u6__p9_0,
  135834. NULL,
  135835. 0
  135836. };
  135837. static long _vq_quantlist__44u6__p9_1[] = {
  135838. 7,
  135839. 6,
  135840. 8,
  135841. 5,
  135842. 9,
  135843. 4,
  135844. 10,
  135845. 3,
  135846. 11,
  135847. 2,
  135848. 12,
  135849. 1,
  135850. 13,
  135851. 0,
  135852. 14,
  135853. };
  135854. static long _vq_lengthlist__44u6__p9_1[] = {
  135855. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135856. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135857. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135858. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135859. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135860. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135861. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135862. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135863. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135864. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135865. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135866. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135867. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135868. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135869. 13,
  135870. };
  135871. static float _vq_quantthresh__44u6__p9_1[] = {
  135872. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135873. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135874. };
  135875. static long _vq_quantmap__44u6__p9_1[] = {
  135876. 13, 11, 9, 7, 5, 3, 1, 0,
  135877. 2, 4, 6, 8, 10, 12, 14,
  135878. };
  135879. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135880. _vq_quantthresh__44u6__p9_1,
  135881. _vq_quantmap__44u6__p9_1,
  135882. 15,
  135883. 15
  135884. };
  135885. static static_codebook _44u6__p9_1 = {
  135886. 2, 225,
  135887. _vq_lengthlist__44u6__p9_1,
  135888. 1, -522338304, 1620115456, 4, 0,
  135889. _vq_quantlist__44u6__p9_1,
  135890. NULL,
  135891. &_vq_auxt__44u6__p9_1,
  135892. NULL,
  135893. 0
  135894. };
  135895. static long _vq_quantlist__44u6__p9_2[] = {
  135896. 8,
  135897. 7,
  135898. 9,
  135899. 6,
  135900. 10,
  135901. 5,
  135902. 11,
  135903. 4,
  135904. 12,
  135905. 3,
  135906. 13,
  135907. 2,
  135908. 14,
  135909. 1,
  135910. 15,
  135911. 0,
  135912. 16,
  135913. };
  135914. static long _vq_lengthlist__44u6__p9_2[] = {
  135915. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135916. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135917. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135918. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135919. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135920. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135921. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135922. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135923. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135924. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135925. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135926. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135927. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135928. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135929. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135930. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135931. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135932. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135933. 10,
  135934. };
  135935. static float _vq_quantthresh__44u6__p9_2[] = {
  135936. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135937. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135938. };
  135939. static long _vq_quantmap__44u6__p9_2[] = {
  135940. 15, 13, 11, 9, 7, 5, 3, 1,
  135941. 0, 2, 4, 6, 8, 10, 12, 14,
  135942. 16,
  135943. };
  135944. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135945. _vq_quantthresh__44u6__p9_2,
  135946. _vq_quantmap__44u6__p9_2,
  135947. 17,
  135948. 17
  135949. };
  135950. static static_codebook _44u6__p9_2 = {
  135951. 2, 289,
  135952. _vq_lengthlist__44u6__p9_2,
  135953. 1, -529530880, 1611661312, 5, 0,
  135954. _vq_quantlist__44u6__p9_2,
  135955. NULL,
  135956. &_vq_auxt__44u6__p9_2,
  135957. NULL,
  135958. 0
  135959. };
  135960. static long _huff_lengthlist__44u6__short[] = {
  135961. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135962. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135963. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135964. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135965. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135966. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135967. 7, 6, 9,16,
  135968. };
  135969. static static_codebook _huff_book__44u6__short = {
  135970. 2, 100,
  135971. _huff_lengthlist__44u6__short,
  135972. 0, 0, 0, 0, 0,
  135973. NULL,
  135974. NULL,
  135975. NULL,
  135976. NULL,
  135977. 0
  135978. };
  135979. static long _huff_lengthlist__44u7__long[] = {
  135980. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135981. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135982. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135983. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135984. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135985. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135986. 12, 8, 6, 7,
  135987. };
  135988. static static_codebook _huff_book__44u7__long = {
  135989. 2, 100,
  135990. _huff_lengthlist__44u7__long,
  135991. 0, 0, 0, 0, 0,
  135992. NULL,
  135993. NULL,
  135994. NULL,
  135995. NULL,
  135996. 0
  135997. };
  135998. static long _vq_quantlist__44u7__p1_0[] = {
  135999. 1,
  136000. 0,
  136001. 2,
  136002. };
  136003. static long _vq_lengthlist__44u7__p1_0[] = {
  136004. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  136005. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  136006. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  136007. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  136008. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  136009. 12,
  136010. };
  136011. static float _vq_quantthresh__44u7__p1_0[] = {
  136012. -0.5, 0.5,
  136013. };
  136014. static long _vq_quantmap__44u7__p1_0[] = {
  136015. 1, 0, 2,
  136016. };
  136017. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  136018. _vq_quantthresh__44u7__p1_0,
  136019. _vq_quantmap__44u7__p1_0,
  136020. 3,
  136021. 3
  136022. };
  136023. static static_codebook _44u7__p1_0 = {
  136024. 4, 81,
  136025. _vq_lengthlist__44u7__p1_0,
  136026. 1, -535822336, 1611661312, 2, 0,
  136027. _vq_quantlist__44u7__p1_0,
  136028. NULL,
  136029. &_vq_auxt__44u7__p1_0,
  136030. NULL,
  136031. 0
  136032. };
  136033. static long _vq_quantlist__44u7__p2_0[] = {
  136034. 1,
  136035. 0,
  136036. 2,
  136037. };
  136038. static long _vq_lengthlist__44u7__p2_0[] = {
  136039. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  136040. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  136041. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  136042. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  136043. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  136044. 9,
  136045. };
  136046. static float _vq_quantthresh__44u7__p2_0[] = {
  136047. -0.5, 0.5,
  136048. };
  136049. static long _vq_quantmap__44u7__p2_0[] = {
  136050. 1, 0, 2,
  136051. };
  136052. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  136053. _vq_quantthresh__44u7__p2_0,
  136054. _vq_quantmap__44u7__p2_0,
  136055. 3,
  136056. 3
  136057. };
  136058. static static_codebook _44u7__p2_0 = {
  136059. 4, 81,
  136060. _vq_lengthlist__44u7__p2_0,
  136061. 1, -535822336, 1611661312, 2, 0,
  136062. _vq_quantlist__44u7__p2_0,
  136063. NULL,
  136064. &_vq_auxt__44u7__p2_0,
  136065. NULL,
  136066. 0
  136067. };
  136068. static long _vq_quantlist__44u7__p3_0[] = {
  136069. 2,
  136070. 1,
  136071. 3,
  136072. 0,
  136073. 4,
  136074. };
  136075. static long _vq_lengthlist__44u7__p3_0[] = {
  136076. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136077. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  136078. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  136079. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  136080. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  136081. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  136082. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  136083. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  136084. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  136085. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  136086. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  136087. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  136088. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  136089. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  136090. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  136091. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  136092. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  136093. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  136094. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  136095. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  136096. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  136097. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  136098. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  136099. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  136100. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  136101. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  136102. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  136103. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  136104. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  136105. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  136106. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  136107. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  136108. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  136109. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  136110. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  136111. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  136112. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  136113. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  136114. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  136115. 0,
  136116. };
  136117. static float _vq_quantthresh__44u7__p3_0[] = {
  136118. -1.5, -0.5, 0.5, 1.5,
  136119. };
  136120. static long _vq_quantmap__44u7__p3_0[] = {
  136121. 3, 1, 0, 2, 4,
  136122. };
  136123. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  136124. _vq_quantthresh__44u7__p3_0,
  136125. _vq_quantmap__44u7__p3_0,
  136126. 5,
  136127. 5
  136128. };
  136129. static static_codebook _44u7__p3_0 = {
  136130. 4, 625,
  136131. _vq_lengthlist__44u7__p3_0,
  136132. 1, -533725184, 1611661312, 3, 0,
  136133. _vq_quantlist__44u7__p3_0,
  136134. NULL,
  136135. &_vq_auxt__44u7__p3_0,
  136136. NULL,
  136137. 0
  136138. };
  136139. static long _vq_quantlist__44u7__p4_0[] = {
  136140. 2,
  136141. 1,
  136142. 3,
  136143. 0,
  136144. 4,
  136145. };
  136146. static long _vq_lengthlist__44u7__p4_0[] = {
  136147. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  136148. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  136149. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  136150. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  136151. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  136152. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  136153. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  136154. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  136155. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  136156. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  136157. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  136158. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  136159. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  136160. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  136161. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  136162. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  136163. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  136164. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  136165. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  136166. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  136167. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  136168. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  136169. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  136170. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136171. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  136172. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  136173. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  136174. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  136175. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  136176. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  136177. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  136178. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136179. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  136180. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  136181. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  136182. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  136183. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  136184. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  136185. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  136186. 14,
  136187. };
  136188. static float _vq_quantthresh__44u7__p4_0[] = {
  136189. -1.5, -0.5, 0.5, 1.5,
  136190. };
  136191. static long _vq_quantmap__44u7__p4_0[] = {
  136192. 3, 1, 0, 2, 4,
  136193. };
  136194. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  136195. _vq_quantthresh__44u7__p4_0,
  136196. _vq_quantmap__44u7__p4_0,
  136197. 5,
  136198. 5
  136199. };
  136200. static static_codebook _44u7__p4_0 = {
  136201. 4, 625,
  136202. _vq_lengthlist__44u7__p4_0,
  136203. 1, -533725184, 1611661312, 3, 0,
  136204. _vq_quantlist__44u7__p4_0,
  136205. NULL,
  136206. &_vq_auxt__44u7__p4_0,
  136207. NULL,
  136208. 0
  136209. };
  136210. static long _vq_quantlist__44u7__p5_0[] = {
  136211. 4,
  136212. 3,
  136213. 5,
  136214. 2,
  136215. 6,
  136216. 1,
  136217. 7,
  136218. 0,
  136219. 8,
  136220. };
  136221. static long _vq_lengthlist__44u7__p5_0[] = {
  136222. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  136223. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  136224. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  136225. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  136226. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  136227. 14,
  136228. };
  136229. static float _vq_quantthresh__44u7__p5_0[] = {
  136230. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136231. };
  136232. static long _vq_quantmap__44u7__p5_0[] = {
  136233. 7, 5, 3, 1, 0, 2, 4, 6,
  136234. 8,
  136235. };
  136236. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  136237. _vq_quantthresh__44u7__p5_0,
  136238. _vq_quantmap__44u7__p5_0,
  136239. 9,
  136240. 9
  136241. };
  136242. static static_codebook _44u7__p5_0 = {
  136243. 2, 81,
  136244. _vq_lengthlist__44u7__p5_0,
  136245. 1, -531628032, 1611661312, 4, 0,
  136246. _vq_quantlist__44u7__p5_0,
  136247. NULL,
  136248. &_vq_auxt__44u7__p5_0,
  136249. NULL,
  136250. 0
  136251. };
  136252. static long _vq_quantlist__44u7__p6_0[] = {
  136253. 4,
  136254. 3,
  136255. 5,
  136256. 2,
  136257. 6,
  136258. 1,
  136259. 7,
  136260. 0,
  136261. 8,
  136262. };
  136263. static long _vq_lengthlist__44u7__p6_0[] = {
  136264. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  136265. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136266. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136267. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  136268. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  136269. 12,
  136270. };
  136271. static float _vq_quantthresh__44u7__p6_0[] = {
  136272. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136273. };
  136274. static long _vq_quantmap__44u7__p6_0[] = {
  136275. 7, 5, 3, 1, 0, 2, 4, 6,
  136276. 8,
  136277. };
  136278. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  136279. _vq_quantthresh__44u7__p6_0,
  136280. _vq_quantmap__44u7__p6_0,
  136281. 9,
  136282. 9
  136283. };
  136284. static static_codebook _44u7__p6_0 = {
  136285. 2, 81,
  136286. _vq_lengthlist__44u7__p6_0,
  136287. 1, -531628032, 1611661312, 4, 0,
  136288. _vq_quantlist__44u7__p6_0,
  136289. NULL,
  136290. &_vq_auxt__44u7__p6_0,
  136291. NULL,
  136292. 0
  136293. };
  136294. static long _vq_quantlist__44u7__p7_0[] = {
  136295. 1,
  136296. 0,
  136297. 2,
  136298. };
  136299. static long _vq_lengthlist__44u7__p7_0[] = {
  136300. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136301. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136302. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136303. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136304. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136305. 10,
  136306. };
  136307. static float _vq_quantthresh__44u7__p7_0[] = {
  136308. -5.5, 5.5,
  136309. };
  136310. static long _vq_quantmap__44u7__p7_0[] = {
  136311. 1, 0, 2,
  136312. };
  136313. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136314. _vq_quantthresh__44u7__p7_0,
  136315. _vq_quantmap__44u7__p7_0,
  136316. 3,
  136317. 3
  136318. };
  136319. static static_codebook _44u7__p7_0 = {
  136320. 4, 81,
  136321. _vq_lengthlist__44u7__p7_0,
  136322. 1, -529137664, 1618345984, 2, 0,
  136323. _vq_quantlist__44u7__p7_0,
  136324. NULL,
  136325. &_vq_auxt__44u7__p7_0,
  136326. NULL,
  136327. 0
  136328. };
  136329. static long _vq_quantlist__44u7__p7_1[] = {
  136330. 5,
  136331. 4,
  136332. 6,
  136333. 3,
  136334. 7,
  136335. 2,
  136336. 8,
  136337. 1,
  136338. 9,
  136339. 0,
  136340. 10,
  136341. };
  136342. static long _vq_lengthlist__44u7__p7_1[] = {
  136343. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136344. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136345. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136346. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136347. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136348. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136349. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136350. 8, 9, 9, 9, 9, 9,10,10,10,
  136351. };
  136352. static float _vq_quantthresh__44u7__p7_1[] = {
  136353. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136354. 3.5, 4.5,
  136355. };
  136356. static long _vq_quantmap__44u7__p7_1[] = {
  136357. 9, 7, 5, 3, 1, 0, 2, 4,
  136358. 6, 8, 10,
  136359. };
  136360. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136361. _vq_quantthresh__44u7__p7_1,
  136362. _vq_quantmap__44u7__p7_1,
  136363. 11,
  136364. 11
  136365. };
  136366. static static_codebook _44u7__p7_1 = {
  136367. 2, 121,
  136368. _vq_lengthlist__44u7__p7_1,
  136369. 1, -531365888, 1611661312, 4, 0,
  136370. _vq_quantlist__44u7__p7_1,
  136371. NULL,
  136372. &_vq_auxt__44u7__p7_1,
  136373. NULL,
  136374. 0
  136375. };
  136376. static long _vq_quantlist__44u7__p8_0[] = {
  136377. 5,
  136378. 4,
  136379. 6,
  136380. 3,
  136381. 7,
  136382. 2,
  136383. 8,
  136384. 1,
  136385. 9,
  136386. 0,
  136387. 10,
  136388. };
  136389. static long _vq_lengthlist__44u7__p8_0[] = {
  136390. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136391. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136392. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136393. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136394. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136395. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136396. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136397. 12,13,13,14,14,15,15,15,16,
  136398. };
  136399. static float _vq_quantthresh__44u7__p8_0[] = {
  136400. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136401. 38.5, 49.5,
  136402. };
  136403. static long _vq_quantmap__44u7__p8_0[] = {
  136404. 9, 7, 5, 3, 1, 0, 2, 4,
  136405. 6, 8, 10,
  136406. };
  136407. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136408. _vq_quantthresh__44u7__p8_0,
  136409. _vq_quantmap__44u7__p8_0,
  136410. 11,
  136411. 11
  136412. };
  136413. static static_codebook _44u7__p8_0 = {
  136414. 2, 121,
  136415. _vq_lengthlist__44u7__p8_0,
  136416. 1, -524582912, 1618345984, 4, 0,
  136417. _vq_quantlist__44u7__p8_0,
  136418. NULL,
  136419. &_vq_auxt__44u7__p8_0,
  136420. NULL,
  136421. 0
  136422. };
  136423. static long _vq_quantlist__44u7__p8_1[] = {
  136424. 5,
  136425. 4,
  136426. 6,
  136427. 3,
  136428. 7,
  136429. 2,
  136430. 8,
  136431. 1,
  136432. 9,
  136433. 0,
  136434. 10,
  136435. };
  136436. static long _vq_lengthlist__44u7__p8_1[] = {
  136437. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136438. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136439. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136440. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136441. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136442. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136443. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136444. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136445. };
  136446. static float _vq_quantthresh__44u7__p8_1[] = {
  136447. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136448. 3.5, 4.5,
  136449. };
  136450. static long _vq_quantmap__44u7__p8_1[] = {
  136451. 9, 7, 5, 3, 1, 0, 2, 4,
  136452. 6, 8, 10,
  136453. };
  136454. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136455. _vq_quantthresh__44u7__p8_1,
  136456. _vq_quantmap__44u7__p8_1,
  136457. 11,
  136458. 11
  136459. };
  136460. static static_codebook _44u7__p8_1 = {
  136461. 2, 121,
  136462. _vq_lengthlist__44u7__p8_1,
  136463. 1, -531365888, 1611661312, 4, 0,
  136464. _vq_quantlist__44u7__p8_1,
  136465. NULL,
  136466. &_vq_auxt__44u7__p8_1,
  136467. NULL,
  136468. 0
  136469. };
  136470. static long _vq_quantlist__44u7__p9_0[] = {
  136471. 5,
  136472. 4,
  136473. 6,
  136474. 3,
  136475. 7,
  136476. 2,
  136477. 8,
  136478. 1,
  136479. 9,
  136480. 0,
  136481. 10,
  136482. };
  136483. static long _vq_lengthlist__44u7__p9_0[] = {
  136484. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136485. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136486. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136487. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136488. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136489. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136490. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136491. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136492. };
  136493. static float _vq_quantthresh__44u7__p9_0[] = {
  136494. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136495. 2229.5, 2866.5,
  136496. };
  136497. static long _vq_quantmap__44u7__p9_0[] = {
  136498. 9, 7, 5, 3, 1, 0, 2, 4,
  136499. 6, 8, 10,
  136500. };
  136501. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136502. _vq_quantthresh__44u7__p9_0,
  136503. _vq_quantmap__44u7__p9_0,
  136504. 11,
  136505. 11
  136506. };
  136507. static static_codebook _44u7__p9_0 = {
  136508. 2, 121,
  136509. _vq_lengthlist__44u7__p9_0,
  136510. 1, -512171520, 1630791680, 4, 0,
  136511. _vq_quantlist__44u7__p9_0,
  136512. NULL,
  136513. &_vq_auxt__44u7__p9_0,
  136514. NULL,
  136515. 0
  136516. };
  136517. static long _vq_quantlist__44u7__p9_1[] = {
  136518. 6,
  136519. 5,
  136520. 7,
  136521. 4,
  136522. 8,
  136523. 3,
  136524. 9,
  136525. 2,
  136526. 10,
  136527. 1,
  136528. 11,
  136529. 0,
  136530. 12,
  136531. };
  136532. static long _vq_lengthlist__44u7__p9_1[] = {
  136533. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136534. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136535. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136536. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136537. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136538. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136539. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136540. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136541. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136542. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136543. 15,15,15,15,17,17,16,17,16,
  136544. };
  136545. static float _vq_quantthresh__44u7__p9_1[] = {
  136546. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136547. 122.5, 171.5, 220.5, 269.5,
  136548. };
  136549. static long _vq_quantmap__44u7__p9_1[] = {
  136550. 11, 9, 7, 5, 3, 1, 0, 2,
  136551. 4, 6, 8, 10, 12,
  136552. };
  136553. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136554. _vq_quantthresh__44u7__p9_1,
  136555. _vq_quantmap__44u7__p9_1,
  136556. 13,
  136557. 13
  136558. };
  136559. static static_codebook _44u7__p9_1 = {
  136560. 2, 169,
  136561. _vq_lengthlist__44u7__p9_1,
  136562. 1, -518889472, 1622704128, 4, 0,
  136563. _vq_quantlist__44u7__p9_1,
  136564. NULL,
  136565. &_vq_auxt__44u7__p9_1,
  136566. NULL,
  136567. 0
  136568. };
  136569. static long _vq_quantlist__44u7__p9_2[] = {
  136570. 24,
  136571. 23,
  136572. 25,
  136573. 22,
  136574. 26,
  136575. 21,
  136576. 27,
  136577. 20,
  136578. 28,
  136579. 19,
  136580. 29,
  136581. 18,
  136582. 30,
  136583. 17,
  136584. 31,
  136585. 16,
  136586. 32,
  136587. 15,
  136588. 33,
  136589. 14,
  136590. 34,
  136591. 13,
  136592. 35,
  136593. 12,
  136594. 36,
  136595. 11,
  136596. 37,
  136597. 10,
  136598. 38,
  136599. 9,
  136600. 39,
  136601. 8,
  136602. 40,
  136603. 7,
  136604. 41,
  136605. 6,
  136606. 42,
  136607. 5,
  136608. 43,
  136609. 4,
  136610. 44,
  136611. 3,
  136612. 45,
  136613. 2,
  136614. 46,
  136615. 1,
  136616. 47,
  136617. 0,
  136618. 48,
  136619. };
  136620. static long _vq_lengthlist__44u7__p9_2[] = {
  136621. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136622. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136623. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136624. 8,
  136625. };
  136626. static float _vq_quantthresh__44u7__p9_2[] = {
  136627. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136628. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136629. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136630. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136631. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136632. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136633. };
  136634. static long _vq_quantmap__44u7__p9_2[] = {
  136635. 47, 45, 43, 41, 39, 37, 35, 33,
  136636. 31, 29, 27, 25, 23, 21, 19, 17,
  136637. 15, 13, 11, 9, 7, 5, 3, 1,
  136638. 0, 2, 4, 6, 8, 10, 12, 14,
  136639. 16, 18, 20, 22, 24, 26, 28, 30,
  136640. 32, 34, 36, 38, 40, 42, 44, 46,
  136641. 48,
  136642. };
  136643. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136644. _vq_quantthresh__44u7__p9_2,
  136645. _vq_quantmap__44u7__p9_2,
  136646. 49,
  136647. 49
  136648. };
  136649. static static_codebook _44u7__p9_2 = {
  136650. 1, 49,
  136651. _vq_lengthlist__44u7__p9_2,
  136652. 1, -526909440, 1611661312, 6, 0,
  136653. _vq_quantlist__44u7__p9_2,
  136654. NULL,
  136655. &_vq_auxt__44u7__p9_2,
  136656. NULL,
  136657. 0
  136658. };
  136659. static long _huff_lengthlist__44u7__short[] = {
  136660. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136661. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136662. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136663. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136664. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136665. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136666. 6, 8, 5, 9,
  136667. };
  136668. static static_codebook _huff_book__44u7__short = {
  136669. 2, 100,
  136670. _huff_lengthlist__44u7__short,
  136671. 0, 0, 0, 0, 0,
  136672. NULL,
  136673. NULL,
  136674. NULL,
  136675. NULL,
  136676. 0
  136677. };
  136678. static long _huff_lengthlist__44u8__long[] = {
  136679. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136680. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136681. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136682. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136683. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136684. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136685. 10, 8, 8, 9,
  136686. };
  136687. static static_codebook _huff_book__44u8__long = {
  136688. 2, 100,
  136689. _huff_lengthlist__44u8__long,
  136690. 0, 0, 0, 0, 0,
  136691. NULL,
  136692. NULL,
  136693. NULL,
  136694. NULL,
  136695. 0
  136696. };
  136697. static long _huff_lengthlist__44u8__short[] = {
  136698. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136699. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136700. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136701. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136702. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136703. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136704. 10,10,15,17,
  136705. };
  136706. static static_codebook _huff_book__44u8__short = {
  136707. 2, 100,
  136708. _huff_lengthlist__44u8__short,
  136709. 0, 0, 0, 0, 0,
  136710. NULL,
  136711. NULL,
  136712. NULL,
  136713. NULL,
  136714. 0
  136715. };
  136716. static long _vq_quantlist__44u8_p1_0[] = {
  136717. 1,
  136718. 0,
  136719. 2,
  136720. };
  136721. static long _vq_lengthlist__44u8_p1_0[] = {
  136722. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136723. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136724. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136725. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136726. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136727. 10,
  136728. };
  136729. static float _vq_quantthresh__44u8_p1_0[] = {
  136730. -0.5, 0.5,
  136731. };
  136732. static long _vq_quantmap__44u8_p1_0[] = {
  136733. 1, 0, 2,
  136734. };
  136735. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136736. _vq_quantthresh__44u8_p1_0,
  136737. _vq_quantmap__44u8_p1_0,
  136738. 3,
  136739. 3
  136740. };
  136741. static static_codebook _44u8_p1_0 = {
  136742. 4, 81,
  136743. _vq_lengthlist__44u8_p1_0,
  136744. 1, -535822336, 1611661312, 2, 0,
  136745. _vq_quantlist__44u8_p1_0,
  136746. NULL,
  136747. &_vq_auxt__44u8_p1_0,
  136748. NULL,
  136749. 0
  136750. };
  136751. static long _vq_quantlist__44u8_p2_0[] = {
  136752. 2,
  136753. 1,
  136754. 3,
  136755. 0,
  136756. 4,
  136757. };
  136758. static long _vq_lengthlist__44u8_p2_0[] = {
  136759. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136760. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136761. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136762. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136763. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136764. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136765. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136766. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136767. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136768. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136769. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136770. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136771. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136772. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136773. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136774. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136775. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136776. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136777. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136778. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136779. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136780. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136781. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136782. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136783. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136784. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136785. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136786. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136787. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136788. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136789. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136790. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136791. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136792. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136793. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136794. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136795. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136796. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136797. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136798. 14,
  136799. };
  136800. static float _vq_quantthresh__44u8_p2_0[] = {
  136801. -1.5, -0.5, 0.5, 1.5,
  136802. };
  136803. static long _vq_quantmap__44u8_p2_0[] = {
  136804. 3, 1, 0, 2, 4,
  136805. };
  136806. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136807. _vq_quantthresh__44u8_p2_0,
  136808. _vq_quantmap__44u8_p2_0,
  136809. 5,
  136810. 5
  136811. };
  136812. static static_codebook _44u8_p2_0 = {
  136813. 4, 625,
  136814. _vq_lengthlist__44u8_p2_0,
  136815. 1, -533725184, 1611661312, 3, 0,
  136816. _vq_quantlist__44u8_p2_0,
  136817. NULL,
  136818. &_vq_auxt__44u8_p2_0,
  136819. NULL,
  136820. 0
  136821. };
  136822. static long _vq_quantlist__44u8_p3_0[] = {
  136823. 4,
  136824. 3,
  136825. 5,
  136826. 2,
  136827. 6,
  136828. 1,
  136829. 7,
  136830. 0,
  136831. 8,
  136832. };
  136833. static long _vq_lengthlist__44u8_p3_0[] = {
  136834. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136835. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136836. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136837. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136838. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136839. 12,
  136840. };
  136841. static float _vq_quantthresh__44u8_p3_0[] = {
  136842. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136843. };
  136844. static long _vq_quantmap__44u8_p3_0[] = {
  136845. 7, 5, 3, 1, 0, 2, 4, 6,
  136846. 8,
  136847. };
  136848. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136849. _vq_quantthresh__44u8_p3_0,
  136850. _vq_quantmap__44u8_p3_0,
  136851. 9,
  136852. 9
  136853. };
  136854. static static_codebook _44u8_p3_0 = {
  136855. 2, 81,
  136856. _vq_lengthlist__44u8_p3_0,
  136857. 1, -531628032, 1611661312, 4, 0,
  136858. _vq_quantlist__44u8_p3_0,
  136859. NULL,
  136860. &_vq_auxt__44u8_p3_0,
  136861. NULL,
  136862. 0
  136863. };
  136864. static long _vq_quantlist__44u8_p4_0[] = {
  136865. 8,
  136866. 7,
  136867. 9,
  136868. 6,
  136869. 10,
  136870. 5,
  136871. 11,
  136872. 4,
  136873. 12,
  136874. 3,
  136875. 13,
  136876. 2,
  136877. 14,
  136878. 1,
  136879. 15,
  136880. 0,
  136881. 16,
  136882. };
  136883. static long _vq_lengthlist__44u8_p4_0[] = {
  136884. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136885. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136886. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136887. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136888. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136889. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136890. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136891. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136892. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136893. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136894. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136895. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136896. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136897. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136898. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136899. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136900. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136901. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136902. 14,
  136903. };
  136904. static float _vq_quantthresh__44u8_p4_0[] = {
  136905. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136906. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136907. };
  136908. static long _vq_quantmap__44u8_p4_0[] = {
  136909. 15, 13, 11, 9, 7, 5, 3, 1,
  136910. 0, 2, 4, 6, 8, 10, 12, 14,
  136911. 16,
  136912. };
  136913. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136914. _vq_quantthresh__44u8_p4_0,
  136915. _vq_quantmap__44u8_p4_0,
  136916. 17,
  136917. 17
  136918. };
  136919. static static_codebook _44u8_p4_0 = {
  136920. 2, 289,
  136921. _vq_lengthlist__44u8_p4_0,
  136922. 1, -529530880, 1611661312, 5, 0,
  136923. _vq_quantlist__44u8_p4_0,
  136924. NULL,
  136925. &_vq_auxt__44u8_p4_0,
  136926. NULL,
  136927. 0
  136928. };
  136929. static long _vq_quantlist__44u8_p5_0[] = {
  136930. 1,
  136931. 0,
  136932. 2,
  136933. };
  136934. static long _vq_lengthlist__44u8_p5_0[] = {
  136935. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136936. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136937. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136938. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136939. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136940. 10,
  136941. };
  136942. static float _vq_quantthresh__44u8_p5_0[] = {
  136943. -5.5, 5.5,
  136944. };
  136945. static long _vq_quantmap__44u8_p5_0[] = {
  136946. 1, 0, 2,
  136947. };
  136948. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136949. _vq_quantthresh__44u8_p5_0,
  136950. _vq_quantmap__44u8_p5_0,
  136951. 3,
  136952. 3
  136953. };
  136954. static static_codebook _44u8_p5_0 = {
  136955. 4, 81,
  136956. _vq_lengthlist__44u8_p5_0,
  136957. 1, -529137664, 1618345984, 2, 0,
  136958. _vq_quantlist__44u8_p5_0,
  136959. NULL,
  136960. &_vq_auxt__44u8_p5_0,
  136961. NULL,
  136962. 0
  136963. };
  136964. static long _vq_quantlist__44u8_p5_1[] = {
  136965. 5,
  136966. 4,
  136967. 6,
  136968. 3,
  136969. 7,
  136970. 2,
  136971. 8,
  136972. 1,
  136973. 9,
  136974. 0,
  136975. 10,
  136976. };
  136977. static long _vq_lengthlist__44u8_p5_1[] = {
  136978. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136979. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136980. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136981. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136982. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136983. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136984. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136985. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136986. };
  136987. static float _vq_quantthresh__44u8_p5_1[] = {
  136988. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136989. 3.5, 4.5,
  136990. };
  136991. static long _vq_quantmap__44u8_p5_1[] = {
  136992. 9, 7, 5, 3, 1, 0, 2, 4,
  136993. 6, 8, 10,
  136994. };
  136995. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136996. _vq_quantthresh__44u8_p5_1,
  136997. _vq_quantmap__44u8_p5_1,
  136998. 11,
  136999. 11
  137000. };
  137001. static static_codebook _44u8_p5_1 = {
  137002. 2, 121,
  137003. _vq_lengthlist__44u8_p5_1,
  137004. 1, -531365888, 1611661312, 4, 0,
  137005. _vq_quantlist__44u8_p5_1,
  137006. NULL,
  137007. &_vq_auxt__44u8_p5_1,
  137008. NULL,
  137009. 0
  137010. };
  137011. static long _vq_quantlist__44u8_p6_0[] = {
  137012. 6,
  137013. 5,
  137014. 7,
  137015. 4,
  137016. 8,
  137017. 3,
  137018. 9,
  137019. 2,
  137020. 10,
  137021. 1,
  137022. 11,
  137023. 0,
  137024. 12,
  137025. };
  137026. static long _vq_lengthlist__44u8_p6_0[] = {
  137027. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137028. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  137029. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  137030. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  137031. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  137032. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137033. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137034. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  137035. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  137036. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137037. 11,11,11,11,11,12,11,12,12,
  137038. };
  137039. static float _vq_quantthresh__44u8_p6_0[] = {
  137040. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137041. 12.5, 17.5, 22.5, 27.5,
  137042. };
  137043. static long _vq_quantmap__44u8_p6_0[] = {
  137044. 11, 9, 7, 5, 3, 1, 0, 2,
  137045. 4, 6, 8, 10, 12,
  137046. };
  137047. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  137048. _vq_quantthresh__44u8_p6_0,
  137049. _vq_quantmap__44u8_p6_0,
  137050. 13,
  137051. 13
  137052. };
  137053. static static_codebook _44u8_p6_0 = {
  137054. 2, 169,
  137055. _vq_lengthlist__44u8_p6_0,
  137056. 1, -526516224, 1616117760, 4, 0,
  137057. _vq_quantlist__44u8_p6_0,
  137058. NULL,
  137059. &_vq_auxt__44u8_p6_0,
  137060. NULL,
  137061. 0
  137062. };
  137063. static long _vq_quantlist__44u8_p6_1[] = {
  137064. 2,
  137065. 1,
  137066. 3,
  137067. 0,
  137068. 4,
  137069. };
  137070. static long _vq_lengthlist__44u8_p6_1[] = {
  137071. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  137072. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137073. };
  137074. static float _vq_quantthresh__44u8_p6_1[] = {
  137075. -1.5, -0.5, 0.5, 1.5,
  137076. };
  137077. static long _vq_quantmap__44u8_p6_1[] = {
  137078. 3, 1, 0, 2, 4,
  137079. };
  137080. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  137081. _vq_quantthresh__44u8_p6_1,
  137082. _vq_quantmap__44u8_p6_1,
  137083. 5,
  137084. 5
  137085. };
  137086. static static_codebook _44u8_p6_1 = {
  137087. 2, 25,
  137088. _vq_lengthlist__44u8_p6_1,
  137089. 1, -533725184, 1611661312, 3, 0,
  137090. _vq_quantlist__44u8_p6_1,
  137091. NULL,
  137092. &_vq_auxt__44u8_p6_1,
  137093. NULL,
  137094. 0
  137095. };
  137096. static long _vq_quantlist__44u8_p7_0[] = {
  137097. 6,
  137098. 5,
  137099. 7,
  137100. 4,
  137101. 8,
  137102. 3,
  137103. 9,
  137104. 2,
  137105. 10,
  137106. 1,
  137107. 11,
  137108. 0,
  137109. 12,
  137110. };
  137111. static long _vq_lengthlist__44u8_p7_0[] = {
  137112. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  137113. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  137114. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  137115. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  137116. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137117. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137118. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  137119. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  137120. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  137121. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  137122. 13,13,14,14,14,15,15,15,16,
  137123. };
  137124. static float _vq_quantthresh__44u8_p7_0[] = {
  137125. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137126. 27.5, 38.5, 49.5, 60.5,
  137127. };
  137128. static long _vq_quantmap__44u8_p7_0[] = {
  137129. 11, 9, 7, 5, 3, 1, 0, 2,
  137130. 4, 6, 8, 10, 12,
  137131. };
  137132. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  137133. _vq_quantthresh__44u8_p7_0,
  137134. _vq_quantmap__44u8_p7_0,
  137135. 13,
  137136. 13
  137137. };
  137138. static static_codebook _44u8_p7_0 = {
  137139. 2, 169,
  137140. _vq_lengthlist__44u8_p7_0,
  137141. 1, -523206656, 1618345984, 4, 0,
  137142. _vq_quantlist__44u8_p7_0,
  137143. NULL,
  137144. &_vq_auxt__44u8_p7_0,
  137145. NULL,
  137146. 0
  137147. };
  137148. static long _vq_quantlist__44u8_p7_1[] = {
  137149. 5,
  137150. 4,
  137151. 6,
  137152. 3,
  137153. 7,
  137154. 2,
  137155. 8,
  137156. 1,
  137157. 9,
  137158. 0,
  137159. 10,
  137160. };
  137161. static long _vq_lengthlist__44u8_p7_1[] = {
  137162. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  137163. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137164. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  137165. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  137166. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  137167. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  137168. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  137169. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  137170. };
  137171. static float _vq_quantthresh__44u8_p7_1[] = {
  137172. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137173. 3.5, 4.5,
  137174. };
  137175. static long _vq_quantmap__44u8_p7_1[] = {
  137176. 9, 7, 5, 3, 1, 0, 2, 4,
  137177. 6, 8, 10,
  137178. };
  137179. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  137180. _vq_quantthresh__44u8_p7_1,
  137181. _vq_quantmap__44u8_p7_1,
  137182. 11,
  137183. 11
  137184. };
  137185. static static_codebook _44u8_p7_1 = {
  137186. 2, 121,
  137187. _vq_lengthlist__44u8_p7_1,
  137188. 1, -531365888, 1611661312, 4, 0,
  137189. _vq_quantlist__44u8_p7_1,
  137190. NULL,
  137191. &_vq_auxt__44u8_p7_1,
  137192. NULL,
  137193. 0
  137194. };
  137195. static long _vq_quantlist__44u8_p8_0[] = {
  137196. 7,
  137197. 6,
  137198. 8,
  137199. 5,
  137200. 9,
  137201. 4,
  137202. 10,
  137203. 3,
  137204. 11,
  137205. 2,
  137206. 12,
  137207. 1,
  137208. 13,
  137209. 0,
  137210. 14,
  137211. };
  137212. static long _vq_lengthlist__44u8_p8_0[] = {
  137213. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  137214. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137215. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  137216. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  137217. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  137218. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  137219. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  137220. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  137221. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  137222. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  137223. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  137224. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  137225. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  137226. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  137227. 17,
  137228. };
  137229. static float _vq_quantthresh__44u8_p8_0[] = {
  137230. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137231. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137232. };
  137233. static long _vq_quantmap__44u8_p8_0[] = {
  137234. 13, 11, 9, 7, 5, 3, 1, 0,
  137235. 2, 4, 6, 8, 10, 12, 14,
  137236. };
  137237. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  137238. _vq_quantthresh__44u8_p8_0,
  137239. _vq_quantmap__44u8_p8_0,
  137240. 15,
  137241. 15
  137242. };
  137243. static static_codebook _44u8_p8_0 = {
  137244. 2, 225,
  137245. _vq_lengthlist__44u8_p8_0,
  137246. 1, -520986624, 1620377600, 4, 0,
  137247. _vq_quantlist__44u8_p8_0,
  137248. NULL,
  137249. &_vq_auxt__44u8_p8_0,
  137250. NULL,
  137251. 0
  137252. };
  137253. static long _vq_quantlist__44u8_p8_1[] = {
  137254. 10,
  137255. 9,
  137256. 11,
  137257. 8,
  137258. 12,
  137259. 7,
  137260. 13,
  137261. 6,
  137262. 14,
  137263. 5,
  137264. 15,
  137265. 4,
  137266. 16,
  137267. 3,
  137268. 17,
  137269. 2,
  137270. 18,
  137271. 1,
  137272. 19,
  137273. 0,
  137274. 20,
  137275. };
  137276. static long _vq_lengthlist__44u8_p8_1[] = {
  137277. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137278. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137279. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  137280. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137281. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137282. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137283. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137284. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137285. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137286. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137287. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137288. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137289. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137290. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137291. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137292. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137293. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137294. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137295. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137296. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137297. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137298. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137299. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137300. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137301. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137302. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137303. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137304. 10,10,10,10,10,10,10,10,10,
  137305. };
  137306. static float _vq_quantthresh__44u8_p8_1[] = {
  137307. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137308. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137309. 6.5, 7.5, 8.5, 9.5,
  137310. };
  137311. static long _vq_quantmap__44u8_p8_1[] = {
  137312. 19, 17, 15, 13, 11, 9, 7, 5,
  137313. 3, 1, 0, 2, 4, 6, 8, 10,
  137314. 12, 14, 16, 18, 20,
  137315. };
  137316. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137317. _vq_quantthresh__44u8_p8_1,
  137318. _vq_quantmap__44u8_p8_1,
  137319. 21,
  137320. 21
  137321. };
  137322. static static_codebook _44u8_p8_1 = {
  137323. 2, 441,
  137324. _vq_lengthlist__44u8_p8_1,
  137325. 1, -529268736, 1611661312, 5, 0,
  137326. _vq_quantlist__44u8_p8_1,
  137327. NULL,
  137328. &_vq_auxt__44u8_p8_1,
  137329. NULL,
  137330. 0
  137331. };
  137332. static long _vq_quantlist__44u8_p9_0[] = {
  137333. 4,
  137334. 3,
  137335. 5,
  137336. 2,
  137337. 6,
  137338. 1,
  137339. 7,
  137340. 0,
  137341. 8,
  137342. };
  137343. static long _vq_lengthlist__44u8_p9_0[] = {
  137344. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137345. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137346. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137347. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137348. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137349. 8,
  137350. };
  137351. static float _vq_quantthresh__44u8_p9_0[] = {
  137352. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137353. };
  137354. static long _vq_quantmap__44u8_p9_0[] = {
  137355. 7, 5, 3, 1, 0, 2, 4, 6,
  137356. 8,
  137357. };
  137358. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137359. _vq_quantthresh__44u8_p9_0,
  137360. _vq_quantmap__44u8_p9_0,
  137361. 9,
  137362. 9
  137363. };
  137364. static static_codebook _44u8_p9_0 = {
  137365. 2, 81,
  137366. _vq_lengthlist__44u8_p9_0,
  137367. 1, -511895552, 1631393792, 4, 0,
  137368. _vq_quantlist__44u8_p9_0,
  137369. NULL,
  137370. &_vq_auxt__44u8_p9_0,
  137371. NULL,
  137372. 0
  137373. };
  137374. static long _vq_quantlist__44u8_p9_1[] = {
  137375. 9,
  137376. 8,
  137377. 10,
  137378. 7,
  137379. 11,
  137380. 6,
  137381. 12,
  137382. 5,
  137383. 13,
  137384. 4,
  137385. 14,
  137386. 3,
  137387. 15,
  137388. 2,
  137389. 16,
  137390. 1,
  137391. 17,
  137392. 0,
  137393. 18,
  137394. };
  137395. static long _vq_lengthlist__44u8_p9_1[] = {
  137396. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137397. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137398. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137399. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137400. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137401. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137402. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137403. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137404. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137405. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137406. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137407. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137408. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137409. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137410. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137411. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137412. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137413. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137414. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137415. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137416. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137417. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137418. 16,15,16,16,16,16,16,16,16,
  137419. };
  137420. static float _vq_quantthresh__44u8_p9_1[] = {
  137421. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137422. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137423. 367.5, 416.5,
  137424. };
  137425. static long _vq_quantmap__44u8_p9_1[] = {
  137426. 17, 15, 13, 11, 9, 7, 5, 3,
  137427. 1, 0, 2, 4, 6, 8, 10, 12,
  137428. 14, 16, 18,
  137429. };
  137430. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137431. _vq_quantthresh__44u8_p9_1,
  137432. _vq_quantmap__44u8_p9_1,
  137433. 19,
  137434. 19
  137435. };
  137436. static static_codebook _44u8_p9_1 = {
  137437. 2, 361,
  137438. _vq_lengthlist__44u8_p9_1,
  137439. 1, -518287360, 1622704128, 5, 0,
  137440. _vq_quantlist__44u8_p9_1,
  137441. NULL,
  137442. &_vq_auxt__44u8_p9_1,
  137443. NULL,
  137444. 0
  137445. };
  137446. static long _vq_quantlist__44u8_p9_2[] = {
  137447. 24,
  137448. 23,
  137449. 25,
  137450. 22,
  137451. 26,
  137452. 21,
  137453. 27,
  137454. 20,
  137455. 28,
  137456. 19,
  137457. 29,
  137458. 18,
  137459. 30,
  137460. 17,
  137461. 31,
  137462. 16,
  137463. 32,
  137464. 15,
  137465. 33,
  137466. 14,
  137467. 34,
  137468. 13,
  137469. 35,
  137470. 12,
  137471. 36,
  137472. 11,
  137473. 37,
  137474. 10,
  137475. 38,
  137476. 9,
  137477. 39,
  137478. 8,
  137479. 40,
  137480. 7,
  137481. 41,
  137482. 6,
  137483. 42,
  137484. 5,
  137485. 43,
  137486. 4,
  137487. 44,
  137488. 3,
  137489. 45,
  137490. 2,
  137491. 46,
  137492. 1,
  137493. 47,
  137494. 0,
  137495. 48,
  137496. };
  137497. static long _vq_lengthlist__44u8_p9_2[] = {
  137498. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137499. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137500. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137501. 7,
  137502. };
  137503. static float _vq_quantthresh__44u8_p9_2[] = {
  137504. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137505. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137506. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137507. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137508. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137509. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137510. };
  137511. static long _vq_quantmap__44u8_p9_2[] = {
  137512. 47, 45, 43, 41, 39, 37, 35, 33,
  137513. 31, 29, 27, 25, 23, 21, 19, 17,
  137514. 15, 13, 11, 9, 7, 5, 3, 1,
  137515. 0, 2, 4, 6, 8, 10, 12, 14,
  137516. 16, 18, 20, 22, 24, 26, 28, 30,
  137517. 32, 34, 36, 38, 40, 42, 44, 46,
  137518. 48,
  137519. };
  137520. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137521. _vq_quantthresh__44u8_p9_2,
  137522. _vq_quantmap__44u8_p9_2,
  137523. 49,
  137524. 49
  137525. };
  137526. static static_codebook _44u8_p9_2 = {
  137527. 1, 49,
  137528. _vq_lengthlist__44u8_p9_2,
  137529. 1, -526909440, 1611661312, 6, 0,
  137530. _vq_quantlist__44u8_p9_2,
  137531. NULL,
  137532. &_vq_auxt__44u8_p9_2,
  137533. NULL,
  137534. 0
  137535. };
  137536. static long _huff_lengthlist__44u9__long[] = {
  137537. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137538. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137539. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137540. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137541. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137542. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137543. 10, 8, 8, 9,
  137544. };
  137545. static static_codebook _huff_book__44u9__long = {
  137546. 2, 100,
  137547. _huff_lengthlist__44u9__long,
  137548. 0, 0, 0, 0, 0,
  137549. NULL,
  137550. NULL,
  137551. NULL,
  137552. NULL,
  137553. 0
  137554. };
  137555. static long _huff_lengthlist__44u9__short[] = {
  137556. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137557. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137558. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137559. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137560. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137561. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137562. 9, 9,12,15,
  137563. };
  137564. static static_codebook _huff_book__44u9__short = {
  137565. 2, 100,
  137566. _huff_lengthlist__44u9__short,
  137567. 0, 0, 0, 0, 0,
  137568. NULL,
  137569. NULL,
  137570. NULL,
  137571. NULL,
  137572. 0
  137573. };
  137574. static long _vq_quantlist__44u9_p1_0[] = {
  137575. 1,
  137576. 0,
  137577. 2,
  137578. };
  137579. static long _vq_lengthlist__44u9_p1_0[] = {
  137580. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137581. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137582. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137583. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137584. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137585. 10,
  137586. };
  137587. static float _vq_quantthresh__44u9_p1_0[] = {
  137588. -0.5, 0.5,
  137589. };
  137590. static long _vq_quantmap__44u9_p1_0[] = {
  137591. 1, 0, 2,
  137592. };
  137593. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137594. _vq_quantthresh__44u9_p1_0,
  137595. _vq_quantmap__44u9_p1_0,
  137596. 3,
  137597. 3
  137598. };
  137599. static static_codebook _44u9_p1_0 = {
  137600. 4, 81,
  137601. _vq_lengthlist__44u9_p1_0,
  137602. 1, -535822336, 1611661312, 2, 0,
  137603. _vq_quantlist__44u9_p1_0,
  137604. NULL,
  137605. &_vq_auxt__44u9_p1_0,
  137606. NULL,
  137607. 0
  137608. };
  137609. static long _vq_quantlist__44u9_p2_0[] = {
  137610. 2,
  137611. 1,
  137612. 3,
  137613. 0,
  137614. 4,
  137615. };
  137616. static long _vq_lengthlist__44u9_p2_0[] = {
  137617. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137618. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137619. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137620. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137621. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137622. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137623. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137624. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137625. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137626. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137627. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137628. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137629. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137630. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137631. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137632. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137633. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137634. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137635. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137636. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137637. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137638. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137639. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137640. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137641. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137642. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137643. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137644. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137645. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137646. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137647. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137648. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137649. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137650. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137651. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137652. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137653. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137654. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137655. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137656. 14,
  137657. };
  137658. static float _vq_quantthresh__44u9_p2_0[] = {
  137659. -1.5, -0.5, 0.5, 1.5,
  137660. };
  137661. static long _vq_quantmap__44u9_p2_0[] = {
  137662. 3, 1, 0, 2, 4,
  137663. };
  137664. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137665. _vq_quantthresh__44u9_p2_0,
  137666. _vq_quantmap__44u9_p2_0,
  137667. 5,
  137668. 5
  137669. };
  137670. static static_codebook _44u9_p2_0 = {
  137671. 4, 625,
  137672. _vq_lengthlist__44u9_p2_0,
  137673. 1, -533725184, 1611661312, 3, 0,
  137674. _vq_quantlist__44u9_p2_0,
  137675. NULL,
  137676. &_vq_auxt__44u9_p2_0,
  137677. NULL,
  137678. 0
  137679. };
  137680. static long _vq_quantlist__44u9_p3_0[] = {
  137681. 4,
  137682. 3,
  137683. 5,
  137684. 2,
  137685. 6,
  137686. 1,
  137687. 7,
  137688. 0,
  137689. 8,
  137690. };
  137691. static long _vq_lengthlist__44u9_p3_0[] = {
  137692. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137693. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137694. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137695. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137696. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137697. 11,
  137698. };
  137699. static float _vq_quantthresh__44u9_p3_0[] = {
  137700. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137701. };
  137702. static long _vq_quantmap__44u9_p3_0[] = {
  137703. 7, 5, 3, 1, 0, 2, 4, 6,
  137704. 8,
  137705. };
  137706. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137707. _vq_quantthresh__44u9_p3_0,
  137708. _vq_quantmap__44u9_p3_0,
  137709. 9,
  137710. 9
  137711. };
  137712. static static_codebook _44u9_p3_0 = {
  137713. 2, 81,
  137714. _vq_lengthlist__44u9_p3_0,
  137715. 1, -531628032, 1611661312, 4, 0,
  137716. _vq_quantlist__44u9_p3_0,
  137717. NULL,
  137718. &_vq_auxt__44u9_p3_0,
  137719. NULL,
  137720. 0
  137721. };
  137722. static long _vq_quantlist__44u9_p4_0[] = {
  137723. 8,
  137724. 7,
  137725. 9,
  137726. 6,
  137727. 10,
  137728. 5,
  137729. 11,
  137730. 4,
  137731. 12,
  137732. 3,
  137733. 13,
  137734. 2,
  137735. 14,
  137736. 1,
  137737. 15,
  137738. 0,
  137739. 16,
  137740. };
  137741. static long _vq_lengthlist__44u9_p4_0[] = {
  137742. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137743. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137744. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137745. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137746. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137747. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137748. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137749. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137750. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137751. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137752. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137753. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137754. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137755. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137756. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137757. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137758. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137759. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137760. 14,
  137761. };
  137762. static float _vq_quantthresh__44u9_p4_0[] = {
  137763. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137764. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137765. };
  137766. static long _vq_quantmap__44u9_p4_0[] = {
  137767. 15, 13, 11, 9, 7, 5, 3, 1,
  137768. 0, 2, 4, 6, 8, 10, 12, 14,
  137769. 16,
  137770. };
  137771. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137772. _vq_quantthresh__44u9_p4_0,
  137773. _vq_quantmap__44u9_p4_0,
  137774. 17,
  137775. 17
  137776. };
  137777. static static_codebook _44u9_p4_0 = {
  137778. 2, 289,
  137779. _vq_lengthlist__44u9_p4_0,
  137780. 1, -529530880, 1611661312, 5, 0,
  137781. _vq_quantlist__44u9_p4_0,
  137782. NULL,
  137783. &_vq_auxt__44u9_p4_0,
  137784. NULL,
  137785. 0
  137786. };
  137787. static long _vq_quantlist__44u9_p5_0[] = {
  137788. 1,
  137789. 0,
  137790. 2,
  137791. };
  137792. static long _vq_lengthlist__44u9_p5_0[] = {
  137793. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137794. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137795. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137796. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137797. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137798. 10,
  137799. };
  137800. static float _vq_quantthresh__44u9_p5_0[] = {
  137801. -5.5, 5.5,
  137802. };
  137803. static long _vq_quantmap__44u9_p5_0[] = {
  137804. 1, 0, 2,
  137805. };
  137806. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137807. _vq_quantthresh__44u9_p5_0,
  137808. _vq_quantmap__44u9_p5_0,
  137809. 3,
  137810. 3
  137811. };
  137812. static static_codebook _44u9_p5_0 = {
  137813. 4, 81,
  137814. _vq_lengthlist__44u9_p5_0,
  137815. 1, -529137664, 1618345984, 2, 0,
  137816. _vq_quantlist__44u9_p5_0,
  137817. NULL,
  137818. &_vq_auxt__44u9_p5_0,
  137819. NULL,
  137820. 0
  137821. };
  137822. static long _vq_quantlist__44u9_p5_1[] = {
  137823. 5,
  137824. 4,
  137825. 6,
  137826. 3,
  137827. 7,
  137828. 2,
  137829. 8,
  137830. 1,
  137831. 9,
  137832. 0,
  137833. 10,
  137834. };
  137835. static long _vq_lengthlist__44u9_p5_1[] = {
  137836. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137837. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137838. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137839. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137840. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137841. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137842. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137843. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137844. };
  137845. static float _vq_quantthresh__44u9_p5_1[] = {
  137846. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137847. 3.5, 4.5,
  137848. };
  137849. static long _vq_quantmap__44u9_p5_1[] = {
  137850. 9, 7, 5, 3, 1, 0, 2, 4,
  137851. 6, 8, 10,
  137852. };
  137853. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137854. _vq_quantthresh__44u9_p5_1,
  137855. _vq_quantmap__44u9_p5_1,
  137856. 11,
  137857. 11
  137858. };
  137859. static static_codebook _44u9_p5_1 = {
  137860. 2, 121,
  137861. _vq_lengthlist__44u9_p5_1,
  137862. 1, -531365888, 1611661312, 4, 0,
  137863. _vq_quantlist__44u9_p5_1,
  137864. NULL,
  137865. &_vq_auxt__44u9_p5_1,
  137866. NULL,
  137867. 0
  137868. };
  137869. static long _vq_quantlist__44u9_p6_0[] = {
  137870. 6,
  137871. 5,
  137872. 7,
  137873. 4,
  137874. 8,
  137875. 3,
  137876. 9,
  137877. 2,
  137878. 10,
  137879. 1,
  137880. 11,
  137881. 0,
  137882. 12,
  137883. };
  137884. static long _vq_lengthlist__44u9_p6_0[] = {
  137885. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137886. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137887. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137888. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137889. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137890. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137891. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137892. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137893. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137894. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137895. 10,11,11,11,11,12,11,12,12,
  137896. };
  137897. static float _vq_quantthresh__44u9_p6_0[] = {
  137898. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137899. 12.5, 17.5, 22.5, 27.5,
  137900. };
  137901. static long _vq_quantmap__44u9_p6_0[] = {
  137902. 11, 9, 7, 5, 3, 1, 0, 2,
  137903. 4, 6, 8, 10, 12,
  137904. };
  137905. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137906. _vq_quantthresh__44u9_p6_0,
  137907. _vq_quantmap__44u9_p6_0,
  137908. 13,
  137909. 13
  137910. };
  137911. static static_codebook _44u9_p6_0 = {
  137912. 2, 169,
  137913. _vq_lengthlist__44u9_p6_0,
  137914. 1, -526516224, 1616117760, 4, 0,
  137915. _vq_quantlist__44u9_p6_0,
  137916. NULL,
  137917. &_vq_auxt__44u9_p6_0,
  137918. NULL,
  137919. 0
  137920. };
  137921. static long _vq_quantlist__44u9_p6_1[] = {
  137922. 2,
  137923. 1,
  137924. 3,
  137925. 0,
  137926. 4,
  137927. };
  137928. static long _vq_lengthlist__44u9_p6_1[] = {
  137929. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137930. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137931. };
  137932. static float _vq_quantthresh__44u9_p6_1[] = {
  137933. -1.5, -0.5, 0.5, 1.5,
  137934. };
  137935. static long _vq_quantmap__44u9_p6_1[] = {
  137936. 3, 1, 0, 2, 4,
  137937. };
  137938. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137939. _vq_quantthresh__44u9_p6_1,
  137940. _vq_quantmap__44u9_p6_1,
  137941. 5,
  137942. 5
  137943. };
  137944. static static_codebook _44u9_p6_1 = {
  137945. 2, 25,
  137946. _vq_lengthlist__44u9_p6_1,
  137947. 1, -533725184, 1611661312, 3, 0,
  137948. _vq_quantlist__44u9_p6_1,
  137949. NULL,
  137950. &_vq_auxt__44u9_p6_1,
  137951. NULL,
  137952. 0
  137953. };
  137954. static long _vq_quantlist__44u9_p7_0[] = {
  137955. 6,
  137956. 5,
  137957. 7,
  137958. 4,
  137959. 8,
  137960. 3,
  137961. 9,
  137962. 2,
  137963. 10,
  137964. 1,
  137965. 11,
  137966. 0,
  137967. 12,
  137968. };
  137969. static long _vq_lengthlist__44u9_p7_0[] = {
  137970. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137971. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137972. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137973. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137974. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137975. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137976. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137977. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137978. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137979. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137980. 12,13,13,14,14,14,15,15,15,
  137981. };
  137982. static float _vq_quantthresh__44u9_p7_0[] = {
  137983. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137984. 27.5, 38.5, 49.5, 60.5,
  137985. };
  137986. static long _vq_quantmap__44u9_p7_0[] = {
  137987. 11, 9, 7, 5, 3, 1, 0, 2,
  137988. 4, 6, 8, 10, 12,
  137989. };
  137990. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137991. _vq_quantthresh__44u9_p7_0,
  137992. _vq_quantmap__44u9_p7_0,
  137993. 13,
  137994. 13
  137995. };
  137996. static static_codebook _44u9_p7_0 = {
  137997. 2, 169,
  137998. _vq_lengthlist__44u9_p7_0,
  137999. 1, -523206656, 1618345984, 4, 0,
  138000. _vq_quantlist__44u9_p7_0,
  138001. NULL,
  138002. &_vq_auxt__44u9_p7_0,
  138003. NULL,
  138004. 0
  138005. };
  138006. static long _vq_quantlist__44u9_p7_1[] = {
  138007. 5,
  138008. 4,
  138009. 6,
  138010. 3,
  138011. 7,
  138012. 2,
  138013. 8,
  138014. 1,
  138015. 9,
  138016. 0,
  138017. 10,
  138018. };
  138019. static long _vq_lengthlist__44u9_p7_1[] = {
  138020. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  138021. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  138022. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  138023. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138024. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138025. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138026. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  138027. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  138028. };
  138029. static float _vq_quantthresh__44u9_p7_1[] = {
  138030. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  138031. 3.5, 4.5,
  138032. };
  138033. static long _vq_quantmap__44u9_p7_1[] = {
  138034. 9, 7, 5, 3, 1, 0, 2, 4,
  138035. 6, 8, 10,
  138036. };
  138037. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  138038. _vq_quantthresh__44u9_p7_1,
  138039. _vq_quantmap__44u9_p7_1,
  138040. 11,
  138041. 11
  138042. };
  138043. static static_codebook _44u9_p7_1 = {
  138044. 2, 121,
  138045. _vq_lengthlist__44u9_p7_1,
  138046. 1, -531365888, 1611661312, 4, 0,
  138047. _vq_quantlist__44u9_p7_1,
  138048. NULL,
  138049. &_vq_auxt__44u9_p7_1,
  138050. NULL,
  138051. 0
  138052. };
  138053. static long _vq_quantlist__44u9_p8_0[] = {
  138054. 7,
  138055. 6,
  138056. 8,
  138057. 5,
  138058. 9,
  138059. 4,
  138060. 10,
  138061. 3,
  138062. 11,
  138063. 2,
  138064. 12,
  138065. 1,
  138066. 13,
  138067. 0,
  138068. 14,
  138069. };
  138070. static long _vq_lengthlist__44u9_p8_0[] = {
  138071. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  138072. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  138073. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  138074. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  138075. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  138076. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  138077. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  138078. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  138079. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  138080. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  138081. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  138082. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  138083. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  138084. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  138085. 15,
  138086. };
  138087. static float _vq_quantthresh__44u9_p8_0[] = {
  138088. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  138089. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  138090. };
  138091. static long _vq_quantmap__44u9_p8_0[] = {
  138092. 13, 11, 9, 7, 5, 3, 1, 0,
  138093. 2, 4, 6, 8, 10, 12, 14,
  138094. };
  138095. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  138096. _vq_quantthresh__44u9_p8_0,
  138097. _vq_quantmap__44u9_p8_0,
  138098. 15,
  138099. 15
  138100. };
  138101. static static_codebook _44u9_p8_0 = {
  138102. 2, 225,
  138103. _vq_lengthlist__44u9_p8_0,
  138104. 1, -520986624, 1620377600, 4, 0,
  138105. _vq_quantlist__44u9_p8_0,
  138106. NULL,
  138107. &_vq_auxt__44u9_p8_0,
  138108. NULL,
  138109. 0
  138110. };
  138111. static long _vq_quantlist__44u9_p8_1[] = {
  138112. 10,
  138113. 9,
  138114. 11,
  138115. 8,
  138116. 12,
  138117. 7,
  138118. 13,
  138119. 6,
  138120. 14,
  138121. 5,
  138122. 15,
  138123. 4,
  138124. 16,
  138125. 3,
  138126. 17,
  138127. 2,
  138128. 18,
  138129. 1,
  138130. 19,
  138131. 0,
  138132. 20,
  138133. };
  138134. static long _vq_lengthlist__44u9_p8_1[] = {
  138135. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  138136. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138137. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  138138. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  138139. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  138140. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  138141. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  138142. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  138143. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138144. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138145. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  138146. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  138147. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138148. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  138149. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138150. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  138151. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138152. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138153. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  138154. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  138155. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138156. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  138157. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  138158. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  138159. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  138160. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  138161. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138162. 10,10,10,10,10,10,10,10,10,
  138163. };
  138164. static float _vq_quantthresh__44u9_p8_1[] = {
  138165. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  138166. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  138167. 6.5, 7.5, 8.5, 9.5,
  138168. };
  138169. static long _vq_quantmap__44u9_p8_1[] = {
  138170. 19, 17, 15, 13, 11, 9, 7, 5,
  138171. 3, 1, 0, 2, 4, 6, 8, 10,
  138172. 12, 14, 16, 18, 20,
  138173. };
  138174. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  138175. _vq_quantthresh__44u9_p8_1,
  138176. _vq_quantmap__44u9_p8_1,
  138177. 21,
  138178. 21
  138179. };
  138180. static static_codebook _44u9_p8_1 = {
  138181. 2, 441,
  138182. _vq_lengthlist__44u9_p8_1,
  138183. 1, -529268736, 1611661312, 5, 0,
  138184. _vq_quantlist__44u9_p8_1,
  138185. NULL,
  138186. &_vq_auxt__44u9_p8_1,
  138187. NULL,
  138188. 0
  138189. };
  138190. static long _vq_quantlist__44u9_p9_0[] = {
  138191. 7,
  138192. 6,
  138193. 8,
  138194. 5,
  138195. 9,
  138196. 4,
  138197. 10,
  138198. 3,
  138199. 11,
  138200. 2,
  138201. 12,
  138202. 1,
  138203. 13,
  138204. 0,
  138205. 14,
  138206. };
  138207. static long _vq_lengthlist__44u9_p9_0[] = {
  138208. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  138209. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  138210. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138211. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138212. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138213. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138214. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138215. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138216. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138217. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138218. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138219. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138220. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138221. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138222. 10,
  138223. };
  138224. static float _vq_quantthresh__44u9_p9_0[] = {
  138225. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  138226. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  138227. };
  138228. static long _vq_quantmap__44u9_p9_0[] = {
  138229. 13, 11, 9, 7, 5, 3, 1, 0,
  138230. 2, 4, 6, 8, 10, 12, 14,
  138231. };
  138232. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  138233. _vq_quantthresh__44u9_p9_0,
  138234. _vq_quantmap__44u9_p9_0,
  138235. 15,
  138236. 15
  138237. };
  138238. static static_codebook _44u9_p9_0 = {
  138239. 2, 225,
  138240. _vq_lengthlist__44u9_p9_0,
  138241. 1, -510036736, 1631393792, 4, 0,
  138242. _vq_quantlist__44u9_p9_0,
  138243. NULL,
  138244. &_vq_auxt__44u9_p9_0,
  138245. NULL,
  138246. 0
  138247. };
  138248. static long _vq_quantlist__44u9_p9_1[] = {
  138249. 9,
  138250. 8,
  138251. 10,
  138252. 7,
  138253. 11,
  138254. 6,
  138255. 12,
  138256. 5,
  138257. 13,
  138258. 4,
  138259. 14,
  138260. 3,
  138261. 15,
  138262. 2,
  138263. 16,
  138264. 1,
  138265. 17,
  138266. 0,
  138267. 18,
  138268. };
  138269. static long _vq_lengthlist__44u9_p9_1[] = {
  138270. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  138271. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  138272. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  138273. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  138274. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  138275. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  138276. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  138277. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  138278. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  138279. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  138280. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  138281. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  138282. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  138283. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  138284. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138285. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138286. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138287. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138288. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138289. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138290. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138291. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138292. 17,17,15,17,15,17,16,16,17,
  138293. };
  138294. static float _vq_quantthresh__44u9_p9_1[] = {
  138295. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138296. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138297. 367.5, 416.5,
  138298. };
  138299. static long _vq_quantmap__44u9_p9_1[] = {
  138300. 17, 15, 13, 11, 9, 7, 5, 3,
  138301. 1, 0, 2, 4, 6, 8, 10, 12,
  138302. 14, 16, 18,
  138303. };
  138304. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138305. _vq_quantthresh__44u9_p9_1,
  138306. _vq_quantmap__44u9_p9_1,
  138307. 19,
  138308. 19
  138309. };
  138310. static static_codebook _44u9_p9_1 = {
  138311. 2, 361,
  138312. _vq_lengthlist__44u9_p9_1,
  138313. 1, -518287360, 1622704128, 5, 0,
  138314. _vq_quantlist__44u9_p9_1,
  138315. NULL,
  138316. &_vq_auxt__44u9_p9_1,
  138317. NULL,
  138318. 0
  138319. };
  138320. static long _vq_quantlist__44u9_p9_2[] = {
  138321. 24,
  138322. 23,
  138323. 25,
  138324. 22,
  138325. 26,
  138326. 21,
  138327. 27,
  138328. 20,
  138329. 28,
  138330. 19,
  138331. 29,
  138332. 18,
  138333. 30,
  138334. 17,
  138335. 31,
  138336. 16,
  138337. 32,
  138338. 15,
  138339. 33,
  138340. 14,
  138341. 34,
  138342. 13,
  138343. 35,
  138344. 12,
  138345. 36,
  138346. 11,
  138347. 37,
  138348. 10,
  138349. 38,
  138350. 9,
  138351. 39,
  138352. 8,
  138353. 40,
  138354. 7,
  138355. 41,
  138356. 6,
  138357. 42,
  138358. 5,
  138359. 43,
  138360. 4,
  138361. 44,
  138362. 3,
  138363. 45,
  138364. 2,
  138365. 46,
  138366. 1,
  138367. 47,
  138368. 0,
  138369. 48,
  138370. };
  138371. static long _vq_lengthlist__44u9_p9_2[] = {
  138372. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138373. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138374. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138375. 7,
  138376. };
  138377. static float _vq_quantthresh__44u9_p9_2[] = {
  138378. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138379. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138380. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138381. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138382. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138383. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138384. };
  138385. static long _vq_quantmap__44u9_p9_2[] = {
  138386. 47, 45, 43, 41, 39, 37, 35, 33,
  138387. 31, 29, 27, 25, 23, 21, 19, 17,
  138388. 15, 13, 11, 9, 7, 5, 3, 1,
  138389. 0, 2, 4, 6, 8, 10, 12, 14,
  138390. 16, 18, 20, 22, 24, 26, 28, 30,
  138391. 32, 34, 36, 38, 40, 42, 44, 46,
  138392. 48,
  138393. };
  138394. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138395. _vq_quantthresh__44u9_p9_2,
  138396. _vq_quantmap__44u9_p9_2,
  138397. 49,
  138398. 49
  138399. };
  138400. static static_codebook _44u9_p9_2 = {
  138401. 1, 49,
  138402. _vq_lengthlist__44u9_p9_2,
  138403. 1, -526909440, 1611661312, 6, 0,
  138404. _vq_quantlist__44u9_p9_2,
  138405. NULL,
  138406. &_vq_auxt__44u9_p9_2,
  138407. NULL,
  138408. 0
  138409. };
  138410. static long _huff_lengthlist__44un1__long[] = {
  138411. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138412. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138413. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138414. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138415. };
  138416. static static_codebook _huff_book__44un1__long = {
  138417. 2, 64,
  138418. _huff_lengthlist__44un1__long,
  138419. 0, 0, 0, 0, 0,
  138420. NULL,
  138421. NULL,
  138422. NULL,
  138423. NULL,
  138424. 0
  138425. };
  138426. static long _vq_quantlist__44un1__p1_0[] = {
  138427. 1,
  138428. 0,
  138429. 2,
  138430. };
  138431. static long _vq_lengthlist__44un1__p1_0[] = {
  138432. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138433. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138434. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138435. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138436. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138437. 12,
  138438. };
  138439. static float _vq_quantthresh__44un1__p1_0[] = {
  138440. -0.5, 0.5,
  138441. };
  138442. static long _vq_quantmap__44un1__p1_0[] = {
  138443. 1, 0, 2,
  138444. };
  138445. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138446. _vq_quantthresh__44un1__p1_0,
  138447. _vq_quantmap__44un1__p1_0,
  138448. 3,
  138449. 3
  138450. };
  138451. static static_codebook _44un1__p1_0 = {
  138452. 4, 81,
  138453. _vq_lengthlist__44un1__p1_0,
  138454. 1, -535822336, 1611661312, 2, 0,
  138455. _vq_quantlist__44un1__p1_0,
  138456. NULL,
  138457. &_vq_auxt__44un1__p1_0,
  138458. NULL,
  138459. 0
  138460. };
  138461. static long _vq_quantlist__44un1__p2_0[] = {
  138462. 1,
  138463. 0,
  138464. 2,
  138465. };
  138466. static long _vq_lengthlist__44un1__p2_0[] = {
  138467. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138468. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138469. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138470. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138471. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138472. 8,
  138473. };
  138474. static float _vq_quantthresh__44un1__p2_0[] = {
  138475. -0.5, 0.5,
  138476. };
  138477. static long _vq_quantmap__44un1__p2_0[] = {
  138478. 1, 0, 2,
  138479. };
  138480. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138481. _vq_quantthresh__44un1__p2_0,
  138482. _vq_quantmap__44un1__p2_0,
  138483. 3,
  138484. 3
  138485. };
  138486. static static_codebook _44un1__p2_0 = {
  138487. 4, 81,
  138488. _vq_lengthlist__44un1__p2_0,
  138489. 1, -535822336, 1611661312, 2, 0,
  138490. _vq_quantlist__44un1__p2_0,
  138491. NULL,
  138492. &_vq_auxt__44un1__p2_0,
  138493. NULL,
  138494. 0
  138495. };
  138496. static long _vq_quantlist__44un1__p3_0[] = {
  138497. 2,
  138498. 1,
  138499. 3,
  138500. 0,
  138501. 4,
  138502. };
  138503. static long _vq_lengthlist__44un1__p3_0[] = {
  138504. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138505. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138506. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138507. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138508. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138509. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138510. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138511. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138512. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138513. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138514. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138515. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138516. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138517. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138518. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138519. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138520. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138521. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138522. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138523. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138524. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138525. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138526. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138527. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138528. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138529. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138530. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138531. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138532. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138533. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138534. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138535. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138536. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138537. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138538. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138539. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138540. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138541. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138542. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138543. 17,
  138544. };
  138545. static float _vq_quantthresh__44un1__p3_0[] = {
  138546. -1.5, -0.5, 0.5, 1.5,
  138547. };
  138548. static long _vq_quantmap__44un1__p3_0[] = {
  138549. 3, 1, 0, 2, 4,
  138550. };
  138551. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138552. _vq_quantthresh__44un1__p3_0,
  138553. _vq_quantmap__44un1__p3_0,
  138554. 5,
  138555. 5
  138556. };
  138557. static static_codebook _44un1__p3_0 = {
  138558. 4, 625,
  138559. _vq_lengthlist__44un1__p3_0,
  138560. 1, -533725184, 1611661312, 3, 0,
  138561. _vq_quantlist__44un1__p3_0,
  138562. NULL,
  138563. &_vq_auxt__44un1__p3_0,
  138564. NULL,
  138565. 0
  138566. };
  138567. static long _vq_quantlist__44un1__p4_0[] = {
  138568. 2,
  138569. 1,
  138570. 3,
  138571. 0,
  138572. 4,
  138573. };
  138574. static long _vq_lengthlist__44un1__p4_0[] = {
  138575. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138576. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138577. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138578. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138579. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138580. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138581. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138582. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138583. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138584. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138585. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138586. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138587. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138588. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138589. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138590. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138591. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138592. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138593. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138594. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138595. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138596. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138597. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138598. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138599. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138600. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138601. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138602. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138603. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138604. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138605. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138606. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138607. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138608. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138609. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138610. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138611. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138612. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138613. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138614. 12,
  138615. };
  138616. static float _vq_quantthresh__44un1__p4_0[] = {
  138617. -1.5, -0.5, 0.5, 1.5,
  138618. };
  138619. static long _vq_quantmap__44un1__p4_0[] = {
  138620. 3, 1, 0, 2, 4,
  138621. };
  138622. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138623. _vq_quantthresh__44un1__p4_0,
  138624. _vq_quantmap__44un1__p4_0,
  138625. 5,
  138626. 5
  138627. };
  138628. static static_codebook _44un1__p4_0 = {
  138629. 4, 625,
  138630. _vq_lengthlist__44un1__p4_0,
  138631. 1, -533725184, 1611661312, 3, 0,
  138632. _vq_quantlist__44un1__p4_0,
  138633. NULL,
  138634. &_vq_auxt__44un1__p4_0,
  138635. NULL,
  138636. 0
  138637. };
  138638. static long _vq_quantlist__44un1__p5_0[] = {
  138639. 4,
  138640. 3,
  138641. 5,
  138642. 2,
  138643. 6,
  138644. 1,
  138645. 7,
  138646. 0,
  138647. 8,
  138648. };
  138649. static long _vq_lengthlist__44un1__p5_0[] = {
  138650. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138651. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138652. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138653. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138654. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138655. 12,
  138656. };
  138657. static float _vq_quantthresh__44un1__p5_0[] = {
  138658. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138659. };
  138660. static long _vq_quantmap__44un1__p5_0[] = {
  138661. 7, 5, 3, 1, 0, 2, 4, 6,
  138662. 8,
  138663. };
  138664. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138665. _vq_quantthresh__44un1__p5_0,
  138666. _vq_quantmap__44un1__p5_0,
  138667. 9,
  138668. 9
  138669. };
  138670. static static_codebook _44un1__p5_0 = {
  138671. 2, 81,
  138672. _vq_lengthlist__44un1__p5_0,
  138673. 1, -531628032, 1611661312, 4, 0,
  138674. _vq_quantlist__44un1__p5_0,
  138675. NULL,
  138676. &_vq_auxt__44un1__p5_0,
  138677. NULL,
  138678. 0
  138679. };
  138680. static long _vq_quantlist__44un1__p6_0[] = {
  138681. 6,
  138682. 5,
  138683. 7,
  138684. 4,
  138685. 8,
  138686. 3,
  138687. 9,
  138688. 2,
  138689. 10,
  138690. 1,
  138691. 11,
  138692. 0,
  138693. 12,
  138694. };
  138695. static long _vq_lengthlist__44un1__p6_0[] = {
  138696. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138697. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138698. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138699. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138700. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138701. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138702. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138703. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138704. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138705. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138706. 16, 0,15,18,18, 0,16, 0, 0,
  138707. };
  138708. static float _vq_quantthresh__44un1__p6_0[] = {
  138709. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138710. 12.5, 17.5, 22.5, 27.5,
  138711. };
  138712. static long _vq_quantmap__44un1__p6_0[] = {
  138713. 11, 9, 7, 5, 3, 1, 0, 2,
  138714. 4, 6, 8, 10, 12,
  138715. };
  138716. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138717. _vq_quantthresh__44un1__p6_0,
  138718. _vq_quantmap__44un1__p6_0,
  138719. 13,
  138720. 13
  138721. };
  138722. static static_codebook _44un1__p6_0 = {
  138723. 2, 169,
  138724. _vq_lengthlist__44un1__p6_0,
  138725. 1, -526516224, 1616117760, 4, 0,
  138726. _vq_quantlist__44un1__p6_0,
  138727. NULL,
  138728. &_vq_auxt__44un1__p6_0,
  138729. NULL,
  138730. 0
  138731. };
  138732. static long _vq_quantlist__44un1__p6_1[] = {
  138733. 2,
  138734. 1,
  138735. 3,
  138736. 0,
  138737. 4,
  138738. };
  138739. static long _vq_lengthlist__44un1__p6_1[] = {
  138740. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138741. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138742. };
  138743. static float _vq_quantthresh__44un1__p6_1[] = {
  138744. -1.5, -0.5, 0.5, 1.5,
  138745. };
  138746. static long _vq_quantmap__44un1__p6_1[] = {
  138747. 3, 1, 0, 2, 4,
  138748. };
  138749. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138750. _vq_quantthresh__44un1__p6_1,
  138751. _vq_quantmap__44un1__p6_1,
  138752. 5,
  138753. 5
  138754. };
  138755. static static_codebook _44un1__p6_1 = {
  138756. 2, 25,
  138757. _vq_lengthlist__44un1__p6_1,
  138758. 1, -533725184, 1611661312, 3, 0,
  138759. _vq_quantlist__44un1__p6_1,
  138760. NULL,
  138761. &_vq_auxt__44un1__p6_1,
  138762. NULL,
  138763. 0
  138764. };
  138765. static long _vq_quantlist__44un1__p7_0[] = {
  138766. 2,
  138767. 1,
  138768. 3,
  138769. 0,
  138770. 4,
  138771. };
  138772. static long _vq_lengthlist__44un1__p7_0[] = {
  138773. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138774. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138775. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138776. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138777. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138778. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138779. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138780. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138781. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138782. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138783. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138784. 11,11,11,11,11,11,11,11,11,11,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,11,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, 7,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,10,11,11,11,11,11,11,11,11,11,11,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,11,
  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,11,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,11,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. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138810. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138811. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138812. 10,
  138813. };
  138814. static float _vq_quantthresh__44un1__p7_0[] = {
  138815. -253.5, -84.5, 84.5, 253.5,
  138816. };
  138817. static long _vq_quantmap__44un1__p7_0[] = {
  138818. 3, 1, 0, 2, 4,
  138819. };
  138820. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138821. _vq_quantthresh__44un1__p7_0,
  138822. _vq_quantmap__44un1__p7_0,
  138823. 5,
  138824. 5
  138825. };
  138826. static static_codebook _44un1__p7_0 = {
  138827. 4, 625,
  138828. _vq_lengthlist__44un1__p7_0,
  138829. 1, -518709248, 1626677248, 3, 0,
  138830. _vq_quantlist__44un1__p7_0,
  138831. NULL,
  138832. &_vq_auxt__44un1__p7_0,
  138833. NULL,
  138834. 0
  138835. };
  138836. static long _vq_quantlist__44un1__p7_1[] = {
  138837. 6,
  138838. 5,
  138839. 7,
  138840. 4,
  138841. 8,
  138842. 3,
  138843. 9,
  138844. 2,
  138845. 10,
  138846. 1,
  138847. 11,
  138848. 0,
  138849. 12,
  138850. };
  138851. static long _vq_lengthlist__44un1__p7_1[] = {
  138852. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138853. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138854. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138855. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138856. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138857. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138858. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138859. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138860. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138861. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138862. 12,13,13,12,13,13,14,14,14,
  138863. };
  138864. static float _vq_quantthresh__44un1__p7_1[] = {
  138865. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138866. 32.5, 45.5, 58.5, 71.5,
  138867. };
  138868. static long _vq_quantmap__44un1__p7_1[] = {
  138869. 11, 9, 7, 5, 3, 1, 0, 2,
  138870. 4, 6, 8, 10, 12,
  138871. };
  138872. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138873. _vq_quantthresh__44un1__p7_1,
  138874. _vq_quantmap__44un1__p7_1,
  138875. 13,
  138876. 13
  138877. };
  138878. static static_codebook _44un1__p7_1 = {
  138879. 2, 169,
  138880. _vq_lengthlist__44un1__p7_1,
  138881. 1, -523010048, 1618608128, 4, 0,
  138882. _vq_quantlist__44un1__p7_1,
  138883. NULL,
  138884. &_vq_auxt__44un1__p7_1,
  138885. NULL,
  138886. 0
  138887. };
  138888. static long _vq_quantlist__44un1__p7_2[] = {
  138889. 6,
  138890. 5,
  138891. 7,
  138892. 4,
  138893. 8,
  138894. 3,
  138895. 9,
  138896. 2,
  138897. 10,
  138898. 1,
  138899. 11,
  138900. 0,
  138901. 12,
  138902. };
  138903. static long _vq_lengthlist__44un1__p7_2[] = {
  138904. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138905. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138906. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138907. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138908. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138909. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138910. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138911. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138912. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138913. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138914. 9, 9, 9,10,10,10,10,10,10,
  138915. };
  138916. static float _vq_quantthresh__44un1__p7_2[] = {
  138917. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138918. 2.5, 3.5, 4.5, 5.5,
  138919. };
  138920. static long _vq_quantmap__44un1__p7_2[] = {
  138921. 11, 9, 7, 5, 3, 1, 0, 2,
  138922. 4, 6, 8, 10, 12,
  138923. };
  138924. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138925. _vq_quantthresh__44un1__p7_2,
  138926. _vq_quantmap__44un1__p7_2,
  138927. 13,
  138928. 13
  138929. };
  138930. static static_codebook _44un1__p7_2 = {
  138931. 2, 169,
  138932. _vq_lengthlist__44un1__p7_2,
  138933. 1, -531103744, 1611661312, 4, 0,
  138934. _vq_quantlist__44un1__p7_2,
  138935. NULL,
  138936. &_vq_auxt__44un1__p7_2,
  138937. NULL,
  138938. 0
  138939. };
  138940. static long _huff_lengthlist__44un1__short[] = {
  138941. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138942. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138943. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138944. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138945. };
  138946. static static_codebook _huff_book__44un1__short = {
  138947. 2, 64,
  138948. _huff_lengthlist__44un1__short,
  138949. 0, 0, 0, 0, 0,
  138950. NULL,
  138951. NULL,
  138952. NULL,
  138953. NULL,
  138954. 0
  138955. };
  138956. /*** End of inlined file: res_books_uncoupled.h ***/
  138957. static vorbis_info_residue0 _residue_44_low_un={
  138958. 0,-1, -1, 8,-1,
  138959. {0},
  138960. {-1},
  138961. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138962. { -1, 25, -1, 45, -1, -1, -1}
  138963. };
  138964. static vorbis_info_residue0 _residue_44_mid_un={
  138965. 0,-1, -1, 10,-1,
  138966. {0},
  138967. {-1},
  138968. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138969. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138970. };
  138971. static vorbis_info_residue0 _residue_44_hi_un={
  138972. 0,-1, -1, 10,-1,
  138973. {0},
  138974. {-1},
  138975. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138976. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138977. };
  138978. static vorbis_info_mapping0 _map_nominal_u[2]={
  138979. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138980. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138981. };
  138982. static static_bookblock _resbook_44u_n1={
  138983. {
  138984. {0},
  138985. {0,0,&_44un1__p1_0},
  138986. {0,0,&_44un1__p2_0},
  138987. {0,0,&_44un1__p3_0},
  138988. {0,0,&_44un1__p4_0},
  138989. {0,0,&_44un1__p5_0},
  138990. {&_44un1__p6_0,&_44un1__p6_1},
  138991. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138992. }
  138993. };
  138994. static static_bookblock _resbook_44u_0={
  138995. {
  138996. {0},
  138997. {0,0,&_44u0__p1_0},
  138998. {0,0,&_44u0__p2_0},
  138999. {0,0,&_44u0__p3_0},
  139000. {0,0,&_44u0__p4_0},
  139001. {0,0,&_44u0__p5_0},
  139002. {&_44u0__p6_0,&_44u0__p6_1},
  139003. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  139004. }
  139005. };
  139006. static static_bookblock _resbook_44u_1={
  139007. {
  139008. {0},
  139009. {0,0,&_44u1__p1_0},
  139010. {0,0,&_44u1__p2_0},
  139011. {0,0,&_44u1__p3_0},
  139012. {0,0,&_44u1__p4_0},
  139013. {0,0,&_44u1__p5_0},
  139014. {&_44u1__p6_0,&_44u1__p6_1},
  139015. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  139016. }
  139017. };
  139018. static static_bookblock _resbook_44u_2={
  139019. {
  139020. {0},
  139021. {0,0,&_44u2__p1_0},
  139022. {0,0,&_44u2__p2_0},
  139023. {0,0,&_44u2__p3_0},
  139024. {0,0,&_44u2__p4_0},
  139025. {0,0,&_44u2__p5_0},
  139026. {&_44u2__p6_0,&_44u2__p6_1},
  139027. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  139028. }
  139029. };
  139030. static static_bookblock _resbook_44u_3={
  139031. {
  139032. {0},
  139033. {0,0,&_44u3__p1_0},
  139034. {0,0,&_44u3__p2_0},
  139035. {0,0,&_44u3__p3_0},
  139036. {0,0,&_44u3__p4_0},
  139037. {0,0,&_44u3__p5_0},
  139038. {&_44u3__p6_0,&_44u3__p6_1},
  139039. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  139040. }
  139041. };
  139042. static static_bookblock _resbook_44u_4={
  139043. {
  139044. {0},
  139045. {0,0,&_44u4__p1_0},
  139046. {0,0,&_44u4__p2_0},
  139047. {0,0,&_44u4__p3_0},
  139048. {0,0,&_44u4__p4_0},
  139049. {0,0,&_44u4__p5_0},
  139050. {&_44u4__p6_0,&_44u4__p6_1},
  139051. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  139052. }
  139053. };
  139054. static static_bookblock _resbook_44u_5={
  139055. {
  139056. {0},
  139057. {0,0,&_44u5__p1_0},
  139058. {0,0,&_44u5__p2_0},
  139059. {0,0,&_44u5__p3_0},
  139060. {0,0,&_44u5__p4_0},
  139061. {0,0,&_44u5__p5_0},
  139062. {0,0,&_44u5__p6_0},
  139063. {&_44u5__p7_0,&_44u5__p7_1},
  139064. {&_44u5__p8_0,&_44u5__p8_1},
  139065. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  139066. }
  139067. };
  139068. static static_bookblock _resbook_44u_6={
  139069. {
  139070. {0},
  139071. {0,0,&_44u6__p1_0},
  139072. {0,0,&_44u6__p2_0},
  139073. {0,0,&_44u6__p3_0},
  139074. {0,0,&_44u6__p4_0},
  139075. {0,0,&_44u6__p5_0},
  139076. {0,0,&_44u6__p6_0},
  139077. {&_44u6__p7_0,&_44u6__p7_1},
  139078. {&_44u6__p8_0,&_44u6__p8_1},
  139079. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  139080. }
  139081. };
  139082. static static_bookblock _resbook_44u_7={
  139083. {
  139084. {0},
  139085. {0,0,&_44u7__p1_0},
  139086. {0,0,&_44u7__p2_0},
  139087. {0,0,&_44u7__p3_0},
  139088. {0,0,&_44u7__p4_0},
  139089. {0,0,&_44u7__p5_0},
  139090. {0,0,&_44u7__p6_0},
  139091. {&_44u7__p7_0,&_44u7__p7_1},
  139092. {&_44u7__p8_0,&_44u7__p8_1},
  139093. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  139094. }
  139095. };
  139096. static static_bookblock _resbook_44u_8={
  139097. {
  139098. {0},
  139099. {0,0,&_44u8_p1_0},
  139100. {0,0,&_44u8_p2_0},
  139101. {0,0,&_44u8_p3_0},
  139102. {0,0,&_44u8_p4_0},
  139103. {&_44u8_p5_0,&_44u8_p5_1},
  139104. {&_44u8_p6_0,&_44u8_p6_1},
  139105. {&_44u8_p7_0,&_44u8_p7_1},
  139106. {&_44u8_p8_0,&_44u8_p8_1},
  139107. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  139108. }
  139109. };
  139110. static static_bookblock _resbook_44u_9={
  139111. {
  139112. {0},
  139113. {0,0,&_44u9_p1_0},
  139114. {0,0,&_44u9_p2_0},
  139115. {0,0,&_44u9_p3_0},
  139116. {0,0,&_44u9_p4_0},
  139117. {&_44u9_p5_0,&_44u9_p5_1},
  139118. {&_44u9_p6_0,&_44u9_p6_1},
  139119. {&_44u9_p7_0,&_44u9_p7_1},
  139120. {&_44u9_p8_0,&_44u9_p8_1},
  139121. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  139122. }
  139123. };
  139124. static vorbis_residue_template _res_44u_n1[]={
  139125. {1,0, &_residue_44_low_un,
  139126. &_huff_book__44un1__short,&_huff_book__44un1__short,
  139127. &_resbook_44u_n1,&_resbook_44u_n1},
  139128. {1,0, &_residue_44_low_un,
  139129. &_huff_book__44un1__long,&_huff_book__44un1__long,
  139130. &_resbook_44u_n1,&_resbook_44u_n1}
  139131. };
  139132. static vorbis_residue_template _res_44u_0[]={
  139133. {1,0, &_residue_44_low_un,
  139134. &_huff_book__44u0__short,&_huff_book__44u0__short,
  139135. &_resbook_44u_0,&_resbook_44u_0},
  139136. {1,0, &_residue_44_low_un,
  139137. &_huff_book__44u0__long,&_huff_book__44u0__long,
  139138. &_resbook_44u_0,&_resbook_44u_0}
  139139. };
  139140. static vorbis_residue_template _res_44u_1[]={
  139141. {1,0, &_residue_44_low_un,
  139142. &_huff_book__44u1__short,&_huff_book__44u1__short,
  139143. &_resbook_44u_1,&_resbook_44u_1},
  139144. {1,0, &_residue_44_low_un,
  139145. &_huff_book__44u1__long,&_huff_book__44u1__long,
  139146. &_resbook_44u_1,&_resbook_44u_1}
  139147. };
  139148. static vorbis_residue_template _res_44u_2[]={
  139149. {1,0, &_residue_44_low_un,
  139150. &_huff_book__44u2__short,&_huff_book__44u2__short,
  139151. &_resbook_44u_2,&_resbook_44u_2},
  139152. {1,0, &_residue_44_low_un,
  139153. &_huff_book__44u2__long,&_huff_book__44u2__long,
  139154. &_resbook_44u_2,&_resbook_44u_2}
  139155. };
  139156. static vorbis_residue_template _res_44u_3[]={
  139157. {1,0, &_residue_44_low_un,
  139158. &_huff_book__44u3__short,&_huff_book__44u3__short,
  139159. &_resbook_44u_3,&_resbook_44u_3},
  139160. {1,0, &_residue_44_low_un,
  139161. &_huff_book__44u3__long,&_huff_book__44u3__long,
  139162. &_resbook_44u_3,&_resbook_44u_3}
  139163. };
  139164. static vorbis_residue_template _res_44u_4[]={
  139165. {1,0, &_residue_44_low_un,
  139166. &_huff_book__44u4__short,&_huff_book__44u4__short,
  139167. &_resbook_44u_4,&_resbook_44u_4},
  139168. {1,0, &_residue_44_low_un,
  139169. &_huff_book__44u4__long,&_huff_book__44u4__long,
  139170. &_resbook_44u_4,&_resbook_44u_4}
  139171. };
  139172. static vorbis_residue_template _res_44u_5[]={
  139173. {1,0, &_residue_44_mid_un,
  139174. &_huff_book__44u5__short,&_huff_book__44u5__short,
  139175. &_resbook_44u_5,&_resbook_44u_5},
  139176. {1,0, &_residue_44_mid_un,
  139177. &_huff_book__44u5__long,&_huff_book__44u5__long,
  139178. &_resbook_44u_5,&_resbook_44u_5}
  139179. };
  139180. static vorbis_residue_template _res_44u_6[]={
  139181. {1,0, &_residue_44_mid_un,
  139182. &_huff_book__44u6__short,&_huff_book__44u6__short,
  139183. &_resbook_44u_6,&_resbook_44u_6},
  139184. {1,0, &_residue_44_mid_un,
  139185. &_huff_book__44u6__long,&_huff_book__44u6__long,
  139186. &_resbook_44u_6,&_resbook_44u_6}
  139187. };
  139188. static vorbis_residue_template _res_44u_7[]={
  139189. {1,0, &_residue_44_mid_un,
  139190. &_huff_book__44u7__short,&_huff_book__44u7__short,
  139191. &_resbook_44u_7,&_resbook_44u_7},
  139192. {1,0, &_residue_44_mid_un,
  139193. &_huff_book__44u7__long,&_huff_book__44u7__long,
  139194. &_resbook_44u_7,&_resbook_44u_7}
  139195. };
  139196. static vorbis_residue_template _res_44u_8[]={
  139197. {1,0, &_residue_44_hi_un,
  139198. &_huff_book__44u8__short,&_huff_book__44u8__short,
  139199. &_resbook_44u_8,&_resbook_44u_8},
  139200. {1,0, &_residue_44_hi_un,
  139201. &_huff_book__44u8__long,&_huff_book__44u8__long,
  139202. &_resbook_44u_8,&_resbook_44u_8}
  139203. };
  139204. static vorbis_residue_template _res_44u_9[]={
  139205. {1,0, &_residue_44_hi_un,
  139206. &_huff_book__44u9__short,&_huff_book__44u9__short,
  139207. &_resbook_44u_9,&_resbook_44u_9},
  139208. {1,0, &_residue_44_hi_un,
  139209. &_huff_book__44u9__long,&_huff_book__44u9__long,
  139210. &_resbook_44u_9,&_resbook_44u_9}
  139211. };
  139212. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  139213. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  139214. { _map_nominal_u, _res_44u_0 }, /* 0 */
  139215. { _map_nominal_u, _res_44u_1 }, /* 1 */
  139216. { _map_nominal_u, _res_44u_2 }, /* 2 */
  139217. { _map_nominal_u, _res_44u_3 }, /* 3 */
  139218. { _map_nominal_u, _res_44u_4 }, /* 4 */
  139219. { _map_nominal_u, _res_44u_5 }, /* 5 */
  139220. { _map_nominal_u, _res_44u_6 }, /* 6 */
  139221. { _map_nominal_u, _res_44u_7 }, /* 7 */
  139222. { _map_nominal_u, _res_44u_8 }, /* 8 */
  139223. { _map_nominal_u, _res_44u_9 }, /* 9 */
  139224. };
  139225. /*** End of inlined file: residue_44u.h ***/
  139226. static double rate_mapping_44_un[12]={
  139227. 32000.,48000.,60000.,70000.,80000.,86000.,
  139228. 96000.,110000.,120000.,140000.,160000.,240001.
  139229. };
  139230. ve_setup_data_template ve_setup_44_uncoupled={
  139231. 11,
  139232. rate_mapping_44_un,
  139233. quality_mapping_44,
  139234. -1,
  139235. 40000,
  139236. 50000,
  139237. blocksize_short_44,
  139238. blocksize_long_44,
  139239. _psy_tone_masteratt_44,
  139240. _psy_tone_0dB,
  139241. _psy_tone_suppress,
  139242. _vp_tonemask_adj_otherblock,
  139243. _vp_tonemask_adj_longblock,
  139244. _vp_tonemask_adj_otherblock,
  139245. _psy_noiseguards_44,
  139246. _psy_noisebias_impulse,
  139247. _psy_noisebias_padding,
  139248. _psy_noisebias_trans,
  139249. _psy_noisebias_long,
  139250. _psy_noise_suppress,
  139251. _psy_compand_44,
  139252. _psy_compand_short_mapping,
  139253. _psy_compand_long_mapping,
  139254. {_noise_start_short_44,_noise_start_long_44},
  139255. {_noise_part_short_44,_noise_part_long_44},
  139256. _noise_thresh_44,
  139257. _psy_ath_floater,
  139258. _psy_ath_abs,
  139259. _psy_lowpass_44,
  139260. _psy_global_44,
  139261. _global_mapping_44,
  139262. NULL,
  139263. _floor_books,
  139264. _floor,
  139265. _floor_short_mapping_44,
  139266. _floor_long_mapping_44,
  139267. _mapres_template_44_uncoupled
  139268. };
  139269. /*** End of inlined file: setup_44u.h ***/
  139270. /*** Start of inlined file: setup_32.h ***/
  139271. static double rate_mapping_32[12]={
  139272. 18000.,28000.,35000.,45000.,56000.,60000.,
  139273. 75000.,90000.,100000.,115000.,150000.,190000.,
  139274. };
  139275. static double rate_mapping_32_un[12]={
  139276. 30000.,42000.,52000.,64000.,72000.,78000.,
  139277. 86000.,92000.,110000.,120000.,140000.,190000.,
  139278. };
  139279. static double _psy_lowpass_32[12]={
  139280. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  139281. };
  139282. ve_setup_data_template ve_setup_32_stereo={
  139283. 11,
  139284. rate_mapping_32,
  139285. quality_mapping_44,
  139286. 2,
  139287. 26000,
  139288. 40000,
  139289. blocksize_short_44,
  139290. blocksize_long_44,
  139291. _psy_tone_masteratt_44,
  139292. _psy_tone_0dB,
  139293. _psy_tone_suppress,
  139294. _vp_tonemask_adj_otherblock,
  139295. _vp_tonemask_adj_longblock,
  139296. _vp_tonemask_adj_otherblock,
  139297. _psy_noiseguards_44,
  139298. _psy_noisebias_impulse,
  139299. _psy_noisebias_padding,
  139300. _psy_noisebias_trans,
  139301. _psy_noisebias_long,
  139302. _psy_noise_suppress,
  139303. _psy_compand_44,
  139304. _psy_compand_short_mapping,
  139305. _psy_compand_long_mapping,
  139306. {_noise_start_short_44,_noise_start_long_44},
  139307. {_noise_part_short_44,_noise_part_long_44},
  139308. _noise_thresh_44,
  139309. _psy_ath_floater,
  139310. _psy_ath_abs,
  139311. _psy_lowpass_32,
  139312. _psy_global_44,
  139313. _global_mapping_44,
  139314. _psy_stereo_modes_44,
  139315. _floor_books,
  139316. _floor,
  139317. _floor_short_mapping_44,
  139318. _floor_long_mapping_44,
  139319. _mapres_template_44_stereo
  139320. };
  139321. ve_setup_data_template ve_setup_32_uncoupled={
  139322. 11,
  139323. rate_mapping_32_un,
  139324. quality_mapping_44,
  139325. -1,
  139326. 26000,
  139327. 40000,
  139328. blocksize_short_44,
  139329. blocksize_long_44,
  139330. _psy_tone_masteratt_44,
  139331. _psy_tone_0dB,
  139332. _psy_tone_suppress,
  139333. _vp_tonemask_adj_otherblock,
  139334. _vp_tonemask_adj_longblock,
  139335. _vp_tonemask_adj_otherblock,
  139336. _psy_noiseguards_44,
  139337. _psy_noisebias_impulse,
  139338. _psy_noisebias_padding,
  139339. _psy_noisebias_trans,
  139340. _psy_noisebias_long,
  139341. _psy_noise_suppress,
  139342. _psy_compand_44,
  139343. _psy_compand_short_mapping,
  139344. _psy_compand_long_mapping,
  139345. {_noise_start_short_44,_noise_start_long_44},
  139346. {_noise_part_short_44,_noise_part_long_44},
  139347. _noise_thresh_44,
  139348. _psy_ath_floater,
  139349. _psy_ath_abs,
  139350. _psy_lowpass_32,
  139351. _psy_global_44,
  139352. _global_mapping_44,
  139353. NULL,
  139354. _floor_books,
  139355. _floor,
  139356. _floor_short_mapping_44,
  139357. _floor_long_mapping_44,
  139358. _mapres_template_44_uncoupled
  139359. };
  139360. /*** End of inlined file: setup_32.h ***/
  139361. /*** Start of inlined file: setup_8.h ***/
  139362. /*** Start of inlined file: psych_8.h ***/
  139363. static att3 _psy_tone_masteratt_8[3]={
  139364. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139365. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139366. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139367. };
  139368. static vp_adjblock _vp_tonemask_adj_8[3]={
  139369. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139370. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139371. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139372. };
  139373. static noise3 _psy_noisebias_8[3]={
  139374. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139375. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139376. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139377. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139378. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139379. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139380. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139381. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139382. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139383. };
  139384. static adj_stereo _psy_stereo_modes_8[3]={
  139385. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139386. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139387. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139388. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139389. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139390. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139391. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139392. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139393. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139394. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139395. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139396. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139397. };
  139398. static noiseguard _psy_noiseguards_8[2]={
  139399. {10,10,-1},
  139400. {10,10,-1},
  139401. };
  139402. static compandblock _psy_compand_8[2]={
  139403. {{
  139404. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139405. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139406. 12,12,13,13,14,14,15, 15, /* 23dB */
  139407. 16,16,17,17,17,18,18, 19, /* 31dB */
  139408. 19,19,20,21,22,23,24, 25, /* 39dB */
  139409. }},
  139410. {{
  139411. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139412. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139413. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139414. 9,10,11,12,13,14,15, 16, /* 31dB */
  139415. 17,18,19,20,21,22,23, 24, /* 39dB */
  139416. }},
  139417. };
  139418. static double _psy_lowpass_8[3]={3.,4.,4.};
  139419. static int _noise_start_8[2]={
  139420. 64,64,
  139421. };
  139422. static int _noise_part_8[2]={
  139423. 8,8,
  139424. };
  139425. static int _psy_ath_floater_8[3]={
  139426. -100,-100,-105,
  139427. };
  139428. static int _psy_ath_abs_8[3]={
  139429. -130,-130,-140,
  139430. };
  139431. /*** End of inlined file: psych_8.h ***/
  139432. /*** Start of inlined file: residue_8.h ***/
  139433. static static_bookblock _resbook_8s_0={
  139434. {
  139435. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139436. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139437. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139438. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139439. }
  139440. };
  139441. static static_bookblock _resbook_8s_1={
  139442. {
  139443. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139444. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139445. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139446. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139447. }
  139448. };
  139449. static vorbis_residue_template _res_8s_0[]={
  139450. {2,0, &_residue_44_mid,
  139451. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139452. &_resbook_8s_0,&_resbook_8s_0},
  139453. };
  139454. static vorbis_residue_template _res_8s_1[]={
  139455. {2,0, &_residue_44_mid,
  139456. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139457. &_resbook_8s_1,&_resbook_8s_1},
  139458. };
  139459. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139460. { _map_nominal, _res_8s_0 }, /* 0 */
  139461. { _map_nominal, _res_8s_1 }, /* 1 */
  139462. };
  139463. static static_bookblock _resbook_8u_0={
  139464. {
  139465. {0},
  139466. {0,0,&_8u0__p1_0},
  139467. {0,0,&_8u0__p2_0},
  139468. {0,0,&_8u0__p3_0},
  139469. {0,0,&_8u0__p4_0},
  139470. {0,0,&_8u0__p5_0},
  139471. {&_8u0__p6_0,&_8u0__p6_1},
  139472. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139473. }
  139474. };
  139475. static static_bookblock _resbook_8u_1={
  139476. {
  139477. {0},
  139478. {0,0,&_8u1__p1_0},
  139479. {0,0,&_8u1__p2_0},
  139480. {0,0,&_8u1__p3_0},
  139481. {0,0,&_8u1__p4_0},
  139482. {0,0,&_8u1__p5_0},
  139483. {0,0,&_8u1__p6_0},
  139484. {&_8u1__p7_0,&_8u1__p7_1},
  139485. {&_8u1__p8_0,&_8u1__p8_1},
  139486. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139487. }
  139488. };
  139489. static vorbis_residue_template _res_8u_0[]={
  139490. {1,0, &_residue_44_low_un,
  139491. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139492. &_resbook_8u_0,&_resbook_8u_0},
  139493. };
  139494. static vorbis_residue_template _res_8u_1[]={
  139495. {1,0, &_residue_44_mid_un,
  139496. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139497. &_resbook_8u_1,&_resbook_8u_1},
  139498. };
  139499. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139500. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139501. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139502. };
  139503. /*** End of inlined file: residue_8.h ***/
  139504. static int blocksize_8[2]={
  139505. 512,512
  139506. };
  139507. static int _floor_mapping_8[2]={
  139508. 6,6,
  139509. };
  139510. static double rate_mapping_8[3]={
  139511. 6000.,9000.,32000.,
  139512. };
  139513. static double rate_mapping_8_uncoupled[3]={
  139514. 8000.,14000.,42000.,
  139515. };
  139516. static double quality_mapping_8[3]={
  139517. -.1,.0,1.
  139518. };
  139519. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139520. static double _global_mapping_8[3]={ 1., 2., 3. };
  139521. ve_setup_data_template ve_setup_8_stereo={
  139522. 2,
  139523. rate_mapping_8,
  139524. quality_mapping_8,
  139525. 2,
  139526. 8000,
  139527. 9000,
  139528. blocksize_8,
  139529. blocksize_8,
  139530. _psy_tone_masteratt_8,
  139531. _psy_tone_0dB,
  139532. _psy_tone_suppress,
  139533. _vp_tonemask_adj_8,
  139534. NULL,
  139535. _vp_tonemask_adj_8,
  139536. _psy_noiseguards_8,
  139537. _psy_noisebias_8,
  139538. _psy_noisebias_8,
  139539. NULL,
  139540. NULL,
  139541. _psy_noise_suppress,
  139542. _psy_compand_8,
  139543. _psy_compand_8_mapping,
  139544. NULL,
  139545. {_noise_start_8,_noise_start_8},
  139546. {_noise_part_8,_noise_part_8},
  139547. _noise_thresh_5only,
  139548. _psy_ath_floater_8,
  139549. _psy_ath_abs_8,
  139550. _psy_lowpass_8,
  139551. _psy_global_44,
  139552. _global_mapping_8,
  139553. _psy_stereo_modes_8,
  139554. _floor_books,
  139555. _floor,
  139556. _floor_mapping_8,
  139557. NULL,
  139558. _mapres_template_8_stereo
  139559. };
  139560. ve_setup_data_template ve_setup_8_uncoupled={
  139561. 2,
  139562. rate_mapping_8_uncoupled,
  139563. quality_mapping_8,
  139564. -1,
  139565. 8000,
  139566. 9000,
  139567. blocksize_8,
  139568. blocksize_8,
  139569. _psy_tone_masteratt_8,
  139570. _psy_tone_0dB,
  139571. _psy_tone_suppress,
  139572. _vp_tonemask_adj_8,
  139573. NULL,
  139574. _vp_tonemask_adj_8,
  139575. _psy_noiseguards_8,
  139576. _psy_noisebias_8,
  139577. _psy_noisebias_8,
  139578. NULL,
  139579. NULL,
  139580. _psy_noise_suppress,
  139581. _psy_compand_8,
  139582. _psy_compand_8_mapping,
  139583. NULL,
  139584. {_noise_start_8,_noise_start_8},
  139585. {_noise_part_8,_noise_part_8},
  139586. _noise_thresh_5only,
  139587. _psy_ath_floater_8,
  139588. _psy_ath_abs_8,
  139589. _psy_lowpass_8,
  139590. _psy_global_44,
  139591. _global_mapping_8,
  139592. _psy_stereo_modes_8,
  139593. _floor_books,
  139594. _floor,
  139595. _floor_mapping_8,
  139596. NULL,
  139597. _mapres_template_8_uncoupled
  139598. };
  139599. /*** End of inlined file: setup_8.h ***/
  139600. /*** Start of inlined file: setup_11.h ***/
  139601. /*** Start of inlined file: psych_11.h ***/
  139602. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139603. static att3 _psy_tone_masteratt_11[3]={
  139604. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139605. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139606. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139607. };
  139608. static vp_adjblock _vp_tonemask_adj_11[3]={
  139609. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139610. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139611. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139612. };
  139613. static noise3 _psy_noisebias_11[3]={
  139614. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139615. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139616. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139617. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139618. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139619. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139620. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139621. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139622. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139623. };
  139624. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139625. /*** End of inlined file: psych_11.h ***/
  139626. static int blocksize_11[2]={
  139627. 512,512
  139628. };
  139629. static int _floor_mapping_11[2]={
  139630. 6,6,
  139631. };
  139632. static double rate_mapping_11[3]={
  139633. 8000.,13000.,44000.,
  139634. };
  139635. static double rate_mapping_11_uncoupled[3]={
  139636. 12000.,20000.,50000.,
  139637. };
  139638. static double quality_mapping_11[3]={
  139639. -.1,.0,1.
  139640. };
  139641. ve_setup_data_template ve_setup_11_stereo={
  139642. 2,
  139643. rate_mapping_11,
  139644. quality_mapping_11,
  139645. 2,
  139646. 9000,
  139647. 15000,
  139648. blocksize_11,
  139649. blocksize_11,
  139650. _psy_tone_masteratt_11,
  139651. _psy_tone_0dB,
  139652. _psy_tone_suppress,
  139653. _vp_tonemask_adj_11,
  139654. NULL,
  139655. _vp_tonemask_adj_11,
  139656. _psy_noiseguards_8,
  139657. _psy_noisebias_11,
  139658. _psy_noisebias_11,
  139659. NULL,
  139660. NULL,
  139661. _psy_noise_suppress,
  139662. _psy_compand_8,
  139663. _psy_compand_8_mapping,
  139664. NULL,
  139665. {_noise_start_8,_noise_start_8},
  139666. {_noise_part_8,_noise_part_8},
  139667. _noise_thresh_11,
  139668. _psy_ath_floater_8,
  139669. _psy_ath_abs_8,
  139670. _psy_lowpass_11,
  139671. _psy_global_44,
  139672. _global_mapping_8,
  139673. _psy_stereo_modes_8,
  139674. _floor_books,
  139675. _floor,
  139676. _floor_mapping_11,
  139677. NULL,
  139678. _mapres_template_8_stereo
  139679. };
  139680. ve_setup_data_template ve_setup_11_uncoupled={
  139681. 2,
  139682. rate_mapping_11_uncoupled,
  139683. quality_mapping_11,
  139684. -1,
  139685. 9000,
  139686. 15000,
  139687. blocksize_11,
  139688. blocksize_11,
  139689. _psy_tone_masteratt_11,
  139690. _psy_tone_0dB,
  139691. _psy_tone_suppress,
  139692. _vp_tonemask_adj_11,
  139693. NULL,
  139694. _vp_tonemask_adj_11,
  139695. _psy_noiseguards_8,
  139696. _psy_noisebias_11,
  139697. _psy_noisebias_11,
  139698. NULL,
  139699. NULL,
  139700. _psy_noise_suppress,
  139701. _psy_compand_8,
  139702. _psy_compand_8_mapping,
  139703. NULL,
  139704. {_noise_start_8,_noise_start_8},
  139705. {_noise_part_8,_noise_part_8},
  139706. _noise_thresh_11,
  139707. _psy_ath_floater_8,
  139708. _psy_ath_abs_8,
  139709. _psy_lowpass_11,
  139710. _psy_global_44,
  139711. _global_mapping_8,
  139712. _psy_stereo_modes_8,
  139713. _floor_books,
  139714. _floor,
  139715. _floor_mapping_11,
  139716. NULL,
  139717. _mapres_template_8_uncoupled
  139718. };
  139719. /*** End of inlined file: setup_11.h ***/
  139720. /*** Start of inlined file: setup_16.h ***/
  139721. /*** Start of inlined file: psych_16.h ***/
  139722. static adj_stereo _psy_stereo_modes_16[4]={
  139723. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139724. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139725. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139726. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139727. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139728. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139729. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139730. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139731. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139732. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139733. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139734. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139735. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139736. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139737. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139738. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139739. };
  139740. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139741. static att3 _psy_tone_masteratt_16[4]={
  139742. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139743. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139744. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139745. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139746. };
  139747. static vp_adjblock _vp_tonemask_adj_16[4]={
  139748. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139749. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139750. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139751. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139752. };
  139753. static noise3 _psy_noisebias_16_short[4]={
  139754. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139755. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139756. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139757. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139758. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139759. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139760. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139761. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139762. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139763. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139764. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139765. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139766. };
  139767. static noise3 _psy_noisebias_16_impulse[4]={
  139768. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139769. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139770. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139771. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139772. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139773. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139774. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139775. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139776. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139777. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139778. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139779. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139780. };
  139781. static noise3 _psy_noisebias_16[4]={
  139782. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139783. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139784. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139785. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139786. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139787. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139788. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139789. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139790. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139791. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139792. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139793. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139794. };
  139795. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139796. static int _noise_start_16[3]={ 256,256,9999 };
  139797. static int _noise_part_16[4]={ 8,8,8,8 };
  139798. static int _psy_ath_floater_16[4]={
  139799. -100,-100,-100,-105,
  139800. };
  139801. static int _psy_ath_abs_16[4]={
  139802. -130,-130,-130,-140,
  139803. };
  139804. /*** End of inlined file: psych_16.h ***/
  139805. /*** Start of inlined file: residue_16.h ***/
  139806. static static_bookblock _resbook_16s_0={
  139807. {
  139808. {0},
  139809. {0,0,&_16c0_s_p1_0},
  139810. {0,0,&_16c0_s_p2_0},
  139811. {0,0,&_16c0_s_p3_0},
  139812. {0,0,&_16c0_s_p4_0},
  139813. {0,0,&_16c0_s_p5_0},
  139814. {0,0,&_16c0_s_p6_0},
  139815. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139816. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139817. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139818. }
  139819. };
  139820. static static_bookblock _resbook_16s_1={
  139821. {
  139822. {0},
  139823. {0,0,&_16c1_s_p1_0},
  139824. {0,0,&_16c1_s_p2_0},
  139825. {0,0,&_16c1_s_p3_0},
  139826. {0,0,&_16c1_s_p4_0},
  139827. {0,0,&_16c1_s_p5_0},
  139828. {0,0,&_16c1_s_p6_0},
  139829. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139830. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139831. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139832. }
  139833. };
  139834. static static_bookblock _resbook_16s_2={
  139835. {
  139836. {0},
  139837. {0,0,&_16c2_s_p1_0},
  139838. {0,0,&_16c2_s_p2_0},
  139839. {0,0,&_16c2_s_p3_0},
  139840. {0,0,&_16c2_s_p4_0},
  139841. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139842. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139843. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139844. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139845. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139846. }
  139847. };
  139848. static vorbis_residue_template _res_16s_0[]={
  139849. {2,0, &_residue_44_mid,
  139850. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139851. &_resbook_16s_0,&_resbook_16s_0},
  139852. };
  139853. static vorbis_residue_template _res_16s_1[]={
  139854. {2,0, &_residue_44_mid,
  139855. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139856. &_resbook_16s_1,&_resbook_16s_1},
  139857. {2,0, &_residue_44_mid,
  139858. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139859. &_resbook_16s_1,&_resbook_16s_1}
  139860. };
  139861. static vorbis_residue_template _res_16s_2[]={
  139862. {2,0, &_residue_44_high,
  139863. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139864. &_resbook_16s_2,&_resbook_16s_2},
  139865. {2,0, &_residue_44_high,
  139866. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139867. &_resbook_16s_2,&_resbook_16s_2}
  139868. };
  139869. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139870. { _map_nominal, _res_16s_0 }, /* 0 */
  139871. { _map_nominal, _res_16s_1 }, /* 1 */
  139872. { _map_nominal, _res_16s_2 }, /* 2 */
  139873. };
  139874. static static_bookblock _resbook_16u_0={
  139875. {
  139876. {0},
  139877. {0,0,&_16u0__p1_0},
  139878. {0,0,&_16u0__p2_0},
  139879. {0,0,&_16u0__p3_0},
  139880. {0,0,&_16u0__p4_0},
  139881. {0,0,&_16u0__p5_0},
  139882. {&_16u0__p6_0,&_16u0__p6_1},
  139883. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139884. }
  139885. };
  139886. static static_bookblock _resbook_16u_1={
  139887. {
  139888. {0},
  139889. {0,0,&_16u1__p1_0},
  139890. {0,0,&_16u1__p2_0},
  139891. {0,0,&_16u1__p3_0},
  139892. {0,0,&_16u1__p4_0},
  139893. {0,0,&_16u1__p5_0},
  139894. {0,0,&_16u1__p6_0},
  139895. {&_16u1__p7_0,&_16u1__p7_1},
  139896. {&_16u1__p8_0,&_16u1__p8_1},
  139897. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139898. }
  139899. };
  139900. static static_bookblock _resbook_16u_2={
  139901. {
  139902. {0},
  139903. {0,0,&_16u2_p1_0},
  139904. {0,0,&_16u2_p2_0},
  139905. {0,0,&_16u2_p3_0},
  139906. {0,0,&_16u2_p4_0},
  139907. {&_16u2_p5_0,&_16u2_p5_1},
  139908. {&_16u2_p6_0,&_16u2_p6_1},
  139909. {&_16u2_p7_0,&_16u2_p7_1},
  139910. {&_16u2_p8_0,&_16u2_p8_1},
  139911. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139912. }
  139913. };
  139914. static vorbis_residue_template _res_16u_0[]={
  139915. {1,0, &_residue_44_low_un,
  139916. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139917. &_resbook_16u_0,&_resbook_16u_0},
  139918. };
  139919. static vorbis_residue_template _res_16u_1[]={
  139920. {1,0, &_residue_44_mid_un,
  139921. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139922. &_resbook_16u_1,&_resbook_16u_1},
  139923. {1,0, &_residue_44_mid_un,
  139924. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139925. &_resbook_16u_1,&_resbook_16u_1}
  139926. };
  139927. static vorbis_residue_template _res_16u_2[]={
  139928. {1,0, &_residue_44_hi_un,
  139929. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139930. &_resbook_16u_2,&_resbook_16u_2},
  139931. {1,0, &_residue_44_hi_un,
  139932. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139933. &_resbook_16u_2,&_resbook_16u_2}
  139934. };
  139935. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139936. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139937. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139938. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139939. };
  139940. /*** End of inlined file: residue_16.h ***/
  139941. static int blocksize_16_short[3]={
  139942. 1024,512,512
  139943. };
  139944. static int blocksize_16_long[3]={
  139945. 1024,1024,1024
  139946. };
  139947. static int _floor_mapping_16_short[3]={
  139948. 9,3,3
  139949. };
  139950. static int _floor_mapping_16[3]={
  139951. 9,9,9
  139952. };
  139953. static double rate_mapping_16[4]={
  139954. 12000.,20000.,44000.,86000.
  139955. };
  139956. static double rate_mapping_16_uncoupled[4]={
  139957. 16000.,28000.,64000.,100000.
  139958. };
  139959. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139960. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139961. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139962. ve_setup_data_template ve_setup_16_stereo={
  139963. 3,
  139964. rate_mapping_16,
  139965. quality_mapping_16,
  139966. 2,
  139967. 15000,
  139968. 19000,
  139969. blocksize_16_short,
  139970. blocksize_16_long,
  139971. _psy_tone_masteratt_16,
  139972. _psy_tone_0dB,
  139973. _psy_tone_suppress,
  139974. _vp_tonemask_adj_16,
  139975. _vp_tonemask_adj_16,
  139976. _vp_tonemask_adj_16,
  139977. _psy_noiseguards_8,
  139978. _psy_noisebias_16_impulse,
  139979. _psy_noisebias_16_short,
  139980. _psy_noisebias_16_short,
  139981. _psy_noisebias_16,
  139982. _psy_noise_suppress,
  139983. _psy_compand_8,
  139984. _psy_compand_16_mapping,
  139985. _psy_compand_16_mapping,
  139986. {_noise_start_16,_noise_start_16},
  139987. { _noise_part_16, _noise_part_16},
  139988. _noise_thresh_16,
  139989. _psy_ath_floater_16,
  139990. _psy_ath_abs_16,
  139991. _psy_lowpass_16,
  139992. _psy_global_44,
  139993. _global_mapping_16,
  139994. _psy_stereo_modes_16,
  139995. _floor_books,
  139996. _floor,
  139997. _floor_mapping_16_short,
  139998. _floor_mapping_16,
  139999. _mapres_template_16_stereo
  140000. };
  140001. ve_setup_data_template ve_setup_16_uncoupled={
  140002. 3,
  140003. rate_mapping_16_uncoupled,
  140004. quality_mapping_16,
  140005. -1,
  140006. 15000,
  140007. 19000,
  140008. blocksize_16_short,
  140009. blocksize_16_long,
  140010. _psy_tone_masteratt_16,
  140011. _psy_tone_0dB,
  140012. _psy_tone_suppress,
  140013. _vp_tonemask_adj_16,
  140014. _vp_tonemask_adj_16,
  140015. _vp_tonemask_adj_16,
  140016. _psy_noiseguards_8,
  140017. _psy_noisebias_16_impulse,
  140018. _psy_noisebias_16_short,
  140019. _psy_noisebias_16_short,
  140020. _psy_noisebias_16,
  140021. _psy_noise_suppress,
  140022. _psy_compand_8,
  140023. _psy_compand_16_mapping,
  140024. _psy_compand_16_mapping,
  140025. {_noise_start_16,_noise_start_16},
  140026. { _noise_part_16, _noise_part_16},
  140027. _noise_thresh_16,
  140028. _psy_ath_floater_16,
  140029. _psy_ath_abs_16,
  140030. _psy_lowpass_16,
  140031. _psy_global_44,
  140032. _global_mapping_16,
  140033. _psy_stereo_modes_16,
  140034. _floor_books,
  140035. _floor,
  140036. _floor_mapping_16_short,
  140037. _floor_mapping_16,
  140038. _mapres_template_16_uncoupled
  140039. };
  140040. /*** End of inlined file: setup_16.h ***/
  140041. /*** Start of inlined file: setup_22.h ***/
  140042. static double rate_mapping_22[4]={
  140043. 15000.,20000.,44000.,86000.
  140044. };
  140045. static double rate_mapping_22_uncoupled[4]={
  140046. 16000.,28000.,50000.,90000.
  140047. };
  140048. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  140049. ve_setup_data_template ve_setup_22_stereo={
  140050. 3,
  140051. rate_mapping_22,
  140052. quality_mapping_16,
  140053. 2,
  140054. 19000,
  140055. 26000,
  140056. blocksize_16_short,
  140057. blocksize_16_long,
  140058. _psy_tone_masteratt_16,
  140059. _psy_tone_0dB,
  140060. _psy_tone_suppress,
  140061. _vp_tonemask_adj_16,
  140062. _vp_tonemask_adj_16,
  140063. _vp_tonemask_adj_16,
  140064. _psy_noiseguards_8,
  140065. _psy_noisebias_16_impulse,
  140066. _psy_noisebias_16_short,
  140067. _psy_noisebias_16_short,
  140068. _psy_noisebias_16,
  140069. _psy_noise_suppress,
  140070. _psy_compand_8,
  140071. _psy_compand_8_mapping,
  140072. _psy_compand_8_mapping,
  140073. {_noise_start_16,_noise_start_16},
  140074. { _noise_part_16, _noise_part_16},
  140075. _noise_thresh_16,
  140076. _psy_ath_floater_16,
  140077. _psy_ath_abs_16,
  140078. _psy_lowpass_22,
  140079. _psy_global_44,
  140080. _global_mapping_16,
  140081. _psy_stereo_modes_16,
  140082. _floor_books,
  140083. _floor,
  140084. _floor_mapping_16_short,
  140085. _floor_mapping_16,
  140086. _mapres_template_16_stereo
  140087. };
  140088. ve_setup_data_template ve_setup_22_uncoupled={
  140089. 3,
  140090. rate_mapping_22_uncoupled,
  140091. quality_mapping_16,
  140092. -1,
  140093. 19000,
  140094. 26000,
  140095. blocksize_16_short,
  140096. blocksize_16_long,
  140097. _psy_tone_masteratt_16,
  140098. _psy_tone_0dB,
  140099. _psy_tone_suppress,
  140100. _vp_tonemask_adj_16,
  140101. _vp_tonemask_adj_16,
  140102. _vp_tonemask_adj_16,
  140103. _psy_noiseguards_8,
  140104. _psy_noisebias_16_impulse,
  140105. _psy_noisebias_16_short,
  140106. _psy_noisebias_16_short,
  140107. _psy_noisebias_16,
  140108. _psy_noise_suppress,
  140109. _psy_compand_8,
  140110. _psy_compand_8_mapping,
  140111. _psy_compand_8_mapping,
  140112. {_noise_start_16,_noise_start_16},
  140113. { _noise_part_16, _noise_part_16},
  140114. _noise_thresh_16,
  140115. _psy_ath_floater_16,
  140116. _psy_ath_abs_16,
  140117. _psy_lowpass_22,
  140118. _psy_global_44,
  140119. _global_mapping_16,
  140120. _psy_stereo_modes_16,
  140121. _floor_books,
  140122. _floor,
  140123. _floor_mapping_16_short,
  140124. _floor_mapping_16,
  140125. _mapres_template_16_uncoupled
  140126. };
  140127. /*** End of inlined file: setup_22.h ***/
  140128. /*** Start of inlined file: setup_X.h ***/
  140129. static double rate_mapping_X[12]={
  140130. -1.,-1.,-1.,-1.,-1.,-1.,
  140131. -1.,-1.,-1.,-1.,-1.,-1.
  140132. };
  140133. ve_setup_data_template ve_setup_X_stereo={
  140134. 11,
  140135. rate_mapping_X,
  140136. quality_mapping_44,
  140137. 2,
  140138. 50000,
  140139. 200000,
  140140. blocksize_short_44,
  140141. blocksize_long_44,
  140142. _psy_tone_masteratt_44,
  140143. _psy_tone_0dB,
  140144. _psy_tone_suppress,
  140145. _vp_tonemask_adj_otherblock,
  140146. _vp_tonemask_adj_longblock,
  140147. _vp_tonemask_adj_otherblock,
  140148. _psy_noiseguards_44,
  140149. _psy_noisebias_impulse,
  140150. _psy_noisebias_padding,
  140151. _psy_noisebias_trans,
  140152. _psy_noisebias_long,
  140153. _psy_noise_suppress,
  140154. _psy_compand_44,
  140155. _psy_compand_short_mapping,
  140156. _psy_compand_long_mapping,
  140157. {_noise_start_short_44,_noise_start_long_44},
  140158. {_noise_part_short_44,_noise_part_long_44},
  140159. _noise_thresh_44,
  140160. _psy_ath_floater,
  140161. _psy_ath_abs,
  140162. _psy_lowpass_44,
  140163. _psy_global_44,
  140164. _global_mapping_44,
  140165. _psy_stereo_modes_44,
  140166. _floor_books,
  140167. _floor,
  140168. _floor_short_mapping_44,
  140169. _floor_long_mapping_44,
  140170. _mapres_template_44_stereo
  140171. };
  140172. ve_setup_data_template ve_setup_X_uncoupled={
  140173. 11,
  140174. rate_mapping_X,
  140175. quality_mapping_44,
  140176. -1,
  140177. 50000,
  140178. 200000,
  140179. blocksize_short_44,
  140180. blocksize_long_44,
  140181. _psy_tone_masteratt_44,
  140182. _psy_tone_0dB,
  140183. _psy_tone_suppress,
  140184. _vp_tonemask_adj_otherblock,
  140185. _vp_tonemask_adj_longblock,
  140186. _vp_tonemask_adj_otherblock,
  140187. _psy_noiseguards_44,
  140188. _psy_noisebias_impulse,
  140189. _psy_noisebias_padding,
  140190. _psy_noisebias_trans,
  140191. _psy_noisebias_long,
  140192. _psy_noise_suppress,
  140193. _psy_compand_44,
  140194. _psy_compand_short_mapping,
  140195. _psy_compand_long_mapping,
  140196. {_noise_start_short_44,_noise_start_long_44},
  140197. {_noise_part_short_44,_noise_part_long_44},
  140198. _noise_thresh_44,
  140199. _psy_ath_floater,
  140200. _psy_ath_abs,
  140201. _psy_lowpass_44,
  140202. _psy_global_44,
  140203. _global_mapping_44,
  140204. NULL,
  140205. _floor_books,
  140206. _floor,
  140207. _floor_short_mapping_44,
  140208. _floor_long_mapping_44,
  140209. _mapres_template_44_uncoupled
  140210. };
  140211. ve_setup_data_template ve_setup_XX_stereo={
  140212. 2,
  140213. rate_mapping_X,
  140214. quality_mapping_8,
  140215. 2,
  140216. 0,
  140217. 8000,
  140218. blocksize_8,
  140219. blocksize_8,
  140220. _psy_tone_masteratt_8,
  140221. _psy_tone_0dB,
  140222. _psy_tone_suppress,
  140223. _vp_tonemask_adj_8,
  140224. NULL,
  140225. _vp_tonemask_adj_8,
  140226. _psy_noiseguards_8,
  140227. _psy_noisebias_8,
  140228. _psy_noisebias_8,
  140229. NULL,
  140230. NULL,
  140231. _psy_noise_suppress,
  140232. _psy_compand_8,
  140233. _psy_compand_8_mapping,
  140234. NULL,
  140235. {_noise_start_8,_noise_start_8},
  140236. {_noise_part_8,_noise_part_8},
  140237. _noise_thresh_5only,
  140238. _psy_ath_floater_8,
  140239. _psy_ath_abs_8,
  140240. _psy_lowpass_8,
  140241. _psy_global_44,
  140242. _global_mapping_8,
  140243. _psy_stereo_modes_8,
  140244. _floor_books,
  140245. _floor,
  140246. _floor_mapping_8,
  140247. NULL,
  140248. _mapres_template_8_stereo
  140249. };
  140250. ve_setup_data_template ve_setup_XX_uncoupled={
  140251. 2,
  140252. rate_mapping_X,
  140253. quality_mapping_8,
  140254. -1,
  140255. 0,
  140256. 8000,
  140257. blocksize_8,
  140258. blocksize_8,
  140259. _psy_tone_masteratt_8,
  140260. _psy_tone_0dB,
  140261. _psy_tone_suppress,
  140262. _vp_tonemask_adj_8,
  140263. NULL,
  140264. _vp_tonemask_adj_8,
  140265. _psy_noiseguards_8,
  140266. _psy_noisebias_8,
  140267. _psy_noisebias_8,
  140268. NULL,
  140269. NULL,
  140270. _psy_noise_suppress,
  140271. _psy_compand_8,
  140272. _psy_compand_8_mapping,
  140273. NULL,
  140274. {_noise_start_8,_noise_start_8},
  140275. {_noise_part_8,_noise_part_8},
  140276. _noise_thresh_5only,
  140277. _psy_ath_floater_8,
  140278. _psy_ath_abs_8,
  140279. _psy_lowpass_8,
  140280. _psy_global_44,
  140281. _global_mapping_8,
  140282. _psy_stereo_modes_8,
  140283. _floor_books,
  140284. _floor,
  140285. _floor_mapping_8,
  140286. NULL,
  140287. _mapres_template_8_uncoupled
  140288. };
  140289. /*** End of inlined file: setup_X.h ***/
  140290. static ve_setup_data_template *setup_list[]={
  140291. &ve_setup_44_stereo,
  140292. &ve_setup_44_uncoupled,
  140293. &ve_setup_32_stereo,
  140294. &ve_setup_32_uncoupled,
  140295. &ve_setup_22_stereo,
  140296. &ve_setup_22_uncoupled,
  140297. &ve_setup_16_stereo,
  140298. &ve_setup_16_uncoupled,
  140299. &ve_setup_11_stereo,
  140300. &ve_setup_11_uncoupled,
  140301. &ve_setup_8_stereo,
  140302. &ve_setup_8_uncoupled,
  140303. &ve_setup_X_stereo,
  140304. &ve_setup_X_uncoupled,
  140305. &ve_setup_XX_stereo,
  140306. &ve_setup_XX_uncoupled,
  140307. 0
  140308. };
  140309. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140310. if(vi && vi->codec_setup){
  140311. vi->version=0;
  140312. vi->channels=ch;
  140313. vi->rate=rate;
  140314. return(0);
  140315. }
  140316. return(OV_EINVAL);
  140317. }
  140318. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140319. static_codebook ***books,
  140320. vorbis_info_floor1 *in,
  140321. int *x){
  140322. int i,k,is=s;
  140323. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140324. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140325. memcpy(f,in+x[is],sizeof(*f));
  140326. f->n=ci->blocksizes[block]>>1;
  140327. {
  140328. int partitions=f->partitions;
  140329. int maxclass=-1;
  140330. int maxbook=-1;
  140331. for(i=0;i<partitions;i++)
  140332. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140333. for(i=0;i<=maxclass;i++){
  140334. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140335. f->class_book[i]+=ci->books;
  140336. for(k=0;k<(1<<f->class_subs[i]);k++){
  140337. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140338. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140339. }
  140340. }
  140341. for(i=0;i<=maxbook;i++)
  140342. ci->book_param[ci->books++]=books[x[is]][i];
  140343. }
  140344. ci->floor_type[ci->floors]=1;
  140345. ci->floor_param[ci->floors]=f;
  140346. ci->floors++;
  140347. return;
  140348. }
  140349. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140350. vorbis_info_psy_global *in,
  140351. double *x){
  140352. int i,is=s;
  140353. double ds=s-is;
  140354. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140355. vorbis_info_psy_global *g=&ci->psy_g_param;
  140356. memcpy(g,in+(int)x[is],sizeof(*g));
  140357. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140358. is=(int)ds;
  140359. ds-=is;
  140360. if(ds==0 && is>0){
  140361. is--;
  140362. ds=1.;
  140363. }
  140364. for(i=0;i<4;i++){
  140365. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140366. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140367. }
  140368. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140369. return;
  140370. }
  140371. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140372. highlevel_encode_setup *hi,
  140373. adj_stereo *p){
  140374. float s=hi->stereo_point_setting;
  140375. int i,is=s;
  140376. double ds=s-is;
  140377. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140378. vorbis_info_psy_global *g=&ci->psy_g_param;
  140379. if(p){
  140380. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140381. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140382. if(hi->managed){
  140383. for(i=0;i<PACKETBLOBS;i++){
  140384. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140385. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140386. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140387. g->coupling_pkHz[i]=kHz;
  140388. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140389. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140390. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140391. }
  140392. }else{
  140393. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140394. for(i=0;i<PACKETBLOBS;i++){
  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. }
  140399. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140400. for(i=0;i<PACKETBLOBS;i++){
  140401. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140402. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140403. }
  140404. }
  140405. }else{
  140406. for(i=0;i<PACKETBLOBS;i++){
  140407. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140408. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140409. }
  140410. }
  140411. return;
  140412. }
  140413. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140414. int *nn_start,
  140415. int *nn_partition,
  140416. double *nn_thresh,
  140417. int block){
  140418. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140419. vorbis_info_psy *p=ci->psy_param[block];
  140420. highlevel_encode_setup *hi=&ci->hi;
  140421. int is=s;
  140422. if(block>=ci->psys)
  140423. ci->psys=block+1;
  140424. if(!p){
  140425. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140426. ci->psy_param[block]=p;
  140427. }
  140428. memcpy(p,&_psy_info_template,sizeof(*p));
  140429. p->blockflag=block>>1;
  140430. if(hi->noise_normalize_p){
  140431. p->normal_channel_p=1;
  140432. p->normal_point_p=1;
  140433. p->normal_start=nn_start[is];
  140434. p->normal_partition=nn_partition[is];
  140435. p->normal_thresh=nn_thresh[is];
  140436. }
  140437. return;
  140438. }
  140439. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140440. att3 *att,
  140441. int *max,
  140442. vp_adjblock *in){
  140443. int i,is=s;
  140444. double ds=s-is;
  140445. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140446. vorbis_info_psy *p=ci->psy_param[block];
  140447. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140448. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140449. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140450. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140451. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140452. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140453. for(i=0;i<P_BANDS;i++)
  140454. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140455. return;
  140456. }
  140457. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140458. compandblock *in, double *x){
  140459. int i,is=s;
  140460. double ds=s-is;
  140461. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140462. vorbis_info_psy *p=ci->psy_param[block];
  140463. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140464. is=(int)ds;
  140465. ds-=is;
  140466. if(ds==0 && is>0){
  140467. is--;
  140468. ds=1.;
  140469. }
  140470. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140471. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140472. return;
  140473. }
  140474. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140475. int *suppress){
  140476. int is=s;
  140477. double ds=s-is;
  140478. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140479. vorbis_info_psy *p=ci->psy_param[block];
  140480. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140481. return;
  140482. }
  140483. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140484. int *suppress,
  140485. noise3 *in,
  140486. noiseguard *guard,
  140487. double userbias){
  140488. int i,is=s,j;
  140489. double ds=s-is;
  140490. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140491. vorbis_info_psy *p=ci->psy_param[block];
  140492. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140493. p->noisewindowlomin=guard[block].lo;
  140494. p->noisewindowhimin=guard[block].hi;
  140495. p->noisewindowfixed=guard[block].fixed;
  140496. for(j=0;j<P_NOISECURVES;j++)
  140497. for(i=0;i<P_BANDS;i++)
  140498. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140499. for(j=0;j<P_NOISECURVES;j++){
  140500. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140501. for(i=0;i<P_BANDS;i++){
  140502. p->noiseoff[j][i]+=userbias;
  140503. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140504. }
  140505. }
  140506. return;
  140507. }
  140508. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140509. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140510. vorbis_info_psy *p=ci->psy_param[block];
  140511. p->ath_adjatt=ci->hi.ath_floating_dB;
  140512. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140513. return;
  140514. }
  140515. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140516. int i;
  140517. for(i=0;i<ci->books;i++)
  140518. if(ci->book_param[i]==book)return(i);
  140519. return(ci->books++);
  140520. }
  140521. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140522. int *shortb,int *longb){
  140523. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140524. int is=s;
  140525. int blockshort=shortb[is];
  140526. int blocklong=longb[is];
  140527. ci->blocksizes[0]=blockshort;
  140528. ci->blocksizes[1]=blocklong;
  140529. }
  140530. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140531. int number, int block,
  140532. vorbis_residue_template *res){
  140533. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140534. int i,n;
  140535. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140536. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140537. memcpy(r,res->res,sizeof(*r));
  140538. if(ci->residues<=number)ci->residues=number+1;
  140539. switch(ci->blocksizes[block]){
  140540. case 64:case 128:case 256:
  140541. r->grouping=16;
  140542. break;
  140543. default:
  140544. r->grouping=32;
  140545. break;
  140546. }
  140547. ci->residue_type[number]=res->res_type;
  140548. n=r->end=ci->blocksizes[block]>>1;
  140549. if(res->res_type==2)
  140550. n=r->end*=vi->channels;
  140551. {
  140552. int booklist=0,k;
  140553. if(ci->hi.managed){
  140554. for(i=0;i<r->partitions;i++)
  140555. for(k=0;k<3;k++)
  140556. if(res->books_base_managed->books[i][k])
  140557. r->secondstages[i]|=(1<<k);
  140558. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140559. ci->book_param[r->groupbook]=res->book_aux_managed;
  140560. for(i=0;i<r->partitions;i++){
  140561. for(k=0;k<3;k++){
  140562. if(res->books_base_managed->books[i][k]){
  140563. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140564. r->booklist[booklist++]=bookid;
  140565. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140566. }
  140567. }
  140568. }
  140569. }else{
  140570. for(i=0;i<r->partitions;i++)
  140571. for(k=0;k<3;k++)
  140572. if(res->books_base->books[i][k])
  140573. r->secondstages[i]|=(1<<k);
  140574. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140575. ci->book_param[r->groupbook]=res->book_aux;
  140576. for(i=0;i<r->partitions;i++){
  140577. for(k=0;k<3;k++){
  140578. if(res->books_base->books[i][k]){
  140579. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140580. r->booklist[booklist++]=bookid;
  140581. ci->book_param[bookid]=res->books_base->books[i][k];
  140582. }
  140583. }
  140584. }
  140585. }
  140586. }
  140587. {
  140588. double freq=ci->hi.lowpass_kHz*1000.;
  140589. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140590. double nyq=vi->rate/2.;
  140591. long blocksize=ci->blocksizes[block]>>1;
  140592. if(freq>nyq)freq=nyq;
  140593. f->n=freq/nyq*blocksize;
  140594. if(res->limit_type){
  140595. if(ci->hi.managed)
  140596. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140597. else
  140598. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140599. if(freq>nyq)freq=nyq;
  140600. }
  140601. if(ci->residue_type[block]==2)
  140602. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140603. r->grouping;
  140604. else
  140605. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140606. r->grouping;
  140607. }
  140608. }
  140609. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140610. vorbis_mapping_template *maps){
  140611. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140612. int i,j,is=s,modes=2;
  140613. vorbis_info_mapping0 *map=maps[is].map;
  140614. vorbis_info_mode *mode=_mode_template;
  140615. vorbis_residue_template *res=maps[is].res;
  140616. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140617. for(i=0;i<modes;i++){
  140618. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140619. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140620. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140621. if(i>=ci->modes)ci->modes=i+1;
  140622. ci->map_type[i]=0;
  140623. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140624. if(i>=ci->maps)ci->maps=i+1;
  140625. for(j=0;j<map[i].submaps;j++)
  140626. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140627. ,res+map[i].residuesubmap[j]);
  140628. }
  140629. }
  140630. static double setting_to_approx_bitrate(vorbis_info *vi){
  140631. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140632. highlevel_encode_setup *hi=&ci->hi;
  140633. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140634. int is=hi->base_setting;
  140635. double ds=hi->base_setting-is;
  140636. int ch=vi->channels;
  140637. double *r=setup->rate_mapping;
  140638. if(r==NULL)
  140639. return(-1);
  140640. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140641. }
  140642. static void get_setup_template(vorbis_info *vi,
  140643. long ch,long srate,
  140644. double req,int q_or_bitrate){
  140645. int i=0,j;
  140646. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140647. highlevel_encode_setup *hi=&ci->hi;
  140648. if(q_or_bitrate)req/=ch;
  140649. while(setup_list[i]){
  140650. if(setup_list[i]->coupling_restriction==-1 ||
  140651. setup_list[i]->coupling_restriction==ch){
  140652. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140653. srate<=setup_list[i]->samplerate_max_restriction){
  140654. int mappings=setup_list[i]->mappings;
  140655. double *map=(q_or_bitrate?
  140656. setup_list[i]->rate_mapping:
  140657. setup_list[i]->quality_mapping);
  140658. if(req<map[0]){++i;continue;}
  140659. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140660. for(j=0;j<mappings;j++)
  140661. if(req>=map[j] && req<map[j+1])break;
  140662. hi->setup=setup_list[i];
  140663. if(j==mappings)
  140664. hi->base_setting=j-.001;
  140665. else{
  140666. float low=map[j];
  140667. float high=map[j+1];
  140668. float del=(req-low)/(high-low);
  140669. hi->base_setting=j+del;
  140670. }
  140671. return;
  140672. }
  140673. }
  140674. i++;
  140675. }
  140676. hi->setup=NULL;
  140677. }
  140678. int vorbis_encode_setup_init(vorbis_info *vi){
  140679. int i0=0,singleblock=0;
  140680. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140681. ve_setup_data_template *setup=NULL;
  140682. highlevel_encode_setup *hi=&ci->hi;
  140683. if(ci==NULL)return(OV_EINVAL);
  140684. if(!hi->impulse_block_p)i0=1;
  140685. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140686. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140687. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140688. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140689. setup=(ve_setup_data_template *)hi->setup;
  140690. if(setup==NULL)return(OV_EINVAL);
  140691. hi->set_in_stone=1;
  140692. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140693. setup->blocksize_short,
  140694. setup->blocksize_long);
  140695. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140696. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140697. setup->floor_books,
  140698. setup->floor_params,
  140699. setup->floor_short_mapping);
  140700. if(!singleblock)
  140701. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140702. setup->floor_books,
  140703. setup->floor_params,
  140704. setup->floor_long_mapping);
  140705. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140706. setup->global_params,
  140707. setup->global_mapping);
  140708. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140709. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140710. setup->psy_noise_normal_start[0],
  140711. setup->psy_noise_normal_partition[0],
  140712. setup->psy_noise_normal_thresh,
  140713. 0);
  140714. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140715. setup->psy_noise_normal_start[0],
  140716. setup->psy_noise_normal_partition[0],
  140717. setup->psy_noise_normal_thresh,
  140718. 1);
  140719. if(!singleblock){
  140720. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140721. setup->psy_noise_normal_start[1],
  140722. setup->psy_noise_normal_partition[1],
  140723. setup->psy_noise_normal_thresh,
  140724. 2);
  140725. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140726. setup->psy_noise_normal_start[1],
  140727. setup->psy_noise_normal_partition[1],
  140728. setup->psy_noise_normal_thresh,
  140729. 3);
  140730. }
  140731. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140732. setup->psy_tone_masteratt,
  140733. setup->psy_tone_0dB,
  140734. setup->psy_tone_adj_impulse);
  140735. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140736. setup->psy_tone_masteratt,
  140737. setup->psy_tone_0dB,
  140738. setup->psy_tone_adj_other);
  140739. if(!singleblock){
  140740. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140741. setup->psy_tone_masteratt,
  140742. setup->psy_tone_0dB,
  140743. setup->psy_tone_adj_other);
  140744. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140745. setup->psy_tone_masteratt,
  140746. setup->psy_tone_0dB,
  140747. setup->psy_tone_adj_long);
  140748. }
  140749. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140750. setup->psy_noise_compand,
  140751. setup->psy_noise_compand_short_mapping);
  140752. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140753. setup->psy_noise_compand,
  140754. setup->psy_noise_compand_short_mapping);
  140755. if(!singleblock){
  140756. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140757. setup->psy_noise_compand,
  140758. setup->psy_noise_compand_long_mapping);
  140759. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140760. setup->psy_noise_compand,
  140761. setup->psy_noise_compand_long_mapping);
  140762. }
  140763. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140764. setup->psy_tone_dBsuppress);
  140765. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140766. setup->psy_tone_dBsuppress);
  140767. if(!singleblock){
  140768. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140769. setup->psy_tone_dBsuppress);
  140770. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140771. setup->psy_tone_dBsuppress);
  140772. }
  140773. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140774. setup->psy_noise_dBsuppress,
  140775. setup->psy_noise_bias_impulse,
  140776. setup->psy_noiseguards,
  140777. (i0==0?hi->impulse_noisetune:0.));
  140778. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140779. setup->psy_noise_dBsuppress,
  140780. setup->psy_noise_bias_padding,
  140781. setup->psy_noiseguards,0.);
  140782. if(!singleblock){
  140783. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140784. setup->psy_noise_dBsuppress,
  140785. setup->psy_noise_bias_trans,
  140786. setup->psy_noiseguards,0.);
  140787. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140788. setup->psy_noise_dBsuppress,
  140789. setup->psy_noise_bias_long,
  140790. setup->psy_noiseguards,0.);
  140791. }
  140792. vorbis_encode_ath_setup(vi,0);
  140793. vorbis_encode_ath_setup(vi,1);
  140794. if(!singleblock){
  140795. vorbis_encode_ath_setup(vi,2);
  140796. vorbis_encode_ath_setup(vi,3);
  140797. }
  140798. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140799. if(hi->bitrate_av>0)
  140800. vi->bitrate_nominal=hi->bitrate_av;
  140801. else{
  140802. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140803. }
  140804. vi->bitrate_lower=hi->bitrate_min;
  140805. vi->bitrate_upper=hi->bitrate_max;
  140806. if(hi->bitrate_av)
  140807. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140808. else
  140809. vi->bitrate_window=0.;
  140810. if(hi->managed){
  140811. ci->bi.avg_rate=hi->bitrate_av;
  140812. ci->bi.min_rate=hi->bitrate_min;
  140813. ci->bi.max_rate=hi->bitrate_max;
  140814. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140815. ci->bi.reservoir_bias=
  140816. hi->bitrate_reservoir_bias;
  140817. ci->bi.slew_damp=hi->bitrate_av_damp;
  140818. }
  140819. return(0);
  140820. }
  140821. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140822. long channels,
  140823. long rate){
  140824. int ret=0,i,is;
  140825. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140826. highlevel_encode_setup *hi=&ci->hi;
  140827. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140828. double ds;
  140829. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140830. if(ret)return(ret);
  140831. is=hi->base_setting;
  140832. ds=hi->base_setting-is;
  140833. hi->short_setting=hi->base_setting;
  140834. hi->long_setting=hi->base_setting;
  140835. hi->managed=0;
  140836. hi->impulse_block_p=1;
  140837. hi->noise_normalize_p=1;
  140838. hi->stereo_point_setting=hi->base_setting;
  140839. hi->lowpass_kHz=
  140840. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140841. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140842. setup->psy_ath_float[is+1]*ds;
  140843. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140844. setup->psy_ath_abs[is+1]*ds;
  140845. hi->amplitude_track_dBpersec=-6.;
  140846. hi->trigger_setting=hi->base_setting;
  140847. for(i=0;i<4;i++){
  140848. hi->block[i].tone_mask_setting=hi->base_setting;
  140849. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140850. hi->block[i].noise_bias_setting=hi->base_setting;
  140851. hi->block[i].noise_compand_setting=hi->base_setting;
  140852. }
  140853. return(ret);
  140854. }
  140855. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140856. long channels,
  140857. long rate,
  140858. float quality){
  140859. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140860. highlevel_encode_setup *hi=&ci->hi;
  140861. quality+=.0000001;
  140862. if(quality>=1.)quality=.9999;
  140863. get_setup_template(vi,channels,rate,quality,0);
  140864. if(!hi->setup)return OV_EIMPL;
  140865. return vorbis_encode_setup_setting(vi,channels,rate);
  140866. }
  140867. int vorbis_encode_init_vbr(vorbis_info *vi,
  140868. long channels,
  140869. long rate,
  140870. float base_quality /* 0. to 1. */
  140871. ){
  140872. int ret=0;
  140873. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140874. if(ret){
  140875. vorbis_info_clear(vi);
  140876. return ret;
  140877. }
  140878. ret=vorbis_encode_setup_init(vi);
  140879. if(ret)
  140880. vorbis_info_clear(vi);
  140881. return(ret);
  140882. }
  140883. int vorbis_encode_setup_managed(vorbis_info *vi,
  140884. long channels,
  140885. long rate,
  140886. long max_bitrate,
  140887. long nominal_bitrate,
  140888. long min_bitrate){
  140889. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140890. highlevel_encode_setup *hi=&ci->hi;
  140891. double tnominal=nominal_bitrate;
  140892. int ret=0;
  140893. if(nominal_bitrate<=0.){
  140894. if(max_bitrate>0.){
  140895. if(min_bitrate>0.)
  140896. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140897. else
  140898. nominal_bitrate=max_bitrate*.875;
  140899. }else{
  140900. if(min_bitrate>0.){
  140901. nominal_bitrate=min_bitrate;
  140902. }else{
  140903. return(OV_EINVAL);
  140904. }
  140905. }
  140906. }
  140907. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140908. if(!hi->setup)return OV_EIMPL;
  140909. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140910. if(ret){
  140911. vorbis_info_clear(vi);
  140912. return ret;
  140913. }
  140914. hi->managed=1;
  140915. hi->bitrate_min=min_bitrate;
  140916. hi->bitrate_max=max_bitrate;
  140917. hi->bitrate_av=tnominal;
  140918. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140919. hi->bitrate_reservoir=nominal_bitrate*2;
  140920. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140921. return(ret);
  140922. }
  140923. int vorbis_encode_init(vorbis_info *vi,
  140924. long channels,
  140925. long rate,
  140926. long max_bitrate,
  140927. long nominal_bitrate,
  140928. long min_bitrate){
  140929. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140930. max_bitrate,
  140931. nominal_bitrate,
  140932. min_bitrate);
  140933. if(ret){
  140934. vorbis_info_clear(vi);
  140935. return(ret);
  140936. }
  140937. ret=vorbis_encode_setup_init(vi);
  140938. if(ret)
  140939. vorbis_info_clear(vi);
  140940. return(ret);
  140941. }
  140942. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140943. if(vi){
  140944. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140945. highlevel_encode_setup *hi=&ci->hi;
  140946. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140947. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140948. switch(number){
  140949. case OV_ECTL_RATEMANAGE_GET:
  140950. {
  140951. struct ovectl_ratemanage_arg *ai=
  140952. (struct ovectl_ratemanage_arg *)arg;
  140953. ai->management_active=hi->managed;
  140954. ai->bitrate_hard_window=ai->bitrate_av_window=
  140955. (double)hi->bitrate_reservoir/vi->rate;
  140956. ai->bitrate_av_window_center=1.;
  140957. ai->bitrate_hard_min=hi->bitrate_min;
  140958. ai->bitrate_hard_max=hi->bitrate_max;
  140959. ai->bitrate_av_lo=hi->bitrate_av;
  140960. ai->bitrate_av_hi=hi->bitrate_av;
  140961. }
  140962. return(0);
  140963. case OV_ECTL_RATEMANAGE_SET:
  140964. {
  140965. struct ovectl_ratemanage_arg *ai=
  140966. (struct ovectl_ratemanage_arg *)arg;
  140967. if(ai==NULL){
  140968. hi->managed=0;
  140969. }else{
  140970. hi->managed=ai->management_active;
  140971. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140972. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140973. }
  140974. }
  140975. return 0;
  140976. case OV_ECTL_RATEMANAGE_AVG:
  140977. {
  140978. struct ovectl_ratemanage_arg *ai=
  140979. (struct ovectl_ratemanage_arg *)arg;
  140980. if(ai==NULL){
  140981. hi->bitrate_av=0;
  140982. }else{
  140983. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140984. }
  140985. }
  140986. return(0);
  140987. case OV_ECTL_RATEMANAGE_HARD:
  140988. {
  140989. struct ovectl_ratemanage_arg *ai=
  140990. (struct ovectl_ratemanage_arg *)arg;
  140991. if(ai==NULL){
  140992. hi->bitrate_min=0;
  140993. hi->bitrate_max=0;
  140994. }else{
  140995. hi->bitrate_min=ai->bitrate_hard_min;
  140996. hi->bitrate_max=ai->bitrate_hard_max;
  140997. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140998. (hi->bitrate_max+hi->bitrate_min)*.5;
  140999. }
  141000. if(hi->bitrate_reservoir<128.)
  141001. hi->bitrate_reservoir=128.;
  141002. }
  141003. return(0);
  141004. case OV_ECTL_RATEMANAGE2_GET:
  141005. {
  141006. struct ovectl_ratemanage2_arg *ai=
  141007. (struct ovectl_ratemanage2_arg *)arg;
  141008. if(ai==NULL)return OV_EINVAL;
  141009. ai->management_active=hi->managed;
  141010. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  141011. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  141012. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  141013. ai->bitrate_average_damping=hi->bitrate_av_damp;
  141014. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  141015. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  141016. }
  141017. return (0);
  141018. case OV_ECTL_RATEMANAGE2_SET:
  141019. {
  141020. struct ovectl_ratemanage2_arg *ai=
  141021. (struct ovectl_ratemanage2_arg *)arg;
  141022. if(ai==NULL){
  141023. hi->managed=0;
  141024. }else{
  141025. if(ai->bitrate_limit_min_kbps>0 &&
  141026. ai->bitrate_average_kbps>0 &&
  141027. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  141028. return OV_EINVAL;
  141029. if(ai->bitrate_limit_max_kbps>0 &&
  141030. ai->bitrate_average_kbps>0 &&
  141031. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  141032. return OV_EINVAL;
  141033. if(ai->bitrate_limit_min_kbps>0 &&
  141034. ai->bitrate_limit_max_kbps>0 &&
  141035. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  141036. return OV_EINVAL;
  141037. if(ai->bitrate_average_damping <= 0.)
  141038. return OV_EINVAL;
  141039. if(ai->bitrate_limit_reservoir_bits < 0)
  141040. return OV_EINVAL;
  141041. if(ai->bitrate_limit_reservoir_bias < 0.)
  141042. return OV_EINVAL;
  141043. if(ai->bitrate_limit_reservoir_bias > 1.)
  141044. return OV_EINVAL;
  141045. hi->managed=ai->management_active;
  141046. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  141047. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  141048. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  141049. hi->bitrate_av_damp=ai->bitrate_average_damping;
  141050. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  141051. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  141052. }
  141053. }
  141054. return 0;
  141055. case OV_ECTL_LOWPASS_GET:
  141056. {
  141057. double *farg=(double *)arg;
  141058. *farg=hi->lowpass_kHz;
  141059. }
  141060. return(0);
  141061. case OV_ECTL_LOWPASS_SET:
  141062. {
  141063. double *farg=(double *)arg;
  141064. hi->lowpass_kHz=*farg;
  141065. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  141066. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  141067. }
  141068. return(0);
  141069. case OV_ECTL_IBLOCK_GET:
  141070. {
  141071. double *farg=(double *)arg;
  141072. *farg=hi->impulse_noisetune;
  141073. }
  141074. return(0);
  141075. case OV_ECTL_IBLOCK_SET:
  141076. {
  141077. double *farg=(double *)arg;
  141078. hi->impulse_noisetune=*farg;
  141079. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  141080. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  141081. }
  141082. return(0);
  141083. }
  141084. return(OV_EIMPL);
  141085. }
  141086. return(OV_EINVAL);
  141087. }
  141088. #endif
  141089. /*** End of inlined file: vorbisenc.c ***/
  141090. /*** Start of inlined file: vorbisfile.c ***/
  141091. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  141092. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141093. // tasks..
  141094. #if JUCE_MSVC
  141095. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141096. #endif
  141097. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  141098. #if JUCE_USE_OGGVORBIS
  141099. #include <stdlib.h>
  141100. #include <stdio.h>
  141101. #include <errno.h>
  141102. #include <string.h>
  141103. #include <math.h>
  141104. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  141105. over 8k gets what they deserve */
  141106. static long _get_data(OggVorbis_File *vf){
  141107. errno=0;
  141108. if(vf->datasource){
  141109. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  141110. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  141111. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  141112. if(bytes==0 && errno)return(-1);
  141113. return(bytes);
  141114. }else
  141115. return(0);
  141116. }
  141117. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  141118. if(vf->datasource){
  141119. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  141120. vf->offset=offset;
  141121. ogg_sync_reset(&vf->oy);
  141122. }else{
  141123. return;
  141124. }
  141125. }
  141126. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  141127. ogg_int64_t boundary){
  141128. if(boundary>0)boundary+=vf->offset;
  141129. while(1){
  141130. long more;
  141131. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  141132. more=ogg_sync_pageseek(&vf->oy,og);
  141133. if(more<0){
  141134. vf->offset-=more;
  141135. }else{
  141136. if(more==0){
  141137. if(!boundary)return(OV_FALSE);
  141138. {
  141139. long ret=_get_data(vf);
  141140. if(ret==0)return(OV_EOF);
  141141. if(ret<0)return(OV_EREAD);
  141142. }
  141143. }else{
  141144. ogg_int64_t ret=vf->offset;
  141145. vf->offset+=more;
  141146. return(ret);
  141147. }
  141148. }
  141149. }
  141150. }
  141151. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  141152. ogg_int64_t begin=vf->offset;
  141153. ogg_int64_t end=begin;
  141154. ogg_int64_t ret;
  141155. ogg_int64_t offset=-1;
  141156. while(offset==-1){
  141157. begin-=CHUNKSIZE;
  141158. if(begin<0)
  141159. begin=0;
  141160. _seek_helper(vf,begin);
  141161. while(vf->offset<end){
  141162. ret=_get_next_page(vf,og,end-vf->offset);
  141163. if(ret==OV_EREAD)return(OV_EREAD);
  141164. if(ret<0){
  141165. break;
  141166. }else{
  141167. offset=ret;
  141168. }
  141169. }
  141170. }
  141171. _seek_helper(vf,offset);
  141172. ret=_get_next_page(vf,og,CHUNKSIZE);
  141173. if(ret<0)
  141174. return(OV_EFAULT);
  141175. return(offset);
  141176. }
  141177. static int _bisect_forward_serialno(OggVorbis_File *vf,
  141178. ogg_int64_t begin,
  141179. ogg_int64_t searched,
  141180. ogg_int64_t end,
  141181. long currentno,
  141182. long m){
  141183. ogg_int64_t endsearched=end;
  141184. ogg_int64_t next=end;
  141185. ogg_page og;
  141186. ogg_int64_t ret;
  141187. while(searched<endsearched){
  141188. ogg_int64_t bisect;
  141189. if(endsearched-searched<CHUNKSIZE){
  141190. bisect=searched;
  141191. }else{
  141192. bisect=(searched+endsearched)/2;
  141193. }
  141194. _seek_helper(vf,bisect);
  141195. ret=_get_next_page(vf,&og,-1);
  141196. if(ret==OV_EREAD)return(OV_EREAD);
  141197. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  141198. endsearched=bisect;
  141199. if(ret>=0)next=ret;
  141200. }else{
  141201. searched=ret+og.header_len+og.body_len;
  141202. }
  141203. }
  141204. _seek_helper(vf,next);
  141205. ret=_get_next_page(vf,&og,-1);
  141206. if(ret==OV_EREAD)return(OV_EREAD);
  141207. if(searched>=end || ret<0){
  141208. vf->links=m+1;
  141209. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  141210. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  141211. vf->offsets[m+1]=searched;
  141212. }else{
  141213. ret=_bisect_forward_serialno(vf,next,vf->offset,
  141214. end,ogg_page_serialno(&og),m+1);
  141215. if(ret==OV_EREAD)return(OV_EREAD);
  141216. }
  141217. vf->offsets[m]=begin;
  141218. vf->serialnos[m]=currentno;
  141219. return(0);
  141220. }
  141221. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  141222. long *serialno,ogg_page *og_ptr){
  141223. ogg_page og;
  141224. ogg_packet op;
  141225. int i,ret;
  141226. if(!og_ptr){
  141227. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  141228. if(llret==OV_EREAD)return(OV_EREAD);
  141229. if(llret<0)return OV_ENOTVORBIS;
  141230. og_ptr=&og;
  141231. }
  141232. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  141233. if(serialno)*serialno=vf->os.serialno;
  141234. vf->ready_state=STREAMSET;
  141235. vorbis_info_init(vi);
  141236. vorbis_comment_init(vc);
  141237. i=0;
  141238. while(i<3){
  141239. ogg_stream_pagein(&vf->os,og_ptr);
  141240. while(i<3){
  141241. int result=ogg_stream_packetout(&vf->os,&op);
  141242. if(result==0)break;
  141243. if(result==-1){
  141244. ret=OV_EBADHEADER;
  141245. goto bail_header;
  141246. }
  141247. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  141248. goto bail_header;
  141249. }
  141250. i++;
  141251. }
  141252. if(i<3)
  141253. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  141254. ret=OV_EBADHEADER;
  141255. goto bail_header;
  141256. }
  141257. }
  141258. return 0;
  141259. bail_header:
  141260. vorbis_info_clear(vi);
  141261. vorbis_comment_clear(vc);
  141262. vf->ready_state=OPENED;
  141263. return ret;
  141264. }
  141265. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  141266. ogg_page og;
  141267. int i;
  141268. ogg_int64_t ret;
  141269. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  141270. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  141271. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  141272. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  141273. for(i=0;i<vf->links;i++){
  141274. if(i==0){
  141275. vf->dataoffsets[i]=dataoffset;
  141276. _seek_helper(vf,dataoffset);
  141277. }else{
  141278. _seek_helper(vf,vf->offsets[i]);
  141279. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  141280. vf->dataoffsets[i]=-1;
  141281. }else{
  141282. vf->dataoffsets[i]=vf->offset;
  141283. }
  141284. }
  141285. if(vf->dataoffsets[i]!=-1){
  141286. ogg_int64_t accumulated=0;
  141287. long lastblock=-1;
  141288. int result;
  141289. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141290. while(1){
  141291. ogg_packet op;
  141292. ret=_get_next_page(vf,&og,-1);
  141293. if(ret<0)
  141294. break;
  141295. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141296. break;
  141297. ogg_stream_pagein(&vf->os,&og);
  141298. while((result=ogg_stream_packetout(&vf->os,&op))){
  141299. if(result>0){ /* ignore holes */
  141300. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141301. if(lastblock!=-1)
  141302. accumulated+=(lastblock+thisblock)>>2;
  141303. lastblock=thisblock;
  141304. }
  141305. }
  141306. if(ogg_page_granulepos(&og)!=-1){
  141307. accumulated= ogg_page_granulepos(&og)-accumulated;
  141308. break;
  141309. }
  141310. }
  141311. if(accumulated<0)accumulated=0;
  141312. vf->pcmlengths[i*2]=accumulated;
  141313. }
  141314. {
  141315. ogg_int64_t end=vf->offsets[i+1];
  141316. _seek_helper(vf,end);
  141317. while(1){
  141318. ret=_get_prev_page(vf,&og);
  141319. if(ret<0){
  141320. vorbis_info_clear(vf->vi+i);
  141321. vorbis_comment_clear(vf->vc+i);
  141322. break;
  141323. }
  141324. if(ogg_page_granulepos(&og)!=-1){
  141325. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141326. break;
  141327. }
  141328. vf->offset=ret;
  141329. }
  141330. }
  141331. }
  141332. }
  141333. static int _make_decode_ready(OggVorbis_File *vf){
  141334. if(vf->ready_state>STREAMSET)return 0;
  141335. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141336. if(vf->seekable){
  141337. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141338. return OV_EBADLINK;
  141339. }else{
  141340. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141341. return OV_EBADLINK;
  141342. }
  141343. vorbis_block_init(&vf->vd,&vf->vb);
  141344. vf->ready_state=INITSET;
  141345. vf->bittrack=0.f;
  141346. vf->samptrack=0.f;
  141347. return 0;
  141348. }
  141349. static int _open_seekable2(OggVorbis_File *vf){
  141350. long serialno=vf->current_serialno;
  141351. ogg_int64_t dataoffset=vf->offset, end;
  141352. ogg_page og;
  141353. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141354. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141355. end=_get_prev_page(vf,&og);
  141356. if(end<0)return(end);
  141357. if(ogg_page_serialno(&og)!=serialno){
  141358. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141359. }else{
  141360. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141361. }
  141362. _prefetch_all_headers(vf,dataoffset);
  141363. return(ov_raw_seek(vf,0));
  141364. }
  141365. static void _decode_clear(OggVorbis_File *vf){
  141366. vorbis_dsp_clear(&vf->vd);
  141367. vorbis_block_clear(&vf->vb);
  141368. vf->ready_state=OPENED;
  141369. }
  141370. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141371. ogg_packet *op_in,
  141372. int readp,
  141373. int spanp){
  141374. ogg_page og;
  141375. while(1){
  141376. if(vf->ready_state==INITSET){
  141377. while(1) {
  141378. ogg_packet op;
  141379. ogg_packet *op_ptr=(op_in?op_in:&op);
  141380. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141381. ogg_int64_t granulepos;
  141382. op_in=NULL;
  141383. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141384. if(result>0){
  141385. granulepos=op_ptr->granulepos;
  141386. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141387. header handling. The
  141388. header packets aren't
  141389. audio, so if/when we
  141390. submit them,
  141391. vorbis_synthesis will
  141392. reject them */
  141393. {
  141394. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141395. if(oldsamples)return(OV_EFAULT);
  141396. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141397. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141398. vf->bittrack+=op_ptr->bytes*8;
  141399. }
  141400. if(granulepos!=-1 && !op_ptr->e_o_s){
  141401. int link=(vf->seekable?vf->current_link:0);
  141402. int i,samples;
  141403. if(vf->seekable && link>0)
  141404. granulepos-=vf->pcmlengths[link*2];
  141405. if(granulepos<0)granulepos=0; /* actually, this
  141406. shouldn't be possible
  141407. here unless the stream
  141408. is very broken */
  141409. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141410. granulepos-=samples;
  141411. for(i=0;i<link;i++)
  141412. granulepos+=vf->pcmlengths[i*2+1];
  141413. vf->pcm_offset=granulepos;
  141414. }
  141415. return(1);
  141416. }
  141417. }
  141418. else
  141419. break;
  141420. }
  141421. }
  141422. if(vf->ready_state>=OPENED){
  141423. ogg_int64_t ret;
  141424. if(!readp)return(0);
  141425. if((ret=_get_next_page(vf,&og,-1))<0){
  141426. return(OV_EOF); /* eof.
  141427. leave unitialized */
  141428. }
  141429. vf->bittrack+=og.header_len*8;
  141430. if(vf->ready_state==INITSET){
  141431. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141432. if(!spanp)
  141433. return(OV_EOF);
  141434. _decode_clear(vf);
  141435. if(!vf->seekable){
  141436. vorbis_info_clear(vf->vi);
  141437. vorbis_comment_clear(vf->vc);
  141438. }
  141439. }
  141440. }
  141441. }
  141442. if(vf->ready_state!=INITSET){
  141443. int link;
  141444. if(vf->ready_state<STREAMSET){
  141445. if(vf->seekable){
  141446. vf->current_serialno=ogg_page_serialno(&og);
  141447. for(link=0;link<vf->links;link++)
  141448. if(vf->serialnos[link]==vf->current_serialno)break;
  141449. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141450. stream. error out,
  141451. leave machine
  141452. uninitialized */
  141453. vf->current_link=link;
  141454. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141455. vf->ready_state=STREAMSET;
  141456. }else{
  141457. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141458. if(ret)return(ret);
  141459. vf->current_link++;
  141460. link=0;
  141461. }
  141462. }
  141463. {
  141464. int ret=_make_decode_ready(vf);
  141465. if(ret<0)return ret;
  141466. }
  141467. }
  141468. ogg_stream_pagein(&vf->os,&og);
  141469. }
  141470. }
  141471. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141472. if(f==NULL)return(-1);
  141473. return fseek(f,off,whence);
  141474. }
  141475. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141476. long ibytes, ov_callbacks callbacks){
  141477. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141478. int ret;
  141479. memset(vf,0,sizeof(*vf));
  141480. vf->datasource=f;
  141481. vf->callbacks = callbacks;
  141482. ogg_sync_init(&vf->oy);
  141483. if(initial){
  141484. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141485. memcpy(buffer,initial,ibytes);
  141486. ogg_sync_wrote(&vf->oy,ibytes);
  141487. }
  141488. if(offsettest!=-1)vf->seekable=1;
  141489. vf->links=1;
  141490. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141491. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141492. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141493. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141494. vf->datasource=NULL;
  141495. ov_clear(vf);
  141496. }else
  141497. vf->ready_state=PARTOPEN;
  141498. return(ret);
  141499. }
  141500. static int _ov_open2(OggVorbis_File *vf){
  141501. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141502. vf->ready_state=OPENED;
  141503. if(vf->seekable){
  141504. int ret=_open_seekable2(vf);
  141505. if(ret){
  141506. vf->datasource=NULL;
  141507. ov_clear(vf);
  141508. }
  141509. return(ret);
  141510. }else
  141511. vf->ready_state=STREAMSET;
  141512. return 0;
  141513. }
  141514. int ov_clear(OggVorbis_File *vf){
  141515. if(vf){
  141516. vorbis_block_clear(&vf->vb);
  141517. vorbis_dsp_clear(&vf->vd);
  141518. ogg_stream_clear(&vf->os);
  141519. if(vf->vi && vf->links){
  141520. int i;
  141521. for(i=0;i<vf->links;i++){
  141522. vorbis_info_clear(vf->vi+i);
  141523. vorbis_comment_clear(vf->vc+i);
  141524. }
  141525. _ogg_free(vf->vi);
  141526. _ogg_free(vf->vc);
  141527. }
  141528. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141529. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141530. if(vf->serialnos)_ogg_free(vf->serialnos);
  141531. if(vf->offsets)_ogg_free(vf->offsets);
  141532. ogg_sync_clear(&vf->oy);
  141533. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141534. memset(vf,0,sizeof(*vf));
  141535. }
  141536. #ifdef DEBUG_LEAKS
  141537. _VDBG_dump();
  141538. #endif
  141539. return(0);
  141540. }
  141541. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141542. ov_callbacks callbacks){
  141543. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141544. if(ret)return ret;
  141545. return _ov_open2(vf);
  141546. }
  141547. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141548. ov_callbacks callbacks = {
  141549. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141550. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141551. (int (*)(void *)) fclose,
  141552. (long (*)(void *)) ftell
  141553. };
  141554. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141555. }
  141556. int ov_halfrate(OggVorbis_File *vf,int flag){
  141557. int i;
  141558. if(vf->vi==NULL)return OV_EINVAL;
  141559. if(!vf->seekable)return OV_EINVAL;
  141560. if(vf->ready_state>=STREAMSET)
  141561. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141562. will be able to swap this on the fly, but
  141563. for now dumping the decode machine is needed
  141564. to reinit the MDCT lookups. 1.1 libvorbis
  141565. is planned to be able to switch on the fly */
  141566. for(i=0;i<vf->links;i++){
  141567. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141568. ov_halfrate(vf,0);
  141569. return OV_EINVAL;
  141570. }
  141571. }
  141572. return 0;
  141573. }
  141574. int ov_halfrate_p(OggVorbis_File *vf){
  141575. if(vf->vi==NULL)return OV_EINVAL;
  141576. return vorbis_synthesis_halfrate_p(vf->vi);
  141577. }
  141578. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141579. ov_callbacks callbacks)
  141580. {
  141581. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141582. }
  141583. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141584. ov_callbacks callbacks = {
  141585. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141586. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141587. (int (*)(void *)) fclose,
  141588. (long (*)(void *)) ftell
  141589. };
  141590. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141591. }
  141592. int ov_test_open(OggVorbis_File *vf){
  141593. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141594. return _ov_open2(vf);
  141595. }
  141596. long ov_streams(OggVorbis_File *vf){
  141597. return vf->links;
  141598. }
  141599. long ov_seekable(OggVorbis_File *vf){
  141600. return vf->seekable;
  141601. }
  141602. long ov_bitrate(OggVorbis_File *vf,int i){
  141603. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141604. if(i>=vf->links)return(OV_EINVAL);
  141605. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141606. if(i<0){
  141607. ogg_int64_t bits=0;
  141608. int i;
  141609. float br;
  141610. for(i=0;i<vf->links;i++)
  141611. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141612. br = bits/ov_time_total(vf,-1);
  141613. return(rint(br));
  141614. }else{
  141615. if(vf->seekable){
  141616. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141617. }else{
  141618. if(vf->vi[i].bitrate_nominal>0){
  141619. return vf->vi[i].bitrate_nominal;
  141620. }else{
  141621. if(vf->vi[i].bitrate_upper>0){
  141622. if(vf->vi[i].bitrate_lower>0){
  141623. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141624. }else{
  141625. return vf->vi[i].bitrate_upper;
  141626. }
  141627. }
  141628. return(OV_FALSE);
  141629. }
  141630. }
  141631. }
  141632. }
  141633. long ov_bitrate_instant(OggVorbis_File *vf){
  141634. int link=(vf->seekable?vf->current_link:0);
  141635. long ret;
  141636. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141637. if(vf->samptrack==0)return(OV_FALSE);
  141638. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141639. vf->bittrack=0.f;
  141640. vf->samptrack=0.f;
  141641. return(ret);
  141642. }
  141643. long ov_serialnumber(OggVorbis_File *vf,int i){
  141644. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141645. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141646. if(i<0){
  141647. return(vf->current_serialno);
  141648. }else{
  141649. return(vf->serialnos[i]);
  141650. }
  141651. }
  141652. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141653. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141654. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141655. if(i<0){
  141656. ogg_int64_t acc=0;
  141657. int i;
  141658. for(i=0;i<vf->links;i++)
  141659. acc+=ov_raw_total(vf,i);
  141660. return(acc);
  141661. }else{
  141662. return(vf->offsets[i+1]-vf->offsets[i]);
  141663. }
  141664. }
  141665. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141666. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141667. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141668. if(i<0){
  141669. ogg_int64_t acc=0;
  141670. int i;
  141671. for(i=0;i<vf->links;i++)
  141672. acc+=ov_pcm_total(vf,i);
  141673. return(acc);
  141674. }else{
  141675. return(vf->pcmlengths[i*2+1]);
  141676. }
  141677. }
  141678. double ov_time_total(OggVorbis_File *vf,int i){
  141679. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141680. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141681. if(i<0){
  141682. double acc=0;
  141683. int i;
  141684. for(i=0;i<vf->links;i++)
  141685. acc+=ov_time_total(vf,i);
  141686. return(acc);
  141687. }else{
  141688. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141689. }
  141690. }
  141691. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141692. ogg_stream_state work_os;
  141693. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141694. if(!vf->seekable)
  141695. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141696. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141697. vf->pcm_offset=-1;
  141698. ogg_stream_reset_serialno(&vf->os,
  141699. vf->current_serialno); /* must set serialno */
  141700. vorbis_synthesis_restart(&vf->vd);
  141701. _seek_helper(vf,pos);
  141702. {
  141703. ogg_page og;
  141704. ogg_packet op;
  141705. int lastblock=0;
  141706. int accblock=0;
  141707. int thisblock;
  141708. int eosflag;
  141709. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141710. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141711. return from not necessarily
  141712. starting from the beginning */
  141713. while(1){
  141714. if(vf->ready_state>=STREAMSET){
  141715. int result=ogg_stream_packetout(&work_os,&op);
  141716. if(result>0){
  141717. if(vf->vi[vf->current_link].codec_setup){
  141718. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141719. if(thisblock<0){
  141720. ogg_stream_packetout(&vf->os,NULL);
  141721. thisblock=0;
  141722. }else{
  141723. if(eosflag)
  141724. ogg_stream_packetout(&vf->os,NULL);
  141725. else
  141726. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141727. }
  141728. if(op.granulepos!=-1){
  141729. int i,link=vf->current_link;
  141730. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141731. if(granulepos<0)granulepos=0;
  141732. for(i=0;i<link;i++)
  141733. granulepos+=vf->pcmlengths[i*2+1];
  141734. vf->pcm_offset=granulepos-accblock;
  141735. break;
  141736. }
  141737. lastblock=thisblock;
  141738. continue;
  141739. }else
  141740. ogg_stream_packetout(&vf->os,NULL);
  141741. }
  141742. }
  141743. if(!lastblock){
  141744. if(_get_next_page(vf,&og,-1)<0){
  141745. vf->pcm_offset=ov_pcm_total(vf,-1);
  141746. break;
  141747. }
  141748. }else{
  141749. vf->pcm_offset=-1;
  141750. break;
  141751. }
  141752. if(vf->ready_state>=STREAMSET)
  141753. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141754. _decode_clear(vf); /* clear out stream state */
  141755. ogg_stream_clear(&work_os);
  141756. }
  141757. if(vf->ready_state<STREAMSET){
  141758. int link;
  141759. vf->current_serialno=ogg_page_serialno(&og);
  141760. for(link=0;link<vf->links;link++)
  141761. if(vf->serialnos[link]==vf->current_serialno)break;
  141762. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141763. error out, leave
  141764. machine uninitialized */
  141765. vf->current_link=link;
  141766. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141767. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141768. vf->ready_state=STREAMSET;
  141769. }
  141770. ogg_stream_pagein(&vf->os,&og);
  141771. ogg_stream_pagein(&work_os,&og);
  141772. eosflag=ogg_page_eos(&og);
  141773. }
  141774. }
  141775. ogg_stream_clear(&work_os);
  141776. vf->bittrack=0.f;
  141777. vf->samptrack=0.f;
  141778. return(0);
  141779. seek_error:
  141780. vf->pcm_offset=-1;
  141781. ogg_stream_clear(&work_os);
  141782. _decode_clear(vf);
  141783. return OV_EBADLINK;
  141784. }
  141785. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141786. int link=-1;
  141787. ogg_int64_t result=0;
  141788. ogg_int64_t total=ov_pcm_total(vf,-1);
  141789. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141790. if(!vf->seekable)return(OV_ENOSEEK);
  141791. if(pos<0 || pos>total)return(OV_EINVAL);
  141792. for(link=vf->links-1;link>=0;link--){
  141793. total-=vf->pcmlengths[link*2+1];
  141794. if(pos>=total)break;
  141795. }
  141796. {
  141797. ogg_int64_t end=vf->offsets[link+1];
  141798. ogg_int64_t begin=vf->offsets[link];
  141799. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141800. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141801. ogg_int64_t target=pos-total+begintime;
  141802. ogg_int64_t best=begin;
  141803. ogg_page og;
  141804. while(begin<end){
  141805. ogg_int64_t bisect;
  141806. if(end-begin<CHUNKSIZE){
  141807. bisect=begin;
  141808. }else{
  141809. bisect=begin +
  141810. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141811. if(bisect<=begin)
  141812. bisect=begin+1;
  141813. }
  141814. _seek_helper(vf,bisect);
  141815. while(begin<end){
  141816. result=_get_next_page(vf,&og,end-vf->offset);
  141817. if(result==OV_EREAD) goto seek_error;
  141818. if(result<0){
  141819. if(bisect<=begin+1)
  141820. end=begin; /* found it */
  141821. else{
  141822. if(bisect==0) goto seek_error;
  141823. bisect-=CHUNKSIZE;
  141824. if(bisect<=begin)bisect=begin+1;
  141825. _seek_helper(vf,bisect);
  141826. }
  141827. }else{
  141828. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141829. if(granulepos==-1)continue;
  141830. if(granulepos<target){
  141831. best=result; /* raw offset of packet with granulepos */
  141832. begin=vf->offset; /* raw offset of next page */
  141833. begintime=granulepos;
  141834. if(target-begintime>44100)break;
  141835. bisect=begin; /* *not* begin + 1 */
  141836. }else{
  141837. if(bisect<=begin+1)
  141838. end=begin; /* found it */
  141839. else{
  141840. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141841. end=result;
  141842. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141843. if(bisect<=begin)bisect=begin+1;
  141844. _seek_helper(vf,bisect);
  141845. }else{
  141846. end=result;
  141847. endtime=granulepos;
  141848. break;
  141849. }
  141850. }
  141851. }
  141852. }
  141853. }
  141854. }
  141855. {
  141856. ogg_page og;
  141857. ogg_packet op;
  141858. _seek_helper(vf,best);
  141859. vf->pcm_offset=-1;
  141860. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141861. if(link!=vf->current_link){
  141862. _decode_clear(vf);
  141863. vf->current_link=link;
  141864. vf->current_serialno=ogg_page_serialno(&og);
  141865. vf->ready_state=STREAMSET;
  141866. }else{
  141867. vorbis_synthesis_restart(&vf->vd);
  141868. }
  141869. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141870. ogg_stream_pagein(&vf->os,&og);
  141871. while(1){
  141872. result=ogg_stream_packetpeek(&vf->os,&op);
  141873. if(result==0){
  141874. _seek_helper(vf,best);
  141875. while(1){
  141876. result=_get_prev_page(vf,&og);
  141877. if(result<0) goto seek_error;
  141878. if(ogg_page_granulepos(&og)>-1 ||
  141879. !ogg_page_continued(&og)){
  141880. return ov_raw_seek(vf,result);
  141881. }
  141882. vf->offset=result;
  141883. }
  141884. }
  141885. if(result<0){
  141886. result = OV_EBADPACKET;
  141887. goto seek_error;
  141888. }
  141889. if(op.granulepos!=-1){
  141890. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141891. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141892. vf->pcm_offset+=total;
  141893. break;
  141894. }else
  141895. result=ogg_stream_packetout(&vf->os,NULL);
  141896. }
  141897. }
  141898. }
  141899. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141900. result=OV_EFAULT;
  141901. goto seek_error;
  141902. }
  141903. vf->bittrack=0.f;
  141904. vf->samptrack=0.f;
  141905. return(0);
  141906. seek_error:
  141907. vf->pcm_offset=-1;
  141908. _decode_clear(vf);
  141909. return (int)result;
  141910. }
  141911. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141912. int thisblock,lastblock=0;
  141913. int ret=ov_pcm_seek_page(vf,pos);
  141914. if(ret<0)return(ret);
  141915. if((ret=_make_decode_ready(vf)))return ret;
  141916. while(1){
  141917. ogg_packet op;
  141918. ogg_page og;
  141919. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141920. if(ret>0){
  141921. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141922. if(thisblock<0){
  141923. ogg_stream_packetout(&vf->os,NULL);
  141924. continue; /* non audio packet */
  141925. }
  141926. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141927. if(vf->pcm_offset+((thisblock+
  141928. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141929. ogg_stream_packetout(&vf->os,NULL);
  141930. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141931. only tracking, no
  141932. pcm_decode */
  141933. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141934. if(op.granulepos>-1){
  141935. int i;
  141936. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141937. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141938. for(i=0;i<vf->current_link;i++)
  141939. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141940. }
  141941. lastblock=thisblock;
  141942. }else{
  141943. if(ret<0 && ret!=OV_HOLE)break;
  141944. if(_get_next_page(vf,&og,-1)<0)break;
  141945. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141946. if(vf->ready_state<STREAMSET){
  141947. int link;
  141948. vf->current_serialno=ogg_page_serialno(&og);
  141949. for(link=0;link<vf->links;link++)
  141950. if(vf->serialnos[link]==vf->current_serialno)break;
  141951. if(link==vf->links)return(OV_EBADLINK);
  141952. vf->current_link=link;
  141953. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141954. vf->ready_state=STREAMSET;
  141955. ret=_make_decode_ready(vf);
  141956. if(ret)return ret;
  141957. lastblock=0;
  141958. }
  141959. ogg_stream_pagein(&vf->os,&og);
  141960. }
  141961. }
  141962. vf->bittrack=0.f;
  141963. vf->samptrack=0.f;
  141964. while(vf->pcm_offset<pos){
  141965. ogg_int64_t target=pos-vf->pcm_offset;
  141966. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141967. if(samples>target)samples=target;
  141968. vorbis_synthesis_read(&vf->vd,samples);
  141969. vf->pcm_offset+=samples;
  141970. if(samples<target)
  141971. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141972. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141973. }
  141974. return 0;
  141975. }
  141976. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141977. int link=-1;
  141978. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141979. double time_total=ov_time_total(vf,-1);
  141980. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141981. if(!vf->seekable)return(OV_ENOSEEK);
  141982. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141983. for(link=vf->links-1;link>=0;link--){
  141984. pcm_total-=vf->pcmlengths[link*2+1];
  141985. time_total-=ov_time_total(vf,link);
  141986. if(seconds>=time_total)break;
  141987. }
  141988. {
  141989. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141990. return(ov_pcm_seek(vf,target));
  141991. }
  141992. }
  141993. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141994. int link=-1;
  141995. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141996. double time_total=ov_time_total(vf,-1);
  141997. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141998. if(!vf->seekable)return(OV_ENOSEEK);
  141999. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142000. for(link=vf->links-1;link>=0;link--){
  142001. pcm_total-=vf->pcmlengths[link*2+1];
  142002. time_total-=ov_time_total(vf,link);
  142003. if(seconds>=time_total)break;
  142004. }
  142005. {
  142006. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142007. return(ov_pcm_seek_page(vf,target));
  142008. }
  142009. }
  142010. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  142011. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142012. return(vf->offset);
  142013. }
  142014. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  142015. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142016. return(vf->pcm_offset);
  142017. }
  142018. double ov_time_tell(OggVorbis_File *vf){
  142019. int link=0;
  142020. ogg_int64_t pcm_total=0;
  142021. double time_total=0.f;
  142022. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142023. if(vf->seekable){
  142024. pcm_total=ov_pcm_total(vf,-1);
  142025. time_total=ov_time_total(vf,-1);
  142026. for(link=vf->links-1;link>=0;link--){
  142027. pcm_total-=vf->pcmlengths[link*2+1];
  142028. time_total-=ov_time_total(vf,link);
  142029. if(vf->pcm_offset>=pcm_total)break;
  142030. }
  142031. }
  142032. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  142033. }
  142034. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  142035. if(vf->seekable){
  142036. if(link<0)
  142037. if(vf->ready_state>=STREAMSET)
  142038. return vf->vi+vf->current_link;
  142039. else
  142040. return vf->vi;
  142041. else
  142042. if(link>=vf->links)
  142043. return NULL;
  142044. else
  142045. return vf->vi+link;
  142046. }else{
  142047. return vf->vi;
  142048. }
  142049. }
  142050. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  142051. if(vf->seekable){
  142052. if(link<0)
  142053. if(vf->ready_state>=STREAMSET)
  142054. return vf->vc+vf->current_link;
  142055. else
  142056. return vf->vc;
  142057. else
  142058. if(link>=vf->links)
  142059. return NULL;
  142060. else
  142061. return vf->vc+link;
  142062. }else{
  142063. return vf->vc;
  142064. }
  142065. }
  142066. static int host_is_big_endian() {
  142067. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  142068. unsigned char *bytewise = (unsigned char *)&pattern;
  142069. if (bytewise[0] == 0xfe) return 1;
  142070. return 0;
  142071. }
  142072. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  142073. int bigendianp,int word,int sgned,int *bitstream){
  142074. int i,j;
  142075. int host_endian = host_is_big_endian();
  142076. float **pcm;
  142077. long samples;
  142078. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142079. while(1){
  142080. if(vf->ready_state==INITSET){
  142081. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142082. if(samples)break;
  142083. }
  142084. {
  142085. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142086. if(ret==OV_EOF)
  142087. return(0);
  142088. if(ret<=0)
  142089. return(ret);
  142090. }
  142091. }
  142092. if(samples>0){
  142093. long channels=ov_info(vf,-1)->channels;
  142094. long bytespersample=word * channels;
  142095. vorbis_fpu_control fpu;
  142096. (void) fpu; // (to avoid a warning about it being unused)
  142097. if(samples>length/bytespersample)samples=length/bytespersample;
  142098. if(samples <= 0)
  142099. return OV_EINVAL;
  142100. {
  142101. int val;
  142102. if(word==1){
  142103. int off=(sgned?0:128);
  142104. vorbis_fpu_setround(&fpu);
  142105. for(j=0;j<samples;j++)
  142106. for(i=0;i<channels;i++){
  142107. val=vorbis_ftoi(pcm[i][j]*128.f);
  142108. if(val>127)val=127;
  142109. else if(val<-128)val=-128;
  142110. *buffer++=val+off;
  142111. }
  142112. vorbis_fpu_restore(fpu);
  142113. }else{
  142114. int off=(sgned?0:32768);
  142115. if(host_endian==bigendianp){
  142116. if(sgned){
  142117. vorbis_fpu_setround(&fpu);
  142118. for(i=0;i<channels;i++) { /* It's faster in this order */
  142119. float *src=pcm[i];
  142120. short *dest=((short *)buffer)+i;
  142121. for(j=0;j<samples;j++) {
  142122. val=vorbis_ftoi(src[j]*32768.f);
  142123. if(val>32767)val=32767;
  142124. else if(val<-32768)val=-32768;
  142125. *dest=val;
  142126. dest+=channels;
  142127. }
  142128. }
  142129. vorbis_fpu_restore(fpu);
  142130. }else{
  142131. vorbis_fpu_setround(&fpu);
  142132. for(i=0;i<channels;i++) {
  142133. float *src=pcm[i];
  142134. short *dest=((short *)buffer)+i;
  142135. for(j=0;j<samples;j++) {
  142136. val=vorbis_ftoi(src[j]*32768.f);
  142137. if(val>32767)val=32767;
  142138. else if(val<-32768)val=-32768;
  142139. *dest=val+off;
  142140. dest+=channels;
  142141. }
  142142. }
  142143. vorbis_fpu_restore(fpu);
  142144. }
  142145. }else if(bigendianp){
  142146. vorbis_fpu_setround(&fpu);
  142147. for(j=0;j<samples;j++)
  142148. for(i=0;i<channels;i++){
  142149. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142150. if(val>32767)val=32767;
  142151. else if(val<-32768)val=-32768;
  142152. val+=off;
  142153. *buffer++=(val>>8);
  142154. *buffer++=(val&0xff);
  142155. }
  142156. vorbis_fpu_restore(fpu);
  142157. }else{
  142158. int val;
  142159. vorbis_fpu_setround(&fpu);
  142160. for(j=0;j<samples;j++)
  142161. for(i=0;i<channels;i++){
  142162. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142163. if(val>32767)val=32767;
  142164. else if(val<-32768)val=-32768;
  142165. val+=off;
  142166. *buffer++=(val&0xff);
  142167. *buffer++=(val>>8);
  142168. }
  142169. vorbis_fpu_restore(fpu);
  142170. }
  142171. }
  142172. }
  142173. vorbis_synthesis_read(&vf->vd,samples);
  142174. vf->pcm_offset+=samples;
  142175. if(bitstream)*bitstream=vf->current_link;
  142176. return(samples*bytespersample);
  142177. }else{
  142178. return(samples);
  142179. }
  142180. }
  142181. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  142182. int *bitstream){
  142183. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142184. while(1){
  142185. if(vf->ready_state==INITSET){
  142186. float **pcm;
  142187. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142188. if(samples){
  142189. if(pcm_channels)*pcm_channels=pcm;
  142190. if(samples>length)samples=length;
  142191. vorbis_synthesis_read(&vf->vd,samples);
  142192. vf->pcm_offset+=samples;
  142193. if(bitstream)*bitstream=vf->current_link;
  142194. return samples;
  142195. }
  142196. }
  142197. {
  142198. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142199. if(ret==OV_EOF)return(0);
  142200. if(ret<=0)return(ret);
  142201. }
  142202. }
  142203. }
  142204. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  142205. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  142206. ogg_int64_t off);
  142207. static void _ov_splice(float **pcm,float **lappcm,
  142208. int n1, int n2,
  142209. int ch1, int ch2,
  142210. float *w1, float *w2){
  142211. int i,j;
  142212. float *w=w1;
  142213. int n=n1;
  142214. if(n1>n2){
  142215. n=n2;
  142216. w=w2;
  142217. }
  142218. for(j=0;j<ch1 && j<ch2;j++){
  142219. float *s=lappcm[j];
  142220. float *d=pcm[j];
  142221. for(i=0;i<n;i++){
  142222. float wd=w[i]*w[i];
  142223. float ws=1.-wd;
  142224. d[i]=d[i]*wd + s[i]*ws;
  142225. }
  142226. }
  142227. for(;j<ch2;j++){
  142228. float *d=pcm[j];
  142229. for(i=0;i<n;i++){
  142230. float wd=w[i]*w[i];
  142231. d[i]=d[i]*wd;
  142232. }
  142233. }
  142234. }
  142235. static int _ov_initset(OggVorbis_File *vf){
  142236. while(1){
  142237. if(vf->ready_state==INITSET)break;
  142238. {
  142239. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142240. if(ret<0 && ret!=OV_HOLE)return(ret);
  142241. }
  142242. }
  142243. return 0;
  142244. }
  142245. static int _ov_initprime(OggVorbis_File *vf){
  142246. vorbis_dsp_state *vd=&vf->vd;
  142247. while(1){
  142248. if(vf->ready_state==INITSET)
  142249. if(vorbis_synthesis_pcmout(vd,NULL))break;
  142250. {
  142251. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142252. if(ret<0 && ret!=OV_HOLE)return(ret);
  142253. }
  142254. }
  142255. return 0;
  142256. }
  142257. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  142258. float **lappcm,int lapsize){
  142259. int lapcount=0,i;
  142260. float **pcm;
  142261. while(lapcount<lapsize){
  142262. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  142263. if(samples){
  142264. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142265. for(i=0;i<vi->channels;i++)
  142266. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142267. lapcount+=samples;
  142268. vorbis_synthesis_read(vd,samples);
  142269. }else{
  142270. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  142271. if(ret==OV_EOF)break;
  142272. }
  142273. }
  142274. if(lapcount<lapsize){
  142275. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  142276. if(samples==0){
  142277. for(i=0;i<vi->channels;i++)
  142278. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  142279. lapcount=lapsize;
  142280. }else{
  142281. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142282. for(i=0;i<vi->channels;i++)
  142283. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142284. lapcount+=samples;
  142285. }
  142286. }
  142287. }
  142288. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142289. vorbis_info *vi1,*vi2;
  142290. float **lappcm;
  142291. float **pcm;
  142292. float *w1,*w2;
  142293. int n1,n2,i,ret,hs1,hs2;
  142294. if(vf1==vf2)return(0); /* degenerate case */
  142295. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142296. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142297. ret=_ov_initset(vf1);
  142298. if(ret)return(ret);
  142299. ret=_ov_initprime(vf2);
  142300. if(ret)return(ret);
  142301. vi1=ov_info(vf1,-1);
  142302. vi2=ov_info(vf2,-1);
  142303. hs1=ov_halfrate_p(vf1);
  142304. hs2=ov_halfrate_p(vf2);
  142305. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142306. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142307. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142308. w1=vorbis_window(&vf1->vd,0);
  142309. w2=vorbis_window(&vf2->vd,0);
  142310. for(i=0;i<vi1->channels;i++)
  142311. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142312. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142313. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142314. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142315. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142316. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142317. return(0);
  142318. }
  142319. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142320. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142321. vorbis_info *vi;
  142322. float **lappcm;
  142323. float **pcm;
  142324. float *w1,*w2;
  142325. int n1,n2,ch1,ch2,hs;
  142326. int i,ret;
  142327. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142328. ret=_ov_initset(vf);
  142329. if(ret)return(ret);
  142330. vi=ov_info(vf,-1);
  142331. hs=ov_halfrate_p(vf);
  142332. ch1=vi->channels;
  142333. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142334. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142335. persistent; even if the decode state
  142336. from this link gets dumped, this
  142337. window array continues to exist */
  142338. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142339. for(i=0;i<ch1;i++)
  142340. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142341. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142342. ret=localseek(vf,pos);
  142343. if(ret)return ret;
  142344. ret=_ov_initprime(vf);
  142345. if(ret)return(ret);
  142346. vi=ov_info(vf,-1);
  142347. ch2=vi->channels;
  142348. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142349. w2=vorbis_window(&vf->vd,0);
  142350. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142351. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142352. return(0);
  142353. }
  142354. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142355. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142356. }
  142357. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142358. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142359. }
  142360. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142361. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142362. }
  142363. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142364. int (*localseek)(OggVorbis_File *,double)){
  142365. vorbis_info *vi;
  142366. float **lappcm;
  142367. float **pcm;
  142368. float *w1,*w2;
  142369. int n1,n2,ch1,ch2,hs;
  142370. int i,ret;
  142371. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142372. ret=_ov_initset(vf);
  142373. if(ret)return(ret);
  142374. vi=ov_info(vf,-1);
  142375. hs=ov_halfrate_p(vf);
  142376. ch1=vi->channels;
  142377. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142378. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142379. persistent; even if the decode state
  142380. from this link gets dumped, this
  142381. window array continues to exist */
  142382. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142383. for(i=0;i<ch1;i++)
  142384. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142385. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142386. ret=localseek(vf,pos);
  142387. if(ret)return ret;
  142388. ret=_ov_initprime(vf);
  142389. if(ret)return(ret);
  142390. vi=ov_info(vf,-1);
  142391. ch2=vi->channels;
  142392. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142393. w2=vorbis_window(&vf->vd,0);
  142394. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142395. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142396. return(0);
  142397. }
  142398. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142399. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142400. }
  142401. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142402. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142403. }
  142404. #endif
  142405. /*** End of inlined file: vorbisfile.c ***/
  142406. /*** Start of inlined file: window.c ***/
  142407. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142408. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142409. // tasks..
  142410. #if JUCE_MSVC
  142411. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142412. #endif
  142413. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142414. #if JUCE_USE_OGGVORBIS
  142415. #include <stdlib.h>
  142416. #include <math.h>
  142417. static float vwin64[32] = {
  142418. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142419. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142420. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142421. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142422. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142423. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142424. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142425. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142426. };
  142427. static float vwin128[64] = {
  142428. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142429. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142430. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142431. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142432. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142433. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142434. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142435. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142436. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142437. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142438. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142439. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142440. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142441. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142442. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142443. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142444. };
  142445. static float vwin256[128] = {
  142446. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142447. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142448. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142449. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142450. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142451. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142452. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142453. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142454. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142455. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142456. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142457. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142458. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142459. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142460. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142461. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142462. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142463. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142464. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142465. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142466. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142467. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142468. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142469. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142470. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142471. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142472. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142473. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142474. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142475. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142476. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142477. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142478. };
  142479. static float vwin512[256] = {
  142480. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142481. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142482. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142483. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142484. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142485. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142486. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142487. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142488. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142489. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142490. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142491. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142492. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142493. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142494. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142495. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142496. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142497. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142498. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142499. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142500. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142501. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142502. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142503. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142504. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142505. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142506. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142507. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142508. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142509. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142510. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142511. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142512. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142513. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142514. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142515. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142516. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142517. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142518. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142519. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142520. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142521. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142522. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142523. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142524. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142525. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142526. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142527. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142528. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142529. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142530. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142531. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142532. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142533. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142534. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142535. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142536. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142537. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142538. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142539. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142540. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142541. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142542. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142543. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142544. };
  142545. static float vwin1024[512] = {
  142546. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142547. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142548. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142549. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142550. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142551. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142552. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142553. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142554. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142555. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142556. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142557. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142558. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142559. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142560. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142561. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142562. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142563. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142564. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142565. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142566. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142567. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142568. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142569. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142570. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142571. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142572. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142573. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142574. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142575. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142576. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142577. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142578. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142579. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142580. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142581. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142582. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142583. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142584. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142585. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142586. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142587. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142588. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142589. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142590. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142591. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142592. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142593. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142594. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142595. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142596. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142597. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142598. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142599. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142600. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142601. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142602. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142603. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142604. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142605. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142606. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142607. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142608. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142609. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142610. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142611. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142612. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142613. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142614. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142615. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142616. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142617. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142618. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142619. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142620. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142621. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142622. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142623. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142624. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142625. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142626. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142627. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142628. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142629. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142630. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142631. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142632. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142633. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142634. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142635. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142636. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142637. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142638. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142639. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142640. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142641. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142642. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142643. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142644. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142645. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142646. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142647. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142648. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142649. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142650. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142651. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142652. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142653. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142654. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142655. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142656. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142657. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142658. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142659. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142660. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142661. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142662. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142663. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142664. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142665. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142666. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142667. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142668. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142669. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142670. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142671. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142672. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142673. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142674. };
  142675. static float vwin2048[1024] = {
  142676. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142677. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142678. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142679. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142680. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142681. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142682. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142683. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142684. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142685. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142686. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142687. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142688. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142689. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142690. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142691. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142692. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142693. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142694. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142695. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142696. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142697. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142698. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142699. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142700. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142701. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142702. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142703. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142704. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142705. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142706. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142707. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142708. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142709. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142710. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142711. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142712. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142713. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142714. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142715. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142716. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142717. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142718. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142719. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142720. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142721. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142722. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142723. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142724. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142725. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142726. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142727. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142728. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142729. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142730. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142731. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142732. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142733. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142734. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142735. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142736. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142737. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142738. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142739. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142740. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142741. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142742. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142743. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142744. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142745. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142746. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142747. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142748. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142749. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142750. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142751. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142752. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142753. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142754. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142755. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142756. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142757. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142758. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142759. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142760. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142761. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142762. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142763. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142764. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142765. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142766. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142767. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142768. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142769. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142770. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142771. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142772. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142773. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142774. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142775. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142776. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142777. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142778. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142779. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142780. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142781. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142782. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142783. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142784. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142785. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142786. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142787. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142788. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142789. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142790. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142791. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142792. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142793. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142794. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142795. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142796. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142797. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142798. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142799. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142800. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142801. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142802. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142803. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142804. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142805. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142806. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142807. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142808. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142809. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142810. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142811. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142812. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142813. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142814. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142815. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142816. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142817. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142818. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142819. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142820. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142821. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142822. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142823. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142824. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142825. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142826. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142827. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142828. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142829. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142830. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142831. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142832. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142833. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142834. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142835. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142836. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142837. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142838. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142839. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142840. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142841. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142842. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142843. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142844. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142845. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142846. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142847. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142848. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142849. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142850. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142851. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142852. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142853. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142854. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142855. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142856. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142857. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142858. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142859. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142860. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142861. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142862. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142863. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142864. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142865. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142866. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142867. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142868. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142869. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142870. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142871. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142872. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142873. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142874. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142875. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142876. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142877. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142878. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142879. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142880. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142881. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142882. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142883. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142884. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142885. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142886. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142887. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142888. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142889. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142890. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142891. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142892. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142893. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142894. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142895. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142896. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142897. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142898. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142899. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142900. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142901. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142902. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142903. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142904. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142905. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142906. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142907. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142908. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142909. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142910. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142911. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142912. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142913. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142914. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142915. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142916. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142917. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142918. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142919. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142920. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142921. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142922. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142923. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142924. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142925. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142926. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142927. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142928. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142929. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142930. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142931. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142932. };
  142933. static float vwin4096[2048] = {
  142934. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142935. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142936. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142937. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142938. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142939. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142940. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142941. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142942. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142943. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142944. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142945. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142946. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142947. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142948. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142949. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142950. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142951. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142952. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142953. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142954. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142955. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142956. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142957. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142958. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142959. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142960. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142961. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142962. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142963. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142964. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142965. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142966. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142967. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142968. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142969. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142970. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142971. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142972. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142973. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142974. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142975. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142976. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142977. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142978. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142979. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142980. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142981. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142982. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142983. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142984. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142985. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142986. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142987. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142988. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142989. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142990. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142991. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142992. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142993. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142994. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142995. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142996. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142997. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142998. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142999. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  143000. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  143001. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  143002. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  143003. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  143004. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  143005. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  143006. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  143007. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  143008. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  143009. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  143010. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  143011. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  143012. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  143013. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  143014. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  143015. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  143016. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  143017. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  143018. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  143019. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  143020. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  143021. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  143022. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  143023. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  143024. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  143025. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  143026. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  143027. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  143028. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  143029. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  143030. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  143031. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  143032. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  143033. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  143034. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  143035. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  143036. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  143037. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  143038. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  143039. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  143040. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  143041. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  143042. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  143043. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  143044. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  143045. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  143046. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  143047. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  143048. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  143049. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  143050. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  143051. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  143052. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  143053. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  143054. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  143055. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  143056. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  143057. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  143058. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  143059. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  143060. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  143061. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  143062. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  143063. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  143064. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  143065. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  143066. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  143067. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  143068. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  143069. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  143070. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  143071. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  143072. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  143073. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  143074. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  143075. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  143076. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  143077. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  143078. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  143079. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  143080. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  143081. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  143082. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  143083. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  143084. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  143085. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  143086. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  143087. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  143088. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  143089. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  143090. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  143091. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  143092. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  143093. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  143094. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  143095. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  143096. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  143097. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  143098. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  143099. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  143100. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  143101. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  143102. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  143103. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  143104. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  143105. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  143106. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  143107. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  143108. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  143109. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  143110. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  143111. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  143112. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  143113. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  143114. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  143115. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  143116. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  143117. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  143118. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  143119. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  143120. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  143121. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  143122. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  143123. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  143124. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  143125. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  143126. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  143127. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  143128. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  143129. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  143130. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  143131. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  143132. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  143133. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  143134. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  143135. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  143136. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  143137. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  143138. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  143139. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  143140. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  143141. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  143142. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  143143. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  143144. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  143145. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  143146. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  143147. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  143148. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  143149. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  143150. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  143151. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  143152. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  143153. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  143154. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  143155. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  143156. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  143157. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  143158. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  143159. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  143160. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  143161. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  143162. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  143163. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  143164. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  143165. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  143166. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  143167. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  143168. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  143169. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  143170. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  143171. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  143172. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  143173. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  143174. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  143175. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  143176. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  143177. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  143178. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  143179. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  143180. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  143181. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  143182. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  143183. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  143184. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  143185. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  143186. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  143187. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  143188. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  143189. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  143190. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  143191. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  143192. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  143193. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  143194. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  143195. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  143196. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  143197. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  143198. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  143199. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  143200. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  143201. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  143202. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  143203. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  143204. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  143205. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  143206. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  143207. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  143208. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  143209. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  143210. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  143211. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  143212. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  143213. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  143214. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  143215. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  143216. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  143217. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  143218. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  143219. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  143220. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  143221. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  143222. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  143223. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  143224. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  143225. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  143226. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  143227. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  143228. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  143229. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  143230. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  143231. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  143232. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  143233. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  143234. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  143235. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  143236. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  143237. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  143238. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  143239. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  143240. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  143241. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  143242. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  143243. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  143244. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  143245. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  143246. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  143247. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  143248. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  143249. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  143250. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  143251. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  143252. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  143253. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  143254. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  143255. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  143256. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  143257. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  143258. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  143259. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  143260. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  143261. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  143262. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  143263. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  143264. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  143265. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  143266. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  143267. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  143268. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  143269. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  143270. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  143271. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  143272. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  143273. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  143274. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  143275. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  143276. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  143277. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  143278. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  143279. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  143280. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  143281. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  143282. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  143283. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  143284. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143285. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143286. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143287. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143288. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143289. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143290. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143291. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143292. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143293. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143294. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143295. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143296. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143297. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143298. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143299. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143300. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143301. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143302. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143303. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143304. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143305. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143306. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143307. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143308. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143309. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143310. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143311. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143312. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143313. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143314. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143315. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143316. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143317. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143318. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143319. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143320. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143321. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143322. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143323. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143324. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143325. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143326. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143327. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143328. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143329. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143330. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143331. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143332. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143333. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143334. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143335. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143336. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143337. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143338. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143339. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143340. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143341. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143342. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143343. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143344. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143345. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143346. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143347. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143348. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143349. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143350. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143351. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143352. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143353. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143354. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143355. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143356. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143357. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143358. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143359. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143360. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143361. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143362. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143363. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143364. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143365. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143366. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143367. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143368. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143369. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143370. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143371. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143372. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143373. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143374. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143375. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143376. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143377. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143378. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143379. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143380. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143381. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143382. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143383. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143384. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143385. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143386. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143387. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143388. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143389. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143390. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143391. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143392. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143393. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143394. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143395. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143396. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143397. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143398. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143399. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143400. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143401. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143402. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143403. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143404. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143405. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143406. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143407. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143408. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143409. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143410. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143411. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143412. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143413. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143414. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143415. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143416. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143417. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143418. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143419. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143420. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143421. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143422. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143423. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143424. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143425. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143426. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143427. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143428. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143429. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143430. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143431. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143432. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143433. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143434. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143435. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143436. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143437. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143438. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143439. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143440. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143441. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143442. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143443. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143444. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143445. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143446. };
  143447. static float vwin8192[4096] = {
  143448. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143449. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143450. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143451. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143452. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143453. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143454. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143455. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143456. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143457. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143458. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143459. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143460. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143461. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143462. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143463. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143464. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143465. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143466. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143467. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143468. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143469. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143470. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143471. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143472. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143473. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143474. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143475. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143476. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143477. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143478. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143479. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143480. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143481. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143482. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143483. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143484. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143485. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143486. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143487. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143488. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143489. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143490. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143491. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143492. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143493. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143494. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143495. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143496. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143497. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143498. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143499. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143500. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143501. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143502. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143503. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143504. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143505. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143506. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143507. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143508. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143509. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143510. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143511. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143512. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143513. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143514. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143515. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143516. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143517. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143518. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143519. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143520. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143521. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143522. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143523. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143524. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143525. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143526. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143527. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143528. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143529. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143530. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143531. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143532. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143533. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143534. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143535. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143536. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143537. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143538. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143539. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143540. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143541. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143542. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143543. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143544. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143545. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143546. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143547. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143548. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143549. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143550. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143551. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143552. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143553. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143554. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143555. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143556. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143557. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143558. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143559. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143560. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143561. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143562. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143563. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143564. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143565. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143566. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143567. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143568. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143569. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143570. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143571. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143572. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143573. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143574. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143575. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143576. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143577. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143578. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143579. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143580. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143581. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143582. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143583. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143584. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143585. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143586. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143587. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143588. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143589. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143590. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143591. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143592. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143593. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143594. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143595. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143596. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143597. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143598. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143599. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143600. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143601. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143602. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143603. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143604. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143605. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143606. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143607. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143608. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143609. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143610. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143611. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143612. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143613. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143614. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143615. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143616. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143617. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143618. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143619. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143620. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143621. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143622. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143623. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143624. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143625. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143626. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143627. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143628. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143629. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143630. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143631. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143632. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143633. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143634. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143635. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143636. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143637. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143638. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143639. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143640. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143641. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143642. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143643. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143644. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143645. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143646. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143647. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143648. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143649. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143650. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143651. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143652. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143653. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143654. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143655. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143656. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143657. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143658. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143659. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143660. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143661. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143662. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143663. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143664. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143665. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143666. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143667. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143668. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143669. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143670. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143671. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143672. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143673. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143674. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143675. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143676. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143677. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143678. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143679. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143680. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143681. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143682. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143683. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143684. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143685. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143686. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143687. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143688. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143689. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143690. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143691. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143692. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143693. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143694. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143695. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143696. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143697. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143698. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143699. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143700. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143701. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143702. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143703. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143704. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143705. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143706. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143707. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143708. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143709. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143710. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143711. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143712. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143713. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143714. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143715. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143716. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143717. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143718. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143719. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143720. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143721. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143722. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143723. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143724. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143725. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143726. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143727. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143728. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143729. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143730. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143731. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143732. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143733. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143734. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143735. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143736. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143737. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143738. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143739. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143740. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143741. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143742. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143743. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143744. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143745. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143746. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143747. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143748. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143749. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143750. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143751. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143752. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143753. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143754. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143755. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143756. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143757. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143758. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143759. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143760. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143761. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143762. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143763. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143764. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143765. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143766. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143767. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143768. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143769. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143770. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143771. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143772. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143773. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143774. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143775. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143776. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143777. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143778. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143779. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143780. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143781. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143782. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143783. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143784. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143785. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143786. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143787. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143788. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143789. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143790. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143791. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143792. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143793. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143794. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143795. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143796. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143797. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143798. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143799. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143800. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143801. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143802. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143803. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143804. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143805. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143806. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143807. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143808. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143809. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143810. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143811. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143812. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143813. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143814. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143815. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143816. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143817. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143818. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143819. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143820. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143821. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143822. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143823. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143824. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143825. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143826. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143827. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143828. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143829. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143830. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143831. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143832. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143833. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143834. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143835. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143836. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143837. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143838. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143839. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143840. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143841. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143842. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143843. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143844. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143845. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143846. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143847. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143848. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143849. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143850. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143851. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143852. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143853. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143854. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143855. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143856. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143857. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143858. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143859. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143860. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143861. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143862. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143863. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143864. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143865. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143866. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143867. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143868. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143869. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143870. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143871. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143872. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143873. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143874. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143875. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143876. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143877. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143878. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143879. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143880. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143881. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143882. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143883. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143884. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143885. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143886. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143887. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143888. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143889. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143890. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143891. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143892. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143893. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143894. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143895. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143896. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143897. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143898. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143899. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143900. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143901. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143902. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143903. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143904. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143905. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143906. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143907. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143908. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143909. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143910. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143911. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143912. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143913. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143914. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143915. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143916. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143917. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143918. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143919. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143920. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143921. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143922. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143923. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143924. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143925. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143926. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143927. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143928. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143929. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143930. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143931. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143932. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143933. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143934. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143935. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143936. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143937. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143938. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143939. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143940. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143941. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143942. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143943. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143944. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143945. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143946. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143947. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143948. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143949. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143950. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143951. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143952. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143953. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143954. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143955. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143956. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143957. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143958. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143959. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143960. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143961. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143962. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143963. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143964. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143965. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143966. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143967. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143968. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143969. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143970. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143971. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143972. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143973. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143974. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143975. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143976. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143977. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143978. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143979. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143980. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143981. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143982. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143983. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143984. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143985. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143986. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143987. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143988. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143989. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143990. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143991. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143992. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143993. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143994. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143995. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143996. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143997. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143998. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143999. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  144000. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  144001. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  144002. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  144003. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  144004. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  144005. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  144006. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  144007. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  144008. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  144009. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  144010. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  144011. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  144012. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  144013. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  144014. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  144015. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  144016. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  144017. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  144018. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  144019. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  144020. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  144021. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  144022. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  144023. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  144024. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  144025. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  144026. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  144027. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  144028. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  144029. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  144030. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  144031. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  144032. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  144033. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  144034. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  144035. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  144036. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  144037. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  144038. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  144039. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  144040. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  144041. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  144042. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  144043. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  144044. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  144045. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  144046. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  144047. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  144048. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  144049. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  144050. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  144051. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  144052. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  144053. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  144054. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  144055. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  144056. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  144057. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  144058. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  144059. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  144060. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  144061. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  144062. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  144063. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  144064. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  144065. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  144066. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  144067. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  144068. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  144069. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  144070. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  144071. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  144072. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  144073. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  144074. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  144075. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  144076. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  144077. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  144078. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  144079. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  144080. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  144081. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  144082. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  144083. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  144084. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  144085. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  144086. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  144087. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  144088. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  144089. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  144090. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  144091. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  144092. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  144093. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  144094. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  144095. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  144096. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  144097. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  144098. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  144099. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  144100. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  144101. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  144102. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  144103. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  144104. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  144105. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  144106. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  144107. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  144108. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  144109. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  144110. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  144111. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  144112. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  144113. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  144114. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  144115. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  144116. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  144117. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  144118. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  144119. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  144120. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  144121. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  144122. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  144123. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  144124. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  144125. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  144126. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  144127. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  144128. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  144129. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  144130. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  144131. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  144132. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  144133. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  144134. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  144135. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  144136. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  144137. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  144138. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  144139. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  144140. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  144141. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  144142. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  144143. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  144144. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  144145. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  144146. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  144147. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  144148. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  144149. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  144150. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  144151. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  144152. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  144153. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  144154. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  144155. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  144156. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  144157. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  144158. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  144159. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  144160. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  144161. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  144162. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  144163. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  144164. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  144165. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  144166. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  144167. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  144168. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  144169. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  144170. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  144171. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  144172. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  144173. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  144174. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  144175. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  144176. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  144177. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  144178. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  144179. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  144180. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  144181. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  144182. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  144183. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  144184. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  144185. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  144186. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  144187. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  144188. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  144189. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  144190. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  144191. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  144192. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  144193. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  144194. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  144195. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  144196. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  144197. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  144198. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  144199. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  144200. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  144201. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  144202. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  144203. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  144204. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  144205. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  144206. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  144207. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  144208. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  144209. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  144210. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  144211. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  144212. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  144213. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  144214. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  144215. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  144216. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  144217. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  144218. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  144219. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  144220. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  144221. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  144222. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  144223. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  144224. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  144225. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  144226. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  144227. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  144228. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  144229. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  144230. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  144231. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  144232. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  144233. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  144234. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  144235. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  144236. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  144237. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  144238. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  144239. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  144240. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  144241. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  144242. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  144243. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  144244. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  144245. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  144246. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  144247. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  144248. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  144249. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  144250. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  144251. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  144252. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  144253. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  144254. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  144255. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  144256. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  144257. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  144258. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  144259. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  144260. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  144261. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  144262. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  144263. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  144264. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  144265. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  144266. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  144267. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  144268. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  144269. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  144270. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  144271. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  144272. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  144273. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  144274. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  144275. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  144276. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  144277. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  144278. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  144279. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  144280. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  144281. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  144282. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  144283. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  144284. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144285. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144286. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144287. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144288. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144289. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144290. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144291. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144292. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144293. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144294. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144295. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144296. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144297. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144298. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144299. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144300. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144301. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144302. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144303. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144304. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144305. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144306. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144307. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144308. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144309. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144310. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144311. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144312. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144313. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144314. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144315. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144316. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144317. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144318. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144319. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144320. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144321. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144322. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144323. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144324. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144325. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144326. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144327. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144328. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144329. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144330. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144331. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144332. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144333. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144334. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144335. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144336. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144337. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144338. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144339. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144340. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144341. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144342. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144343. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144344. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144345. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144346. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144347. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144348. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144349. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144350. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144351. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144352. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144353. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144354. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144355. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144356. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144357. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144358. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144359. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144360. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144361. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144362. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144363. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144364. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144365. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144366. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144367. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144368. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144369. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144370. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144371. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144372. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144373. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144374. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144375. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144376. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144377. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144378. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144379. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144380. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144381. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144382. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144383. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144384. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144385. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144386. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144387. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144388. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144389. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144390. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144391. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144392. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144393. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144394. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144395. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144396. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144397. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144398. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144399. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144400. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144401. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144402. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144403. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144404. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144405. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144406. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144407. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144408. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144409. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144410. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144411. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144412. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144413. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144414. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144415. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144416. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144417. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144418. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144419. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144420. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144421. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144422. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144423. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144424. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144425. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144426. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144427. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144428. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144429. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144430. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144431. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144432. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144433. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144434. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144435. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144436. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144437. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144438. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144439. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144440. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144441. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144442. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144443. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144444. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144445. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144446. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144447. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144448. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144449. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144450. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144451. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144452. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144453. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144454. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144455. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144456. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144457. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144458. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144459. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144460. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144461. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144462. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144463. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144464. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144465. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144466. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144467. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144468. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144469. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144470. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144471. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144472. };
  144473. static float *vwin[8] = {
  144474. vwin64,
  144475. vwin128,
  144476. vwin256,
  144477. vwin512,
  144478. vwin1024,
  144479. vwin2048,
  144480. vwin4096,
  144481. vwin8192,
  144482. };
  144483. float *_vorbis_window_get(int n){
  144484. return vwin[n];
  144485. }
  144486. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144487. int lW,int W,int nW){
  144488. lW=(W?lW:0);
  144489. nW=(W?nW:0);
  144490. {
  144491. float *windowLW=vwin[winno[lW]];
  144492. float *windowNW=vwin[winno[nW]];
  144493. long n=blocksizes[W];
  144494. long ln=blocksizes[lW];
  144495. long rn=blocksizes[nW];
  144496. long leftbegin=n/4-ln/4;
  144497. long leftend=leftbegin+ln/2;
  144498. long rightbegin=n/2+n/4-rn/4;
  144499. long rightend=rightbegin+rn/2;
  144500. int i,p;
  144501. for(i=0;i<leftbegin;i++)
  144502. d[i]=0.f;
  144503. for(p=0;i<leftend;i++,p++)
  144504. d[i]*=windowLW[p];
  144505. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144506. d[i]*=windowNW[p];
  144507. for(;i<n;i++)
  144508. d[i]=0.f;
  144509. }
  144510. }
  144511. #endif
  144512. /*** End of inlined file: window.c ***/
  144513. #else
  144514. #include <vorbis/vorbisenc.h>
  144515. #include <vorbis/codec.h>
  144516. #include <vorbis/vorbisfile.h>
  144517. #endif
  144518. }
  144519. BEGIN_JUCE_NAMESPACE
  144520. using namespace OggVorbisNamespace;
  144521. static const char* const oggFormatName = "Ogg-Vorbis file";
  144522. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144523. class OggReader : public AudioFormatReader
  144524. {
  144525. OggVorbis_File ovFile;
  144526. ov_callbacks callbacks;
  144527. AudioSampleBuffer reservoir;
  144528. int reservoirStart, samplesInReservoir;
  144529. public:
  144530. OggReader (InputStream* const inp)
  144531. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144532. reservoir (2, 4096),
  144533. reservoirStart (0),
  144534. samplesInReservoir (0)
  144535. {
  144536. sampleRate = 0;
  144537. usesFloatingPointData = true;
  144538. callbacks.read_func = &oggReadCallback;
  144539. callbacks.seek_func = &oggSeekCallback;
  144540. callbacks.close_func = &oggCloseCallback;
  144541. callbacks.tell_func = &oggTellCallback;
  144542. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144543. if (err == 0)
  144544. {
  144545. vorbis_info* info = ov_info (&ovFile, -1);
  144546. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144547. numChannels = info->channels;
  144548. bitsPerSample = 16;
  144549. sampleRate = info->rate;
  144550. reservoir.setSize (numChannels,
  144551. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144552. }
  144553. }
  144554. ~OggReader()
  144555. {
  144556. ov_clear (&ovFile);
  144557. }
  144558. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144559. int64 startSampleInFile, int numSamples)
  144560. {
  144561. while (numSamples > 0)
  144562. {
  144563. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144564. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144565. {
  144566. // got a few samples overlapping, so use them before seeking..
  144567. const int numToUse = jmin (numSamples, numAvailable);
  144568. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144569. if (destSamples[i] != 0)
  144570. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144571. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144572. sizeof (float) * numToUse);
  144573. startSampleInFile += numToUse;
  144574. numSamples -= numToUse;
  144575. startOffsetInDestBuffer += numToUse;
  144576. if (numSamples == 0)
  144577. break;
  144578. }
  144579. if (startSampleInFile < reservoirStart
  144580. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144581. {
  144582. // buffer miss, so refill the reservoir
  144583. int bitStream = 0;
  144584. reservoirStart = jmax (0, (int) startSampleInFile);
  144585. samplesInReservoir = reservoir.getNumSamples();
  144586. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  144587. ov_pcm_seek (&ovFile, reservoirStart);
  144588. int offset = 0;
  144589. int numToRead = samplesInReservoir;
  144590. while (numToRead > 0)
  144591. {
  144592. float** dataIn = 0;
  144593. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144594. if (samps <= 0)
  144595. break;
  144596. jassert (samps <= numToRead);
  144597. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144598. {
  144599. memcpy (reservoir.getSampleData (i, offset),
  144600. dataIn[i],
  144601. sizeof (float) * samps);
  144602. }
  144603. numToRead -= samps;
  144604. offset += samps;
  144605. }
  144606. if (numToRead > 0)
  144607. reservoir.clear (offset, numToRead);
  144608. }
  144609. }
  144610. if (numSamples > 0)
  144611. {
  144612. for (int i = numDestChannels; --i >= 0;)
  144613. if (destSamples[i] != 0)
  144614. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144615. sizeof (int) * numSamples);
  144616. }
  144617. return true;
  144618. }
  144619. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144620. {
  144621. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144622. }
  144623. static int oggSeekCallback (void* datasource, ogg_int64_t offset, int whence)
  144624. {
  144625. InputStream* const in = (InputStream*) datasource;
  144626. if (whence == SEEK_CUR)
  144627. offset += in->getPosition();
  144628. else if (whence == SEEK_END)
  144629. offset += in->getTotalLength();
  144630. in->setPosition (offset);
  144631. return 0;
  144632. }
  144633. static int oggCloseCallback (void*)
  144634. {
  144635. return 0;
  144636. }
  144637. static long oggTellCallback (void* datasource)
  144638. {
  144639. return (long) ((InputStream*) datasource)->getPosition();
  144640. }
  144641. juce_UseDebuggingNewOperator
  144642. };
  144643. class OggWriter : public AudioFormatWriter
  144644. {
  144645. ogg_stream_state os;
  144646. ogg_page og;
  144647. ogg_packet op;
  144648. vorbis_info vi;
  144649. vorbis_comment vc;
  144650. vorbis_dsp_state vd;
  144651. vorbis_block vb;
  144652. public:
  144653. bool ok;
  144654. OggWriter (OutputStream* const out,
  144655. const double sampleRate,
  144656. const int numChannels,
  144657. const int bitsPerSample,
  144658. const int qualityIndex)
  144659. : AudioFormatWriter (out, TRANS (oggFormatName),
  144660. sampleRate,
  144661. numChannels,
  144662. bitsPerSample)
  144663. {
  144664. ok = false;
  144665. vorbis_info_init (&vi);
  144666. if (vorbis_encode_init_vbr (&vi,
  144667. numChannels,
  144668. (int) sampleRate,
  144669. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144670. {
  144671. vorbis_comment_init (&vc);
  144672. if (JUCEApplication::getInstance() != 0)
  144673. vorbis_comment_add_tag (&vc, "ENCODER",
  144674. (char*) (const char*) JUCEApplication::getInstance()->getApplicationName());
  144675. vorbis_analysis_init (&vd, &vi);
  144676. vorbis_block_init (&vd, &vb);
  144677. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144678. ogg_packet header;
  144679. ogg_packet header_comm;
  144680. ogg_packet header_code;
  144681. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144682. ogg_stream_packetin (&os, &header);
  144683. ogg_stream_packetin (&os, &header_comm);
  144684. ogg_stream_packetin (&os, &header_code);
  144685. for (;;)
  144686. {
  144687. if (ogg_stream_flush (&os, &og) == 0)
  144688. break;
  144689. output->write (og.header, og.header_len);
  144690. output->write (og.body, og.body_len);
  144691. }
  144692. ok = true;
  144693. }
  144694. }
  144695. ~OggWriter()
  144696. {
  144697. if (ok)
  144698. {
  144699. // write a zero-length packet to show ogg that we're finished..
  144700. write (0, 0);
  144701. ogg_stream_clear (&os);
  144702. vorbis_block_clear (&vb);
  144703. vorbis_dsp_clear (&vd);
  144704. vorbis_comment_clear (&vc);
  144705. vorbis_info_clear (&vi);
  144706. output->flush();
  144707. }
  144708. else
  144709. {
  144710. vorbis_info_clear (&vi);
  144711. output = 0; // to stop the base class deleting this, as it needs to be returned
  144712. // to the caller of createWriter()
  144713. }
  144714. }
  144715. bool write (const int** samplesToWrite, int numSamples)
  144716. {
  144717. if (! ok)
  144718. return false;
  144719. if (numSamples > 0)
  144720. {
  144721. const double gain = 1.0 / 0x80000000u;
  144722. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144723. for (int i = numChannels; --i >= 0;)
  144724. {
  144725. float* const dst = vorbisBuffer[i];
  144726. const int* const src = samplesToWrite [i];
  144727. if (src != 0 && dst != 0)
  144728. {
  144729. for (int j = 0; j < numSamples; ++j)
  144730. dst[j] = (float) (src[j] * gain);
  144731. }
  144732. }
  144733. }
  144734. vorbis_analysis_wrote (&vd, numSamples);
  144735. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144736. {
  144737. vorbis_analysis (&vb, 0);
  144738. vorbis_bitrate_addblock (&vb);
  144739. while (vorbis_bitrate_flushpacket (&vd, &op))
  144740. {
  144741. ogg_stream_packetin (&os, &op);
  144742. for (;;)
  144743. {
  144744. if (ogg_stream_pageout (&os, &og) == 0)
  144745. break;
  144746. output->write (og.header, og.header_len);
  144747. output->write (og.body, og.body_len);
  144748. if (ogg_page_eos (&og))
  144749. break;
  144750. }
  144751. }
  144752. }
  144753. return true;
  144754. }
  144755. juce_UseDebuggingNewOperator
  144756. };
  144757. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144758. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  144759. {
  144760. }
  144761. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144762. {
  144763. }
  144764. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144765. {
  144766. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144767. return Array <int> (rates);
  144768. }
  144769. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144770. {
  144771. Array <int> depths;
  144772. depths.add (32);
  144773. return depths;
  144774. }
  144775. bool OggVorbisAudioFormat::canDoStereo()
  144776. {
  144777. return true;
  144778. }
  144779. bool OggVorbisAudioFormat::canDoMono()
  144780. {
  144781. return true;
  144782. }
  144783. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144784. const bool deleteStreamIfOpeningFails)
  144785. {
  144786. ScopedPointer <OggReader> r (new OggReader (in));
  144787. if (r->sampleRate != 0)
  144788. return r.release();
  144789. if (! deleteStreamIfOpeningFails)
  144790. r->input = 0;
  144791. return 0;
  144792. }
  144793. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144794. double sampleRate,
  144795. unsigned int numChannels,
  144796. int bitsPerSample,
  144797. const StringPairArray& /*metadataValues*/,
  144798. int qualityOptionIndex)
  144799. {
  144800. ScopedPointer <OggWriter> w (new OggWriter (out,
  144801. sampleRate,
  144802. numChannels,
  144803. bitsPerSample,
  144804. qualityOptionIndex));
  144805. return w->ok ? w.release() : 0;
  144806. }
  144807. bool OggVorbisAudioFormat::isCompressed()
  144808. {
  144809. return true;
  144810. }
  144811. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144812. {
  144813. StringArray s;
  144814. s.add ("Low Quality");
  144815. s.add ("Medium Quality");
  144816. s.add ("High Quality");
  144817. return s;
  144818. }
  144819. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144820. {
  144821. FileInputStream* const in = source.createInputStream();
  144822. if (in != 0)
  144823. {
  144824. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144825. if (r != 0)
  144826. {
  144827. const int64 numSamps = r->lengthInSamples;
  144828. r = 0;
  144829. const int64 fileNumSamps = source.getSize() / 4;
  144830. const double ratio = numSamps / (double) fileNumSamps;
  144831. if (ratio > 12.0)
  144832. return 0;
  144833. else if (ratio > 6.0)
  144834. return 1;
  144835. else
  144836. return 2;
  144837. }
  144838. }
  144839. return 1;
  144840. }
  144841. END_JUCE_NAMESPACE
  144842. #endif
  144843. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144844. #endif
  144845. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144846. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144847. #if JUCE_MSVC
  144848. #pragma warning (push)
  144849. #endif
  144850. namespace jpeglibNamespace
  144851. {
  144852. #if JUCE_INCLUDE_JPEGLIB_CODE
  144853. #if JUCE_MINGW
  144854. typedef unsigned char boolean;
  144855. #endif
  144856. extern "C"
  144857. {
  144858. #define JPEG_INTERNALS
  144859. #undef FAR
  144860. /*** Start of inlined file: jpeglib.h ***/
  144861. #ifndef JPEGLIB_H
  144862. #define JPEGLIB_H
  144863. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144864. /*** Start of inlined file: jconfig.h ***/
  144865. // disable all the warnings under MSVC
  144866. #ifdef _MSC_VER
  144867. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144868. #endif
  144869. #ifdef __BORLANDC__
  144870. #pragma warn -8057
  144871. #pragma warn -8019
  144872. #pragma warn -8004
  144873. #pragma warn -8008
  144874. #endif
  144875. #define HAVE_PROTOTYPES
  144876. #define HAVE_UNSIGNED_CHAR
  144877. #define HAVE_UNSIGNED_SHORT
  144878. #undef CHAR_IS_UNSIGNED
  144879. #define HAVE_STDDEF_H
  144880. #define HAVE_STDLIB_H
  144881. #undef NEED_BSD_STRINGS
  144882. #undef NEED_SYS_TYPES_H
  144883. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144884. #undef NEED_SHORT_EXTERNAL_NAMES
  144885. #undef INCOMPLETE_TYPES_BROKEN
  144886. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144887. typedef unsigned char boolean;
  144888. #endif
  144889. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144890. #ifdef JPEG_INTERNALS
  144891. #undef RIGHT_SHIFT_IS_UNSIGNED
  144892. #endif /* JPEG_INTERNALS */
  144893. #ifdef JPEG_CJPEG_DJPEG
  144894. #define BMP_SUPPORTED /* BMP image file format */
  144895. #define GIF_SUPPORTED /* GIF image file format */
  144896. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144897. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144898. #define TARGA_SUPPORTED /* Targa image file format */
  144899. #define TWO_FILE_COMMANDLINE /* optional */
  144900. #define USE_SETMODE /* Microsoft has setmode() */
  144901. #undef NEED_SIGNAL_CATCHER
  144902. #undef DONT_USE_B_MODE
  144903. #undef PROGRESS_REPORT /* optional */
  144904. #endif /* JPEG_CJPEG_DJPEG */
  144905. /*** End of inlined file: jconfig.h ***/
  144906. /* widely used configuration options */
  144907. #endif
  144908. /*** Start of inlined file: jmorecfg.h ***/
  144909. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144910. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144911. #if BITS_IN_JSAMPLE == 8
  144912. #ifdef HAVE_UNSIGNED_CHAR
  144913. typedef unsigned char JSAMPLE;
  144914. #define GETJSAMPLE(value) ((int) (value))
  144915. #else /* not HAVE_UNSIGNED_CHAR */
  144916. typedef char JSAMPLE;
  144917. #ifdef CHAR_IS_UNSIGNED
  144918. #define GETJSAMPLE(value) ((int) (value))
  144919. #else
  144920. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144921. #endif /* CHAR_IS_UNSIGNED */
  144922. #endif /* HAVE_UNSIGNED_CHAR */
  144923. #define MAXJSAMPLE 255
  144924. #define CENTERJSAMPLE 128
  144925. #endif /* BITS_IN_JSAMPLE == 8 */
  144926. #if BITS_IN_JSAMPLE == 12
  144927. typedef short JSAMPLE;
  144928. #define GETJSAMPLE(value) ((int) (value))
  144929. #define MAXJSAMPLE 4095
  144930. #define CENTERJSAMPLE 2048
  144931. #endif /* BITS_IN_JSAMPLE == 12 */
  144932. typedef short JCOEF;
  144933. #ifdef HAVE_UNSIGNED_CHAR
  144934. typedef unsigned char JOCTET;
  144935. #define GETJOCTET(value) (value)
  144936. #else /* not HAVE_UNSIGNED_CHAR */
  144937. typedef char JOCTET;
  144938. #ifdef CHAR_IS_UNSIGNED
  144939. #define GETJOCTET(value) (value)
  144940. #else
  144941. #define GETJOCTET(value) ((value) & 0xFF)
  144942. #endif /* CHAR_IS_UNSIGNED */
  144943. #endif /* HAVE_UNSIGNED_CHAR */
  144944. #ifdef HAVE_UNSIGNED_CHAR
  144945. typedef unsigned char UINT8;
  144946. #else /* not HAVE_UNSIGNED_CHAR */
  144947. #ifdef CHAR_IS_UNSIGNED
  144948. typedef char UINT8;
  144949. #else /* not CHAR_IS_UNSIGNED */
  144950. typedef short UINT8;
  144951. #endif /* CHAR_IS_UNSIGNED */
  144952. #endif /* HAVE_UNSIGNED_CHAR */
  144953. #ifdef HAVE_UNSIGNED_SHORT
  144954. typedef unsigned short UINT16;
  144955. #else /* not HAVE_UNSIGNED_SHORT */
  144956. typedef unsigned int UINT16;
  144957. #endif /* HAVE_UNSIGNED_SHORT */
  144958. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144959. typedef short INT16;
  144960. #endif
  144961. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144962. typedef long INT32;
  144963. #endif
  144964. typedef unsigned int JDIMENSION;
  144965. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144966. #define METHODDEF(type) static type
  144967. #define LOCAL(type) static type
  144968. #define GLOBAL(type) type
  144969. #define EXTERN(type) extern type
  144970. #ifdef HAVE_PROTOTYPES
  144971. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144972. #else
  144973. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144974. #endif
  144975. #ifdef NEED_FAR_POINTERS
  144976. #define FAR far
  144977. #else
  144978. #define FAR
  144979. #endif
  144980. #ifndef HAVE_BOOLEAN
  144981. typedef int boolean;
  144982. #endif
  144983. #ifndef FALSE /* in case these macros already exist */
  144984. #define FALSE 0 /* values of boolean */
  144985. #endif
  144986. #ifndef TRUE
  144987. #define TRUE 1
  144988. #endif
  144989. #ifdef JPEG_INTERNALS
  144990. #define JPEG_INTERNAL_OPTIONS
  144991. #endif
  144992. #ifdef JPEG_INTERNAL_OPTIONS
  144993. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144994. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144995. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144996. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144997. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144998. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144999. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  145000. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  145001. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145002. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145003. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145004. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  145005. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  145006. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  145007. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  145008. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  145009. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  145010. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  145011. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  145012. #define RGB_GREEN 1 /* Offset of Green */
  145013. #define RGB_BLUE 2 /* Offset of Blue */
  145014. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  145015. #ifndef INLINE
  145016. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  145017. #define INLINE __inline__
  145018. #endif
  145019. #ifndef INLINE
  145020. #define INLINE /* default is to define it as empty */
  145021. #endif
  145022. #endif
  145023. #ifndef MULTIPLIER
  145024. #define MULTIPLIER int /* type for fastest integer multiply */
  145025. #endif
  145026. #ifndef FAST_FLOAT
  145027. #ifdef HAVE_PROTOTYPES
  145028. #define FAST_FLOAT float
  145029. #else
  145030. #define FAST_FLOAT double
  145031. #endif
  145032. #endif
  145033. #endif /* JPEG_INTERNAL_OPTIONS */
  145034. /*** End of inlined file: jmorecfg.h ***/
  145035. /* seldom changed options */
  145036. #define JPEG_LIB_VERSION 62 /* Version 6b */
  145037. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  145038. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  145039. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  145040. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  145041. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  145042. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  145043. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  145044. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  145045. #ifndef D_MAX_BLOCKS_IN_MCU
  145046. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  145047. #endif
  145048. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  145049. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  145050. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  145051. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  145052. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  145053. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  145054. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  145055. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  145056. typedef struct {
  145057. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  145058. boolean sent_table; /* TRUE when table has been output */
  145059. } JQUANT_TBL;
  145060. typedef struct {
  145061. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  145062. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  145063. boolean sent_table; /* TRUE when table has been output */
  145064. } JHUFF_TBL;
  145065. typedef struct {
  145066. int component_id; /* identifier for this component (0..255) */
  145067. int component_index; /* its index in SOF or cinfo->comp_info[] */
  145068. int h_samp_factor; /* horizontal sampling factor (1..4) */
  145069. int v_samp_factor; /* vertical sampling factor (1..4) */
  145070. int quant_tbl_no; /* quantization table selector (0..3) */
  145071. int dc_tbl_no; /* DC entropy table selector (0..3) */
  145072. int ac_tbl_no; /* AC entropy table selector (0..3) */
  145073. JDIMENSION width_in_blocks;
  145074. JDIMENSION height_in_blocks;
  145075. int DCT_scaled_size;
  145076. JDIMENSION downsampled_width; /* actual width in samples */
  145077. JDIMENSION downsampled_height; /* actual height in samples */
  145078. boolean component_needed; /* do we need the value of this component? */
  145079. int MCU_width; /* number of blocks per MCU, horizontally */
  145080. int MCU_height; /* number of blocks per MCU, vertically */
  145081. int MCU_blocks; /* MCU_width * MCU_height */
  145082. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  145083. int last_col_width; /* # of non-dummy blocks across in last MCU */
  145084. int last_row_height; /* # of non-dummy blocks down in last MCU */
  145085. JQUANT_TBL * quant_table;
  145086. void * dct_table;
  145087. } jpeg_component_info;
  145088. typedef struct {
  145089. int comps_in_scan; /* number of components encoded in this scan */
  145090. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  145091. int Ss, Se; /* progressive JPEG spectral selection parms */
  145092. int Ah, Al; /* progressive JPEG successive approx. parms */
  145093. } jpeg_scan_info;
  145094. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  145095. struct jpeg_marker_struct {
  145096. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  145097. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  145098. unsigned int original_length; /* # bytes of data in the file */
  145099. unsigned int data_length; /* # bytes of data saved at data[] */
  145100. JOCTET FAR * data; /* the data contained in the marker */
  145101. };
  145102. typedef enum {
  145103. JCS_UNKNOWN, /* error/unspecified */
  145104. JCS_GRAYSCALE, /* monochrome */
  145105. JCS_RGB, /* red/green/blue */
  145106. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  145107. JCS_CMYK, /* C/M/Y/K */
  145108. JCS_YCCK /* Y/Cb/Cr/K */
  145109. } J_COLOR_SPACE;
  145110. typedef enum {
  145111. JDCT_ISLOW, /* slow but accurate integer algorithm */
  145112. JDCT_IFAST, /* faster, less accurate integer method */
  145113. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  145114. } J_DCT_METHOD;
  145115. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  145116. #define JDCT_DEFAULT JDCT_ISLOW
  145117. #endif
  145118. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  145119. #define JDCT_FASTEST JDCT_IFAST
  145120. #endif
  145121. typedef enum {
  145122. JDITHER_NONE, /* no dithering */
  145123. JDITHER_ORDERED, /* simple ordered dither */
  145124. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  145125. } J_DITHER_MODE;
  145126. #define jpeg_common_fields \
  145127. struct jpeg_error_mgr * err; /* Error handler module */\
  145128. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  145129. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  145130. void * client_data; /* Available for use by application */\
  145131. boolean is_decompressor; /* So common code can tell which is which */\
  145132. int global_state /* For checking call sequence validity */
  145133. struct jpeg_common_struct {
  145134. jpeg_common_fields; /* Fields common to both master struct types */
  145135. };
  145136. typedef struct jpeg_common_struct * j_common_ptr;
  145137. typedef struct jpeg_compress_struct * j_compress_ptr;
  145138. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  145139. struct jpeg_compress_struct {
  145140. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  145141. struct jpeg_destination_mgr * dest;
  145142. JDIMENSION image_width; /* input image width */
  145143. JDIMENSION image_height; /* input image height */
  145144. int input_components; /* # of color components in input image */
  145145. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  145146. double input_gamma; /* image gamma of input image */
  145147. int data_precision; /* bits of precision in image data */
  145148. int num_components; /* # of color components in JPEG image */
  145149. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145150. jpeg_component_info * comp_info;
  145151. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145152. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145153. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145154. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145155. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145156. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145157. int num_scans; /* # of entries in scan_info array */
  145158. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  145159. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  145160. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145161. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  145162. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145163. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  145164. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  145165. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  145166. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  145167. boolean write_JFIF_header; /* should a JFIF marker be written? */
  145168. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  145169. UINT8 JFIF_minor_version;
  145170. UINT8 density_unit; /* JFIF code for pixel size units */
  145171. UINT16 X_density; /* Horizontal pixel density */
  145172. UINT16 Y_density; /* Vertical pixel density */
  145173. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  145174. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  145175. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  145176. int max_h_samp_factor; /* largest h_samp_factor */
  145177. int max_v_samp_factor; /* largest v_samp_factor */
  145178. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  145179. int comps_in_scan; /* # of JPEG components in this scan */
  145180. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145181. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145182. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145183. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145184. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  145185. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145186. struct jpeg_comp_master * master;
  145187. struct jpeg_c_main_controller * main;
  145188. struct jpeg_c_prep_controller * prep;
  145189. struct jpeg_c_coef_controller * coef;
  145190. struct jpeg_marker_writer * marker;
  145191. struct jpeg_color_converter * cconvert;
  145192. struct jpeg_downsampler * downsample;
  145193. struct jpeg_forward_dct * fdct;
  145194. struct jpeg_entropy_encoder * entropy;
  145195. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  145196. int script_space_size;
  145197. };
  145198. struct jpeg_decompress_struct {
  145199. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  145200. struct jpeg_source_mgr * src;
  145201. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  145202. JDIMENSION image_height; /* nominal image height */
  145203. int num_components; /* # of color components in JPEG image */
  145204. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145205. J_COLOR_SPACE out_color_space; /* colorspace for output */
  145206. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  145207. double output_gamma; /* image gamma wanted in output */
  145208. boolean buffered_image; /* TRUE=multiple output passes */
  145209. boolean raw_data_out; /* TRUE=downsampled data wanted */
  145210. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  145211. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  145212. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  145213. boolean quantize_colors; /* TRUE=colormapped output wanted */
  145214. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  145215. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  145216. int desired_number_of_colors; /* max # colors to use in created colormap */
  145217. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  145218. boolean enable_external_quant;/* enable future use of external colormap */
  145219. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  145220. JDIMENSION output_width; /* scaled image width */
  145221. JDIMENSION output_height; /* scaled image height */
  145222. int out_color_components; /* # of color components in out_color_space */
  145223. int output_components; /* # of color components returned */
  145224. int rec_outbuf_height; /* min recommended height of scanline buffer */
  145225. int actual_number_of_colors; /* number of entries in use */
  145226. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  145227. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  145228. int input_scan_number; /* Number of SOS markers seen so far */
  145229. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  145230. int output_scan_number; /* Nominal scan number being displayed */
  145231. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  145232. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  145233. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145234. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145235. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145236. int data_precision; /* bits of precision in image data */
  145237. jpeg_component_info * comp_info;
  145238. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  145239. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145240. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145241. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145242. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145243. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  145244. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  145245. UINT8 JFIF_major_version; /* JFIF version number */
  145246. UINT8 JFIF_minor_version;
  145247. UINT8 density_unit; /* JFIF code for pixel size units */
  145248. UINT16 X_density; /* Horizontal pixel density */
  145249. UINT16 Y_density; /* Vertical pixel density */
  145250. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  145251. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  145252. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145253. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  145254. int max_h_samp_factor; /* largest h_samp_factor */
  145255. int max_v_samp_factor; /* largest v_samp_factor */
  145256. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  145257. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  145258. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  145259. int comps_in_scan; /* # of JPEG components in this scan */
  145260. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145261. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145262. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145263. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145264. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  145265. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145266. int unread_marker;
  145267. struct jpeg_decomp_master * master;
  145268. struct jpeg_d_main_controller * main;
  145269. struct jpeg_d_coef_controller * coef;
  145270. struct jpeg_d_post_controller * post;
  145271. struct jpeg_input_controller * inputctl;
  145272. struct jpeg_marker_reader * marker;
  145273. struct jpeg_entropy_decoder * entropy;
  145274. struct jpeg_inverse_dct * idct;
  145275. struct jpeg_upsampler * upsample;
  145276. struct jpeg_color_deconverter * cconvert;
  145277. struct jpeg_color_quantizer * cquantize;
  145278. };
  145279. struct jpeg_error_mgr {
  145280. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  145281. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  145282. JMETHOD(void, output_message, (j_common_ptr cinfo));
  145283. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  145284. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  145285. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145286. int msg_code;
  145287. #define JMSG_STR_PARM_MAX 80
  145288. union {
  145289. int i[8];
  145290. char s[JMSG_STR_PARM_MAX];
  145291. } msg_parm;
  145292. int trace_level; /* max msg_level that will be displayed */
  145293. long num_warnings; /* number of corrupt-data warnings */
  145294. const char * const * jpeg_message_table; /* Library errors */
  145295. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145296. const char * const * addon_message_table; /* Non-library errors */
  145297. int first_addon_message; /* code for first string in addon table */
  145298. int last_addon_message; /* code for last string in addon table */
  145299. };
  145300. struct jpeg_progress_mgr {
  145301. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145302. long pass_counter; /* work units completed in this pass */
  145303. long pass_limit; /* total number of work units in this pass */
  145304. int completed_passes; /* passes completed so far */
  145305. int total_passes; /* total number of passes expected */
  145306. };
  145307. struct jpeg_destination_mgr {
  145308. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145309. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145310. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145311. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145312. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145313. };
  145314. struct jpeg_source_mgr {
  145315. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145316. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145317. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145318. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145319. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145320. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145321. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145322. };
  145323. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145324. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145325. #define JPOOL_NUMPOOLS 2
  145326. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145327. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145328. struct jpeg_memory_mgr {
  145329. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145330. size_t sizeofobject));
  145331. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145332. size_t sizeofobject));
  145333. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145334. JDIMENSION samplesperrow,
  145335. JDIMENSION numrows));
  145336. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145337. JDIMENSION blocksperrow,
  145338. JDIMENSION numrows));
  145339. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145340. int pool_id,
  145341. boolean pre_zero,
  145342. JDIMENSION samplesperrow,
  145343. JDIMENSION numrows,
  145344. JDIMENSION maxaccess));
  145345. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145346. int pool_id,
  145347. boolean pre_zero,
  145348. JDIMENSION blocksperrow,
  145349. JDIMENSION numrows,
  145350. JDIMENSION maxaccess));
  145351. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145352. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145353. jvirt_sarray_ptr ptr,
  145354. JDIMENSION start_row,
  145355. JDIMENSION num_rows,
  145356. boolean writable));
  145357. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145358. jvirt_barray_ptr ptr,
  145359. JDIMENSION start_row,
  145360. JDIMENSION num_rows,
  145361. boolean writable));
  145362. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145363. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145364. long max_memory_to_use;
  145365. long max_alloc_chunk;
  145366. };
  145367. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145368. #ifdef HAVE_PROTOTYPES
  145369. #define JPP(arglist) arglist
  145370. #else
  145371. #define JPP(arglist) ()
  145372. #endif
  145373. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145374. #define jpeg_std_error jStdError
  145375. #define jpeg_CreateCompress jCreaCompress
  145376. #define jpeg_CreateDecompress jCreaDecompress
  145377. #define jpeg_destroy_compress jDestCompress
  145378. #define jpeg_destroy_decompress jDestDecompress
  145379. #define jpeg_stdio_dest jStdDest
  145380. #define jpeg_stdio_src jStdSrc
  145381. #define jpeg_set_defaults jSetDefaults
  145382. #define jpeg_set_colorspace jSetColorspace
  145383. #define jpeg_default_colorspace jDefColorspace
  145384. #define jpeg_set_quality jSetQuality
  145385. #define jpeg_set_linear_quality jSetLQuality
  145386. #define jpeg_add_quant_table jAddQuantTable
  145387. #define jpeg_quality_scaling jQualityScaling
  145388. #define jpeg_simple_progression jSimProgress
  145389. #define jpeg_suppress_tables jSuppressTables
  145390. #define jpeg_alloc_quant_table jAlcQTable
  145391. #define jpeg_alloc_huff_table jAlcHTable
  145392. #define jpeg_start_compress jStrtCompress
  145393. #define jpeg_write_scanlines jWrtScanlines
  145394. #define jpeg_finish_compress jFinCompress
  145395. #define jpeg_write_raw_data jWrtRawData
  145396. #define jpeg_write_marker jWrtMarker
  145397. #define jpeg_write_m_header jWrtMHeader
  145398. #define jpeg_write_m_byte jWrtMByte
  145399. #define jpeg_write_tables jWrtTables
  145400. #define jpeg_read_header jReadHeader
  145401. #define jpeg_start_decompress jStrtDecompress
  145402. #define jpeg_read_scanlines jReadScanlines
  145403. #define jpeg_finish_decompress jFinDecompress
  145404. #define jpeg_read_raw_data jReadRawData
  145405. #define jpeg_has_multiple_scans jHasMultScn
  145406. #define jpeg_start_output jStrtOutput
  145407. #define jpeg_finish_output jFinOutput
  145408. #define jpeg_input_complete jInComplete
  145409. #define jpeg_new_colormap jNewCMap
  145410. #define jpeg_consume_input jConsumeInput
  145411. #define jpeg_calc_output_dimensions jCalcDimensions
  145412. #define jpeg_save_markers jSaveMarkers
  145413. #define jpeg_set_marker_processor jSetMarker
  145414. #define jpeg_read_coefficients jReadCoefs
  145415. #define jpeg_write_coefficients jWrtCoefs
  145416. #define jpeg_copy_critical_parameters jCopyCrit
  145417. #define jpeg_abort_compress jAbrtCompress
  145418. #define jpeg_abort_decompress jAbrtDecompress
  145419. #define jpeg_abort jAbort
  145420. #define jpeg_destroy jDestroy
  145421. #define jpeg_resync_to_restart jResyncRestart
  145422. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145423. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145424. JPP((struct jpeg_error_mgr * err));
  145425. #define jpeg_create_compress(cinfo) \
  145426. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145427. (size_t) sizeof(struct jpeg_compress_struct))
  145428. #define jpeg_create_decompress(cinfo) \
  145429. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145430. (size_t) sizeof(struct jpeg_decompress_struct))
  145431. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145432. int version, size_t structsize));
  145433. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145434. int version, size_t structsize));
  145435. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145436. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145437. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145438. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145439. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145440. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145441. J_COLOR_SPACE colorspace));
  145442. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145443. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145444. boolean force_baseline));
  145445. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145446. int scale_factor,
  145447. boolean force_baseline));
  145448. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145449. const unsigned int *basic_table,
  145450. int scale_factor,
  145451. boolean force_baseline));
  145452. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145453. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145454. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145455. boolean suppress));
  145456. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145457. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145458. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145459. boolean write_all_tables));
  145460. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145461. JSAMPARRAY scanlines,
  145462. JDIMENSION num_lines));
  145463. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145464. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145465. JSAMPIMAGE data,
  145466. JDIMENSION num_lines));
  145467. EXTERN(void) jpeg_write_marker
  145468. JPP((j_compress_ptr cinfo, int marker,
  145469. const JOCTET * dataptr, unsigned int datalen));
  145470. EXTERN(void) jpeg_write_m_header
  145471. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145472. EXTERN(void) jpeg_write_m_byte
  145473. JPP((j_compress_ptr cinfo, int val));
  145474. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145475. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145476. boolean require_image));
  145477. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145478. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145479. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145480. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145481. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145482. JSAMPARRAY scanlines,
  145483. JDIMENSION max_lines));
  145484. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145485. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145486. JSAMPIMAGE data,
  145487. JDIMENSION max_lines));
  145488. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145489. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145490. int scan_number));
  145491. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145492. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145493. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145494. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145495. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145496. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145497. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145498. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145499. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145500. EXTERN(void) jpeg_save_markers
  145501. JPP((j_decompress_ptr cinfo, int marker_code,
  145502. unsigned int length_limit));
  145503. EXTERN(void) jpeg_set_marker_processor
  145504. JPP((j_decompress_ptr cinfo, int marker_code,
  145505. jpeg_marker_parser_method routine));
  145506. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145507. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145508. jvirt_barray_ptr * coef_arrays));
  145509. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145510. j_compress_ptr dstinfo));
  145511. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145512. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145513. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145514. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145515. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145516. int desired));
  145517. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145518. #define JPEG_EOI 0xD9 /* EOI marker code */
  145519. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145520. #define JPEG_COM 0xFE /* COM marker code */
  145521. #ifdef INCOMPLETE_TYPES_BROKEN
  145522. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145523. struct jvirt_sarray_control { long dummy; };
  145524. struct jvirt_barray_control { long dummy; };
  145525. struct jpeg_comp_master { long dummy; };
  145526. struct jpeg_c_main_controller { long dummy; };
  145527. struct jpeg_c_prep_controller { long dummy; };
  145528. struct jpeg_c_coef_controller { long dummy; };
  145529. struct jpeg_marker_writer { long dummy; };
  145530. struct jpeg_color_converter { long dummy; };
  145531. struct jpeg_downsampler { long dummy; };
  145532. struct jpeg_forward_dct { long dummy; };
  145533. struct jpeg_entropy_encoder { long dummy; };
  145534. struct jpeg_decomp_master { long dummy; };
  145535. struct jpeg_d_main_controller { long dummy; };
  145536. struct jpeg_d_coef_controller { long dummy; };
  145537. struct jpeg_d_post_controller { long dummy; };
  145538. struct jpeg_input_controller { long dummy; };
  145539. struct jpeg_marker_reader { long dummy; };
  145540. struct jpeg_entropy_decoder { long dummy; };
  145541. struct jpeg_inverse_dct { long dummy; };
  145542. struct jpeg_upsampler { long dummy; };
  145543. struct jpeg_color_deconverter { long dummy; };
  145544. struct jpeg_color_quantizer { long dummy; };
  145545. #endif /* JPEG_INTERNALS */
  145546. #endif /* INCOMPLETE_TYPES_BROKEN */
  145547. #ifdef JPEG_INTERNALS
  145548. /*** Start of inlined file: jpegint.h ***/
  145549. typedef enum { /* Operating modes for buffer controllers */
  145550. JBUF_PASS_THRU, /* Plain stripwise operation */
  145551. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145552. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145553. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145554. } J_BUF_MODE;
  145555. #define CSTATE_START 100 /* after create_compress */
  145556. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145557. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145558. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145559. #define DSTATE_START 200 /* after create_decompress */
  145560. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145561. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145562. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145563. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145564. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145565. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145566. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145567. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145568. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145569. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145570. struct jpeg_comp_master {
  145571. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145572. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145573. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145574. boolean call_pass_startup; /* True if pass_startup must be called */
  145575. boolean is_last_pass; /* True during last pass */
  145576. };
  145577. struct jpeg_c_main_controller {
  145578. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145579. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145580. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145581. JDIMENSION in_rows_avail));
  145582. };
  145583. struct jpeg_c_prep_controller {
  145584. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145585. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145586. JSAMPARRAY input_buf,
  145587. JDIMENSION *in_row_ctr,
  145588. JDIMENSION in_rows_avail,
  145589. JSAMPIMAGE output_buf,
  145590. JDIMENSION *out_row_group_ctr,
  145591. JDIMENSION out_row_groups_avail));
  145592. };
  145593. struct jpeg_c_coef_controller {
  145594. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145595. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145596. JSAMPIMAGE input_buf));
  145597. };
  145598. struct jpeg_color_converter {
  145599. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145600. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145601. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145602. JDIMENSION output_row, int num_rows));
  145603. };
  145604. struct jpeg_downsampler {
  145605. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145606. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145607. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145608. JSAMPIMAGE output_buf,
  145609. JDIMENSION out_row_group_index));
  145610. boolean need_context_rows; /* TRUE if need rows above & below */
  145611. };
  145612. struct jpeg_forward_dct {
  145613. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145614. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145615. jpeg_component_info * compptr,
  145616. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145617. JDIMENSION start_row, JDIMENSION start_col,
  145618. JDIMENSION num_blocks));
  145619. };
  145620. struct jpeg_entropy_encoder {
  145621. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145622. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145623. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145624. };
  145625. struct jpeg_marker_writer {
  145626. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145627. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145628. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145629. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145630. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145631. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145632. unsigned int datalen));
  145633. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145634. };
  145635. struct jpeg_decomp_master {
  145636. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145637. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145638. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145639. };
  145640. struct jpeg_input_controller {
  145641. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145642. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145643. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145644. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145645. boolean has_multiple_scans; /* True if file has multiple scans */
  145646. boolean eoi_reached; /* True when EOI has been consumed */
  145647. };
  145648. struct jpeg_d_main_controller {
  145649. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145650. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145651. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145652. JDIMENSION out_rows_avail));
  145653. };
  145654. struct jpeg_d_coef_controller {
  145655. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145656. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145657. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145658. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145659. JSAMPIMAGE output_buf));
  145660. jvirt_barray_ptr *coef_arrays;
  145661. };
  145662. struct jpeg_d_post_controller {
  145663. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145664. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145665. JSAMPIMAGE input_buf,
  145666. JDIMENSION *in_row_group_ctr,
  145667. JDIMENSION in_row_groups_avail,
  145668. JSAMPARRAY output_buf,
  145669. JDIMENSION *out_row_ctr,
  145670. JDIMENSION out_rows_avail));
  145671. };
  145672. struct jpeg_marker_reader {
  145673. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145674. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145675. jpeg_marker_parser_method read_restart_marker;
  145676. boolean saw_SOI; /* found SOI? */
  145677. boolean saw_SOF; /* found SOF? */
  145678. int next_restart_num; /* next restart number expected (0-7) */
  145679. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145680. };
  145681. struct jpeg_entropy_decoder {
  145682. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145683. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145684. JBLOCKROW *MCU_data));
  145685. boolean insufficient_data; /* set TRUE after emitting warning */
  145686. };
  145687. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145688. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145689. JCOEFPTR coef_block,
  145690. JSAMPARRAY output_buf, JDIMENSION output_col));
  145691. struct jpeg_inverse_dct {
  145692. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145693. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145694. };
  145695. struct jpeg_upsampler {
  145696. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145697. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145698. JSAMPIMAGE input_buf,
  145699. JDIMENSION *in_row_group_ctr,
  145700. JDIMENSION in_row_groups_avail,
  145701. JSAMPARRAY output_buf,
  145702. JDIMENSION *out_row_ctr,
  145703. JDIMENSION out_rows_avail));
  145704. boolean need_context_rows; /* TRUE if need rows above & below */
  145705. };
  145706. struct jpeg_color_deconverter {
  145707. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145708. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145709. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145710. JSAMPARRAY output_buf, int num_rows));
  145711. };
  145712. struct jpeg_color_quantizer {
  145713. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145714. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145715. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145716. int num_rows));
  145717. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145718. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145719. };
  145720. #undef MAX
  145721. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145722. #undef MIN
  145723. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145724. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145725. #define SHIFT_TEMPS INT32 shift_temp;
  145726. #define RIGHT_SHIFT(x,shft) \
  145727. ((shift_temp = (x)) < 0 ? \
  145728. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145729. (shift_temp >> (shft)))
  145730. #else
  145731. #define SHIFT_TEMPS
  145732. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145733. #endif
  145734. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145735. #define jinit_compress_master jICompress
  145736. #define jinit_c_master_control jICMaster
  145737. #define jinit_c_main_controller jICMainC
  145738. #define jinit_c_prep_controller jICPrepC
  145739. #define jinit_c_coef_controller jICCoefC
  145740. #define jinit_color_converter jICColor
  145741. #define jinit_downsampler jIDownsampler
  145742. #define jinit_forward_dct jIFDCT
  145743. #define jinit_huff_encoder jIHEncoder
  145744. #define jinit_phuff_encoder jIPHEncoder
  145745. #define jinit_marker_writer jIMWriter
  145746. #define jinit_master_decompress jIDMaster
  145747. #define jinit_d_main_controller jIDMainC
  145748. #define jinit_d_coef_controller jIDCoefC
  145749. #define jinit_d_post_controller jIDPostC
  145750. #define jinit_input_controller jIInCtlr
  145751. #define jinit_marker_reader jIMReader
  145752. #define jinit_huff_decoder jIHDecoder
  145753. #define jinit_phuff_decoder jIPHDecoder
  145754. #define jinit_inverse_dct jIIDCT
  145755. #define jinit_upsampler jIUpsampler
  145756. #define jinit_color_deconverter jIDColor
  145757. #define jinit_1pass_quantizer jI1Quant
  145758. #define jinit_2pass_quantizer jI2Quant
  145759. #define jinit_merged_upsampler jIMUpsampler
  145760. #define jinit_memory_mgr jIMemMgr
  145761. #define jdiv_round_up jDivRound
  145762. #define jround_up jRound
  145763. #define jcopy_sample_rows jCopySamples
  145764. #define jcopy_block_row jCopyBlocks
  145765. #define jzero_far jZeroFar
  145766. #define jpeg_zigzag_order jZIGTable
  145767. #define jpeg_natural_order jZAGTable
  145768. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145769. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145770. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145771. boolean transcode_only));
  145772. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145773. boolean need_full_buffer));
  145774. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145775. boolean need_full_buffer));
  145776. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145777. boolean need_full_buffer));
  145778. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145779. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145780. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145781. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145782. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145783. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145784. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145785. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145786. boolean need_full_buffer));
  145787. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145788. boolean need_full_buffer));
  145789. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145790. boolean need_full_buffer));
  145791. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145792. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145793. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145794. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145795. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145796. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145797. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145798. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145799. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145800. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145801. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145802. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145803. EXTERN(long) jround_up JPP((long a, long b));
  145804. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145805. JSAMPARRAY output_array, int dest_row,
  145806. int num_rows, JDIMENSION num_cols));
  145807. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145808. JDIMENSION num_blocks));
  145809. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145810. #if 0 /* This table is not actually needed in v6a */
  145811. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145812. #endif
  145813. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145814. #ifdef INCOMPLETE_TYPES_BROKEN
  145815. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145816. struct jvirt_sarray_control { long dummy; };
  145817. struct jvirt_barray_control { long dummy; };
  145818. #endif
  145819. #endif /* INCOMPLETE_TYPES_BROKEN */
  145820. /*** End of inlined file: jpegint.h ***/
  145821. /* fetch private declarations */
  145822. /*** Start of inlined file: jerror.h ***/
  145823. #ifndef JMESSAGE
  145824. #ifndef JERROR_H
  145825. #define JMAKE_ENUM_LIST
  145826. #else
  145827. #define JMESSAGE(code,string)
  145828. #endif /* JERROR_H */
  145829. #endif /* JMESSAGE */
  145830. #ifdef JMAKE_ENUM_LIST
  145831. typedef enum {
  145832. #define JMESSAGE(code,string) code ,
  145833. #endif /* JMAKE_ENUM_LIST */
  145834. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145835. JMESSAGE(JERR_ARITH_NOTIMPL,
  145836. "Sorry, there are legal restrictions on arithmetic coding")
  145837. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145838. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145839. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145840. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145841. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145842. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145843. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145844. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145845. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145846. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145847. JMESSAGE(JERR_BAD_LIB_VERSION,
  145848. "Wrong JPEG library version: library is %d, caller expects %d")
  145849. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145850. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145851. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145852. JMESSAGE(JERR_BAD_PROGRESSION,
  145853. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145854. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145855. "Invalid progressive parameters at scan script entry %d")
  145856. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145857. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145858. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145859. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145860. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145861. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145862. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145863. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145864. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145865. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145866. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145867. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145868. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145869. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145870. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145871. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145872. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145873. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145874. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145875. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145876. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145877. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145878. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145879. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145880. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145881. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145882. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145883. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145884. "Cannot transcode due to multiple use of quantization table %d")
  145885. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145886. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145887. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145888. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145889. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145890. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145891. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145892. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145893. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145894. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145895. JMESSAGE(JERR_QUANT_COMPONENTS,
  145896. "Cannot quantize more than %d color components")
  145897. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145898. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145899. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145900. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145901. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145902. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145903. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145904. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145905. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145906. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145907. JMESSAGE(JERR_TFILE_WRITE,
  145908. "Write failed on temporary file --- out of disk space?")
  145909. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145910. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145911. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145912. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145913. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145914. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145915. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145916. JMESSAGE(JMSG_VERSION, JVERSION)
  145917. JMESSAGE(JTRC_16BIT_TABLES,
  145918. "Caution: quantization tables are too coarse for baseline JPEG")
  145919. JMESSAGE(JTRC_ADOBE,
  145920. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145921. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145922. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145923. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145924. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145925. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145926. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145927. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145928. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145929. JMESSAGE(JTRC_EOI, "End Of Image")
  145930. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145931. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145932. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145933. "Warning: thumbnail image size does not match data length %u")
  145934. JMESSAGE(JTRC_JFIF_EXTENSION,
  145935. "JFIF extension marker: type 0x%02x, length %u")
  145936. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145937. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145938. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145939. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145940. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145941. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145942. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145943. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145944. JMESSAGE(JTRC_RST, "RST%d")
  145945. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145946. "Smoothing not supported with nonstandard sampling ratios")
  145947. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145948. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145949. JMESSAGE(JTRC_SOI, "Start of Image")
  145950. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145951. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145952. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145953. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145954. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145955. JMESSAGE(JTRC_THUMB_JPEG,
  145956. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145957. JMESSAGE(JTRC_THUMB_PALETTE,
  145958. "JFIF extension marker: palette thumbnail image, length %u")
  145959. JMESSAGE(JTRC_THUMB_RGB,
  145960. "JFIF extension marker: RGB thumbnail image, length %u")
  145961. JMESSAGE(JTRC_UNKNOWN_IDS,
  145962. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145963. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145964. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145965. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145966. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145967. "Inconsistent progression sequence for component %d coefficient %d")
  145968. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145969. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145970. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145971. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145972. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145973. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145974. JMESSAGE(JWRN_MUST_RESYNC,
  145975. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145976. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145977. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145978. #ifdef JMAKE_ENUM_LIST
  145979. JMSG_LASTMSGCODE
  145980. } J_MESSAGE_CODE;
  145981. #undef JMAKE_ENUM_LIST
  145982. #endif /* JMAKE_ENUM_LIST */
  145983. #undef JMESSAGE
  145984. #ifndef JERROR_H
  145985. #define JERROR_H
  145986. #define ERREXIT(cinfo,code) \
  145987. ((cinfo)->err->msg_code = (code), \
  145988. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145989. #define ERREXIT1(cinfo,code,p1) \
  145990. ((cinfo)->err->msg_code = (code), \
  145991. (cinfo)->err->msg_parm.i[0] = (p1), \
  145992. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145993. #define ERREXIT2(cinfo,code,p1,p2) \
  145994. ((cinfo)->err->msg_code = (code), \
  145995. (cinfo)->err->msg_parm.i[0] = (p1), \
  145996. (cinfo)->err->msg_parm.i[1] = (p2), \
  145997. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145998. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145999. ((cinfo)->err->msg_code = (code), \
  146000. (cinfo)->err->msg_parm.i[0] = (p1), \
  146001. (cinfo)->err->msg_parm.i[1] = (p2), \
  146002. (cinfo)->err->msg_parm.i[2] = (p3), \
  146003. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146004. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  146005. ((cinfo)->err->msg_code = (code), \
  146006. (cinfo)->err->msg_parm.i[0] = (p1), \
  146007. (cinfo)->err->msg_parm.i[1] = (p2), \
  146008. (cinfo)->err->msg_parm.i[2] = (p3), \
  146009. (cinfo)->err->msg_parm.i[3] = (p4), \
  146010. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146011. #define ERREXITS(cinfo,code,str) \
  146012. ((cinfo)->err->msg_code = (code), \
  146013. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146014. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146015. #define MAKESTMT(stuff) do { stuff } while (0)
  146016. #define WARNMS(cinfo,code) \
  146017. ((cinfo)->err->msg_code = (code), \
  146018. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146019. #define WARNMS1(cinfo,code,p1) \
  146020. ((cinfo)->err->msg_code = (code), \
  146021. (cinfo)->err->msg_parm.i[0] = (p1), \
  146022. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146023. #define WARNMS2(cinfo,code,p1,p2) \
  146024. ((cinfo)->err->msg_code = (code), \
  146025. (cinfo)->err->msg_parm.i[0] = (p1), \
  146026. (cinfo)->err->msg_parm.i[1] = (p2), \
  146027. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146028. #define TRACEMS(cinfo,lvl,code) \
  146029. ((cinfo)->err->msg_code = (code), \
  146030. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146031. #define TRACEMS1(cinfo,lvl,code,p1) \
  146032. ((cinfo)->err->msg_code = (code), \
  146033. (cinfo)->err->msg_parm.i[0] = (p1), \
  146034. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146035. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  146036. ((cinfo)->err->msg_code = (code), \
  146037. (cinfo)->err->msg_parm.i[0] = (p1), \
  146038. (cinfo)->err->msg_parm.i[1] = (p2), \
  146039. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146040. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  146041. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146042. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  146043. (cinfo)->err->msg_code = (code); \
  146044. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146045. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  146046. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146047. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146048. (cinfo)->err->msg_code = (code); \
  146049. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146050. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  146051. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146052. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146053. _mp[4] = (p5); \
  146054. (cinfo)->err->msg_code = (code); \
  146055. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146056. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  146057. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146058. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146059. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  146060. (cinfo)->err->msg_code = (code); \
  146061. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146062. #define TRACEMSS(cinfo,lvl,code,str) \
  146063. ((cinfo)->err->msg_code = (code), \
  146064. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146065. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146066. #endif /* JERROR_H */
  146067. /*** End of inlined file: jerror.h ***/
  146068. /* fetch error codes too */
  146069. #endif
  146070. #endif /* JPEGLIB_H */
  146071. /*** End of inlined file: jpeglib.h ***/
  146072. /*** Start of inlined file: jcapimin.c ***/
  146073. #define JPEG_INTERNALS
  146074. /*** Start of inlined file: jinclude.h ***/
  146075. #ifndef __jinclude_h__
  146076. #define __jinclude_h__
  146077. /*** Start of inlined file: jconfig.h ***/
  146078. // disable all the warnings under MSVC
  146079. #ifdef _MSC_VER
  146080. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  146081. #endif
  146082. #ifdef __BORLANDC__
  146083. #pragma warn -8057
  146084. #pragma warn -8019
  146085. #pragma warn -8004
  146086. #pragma warn -8008
  146087. #endif
  146088. #define HAVE_PROTOTYPES
  146089. #define HAVE_UNSIGNED_CHAR
  146090. #define HAVE_UNSIGNED_SHORT
  146091. #undef CHAR_IS_UNSIGNED
  146092. #define HAVE_STDDEF_H
  146093. #define HAVE_STDLIB_H
  146094. #undef NEED_BSD_STRINGS
  146095. #undef NEED_SYS_TYPES_H
  146096. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  146097. #undef NEED_SHORT_EXTERNAL_NAMES
  146098. #undef INCOMPLETE_TYPES_BROKEN
  146099. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  146100. typedef unsigned char boolean;
  146101. #endif
  146102. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  146103. #ifdef JPEG_INTERNALS
  146104. #undef RIGHT_SHIFT_IS_UNSIGNED
  146105. #endif /* JPEG_INTERNALS */
  146106. #ifdef JPEG_CJPEG_DJPEG
  146107. #define BMP_SUPPORTED /* BMP image file format */
  146108. #define GIF_SUPPORTED /* GIF image file format */
  146109. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  146110. #undef RLE_SUPPORTED /* Utah RLE image file format */
  146111. #define TARGA_SUPPORTED /* Targa image file format */
  146112. #define TWO_FILE_COMMANDLINE /* optional */
  146113. #define USE_SETMODE /* Microsoft has setmode() */
  146114. #undef NEED_SIGNAL_CATCHER
  146115. #undef DONT_USE_B_MODE
  146116. #undef PROGRESS_REPORT /* optional */
  146117. #endif /* JPEG_CJPEG_DJPEG */
  146118. /*** End of inlined file: jconfig.h ***/
  146119. /* auto configuration options */
  146120. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  146121. #ifdef HAVE_STDDEF_H
  146122. #include <stddef.h>
  146123. #endif
  146124. #ifdef HAVE_STDLIB_H
  146125. #include <stdlib.h>
  146126. #endif
  146127. #ifdef NEED_SYS_TYPES_H
  146128. #include <sys/types.h>
  146129. #endif
  146130. #include <stdio.h>
  146131. #ifdef NEED_BSD_STRINGS
  146132. #include <strings.h>
  146133. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  146134. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  146135. #else /* not BSD, assume ANSI/SysV string lib */
  146136. #include <string.h>
  146137. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  146138. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  146139. #endif
  146140. #define SIZEOF(object) ((size_t) sizeof(object))
  146141. #define JFREAD(file,buf,sizeofbuf) \
  146142. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146143. #define JFWRITE(file,buf,sizeofbuf) \
  146144. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146145. typedef enum { /* JPEG marker codes */
  146146. M_SOF0 = 0xc0,
  146147. M_SOF1 = 0xc1,
  146148. M_SOF2 = 0xc2,
  146149. M_SOF3 = 0xc3,
  146150. M_SOF5 = 0xc5,
  146151. M_SOF6 = 0xc6,
  146152. M_SOF7 = 0xc7,
  146153. M_JPG = 0xc8,
  146154. M_SOF9 = 0xc9,
  146155. M_SOF10 = 0xca,
  146156. M_SOF11 = 0xcb,
  146157. M_SOF13 = 0xcd,
  146158. M_SOF14 = 0xce,
  146159. M_SOF15 = 0xcf,
  146160. M_DHT = 0xc4,
  146161. M_DAC = 0xcc,
  146162. M_RST0 = 0xd0,
  146163. M_RST1 = 0xd1,
  146164. M_RST2 = 0xd2,
  146165. M_RST3 = 0xd3,
  146166. M_RST4 = 0xd4,
  146167. M_RST5 = 0xd5,
  146168. M_RST6 = 0xd6,
  146169. M_RST7 = 0xd7,
  146170. M_SOI = 0xd8,
  146171. M_EOI = 0xd9,
  146172. M_SOS = 0xda,
  146173. M_DQT = 0xdb,
  146174. M_DNL = 0xdc,
  146175. M_DRI = 0xdd,
  146176. M_DHP = 0xde,
  146177. M_EXP = 0xdf,
  146178. M_APP0 = 0xe0,
  146179. M_APP1 = 0xe1,
  146180. M_APP2 = 0xe2,
  146181. M_APP3 = 0xe3,
  146182. M_APP4 = 0xe4,
  146183. M_APP5 = 0xe5,
  146184. M_APP6 = 0xe6,
  146185. M_APP7 = 0xe7,
  146186. M_APP8 = 0xe8,
  146187. M_APP9 = 0xe9,
  146188. M_APP10 = 0xea,
  146189. M_APP11 = 0xeb,
  146190. M_APP12 = 0xec,
  146191. M_APP13 = 0xed,
  146192. M_APP14 = 0xee,
  146193. M_APP15 = 0xef,
  146194. M_JPG0 = 0xf0,
  146195. M_JPG13 = 0xfd,
  146196. M_COM = 0xfe,
  146197. M_TEM = 0x01,
  146198. M_ERROR = 0x100
  146199. } JPEG_MARKER;
  146200. #ifdef AVOID_TABLES
  146201. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  146202. #else
  146203. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  146204. static const int extend_test[16] = /* entry n is 2**(n-1) */
  146205. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  146206. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  146207. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  146208. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  146209. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  146210. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  146211. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  146212. #endif /* AVOID_TABLES */
  146213. #endif
  146214. /*** End of inlined file: jinclude.h ***/
  146215. GLOBAL(void)
  146216. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  146217. {
  146218. int i;
  146219. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  146220. if (version != JPEG_LIB_VERSION)
  146221. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  146222. if (structsize != SIZEOF(struct jpeg_compress_struct))
  146223. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  146224. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  146225. {
  146226. struct jpeg_error_mgr * err = cinfo->err;
  146227. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  146228. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  146229. cinfo->err = err;
  146230. cinfo->client_data = client_data;
  146231. }
  146232. cinfo->is_decompressor = FALSE;
  146233. jinit_memory_mgr((j_common_ptr) cinfo);
  146234. cinfo->progress = NULL;
  146235. cinfo->dest = NULL;
  146236. cinfo->comp_info = NULL;
  146237. for (i = 0; i < NUM_QUANT_TBLS; i++)
  146238. cinfo->quant_tbl_ptrs[i] = NULL;
  146239. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146240. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  146241. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  146242. }
  146243. cinfo->script_space = NULL;
  146244. cinfo->input_gamma = 1.0; /* in case application forgets */
  146245. cinfo->global_state = CSTATE_START;
  146246. }
  146247. GLOBAL(void)
  146248. jpeg_destroy_compress (j_compress_ptr cinfo)
  146249. {
  146250. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  146251. }
  146252. GLOBAL(void)
  146253. jpeg_abort_compress (j_compress_ptr cinfo)
  146254. {
  146255. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  146256. }
  146257. GLOBAL(void)
  146258. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  146259. {
  146260. int i;
  146261. JQUANT_TBL * qtbl;
  146262. JHUFF_TBL * htbl;
  146263. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146264. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  146265. qtbl->sent_table = suppress;
  146266. }
  146267. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146268. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  146269. htbl->sent_table = suppress;
  146270. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  146271. htbl->sent_table = suppress;
  146272. }
  146273. }
  146274. GLOBAL(void)
  146275. jpeg_finish_compress (j_compress_ptr cinfo)
  146276. {
  146277. JDIMENSION iMCU_row;
  146278. if (cinfo->global_state == CSTATE_SCANNING ||
  146279. cinfo->global_state == CSTATE_RAW_OK) {
  146280. if (cinfo->next_scanline < cinfo->image_height)
  146281. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  146282. (*cinfo->master->finish_pass) (cinfo);
  146283. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  146284. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146285. while (! cinfo->master->is_last_pass) {
  146286. (*cinfo->master->prepare_for_pass) (cinfo);
  146287. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146288. if (cinfo->progress != NULL) {
  146289. cinfo->progress->pass_counter = (long) iMCU_row;
  146290. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146291. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146292. }
  146293. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146294. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146295. }
  146296. (*cinfo->master->finish_pass) (cinfo);
  146297. }
  146298. (*cinfo->marker->write_file_trailer) (cinfo);
  146299. (*cinfo->dest->term_destination) (cinfo);
  146300. jpeg_abort((j_common_ptr) cinfo);
  146301. }
  146302. GLOBAL(void)
  146303. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146304. const JOCTET *dataptr, unsigned int datalen)
  146305. {
  146306. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146307. if (cinfo->next_scanline != 0 ||
  146308. (cinfo->global_state != CSTATE_SCANNING &&
  146309. cinfo->global_state != CSTATE_RAW_OK &&
  146310. cinfo->global_state != CSTATE_WRCOEFS))
  146311. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146312. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146313. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146314. while (datalen--) {
  146315. (*write_marker_byte) (cinfo, *dataptr);
  146316. dataptr++;
  146317. }
  146318. }
  146319. GLOBAL(void)
  146320. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146321. {
  146322. if (cinfo->next_scanline != 0 ||
  146323. (cinfo->global_state != CSTATE_SCANNING &&
  146324. cinfo->global_state != CSTATE_RAW_OK &&
  146325. cinfo->global_state != CSTATE_WRCOEFS))
  146326. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146327. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146328. }
  146329. GLOBAL(void)
  146330. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146331. {
  146332. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146333. }
  146334. GLOBAL(void)
  146335. jpeg_write_tables (j_compress_ptr cinfo)
  146336. {
  146337. if (cinfo->global_state != CSTATE_START)
  146338. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146339. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146340. (*cinfo->dest->init_destination) (cinfo);
  146341. jinit_marker_writer(cinfo);
  146342. (*cinfo->marker->write_tables_only) (cinfo);
  146343. (*cinfo->dest->term_destination) (cinfo);
  146344. }
  146345. /*** End of inlined file: jcapimin.c ***/
  146346. /*** Start of inlined file: jcapistd.c ***/
  146347. #define JPEG_INTERNALS
  146348. GLOBAL(void)
  146349. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146350. {
  146351. if (cinfo->global_state != CSTATE_START)
  146352. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146353. if (write_all_tables)
  146354. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146355. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146356. (*cinfo->dest->init_destination) (cinfo);
  146357. jinit_compress_master(cinfo);
  146358. (*cinfo->master->prepare_for_pass) (cinfo);
  146359. cinfo->next_scanline = 0;
  146360. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146361. }
  146362. GLOBAL(JDIMENSION)
  146363. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146364. JDIMENSION num_lines)
  146365. {
  146366. JDIMENSION row_ctr, rows_left;
  146367. if (cinfo->global_state != CSTATE_SCANNING)
  146368. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146369. if (cinfo->next_scanline >= cinfo->image_height)
  146370. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146371. if (cinfo->progress != NULL) {
  146372. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146373. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146374. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146375. }
  146376. if (cinfo->master->call_pass_startup)
  146377. (*cinfo->master->pass_startup) (cinfo);
  146378. rows_left = cinfo->image_height - cinfo->next_scanline;
  146379. if (num_lines > rows_left)
  146380. num_lines = rows_left;
  146381. row_ctr = 0;
  146382. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146383. cinfo->next_scanline += row_ctr;
  146384. return row_ctr;
  146385. }
  146386. GLOBAL(JDIMENSION)
  146387. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146388. JDIMENSION num_lines)
  146389. {
  146390. JDIMENSION lines_per_iMCU_row;
  146391. if (cinfo->global_state != CSTATE_RAW_OK)
  146392. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146393. if (cinfo->next_scanline >= cinfo->image_height) {
  146394. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146395. return 0;
  146396. }
  146397. if (cinfo->progress != NULL) {
  146398. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146399. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146400. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146401. }
  146402. if (cinfo->master->call_pass_startup)
  146403. (*cinfo->master->pass_startup) (cinfo);
  146404. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146405. if (num_lines < lines_per_iMCU_row)
  146406. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146407. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146408. return 0;
  146409. }
  146410. cinfo->next_scanline += lines_per_iMCU_row;
  146411. return lines_per_iMCU_row;
  146412. }
  146413. /*** End of inlined file: jcapistd.c ***/
  146414. /*** Start of inlined file: jccoefct.c ***/
  146415. #define JPEG_INTERNALS
  146416. #ifdef ENTROPY_OPT_SUPPORTED
  146417. #define FULL_COEF_BUFFER_SUPPORTED
  146418. #else
  146419. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146420. #define FULL_COEF_BUFFER_SUPPORTED
  146421. #endif
  146422. #endif
  146423. typedef struct {
  146424. struct jpeg_c_coef_controller pub; /* public fields */
  146425. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146426. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146427. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146428. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146429. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146430. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146431. } my_coef_controller;
  146432. typedef my_coef_controller * my_coef_ptr;
  146433. METHODDEF(boolean) compress_data
  146434. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146435. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146436. METHODDEF(boolean) compress_first_pass
  146437. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146438. METHODDEF(boolean) compress_output
  146439. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146440. #endif
  146441. LOCAL(void)
  146442. start_iMCU_row (j_compress_ptr cinfo)
  146443. {
  146444. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146445. if (cinfo->comps_in_scan > 1) {
  146446. coef->MCU_rows_per_iMCU_row = 1;
  146447. } else {
  146448. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146449. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146450. else
  146451. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146452. }
  146453. coef->mcu_ctr = 0;
  146454. coef->MCU_vert_offset = 0;
  146455. }
  146456. METHODDEF(void)
  146457. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146458. {
  146459. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146460. coef->iMCU_row_num = 0;
  146461. start_iMCU_row(cinfo);
  146462. switch (pass_mode) {
  146463. case JBUF_PASS_THRU:
  146464. if (coef->whole_image[0] != NULL)
  146465. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146466. coef->pub.compress_data = compress_data;
  146467. break;
  146468. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146469. case JBUF_SAVE_AND_PASS:
  146470. if (coef->whole_image[0] == NULL)
  146471. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146472. coef->pub.compress_data = compress_first_pass;
  146473. break;
  146474. case JBUF_CRANK_DEST:
  146475. if (coef->whole_image[0] == NULL)
  146476. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146477. coef->pub.compress_data = compress_output;
  146478. break;
  146479. #endif
  146480. default:
  146481. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146482. break;
  146483. }
  146484. }
  146485. METHODDEF(boolean)
  146486. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146487. {
  146488. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146489. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146490. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146491. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146492. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146493. JDIMENSION ypos, xpos;
  146494. jpeg_component_info *compptr;
  146495. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146496. yoffset++) {
  146497. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146498. MCU_col_num++) {
  146499. blkn = 0;
  146500. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146501. compptr = cinfo->cur_comp_info[ci];
  146502. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146503. : compptr->last_col_width;
  146504. xpos = MCU_col_num * compptr->MCU_sample_width;
  146505. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146506. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146507. if (coef->iMCU_row_num < last_iMCU_row ||
  146508. yoffset+yindex < compptr->last_row_height) {
  146509. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146510. input_buf[compptr->component_index],
  146511. coef->MCU_buffer[blkn],
  146512. ypos, xpos, (JDIMENSION) blockcnt);
  146513. if (blockcnt < compptr->MCU_width) {
  146514. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146515. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146516. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146517. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146518. }
  146519. }
  146520. } else {
  146521. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146522. compptr->MCU_width * SIZEOF(JBLOCK));
  146523. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146524. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146525. }
  146526. }
  146527. blkn += compptr->MCU_width;
  146528. ypos += DCTSIZE;
  146529. }
  146530. }
  146531. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146532. coef->MCU_vert_offset = yoffset;
  146533. coef->mcu_ctr = MCU_col_num;
  146534. return FALSE;
  146535. }
  146536. }
  146537. coef->mcu_ctr = 0;
  146538. }
  146539. coef->iMCU_row_num++;
  146540. start_iMCU_row(cinfo);
  146541. return TRUE;
  146542. }
  146543. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146544. METHODDEF(boolean)
  146545. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146546. {
  146547. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146548. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146549. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146550. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146551. JCOEF lastDC;
  146552. jpeg_component_info *compptr;
  146553. JBLOCKARRAY buffer;
  146554. JBLOCKROW thisblockrow, lastblockrow;
  146555. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146556. ci++, compptr++) {
  146557. buffer = (*cinfo->mem->access_virt_barray)
  146558. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146559. coef->iMCU_row_num * compptr->v_samp_factor,
  146560. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146561. if (coef->iMCU_row_num < last_iMCU_row)
  146562. block_rows = compptr->v_samp_factor;
  146563. else {
  146564. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146565. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146566. }
  146567. blocks_across = compptr->width_in_blocks;
  146568. h_samp_factor = compptr->h_samp_factor;
  146569. ndummy = (int) (blocks_across % h_samp_factor);
  146570. if (ndummy > 0)
  146571. ndummy = h_samp_factor - ndummy;
  146572. for (block_row = 0; block_row < block_rows; block_row++) {
  146573. thisblockrow = buffer[block_row];
  146574. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146575. input_buf[ci], thisblockrow,
  146576. (JDIMENSION) (block_row * DCTSIZE),
  146577. (JDIMENSION) 0, blocks_across);
  146578. if (ndummy > 0) {
  146579. thisblockrow += blocks_across; /* => first dummy block */
  146580. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146581. lastDC = thisblockrow[-1][0];
  146582. for (bi = 0; bi < ndummy; bi++) {
  146583. thisblockrow[bi][0] = lastDC;
  146584. }
  146585. }
  146586. }
  146587. if (coef->iMCU_row_num == last_iMCU_row) {
  146588. blocks_across += ndummy; /* include lower right corner */
  146589. MCUs_across = blocks_across / h_samp_factor;
  146590. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146591. block_row++) {
  146592. thisblockrow = buffer[block_row];
  146593. lastblockrow = buffer[block_row-1];
  146594. jzero_far((void FAR *) thisblockrow,
  146595. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146596. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146597. lastDC = lastblockrow[h_samp_factor-1][0];
  146598. for (bi = 0; bi < h_samp_factor; bi++) {
  146599. thisblockrow[bi][0] = lastDC;
  146600. }
  146601. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146602. lastblockrow += h_samp_factor;
  146603. }
  146604. }
  146605. }
  146606. }
  146607. return compress_output(cinfo, input_buf);
  146608. }
  146609. METHODDEF(boolean)
  146610. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146611. {
  146612. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146613. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146614. int blkn, ci, xindex, yindex, yoffset;
  146615. JDIMENSION start_col;
  146616. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146617. JBLOCKROW buffer_ptr;
  146618. jpeg_component_info *compptr;
  146619. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146620. compptr = cinfo->cur_comp_info[ci];
  146621. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146622. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146623. coef->iMCU_row_num * compptr->v_samp_factor,
  146624. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146625. }
  146626. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146627. yoffset++) {
  146628. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146629. MCU_col_num++) {
  146630. blkn = 0; /* index of current DCT block within MCU */
  146631. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146632. compptr = cinfo->cur_comp_info[ci];
  146633. start_col = MCU_col_num * compptr->MCU_width;
  146634. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146635. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146636. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146637. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146638. }
  146639. }
  146640. }
  146641. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146642. coef->MCU_vert_offset = yoffset;
  146643. coef->mcu_ctr = MCU_col_num;
  146644. return FALSE;
  146645. }
  146646. }
  146647. coef->mcu_ctr = 0;
  146648. }
  146649. coef->iMCU_row_num++;
  146650. start_iMCU_row(cinfo);
  146651. return TRUE;
  146652. }
  146653. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146654. GLOBAL(void)
  146655. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146656. {
  146657. my_coef_ptr coef;
  146658. coef = (my_coef_ptr)
  146659. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146660. SIZEOF(my_coef_controller));
  146661. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146662. coef->pub.start_pass = start_pass_coef;
  146663. if (need_full_buffer) {
  146664. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146665. int ci;
  146666. jpeg_component_info *compptr;
  146667. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146668. ci++, compptr++) {
  146669. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146670. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146671. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146672. (long) compptr->h_samp_factor),
  146673. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146674. (long) compptr->v_samp_factor),
  146675. (JDIMENSION) compptr->v_samp_factor);
  146676. }
  146677. #else
  146678. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146679. #endif
  146680. } else {
  146681. JBLOCKROW buffer;
  146682. int i;
  146683. buffer = (JBLOCKROW)
  146684. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146685. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146686. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146687. coef->MCU_buffer[i] = buffer + i;
  146688. }
  146689. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146690. }
  146691. }
  146692. /*** End of inlined file: jccoefct.c ***/
  146693. /*** Start of inlined file: jccolor.c ***/
  146694. #define JPEG_INTERNALS
  146695. typedef struct {
  146696. struct jpeg_color_converter pub; /* public fields */
  146697. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146698. } my_color_converter;
  146699. typedef my_color_converter * my_cconvert_ptr;
  146700. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146701. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146702. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146703. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146704. #define R_Y_OFF 0 /* offset to R => Y section */
  146705. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146706. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146707. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146708. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146709. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146710. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146711. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146712. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146713. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146714. METHODDEF(void)
  146715. rgb_ycc_start (j_compress_ptr cinfo)
  146716. {
  146717. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146718. INT32 * rgb_ycc_tab;
  146719. INT32 i;
  146720. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146721. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146722. (TABLE_SIZE * SIZEOF(INT32)));
  146723. for (i = 0; i <= MAXJSAMPLE; i++) {
  146724. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146725. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146726. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146727. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146728. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146729. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146730. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146731. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146732. }
  146733. }
  146734. METHODDEF(void)
  146735. rgb_ycc_convert (j_compress_ptr cinfo,
  146736. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146737. JDIMENSION output_row, int num_rows)
  146738. {
  146739. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146740. register int r, g, b;
  146741. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146742. register JSAMPROW inptr;
  146743. register JSAMPROW outptr0, outptr1, outptr2;
  146744. register JDIMENSION col;
  146745. JDIMENSION num_cols = cinfo->image_width;
  146746. while (--num_rows >= 0) {
  146747. inptr = *input_buf++;
  146748. outptr0 = output_buf[0][output_row];
  146749. outptr1 = output_buf[1][output_row];
  146750. outptr2 = output_buf[2][output_row];
  146751. output_row++;
  146752. for (col = 0; col < num_cols; col++) {
  146753. r = GETJSAMPLE(inptr[RGB_RED]);
  146754. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146755. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146756. inptr += RGB_PIXELSIZE;
  146757. outptr0[col] = (JSAMPLE)
  146758. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146759. >> SCALEBITS);
  146760. outptr1[col] = (JSAMPLE)
  146761. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146762. >> SCALEBITS);
  146763. outptr2[col] = (JSAMPLE)
  146764. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146765. >> SCALEBITS);
  146766. }
  146767. }
  146768. }
  146769. METHODDEF(void)
  146770. rgb_gray_convert (j_compress_ptr cinfo,
  146771. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146772. JDIMENSION output_row, int num_rows)
  146773. {
  146774. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146775. register int r, g, b;
  146776. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146777. register JSAMPROW inptr;
  146778. register JSAMPROW outptr;
  146779. register JDIMENSION col;
  146780. JDIMENSION num_cols = cinfo->image_width;
  146781. while (--num_rows >= 0) {
  146782. inptr = *input_buf++;
  146783. outptr = output_buf[0][output_row];
  146784. output_row++;
  146785. for (col = 0; col < num_cols; col++) {
  146786. r = GETJSAMPLE(inptr[RGB_RED]);
  146787. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146788. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146789. inptr += RGB_PIXELSIZE;
  146790. outptr[col] = (JSAMPLE)
  146791. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146792. >> SCALEBITS);
  146793. }
  146794. }
  146795. }
  146796. METHODDEF(void)
  146797. cmyk_ycck_convert (j_compress_ptr cinfo,
  146798. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146799. JDIMENSION output_row, int num_rows)
  146800. {
  146801. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146802. register int r, g, b;
  146803. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146804. register JSAMPROW inptr;
  146805. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146806. register JDIMENSION col;
  146807. JDIMENSION num_cols = cinfo->image_width;
  146808. while (--num_rows >= 0) {
  146809. inptr = *input_buf++;
  146810. outptr0 = output_buf[0][output_row];
  146811. outptr1 = output_buf[1][output_row];
  146812. outptr2 = output_buf[2][output_row];
  146813. outptr3 = output_buf[3][output_row];
  146814. output_row++;
  146815. for (col = 0; col < num_cols; col++) {
  146816. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146817. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146818. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146819. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146820. inptr += 4;
  146821. outptr0[col] = (JSAMPLE)
  146822. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146823. >> SCALEBITS);
  146824. outptr1[col] = (JSAMPLE)
  146825. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146826. >> SCALEBITS);
  146827. outptr2[col] = (JSAMPLE)
  146828. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146829. >> SCALEBITS);
  146830. }
  146831. }
  146832. }
  146833. METHODDEF(void)
  146834. grayscale_convert (j_compress_ptr cinfo,
  146835. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146836. JDIMENSION output_row, int num_rows)
  146837. {
  146838. register JSAMPROW inptr;
  146839. register JSAMPROW outptr;
  146840. register JDIMENSION col;
  146841. JDIMENSION num_cols = cinfo->image_width;
  146842. int instride = cinfo->input_components;
  146843. while (--num_rows >= 0) {
  146844. inptr = *input_buf++;
  146845. outptr = output_buf[0][output_row];
  146846. output_row++;
  146847. for (col = 0; col < num_cols; col++) {
  146848. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146849. inptr += instride;
  146850. }
  146851. }
  146852. }
  146853. METHODDEF(void)
  146854. null_convert (j_compress_ptr cinfo,
  146855. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146856. JDIMENSION output_row, int num_rows)
  146857. {
  146858. register JSAMPROW inptr;
  146859. register JSAMPROW outptr;
  146860. register JDIMENSION col;
  146861. register int ci;
  146862. int nc = cinfo->num_components;
  146863. JDIMENSION num_cols = cinfo->image_width;
  146864. while (--num_rows >= 0) {
  146865. for (ci = 0; ci < nc; ci++) {
  146866. inptr = *input_buf;
  146867. outptr = output_buf[ci][output_row];
  146868. for (col = 0; col < num_cols; col++) {
  146869. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146870. inptr += nc;
  146871. }
  146872. }
  146873. input_buf++;
  146874. output_row++;
  146875. }
  146876. }
  146877. METHODDEF(void)
  146878. null_method (j_compress_ptr cinfo)
  146879. {
  146880. }
  146881. GLOBAL(void)
  146882. jinit_color_converter (j_compress_ptr cinfo)
  146883. {
  146884. my_cconvert_ptr cconvert;
  146885. cconvert = (my_cconvert_ptr)
  146886. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146887. SIZEOF(my_color_converter));
  146888. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146889. cconvert->pub.start_pass = null_method;
  146890. switch (cinfo->in_color_space) {
  146891. case JCS_GRAYSCALE:
  146892. if (cinfo->input_components != 1)
  146893. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146894. break;
  146895. case JCS_RGB:
  146896. #if RGB_PIXELSIZE != 3
  146897. if (cinfo->input_components != RGB_PIXELSIZE)
  146898. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146899. break;
  146900. #endif /* else share code with YCbCr */
  146901. case JCS_YCbCr:
  146902. if (cinfo->input_components != 3)
  146903. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146904. break;
  146905. case JCS_CMYK:
  146906. case JCS_YCCK:
  146907. if (cinfo->input_components != 4)
  146908. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146909. break;
  146910. default: /* JCS_UNKNOWN can be anything */
  146911. if (cinfo->input_components < 1)
  146912. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146913. break;
  146914. }
  146915. switch (cinfo->jpeg_color_space) {
  146916. case JCS_GRAYSCALE:
  146917. if (cinfo->num_components != 1)
  146918. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146919. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146920. cconvert->pub.color_convert = grayscale_convert;
  146921. else if (cinfo->in_color_space == JCS_RGB) {
  146922. cconvert->pub.start_pass = rgb_ycc_start;
  146923. cconvert->pub.color_convert = rgb_gray_convert;
  146924. } else if (cinfo->in_color_space == JCS_YCbCr)
  146925. cconvert->pub.color_convert = grayscale_convert;
  146926. else
  146927. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146928. break;
  146929. case JCS_RGB:
  146930. if (cinfo->num_components != 3)
  146931. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146932. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146933. cconvert->pub.color_convert = null_convert;
  146934. else
  146935. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146936. break;
  146937. case JCS_YCbCr:
  146938. if (cinfo->num_components != 3)
  146939. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146940. if (cinfo->in_color_space == JCS_RGB) {
  146941. cconvert->pub.start_pass = rgb_ycc_start;
  146942. cconvert->pub.color_convert = rgb_ycc_convert;
  146943. } else if (cinfo->in_color_space == JCS_YCbCr)
  146944. cconvert->pub.color_convert = null_convert;
  146945. else
  146946. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146947. break;
  146948. case JCS_CMYK:
  146949. if (cinfo->num_components != 4)
  146950. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146951. if (cinfo->in_color_space == JCS_CMYK)
  146952. cconvert->pub.color_convert = null_convert;
  146953. else
  146954. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146955. break;
  146956. case JCS_YCCK:
  146957. if (cinfo->num_components != 4)
  146958. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146959. if (cinfo->in_color_space == JCS_CMYK) {
  146960. cconvert->pub.start_pass = rgb_ycc_start;
  146961. cconvert->pub.color_convert = cmyk_ycck_convert;
  146962. } else if (cinfo->in_color_space == JCS_YCCK)
  146963. cconvert->pub.color_convert = null_convert;
  146964. else
  146965. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146966. break;
  146967. default: /* allow null conversion of JCS_UNKNOWN */
  146968. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146969. cinfo->num_components != cinfo->input_components)
  146970. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146971. cconvert->pub.color_convert = null_convert;
  146972. break;
  146973. }
  146974. }
  146975. /*** End of inlined file: jccolor.c ***/
  146976. #undef FIX
  146977. /*** Start of inlined file: jcdctmgr.c ***/
  146978. #define JPEG_INTERNALS
  146979. /*** Start of inlined file: jdct.h ***/
  146980. #ifndef __jdct_h__
  146981. #define __jdct_h__
  146982. #if BITS_IN_JSAMPLE == 8
  146983. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146984. #else
  146985. typedef INT32 DCTELEM; /* must have 32 bits */
  146986. #endif
  146987. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146988. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146989. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146990. #if BITS_IN_JSAMPLE == 8
  146991. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146992. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146993. #else
  146994. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146995. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146996. #endif
  146997. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146998. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146999. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  147000. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147001. #define jpeg_fdct_islow jFDislow
  147002. #define jpeg_fdct_ifast jFDifast
  147003. #define jpeg_fdct_float jFDfloat
  147004. #define jpeg_idct_islow jRDislow
  147005. #define jpeg_idct_ifast jRDifast
  147006. #define jpeg_idct_float jRDfloat
  147007. #define jpeg_idct_4x4 jRD4x4
  147008. #define jpeg_idct_2x2 jRD2x2
  147009. #define jpeg_idct_1x1 jRD1x1
  147010. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147011. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  147012. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  147013. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  147014. EXTERN(void) jpeg_idct_islow
  147015. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147016. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147017. EXTERN(void) jpeg_idct_ifast
  147018. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147019. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147020. EXTERN(void) jpeg_idct_float
  147021. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147022. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147023. EXTERN(void) jpeg_idct_4x4
  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_2x2
  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_1x1
  147030. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147031. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147032. #define ONE ((INT32) 1)
  147033. #define CONST_SCALE (ONE << CONST_BITS)
  147034. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  147035. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  147036. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147037. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  147038. #endif
  147039. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  147040. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  147041. #endif
  147042. #ifndef MULTIPLY16C16 /* default definition */
  147043. #define MULTIPLY16C16(var,const) ((var) * (const))
  147044. #endif
  147045. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147046. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  147047. #endif
  147048. #ifndef MULTIPLY16V16 /* default definition */
  147049. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  147050. #endif
  147051. #endif
  147052. /*** End of inlined file: jdct.h ***/
  147053. /* Private declarations for DCT subsystem */
  147054. typedef struct {
  147055. struct jpeg_forward_dct pub; /* public fields */
  147056. forward_DCT_method_ptr do_dct;
  147057. DCTELEM * divisors[NUM_QUANT_TBLS];
  147058. #ifdef DCT_FLOAT_SUPPORTED
  147059. float_DCT_method_ptr do_float_dct;
  147060. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  147061. #endif
  147062. } my_fdct_controller;
  147063. typedef my_fdct_controller * my_fdct_ptr;
  147064. METHODDEF(void)
  147065. start_pass_fdctmgr (j_compress_ptr cinfo)
  147066. {
  147067. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147068. int ci, qtblno, i;
  147069. jpeg_component_info *compptr;
  147070. JQUANT_TBL * qtbl;
  147071. DCTELEM * dtbl;
  147072. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147073. ci++, compptr++) {
  147074. qtblno = compptr->quant_tbl_no;
  147075. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  147076. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  147077. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  147078. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  147079. switch (cinfo->dct_method) {
  147080. #ifdef DCT_ISLOW_SUPPORTED
  147081. case JDCT_ISLOW:
  147082. if (fdct->divisors[qtblno] == NULL) {
  147083. fdct->divisors[qtblno] = (DCTELEM *)
  147084. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147085. DCTSIZE2 * SIZEOF(DCTELEM));
  147086. }
  147087. dtbl = fdct->divisors[qtblno];
  147088. for (i = 0; i < DCTSIZE2; i++) {
  147089. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  147090. }
  147091. break;
  147092. #endif
  147093. #ifdef DCT_IFAST_SUPPORTED
  147094. case JDCT_IFAST:
  147095. {
  147096. #define CONST_BITS 14
  147097. static const INT16 aanscales[DCTSIZE2] = {
  147098. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147099. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  147100. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  147101. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  147102. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147103. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  147104. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  147105. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  147106. };
  147107. SHIFT_TEMPS
  147108. if (fdct->divisors[qtblno] == NULL) {
  147109. fdct->divisors[qtblno] = (DCTELEM *)
  147110. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147111. DCTSIZE2 * SIZEOF(DCTELEM));
  147112. }
  147113. dtbl = fdct->divisors[qtblno];
  147114. for (i = 0; i < DCTSIZE2; i++) {
  147115. dtbl[i] = (DCTELEM)
  147116. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  147117. (INT32) aanscales[i]),
  147118. CONST_BITS-3);
  147119. }
  147120. }
  147121. break;
  147122. #endif
  147123. #ifdef DCT_FLOAT_SUPPORTED
  147124. case JDCT_FLOAT:
  147125. {
  147126. FAST_FLOAT * fdtbl;
  147127. int row, col;
  147128. static const double aanscalefactor[DCTSIZE] = {
  147129. 1.0, 1.387039845, 1.306562965, 1.175875602,
  147130. 1.0, 0.785694958, 0.541196100, 0.275899379
  147131. };
  147132. if (fdct->float_divisors[qtblno] == NULL) {
  147133. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  147134. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147135. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  147136. }
  147137. fdtbl = fdct->float_divisors[qtblno];
  147138. i = 0;
  147139. for (row = 0; row < DCTSIZE; row++) {
  147140. for (col = 0; col < DCTSIZE; col++) {
  147141. fdtbl[i] = (FAST_FLOAT)
  147142. (1.0 / (((double) qtbl->quantval[i] *
  147143. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  147144. i++;
  147145. }
  147146. }
  147147. }
  147148. break;
  147149. #endif
  147150. default:
  147151. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147152. break;
  147153. }
  147154. }
  147155. }
  147156. METHODDEF(void)
  147157. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147158. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147159. JDIMENSION start_row, JDIMENSION start_col,
  147160. JDIMENSION num_blocks)
  147161. {
  147162. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147163. forward_DCT_method_ptr do_dct = fdct->do_dct;
  147164. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  147165. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147166. JDIMENSION bi;
  147167. sample_data += start_row; /* fold in the vertical offset once */
  147168. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147169. { register DCTELEM *workspaceptr;
  147170. register JSAMPROW elemptr;
  147171. register int elemr;
  147172. workspaceptr = workspace;
  147173. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147174. elemptr = sample_data[elemr] + start_col;
  147175. #if DCTSIZE == 8 /* unroll the inner loop */
  147176. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147177. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147178. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147179. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147180. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147181. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147182. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147183. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147184. #else
  147185. { register int elemc;
  147186. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147187. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147188. }
  147189. }
  147190. #endif
  147191. }
  147192. }
  147193. (*do_dct) (workspace);
  147194. { register DCTELEM temp, qval;
  147195. register int i;
  147196. register JCOEFPTR output_ptr = coef_blocks[bi];
  147197. for (i = 0; i < DCTSIZE2; i++) {
  147198. qval = divisors[i];
  147199. temp = workspace[i];
  147200. #ifdef FAST_DIVIDE
  147201. #define DIVIDE_BY(a,b) a /= b
  147202. #else
  147203. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  147204. #endif
  147205. if (temp < 0) {
  147206. temp = -temp;
  147207. temp += qval>>1; /* for rounding */
  147208. DIVIDE_BY(temp, qval);
  147209. temp = -temp;
  147210. } else {
  147211. temp += qval>>1; /* for rounding */
  147212. DIVIDE_BY(temp, qval);
  147213. }
  147214. output_ptr[i] = (JCOEF) temp;
  147215. }
  147216. }
  147217. }
  147218. }
  147219. #ifdef DCT_FLOAT_SUPPORTED
  147220. METHODDEF(void)
  147221. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147222. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147223. JDIMENSION start_row, JDIMENSION start_col,
  147224. JDIMENSION num_blocks)
  147225. {
  147226. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147227. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  147228. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  147229. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147230. JDIMENSION bi;
  147231. sample_data += start_row; /* fold in the vertical offset once */
  147232. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147233. { register FAST_FLOAT *workspaceptr;
  147234. register JSAMPROW elemptr;
  147235. register int elemr;
  147236. workspaceptr = workspace;
  147237. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147238. elemptr = sample_data[elemr] + start_col;
  147239. #if DCTSIZE == 8 /* unroll the inner loop */
  147240. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147241. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147242. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147243. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147244. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147245. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147246. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147247. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147248. #else
  147249. { register int elemc;
  147250. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147251. *workspaceptr++ = (FAST_FLOAT)
  147252. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147253. }
  147254. }
  147255. #endif
  147256. }
  147257. }
  147258. (*do_dct) (workspace);
  147259. { register FAST_FLOAT temp;
  147260. register int i;
  147261. register JCOEFPTR output_ptr = coef_blocks[bi];
  147262. for (i = 0; i < DCTSIZE2; i++) {
  147263. temp = workspace[i] * divisors[i];
  147264. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  147265. }
  147266. }
  147267. }
  147268. }
  147269. #endif /* DCT_FLOAT_SUPPORTED */
  147270. GLOBAL(void)
  147271. jinit_forward_dct (j_compress_ptr cinfo)
  147272. {
  147273. my_fdct_ptr fdct;
  147274. int i;
  147275. fdct = (my_fdct_ptr)
  147276. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147277. SIZEOF(my_fdct_controller));
  147278. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  147279. fdct->pub.start_pass = start_pass_fdctmgr;
  147280. switch (cinfo->dct_method) {
  147281. #ifdef DCT_ISLOW_SUPPORTED
  147282. case JDCT_ISLOW:
  147283. fdct->pub.forward_DCT = forward_DCT;
  147284. fdct->do_dct = jpeg_fdct_islow;
  147285. break;
  147286. #endif
  147287. #ifdef DCT_IFAST_SUPPORTED
  147288. case JDCT_IFAST:
  147289. fdct->pub.forward_DCT = forward_DCT;
  147290. fdct->do_dct = jpeg_fdct_ifast;
  147291. break;
  147292. #endif
  147293. #ifdef DCT_FLOAT_SUPPORTED
  147294. case JDCT_FLOAT:
  147295. fdct->pub.forward_DCT = forward_DCT_float;
  147296. fdct->do_float_dct = jpeg_fdct_float;
  147297. break;
  147298. #endif
  147299. default:
  147300. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147301. break;
  147302. }
  147303. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147304. fdct->divisors[i] = NULL;
  147305. #ifdef DCT_FLOAT_SUPPORTED
  147306. fdct->float_divisors[i] = NULL;
  147307. #endif
  147308. }
  147309. }
  147310. /*** End of inlined file: jcdctmgr.c ***/
  147311. #undef CONST_BITS
  147312. /*** Start of inlined file: jchuff.c ***/
  147313. #define JPEG_INTERNALS
  147314. /*** Start of inlined file: jchuff.h ***/
  147315. #ifndef _jchuff_h_
  147316. #define _jchuff_h_
  147317. #if BITS_IN_JSAMPLE == 8
  147318. #define MAX_COEF_BITS 10
  147319. #else
  147320. #define MAX_COEF_BITS 14
  147321. #endif
  147322. typedef struct {
  147323. unsigned int ehufco[256]; /* code for each symbol */
  147324. char ehufsi[256]; /* length of code for each symbol */
  147325. } c_derived_tbl;
  147326. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147327. #define jpeg_make_c_derived_tbl jMkCDerived
  147328. #define jpeg_gen_optimal_table jGenOptTbl
  147329. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147330. EXTERN(void) jpeg_make_c_derived_tbl
  147331. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147332. c_derived_tbl ** pdtbl));
  147333. EXTERN(void) jpeg_gen_optimal_table
  147334. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147335. #endif
  147336. /*** End of inlined file: jchuff.h ***/
  147337. /* Declarations shared with jcphuff.c */
  147338. typedef struct {
  147339. INT32 put_buffer; /* current bit-accumulation buffer */
  147340. int put_bits; /* # of bits now in it */
  147341. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147342. } savable_state;
  147343. #ifndef NO_STRUCT_ASSIGN
  147344. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147345. #else
  147346. #if MAX_COMPS_IN_SCAN == 4
  147347. #define ASSIGN_STATE(dest,src) \
  147348. ((dest).put_buffer = (src).put_buffer, \
  147349. (dest).put_bits = (src).put_bits, \
  147350. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147351. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147352. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147353. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147354. #endif
  147355. #endif
  147356. typedef struct {
  147357. struct jpeg_entropy_encoder pub; /* public fields */
  147358. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147359. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147360. int next_restart_num; /* next restart number to write (0-7) */
  147361. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147362. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147363. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147364. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147365. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147366. #endif
  147367. } huff_entropy_encoder;
  147368. typedef huff_entropy_encoder * huff_entropy_ptr;
  147369. typedef struct {
  147370. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147371. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147372. savable_state cur; /* Current bit buffer & DC state */
  147373. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147374. } working_state;
  147375. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147376. JBLOCKROW *MCU_data));
  147377. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147378. #ifdef ENTROPY_OPT_SUPPORTED
  147379. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147380. JBLOCKROW *MCU_data));
  147381. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147382. #endif
  147383. METHODDEF(void)
  147384. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147385. {
  147386. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147387. int ci, dctbl, actbl;
  147388. jpeg_component_info * compptr;
  147389. if (gather_statistics) {
  147390. #ifdef ENTROPY_OPT_SUPPORTED
  147391. entropy->pub.encode_mcu = encode_mcu_gather;
  147392. entropy->pub.finish_pass = finish_pass_gather;
  147393. #else
  147394. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147395. #endif
  147396. } else {
  147397. entropy->pub.encode_mcu = encode_mcu_huff;
  147398. entropy->pub.finish_pass = finish_pass_huff;
  147399. }
  147400. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147401. compptr = cinfo->cur_comp_info[ci];
  147402. dctbl = compptr->dc_tbl_no;
  147403. actbl = compptr->ac_tbl_no;
  147404. if (gather_statistics) {
  147405. #ifdef ENTROPY_OPT_SUPPORTED
  147406. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147407. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147408. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147409. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147410. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147411. entropy->dc_count_ptrs[dctbl] = (long *)
  147412. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147413. 257 * SIZEOF(long));
  147414. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147415. if (entropy->ac_count_ptrs[actbl] == NULL)
  147416. entropy->ac_count_ptrs[actbl] = (long *)
  147417. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147418. 257 * SIZEOF(long));
  147419. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147420. #endif
  147421. } else {
  147422. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147423. & entropy->dc_derived_tbls[dctbl]);
  147424. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147425. & entropy->ac_derived_tbls[actbl]);
  147426. }
  147427. entropy->saved.last_dc_val[ci] = 0;
  147428. }
  147429. entropy->saved.put_buffer = 0;
  147430. entropy->saved.put_bits = 0;
  147431. entropy->restarts_to_go = cinfo->restart_interval;
  147432. entropy->next_restart_num = 0;
  147433. }
  147434. GLOBAL(void)
  147435. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147436. c_derived_tbl ** pdtbl)
  147437. {
  147438. JHUFF_TBL *htbl;
  147439. c_derived_tbl *dtbl;
  147440. int p, i, l, lastp, si, maxsymbol;
  147441. char huffsize[257];
  147442. unsigned int huffcode[257];
  147443. unsigned int code;
  147444. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147445. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147446. htbl =
  147447. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147448. if (htbl == NULL)
  147449. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147450. if (*pdtbl == NULL)
  147451. *pdtbl = (c_derived_tbl *)
  147452. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147453. SIZEOF(c_derived_tbl));
  147454. dtbl = *pdtbl;
  147455. p = 0;
  147456. for (l = 1; l <= 16; l++) {
  147457. i = (int) htbl->bits[l];
  147458. if (i < 0 || p + i > 256) /* protect against table overrun */
  147459. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147460. while (i--)
  147461. huffsize[p++] = (char) l;
  147462. }
  147463. huffsize[p] = 0;
  147464. lastp = p;
  147465. code = 0;
  147466. si = huffsize[0];
  147467. p = 0;
  147468. while (huffsize[p]) {
  147469. while (((int) huffsize[p]) == si) {
  147470. huffcode[p++] = code;
  147471. code++;
  147472. }
  147473. if (((INT32) code) >= (((INT32) 1) << si))
  147474. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147475. code <<= 1;
  147476. si++;
  147477. }
  147478. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147479. maxsymbol = isDC ? 15 : 255;
  147480. for (p = 0; p < lastp; p++) {
  147481. i = htbl->huffval[p];
  147482. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147483. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147484. dtbl->ehufco[i] = huffcode[p];
  147485. dtbl->ehufsi[i] = huffsize[p];
  147486. }
  147487. }
  147488. #define emit_byte(state,val,action) \
  147489. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147490. if (--(state)->free_in_buffer == 0) \
  147491. if (! dump_buffer(state)) \
  147492. { action; } }
  147493. LOCAL(boolean)
  147494. dump_buffer (working_state * state)
  147495. {
  147496. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147497. if (! (*dest->empty_output_buffer) (state->cinfo))
  147498. return FALSE;
  147499. state->next_output_byte = dest->next_output_byte;
  147500. state->free_in_buffer = dest->free_in_buffer;
  147501. return TRUE;
  147502. }
  147503. INLINE
  147504. LOCAL(boolean)
  147505. emit_bits (working_state * state, unsigned int code, int size)
  147506. {
  147507. register INT32 put_buffer = (INT32) code;
  147508. register int put_bits = state->cur.put_bits;
  147509. if (size == 0)
  147510. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147511. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147512. put_bits += size; /* new number of bits in buffer */
  147513. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147514. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147515. while (put_bits >= 8) {
  147516. int c = (int) ((put_buffer >> 16) & 0xFF);
  147517. emit_byte(state, c, return FALSE);
  147518. if (c == 0xFF) { /* need to stuff a zero byte? */
  147519. emit_byte(state, 0, return FALSE);
  147520. }
  147521. put_buffer <<= 8;
  147522. put_bits -= 8;
  147523. }
  147524. state->cur.put_buffer = put_buffer; /* update state variables */
  147525. state->cur.put_bits = put_bits;
  147526. return TRUE;
  147527. }
  147528. LOCAL(boolean)
  147529. flush_bits (working_state * state)
  147530. {
  147531. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147532. return FALSE;
  147533. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147534. state->cur.put_bits = 0;
  147535. return TRUE;
  147536. }
  147537. LOCAL(boolean)
  147538. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147539. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147540. {
  147541. register int temp, temp2;
  147542. register int nbits;
  147543. register int k, r, i;
  147544. temp = temp2 = block[0] - last_dc_val;
  147545. if (temp < 0) {
  147546. temp = -temp; /* temp is abs value of input */
  147547. temp2--;
  147548. }
  147549. nbits = 0;
  147550. while (temp) {
  147551. nbits++;
  147552. temp >>= 1;
  147553. }
  147554. if (nbits > MAX_COEF_BITS+1)
  147555. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147556. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147557. return FALSE;
  147558. if (nbits) /* emit_bits rejects calls with size 0 */
  147559. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147560. return FALSE;
  147561. r = 0; /* r = run length of zeros */
  147562. for (k = 1; k < DCTSIZE2; k++) {
  147563. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147564. r++;
  147565. } else {
  147566. while (r > 15) {
  147567. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147568. return FALSE;
  147569. r -= 16;
  147570. }
  147571. temp2 = temp;
  147572. if (temp < 0) {
  147573. temp = -temp; /* temp is abs value of input */
  147574. temp2--;
  147575. }
  147576. nbits = 1; /* there must be at least one 1 bit */
  147577. while ((temp >>= 1))
  147578. nbits++;
  147579. if (nbits > MAX_COEF_BITS)
  147580. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147581. i = (r << 4) + nbits;
  147582. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147583. return FALSE;
  147584. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147585. return FALSE;
  147586. r = 0;
  147587. }
  147588. }
  147589. if (r > 0)
  147590. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147591. return FALSE;
  147592. return TRUE;
  147593. }
  147594. LOCAL(boolean)
  147595. emit_restart (working_state * state, int restart_num)
  147596. {
  147597. int ci;
  147598. if (! flush_bits(state))
  147599. return FALSE;
  147600. emit_byte(state, 0xFF, return FALSE);
  147601. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147602. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147603. state->cur.last_dc_val[ci] = 0;
  147604. return TRUE;
  147605. }
  147606. METHODDEF(boolean)
  147607. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147608. {
  147609. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147610. working_state state;
  147611. int blkn, ci;
  147612. jpeg_component_info * compptr;
  147613. state.next_output_byte = cinfo->dest->next_output_byte;
  147614. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147615. ASSIGN_STATE(state.cur, entropy->saved);
  147616. state.cinfo = cinfo;
  147617. if (cinfo->restart_interval) {
  147618. if (entropy->restarts_to_go == 0)
  147619. if (! emit_restart(&state, entropy->next_restart_num))
  147620. return FALSE;
  147621. }
  147622. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147623. ci = cinfo->MCU_membership[blkn];
  147624. compptr = cinfo->cur_comp_info[ci];
  147625. if (! encode_one_block(&state,
  147626. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147627. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147628. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147629. return FALSE;
  147630. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147631. }
  147632. cinfo->dest->next_output_byte = state.next_output_byte;
  147633. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147634. ASSIGN_STATE(entropy->saved, state.cur);
  147635. if (cinfo->restart_interval) {
  147636. if (entropy->restarts_to_go == 0) {
  147637. entropy->restarts_to_go = cinfo->restart_interval;
  147638. entropy->next_restart_num++;
  147639. entropy->next_restart_num &= 7;
  147640. }
  147641. entropy->restarts_to_go--;
  147642. }
  147643. return TRUE;
  147644. }
  147645. METHODDEF(void)
  147646. finish_pass_huff (j_compress_ptr cinfo)
  147647. {
  147648. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147649. working_state state;
  147650. state.next_output_byte = cinfo->dest->next_output_byte;
  147651. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147652. ASSIGN_STATE(state.cur, entropy->saved);
  147653. state.cinfo = cinfo;
  147654. if (! flush_bits(&state))
  147655. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147656. cinfo->dest->next_output_byte = state.next_output_byte;
  147657. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147658. ASSIGN_STATE(entropy->saved, state.cur);
  147659. }
  147660. #ifdef ENTROPY_OPT_SUPPORTED
  147661. LOCAL(void)
  147662. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147663. long dc_counts[], long ac_counts[])
  147664. {
  147665. register int temp;
  147666. register int nbits;
  147667. register int k, r;
  147668. temp = block[0] - last_dc_val;
  147669. if (temp < 0)
  147670. temp = -temp;
  147671. nbits = 0;
  147672. while (temp) {
  147673. nbits++;
  147674. temp >>= 1;
  147675. }
  147676. if (nbits > MAX_COEF_BITS+1)
  147677. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147678. dc_counts[nbits]++;
  147679. r = 0; /* r = run length of zeros */
  147680. for (k = 1; k < DCTSIZE2; k++) {
  147681. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147682. r++;
  147683. } else {
  147684. while (r > 15) {
  147685. ac_counts[0xF0]++;
  147686. r -= 16;
  147687. }
  147688. if (temp < 0)
  147689. temp = -temp;
  147690. nbits = 1; /* there must be at least one 1 bit */
  147691. while ((temp >>= 1))
  147692. nbits++;
  147693. if (nbits > MAX_COEF_BITS)
  147694. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147695. ac_counts[(r << 4) + nbits]++;
  147696. r = 0;
  147697. }
  147698. }
  147699. if (r > 0)
  147700. ac_counts[0]++;
  147701. }
  147702. METHODDEF(boolean)
  147703. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147704. {
  147705. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147706. int blkn, ci;
  147707. jpeg_component_info * compptr;
  147708. if (cinfo->restart_interval) {
  147709. if (entropy->restarts_to_go == 0) {
  147710. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147711. entropy->saved.last_dc_val[ci] = 0;
  147712. entropy->restarts_to_go = cinfo->restart_interval;
  147713. }
  147714. entropy->restarts_to_go--;
  147715. }
  147716. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147717. ci = cinfo->MCU_membership[blkn];
  147718. compptr = cinfo->cur_comp_info[ci];
  147719. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147720. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147721. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147722. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147723. }
  147724. return TRUE;
  147725. }
  147726. GLOBAL(void)
  147727. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147728. {
  147729. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147730. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147731. int codesize[257]; /* codesize[k] = code length of symbol k */
  147732. int others[257]; /* next symbol in current branch of tree */
  147733. int c1, c2;
  147734. int p, i, j;
  147735. long v;
  147736. MEMZERO(bits, SIZEOF(bits));
  147737. MEMZERO(codesize, SIZEOF(codesize));
  147738. for (i = 0; i < 257; i++)
  147739. others[i] = -1; /* init links to empty */
  147740. freq[256] = 1; /* make sure 256 has a nonzero count */
  147741. for (;;) {
  147742. c1 = -1;
  147743. v = 1000000000L;
  147744. for (i = 0; i <= 256; i++) {
  147745. if (freq[i] && freq[i] <= v) {
  147746. v = freq[i];
  147747. c1 = i;
  147748. }
  147749. }
  147750. c2 = -1;
  147751. v = 1000000000L;
  147752. for (i = 0; i <= 256; i++) {
  147753. if (freq[i] && freq[i] <= v && i != c1) {
  147754. v = freq[i];
  147755. c2 = i;
  147756. }
  147757. }
  147758. if (c2 < 0)
  147759. break;
  147760. freq[c1] += freq[c2];
  147761. freq[c2] = 0;
  147762. codesize[c1]++;
  147763. while (others[c1] >= 0) {
  147764. c1 = others[c1];
  147765. codesize[c1]++;
  147766. }
  147767. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147768. codesize[c2]++;
  147769. while (others[c2] >= 0) {
  147770. c2 = others[c2];
  147771. codesize[c2]++;
  147772. }
  147773. }
  147774. for (i = 0; i <= 256; i++) {
  147775. if (codesize[i]) {
  147776. if (codesize[i] > MAX_CLEN)
  147777. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147778. bits[codesize[i]]++;
  147779. }
  147780. }
  147781. for (i = MAX_CLEN; i > 16; i--) {
  147782. while (bits[i] > 0) {
  147783. j = i - 2; /* find length of new prefix to be used */
  147784. while (bits[j] == 0)
  147785. j--;
  147786. bits[i] -= 2; /* remove two symbols */
  147787. bits[i-1]++; /* one goes in this length */
  147788. bits[j+1] += 2; /* two new symbols in this length */
  147789. bits[j]--; /* symbol of this length is now a prefix */
  147790. }
  147791. }
  147792. while (bits[i] == 0) /* find largest codelength still in use */
  147793. i--;
  147794. bits[i]--;
  147795. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147796. p = 0;
  147797. for (i = 1; i <= MAX_CLEN; i++) {
  147798. for (j = 0; j <= 255; j++) {
  147799. if (codesize[j] == i) {
  147800. htbl->huffval[p] = (UINT8) j;
  147801. p++;
  147802. }
  147803. }
  147804. }
  147805. htbl->sent_table = FALSE;
  147806. }
  147807. METHODDEF(void)
  147808. finish_pass_gather (j_compress_ptr cinfo)
  147809. {
  147810. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147811. int ci, dctbl, actbl;
  147812. jpeg_component_info * compptr;
  147813. JHUFF_TBL **htblptr;
  147814. boolean did_dc[NUM_HUFF_TBLS];
  147815. boolean did_ac[NUM_HUFF_TBLS];
  147816. MEMZERO(did_dc, SIZEOF(did_dc));
  147817. MEMZERO(did_ac, SIZEOF(did_ac));
  147818. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147819. compptr = cinfo->cur_comp_info[ci];
  147820. dctbl = compptr->dc_tbl_no;
  147821. actbl = compptr->ac_tbl_no;
  147822. if (! did_dc[dctbl]) {
  147823. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147824. if (*htblptr == NULL)
  147825. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147826. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147827. did_dc[dctbl] = TRUE;
  147828. }
  147829. if (! did_ac[actbl]) {
  147830. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147831. if (*htblptr == NULL)
  147832. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147833. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147834. did_ac[actbl] = TRUE;
  147835. }
  147836. }
  147837. }
  147838. #endif /* ENTROPY_OPT_SUPPORTED */
  147839. GLOBAL(void)
  147840. jinit_huff_encoder (j_compress_ptr cinfo)
  147841. {
  147842. huff_entropy_ptr entropy;
  147843. int i;
  147844. entropy = (huff_entropy_ptr)
  147845. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147846. SIZEOF(huff_entropy_encoder));
  147847. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147848. entropy->pub.start_pass = start_pass_huff;
  147849. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147850. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147851. #ifdef ENTROPY_OPT_SUPPORTED
  147852. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147853. #endif
  147854. }
  147855. }
  147856. /*** End of inlined file: jchuff.c ***/
  147857. #undef emit_byte
  147858. /*** Start of inlined file: jcinit.c ***/
  147859. #define JPEG_INTERNALS
  147860. GLOBAL(void)
  147861. jinit_compress_master (j_compress_ptr cinfo)
  147862. {
  147863. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147864. if (! cinfo->raw_data_in) {
  147865. jinit_color_converter(cinfo);
  147866. jinit_downsampler(cinfo);
  147867. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147868. }
  147869. jinit_forward_dct(cinfo);
  147870. if (cinfo->arith_code) {
  147871. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147872. } else {
  147873. if (cinfo->progressive_mode) {
  147874. #ifdef C_PROGRESSIVE_SUPPORTED
  147875. jinit_phuff_encoder(cinfo);
  147876. #else
  147877. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147878. #endif
  147879. } else
  147880. jinit_huff_encoder(cinfo);
  147881. }
  147882. jinit_c_coef_controller(cinfo,
  147883. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147884. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147885. jinit_marker_writer(cinfo);
  147886. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147887. (*cinfo->marker->write_file_header) (cinfo);
  147888. }
  147889. /*** End of inlined file: jcinit.c ***/
  147890. /*** Start of inlined file: jcmainct.c ***/
  147891. #define JPEG_INTERNALS
  147892. #undef FULL_MAIN_BUFFER_SUPPORTED
  147893. typedef struct {
  147894. struct jpeg_c_main_controller pub; /* public fields */
  147895. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147896. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147897. boolean suspended; /* remember if we suspended output */
  147898. J_BUF_MODE pass_mode; /* current operating mode */
  147899. JSAMPARRAY buffer[MAX_COMPONENTS];
  147900. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147901. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147902. #endif
  147903. } my_main_controller;
  147904. typedef my_main_controller * my_main_ptr;
  147905. METHODDEF(void) process_data_simple_main
  147906. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147907. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147908. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147909. METHODDEF(void) process_data_buffer_main
  147910. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147911. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147912. #endif
  147913. METHODDEF(void)
  147914. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147915. {
  147916. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147917. if (cinfo->raw_data_in)
  147918. return;
  147919. main_->cur_iMCU_row = 0; /* initialize counters */
  147920. main_->rowgroup_ctr = 0;
  147921. main_->suspended = FALSE;
  147922. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147923. switch (pass_mode) {
  147924. case JBUF_PASS_THRU:
  147925. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147926. if (main_->whole_image[0] != NULL)
  147927. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147928. #endif
  147929. main_->pub.process_data = process_data_simple_main;
  147930. break;
  147931. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147932. case JBUF_SAVE_SOURCE:
  147933. case JBUF_CRANK_DEST:
  147934. case JBUF_SAVE_AND_PASS:
  147935. if (main_->whole_image[0] == NULL)
  147936. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147937. main_->pub.process_data = process_data_buffer_main;
  147938. break;
  147939. #endif
  147940. default:
  147941. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147942. break;
  147943. }
  147944. }
  147945. METHODDEF(void)
  147946. process_data_simple_main (j_compress_ptr cinfo,
  147947. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147948. JDIMENSION in_rows_avail)
  147949. {
  147950. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147951. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147952. if (main_->rowgroup_ctr < DCTSIZE)
  147953. (*cinfo->prep->pre_process_data) (cinfo,
  147954. input_buf, in_row_ctr, in_rows_avail,
  147955. main_->buffer, &main_->rowgroup_ctr,
  147956. (JDIMENSION) DCTSIZE);
  147957. if (main_->rowgroup_ctr != DCTSIZE)
  147958. return;
  147959. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147960. if (! main_->suspended) {
  147961. (*in_row_ctr)--;
  147962. main_->suspended = TRUE;
  147963. }
  147964. return;
  147965. }
  147966. if (main_->suspended) {
  147967. (*in_row_ctr)++;
  147968. main_->suspended = FALSE;
  147969. }
  147970. main_->rowgroup_ctr = 0;
  147971. main_->cur_iMCU_row++;
  147972. }
  147973. }
  147974. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147975. METHODDEF(void)
  147976. process_data_buffer_main (j_compress_ptr cinfo,
  147977. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147978. JDIMENSION in_rows_avail)
  147979. {
  147980. my_main_ptr main = (my_main_ptr) cinfo->main;
  147981. int ci;
  147982. jpeg_component_info *compptr;
  147983. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147984. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147985. if (main->rowgroup_ctr == 0) {
  147986. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147987. ci++, compptr++) {
  147988. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147989. ((j_common_ptr) cinfo, main->whole_image[ci],
  147990. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147991. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147992. }
  147993. if (! writing) {
  147994. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147995. main->rowgroup_ctr = DCTSIZE;
  147996. }
  147997. }
  147998. if (writing) {
  147999. (*cinfo->prep->pre_process_data) (cinfo,
  148000. input_buf, in_row_ctr, in_rows_avail,
  148001. main->buffer, &main->rowgroup_ctr,
  148002. (JDIMENSION) DCTSIZE);
  148003. if (main->rowgroup_ctr < DCTSIZE)
  148004. return;
  148005. }
  148006. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  148007. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  148008. if (! main->suspended) {
  148009. (*in_row_ctr)--;
  148010. main->suspended = TRUE;
  148011. }
  148012. return;
  148013. }
  148014. if (main->suspended) {
  148015. (*in_row_ctr)++;
  148016. main->suspended = FALSE;
  148017. }
  148018. }
  148019. main->rowgroup_ctr = 0;
  148020. main->cur_iMCU_row++;
  148021. }
  148022. }
  148023. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  148024. GLOBAL(void)
  148025. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  148026. {
  148027. my_main_ptr main_;
  148028. int ci;
  148029. jpeg_component_info *compptr;
  148030. main_ = (my_main_ptr)
  148031. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148032. SIZEOF(my_main_controller));
  148033. cinfo->main = (struct jpeg_c_main_controller *) main_;
  148034. main_->pub.start_pass = start_pass_main;
  148035. if (cinfo->raw_data_in)
  148036. return;
  148037. if (need_full_buffer) {
  148038. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148039. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148040. ci++, compptr++) {
  148041. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  148042. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  148043. compptr->width_in_blocks * DCTSIZE,
  148044. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  148045. (long) compptr->v_samp_factor) * DCTSIZE,
  148046. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148047. }
  148048. #else
  148049. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148050. #endif
  148051. } else {
  148052. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148053. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  148054. #endif
  148055. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148056. ci++, compptr++) {
  148057. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  148058. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148059. compptr->width_in_blocks * DCTSIZE,
  148060. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148061. }
  148062. }
  148063. }
  148064. /*** End of inlined file: jcmainct.c ***/
  148065. /*** Start of inlined file: jcmarker.c ***/
  148066. #define JPEG_INTERNALS
  148067. typedef struct {
  148068. struct jpeg_marker_writer pub; /* public fields */
  148069. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  148070. } my_marker_writer;
  148071. typedef my_marker_writer * my_marker_ptr;
  148072. LOCAL(void)
  148073. emit_byte (j_compress_ptr cinfo, int val)
  148074. {
  148075. struct jpeg_destination_mgr * dest = cinfo->dest;
  148076. *(dest->next_output_byte)++ = (JOCTET) val;
  148077. if (--dest->free_in_buffer == 0) {
  148078. if (! (*dest->empty_output_buffer) (cinfo))
  148079. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  148080. }
  148081. }
  148082. LOCAL(void)
  148083. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  148084. {
  148085. emit_byte(cinfo, 0xFF);
  148086. emit_byte(cinfo, (int) mark);
  148087. }
  148088. LOCAL(void)
  148089. emit_2bytes (j_compress_ptr cinfo, int value)
  148090. {
  148091. emit_byte(cinfo, (value >> 8) & 0xFF);
  148092. emit_byte(cinfo, value & 0xFF);
  148093. }
  148094. LOCAL(int)
  148095. emit_dqt (j_compress_ptr cinfo, int index)
  148096. {
  148097. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  148098. int prec;
  148099. int i;
  148100. if (qtbl == NULL)
  148101. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  148102. prec = 0;
  148103. for (i = 0; i < DCTSIZE2; i++) {
  148104. if (qtbl->quantval[i] > 255)
  148105. prec = 1;
  148106. }
  148107. if (! qtbl->sent_table) {
  148108. emit_marker(cinfo, M_DQT);
  148109. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  148110. emit_byte(cinfo, index + (prec<<4));
  148111. for (i = 0; i < DCTSIZE2; i++) {
  148112. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  148113. if (prec)
  148114. emit_byte(cinfo, (int) (qval >> 8));
  148115. emit_byte(cinfo, (int) (qval & 0xFF));
  148116. }
  148117. qtbl->sent_table = TRUE;
  148118. }
  148119. return prec;
  148120. }
  148121. LOCAL(void)
  148122. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  148123. {
  148124. JHUFF_TBL * htbl;
  148125. int length, i;
  148126. if (is_ac) {
  148127. htbl = cinfo->ac_huff_tbl_ptrs[index];
  148128. index += 0x10; /* output index has AC bit set */
  148129. } else {
  148130. htbl = cinfo->dc_huff_tbl_ptrs[index];
  148131. }
  148132. if (htbl == NULL)
  148133. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  148134. if (! htbl->sent_table) {
  148135. emit_marker(cinfo, M_DHT);
  148136. length = 0;
  148137. for (i = 1; i <= 16; i++)
  148138. length += htbl->bits[i];
  148139. emit_2bytes(cinfo, length + 2 + 1 + 16);
  148140. emit_byte(cinfo, index);
  148141. for (i = 1; i <= 16; i++)
  148142. emit_byte(cinfo, htbl->bits[i]);
  148143. for (i = 0; i < length; i++)
  148144. emit_byte(cinfo, htbl->huffval[i]);
  148145. htbl->sent_table = TRUE;
  148146. }
  148147. }
  148148. LOCAL(void)
  148149. emit_dac (j_compress_ptr cinfo)
  148150. {
  148151. #ifdef C_ARITH_CODING_SUPPORTED
  148152. char dc_in_use[NUM_ARITH_TBLS];
  148153. char ac_in_use[NUM_ARITH_TBLS];
  148154. int length, i;
  148155. jpeg_component_info *compptr;
  148156. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148157. dc_in_use[i] = ac_in_use[i] = 0;
  148158. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148159. compptr = cinfo->cur_comp_info[i];
  148160. dc_in_use[compptr->dc_tbl_no] = 1;
  148161. ac_in_use[compptr->ac_tbl_no] = 1;
  148162. }
  148163. length = 0;
  148164. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148165. length += dc_in_use[i] + ac_in_use[i];
  148166. emit_marker(cinfo, M_DAC);
  148167. emit_2bytes(cinfo, length*2 + 2);
  148168. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148169. if (dc_in_use[i]) {
  148170. emit_byte(cinfo, i);
  148171. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  148172. }
  148173. if (ac_in_use[i]) {
  148174. emit_byte(cinfo, i + 0x10);
  148175. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  148176. }
  148177. }
  148178. #endif /* C_ARITH_CODING_SUPPORTED */
  148179. }
  148180. LOCAL(void)
  148181. emit_dri (j_compress_ptr cinfo)
  148182. {
  148183. emit_marker(cinfo, M_DRI);
  148184. emit_2bytes(cinfo, 4); /* fixed length */
  148185. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  148186. }
  148187. LOCAL(void)
  148188. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  148189. {
  148190. int ci;
  148191. jpeg_component_info *compptr;
  148192. emit_marker(cinfo, code);
  148193. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  148194. if ((long) cinfo->image_height > 65535L ||
  148195. (long) cinfo->image_width > 65535L)
  148196. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  148197. emit_byte(cinfo, cinfo->data_precision);
  148198. emit_2bytes(cinfo, (int) cinfo->image_height);
  148199. emit_2bytes(cinfo, (int) cinfo->image_width);
  148200. emit_byte(cinfo, cinfo->num_components);
  148201. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148202. ci++, compptr++) {
  148203. emit_byte(cinfo, compptr->component_id);
  148204. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  148205. emit_byte(cinfo, compptr->quant_tbl_no);
  148206. }
  148207. }
  148208. LOCAL(void)
  148209. emit_sos (j_compress_ptr cinfo)
  148210. {
  148211. int i, td, ta;
  148212. jpeg_component_info *compptr;
  148213. emit_marker(cinfo, M_SOS);
  148214. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  148215. emit_byte(cinfo, cinfo->comps_in_scan);
  148216. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148217. compptr = cinfo->cur_comp_info[i];
  148218. emit_byte(cinfo, compptr->component_id);
  148219. td = compptr->dc_tbl_no;
  148220. ta = compptr->ac_tbl_no;
  148221. if (cinfo->progressive_mode) {
  148222. if (cinfo->Ss == 0) {
  148223. ta = 0; /* DC scan */
  148224. if (cinfo->Ah != 0 && !cinfo->arith_code)
  148225. td = 0; /* no DC table either */
  148226. } else {
  148227. td = 0; /* AC scan */
  148228. }
  148229. }
  148230. emit_byte(cinfo, (td << 4) + ta);
  148231. }
  148232. emit_byte(cinfo, cinfo->Ss);
  148233. emit_byte(cinfo, cinfo->Se);
  148234. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  148235. }
  148236. LOCAL(void)
  148237. emit_jfif_app0 (j_compress_ptr cinfo)
  148238. {
  148239. emit_marker(cinfo, M_APP0);
  148240. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  148241. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  148242. emit_byte(cinfo, 0x46);
  148243. emit_byte(cinfo, 0x49);
  148244. emit_byte(cinfo, 0x46);
  148245. emit_byte(cinfo, 0);
  148246. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  148247. emit_byte(cinfo, cinfo->JFIF_minor_version);
  148248. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  148249. emit_2bytes(cinfo, (int) cinfo->X_density);
  148250. emit_2bytes(cinfo, (int) cinfo->Y_density);
  148251. emit_byte(cinfo, 0); /* No thumbnail image */
  148252. emit_byte(cinfo, 0);
  148253. }
  148254. LOCAL(void)
  148255. emit_adobe_app14 (j_compress_ptr cinfo)
  148256. {
  148257. emit_marker(cinfo, M_APP14);
  148258. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  148259. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  148260. emit_byte(cinfo, 0x64);
  148261. emit_byte(cinfo, 0x6F);
  148262. emit_byte(cinfo, 0x62);
  148263. emit_byte(cinfo, 0x65);
  148264. emit_2bytes(cinfo, 100); /* Version */
  148265. emit_2bytes(cinfo, 0); /* Flags0 */
  148266. emit_2bytes(cinfo, 0); /* Flags1 */
  148267. switch (cinfo->jpeg_color_space) {
  148268. case JCS_YCbCr:
  148269. emit_byte(cinfo, 1); /* Color transform = 1 */
  148270. break;
  148271. case JCS_YCCK:
  148272. emit_byte(cinfo, 2); /* Color transform = 2 */
  148273. break;
  148274. default:
  148275. emit_byte(cinfo, 0); /* Color transform = 0 */
  148276. break;
  148277. }
  148278. }
  148279. METHODDEF(void)
  148280. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  148281. {
  148282. if (datalen > (unsigned int) 65533) /* safety check */
  148283. ERREXIT(cinfo, JERR_BAD_LENGTH);
  148284. emit_marker(cinfo, (JPEG_MARKER) marker);
  148285. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148286. }
  148287. METHODDEF(void)
  148288. write_marker_byte (j_compress_ptr cinfo, int val)
  148289. {
  148290. emit_byte(cinfo, val);
  148291. }
  148292. METHODDEF(void)
  148293. write_file_header (j_compress_ptr cinfo)
  148294. {
  148295. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148296. emit_marker(cinfo, M_SOI); /* first the SOI */
  148297. marker->last_restart_interval = 0;
  148298. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148299. emit_jfif_app0(cinfo);
  148300. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148301. emit_adobe_app14(cinfo);
  148302. }
  148303. METHODDEF(void)
  148304. write_frame_header (j_compress_ptr cinfo)
  148305. {
  148306. int ci, prec;
  148307. boolean is_baseline;
  148308. jpeg_component_info *compptr;
  148309. prec = 0;
  148310. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148311. ci++, compptr++) {
  148312. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148313. }
  148314. if (cinfo->arith_code || cinfo->progressive_mode ||
  148315. cinfo->data_precision != 8) {
  148316. is_baseline = FALSE;
  148317. } else {
  148318. is_baseline = TRUE;
  148319. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148320. ci++, compptr++) {
  148321. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148322. is_baseline = FALSE;
  148323. }
  148324. if (prec && is_baseline) {
  148325. is_baseline = FALSE;
  148326. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148327. }
  148328. }
  148329. if (cinfo->arith_code) {
  148330. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148331. } else {
  148332. if (cinfo->progressive_mode)
  148333. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148334. else if (is_baseline)
  148335. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148336. else
  148337. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148338. }
  148339. }
  148340. METHODDEF(void)
  148341. write_scan_header (j_compress_ptr cinfo)
  148342. {
  148343. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148344. int i;
  148345. jpeg_component_info *compptr;
  148346. if (cinfo->arith_code) {
  148347. emit_dac(cinfo);
  148348. } else {
  148349. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148350. compptr = cinfo->cur_comp_info[i];
  148351. if (cinfo->progressive_mode) {
  148352. if (cinfo->Ss == 0) {
  148353. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148354. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148355. } else {
  148356. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148357. }
  148358. } else {
  148359. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148360. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148361. }
  148362. }
  148363. }
  148364. if (cinfo->restart_interval != marker->last_restart_interval) {
  148365. emit_dri(cinfo);
  148366. marker->last_restart_interval = cinfo->restart_interval;
  148367. }
  148368. emit_sos(cinfo);
  148369. }
  148370. METHODDEF(void)
  148371. write_file_trailer (j_compress_ptr cinfo)
  148372. {
  148373. emit_marker(cinfo, M_EOI);
  148374. }
  148375. METHODDEF(void)
  148376. write_tables_only (j_compress_ptr cinfo)
  148377. {
  148378. int i;
  148379. emit_marker(cinfo, M_SOI);
  148380. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148381. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148382. (void) emit_dqt(cinfo, i);
  148383. }
  148384. if (! cinfo->arith_code) {
  148385. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148386. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148387. emit_dht(cinfo, i, FALSE);
  148388. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148389. emit_dht(cinfo, i, TRUE);
  148390. }
  148391. }
  148392. emit_marker(cinfo, M_EOI);
  148393. }
  148394. GLOBAL(void)
  148395. jinit_marker_writer (j_compress_ptr cinfo)
  148396. {
  148397. my_marker_ptr marker;
  148398. marker = (my_marker_ptr)
  148399. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148400. SIZEOF(my_marker_writer));
  148401. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148402. marker->pub.write_file_header = write_file_header;
  148403. marker->pub.write_frame_header = write_frame_header;
  148404. marker->pub.write_scan_header = write_scan_header;
  148405. marker->pub.write_file_trailer = write_file_trailer;
  148406. marker->pub.write_tables_only = write_tables_only;
  148407. marker->pub.write_marker_header = write_marker_header;
  148408. marker->pub.write_marker_byte = write_marker_byte;
  148409. marker->last_restart_interval = 0;
  148410. }
  148411. /*** End of inlined file: jcmarker.c ***/
  148412. /*** Start of inlined file: jcmaster.c ***/
  148413. #define JPEG_INTERNALS
  148414. typedef enum {
  148415. main_pass, /* input data, also do first output step */
  148416. huff_opt_pass, /* Huffman code optimization pass */
  148417. output_pass /* data output pass */
  148418. } c_pass_type;
  148419. typedef struct {
  148420. struct jpeg_comp_master pub; /* public fields */
  148421. c_pass_type pass_type; /* the type of the current pass */
  148422. int pass_number; /* # of passes completed */
  148423. int total_passes; /* total # of passes needed */
  148424. int scan_number; /* current index in scan_info[] */
  148425. } my_comp_master;
  148426. typedef my_comp_master * my_master_ptr;
  148427. LOCAL(void)
  148428. initial_setup (j_compress_ptr cinfo)
  148429. {
  148430. int ci;
  148431. jpeg_component_info *compptr;
  148432. long samplesperrow;
  148433. JDIMENSION jd_samplesperrow;
  148434. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148435. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148436. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148437. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148438. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148439. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148440. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148441. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148442. if ((long) jd_samplesperrow != samplesperrow)
  148443. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148444. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148445. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148446. if (cinfo->num_components > MAX_COMPONENTS)
  148447. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148448. MAX_COMPONENTS);
  148449. cinfo->max_h_samp_factor = 1;
  148450. cinfo->max_v_samp_factor = 1;
  148451. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148452. ci++, compptr++) {
  148453. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148454. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148455. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148456. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148457. compptr->h_samp_factor);
  148458. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148459. compptr->v_samp_factor);
  148460. }
  148461. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148462. ci++, compptr++) {
  148463. compptr->component_index = ci;
  148464. compptr->DCT_scaled_size = DCTSIZE;
  148465. compptr->width_in_blocks = (JDIMENSION)
  148466. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148467. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148468. compptr->height_in_blocks = (JDIMENSION)
  148469. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148470. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148471. compptr->downsampled_width = (JDIMENSION)
  148472. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148473. (long) cinfo->max_h_samp_factor);
  148474. compptr->downsampled_height = (JDIMENSION)
  148475. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148476. (long) cinfo->max_v_samp_factor);
  148477. compptr->component_needed = TRUE;
  148478. }
  148479. cinfo->total_iMCU_rows = (JDIMENSION)
  148480. jdiv_round_up((long) cinfo->image_height,
  148481. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148482. }
  148483. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148484. LOCAL(void)
  148485. validate_script (j_compress_ptr cinfo)
  148486. {
  148487. const jpeg_scan_info * scanptr;
  148488. int scanno, ncomps, ci, coefi, thisi;
  148489. int Ss, Se, Ah, Al;
  148490. boolean component_sent[MAX_COMPONENTS];
  148491. #ifdef C_PROGRESSIVE_SUPPORTED
  148492. int * last_bitpos_ptr;
  148493. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148494. #endif
  148495. if (cinfo->num_scans <= 0)
  148496. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148497. scanptr = cinfo->scan_info;
  148498. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148499. #ifdef C_PROGRESSIVE_SUPPORTED
  148500. cinfo->progressive_mode = TRUE;
  148501. last_bitpos_ptr = & last_bitpos[0][0];
  148502. for (ci = 0; ci < cinfo->num_components; ci++)
  148503. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148504. *last_bitpos_ptr++ = -1;
  148505. #else
  148506. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148507. #endif
  148508. } else {
  148509. cinfo->progressive_mode = FALSE;
  148510. for (ci = 0; ci < cinfo->num_components; ci++)
  148511. component_sent[ci] = FALSE;
  148512. }
  148513. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148514. ncomps = scanptr->comps_in_scan;
  148515. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148516. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148517. for (ci = 0; ci < ncomps; ci++) {
  148518. thisi = scanptr->component_index[ci];
  148519. if (thisi < 0 || thisi >= cinfo->num_components)
  148520. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148521. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148522. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148523. }
  148524. Ss = scanptr->Ss;
  148525. Se = scanptr->Se;
  148526. Ah = scanptr->Ah;
  148527. Al = scanptr->Al;
  148528. if (cinfo->progressive_mode) {
  148529. #ifdef C_PROGRESSIVE_SUPPORTED
  148530. #if BITS_IN_JSAMPLE == 8
  148531. #define MAX_AH_AL 10
  148532. #else
  148533. #define MAX_AH_AL 13
  148534. #endif
  148535. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148536. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148537. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148538. if (Ss == 0) {
  148539. if (Se != 0) /* DC and AC together not OK */
  148540. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148541. } else {
  148542. if (ncomps != 1) /* AC scans must be for only one component */
  148543. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148544. }
  148545. for (ci = 0; ci < ncomps; ci++) {
  148546. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148547. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148548. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148549. for (coefi = Ss; coefi <= Se; coefi++) {
  148550. if (last_bitpos_ptr[coefi] < 0) {
  148551. if (Ah != 0)
  148552. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148553. } else {
  148554. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148555. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148556. }
  148557. last_bitpos_ptr[coefi] = Al;
  148558. }
  148559. }
  148560. #endif
  148561. } else {
  148562. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148563. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148564. for (ci = 0; ci < ncomps; ci++) {
  148565. thisi = scanptr->component_index[ci];
  148566. if (component_sent[thisi])
  148567. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148568. component_sent[thisi] = TRUE;
  148569. }
  148570. }
  148571. }
  148572. if (cinfo->progressive_mode) {
  148573. #ifdef C_PROGRESSIVE_SUPPORTED
  148574. for (ci = 0; ci < cinfo->num_components; ci++) {
  148575. if (last_bitpos[ci][0] < 0)
  148576. ERREXIT(cinfo, JERR_MISSING_DATA);
  148577. }
  148578. #endif
  148579. } else {
  148580. for (ci = 0; ci < cinfo->num_components; ci++) {
  148581. if (! component_sent[ci])
  148582. ERREXIT(cinfo, JERR_MISSING_DATA);
  148583. }
  148584. }
  148585. }
  148586. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148587. LOCAL(void)
  148588. select_scan_parameters (j_compress_ptr cinfo)
  148589. {
  148590. int ci;
  148591. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148592. if (cinfo->scan_info != NULL) {
  148593. my_master_ptr master = (my_master_ptr) cinfo->master;
  148594. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148595. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148596. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148597. cinfo->cur_comp_info[ci] =
  148598. &cinfo->comp_info[scanptr->component_index[ci]];
  148599. }
  148600. cinfo->Ss = scanptr->Ss;
  148601. cinfo->Se = scanptr->Se;
  148602. cinfo->Ah = scanptr->Ah;
  148603. cinfo->Al = scanptr->Al;
  148604. }
  148605. else
  148606. #endif
  148607. {
  148608. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148609. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148610. MAX_COMPS_IN_SCAN);
  148611. cinfo->comps_in_scan = cinfo->num_components;
  148612. for (ci = 0; ci < cinfo->num_components; ci++) {
  148613. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148614. }
  148615. cinfo->Ss = 0;
  148616. cinfo->Se = DCTSIZE2-1;
  148617. cinfo->Ah = 0;
  148618. cinfo->Al = 0;
  148619. }
  148620. }
  148621. LOCAL(void)
  148622. per_scan_setup (j_compress_ptr cinfo)
  148623. {
  148624. int ci, mcublks, tmp;
  148625. jpeg_component_info *compptr;
  148626. if (cinfo->comps_in_scan == 1) {
  148627. compptr = cinfo->cur_comp_info[0];
  148628. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148629. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148630. compptr->MCU_width = 1;
  148631. compptr->MCU_height = 1;
  148632. compptr->MCU_blocks = 1;
  148633. compptr->MCU_sample_width = DCTSIZE;
  148634. compptr->last_col_width = 1;
  148635. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148636. if (tmp == 0) tmp = compptr->v_samp_factor;
  148637. compptr->last_row_height = tmp;
  148638. cinfo->blocks_in_MCU = 1;
  148639. cinfo->MCU_membership[0] = 0;
  148640. } else {
  148641. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148642. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148643. MAX_COMPS_IN_SCAN);
  148644. cinfo->MCUs_per_row = (JDIMENSION)
  148645. jdiv_round_up((long) cinfo->image_width,
  148646. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148647. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148648. jdiv_round_up((long) cinfo->image_height,
  148649. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148650. cinfo->blocks_in_MCU = 0;
  148651. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148652. compptr = cinfo->cur_comp_info[ci];
  148653. compptr->MCU_width = compptr->h_samp_factor;
  148654. compptr->MCU_height = compptr->v_samp_factor;
  148655. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148656. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148657. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148658. if (tmp == 0) tmp = compptr->MCU_width;
  148659. compptr->last_col_width = tmp;
  148660. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148661. if (tmp == 0) tmp = compptr->MCU_height;
  148662. compptr->last_row_height = tmp;
  148663. mcublks = compptr->MCU_blocks;
  148664. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148665. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148666. while (mcublks-- > 0) {
  148667. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148668. }
  148669. }
  148670. }
  148671. if (cinfo->restart_in_rows > 0) {
  148672. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148673. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148674. }
  148675. }
  148676. METHODDEF(void)
  148677. prepare_for_pass (j_compress_ptr cinfo)
  148678. {
  148679. my_master_ptr master = (my_master_ptr) cinfo->master;
  148680. switch (master->pass_type) {
  148681. case main_pass:
  148682. select_scan_parameters(cinfo);
  148683. per_scan_setup(cinfo);
  148684. if (! cinfo->raw_data_in) {
  148685. (*cinfo->cconvert->start_pass) (cinfo);
  148686. (*cinfo->downsample->start_pass) (cinfo);
  148687. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148688. }
  148689. (*cinfo->fdct->start_pass) (cinfo);
  148690. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148691. (*cinfo->coef->start_pass) (cinfo,
  148692. (master->total_passes > 1 ?
  148693. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148694. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148695. if (cinfo->optimize_coding) {
  148696. master->pub.call_pass_startup = FALSE;
  148697. } else {
  148698. master->pub.call_pass_startup = TRUE;
  148699. }
  148700. break;
  148701. #ifdef ENTROPY_OPT_SUPPORTED
  148702. case huff_opt_pass:
  148703. select_scan_parameters(cinfo);
  148704. per_scan_setup(cinfo);
  148705. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148706. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148707. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148708. master->pub.call_pass_startup = FALSE;
  148709. break;
  148710. }
  148711. master->pass_type = output_pass;
  148712. master->pass_number++;
  148713. #endif
  148714. case output_pass:
  148715. if (! cinfo->optimize_coding) {
  148716. select_scan_parameters(cinfo);
  148717. per_scan_setup(cinfo);
  148718. }
  148719. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148720. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148721. if (master->scan_number == 0)
  148722. (*cinfo->marker->write_frame_header) (cinfo);
  148723. (*cinfo->marker->write_scan_header) (cinfo);
  148724. master->pub.call_pass_startup = FALSE;
  148725. break;
  148726. default:
  148727. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148728. }
  148729. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148730. if (cinfo->progress != NULL) {
  148731. cinfo->progress->completed_passes = master->pass_number;
  148732. cinfo->progress->total_passes = master->total_passes;
  148733. }
  148734. }
  148735. METHODDEF(void)
  148736. pass_startup (j_compress_ptr cinfo)
  148737. {
  148738. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148739. (*cinfo->marker->write_frame_header) (cinfo);
  148740. (*cinfo->marker->write_scan_header) (cinfo);
  148741. }
  148742. METHODDEF(void)
  148743. finish_pass_master (j_compress_ptr cinfo)
  148744. {
  148745. my_master_ptr master = (my_master_ptr) cinfo->master;
  148746. (*cinfo->entropy->finish_pass) (cinfo);
  148747. switch (master->pass_type) {
  148748. case main_pass:
  148749. master->pass_type = output_pass;
  148750. if (! cinfo->optimize_coding)
  148751. master->scan_number++;
  148752. break;
  148753. case huff_opt_pass:
  148754. master->pass_type = output_pass;
  148755. break;
  148756. case output_pass:
  148757. if (cinfo->optimize_coding)
  148758. master->pass_type = huff_opt_pass;
  148759. master->scan_number++;
  148760. break;
  148761. }
  148762. master->pass_number++;
  148763. }
  148764. GLOBAL(void)
  148765. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148766. {
  148767. my_master_ptr master;
  148768. master = (my_master_ptr)
  148769. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148770. SIZEOF(my_comp_master));
  148771. cinfo->master = (struct jpeg_comp_master *) master;
  148772. master->pub.prepare_for_pass = prepare_for_pass;
  148773. master->pub.pass_startup = pass_startup;
  148774. master->pub.finish_pass = finish_pass_master;
  148775. master->pub.is_last_pass = FALSE;
  148776. initial_setup(cinfo);
  148777. if (cinfo->scan_info != NULL) {
  148778. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148779. validate_script(cinfo);
  148780. #else
  148781. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148782. #endif
  148783. } else {
  148784. cinfo->progressive_mode = FALSE;
  148785. cinfo->num_scans = 1;
  148786. }
  148787. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148788. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148789. if (transcode_only) {
  148790. if (cinfo->optimize_coding)
  148791. master->pass_type = huff_opt_pass;
  148792. else
  148793. master->pass_type = output_pass;
  148794. } else {
  148795. master->pass_type = main_pass;
  148796. }
  148797. master->scan_number = 0;
  148798. master->pass_number = 0;
  148799. if (cinfo->optimize_coding)
  148800. master->total_passes = cinfo->num_scans * 2;
  148801. else
  148802. master->total_passes = cinfo->num_scans;
  148803. }
  148804. /*** End of inlined file: jcmaster.c ***/
  148805. /*** Start of inlined file: jcomapi.c ***/
  148806. #define JPEG_INTERNALS
  148807. GLOBAL(void)
  148808. jpeg_abort (j_common_ptr cinfo)
  148809. {
  148810. int pool;
  148811. if (cinfo->mem == NULL)
  148812. return;
  148813. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148814. (*cinfo->mem->free_pool) (cinfo, pool);
  148815. }
  148816. if (cinfo->is_decompressor) {
  148817. cinfo->global_state = DSTATE_START;
  148818. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148819. } else {
  148820. cinfo->global_state = CSTATE_START;
  148821. }
  148822. }
  148823. GLOBAL(void)
  148824. jpeg_destroy (j_common_ptr cinfo)
  148825. {
  148826. if (cinfo->mem != NULL)
  148827. (*cinfo->mem->self_destruct) (cinfo);
  148828. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148829. cinfo->global_state = 0; /* mark it destroyed */
  148830. }
  148831. GLOBAL(JQUANT_TBL *)
  148832. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148833. {
  148834. JQUANT_TBL *tbl;
  148835. tbl = (JQUANT_TBL *)
  148836. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148837. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148838. return tbl;
  148839. }
  148840. GLOBAL(JHUFF_TBL *)
  148841. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148842. {
  148843. JHUFF_TBL *tbl;
  148844. tbl = (JHUFF_TBL *)
  148845. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148846. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148847. return tbl;
  148848. }
  148849. /*** End of inlined file: jcomapi.c ***/
  148850. /*** Start of inlined file: jcparam.c ***/
  148851. #define JPEG_INTERNALS
  148852. GLOBAL(void)
  148853. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148854. const unsigned int *basic_table,
  148855. int scale_factor, boolean force_baseline)
  148856. {
  148857. JQUANT_TBL ** qtblptr;
  148858. int i;
  148859. long temp;
  148860. if (cinfo->global_state != CSTATE_START)
  148861. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148862. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148863. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148864. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148865. if (*qtblptr == NULL)
  148866. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148867. for (i = 0; i < DCTSIZE2; i++) {
  148868. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148869. if (temp <= 0L) temp = 1L;
  148870. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148871. if (force_baseline && temp > 255L)
  148872. temp = 255L; /* limit to baseline range if requested */
  148873. (*qtblptr)->quantval[i] = (UINT16) temp;
  148874. }
  148875. (*qtblptr)->sent_table = FALSE;
  148876. }
  148877. GLOBAL(void)
  148878. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148879. boolean force_baseline)
  148880. {
  148881. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148882. 16, 11, 10, 16, 24, 40, 51, 61,
  148883. 12, 12, 14, 19, 26, 58, 60, 55,
  148884. 14, 13, 16, 24, 40, 57, 69, 56,
  148885. 14, 17, 22, 29, 51, 87, 80, 62,
  148886. 18, 22, 37, 56, 68, 109, 103, 77,
  148887. 24, 35, 55, 64, 81, 104, 113, 92,
  148888. 49, 64, 78, 87, 103, 121, 120, 101,
  148889. 72, 92, 95, 98, 112, 100, 103, 99
  148890. };
  148891. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148892. 17, 18, 24, 47, 99, 99, 99, 99,
  148893. 18, 21, 26, 66, 99, 99, 99, 99,
  148894. 24, 26, 56, 99, 99, 99, 99, 99,
  148895. 47, 66, 99, 99, 99, 99, 99, 99,
  148896. 99, 99, 99, 99, 99, 99, 99, 99,
  148897. 99, 99, 99, 99, 99, 99, 99, 99,
  148898. 99, 99, 99, 99, 99, 99, 99, 99,
  148899. 99, 99, 99, 99, 99, 99, 99, 99
  148900. };
  148901. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148902. scale_factor, force_baseline);
  148903. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148904. scale_factor, force_baseline);
  148905. }
  148906. GLOBAL(int)
  148907. jpeg_quality_scaling (int quality)
  148908. {
  148909. if (quality <= 0) quality = 1;
  148910. if (quality > 100) quality = 100;
  148911. if (quality < 50)
  148912. quality = 5000 / quality;
  148913. else
  148914. quality = 200 - quality*2;
  148915. return quality;
  148916. }
  148917. GLOBAL(void)
  148918. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148919. {
  148920. quality = jpeg_quality_scaling(quality);
  148921. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148922. }
  148923. LOCAL(void)
  148924. add_huff_table (j_compress_ptr cinfo,
  148925. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148926. {
  148927. int nsymbols, len;
  148928. if (*htblptr == NULL)
  148929. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148930. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148931. nsymbols = 0;
  148932. for (len = 1; len <= 16; len++)
  148933. nsymbols += bits[len];
  148934. if (nsymbols < 1 || nsymbols > 256)
  148935. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148936. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148937. (*htblptr)->sent_table = FALSE;
  148938. }
  148939. LOCAL(void)
  148940. std_huff_tables (j_compress_ptr cinfo)
  148941. {
  148942. static const UINT8 bits_dc_luminance[17] =
  148943. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148944. static const UINT8 val_dc_luminance[] =
  148945. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148946. static const UINT8 bits_dc_chrominance[17] =
  148947. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148948. static const UINT8 val_dc_chrominance[] =
  148949. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148950. static const UINT8 bits_ac_luminance[17] =
  148951. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148952. static const UINT8 val_ac_luminance[] =
  148953. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148954. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148955. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148956. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148957. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148958. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148959. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148960. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148961. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148962. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148963. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148964. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148965. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148966. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148967. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148968. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148969. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148970. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148971. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148972. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148973. 0xf9, 0xfa };
  148974. static const UINT8 bits_ac_chrominance[17] =
  148975. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148976. static const UINT8 val_ac_chrominance[] =
  148977. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148978. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148979. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148980. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148981. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148982. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148983. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148984. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148985. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148986. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148987. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148988. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148989. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148990. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148991. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148992. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148993. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148994. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148995. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148996. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148997. 0xf9, 0xfa };
  148998. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148999. bits_dc_luminance, val_dc_luminance);
  149000. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  149001. bits_ac_luminance, val_ac_luminance);
  149002. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  149003. bits_dc_chrominance, val_dc_chrominance);
  149004. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  149005. bits_ac_chrominance, val_ac_chrominance);
  149006. }
  149007. GLOBAL(void)
  149008. jpeg_set_defaults (j_compress_ptr cinfo)
  149009. {
  149010. int i;
  149011. if (cinfo->global_state != CSTATE_START)
  149012. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149013. if (cinfo->comp_info == NULL)
  149014. cinfo->comp_info = (jpeg_component_info *)
  149015. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149016. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  149017. cinfo->data_precision = BITS_IN_JSAMPLE;
  149018. jpeg_set_quality(cinfo, 75, TRUE);
  149019. std_huff_tables(cinfo);
  149020. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  149021. cinfo->arith_dc_L[i] = 0;
  149022. cinfo->arith_dc_U[i] = 1;
  149023. cinfo->arith_ac_K[i] = 5;
  149024. }
  149025. cinfo->scan_info = NULL;
  149026. cinfo->num_scans = 0;
  149027. cinfo->raw_data_in = FALSE;
  149028. cinfo->arith_code = FALSE;
  149029. cinfo->optimize_coding = FALSE;
  149030. if (cinfo->data_precision > 8)
  149031. cinfo->optimize_coding = TRUE;
  149032. cinfo->CCIR601_sampling = FALSE;
  149033. cinfo->smoothing_factor = 0;
  149034. cinfo->dct_method = JDCT_DEFAULT;
  149035. cinfo->restart_interval = 0;
  149036. cinfo->restart_in_rows = 0;
  149037. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  149038. cinfo->JFIF_minor_version = 1;
  149039. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  149040. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  149041. cinfo->Y_density = 1;
  149042. jpeg_default_colorspace(cinfo);
  149043. }
  149044. GLOBAL(void)
  149045. jpeg_default_colorspace (j_compress_ptr cinfo)
  149046. {
  149047. switch (cinfo->in_color_space) {
  149048. case JCS_GRAYSCALE:
  149049. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  149050. break;
  149051. case JCS_RGB:
  149052. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149053. break;
  149054. case JCS_YCbCr:
  149055. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149056. break;
  149057. case JCS_CMYK:
  149058. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  149059. break;
  149060. case JCS_YCCK:
  149061. jpeg_set_colorspace(cinfo, JCS_YCCK);
  149062. break;
  149063. case JCS_UNKNOWN:
  149064. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  149065. break;
  149066. default:
  149067. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  149068. }
  149069. }
  149070. GLOBAL(void)
  149071. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  149072. {
  149073. jpeg_component_info * compptr;
  149074. int ci;
  149075. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  149076. (compptr = &cinfo->comp_info[index], \
  149077. compptr->component_id = (id), \
  149078. compptr->h_samp_factor = (hsamp), \
  149079. compptr->v_samp_factor = (vsamp), \
  149080. compptr->quant_tbl_no = (quant), \
  149081. compptr->dc_tbl_no = (dctbl), \
  149082. compptr->ac_tbl_no = (actbl) )
  149083. if (cinfo->global_state != CSTATE_START)
  149084. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149085. cinfo->jpeg_color_space = colorspace;
  149086. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  149087. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  149088. switch (colorspace) {
  149089. case JCS_GRAYSCALE:
  149090. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149091. cinfo->num_components = 1;
  149092. SET_COMP(0, 1, 1,1, 0, 0,0);
  149093. break;
  149094. case JCS_RGB:
  149095. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  149096. cinfo->num_components = 3;
  149097. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  149098. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  149099. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  149100. break;
  149101. case JCS_YCbCr:
  149102. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149103. cinfo->num_components = 3;
  149104. SET_COMP(0, 1, 2,2, 0, 0,0);
  149105. SET_COMP(1, 2, 1,1, 1, 1,1);
  149106. SET_COMP(2, 3, 1,1, 1, 1,1);
  149107. break;
  149108. case JCS_CMYK:
  149109. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  149110. cinfo->num_components = 4;
  149111. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  149112. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  149113. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  149114. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  149115. break;
  149116. case JCS_YCCK:
  149117. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  149118. cinfo->num_components = 4;
  149119. SET_COMP(0, 1, 2,2, 0, 0,0);
  149120. SET_COMP(1, 2, 1,1, 1, 1,1);
  149121. SET_COMP(2, 3, 1,1, 1, 1,1);
  149122. SET_COMP(3, 4, 2,2, 0, 0,0);
  149123. break;
  149124. case JCS_UNKNOWN:
  149125. cinfo->num_components = cinfo->input_components;
  149126. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  149127. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  149128. MAX_COMPONENTS);
  149129. for (ci = 0; ci < cinfo->num_components; ci++) {
  149130. SET_COMP(ci, ci, 1,1, 0, 0,0);
  149131. }
  149132. break;
  149133. default:
  149134. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  149135. }
  149136. }
  149137. #ifdef C_PROGRESSIVE_SUPPORTED
  149138. LOCAL(jpeg_scan_info *)
  149139. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  149140. int Ss, int Se, int Ah, int Al)
  149141. {
  149142. scanptr->comps_in_scan = 1;
  149143. scanptr->component_index[0] = ci;
  149144. scanptr->Ss = Ss;
  149145. scanptr->Se = Se;
  149146. scanptr->Ah = Ah;
  149147. scanptr->Al = Al;
  149148. scanptr++;
  149149. return scanptr;
  149150. }
  149151. LOCAL(jpeg_scan_info *)
  149152. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  149153. int Ss, int Se, int Ah, int Al)
  149154. {
  149155. int ci;
  149156. for (ci = 0; ci < ncomps; ci++) {
  149157. scanptr->comps_in_scan = 1;
  149158. scanptr->component_index[0] = ci;
  149159. scanptr->Ss = Ss;
  149160. scanptr->Se = Se;
  149161. scanptr->Ah = Ah;
  149162. scanptr->Al = Al;
  149163. scanptr++;
  149164. }
  149165. return scanptr;
  149166. }
  149167. LOCAL(jpeg_scan_info *)
  149168. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  149169. {
  149170. int ci;
  149171. if (ncomps <= MAX_COMPS_IN_SCAN) {
  149172. scanptr->comps_in_scan = ncomps;
  149173. for (ci = 0; ci < ncomps; ci++)
  149174. scanptr->component_index[ci] = ci;
  149175. scanptr->Ss = scanptr->Se = 0;
  149176. scanptr->Ah = Ah;
  149177. scanptr->Al = Al;
  149178. scanptr++;
  149179. } else {
  149180. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  149181. }
  149182. return scanptr;
  149183. }
  149184. GLOBAL(void)
  149185. jpeg_simple_progression (j_compress_ptr cinfo)
  149186. {
  149187. int ncomps = cinfo->num_components;
  149188. int nscans;
  149189. jpeg_scan_info * scanptr;
  149190. if (cinfo->global_state != CSTATE_START)
  149191. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149192. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149193. nscans = 10;
  149194. } else {
  149195. if (ncomps > MAX_COMPS_IN_SCAN)
  149196. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  149197. else
  149198. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  149199. }
  149200. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  149201. cinfo->script_space_size = MAX(nscans, 10);
  149202. cinfo->script_space = (jpeg_scan_info *)
  149203. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149204. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  149205. }
  149206. scanptr = cinfo->script_space;
  149207. cinfo->scan_info = scanptr;
  149208. cinfo->num_scans = nscans;
  149209. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149210. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149211. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  149212. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  149213. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  149214. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  149215. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  149216. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149217. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  149218. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  149219. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  149220. } else {
  149221. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149222. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  149223. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  149224. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  149225. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149226. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  149227. }
  149228. }
  149229. #endif /* C_PROGRESSIVE_SUPPORTED */
  149230. /*** End of inlined file: jcparam.c ***/
  149231. /*** Start of inlined file: jcphuff.c ***/
  149232. #define JPEG_INTERNALS
  149233. #ifdef C_PROGRESSIVE_SUPPORTED
  149234. typedef struct {
  149235. struct jpeg_entropy_encoder pub; /* public fields */
  149236. boolean gather_statistics;
  149237. JOCTET * next_output_byte; /* => next byte to write in buffer */
  149238. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  149239. INT32 put_buffer; /* current bit-accumulation buffer */
  149240. int put_bits; /* # of bits now in it */
  149241. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  149242. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  149243. int ac_tbl_no; /* the table number of the single component */
  149244. unsigned int EOBRUN; /* run length of EOBs */
  149245. unsigned int BE; /* # of buffered correction bits before MCU */
  149246. char * bit_buffer; /* buffer for correction bits (1 per char) */
  149247. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  149248. int next_restart_num; /* next restart number to write (0-7) */
  149249. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  149250. long * count_ptrs[NUM_HUFF_TBLS];
  149251. } phuff_entropy_encoder;
  149252. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  149253. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  149254. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  149255. #define ISHIFT_TEMPS int ishift_temp;
  149256. #define IRIGHT_SHIFT(x,shft) \
  149257. ((ishift_temp = (x)) < 0 ? \
  149258. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  149259. (ishift_temp >> (shft)))
  149260. #else
  149261. #define ISHIFT_TEMPS
  149262. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  149263. #endif
  149264. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  149265. JBLOCKROW *MCU_data));
  149266. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  149267. JBLOCKROW *MCU_data));
  149268. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  149269. JBLOCKROW *MCU_data));
  149270. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  149271. JBLOCKROW *MCU_data));
  149272. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  149273. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  149274. METHODDEF(void)
  149275. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  149276. {
  149277. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149278. boolean is_DC_band;
  149279. int ci, tbl;
  149280. jpeg_component_info * compptr;
  149281. entropy->cinfo = cinfo;
  149282. entropy->gather_statistics = gather_statistics;
  149283. is_DC_band = (cinfo->Ss == 0);
  149284. if (cinfo->Ah == 0) {
  149285. if (is_DC_band)
  149286. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149287. else
  149288. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149289. } else {
  149290. if (is_DC_band)
  149291. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149292. else {
  149293. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149294. if (entropy->bit_buffer == NULL)
  149295. entropy->bit_buffer = (char *)
  149296. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149297. MAX_CORR_BITS * SIZEOF(char));
  149298. }
  149299. }
  149300. if (gather_statistics)
  149301. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149302. else
  149303. entropy->pub.finish_pass = finish_pass_phuff;
  149304. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149305. compptr = cinfo->cur_comp_info[ci];
  149306. entropy->last_dc_val[ci] = 0;
  149307. if (is_DC_band) {
  149308. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149309. continue;
  149310. tbl = compptr->dc_tbl_no;
  149311. } else {
  149312. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149313. }
  149314. if (gather_statistics) {
  149315. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149316. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149317. if (entropy->count_ptrs[tbl] == NULL)
  149318. entropy->count_ptrs[tbl] = (long *)
  149319. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149320. 257 * SIZEOF(long));
  149321. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149322. } else {
  149323. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149324. & entropy->derived_tbls[tbl]);
  149325. }
  149326. }
  149327. entropy->EOBRUN = 0;
  149328. entropy->BE = 0;
  149329. entropy->put_buffer = 0;
  149330. entropy->put_bits = 0;
  149331. entropy->restarts_to_go = cinfo->restart_interval;
  149332. entropy->next_restart_num = 0;
  149333. }
  149334. #define emit_byte(entropy,val) \
  149335. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149336. if (--(entropy)->free_in_buffer == 0) \
  149337. dump_buffer_p(entropy); }
  149338. LOCAL(void)
  149339. dump_buffer_p (phuff_entropy_ptr entropy)
  149340. {
  149341. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149342. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149343. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149344. entropy->next_output_byte = dest->next_output_byte;
  149345. entropy->free_in_buffer = dest->free_in_buffer;
  149346. }
  149347. INLINE
  149348. LOCAL(void)
  149349. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149350. {
  149351. register INT32 put_buffer = (INT32) code;
  149352. register int put_bits = entropy->put_bits;
  149353. if (size == 0)
  149354. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149355. if (entropy->gather_statistics)
  149356. return; /* do nothing if we're only getting stats */
  149357. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149358. put_bits += size; /* new number of bits in buffer */
  149359. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149360. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149361. while (put_bits >= 8) {
  149362. int c = (int) ((put_buffer >> 16) & 0xFF);
  149363. emit_byte(entropy, c);
  149364. if (c == 0xFF) { /* need to stuff a zero byte? */
  149365. emit_byte(entropy, 0);
  149366. }
  149367. put_buffer <<= 8;
  149368. put_bits -= 8;
  149369. }
  149370. entropy->put_buffer = put_buffer; /* update variables */
  149371. entropy->put_bits = put_bits;
  149372. }
  149373. LOCAL(void)
  149374. flush_bits_p (phuff_entropy_ptr entropy)
  149375. {
  149376. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149377. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149378. entropy->put_bits = 0;
  149379. }
  149380. INLINE
  149381. LOCAL(void)
  149382. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149383. {
  149384. if (entropy->gather_statistics)
  149385. entropy->count_ptrs[tbl_no][symbol]++;
  149386. else {
  149387. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149388. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149389. }
  149390. }
  149391. LOCAL(void)
  149392. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149393. unsigned int nbits)
  149394. {
  149395. if (entropy->gather_statistics)
  149396. return; /* no real work */
  149397. while (nbits > 0) {
  149398. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149399. bufstart++;
  149400. nbits--;
  149401. }
  149402. }
  149403. LOCAL(void)
  149404. emit_eobrun (phuff_entropy_ptr entropy)
  149405. {
  149406. register int temp, nbits;
  149407. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149408. temp = entropy->EOBRUN;
  149409. nbits = 0;
  149410. while ((temp >>= 1))
  149411. nbits++;
  149412. if (nbits > 14)
  149413. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149414. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149415. if (nbits)
  149416. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149417. entropy->EOBRUN = 0;
  149418. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149419. entropy->BE = 0;
  149420. }
  149421. }
  149422. LOCAL(void)
  149423. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149424. {
  149425. int ci;
  149426. emit_eobrun(entropy);
  149427. if (! entropy->gather_statistics) {
  149428. flush_bits_p(entropy);
  149429. emit_byte(entropy, 0xFF);
  149430. emit_byte(entropy, JPEG_RST0 + restart_num);
  149431. }
  149432. if (entropy->cinfo->Ss == 0) {
  149433. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149434. entropy->last_dc_val[ci] = 0;
  149435. } else {
  149436. entropy->EOBRUN = 0;
  149437. entropy->BE = 0;
  149438. }
  149439. }
  149440. METHODDEF(boolean)
  149441. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149442. {
  149443. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149444. register int temp, temp2;
  149445. register int nbits;
  149446. int blkn, ci;
  149447. int Al = cinfo->Al;
  149448. JBLOCKROW block;
  149449. jpeg_component_info * compptr;
  149450. ISHIFT_TEMPS
  149451. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149452. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149453. if (cinfo->restart_interval)
  149454. if (entropy->restarts_to_go == 0)
  149455. emit_restart_p(entropy, entropy->next_restart_num);
  149456. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149457. block = MCU_data[blkn];
  149458. ci = cinfo->MCU_membership[blkn];
  149459. compptr = cinfo->cur_comp_info[ci];
  149460. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149461. temp = temp2 - entropy->last_dc_val[ci];
  149462. entropy->last_dc_val[ci] = temp2;
  149463. temp2 = temp;
  149464. if (temp < 0) {
  149465. temp = -temp; /* temp is abs value of input */
  149466. temp2--;
  149467. }
  149468. nbits = 0;
  149469. while (temp) {
  149470. nbits++;
  149471. temp >>= 1;
  149472. }
  149473. if (nbits > MAX_COEF_BITS+1)
  149474. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149475. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149476. if (nbits) /* emit_bits rejects calls with size 0 */
  149477. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149478. }
  149479. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149480. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149481. if (cinfo->restart_interval) {
  149482. if (entropy->restarts_to_go == 0) {
  149483. entropy->restarts_to_go = cinfo->restart_interval;
  149484. entropy->next_restart_num++;
  149485. entropy->next_restart_num &= 7;
  149486. }
  149487. entropy->restarts_to_go--;
  149488. }
  149489. return TRUE;
  149490. }
  149491. METHODDEF(boolean)
  149492. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149493. {
  149494. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149495. register int temp, temp2;
  149496. register int nbits;
  149497. register int r, k;
  149498. int Se = cinfo->Se;
  149499. int Al = cinfo->Al;
  149500. JBLOCKROW block;
  149501. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149502. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149503. if (cinfo->restart_interval)
  149504. if (entropy->restarts_to_go == 0)
  149505. emit_restart_p(entropy, entropy->next_restart_num);
  149506. block = MCU_data[0];
  149507. r = 0; /* r = run length of zeros */
  149508. for (k = cinfo->Ss; k <= Se; k++) {
  149509. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149510. r++;
  149511. continue;
  149512. }
  149513. if (temp < 0) {
  149514. temp = -temp; /* temp is abs value of input */
  149515. temp >>= Al; /* apply the point transform */
  149516. temp2 = ~temp;
  149517. } else {
  149518. temp >>= Al; /* apply the point transform */
  149519. temp2 = temp;
  149520. }
  149521. if (temp == 0) {
  149522. r++;
  149523. continue;
  149524. }
  149525. if (entropy->EOBRUN > 0)
  149526. emit_eobrun(entropy);
  149527. while (r > 15) {
  149528. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149529. r -= 16;
  149530. }
  149531. nbits = 1; /* there must be at least one 1 bit */
  149532. while ((temp >>= 1))
  149533. nbits++;
  149534. if (nbits > MAX_COEF_BITS)
  149535. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149536. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149537. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149538. r = 0; /* reset zero run length */
  149539. }
  149540. if (r > 0) { /* If there are trailing zeroes, */
  149541. entropy->EOBRUN++; /* count an EOB */
  149542. if (entropy->EOBRUN == 0x7FFF)
  149543. emit_eobrun(entropy); /* force it out to avoid overflow */
  149544. }
  149545. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149546. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149547. if (cinfo->restart_interval) {
  149548. if (entropy->restarts_to_go == 0) {
  149549. entropy->restarts_to_go = cinfo->restart_interval;
  149550. entropy->next_restart_num++;
  149551. entropy->next_restart_num &= 7;
  149552. }
  149553. entropy->restarts_to_go--;
  149554. }
  149555. return TRUE;
  149556. }
  149557. METHODDEF(boolean)
  149558. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149559. {
  149560. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149561. register int temp;
  149562. int blkn;
  149563. int Al = cinfo->Al;
  149564. JBLOCKROW block;
  149565. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149566. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149567. if (cinfo->restart_interval)
  149568. if (entropy->restarts_to_go == 0)
  149569. emit_restart_p(entropy, entropy->next_restart_num);
  149570. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149571. block = MCU_data[blkn];
  149572. temp = (*block)[0];
  149573. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149574. }
  149575. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149576. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149577. if (cinfo->restart_interval) {
  149578. if (entropy->restarts_to_go == 0) {
  149579. entropy->restarts_to_go = cinfo->restart_interval;
  149580. entropy->next_restart_num++;
  149581. entropy->next_restart_num &= 7;
  149582. }
  149583. entropy->restarts_to_go--;
  149584. }
  149585. return TRUE;
  149586. }
  149587. METHODDEF(boolean)
  149588. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149589. {
  149590. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149591. register int temp;
  149592. register int r, k;
  149593. int EOB;
  149594. char *BR_buffer;
  149595. unsigned int BR;
  149596. int Se = cinfo->Se;
  149597. int Al = cinfo->Al;
  149598. JBLOCKROW block;
  149599. int absvalues[DCTSIZE2];
  149600. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149601. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149602. if (cinfo->restart_interval)
  149603. if (entropy->restarts_to_go == 0)
  149604. emit_restart_p(entropy, entropy->next_restart_num);
  149605. block = MCU_data[0];
  149606. EOB = 0;
  149607. for (k = cinfo->Ss; k <= Se; k++) {
  149608. temp = (*block)[jpeg_natural_order[k]];
  149609. if (temp < 0)
  149610. temp = -temp; /* temp is abs value of input */
  149611. temp >>= Al; /* apply the point transform */
  149612. absvalues[k] = temp; /* save abs value for main pass */
  149613. if (temp == 1)
  149614. EOB = k; /* EOB = index of last newly-nonzero coef */
  149615. }
  149616. r = 0; /* r = run length of zeros */
  149617. BR = 0; /* BR = count of buffered bits added now */
  149618. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149619. for (k = cinfo->Ss; k <= Se; k++) {
  149620. if ((temp = absvalues[k]) == 0) {
  149621. r++;
  149622. continue;
  149623. }
  149624. while (r > 15 && k <= EOB) {
  149625. emit_eobrun(entropy);
  149626. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149627. r -= 16;
  149628. emit_buffered_bits(entropy, BR_buffer, BR);
  149629. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149630. BR = 0;
  149631. }
  149632. if (temp > 1) {
  149633. BR_buffer[BR++] = (char) (temp & 1);
  149634. continue;
  149635. }
  149636. emit_eobrun(entropy);
  149637. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149638. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149639. emit_bits_p(entropy, (unsigned int) temp, 1);
  149640. emit_buffered_bits(entropy, BR_buffer, BR);
  149641. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149642. BR = 0;
  149643. r = 0; /* reset zero run length */
  149644. }
  149645. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149646. entropy->EOBRUN++; /* count an EOB */
  149647. entropy->BE += BR; /* concat my correction bits to older ones */
  149648. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149649. emit_eobrun(entropy);
  149650. }
  149651. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149652. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149653. if (cinfo->restart_interval) {
  149654. if (entropy->restarts_to_go == 0) {
  149655. entropy->restarts_to_go = cinfo->restart_interval;
  149656. entropy->next_restart_num++;
  149657. entropy->next_restart_num &= 7;
  149658. }
  149659. entropy->restarts_to_go--;
  149660. }
  149661. return TRUE;
  149662. }
  149663. METHODDEF(void)
  149664. finish_pass_phuff (j_compress_ptr cinfo)
  149665. {
  149666. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149667. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149668. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149669. emit_eobrun(entropy);
  149670. flush_bits_p(entropy);
  149671. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149672. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149673. }
  149674. METHODDEF(void)
  149675. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149676. {
  149677. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149678. boolean is_DC_band;
  149679. int ci, tbl;
  149680. jpeg_component_info * compptr;
  149681. JHUFF_TBL **htblptr;
  149682. boolean did[NUM_HUFF_TBLS];
  149683. emit_eobrun(entropy);
  149684. is_DC_band = (cinfo->Ss == 0);
  149685. MEMZERO(did, SIZEOF(did));
  149686. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149687. compptr = cinfo->cur_comp_info[ci];
  149688. if (is_DC_band) {
  149689. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149690. continue;
  149691. tbl = compptr->dc_tbl_no;
  149692. } else {
  149693. tbl = compptr->ac_tbl_no;
  149694. }
  149695. if (! did[tbl]) {
  149696. if (is_DC_band)
  149697. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149698. else
  149699. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149700. if (*htblptr == NULL)
  149701. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149702. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149703. did[tbl] = TRUE;
  149704. }
  149705. }
  149706. }
  149707. GLOBAL(void)
  149708. jinit_phuff_encoder (j_compress_ptr cinfo)
  149709. {
  149710. phuff_entropy_ptr entropy;
  149711. int i;
  149712. entropy = (phuff_entropy_ptr)
  149713. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149714. SIZEOF(phuff_entropy_encoder));
  149715. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149716. entropy->pub.start_pass = start_pass_phuff;
  149717. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149718. entropy->derived_tbls[i] = NULL;
  149719. entropy->count_ptrs[i] = NULL;
  149720. }
  149721. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149722. }
  149723. #endif /* C_PROGRESSIVE_SUPPORTED */
  149724. /*** End of inlined file: jcphuff.c ***/
  149725. /*** Start of inlined file: jcprepct.c ***/
  149726. #define JPEG_INTERNALS
  149727. #ifdef INPUT_SMOOTHING_SUPPORTED
  149728. #define CONTEXT_ROWS_SUPPORTED
  149729. #endif
  149730. typedef struct {
  149731. struct jpeg_c_prep_controller pub; /* public fields */
  149732. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149733. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149734. int next_buf_row; /* index of next row to store in color_buf */
  149735. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149736. int this_row_group; /* starting row index of group to process */
  149737. int next_buf_stop; /* downsample when we reach this index */
  149738. #endif
  149739. } my_prep_controller;
  149740. typedef my_prep_controller * my_prep_ptr;
  149741. METHODDEF(void)
  149742. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149743. {
  149744. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149745. if (pass_mode != JBUF_PASS_THRU)
  149746. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149747. prep->rows_to_go = cinfo->image_height;
  149748. prep->next_buf_row = 0;
  149749. #ifdef CONTEXT_ROWS_SUPPORTED
  149750. prep->this_row_group = 0;
  149751. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149752. #endif
  149753. }
  149754. LOCAL(void)
  149755. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149756. int input_rows, int output_rows)
  149757. {
  149758. register int row;
  149759. for (row = input_rows; row < output_rows; row++) {
  149760. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149761. 1, num_cols);
  149762. }
  149763. }
  149764. METHODDEF(void)
  149765. pre_process_data (j_compress_ptr cinfo,
  149766. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149767. JDIMENSION in_rows_avail,
  149768. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149769. JDIMENSION out_row_groups_avail)
  149770. {
  149771. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149772. int numrows, ci;
  149773. JDIMENSION inrows;
  149774. jpeg_component_info * compptr;
  149775. while (*in_row_ctr < in_rows_avail &&
  149776. *out_row_group_ctr < out_row_groups_avail) {
  149777. inrows = in_rows_avail - *in_row_ctr;
  149778. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149779. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149780. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149781. prep->color_buf,
  149782. (JDIMENSION) prep->next_buf_row,
  149783. numrows);
  149784. *in_row_ctr += numrows;
  149785. prep->next_buf_row += numrows;
  149786. prep->rows_to_go -= numrows;
  149787. if (prep->rows_to_go == 0 &&
  149788. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149789. for (ci = 0; ci < cinfo->num_components; ci++) {
  149790. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149791. prep->next_buf_row, cinfo->max_v_samp_factor);
  149792. }
  149793. prep->next_buf_row = cinfo->max_v_samp_factor;
  149794. }
  149795. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149796. (*cinfo->downsample->downsample) (cinfo,
  149797. prep->color_buf, (JDIMENSION) 0,
  149798. output_buf, *out_row_group_ctr);
  149799. prep->next_buf_row = 0;
  149800. (*out_row_group_ctr)++;
  149801. }
  149802. if (prep->rows_to_go == 0 &&
  149803. *out_row_group_ctr < out_row_groups_avail) {
  149804. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149805. ci++, compptr++) {
  149806. expand_bottom_edge(output_buf[ci],
  149807. compptr->width_in_blocks * DCTSIZE,
  149808. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149809. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149810. }
  149811. *out_row_group_ctr = out_row_groups_avail;
  149812. break; /* can exit outer loop without test */
  149813. }
  149814. }
  149815. }
  149816. #ifdef CONTEXT_ROWS_SUPPORTED
  149817. METHODDEF(void)
  149818. pre_process_context (j_compress_ptr cinfo,
  149819. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149820. JDIMENSION in_rows_avail,
  149821. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149822. JDIMENSION out_row_groups_avail)
  149823. {
  149824. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149825. int numrows, ci;
  149826. int buf_height = cinfo->max_v_samp_factor * 3;
  149827. JDIMENSION inrows;
  149828. while (*out_row_group_ctr < out_row_groups_avail) {
  149829. if (*in_row_ctr < in_rows_avail) {
  149830. inrows = in_rows_avail - *in_row_ctr;
  149831. numrows = prep->next_buf_stop - prep->next_buf_row;
  149832. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149833. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149834. prep->color_buf,
  149835. (JDIMENSION) prep->next_buf_row,
  149836. numrows);
  149837. if (prep->rows_to_go == cinfo->image_height) {
  149838. for (ci = 0; ci < cinfo->num_components; ci++) {
  149839. int row;
  149840. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149841. jcopy_sample_rows(prep->color_buf[ci], 0,
  149842. prep->color_buf[ci], -row,
  149843. 1, cinfo->image_width);
  149844. }
  149845. }
  149846. }
  149847. *in_row_ctr += numrows;
  149848. prep->next_buf_row += numrows;
  149849. prep->rows_to_go -= numrows;
  149850. } else {
  149851. if (prep->rows_to_go != 0)
  149852. break;
  149853. if (prep->next_buf_row < prep->next_buf_stop) {
  149854. for (ci = 0; ci < cinfo->num_components; ci++) {
  149855. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149856. prep->next_buf_row, prep->next_buf_stop);
  149857. }
  149858. prep->next_buf_row = prep->next_buf_stop;
  149859. }
  149860. }
  149861. if (prep->next_buf_row == prep->next_buf_stop) {
  149862. (*cinfo->downsample->downsample) (cinfo,
  149863. prep->color_buf,
  149864. (JDIMENSION) prep->this_row_group,
  149865. output_buf, *out_row_group_ctr);
  149866. (*out_row_group_ctr)++;
  149867. prep->this_row_group += cinfo->max_v_samp_factor;
  149868. if (prep->this_row_group >= buf_height)
  149869. prep->this_row_group = 0;
  149870. if (prep->next_buf_row >= buf_height)
  149871. prep->next_buf_row = 0;
  149872. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149873. }
  149874. }
  149875. }
  149876. LOCAL(void)
  149877. create_context_buffer (j_compress_ptr cinfo)
  149878. {
  149879. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149880. int rgroup_height = cinfo->max_v_samp_factor;
  149881. int ci, i;
  149882. jpeg_component_info * compptr;
  149883. JSAMPARRAY true_buffer, fake_buffer;
  149884. fake_buffer = (JSAMPARRAY)
  149885. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149886. (cinfo->num_components * 5 * rgroup_height) *
  149887. SIZEOF(JSAMPROW));
  149888. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149889. ci++, compptr++) {
  149890. true_buffer = (*cinfo->mem->alloc_sarray)
  149891. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149892. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149893. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149894. (JDIMENSION) (3 * rgroup_height));
  149895. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149896. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149897. for (i = 0; i < rgroup_height; i++) {
  149898. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149899. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149900. }
  149901. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149902. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149903. }
  149904. }
  149905. #endif /* CONTEXT_ROWS_SUPPORTED */
  149906. GLOBAL(void)
  149907. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149908. {
  149909. my_prep_ptr prep;
  149910. int ci;
  149911. jpeg_component_info * compptr;
  149912. if (need_full_buffer) /* safety check */
  149913. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149914. prep = (my_prep_ptr)
  149915. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149916. SIZEOF(my_prep_controller));
  149917. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149918. prep->pub.start_pass = start_pass_prep;
  149919. if (cinfo->downsample->need_context_rows) {
  149920. #ifdef CONTEXT_ROWS_SUPPORTED
  149921. prep->pub.pre_process_data = pre_process_context;
  149922. create_context_buffer(cinfo);
  149923. #else
  149924. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149925. #endif
  149926. } else {
  149927. prep->pub.pre_process_data = pre_process_data;
  149928. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149929. ci++, compptr++) {
  149930. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149931. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149932. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149933. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149934. (JDIMENSION) cinfo->max_v_samp_factor);
  149935. }
  149936. }
  149937. }
  149938. /*** End of inlined file: jcprepct.c ***/
  149939. /*** Start of inlined file: jcsample.c ***/
  149940. #define JPEG_INTERNALS
  149941. typedef JMETHOD(void, downsample1_ptr,
  149942. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149943. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149944. typedef struct {
  149945. struct jpeg_downsampler pub; /* public fields */
  149946. downsample1_ptr methods[MAX_COMPONENTS];
  149947. } my_downsampler;
  149948. typedef my_downsampler * my_downsample_ptr;
  149949. METHODDEF(void)
  149950. start_pass_downsample (j_compress_ptr cinfo)
  149951. {
  149952. }
  149953. LOCAL(void)
  149954. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149955. JDIMENSION input_cols, JDIMENSION output_cols)
  149956. {
  149957. register JSAMPROW ptr;
  149958. register JSAMPLE pixval;
  149959. register int count;
  149960. int row;
  149961. int numcols = (int) (output_cols - input_cols);
  149962. if (numcols > 0) {
  149963. for (row = 0; row < num_rows; row++) {
  149964. ptr = image_data[row] + input_cols;
  149965. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149966. for (count = numcols; count > 0; count--)
  149967. *ptr++ = pixval;
  149968. }
  149969. }
  149970. }
  149971. METHODDEF(void)
  149972. sep_downsample (j_compress_ptr cinfo,
  149973. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149974. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149975. {
  149976. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149977. int ci;
  149978. jpeg_component_info * compptr;
  149979. JSAMPARRAY in_ptr, out_ptr;
  149980. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149981. ci++, compptr++) {
  149982. in_ptr = input_buf[ci] + in_row_index;
  149983. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149984. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149985. }
  149986. }
  149987. METHODDEF(void)
  149988. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149989. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149990. {
  149991. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149992. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149993. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149994. JSAMPROW inptr, outptr;
  149995. INT32 outvalue;
  149996. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149997. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149998. numpix = h_expand * v_expand;
  149999. numpix2 = numpix/2;
  150000. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150001. cinfo->image_width, output_cols * h_expand);
  150002. inrow = 0;
  150003. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150004. outptr = output_data[outrow];
  150005. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  150006. outcol++, outcol_h += h_expand) {
  150007. outvalue = 0;
  150008. for (v = 0; v < v_expand; v++) {
  150009. inptr = input_data[inrow+v] + outcol_h;
  150010. for (h = 0; h < h_expand; h++) {
  150011. outvalue += (INT32) GETJSAMPLE(*inptr++);
  150012. }
  150013. }
  150014. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  150015. }
  150016. inrow += v_expand;
  150017. }
  150018. }
  150019. METHODDEF(void)
  150020. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150021. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150022. {
  150023. jcopy_sample_rows(input_data, 0, output_data, 0,
  150024. cinfo->max_v_samp_factor, cinfo->image_width);
  150025. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  150026. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  150027. }
  150028. METHODDEF(void)
  150029. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150030. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150031. {
  150032. int outrow;
  150033. JDIMENSION outcol;
  150034. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150035. register JSAMPROW inptr, outptr;
  150036. register int bias;
  150037. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150038. cinfo->image_width, output_cols * 2);
  150039. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150040. outptr = output_data[outrow];
  150041. inptr = input_data[outrow];
  150042. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  150043. for (outcol = 0; outcol < output_cols; outcol++) {
  150044. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  150045. + bias) >> 1);
  150046. bias ^= 1; /* 0=>1, 1=>0 */
  150047. inptr += 2;
  150048. }
  150049. }
  150050. }
  150051. METHODDEF(void)
  150052. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150053. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150054. {
  150055. int inrow, outrow;
  150056. JDIMENSION outcol;
  150057. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150058. register JSAMPROW inptr0, inptr1, outptr;
  150059. register int bias;
  150060. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150061. cinfo->image_width, output_cols * 2);
  150062. inrow = 0;
  150063. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150064. outptr = output_data[outrow];
  150065. inptr0 = input_data[inrow];
  150066. inptr1 = input_data[inrow+1];
  150067. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  150068. for (outcol = 0; outcol < output_cols; outcol++) {
  150069. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150070. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  150071. + bias) >> 2);
  150072. bias ^= 3; /* 1=>2, 2=>1 */
  150073. inptr0 += 2; inptr1 += 2;
  150074. }
  150075. inrow += 2;
  150076. }
  150077. }
  150078. #ifdef INPUT_SMOOTHING_SUPPORTED
  150079. METHODDEF(void)
  150080. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150081. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150082. {
  150083. int inrow, outrow;
  150084. JDIMENSION colctr;
  150085. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150086. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  150087. INT32 membersum, neighsum, memberscale, neighscale;
  150088. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150089. cinfo->image_width, output_cols * 2);
  150090. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  150091. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  150092. inrow = 0;
  150093. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150094. outptr = output_data[outrow];
  150095. inptr0 = input_data[inrow];
  150096. inptr1 = input_data[inrow+1];
  150097. above_ptr = input_data[inrow-1];
  150098. below_ptr = input_data[inrow+2];
  150099. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150100. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150101. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150102. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150103. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  150104. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  150105. neighsum += neighsum;
  150106. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  150107. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  150108. membersum = membersum * memberscale + neighsum * neighscale;
  150109. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150110. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150111. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150112. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150113. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150114. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150115. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150116. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  150117. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  150118. neighsum += neighsum;
  150119. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  150120. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  150121. membersum = membersum * memberscale + neighsum * neighscale;
  150122. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150123. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150124. }
  150125. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150126. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150127. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150128. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150129. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  150130. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  150131. neighsum += neighsum;
  150132. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  150133. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  150134. membersum = membersum * memberscale + neighsum * neighscale;
  150135. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150136. inrow += 2;
  150137. }
  150138. }
  150139. METHODDEF(void)
  150140. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  150141. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150142. {
  150143. int outrow;
  150144. JDIMENSION colctr;
  150145. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150146. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  150147. INT32 membersum, neighsum, memberscale, neighscale;
  150148. int colsum, lastcolsum, nextcolsum;
  150149. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150150. cinfo->image_width, output_cols);
  150151. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  150152. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  150153. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150154. outptr = output_data[outrow];
  150155. inptr = input_data[outrow];
  150156. above_ptr = input_data[outrow-1];
  150157. below_ptr = input_data[outrow+1];
  150158. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  150159. GETJSAMPLE(*inptr);
  150160. membersum = GETJSAMPLE(*inptr++);
  150161. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150162. GETJSAMPLE(*inptr);
  150163. neighsum = colsum + (colsum - membersum) + nextcolsum;
  150164. membersum = membersum * memberscale + neighsum * neighscale;
  150165. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150166. lastcolsum = colsum; colsum = nextcolsum;
  150167. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150168. membersum = GETJSAMPLE(*inptr++);
  150169. above_ptr++; below_ptr++;
  150170. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150171. GETJSAMPLE(*inptr);
  150172. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  150173. membersum = membersum * memberscale + neighsum * neighscale;
  150174. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150175. lastcolsum = colsum; colsum = nextcolsum;
  150176. }
  150177. membersum = GETJSAMPLE(*inptr);
  150178. neighsum = lastcolsum + (colsum - membersum) + colsum;
  150179. membersum = membersum * memberscale + neighsum * neighscale;
  150180. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150181. }
  150182. }
  150183. #endif /* INPUT_SMOOTHING_SUPPORTED */
  150184. GLOBAL(void)
  150185. jinit_downsampler (j_compress_ptr cinfo)
  150186. {
  150187. my_downsample_ptr downsample;
  150188. int ci;
  150189. jpeg_component_info * compptr;
  150190. boolean smoothok = TRUE;
  150191. downsample = (my_downsample_ptr)
  150192. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150193. SIZEOF(my_downsampler));
  150194. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  150195. downsample->pub.start_pass = start_pass_downsample;
  150196. downsample->pub.downsample = sep_downsample;
  150197. downsample->pub.need_context_rows = FALSE;
  150198. if (cinfo->CCIR601_sampling)
  150199. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  150200. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150201. ci++, compptr++) {
  150202. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  150203. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150204. #ifdef INPUT_SMOOTHING_SUPPORTED
  150205. if (cinfo->smoothing_factor) {
  150206. downsample->methods[ci] = fullsize_smooth_downsample;
  150207. downsample->pub.need_context_rows = TRUE;
  150208. } else
  150209. #endif
  150210. downsample->methods[ci] = fullsize_downsample;
  150211. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150212. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150213. smoothok = FALSE;
  150214. downsample->methods[ci] = h2v1_downsample;
  150215. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150216. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  150217. #ifdef INPUT_SMOOTHING_SUPPORTED
  150218. if (cinfo->smoothing_factor) {
  150219. downsample->methods[ci] = h2v2_smooth_downsample;
  150220. downsample->pub.need_context_rows = TRUE;
  150221. } else
  150222. #endif
  150223. downsample->methods[ci] = h2v2_downsample;
  150224. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  150225. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  150226. smoothok = FALSE;
  150227. downsample->methods[ci] = int_downsample;
  150228. } else
  150229. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  150230. }
  150231. #ifdef INPUT_SMOOTHING_SUPPORTED
  150232. if (cinfo->smoothing_factor && !smoothok)
  150233. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  150234. #endif
  150235. }
  150236. /*** End of inlined file: jcsample.c ***/
  150237. /*** Start of inlined file: jctrans.c ***/
  150238. #define JPEG_INTERNALS
  150239. LOCAL(void) transencode_master_selection
  150240. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150241. LOCAL(void) transencode_coef_controller
  150242. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150243. GLOBAL(void)
  150244. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  150245. {
  150246. if (cinfo->global_state != CSTATE_START)
  150247. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150248. jpeg_suppress_tables(cinfo, FALSE);
  150249. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  150250. (*cinfo->dest->init_destination) (cinfo);
  150251. transencode_master_selection(cinfo, coef_arrays);
  150252. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  150253. cinfo->global_state = CSTATE_WRCOEFS;
  150254. }
  150255. GLOBAL(void)
  150256. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  150257. j_compress_ptr dstinfo)
  150258. {
  150259. JQUANT_TBL ** qtblptr;
  150260. jpeg_component_info *incomp, *outcomp;
  150261. JQUANT_TBL *c_quant, *slot_quant;
  150262. int tblno, ci, coefi;
  150263. if (dstinfo->global_state != CSTATE_START)
  150264. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  150265. dstinfo->image_width = srcinfo->image_width;
  150266. dstinfo->image_height = srcinfo->image_height;
  150267. dstinfo->input_components = srcinfo->num_components;
  150268. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  150269. jpeg_set_defaults(dstinfo);
  150270. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  150271. dstinfo->data_precision = srcinfo->data_precision;
  150272. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  150273. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  150274. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  150275. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  150276. if (*qtblptr == NULL)
  150277. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  150278. MEMCOPY((*qtblptr)->quantval,
  150279. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  150280. SIZEOF((*qtblptr)->quantval));
  150281. (*qtblptr)->sent_table = FALSE;
  150282. }
  150283. }
  150284. dstinfo->num_components = srcinfo->num_components;
  150285. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150286. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150287. MAX_COMPONENTS);
  150288. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150289. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150290. outcomp->component_id = incomp->component_id;
  150291. outcomp->h_samp_factor = incomp->h_samp_factor;
  150292. outcomp->v_samp_factor = incomp->v_samp_factor;
  150293. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150294. tblno = outcomp->quant_tbl_no;
  150295. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150296. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150297. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150298. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150299. c_quant = incomp->quant_table;
  150300. if (c_quant != NULL) {
  150301. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150302. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150303. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150304. }
  150305. }
  150306. }
  150307. if (srcinfo->saw_JFIF_marker) {
  150308. if (srcinfo->JFIF_major_version == 1) {
  150309. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150310. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150311. }
  150312. dstinfo->density_unit = srcinfo->density_unit;
  150313. dstinfo->X_density = srcinfo->X_density;
  150314. dstinfo->Y_density = srcinfo->Y_density;
  150315. }
  150316. }
  150317. LOCAL(void)
  150318. transencode_master_selection (j_compress_ptr cinfo,
  150319. jvirt_barray_ptr * coef_arrays)
  150320. {
  150321. cinfo->input_components = 1;
  150322. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150323. if (cinfo->arith_code) {
  150324. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150325. } else {
  150326. if (cinfo->progressive_mode) {
  150327. #ifdef C_PROGRESSIVE_SUPPORTED
  150328. jinit_phuff_encoder(cinfo);
  150329. #else
  150330. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150331. #endif
  150332. } else
  150333. jinit_huff_encoder(cinfo);
  150334. }
  150335. transencode_coef_controller(cinfo, coef_arrays);
  150336. jinit_marker_writer(cinfo);
  150337. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150338. (*cinfo->marker->write_file_header) (cinfo);
  150339. }
  150340. typedef struct {
  150341. struct jpeg_c_coef_controller pub; /* public fields */
  150342. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150343. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150344. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150345. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150346. jvirt_barray_ptr * whole_image;
  150347. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150348. } my_coef_controller2;
  150349. typedef my_coef_controller2 * my_coef_ptr2;
  150350. LOCAL(void)
  150351. start_iMCU_row2 (j_compress_ptr cinfo)
  150352. {
  150353. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150354. if (cinfo->comps_in_scan > 1) {
  150355. coef->MCU_rows_per_iMCU_row = 1;
  150356. } else {
  150357. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150358. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150359. else
  150360. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150361. }
  150362. coef->mcu_ctr = 0;
  150363. coef->MCU_vert_offset = 0;
  150364. }
  150365. METHODDEF(void)
  150366. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150367. {
  150368. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150369. if (pass_mode != JBUF_CRANK_DEST)
  150370. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150371. coef->iMCU_row_num = 0;
  150372. start_iMCU_row2(cinfo);
  150373. }
  150374. METHODDEF(boolean)
  150375. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150376. {
  150377. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150378. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150379. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150380. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150381. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150382. JDIMENSION start_col;
  150383. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150384. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150385. JBLOCKROW buffer_ptr;
  150386. jpeg_component_info *compptr;
  150387. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150388. compptr = cinfo->cur_comp_info[ci];
  150389. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150390. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150391. coef->iMCU_row_num * compptr->v_samp_factor,
  150392. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150393. }
  150394. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150395. yoffset++) {
  150396. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150397. MCU_col_num++) {
  150398. blkn = 0; /* index of current DCT block within MCU */
  150399. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150400. compptr = cinfo->cur_comp_info[ci];
  150401. start_col = MCU_col_num * compptr->MCU_width;
  150402. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150403. : compptr->last_col_width;
  150404. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150405. if (coef->iMCU_row_num < last_iMCU_row ||
  150406. yindex+yoffset < compptr->last_row_height) {
  150407. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150408. for (xindex = 0; xindex < blockcnt; xindex++)
  150409. MCU_buffer[blkn++] = buffer_ptr++;
  150410. } else {
  150411. xindex = 0;
  150412. }
  150413. for (; xindex < compptr->MCU_width; xindex++) {
  150414. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150415. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150416. blkn++;
  150417. }
  150418. }
  150419. }
  150420. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150421. coef->MCU_vert_offset = yoffset;
  150422. coef->mcu_ctr = MCU_col_num;
  150423. return FALSE;
  150424. }
  150425. }
  150426. coef->mcu_ctr = 0;
  150427. }
  150428. coef->iMCU_row_num++;
  150429. start_iMCU_row2(cinfo);
  150430. return TRUE;
  150431. }
  150432. LOCAL(void)
  150433. transencode_coef_controller (j_compress_ptr cinfo,
  150434. jvirt_barray_ptr * coef_arrays)
  150435. {
  150436. my_coef_ptr2 coef;
  150437. JBLOCKROW buffer;
  150438. int i;
  150439. coef = (my_coef_ptr2)
  150440. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150441. SIZEOF(my_coef_controller2));
  150442. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150443. coef->pub.start_pass = start_pass_coef2;
  150444. coef->pub.compress_data = compress_output2;
  150445. coef->whole_image = coef_arrays;
  150446. buffer = (JBLOCKROW)
  150447. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150448. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150449. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150450. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150451. coef->dummy_buffer[i] = buffer + i;
  150452. }
  150453. }
  150454. /*** End of inlined file: jctrans.c ***/
  150455. /*** Start of inlined file: jdapistd.c ***/
  150456. #define JPEG_INTERNALS
  150457. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150458. GLOBAL(boolean)
  150459. jpeg_start_decompress (j_decompress_ptr cinfo)
  150460. {
  150461. if (cinfo->global_state == DSTATE_READY) {
  150462. jinit_master_decompress(cinfo);
  150463. if (cinfo->buffered_image) {
  150464. cinfo->global_state = DSTATE_BUFIMAGE;
  150465. return TRUE;
  150466. }
  150467. cinfo->global_state = DSTATE_PRELOAD;
  150468. }
  150469. if (cinfo->global_state == DSTATE_PRELOAD) {
  150470. if (cinfo->inputctl->has_multiple_scans) {
  150471. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150472. for (;;) {
  150473. int retcode;
  150474. if (cinfo->progress != NULL)
  150475. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150476. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150477. if (retcode == JPEG_SUSPENDED)
  150478. return FALSE;
  150479. if (retcode == JPEG_REACHED_EOI)
  150480. break;
  150481. if (cinfo->progress != NULL &&
  150482. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150483. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150484. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150485. }
  150486. }
  150487. }
  150488. #else
  150489. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150490. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150491. }
  150492. cinfo->output_scan_number = cinfo->input_scan_number;
  150493. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150494. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150495. return output_pass_setup(cinfo);
  150496. }
  150497. LOCAL(boolean)
  150498. output_pass_setup (j_decompress_ptr cinfo)
  150499. {
  150500. if (cinfo->global_state != DSTATE_PRESCAN) {
  150501. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150502. cinfo->output_scanline = 0;
  150503. cinfo->global_state = DSTATE_PRESCAN;
  150504. }
  150505. while (cinfo->master->is_dummy_pass) {
  150506. #ifdef QUANT_2PASS_SUPPORTED
  150507. while (cinfo->output_scanline < cinfo->output_height) {
  150508. JDIMENSION last_scanline;
  150509. if (cinfo->progress != NULL) {
  150510. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150511. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150512. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150513. }
  150514. last_scanline = cinfo->output_scanline;
  150515. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150516. &cinfo->output_scanline, (JDIMENSION) 0);
  150517. if (cinfo->output_scanline == last_scanline)
  150518. return FALSE; /* No progress made, must suspend */
  150519. }
  150520. (*cinfo->master->finish_output_pass) (cinfo);
  150521. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150522. cinfo->output_scanline = 0;
  150523. #else
  150524. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150525. #endif /* QUANT_2PASS_SUPPORTED */
  150526. }
  150527. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150528. return TRUE;
  150529. }
  150530. GLOBAL(JDIMENSION)
  150531. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150532. JDIMENSION max_lines)
  150533. {
  150534. JDIMENSION row_ctr;
  150535. if (cinfo->global_state != DSTATE_SCANNING)
  150536. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150537. if (cinfo->output_scanline >= cinfo->output_height) {
  150538. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150539. return 0;
  150540. }
  150541. if (cinfo->progress != NULL) {
  150542. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150543. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150544. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150545. }
  150546. row_ctr = 0;
  150547. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150548. cinfo->output_scanline += row_ctr;
  150549. return row_ctr;
  150550. }
  150551. GLOBAL(JDIMENSION)
  150552. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150553. JDIMENSION max_lines)
  150554. {
  150555. JDIMENSION lines_per_iMCU_row;
  150556. if (cinfo->global_state != DSTATE_RAW_OK)
  150557. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150558. if (cinfo->output_scanline >= cinfo->output_height) {
  150559. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150560. return 0;
  150561. }
  150562. if (cinfo->progress != NULL) {
  150563. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150564. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150565. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150566. }
  150567. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150568. if (max_lines < lines_per_iMCU_row)
  150569. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150570. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150571. return 0; /* suspension forced, can do nothing more */
  150572. cinfo->output_scanline += lines_per_iMCU_row;
  150573. return lines_per_iMCU_row;
  150574. }
  150575. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150576. GLOBAL(boolean)
  150577. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150578. {
  150579. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150580. cinfo->global_state != DSTATE_PRESCAN)
  150581. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150582. if (scan_number <= 0)
  150583. scan_number = 1;
  150584. if (cinfo->inputctl->eoi_reached &&
  150585. scan_number > cinfo->input_scan_number)
  150586. scan_number = cinfo->input_scan_number;
  150587. cinfo->output_scan_number = scan_number;
  150588. return output_pass_setup(cinfo);
  150589. }
  150590. GLOBAL(boolean)
  150591. jpeg_finish_output (j_decompress_ptr cinfo)
  150592. {
  150593. if ((cinfo->global_state == DSTATE_SCANNING ||
  150594. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150595. (*cinfo->master->finish_output_pass) (cinfo);
  150596. cinfo->global_state = DSTATE_BUFPOST;
  150597. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150598. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150599. }
  150600. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150601. ! cinfo->inputctl->eoi_reached) {
  150602. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150603. return FALSE; /* Suspend, come back later */
  150604. }
  150605. cinfo->global_state = DSTATE_BUFIMAGE;
  150606. return TRUE;
  150607. }
  150608. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150609. /*** End of inlined file: jdapistd.c ***/
  150610. /*** Start of inlined file: jdapimin.c ***/
  150611. #define JPEG_INTERNALS
  150612. GLOBAL(void)
  150613. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150614. {
  150615. int i;
  150616. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150617. if (version != JPEG_LIB_VERSION)
  150618. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150619. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150620. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150621. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150622. {
  150623. struct jpeg_error_mgr * err = cinfo->err;
  150624. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150625. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150626. cinfo->err = err;
  150627. cinfo->client_data = client_data;
  150628. }
  150629. cinfo->is_decompressor = TRUE;
  150630. jinit_memory_mgr((j_common_ptr) cinfo);
  150631. cinfo->progress = NULL;
  150632. cinfo->src = NULL;
  150633. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150634. cinfo->quant_tbl_ptrs[i] = NULL;
  150635. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150636. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150637. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150638. }
  150639. cinfo->marker_list = NULL;
  150640. jinit_marker_reader(cinfo);
  150641. jinit_input_controller(cinfo);
  150642. cinfo->global_state = DSTATE_START;
  150643. }
  150644. GLOBAL(void)
  150645. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150646. {
  150647. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150648. }
  150649. GLOBAL(void)
  150650. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150651. {
  150652. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150653. }
  150654. LOCAL(void)
  150655. default_decompress_parms (j_decompress_ptr cinfo)
  150656. {
  150657. switch (cinfo->num_components) {
  150658. case 1:
  150659. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150660. cinfo->out_color_space = JCS_GRAYSCALE;
  150661. break;
  150662. case 3:
  150663. if (cinfo->saw_JFIF_marker) {
  150664. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150665. } else if (cinfo->saw_Adobe_marker) {
  150666. switch (cinfo->Adobe_transform) {
  150667. case 0:
  150668. cinfo->jpeg_color_space = JCS_RGB;
  150669. break;
  150670. case 1:
  150671. cinfo->jpeg_color_space = JCS_YCbCr;
  150672. break;
  150673. default:
  150674. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150675. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150676. break;
  150677. }
  150678. } else {
  150679. int cid0 = cinfo->comp_info[0].component_id;
  150680. int cid1 = cinfo->comp_info[1].component_id;
  150681. int cid2 = cinfo->comp_info[2].component_id;
  150682. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150683. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150684. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150685. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150686. else {
  150687. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150688. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150689. }
  150690. }
  150691. cinfo->out_color_space = JCS_RGB;
  150692. break;
  150693. case 4:
  150694. if (cinfo->saw_Adobe_marker) {
  150695. switch (cinfo->Adobe_transform) {
  150696. case 0:
  150697. cinfo->jpeg_color_space = JCS_CMYK;
  150698. break;
  150699. case 2:
  150700. cinfo->jpeg_color_space = JCS_YCCK;
  150701. break;
  150702. default:
  150703. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150704. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150705. break;
  150706. }
  150707. } else {
  150708. cinfo->jpeg_color_space = JCS_CMYK;
  150709. }
  150710. cinfo->out_color_space = JCS_CMYK;
  150711. break;
  150712. default:
  150713. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150714. cinfo->out_color_space = JCS_UNKNOWN;
  150715. break;
  150716. }
  150717. cinfo->scale_num = 1; /* 1:1 scaling */
  150718. cinfo->scale_denom = 1;
  150719. cinfo->output_gamma = 1.0;
  150720. cinfo->buffered_image = FALSE;
  150721. cinfo->raw_data_out = FALSE;
  150722. cinfo->dct_method = JDCT_DEFAULT;
  150723. cinfo->do_fancy_upsampling = TRUE;
  150724. cinfo->do_block_smoothing = TRUE;
  150725. cinfo->quantize_colors = FALSE;
  150726. cinfo->dither_mode = JDITHER_FS;
  150727. #ifdef QUANT_2PASS_SUPPORTED
  150728. cinfo->two_pass_quantize = TRUE;
  150729. #else
  150730. cinfo->two_pass_quantize = FALSE;
  150731. #endif
  150732. cinfo->desired_number_of_colors = 256;
  150733. cinfo->colormap = NULL;
  150734. cinfo->enable_1pass_quant = FALSE;
  150735. cinfo->enable_external_quant = FALSE;
  150736. cinfo->enable_2pass_quant = FALSE;
  150737. }
  150738. GLOBAL(int)
  150739. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150740. {
  150741. int retcode;
  150742. if (cinfo->global_state != DSTATE_START &&
  150743. cinfo->global_state != DSTATE_INHEADER)
  150744. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150745. retcode = jpeg_consume_input(cinfo);
  150746. switch (retcode) {
  150747. case JPEG_REACHED_SOS:
  150748. retcode = JPEG_HEADER_OK;
  150749. break;
  150750. case JPEG_REACHED_EOI:
  150751. if (require_image) /* Complain if application wanted an image */
  150752. ERREXIT(cinfo, JERR_NO_IMAGE);
  150753. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150754. retcode = JPEG_HEADER_TABLES_ONLY;
  150755. break;
  150756. case JPEG_SUSPENDED:
  150757. break;
  150758. }
  150759. return retcode;
  150760. }
  150761. GLOBAL(int)
  150762. jpeg_consume_input (j_decompress_ptr cinfo)
  150763. {
  150764. int retcode = JPEG_SUSPENDED;
  150765. switch (cinfo->global_state) {
  150766. case DSTATE_START:
  150767. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150768. (*cinfo->src->init_source) (cinfo);
  150769. cinfo->global_state = DSTATE_INHEADER;
  150770. case DSTATE_INHEADER:
  150771. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150772. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150773. default_decompress_parms(cinfo);
  150774. cinfo->global_state = DSTATE_READY;
  150775. }
  150776. break;
  150777. case DSTATE_READY:
  150778. retcode = JPEG_REACHED_SOS;
  150779. break;
  150780. case DSTATE_PRELOAD:
  150781. case DSTATE_PRESCAN:
  150782. case DSTATE_SCANNING:
  150783. case DSTATE_RAW_OK:
  150784. case DSTATE_BUFIMAGE:
  150785. case DSTATE_BUFPOST:
  150786. case DSTATE_STOPPING:
  150787. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150788. break;
  150789. default:
  150790. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150791. }
  150792. return retcode;
  150793. }
  150794. GLOBAL(boolean)
  150795. jpeg_input_complete (j_decompress_ptr cinfo)
  150796. {
  150797. if (cinfo->global_state < DSTATE_START ||
  150798. cinfo->global_state > DSTATE_STOPPING)
  150799. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150800. return cinfo->inputctl->eoi_reached;
  150801. }
  150802. GLOBAL(boolean)
  150803. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150804. {
  150805. if (cinfo->global_state < DSTATE_READY ||
  150806. cinfo->global_state > DSTATE_STOPPING)
  150807. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150808. return cinfo->inputctl->has_multiple_scans;
  150809. }
  150810. GLOBAL(boolean)
  150811. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150812. {
  150813. if ((cinfo->global_state == DSTATE_SCANNING ||
  150814. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150815. if (cinfo->output_scanline < cinfo->output_height)
  150816. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150817. (*cinfo->master->finish_output_pass) (cinfo);
  150818. cinfo->global_state = DSTATE_STOPPING;
  150819. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150820. cinfo->global_state = DSTATE_STOPPING;
  150821. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150822. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150823. }
  150824. while (! cinfo->inputctl->eoi_reached) {
  150825. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150826. return FALSE; /* Suspend, come back later */
  150827. }
  150828. (*cinfo->src->term_source) (cinfo);
  150829. jpeg_abort((j_common_ptr) cinfo);
  150830. return TRUE;
  150831. }
  150832. /*** End of inlined file: jdapimin.c ***/
  150833. /*** Start of inlined file: jdatasrc.c ***/
  150834. /*** Start of inlined file: jerror.h ***/
  150835. #ifndef JMESSAGE
  150836. #ifndef JERROR_H
  150837. #define JMAKE_ENUM_LIST
  150838. #else
  150839. #define JMESSAGE(code,string)
  150840. #endif /* JERROR_H */
  150841. #endif /* JMESSAGE */
  150842. #ifdef JMAKE_ENUM_LIST
  150843. typedef enum {
  150844. #define JMESSAGE(code,string) code ,
  150845. #endif /* JMAKE_ENUM_LIST */
  150846. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150847. JMESSAGE(JERR_ARITH_NOTIMPL,
  150848. "Sorry, there are legal restrictions on arithmetic coding")
  150849. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150850. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150851. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150852. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150853. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150854. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150855. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150856. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150857. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150858. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150859. JMESSAGE(JERR_BAD_LIB_VERSION,
  150860. "Wrong JPEG library version: library is %d, caller expects %d")
  150861. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150862. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150863. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150864. JMESSAGE(JERR_BAD_PROGRESSION,
  150865. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150866. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150867. "Invalid progressive parameters at scan script entry %d")
  150868. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150869. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150870. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150871. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150872. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150873. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150874. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150875. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150876. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150877. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150878. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150879. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150880. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150881. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150882. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150883. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150884. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150885. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150886. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150887. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150888. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150889. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150890. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150891. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150892. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150893. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150894. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150895. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150896. "Cannot transcode due to multiple use of quantization table %d")
  150897. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150898. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150899. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150900. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150901. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150902. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150903. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150904. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150905. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150906. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150907. JMESSAGE(JERR_QUANT_COMPONENTS,
  150908. "Cannot quantize more than %d color components")
  150909. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150910. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150911. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150912. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150913. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150914. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150915. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150916. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150917. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150918. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150919. JMESSAGE(JERR_TFILE_WRITE,
  150920. "Write failed on temporary file --- out of disk space?")
  150921. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150922. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150923. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150924. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150925. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150926. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150927. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150928. JMESSAGE(JMSG_VERSION, JVERSION)
  150929. JMESSAGE(JTRC_16BIT_TABLES,
  150930. "Caution: quantization tables are too coarse for baseline JPEG")
  150931. JMESSAGE(JTRC_ADOBE,
  150932. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150933. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150934. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150935. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150936. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150937. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150938. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150939. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150940. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150941. JMESSAGE(JTRC_EOI, "End Of Image")
  150942. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150943. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150944. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150945. "Warning: thumbnail image size does not match data length %u")
  150946. JMESSAGE(JTRC_JFIF_EXTENSION,
  150947. "JFIF extension marker: type 0x%02x, length %u")
  150948. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150949. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150950. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150951. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150952. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150953. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150954. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150955. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150956. JMESSAGE(JTRC_RST, "RST%d")
  150957. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150958. "Smoothing not supported with nonstandard sampling ratios")
  150959. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150960. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150961. JMESSAGE(JTRC_SOI, "Start of Image")
  150962. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150963. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150964. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150965. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150966. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150967. JMESSAGE(JTRC_THUMB_JPEG,
  150968. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150969. JMESSAGE(JTRC_THUMB_PALETTE,
  150970. "JFIF extension marker: palette thumbnail image, length %u")
  150971. JMESSAGE(JTRC_THUMB_RGB,
  150972. "JFIF extension marker: RGB thumbnail image, length %u")
  150973. JMESSAGE(JTRC_UNKNOWN_IDS,
  150974. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150975. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150976. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150977. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150978. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150979. "Inconsistent progression sequence for component %d coefficient %d")
  150980. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150981. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150982. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150983. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150984. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150985. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150986. JMESSAGE(JWRN_MUST_RESYNC,
  150987. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150988. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150989. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150990. #ifdef JMAKE_ENUM_LIST
  150991. JMSG_LASTMSGCODE
  150992. } J_MESSAGE_CODE;
  150993. #undef JMAKE_ENUM_LIST
  150994. #endif /* JMAKE_ENUM_LIST */
  150995. #undef JMESSAGE
  150996. #ifndef JERROR_H
  150997. #define JERROR_H
  150998. #define ERREXIT(cinfo,code) \
  150999. ((cinfo)->err->msg_code = (code), \
  151000. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151001. #define ERREXIT1(cinfo,code,p1) \
  151002. ((cinfo)->err->msg_code = (code), \
  151003. (cinfo)->err->msg_parm.i[0] = (p1), \
  151004. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151005. #define ERREXIT2(cinfo,code,p1,p2) \
  151006. ((cinfo)->err->msg_code = (code), \
  151007. (cinfo)->err->msg_parm.i[0] = (p1), \
  151008. (cinfo)->err->msg_parm.i[1] = (p2), \
  151009. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151010. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  151011. ((cinfo)->err->msg_code = (code), \
  151012. (cinfo)->err->msg_parm.i[0] = (p1), \
  151013. (cinfo)->err->msg_parm.i[1] = (p2), \
  151014. (cinfo)->err->msg_parm.i[2] = (p3), \
  151015. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151016. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  151017. ((cinfo)->err->msg_code = (code), \
  151018. (cinfo)->err->msg_parm.i[0] = (p1), \
  151019. (cinfo)->err->msg_parm.i[1] = (p2), \
  151020. (cinfo)->err->msg_parm.i[2] = (p3), \
  151021. (cinfo)->err->msg_parm.i[3] = (p4), \
  151022. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151023. #define ERREXITS(cinfo,code,str) \
  151024. ((cinfo)->err->msg_code = (code), \
  151025. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151026. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151027. #define MAKESTMT(stuff) do { stuff } while (0)
  151028. #define WARNMS(cinfo,code) \
  151029. ((cinfo)->err->msg_code = (code), \
  151030. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151031. #define WARNMS1(cinfo,code,p1) \
  151032. ((cinfo)->err->msg_code = (code), \
  151033. (cinfo)->err->msg_parm.i[0] = (p1), \
  151034. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151035. #define WARNMS2(cinfo,code,p1,p2) \
  151036. ((cinfo)->err->msg_code = (code), \
  151037. (cinfo)->err->msg_parm.i[0] = (p1), \
  151038. (cinfo)->err->msg_parm.i[1] = (p2), \
  151039. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151040. #define TRACEMS(cinfo,lvl,code) \
  151041. ((cinfo)->err->msg_code = (code), \
  151042. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151043. #define TRACEMS1(cinfo,lvl,code,p1) \
  151044. ((cinfo)->err->msg_code = (code), \
  151045. (cinfo)->err->msg_parm.i[0] = (p1), \
  151046. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151047. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  151048. ((cinfo)->err->msg_code = (code), \
  151049. (cinfo)->err->msg_parm.i[0] = (p1), \
  151050. (cinfo)->err->msg_parm.i[1] = (p2), \
  151051. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151052. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  151053. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151054. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  151055. (cinfo)->err->msg_code = (code); \
  151056. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151057. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  151058. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151059. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151060. (cinfo)->err->msg_code = (code); \
  151061. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151062. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  151063. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151064. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151065. _mp[4] = (p5); \
  151066. (cinfo)->err->msg_code = (code); \
  151067. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151068. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  151069. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151070. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151071. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  151072. (cinfo)->err->msg_code = (code); \
  151073. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151074. #define TRACEMSS(cinfo,lvl,code,str) \
  151075. ((cinfo)->err->msg_code = (code), \
  151076. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151077. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151078. #endif /* JERROR_H */
  151079. /*** End of inlined file: jerror.h ***/
  151080. typedef struct {
  151081. struct jpeg_source_mgr pub; /* public fields */
  151082. FILE * infile; /* source stream */
  151083. JOCTET * buffer; /* start of buffer */
  151084. boolean start_of_file; /* have we gotten any data yet? */
  151085. } my_source_mgr;
  151086. typedef my_source_mgr * my_src_ptr;
  151087. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  151088. METHODDEF(void)
  151089. init_source (j_decompress_ptr cinfo)
  151090. {
  151091. my_src_ptr src = (my_src_ptr) cinfo->src;
  151092. src->start_of_file = TRUE;
  151093. }
  151094. METHODDEF(boolean)
  151095. fill_input_buffer (j_decompress_ptr cinfo)
  151096. {
  151097. my_src_ptr src = (my_src_ptr) cinfo->src;
  151098. size_t nbytes;
  151099. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  151100. if (nbytes <= 0) {
  151101. if (src->start_of_file) /* Treat empty input file as fatal error */
  151102. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  151103. WARNMS(cinfo, JWRN_JPEG_EOF);
  151104. src->buffer[0] = (JOCTET) 0xFF;
  151105. src->buffer[1] = (JOCTET) JPEG_EOI;
  151106. nbytes = 2;
  151107. }
  151108. src->pub.next_input_byte = src->buffer;
  151109. src->pub.bytes_in_buffer = nbytes;
  151110. src->start_of_file = FALSE;
  151111. return TRUE;
  151112. }
  151113. METHODDEF(void)
  151114. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  151115. {
  151116. my_src_ptr src = (my_src_ptr) cinfo->src;
  151117. if (num_bytes > 0) {
  151118. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  151119. num_bytes -= (long) src->pub.bytes_in_buffer;
  151120. (void) fill_input_buffer(cinfo);
  151121. }
  151122. src->pub.next_input_byte += (size_t) num_bytes;
  151123. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  151124. }
  151125. }
  151126. METHODDEF(void)
  151127. term_source (j_decompress_ptr cinfo)
  151128. {
  151129. }
  151130. GLOBAL(void)
  151131. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  151132. {
  151133. my_src_ptr src;
  151134. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  151135. cinfo->src = (struct jpeg_source_mgr *)
  151136. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151137. SIZEOF(my_source_mgr));
  151138. src = (my_src_ptr) cinfo->src;
  151139. src->buffer = (JOCTET *)
  151140. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151141. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  151142. }
  151143. src = (my_src_ptr) cinfo->src;
  151144. src->pub.init_source = init_source;
  151145. src->pub.fill_input_buffer = fill_input_buffer;
  151146. src->pub.skip_input_data = skip_input_data;
  151147. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  151148. src->pub.term_source = term_source;
  151149. src->infile = infile;
  151150. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  151151. src->pub.next_input_byte = NULL; /* until buffer loaded */
  151152. }
  151153. /*** End of inlined file: jdatasrc.c ***/
  151154. /*** Start of inlined file: jdcoefct.c ***/
  151155. #define JPEG_INTERNALS
  151156. #ifndef D_PROGRESSIVE_SUPPORTED
  151157. #undef BLOCK_SMOOTHING_SUPPORTED
  151158. #endif
  151159. typedef struct {
  151160. struct jpeg_d_coef_controller pub; /* public fields */
  151161. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  151162. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  151163. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  151164. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  151165. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151166. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  151167. #endif
  151168. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151169. int * coef_bits_latch;
  151170. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  151171. #endif
  151172. } my_coef_controller3;
  151173. typedef my_coef_controller3 * my_coef_ptr3;
  151174. METHODDEF(int) decompress_onepass
  151175. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151176. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151177. METHODDEF(int) decompress_data
  151178. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151179. #endif
  151180. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151181. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  151182. METHODDEF(int) decompress_smooth_data
  151183. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151184. #endif
  151185. LOCAL(void)
  151186. start_iMCU_row3 (j_decompress_ptr cinfo)
  151187. {
  151188. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151189. if (cinfo->comps_in_scan > 1) {
  151190. coef->MCU_rows_per_iMCU_row = 1;
  151191. } else {
  151192. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  151193. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  151194. else
  151195. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  151196. }
  151197. coef->MCU_ctr = 0;
  151198. coef->MCU_vert_offset = 0;
  151199. }
  151200. METHODDEF(void)
  151201. start_input_pass (j_decompress_ptr cinfo)
  151202. {
  151203. cinfo->input_iMCU_row = 0;
  151204. start_iMCU_row3(cinfo);
  151205. }
  151206. METHODDEF(void)
  151207. start_output_pass (j_decompress_ptr cinfo)
  151208. {
  151209. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151210. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151211. if (coef->pub.coef_arrays != NULL) {
  151212. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  151213. coef->pub.decompress_data = decompress_smooth_data;
  151214. else
  151215. coef->pub.decompress_data = decompress_data;
  151216. }
  151217. #endif
  151218. cinfo->output_iMCU_row = 0;
  151219. }
  151220. METHODDEF(int)
  151221. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151222. {
  151223. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151224. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151225. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  151226. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151227. int blkn, ci, xindex, yindex, yoffset, useful_width;
  151228. JSAMPARRAY output_ptr;
  151229. JDIMENSION start_col, output_col;
  151230. jpeg_component_info *compptr;
  151231. inverse_DCT_method_ptr inverse_DCT;
  151232. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151233. yoffset++) {
  151234. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  151235. MCU_col_num++) {
  151236. jzero_far((void FAR *) coef->MCU_buffer[0],
  151237. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  151238. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151239. coef->MCU_vert_offset = yoffset;
  151240. coef->MCU_ctr = MCU_col_num;
  151241. return JPEG_SUSPENDED;
  151242. }
  151243. blkn = 0; /* index of current DCT block within MCU */
  151244. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151245. compptr = cinfo->cur_comp_info[ci];
  151246. if (! compptr->component_needed) {
  151247. blkn += compptr->MCU_blocks;
  151248. continue;
  151249. }
  151250. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  151251. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  151252. : compptr->last_col_width;
  151253. output_ptr = output_buf[compptr->component_index] +
  151254. yoffset * compptr->DCT_scaled_size;
  151255. start_col = MCU_col_num * compptr->MCU_sample_width;
  151256. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151257. if (cinfo->input_iMCU_row < last_iMCU_row ||
  151258. yoffset+yindex < compptr->last_row_height) {
  151259. output_col = start_col;
  151260. for (xindex = 0; xindex < useful_width; xindex++) {
  151261. (*inverse_DCT) (cinfo, compptr,
  151262. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  151263. output_ptr, output_col);
  151264. output_col += compptr->DCT_scaled_size;
  151265. }
  151266. }
  151267. blkn += compptr->MCU_width;
  151268. output_ptr += compptr->DCT_scaled_size;
  151269. }
  151270. }
  151271. }
  151272. coef->MCU_ctr = 0;
  151273. }
  151274. cinfo->output_iMCU_row++;
  151275. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151276. start_iMCU_row3(cinfo);
  151277. return JPEG_ROW_COMPLETED;
  151278. }
  151279. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151280. return JPEG_SCAN_COMPLETED;
  151281. }
  151282. METHODDEF(int)
  151283. dummy_consume_data (j_decompress_ptr cinfo)
  151284. {
  151285. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151286. }
  151287. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151288. METHODDEF(int)
  151289. consume_data (j_decompress_ptr cinfo)
  151290. {
  151291. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151292. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151293. int blkn, ci, xindex, yindex, yoffset;
  151294. JDIMENSION start_col;
  151295. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151296. JBLOCKROW buffer_ptr;
  151297. jpeg_component_info *compptr;
  151298. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151299. compptr = cinfo->cur_comp_info[ci];
  151300. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151301. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151302. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151303. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151304. }
  151305. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151306. yoffset++) {
  151307. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151308. MCU_col_num++) {
  151309. blkn = 0; /* index of current DCT block within MCU */
  151310. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151311. compptr = cinfo->cur_comp_info[ci];
  151312. start_col = MCU_col_num * compptr->MCU_width;
  151313. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151314. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151315. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151316. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151317. }
  151318. }
  151319. }
  151320. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151321. coef->MCU_vert_offset = yoffset;
  151322. coef->MCU_ctr = MCU_col_num;
  151323. return JPEG_SUSPENDED;
  151324. }
  151325. }
  151326. coef->MCU_ctr = 0;
  151327. }
  151328. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151329. start_iMCU_row3(cinfo);
  151330. return JPEG_ROW_COMPLETED;
  151331. }
  151332. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151333. return JPEG_SCAN_COMPLETED;
  151334. }
  151335. METHODDEF(int)
  151336. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151337. {
  151338. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151339. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151340. JDIMENSION block_num;
  151341. int ci, block_row, block_rows;
  151342. JBLOCKARRAY buffer;
  151343. JBLOCKROW buffer_ptr;
  151344. JSAMPARRAY output_ptr;
  151345. JDIMENSION output_col;
  151346. jpeg_component_info *compptr;
  151347. inverse_DCT_method_ptr inverse_DCT;
  151348. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151349. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151350. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151351. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151352. return JPEG_SUSPENDED;
  151353. }
  151354. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151355. ci++, compptr++) {
  151356. if (! compptr->component_needed)
  151357. continue;
  151358. buffer = (*cinfo->mem->access_virt_barray)
  151359. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151360. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151361. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151362. if (cinfo->output_iMCU_row < last_iMCU_row)
  151363. block_rows = compptr->v_samp_factor;
  151364. else {
  151365. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151366. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151367. }
  151368. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151369. output_ptr = output_buf[ci];
  151370. for (block_row = 0; block_row < block_rows; block_row++) {
  151371. buffer_ptr = buffer[block_row];
  151372. output_col = 0;
  151373. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151374. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151375. output_ptr, output_col);
  151376. buffer_ptr++;
  151377. output_col += compptr->DCT_scaled_size;
  151378. }
  151379. output_ptr += compptr->DCT_scaled_size;
  151380. }
  151381. }
  151382. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151383. return JPEG_ROW_COMPLETED;
  151384. return JPEG_SCAN_COMPLETED;
  151385. }
  151386. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151387. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151388. #define Q01_POS 1
  151389. #define Q10_POS 8
  151390. #define Q20_POS 16
  151391. #define Q11_POS 9
  151392. #define Q02_POS 2
  151393. LOCAL(boolean)
  151394. smoothing_ok (j_decompress_ptr cinfo)
  151395. {
  151396. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151397. boolean smoothing_useful = FALSE;
  151398. int ci, coefi;
  151399. jpeg_component_info *compptr;
  151400. JQUANT_TBL * qtable;
  151401. int * coef_bits;
  151402. int * coef_bits_latch;
  151403. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151404. return FALSE;
  151405. if (coef->coef_bits_latch == NULL)
  151406. coef->coef_bits_latch = (int *)
  151407. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151408. cinfo->num_components *
  151409. (SAVED_COEFS * SIZEOF(int)));
  151410. coef_bits_latch = coef->coef_bits_latch;
  151411. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151412. ci++, compptr++) {
  151413. if ((qtable = compptr->quant_table) == NULL)
  151414. return FALSE;
  151415. if (qtable->quantval[0] == 0 ||
  151416. qtable->quantval[Q01_POS] == 0 ||
  151417. qtable->quantval[Q10_POS] == 0 ||
  151418. qtable->quantval[Q20_POS] == 0 ||
  151419. qtable->quantval[Q11_POS] == 0 ||
  151420. qtable->quantval[Q02_POS] == 0)
  151421. return FALSE;
  151422. coef_bits = cinfo->coef_bits[ci];
  151423. if (coef_bits[0] < 0)
  151424. return FALSE;
  151425. for (coefi = 1; coefi <= 5; coefi++) {
  151426. coef_bits_latch[coefi] = coef_bits[coefi];
  151427. if (coef_bits[coefi] != 0)
  151428. smoothing_useful = TRUE;
  151429. }
  151430. coef_bits_latch += SAVED_COEFS;
  151431. }
  151432. return smoothing_useful;
  151433. }
  151434. METHODDEF(int)
  151435. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151436. {
  151437. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151438. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151439. JDIMENSION block_num, last_block_column;
  151440. int ci, block_row, block_rows, access_rows;
  151441. JBLOCKARRAY buffer;
  151442. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151443. JSAMPARRAY output_ptr;
  151444. JDIMENSION output_col;
  151445. jpeg_component_info *compptr;
  151446. inverse_DCT_method_ptr inverse_DCT;
  151447. boolean first_row, last_row;
  151448. JBLOCK workspace;
  151449. int *coef_bits;
  151450. JQUANT_TBL *quanttbl;
  151451. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151452. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151453. int Al, pred;
  151454. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151455. ! cinfo->inputctl->eoi_reached) {
  151456. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151457. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151458. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151459. break;
  151460. }
  151461. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151462. return JPEG_SUSPENDED;
  151463. }
  151464. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151465. ci++, compptr++) {
  151466. if (! compptr->component_needed)
  151467. continue;
  151468. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151469. block_rows = compptr->v_samp_factor;
  151470. access_rows = block_rows * 2; /* this and next iMCU row */
  151471. last_row = FALSE;
  151472. } else {
  151473. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151474. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151475. access_rows = block_rows; /* this iMCU row only */
  151476. last_row = TRUE;
  151477. }
  151478. if (cinfo->output_iMCU_row > 0) {
  151479. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151480. buffer = (*cinfo->mem->access_virt_barray)
  151481. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151482. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151483. (JDIMENSION) access_rows, FALSE);
  151484. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151485. first_row = FALSE;
  151486. } else {
  151487. buffer = (*cinfo->mem->access_virt_barray)
  151488. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151489. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151490. first_row = TRUE;
  151491. }
  151492. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151493. quanttbl = compptr->quant_table;
  151494. Q00 = quanttbl->quantval[0];
  151495. Q01 = quanttbl->quantval[Q01_POS];
  151496. Q10 = quanttbl->quantval[Q10_POS];
  151497. Q20 = quanttbl->quantval[Q20_POS];
  151498. Q11 = quanttbl->quantval[Q11_POS];
  151499. Q02 = quanttbl->quantval[Q02_POS];
  151500. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151501. output_ptr = output_buf[ci];
  151502. for (block_row = 0; block_row < block_rows; block_row++) {
  151503. buffer_ptr = buffer[block_row];
  151504. if (first_row && block_row == 0)
  151505. prev_block_row = buffer_ptr;
  151506. else
  151507. prev_block_row = buffer[block_row-1];
  151508. if (last_row && block_row == block_rows-1)
  151509. next_block_row = buffer_ptr;
  151510. else
  151511. next_block_row = buffer[block_row+1];
  151512. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151513. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151514. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151515. output_col = 0;
  151516. last_block_column = compptr->width_in_blocks - 1;
  151517. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151518. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151519. if (block_num < last_block_column) {
  151520. DC3 = (int) prev_block_row[1][0];
  151521. DC6 = (int) buffer_ptr[1][0];
  151522. DC9 = (int) next_block_row[1][0];
  151523. }
  151524. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151525. num = 36 * Q00 * (DC4 - DC6);
  151526. if (num >= 0) {
  151527. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151528. if (Al > 0 && pred >= (1<<Al))
  151529. pred = (1<<Al)-1;
  151530. } else {
  151531. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151532. if (Al > 0 && pred >= (1<<Al))
  151533. pred = (1<<Al)-1;
  151534. pred = -pred;
  151535. }
  151536. workspace[1] = (JCOEF) pred;
  151537. }
  151538. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151539. num = 36 * Q00 * (DC2 - DC8);
  151540. if (num >= 0) {
  151541. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151542. if (Al > 0 && pred >= (1<<Al))
  151543. pred = (1<<Al)-1;
  151544. } else {
  151545. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151546. if (Al > 0 && pred >= (1<<Al))
  151547. pred = (1<<Al)-1;
  151548. pred = -pred;
  151549. }
  151550. workspace[8] = (JCOEF) pred;
  151551. }
  151552. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151553. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151554. if (num >= 0) {
  151555. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151556. if (Al > 0 && pred >= (1<<Al))
  151557. pred = (1<<Al)-1;
  151558. } else {
  151559. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151560. if (Al > 0 && pred >= (1<<Al))
  151561. pred = (1<<Al)-1;
  151562. pred = -pred;
  151563. }
  151564. workspace[16] = (JCOEF) pred;
  151565. }
  151566. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151567. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151568. if (num >= 0) {
  151569. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151570. if (Al > 0 && pred >= (1<<Al))
  151571. pred = (1<<Al)-1;
  151572. } else {
  151573. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151574. if (Al > 0 && pred >= (1<<Al))
  151575. pred = (1<<Al)-1;
  151576. pred = -pred;
  151577. }
  151578. workspace[9] = (JCOEF) pred;
  151579. }
  151580. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151581. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151582. if (num >= 0) {
  151583. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151584. if (Al > 0 && pred >= (1<<Al))
  151585. pred = (1<<Al)-1;
  151586. } else {
  151587. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151588. if (Al > 0 && pred >= (1<<Al))
  151589. pred = (1<<Al)-1;
  151590. pred = -pred;
  151591. }
  151592. workspace[2] = (JCOEF) pred;
  151593. }
  151594. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151595. output_ptr, output_col);
  151596. DC1 = DC2; DC2 = DC3;
  151597. DC4 = DC5; DC5 = DC6;
  151598. DC7 = DC8; DC8 = DC9;
  151599. buffer_ptr++, prev_block_row++, next_block_row++;
  151600. output_col += compptr->DCT_scaled_size;
  151601. }
  151602. output_ptr += compptr->DCT_scaled_size;
  151603. }
  151604. }
  151605. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151606. return JPEG_ROW_COMPLETED;
  151607. return JPEG_SCAN_COMPLETED;
  151608. }
  151609. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151610. GLOBAL(void)
  151611. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151612. {
  151613. my_coef_ptr3 coef;
  151614. coef = (my_coef_ptr3)
  151615. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151616. SIZEOF(my_coef_controller3));
  151617. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151618. coef->pub.start_input_pass = start_input_pass;
  151619. coef->pub.start_output_pass = start_output_pass;
  151620. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151621. coef->coef_bits_latch = NULL;
  151622. #endif
  151623. if (need_full_buffer) {
  151624. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151625. int ci, access_rows;
  151626. jpeg_component_info *compptr;
  151627. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151628. ci++, compptr++) {
  151629. access_rows = compptr->v_samp_factor;
  151630. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151631. if (cinfo->progressive_mode)
  151632. access_rows *= 3;
  151633. #endif
  151634. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151635. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151636. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151637. (long) compptr->h_samp_factor),
  151638. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151639. (long) compptr->v_samp_factor),
  151640. (JDIMENSION) access_rows);
  151641. }
  151642. coef->pub.consume_data = consume_data;
  151643. coef->pub.decompress_data = decompress_data;
  151644. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151645. #else
  151646. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151647. #endif
  151648. } else {
  151649. JBLOCKROW buffer;
  151650. int i;
  151651. buffer = (JBLOCKROW)
  151652. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151653. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151654. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151655. coef->MCU_buffer[i] = buffer + i;
  151656. }
  151657. coef->pub.consume_data = dummy_consume_data;
  151658. coef->pub.decompress_data = decompress_onepass;
  151659. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151660. }
  151661. }
  151662. /*** End of inlined file: jdcoefct.c ***/
  151663. #undef FIX
  151664. /*** Start of inlined file: jdcolor.c ***/
  151665. #define JPEG_INTERNALS
  151666. typedef struct {
  151667. struct jpeg_color_deconverter pub; /* public fields */
  151668. int * Cr_r_tab; /* => table for Cr to R conversion */
  151669. int * Cb_b_tab; /* => table for Cb to B conversion */
  151670. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151671. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151672. } my_color_deconverter2;
  151673. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151674. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151675. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151676. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151677. LOCAL(void)
  151678. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151679. {
  151680. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151681. int i;
  151682. INT32 x;
  151683. SHIFT_TEMPS
  151684. cconvert->Cr_r_tab = (int *)
  151685. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151686. (MAXJSAMPLE+1) * SIZEOF(int));
  151687. cconvert->Cb_b_tab = (int *)
  151688. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151689. (MAXJSAMPLE+1) * SIZEOF(int));
  151690. cconvert->Cr_g_tab = (INT32 *)
  151691. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151692. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151693. cconvert->Cb_g_tab = (INT32 *)
  151694. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151695. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151696. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151697. cconvert->Cr_r_tab[i] = (int)
  151698. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151699. cconvert->Cb_b_tab[i] = (int)
  151700. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151701. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151702. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151703. }
  151704. }
  151705. METHODDEF(void)
  151706. ycc_rgb_convert (j_decompress_ptr cinfo,
  151707. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151708. JSAMPARRAY output_buf, int num_rows)
  151709. {
  151710. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151711. register int y, cb, cr;
  151712. register JSAMPROW outptr;
  151713. register JSAMPROW inptr0, inptr1, inptr2;
  151714. register JDIMENSION col;
  151715. JDIMENSION num_cols = cinfo->output_width;
  151716. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151717. register int * Crrtab = cconvert->Cr_r_tab;
  151718. register int * Cbbtab = cconvert->Cb_b_tab;
  151719. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151720. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151721. SHIFT_TEMPS
  151722. while (--num_rows >= 0) {
  151723. inptr0 = input_buf[0][input_row];
  151724. inptr1 = input_buf[1][input_row];
  151725. inptr2 = input_buf[2][input_row];
  151726. input_row++;
  151727. outptr = *output_buf++;
  151728. for (col = 0; col < num_cols; col++) {
  151729. y = GETJSAMPLE(inptr0[col]);
  151730. cb = GETJSAMPLE(inptr1[col]);
  151731. cr = GETJSAMPLE(inptr2[col]);
  151732. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151733. outptr[RGB_GREEN] = range_limit[y +
  151734. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151735. SCALEBITS))];
  151736. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151737. outptr += RGB_PIXELSIZE;
  151738. }
  151739. }
  151740. }
  151741. METHODDEF(void)
  151742. null_convert2 (j_decompress_ptr cinfo,
  151743. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151744. JSAMPARRAY output_buf, int num_rows)
  151745. {
  151746. register JSAMPROW inptr, outptr;
  151747. register JDIMENSION count;
  151748. register int num_components = cinfo->num_components;
  151749. JDIMENSION num_cols = cinfo->output_width;
  151750. int ci;
  151751. while (--num_rows >= 0) {
  151752. for (ci = 0; ci < num_components; ci++) {
  151753. inptr = input_buf[ci][input_row];
  151754. outptr = output_buf[0] + ci;
  151755. for (count = num_cols; count > 0; count--) {
  151756. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151757. outptr += num_components;
  151758. }
  151759. }
  151760. input_row++;
  151761. output_buf++;
  151762. }
  151763. }
  151764. METHODDEF(void)
  151765. grayscale_convert2 (j_decompress_ptr cinfo,
  151766. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151767. JSAMPARRAY output_buf, int num_rows)
  151768. {
  151769. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151770. num_rows, cinfo->output_width);
  151771. }
  151772. METHODDEF(void)
  151773. gray_rgb_convert (j_decompress_ptr cinfo,
  151774. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151775. JSAMPARRAY output_buf, int num_rows)
  151776. {
  151777. register JSAMPROW inptr, outptr;
  151778. register JDIMENSION col;
  151779. JDIMENSION num_cols = cinfo->output_width;
  151780. while (--num_rows >= 0) {
  151781. inptr = input_buf[0][input_row++];
  151782. outptr = *output_buf++;
  151783. for (col = 0; col < num_cols; col++) {
  151784. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151785. outptr += RGB_PIXELSIZE;
  151786. }
  151787. }
  151788. }
  151789. METHODDEF(void)
  151790. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151791. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151792. JSAMPARRAY output_buf, int num_rows)
  151793. {
  151794. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151795. register int y, cb, cr;
  151796. register JSAMPROW outptr;
  151797. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151798. register JDIMENSION col;
  151799. JDIMENSION num_cols = cinfo->output_width;
  151800. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151801. register int * Crrtab = cconvert->Cr_r_tab;
  151802. register int * Cbbtab = cconvert->Cb_b_tab;
  151803. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151804. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151805. SHIFT_TEMPS
  151806. while (--num_rows >= 0) {
  151807. inptr0 = input_buf[0][input_row];
  151808. inptr1 = input_buf[1][input_row];
  151809. inptr2 = input_buf[2][input_row];
  151810. inptr3 = input_buf[3][input_row];
  151811. input_row++;
  151812. outptr = *output_buf++;
  151813. for (col = 0; col < num_cols; col++) {
  151814. y = GETJSAMPLE(inptr0[col]);
  151815. cb = GETJSAMPLE(inptr1[col]);
  151816. cr = GETJSAMPLE(inptr2[col]);
  151817. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151818. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151819. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151820. SCALEBITS)))];
  151821. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151822. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151823. outptr += 4;
  151824. }
  151825. }
  151826. }
  151827. METHODDEF(void)
  151828. start_pass_dcolor (j_decompress_ptr cinfo)
  151829. {
  151830. }
  151831. GLOBAL(void)
  151832. jinit_color_deconverter (j_decompress_ptr cinfo)
  151833. {
  151834. my_cconvert_ptr2 cconvert;
  151835. int ci;
  151836. cconvert = (my_cconvert_ptr2)
  151837. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151838. SIZEOF(my_color_deconverter2));
  151839. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151840. cconvert->pub.start_pass = start_pass_dcolor;
  151841. switch (cinfo->jpeg_color_space) {
  151842. case JCS_GRAYSCALE:
  151843. if (cinfo->num_components != 1)
  151844. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151845. break;
  151846. case JCS_RGB:
  151847. case JCS_YCbCr:
  151848. if (cinfo->num_components != 3)
  151849. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151850. break;
  151851. case JCS_CMYK:
  151852. case JCS_YCCK:
  151853. if (cinfo->num_components != 4)
  151854. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151855. break;
  151856. default: /* JCS_UNKNOWN can be anything */
  151857. if (cinfo->num_components < 1)
  151858. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151859. break;
  151860. }
  151861. switch (cinfo->out_color_space) {
  151862. case JCS_GRAYSCALE:
  151863. cinfo->out_color_components = 1;
  151864. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151865. cinfo->jpeg_color_space == JCS_YCbCr) {
  151866. cconvert->pub.color_convert = grayscale_convert2;
  151867. for (ci = 1; ci < cinfo->num_components; ci++)
  151868. cinfo->comp_info[ci].component_needed = FALSE;
  151869. } else
  151870. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151871. break;
  151872. case JCS_RGB:
  151873. cinfo->out_color_components = RGB_PIXELSIZE;
  151874. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151875. cconvert->pub.color_convert = ycc_rgb_convert;
  151876. build_ycc_rgb_table(cinfo);
  151877. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151878. cconvert->pub.color_convert = gray_rgb_convert;
  151879. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151880. cconvert->pub.color_convert = null_convert2;
  151881. } else
  151882. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151883. break;
  151884. case JCS_CMYK:
  151885. cinfo->out_color_components = 4;
  151886. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151887. cconvert->pub.color_convert = ycck_cmyk_convert;
  151888. build_ycc_rgb_table(cinfo);
  151889. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151890. cconvert->pub.color_convert = null_convert2;
  151891. } else
  151892. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151893. break;
  151894. default:
  151895. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151896. cinfo->out_color_components = cinfo->num_components;
  151897. cconvert->pub.color_convert = null_convert2;
  151898. } else /* unsupported non-null conversion */
  151899. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151900. break;
  151901. }
  151902. if (cinfo->quantize_colors)
  151903. cinfo->output_components = 1; /* single colormapped output component */
  151904. else
  151905. cinfo->output_components = cinfo->out_color_components;
  151906. }
  151907. /*** End of inlined file: jdcolor.c ***/
  151908. #undef FIX
  151909. /*** Start of inlined file: jddctmgr.c ***/
  151910. #define JPEG_INTERNALS
  151911. typedef struct {
  151912. struct jpeg_inverse_dct pub; /* public fields */
  151913. int cur_method[MAX_COMPONENTS];
  151914. } my_idct_controller;
  151915. typedef my_idct_controller * my_idct_ptr;
  151916. typedef union {
  151917. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151918. #ifdef DCT_IFAST_SUPPORTED
  151919. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151920. #endif
  151921. #ifdef DCT_FLOAT_SUPPORTED
  151922. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151923. #endif
  151924. } multiplier_table;
  151925. #ifdef DCT_ISLOW_SUPPORTED
  151926. #define PROVIDE_ISLOW_TABLES
  151927. #else
  151928. #ifdef IDCT_SCALING_SUPPORTED
  151929. #define PROVIDE_ISLOW_TABLES
  151930. #endif
  151931. #endif
  151932. METHODDEF(void)
  151933. start_pass (j_decompress_ptr cinfo)
  151934. {
  151935. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151936. int ci, i;
  151937. jpeg_component_info *compptr;
  151938. int method = 0;
  151939. inverse_DCT_method_ptr method_ptr = NULL;
  151940. JQUANT_TBL * qtbl;
  151941. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151942. ci++, compptr++) {
  151943. switch (compptr->DCT_scaled_size) {
  151944. #ifdef IDCT_SCALING_SUPPORTED
  151945. case 1:
  151946. method_ptr = jpeg_idct_1x1;
  151947. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151948. break;
  151949. case 2:
  151950. method_ptr = jpeg_idct_2x2;
  151951. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151952. break;
  151953. case 4:
  151954. method_ptr = jpeg_idct_4x4;
  151955. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151956. break;
  151957. #endif
  151958. case DCTSIZE:
  151959. switch (cinfo->dct_method) {
  151960. #ifdef DCT_ISLOW_SUPPORTED
  151961. case JDCT_ISLOW:
  151962. method_ptr = jpeg_idct_islow;
  151963. method = JDCT_ISLOW;
  151964. break;
  151965. #endif
  151966. #ifdef DCT_IFAST_SUPPORTED
  151967. case JDCT_IFAST:
  151968. method_ptr = jpeg_idct_ifast;
  151969. method = JDCT_IFAST;
  151970. break;
  151971. #endif
  151972. #ifdef DCT_FLOAT_SUPPORTED
  151973. case JDCT_FLOAT:
  151974. method_ptr = jpeg_idct_float;
  151975. method = JDCT_FLOAT;
  151976. break;
  151977. #endif
  151978. default:
  151979. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151980. break;
  151981. }
  151982. break;
  151983. default:
  151984. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151985. break;
  151986. }
  151987. idct->pub.inverse_DCT[ci] = method_ptr;
  151988. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151989. continue;
  151990. qtbl = compptr->quant_table;
  151991. if (qtbl == NULL) /* happens if no data yet for component */
  151992. continue;
  151993. idct->cur_method[ci] = method;
  151994. switch (method) {
  151995. #ifdef PROVIDE_ISLOW_TABLES
  151996. case JDCT_ISLOW:
  151997. {
  151998. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151999. for (i = 0; i < DCTSIZE2; i++) {
  152000. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  152001. }
  152002. }
  152003. break;
  152004. #endif
  152005. #ifdef DCT_IFAST_SUPPORTED
  152006. case JDCT_IFAST:
  152007. {
  152008. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  152009. #define CONST_BITS 14
  152010. static const INT16 aanscales[DCTSIZE2] = {
  152011. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152012. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  152013. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  152014. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  152015. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152016. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  152017. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  152018. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  152019. };
  152020. SHIFT_TEMPS
  152021. for (i = 0; i < DCTSIZE2; i++) {
  152022. ifmtbl[i] = (IFAST_MULT_TYPE)
  152023. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  152024. (INT32) aanscales[i]),
  152025. CONST_BITS-IFAST_SCALE_BITS);
  152026. }
  152027. }
  152028. break;
  152029. #endif
  152030. #ifdef DCT_FLOAT_SUPPORTED
  152031. case JDCT_FLOAT:
  152032. {
  152033. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  152034. int row, col;
  152035. static const double aanscalefactor[DCTSIZE] = {
  152036. 1.0, 1.387039845, 1.306562965, 1.175875602,
  152037. 1.0, 0.785694958, 0.541196100, 0.275899379
  152038. };
  152039. i = 0;
  152040. for (row = 0; row < DCTSIZE; row++) {
  152041. for (col = 0; col < DCTSIZE; col++) {
  152042. fmtbl[i] = (FLOAT_MULT_TYPE)
  152043. ((double) qtbl->quantval[i] *
  152044. aanscalefactor[row] * aanscalefactor[col]);
  152045. i++;
  152046. }
  152047. }
  152048. }
  152049. break;
  152050. #endif
  152051. default:
  152052. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152053. break;
  152054. }
  152055. }
  152056. }
  152057. GLOBAL(void)
  152058. jinit_inverse_dct (j_decompress_ptr cinfo)
  152059. {
  152060. my_idct_ptr idct;
  152061. int ci;
  152062. jpeg_component_info *compptr;
  152063. idct = (my_idct_ptr)
  152064. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152065. SIZEOF(my_idct_controller));
  152066. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  152067. idct->pub.start_pass = start_pass;
  152068. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152069. ci++, compptr++) {
  152070. compptr->dct_table =
  152071. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152072. SIZEOF(multiplier_table));
  152073. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  152074. idct->cur_method[ci] = -1;
  152075. }
  152076. }
  152077. /*** End of inlined file: jddctmgr.c ***/
  152078. #undef CONST_BITS
  152079. #undef ASSIGN_STATE
  152080. /*** Start of inlined file: jdhuff.c ***/
  152081. #define JPEG_INTERNALS
  152082. /*** Start of inlined file: jdhuff.h ***/
  152083. #ifndef __jdhuff_h__
  152084. #define __jdhuff_h__
  152085. #ifdef NEED_SHORT_EXTERNAL_NAMES
  152086. #define jpeg_make_d_derived_tbl jMkDDerived
  152087. #define jpeg_fill_bit_buffer jFilBitBuf
  152088. #define jpeg_huff_decode jHufDecode
  152089. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  152090. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  152091. typedef struct {
  152092. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  152093. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  152094. JHUFF_TBL *pub;
  152095. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  152096. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  152097. } d_derived_tbl;
  152098. EXTERN(void) jpeg_make_d_derived_tbl
  152099. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  152100. d_derived_tbl ** pdtbl));
  152101. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  152102. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  152103. typedef struct { /* Bitreading state saved across MCUs */
  152104. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152105. int bits_left; /* # of unused bits in it */
  152106. } bitread_perm_state;
  152107. typedef struct { /* Bitreading working state within an MCU */
  152108. const JOCTET * next_input_byte; /* => next byte to read from source */
  152109. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  152110. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152111. int bits_left; /* # of unused bits in it */
  152112. j_decompress_ptr cinfo; /* back link to decompress master record */
  152113. } bitread_working_state;
  152114. #define BITREAD_STATE_VARS \
  152115. register bit_buf_type get_buffer; \
  152116. register int bits_left; \
  152117. bitread_working_state br_state
  152118. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  152119. br_state.cinfo = cinfop; \
  152120. br_state.next_input_byte = cinfop->src->next_input_byte; \
  152121. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  152122. get_buffer = permstate.get_buffer; \
  152123. bits_left = permstate.bits_left;
  152124. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  152125. cinfop->src->next_input_byte = br_state.next_input_byte; \
  152126. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  152127. permstate.get_buffer = get_buffer; \
  152128. permstate.bits_left = bits_left
  152129. #define CHECK_BIT_BUFFER(state,nbits,action) \
  152130. { if (bits_left < (nbits)) { \
  152131. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  152132. { action; } \
  152133. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  152134. #define GET_BITS(nbits) \
  152135. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  152136. #define PEEK_BITS(nbits) \
  152137. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  152138. #define DROP_BITS(nbits) \
  152139. (bits_left -= (nbits))
  152140. EXTERN(boolean) jpeg_fill_bit_buffer
  152141. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152142. register int bits_left, int nbits));
  152143. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  152144. { register int nb, look; \
  152145. if (bits_left < HUFF_LOOKAHEAD) { \
  152146. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  152147. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152148. if (bits_left < HUFF_LOOKAHEAD) { \
  152149. nb = 1; goto slowlabel; \
  152150. } \
  152151. } \
  152152. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  152153. if ((nb = htbl->look_nbits[look]) != 0) { \
  152154. DROP_BITS(nb); \
  152155. result = htbl->look_sym[look]; \
  152156. } else { \
  152157. nb = HUFF_LOOKAHEAD+1; \
  152158. slowlabel: \
  152159. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  152160. { failaction; } \
  152161. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152162. } \
  152163. }
  152164. EXTERN(int) jpeg_huff_decode
  152165. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152166. register int bits_left, d_derived_tbl * htbl, int min_bits));
  152167. #endif
  152168. /*** End of inlined file: jdhuff.h ***/
  152169. /* Declarations shared with jdphuff.c */
  152170. typedef struct {
  152171. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  152172. } savable_state2;
  152173. #ifndef NO_STRUCT_ASSIGN
  152174. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  152175. #else
  152176. #if MAX_COMPS_IN_SCAN == 4
  152177. #define ASSIGN_STATE(dest,src) \
  152178. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  152179. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  152180. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  152181. (dest).last_dc_val[3] = (src).last_dc_val[3])
  152182. #endif
  152183. #endif
  152184. typedef struct {
  152185. struct jpeg_entropy_decoder pub; /* public fields */
  152186. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  152187. savable_state2 saved; /* Other state at start of MCU */
  152188. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  152189. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  152190. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  152191. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152192. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152193. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  152194. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  152195. } huff_entropy_decoder2;
  152196. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  152197. METHODDEF(void)
  152198. start_pass_huff_decoder (j_decompress_ptr cinfo)
  152199. {
  152200. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152201. int ci, blkn, dctbl, actbl;
  152202. jpeg_component_info * compptr;
  152203. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  152204. cinfo->Ah != 0 || cinfo->Al != 0)
  152205. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  152206. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152207. compptr = cinfo->cur_comp_info[ci];
  152208. dctbl = compptr->dc_tbl_no;
  152209. actbl = compptr->ac_tbl_no;
  152210. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  152211. & entropy->dc_derived_tbls[dctbl]);
  152212. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  152213. & entropy->ac_derived_tbls[actbl]);
  152214. entropy->saved.last_dc_val[ci] = 0;
  152215. }
  152216. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152217. ci = cinfo->MCU_membership[blkn];
  152218. compptr = cinfo->cur_comp_info[ci];
  152219. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  152220. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  152221. if (compptr->component_needed) {
  152222. entropy->dc_needed[blkn] = TRUE;
  152223. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  152224. } else {
  152225. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  152226. }
  152227. }
  152228. entropy->bitstate.bits_left = 0;
  152229. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  152230. entropy->pub.insufficient_data = FALSE;
  152231. entropy->restarts_to_go = cinfo->restart_interval;
  152232. }
  152233. GLOBAL(void)
  152234. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  152235. d_derived_tbl ** pdtbl)
  152236. {
  152237. JHUFF_TBL *htbl;
  152238. d_derived_tbl *dtbl;
  152239. int p, i, l, si, numsymbols;
  152240. int lookbits, ctr;
  152241. char huffsize[257];
  152242. unsigned int huffcode[257];
  152243. unsigned int code;
  152244. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  152245. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152246. htbl =
  152247. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  152248. if (htbl == NULL)
  152249. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152250. if (*pdtbl == NULL)
  152251. *pdtbl = (d_derived_tbl *)
  152252. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152253. SIZEOF(d_derived_tbl));
  152254. dtbl = *pdtbl;
  152255. dtbl->pub = htbl; /* fill in back link */
  152256. p = 0;
  152257. for (l = 1; l <= 16; l++) {
  152258. i = (int) htbl->bits[l];
  152259. if (i < 0 || p + i > 256) /* protect against table overrun */
  152260. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152261. while (i--)
  152262. huffsize[p++] = (char) l;
  152263. }
  152264. huffsize[p] = 0;
  152265. numsymbols = p;
  152266. code = 0;
  152267. si = huffsize[0];
  152268. p = 0;
  152269. while (huffsize[p]) {
  152270. while (((int) huffsize[p]) == si) {
  152271. huffcode[p++] = code;
  152272. code++;
  152273. }
  152274. if (((INT32) code) >= (((INT32) 1) << si))
  152275. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152276. code <<= 1;
  152277. si++;
  152278. }
  152279. p = 0;
  152280. for (l = 1; l <= 16; l++) {
  152281. if (htbl->bits[l]) {
  152282. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  152283. p += htbl->bits[l];
  152284. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  152285. } else {
  152286. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152287. }
  152288. }
  152289. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152290. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152291. p = 0;
  152292. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152293. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152294. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152295. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152296. dtbl->look_nbits[lookbits] = l;
  152297. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152298. lookbits++;
  152299. }
  152300. }
  152301. }
  152302. if (isDC) {
  152303. for (i = 0; i < numsymbols; i++) {
  152304. int sym = htbl->huffval[i];
  152305. if (sym < 0 || sym > 15)
  152306. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152307. }
  152308. }
  152309. }
  152310. #ifdef SLOW_SHIFT_32
  152311. #define MIN_GET_BITS 15 /* minimum allowable value */
  152312. #else
  152313. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152314. #endif
  152315. GLOBAL(boolean)
  152316. jpeg_fill_bit_buffer (bitread_working_state * state,
  152317. register bit_buf_type get_buffer, register int bits_left,
  152318. int nbits)
  152319. {
  152320. register const JOCTET * next_input_byte = state->next_input_byte;
  152321. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152322. j_decompress_ptr cinfo = state->cinfo;
  152323. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152324. while (bits_left < MIN_GET_BITS) {
  152325. register int c;
  152326. if (bytes_in_buffer == 0) {
  152327. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152328. return FALSE;
  152329. next_input_byte = cinfo->src->next_input_byte;
  152330. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152331. }
  152332. bytes_in_buffer--;
  152333. c = GETJOCTET(*next_input_byte++);
  152334. if (c == 0xFF) {
  152335. do {
  152336. if (bytes_in_buffer == 0) {
  152337. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152338. return FALSE;
  152339. next_input_byte = cinfo->src->next_input_byte;
  152340. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152341. }
  152342. bytes_in_buffer--;
  152343. c = GETJOCTET(*next_input_byte++);
  152344. } while (c == 0xFF);
  152345. if (c == 0) {
  152346. c = 0xFF;
  152347. } else {
  152348. cinfo->unread_marker = c;
  152349. goto no_more_bytes;
  152350. }
  152351. }
  152352. get_buffer = (get_buffer << 8) | c;
  152353. bits_left += 8;
  152354. } /* end while */
  152355. } else {
  152356. no_more_bytes:
  152357. if (nbits > bits_left) {
  152358. if (! cinfo->entropy->insufficient_data) {
  152359. WARNMS(cinfo, JWRN_HIT_MARKER);
  152360. cinfo->entropy->insufficient_data = TRUE;
  152361. }
  152362. get_buffer <<= MIN_GET_BITS - bits_left;
  152363. bits_left = MIN_GET_BITS;
  152364. }
  152365. }
  152366. state->next_input_byte = next_input_byte;
  152367. state->bytes_in_buffer = bytes_in_buffer;
  152368. state->get_buffer = get_buffer;
  152369. state->bits_left = bits_left;
  152370. return TRUE;
  152371. }
  152372. GLOBAL(int)
  152373. jpeg_huff_decode (bitread_working_state * state,
  152374. register bit_buf_type get_buffer, register int bits_left,
  152375. d_derived_tbl * htbl, int min_bits)
  152376. {
  152377. register int l = min_bits;
  152378. register INT32 code;
  152379. CHECK_BIT_BUFFER(*state, l, return -1);
  152380. code = GET_BITS(l);
  152381. while (code > htbl->maxcode[l]) {
  152382. code <<= 1;
  152383. CHECK_BIT_BUFFER(*state, 1, return -1);
  152384. code |= GET_BITS(1);
  152385. l++;
  152386. }
  152387. state->get_buffer = get_buffer;
  152388. state->bits_left = bits_left;
  152389. if (l > 16) {
  152390. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152391. return 0; /* fake a zero as the safest result */
  152392. }
  152393. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152394. }
  152395. LOCAL(boolean)
  152396. process_restart (j_decompress_ptr cinfo)
  152397. {
  152398. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152399. int ci;
  152400. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152401. entropy->bitstate.bits_left = 0;
  152402. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152403. return FALSE;
  152404. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152405. entropy->saved.last_dc_val[ci] = 0;
  152406. entropy->restarts_to_go = cinfo->restart_interval;
  152407. if (cinfo->unread_marker == 0)
  152408. entropy->pub.insufficient_data = FALSE;
  152409. return TRUE;
  152410. }
  152411. METHODDEF(boolean)
  152412. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152413. {
  152414. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152415. int blkn;
  152416. BITREAD_STATE_VARS;
  152417. savable_state2 state;
  152418. if (cinfo->restart_interval) {
  152419. if (entropy->restarts_to_go == 0)
  152420. if (! process_restart(cinfo))
  152421. return FALSE;
  152422. }
  152423. if (! entropy->pub.insufficient_data) {
  152424. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152425. ASSIGN_STATE(state, entropy->saved);
  152426. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152427. JBLOCKROW block = MCU_data[blkn];
  152428. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152429. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152430. register int s, k, r;
  152431. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152432. if (s) {
  152433. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152434. r = GET_BITS(s);
  152435. s = HUFF_EXTEND(r, s);
  152436. }
  152437. if (entropy->dc_needed[blkn]) {
  152438. int ci = cinfo->MCU_membership[blkn];
  152439. s += state.last_dc_val[ci];
  152440. state.last_dc_val[ci] = s;
  152441. (*block)[0] = (JCOEF) s;
  152442. }
  152443. if (entropy->ac_needed[blkn]) {
  152444. for (k = 1; k < DCTSIZE2; k++) {
  152445. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152446. r = s >> 4;
  152447. s &= 15;
  152448. if (s) {
  152449. k += r;
  152450. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152451. r = GET_BITS(s);
  152452. s = HUFF_EXTEND(r, s);
  152453. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152454. } else {
  152455. if (r != 15)
  152456. break;
  152457. k += 15;
  152458. }
  152459. }
  152460. } else {
  152461. for (k = 1; k < DCTSIZE2; k++) {
  152462. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152463. r = s >> 4;
  152464. s &= 15;
  152465. if (s) {
  152466. k += r;
  152467. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152468. DROP_BITS(s);
  152469. } else {
  152470. if (r != 15)
  152471. break;
  152472. k += 15;
  152473. }
  152474. }
  152475. }
  152476. }
  152477. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152478. ASSIGN_STATE(entropy->saved, state);
  152479. }
  152480. entropy->restarts_to_go--;
  152481. return TRUE;
  152482. }
  152483. GLOBAL(void)
  152484. jinit_huff_decoder (j_decompress_ptr cinfo)
  152485. {
  152486. huff_entropy_ptr2 entropy;
  152487. int i;
  152488. entropy = (huff_entropy_ptr2)
  152489. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152490. SIZEOF(huff_entropy_decoder2));
  152491. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152492. entropy->pub.start_pass = start_pass_huff_decoder;
  152493. entropy->pub.decode_mcu = decode_mcu;
  152494. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152495. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152496. }
  152497. }
  152498. /*** End of inlined file: jdhuff.c ***/
  152499. /*** Start of inlined file: jdinput.c ***/
  152500. #define JPEG_INTERNALS
  152501. typedef struct {
  152502. struct jpeg_input_controller pub; /* public fields */
  152503. boolean inheaders; /* TRUE until first SOS is reached */
  152504. } my_input_controller;
  152505. typedef my_input_controller * my_inputctl_ptr;
  152506. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152507. LOCAL(void)
  152508. initial_setup2 (j_decompress_ptr cinfo)
  152509. {
  152510. int ci;
  152511. jpeg_component_info *compptr;
  152512. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152513. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152514. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152515. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152516. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152517. if (cinfo->num_components > MAX_COMPONENTS)
  152518. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152519. MAX_COMPONENTS);
  152520. cinfo->max_h_samp_factor = 1;
  152521. cinfo->max_v_samp_factor = 1;
  152522. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152523. ci++, compptr++) {
  152524. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152525. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152526. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152527. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152528. compptr->h_samp_factor);
  152529. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152530. compptr->v_samp_factor);
  152531. }
  152532. cinfo->min_DCT_scaled_size = DCTSIZE;
  152533. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152534. ci++, compptr++) {
  152535. compptr->DCT_scaled_size = DCTSIZE;
  152536. compptr->width_in_blocks = (JDIMENSION)
  152537. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152538. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152539. compptr->height_in_blocks = (JDIMENSION)
  152540. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152541. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152542. compptr->downsampled_width = (JDIMENSION)
  152543. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152544. (long) cinfo->max_h_samp_factor);
  152545. compptr->downsampled_height = (JDIMENSION)
  152546. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152547. (long) cinfo->max_v_samp_factor);
  152548. compptr->component_needed = TRUE;
  152549. compptr->quant_table = NULL;
  152550. }
  152551. cinfo->total_iMCU_rows = (JDIMENSION)
  152552. jdiv_round_up((long) cinfo->image_height,
  152553. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152554. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152555. cinfo->inputctl->has_multiple_scans = TRUE;
  152556. else
  152557. cinfo->inputctl->has_multiple_scans = FALSE;
  152558. }
  152559. LOCAL(void)
  152560. per_scan_setup2 (j_decompress_ptr cinfo)
  152561. {
  152562. int ci, mcublks, tmp;
  152563. jpeg_component_info *compptr;
  152564. if (cinfo->comps_in_scan == 1) {
  152565. compptr = cinfo->cur_comp_info[0];
  152566. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152567. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152568. compptr->MCU_width = 1;
  152569. compptr->MCU_height = 1;
  152570. compptr->MCU_blocks = 1;
  152571. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152572. compptr->last_col_width = 1;
  152573. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152574. if (tmp == 0) tmp = compptr->v_samp_factor;
  152575. compptr->last_row_height = tmp;
  152576. cinfo->blocks_in_MCU = 1;
  152577. cinfo->MCU_membership[0] = 0;
  152578. } else {
  152579. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152580. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152581. MAX_COMPS_IN_SCAN);
  152582. cinfo->MCUs_per_row = (JDIMENSION)
  152583. jdiv_round_up((long) cinfo->image_width,
  152584. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152585. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152586. jdiv_round_up((long) cinfo->image_height,
  152587. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152588. cinfo->blocks_in_MCU = 0;
  152589. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152590. compptr = cinfo->cur_comp_info[ci];
  152591. compptr->MCU_width = compptr->h_samp_factor;
  152592. compptr->MCU_height = compptr->v_samp_factor;
  152593. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152594. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152595. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152596. if (tmp == 0) tmp = compptr->MCU_width;
  152597. compptr->last_col_width = tmp;
  152598. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152599. if (tmp == 0) tmp = compptr->MCU_height;
  152600. compptr->last_row_height = tmp;
  152601. mcublks = compptr->MCU_blocks;
  152602. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152603. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152604. while (mcublks-- > 0) {
  152605. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152606. }
  152607. }
  152608. }
  152609. }
  152610. LOCAL(void)
  152611. latch_quant_tables (j_decompress_ptr cinfo)
  152612. {
  152613. int ci, qtblno;
  152614. jpeg_component_info *compptr;
  152615. JQUANT_TBL * qtbl;
  152616. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152617. compptr = cinfo->cur_comp_info[ci];
  152618. if (compptr->quant_table != NULL)
  152619. continue;
  152620. qtblno = compptr->quant_tbl_no;
  152621. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152622. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152623. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152624. qtbl = (JQUANT_TBL *)
  152625. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152626. SIZEOF(JQUANT_TBL));
  152627. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152628. compptr->quant_table = qtbl;
  152629. }
  152630. }
  152631. METHODDEF(void)
  152632. start_input_pass2 (j_decompress_ptr cinfo)
  152633. {
  152634. per_scan_setup2(cinfo);
  152635. latch_quant_tables(cinfo);
  152636. (*cinfo->entropy->start_pass) (cinfo);
  152637. (*cinfo->coef->start_input_pass) (cinfo);
  152638. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152639. }
  152640. METHODDEF(void)
  152641. finish_input_pass (j_decompress_ptr cinfo)
  152642. {
  152643. cinfo->inputctl->consume_input = consume_markers;
  152644. }
  152645. METHODDEF(int)
  152646. consume_markers (j_decompress_ptr cinfo)
  152647. {
  152648. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152649. int val;
  152650. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152651. return JPEG_REACHED_EOI;
  152652. val = (*cinfo->marker->read_markers) (cinfo);
  152653. switch (val) {
  152654. case JPEG_REACHED_SOS: /* Found SOS */
  152655. if (inputctl->inheaders) { /* 1st SOS */
  152656. initial_setup2(cinfo);
  152657. inputctl->inheaders = FALSE;
  152658. } else { /* 2nd or later SOS marker */
  152659. if (! inputctl->pub.has_multiple_scans)
  152660. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152661. start_input_pass2(cinfo);
  152662. }
  152663. break;
  152664. case JPEG_REACHED_EOI: /* Found EOI */
  152665. inputctl->pub.eoi_reached = TRUE;
  152666. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152667. if (cinfo->marker->saw_SOF)
  152668. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152669. } else {
  152670. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152671. cinfo->output_scan_number = cinfo->input_scan_number;
  152672. }
  152673. break;
  152674. case JPEG_SUSPENDED:
  152675. break;
  152676. }
  152677. return val;
  152678. }
  152679. METHODDEF(void)
  152680. reset_input_controller (j_decompress_ptr cinfo)
  152681. {
  152682. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152683. inputctl->pub.consume_input = consume_markers;
  152684. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152685. inputctl->pub.eoi_reached = FALSE;
  152686. inputctl->inheaders = TRUE;
  152687. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152688. (*cinfo->marker->reset_marker_reader) (cinfo);
  152689. cinfo->coef_bits = NULL;
  152690. }
  152691. GLOBAL(void)
  152692. jinit_input_controller (j_decompress_ptr cinfo)
  152693. {
  152694. my_inputctl_ptr inputctl;
  152695. inputctl = (my_inputctl_ptr)
  152696. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152697. SIZEOF(my_input_controller));
  152698. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152699. inputctl->pub.consume_input = consume_markers;
  152700. inputctl->pub.reset_input_controller = reset_input_controller;
  152701. inputctl->pub.start_input_pass = start_input_pass2;
  152702. inputctl->pub.finish_input_pass = finish_input_pass;
  152703. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152704. inputctl->pub.eoi_reached = FALSE;
  152705. inputctl->inheaders = TRUE;
  152706. }
  152707. /*** End of inlined file: jdinput.c ***/
  152708. /*** Start of inlined file: jdmainct.c ***/
  152709. #define JPEG_INTERNALS
  152710. typedef struct {
  152711. struct jpeg_d_main_controller pub; /* public fields */
  152712. JSAMPARRAY buffer[MAX_COMPONENTS];
  152713. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152714. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152715. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152716. int whichptr; /* indicates which pointer set is now in use */
  152717. int context_state; /* process_data state machine status */
  152718. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152719. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152720. } my_main_controller4;
  152721. typedef my_main_controller4 * my_main_ptr4;
  152722. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152723. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152724. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152725. METHODDEF(void) process_data_simple_main2
  152726. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152727. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152728. METHODDEF(void) process_data_context_main
  152729. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152730. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152731. #ifdef QUANT_2PASS_SUPPORTED
  152732. METHODDEF(void) process_data_crank_post
  152733. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152734. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152735. #endif
  152736. LOCAL(void)
  152737. alloc_funny_pointers (j_decompress_ptr cinfo)
  152738. {
  152739. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152740. int ci, rgroup;
  152741. int M = cinfo->min_DCT_scaled_size;
  152742. jpeg_component_info *compptr;
  152743. JSAMPARRAY xbuf;
  152744. main_->xbuffer[0] = (JSAMPIMAGE)
  152745. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152746. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152747. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152748. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152749. ci++, compptr++) {
  152750. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152751. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152752. xbuf = (JSAMPARRAY)
  152753. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152754. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152755. xbuf += rgroup; /* want one row group at negative offsets */
  152756. main_->xbuffer[0][ci] = xbuf;
  152757. xbuf += rgroup * (M + 4);
  152758. main_->xbuffer[1][ci] = xbuf;
  152759. }
  152760. }
  152761. LOCAL(void)
  152762. make_funny_pointers (j_decompress_ptr cinfo)
  152763. {
  152764. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152765. int ci, i, rgroup;
  152766. int M = cinfo->min_DCT_scaled_size;
  152767. jpeg_component_info *compptr;
  152768. JSAMPARRAY buf, xbuf0, xbuf1;
  152769. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152770. ci++, compptr++) {
  152771. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152772. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152773. xbuf0 = main_->xbuffer[0][ci];
  152774. xbuf1 = main_->xbuffer[1][ci];
  152775. buf = main_->buffer[ci];
  152776. for (i = 0; i < rgroup * (M + 2); i++) {
  152777. xbuf0[i] = xbuf1[i] = buf[i];
  152778. }
  152779. for (i = 0; i < rgroup * 2; i++) {
  152780. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152781. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152782. }
  152783. for (i = 0; i < rgroup; i++) {
  152784. xbuf0[i - rgroup] = xbuf0[0];
  152785. }
  152786. }
  152787. }
  152788. LOCAL(void)
  152789. set_wraparound_pointers (j_decompress_ptr cinfo)
  152790. {
  152791. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152792. int ci, i, rgroup;
  152793. int M = cinfo->min_DCT_scaled_size;
  152794. jpeg_component_info *compptr;
  152795. JSAMPARRAY xbuf0, xbuf1;
  152796. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152797. ci++, compptr++) {
  152798. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152799. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152800. xbuf0 = main_->xbuffer[0][ci];
  152801. xbuf1 = main_->xbuffer[1][ci];
  152802. for (i = 0; i < rgroup; i++) {
  152803. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152804. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152805. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152806. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152807. }
  152808. }
  152809. }
  152810. LOCAL(void)
  152811. set_bottom_pointers (j_decompress_ptr cinfo)
  152812. {
  152813. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152814. int ci, i, rgroup, iMCUheight, rows_left;
  152815. jpeg_component_info *compptr;
  152816. JSAMPARRAY xbuf;
  152817. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152818. ci++, compptr++) {
  152819. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152820. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152821. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152822. if (rows_left == 0) rows_left = iMCUheight;
  152823. if (ci == 0) {
  152824. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152825. }
  152826. xbuf = main_->xbuffer[main_->whichptr][ci];
  152827. for (i = 0; i < rgroup * 2; i++) {
  152828. xbuf[rows_left + i] = xbuf[rows_left-1];
  152829. }
  152830. }
  152831. }
  152832. METHODDEF(void)
  152833. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152834. {
  152835. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152836. switch (pass_mode) {
  152837. case JBUF_PASS_THRU:
  152838. if (cinfo->upsample->need_context_rows) {
  152839. main_->pub.process_data = process_data_context_main;
  152840. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152841. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152842. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152843. main_->iMCU_row_ctr = 0;
  152844. } else {
  152845. main_->pub.process_data = process_data_simple_main2;
  152846. }
  152847. main_->buffer_full = FALSE; /* Mark buffer empty */
  152848. main_->rowgroup_ctr = 0;
  152849. break;
  152850. #ifdef QUANT_2PASS_SUPPORTED
  152851. case JBUF_CRANK_DEST:
  152852. main_->pub.process_data = process_data_crank_post;
  152853. break;
  152854. #endif
  152855. default:
  152856. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152857. break;
  152858. }
  152859. }
  152860. METHODDEF(void)
  152861. process_data_simple_main2 (j_decompress_ptr cinfo,
  152862. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152863. JDIMENSION out_rows_avail)
  152864. {
  152865. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152866. JDIMENSION rowgroups_avail;
  152867. if (! main_->buffer_full) {
  152868. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152869. return; /* suspension forced, can do nothing more */
  152870. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152871. }
  152872. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152873. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152874. &main_->rowgroup_ctr, rowgroups_avail,
  152875. output_buf, out_row_ctr, out_rows_avail);
  152876. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152877. main_->buffer_full = FALSE;
  152878. main_->rowgroup_ctr = 0;
  152879. }
  152880. }
  152881. METHODDEF(void)
  152882. process_data_context_main (j_decompress_ptr cinfo,
  152883. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152884. JDIMENSION out_rows_avail)
  152885. {
  152886. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152887. if (! main_->buffer_full) {
  152888. if (! (*cinfo->coef->decompress_data) (cinfo,
  152889. main_->xbuffer[main_->whichptr]))
  152890. return; /* suspension forced, can do nothing more */
  152891. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152892. main_->iMCU_row_ctr++; /* count rows received */
  152893. }
  152894. switch (main_->context_state) {
  152895. case CTX_POSTPONED_ROW:
  152896. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152897. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152898. output_buf, out_row_ctr, out_rows_avail);
  152899. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152900. return; /* Need to suspend */
  152901. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152902. if (*out_row_ctr >= out_rows_avail)
  152903. return; /* Postprocessor exactly filled output buf */
  152904. case CTX_PREPARE_FOR_IMCU:
  152905. main_->rowgroup_ctr = 0;
  152906. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152907. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152908. set_bottom_pointers(cinfo);
  152909. main_->context_state = CTX_PROCESS_IMCU;
  152910. case CTX_PROCESS_IMCU:
  152911. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152912. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152913. output_buf, out_row_ctr, out_rows_avail);
  152914. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152915. return; /* Need to suspend */
  152916. if (main_->iMCU_row_ctr == 1)
  152917. set_wraparound_pointers(cinfo);
  152918. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152919. main_->buffer_full = FALSE;
  152920. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152921. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152922. main_->context_state = CTX_POSTPONED_ROW;
  152923. }
  152924. }
  152925. #ifdef QUANT_2PASS_SUPPORTED
  152926. METHODDEF(void)
  152927. process_data_crank_post (j_decompress_ptr cinfo,
  152928. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152929. JDIMENSION out_rows_avail)
  152930. {
  152931. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152932. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152933. output_buf, out_row_ctr, out_rows_avail);
  152934. }
  152935. #endif /* QUANT_2PASS_SUPPORTED */
  152936. GLOBAL(void)
  152937. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152938. {
  152939. my_main_ptr4 main_;
  152940. int ci, rgroup, ngroups;
  152941. jpeg_component_info *compptr;
  152942. main_ = (my_main_ptr4)
  152943. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152944. SIZEOF(my_main_controller4));
  152945. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152946. main_->pub.start_pass = start_pass_main2;
  152947. if (need_full_buffer) /* shouldn't happen */
  152948. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152949. if (cinfo->upsample->need_context_rows) {
  152950. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152951. ERREXIT(cinfo, JERR_NOTIMPL);
  152952. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152953. ngroups = cinfo->min_DCT_scaled_size + 2;
  152954. } else {
  152955. ngroups = cinfo->min_DCT_scaled_size;
  152956. }
  152957. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152958. ci++, compptr++) {
  152959. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152960. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152961. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152962. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152963. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152964. (JDIMENSION) (rgroup * ngroups));
  152965. }
  152966. }
  152967. /*** End of inlined file: jdmainct.c ***/
  152968. /*** Start of inlined file: jdmarker.c ***/
  152969. #define JPEG_INTERNALS
  152970. typedef struct {
  152971. struct jpeg_marker_reader pub; /* public fields */
  152972. jpeg_marker_parser_method process_COM;
  152973. jpeg_marker_parser_method process_APPn[16];
  152974. unsigned int length_limit_COM;
  152975. unsigned int length_limit_APPn[16];
  152976. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152977. unsigned int bytes_read; /* data bytes read so far in marker */
  152978. } my_marker_reader;
  152979. typedef my_marker_reader * my_marker_ptr2;
  152980. #define INPUT_VARS(cinfo) \
  152981. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152982. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152983. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152984. #define INPUT_SYNC(cinfo) \
  152985. ( datasrc->next_input_byte = next_input_byte, \
  152986. datasrc->bytes_in_buffer = bytes_in_buffer )
  152987. #define INPUT_RELOAD(cinfo) \
  152988. ( next_input_byte = datasrc->next_input_byte, \
  152989. bytes_in_buffer = datasrc->bytes_in_buffer )
  152990. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152991. if (bytes_in_buffer == 0) { \
  152992. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152993. { action; } \
  152994. INPUT_RELOAD(cinfo); \
  152995. }
  152996. #define INPUT_BYTE(cinfo,V,action) \
  152997. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152998. bytes_in_buffer--; \
  152999. V = GETJOCTET(*next_input_byte++); )
  153000. #define INPUT_2BYTES(cinfo,V,action) \
  153001. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153002. bytes_in_buffer--; \
  153003. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  153004. MAKE_BYTE_AVAIL(cinfo,action); \
  153005. bytes_in_buffer--; \
  153006. V += GETJOCTET(*next_input_byte++); )
  153007. LOCAL(boolean)
  153008. get_soi (j_decompress_ptr cinfo)
  153009. {
  153010. int i;
  153011. TRACEMS(cinfo, 1, JTRC_SOI);
  153012. if (cinfo->marker->saw_SOI)
  153013. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  153014. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  153015. cinfo->arith_dc_L[i] = 0;
  153016. cinfo->arith_dc_U[i] = 1;
  153017. cinfo->arith_ac_K[i] = 5;
  153018. }
  153019. cinfo->restart_interval = 0;
  153020. cinfo->jpeg_color_space = JCS_UNKNOWN;
  153021. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  153022. cinfo->saw_JFIF_marker = FALSE;
  153023. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  153024. cinfo->JFIF_minor_version = 1;
  153025. cinfo->density_unit = 0;
  153026. cinfo->X_density = 1;
  153027. cinfo->Y_density = 1;
  153028. cinfo->saw_Adobe_marker = FALSE;
  153029. cinfo->Adobe_transform = 0;
  153030. cinfo->marker->saw_SOI = TRUE;
  153031. return TRUE;
  153032. }
  153033. LOCAL(boolean)
  153034. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  153035. {
  153036. INT32 length;
  153037. int c, ci;
  153038. jpeg_component_info * compptr;
  153039. INPUT_VARS(cinfo);
  153040. cinfo->progressive_mode = is_prog;
  153041. cinfo->arith_code = is_arith;
  153042. INPUT_2BYTES(cinfo, length, return FALSE);
  153043. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  153044. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  153045. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  153046. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  153047. length -= 8;
  153048. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  153049. (int) cinfo->image_width, (int) cinfo->image_height,
  153050. cinfo->num_components);
  153051. if (cinfo->marker->saw_SOF)
  153052. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  153053. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  153054. || cinfo->num_components <= 0)
  153055. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  153056. if (length != (cinfo->num_components * 3))
  153057. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153058. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  153059. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  153060. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153061. cinfo->num_components * SIZEOF(jpeg_component_info));
  153062. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153063. ci++, compptr++) {
  153064. compptr->component_index = ci;
  153065. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  153066. INPUT_BYTE(cinfo, c, return FALSE);
  153067. compptr->h_samp_factor = (c >> 4) & 15;
  153068. compptr->v_samp_factor = (c ) & 15;
  153069. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  153070. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  153071. compptr->component_id, compptr->h_samp_factor,
  153072. compptr->v_samp_factor, compptr->quant_tbl_no);
  153073. }
  153074. cinfo->marker->saw_SOF = TRUE;
  153075. INPUT_SYNC(cinfo);
  153076. return TRUE;
  153077. }
  153078. LOCAL(boolean)
  153079. get_sos (j_decompress_ptr cinfo)
  153080. {
  153081. INT32 length;
  153082. int i, ci, n, c, cc;
  153083. jpeg_component_info * compptr;
  153084. INPUT_VARS(cinfo);
  153085. if (! cinfo->marker->saw_SOF)
  153086. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  153087. INPUT_2BYTES(cinfo, length, return FALSE);
  153088. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  153089. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  153090. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  153091. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153092. cinfo->comps_in_scan = n;
  153093. for (i = 0; i < n; i++) {
  153094. INPUT_BYTE(cinfo, cc, return FALSE);
  153095. INPUT_BYTE(cinfo, c, return FALSE);
  153096. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153097. ci++, compptr++) {
  153098. if (cc == compptr->component_id)
  153099. goto id_found;
  153100. }
  153101. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  153102. id_found:
  153103. cinfo->cur_comp_info[i] = compptr;
  153104. compptr->dc_tbl_no = (c >> 4) & 15;
  153105. compptr->ac_tbl_no = (c ) & 15;
  153106. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  153107. compptr->dc_tbl_no, compptr->ac_tbl_no);
  153108. }
  153109. INPUT_BYTE(cinfo, c, return FALSE);
  153110. cinfo->Ss = c;
  153111. INPUT_BYTE(cinfo, c, return FALSE);
  153112. cinfo->Se = c;
  153113. INPUT_BYTE(cinfo, c, return FALSE);
  153114. cinfo->Ah = (c >> 4) & 15;
  153115. cinfo->Al = (c ) & 15;
  153116. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  153117. cinfo->Ah, cinfo->Al);
  153118. cinfo->marker->next_restart_num = 0;
  153119. cinfo->input_scan_number++;
  153120. INPUT_SYNC(cinfo);
  153121. return TRUE;
  153122. }
  153123. #ifdef D_ARITH_CODING_SUPPORTED
  153124. LOCAL(boolean)
  153125. get_dac (j_decompress_ptr cinfo)
  153126. {
  153127. INT32 length;
  153128. int index, val;
  153129. INPUT_VARS(cinfo);
  153130. INPUT_2BYTES(cinfo, length, return FALSE);
  153131. length -= 2;
  153132. while (length > 0) {
  153133. INPUT_BYTE(cinfo, index, return FALSE);
  153134. INPUT_BYTE(cinfo, val, return FALSE);
  153135. length -= 2;
  153136. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  153137. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  153138. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  153139. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  153140. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  153141. } else { /* define DC table */
  153142. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  153143. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  153144. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  153145. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  153146. }
  153147. }
  153148. if (length != 0)
  153149. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153150. INPUT_SYNC(cinfo);
  153151. return TRUE;
  153152. }
  153153. #else /* ! D_ARITH_CODING_SUPPORTED */
  153154. #define get_dac(cinfo) skip_variable(cinfo)
  153155. #endif /* D_ARITH_CODING_SUPPORTED */
  153156. LOCAL(boolean)
  153157. get_dht (j_decompress_ptr cinfo)
  153158. {
  153159. INT32 length;
  153160. UINT8 bits[17];
  153161. UINT8 huffval[256];
  153162. int i, index, count;
  153163. JHUFF_TBL **htblptr;
  153164. INPUT_VARS(cinfo);
  153165. INPUT_2BYTES(cinfo, length, return FALSE);
  153166. length -= 2;
  153167. while (length > 16) {
  153168. INPUT_BYTE(cinfo, index, return FALSE);
  153169. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  153170. bits[0] = 0;
  153171. count = 0;
  153172. for (i = 1; i <= 16; i++) {
  153173. INPUT_BYTE(cinfo, bits[i], return FALSE);
  153174. count += bits[i];
  153175. }
  153176. length -= 1 + 16;
  153177. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153178. bits[1], bits[2], bits[3], bits[4],
  153179. bits[5], bits[6], bits[7], bits[8]);
  153180. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153181. bits[9], bits[10], bits[11], bits[12],
  153182. bits[13], bits[14], bits[15], bits[16]);
  153183. if (count > 256 || ((INT32) count) > length)
  153184. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  153185. for (i = 0; i < count; i++)
  153186. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  153187. length -= count;
  153188. if (index & 0x10) { /* AC table definition */
  153189. index -= 0x10;
  153190. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  153191. } else { /* DC table definition */
  153192. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  153193. }
  153194. if (index < 0 || index >= NUM_HUFF_TBLS)
  153195. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  153196. if (*htblptr == NULL)
  153197. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  153198. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  153199. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  153200. }
  153201. if (length != 0)
  153202. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153203. INPUT_SYNC(cinfo);
  153204. return TRUE;
  153205. }
  153206. LOCAL(boolean)
  153207. get_dqt (j_decompress_ptr cinfo)
  153208. {
  153209. INT32 length;
  153210. int n, i, prec;
  153211. unsigned int tmp;
  153212. JQUANT_TBL *quant_ptr;
  153213. INPUT_VARS(cinfo);
  153214. INPUT_2BYTES(cinfo, length, return FALSE);
  153215. length -= 2;
  153216. while (length > 0) {
  153217. INPUT_BYTE(cinfo, n, return FALSE);
  153218. prec = n >> 4;
  153219. n &= 0x0F;
  153220. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  153221. if (n >= NUM_QUANT_TBLS)
  153222. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  153223. if (cinfo->quant_tbl_ptrs[n] == NULL)
  153224. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  153225. quant_ptr = cinfo->quant_tbl_ptrs[n];
  153226. for (i = 0; i < DCTSIZE2; i++) {
  153227. if (prec)
  153228. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153229. else
  153230. INPUT_BYTE(cinfo, tmp, return FALSE);
  153231. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  153232. }
  153233. if (cinfo->err->trace_level >= 2) {
  153234. for (i = 0; i < DCTSIZE2; i += 8) {
  153235. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  153236. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  153237. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  153238. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  153239. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  153240. }
  153241. }
  153242. length -= DCTSIZE2+1;
  153243. if (prec) length -= DCTSIZE2;
  153244. }
  153245. if (length != 0)
  153246. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153247. INPUT_SYNC(cinfo);
  153248. return TRUE;
  153249. }
  153250. LOCAL(boolean)
  153251. get_dri (j_decompress_ptr cinfo)
  153252. {
  153253. INT32 length;
  153254. unsigned int tmp;
  153255. INPUT_VARS(cinfo);
  153256. INPUT_2BYTES(cinfo, length, return FALSE);
  153257. if (length != 4)
  153258. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153259. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153260. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  153261. cinfo->restart_interval = tmp;
  153262. INPUT_SYNC(cinfo);
  153263. return TRUE;
  153264. }
  153265. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  153266. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  153267. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  153268. LOCAL(void)
  153269. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153270. unsigned int datalen, INT32 remaining)
  153271. {
  153272. INT32 totallen = (INT32) datalen + remaining;
  153273. if (datalen >= APP0_DATA_LEN &&
  153274. GETJOCTET(data[0]) == 0x4A &&
  153275. GETJOCTET(data[1]) == 0x46 &&
  153276. GETJOCTET(data[2]) == 0x49 &&
  153277. GETJOCTET(data[3]) == 0x46 &&
  153278. GETJOCTET(data[4]) == 0) {
  153279. cinfo->saw_JFIF_marker = TRUE;
  153280. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  153281. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  153282. cinfo->density_unit = GETJOCTET(data[7]);
  153283. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  153284. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  153285. if (cinfo->JFIF_major_version != 1)
  153286. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153287. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153288. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153289. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153290. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153291. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153292. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153293. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153294. totallen -= APP0_DATA_LEN;
  153295. if (totallen !=
  153296. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153297. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153298. } else if (datalen >= 6 &&
  153299. GETJOCTET(data[0]) == 0x4A &&
  153300. GETJOCTET(data[1]) == 0x46 &&
  153301. GETJOCTET(data[2]) == 0x58 &&
  153302. GETJOCTET(data[3]) == 0x58 &&
  153303. GETJOCTET(data[4]) == 0) {
  153304. switch (GETJOCTET(data[5])) {
  153305. case 0x10:
  153306. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153307. break;
  153308. case 0x11:
  153309. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153310. break;
  153311. case 0x13:
  153312. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153313. break;
  153314. default:
  153315. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153316. GETJOCTET(data[5]), (int) totallen);
  153317. break;
  153318. }
  153319. } else {
  153320. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153321. }
  153322. }
  153323. LOCAL(void)
  153324. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153325. unsigned int datalen, INT32 remaining)
  153326. {
  153327. unsigned int version, flags0, flags1, transform;
  153328. if (datalen >= APP14_DATA_LEN &&
  153329. GETJOCTET(data[0]) == 0x41 &&
  153330. GETJOCTET(data[1]) == 0x64 &&
  153331. GETJOCTET(data[2]) == 0x6F &&
  153332. GETJOCTET(data[3]) == 0x62 &&
  153333. GETJOCTET(data[4]) == 0x65) {
  153334. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153335. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153336. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153337. transform = GETJOCTET(data[11]);
  153338. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153339. cinfo->saw_Adobe_marker = TRUE;
  153340. cinfo->Adobe_transform = (UINT8) transform;
  153341. } else {
  153342. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153343. }
  153344. }
  153345. METHODDEF(boolean)
  153346. get_interesting_appn (j_decompress_ptr cinfo)
  153347. {
  153348. INT32 length;
  153349. JOCTET b[APPN_DATA_LEN];
  153350. unsigned int i, numtoread;
  153351. INPUT_VARS(cinfo);
  153352. INPUT_2BYTES(cinfo, length, return FALSE);
  153353. length -= 2;
  153354. if (length >= APPN_DATA_LEN)
  153355. numtoread = APPN_DATA_LEN;
  153356. else if (length > 0)
  153357. numtoread = (unsigned int) length;
  153358. else
  153359. numtoread = 0;
  153360. for (i = 0; i < numtoread; i++)
  153361. INPUT_BYTE(cinfo, b[i], return FALSE);
  153362. length -= numtoread;
  153363. switch (cinfo->unread_marker) {
  153364. case M_APP0:
  153365. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153366. break;
  153367. case M_APP14:
  153368. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153369. break;
  153370. default:
  153371. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153372. break;
  153373. }
  153374. INPUT_SYNC(cinfo);
  153375. if (length > 0)
  153376. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153377. return TRUE;
  153378. }
  153379. #ifdef SAVE_MARKERS_SUPPORTED
  153380. METHODDEF(boolean)
  153381. save_marker (j_decompress_ptr cinfo)
  153382. {
  153383. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153384. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153385. unsigned int bytes_read, data_length;
  153386. JOCTET FAR * data;
  153387. INT32 length = 0;
  153388. INPUT_VARS(cinfo);
  153389. if (cur_marker == NULL) {
  153390. INPUT_2BYTES(cinfo, length, return FALSE);
  153391. length -= 2;
  153392. if (length >= 0) { /* watch out for bogus length word */
  153393. unsigned int limit;
  153394. if (cinfo->unread_marker == (int) M_COM)
  153395. limit = marker->length_limit_COM;
  153396. else
  153397. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153398. if ((unsigned int) length < limit)
  153399. limit = (unsigned int) length;
  153400. cur_marker = (jpeg_saved_marker_ptr)
  153401. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153402. SIZEOF(struct jpeg_marker_struct) + limit);
  153403. cur_marker->next = NULL;
  153404. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153405. cur_marker->original_length = (unsigned int) length;
  153406. cur_marker->data_length = limit;
  153407. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153408. marker->cur_marker = cur_marker;
  153409. marker->bytes_read = 0;
  153410. bytes_read = 0;
  153411. data_length = limit;
  153412. } else {
  153413. bytes_read = data_length = 0;
  153414. data = NULL;
  153415. }
  153416. } else {
  153417. bytes_read = marker->bytes_read;
  153418. data_length = cur_marker->data_length;
  153419. data = cur_marker->data + bytes_read;
  153420. }
  153421. while (bytes_read < data_length) {
  153422. INPUT_SYNC(cinfo); /* move the restart point to here */
  153423. marker->bytes_read = bytes_read;
  153424. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153425. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153426. *data++ = *next_input_byte++;
  153427. bytes_in_buffer--;
  153428. bytes_read++;
  153429. }
  153430. }
  153431. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153432. if (cinfo->marker_list == NULL) {
  153433. cinfo->marker_list = cur_marker;
  153434. } else {
  153435. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153436. while (prev->next != NULL)
  153437. prev = prev->next;
  153438. prev->next = cur_marker;
  153439. }
  153440. data = cur_marker->data;
  153441. length = cur_marker->original_length - data_length;
  153442. }
  153443. marker->cur_marker = NULL;
  153444. switch (cinfo->unread_marker) {
  153445. case M_APP0:
  153446. examine_app0(cinfo, data, data_length, length);
  153447. break;
  153448. case M_APP14:
  153449. examine_app14(cinfo, data, data_length, length);
  153450. break;
  153451. default:
  153452. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153453. (int) (data_length + length));
  153454. break;
  153455. }
  153456. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153457. if (length > 0)
  153458. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153459. return TRUE;
  153460. }
  153461. #endif /* SAVE_MARKERS_SUPPORTED */
  153462. METHODDEF(boolean)
  153463. skip_variable (j_decompress_ptr cinfo)
  153464. {
  153465. INT32 length;
  153466. INPUT_VARS(cinfo);
  153467. INPUT_2BYTES(cinfo, length, return FALSE);
  153468. length -= 2;
  153469. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153470. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153471. if (length > 0)
  153472. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153473. return TRUE;
  153474. }
  153475. LOCAL(boolean)
  153476. next_marker (j_decompress_ptr cinfo)
  153477. {
  153478. int c;
  153479. INPUT_VARS(cinfo);
  153480. for (;;) {
  153481. INPUT_BYTE(cinfo, c, return FALSE);
  153482. while (c != 0xFF) {
  153483. cinfo->marker->discarded_bytes++;
  153484. INPUT_SYNC(cinfo);
  153485. INPUT_BYTE(cinfo, c, return FALSE);
  153486. }
  153487. do {
  153488. INPUT_BYTE(cinfo, c, return FALSE);
  153489. } while (c == 0xFF);
  153490. if (c != 0)
  153491. break; /* found a valid marker, exit loop */
  153492. cinfo->marker->discarded_bytes += 2;
  153493. INPUT_SYNC(cinfo);
  153494. }
  153495. if (cinfo->marker->discarded_bytes != 0) {
  153496. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153497. cinfo->marker->discarded_bytes = 0;
  153498. }
  153499. cinfo->unread_marker = c;
  153500. INPUT_SYNC(cinfo);
  153501. return TRUE;
  153502. }
  153503. LOCAL(boolean)
  153504. first_marker (j_decompress_ptr cinfo)
  153505. {
  153506. int c, c2;
  153507. INPUT_VARS(cinfo);
  153508. INPUT_BYTE(cinfo, c, return FALSE);
  153509. INPUT_BYTE(cinfo, c2, return FALSE);
  153510. if (c != 0xFF || c2 != (int) M_SOI)
  153511. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153512. cinfo->unread_marker = c2;
  153513. INPUT_SYNC(cinfo);
  153514. return TRUE;
  153515. }
  153516. METHODDEF(int)
  153517. read_markers (j_decompress_ptr cinfo)
  153518. {
  153519. for (;;) {
  153520. if (cinfo->unread_marker == 0) {
  153521. if (! cinfo->marker->saw_SOI) {
  153522. if (! first_marker(cinfo))
  153523. return JPEG_SUSPENDED;
  153524. } else {
  153525. if (! next_marker(cinfo))
  153526. return JPEG_SUSPENDED;
  153527. }
  153528. }
  153529. switch (cinfo->unread_marker) {
  153530. case M_SOI:
  153531. if (! get_soi(cinfo))
  153532. return JPEG_SUSPENDED;
  153533. break;
  153534. case M_SOF0: /* Baseline */
  153535. case M_SOF1: /* Extended sequential, Huffman */
  153536. if (! get_sof(cinfo, FALSE, FALSE))
  153537. return JPEG_SUSPENDED;
  153538. break;
  153539. case M_SOF2: /* Progressive, Huffman */
  153540. if (! get_sof(cinfo, TRUE, FALSE))
  153541. return JPEG_SUSPENDED;
  153542. break;
  153543. case M_SOF9: /* Extended sequential, arithmetic */
  153544. if (! get_sof(cinfo, FALSE, TRUE))
  153545. return JPEG_SUSPENDED;
  153546. break;
  153547. case M_SOF10: /* Progressive, arithmetic */
  153548. if (! get_sof(cinfo, TRUE, TRUE))
  153549. return JPEG_SUSPENDED;
  153550. break;
  153551. case M_SOF3: /* Lossless, Huffman */
  153552. case M_SOF5: /* Differential sequential, Huffman */
  153553. case M_SOF6: /* Differential progressive, Huffman */
  153554. case M_SOF7: /* Differential lossless, Huffman */
  153555. case M_JPG: /* Reserved for JPEG extensions */
  153556. case M_SOF11: /* Lossless, arithmetic */
  153557. case M_SOF13: /* Differential sequential, arithmetic */
  153558. case M_SOF14: /* Differential progressive, arithmetic */
  153559. case M_SOF15: /* Differential lossless, arithmetic */
  153560. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153561. break;
  153562. case M_SOS:
  153563. if (! get_sos(cinfo))
  153564. return JPEG_SUSPENDED;
  153565. cinfo->unread_marker = 0; /* processed the marker */
  153566. return JPEG_REACHED_SOS;
  153567. case M_EOI:
  153568. TRACEMS(cinfo, 1, JTRC_EOI);
  153569. cinfo->unread_marker = 0; /* processed the marker */
  153570. return JPEG_REACHED_EOI;
  153571. case M_DAC:
  153572. if (! get_dac(cinfo))
  153573. return JPEG_SUSPENDED;
  153574. break;
  153575. case M_DHT:
  153576. if (! get_dht(cinfo))
  153577. return JPEG_SUSPENDED;
  153578. break;
  153579. case M_DQT:
  153580. if (! get_dqt(cinfo))
  153581. return JPEG_SUSPENDED;
  153582. break;
  153583. case M_DRI:
  153584. if (! get_dri(cinfo))
  153585. return JPEG_SUSPENDED;
  153586. break;
  153587. case M_APP0:
  153588. case M_APP1:
  153589. case M_APP2:
  153590. case M_APP3:
  153591. case M_APP4:
  153592. case M_APP5:
  153593. case M_APP6:
  153594. case M_APP7:
  153595. case M_APP8:
  153596. case M_APP9:
  153597. case M_APP10:
  153598. case M_APP11:
  153599. case M_APP12:
  153600. case M_APP13:
  153601. case M_APP14:
  153602. case M_APP15:
  153603. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153604. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153605. return JPEG_SUSPENDED;
  153606. break;
  153607. case M_COM:
  153608. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153609. return JPEG_SUSPENDED;
  153610. break;
  153611. case M_RST0: /* these are all parameterless */
  153612. case M_RST1:
  153613. case M_RST2:
  153614. case M_RST3:
  153615. case M_RST4:
  153616. case M_RST5:
  153617. case M_RST6:
  153618. case M_RST7:
  153619. case M_TEM:
  153620. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153621. break;
  153622. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153623. if (! skip_variable(cinfo))
  153624. return JPEG_SUSPENDED;
  153625. break;
  153626. default: /* must be DHP, EXP, JPGn, or RESn */
  153627. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153628. break;
  153629. }
  153630. cinfo->unread_marker = 0;
  153631. } /* end loop */
  153632. }
  153633. METHODDEF(boolean)
  153634. read_restart_marker (j_decompress_ptr cinfo)
  153635. {
  153636. if (cinfo->unread_marker == 0) {
  153637. if (! next_marker(cinfo))
  153638. return FALSE;
  153639. }
  153640. if (cinfo->unread_marker ==
  153641. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153642. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153643. cinfo->unread_marker = 0;
  153644. } else {
  153645. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153646. cinfo->marker->next_restart_num))
  153647. return FALSE;
  153648. }
  153649. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153650. return TRUE;
  153651. }
  153652. GLOBAL(boolean)
  153653. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153654. {
  153655. int marker = cinfo->unread_marker;
  153656. int action = 1;
  153657. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153658. for (;;) {
  153659. if (marker < (int) M_SOF0)
  153660. action = 2; /* invalid marker */
  153661. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153662. action = 3; /* valid non-restart marker */
  153663. else {
  153664. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153665. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153666. action = 3; /* one of the next two expected restarts */
  153667. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153668. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153669. action = 2; /* a prior restart, so advance */
  153670. else
  153671. action = 1; /* desired restart or too far away */
  153672. }
  153673. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153674. switch (action) {
  153675. case 1:
  153676. cinfo->unread_marker = 0;
  153677. return TRUE;
  153678. case 2:
  153679. if (! next_marker(cinfo))
  153680. return FALSE;
  153681. marker = cinfo->unread_marker;
  153682. break;
  153683. case 3:
  153684. return TRUE;
  153685. }
  153686. } /* end loop */
  153687. }
  153688. METHODDEF(void)
  153689. reset_marker_reader (j_decompress_ptr cinfo)
  153690. {
  153691. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153692. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153693. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153694. cinfo->unread_marker = 0; /* no pending marker */
  153695. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153696. marker->pub.saw_SOF = FALSE;
  153697. marker->pub.discarded_bytes = 0;
  153698. marker->cur_marker = NULL;
  153699. }
  153700. GLOBAL(void)
  153701. jinit_marker_reader (j_decompress_ptr cinfo)
  153702. {
  153703. my_marker_ptr2 marker;
  153704. int i;
  153705. marker = (my_marker_ptr2)
  153706. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153707. SIZEOF(my_marker_reader));
  153708. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153709. marker->pub.reset_marker_reader = reset_marker_reader;
  153710. marker->pub.read_markers = read_markers;
  153711. marker->pub.read_restart_marker = read_restart_marker;
  153712. marker->process_COM = skip_variable;
  153713. marker->length_limit_COM = 0;
  153714. for (i = 0; i < 16; i++) {
  153715. marker->process_APPn[i] = skip_variable;
  153716. marker->length_limit_APPn[i] = 0;
  153717. }
  153718. marker->process_APPn[0] = get_interesting_appn;
  153719. marker->process_APPn[14] = get_interesting_appn;
  153720. reset_marker_reader(cinfo);
  153721. }
  153722. #ifdef SAVE_MARKERS_SUPPORTED
  153723. GLOBAL(void)
  153724. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153725. unsigned int length_limit)
  153726. {
  153727. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153728. long maxlength;
  153729. jpeg_marker_parser_method processor;
  153730. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153731. if (((long) length_limit) > maxlength)
  153732. length_limit = (unsigned int) maxlength;
  153733. if (length_limit) {
  153734. processor = save_marker;
  153735. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153736. length_limit = APP0_DATA_LEN;
  153737. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153738. length_limit = APP14_DATA_LEN;
  153739. } else {
  153740. processor = skip_variable;
  153741. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153742. processor = get_interesting_appn;
  153743. }
  153744. if (marker_code == (int) M_COM) {
  153745. marker->process_COM = processor;
  153746. marker->length_limit_COM = length_limit;
  153747. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153748. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153749. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153750. } else
  153751. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153752. }
  153753. #endif /* SAVE_MARKERS_SUPPORTED */
  153754. GLOBAL(void)
  153755. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153756. jpeg_marker_parser_method routine)
  153757. {
  153758. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153759. if (marker_code == (int) M_COM)
  153760. marker->process_COM = routine;
  153761. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153762. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153763. else
  153764. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153765. }
  153766. /*** End of inlined file: jdmarker.c ***/
  153767. /*** Start of inlined file: jdmaster.c ***/
  153768. #define JPEG_INTERNALS
  153769. typedef struct {
  153770. struct jpeg_decomp_master pub; /* public fields */
  153771. int pass_number; /* # of passes completed */
  153772. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153773. struct jpeg_color_quantizer * quantizer_1pass;
  153774. struct jpeg_color_quantizer * quantizer_2pass;
  153775. } my_decomp_master;
  153776. typedef my_decomp_master * my_master_ptr6;
  153777. LOCAL(boolean)
  153778. use_merged_upsample (j_decompress_ptr cinfo)
  153779. {
  153780. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153781. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153782. return FALSE;
  153783. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153784. cinfo->out_color_space != JCS_RGB ||
  153785. cinfo->out_color_components != RGB_PIXELSIZE)
  153786. return FALSE;
  153787. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153788. cinfo->comp_info[1].h_samp_factor != 1 ||
  153789. cinfo->comp_info[2].h_samp_factor != 1 ||
  153790. cinfo->comp_info[0].v_samp_factor > 2 ||
  153791. cinfo->comp_info[1].v_samp_factor != 1 ||
  153792. cinfo->comp_info[2].v_samp_factor != 1)
  153793. return FALSE;
  153794. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153795. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153796. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153797. return FALSE;
  153798. return TRUE; /* by golly, it'll work... */
  153799. #else
  153800. return FALSE;
  153801. #endif
  153802. }
  153803. GLOBAL(void)
  153804. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153805. {
  153806. #ifdef IDCT_SCALING_SUPPORTED
  153807. int ci;
  153808. jpeg_component_info *compptr;
  153809. #endif
  153810. if (cinfo->global_state != DSTATE_READY)
  153811. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153812. #ifdef IDCT_SCALING_SUPPORTED
  153813. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153814. cinfo->output_width = (JDIMENSION)
  153815. jdiv_round_up((long) cinfo->image_width, 8L);
  153816. cinfo->output_height = (JDIMENSION)
  153817. jdiv_round_up((long) cinfo->image_height, 8L);
  153818. cinfo->min_DCT_scaled_size = 1;
  153819. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153820. cinfo->output_width = (JDIMENSION)
  153821. jdiv_round_up((long) cinfo->image_width, 4L);
  153822. cinfo->output_height = (JDIMENSION)
  153823. jdiv_round_up((long) cinfo->image_height, 4L);
  153824. cinfo->min_DCT_scaled_size = 2;
  153825. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153826. cinfo->output_width = (JDIMENSION)
  153827. jdiv_round_up((long) cinfo->image_width, 2L);
  153828. cinfo->output_height = (JDIMENSION)
  153829. jdiv_round_up((long) cinfo->image_height, 2L);
  153830. cinfo->min_DCT_scaled_size = 4;
  153831. } else {
  153832. cinfo->output_width = cinfo->image_width;
  153833. cinfo->output_height = cinfo->image_height;
  153834. cinfo->min_DCT_scaled_size = DCTSIZE;
  153835. }
  153836. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153837. ci++, compptr++) {
  153838. int ssize = cinfo->min_DCT_scaled_size;
  153839. while (ssize < DCTSIZE &&
  153840. (compptr->h_samp_factor * ssize * 2 <=
  153841. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153842. (compptr->v_samp_factor * ssize * 2 <=
  153843. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153844. ssize = ssize * 2;
  153845. }
  153846. compptr->DCT_scaled_size = ssize;
  153847. }
  153848. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153849. ci++, compptr++) {
  153850. compptr->downsampled_width = (JDIMENSION)
  153851. jdiv_round_up((long) cinfo->image_width *
  153852. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153853. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153854. compptr->downsampled_height = (JDIMENSION)
  153855. jdiv_round_up((long) cinfo->image_height *
  153856. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153857. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153858. }
  153859. #else /* !IDCT_SCALING_SUPPORTED */
  153860. cinfo->output_width = cinfo->image_width;
  153861. cinfo->output_height = cinfo->image_height;
  153862. #endif /* IDCT_SCALING_SUPPORTED */
  153863. switch (cinfo->out_color_space) {
  153864. case JCS_GRAYSCALE:
  153865. cinfo->out_color_components = 1;
  153866. break;
  153867. case JCS_RGB:
  153868. #if RGB_PIXELSIZE != 3
  153869. cinfo->out_color_components = RGB_PIXELSIZE;
  153870. break;
  153871. #endif /* else share code with YCbCr */
  153872. case JCS_YCbCr:
  153873. cinfo->out_color_components = 3;
  153874. break;
  153875. case JCS_CMYK:
  153876. case JCS_YCCK:
  153877. cinfo->out_color_components = 4;
  153878. break;
  153879. default: /* else must be same colorspace as in file */
  153880. cinfo->out_color_components = cinfo->num_components;
  153881. break;
  153882. }
  153883. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153884. cinfo->out_color_components);
  153885. if (use_merged_upsample(cinfo))
  153886. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153887. else
  153888. cinfo->rec_outbuf_height = 1;
  153889. }
  153890. LOCAL(void)
  153891. prepare_range_limit_table (j_decompress_ptr cinfo)
  153892. {
  153893. JSAMPLE * table;
  153894. int i;
  153895. table = (JSAMPLE *)
  153896. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153897. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153898. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153899. cinfo->sample_range_limit = table;
  153900. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153901. for (i = 0; i <= MAXJSAMPLE; i++)
  153902. table[i] = (JSAMPLE) i;
  153903. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153904. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153905. table[i] = MAXJSAMPLE;
  153906. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153907. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153908. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153909. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153910. }
  153911. LOCAL(void)
  153912. master_selection (j_decompress_ptr cinfo)
  153913. {
  153914. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153915. boolean use_c_buffer;
  153916. long samplesperrow;
  153917. JDIMENSION jd_samplesperrow;
  153918. jpeg_calc_output_dimensions(cinfo);
  153919. prepare_range_limit_table(cinfo);
  153920. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153921. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153922. if ((long) jd_samplesperrow != samplesperrow)
  153923. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153924. master->pass_number = 0;
  153925. master->using_merged_upsample = use_merged_upsample(cinfo);
  153926. master->quantizer_1pass = NULL;
  153927. master->quantizer_2pass = NULL;
  153928. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153929. cinfo->enable_1pass_quant = FALSE;
  153930. cinfo->enable_external_quant = FALSE;
  153931. cinfo->enable_2pass_quant = FALSE;
  153932. }
  153933. if (cinfo->quantize_colors) {
  153934. if (cinfo->raw_data_out)
  153935. ERREXIT(cinfo, JERR_NOTIMPL);
  153936. if (cinfo->out_color_components != 3) {
  153937. cinfo->enable_1pass_quant = TRUE;
  153938. cinfo->enable_external_quant = FALSE;
  153939. cinfo->enable_2pass_quant = FALSE;
  153940. cinfo->colormap = NULL;
  153941. } else if (cinfo->colormap != NULL) {
  153942. cinfo->enable_external_quant = TRUE;
  153943. } else if (cinfo->two_pass_quantize) {
  153944. cinfo->enable_2pass_quant = TRUE;
  153945. } else {
  153946. cinfo->enable_1pass_quant = TRUE;
  153947. }
  153948. if (cinfo->enable_1pass_quant) {
  153949. #ifdef QUANT_1PASS_SUPPORTED
  153950. jinit_1pass_quantizer(cinfo);
  153951. master->quantizer_1pass = cinfo->cquantize;
  153952. #else
  153953. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153954. #endif
  153955. }
  153956. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153957. #ifdef QUANT_2PASS_SUPPORTED
  153958. jinit_2pass_quantizer(cinfo);
  153959. master->quantizer_2pass = cinfo->cquantize;
  153960. #else
  153961. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153962. #endif
  153963. }
  153964. }
  153965. if (! cinfo->raw_data_out) {
  153966. if (master->using_merged_upsample) {
  153967. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153968. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153969. #else
  153970. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153971. #endif
  153972. } else {
  153973. jinit_color_deconverter(cinfo);
  153974. jinit_upsampler(cinfo);
  153975. }
  153976. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153977. }
  153978. jinit_inverse_dct(cinfo);
  153979. if (cinfo->arith_code) {
  153980. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153981. } else {
  153982. if (cinfo->progressive_mode) {
  153983. #ifdef D_PROGRESSIVE_SUPPORTED
  153984. jinit_phuff_decoder(cinfo);
  153985. #else
  153986. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153987. #endif
  153988. } else
  153989. jinit_huff_decoder(cinfo);
  153990. }
  153991. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153992. jinit_d_coef_controller(cinfo, use_c_buffer);
  153993. if (! cinfo->raw_data_out)
  153994. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153995. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153996. (*cinfo->inputctl->start_input_pass) (cinfo);
  153997. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153998. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153999. cinfo->inputctl->has_multiple_scans) {
  154000. int nscans;
  154001. if (cinfo->progressive_mode) {
  154002. nscans = 2 + 3 * cinfo->num_components;
  154003. } else {
  154004. nscans = cinfo->num_components;
  154005. }
  154006. cinfo->progress->pass_counter = 0L;
  154007. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154008. cinfo->progress->completed_passes = 0;
  154009. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  154010. master->pass_number++;
  154011. }
  154012. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154013. }
  154014. METHODDEF(void)
  154015. prepare_for_output_pass (j_decompress_ptr cinfo)
  154016. {
  154017. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154018. if (master->pub.is_dummy_pass) {
  154019. #ifdef QUANT_2PASS_SUPPORTED
  154020. master->pub.is_dummy_pass = FALSE;
  154021. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  154022. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  154023. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  154024. #else
  154025. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154026. #endif /* QUANT_2PASS_SUPPORTED */
  154027. } else {
  154028. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  154029. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  154030. cinfo->cquantize = master->quantizer_2pass;
  154031. master->pub.is_dummy_pass = TRUE;
  154032. } else if (cinfo->enable_1pass_quant) {
  154033. cinfo->cquantize = master->quantizer_1pass;
  154034. } else {
  154035. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154036. }
  154037. }
  154038. (*cinfo->idct->start_pass) (cinfo);
  154039. (*cinfo->coef->start_output_pass) (cinfo);
  154040. if (! cinfo->raw_data_out) {
  154041. if (! master->using_merged_upsample)
  154042. (*cinfo->cconvert->start_pass) (cinfo);
  154043. (*cinfo->upsample->start_pass) (cinfo);
  154044. if (cinfo->quantize_colors)
  154045. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  154046. (*cinfo->post->start_pass) (cinfo,
  154047. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  154048. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  154049. }
  154050. }
  154051. if (cinfo->progress != NULL) {
  154052. cinfo->progress->completed_passes = master->pass_number;
  154053. cinfo->progress->total_passes = master->pass_number +
  154054. (master->pub.is_dummy_pass ? 2 : 1);
  154055. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  154056. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  154057. }
  154058. }
  154059. }
  154060. METHODDEF(void)
  154061. finish_output_pass (j_decompress_ptr cinfo)
  154062. {
  154063. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154064. if (cinfo->quantize_colors)
  154065. (*cinfo->cquantize->finish_pass) (cinfo);
  154066. master->pass_number++;
  154067. }
  154068. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154069. GLOBAL(void)
  154070. jpeg_new_colormap (j_decompress_ptr cinfo)
  154071. {
  154072. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154073. if (cinfo->global_state != DSTATE_BUFIMAGE)
  154074. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154075. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  154076. cinfo->colormap != NULL) {
  154077. cinfo->cquantize = master->quantizer_2pass;
  154078. (*cinfo->cquantize->new_color_map) (cinfo);
  154079. master->pub.is_dummy_pass = FALSE; /* just in case */
  154080. } else
  154081. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154082. }
  154083. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154084. GLOBAL(void)
  154085. jinit_master_decompress (j_decompress_ptr cinfo)
  154086. {
  154087. my_master_ptr6 master;
  154088. master = (my_master_ptr6)
  154089. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154090. SIZEOF(my_decomp_master));
  154091. cinfo->master = (struct jpeg_decomp_master *) master;
  154092. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  154093. master->pub.finish_output_pass = finish_output_pass;
  154094. master->pub.is_dummy_pass = FALSE;
  154095. master_selection(cinfo);
  154096. }
  154097. /*** End of inlined file: jdmaster.c ***/
  154098. #undef FIX
  154099. /*** Start of inlined file: jdmerge.c ***/
  154100. #define JPEG_INTERNALS
  154101. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154102. typedef struct {
  154103. struct jpeg_upsampler pub; /* public fields */
  154104. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  154105. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154106. JSAMPARRAY output_buf));
  154107. int * Cr_r_tab; /* => table for Cr to R conversion */
  154108. int * Cb_b_tab; /* => table for Cb to B conversion */
  154109. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  154110. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  154111. JSAMPROW spare_row;
  154112. boolean spare_full; /* T if spare buffer is occupied */
  154113. JDIMENSION out_row_width; /* samples per output row */
  154114. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154115. } my_upsampler;
  154116. typedef my_upsampler * my_upsample_ptr;
  154117. #define SCALEBITS 16 /* speediest right-shift on some machines */
  154118. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  154119. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  154120. LOCAL(void)
  154121. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  154122. {
  154123. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154124. int i;
  154125. INT32 x;
  154126. SHIFT_TEMPS
  154127. upsample->Cr_r_tab = (int *)
  154128. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154129. (MAXJSAMPLE+1) * SIZEOF(int));
  154130. upsample->Cb_b_tab = (int *)
  154131. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154132. (MAXJSAMPLE+1) * SIZEOF(int));
  154133. upsample->Cr_g_tab = (INT32 *)
  154134. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154135. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154136. upsample->Cb_g_tab = (INT32 *)
  154137. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154138. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154139. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  154140. upsample->Cr_r_tab[i] = (int)
  154141. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  154142. upsample->Cb_b_tab[i] = (int)
  154143. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  154144. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  154145. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  154146. }
  154147. }
  154148. METHODDEF(void)
  154149. start_pass_merged_upsample (j_decompress_ptr cinfo)
  154150. {
  154151. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154152. upsample->spare_full = FALSE;
  154153. upsample->rows_to_go = cinfo->output_height;
  154154. }
  154155. METHODDEF(void)
  154156. merged_2v_upsample (j_decompress_ptr cinfo,
  154157. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154158. JDIMENSION in_row_groups_avail,
  154159. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154160. JDIMENSION out_rows_avail)
  154161. {
  154162. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154163. JSAMPROW work_ptrs[2];
  154164. JDIMENSION num_rows; /* number of rows returned to caller */
  154165. if (upsample->spare_full) {
  154166. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  154167. 1, upsample->out_row_width);
  154168. num_rows = 1;
  154169. upsample->spare_full = FALSE;
  154170. } else {
  154171. num_rows = 2;
  154172. if (num_rows > upsample->rows_to_go)
  154173. num_rows = upsample->rows_to_go;
  154174. out_rows_avail -= *out_row_ctr;
  154175. if (num_rows > out_rows_avail)
  154176. num_rows = out_rows_avail;
  154177. work_ptrs[0] = output_buf[*out_row_ctr];
  154178. if (num_rows > 1) {
  154179. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  154180. } else {
  154181. work_ptrs[1] = upsample->spare_row;
  154182. upsample->spare_full = TRUE;
  154183. }
  154184. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  154185. }
  154186. *out_row_ctr += num_rows;
  154187. upsample->rows_to_go -= num_rows;
  154188. if (! upsample->spare_full)
  154189. (*in_row_group_ctr)++;
  154190. }
  154191. METHODDEF(void)
  154192. merged_1v_upsample (j_decompress_ptr cinfo,
  154193. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154194. JDIMENSION in_row_groups_avail,
  154195. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154196. JDIMENSION out_rows_avail)
  154197. {
  154198. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154199. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  154200. output_buf + *out_row_ctr);
  154201. (*out_row_ctr)++;
  154202. (*in_row_group_ctr)++;
  154203. }
  154204. METHODDEF(void)
  154205. h2v1_merged_upsample (j_decompress_ptr cinfo,
  154206. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154207. JSAMPARRAY output_buf)
  154208. {
  154209. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154210. register int y, cred, cgreen, cblue;
  154211. int cb, cr;
  154212. register JSAMPROW outptr;
  154213. JSAMPROW inptr0, inptr1, inptr2;
  154214. JDIMENSION col;
  154215. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154216. int * Crrtab = upsample->Cr_r_tab;
  154217. int * Cbbtab = upsample->Cb_b_tab;
  154218. INT32 * Crgtab = upsample->Cr_g_tab;
  154219. INT32 * Cbgtab = upsample->Cb_g_tab;
  154220. SHIFT_TEMPS
  154221. inptr0 = input_buf[0][in_row_group_ctr];
  154222. inptr1 = input_buf[1][in_row_group_ctr];
  154223. inptr2 = input_buf[2][in_row_group_ctr];
  154224. outptr = output_buf[0];
  154225. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154226. cb = GETJSAMPLE(*inptr1++);
  154227. cr = GETJSAMPLE(*inptr2++);
  154228. cred = Crrtab[cr];
  154229. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154230. cblue = Cbbtab[cb];
  154231. y = GETJSAMPLE(*inptr0++);
  154232. outptr[RGB_RED] = range_limit[y + cred];
  154233. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154234. outptr[RGB_BLUE] = range_limit[y + cblue];
  154235. outptr += RGB_PIXELSIZE;
  154236. y = GETJSAMPLE(*inptr0++);
  154237. outptr[RGB_RED] = range_limit[y + cred];
  154238. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154239. outptr[RGB_BLUE] = range_limit[y + cblue];
  154240. outptr += RGB_PIXELSIZE;
  154241. }
  154242. if (cinfo->output_width & 1) {
  154243. cb = GETJSAMPLE(*inptr1);
  154244. cr = GETJSAMPLE(*inptr2);
  154245. cred = Crrtab[cr];
  154246. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154247. cblue = Cbbtab[cb];
  154248. y = GETJSAMPLE(*inptr0);
  154249. outptr[RGB_RED] = range_limit[y + cred];
  154250. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154251. outptr[RGB_BLUE] = range_limit[y + cblue];
  154252. }
  154253. }
  154254. METHODDEF(void)
  154255. h2v2_merged_upsample (j_decompress_ptr cinfo,
  154256. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154257. JSAMPARRAY output_buf)
  154258. {
  154259. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154260. register int y, cred, cgreen, cblue;
  154261. int cb, cr;
  154262. register JSAMPROW outptr0, outptr1;
  154263. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  154264. JDIMENSION col;
  154265. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154266. int * Crrtab = upsample->Cr_r_tab;
  154267. int * Cbbtab = upsample->Cb_b_tab;
  154268. INT32 * Crgtab = upsample->Cr_g_tab;
  154269. INT32 * Cbgtab = upsample->Cb_g_tab;
  154270. SHIFT_TEMPS
  154271. inptr00 = input_buf[0][in_row_group_ctr*2];
  154272. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  154273. inptr1 = input_buf[1][in_row_group_ctr];
  154274. inptr2 = input_buf[2][in_row_group_ctr];
  154275. outptr0 = output_buf[0];
  154276. outptr1 = output_buf[1];
  154277. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154278. cb = GETJSAMPLE(*inptr1++);
  154279. cr = GETJSAMPLE(*inptr2++);
  154280. cred = Crrtab[cr];
  154281. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154282. cblue = Cbbtab[cb];
  154283. y = GETJSAMPLE(*inptr00++);
  154284. outptr0[RGB_RED] = range_limit[y + cred];
  154285. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154286. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154287. outptr0 += RGB_PIXELSIZE;
  154288. y = GETJSAMPLE(*inptr00++);
  154289. outptr0[RGB_RED] = range_limit[y + cred];
  154290. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154291. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154292. outptr0 += RGB_PIXELSIZE;
  154293. y = GETJSAMPLE(*inptr01++);
  154294. outptr1[RGB_RED] = range_limit[y + cred];
  154295. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154296. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154297. outptr1 += RGB_PIXELSIZE;
  154298. y = GETJSAMPLE(*inptr01++);
  154299. outptr1[RGB_RED] = range_limit[y + cred];
  154300. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154301. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154302. outptr1 += RGB_PIXELSIZE;
  154303. }
  154304. if (cinfo->output_width & 1) {
  154305. cb = GETJSAMPLE(*inptr1);
  154306. cr = GETJSAMPLE(*inptr2);
  154307. cred = Crrtab[cr];
  154308. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154309. cblue = Cbbtab[cb];
  154310. y = GETJSAMPLE(*inptr00);
  154311. outptr0[RGB_RED] = range_limit[y + cred];
  154312. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154313. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154314. y = GETJSAMPLE(*inptr01);
  154315. outptr1[RGB_RED] = range_limit[y + cred];
  154316. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154317. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154318. }
  154319. }
  154320. GLOBAL(void)
  154321. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154322. {
  154323. my_upsample_ptr upsample;
  154324. upsample = (my_upsample_ptr)
  154325. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154326. SIZEOF(my_upsampler));
  154327. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154328. upsample->pub.start_pass = start_pass_merged_upsample;
  154329. upsample->pub.need_context_rows = FALSE;
  154330. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154331. if (cinfo->max_v_samp_factor == 2) {
  154332. upsample->pub.upsample = merged_2v_upsample;
  154333. upsample->upmethod = h2v2_merged_upsample;
  154334. upsample->spare_row = (JSAMPROW)
  154335. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154336. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154337. } else {
  154338. upsample->pub.upsample = merged_1v_upsample;
  154339. upsample->upmethod = h2v1_merged_upsample;
  154340. upsample->spare_row = NULL;
  154341. }
  154342. build_ycc_rgb_table2(cinfo);
  154343. }
  154344. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154345. /*** End of inlined file: jdmerge.c ***/
  154346. #undef ASSIGN_STATE
  154347. /*** Start of inlined file: jdphuff.c ***/
  154348. #define JPEG_INTERNALS
  154349. #ifdef D_PROGRESSIVE_SUPPORTED
  154350. typedef struct {
  154351. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154352. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154353. } savable_state3;
  154354. #ifndef NO_STRUCT_ASSIGN
  154355. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154356. #else
  154357. #if MAX_COMPS_IN_SCAN == 4
  154358. #define ASSIGN_STATE(dest,src) \
  154359. ((dest).EOBRUN = (src).EOBRUN, \
  154360. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154361. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154362. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154363. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154364. #endif
  154365. #endif
  154366. typedef struct {
  154367. struct jpeg_entropy_decoder pub; /* public fields */
  154368. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154369. savable_state3 saved; /* Other state at start of MCU */
  154370. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154371. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154372. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154373. } phuff_entropy_decoder;
  154374. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154375. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154376. JBLOCKROW *MCU_data));
  154377. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154378. JBLOCKROW *MCU_data));
  154379. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154380. JBLOCKROW *MCU_data));
  154381. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154382. JBLOCKROW *MCU_data));
  154383. METHODDEF(void)
  154384. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154385. {
  154386. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154387. boolean is_DC_band, bad;
  154388. int ci, coefi, tbl;
  154389. int *coef_bit_ptr;
  154390. jpeg_component_info * compptr;
  154391. is_DC_band = (cinfo->Ss == 0);
  154392. bad = FALSE;
  154393. if (is_DC_band) {
  154394. if (cinfo->Se != 0)
  154395. bad = TRUE;
  154396. } else {
  154397. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154398. bad = TRUE;
  154399. if (cinfo->comps_in_scan != 1)
  154400. bad = TRUE;
  154401. }
  154402. if (cinfo->Ah != 0) {
  154403. if (cinfo->Al != cinfo->Ah-1)
  154404. bad = TRUE;
  154405. }
  154406. if (cinfo->Al > 13) /* need not check for < 0 */
  154407. bad = TRUE;
  154408. if (bad)
  154409. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154410. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154411. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154412. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154413. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154414. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154415. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154416. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154417. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154418. if (cinfo->Ah != expected)
  154419. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154420. coef_bit_ptr[coefi] = cinfo->Al;
  154421. }
  154422. }
  154423. if (cinfo->Ah == 0) {
  154424. if (is_DC_band)
  154425. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154426. else
  154427. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154428. } else {
  154429. if (is_DC_band)
  154430. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154431. else
  154432. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154433. }
  154434. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154435. compptr = cinfo->cur_comp_info[ci];
  154436. if (is_DC_band) {
  154437. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154438. tbl = compptr->dc_tbl_no;
  154439. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154440. & entropy->derived_tbls[tbl]);
  154441. }
  154442. } else {
  154443. tbl = compptr->ac_tbl_no;
  154444. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154445. & entropy->derived_tbls[tbl]);
  154446. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154447. }
  154448. entropy->saved.last_dc_val[ci] = 0;
  154449. }
  154450. entropy->bitstate.bits_left = 0;
  154451. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154452. entropy->pub.insufficient_data = FALSE;
  154453. entropy->saved.EOBRUN = 0;
  154454. entropy->restarts_to_go = cinfo->restart_interval;
  154455. }
  154456. LOCAL(boolean)
  154457. process_restartp (j_decompress_ptr cinfo)
  154458. {
  154459. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154460. int ci;
  154461. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154462. entropy->bitstate.bits_left = 0;
  154463. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154464. return FALSE;
  154465. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154466. entropy->saved.last_dc_val[ci] = 0;
  154467. entropy->saved.EOBRUN = 0;
  154468. entropy->restarts_to_go = cinfo->restart_interval;
  154469. if (cinfo->unread_marker == 0)
  154470. entropy->pub.insufficient_data = FALSE;
  154471. return TRUE;
  154472. }
  154473. METHODDEF(boolean)
  154474. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154475. {
  154476. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154477. int Al = cinfo->Al;
  154478. register int s, r;
  154479. int blkn, ci;
  154480. JBLOCKROW block;
  154481. BITREAD_STATE_VARS;
  154482. savable_state3 state;
  154483. d_derived_tbl * tbl;
  154484. jpeg_component_info * compptr;
  154485. if (cinfo->restart_interval) {
  154486. if (entropy->restarts_to_go == 0)
  154487. if (! process_restartp(cinfo))
  154488. return FALSE;
  154489. }
  154490. if (! entropy->pub.insufficient_data) {
  154491. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154492. ASSIGN_STATE(state, entropy->saved);
  154493. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154494. block = MCU_data[blkn];
  154495. ci = cinfo->MCU_membership[blkn];
  154496. compptr = cinfo->cur_comp_info[ci];
  154497. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154498. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154499. if (s) {
  154500. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154501. r = GET_BITS(s);
  154502. s = HUFF_EXTEND(r, s);
  154503. }
  154504. s += state.last_dc_val[ci];
  154505. state.last_dc_val[ci] = s;
  154506. (*block)[0] = (JCOEF) (s << Al);
  154507. }
  154508. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154509. ASSIGN_STATE(entropy->saved, state);
  154510. }
  154511. entropy->restarts_to_go--;
  154512. return TRUE;
  154513. }
  154514. METHODDEF(boolean)
  154515. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154516. {
  154517. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154518. int Se = cinfo->Se;
  154519. int Al = cinfo->Al;
  154520. register int s, k, r;
  154521. unsigned int EOBRUN;
  154522. JBLOCKROW block;
  154523. BITREAD_STATE_VARS;
  154524. d_derived_tbl * tbl;
  154525. if (cinfo->restart_interval) {
  154526. if (entropy->restarts_to_go == 0)
  154527. if (! process_restartp(cinfo))
  154528. return FALSE;
  154529. }
  154530. if (! entropy->pub.insufficient_data) {
  154531. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154532. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154533. EOBRUN--; /* ...process it now (we do nothing) */
  154534. else {
  154535. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154536. block = MCU_data[0];
  154537. tbl = entropy->ac_derived_tbl;
  154538. for (k = cinfo->Ss; k <= Se; k++) {
  154539. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154540. r = s >> 4;
  154541. s &= 15;
  154542. if (s) {
  154543. k += r;
  154544. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154545. r = GET_BITS(s);
  154546. s = HUFF_EXTEND(r, s);
  154547. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154548. } else {
  154549. if (r == 15) { /* ZRL */
  154550. k += 15; /* skip 15 zeroes in band */
  154551. } else { /* EOBr, run length is 2^r + appended bits */
  154552. EOBRUN = 1 << r;
  154553. if (r) { /* EOBr, r > 0 */
  154554. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154555. r = GET_BITS(r);
  154556. EOBRUN += r;
  154557. }
  154558. EOBRUN--; /* this band is processed at this moment */
  154559. break; /* force end-of-band */
  154560. }
  154561. }
  154562. }
  154563. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154564. }
  154565. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154566. }
  154567. entropy->restarts_to_go--;
  154568. return TRUE;
  154569. }
  154570. METHODDEF(boolean)
  154571. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154572. {
  154573. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154574. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154575. int blkn;
  154576. JBLOCKROW block;
  154577. BITREAD_STATE_VARS;
  154578. if (cinfo->restart_interval) {
  154579. if (entropy->restarts_to_go == 0)
  154580. if (! process_restartp(cinfo))
  154581. return FALSE;
  154582. }
  154583. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154584. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154585. block = MCU_data[blkn];
  154586. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154587. if (GET_BITS(1))
  154588. (*block)[0] |= p1;
  154589. }
  154590. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154591. entropy->restarts_to_go--;
  154592. return TRUE;
  154593. }
  154594. METHODDEF(boolean)
  154595. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154596. {
  154597. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154598. int Se = cinfo->Se;
  154599. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154600. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154601. register int s, k, r;
  154602. unsigned int EOBRUN;
  154603. JBLOCKROW block;
  154604. JCOEFPTR thiscoef;
  154605. BITREAD_STATE_VARS;
  154606. d_derived_tbl * tbl;
  154607. int num_newnz;
  154608. int newnz_pos[DCTSIZE2];
  154609. if (cinfo->restart_interval) {
  154610. if (entropy->restarts_to_go == 0)
  154611. if (! process_restartp(cinfo))
  154612. return FALSE;
  154613. }
  154614. if (! entropy->pub.insufficient_data) {
  154615. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154616. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154617. block = MCU_data[0];
  154618. tbl = entropy->ac_derived_tbl;
  154619. num_newnz = 0;
  154620. k = cinfo->Ss;
  154621. if (EOBRUN == 0) {
  154622. for (; k <= Se; k++) {
  154623. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154624. r = s >> 4;
  154625. s &= 15;
  154626. if (s) {
  154627. if (s != 1) /* size of new coef should always be 1 */
  154628. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154629. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154630. if (GET_BITS(1))
  154631. s = p1; /* newly nonzero coef is positive */
  154632. else
  154633. s = m1; /* newly nonzero coef is negative */
  154634. } else {
  154635. if (r != 15) {
  154636. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154637. if (r) {
  154638. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154639. r = GET_BITS(r);
  154640. EOBRUN += r;
  154641. }
  154642. break; /* rest of block is handled by EOB logic */
  154643. }
  154644. }
  154645. do {
  154646. thiscoef = *block + jpeg_natural_order[k];
  154647. if (*thiscoef != 0) {
  154648. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154649. if (GET_BITS(1)) {
  154650. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154651. if (*thiscoef >= 0)
  154652. *thiscoef += p1;
  154653. else
  154654. *thiscoef += m1;
  154655. }
  154656. }
  154657. } else {
  154658. if (--r < 0)
  154659. break; /* reached target zero coefficient */
  154660. }
  154661. k++;
  154662. } while (k <= Se);
  154663. if (s) {
  154664. int pos = jpeg_natural_order[k];
  154665. (*block)[pos] = (JCOEF) s;
  154666. newnz_pos[num_newnz++] = pos;
  154667. }
  154668. }
  154669. }
  154670. if (EOBRUN > 0) {
  154671. for (; k <= Se; k++) {
  154672. thiscoef = *block + jpeg_natural_order[k];
  154673. if (*thiscoef != 0) {
  154674. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154675. if (GET_BITS(1)) {
  154676. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154677. if (*thiscoef >= 0)
  154678. *thiscoef += p1;
  154679. else
  154680. *thiscoef += m1;
  154681. }
  154682. }
  154683. }
  154684. }
  154685. EOBRUN--;
  154686. }
  154687. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154688. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154689. }
  154690. entropy->restarts_to_go--;
  154691. return TRUE;
  154692. undoit:
  154693. while (num_newnz > 0)
  154694. (*block)[newnz_pos[--num_newnz]] = 0;
  154695. return FALSE;
  154696. }
  154697. GLOBAL(void)
  154698. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154699. {
  154700. phuff_entropy_ptr2 entropy;
  154701. int *coef_bit_ptr;
  154702. int ci, i;
  154703. entropy = (phuff_entropy_ptr2)
  154704. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154705. SIZEOF(phuff_entropy_decoder));
  154706. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154707. entropy->pub.start_pass = start_pass_phuff_decoder;
  154708. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154709. entropy->derived_tbls[i] = NULL;
  154710. }
  154711. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154712. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154713. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154714. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154715. for (ci = 0; ci < cinfo->num_components; ci++)
  154716. for (i = 0; i < DCTSIZE2; i++)
  154717. *coef_bit_ptr++ = -1;
  154718. }
  154719. #endif /* D_PROGRESSIVE_SUPPORTED */
  154720. /*** End of inlined file: jdphuff.c ***/
  154721. /*** Start of inlined file: jdpostct.c ***/
  154722. #define JPEG_INTERNALS
  154723. typedef struct {
  154724. struct jpeg_d_post_controller pub; /* public fields */
  154725. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154726. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154727. JDIMENSION strip_height; /* buffer size in rows */
  154728. JDIMENSION starting_row; /* row # of first row in current strip */
  154729. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154730. } my_post_controller;
  154731. typedef my_post_controller * my_post_ptr;
  154732. METHODDEF(void) post_process_1pass
  154733. JPP((j_decompress_ptr cinfo,
  154734. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154735. JDIMENSION in_row_groups_avail,
  154736. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154737. JDIMENSION out_rows_avail));
  154738. #ifdef QUANT_2PASS_SUPPORTED
  154739. METHODDEF(void) post_process_prepass
  154740. JPP((j_decompress_ptr cinfo,
  154741. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154742. JDIMENSION in_row_groups_avail,
  154743. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154744. JDIMENSION out_rows_avail));
  154745. METHODDEF(void) post_process_2pass
  154746. JPP((j_decompress_ptr cinfo,
  154747. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154748. JDIMENSION in_row_groups_avail,
  154749. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154750. JDIMENSION out_rows_avail));
  154751. #endif
  154752. METHODDEF(void)
  154753. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154754. {
  154755. my_post_ptr post = (my_post_ptr) cinfo->post;
  154756. switch (pass_mode) {
  154757. case JBUF_PASS_THRU:
  154758. if (cinfo->quantize_colors) {
  154759. post->pub.post_process_data = post_process_1pass;
  154760. if (post->buffer == NULL) {
  154761. post->buffer = (*cinfo->mem->access_virt_sarray)
  154762. ((j_common_ptr) cinfo, post->whole_image,
  154763. (JDIMENSION) 0, post->strip_height, TRUE);
  154764. }
  154765. } else {
  154766. post->pub.post_process_data = cinfo->upsample->upsample;
  154767. }
  154768. break;
  154769. #ifdef QUANT_2PASS_SUPPORTED
  154770. case JBUF_SAVE_AND_PASS:
  154771. if (post->whole_image == NULL)
  154772. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154773. post->pub.post_process_data = post_process_prepass;
  154774. break;
  154775. case JBUF_CRANK_DEST:
  154776. if (post->whole_image == NULL)
  154777. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154778. post->pub.post_process_data = post_process_2pass;
  154779. break;
  154780. #endif /* QUANT_2PASS_SUPPORTED */
  154781. default:
  154782. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154783. break;
  154784. }
  154785. post->starting_row = post->next_row = 0;
  154786. }
  154787. METHODDEF(void)
  154788. post_process_1pass (j_decompress_ptr cinfo,
  154789. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154790. JDIMENSION in_row_groups_avail,
  154791. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154792. JDIMENSION out_rows_avail)
  154793. {
  154794. my_post_ptr post = (my_post_ptr) cinfo->post;
  154795. JDIMENSION num_rows, max_rows;
  154796. max_rows = out_rows_avail - *out_row_ctr;
  154797. if (max_rows > post->strip_height)
  154798. max_rows = post->strip_height;
  154799. num_rows = 0;
  154800. (*cinfo->upsample->upsample) (cinfo,
  154801. input_buf, in_row_group_ctr, in_row_groups_avail,
  154802. post->buffer, &num_rows, max_rows);
  154803. (*cinfo->cquantize->color_quantize) (cinfo,
  154804. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154805. *out_row_ctr += num_rows;
  154806. }
  154807. #ifdef QUANT_2PASS_SUPPORTED
  154808. METHODDEF(void)
  154809. post_process_prepass (j_decompress_ptr cinfo,
  154810. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154811. JDIMENSION in_row_groups_avail,
  154812. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154813. JDIMENSION out_rows_avail)
  154814. {
  154815. my_post_ptr post = (my_post_ptr) cinfo->post;
  154816. JDIMENSION old_next_row, num_rows;
  154817. if (post->next_row == 0) {
  154818. post->buffer = (*cinfo->mem->access_virt_sarray)
  154819. ((j_common_ptr) cinfo, post->whole_image,
  154820. post->starting_row, post->strip_height, TRUE);
  154821. }
  154822. old_next_row = post->next_row;
  154823. (*cinfo->upsample->upsample) (cinfo,
  154824. input_buf, in_row_group_ctr, in_row_groups_avail,
  154825. post->buffer, &post->next_row, post->strip_height);
  154826. if (post->next_row > old_next_row) {
  154827. num_rows = post->next_row - old_next_row;
  154828. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154829. (JSAMPARRAY) NULL, (int) num_rows);
  154830. *out_row_ctr += num_rows;
  154831. }
  154832. if (post->next_row >= post->strip_height) {
  154833. post->starting_row += post->strip_height;
  154834. post->next_row = 0;
  154835. }
  154836. }
  154837. METHODDEF(void)
  154838. post_process_2pass (j_decompress_ptr cinfo,
  154839. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154840. JDIMENSION in_row_groups_avail,
  154841. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154842. JDIMENSION out_rows_avail)
  154843. {
  154844. my_post_ptr post = (my_post_ptr) cinfo->post;
  154845. JDIMENSION num_rows, max_rows;
  154846. if (post->next_row == 0) {
  154847. post->buffer = (*cinfo->mem->access_virt_sarray)
  154848. ((j_common_ptr) cinfo, post->whole_image,
  154849. post->starting_row, post->strip_height, FALSE);
  154850. }
  154851. num_rows = post->strip_height - post->next_row; /* available in strip */
  154852. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154853. if (num_rows > max_rows)
  154854. num_rows = max_rows;
  154855. max_rows = cinfo->output_height - post->starting_row;
  154856. if (num_rows > max_rows)
  154857. num_rows = max_rows;
  154858. (*cinfo->cquantize->color_quantize) (cinfo,
  154859. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154860. (int) num_rows);
  154861. *out_row_ctr += num_rows;
  154862. post->next_row += num_rows;
  154863. if (post->next_row >= post->strip_height) {
  154864. post->starting_row += post->strip_height;
  154865. post->next_row = 0;
  154866. }
  154867. }
  154868. #endif /* QUANT_2PASS_SUPPORTED */
  154869. GLOBAL(void)
  154870. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154871. {
  154872. my_post_ptr post;
  154873. post = (my_post_ptr)
  154874. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154875. SIZEOF(my_post_controller));
  154876. cinfo->post = (struct jpeg_d_post_controller *) post;
  154877. post->pub.start_pass = start_pass_dpost;
  154878. post->whole_image = NULL; /* flag for no virtual arrays */
  154879. post->buffer = NULL; /* flag for no strip buffer */
  154880. if (cinfo->quantize_colors) {
  154881. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154882. if (need_full_buffer) {
  154883. #ifdef QUANT_2PASS_SUPPORTED
  154884. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154885. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154886. cinfo->output_width * cinfo->out_color_components,
  154887. (JDIMENSION) jround_up((long) cinfo->output_height,
  154888. (long) post->strip_height),
  154889. post->strip_height);
  154890. #else
  154891. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154892. #endif /* QUANT_2PASS_SUPPORTED */
  154893. } else {
  154894. post->buffer = (*cinfo->mem->alloc_sarray)
  154895. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154896. cinfo->output_width * cinfo->out_color_components,
  154897. post->strip_height);
  154898. }
  154899. }
  154900. }
  154901. /*** End of inlined file: jdpostct.c ***/
  154902. #undef FIX
  154903. /*** Start of inlined file: jdsample.c ***/
  154904. #define JPEG_INTERNALS
  154905. typedef JMETHOD(void, upsample1_ptr,
  154906. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154907. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154908. typedef struct {
  154909. struct jpeg_upsampler pub; /* public fields */
  154910. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154911. upsample1_ptr methods[MAX_COMPONENTS];
  154912. int next_row_out; /* counts rows emitted from color_buf */
  154913. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154914. int rowgroup_height[MAX_COMPONENTS];
  154915. UINT8 h_expand[MAX_COMPONENTS];
  154916. UINT8 v_expand[MAX_COMPONENTS];
  154917. } my_upsampler2;
  154918. typedef my_upsampler2 * my_upsample_ptr2;
  154919. METHODDEF(void)
  154920. start_pass_upsample (j_decompress_ptr cinfo)
  154921. {
  154922. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154923. upsample->next_row_out = cinfo->max_v_samp_factor;
  154924. upsample->rows_to_go = cinfo->output_height;
  154925. }
  154926. METHODDEF(void)
  154927. sep_upsample (j_decompress_ptr cinfo,
  154928. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154929. JDIMENSION in_row_groups_avail,
  154930. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154931. JDIMENSION out_rows_avail)
  154932. {
  154933. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154934. int ci;
  154935. jpeg_component_info * compptr;
  154936. JDIMENSION num_rows;
  154937. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154938. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154939. ci++, compptr++) {
  154940. (*upsample->methods[ci]) (cinfo, compptr,
  154941. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154942. upsample->color_buf + ci);
  154943. }
  154944. upsample->next_row_out = 0;
  154945. }
  154946. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154947. if (num_rows > upsample->rows_to_go)
  154948. num_rows = upsample->rows_to_go;
  154949. out_rows_avail -= *out_row_ctr;
  154950. if (num_rows > out_rows_avail)
  154951. num_rows = out_rows_avail;
  154952. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154953. (JDIMENSION) upsample->next_row_out,
  154954. output_buf + *out_row_ctr,
  154955. (int) num_rows);
  154956. *out_row_ctr += num_rows;
  154957. upsample->rows_to_go -= num_rows;
  154958. upsample->next_row_out += num_rows;
  154959. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154960. (*in_row_group_ctr)++;
  154961. }
  154962. METHODDEF(void)
  154963. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154964. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154965. {
  154966. *output_data_ptr = input_data;
  154967. }
  154968. METHODDEF(void)
  154969. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154970. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154971. {
  154972. *output_data_ptr = NULL; /* safety check */
  154973. }
  154974. METHODDEF(void)
  154975. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154976. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154977. {
  154978. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154979. JSAMPARRAY output_data = *output_data_ptr;
  154980. register JSAMPROW inptr, outptr;
  154981. register JSAMPLE invalue;
  154982. register int h;
  154983. JSAMPROW outend;
  154984. int h_expand, v_expand;
  154985. int inrow, outrow;
  154986. h_expand = upsample->h_expand[compptr->component_index];
  154987. v_expand = upsample->v_expand[compptr->component_index];
  154988. inrow = outrow = 0;
  154989. while (outrow < cinfo->max_v_samp_factor) {
  154990. inptr = input_data[inrow];
  154991. outptr = output_data[outrow];
  154992. outend = outptr + cinfo->output_width;
  154993. while (outptr < outend) {
  154994. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154995. for (h = h_expand; h > 0; h--) {
  154996. *outptr++ = invalue;
  154997. }
  154998. }
  154999. if (v_expand > 1) {
  155000. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155001. v_expand-1, cinfo->output_width);
  155002. }
  155003. inrow++;
  155004. outrow += v_expand;
  155005. }
  155006. }
  155007. METHODDEF(void)
  155008. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155009. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155010. {
  155011. JSAMPARRAY output_data = *output_data_ptr;
  155012. register JSAMPROW inptr, outptr;
  155013. register JSAMPLE invalue;
  155014. JSAMPROW outend;
  155015. int inrow;
  155016. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155017. inptr = input_data[inrow];
  155018. outptr = output_data[inrow];
  155019. outend = outptr + cinfo->output_width;
  155020. while (outptr < outend) {
  155021. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155022. *outptr++ = invalue;
  155023. *outptr++ = invalue;
  155024. }
  155025. }
  155026. }
  155027. METHODDEF(void)
  155028. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155029. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155030. {
  155031. JSAMPARRAY output_data = *output_data_ptr;
  155032. register JSAMPROW inptr, outptr;
  155033. register JSAMPLE invalue;
  155034. JSAMPROW outend;
  155035. int inrow, outrow;
  155036. inrow = outrow = 0;
  155037. while (outrow < cinfo->max_v_samp_factor) {
  155038. inptr = input_data[inrow];
  155039. outptr = output_data[outrow];
  155040. outend = outptr + cinfo->output_width;
  155041. while (outptr < outend) {
  155042. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155043. *outptr++ = invalue;
  155044. *outptr++ = invalue;
  155045. }
  155046. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155047. 1, cinfo->output_width);
  155048. inrow++;
  155049. outrow += 2;
  155050. }
  155051. }
  155052. METHODDEF(void)
  155053. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155054. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155055. {
  155056. JSAMPARRAY output_data = *output_data_ptr;
  155057. register JSAMPROW inptr, outptr;
  155058. register int invalue;
  155059. register JDIMENSION colctr;
  155060. int inrow;
  155061. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155062. inptr = input_data[inrow];
  155063. outptr = output_data[inrow];
  155064. invalue = GETJSAMPLE(*inptr++);
  155065. *outptr++ = (JSAMPLE) invalue;
  155066. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  155067. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155068. invalue = GETJSAMPLE(*inptr++) * 3;
  155069. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  155070. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  155071. }
  155072. invalue = GETJSAMPLE(*inptr);
  155073. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  155074. *outptr++ = (JSAMPLE) invalue;
  155075. }
  155076. }
  155077. METHODDEF(void)
  155078. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155079. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155080. {
  155081. JSAMPARRAY output_data = *output_data_ptr;
  155082. register JSAMPROW inptr0, inptr1, outptr;
  155083. #if BITS_IN_JSAMPLE == 8
  155084. register int thiscolsum, lastcolsum, nextcolsum;
  155085. #else
  155086. register INT32 thiscolsum, lastcolsum, nextcolsum;
  155087. #endif
  155088. register JDIMENSION colctr;
  155089. int inrow, outrow, v;
  155090. inrow = outrow = 0;
  155091. while (outrow < cinfo->max_v_samp_factor) {
  155092. for (v = 0; v < 2; v++) {
  155093. inptr0 = input_data[inrow];
  155094. if (v == 0) /* next nearest is row above */
  155095. inptr1 = input_data[inrow-1];
  155096. else /* next nearest is row below */
  155097. inptr1 = input_data[inrow+1];
  155098. outptr = output_data[outrow++];
  155099. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155100. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155101. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  155102. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155103. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155104. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155105. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155106. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155107. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155108. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155109. }
  155110. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155111. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  155112. }
  155113. inrow++;
  155114. }
  155115. }
  155116. GLOBAL(void)
  155117. jinit_upsampler (j_decompress_ptr cinfo)
  155118. {
  155119. my_upsample_ptr2 upsample;
  155120. int ci;
  155121. jpeg_component_info * compptr;
  155122. boolean need_buffer, do_fancy;
  155123. int h_in_group, v_in_group, h_out_group, v_out_group;
  155124. upsample = (my_upsample_ptr2)
  155125. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155126. SIZEOF(my_upsampler2));
  155127. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  155128. upsample->pub.start_pass = start_pass_upsample;
  155129. upsample->pub.upsample = sep_upsample;
  155130. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  155131. if (cinfo->CCIR601_sampling) /* this isn't supported */
  155132. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  155133. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  155134. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155135. ci++, compptr++) {
  155136. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  155137. cinfo->min_DCT_scaled_size;
  155138. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  155139. cinfo->min_DCT_scaled_size;
  155140. h_out_group = cinfo->max_h_samp_factor;
  155141. v_out_group = cinfo->max_v_samp_factor;
  155142. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  155143. need_buffer = TRUE;
  155144. if (! compptr->component_needed) {
  155145. upsample->methods[ci] = noop_upsample;
  155146. need_buffer = FALSE;
  155147. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  155148. upsample->methods[ci] = fullsize_upsample;
  155149. need_buffer = FALSE;
  155150. } else if (h_in_group * 2 == h_out_group &&
  155151. v_in_group == v_out_group) {
  155152. if (do_fancy && compptr->downsampled_width > 2)
  155153. upsample->methods[ci] = h2v1_fancy_upsample;
  155154. else
  155155. upsample->methods[ci] = h2v1_upsample;
  155156. } else if (h_in_group * 2 == h_out_group &&
  155157. v_in_group * 2 == v_out_group) {
  155158. if (do_fancy && compptr->downsampled_width > 2) {
  155159. upsample->methods[ci] = h2v2_fancy_upsample;
  155160. upsample->pub.need_context_rows = TRUE;
  155161. } else
  155162. upsample->methods[ci] = h2v2_upsample;
  155163. } else if ((h_out_group % h_in_group) == 0 &&
  155164. (v_out_group % v_in_group) == 0) {
  155165. upsample->methods[ci] = int_upsample;
  155166. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  155167. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  155168. } else
  155169. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  155170. if (need_buffer) {
  155171. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  155172. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155173. (JDIMENSION) jround_up((long) cinfo->output_width,
  155174. (long) cinfo->max_h_samp_factor),
  155175. (JDIMENSION) cinfo->max_v_samp_factor);
  155176. }
  155177. }
  155178. }
  155179. /*** End of inlined file: jdsample.c ***/
  155180. /*** Start of inlined file: jdtrans.c ***/
  155181. #define JPEG_INTERNALS
  155182. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  155183. GLOBAL(jvirt_barray_ptr *)
  155184. jpeg_read_coefficients (j_decompress_ptr cinfo)
  155185. {
  155186. if (cinfo->global_state == DSTATE_READY) {
  155187. transdecode_master_selection(cinfo);
  155188. cinfo->global_state = DSTATE_RDCOEFS;
  155189. }
  155190. if (cinfo->global_state == DSTATE_RDCOEFS) {
  155191. for (;;) {
  155192. int retcode;
  155193. if (cinfo->progress != NULL)
  155194. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  155195. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  155196. if (retcode == JPEG_SUSPENDED)
  155197. return NULL;
  155198. if (retcode == JPEG_REACHED_EOI)
  155199. break;
  155200. if (cinfo->progress != NULL &&
  155201. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  155202. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  155203. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  155204. }
  155205. }
  155206. }
  155207. cinfo->global_state = DSTATE_STOPPING;
  155208. }
  155209. if ((cinfo->global_state == DSTATE_STOPPING ||
  155210. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  155211. return cinfo->coef->coef_arrays;
  155212. }
  155213. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  155214. return NULL; /* keep compiler happy */
  155215. }
  155216. LOCAL(void)
  155217. transdecode_master_selection (j_decompress_ptr cinfo)
  155218. {
  155219. cinfo->buffered_image = TRUE;
  155220. if (cinfo->arith_code) {
  155221. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  155222. } else {
  155223. if (cinfo->progressive_mode) {
  155224. #ifdef D_PROGRESSIVE_SUPPORTED
  155225. jinit_phuff_decoder(cinfo);
  155226. #else
  155227. ERREXIT(cinfo, JERR_NOT_COMPILED);
  155228. #endif
  155229. } else
  155230. jinit_huff_decoder(cinfo);
  155231. }
  155232. jinit_d_coef_controller(cinfo, TRUE);
  155233. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  155234. (*cinfo->inputctl->start_input_pass) (cinfo);
  155235. if (cinfo->progress != NULL) {
  155236. int nscans;
  155237. if (cinfo->progressive_mode) {
  155238. nscans = 2 + 3 * cinfo->num_components;
  155239. } else if (cinfo->inputctl->has_multiple_scans) {
  155240. nscans = cinfo->num_components;
  155241. } else {
  155242. nscans = 1;
  155243. }
  155244. cinfo->progress->pass_counter = 0L;
  155245. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  155246. cinfo->progress->completed_passes = 0;
  155247. cinfo->progress->total_passes = 1;
  155248. }
  155249. }
  155250. /*** End of inlined file: jdtrans.c ***/
  155251. /*** Start of inlined file: jfdctflt.c ***/
  155252. #define JPEG_INTERNALS
  155253. #ifdef DCT_FLOAT_SUPPORTED
  155254. #if DCTSIZE != 8
  155255. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155256. #endif
  155257. GLOBAL(void)
  155258. jpeg_fdct_float (FAST_FLOAT * data)
  155259. {
  155260. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155261. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155262. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  155263. FAST_FLOAT *dataptr;
  155264. int ctr;
  155265. dataptr = data;
  155266. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155267. tmp0 = dataptr[0] + dataptr[7];
  155268. tmp7 = dataptr[0] - dataptr[7];
  155269. tmp1 = dataptr[1] + dataptr[6];
  155270. tmp6 = dataptr[1] - dataptr[6];
  155271. tmp2 = dataptr[2] + dataptr[5];
  155272. tmp5 = dataptr[2] - dataptr[5];
  155273. tmp3 = dataptr[3] + dataptr[4];
  155274. tmp4 = dataptr[3] - dataptr[4];
  155275. tmp10 = tmp0 + tmp3; /* phase 2 */
  155276. tmp13 = tmp0 - tmp3;
  155277. tmp11 = tmp1 + tmp2;
  155278. tmp12 = tmp1 - tmp2;
  155279. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155280. dataptr[4] = tmp10 - tmp11;
  155281. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155282. dataptr[2] = tmp13 + z1; /* phase 5 */
  155283. dataptr[6] = tmp13 - z1;
  155284. tmp10 = tmp4 + tmp5; /* phase 2 */
  155285. tmp11 = tmp5 + tmp6;
  155286. tmp12 = tmp6 + tmp7;
  155287. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155288. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155289. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155290. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155291. z11 = tmp7 + z3; /* phase 5 */
  155292. z13 = tmp7 - z3;
  155293. dataptr[5] = z13 + z2; /* phase 6 */
  155294. dataptr[3] = z13 - z2;
  155295. dataptr[1] = z11 + z4;
  155296. dataptr[7] = z11 - z4;
  155297. dataptr += DCTSIZE; /* advance pointer to next row */
  155298. }
  155299. dataptr = data;
  155300. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155301. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155302. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155303. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155304. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155305. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155306. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155307. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155308. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155309. tmp10 = tmp0 + tmp3; /* phase 2 */
  155310. tmp13 = tmp0 - tmp3;
  155311. tmp11 = tmp1 + tmp2;
  155312. tmp12 = tmp1 - tmp2;
  155313. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155314. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155315. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155316. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155317. dataptr[DCTSIZE*6] = tmp13 - z1;
  155318. tmp10 = tmp4 + tmp5; /* phase 2 */
  155319. tmp11 = tmp5 + tmp6;
  155320. tmp12 = tmp6 + tmp7;
  155321. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155322. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155323. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155324. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155325. z11 = tmp7 + z3; /* phase 5 */
  155326. z13 = tmp7 - z3;
  155327. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155328. dataptr[DCTSIZE*3] = z13 - z2;
  155329. dataptr[DCTSIZE*1] = z11 + z4;
  155330. dataptr[DCTSIZE*7] = z11 - z4;
  155331. dataptr++; /* advance pointer to next column */
  155332. }
  155333. }
  155334. #endif /* DCT_FLOAT_SUPPORTED */
  155335. /*** End of inlined file: jfdctflt.c ***/
  155336. /*** Start of inlined file: jfdctint.c ***/
  155337. #define JPEG_INTERNALS
  155338. #ifdef DCT_ISLOW_SUPPORTED
  155339. #if DCTSIZE != 8
  155340. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155341. #endif
  155342. #if BITS_IN_JSAMPLE == 8
  155343. #define CONST_BITS 13
  155344. #define PASS1_BITS 2
  155345. #else
  155346. #define CONST_BITS 13
  155347. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155348. #endif
  155349. #if CONST_BITS == 13
  155350. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155351. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155352. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155353. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155354. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155355. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155356. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155357. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155358. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155359. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155360. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155361. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155362. #else
  155363. #define FIX_0_298631336 FIX(0.298631336)
  155364. #define FIX_0_390180644 FIX(0.390180644)
  155365. #define FIX_0_541196100 FIX(0.541196100)
  155366. #define FIX_0_765366865 FIX(0.765366865)
  155367. #define FIX_0_899976223 FIX(0.899976223)
  155368. #define FIX_1_175875602 FIX(1.175875602)
  155369. #define FIX_1_501321110 FIX(1.501321110)
  155370. #define FIX_1_847759065 FIX(1.847759065)
  155371. #define FIX_1_961570560 FIX(1.961570560)
  155372. #define FIX_2_053119869 FIX(2.053119869)
  155373. #define FIX_2_562915447 FIX(2.562915447)
  155374. #define FIX_3_072711026 FIX(3.072711026)
  155375. #endif
  155376. #if BITS_IN_JSAMPLE == 8
  155377. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155378. #else
  155379. #define MULTIPLY(var,const) ((var) * (const))
  155380. #endif
  155381. GLOBAL(void)
  155382. jpeg_fdct_islow (DCTELEM * data)
  155383. {
  155384. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155385. INT32 tmp10, tmp11, tmp12, tmp13;
  155386. INT32 z1, z2, z3, z4, z5;
  155387. DCTELEM *dataptr;
  155388. int ctr;
  155389. SHIFT_TEMPS
  155390. dataptr = data;
  155391. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155392. tmp0 = dataptr[0] + dataptr[7];
  155393. tmp7 = dataptr[0] - dataptr[7];
  155394. tmp1 = dataptr[1] + dataptr[6];
  155395. tmp6 = dataptr[1] - dataptr[6];
  155396. tmp2 = dataptr[2] + dataptr[5];
  155397. tmp5 = dataptr[2] - dataptr[5];
  155398. tmp3 = dataptr[3] + dataptr[4];
  155399. tmp4 = dataptr[3] - dataptr[4];
  155400. tmp10 = tmp0 + tmp3;
  155401. tmp13 = tmp0 - tmp3;
  155402. tmp11 = tmp1 + tmp2;
  155403. tmp12 = tmp1 - tmp2;
  155404. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155405. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155406. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155407. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155408. CONST_BITS-PASS1_BITS);
  155409. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155410. CONST_BITS-PASS1_BITS);
  155411. z1 = tmp4 + tmp7;
  155412. z2 = tmp5 + tmp6;
  155413. z3 = tmp4 + tmp6;
  155414. z4 = tmp5 + tmp7;
  155415. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155416. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155417. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155418. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155419. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155420. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155421. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155422. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155423. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155424. z3 += z5;
  155425. z4 += z5;
  155426. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155427. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155428. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155429. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155430. dataptr += DCTSIZE; /* advance pointer to next row */
  155431. }
  155432. dataptr = data;
  155433. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155434. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155435. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155436. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155437. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155438. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155439. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155440. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155441. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155442. tmp10 = tmp0 + tmp3;
  155443. tmp13 = tmp0 - tmp3;
  155444. tmp11 = tmp1 + tmp2;
  155445. tmp12 = tmp1 - tmp2;
  155446. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155447. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155448. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155449. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155450. CONST_BITS+PASS1_BITS);
  155451. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155452. CONST_BITS+PASS1_BITS);
  155453. z1 = tmp4 + tmp7;
  155454. z2 = tmp5 + tmp6;
  155455. z3 = tmp4 + tmp6;
  155456. z4 = tmp5 + tmp7;
  155457. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155458. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155459. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155460. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155461. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155462. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155463. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155464. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155465. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155466. z3 += z5;
  155467. z4 += z5;
  155468. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155469. CONST_BITS+PASS1_BITS);
  155470. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155471. CONST_BITS+PASS1_BITS);
  155472. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155473. CONST_BITS+PASS1_BITS);
  155474. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155475. CONST_BITS+PASS1_BITS);
  155476. dataptr++; /* advance pointer to next column */
  155477. }
  155478. }
  155479. #endif /* DCT_ISLOW_SUPPORTED */
  155480. /*** End of inlined file: jfdctint.c ***/
  155481. #undef CONST_BITS
  155482. #undef MULTIPLY
  155483. #undef FIX_0_541196100
  155484. /*** Start of inlined file: jfdctfst.c ***/
  155485. #define JPEG_INTERNALS
  155486. #ifdef DCT_IFAST_SUPPORTED
  155487. #if DCTSIZE != 8
  155488. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155489. #endif
  155490. #define CONST_BITS 8
  155491. #if CONST_BITS == 8
  155492. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155493. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155494. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155495. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155496. #else
  155497. #define FIX_0_382683433 FIX(0.382683433)
  155498. #define FIX_0_541196100 FIX(0.541196100)
  155499. #define FIX_0_707106781 FIX(0.707106781)
  155500. #define FIX_1_306562965 FIX(1.306562965)
  155501. #endif
  155502. #ifndef USE_ACCURATE_ROUNDING
  155503. #undef DESCALE
  155504. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155505. #endif
  155506. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155507. GLOBAL(void)
  155508. jpeg_fdct_ifast (DCTELEM * data)
  155509. {
  155510. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155511. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155512. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155513. DCTELEM *dataptr;
  155514. int ctr;
  155515. SHIFT_TEMPS
  155516. dataptr = data;
  155517. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155518. tmp0 = dataptr[0] + dataptr[7];
  155519. tmp7 = dataptr[0] - dataptr[7];
  155520. tmp1 = dataptr[1] + dataptr[6];
  155521. tmp6 = dataptr[1] - dataptr[6];
  155522. tmp2 = dataptr[2] + dataptr[5];
  155523. tmp5 = dataptr[2] - dataptr[5];
  155524. tmp3 = dataptr[3] + dataptr[4];
  155525. tmp4 = dataptr[3] - dataptr[4];
  155526. tmp10 = tmp0 + tmp3; /* phase 2 */
  155527. tmp13 = tmp0 - tmp3;
  155528. tmp11 = tmp1 + tmp2;
  155529. tmp12 = tmp1 - tmp2;
  155530. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155531. dataptr[4] = tmp10 - tmp11;
  155532. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155533. dataptr[2] = tmp13 + z1; /* phase 5 */
  155534. dataptr[6] = tmp13 - z1;
  155535. tmp10 = tmp4 + tmp5; /* phase 2 */
  155536. tmp11 = tmp5 + tmp6;
  155537. tmp12 = tmp6 + tmp7;
  155538. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155539. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155540. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155541. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155542. z11 = tmp7 + z3; /* phase 5 */
  155543. z13 = tmp7 - z3;
  155544. dataptr[5] = z13 + z2; /* phase 6 */
  155545. dataptr[3] = z13 - z2;
  155546. dataptr[1] = z11 + z4;
  155547. dataptr[7] = z11 - z4;
  155548. dataptr += DCTSIZE; /* advance pointer to next row */
  155549. }
  155550. dataptr = data;
  155551. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155552. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155553. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155554. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155555. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155556. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155557. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155558. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155559. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155560. tmp10 = tmp0 + tmp3; /* phase 2 */
  155561. tmp13 = tmp0 - tmp3;
  155562. tmp11 = tmp1 + tmp2;
  155563. tmp12 = tmp1 - tmp2;
  155564. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155565. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155566. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155567. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155568. dataptr[DCTSIZE*6] = tmp13 - z1;
  155569. tmp10 = tmp4 + tmp5; /* phase 2 */
  155570. tmp11 = tmp5 + tmp6;
  155571. tmp12 = tmp6 + tmp7;
  155572. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155573. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155574. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155575. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155576. z11 = tmp7 + z3; /* phase 5 */
  155577. z13 = tmp7 - z3;
  155578. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155579. dataptr[DCTSIZE*3] = z13 - z2;
  155580. dataptr[DCTSIZE*1] = z11 + z4;
  155581. dataptr[DCTSIZE*7] = z11 - z4;
  155582. dataptr++; /* advance pointer to next column */
  155583. }
  155584. }
  155585. #endif /* DCT_IFAST_SUPPORTED */
  155586. /*** End of inlined file: jfdctfst.c ***/
  155587. #undef FIX_0_541196100
  155588. /*** Start of inlined file: jidctflt.c ***/
  155589. #define JPEG_INTERNALS
  155590. #ifdef DCT_FLOAT_SUPPORTED
  155591. #if DCTSIZE != 8
  155592. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155593. #endif
  155594. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155595. GLOBAL(void)
  155596. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155597. JCOEFPTR coef_block,
  155598. JSAMPARRAY output_buf, JDIMENSION output_col)
  155599. {
  155600. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155601. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155602. FAST_FLOAT z5, z10, z11, z12, z13;
  155603. JCOEFPTR inptr;
  155604. FLOAT_MULT_TYPE * quantptr;
  155605. FAST_FLOAT * wsptr;
  155606. JSAMPROW outptr;
  155607. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155608. int ctr;
  155609. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155610. SHIFT_TEMPS
  155611. inptr = coef_block;
  155612. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155613. wsptr = workspace;
  155614. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155615. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155616. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155617. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155618. inptr[DCTSIZE*7] == 0) {
  155619. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155620. wsptr[DCTSIZE*0] = dcval;
  155621. wsptr[DCTSIZE*1] = dcval;
  155622. wsptr[DCTSIZE*2] = dcval;
  155623. wsptr[DCTSIZE*3] = dcval;
  155624. wsptr[DCTSIZE*4] = dcval;
  155625. wsptr[DCTSIZE*5] = dcval;
  155626. wsptr[DCTSIZE*6] = dcval;
  155627. wsptr[DCTSIZE*7] = dcval;
  155628. inptr++; /* advance pointers to next column */
  155629. quantptr++;
  155630. wsptr++;
  155631. continue;
  155632. }
  155633. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155634. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155635. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155636. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155637. tmp10 = tmp0 + tmp2; /* phase 3 */
  155638. tmp11 = tmp0 - tmp2;
  155639. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155640. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155641. tmp0 = tmp10 + tmp13; /* phase 2 */
  155642. tmp3 = tmp10 - tmp13;
  155643. tmp1 = tmp11 + tmp12;
  155644. tmp2 = tmp11 - tmp12;
  155645. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155646. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155647. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155648. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155649. z13 = tmp6 + tmp5; /* phase 6 */
  155650. z10 = tmp6 - tmp5;
  155651. z11 = tmp4 + tmp7;
  155652. z12 = tmp4 - tmp7;
  155653. tmp7 = z11 + z13; /* phase 5 */
  155654. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155655. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155656. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155657. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155658. tmp6 = tmp12 - tmp7; /* phase 2 */
  155659. tmp5 = tmp11 - tmp6;
  155660. tmp4 = tmp10 + tmp5;
  155661. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155662. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155663. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155664. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155665. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155666. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155667. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155668. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155669. inptr++; /* advance pointers to next column */
  155670. quantptr++;
  155671. wsptr++;
  155672. }
  155673. wsptr = workspace;
  155674. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155675. outptr = output_buf[ctr] + output_col;
  155676. tmp10 = wsptr[0] + wsptr[4];
  155677. tmp11 = wsptr[0] - wsptr[4];
  155678. tmp13 = wsptr[2] + wsptr[6];
  155679. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155680. tmp0 = tmp10 + tmp13;
  155681. tmp3 = tmp10 - tmp13;
  155682. tmp1 = tmp11 + tmp12;
  155683. tmp2 = tmp11 - tmp12;
  155684. z13 = wsptr[5] + wsptr[3];
  155685. z10 = wsptr[5] - wsptr[3];
  155686. z11 = wsptr[1] + wsptr[7];
  155687. z12 = wsptr[1] - wsptr[7];
  155688. tmp7 = z11 + z13;
  155689. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155690. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155691. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155692. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155693. tmp6 = tmp12 - tmp7;
  155694. tmp5 = tmp11 - tmp6;
  155695. tmp4 = tmp10 + tmp5;
  155696. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155697. & RANGE_MASK];
  155698. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155699. & RANGE_MASK];
  155700. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155701. & RANGE_MASK];
  155702. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155703. & RANGE_MASK];
  155704. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155705. & RANGE_MASK];
  155706. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155707. & RANGE_MASK];
  155708. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155709. & RANGE_MASK];
  155710. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155711. & RANGE_MASK];
  155712. wsptr += DCTSIZE; /* advance pointer to next row */
  155713. }
  155714. }
  155715. #endif /* DCT_FLOAT_SUPPORTED */
  155716. /*** End of inlined file: jidctflt.c ***/
  155717. #undef CONST_BITS
  155718. #undef FIX_1_847759065
  155719. #undef MULTIPLY
  155720. #undef DEQUANTIZE
  155721. #undef DESCALE
  155722. /*** Start of inlined file: jidctfst.c ***/
  155723. #define JPEG_INTERNALS
  155724. #ifdef DCT_IFAST_SUPPORTED
  155725. #if DCTSIZE != 8
  155726. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155727. #endif
  155728. #if BITS_IN_JSAMPLE == 8
  155729. #define CONST_BITS 8
  155730. #define PASS1_BITS 2
  155731. #else
  155732. #define CONST_BITS 8
  155733. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155734. #endif
  155735. #if CONST_BITS == 8
  155736. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155737. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155738. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155739. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155740. #else
  155741. #define FIX_1_082392200 FIX(1.082392200)
  155742. #define FIX_1_414213562 FIX(1.414213562)
  155743. #define FIX_1_847759065 FIX(1.847759065)
  155744. #define FIX_2_613125930 FIX(2.613125930)
  155745. #endif
  155746. #ifndef USE_ACCURATE_ROUNDING
  155747. #undef DESCALE
  155748. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155749. #endif
  155750. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155751. #if BITS_IN_JSAMPLE == 8
  155752. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155753. #else
  155754. #define DEQUANTIZE(coef,quantval) \
  155755. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155756. #endif
  155757. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155758. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155759. #if BITS_IN_JSAMPLE == 8
  155760. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155761. #else
  155762. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155763. #endif
  155764. #define IRIGHT_SHIFT(x,shft) \
  155765. ((ishift_temp = (x)) < 0 ? \
  155766. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155767. (ishift_temp >> (shft)))
  155768. #else
  155769. #define ISHIFT_TEMPS
  155770. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155771. #endif
  155772. #ifdef USE_ACCURATE_ROUNDING
  155773. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155774. #else
  155775. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155776. #endif
  155777. GLOBAL(void)
  155778. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155779. JCOEFPTR coef_block,
  155780. JSAMPARRAY output_buf, JDIMENSION output_col)
  155781. {
  155782. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155783. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155784. DCTELEM z5, z10, z11, z12, z13;
  155785. JCOEFPTR inptr;
  155786. IFAST_MULT_TYPE * quantptr;
  155787. int * wsptr;
  155788. JSAMPROW outptr;
  155789. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155790. int ctr;
  155791. int workspace[DCTSIZE2]; /* buffers data between passes */
  155792. SHIFT_TEMPS /* for DESCALE */
  155793. ISHIFT_TEMPS /* for IDESCALE */
  155794. inptr = coef_block;
  155795. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155796. wsptr = workspace;
  155797. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155798. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155799. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155800. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155801. inptr[DCTSIZE*7] == 0) {
  155802. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155803. wsptr[DCTSIZE*0] = dcval;
  155804. wsptr[DCTSIZE*1] = dcval;
  155805. wsptr[DCTSIZE*2] = dcval;
  155806. wsptr[DCTSIZE*3] = dcval;
  155807. wsptr[DCTSIZE*4] = dcval;
  155808. wsptr[DCTSIZE*5] = dcval;
  155809. wsptr[DCTSIZE*6] = dcval;
  155810. wsptr[DCTSIZE*7] = dcval;
  155811. inptr++; /* advance pointers to next column */
  155812. quantptr++;
  155813. wsptr++;
  155814. continue;
  155815. }
  155816. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155817. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155818. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155819. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155820. tmp10 = tmp0 + tmp2; /* phase 3 */
  155821. tmp11 = tmp0 - tmp2;
  155822. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155823. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155824. tmp0 = tmp10 + tmp13; /* phase 2 */
  155825. tmp3 = tmp10 - tmp13;
  155826. tmp1 = tmp11 + tmp12;
  155827. tmp2 = tmp11 - tmp12;
  155828. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155829. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155830. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155831. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155832. z13 = tmp6 + tmp5; /* phase 6 */
  155833. z10 = tmp6 - tmp5;
  155834. z11 = tmp4 + tmp7;
  155835. z12 = tmp4 - tmp7;
  155836. tmp7 = z11 + z13; /* phase 5 */
  155837. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155838. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155839. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155840. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155841. tmp6 = tmp12 - tmp7; /* phase 2 */
  155842. tmp5 = tmp11 - tmp6;
  155843. tmp4 = tmp10 + tmp5;
  155844. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155845. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155846. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155847. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155848. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155849. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155850. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155851. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155852. inptr++; /* advance pointers to next column */
  155853. quantptr++;
  155854. wsptr++;
  155855. }
  155856. wsptr = workspace;
  155857. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155858. outptr = output_buf[ctr] + output_col;
  155859. #ifndef NO_ZERO_ROW_TEST
  155860. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155861. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155862. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155863. & RANGE_MASK];
  155864. outptr[0] = dcval;
  155865. outptr[1] = dcval;
  155866. outptr[2] = dcval;
  155867. outptr[3] = dcval;
  155868. outptr[4] = dcval;
  155869. outptr[5] = dcval;
  155870. outptr[6] = dcval;
  155871. outptr[7] = dcval;
  155872. wsptr += DCTSIZE; /* advance pointer to next row */
  155873. continue;
  155874. }
  155875. #endif
  155876. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155877. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155878. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155879. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155880. - tmp13;
  155881. tmp0 = tmp10 + tmp13;
  155882. tmp3 = tmp10 - tmp13;
  155883. tmp1 = tmp11 + tmp12;
  155884. tmp2 = tmp11 - tmp12;
  155885. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155886. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155887. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155888. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155889. tmp7 = z11 + z13; /* phase 5 */
  155890. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155891. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155892. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155893. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155894. tmp6 = tmp12 - tmp7; /* phase 2 */
  155895. tmp5 = tmp11 - tmp6;
  155896. tmp4 = tmp10 + tmp5;
  155897. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155898. & RANGE_MASK];
  155899. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155900. & RANGE_MASK];
  155901. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155902. & RANGE_MASK];
  155903. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155904. & RANGE_MASK];
  155905. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155906. & RANGE_MASK];
  155907. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155908. & RANGE_MASK];
  155909. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155910. & RANGE_MASK];
  155911. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155912. & RANGE_MASK];
  155913. wsptr += DCTSIZE; /* advance pointer to next row */
  155914. }
  155915. }
  155916. #endif /* DCT_IFAST_SUPPORTED */
  155917. /*** End of inlined file: jidctfst.c ***/
  155918. #undef CONST_BITS
  155919. #undef FIX_1_847759065
  155920. #undef MULTIPLY
  155921. #undef DEQUANTIZE
  155922. /*** Start of inlined file: jidctint.c ***/
  155923. #define JPEG_INTERNALS
  155924. #ifdef DCT_ISLOW_SUPPORTED
  155925. #if DCTSIZE != 8
  155926. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155927. #endif
  155928. #if BITS_IN_JSAMPLE == 8
  155929. #define CONST_BITS 13
  155930. #define PASS1_BITS 2
  155931. #else
  155932. #define CONST_BITS 13
  155933. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155934. #endif
  155935. #if CONST_BITS == 13
  155936. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155937. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155938. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155939. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155940. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155941. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155942. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155943. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155944. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155945. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155946. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155947. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155948. #else
  155949. #define FIX_0_298631336 FIX(0.298631336)
  155950. #define FIX_0_390180644 FIX(0.390180644)
  155951. #define FIX_0_541196100 FIX(0.541196100)
  155952. #define FIX_0_765366865 FIX(0.765366865)
  155953. #define FIX_0_899976223 FIX(0.899976223)
  155954. #define FIX_1_175875602 FIX(1.175875602)
  155955. #define FIX_1_501321110 FIX(1.501321110)
  155956. #define FIX_1_847759065 FIX(1.847759065)
  155957. #define FIX_1_961570560 FIX(1.961570560)
  155958. #define FIX_2_053119869 FIX(2.053119869)
  155959. #define FIX_2_562915447 FIX(2.562915447)
  155960. #define FIX_3_072711026 FIX(3.072711026)
  155961. #endif
  155962. #if BITS_IN_JSAMPLE == 8
  155963. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155964. #else
  155965. #define MULTIPLY(var,const) ((var) * (const))
  155966. #endif
  155967. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155968. GLOBAL(void)
  155969. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155970. JCOEFPTR coef_block,
  155971. JSAMPARRAY output_buf, JDIMENSION output_col)
  155972. {
  155973. INT32 tmp0, tmp1, tmp2, tmp3;
  155974. INT32 tmp10, tmp11, tmp12, tmp13;
  155975. INT32 z1, z2, z3, z4, z5;
  155976. JCOEFPTR inptr;
  155977. ISLOW_MULT_TYPE * quantptr;
  155978. int * wsptr;
  155979. JSAMPROW outptr;
  155980. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155981. int ctr;
  155982. int workspace[DCTSIZE2]; /* buffers data between passes */
  155983. SHIFT_TEMPS
  155984. inptr = coef_block;
  155985. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155986. wsptr = workspace;
  155987. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155988. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155989. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155990. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155991. inptr[DCTSIZE*7] == 0) {
  155992. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155993. wsptr[DCTSIZE*0] = dcval;
  155994. wsptr[DCTSIZE*1] = dcval;
  155995. wsptr[DCTSIZE*2] = dcval;
  155996. wsptr[DCTSIZE*3] = dcval;
  155997. wsptr[DCTSIZE*4] = dcval;
  155998. wsptr[DCTSIZE*5] = dcval;
  155999. wsptr[DCTSIZE*6] = dcval;
  156000. wsptr[DCTSIZE*7] = dcval;
  156001. inptr++; /* advance pointers to next column */
  156002. quantptr++;
  156003. wsptr++;
  156004. continue;
  156005. }
  156006. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156007. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156008. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156009. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156010. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156011. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156012. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156013. tmp0 = (z2 + z3) << CONST_BITS;
  156014. tmp1 = (z2 - z3) << CONST_BITS;
  156015. tmp10 = tmp0 + tmp3;
  156016. tmp13 = tmp0 - tmp3;
  156017. tmp11 = tmp1 + tmp2;
  156018. tmp12 = tmp1 - tmp2;
  156019. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156020. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156021. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156022. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156023. z1 = tmp0 + tmp3;
  156024. z2 = tmp1 + tmp2;
  156025. z3 = tmp0 + tmp2;
  156026. z4 = tmp1 + tmp3;
  156027. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156028. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156029. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156030. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156031. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156032. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156033. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156034. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156035. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156036. z3 += z5;
  156037. z4 += z5;
  156038. tmp0 += z1 + z3;
  156039. tmp1 += z2 + z4;
  156040. tmp2 += z2 + z3;
  156041. tmp3 += z1 + z4;
  156042. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  156043. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  156044. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  156045. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  156046. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  156047. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  156048. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  156049. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  156050. inptr++; /* advance pointers to next column */
  156051. quantptr++;
  156052. wsptr++;
  156053. }
  156054. wsptr = workspace;
  156055. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156056. outptr = output_buf[ctr] + output_col;
  156057. #ifndef NO_ZERO_ROW_TEST
  156058. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  156059. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156060. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156061. & RANGE_MASK];
  156062. outptr[0] = dcval;
  156063. outptr[1] = dcval;
  156064. outptr[2] = dcval;
  156065. outptr[3] = dcval;
  156066. outptr[4] = dcval;
  156067. outptr[5] = dcval;
  156068. outptr[6] = dcval;
  156069. outptr[7] = dcval;
  156070. wsptr += DCTSIZE; /* advance pointer to next row */
  156071. continue;
  156072. }
  156073. #endif
  156074. z2 = (INT32) wsptr[2];
  156075. z3 = (INT32) wsptr[6];
  156076. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156077. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156078. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156079. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  156080. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  156081. tmp10 = tmp0 + tmp3;
  156082. tmp13 = tmp0 - tmp3;
  156083. tmp11 = tmp1 + tmp2;
  156084. tmp12 = tmp1 - tmp2;
  156085. tmp0 = (INT32) wsptr[7];
  156086. tmp1 = (INT32) wsptr[5];
  156087. tmp2 = (INT32) wsptr[3];
  156088. tmp3 = (INT32) wsptr[1];
  156089. z1 = tmp0 + tmp3;
  156090. z2 = tmp1 + tmp2;
  156091. z3 = tmp0 + tmp2;
  156092. z4 = tmp1 + tmp3;
  156093. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156094. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156095. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156096. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156097. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156098. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156099. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156100. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156101. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156102. z3 += z5;
  156103. z4 += z5;
  156104. tmp0 += z1 + z3;
  156105. tmp1 += z2 + z4;
  156106. tmp2 += z2 + z3;
  156107. tmp3 += z1 + z4;
  156108. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  156109. CONST_BITS+PASS1_BITS+3)
  156110. & RANGE_MASK];
  156111. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  156112. CONST_BITS+PASS1_BITS+3)
  156113. & RANGE_MASK];
  156114. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  156115. CONST_BITS+PASS1_BITS+3)
  156116. & RANGE_MASK];
  156117. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  156118. CONST_BITS+PASS1_BITS+3)
  156119. & RANGE_MASK];
  156120. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  156121. CONST_BITS+PASS1_BITS+3)
  156122. & RANGE_MASK];
  156123. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  156124. CONST_BITS+PASS1_BITS+3)
  156125. & RANGE_MASK];
  156126. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  156127. CONST_BITS+PASS1_BITS+3)
  156128. & RANGE_MASK];
  156129. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  156130. CONST_BITS+PASS1_BITS+3)
  156131. & RANGE_MASK];
  156132. wsptr += DCTSIZE; /* advance pointer to next row */
  156133. }
  156134. }
  156135. #endif /* DCT_ISLOW_SUPPORTED */
  156136. /*** End of inlined file: jidctint.c ***/
  156137. /*** Start of inlined file: jidctred.c ***/
  156138. #define JPEG_INTERNALS
  156139. #ifdef IDCT_SCALING_SUPPORTED
  156140. #if DCTSIZE != 8
  156141. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156142. #endif
  156143. #if BITS_IN_JSAMPLE == 8
  156144. #define CONST_BITS 13
  156145. #define PASS1_BITS 2
  156146. #else
  156147. #define CONST_BITS 13
  156148. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156149. #endif
  156150. #if CONST_BITS == 13
  156151. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  156152. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  156153. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  156154. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  156155. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156156. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  156157. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156158. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  156159. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  156160. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  156161. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156162. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  156163. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156164. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  156165. #else
  156166. #define FIX_0_211164243 FIX(0.211164243)
  156167. #define FIX_0_509795579 FIX(0.509795579)
  156168. #define FIX_0_601344887 FIX(0.601344887)
  156169. #define FIX_0_720959822 FIX(0.720959822)
  156170. #define FIX_0_765366865 FIX(0.765366865)
  156171. #define FIX_0_850430095 FIX(0.850430095)
  156172. #define FIX_0_899976223 FIX(0.899976223)
  156173. #define FIX_1_061594337 FIX(1.061594337)
  156174. #define FIX_1_272758580 FIX(1.272758580)
  156175. #define FIX_1_451774981 FIX(1.451774981)
  156176. #define FIX_1_847759065 FIX(1.847759065)
  156177. #define FIX_2_172734803 FIX(2.172734803)
  156178. #define FIX_2_562915447 FIX(2.562915447)
  156179. #define FIX_3_624509785 FIX(3.624509785)
  156180. #endif
  156181. #if BITS_IN_JSAMPLE == 8
  156182. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156183. #else
  156184. #define MULTIPLY(var,const) ((var) * (const))
  156185. #endif
  156186. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156187. GLOBAL(void)
  156188. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156189. JCOEFPTR coef_block,
  156190. JSAMPARRAY output_buf, JDIMENSION output_col)
  156191. {
  156192. INT32 tmp0, tmp2, tmp10, tmp12;
  156193. INT32 z1, z2, z3, z4;
  156194. JCOEFPTR inptr;
  156195. ISLOW_MULT_TYPE * quantptr;
  156196. int * wsptr;
  156197. JSAMPROW outptr;
  156198. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156199. int ctr;
  156200. int workspace[DCTSIZE*4]; /* buffers data between passes */
  156201. SHIFT_TEMPS
  156202. inptr = coef_block;
  156203. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156204. wsptr = workspace;
  156205. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156206. if (ctr == DCTSIZE-4)
  156207. continue;
  156208. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156209. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  156210. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  156211. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156212. wsptr[DCTSIZE*0] = dcval;
  156213. wsptr[DCTSIZE*1] = dcval;
  156214. wsptr[DCTSIZE*2] = dcval;
  156215. wsptr[DCTSIZE*3] = dcval;
  156216. continue;
  156217. }
  156218. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156219. tmp0 <<= (CONST_BITS+1);
  156220. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156221. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156222. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  156223. tmp10 = tmp0 + tmp2;
  156224. tmp12 = tmp0 - tmp2;
  156225. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156226. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156227. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156228. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156229. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156230. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156231. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156232. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156233. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156234. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156235. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156236. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156237. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  156238. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  156239. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  156240. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  156241. }
  156242. wsptr = workspace;
  156243. for (ctr = 0; ctr < 4; ctr++) {
  156244. outptr = output_buf[ctr] + output_col;
  156245. #ifndef NO_ZERO_ROW_TEST
  156246. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  156247. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156248. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156249. & RANGE_MASK];
  156250. outptr[0] = dcval;
  156251. outptr[1] = dcval;
  156252. outptr[2] = dcval;
  156253. outptr[3] = dcval;
  156254. wsptr += DCTSIZE; /* advance pointer to next row */
  156255. continue;
  156256. }
  156257. #endif
  156258. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  156259. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  156260. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  156261. tmp10 = tmp0 + tmp2;
  156262. tmp12 = tmp0 - tmp2;
  156263. z1 = (INT32) wsptr[7];
  156264. z2 = (INT32) wsptr[5];
  156265. z3 = (INT32) wsptr[3];
  156266. z4 = (INT32) wsptr[1];
  156267. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156268. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156269. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156270. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156271. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156272. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156273. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156274. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156275. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  156276. CONST_BITS+PASS1_BITS+3+1)
  156277. & RANGE_MASK];
  156278. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  156279. CONST_BITS+PASS1_BITS+3+1)
  156280. & RANGE_MASK];
  156281. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  156282. CONST_BITS+PASS1_BITS+3+1)
  156283. & RANGE_MASK];
  156284. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  156285. CONST_BITS+PASS1_BITS+3+1)
  156286. & RANGE_MASK];
  156287. wsptr += DCTSIZE; /* advance pointer to next row */
  156288. }
  156289. }
  156290. GLOBAL(void)
  156291. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156292. JCOEFPTR coef_block,
  156293. JSAMPARRAY output_buf, JDIMENSION output_col)
  156294. {
  156295. INT32 tmp0, tmp10, z1;
  156296. JCOEFPTR inptr;
  156297. ISLOW_MULT_TYPE * quantptr;
  156298. int * wsptr;
  156299. JSAMPROW outptr;
  156300. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156301. int ctr;
  156302. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156303. SHIFT_TEMPS
  156304. inptr = coef_block;
  156305. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156306. wsptr = workspace;
  156307. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156308. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156309. continue;
  156310. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156311. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156312. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156313. wsptr[DCTSIZE*0] = dcval;
  156314. wsptr[DCTSIZE*1] = dcval;
  156315. continue;
  156316. }
  156317. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156318. tmp10 = z1 << (CONST_BITS+2);
  156319. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156320. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156321. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156322. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156323. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156324. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156325. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156326. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156327. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156328. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156329. }
  156330. wsptr = workspace;
  156331. for (ctr = 0; ctr < 2; ctr++) {
  156332. outptr = output_buf[ctr] + output_col;
  156333. #ifndef NO_ZERO_ROW_TEST
  156334. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156335. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156336. & RANGE_MASK];
  156337. outptr[0] = dcval;
  156338. outptr[1] = dcval;
  156339. wsptr += DCTSIZE; /* advance pointer to next row */
  156340. continue;
  156341. }
  156342. #endif
  156343. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156344. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156345. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156346. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156347. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156348. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156349. CONST_BITS+PASS1_BITS+3+2)
  156350. & RANGE_MASK];
  156351. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156352. CONST_BITS+PASS1_BITS+3+2)
  156353. & RANGE_MASK];
  156354. wsptr += DCTSIZE; /* advance pointer to next row */
  156355. }
  156356. }
  156357. GLOBAL(void)
  156358. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156359. JCOEFPTR coef_block,
  156360. JSAMPARRAY output_buf, JDIMENSION output_col)
  156361. {
  156362. int dcval;
  156363. ISLOW_MULT_TYPE * quantptr;
  156364. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156365. SHIFT_TEMPS
  156366. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156367. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156368. dcval = (int) DESCALE((INT32) dcval, 3);
  156369. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156370. }
  156371. #endif /* IDCT_SCALING_SUPPORTED */
  156372. /*** End of inlined file: jidctred.c ***/
  156373. /*** Start of inlined file: jmemmgr.c ***/
  156374. #define JPEG_INTERNALS
  156375. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156376. /*** Start of inlined file: jmemsys.h ***/
  156377. #ifndef __jmemsys_h__
  156378. #define __jmemsys_h__
  156379. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156380. #define jpeg_get_small jGetSmall
  156381. #define jpeg_free_small jFreeSmall
  156382. #define jpeg_get_large jGetLarge
  156383. #define jpeg_free_large jFreeLarge
  156384. #define jpeg_mem_available jMemAvail
  156385. #define jpeg_open_backing_store jOpenBackStore
  156386. #define jpeg_mem_init jMemInit
  156387. #define jpeg_mem_term jMemTerm
  156388. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156389. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156390. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156391. size_t sizeofobject));
  156392. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156393. size_t sizeofobject));
  156394. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156395. size_t sizeofobject));
  156396. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156397. #define MAX_ALLOC_CHUNK 1000000000L
  156398. #endif
  156399. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156400. long min_bytes_needed,
  156401. long max_bytes_needed,
  156402. long already_allocated));
  156403. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156404. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156405. typedef unsigned short XMSH; /* type of extended-memory handles */
  156406. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156407. typedef union {
  156408. short file_handle; /* DOS file handle if it's a temp file */
  156409. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156410. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156411. } handle_union;
  156412. #endif /* USE_MSDOS_MEMMGR */
  156413. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156414. #include <Files.h>
  156415. #endif /* USE_MAC_MEMMGR */
  156416. //typedef struct backing_store_struct * backing_store_ptr;
  156417. typedef struct backing_store_struct {
  156418. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156419. struct backing_store_struct *info,
  156420. void FAR * buffer_address,
  156421. long file_offset, long byte_count));
  156422. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156423. struct backing_store_struct *info,
  156424. void FAR * buffer_address,
  156425. long file_offset, long byte_count));
  156426. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156427. struct backing_store_struct *info));
  156428. #ifdef USE_MSDOS_MEMMGR
  156429. handle_union handle; /* reference to backing-store storage object */
  156430. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156431. #else
  156432. #ifdef USE_MAC_MEMMGR
  156433. short temp_file; /* file reference number to temp file */
  156434. FSSpec tempSpec; /* the FSSpec for the temp file */
  156435. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156436. #else
  156437. FILE * temp_file; /* stdio reference to temp file */
  156438. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156439. #endif
  156440. #endif
  156441. } backing_store_info;
  156442. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156443. struct backing_store_struct *info,
  156444. long total_bytes_needed));
  156445. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156446. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156447. #endif
  156448. /*** End of inlined file: jmemsys.h ***/
  156449. /* import the system-dependent declarations */
  156450. #ifndef NO_GETENV
  156451. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156452. extern char * getenv JPP((const char * name));
  156453. #endif
  156454. #endif
  156455. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156456. #define ALIGN_TYPE double
  156457. #endif
  156458. typedef union small_pool_struct * small_pool_ptr;
  156459. typedef union small_pool_struct {
  156460. struct {
  156461. small_pool_ptr next; /* next in list of pools */
  156462. size_t bytes_used; /* how many bytes already used within pool */
  156463. size_t bytes_left; /* bytes still available in this pool */
  156464. } hdr;
  156465. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156466. } small_pool_hdr;
  156467. typedef union large_pool_struct FAR * large_pool_ptr;
  156468. typedef union large_pool_struct {
  156469. struct {
  156470. large_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. } large_pool_hdr;
  156476. typedef struct {
  156477. struct jpeg_memory_mgr pub; /* public fields */
  156478. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156479. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156480. jvirt_sarray_ptr virt_sarray_list;
  156481. jvirt_barray_ptr virt_barray_list;
  156482. long total_space_allocated;
  156483. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156484. } my_memory_mgr;
  156485. typedef my_memory_mgr * my_mem_ptr;
  156486. struct jvirt_sarray_control {
  156487. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156488. JDIMENSION rows_in_array; /* total virtual array height */
  156489. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156490. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156491. JDIMENSION rows_in_mem; /* height of memory buffer */
  156492. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156493. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156494. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156495. boolean pre_zero; /* pre-zero mode requested? */
  156496. boolean dirty; /* do current buffer contents need written? */
  156497. boolean b_s_open; /* is backing-store data valid? */
  156498. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156499. backing_store_info b_s_info; /* System-dependent control info */
  156500. };
  156501. struct jvirt_barray_control {
  156502. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156503. JDIMENSION rows_in_array; /* total virtual array height */
  156504. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156505. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156506. JDIMENSION rows_in_mem; /* height of memory buffer */
  156507. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156508. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156509. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156510. boolean pre_zero; /* pre-zero mode requested? */
  156511. boolean dirty; /* do current buffer contents need written? */
  156512. boolean b_s_open; /* is backing-store data valid? */
  156513. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156514. backing_store_info b_s_info; /* System-dependent control info */
  156515. };
  156516. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156517. LOCAL(void)
  156518. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156519. {
  156520. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156521. small_pool_ptr shdr_ptr;
  156522. large_pool_ptr lhdr_ptr;
  156523. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156524. pool_id, mem->total_space_allocated);
  156525. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156526. lhdr_ptr = lhdr_ptr->hdr.next) {
  156527. fprintf(stderr, " Large chunk used %ld\n",
  156528. (long) lhdr_ptr->hdr.bytes_used);
  156529. }
  156530. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156531. shdr_ptr = shdr_ptr->hdr.next) {
  156532. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156533. (long) shdr_ptr->hdr.bytes_used,
  156534. (long) shdr_ptr->hdr.bytes_left);
  156535. }
  156536. }
  156537. #endif /* MEM_STATS */
  156538. LOCAL(void)
  156539. out_of_memory (j_common_ptr cinfo, int which)
  156540. {
  156541. #ifdef MEM_STATS
  156542. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156543. #endif
  156544. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156545. }
  156546. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156547. {
  156548. 1600, /* first PERMANENT pool */
  156549. 16000 /* first IMAGE pool */
  156550. };
  156551. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156552. {
  156553. 0, /* additional PERMANENT pools */
  156554. 5000 /* additional IMAGE pools */
  156555. };
  156556. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156557. METHODDEF(void *)
  156558. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156559. {
  156560. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156561. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156562. char * data_ptr;
  156563. size_t odd_bytes, min_request, slop;
  156564. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156565. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156566. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156567. if (odd_bytes > 0)
  156568. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156569. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156570. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156571. prev_hdr_ptr = NULL;
  156572. hdr_ptr = mem->small_list[pool_id];
  156573. while (hdr_ptr != NULL) {
  156574. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156575. break; /* found pool with enough space */
  156576. prev_hdr_ptr = hdr_ptr;
  156577. hdr_ptr = hdr_ptr->hdr.next;
  156578. }
  156579. if (hdr_ptr == NULL) {
  156580. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156581. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156582. slop = first_pool_slop[pool_id];
  156583. else
  156584. slop = extra_pool_slop[pool_id];
  156585. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156586. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156587. for (;;) {
  156588. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156589. if (hdr_ptr != NULL)
  156590. break;
  156591. slop /= 2;
  156592. if (slop < MIN_SLOP) /* give up when it gets real small */
  156593. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156594. }
  156595. mem->total_space_allocated += min_request + slop;
  156596. hdr_ptr->hdr.next = NULL;
  156597. hdr_ptr->hdr.bytes_used = 0;
  156598. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156599. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156600. mem->small_list[pool_id] = hdr_ptr;
  156601. else
  156602. prev_hdr_ptr->hdr.next = hdr_ptr;
  156603. }
  156604. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156605. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156606. hdr_ptr->hdr.bytes_used += sizeofobject;
  156607. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156608. return (void *) data_ptr;
  156609. }
  156610. METHODDEF(void FAR *)
  156611. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156612. {
  156613. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156614. large_pool_ptr hdr_ptr;
  156615. size_t odd_bytes;
  156616. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156617. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156618. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156619. if (odd_bytes > 0)
  156620. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156621. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156622. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156623. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156624. SIZEOF(large_pool_hdr));
  156625. if (hdr_ptr == NULL)
  156626. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156627. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156628. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156629. hdr_ptr->hdr.bytes_used = sizeofobject;
  156630. hdr_ptr->hdr.bytes_left = 0;
  156631. mem->large_list[pool_id] = hdr_ptr;
  156632. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156633. }
  156634. METHODDEF(JSAMPARRAY)
  156635. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156636. JDIMENSION samplesperrow, JDIMENSION numrows)
  156637. {
  156638. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156639. JSAMPARRAY result;
  156640. JSAMPROW workspace;
  156641. JDIMENSION rowsperchunk, currow, i;
  156642. long ltemp;
  156643. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156644. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156645. if (ltemp <= 0)
  156646. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156647. if (ltemp < (long) numrows)
  156648. rowsperchunk = (JDIMENSION) ltemp;
  156649. else
  156650. rowsperchunk = numrows;
  156651. mem->last_rowsperchunk = rowsperchunk;
  156652. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156653. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156654. currow = 0;
  156655. while (currow < numrows) {
  156656. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156657. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156658. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156659. * SIZEOF(JSAMPLE)));
  156660. for (i = rowsperchunk; i > 0; i--) {
  156661. result[currow++] = workspace;
  156662. workspace += samplesperrow;
  156663. }
  156664. }
  156665. return result;
  156666. }
  156667. METHODDEF(JBLOCKARRAY)
  156668. alloc_barray (j_common_ptr cinfo, int pool_id,
  156669. JDIMENSION blocksperrow, JDIMENSION numrows)
  156670. {
  156671. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156672. JBLOCKARRAY result;
  156673. JBLOCKROW workspace;
  156674. JDIMENSION rowsperchunk, currow, i;
  156675. long ltemp;
  156676. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156677. ((long) blocksperrow * SIZEOF(JBLOCK));
  156678. if (ltemp <= 0)
  156679. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156680. if (ltemp < (long) numrows)
  156681. rowsperchunk = (JDIMENSION) ltemp;
  156682. else
  156683. rowsperchunk = numrows;
  156684. mem->last_rowsperchunk = rowsperchunk;
  156685. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156686. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156687. currow = 0;
  156688. while (currow < numrows) {
  156689. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156690. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156691. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156692. * SIZEOF(JBLOCK)));
  156693. for (i = rowsperchunk; i > 0; i--) {
  156694. result[currow++] = workspace;
  156695. workspace += blocksperrow;
  156696. }
  156697. }
  156698. return result;
  156699. }
  156700. METHODDEF(jvirt_sarray_ptr)
  156701. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156702. JDIMENSION samplesperrow, JDIMENSION numrows,
  156703. JDIMENSION maxaccess)
  156704. {
  156705. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156706. jvirt_sarray_ptr result;
  156707. if (pool_id != JPOOL_IMAGE)
  156708. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156709. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156710. SIZEOF(struct jvirt_sarray_control));
  156711. result->mem_buffer = NULL; /* marks array not yet realized */
  156712. result->rows_in_array = numrows;
  156713. result->samplesperrow = samplesperrow;
  156714. result->maxaccess = maxaccess;
  156715. result->pre_zero = pre_zero;
  156716. result->b_s_open = FALSE; /* no associated backing-store object */
  156717. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156718. mem->virt_sarray_list = result;
  156719. return result;
  156720. }
  156721. METHODDEF(jvirt_barray_ptr)
  156722. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156723. JDIMENSION blocksperrow, JDIMENSION numrows,
  156724. JDIMENSION maxaccess)
  156725. {
  156726. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156727. jvirt_barray_ptr result;
  156728. if (pool_id != JPOOL_IMAGE)
  156729. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156730. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156731. SIZEOF(struct jvirt_barray_control));
  156732. result->mem_buffer = NULL; /* marks array not yet realized */
  156733. result->rows_in_array = numrows;
  156734. result->blocksperrow = blocksperrow;
  156735. result->maxaccess = maxaccess;
  156736. result->pre_zero = pre_zero;
  156737. result->b_s_open = FALSE; /* no associated backing-store object */
  156738. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156739. mem->virt_barray_list = result;
  156740. return result;
  156741. }
  156742. METHODDEF(void)
  156743. realize_virt_arrays (j_common_ptr cinfo)
  156744. {
  156745. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156746. long space_per_minheight, maximum_space, avail_mem;
  156747. long minheights, max_minheights;
  156748. jvirt_sarray_ptr sptr;
  156749. jvirt_barray_ptr bptr;
  156750. space_per_minheight = 0;
  156751. maximum_space = 0;
  156752. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156753. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156754. space_per_minheight += (long) sptr->maxaccess *
  156755. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156756. maximum_space += (long) sptr->rows_in_array *
  156757. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156758. }
  156759. }
  156760. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156761. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156762. space_per_minheight += (long) bptr->maxaccess *
  156763. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156764. maximum_space += (long) bptr->rows_in_array *
  156765. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156766. }
  156767. }
  156768. if (space_per_minheight <= 0)
  156769. return; /* no unrealized arrays, no work */
  156770. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156771. mem->total_space_allocated);
  156772. if (avail_mem >= maximum_space)
  156773. max_minheights = 1000000000L;
  156774. else {
  156775. max_minheights = avail_mem / space_per_minheight;
  156776. if (max_minheights <= 0)
  156777. max_minheights = 1;
  156778. }
  156779. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156780. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156781. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156782. if (minheights <= max_minheights) {
  156783. sptr->rows_in_mem = sptr->rows_in_array;
  156784. } else {
  156785. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156786. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156787. (long) sptr->rows_in_array *
  156788. (long) sptr->samplesperrow *
  156789. (long) SIZEOF(JSAMPLE));
  156790. sptr->b_s_open = TRUE;
  156791. }
  156792. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156793. sptr->samplesperrow, sptr->rows_in_mem);
  156794. sptr->rowsperchunk = mem->last_rowsperchunk;
  156795. sptr->cur_start_row = 0;
  156796. sptr->first_undef_row = 0;
  156797. sptr->dirty = FALSE;
  156798. }
  156799. }
  156800. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156801. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156802. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156803. if (minheights <= max_minheights) {
  156804. bptr->rows_in_mem = bptr->rows_in_array;
  156805. } else {
  156806. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156807. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156808. (long) bptr->rows_in_array *
  156809. (long) bptr->blocksperrow *
  156810. (long) SIZEOF(JBLOCK));
  156811. bptr->b_s_open = TRUE;
  156812. }
  156813. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156814. bptr->blocksperrow, bptr->rows_in_mem);
  156815. bptr->rowsperchunk = mem->last_rowsperchunk;
  156816. bptr->cur_start_row = 0;
  156817. bptr->first_undef_row = 0;
  156818. bptr->dirty = FALSE;
  156819. }
  156820. }
  156821. }
  156822. LOCAL(void)
  156823. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156824. {
  156825. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156826. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156827. file_offset = ptr->cur_start_row * bytesperrow;
  156828. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156829. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156830. thisrow = (long) ptr->cur_start_row + i;
  156831. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156832. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156833. if (rows <= 0) /* this chunk might be past end of file! */
  156834. break;
  156835. byte_count = rows * bytesperrow;
  156836. if (writing)
  156837. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156838. (void FAR *) ptr->mem_buffer[i],
  156839. file_offset, byte_count);
  156840. else
  156841. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156842. (void FAR *) ptr->mem_buffer[i],
  156843. file_offset, byte_count);
  156844. file_offset += byte_count;
  156845. }
  156846. }
  156847. LOCAL(void)
  156848. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156849. {
  156850. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156851. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156852. file_offset = ptr->cur_start_row * bytesperrow;
  156853. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156854. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156855. thisrow = (long) ptr->cur_start_row + i;
  156856. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156857. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156858. if (rows <= 0) /* this chunk might be past end of file! */
  156859. break;
  156860. byte_count = rows * bytesperrow;
  156861. if (writing)
  156862. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156863. (void FAR *) ptr->mem_buffer[i],
  156864. file_offset, byte_count);
  156865. else
  156866. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156867. (void FAR *) ptr->mem_buffer[i],
  156868. file_offset, byte_count);
  156869. file_offset += byte_count;
  156870. }
  156871. }
  156872. METHODDEF(JSAMPARRAY)
  156873. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156874. JDIMENSION start_row, JDIMENSION num_rows,
  156875. boolean writable)
  156876. {
  156877. JDIMENSION end_row = start_row + num_rows;
  156878. JDIMENSION undef_row;
  156879. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156880. ptr->mem_buffer == NULL)
  156881. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156882. if (start_row < ptr->cur_start_row ||
  156883. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156884. if (! ptr->b_s_open)
  156885. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156886. if (ptr->dirty) {
  156887. do_sarray_io(cinfo, ptr, TRUE);
  156888. ptr->dirty = FALSE;
  156889. }
  156890. if (start_row > ptr->cur_start_row) {
  156891. ptr->cur_start_row = start_row;
  156892. } else {
  156893. long ltemp;
  156894. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156895. if (ltemp < 0)
  156896. ltemp = 0; /* don't fall off front end of file */
  156897. ptr->cur_start_row = (JDIMENSION) ltemp;
  156898. }
  156899. do_sarray_io(cinfo, ptr, FALSE);
  156900. }
  156901. if (ptr->first_undef_row < end_row) {
  156902. if (ptr->first_undef_row < start_row) {
  156903. if (writable) /* writer skipped over a section of array */
  156904. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156905. undef_row = start_row; /* but reader is allowed to read ahead */
  156906. } else {
  156907. undef_row = ptr->first_undef_row;
  156908. }
  156909. if (writable)
  156910. ptr->first_undef_row = end_row;
  156911. if (ptr->pre_zero) {
  156912. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156913. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156914. end_row -= ptr->cur_start_row;
  156915. while (undef_row < end_row) {
  156916. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156917. undef_row++;
  156918. }
  156919. } else {
  156920. if (! writable) /* reader looking at undefined data */
  156921. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156922. }
  156923. }
  156924. if (writable)
  156925. ptr->dirty = TRUE;
  156926. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156927. }
  156928. METHODDEF(JBLOCKARRAY)
  156929. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156930. JDIMENSION start_row, JDIMENSION num_rows,
  156931. boolean writable)
  156932. {
  156933. JDIMENSION end_row = start_row + num_rows;
  156934. JDIMENSION undef_row;
  156935. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156936. ptr->mem_buffer == NULL)
  156937. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156938. if (start_row < ptr->cur_start_row ||
  156939. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156940. if (! ptr->b_s_open)
  156941. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156942. if (ptr->dirty) {
  156943. do_barray_io(cinfo, ptr, TRUE);
  156944. ptr->dirty = FALSE;
  156945. }
  156946. if (start_row > ptr->cur_start_row) {
  156947. ptr->cur_start_row = start_row;
  156948. } else {
  156949. long ltemp;
  156950. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156951. if (ltemp < 0)
  156952. ltemp = 0; /* don't fall off front end of file */
  156953. ptr->cur_start_row = (JDIMENSION) ltemp;
  156954. }
  156955. do_barray_io(cinfo, ptr, FALSE);
  156956. }
  156957. if (ptr->first_undef_row < end_row) {
  156958. if (ptr->first_undef_row < start_row) {
  156959. if (writable) /* writer skipped over a section of array */
  156960. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156961. undef_row = start_row; /* but reader is allowed to read ahead */
  156962. } else {
  156963. undef_row = ptr->first_undef_row;
  156964. }
  156965. if (writable)
  156966. ptr->first_undef_row = end_row;
  156967. if (ptr->pre_zero) {
  156968. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156969. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156970. end_row -= ptr->cur_start_row;
  156971. while (undef_row < end_row) {
  156972. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156973. undef_row++;
  156974. }
  156975. } else {
  156976. if (! writable) /* reader looking at undefined data */
  156977. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156978. }
  156979. }
  156980. if (writable)
  156981. ptr->dirty = TRUE;
  156982. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156983. }
  156984. METHODDEF(void)
  156985. free_pool (j_common_ptr cinfo, int pool_id)
  156986. {
  156987. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156988. small_pool_ptr shdr_ptr;
  156989. large_pool_ptr lhdr_ptr;
  156990. size_t space_freed;
  156991. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156992. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156993. #ifdef MEM_STATS
  156994. if (cinfo->err->trace_level > 1)
  156995. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156996. #endif
  156997. if (pool_id == JPOOL_IMAGE) {
  156998. jvirt_sarray_ptr sptr;
  156999. jvirt_barray_ptr bptr;
  157000. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157001. if (sptr->b_s_open) { /* there may be no backing store */
  157002. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  157003. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  157004. }
  157005. }
  157006. mem->virt_sarray_list = NULL;
  157007. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157008. if (bptr->b_s_open) { /* there may be no backing store */
  157009. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  157010. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  157011. }
  157012. }
  157013. mem->virt_barray_list = NULL;
  157014. }
  157015. lhdr_ptr = mem->large_list[pool_id];
  157016. mem->large_list[pool_id] = NULL;
  157017. while (lhdr_ptr != NULL) {
  157018. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  157019. space_freed = lhdr_ptr->hdr.bytes_used +
  157020. lhdr_ptr->hdr.bytes_left +
  157021. SIZEOF(large_pool_hdr);
  157022. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  157023. mem->total_space_allocated -= space_freed;
  157024. lhdr_ptr = next_lhdr_ptr;
  157025. }
  157026. shdr_ptr = mem->small_list[pool_id];
  157027. mem->small_list[pool_id] = NULL;
  157028. while (shdr_ptr != NULL) {
  157029. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  157030. space_freed = shdr_ptr->hdr.bytes_used +
  157031. shdr_ptr->hdr.bytes_left +
  157032. SIZEOF(small_pool_hdr);
  157033. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  157034. mem->total_space_allocated -= space_freed;
  157035. shdr_ptr = next_shdr_ptr;
  157036. }
  157037. }
  157038. METHODDEF(void)
  157039. self_destruct (j_common_ptr cinfo)
  157040. {
  157041. int pool;
  157042. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157043. free_pool(cinfo, pool);
  157044. }
  157045. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  157046. cinfo->mem = NULL; /* ensures I will be called only once */
  157047. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157048. }
  157049. GLOBAL(void)
  157050. jinit_memory_mgr (j_common_ptr cinfo)
  157051. {
  157052. my_mem_ptr mem;
  157053. long max_to_use;
  157054. int pool;
  157055. size_t test_mac;
  157056. cinfo->mem = NULL; /* for safety if init fails */
  157057. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  157058. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  157059. test_mac = (size_t) MAX_ALLOC_CHUNK;
  157060. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  157061. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  157062. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  157063. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  157064. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  157065. if (mem == NULL) {
  157066. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157067. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  157068. }
  157069. mem->pub.alloc_small = alloc_small;
  157070. mem->pub.alloc_large = alloc_large;
  157071. mem->pub.alloc_sarray = alloc_sarray;
  157072. mem->pub.alloc_barray = alloc_barray;
  157073. mem->pub.request_virt_sarray = request_virt_sarray;
  157074. mem->pub.request_virt_barray = request_virt_barray;
  157075. mem->pub.realize_virt_arrays = realize_virt_arrays;
  157076. mem->pub.access_virt_sarray = access_virt_sarray;
  157077. mem->pub.access_virt_barray = access_virt_barray;
  157078. mem->pub.free_pool = free_pool;
  157079. mem->pub.self_destruct = self_destruct;
  157080. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  157081. mem->pub.max_memory_to_use = max_to_use;
  157082. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157083. mem->small_list[pool] = NULL;
  157084. mem->large_list[pool] = NULL;
  157085. }
  157086. mem->virt_sarray_list = NULL;
  157087. mem->virt_barray_list = NULL;
  157088. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  157089. cinfo->mem = & mem->pub;
  157090. #ifndef NO_GETENV
  157091. { char * memenv;
  157092. if ((memenv = getenv("JPEGMEM")) != NULL) {
  157093. char ch = 'x';
  157094. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  157095. if (ch == 'm' || ch == 'M')
  157096. max_to_use *= 1000L;
  157097. mem->pub.max_memory_to_use = max_to_use * 1000L;
  157098. }
  157099. }
  157100. }
  157101. #endif
  157102. }
  157103. /*** End of inlined file: jmemmgr.c ***/
  157104. /*** Start of inlined file: jmemnobs.c ***/
  157105. #define JPEG_INTERNALS
  157106. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  157107. extern void * malloc JPP((size_t size));
  157108. extern void free JPP((void *ptr));
  157109. #endif
  157110. GLOBAL(void *)
  157111. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  157112. {
  157113. return (void *) malloc(sizeofobject);
  157114. }
  157115. GLOBAL(void)
  157116. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  157117. {
  157118. free(object);
  157119. }
  157120. GLOBAL(void FAR *)
  157121. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  157122. {
  157123. return (void FAR *) malloc(sizeofobject);
  157124. }
  157125. GLOBAL(void)
  157126. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  157127. {
  157128. free(object);
  157129. }
  157130. GLOBAL(long)
  157131. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  157132. long max_bytes_needed, long already_allocated)
  157133. {
  157134. return max_bytes_needed;
  157135. }
  157136. GLOBAL(void)
  157137. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  157138. long total_bytes_needed)
  157139. {
  157140. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  157141. }
  157142. GLOBAL(long)
  157143. jpeg_mem_init (j_common_ptr cinfo)
  157144. {
  157145. return 0; /* just set max_memory_to_use to 0 */
  157146. }
  157147. GLOBAL(void)
  157148. jpeg_mem_term (j_common_ptr cinfo)
  157149. {
  157150. }
  157151. /*** End of inlined file: jmemnobs.c ***/
  157152. /*** Start of inlined file: jquant1.c ***/
  157153. #define JPEG_INTERNALS
  157154. #ifdef QUANT_1PASS_SUPPORTED
  157155. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  157156. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  157157. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  157158. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  157159. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  157160. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  157161. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  157162. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  157163. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  157164. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  157165. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  157166. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  157167. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  157168. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  157169. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  157170. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  157171. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  157172. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  157173. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  157174. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  157175. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  157176. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  157177. };
  157178. #if BITS_IN_JSAMPLE == 8
  157179. typedef INT16 FSERROR; /* 16 bits should be enough */
  157180. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157181. #else
  157182. typedef INT32 FSERROR; /* may need more than 16 bits */
  157183. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157184. #endif
  157185. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157186. #define MAX_Q_COMPS 4 /* max components I can handle */
  157187. typedef struct {
  157188. struct jpeg_color_quantizer pub; /* public fields */
  157189. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  157190. int sv_actual; /* number of entries in use */
  157191. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  157192. boolean is_padded; /* is the colorindex padded for odither? */
  157193. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  157194. int row_index; /* cur row's vertical index in dither matrix */
  157195. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  157196. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  157197. boolean on_odd_row; /* flag to remember which row we are on */
  157198. } my_cquantizer;
  157199. typedef my_cquantizer * my_cquantize_ptr;
  157200. LOCAL(int)
  157201. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  157202. {
  157203. int nc = cinfo->out_color_components; /* number of color components */
  157204. int max_colors = cinfo->desired_number_of_colors;
  157205. int total_colors, iroot, i, j;
  157206. boolean changed;
  157207. long temp;
  157208. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  157209. iroot = 1;
  157210. do {
  157211. iroot++;
  157212. temp = iroot; /* set temp = iroot ** nc */
  157213. for (i = 1; i < nc; i++)
  157214. temp *= iroot;
  157215. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  157216. iroot--; /* now iroot = floor(root) */
  157217. if (iroot < 2)
  157218. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  157219. total_colors = 1;
  157220. for (i = 0; i < nc; i++) {
  157221. Ncolors[i] = iroot;
  157222. total_colors *= iroot;
  157223. }
  157224. do {
  157225. changed = FALSE;
  157226. for (i = 0; i < nc; i++) {
  157227. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  157228. temp = total_colors / Ncolors[j];
  157229. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  157230. if (temp > (long) max_colors)
  157231. break; /* won't fit, done with this pass */
  157232. Ncolors[j]++; /* OK, apply the increment */
  157233. total_colors = (int) temp;
  157234. changed = TRUE;
  157235. }
  157236. } while (changed);
  157237. return total_colors;
  157238. }
  157239. LOCAL(int)
  157240. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157241. {
  157242. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  157243. }
  157244. LOCAL(int)
  157245. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157246. {
  157247. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  157248. }
  157249. LOCAL(void)
  157250. create_colormap (j_decompress_ptr cinfo)
  157251. {
  157252. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157253. JSAMPARRAY colormap; /* Created colormap */
  157254. int total_colors; /* Number of distinct output colors */
  157255. int i,j,k, nci, blksize, blkdist, ptr, val;
  157256. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  157257. if (cinfo->out_color_components == 3)
  157258. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  157259. total_colors, cquantize->Ncolors[0],
  157260. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  157261. else
  157262. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  157263. colormap = (*cinfo->mem->alloc_sarray)
  157264. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157265. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  157266. blkdist = total_colors;
  157267. for (i = 0; i < cinfo->out_color_components; i++) {
  157268. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157269. blksize = blkdist / nci;
  157270. for (j = 0; j < nci; j++) {
  157271. val = output_value(cinfo, i, j, nci-1);
  157272. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  157273. for (k = 0; k < blksize; k++)
  157274. colormap[i][ptr+k] = (JSAMPLE) val;
  157275. }
  157276. }
  157277. blkdist = blksize; /* blksize of this color is blkdist of next */
  157278. }
  157279. cquantize->sv_colormap = colormap;
  157280. cquantize->sv_actual = total_colors;
  157281. }
  157282. LOCAL(void)
  157283. create_colorindex (j_decompress_ptr cinfo)
  157284. {
  157285. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157286. JSAMPROW indexptr;
  157287. int i,j,k, nci, blksize, val, pad;
  157288. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157289. pad = MAXJSAMPLE*2;
  157290. cquantize->is_padded = TRUE;
  157291. } else {
  157292. pad = 0;
  157293. cquantize->is_padded = FALSE;
  157294. }
  157295. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157296. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157297. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157298. (JDIMENSION) cinfo->out_color_components);
  157299. blksize = cquantize->sv_actual;
  157300. for (i = 0; i < cinfo->out_color_components; i++) {
  157301. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157302. blksize = blksize / nci;
  157303. if (pad)
  157304. cquantize->colorindex[i] += MAXJSAMPLE;
  157305. indexptr = cquantize->colorindex[i];
  157306. val = 0;
  157307. k = largest_input_value(cinfo, i, 0, nci-1);
  157308. for (j = 0; j <= MAXJSAMPLE; j++) {
  157309. while (j > k) /* advance val if past boundary */
  157310. k = largest_input_value(cinfo, i, ++val, nci-1);
  157311. indexptr[j] = (JSAMPLE) (val * blksize);
  157312. }
  157313. if (pad)
  157314. for (j = 1; j <= MAXJSAMPLE; j++) {
  157315. indexptr[-j] = indexptr[0];
  157316. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157317. }
  157318. }
  157319. }
  157320. LOCAL(ODITHER_MATRIX_PTR)
  157321. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157322. {
  157323. ODITHER_MATRIX_PTR odither;
  157324. int j,k;
  157325. INT32 num,den;
  157326. odither = (ODITHER_MATRIX_PTR)
  157327. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157328. SIZEOF(ODITHER_MATRIX));
  157329. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157330. for (j = 0; j < ODITHER_SIZE; j++) {
  157331. for (k = 0; k < ODITHER_SIZE; k++) {
  157332. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157333. * MAXJSAMPLE;
  157334. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157335. }
  157336. }
  157337. return odither;
  157338. }
  157339. LOCAL(void)
  157340. create_odither_tables (j_decompress_ptr cinfo)
  157341. {
  157342. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157343. ODITHER_MATRIX_PTR odither;
  157344. int i, j, nci;
  157345. for (i = 0; i < cinfo->out_color_components; i++) {
  157346. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157347. odither = NULL; /* search for matching prior component */
  157348. for (j = 0; j < i; j++) {
  157349. if (nci == cquantize->Ncolors[j]) {
  157350. odither = cquantize->odither[j];
  157351. break;
  157352. }
  157353. }
  157354. if (odither == NULL) /* need a new table? */
  157355. odither = make_odither_array(cinfo, nci);
  157356. cquantize->odither[i] = odither;
  157357. }
  157358. }
  157359. METHODDEF(void)
  157360. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157361. JSAMPARRAY output_buf, int num_rows)
  157362. {
  157363. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157364. JSAMPARRAY colorindex = cquantize->colorindex;
  157365. register int pixcode, ci;
  157366. register JSAMPROW ptrin, ptrout;
  157367. int row;
  157368. JDIMENSION col;
  157369. JDIMENSION width = cinfo->output_width;
  157370. register int nc = cinfo->out_color_components;
  157371. for (row = 0; row < num_rows; row++) {
  157372. ptrin = input_buf[row];
  157373. ptrout = output_buf[row];
  157374. for (col = width; col > 0; col--) {
  157375. pixcode = 0;
  157376. for (ci = 0; ci < nc; ci++) {
  157377. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157378. }
  157379. *ptrout++ = (JSAMPLE) pixcode;
  157380. }
  157381. }
  157382. }
  157383. METHODDEF(void)
  157384. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157385. JSAMPARRAY output_buf, int num_rows)
  157386. {
  157387. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157388. register int pixcode;
  157389. register JSAMPROW ptrin, ptrout;
  157390. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157391. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157392. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157393. int row;
  157394. JDIMENSION col;
  157395. JDIMENSION width = cinfo->output_width;
  157396. for (row = 0; row < num_rows; row++) {
  157397. ptrin = input_buf[row];
  157398. ptrout = output_buf[row];
  157399. for (col = width; col > 0; col--) {
  157400. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157401. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157402. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157403. *ptrout++ = (JSAMPLE) pixcode;
  157404. }
  157405. }
  157406. }
  157407. METHODDEF(void)
  157408. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157409. JSAMPARRAY output_buf, int num_rows)
  157410. {
  157411. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157412. register JSAMPROW input_ptr;
  157413. register JSAMPROW output_ptr;
  157414. JSAMPROW colorindex_ci;
  157415. int * dither; /* points to active row of dither matrix */
  157416. int row_index, col_index; /* current indexes into dither matrix */
  157417. int nc = cinfo->out_color_components;
  157418. int ci;
  157419. int row;
  157420. JDIMENSION col;
  157421. JDIMENSION width = cinfo->output_width;
  157422. for (row = 0; row < num_rows; row++) {
  157423. jzero_far((void FAR *) output_buf[row],
  157424. (size_t) (width * SIZEOF(JSAMPLE)));
  157425. row_index = cquantize->row_index;
  157426. for (ci = 0; ci < nc; ci++) {
  157427. input_ptr = input_buf[row] + ci;
  157428. output_ptr = output_buf[row];
  157429. colorindex_ci = cquantize->colorindex[ci];
  157430. dither = cquantize->odither[ci][row_index];
  157431. col_index = 0;
  157432. for (col = width; col > 0; col--) {
  157433. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157434. input_ptr += nc;
  157435. output_ptr++;
  157436. col_index = (col_index + 1) & ODITHER_MASK;
  157437. }
  157438. }
  157439. row_index = (row_index + 1) & ODITHER_MASK;
  157440. cquantize->row_index = row_index;
  157441. }
  157442. }
  157443. METHODDEF(void)
  157444. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157445. JSAMPARRAY output_buf, int num_rows)
  157446. {
  157447. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157448. register int pixcode;
  157449. register JSAMPROW input_ptr;
  157450. register JSAMPROW output_ptr;
  157451. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157452. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157453. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157454. int * dither0; /* points to active row of dither matrix */
  157455. int * dither1;
  157456. int * dither2;
  157457. int row_index, col_index; /* current indexes into dither matrix */
  157458. int row;
  157459. JDIMENSION col;
  157460. JDIMENSION width = cinfo->output_width;
  157461. for (row = 0; row < num_rows; row++) {
  157462. row_index = cquantize->row_index;
  157463. input_ptr = input_buf[row];
  157464. output_ptr = output_buf[row];
  157465. dither0 = cquantize->odither[0][row_index];
  157466. dither1 = cquantize->odither[1][row_index];
  157467. dither2 = cquantize->odither[2][row_index];
  157468. col_index = 0;
  157469. for (col = width; col > 0; col--) {
  157470. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157471. dither0[col_index]]);
  157472. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157473. dither1[col_index]]);
  157474. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157475. dither2[col_index]]);
  157476. *output_ptr++ = (JSAMPLE) pixcode;
  157477. col_index = (col_index + 1) & ODITHER_MASK;
  157478. }
  157479. row_index = (row_index + 1) & ODITHER_MASK;
  157480. cquantize->row_index = row_index;
  157481. }
  157482. }
  157483. METHODDEF(void)
  157484. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157485. JSAMPARRAY output_buf, int num_rows)
  157486. {
  157487. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157488. register LOCFSERROR cur; /* current error or pixel value */
  157489. LOCFSERROR belowerr; /* error for pixel below cur */
  157490. LOCFSERROR bpreverr; /* error for below/prev col */
  157491. LOCFSERROR bnexterr; /* error for below/next col */
  157492. LOCFSERROR delta;
  157493. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157494. register JSAMPROW input_ptr;
  157495. register JSAMPROW output_ptr;
  157496. JSAMPROW colorindex_ci;
  157497. JSAMPROW colormap_ci;
  157498. int pixcode;
  157499. int nc = cinfo->out_color_components;
  157500. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157501. int dirnc; /* dir * nc */
  157502. int ci;
  157503. int row;
  157504. JDIMENSION col;
  157505. JDIMENSION width = cinfo->output_width;
  157506. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157507. SHIFT_TEMPS
  157508. for (row = 0; row < num_rows; row++) {
  157509. jzero_far((void FAR *) output_buf[row],
  157510. (size_t) (width * SIZEOF(JSAMPLE)));
  157511. for (ci = 0; ci < nc; ci++) {
  157512. input_ptr = input_buf[row] + ci;
  157513. output_ptr = output_buf[row];
  157514. if (cquantize->on_odd_row) {
  157515. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157516. output_ptr += width-1;
  157517. dir = -1;
  157518. dirnc = -nc;
  157519. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157520. } else {
  157521. dir = 1;
  157522. dirnc = nc;
  157523. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157524. }
  157525. colorindex_ci = cquantize->colorindex[ci];
  157526. colormap_ci = cquantize->sv_colormap[ci];
  157527. cur = 0;
  157528. belowerr = bpreverr = 0;
  157529. for (col = width; col > 0; col--) {
  157530. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157531. cur += GETJSAMPLE(*input_ptr);
  157532. cur = GETJSAMPLE(range_limit[cur]);
  157533. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157534. *output_ptr += (JSAMPLE) pixcode;
  157535. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157536. bnexterr = cur;
  157537. delta = cur * 2;
  157538. cur += delta; /* form error * 3 */
  157539. errorptr[0] = (FSERROR) (bpreverr + cur);
  157540. cur += delta; /* form error * 5 */
  157541. bpreverr = belowerr + cur;
  157542. belowerr = bnexterr;
  157543. cur += delta; /* form error * 7 */
  157544. input_ptr += dirnc; /* advance input ptr to next column */
  157545. output_ptr += dir; /* advance output ptr to next column */
  157546. errorptr += dir; /* advance errorptr to current column */
  157547. }
  157548. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157549. }
  157550. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157551. }
  157552. }
  157553. LOCAL(void)
  157554. alloc_fs_workspace (j_decompress_ptr cinfo)
  157555. {
  157556. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157557. size_t arraysize;
  157558. int i;
  157559. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157560. for (i = 0; i < cinfo->out_color_components; i++) {
  157561. cquantize->fserrors[i] = (FSERRPTR)
  157562. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157563. }
  157564. }
  157565. METHODDEF(void)
  157566. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157567. {
  157568. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157569. size_t arraysize;
  157570. int i;
  157571. cinfo->colormap = cquantize->sv_colormap;
  157572. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157573. switch (cinfo->dither_mode) {
  157574. case JDITHER_NONE:
  157575. if (cinfo->out_color_components == 3)
  157576. cquantize->pub.color_quantize = color_quantize3;
  157577. else
  157578. cquantize->pub.color_quantize = color_quantize;
  157579. break;
  157580. case JDITHER_ORDERED:
  157581. if (cinfo->out_color_components == 3)
  157582. cquantize->pub.color_quantize = quantize3_ord_dither;
  157583. else
  157584. cquantize->pub.color_quantize = quantize_ord_dither;
  157585. cquantize->row_index = 0; /* initialize state for ordered dither */
  157586. if (! cquantize->is_padded)
  157587. create_colorindex(cinfo);
  157588. if (cquantize->odither[0] == NULL)
  157589. create_odither_tables(cinfo);
  157590. break;
  157591. case JDITHER_FS:
  157592. cquantize->pub.color_quantize = quantize_fs_dither;
  157593. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157594. if (cquantize->fserrors[0] == NULL)
  157595. alloc_fs_workspace(cinfo);
  157596. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157597. for (i = 0; i < cinfo->out_color_components; i++)
  157598. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157599. break;
  157600. default:
  157601. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157602. break;
  157603. }
  157604. }
  157605. METHODDEF(void)
  157606. finish_pass_1_quant (j_decompress_ptr cinfo)
  157607. {
  157608. }
  157609. METHODDEF(void)
  157610. new_color_map_1_quant (j_decompress_ptr cinfo)
  157611. {
  157612. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157613. }
  157614. GLOBAL(void)
  157615. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157616. {
  157617. my_cquantize_ptr cquantize;
  157618. cquantize = (my_cquantize_ptr)
  157619. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157620. SIZEOF(my_cquantizer));
  157621. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157622. cquantize->pub.start_pass = start_pass_1_quant;
  157623. cquantize->pub.finish_pass = finish_pass_1_quant;
  157624. cquantize->pub.new_color_map = new_color_map_1_quant;
  157625. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157626. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157627. if (cinfo->out_color_components > MAX_Q_COMPS)
  157628. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157629. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157630. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157631. create_colormap(cinfo);
  157632. create_colorindex(cinfo);
  157633. if (cinfo->dither_mode == JDITHER_FS)
  157634. alloc_fs_workspace(cinfo);
  157635. }
  157636. #endif /* QUANT_1PASS_SUPPORTED */
  157637. /*** End of inlined file: jquant1.c ***/
  157638. /*** Start of inlined file: jquant2.c ***/
  157639. #define JPEG_INTERNALS
  157640. #ifdef QUANT_2PASS_SUPPORTED
  157641. #define R_SCALE 2 /* scale R distances by this much */
  157642. #define G_SCALE 3 /* scale G distances by this much */
  157643. #define B_SCALE 1 /* and B by this much */
  157644. #if RGB_RED == 0
  157645. #define C0_SCALE R_SCALE
  157646. #endif
  157647. #if RGB_BLUE == 0
  157648. #define C0_SCALE B_SCALE
  157649. #endif
  157650. #if RGB_GREEN == 1
  157651. #define C1_SCALE G_SCALE
  157652. #endif
  157653. #if RGB_RED == 2
  157654. #define C2_SCALE R_SCALE
  157655. #endif
  157656. #if RGB_BLUE == 2
  157657. #define C2_SCALE B_SCALE
  157658. #endif
  157659. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157660. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157661. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157662. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157663. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157664. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157665. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157666. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157667. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157668. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157669. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157670. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157671. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157672. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157673. typedef hist2d * hist3d; /* type for top-level pointer */
  157674. #if BITS_IN_JSAMPLE == 8
  157675. typedef INT16 FSERROR; /* 16 bits should be enough */
  157676. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157677. #else
  157678. typedef INT32 FSERROR; /* may need more than 16 bits */
  157679. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157680. #endif
  157681. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157682. typedef struct {
  157683. struct jpeg_color_quantizer pub; /* public fields */
  157684. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157685. int desired; /* desired # of colors = size of colormap */
  157686. hist3d histogram; /* pointer to the histogram */
  157687. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157688. FSERRPTR fserrors; /* accumulated errors */
  157689. boolean on_odd_row; /* flag to remember which row we are on */
  157690. int * error_limiter; /* table for clamping the applied error */
  157691. } my_cquantizer2;
  157692. typedef my_cquantizer2 * my_cquantize_ptr2;
  157693. METHODDEF(void)
  157694. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157695. JSAMPARRAY output_buf, int num_rows)
  157696. {
  157697. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157698. register JSAMPROW ptr;
  157699. register histptr histp;
  157700. register hist3d histogram = cquantize->histogram;
  157701. int row;
  157702. JDIMENSION col;
  157703. JDIMENSION width = cinfo->output_width;
  157704. for (row = 0; row < num_rows; row++) {
  157705. ptr = input_buf[row];
  157706. for (col = width; col > 0; col--) {
  157707. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157708. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157709. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157710. if (++(*histp) <= 0)
  157711. (*histp)--;
  157712. ptr += 3;
  157713. }
  157714. }
  157715. }
  157716. typedef struct {
  157717. int c0min, c0max;
  157718. int c1min, c1max;
  157719. int c2min, c2max;
  157720. INT32 volume;
  157721. long colorcount;
  157722. } box;
  157723. typedef box * boxptr;
  157724. LOCAL(boxptr)
  157725. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157726. {
  157727. register boxptr boxp;
  157728. register int i;
  157729. register long maxc = 0;
  157730. boxptr which = NULL;
  157731. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157732. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157733. which = boxp;
  157734. maxc = boxp->colorcount;
  157735. }
  157736. }
  157737. return which;
  157738. }
  157739. LOCAL(boxptr)
  157740. find_biggest_volume (boxptr boxlist, int numboxes)
  157741. {
  157742. register boxptr boxp;
  157743. register int i;
  157744. register INT32 maxv = 0;
  157745. boxptr which = NULL;
  157746. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157747. if (boxp->volume > maxv) {
  157748. which = boxp;
  157749. maxv = boxp->volume;
  157750. }
  157751. }
  157752. return which;
  157753. }
  157754. LOCAL(void)
  157755. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157756. {
  157757. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157758. hist3d histogram = cquantize->histogram;
  157759. histptr histp;
  157760. int c0,c1,c2;
  157761. int c0min,c0max,c1min,c1max,c2min,c2max;
  157762. INT32 dist0,dist1,dist2;
  157763. long ccount;
  157764. c0min = boxp->c0min; c0max = boxp->c0max;
  157765. c1min = boxp->c1min; c1max = boxp->c1max;
  157766. c2min = boxp->c2min; c2max = boxp->c2max;
  157767. if (c0max > c0min)
  157768. for (c0 = c0min; c0 <= c0max; c0++)
  157769. for (c1 = c1min; c1 <= c1max; c1++) {
  157770. histp = & histogram[c0][c1][c2min];
  157771. for (c2 = c2min; c2 <= c2max; c2++)
  157772. if (*histp++ != 0) {
  157773. boxp->c0min = c0min = c0;
  157774. goto have_c0min;
  157775. }
  157776. }
  157777. have_c0min:
  157778. if (c0max > c0min)
  157779. for (c0 = c0max; c0 >= c0min; c0--)
  157780. for (c1 = c1min; c1 <= c1max; c1++) {
  157781. histp = & histogram[c0][c1][c2min];
  157782. for (c2 = c2min; c2 <= c2max; c2++)
  157783. if (*histp++ != 0) {
  157784. boxp->c0max = c0max = c0;
  157785. goto have_c0max;
  157786. }
  157787. }
  157788. have_c0max:
  157789. if (c1max > c1min)
  157790. for (c1 = c1min; c1 <= c1max; c1++)
  157791. for (c0 = c0min; c0 <= c0max; c0++) {
  157792. histp = & histogram[c0][c1][c2min];
  157793. for (c2 = c2min; c2 <= c2max; c2++)
  157794. if (*histp++ != 0) {
  157795. boxp->c1min = c1min = c1;
  157796. goto have_c1min;
  157797. }
  157798. }
  157799. have_c1min:
  157800. if (c1max > c1min)
  157801. for (c1 = c1max; c1 >= c1min; c1--)
  157802. for (c0 = c0min; c0 <= c0max; c0++) {
  157803. histp = & histogram[c0][c1][c2min];
  157804. for (c2 = c2min; c2 <= c2max; c2++)
  157805. if (*histp++ != 0) {
  157806. boxp->c1max = c1max = c1;
  157807. goto have_c1max;
  157808. }
  157809. }
  157810. have_c1max:
  157811. if (c2max > c2min)
  157812. for (c2 = c2min; c2 <= c2max; c2++)
  157813. for (c0 = c0min; c0 <= c0max; c0++) {
  157814. histp = & histogram[c0][c1min][c2];
  157815. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157816. if (*histp != 0) {
  157817. boxp->c2min = c2min = c2;
  157818. goto have_c2min;
  157819. }
  157820. }
  157821. have_c2min:
  157822. if (c2max > c2min)
  157823. for (c2 = c2max; c2 >= c2min; c2--)
  157824. for (c0 = c0min; c0 <= c0max; c0++) {
  157825. histp = & histogram[c0][c1min][c2];
  157826. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157827. if (*histp != 0) {
  157828. boxp->c2max = c2max = c2;
  157829. goto have_c2max;
  157830. }
  157831. }
  157832. have_c2max:
  157833. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157834. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157835. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157836. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157837. ccount = 0;
  157838. for (c0 = c0min; c0 <= c0max; c0++)
  157839. for (c1 = c1min; c1 <= c1max; c1++) {
  157840. histp = & histogram[c0][c1][c2min];
  157841. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157842. if (*histp != 0) {
  157843. ccount++;
  157844. }
  157845. }
  157846. boxp->colorcount = ccount;
  157847. }
  157848. LOCAL(int)
  157849. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157850. int desired_colors)
  157851. {
  157852. int n,lb;
  157853. int c0,c1,c2,cmax;
  157854. register boxptr b1,b2;
  157855. while (numboxes < desired_colors) {
  157856. if (numboxes*2 <= desired_colors) {
  157857. b1 = find_biggest_color_pop(boxlist, numboxes);
  157858. } else {
  157859. b1 = find_biggest_volume(boxlist, numboxes);
  157860. }
  157861. if (b1 == NULL) /* no splittable boxes left! */
  157862. break;
  157863. b2 = &boxlist[numboxes]; /* where new box will go */
  157864. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157865. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157866. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157867. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157868. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157869. #if RGB_RED == 0
  157870. cmax = c1; n = 1;
  157871. if (c0 > cmax) { cmax = c0; n = 0; }
  157872. if (c2 > cmax) { n = 2; }
  157873. #else
  157874. cmax = c1; n = 1;
  157875. if (c2 > cmax) { cmax = c2; n = 2; }
  157876. if (c0 > cmax) { n = 0; }
  157877. #endif
  157878. switch (n) {
  157879. case 0:
  157880. lb = (b1->c0max + b1->c0min) / 2;
  157881. b1->c0max = lb;
  157882. b2->c0min = lb+1;
  157883. break;
  157884. case 1:
  157885. lb = (b1->c1max + b1->c1min) / 2;
  157886. b1->c1max = lb;
  157887. b2->c1min = lb+1;
  157888. break;
  157889. case 2:
  157890. lb = (b1->c2max + b1->c2min) / 2;
  157891. b1->c2max = lb;
  157892. b2->c2min = lb+1;
  157893. break;
  157894. }
  157895. update_box(cinfo, b1);
  157896. update_box(cinfo, b2);
  157897. numboxes++;
  157898. }
  157899. return numboxes;
  157900. }
  157901. LOCAL(void)
  157902. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157903. {
  157904. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157905. hist3d histogram = cquantize->histogram;
  157906. histptr histp;
  157907. int c0,c1,c2;
  157908. int c0min,c0max,c1min,c1max,c2min,c2max;
  157909. long count;
  157910. long total = 0;
  157911. long c0total = 0;
  157912. long c1total = 0;
  157913. long c2total = 0;
  157914. c0min = boxp->c0min; c0max = boxp->c0max;
  157915. c1min = boxp->c1min; c1max = boxp->c1max;
  157916. c2min = boxp->c2min; c2max = boxp->c2max;
  157917. for (c0 = c0min; c0 <= c0max; c0++)
  157918. for (c1 = c1min; c1 <= c1max; c1++) {
  157919. histp = & histogram[c0][c1][c2min];
  157920. for (c2 = c2min; c2 <= c2max; c2++) {
  157921. if ((count = *histp++) != 0) {
  157922. total += count;
  157923. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157924. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157925. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157926. }
  157927. }
  157928. }
  157929. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157930. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157931. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157932. }
  157933. LOCAL(void)
  157934. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157935. {
  157936. boxptr boxlist;
  157937. int numboxes;
  157938. int i;
  157939. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157940. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157941. numboxes = 1;
  157942. boxlist[0].c0min = 0;
  157943. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157944. boxlist[0].c1min = 0;
  157945. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157946. boxlist[0].c2min = 0;
  157947. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157948. update_box(cinfo, & boxlist[0]);
  157949. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157950. for (i = 0; i < numboxes; i++)
  157951. compute_color(cinfo, & boxlist[i], i);
  157952. cinfo->actual_number_of_colors = numboxes;
  157953. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157954. }
  157955. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157956. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157957. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157958. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157959. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157960. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157961. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157962. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157963. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157964. LOCAL(int)
  157965. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157966. JSAMPLE colorlist[])
  157967. {
  157968. int numcolors = cinfo->actual_number_of_colors;
  157969. int maxc0, maxc1, maxc2;
  157970. int centerc0, centerc1, centerc2;
  157971. int i, x, ncolors;
  157972. INT32 minmaxdist, min_dist, max_dist, tdist;
  157973. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157974. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157975. centerc0 = (minc0 + maxc0) >> 1;
  157976. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157977. centerc1 = (minc1 + maxc1) >> 1;
  157978. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157979. centerc2 = (minc2 + maxc2) >> 1;
  157980. minmaxdist = 0x7FFFFFFFL;
  157981. for (i = 0; i < numcolors; i++) {
  157982. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157983. if (x < minc0) {
  157984. tdist = (x - minc0) * C0_SCALE;
  157985. min_dist = tdist*tdist;
  157986. tdist = (x - maxc0) * C0_SCALE;
  157987. max_dist = tdist*tdist;
  157988. } else if (x > maxc0) {
  157989. tdist = (x - maxc0) * C0_SCALE;
  157990. min_dist = tdist*tdist;
  157991. tdist = (x - minc0) * C0_SCALE;
  157992. max_dist = tdist*tdist;
  157993. } else {
  157994. min_dist = 0;
  157995. if (x <= centerc0) {
  157996. tdist = (x - maxc0) * C0_SCALE;
  157997. max_dist = tdist*tdist;
  157998. } else {
  157999. tdist = (x - minc0) * C0_SCALE;
  158000. max_dist = tdist*tdist;
  158001. }
  158002. }
  158003. x = GETJSAMPLE(cinfo->colormap[1][i]);
  158004. if (x < minc1) {
  158005. tdist = (x - minc1) * C1_SCALE;
  158006. min_dist += tdist*tdist;
  158007. tdist = (x - maxc1) * C1_SCALE;
  158008. max_dist += tdist*tdist;
  158009. } else if (x > maxc1) {
  158010. tdist = (x - maxc1) * C1_SCALE;
  158011. min_dist += tdist*tdist;
  158012. tdist = (x - minc1) * C1_SCALE;
  158013. max_dist += tdist*tdist;
  158014. } else {
  158015. if (x <= centerc1) {
  158016. tdist = (x - maxc1) * C1_SCALE;
  158017. max_dist += tdist*tdist;
  158018. } else {
  158019. tdist = (x - minc1) * C1_SCALE;
  158020. max_dist += tdist*tdist;
  158021. }
  158022. }
  158023. x = GETJSAMPLE(cinfo->colormap[2][i]);
  158024. if (x < minc2) {
  158025. tdist = (x - minc2) * C2_SCALE;
  158026. min_dist += tdist*tdist;
  158027. tdist = (x - maxc2) * C2_SCALE;
  158028. max_dist += tdist*tdist;
  158029. } else if (x > maxc2) {
  158030. tdist = (x - maxc2) * C2_SCALE;
  158031. min_dist += tdist*tdist;
  158032. tdist = (x - minc2) * C2_SCALE;
  158033. max_dist += tdist*tdist;
  158034. } else {
  158035. if (x <= centerc2) {
  158036. tdist = (x - maxc2) * C2_SCALE;
  158037. max_dist += tdist*tdist;
  158038. } else {
  158039. tdist = (x - minc2) * C2_SCALE;
  158040. max_dist += tdist*tdist;
  158041. }
  158042. }
  158043. mindist[i] = min_dist; /* save away the results */
  158044. if (max_dist < minmaxdist)
  158045. minmaxdist = max_dist;
  158046. }
  158047. ncolors = 0;
  158048. for (i = 0; i < numcolors; i++) {
  158049. if (mindist[i] <= minmaxdist)
  158050. colorlist[ncolors++] = (JSAMPLE) i;
  158051. }
  158052. return ncolors;
  158053. }
  158054. LOCAL(void)
  158055. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158056. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  158057. {
  158058. int ic0, ic1, ic2;
  158059. int i, icolor;
  158060. register INT32 * bptr; /* pointer into bestdist[] array */
  158061. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158062. INT32 dist0, dist1; /* initial distance values */
  158063. register INT32 dist2; /* current distance in inner loop */
  158064. INT32 xx0, xx1; /* distance increments */
  158065. register INT32 xx2;
  158066. INT32 inc0, inc1, inc2; /* initial values for increments */
  158067. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158068. bptr = bestdist;
  158069. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  158070. *bptr++ = 0x7FFFFFFFL;
  158071. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  158072. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  158073. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  158074. for (i = 0; i < numcolors; i++) {
  158075. icolor = GETJSAMPLE(colorlist[i]);
  158076. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  158077. dist0 = inc0*inc0;
  158078. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  158079. dist0 += inc1*inc1;
  158080. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  158081. dist0 += inc2*inc2;
  158082. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  158083. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  158084. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  158085. bptr = bestdist;
  158086. cptr = bestcolor;
  158087. xx0 = inc0;
  158088. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  158089. dist1 = dist0;
  158090. xx1 = inc1;
  158091. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  158092. dist2 = dist1;
  158093. xx2 = inc2;
  158094. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  158095. if (dist2 < *bptr) {
  158096. *bptr = dist2;
  158097. *cptr = (JSAMPLE) icolor;
  158098. }
  158099. dist2 += xx2;
  158100. xx2 += 2 * STEP_C2 * STEP_C2;
  158101. bptr++;
  158102. cptr++;
  158103. }
  158104. dist1 += xx1;
  158105. xx1 += 2 * STEP_C1 * STEP_C1;
  158106. }
  158107. dist0 += xx0;
  158108. xx0 += 2 * STEP_C0 * STEP_C0;
  158109. }
  158110. }
  158111. }
  158112. LOCAL(void)
  158113. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  158114. {
  158115. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158116. hist3d histogram = cquantize->histogram;
  158117. int minc0, minc1, minc2; /* lower left corner of update box */
  158118. int ic0, ic1, ic2;
  158119. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158120. register histptr cachep; /* pointer into main cache array */
  158121. JSAMPLE colorlist[MAXNUMCOLORS];
  158122. int numcolors; /* number of candidate colors */
  158123. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158124. c0 >>= BOX_C0_LOG;
  158125. c1 >>= BOX_C1_LOG;
  158126. c2 >>= BOX_C2_LOG;
  158127. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  158128. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  158129. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  158130. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  158131. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  158132. bestcolor);
  158133. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  158134. c1 <<= BOX_C1_LOG;
  158135. c2 <<= BOX_C2_LOG;
  158136. cptr = bestcolor;
  158137. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  158138. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  158139. cachep = & histogram[c0+ic0][c1+ic1][c2];
  158140. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  158141. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  158142. }
  158143. }
  158144. }
  158145. }
  158146. METHODDEF(void)
  158147. pass2_no_dither (j_decompress_ptr cinfo,
  158148. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158149. {
  158150. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158151. hist3d histogram = cquantize->histogram;
  158152. register JSAMPROW inptr, outptr;
  158153. register histptr cachep;
  158154. register int c0, c1, c2;
  158155. int row;
  158156. JDIMENSION col;
  158157. JDIMENSION width = cinfo->output_width;
  158158. for (row = 0; row < num_rows; row++) {
  158159. inptr = input_buf[row];
  158160. outptr = output_buf[row];
  158161. for (col = width; col > 0; col--) {
  158162. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  158163. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  158164. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  158165. cachep = & histogram[c0][c1][c2];
  158166. if (*cachep == 0)
  158167. fill_inverse_cmap(cinfo, c0,c1,c2);
  158168. *outptr++ = (JSAMPLE) (*cachep - 1);
  158169. }
  158170. }
  158171. }
  158172. METHODDEF(void)
  158173. pass2_fs_dither (j_decompress_ptr cinfo,
  158174. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158175. {
  158176. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158177. hist3d histogram = cquantize->histogram;
  158178. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  158179. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  158180. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  158181. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  158182. JSAMPROW inptr; /* => current input pixel */
  158183. JSAMPROW outptr; /* => current output pixel */
  158184. histptr cachep;
  158185. int dir; /* +1 or -1 depending on direction */
  158186. int dir3; /* 3*dir, for advancing inptr & errorptr */
  158187. int row;
  158188. JDIMENSION col;
  158189. JDIMENSION width = cinfo->output_width;
  158190. JSAMPLE *range_limit = cinfo->sample_range_limit;
  158191. int *error_limit = cquantize->error_limiter;
  158192. JSAMPROW colormap0 = cinfo->colormap[0];
  158193. JSAMPROW colormap1 = cinfo->colormap[1];
  158194. JSAMPROW colormap2 = cinfo->colormap[2];
  158195. SHIFT_TEMPS
  158196. for (row = 0; row < num_rows; row++) {
  158197. inptr = input_buf[row];
  158198. outptr = output_buf[row];
  158199. if (cquantize->on_odd_row) {
  158200. inptr += (width-1) * 3; /* so point to rightmost pixel */
  158201. outptr += width-1;
  158202. dir = -1;
  158203. dir3 = -3;
  158204. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  158205. cquantize->on_odd_row = FALSE; /* flip for next time */
  158206. } else {
  158207. dir = 1;
  158208. dir3 = 3;
  158209. errorptr = cquantize->fserrors; /* => entry before first real column */
  158210. cquantize->on_odd_row = TRUE; /* flip for next time */
  158211. }
  158212. cur0 = cur1 = cur2 = 0;
  158213. belowerr0 = belowerr1 = belowerr2 = 0;
  158214. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  158215. for (col = width; col > 0; col--) {
  158216. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  158217. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  158218. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  158219. cur0 = error_limit[cur0];
  158220. cur1 = error_limit[cur1];
  158221. cur2 = error_limit[cur2];
  158222. cur0 += GETJSAMPLE(inptr[0]);
  158223. cur1 += GETJSAMPLE(inptr[1]);
  158224. cur2 += GETJSAMPLE(inptr[2]);
  158225. cur0 = GETJSAMPLE(range_limit[cur0]);
  158226. cur1 = GETJSAMPLE(range_limit[cur1]);
  158227. cur2 = GETJSAMPLE(range_limit[cur2]);
  158228. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  158229. if (*cachep == 0)
  158230. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  158231. { register int pixcode = *cachep - 1;
  158232. *outptr = (JSAMPLE) pixcode;
  158233. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  158234. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  158235. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  158236. }
  158237. { register LOCFSERROR bnexterr, delta;
  158238. bnexterr = cur0; /* Process component 0 */
  158239. delta = cur0 * 2;
  158240. cur0 += delta; /* form error * 3 */
  158241. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  158242. cur0 += delta; /* form error * 5 */
  158243. bpreverr0 = belowerr0 + cur0;
  158244. belowerr0 = bnexterr;
  158245. cur0 += delta; /* form error * 7 */
  158246. bnexterr = cur1; /* Process component 1 */
  158247. delta = cur1 * 2;
  158248. cur1 += delta; /* form error * 3 */
  158249. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  158250. cur1 += delta; /* form error * 5 */
  158251. bpreverr1 = belowerr1 + cur1;
  158252. belowerr1 = bnexterr;
  158253. cur1 += delta; /* form error * 7 */
  158254. bnexterr = cur2; /* Process component 2 */
  158255. delta = cur2 * 2;
  158256. cur2 += delta; /* form error * 3 */
  158257. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  158258. cur2 += delta; /* form error * 5 */
  158259. bpreverr2 = belowerr2 + cur2;
  158260. belowerr2 = bnexterr;
  158261. cur2 += delta; /* form error * 7 */
  158262. }
  158263. inptr += dir3; /* Advance pixel pointers to next column */
  158264. outptr += dir;
  158265. errorptr += dir3; /* advance errorptr to current column */
  158266. }
  158267. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  158268. errorptr[1] = (FSERROR) bpreverr1;
  158269. errorptr[2] = (FSERROR) bpreverr2;
  158270. }
  158271. }
  158272. LOCAL(void)
  158273. init_error_limit (j_decompress_ptr cinfo)
  158274. {
  158275. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158276. int * table;
  158277. int in, out;
  158278. table = (int *) (*cinfo->mem->alloc_small)
  158279. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  158280. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  158281. cquantize->error_limiter = table;
  158282. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  158283. out = 0;
  158284. for (in = 0; in < STEPSIZE; in++, out++) {
  158285. table[in] = out; table[-in] = -out;
  158286. }
  158287. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158288. table[in] = out; table[-in] = -out;
  158289. }
  158290. for (; in <= MAXJSAMPLE; in++) {
  158291. table[in] = out; table[-in] = -out;
  158292. }
  158293. #undef STEPSIZE
  158294. }
  158295. METHODDEF(void)
  158296. finish_pass1 (j_decompress_ptr cinfo)
  158297. {
  158298. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158299. cinfo->colormap = cquantize->sv_colormap;
  158300. select_colors(cinfo, cquantize->desired);
  158301. cquantize->needs_zeroed = TRUE;
  158302. }
  158303. METHODDEF(void)
  158304. finish_pass2 (j_decompress_ptr cinfo)
  158305. {
  158306. }
  158307. METHODDEF(void)
  158308. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158309. {
  158310. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158311. hist3d histogram = cquantize->histogram;
  158312. int i;
  158313. if (cinfo->dither_mode != JDITHER_NONE)
  158314. cinfo->dither_mode = JDITHER_FS;
  158315. if (is_pre_scan) {
  158316. cquantize->pub.color_quantize = prescan_quantize;
  158317. cquantize->pub.finish_pass = finish_pass1;
  158318. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158319. } else {
  158320. if (cinfo->dither_mode == JDITHER_FS)
  158321. cquantize->pub.color_quantize = pass2_fs_dither;
  158322. else
  158323. cquantize->pub.color_quantize = pass2_no_dither;
  158324. cquantize->pub.finish_pass = finish_pass2;
  158325. i = cinfo->actual_number_of_colors;
  158326. if (i < 1)
  158327. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158328. if (i > MAXNUMCOLORS)
  158329. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158330. if (cinfo->dither_mode == JDITHER_FS) {
  158331. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158332. (3 * SIZEOF(FSERROR)));
  158333. if (cquantize->fserrors == NULL)
  158334. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158335. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158336. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158337. if (cquantize->error_limiter == NULL)
  158338. init_error_limit(cinfo);
  158339. cquantize->on_odd_row = FALSE;
  158340. }
  158341. }
  158342. if (cquantize->needs_zeroed) {
  158343. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158344. jzero_far((void FAR *) histogram[i],
  158345. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158346. }
  158347. cquantize->needs_zeroed = FALSE;
  158348. }
  158349. }
  158350. METHODDEF(void)
  158351. new_color_map_2_quant (j_decompress_ptr cinfo)
  158352. {
  158353. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158354. cquantize->needs_zeroed = TRUE;
  158355. }
  158356. GLOBAL(void)
  158357. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158358. {
  158359. my_cquantize_ptr2 cquantize;
  158360. int i;
  158361. cquantize = (my_cquantize_ptr2)
  158362. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158363. SIZEOF(my_cquantizer2));
  158364. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158365. cquantize->pub.start_pass = start_pass_2_quant;
  158366. cquantize->pub.new_color_map = new_color_map_2_quant;
  158367. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158368. cquantize->error_limiter = NULL;
  158369. if (cinfo->out_color_components != 3)
  158370. ERREXIT(cinfo, JERR_NOTIMPL);
  158371. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158372. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158373. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158374. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158375. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158376. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158377. }
  158378. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158379. if (cinfo->enable_2pass_quant) {
  158380. int desired = cinfo->desired_number_of_colors;
  158381. if (desired < 8)
  158382. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158383. if (desired > MAXNUMCOLORS)
  158384. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158385. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158386. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158387. cquantize->desired = desired;
  158388. } else
  158389. cquantize->sv_colormap = NULL;
  158390. if (cinfo->dither_mode != JDITHER_NONE)
  158391. cinfo->dither_mode = JDITHER_FS;
  158392. if (cinfo->dither_mode == JDITHER_FS) {
  158393. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158394. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158395. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158396. init_error_limit(cinfo);
  158397. }
  158398. }
  158399. #endif /* QUANT_2PASS_SUPPORTED */
  158400. /*** End of inlined file: jquant2.c ***/
  158401. /*** Start of inlined file: jutils.c ***/
  158402. #define JPEG_INTERNALS
  158403. #if 0 /* This table is not actually needed in v6a */
  158404. const int jpeg_zigzag_order[DCTSIZE2] = {
  158405. 0, 1, 5, 6, 14, 15, 27, 28,
  158406. 2, 4, 7, 13, 16, 26, 29, 42,
  158407. 3, 8, 12, 17, 25, 30, 41, 43,
  158408. 9, 11, 18, 24, 31, 40, 44, 53,
  158409. 10, 19, 23, 32, 39, 45, 52, 54,
  158410. 20, 22, 33, 38, 46, 51, 55, 60,
  158411. 21, 34, 37, 47, 50, 56, 59, 61,
  158412. 35, 36, 48, 49, 57, 58, 62, 63
  158413. };
  158414. #endif
  158415. const int jpeg_natural_order[DCTSIZE2+16] = {
  158416. 0, 1, 8, 16, 9, 2, 3, 10,
  158417. 17, 24, 32, 25, 18, 11, 4, 5,
  158418. 12, 19, 26, 33, 40, 48, 41, 34,
  158419. 27, 20, 13, 6, 7, 14, 21, 28,
  158420. 35, 42, 49, 56, 57, 50, 43, 36,
  158421. 29, 22, 15, 23, 30, 37, 44, 51,
  158422. 58, 59, 52, 45, 38, 31, 39, 46,
  158423. 53, 60, 61, 54, 47, 55, 62, 63,
  158424. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158425. 63, 63, 63, 63, 63, 63, 63, 63
  158426. };
  158427. GLOBAL(long)
  158428. jdiv_round_up (long a, long b)
  158429. {
  158430. return (a + b - 1L) / b;
  158431. }
  158432. GLOBAL(long)
  158433. jround_up (long a, long b)
  158434. {
  158435. a += b - 1L;
  158436. return a - (a % b);
  158437. }
  158438. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158439. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158440. #define FMEMZERO(target,size) MEMZERO(target,size)
  158441. #else /* 80x86 case, define if we can */
  158442. #ifdef USE_FMEM
  158443. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158444. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158445. #endif
  158446. #endif
  158447. GLOBAL(void)
  158448. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158449. JSAMPARRAY output_array, int dest_row,
  158450. int num_rows, JDIMENSION num_cols)
  158451. {
  158452. register JSAMPROW inptr, outptr;
  158453. #ifdef FMEMCOPY
  158454. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158455. #else
  158456. register JDIMENSION count;
  158457. #endif
  158458. register int row;
  158459. input_array += source_row;
  158460. output_array += dest_row;
  158461. for (row = num_rows; row > 0; row--) {
  158462. inptr = *input_array++;
  158463. outptr = *output_array++;
  158464. #ifdef FMEMCOPY
  158465. FMEMCOPY(outptr, inptr, count);
  158466. #else
  158467. for (count = num_cols; count > 0; count--)
  158468. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158469. #endif
  158470. }
  158471. }
  158472. GLOBAL(void)
  158473. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158474. JDIMENSION num_blocks)
  158475. {
  158476. #ifdef FMEMCOPY
  158477. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158478. #else
  158479. register JCOEFPTR inptr, outptr;
  158480. register long count;
  158481. inptr = (JCOEFPTR) input_row;
  158482. outptr = (JCOEFPTR) output_row;
  158483. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158484. *outptr++ = *inptr++;
  158485. }
  158486. #endif
  158487. }
  158488. GLOBAL(void)
  158489. jzero_far (void FAR * target, size_t bytestozero)
  158490. {
  158491. #ifdef FMEMZERO
  158492. FMEMZERO(target, bytestozero);
  158493. #else
  158494. register char FAR * ptr = (char FAR *) target;
  158495. register size_t count;
  158496. for (count = bytestozero; count > 0; count--) {
  158497. *ptr++ = 0;
  158498. }
  158499. #endif
  158500. }
  158501. /*** End of inlined file: jutils.c ***/
  158502. /*** Start of inlined file: transupp.c ***/
  158503. #define JPEG_INTERNALS
  158504. /*** Start of inlined file: transupp.h ***/
  158505. #ifndef TRANSFORMS_SUPPORTED
  158506. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158507. #endif
  158508. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158509. #define jtransform_request_workspace jTrRequest
  158510. #define jtransform_adjust_parameters jTrAdjust
  158511. #define jtransform_execute_transformation jTrExec
  158512. #define jcopy_markers_setup jCMrkSetup
  158513. #define jcopy_markers_execute jCMrkExec
  158514. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158515. typedef enum {
  158516. JXFORM_NONE, /* no transformation */
  158517. JXFORM_FLIP_H, /* horizontal flip */
  158518. JXFORM_FLIP_V, /* vertical flip */
  158519. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158520. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158521. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158522. JXFORM_ROT_180, /* 180-degree rotation */
  158523. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158524. } JXFORM_CODE;
  158525. typedef struct {
  158526. JXFORM_CODE transform; /* image transform operator */
  158527. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158528. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158529. int num_components; /* # of components in workspace */
  158530. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158531. } jpeg_transform_info;
  158532. #if TRANSFORMS_SUPPORTED
  158533. EXTERN(void) jtransform_request_workspace
  158534. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158535. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158536. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158537. jvirt_barray_ptr *src_coef_arrays,
  158538. jpeg_transform_info *info));
  158539. EXTERN(void) jtransform_execute_transformation
  158540. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158541. jvirt_barray_ptr *src_coef_arrays,
  158542. jpeg_transform_info *info));
  158543. #endif /* TRANSFORMS_SUPPORTED */
  158544. typedef enum {
  158545. JCOPYOPT_NONE, /* copy no optional markers */
  158546. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158547. JCOPYOPT_ALL /* copy all optional markers */
  158548. } JCOPY_OPTION;
  158549. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158550. EXTERN(void) jcopy_markers_setup
  158551. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158552. EXTERN(void) jcopy_markers_execute
  158553. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158554. JCOPY_OPTION option));
  158555. /*** End of inlined file: transupp.h ***/
  158556. /* My own external interface */
  158557. #if TRANSFORMS_SUPPORTED
  158558. LOCAL(void)
  158559. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158560. jvirt_barray_ptr *src_coef_arrays)
  158561. {
  158562. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158563. int ci, k, offset_y;
  158564. JBLOCKARRAY buffer;
  158565. JCOEFPTR ptr1, ptr2;
  158566. JCOEF temp1, temp2;
  158567. jpeg_component_info *compptr;
  158568. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158569. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158570. compptr = dstinfo->comp_info + ci;
  158571. comp_width = MCU_cols * compptr->h_samp_factor;
  158572. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158573. blk_y += compptr->v_samp_factor) {
  158574. buffer = (*srcinfo->mem->access_virt_barray)
  158575. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158576. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158577. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158578. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158579. ptr1 = buffer[offset_y][blk_x];
  158580. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158581. for (k = 0; k < DCTSIZE2; k += 2) {
  158582. temp1 = *ptr1; /* swap even column */
  158583. temp2 = *ptr2;
  158584. *ptr1++ = temp2;
  158585. *ptr2++ = temp1;
  158586. temp1 = *ptr1; /* swap odd column with sign change */
  158587. temp2 = *ptr2;
  158588. *ptr1++ = -temp2;
  158589. *ptr2++ = -temp1;
  158590. }
  158591. }
  158592. }
  158593. }
  158594. }
  158595. }
  158596. LOCAL(void)
  158597. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158598. jvirt_barray_ptr *src_coef_arrays,
  158599. jvirt_barray_ptr *dst_coef_arrays)
  158600. {
  158601. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158602. int ci, i, j, offset_y;
  158603. JBLOCKARRAY src_buffer, dst_buffer;
  158604. JBLOCKROW src_row_ptr, dst_row_ptr;
  158605. JCOEFPTR src_ptr, dst_ptr;
  158606. jpeg_component_info *compptr;
  158607. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158608. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158609. compptr = dstinfo->comp_info + ci;
  158610. comp_height = MCU_rows * compptr->v_samp_factor;
  158611. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158612. dst_blk_y += compptr->v_samp_factor) {
  158613. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158614. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158615. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158616. if (dst_blk_y < comp_height) {
  158617. src_buffer = (*srcinfo->mem->access_virt_barray)
  158618. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158619. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158620. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158621. } else {
  158622. src_buffer = (*srcinfo->mem->access_virt_barray)
  158623. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158624. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158625. }
  158626. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158627. if (dst_blk_y < comp_height) {
  158628. dst_row_ptr = dst_buffer[offset_y];
  158629. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158630. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158631. dst_blk_x++) {
  158632. dst_ptr = dst_row_ptr[dst_blk_x];
  158633. src_ptr = src_row_ptr[dst_blk_x];
  158634. for (i = 0; i < DCTSIZE; i += 2) {
  158635. for (j = 0; j < DCTSIZE; j++)
  158636. *dst_ptr++ = *src_ptr++;
  158637. for (j = 0; j < DCTSIZE; j++)
  158638. *dst_ptr++ = - *src_ptr++;
  158639. }
  158640. }
  158641. } else {
  158642. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158643. compptr->width_in_blocks);
  158644. }
  158645. }
  158646. }
  158647. }
  158648. }
  158649. LOCAL(void)
  158650. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158651. jvirt_barray_ptr *src_coef_arrays,
  158652. jvirt_barray_ptr *dst_coef_arrays)
  158653. {
  158654. JDIMENSION dst_blk_x, dst_blk_y;
  158655. int ci, i, j, offset_x, offset_y;
  158656. JBLOCKARRAY src_buffer, dst_buffer;
  158657. JCOEFPTR src_ptr, dst_ptr;
  158658. jpeg_component_info *compptr;
  158659. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158660. compptr = dstinfo->comp_info + ci;
  158661. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158662. dst_blk_y += compptr->v_samp_factor) {
  158663. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158664. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158665. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158666. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158667. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158668. dst_blk_x += compptr->h_samp_factor) {
  158669. src_buffer = (*srcinfo->mem->access_virt_barray)
  158670. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158671. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158672. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158673. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158674. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158675. for (i = 0; i < DCTSIZE; i++)
  158676. for (j = 0; j < DCTSIZE; j++)
  158677. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158678. }
  158679. }
  158680. }
  158681. }
  158682. }
  158683. }
  158684. LOCAL(void)
  158685. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158686. jvirt_barray_ptr *src_coef_arrays,
  158687. jvirt_barray_ptr *dst_coef_arrays)
  158688. {
  158689. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158690. int ci, i, j, offset_x, offset_y;
  158691. JBLOCKARRAY src_buffer, dst_buffer;
  158692. JCOEFPTR src_ptr, dst_ptr;
  158693. jpeg_component_info *compptr;
  158694. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158695. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158696. compptr = dstinfo->comp_info + ci;
  158697. comp_width = MCU_cols * compptr->h_samp_factor;
  158698. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158699. dst_blk_y += compptr->v_samp_factor) {
  158700. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158701. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158702. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158703. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158704. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158705. dst_blk_x += compptr->h_samp_factor) {
  158706. src_buffer = (*srcinfo->mem->access_virt_barray)
  158707. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158708. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158709. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158710. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158711. if (dst_blk_x < comp_width) {
  158712. dst_ptr = dst_buffer[offset_y]
  158713. [comp_width - dst_blk_x - offset_x - 1];
  158714. for (i = 0; i < DCTSIZE; i++) {
  158715. for (j = 0; j < DCTSIZE; j++)
  158716. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158717. i++;
  158718. for (j = 0; j < DCTSIZE; j++)
  158719. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158720. }
  158721. } else {
  158722. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  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. }
  158727. }
  158728. }
  158729. }
  158730. }
  158731. }
  158732. }
  158733. LOCAL(void)
  158734. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158735. jvirt_barray_ptr *src_coef_arrays,
  158736. jvirt_barray_ptr *dst_coef_arrays)
  158737. {
  158738. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158739. int ci, i, j, offset_x, offset_y;
  158740. JBLOCKARRAY src_buffer, dst_buffer;
  158741. JCOEFPTR src_ptr, dst_ptr;
  158742. jpeg_component_info *compptr;
  158743. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158744. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158745. compptr = dstinfo->comp_info + ci;
  158746. comp_height = MCU_rows * compptr->v_samp_factor;
  158747. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158748. dst_blk_y += compptr->v_samp_factor) {
  158749. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158750. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158751. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158752. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158753. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158754. dst_blk_x += compptr->h_samp_factor) {
  158755. src_buffer = (*srcinfo->mem->access_virt_barray)
  158756. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158757. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158758. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158759. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158760. if (dst_blk_y < comp_height) {
  158761. src_ptr = src_buffer[offset_x]
  158762. [comp_height - dst_blk_y - offset_y - 1];
  158763. for (i = 0; i < DCTSIZE; i++) {
  158764. for (j = 0; j < DCTSIZE; j++) {
  158765. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158766. j++;
  158767. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158768. }
  158769. }
  158770. } else {
  158771. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  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. }
  158776. }
  158777. }
  158778. }
  158779. }
  158780. }
  158781. }
  158782. LOCAL(void)
  158783. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158784. jvirt_barray_ptr *src_coef_arrays,
  158785. jvirt_barray_ptr *dst_coef_arrays)
  158786. {
  158787. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158788. int ci, i, j, offset_y;
  158789. JBLOCKARRAY src_buffer, dst_buffer;
  158790. JBLOCKROW src_row_ptr, dst_row_ptr;
  158791. JCOEFPTR src_ptr, dst_ptr;
  158792. jpeg_component_info *compptr;
  158793. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158794. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158795. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158796. compptr = dstinfo->comp_info + ci;
  158797. comp_width = MCU_cols * compptr->h_samp_factor;
  158798. comp_height = MCU_rows * compptr->v_samp_factor;
  158799. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158800. dst_blk_y += compptr->v_samp_factor) {
  158801. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158802. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158803. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158804. if (dst_blk_y < comp_height) {
  158805. src_buffer = (*srcinfo->mem->access_virt_barray)
  158806. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158807. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158808. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158809. } else {
  158810. src_buffer = (*srcinfo->mem->access_virt_barray)
  158811. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158812. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158813. }
  158814. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158815. if (dst_blk_y < comp_height) {
  158816. dst_row_ptr = dst_buffer[offset_y];
  158817. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158818. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158819. dst_ptr = dst_row_ptr[dst_blk_x];
  158820. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158821. for (i = 0; i < DCTSIZE; i += 2) {
  158822. for (j = 0; j < DCTSIZE; j += 2) {
  158823. *dst_ptr++ = *src_ptr++;
  158824. *dst_ptr++ = - *src_ptr++;
  158825. }
  158826. for (j = 0; j < DCTSIZE; j += 2) {
  158827. *dst_ptr++ = - *src_ptr++;
  158828. *dst_ptr++ = *src_ptr++;
  158829. }
  158830. }
  158831. }
  158832. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158833. dst_ptr = dst_row_ptr[dst_blk_x];
  158834. src_ptr = src_row_ptr[dst_blk_x];
  158835. for (i = 0; i < DCTSIZE; i += 2) {
  158836. for (j = 0; j < DCTSIZE; j++)
  158837. *dst_ptr++ = *src_ptr++;
  158838. for (j = 0; j < DCTSIZE; j++)
  158839. *dst_ptr++ = - *src_ptr++;
  158840. }
  158841. }
  158842. } else {
  158843. dst_row_ptr = dst_buffer[offset_y];
  158844. src_row_ptr = src_buffer[offset_y];
  158845. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158846. dst_ptr = dst_row_ptr[dst_blk_x];
  158847. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158848. for (i = 0; i < DCTSIZE2; i += 2) {
  158849. *dst_ptr++ = *src_ptr++;
  158850. *dst_ptr++ = - *src_ptr++;
  158851. }
  158852. }
  158853. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158854. dst_ptr = dst_row_ptr[dst_blk_x];
  158855. src_ptr = src_row_ptr[dst_blk_x];
  158856. for (i = 0; i < DCTSIZE2; i++)
  158857. *dst_ptr++ = *src_ptr++;
  158858. }
  158859. }
  158860. }
  158861. }
  158862. }
  158863. }
  158864. LOCAL(void)
  158865. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158866. jvirt_barray_ptr *src_coef_arrays,
  158867. jvirt_barray_ptr *dst_coef_arrays)
  158868. {
  158869. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158870. int ci, i, j, offset_x, offset_y;
  158871. JBLOCKARRAY src_buffer, dst_buffer;
  158872. JCOEFPTR src_ptr, dst_ptr;
  158873. jpeg_component_info *compptr;
  158874. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158875. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158876. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158877. compptr = dstinfo->comp_info + ci;
  158878. comp_width = MCU_cols * compptr->h_samp_factor;
  158879. comp_height = MCU_rows * compptr->v_samp_factor;
  158880. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158881. dst_blk_y += compptr->v_samp_factor) {
  158882. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158883. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158884. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158885. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158886. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158887. dst_blk_x += compptr->h_samp_factor) {
  158888. src_buffer = (*srcinfo->mem->access_virt_barray)
  158889. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158890. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158891. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158892. if (dst_blk_y < comp_height) {
  158893. src_ptr = src_buffer[offset_x]
  158894. [comp_height - dst_blk_y - offset_y - 1];
  158895. if (dst_blk_x < comp_width) {
  158896. dst_ptr = dst_buffer[offset_y]
  158897. [comp_width - dst_blk_x - offset_x - 1];
  158898. for (i = 0; i < DCTSIZE; i++) {
  158899. for (j = 0; j < DCTSIZE; j++) {
  158900. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158901. j++;
  158902. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158903. }
  158904. i++;
  158905. for (j = 0; j < DCTSIZE; j++) {
  158906. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158907. j++;
  158908. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158909. }
  158910. }
  158911. } else {
  158912. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158913. for (i = 0; i < DCTSIZE; 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. }
  158921. } else {
  158922. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158923. if (dst_blk_x < comp_width) {
  158924. dst_ptr = dst_buffer[offset_y]
  158925. [comp_width - dst_blk_x - offset_x - 1];
  158926. for (i = 0; i < DCTSIZE; i++) {
  158927. for (j = 0; j < DCTSIZE; j++)
  158928. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158929. i++;
  158930. for (j = 0; j < DCTSIZE; j++)
  158931. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158932. }
  158933. } else {
  158934. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  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. }
  158939. }
  158940. }
  158941. }
  158942. }
  158943. }
  158944. }
  158945. }
  158946. GLOBAL(void)
  158947. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158948. jpeg_transform_info *info)
  158949. {
  158950. jvirt_barray_ptr *coef_arrays = NULL;
  158951. jpeg_component_info *compptr;
  158952. int ci;
  158953. if (info->force_grayscale &&
  158954. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158955. srcinfo->num_components == 3) {
  158956. info->num_components = 1;
  158957. } else {
  158958. info->num_components = srcinfo->num_components;
  158959. }
  158960. switch (info->transform) {
  158961. case JXFORM_NONE:
  158962. case JXFORM_FLIP_H:
  158963. break;
  158964. case JXFORM_FLIP_V:
  158965. case JXFORM_ROT_180:
  158966. coef_arrays = (jvirt_barray_ptr *)
  158967. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158968. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158969. for (ci = 0; ci < info->num_components; ci++) {
  158970. compptr = srcinfo->comp_info + ci;
  158971. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158972. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158973. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158974. (long) compptr->h_samp_factor),
  158975. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158976. (long) compptr->v_samp_factor),
  158977. (JDIMENSION) compptr->v_samp_factor);
  158978. }
  158979. break;
  158980. case JXFORM_TRANSPOSE:
  158981. case JXFORM_TRANSVERSE:
  158982. case JXFORM_ROT_90:
  158983. case JXFORM_ROT_270:
  158984. coef_arrays = (jvirt_barray_ptr *)
  158985. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158986. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158987. for (ci = 0; ci < info->num_components; ci++) {
  158988. compptr = srcinfo->comp_info + ci;
  158989. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158990. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158991. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158992. (long) compptr->v_samp_factor),
  158993. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158994. (long) compptr->h_samp_factor),
  158995. (JDIMENSION) compptr->h_samp_factor);
  158996. }
  158997. break;
  158998. }
  158999. info->workspace_coef_arrays = coef_arrays;
  159000. }
  159001. LOCAL(void)
  159002. transpose_critical_parameters (j_compress_ptr dstinfo)
  159003. {
  159004. int tblno, i, j, ci, itemp;
  159005. jpeg_component_info *compptr;
  159006. JQUANT_TBL *qtblptr;
  159007. JDIMENSION dtemp;
  159008. UINT16 qtemp;
  159009. dtemp = dstinfo->image_width;
  159010. dstinfo->image_width = dstinfo->image_height;
  159011. dstinfo->image_height = dtemp;
  159012. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159013. compptr = dstinfo->comp_info + ci;
  159014. itemp = compptr->h_samp_factor;
  159015. compptr->h_samp_factor = compptr->v_samp_factor;
  159016. compptr->v_samp_factor = itemp;
  159017. }
  159018. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  159019. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  159020. if (qtblptr != NULL) {
  159021. for (i = 0; i < DCTSIZE; i++) {
  159022. for (j = 0; j < i; j++) {
  159023. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  159024. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  159025. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  159026. }
  159027. }
  159028. }
  159029. }
  159030. }
  159031. LOCAL(void)
  159032. trim_right_edge (j_compress_ptr dstinfo)
  159033. {
  159034. int ci, max_h_samp_factor;
  159035. JDIMENSION MCU_cols;
  159036. max_h_samp_factor = 1;
  159037. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159038. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  159039. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  159040. }
  159041. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  159042. if (MCU_cols > 0) /* can't trim to 0 pixels */
  159043. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  159044. }
  159045. LOCAL(void)
  159046. trim_bottom_edge (j_compress_ptr dstinfo)
  159047. {
  159048. int ci, max_v_samp_factor;
  159049. JDIMENSION MCU_rows;
  159050. max_v_samp_factor = 1;
  159051. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159052. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  159053. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  159054. }
  159055. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  159056. if (MCU_rows > 0) /* can't trim to 0 pixels */
  159057. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  159058. }
  159059. GLOBAL(jvirt_barray_ptr *)
  159060. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  159061. j_compress_ptr dstinfo,
  159062. jvirt_barray_ptr *src_coef_arrays,
  159063. jpeg_transform_info *info)
  159064. {
  159065. if (info->force_grayscale) {
  159066. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  159067. dstinfo->num_components == 3) ||
  159068. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  159069. dstinfo->num_components == 1)) {
  159070. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  159071. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  159072. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  159073. } else {
  159074. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  159075. }
  159076. }
  159077. switch (info->transform) {
  159078. case JXFORM_NONE:
  159079. break;
  159080. case JXFORM_FLIP_H:
  159081. if (info->trim)
  159082. trim_right_edge(dstinfo);
  159083. break;
  159084. case JXFORM_FLIP_V:
  159085. if (info->trim)
  159086. trim_bottom_edge(dstinfo);
  159087. break;
  159088. case JXFORM_TRANSPOSE:
  159089. transpose_critical_parameters(dstinfo);
  159090. break;
  159091. case JXFORM_TRANSVERSE:
  159092. transpose_critical_parameters(dstinfo);
  159093. if (info->trim) {
  159094. trim_right_edge(dstinfo);
  159095. trim_bottom_edge(dstinfo);
  159096. }
  159097. break;
  159098. case JXFORM_ROT_90:
  159099. transpose_critical_parameters(dstinfo);
  159100. if (info->trim)
  159101. trim_right_edge(dstinfo);
  159102. break;
  159103. case JXFORM_ROT_180:
  159104. if (info->trim) {
  159105. trim_right_edge(dstinfo);
  159106. trim_bottom_edge(dstinfo);
  159107. }
  159108. break;
  159109. case JXFORM_ROT_270:
  159110. transpose_critical_parameters(dstinfo);
  159111. if (info->trim)
  159112. trim_bottom_edge(dstinfo);
  159113. break;
  159114. }
  159115. if (info->workspace_coef_arrays != NULL)
  159116. return info->workspace_coef_arrays;
  159117. return src_coef_arrays;
  159118. }
  159119. GLOBAL(void)
  159120. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  159121. j_compress_ptr dstinfo,
  159122. jvirt_barray_ptr *src_coef_arrays,
  159123. jpeg_transform_info *info)
  159124. {
  159125. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  159126. switch (info->transform) {
  159127. case JXFORM_NONE:
  159128. break;
  159129. case JXFORM_FLIP_H:
  159130. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  159131. break;
  159132. case JXFORM_FLIP_V:
  159133. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159134. break;
  159135. case JXFORM_TRANSPOSE:
  159136. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159137. break;
  159138. case JXFORM_TRANSVERSE:
  159139. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159140. break;
  159141. case JXFORM_ROT_90:
  159142. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159143. break;
  159144. case JXFORM_ROT_180:
  159145. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159146. break;
  159147. case JXFORM_ROT_270:
  159148. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159149. break;
  159150. }
  159151. }
  159152. #endif /* TRANSFORMS_SUPPORTED */
  159153. GLOBAL(void)
  159154. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  159155. {
  159156. #ifdef SAVE_MARKERS_SUPPORTED
  159157. int m;
  159158. if (option != JCOPYOPT_NONE) {
  159159. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  159160. }
  159161. if (option == JCOPYOPT_ALL) {
  159162. for (m = 0; m < 16; m++)
  159163. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  159164. }
  159165. #endif /* SAVE_MARKERS_SUPPORTED */
  159166. }
  159167. GLOBAL(void)
  159168. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159169. JCOPY_OPTION option)
  159170. {
  159171. jpeg_saved_marker_ptr marker;
  159172. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  159173. if (dstinfo->write_JFIF_header &&
  159174. marker->marker == JPEG_APP0 &&
  159175. marker->data_length >= 5 &&
  159176. GETJOCTET(marker->data[0]) == 0x4A &&
  159177. GETJOCTET(marker->data[1]) == 0x46 &&
  159178. GETJOCTET(marker->data[2]) == 0x49 &&
  159179. GETJOCTET(marker->data[3]) == 0x46 &&
  159180. GETJOCTET(marker->data[4]) == 0)
  159181. continue; /* reject duplicate JFIF */
  159182. if (dstinfo->write_Adobe_marker &&
  159183. marker->marker == JPEG_APP0+14 &&
  159184. marker->data_length >= 5 &&
  159185. GETJOCTET(marker->data[0]) == 0x41 &&
  159186. GETJOCTET(marker->data[1]) == 0x64 &&
  159187. GETJOCTET(marker->data[2]) == 0x6F &&
  159188. GETJOCTET(marker->data[3]) == 0x62 &&
  159189. GETJOCTET(marker->data[4]) == 0x65)
  159190. continue; /* reject duplicate Adobe */
  159191. #ifdef NEED_FAR_POINTERS
  159192. {
  159193. unsigned int i;
  159194. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  159195. for (i = 0; i < marker->data_length; i++)
  159196. jpeg_write_m_byte(dstinfo, marker->data[i]);
  159197. }
  159198. #else
  159199. jpeg_write_marker(dstinfo, marker->marker,
  159200. marker->data, marker->data_length);
  159201. #endif
  159202. }
  159203. }
  159204. /*** End of inlined file: transupp.c ***/
  159205. }
  159206. #else
  159207. #define JPEG_INTERNALS
  159208. #undef FAR
  159209. #include <jpeglib.h>
  159210. #endif
  159211. }
  159212. #if JUCE_MSVC
  159213. #pragma warning (pop)
  159214. #endif
  159215. BEGIN_JUCE_NAMESPACE
  159216. using namespace jpeglibNamespace;
  159217. #if ! JUCE_MSVC
  159218. using jpeglibNamespace::boolean;
  159219. #endif
  159220. struct JPEGDecodingFailure {};
  159221. static void fatalErrorHandler (j_common_ptr)
  159222. {
  159223. throw JPEGDecodingFailure();
  159224. }
  159225. static void silentErrorCallback1 (j_common_ptr) {}
  159226. static void silentErrorCallback2 (j_common_ptr, int) {}
  159227. static void silentErrorCallback3 (j_common_ptr, char*) {}
  159228. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  159229. {
  159230. zerostruct (err);
  159231. err.error_exit = fatalErrorHandler;
  159232. err.emit_message = silentErrorCallback2;
  159233. err.output_message = silentErrorCallback1;
  159234. err.format_message = silentErrorCallback3;
  159235. err.reset_error_mgr = silentErrorCallback1;
  159236. }
  159237. static void dummyCallback1 (j_decompress_ptr)
  159238. {
  159239. }
  159240. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  159241. {
  159242. decompStruct->src->next_input_byte += num;
  159243. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  159244. decompStruct->src->bytes_in_buffer -= num;
  159245. }
  159246. static boolean jpegFill (j_decompress_ptr)
  159247. {
  159248. return 0;
  159249. }
  159250. Image* juce_loadJPEGImageFromStream (InputStream& in)
  159251. {
  159252. MemoryBlock mb;
  159253. in.readIntoMemoryBlock (mb);
  159254. Image* image = 0;
  159255. if (mb.getSize() > 16)
  159256. {
  159257. struct jpeg_decompress_struct jpegDecompStruct;
  159258. struct jpeg_error_mgr jerr;
  159259. setupSilentErrorHandler (jerr);
  159260. jpegDecompStruct.err = &jerr;
  159261. jpeg_create_decompress (&jpegDecompStruct);
  159262. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  159263. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  159264. jpegDecompStruct.src->init_source = dummyCallback1;
  159265. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  159266. jpegDecompStruct.src->skip_input_data = jpegSkip;
  159267. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  159268. jpegDecompStruct.src->term_source = dummyCallback1;
  159269. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  159270. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  159271. try
  159272. {
  159273. jpeg_read_header (&jpegDecompStruct, TRUE);
  159274. jpeg_calc_output_dimensions (&jpegDecompStruct);
  159275. const int width = jpegDecompStruct.output_width;
  159276. const int height = jpegDecompStruct.output_height;
  159277. jpegDecompStruct.out_color_space = JCS_RGB;
  159278. JSAMPARRAY buffer
  159279. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  159280. JPOOL_IMAGE,
  159281. width * 3, 1);
  159282. if (jpeg_start_decompress (&jpegDecompStruct))
  159283. {
  159284. image = Image::createNativeImage (Image::RGB, width, height, false);
  159285. const bool hasAlphaChan = image->hasAlphaChannel();
  159286. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159287. for (int y = 0; y < height; ++y)
  159288. {
  159289. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159290. const uint8* src = *buffer;
  159291. uint8* dest = destData.getLinePointer (y);
  159292. if (hasAlphaChan)
  159293. {
  159294. for (int i = width; --i >= 0;)
  159295. {
  159296. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159297. ((PixelARGB*) dest)->premultiply();
  159298. dest += destData.pixelStride;
  159299. src += 3;
  159300. }
  159301. }
  159302. else
  159303. {
  159304. for (int i = width; --i >= 0;)
  159305. {
  159306. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159307. dest += destData.pixelStride;
  159308. src += 3;
  159309. }
  159310. }
  159311. }
  159312. jpeg_finish_decompress (&jpegDecompStruct);
  159313. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159314. }
  159315. jpeg_destroy_decompress (&jpegDecompStruct);
  159316. }
  159317. catch (...)
  159318. {}
  159319. }
  159320. return image;
  159321. }
  159322. static const int jpegBufferSize = 512;
  159323. struct JuceJpegDest : public jpeg_destination_mgr
  159324. {
  159325. OutputStream* output;
  159326. char* buffer;
  159327. };
  159328. static void jpegWriteInit (j_compress_ptr)
  159329. {
  159330. }
  159331. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159332. {
  159333. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159334. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159335. dest->output->write (dest->buffer, (int) numToWrite);
  159336. }
  159337. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159338. {
  159339. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159340. const int numToWrite = jpegBufferSize;
  159341. dest->next_output_byte = (JOCTET*) dest->buffer;
  159342. dest->free_in_buffer = jpegBufferSize;
  159343. return dest->output->write (dest->buffer, numToWrite);
  159344. }
  159345. bool juce_writeJPEGImageToStream (const Image& image,
  159346. OutputStream& out,
  159347. float quality)
  159348. {
  159349. if (image.hasAlphaChannel())
  159350. {
  159351. // this method could fill the background in white and still save the image..
  159352. jassertfalse
  159353. return true;
  159354. }
  159355. struct jpeg_compress_struct jpegCompStruct;
  159356. struct jpeg_error_mgr jerr;
  159357. setupSilentErrorHandler (jerr);
  159358. jpegCompStruct.err = &jerr;
  159359. jpeg_create_compress (&jpegCompStruct);
  159360. JuceJpegDest dest;
  159361. jpegCompStruct.dest = &dest;
  159362. dest.output = &out;
  159363. HeapBlock <char> tempBuffer (jpegBufferSize);
  159364. dest.buffer = (char*) tempBuffer;
  159365. dest.next_output_byte = (JOCTET*) dest.buffer;
  159366. dest.free_in_buffer = jpegBufferSize;
  159367. dest.init_destination = jpegWriteInit;
  159368. dest.empty_output_buffer = jpegWriteFlush;
  159369. dest.term_destination = jpegWriteTerminate;
  159370. jpegCompStruct.image_width = image.getWidth();
  159371. jpegCompStruct.image_height = image.getHeight();
  159372. jpegCompStruct.input_components = 3;
  159373. jpegCompStruct.in_color_space = JCS_RGB;
  159374. jpegCompStruct.write_JFIF_header = 1;
  159375. jpegCompStruct.X_density = 72;
  159376. jpegCompStruct.Y_density = 72;
  159377. jpeg_set_defaults (&jpegCompStruct);
  159378. jpegCompStruct.dct_method = JDCT_FLOAT;
  159379. jpegCompStruct.optimize_coding = 1;
  159380. // jpegCompStruct.smoothing_factor = 10;
  159381. if (quality < 0.0f)
  159382. quality = 0.85f;
  159383. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159384. jpeg_start_compress (&jpegCompStruct, TRUE);
  159385. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159386. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159387. JPOOL_IMAGE,
  159388. strideBytes, 1);
  159389. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159390. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159391. {
  159392. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159393. uint8* dst = *buffer;
  159394. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159395. {
  159396. *dst++ = ((const PixelRGB*) src)->getRed();
  159397. *dst++ = ((const PixelRGB*) src)->getGreen();
  159398. *dst++ = ((const PixelRGB*) src)->getBlue();
  159399. src += srcData.pixelStride;
  159400. }
  159401. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159402. }
  159403. jpeg_finish_compress (&jpegCompStruct);
  159404. jpeg_destroy_compress (&jpegCompStruct);
  159405. out.flush();
  159406. return true;
  159407. }
  159408. END_JUCE_NAMESPACE
  159409. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159410. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159411. #ifdef _MSC_VER
  159412. #pragma warning (push)
  159413. #pragma warning (disable: 4390 4611)
  159414. #endif
  159415. namespace zlibNamespace
  159416. {
  159417. #if JUCE_INCLUDE_ZLIB_CODE
  159418. #undef OS_CODE
  159419. #undef fdopen
  159420. #undef OS_CODE
  159421. #else
  159422. #include <zlib.h>
  159423. #endif
  159424. }
  159425. namespace pnglibNamespace
  159426. {
  159427. using namespace zlibNamespace;
  159428. #if JUCE_INCLUDE_PNGLIB_CODE
  159429. #if _MSC_VER != 1310
  159430. using ::calloc; // (causes conflict in VS.NET 2003)
  159431. using ::malloc;
  159432. using ::free;
  159433. #endif
  159434. extern "C"
  159435. {
  159436. using ::abs;
  159437. #define PNG_INTERNAL
  159438. #define NO_DUMMY_DECL
  159439. #define PNG_SETJMP_NOT_SUPPORTED
  159440. /*** Start of inlined file: png.h ***/
  159441. #ifndef PNG_H
  159442. #define PNG_H
  159443. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159444. #define PNG_HEADER_VERSION_STRING \
  159445. " libpng version 1.2.21 - October 4, 2007\n"
  159446. #define PNG_LIBPNG_VER_SONUM 0
  159447. #define PNG_LIBPNG_VER_DLLNUM 13
  159448. #define PNG_LIBPNG_VER_MAJOR 1
  159449. #define PNG_LIBPNG_VER_MINOR 2
  159450. #define PNG_LIBPNG_VER_RELEASE 21
  159451. #define PNG_LIBPNG_VER_BUILD 0
  159452. #define PNG_LIBPNG_BUILD_ALPHA 1
  159453. #define PNG_LIBPNG_BUILD_BETA 2
  159454. #define PNG_LIBPNG_BUILD_RC 3
  159455. #define PNG_LIBPNG_BUILD_STABLE 4
  159456. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159457. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159458. PNG_LIBPNG_BUILD_STABLE only */
  159459. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159460. PNG_LIBPNG_BUILD_SPECIAL */
  159461. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159462. PNG_LIBPNG_BUILD_PRIVATE */
  159463. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159464. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159465. #ifndef PNG_VERSION_INFO_ONLY
  159466. #endif
  159467. /*** Start of inlined file: pngconf.h ***/
  159468. #ifndef PNGCONF_H
  159469. #define PNGCONF_H
  159470. #define PNG_1_2_X
  159471. // These are some Juce config settings that should remove any unnecessary code bloat..
  159472. #define PNG_NO_STDIO 1
  159473. #define PNG_DEBUG 0
  159474. #define PNG_NO_WARNINGS 1
  159475. #define PNG_NO_ERROR_TEXT 1
  159476. #define PNG_NO_ERROR_NUMBERS 1
  159477. #define PNG_NO_USER_MEM 1
  159478. #define PNG_NO_READ_iCCP 1
  159479. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159480. #define PNG_NO_READ_USER_CHUNKS 1
  159481. #define PNG_NO_READ_iTXt 1
  159482. #define PNG_NO_READ_sCAL 1
  159483. #define PNG_NO_READ_sPLT 1
  159484. #define png_error(a, b) png_err(a)
  159485. #define png_warning(a, b)
  159486. #define png_chunk_error(a, b) png_err(a)
  159487. #define png_chunk_warning(a, b)
  159488. #ifdef PNG_USER_CONFIG
  159489. # ifndef PNG_USER_PRIVATEBUILD
  159490. # define PNG_USER_PRIVATEBUILD
  159491. # endif
  159492. #include "pngusr.h"
  159493. #endif
  159494. #ifdef PNG_CONFIGURE_LIBPNG
  159495. #ifdef HAVE_CONFIG_H
  159496. #include "config.h"
  159497. #endif
  159498. #endif
  159499. #ifdef __STDC__
  159500. #ifdef SPECIALBUILD
  159501. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159502. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159503. #endif
  159504. #ifdef PRIVATEBUILD
  159505. # pragma message("PRIVATEBUILD is deprecated.\
  159506. Use PNG_USER_PRIVATEBUILD instead.")
  159507. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159508. #endif
  159509. #endif /* __STDC__ */
  159510. #ifndef PNG_VERSION_INFO_ONLY
  159511. # define PNG_WARN_UNINITIALIZED_ROW 1
  159512. #ifndef PNG_ZBUF_SIZE
  159513. # define PNG_ZBUF_SIZE 8192
  159514. #endif
  159515. #ifndef PNG_NO_READ_SUPPORTED
  159516. # define PNG_READ_SUPPORTED
  159517. #endif
  159518. #ifndef PNG_NO_WRITE_SUPPORTED
  159519. # define PNG_WRITE_SUPPORTED
  159520. #endif
  159521. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159522. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159523. # define PNG_MNG_FEATURES_SUPPORTED
  159524. # endif
  159525. #endif
  159526. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159527. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159528. # define PNG_FLOATING_POINT_SUPPORTED
  159529. # endif
  159530. #endif
  159531. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159532. # define PNG_MAX_MALLOC_64K
  159533. #endif
  159534. #if defined(__CYGWIN__)
  159535. # if defined(ALL_STATIC)
  159536. # if defined(PNG_BUILD_DLL)
  159537. # undef PNG_BUILD_DLL
  159538. # endif
  159539. # if defined(PNG_USE_DLL)
  159540. # undef PNG_USE_DLL
  159541. # endif
  159542. # if defined(PNG_DLL)
  159543. # undef PNG_DLL
  159544. # endif
  159545. # if !defined(PNG_STATIC)
  159546. # define PNG_STATIC
  159547. # endif
  159548. # else
  159549. # if defined (PNG_BUILD_DLL)
  159550. # if defined(PNG_STATIC)
  159551. # undef PNG_STATIC
  159552. # endif
  159553. # if defined(PNG_USE_DLL)
  159554. # undef PNG_USE_DLL
  159555. # endif
  159556. # if !defined(PNG_DLL)
  159557. # define PNG_DLL
  159558. # endif
  159559. # else
  159560. # if defined(PNG_STATIC)
  159561. # if defined(PNG_USE_DLL)
  159562. # undef PNG_USE_DLL
  159563. # endif
  159564. # if defined(PNG_DLL)
  159565. # undef PNG_DLL
  159566. # endif
  159567. # else
  159568. # if !defined(PNG_USE_DLL)
  159569. # define PNG_USE_DLL
  159570. # endif
  159571. # if !defined(PNG_DLL)
  159572. # define PNG_DLL
  159573. # endif
  159574. # endif
  159575. # endif
  159576. # endif
  159577. #endif
  159578. #if defined(_WIN32_WCE)
  159579. # include <windows.h>
  159580. # define PNG_NO_CONSOLE_IO
  159581. # ifdef PNG_DEBUG
  159582. # undef PNG_DEBUG
  159583. # endif
  159584. #endif
  159585. #ifdef PNG_BUILD_DLL
  159586. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159587. # ifndef PNG_NO_CONSOLE_IO
  159588. # define PNG_NO_CONSOLE_IO
  159589. # endif
  159590. # endif
  159591. #endif
  159592. # ifdef PNG_NO_STDIO
  159593. # ifndef PNG_NO_CONSOLE_IO
  159594. # define PNG_NO_CONSOLE_IO
  159595. # endif
  159596. # ifdef PNG_DEBUG
  159597. # if (PNG_DEBUG > 0)
  159598. # include <stdio.h>
  159599. # endif
  159600. # endif
  159601. # else
  159602. # if !defined(_WIN32_WCE)
  159603. # include <stdio.h>
  159604. # endif
  159605. # endif
  159606. #ifndef PNGARG
  159607. #ifdef OF /* zlib prototype munger */
  159608. # define PNGARG(arglist) OF(arglist)
  159609. #else
  159610. #ifdef _NO_PROTO
  159611. # define PNGARG(arglist) ()
  159612. # ifndef PNG_TYPECAST_NULL
  159613. # define PNG_TYPECAST_NULL
  159614. # endif
  159615. #else
  159616. # define PNGARG(arglist) arglist
  159617. #endif /* _NO_PROTO */
  159618. #endif /* OF */
  159619. #endif /* PNGARG */
  159620. #ifndef MACOS
  159621. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159622. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159623. # define MACOS
  159624. # endif
  159625. #endif
  159626. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159627. # include <sys/types.h>
  159628. #endif
  159629. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159630. # define PNG_SETJMP_SUPPORTED
  159631. #endif
  159632. #ifdef PNG_SETJMP_SUPPORTED
  159633. # ifdef __linux__
  159634. # ifdef _BSD_SOURCE
  159635. # define PNG_SAVE_BSD_SOURCE
  159636. # undef _BSD_SOURCE
  159637. # endif
  159638. # ifdef _SETJMP_H
  159639. __png.h__ already includes setjmp.h;
  159640. __dont__ include it again.;
  159641. # endif
  159642. # endif /* __linux__ */
  159643. # include <setjmp.h>
  159644. # ifdef __linux__
  159645. # ifdef PNG_SAVE_BSD_SOURCE
  159646. # define _BSD_SOURCE
  159647. # undef PNG_SAVE_BSD_SOURCE
  159648. # endif
  159649. # endif /* __linux__ */
  159650. #endif /* PNG_SETJMP_SUPPORTED */
  159651. #ifdef BSD
  159652. #if ! JUCE_MAC
  159653. # include <strings.h>
  159654. #endif
  159655. #else
  159656. # include <string.h>
  159657. #endif
  159658. #ifdef PNG_INTERNAL
  159659. #include <stdlib.h>
  159660. #define PNG_EXTERN
  159661. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159662. # if defined(MACOS)
  159663. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159664. # include <fp.h>
  159665. # endif
  159666. # else
  159667. # include <math.h>
  159668. # endif
  159669. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159670. # include <m68881.h>
  159671. # endif
  159672. #endif
  159673. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159674. # define PNG_ALWAYS_EXTERN
  159675. #endif
  159676. #if defined(__TURBOC__) && defined(__MSDOS__)
  159677. # include <mem.h>
  159678. # include <alloc.h>
  159679. #endif
  159680. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159681. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159682. # include <malloc.h>
  159683. #endif
  159684. #ifndef PNG_DITHER_RED_BITS
  159685. # define PNG_DITHER_RED_BITS 5
  159686. #endif
  159687. #ifndef PNG_DITHER_GREEN_BITS
  159688. # define PNG_DITHER_GREEN_BITS 5
  159689. #endif
  159690. #ifndef PNG_DITHER_BLUE_BITS
  159691. # define PNG_DITHER_BLUE_BITS 5
  159692. #endif
  159693. #ifndef PNG_MAX_GAMMA_8
  159694. # define PNG_MAX_GAMMA_8 11
  159695. #endif
  159696. #ifndef PNG_GAMMA_THRESHOLD
  159697. # define PNG_GAMMA_THRESHOLD 0.05
  159698. #endif
  159699. #endif /* PNG_INTERNAL */
  159700. #ifndef PNG_NO_CONST
  159701. # define PNG_CONST const
  159702. #else
  159703. # define PNG_CONST
  159704. #endif
  159705. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159706. # ifndef PNG_NO_iTXt_SUPPORTED
  159707. # define PNG_NO_iTXt_SUPPORTED
  159708. # endif
  159709. # ifndef PNG_NO_READ_iTXt
  159710. # define PNG_NO_READ_iTXt
  159711. # endif
  159712. # ifndef PNG_NO_WRITE_iTXt
  159713. # define PNG_NO_WRITE_iTXt
  159714. # endif
  159715. #endif
  159716. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159717. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159718. # define PNG_READ_iTXt
  159719. # endif
  159720. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159721. # define PNG_WRITE_iTXt
  159722. # endif
  159723. #endif
  159724. #ifdef PNG_LEGACY_SUPPORTED
  159725. # define PNG_NO_FREE_ME
  159726. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159727. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159728. # define PNG_NO_READ_USER_CHUNKS
  159729. # define PNG_NO_READ_iCCP
  159730. # define PNG_NO_WRITE_iCCP
  159731. # define PNG_NO_READ_iTXt
  159732. # define PNG_NO_WRITE_iTXt
  159733. # define PNG_NO_READ_sCAL
  159734. # define PNG_NO_WRITE_sCAL
  159735. # define PNG_NO_READ_sPLT
  159736. # define PNG_NO_WRITE_sPLT
  159737. # define PNG_NO_INFO_IMAGE
  159738. # define PNG_NO_READ_RGB_TO_GRAY
  159739. # define PNG_NO_READ_USER_TRANSFORM
  159740. # define PNG_NO_WRITE_USER_TRANSFORM
  159741. # define PNG_NO_USER_MEM
  159742. # define PNG_NO_READ_EMPTY_PLTE
  159743. # define PNG_NO_MNG_FEATURES
  159744. # define PNG_NO_FIXED_POINT_SUPPORTED
  159745. #endif
  159746. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159747. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159748. # define PNG_FIXED_POINT_SUPPORTED
  159749. #endif
  159750. #ifndef PNG_NO_FREE_ME
  159751. # define PNG_FREE_ME_SUPPORTED
  159752. #endif
  159753. #if defined(PNG_READ_SUPPORTED)
  159754. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159755. !defined(PNG_NO_READ_TRANSFORMS)
  159756. # define PNG_READ_TRANSFORMS_SUPPORTED
  159757. #endif
  159758. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159759. # ifndef PNG_NO_READ_EXPAND
  159760. # define PNG_READ_EXPAND_SUPPORTED
  159761. # endif
  159762. # ifndef PNG_NO_READ_SHIFT
  159763. # define PNG_READ_SHIFT_SUPPORTED
  159764. # endif
  159765. # ifndef PNG_NO_READ_PACK
  159766. # define PNG_READ_PACK_SUPPORTED
  159767. # endif
  159768. # ifndef PNG_NO_READ_BGR
  159769. # define PNG_READ_BGR_SUPPORTED
  159770. # endif
  159771. # ifndef PNG_NO_READ_SWAP
  159772. # define PNG_READ_SWAP_SUPPORTED
  159773. # endif
  159774. # ifndef PNG_NO_READ_PACKSWAP
  159775. # define PNG_READ_PACKSWAP_SUPPORTED
  159776. # endif
  159777. # ifndef PNG_NO_READ_INVERT
  159778. # define PNG_READ_INVERT_SUPPORTED
  159779. # endif
  159780. # ifndef PNG_NO_READ_DITHER
  159781. # define PNG_READ_DITHER_SUPPORTED
  159782. # endif
  159783. # ifndef PNG_NO_READ_BACKGROUND
  159784. # define PNG_READ_BACKGROUND_SUPPORTED
  159785. # endif
  159786. # ifndef PNG_NO_READ_16_TO_8
  159787. # define PNG_READ_16_TO_8_SUPPORTED
  159788. # endif
  159789. # ifndef PNG_NO_READ_FILLER
  159790. # define PNG_READ_FILLER_SUPPORTED
  159791. # endif
  159792. # ifndef PNG_NO_READ_GAMMA
  159793. # define PNG_READ_GAMMA_SUPPORTED
  159794. # endif
  159795. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159796. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159797. # endif
  159798. # ifndef PNG_NO_READ_SWAP_ALPHA
  159799. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159800. # endif
  159801. # ifndef PNG_NO_READ_INVERT_ALPHA
  159802. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159803. # endif
  159804. # ifndef PNG_NO_READ_STRIP_ALPHA
  159805. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159806. # endif
  159807. # ifndef PNG_NO_READ_USER_TRANSFORM
  159808. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159809. # endif
  159810. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159811. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159812. # endif
  159813. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159814. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159815. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159816. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159817. #endif /* about interlacing capability! You'll */
  159818. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159819. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159820. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159821. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159822. # endif
  159823. #endif
  159824. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159825. #ifndef PNG_NO_READ_EMPTY_PLTE
  159826. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159827. #endif
  159828. #endif
  159829. #endif /* PNG_READ_SUPPORTED */
  159830. #if defined(PNG_WRITE_SUPPORTED)
  159831. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159832. !defined(PNG_NO_WRITE_TRANSFORMS)
  159833. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159834. #endif
  159835. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159836. # ifndef PNG_NO_WRITE_SHIFT
  159837. # define PNG_WRITE_SHIFT_SUPPORTED
  159838. # endif
  159839. # ifndef PNG_NO_WRITE_PACK
  159840. # define PNG_WRITE_PACK_SUPPORTED
  159841. # endif
  159842. # ifndef PNG_NO_WRITE_BGR
  159843. # define PNG_WRITE_BGR_SUPPORTED
  159844. # endif
  159845. # ifndef PNG_NO_WRITE_SWAP
  159846. # define PNG_WRITE_SWAP_SUPPORTED
  159847. # endif
  159848. # ifndef PNG_NO_WRITE_PACKSWAP
  159849. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159850. # endif
  159851. # ifndef PNG_NO_WRITE_INVERT
  159852. # define PNG_WRITE_INVERT_SUPPORTED
  159853. # endif
  159854. # ifndef PNG_NO_WRITE_FILLER
  159855. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159856. # endif
  159857. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159858. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159859. # endif
  159860. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159861. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159862. # endif
  159863. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159864. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159865. # endif
  159866. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159867. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159868. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159869. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159870. encoders, but can cause trouble
  159871. if left undefined */
  159872. #endif
  159873. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159874. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159875. defined(PNG_FLOATING_POINT_SUPPORTED)
  159876. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159877. #endif
  159878. #ifndef PNG_NO_WRITE_FLUSH
  159879. # define PNG_WRITE_FLUSH_SUPPORTED
  159880. #endif
  159881. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159882. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159883. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159884. #endif
  159885. #endif
  159886. #endif /* PNG_WRITE_SUPPORTED */
  159887. #ifndef PNG_1_0_X
  159888. # ifndef PNG_NO_ERROR_NUMBERS
  159889. # define PNG_ERROR_NUMBERS_SUPPORTED
  159890. # endif
  159891. #endif /* PNG_1_0_X */
  159892. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159893. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159894. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159895. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159896. # endif
  159897. #endif
  159898. #ifndef PNG_NO_STDIO
  159899. # define PNG_TIME_RFC1123_SUPPORTED
  159900. #endif
  159901. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159902. # define PNG_EASY_ACCESS_SUPPORTED
  159903. #endif
  159904. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159905. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159906. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159907. # endif
  159908. #endif
  159909. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159910. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159911. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159912. # endif
  159913. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159914. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159915. # define PNG_NO_MMX_CODE
  159916. # endif
  159917. # endif
  159918. # if defined(__APPLE__)
  159919. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159920. # define PNG_NO_MMX_CODE
  159921. # endif
  159922. # endif
  159923. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159924. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159925. # define PNG_NO_MMX_CODE
  159926. # endif
  159927. # endif
  159928. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159929. # define PNG_MMX_CODE_SUPPORTED
  159930. # endif
  159931. #endif
  159932. #if !defined(PNG_1_0_X)
  159933. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159934. # define PNG_USER_MEM_SUPPORTED
  159935. #endif
  159936. #endif /* PNG_1_0_X */
  159937. #if !defined(PNG_1_0_X)
  159938. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159939. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159940. # define PNG_SET_USER_LIMITS_SUPPORTED
  159941. #endif
  159942. #endif
  159943. #endif /* PNG_1_0_X */
  159944. #ifndef PNG_USER_WIDTH_MAX
  159945. # define PNG_USER_WIDTH_MAX 1000000L
  159946. #endif
  159947. #ifndef PNG_USER_HEIGHT_MAX
  159948. # define PNG_USER_HEIGHT_MAX 1000000L
  159949. #endif
  159950. #if defined(PNG_READ_SUPPORTED) && \
  159951. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159952. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159953. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159954. #endif
  159955. #if defined(PNG_WRITE_SUPPORTED) && \
  159956. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159957. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159958. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159959. #endif
  159960. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159961. #ifdef PNG_NO_READ_TEXT
  159962. # define PNG_NO_READ_iTXt
  159963. # define PNG_NO_READ_tEXt
  159964. # define PNG_NO_READ_zTXt
  159965. #endif
  159966. #ifndef PNG_NO_READ_bKGD
  159967. # define PNG_READ_bKGD_SUPPORTED
  159968. # define PNG_bKGD_SUPPORTED
  159969. #endif
  159970. #ifndef PNG_NO_READ_cHRM
  159971. # define PNG_READ_cHRM_SUPPORTED
  159972. # define PNG_cHRM_SUPPORTED
  159973. #endif
  159974. #ifndef PNG_NO_READ_gAMA
  159975. # define PNG_READ_gAMA_SUPPORTED
  159976. # define PNG_gAMA_SUPPORTED
  159977. #endif
  159978. #ifndef PNG_NO_READ_hIST
  159979. # define PNG_READ_hIST_SUPPORTED
  159980. # define PNG_hIST_SUPPORTED
  159981. #endif
  159982. #ifndef PNG_NO_READ_iCCP
  159983. # define PNG_READ_iCCP_SUPPORTED
  159984. # define PNG_iCCP_SUPPORTED
  159985. #endif
  159986. #ifndef PNG_NO_READ_iTXt
  159987. # ifndef PNG_READ_iTXt_SUPPORTED
  159988. # define PNG_READ_iTXt_SUPPORTED
  159989. # endif
  159990. # ifndef PNG_iTXt_SUPPORTED
  159991. # define PNG_iTXt_SUPPORTED
  159992. # endif
  159993. #endif
  159994. #ifndef PNG_NO_READ_oFFs
  159995. # define PNG_READ_oFFs_SUPPORTED
  159996. # define PNG_oFFs_SUPPORTED
  159997. #endif
  159998. #ifndef PNG_NO_READ_pCAL
  159999. # define PNG_READ_pCAL_SUPPORTED
  160000. # define PNG_pCAL_SUPPORTED
  160001. #endif
  160002. #ifndef PNG_NO_READ_sCAL
  160003. # define PNG_READ_sCAL_SUPPORTED
  160004. # define PNG_sCAL_SUPPORTED
  160005. #endif
  160006. #ifndef PNG_NO_READ_pHYs
  160007. # define PNG_READ_pHYs_SUPPORTED
  160008. # define PNG_pHYs_SUPPORTED
  160009. #endif
  160010. #ifndef PNG_NO_READ_sBIT
  160011. # define PNG_READ_sBIT_SUPPORTED
  160012. # define PNG_sBIT_SUPPORTED
  160013. #endif
  160014. #ifndef PNG_NO_READ_sPLT
  160015. # define PNG_READ_sPLT_SUPPORTED
  160016. # define PNG_sPLT_SUPPORTED
  160017. #endif
  160018. #ifndef PNG_NO_READ_sRGB
  160019. # define PNG_READ_sRGB_SUPPORTED
  160020. # define PNG_sRGB_SUPPORTED
  160021. #endif
  160022. #ifndef PNG_NO_READ_tEXt
  160023. # define PNG_READ_tEXt_SUPPORTED
  160024. # define PNG_tEXt_SUPPORTED
  160025. #endif
  160026. #ifndef PNG_NO_READ_tIME
  160027. # define PNG_READ_tIME_SUPPORTED
  160028. # define PNG_tIME_SUPPORTED
  160029. #endif
  160030. #ifndef PNG_NO_READ_tRNS
  160031. # define PNG_READ_tRNS_SUPPORTED
  160032. # define PNG_tRNS_SUPPORTED
  160033. #endif
  160034. #ifndef PNG_NO_READ_zTXt
  160035. # define PNG_READ_zTXt_SUPPORTED
  160036. # define PNG_zTXt_SUPPORTED
  160037. #endif
  160038. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  160039. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  160040. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160041. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160042. # endif
  160043. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160044. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160045. # endif
  160046. #endif
  160047. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  160048. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  160049. # define PNG_READ_USER_CHUNKS_SUPPORTED
  160050. # define PNG_USER_CHUNKS_SUPPORTED
  160051. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  160052. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  160053. # endif
  160054. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  160055. # undef PNG_NO_HANDLE_AS_UNKNOWN
  160056. # endif
  160057. #endif
  160058. #ifndef PNG_NO_READ_OPT_PLTE
  160059. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  160060. #endif /* optional PLTE chunk in RGB and RGBA images */
  160061. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  160062. defined(PNG_READ_zTXt_SUPPORTED)
  160063. # define PNG_READ_TEXT_SUPPORTED
  160064. # define PNG_TEXT_SUPPORTED
  160065. #endif
  160066. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  160067. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160068. #ifdef PNG_NO_WRITE_TEXT
  160069. # define PNG_NO_WRITE_iTXt
  160070. # define PNG_NO_WRITE_tEXt
  160071. # define PNG_NO_WRITE_zTXt
  160072. #endif
  160073. #ifndef PNG_NO_WRITE_bKGD
  160074. # define PNG_WRITE_bKGD_SUPPORTED
  160075. # ifndef PNG_bKGD_SUPPORTED
  160076. # define PNG_bKGD_SUPPORTED
  160077. # endif
  160078. #endif
  160079. #ifndef PNG_NO_WRITE_cHRM
  160080. # define PNG_WRITE_cHRM_SUPPORTED
  160081. # ifndef PNG_cHRM_SUPPORTED
  160082. # define PNG_cHRM_SUPPORTED
  160083. # endif
  160084. #endif
  160085. #ifndef PNG_NO_WRITE_gAMA
  160086. # define PNG_WRITE_gAMA_SUPPORTED
  160087. # ifndef PNG_gAMA_SUPPORTED
  160088. # define PNG_gAMA_SUPPORTED
  160089. # endif
  160090. #endif
  160091. #ifndef PNG_NO_WRITE_hIST
  160092. # define PNG_WRITE_hIST_SUPPORTED
  160093. # ifndef PNG_hIST_SUPPORTED
  160094. # define PNG_hIST_SUPPORTED
  160095. # endif
  160096. #endif
  160097. #ifndef PNG_NO_WRITE_iCCP
  160098. # define PNG_WRITE_iCCP_SUPPORTED
  160099. # ifndef PNG_iCCP_SUPPORTED
  160100. # define PNG_iCCP_SUPPORTED
  160101. # endif
  160102. #endif
  160103. #ifndef PNG_NO_WRITE_iTXt
  160104. # ifndef PNG_WRITE_iTXt_SUPPORTED
  160105. # define PNG_WRITE_iTXt_SUPPORTED
  160106. # endif
  160107. # ifndef PNG_iTXt_SUPPORTED
  160108. # define PNG_iTXt_SUPPORTED
  160109. # endif
  160110. #endif
  160111. #ifndef PNG_NO_WRITE_oFFs
  160112. # define PNG_WRITE_oFFs_SUPPORTED
  160113. # ifndef PNG_oFFs_SUPPORTED
  160114. # define PNG_oFFs_SUPPORTED
  160115. # endif
  160116. #endif
  160117. #ifndef PNG_NO_WRITE_pCAL
  160118. # define PNG_WRITE_pCAL_SUPPORTED
  160119. # ifndef PNG_pCAL_SUPPORTED
  160120. # define PNG_pCAL_SUPPORTED
  160121. # endif
  160122. #endif
  160123. #ifndef PNG_NO_WRITE_sCAL
  160124. # define PNG_WRITE_sCAL_SUPPORTED
  160125. # ifndef PNG_sCAL_SUPPORTED
  160126. # define PNG_sCAL_SUPPORTED
  160127. # endif
  160128. #endif
  160129. #ifndef PNG_NO_WRITE_pHYs
  160130. # define PNG_WRITE_pHYs_SUPPORTED
  160131. # ifndef PNG_pHYs_SUPPORTED
  160132. # define PNG_pHYs_SUPPORTED
  160133. # endif
  160134. #endif
  160135. #ifndef PNG_NO_WRITE_sBIT
  160136. # define PNG_WRITE_sBIT_SUPPORTED
  160137. # ifndef PNG_sBIT_SUPPORTED
  160138. # define PNG_sBIT_SUPPORTED
  160139. # endif
  160140. #endif
  160141. #ifndef PNG_NO_WRITE_sPLT
  160142. # define PNG_WRITE_sPLT_SUPPORTED
  160143. # ifndef PNG_sPLT_SUPPORTED
  160144. # define PNG_sPLT_SUPPORTED
  160145. # endif
  160146. #endif
  160147. #ifndef PNG_NO_WRITE_sRGB
  160148. # define PNG_WRITE_sRGB_SUPPORTED
  160149. # ifndef PNG_sRGB_SUPPORTED
  160150. # define PNG_sRGB_SUPPORTED
  160151. # endif
  160152. #endif
  160153. #ifndef PNG_NO_WRITE_tEXt
  160154. # define PNG_WRITE_tEXt_SUPPORTED
  160155. # ifndef PNG_tEXt_SUPPORTED
  160156. # define PNG_tEXt_SUPPORTED
  160157. # endif
  160158. #endif
  160159. #ifndef PNG_NO_WRITE_tIME
  160160. # define PNG_WRITE_tIME_SUPPORTED
  160161. # ifndef PNG_tIME_SUPPORTED
  160162. # define PNG_tIME_SUPPORTED
  160163. # endif
  160164. #endif
  160165. #ifndef PNG_NO_WRITE_tRNS
  160166. # define PNG_WRITE_tRNS_SUPPORTED
  160167. # ifndef PNG_tRNS_SUPPORTED
  160168. # define PNG_tRNS_SUPPORTED
  160169. # endif
  160170. #endif
  160171. #ifndef PNG_NO_WRITE_zTXt
  160172. # define PNG_WRITE_zTXt_SUPPORTED
  160173. # ifndef PNG_zTXt_SUPPORTED
  160174. # define PNG_zTXt_SUPPORTED
  160175. # endif
  160176. #endif
  160177. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  160178. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  160179. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160180. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160181. # endif
  160182. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160183. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160184. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160185. # endif
  160186. # endif
  160187. #endif
  160188. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  160189. defined(PNG_WRITE_zTXt_SUPPORTED)
  160190. # define PNG_WRITE_TEXT_SUPPORTED
  160191. # ifndef PNG_TEXT_SUPPORTED
  160192. # define PNG_TEXT_SUPPORTED
  160193. # endif
  160194. #endif
  160195. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  160196. #ifndef PNG_NO_INFO_IMAGE
  160197. # define PNG_INFO_IMAGE_SUPPORTED
  160198. #endif
  160199. #if defined(PNG_tIME_SUPPORTED)
  160200. # if !defined(_WIN32_WCE)
  160201. # include <time.h>
  160202. # endif
  160203. #endif
  160204. typedef unsigned long png_uint_32;
  160205. typedef long png_int_32;
  160206. typedef unsigned short png_uint_16;
  160207. typedef short png_int_16;
  160208. typedef unsigned char png_byte;
  160209. #ifdef PNG_SIZE_T
  160210. typedef PNG_SIZE_T png_size_t;
  160211. # define png_sizeof(x) png_convert_size(sizeof (x))
  160212. #else
  160213. typedef size_t png_size_t;
  160214. # define png_sizeof(x) sizeof (x)
  160215. #endif
  160216. #ifdef __BORLANDC__
  160217. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  160218. # define LDATA 1
  160219. # else
  160220. # define LDATA 0
  160221. # endif
  160222. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  160223. # define PNG_MAX_MALLOC_64K
  160224. # if (LDATA != 1)
  160225. # ifndef FAR
  160226. # define FAR __far
  160227. # endif
  160228. # define USE_FAR_KEYWORD
  160229. # endif /* LDATA != 1 */
  160230. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  160231. #endif /* __BORLANDC__ */
  160232. #if defined(FAR)
  160233. # if defined(M_I86MM)
  160234. # define USE_FAR_KEYWORD
  160235. # define FARDATA FAR
  160236. # include <dos.h>
  160237. # endif
  160238. #endif
  160239. #ifndef FAR
  160240. # define FAR
  160241. #endif
  160242. #ifndef FARDATA
  160243. # define FARDATA
  160244. #endif
  160245. typedef png_int_32 png_fixed_point;
  160246. typedef void FAR * png_voidp;
  160247. typedef png_byte FAR * png_bytep;
  160248. typedef png_uint_32 FAR * png_uint_32p;
  160249. typedef png_int_32 FAR * png_int_32p;
  160250. typedef png_uint_16 FAR * png_uint_16p;
  160251. typedef png_int_16 FAR * png_int_16p;
  160252. typedef PNG_CONST char FAR * png_const_charp;
  160253. typedef char FAR * png_charp;
  160254. typedef png_fixed_point FAR * png_fixed_point_p;
  160255. #ifndef PNG_NO_STDIO
  160256. #if defined(_WIN32_WCE)
  160257. typedef HANDLE png_FILE_p;
  160258. #else
  160259. typedef FILE * png_FILE_p;
  160260. #endif
  160261. #endif
  160262. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160263. typedef double FAR * png_doublep;
  160264. #endif
  160265. typedef png_byte FAR * FAR * png_bytepp;
  160266. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  160267. typedef png_int_32 FAR * FAR * png_int_32pp;
  160268. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  160269. typedef png_int_16 FAR * FAR * png_int_16pp;
  160270. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  160271. typedef char FAR * FAR * png_charpp;
  160272. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  160273. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160274. typedef double FAR * FAR * png_doublepp;
  160275. #endif
  160276. typedef char FAR * FAR * FAR * png_charppp;
  160277. #if 0
  160278. typedef charf * png_zcharp;
  160279. typedef charf * FAR * png_zcharpp;
  160280. typedef z_stream FAR * png_zstreamp;
  160281. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  160282. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  160283. # define PNG_DLL
  160284. #endif
  160285. #if defined(__CYGWIN__)
  160286. # if !defined(PNG_STATIC)
  160287. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160288. # undef PNG_USE_GLOBAL_ARRAYS
  160289. # endif
  160290. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160291. # define PNG_USE_LOCAL_ARRAYS
  160292. # endif
  160293. # else
  160294. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160295. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160296. # undef PNG_USE_GLOBAL_ARRAYS
  160297. # endif
  160298. # endif
  160299. # endif
  160300. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160301. # define PNG_USE_LOCAL_ARRAYS
  160302. # endif
  160303. #endif
  160304. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160305. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160306. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160307. # define PNG_USE_LOCAL_ARRAYS
  160308. # else
  160309. # define PNG_USE_GLOBAL_ARRAYS
  160310. # endif
  160311. #endif
  160312. #if defined(__CYGWIN__)
  160313. # undef PNGAPI
  160314. # define PNGAPI __cdecl
  160315. # undef PNG_IMPEXP
  160316. # define PNG_IMPEXP
  160317. #endif
  160318. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160319. # ifndef PNG_NO_MODULEDEF
  160320. # define PNG_NO_MODULEDEF
  160321. # endif
  160322. #endif
  160323. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160324. # define PNG_IMPEXP
  160325. #endif
  160326. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160327. (( defined(_Windows) || defined(_WINDOWS) || \
  160328. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160329. # ifndef PNGAPI
  160330. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160331. # define PNGAPI __cdecl
  160332. # else
  160333. # define PNGAPI _cdecl
  160334. # endif
  160335. # endif
  160336. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160337. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160338. # define PNG_IMPEXP
  160339. # endif
  160340. # if !defined(PNG_IMPEXP)
  160341. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160342. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160343. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160344. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160345. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160346. # else
  160347. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160348. # if defined(PNG_BUILD_DLL)
  160349. # define PNG_IMPEXP __export
  160350. # else
  160351. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160352. VC++ */
  160353. # endif /* Exists in Borland C++ for
  160354. C++ classes (== huge) */
  160355. # endif
  160356. # endif
  160357. # if !defined(PNG_IMPEXP)
  160358. # if defined(PNG_BUILD_DLL)
  160359. # define PNG_IMPEXP __declspec(dllexport)
  160360. # else
  160361. # define PNG_IMPEXP __declspec(dllimport)
  160362. # endif
  160363. # endif
  160364. # endif /* PNG_IMPEXP */
  160365. #else /* !(DLL || non-cygwin WINDOWS) */
  160366. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160367. # ifndef PNGAPI
  160368. # define PNGAPI _System
  160369. # endif
  160370. # else
  160371. # if 0 /* ... other platforms, with other meanings */
  160372. # endif
  160373. # endif
  160374. #endif
  160375. #ifndef PNGAPI
  160376. # define PNGAPI
  160377. #endif
  160378. #ifndef PNG_IMPEXP
  160379. # define PNG_IMPEXP
  160380. #endif
  160381. #ifdef PNG_BUILDSYMS
  160382. # ifndef PNG_EXPORT
  160383. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160384. # endif
  160385. # ifdef PNG_USE_GLOBAL_ARRAYS
  160386. # ifndef PNG_EXPORT_VAR
  160387. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160388. # endif
  160389. # endif
  160390. #endif
  160391. #ifndef PNG_EXPORT
  160392. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160393. #endif
  160394. #ifdef PNG_USE_GLOBAL_ARRAYS
  160395. # ifndef PNG_EXPORT_VAR
  160396. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160397. # endif
  160398. #endif
  160399. #ifndef PNG_ABORT
  160400. # define PNG_ABORT() abort()
  160401. #endif
  160402. #ifdef PNG_SETJMP_SUPPORTED
  160403. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160404. #else
  160405. # define png_jmpbuf(png_ptr) \
  160406. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160407. #endif
  160408. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160409. # define CHECK 1
  160410. # define NOCHECK 0
  160411. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160412. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160413. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160414. # define png_strcpy _fstrcpy
  160415. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160416. # define png_strlen _fstrlen
  160417. # define png_memcmp _fmemcmp /* SJT: added */
  160418. # define png_memcpy _fmemcpy
  160419. # define png_memset _fmemset
  160420. #else /* use the usual functions */
  160421. # define CVT_PTR(ptr) (ptr)
  160422. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160423. # ifndef PNG_NO_SNPRINTF
  160424. # ifdef _MSC_VER
  160425. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160426. # define png_snprintf2 _snprintf
  160427. # define png_snprintf6 _snprintf
  160428. # else
  160429. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160430. # define png_snprintf2 snprintf
  160431. # define png_snprintf6 snprintf
  160432. # endif
  160433. # else
  160434. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160435. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160436. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160437. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160438. # endif
  160439. # define png_strcpy strcpy
  160440. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160441. # define png_strlen strlen
  160442. # define png_memcmp memcmp /* SJT: added */
  160443. # define png_memcpy memcpy
  160444. # define png_memset memset
  160445. #endif
  160446. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160447. # undef PNG_ZBUF_SIZE
  160448. # define PNG_ZBUF_SIZE 65536L
  160449. #endif
  160450. #endif /* PNG_VERSION_INFO_ONLY */
  160451. #endif /* PNGCONF_H */
  160452. /*** End of inlined file: pngconf.h ***/
  160453. #ifdef _MSC_VER
  160454. #pragma warning (disable: 4996 4100)
  160455. #endif
  160456. #if defined(PNG_USER_PRIVATEBUILD)
  160457. # define PNG_LIBPNG_BUILD_TYPE \
  160458. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160459. #else
  160460. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160461. # define PNG_LIBPNG_BUILD_TYPE \
  160462. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160463. # else
  160464. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160465. # endif
  160466. #endif
  160467. #ifndef PNG_VERSION_INFO_ONLY
  160468. #ifdef __cplusplus
  160469. extern "C" {
  160470. #endif /* __cplusplus */
  160471. #ifndef PNG_NO_TYPECAST_NULL
  160472. #define int_p_NULL (int *)NULL
  160473. #define png_bytep_NULL (png_bytep)NULL
  160474. #define png_bytepp_NULL (png_bytepp)NULL
  160475. #define png_doublep_NULL (png_doublep)NULL
  160476. #define png_error_ptr_NULL (png_error_ptr)NULL
  160477. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160478. #define png_free_ptr_NULL (png_free_ptr)NULL
  160479. #define png_infopp_NULL (png_infopp)NULL
  160480. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160481. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160482. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160483. #define png_structp_NULL (png_structp)NULL
  160484. #define png_uint_16p_NULL (png_uint_16p)NULL
  160485. #define png_voidp_NULL (png_voidp)NULL
  160486. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160487. #else
  160488. #define int_p_NULL NULL
  160489. #define png_bytep_NULL NULL
  160490. #define png_bytepp_NULL NULL
  160491. #define png_doublep_NULL NULL
  160492. #define png_error_ptr_NULL NULL
  160493. #define png_flush_ptr_NULL NULL
  160494. #define png_free_ptr_NULL NULL
  160495. #define png_infopp_NULL NULL
  160496. #define png_malloc_ptr_NULL NULL
  160497. #define png_read_status_ptr_NULL NULL
  160498. #define png_rw_ptr_NULL NULL
  160499. #define png_structp_NULL NULL
  160500. #define png_uint_16p_NULL NULL
  160501. #define png_voidp_NULL NULL
  160502. #define png_write_status_ptr_NULL NULL
  160503. #endif
  160504. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160505. #ifdef PNG_USE_GLOBAL_ARRAYS
  160506. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160507. #else
  160508. #define png_libpng_ver png_get_header_ver(NULL)
  160509. #endif
  160510. #ifdef PNG_USE_GLOBAL_ARRAYS
  160511. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160512. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160513. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160514. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160515. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160516. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160517. #endif
  160518. #endif /* PNG_NO_EXTERN */
  160519. typedef struct png_color_struct
  160520. {
  160521. png_byte red;
  160522. png_byte green;
  160523. png_byte blue;
  160524. } png_color;
  160525. typedef png_color FAR * png_colorp;
  160526. typedef png_color FAR * FAR * png_colorpp;
  160527. typedef struct png_color_16_struct
  160528. {
  160529. png_byte index; /* used for palette files */
  160530. png_uint_16 red; /* for use in red green blue files */
  160531. png_uint_16 green;
  160532. png_uint_16 blue;
  160533. png_uint_16 gray; /* for use in grayscale files */
  160534. } png_color_16;
  160535. typedef png_color_16 FAR * png_color_16p;
  160536. typedef png_color_16 FAR * FAR * png_color_16pp;
  160537. typedef struct png_color_8_struct
  160538. {
  160539. png_byte red; /* for use in red green blue files */
  160540. png_byte green;
  160541. png_byte blue;
  160542. png_byte gray; /* for use in grayscale files */
  160543. png_byte alpha; /* for alpha channel files */
  160544. } png_color_8;
  160545. typedef png_color_8 FAR * png_color_8p;
  160546. typedef png_color_8 FAR * FAR * png_color_8pp;
  160547. typedef struct png_sPLT_entry_struct
  160548. {
  160549. png_uint_16 red;
  160550. png_uint_16 green;
  160551. png_uint_16 blue;
  160552. png_uint_16 alpha;
  160553. png_uint_16 frequency;
  160554. } png_sPLT_entry;
  160555. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160556. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160557. typedef struct png_sPLT_struct
  160558. {
  160559. png_charp name; /* palette name */
  160560. png_byte depth; /* depth of palette samples */
  160561. png_sPLT_entryp entries; /* palette entries */
  160562. png_int_32 nentries; /* number of palette entries */
  160563. } png_sPLT_t;
  160564. typedef png_sPLT_t FAR * png_sPLT_tp;
  160565. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160566. #ifdef PNG_TEXT_SUPPORTED
  160567. typedef struct png_text_struct
  160568. {
  160569. int compression; /* compression value:
  160570. -1: tEXt, none
  160571. 0: zTXt, deflate
  160572. 1: iTXt, none
  160573. 2: iTXt, deflate */
  160574. png_charp key; /* keyword, 1-79 character description of "text" */
  160575. png_charp text; /* comment, may be an empty string (ie "")
  160576. or a NULL pointer */
  160577. png_size_t text_length; /* length of the text string */
  160578. #ifdef PNG_iTXt_SUPPORTED
  160579. png_size_t itxt_length; /* length of the itxt string */
  160580. png_charp lang; /* language code, 0-79 characters
  160581. or a NULL pointer */
  160582. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160583. chars or a NULL pointer */
  160584. #endif
  160585. } png_text;
  160586. typedef png_text FAR * png_textp;
  160587. typedef png_text FAR * FAR * png_textpp;
  160588. #endif
  160589. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160590. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160591. #define PNG_TEXT_COMPRESSION_NONE -1
  160592. #define PNG_TEXT_COMPRESSION_zTXt 0
  160593. #define PNG_ITXT_COMPRESSION_NONE 1
  160594. #define PNG_ITXT_COMPRESSION_zTXt 2
  160595. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160596. typedef struct png_time_struct
  160597. {
  160598. png_uint_16 year; /* full year, as in, 1995 */
  160599. png_byte month; /* month of year, 1 - 12 */
  160600. png_byte day; /* day of month, 1 - 31 */
  160601. png_byte hour; /* hour of day, 0 - 23 */
  160602. png_byte minute; /* minute of hour, 0 - 59 */
  160603. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160604. } png_time;
  160605. typedef png_time FAR * png_timep;
  160606. typedef png_time FAR * FAR * png_timepp;
  160607. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160608. typedef struct png_unknown_chunk_t
  160609. {
  160610. png_byte name[5];
  160611. png_byte *data;
  160612. png_size_t size;
  160613. png_byte location; /* mode of operation at read time */
  160614. }
  160615. png_unknown_chunk;
  160616. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160617. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160618. #endif
  160619. typedef struct png_info_struct
  160620. {
  160621. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160622. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160623. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160624. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160625. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160626. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160627. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160628. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160629. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160630. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160631. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160632. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160633. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160634. png_byte pixel_depth; /* number of bits per pixel */
  160635. png_byte spare_byte; /* to align the data, and for future use */
  160636. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160637. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160638. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160639. #endif
  160640. #if defined(PNG_sRGB_SUPPORTED)
  160641. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160642. #endif
  160643. #if defined(PNG_TEXT_SUPPORTED)
  160644. int num_text; /* number of comments read/to write */
  160645. int max_text; /* current size of text array */
  160646. png_textp text; /* array of comments read/to write */
  160647. #endif /* PNG_TEXT_SUPPORTED */
  160648. #if defined(PNG_tIME_SUPPORTED)
  160649. png_time mod_time;
  160650. #endif
  160651. #if defined(PNG_sBIT_SUPPORTED)
  160652. png_color_8 sig_bit; /* significant bits in color channels */
  160653. #endif
  160654. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160655. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160656. png_bytep trans; /* transparent values for paletted image */
  160657. png_color_16 trans_values; /* transparent color for non-palette image */
  160658. #endif
  160659. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160660. png_color_16 background;
  160661. #endif
  160662. #if defined(PNG_oFFs_SUPPORTED)
  160663. png_int_32 x_offset; /* x offset on page */
  160664. png_int_32 y_offset; /* y offset on page */
  160665. png_byte offset_unit_type; /* offset units type */
  160666. #endif
  160667. #if defined(PNG_pHYs_SUPPORTED)
  160668. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160669. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160670. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160671. #endif
  160672. #if defined(PNG_hIST_SUPPORTED)
  160673. png_uint_16p hist;
  160674. #endif
  160675. #ifdef PNG_cHRM_SUPPORTED
  160676. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160677. float x_white;
  160678. float y_white;
  160679. float x_red;
  160680. float y_red;
  160681. float x_green;
  160682. float y_green;
  160683. float x_blue;
  160684. float y_blue;
  160685. #endif
  160686. #endif
  160687. #if defined(PNG_pCAL_SUPPORTED)
  160688. png_charp pcal_purpose; /* pCAL chunk description string */
  160689. png_int_32 pcal_X0; /* minimum value */
  160690. png_int_32 pcal_X1; /* maximum value */
  160691. png_charp pcal_units; /* Latin-1 string giving physical units */
  160692. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160693. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160694. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160695. #endif
  160696. #ifdef PNG_FREE_ME_SUPPORTED
  160697. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160698. #endif
  160699. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160700. png_unknown_chunkp unknown_chunks;
  160701. png_size_t unknown_chunks_num;
  160702. #endif
  160703. #if defined(PNG_iCCP_SUPPORTED)
  160704. png_charp iccp_name; /* profile name */
  160705. png_charp iccp_profile; /* International Color Consortium profile data */
  160706. png_uint_32 iccp_proflen; /* ICC profile data length */
  160707. png_byte iccp_compression; /* Always zero */
  160708. #endif
  160709. #if defined(PNG_sPLT_SUPPORTED)
  160710. png_sPLT_tp splt_palettes;
  160711. png_uint_32 splt_palettes_num;
  160712. #endif
  160713. #if defined(PNG_sCAL_SUPPORTED)
  160714. png_byte scal_unit; /* unit of physical scale */
  160715. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160716. double scal_pixel_width; /* width of one pixel */
  160717. double scal_pixel_height; /* height of one pixel */
  160718. #endif
  160719. #ifdef PNG_FIXED_POINT_SUPPORTED
  160720. png_charp scal_s_width; /* string containing height */
  160721. png_charp scal_s_height; /* string containing width */
  160722. #endif
  160723. #endif
  160724. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160725. png_bytepp row_pointers; /* the image bits */
  160726. #endif
  160727. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160728. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160729. #endif
  160730. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160731. png_fixed_point int_x_white;
  160732. png_fixed_point int_y_white;
  160733. png_fixed_point int_x_red;
  160734. png_fixed_point int_y_red;
  160735. png_fixed_point int_x_green;
  160736. png_fixed_point int_y_green;
  160737. png_fixed_point int_x_blue;
  160738. png_fixed_point int_y_blue;
  160739. #endif
  160740. } png_info;
  160741. typedef png_info FAR * png_infop;
  160742. typedef png_info FAR * FAR * png_infopp;
  160743. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160744. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160745. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160746. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160747. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160748. #endif
  160749. #define PNG_COLOR_MASK_PALETTE 1
  160750. #define PNG_COLOR_MASK_COLOR 2
  160751. #define PNG_COLOR_MASK_ALPHA 4
  160752. #define PNG_COLOR_TYPE_GRAY 0
  160753. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160754. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160755. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160756. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160757. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160758. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160759. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160760. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160761. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160762. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160763. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160764. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160765. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160766. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160767. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160768. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160769. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160770. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160771. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160772. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160773. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160774. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160775. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160776. #define PNG_SCALE_METER 1 /* meters per pixel */
  160777. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160778. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160779. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160780. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160781. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160782. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160783. #define PNG_sRGB_INTENT_RELATIVE 1
  160784. #define PNG_sRGB_INTENT_SATURATION 2
  160785. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160786. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160787. #define PNG_KEYWORD_MAX_LENGTH 79
  160788. #define PNG_MAX_PALETTE_LENGTH 256
  160789. #define PNG_INFO_gAMA 0x0001
  160790. #define PNG_INFO_sBIT 0x0002
  160791. #define PNG_INFO_cHRM 0x0004
  160792. #define PNG_INFO_PLTE 0x0008
  160793. #define PNG_INFO_tRNS 0x0010
  160794. #define PNG_INFO_bKGD 0x0020
  160795. #define PNG_INFO_hIST 0x0040
  160796. #define PNG_INFO_pHYs 0x0080
  160797. #define PNG_INFO_oFFs 0x0100
  160798. #define PNG_INFO_tIME 0x0200
  160799. #define PNG_INFO_pCAL 0x0400
  160800. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160801. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160802. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160803. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160804. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160805. typedef struct png_row_info_struct
  160806. {
  160807. png_uint_32 width; /* width of row */
  160808. png_uint_32 rowbytes; /* number of bytes in row */
  160809. png_byte color_type; /* color type of row */
  160810. png_byte bit_depth; /* bit depth of row */
  160811. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160812. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160813. } png_row_info;
  160814. typedef png_row_info FAR * png_row_infop;
  160815. typedef png_row_info FAR * FAR * png_row_infopp;
  160816. typedef struct png_struct_def png_struct;
  160817. typedef png_struct FAR * png_structp;
  160818. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160819. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160820. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160821. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160822. int));
  160823. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160824. int));
  160825. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160826. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160827. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160828. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160829. png_uint_32, int));
  160830. #endif
  160831. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160832. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160833. defined(PNG_LEGACY_SUPPORTED)
  160834. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160835. png_row_infop, png_bytep));
  160836. #endif
  160837. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160838. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160839. #endif
  160840. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160841. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160842. #endif
  160843. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160844. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160845. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160846. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160847. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160848. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160849. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160850. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160851. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160852. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160853. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160854. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160855. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160856. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160857. #define PNG_FLAG_MNG_FILTER_64 0x04
  160858. #define PNG_ALL_MNG_FEATURES 0x05
  160859. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160860. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160861. struct png_struct_def
  160862. {
  160863. #ifdef PNG_SETJMP_SUPPORTED
  160864. jmp_buf jmpbuf; /* used in png_error */
  160865. #endif
  160866. png_error_ptr error_fn; /* function for printing errors and aborting */
  160867. png_error_ptr warning_fn; /* function for printing warnings */
  160868. png_voidp error_ptr; /* user supplied struct for error functions */
  160869. png_rw_ptr write_data_fn; /* function for writing output data */
  160870. png_rw_ptr read_data_fn; /* function for reading input data */
  160871. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160872. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160873. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160874. #endif
  160875. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160876. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160877. #endif
  160878. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160879. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160880. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160881. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160882. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160883. png_byte user_transform_channels; /* channels in user transformed pixels */
  160884. #endif
  160885. #endif
  160886. png_uint_32 mode; /* tells us where we are in the PNG file */
  160887. png_uint_32 flags; /* flags indicating various things to libpng */
  160888. png_uint_32 transformations; /* which transformations to perform */
  160889. z_stream zstream; /* pointer to decompression structure (below) */
  160890. png_bytep zbuf; /* buffer for zlib */
  160891. png_size_t zbuf_size; /* size of zbuf */
  160892. int zlib_level; /* holds zlib compression level */
  160893. int zlib_method; /* holds zlib compression method */
  160894. int zlib_window_bits; /* holds zlib compression window bits */
  160895. int zlib_mem_level; /* holds zlib compression memory level */
  160896. int zlib_strategy; /* holds zlib compression strategy */
  160897. png_uint_32 width; /* width of image in pixels */
  160898. png_uint_32 height; /* height of image in pixels */
  160899. png_uint_32 num_rows; /* number of rows in current pass */
  160900. png_uint_32 usr_width; /* width of row at start of write */
  160901. png_uint_32 rowbytes; /* size of row in bytes */
  160902. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160903. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160904. png_uint_32 row_number; /* current row in interlace pass */
  160905. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160906. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160907. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160908. png_bytep up_row; /* buffer to save "up" row when filtering */
  160909. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160910. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160911. png_row_info row_info; /* used for transformation routines */
  160912. png_uint_32 idat_size; /* current IDAT size for read */
  160913. png_uint_32 crc; /* current chunk CRC value */
  160914. png_colorp palette; /* palette from the input file */
  160915. png_uint_16 num_palette; /* number of color entries in palette */
  160916. png_uint_16 num_trans; /* number of transparency values */
  160917. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160918. png_byte compression; /* file compression type (always 0) */
  160919. png_byte filter; /* file filter type (always 0) */
  160920. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160921. png_byte pass; /* current interlace pass (0 - 6) */
  160922. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160923. png_byte color_type; /* color type of file */
  160924. png_byte bit_depth; /* bit depth of file */
  160925. png_byte usr_bit_depth; /* bit depth of users row */
  160926. png_byte pixel_depth; /* number of bits per pixel */
  160927. png_byte channels; /* number of channels in file */
  160928. png_byte usr_channels; /* channels at start of write */
  160929. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160930. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160931. #ifdef PNG_LEGACY_SUPPORTED
  160932. png_byte filler; /* filler byte for pixel expansion */
  160933. #else
  160934. png_uint_16 filler; /* filler bytes for pixel expansion */
  160935. #endif
  160936. #endif
  160937. #if defined(PNG_bKGD_SUPPORTED)
  160938. png_byte background_gamma_type;
  160939. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160940. float background_gamma;
  160941. # endif
  160942. png_color_16 background; /* background color in screen gamma space */
  160943. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160944. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160945. #endif
  160946. #endif /* PNG_bKGD_SUPPORTED */
  160947. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160948. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160949. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160950. png_uint_32 flush_rows; /* number of rows written since last flush */
  160951. #endif
  160952. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160953. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160954. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160955. float gamma; /* file gamma value */
  160956. float screen_gamma; /* screen gamma value (display_exponent) */
  160957. #endif
  160958. #endif
  160959. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160960. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160961. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160962. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160963. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160964. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160965. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160966. #endif
  160967. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160968. png_color_8 sig_bit; /* significant bits in each available channel */
  160969. #endif
  160970. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160971. png_color_8 shift; /* shift for significant bit tranformation */
  160972. #endif
  160973. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160974. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160975. png_bytep trans; /* transparency values for paletted files */
  160976. png_color_16 trans_values; /* transparency values for non-paletted files */
  160977. #endif
  160978. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160979. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160980. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160981. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160982. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160983. png_progressive_end_ptr end_fn; /* called after image is complete */
  160984. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160985. png_bytep save_buffer; /* buffer for previously read data */
  160986. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160987. png_bytep current_buffer; /* buffer for recently used data */
  160988. png_uint_32 push_length; /* size of current input chunk */
  160989. png_uint_32 skip_length; /* bytes to skip in input data */
  160990. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160991. png_size_t save_buffer_max; /* total size of save_buffer */
  160992. png_size_t buffer_size; /* total amount of available input data */
  160993. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160994. int process_mode; /* what push library is currently doing */
  160995. int cur_palette; /* current push library palette index */
  160996. # if defined(PNG_TEXT_SUPPORTED)
  160997. png_size_t current_text_size; /* current size of text input data */
  160998. png_size_t current_text_left; /* how much text left to read in input */
  160999. png_charp current_text; /* current text chunk buffer */
  161000. png_charp current_text_ptr; /* current location in current_text */
  161001. # endif /* PNG_TEXT_SUPPORTED */
  161002. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161003. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  161004. png_bytepp offset_table_ptr;
  161005. png_bytep offset_table;
  161006. png_uint_16 offset_table_number;
  161007. png_uint_16 offset_table_count;
  161008. png_uint_16 offset_table_count_free;
  161009. #endif
  161010. #if defined(PNG_READ_DITHER_SUPPORTED)
  161011. png_bytep palette_lookup; /* lookup table for dithering */
  161012. png_bytep dither_index; /* index translation for palette files */
  161013. #endif
  161014. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  161015. png_uint_16p hist; /* histogram */
  161016. #endif
  161017. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  161018. png_byte heuristic_method; /* heuristic for row filter selection */
  161019. png_byte num_prev_filters; /* number of weights for previous rows */
  161020. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  161021. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  161022. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  161023. png_uint_16p filter_costs; /* relative filter calculation cost */
  161024. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  161025. #endif
  161026. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161027. png_charp time_buffer; /* String to hold RFC 1123 time text */
  161028. #endif
  161029. #ifdef PNG_FREE_ME_SUPPORTED
  161030. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  161031. #endif
  161032. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  161033. png_voidp user_chunk_ptr;
  161034. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  161035. #endif
  161036. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161037. int num_chunk_list;
  161038. png_bytep chunk_list;
  161039. #endif
  161040. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161041. png_byte rgb_to_gray_status;
  161042. png_uint_16 rgb_to_gray_red_coeff;
  161043. png_uint_16 rgb_to_gray_green_coeff;
  161044. png_uint_16 rgb_to_gray_blue_coeff;
  161045. #endif
  161046. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  161047. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161048. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161049. #ifdef PNG_1_0_X
  161050. png_byte mng_features_permitted;
  161051. #else
  161052. png_uint_32 mng_features_permitted;
  161053. #endif /* PNG_1_0_X */
  161054. #endif
  161055. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161056. png_fixed_point int_gamma;
  161057. #endif
  161058. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  161059. png_byte filter_type;
  161060. #endif
  161061. #if defined(PNG_1_0_X)
  161062. png_uint_32 row_buf_size;
  161063. #endif
  161064. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161065. # if !defined(PNG_1_0_X)
  161066. # if defined(PNG_MMX_CODE_SUPPORTED)
  161067. png_byte mmx_bitdepth_threshold;
  161068. png_uint_32 mmx_rowbytes_threshold;
  161069. # endif
  161070. png_uint_32 asm_flags;
  161071. # endif
  161072. #endif
  161073. #ifdef PNG_USER_MEM_SUPPORTED
  161074. png_voidp mem_ptr; /* user supplied struct for mem functions */
  161075. png_malloc_ptr malloc_fn; /* function for allocating memory */
  161076. png_free_ptr free_fn; /* function for freeing memory */
  161077. #endif
  161078. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  161079. #if defined(PNG_READ_DITHER_SUPPORTED)
  161080. png_bytep dither_sort; /* working sort array */
  161081. png_bytep index_to_palette; /* where the original index currently is */
  161082. png_bytep palette_to_index; /* which original index points to this */
  161083. #endif
  161084. png_byte compression_type;
  161085. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161086. png_uint_32 user_width_max;
  161087. png_uint_32 user_height_max;
  161088. #endif
  161089. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161090. png_unknown_chunk unknown_chunk;
  161091. #endif
  161092. };
  161093. typedef png_structp version_1_2_21;
  161094. typedef png_struct FAR * FAR * png_structpp;
  161095. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  161096. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  161097. int num_bytes));
  161098. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  161099. png_size_t num_to_check));
  161100. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  161101. extern PNG_EXPORT(png_structp,png_create_read_struct)
  161102. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161103. png_error_ptr error_fn, png_error_ptr warn_fn));
  161104. extern PNG_EXPORT(png_structp,png_create_write_struct)
  161105. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161106. png_error_ptr error_fn, png_error_ptr warn_fn));
  161107. #ifdef PNG_WRITE_SUPPORTED
  161108. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  161109. PNGARG((png_structp png_ptr));
  161110. #endif
  161111. #ifdef PNG_WRITE_SUPPORTED
  161112. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  161113. PNGARG((png_structp png_ptr, png_uint_32 size));
  161114. #endif
  161115. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  161116. #ifdef PNG_USER_MEM_SUPPORTED
  161117. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  161118. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161119. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161120. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161121. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  161122. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161123. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161124. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161125. #endif
  161126. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  161127. png_bytep chunk_name, png_bytep data, png_size_t length));
  161128. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  161129. png_bytep chunk_name, png_uint_32 length));
  161130. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  161131. png_bytep data, png_size_t length));
  161132. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  161133. extern PNG_EXPORT(png_infop,png_create_info_struct)
  161134. PNGARG((png_structp png_ptr));
  161135. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161136. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  161137. #undef png_info_init
  161138. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  161139. png_sizeof(png_info));
  161140. #endif
  161141. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  161142. png_size_t png_info_struct_size));
  161143. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  161144. png_infop info_ptr));
  161145. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  161146. png_infop info_ptr));
  161147. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161148. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  161149. png_infop info_ptr));
  161150. #endif
  161151. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161152. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  161153. PNGARG((png_structp png_ptr, png_timep ptime));
  161154. #endif
  161155. #if !defined(_WIN32_WCE)
  161156. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161157. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  161158. struct tm FAR * ttime));
  161159. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  161160. time_t ttime));
  161161. #endif /* PNG_WRITE_tIME_SUPPORTED */
  161162. #endif /* _WIN32_WCE */
  161163. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161164. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  161165. #if !defined(PNG_1_0_X)
  161166. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  161167. png_ptr));
  161168. #endif
  161169. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  161170. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  161171. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161172. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  161173. #endif
  161174. #endif
  161175. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161176. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  161177. #endif
  161178. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161179. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  161180. #endif
  161181. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161182. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161183. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  161184. int error_action, double red, double green ));
  161185. #endif
  161186. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  161187. int error_action, png_fixed_point red, png_fixed_point green ));
  161188. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  161189. png_ptr));
  161190. #endif
  161191. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  161192. png_colorp palette));
  161193. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161194. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  161195. #endif
  161196. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  161197. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161198. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  161199. #endif
  161200. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  161201. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161202. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  161203. #endif
  161204. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161205. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  161206. png_uint_32 filler, int flags));
  161207. #define PNG_FILLER_BEFORE 0
  161208. #define PNG_FILLER_AFTER 1
  161209. #if !defined(PNG_1_0_X)
  161210. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  161211. png_uint_32 filler, int flags));
  161212. #endif
  161213. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  161214. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161215. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  161216. #endif
  161217. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  161218. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  161219. #endif
  161220. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161221. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  161222. #endif
  161223. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161224. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  161225. png_color_8p true_bits));
  161226. #endif
  161227. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  161228. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161229. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  161230. #endif
  161231. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161232. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  161233. #endif
  161234. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161235. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161236. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  161237. png_color_16p background_color, int background_gamma_code,
  161238. int need_expand, double background_gamma));
  161239. #endif
  161240. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  161241. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  161242. #define PNG_BACKGROUND_GAMMA_FILE 2
  161243. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  161244. #endif
  161245. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161246. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  161247. #endif
  161248. #if defined(PNG_READ_DITHER_SUPPORTED)
  161249. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  161250. png_colorp palette, int num_palette, int maximum_colors,
  161251. png_uint_16p histogram, int full_dither));
  161252. #endif
  161253. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161254. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161255. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  161256. double screen_gamma, double default_file_gamma));
  161257. #endif
  161258. #endif
  161259. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161260. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161261. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161262. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  161263. int empty_plte_permitted));
  161264. #endif
  161265. #endif
  161266. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161267. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  161268. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  161269. #endif
  161270. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  161271. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  161272. png_infop info_ptr));
  161273. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161274. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  161275. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  161276. #endif
  161277. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161278. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  161279. png_bytep row,
  161280. png_bytep display_row));
  161281. #endif
  161282. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161283. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  161284. png_bytepp image));
  161285. #endif
  161286. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161287. png_bytep row));
  161288. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161289. png_bytepp row, png_uint_32 num_rows));
  161290. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161291. png_bytepp image));
  161292. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161293. png_infop info_ptr));
  161294. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161295. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161296. png_infop info_ptr));
  161297. #endif
  161298. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161299. png_infopp info_ptr_ptr));
  161300. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161301. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161302. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161303. png_infop end_info_ptr));
  161304. extern PNG_EXPORT(void,png_destroy_write_struct)
  161305. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161306. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161307. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161308. int crit_action, int ancil_action));
  161309. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161310. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161311. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161312. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161313. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161314. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161315. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161316. int filters));
  161317. #define PNG_NO_FILTERS 0x00
  161318. #define PNG_FILTER_NONE 0x08
  161319. #define PNG_FILTER_SUB 0x10
  161320. #define PNG_FILTER_UP 0x20
  161321. #define PNG_FILTER_AVG 0x40
  161322. #define PNG_FILTER_PAETH 0x80
  161323. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161324. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161325. #define PNG_FILTER_VALUE_NONE 0
  161326. #define PNG_FILTER_VALUE_SUB 1
  161327. #define PNG_FILTER_VALUE_UP 2
  161328. #define PNG_FILTER_VALUE_AVG 3
  161329. #define PNG_FILTER_VALUE_PAETH 4
  161330. #define PNG_FILTER_VALUE_LAST 5
  161331. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161332. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161333. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161334. int heuristic_method, int num_weights, png_doublep filter_weights,
  161335. png_doublep filter_costs));
  161336. #endif
  161337. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161338. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161339. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161340. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161341. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161342. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161343. int level));
  161344. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161345. PNGARG((png_structp png_ptr, int mem_level));
  161346. extern PNG_EXPORT(void,png_set_compression_strategy)
  161347. PNGARG((png_structp png_ptr, int strategy));
  161348. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161349. PNGARG((png_structp png_ptr, int window_bits));
  161350. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161351. int method));
  161352. #if !defined(PNG_NO_STDIO)
  161353. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161354. #endif
  161355. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161356. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161357. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161358. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161359. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161360. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161361. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161362. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161363. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161364. png_read_status_ptr read_row_fn));
  161365. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161366. png_write_status_ptr write_row_fn));
  161367. #ifdef PNG_USER_MEM_SUPPORTED
  161368. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161369. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161370. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161371. #endif
  161372. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161373. defined(PNG_LEGACY_SUPPORTED)
  161374. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161375. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161376. #endif
  161377. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161378. defined(PNG_LEGACY_SUPPORTED)
  161379. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161380. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161381. #endif
  161382. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161383. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161384. defined(PNG_LEGACY_SUPPORTED)
  161385. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161386. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161387. int user_transform_channels));
  161388. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161389. PNGARG((png_structp png_ptr));
  161390. #endif
  161391. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161392. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161393. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161394. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161395. png_ptr));
  161396. #endif
  161397. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161398. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161399. png_voidp progressive_ptr,
  161400. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161401. png_progressive_end_ptr end_fn));
  161402. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161403. PNGARG((png_structp png_ptr));
  161404. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161405. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161406. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161407. png_bytep old_row, png_bytep new_row));
  161408. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161409. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161410. png_uint_32 size));
  161411. #if defined(PNG_1_0_X)
  161412. # define png_malloc_warn png_malloc
  161413. #else
  161414. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161415. png_uint_32 size));
  161416. #endif
  161417. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161418. #if defined(PNG_1_0_X)
  161419. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161420. uInt size));
  161421. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161422. #endif
  161423. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161424. png_infop info_ptr, png_uint_32 free_me, int num));
  161425. #ifdef PNG_FREE_ME_SUPPORTED
  161426. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161427. png_infop info_ptr, int freer, png_uint_32 mask));
  161428. #endif
  161429. #define PNG_DESTROY_WILL_FREE_DATA 1
  161430. #define PNG_SET_WILL_FREE_DATA 1
  161431. #define PNG_USER_WILL_FREE_DATA 2
  161432. #define PNG_FREE_HIST 0x0008
  161433. #define PNG_FREE_ICCP 0x0010
  161434. #define PNG_FREE_SPLT 0x0020
  161435. #define PNG_FREE_ROWS 0x0040
  161436. #define PNG_FREE_PCAL 0x0080
  161437. #define PNG_FREE_SCAL 0x0100
  161438. #define PNG_FREE_UNKN 0x0200
  161439. #define PNG_FREE_LIST 0x0400
  161440. #define PNG_FREE_PLTE 0x1000
  161441. #define PNG_FREE_TRNS 0x2000
  161442. #define PNG_FREE_TEXT 0x4000
  161443. #define PNG_FREE_ALL 0x7fff
  161444. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161445. #ifdef PNG_USER_MEM_SUPPORTED
  161446. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161447. png_uint_32 size));
  161448. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161449. png_voidp ptr));
  161450. #endif
  161451. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161452. png_voidp s1, png_voidp s2, png_uint_32 size));
  161453. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161454. png_voidp s1, int value, png_uint_32 size));
  161455. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161456. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161457. int check));
  161458. #endif /* USE_FAR_KEYWORD */
  161459. #ifndef PNG_NO_ERROR_TEXT
  161460. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161461. png_const_charp error_message));
  161462. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161463. png_const_charp error_message));
  161464. #else
  161465. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161466. #endif
  161467. #ifndef PNG_NO_WARNINGS
  161468. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161469. png_const_charp warning_message));
  161470. #ifdef PNG_READ_SUPPORTED
  161471. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161472. png_const_charp warning_message));
  161473. #endif /* PNG_READ_SUPPORTED */
  161474. #endif /* PNG_NO_WARNINGS */
  161475. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161476. png_infop info_ptr, png_uint_32 flag));
  161477. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161478. png_infop info_ptr));
  161479. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161480. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161481. png_infop info_ptr));
  161482. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161483. png_infop info_ptr, png_bytepp row_pointers));
  161484. #endif
  161485. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161486. png_infop info_ptr));
  161487. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161488. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161489. png_ptr, png_infop info_ptr));
  161490. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161491. png_ptr, png_infop info_ptr));
  161492. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161493. png_ptr, png_infop info_ptr));
  161494. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161495. png_ptr, png_infop info_ptr));
  161496. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161497. png_ptr, png_infop info_ptr));
  161498. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161499. png_ptr, png_infop info_ptr));
  161500. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161501. png_ptr, png_infop info_ptr));
  161502. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161503. png_ptr, png_infop info_ptr));
  161504. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161505. png_ptr, png_infop info_ptr));
  161506. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161507. png_ptr, png_infop info_ptr));
  161508. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161509. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161510. png_ptr, png_infop info_ptr));
  161511. #endif
  161512. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161513. png_ptr, png_infop info_ptr));
  161514. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161515. png_ptr, png_infop info_ptr));
  161516. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161517. png_ptr, png_infop info_ptr));
  161518. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161519. png_ptr, png_infop info_ptr));
  161520. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161521. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161522. png_infop info_ptr));
  161523. #if defined(PNG_bKGD_SUPPORTED)
  161524. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161525. png_infop info_ptr, png_color_16p *background));
  161526. #endif
  161527. #if defined(PNG_bKGD_SUPPORTED)
  161528. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161529. png_infop info_ptr, png_color_16p background));
  161530. #endif
  161531. #if defined(PNG_cHRM_SUPPORTED)
  161532. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161533. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161534. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161535. double *red_y, double *green_x, double *green_y, double *blue_x,
  161536. double *blue_y));
  161537. #endif
  161538. #ifdef PNG_FIXED_POINT_SUPPORTED
  161539. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161540. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161541. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161542. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161543. *int_blue_x, png_fixed_point *int_blue_y));
  161544. #endif
  161545. #endif
  161546. #if defined(PNG_cHRM_SUPPORTED)
  161547. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161548. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161549. png_infop info_ptr, double white_x, double white_y, double red_x,
  161550. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161551. #endif
  161552. #ifdef PNG_FIXED_POINT_SUPPORTED
  161553. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161554. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161555. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161556. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161557. png_fixed_point int_blue_y));
  161558. #endif
  161559. #endif
  161560. #if defined(PNG_gAMA_SUPPORTED)
  161561. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161562. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161563. png_infop info_ptr, double *file_gamma));
  161564. #endif
  161565. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161566. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161567. #endif
  161568. #if defined(PNG_gAMA_SUPPORTED)
  161569. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161570. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161571. png_infop info_ptr, double file_gamma));
  161572. #endif
  161573. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161574. png_infop info_ptr, png_fixed_point int_file_gamma));
  161575. #endif
  161576. #if defined(PNG_hIST_SUPPORTED)
  161577. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161578. png_infop info_ptr, png_uint_16p *hist));
  161579. #endif
  161580. #if defined(PNG_hIST_SUPPORTED)
  161581. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161582. png_infop info_ptr, png_uint_16p hist));
  161583. #endif
  161584. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161585. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161586. int *bit_depth, int *color_type, int *interlace_method,
  161587. int *compression_method, int *filter_method));
  161588. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161589. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161590. int color_type, int interlace_method, int compression_method,
  161591. int filter_method));
  161592. #if defined(PNG_oFFs_SUPPORTED)
  161593. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161594. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161595. int *unit_type));
  161596. #endif
  161597. #if defined(PNG_oFFs_SUPPORTED)
  161598. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161599. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161600. int unit_type));
  161601. #endif
  161602. #if defined(PNG_pCAL_SUPPORTED)
  161603. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161604. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161605. int *type, int *nparams, png_charp *units, png_charpp *params));
  161606. #endif
  161607. #if defined(PNG_pCAL_SUPPORTED)
  161608. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161609. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161610. int type, int nparams, png_charp units, png_charpp params));
  161611. #endif
  161612. #if defined(PNG_pHYs_SUPPORTED)
  161613. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161614. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161615. #endif
  161616. #if defined(PNG_pHYs_SUPPORTED)
  161617. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161618. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161619. #endif
  161620. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161621. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161622. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161623. png_infop info_ptr, png_colorp palette, int num_palette));
  161624. #if defined(PNG_sBIT_SUPPORTED)
  161625. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161626. png_infop info_ptr, png_color_8p *sig_bit));
  161627. #endif
  161628. #if defined(PNG_sBIT_SUPPORTED)
  161629. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161630. png_infop info_ptr, png_color_8p sig_bit));
  161631. #endif
  161632. #if defined(PNG_sRGB_SUPPORTED)
  161633. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161634. png_infop info_ptr, int *intent));
  161635. #endif
  161636. #if defined(PNG_sRGB_SUPPORTED)
  161637. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161638. png_infop info_ptr, int intent));
  161639. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161640. png_infop info_ptr, int intent));
  161641. #endif
  161642. #if defined(PNG_iCCP_SUPPORTED)
  161643. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161644. png_infop info_ptr, png_charpp name, int *compression_type,
  161645. png_charpp profile, png_uint_32 *proflen));
  161646. #endif
  161647. #if defined(PNG_iCCP_SUPPORTED)
  161648. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161649. png_infop info_ptr, png_charp name, int compression_type,
  161650. png_charp profile, png_uint_32 proflen));
  161651. #endif
  161652. #if defined(PNG_sPLT_SUPPORTED)
  161653. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161654. png_infop info_ptr, png_sPLT_tpp entries));
  161655. #endif
  161656. #if defined(PNG_sPLT_SUPPORTED)
  161657. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161658. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161659. #endif
  161660. #if defined(PNG_TEXT_SUPPORTED)
  161661. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161662. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161663. #endif
  161664. #if defined(PNG_TEXT_SUPPORTED)
  161665. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161666. png_infop info_ptr, png_textp text_ptr, int num_text));
  161667. #endif
  161668. #if defined(PNG_tIME_SUPPORTED)
  161669. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161670. png_infop info_ptr, png_timep *mod_time));
  161671. #endif
  161672. #if defined(PNG_tIME_SUPPORTED)
  161673. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161674. png_infop info_ptr, png_timep mod_time));
  161675. #endif
  161676. #if defined(PNG_tRNS_SUPPORTED)
  161677. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161678. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161679. png_color_16p *trans_values));
  161680. #endif
  161681. #if defined(PNG_tRNS_SUPPORTED)
  161682. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161683. png_infop info_ptr, png_bytep trans, int num_trans,
  161684. png_color_16p trans_values));
  161685. #endif
  161686. #if defined(PNG_tRNS_SUPPORTED)
  161687. #endif
  161688. #if defined(PNG_sCAL_SUPPORTED)
  161689. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161690. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161691. png_infop info_ptr, int *unit, double *width, double *height));
  161692. #else
  161693. #ifdef PNG_FIXED_POINT_SUPPORTED
  161694. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161695. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161696. #endif
  161697. #endif
  161698. #endif /* PNG_sCAL_SUPPORTED */
  161699. #if defined(PNG_sCAL_SUPPORTED)
  161700. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161701. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161702. png_infop info_ptr, int unit, double width, double height));
  161703. #else
  161704. #ifdef PNG_FIXED_POINT_SUPPORTED
  161705. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161706. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161707. #endif
  161708. #endif
  161709. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161710. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161711. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161712. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161713. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161714. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161715. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161716. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161717. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161718. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161719. #endif
  161720. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161721. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161722. chunk_name));
  161723. #endif
  161724. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161725. png_infop info_ptr, int mask));
  161726. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161727. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161728. png_infop info_ptr,
  161729. int transforms,
  161730. png_voidp params));
  161731. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161732. png_infop info_ptr,
  161733. int transforms,
  161734. png_voidp params));
  161735. #endif
  161736. #ifdef PNG_DEBUG
  161737. #if (PNG_DEBUG > 0)
  161738. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161739. #include <crtdbg.h>
  161740. #if (PNG_DEBUG > 1)
  161741. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161742. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161743. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161744. #endif
  161745. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161746. #ifndef PNG_DEBUG_FILE
  161747. #define PNG_DEBUG_FILE stderr
  161748. #endif /* PNG_DEBUG_FILE */
  161749. #if (PNG_DEBUG > 1)
  161750. #define png_debug(l,m) \
  161751. { \
  161752. int num_tabs=l; \
  161753. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161754. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161755. }
  161756. #define png_debug1(l,m,p1) \
  161757. { \
  161758. int num_tabs=l; \
  161759. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161760. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161761. }
  161762. #define png_debug2(l,m,p1,p2) \
  161763. { \
  161764. int num_tabs=l; \
  161765. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161766. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161767. }
  161768. #endif /* (PNG_DEBUG > 1) */
  161769. #endif /* _MSC_VER */
  161770. #endif /* (PNG_DEBUG > 0) */
  161771. #endif /* PNG_DEBUG */
  161772. #ifndef png_debug
  161773. #define png_debug(l, m)
  161774. #endif
  161775. #ifndef png_debug1
  161776. #define png_debug1(l, m, p1)
  161777. #endif
  161778. #ifndef png_debug2
  161779. #define png_debug2(l, m, p1, p2)
  161780. #endif
  161781. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161782. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161783. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161784. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161785. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161786. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161787. png_ptr, png_uint_32 mng_features_permitted));
  161788. #endif
  161789. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161790. #define PNG_HANDLE_CHUNK_NEVER 1
  161791. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161792. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161793. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161794. #if defined(PNG_MMX_CODE_SUPPORTED)
  161795. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161796. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161797. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161798. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161799. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161800. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161801. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161802. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161803. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161804. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161805. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161806. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161807. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161808. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161809. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161810. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161811. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161812. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161813. | PNG_MMX_READ_FLAGS \
  161814. | PNG_MMX_WRITE_FLAGS )
  161815. #define PNG_SELECT_READ 1
  161816. #define PNG_SELECT_WRITE 2
  161817. #endif /* PNG_MMX_CODE_SUPPORTED */
  161818. #if !defined(PNG_1_0_X)
  161819. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161820. PNGARG((int flag_select, int *compilerID));
  161821. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161822. PNGARG((int flag_select));
  161823. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161824. PNGARG((png_structp png_ptr));
  161825. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161826. PNGARG((png_structp png_ptr));
  161827. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161828. PNGARG((png_structp png_ptr));
  161829. extern PNG_EXPORT(void,png_set_asm_flags)
  161830. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161831. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161832. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161833. png_uint_32 mmx_rowbytes_threshold));
  161834. #endif /* PNG_1_0_X */
  161835. #if !defined(PNG_1_0_X)
  161836. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161837. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161838. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161839. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161840. png_ptr, png_uint_32 strip_mode));
  161841. #endif
  161842. #endif /* PNG_1_0_X */
  161843. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161844. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161845. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161846. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161847. png_ptr));
  161848. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161849. png_ptr));
  161850. #endif
  161851. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161852. # define png_composite(composite, fg, alpha, bg) \
  161853. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161854. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161855. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161856. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161857. # define png_composite_16(composite, fg, alpha, bg) \
  161858. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161859. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161860. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161861. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161862. #else /* standard method using integer division */
  161863. # define png_composite(composite, fg, alpha, bg) \
  161864. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161865. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161866. (png_uint_16)127) / 255)
  161867. # define png_composite_16(composite, fg, alpha, bg) \
  161868. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161869. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161870. (png_uint_32)32767) / (png_uint_32)65535L)
  161871. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161872. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161873. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161874. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161875. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161876. #else
  161877. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161878. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161879. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161880. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161881. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161882. PNGARG((png_structp png_ptr, png_bytep buf));
  161883. extern PNG_EXPORT(void,png_save_uint_32)
  161884. PNGARG((png_bytep buf, png_uint_32 i));
  161885. extern PNG_EXPORT(void,png_save_int_32)
  161886. PNGARG((png_bytep buf, png_int_32 i));
  161887. extern PNG_EXPORT(void,png_save_uint_16)
  161888. PNGARG((png_bytep buf, unsigned int i));
  161889. #define PNG_HAVE_IHDR 0x01
  161890. #define PNG_HAVE_PLTE 0x02
  161891. #define PNG_HAVE_IDAT 0x04
  161892. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161893. #define PNG_HAVE_IEND 0x10
  161894. #if defined(PNG_INTERNAL)
  161895. #define PNG_HAVE_gAMA 0x20
  161896. #define PNG_HAVE_cHRM 0x40
  161897. #define PNG_HAVE_sRGB 0x80
  161898. #define PNG_HAVE_CHUNK_HEADER 0x100
  161899. #define PNG_WROTE_tIME 0x200
  161900. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161901. #define PNG_BACKGROUND_IS_GRAY 0x800
  161902. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161903. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161904. #define PNG_BGR 0x0001
  161905. #define PNG_INTERLACE 0x0002
  161906. #define PNG_PACK 0x0004
  161907. #define PNG_SHIFT 0x0008
  161908. #define PNG_SWAP_BYTES 0x0010
  161909. #define PNG_INVERT_MONO 0x0020
  161910. #define PNG_DITHER 0x0040
  161911. #define PNG_BACKGROUND 0x0080
  161912. #define PNG_BACKGROUND_EXPAND 0x0100
  161913. #define PNG_16_TO_8 0x0400
  161914. #define PNG_RGBA 0x0800
  161915. #define PNG_EXPAND 0x1000
  161916. #define PNG_GAMMA 0x2000
  161917. #define PNG_GRAY_TO_RGB 0x4000
  161918. #define PNG_FILLER 0x8000L
  161919. #define PNG_PACKSWAP 0x10000L
  161920. #define PNG_SWAP_ALPHA 0x20000L
  161921. #define PNG_STRIP_ALPHA 0x40000L
  161922. #define PNG_INVERT_ALPHA 0x80000L
  161923. #define PNG_USER_TRANSFORM 0x100000L
  161924. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161925. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161926. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161927. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161928. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161929. #define PNG_STRUCT_PNG 0x0001
  161930. #define PNG_STRUCT_INFO 0x0002
  161931. #define PNG_WEIGHT_SHIFT 8
  161932. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161933. #define PNG_COST_SHIFT 3
  161934. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161935. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161936. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161937. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161938. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161939. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161940. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161941. #define PNG_FLAG_ROW_INIT 0x0040
  161942. #define PNG_FLAG_FILLER_AFTER 0x0080
  161943. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161944. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161945. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161946. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161947. #define PNG_FLAG_FREE_PLTE 0x1000
  161948. #define PNG_FLAG_FREE_TRNS 0x2000
  161949. #define PNG_FLAG_FREE_HIST 0x4000
  161950. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161951. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161952. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161953. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161954. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161955. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161956. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161957. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161958. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161959. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161960. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161961. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161962. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161963. PNG_FLAG_CRC_CRITICAL_MASK)
  161964. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161965. abs((int)((c1).green) - (int)((c2).green)) + \
  161966. abs((int)((c1).blue) - (int)((c2).blue)))
  161967. #define PNG_ROWBYTES(pixel_bits, width) \
  161968. ((pixel_bits) >= 8 ? \
  161969. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161970. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161971. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161972. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161973. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161974. #ifdef PNG_USE_GLOBAL_ARRAYS
  161975. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161976. #else
  161977. #endif
  161978. #endif /* PNG_NO_EXTERN */
  161979. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161980. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161981. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161982. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161983. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161984. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161985. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161986. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161987. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161988. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161989. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161990. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161991. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161992. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161993. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161994. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161995. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161996. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161997. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161998. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161999. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  162000. #ifdef PNG_USE_GLOBAL_ARRAYS
  162001. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  162002. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  162003. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  162004. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  162005. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  162006. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  162007. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  162008. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  162009. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  162010. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  162011. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  162012. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  162013. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  162014. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  162015. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  162016. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  162017. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  162018. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  162019. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  162020. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  162021. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  162022. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162023. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162024. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  162025. #undef png_read_init
  162026. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  162027. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162028. #endif
  162029. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  162030. png_const_charp user_png_ver, png_size_t png_struct_size));
  162031. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162032. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  162033. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162034. png_info_size));
  162035. #endif
  162036. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162037. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  162038. #undef png_write_init
  162039. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  162040. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162041. #endif
  162042. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  162043. png_const_charp user_png_ver, png_size_t png_struct_size));
  162044. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  162045. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162046. png_info_size));
  162047. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  162048. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  162049. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  162050. malloc_fn, png_voidp mem_ptr));
  162051. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  162052. png_free_ptr free_fn, png_voidp mem_ptr));
  162053. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  162054. png_infop info_ptr));
  162055. #ifndef PNG_1_0_X
  162056. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  162057. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  162058. #ifdef PNG_SIZE_T
  162059. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162060. #endif
  162061. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  162062. png_bytep data, png_size_t length));
  162063. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162064. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  162065. png_bytep buffer, png_size_t length));
  162066. #endif
  162067. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  162068. png_bytep data, png_size_t length));
  162069. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162070. #if !defined(PNG_NO_STDIO)
  162071. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  162072. #endif
  162073. #endif
  162074. #else /* PNG_1_0_X */
  162075. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162076. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  162077. png_bytep buffer, png_size_t length));
  162078. #endif
  162079. #endif /* PNG_1_0_X */
  162080. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  162081. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  162082. png_size_t length));
  162083. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  162084. png_size_t length));
  162085. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  162086. png_size_t length));
  162087. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  162088. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  162089. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  162090. int comp_type, png_charp chunkdata, png_size_t chunklength,
  162091. png_size_t prefix_length, png_size_t *data_length));
  162092. #endif
  162093. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  162094. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  162095. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  162096. png_size_t length));
  162097. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162098. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  162099. #endif
  162100. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  162101. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  162102. png_uint_32 height,
  162103. int bit_depth, int color_type, int compression_method, int filter_method,
  162104. int interlace_method));
  162105. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  162106. png_uint_32 num_pal));
  162107. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  162108. png_size_t length));
  162109. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  162110. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  162111. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162112. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  162113. #endif
  162114. #ifdef PNG_FIXED_POINT_SUPPORTED
  162115. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  162116. file_gamma));
  162117. #endif
  162118. #endif
  162119. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  162120. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  162121. int color_type));
  162122. #endif
  162123. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  162124. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162125. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  162126. double white_x, double white_y,
  162127. double red_x, double red_y, double green_x, double green_y,
  162128. double blue_x, double blue_y));
  162129. #endif
  162130. #ifdef PNG_FIXED_POINT_SUPPORTED
  162131. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  162132. png_fixed_point int_white_x, png_fixed_point int_white_y,
  162133. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  162134. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  162135. png_fixed_point int_blue_y));
  162136. #endif
  162137. #endif
  162138. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  162139. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  162140. int intent));
  162141. #endif
  162142. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  162143. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  162144. png_charp name, int compression_type,
  162145. png_charp profile, int proflen));
  162146. #endif
  162147. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  162148. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  162149. png_sPLT_tp palette));
  162150. #endif
  162151. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  162152. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  162153. png_color_16p values, int number, int color_type));
  162154. #endif
  162155. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  162156. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  162157. png_color_16p values, int color_type));
  162158. #endif
  162159. #if defined(PNG_WRITE_hIST_SUPPORTED)
  162160. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  162161. int num_hist));
  162162. #endif
  162163. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  162164. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  162165. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  162166. png_charp key, png_charpp new_key));
  162167. #endif
  162168. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  162169. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  162170. png_charp text, png_size_t text_len));
  162171. #endif
  162172. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  162173. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  162174. png_charp text, png_size_t text_len, int compression));
  162175. #endif
  162176. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  162177. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  162178. int compression, png_charp key, png_charp lang, png_charp lang_key,
  162179. png_charp text));
  162180. #endif
  162181. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  162182. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  162183. png_infop info_ptr, png_textp text_ptr, int num_text));
  162184. #endif
  162185. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  162186. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  162187. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  162188. #endif
  162189. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  162190. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  162191. png_int_32 X0, png_int_32 X1, int type, int nparams,
  162192. png_charp units, png_charpp params));
  162193. #endif
  162194. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  162195. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  162196. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  162197. int unit_type));
  162198. #endif
  162199. #if defined(PNG_WRITE_tIME_SUPPORTED)
  162200. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  162201. png_timep mod_time));
  162202. #endif
  162203. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  162204. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  162205. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  162206. int unit, double width, double height));
  162207. #else
  162208. #ifdef PNG_FIXED_POINT_SUPPORTED
  162209. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  162210. int unit, png_charp width, png_charp height));
  162211. #endif
  162212. #endif
  162213. #endif
  162214. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  162215. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  162216. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162217. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  162218. #endif
  162219. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  162220. int mask));
  162221. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  162222. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  162223. #endif
  162224. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  162225. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  162226. png_bytep row, int pass));
  162227. #endif
  162228. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  162229. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  162230. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  162231. png_row_infop row_info));
  162232. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  162233. png_bytep filtered_row));
  162234. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  162235. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  162236. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  162237. png_infop info_ptr));
  162238. #if defined(PNG_READ_FILLER_SUPPORTED)
  162239. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  162240. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  162241. #endif
  162242. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  162243. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  162244. png_bytep row));
  162245. #endif
  162246. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  162247. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  162248. png_bytep row));
  162249. #endif
  162250. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  162251. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  162252. png_bytep row));
  162253. #endif
  162254. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  162255. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  162256. png_bytep row));
  162257. #endif
  162258. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  162259. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  162260. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  162261. png_bytep row, png_uint_32 flags));
  162262. #endif
  162263. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162264. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  162265. #endif
  162266. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162267. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  162268. #endif
  162269. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  162270. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  162271. row_info, png_bytep row));
  162272. #endif
  162273. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  162274. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  162275. png_bytep row));
  162276. #endif
  162277. #if defined(PNG_READ_PACK_SUPPORTED)
  162278. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  162279. #endif
  162280. #if defined(PNG_READ_SHIFT_SUPPORTED)
  162281. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  162282. png_color_8p sig_bits));
  162283. #endif
  162284. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  162285. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162286. #endif
  162287. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162288. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162289. #endif
  162290. #if defined(PNG_READ_DITHER_SUPPORTED)
  162291. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162292. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162293. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162294. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162295. png_colorp palette, int num_palette));
  162296. # endif
  162297. #endif
  162298. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162299. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162300. #endif
  162301. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162302. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162303. png_bytep row, png_uint_32 bit_depth));
  162304. #endif
  162305. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162306. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162307. png_color_8p bit_depth));
  162308. #endif
  162309. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162310. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162311. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162312. png_color_16p trans_values, png_color_16p background,
  162313. png_color_16p background_1,
  162314. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162315. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162316. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162317. #else
  162318. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162319. png_color_16p trans_values, png_color_16p background));
  162320. #endif
  162321. #endif
  162322. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162323. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162324. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162325. int gamma_shift));
  162326. #endif
  162327. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162328. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162329. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162330. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162331. png_bytep row, png_color_16p trans_value));
  162332. #endif
  162333. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162334. png_uint_32 length));
  162335. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162336. png_uint_32 length));
  162337. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162338. png_uint_32 length));
  162339. #if defined(PNG_READ_bKGD_SUPPORTED)
  162340. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162341. png_uint_32 length));
  162342. #endif
  162343. #if defined(PNG_READ_cHRM_SUPPORTED)
  162344. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162345. png_uint_32 length));
  162346. #endif
  162347. #if defined(PNG_READ_gAMA_SUPPORTED)
  162348. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162349. png_uint_32 length));
  162350. #endif
  162351. #if defined(PNG_READ_hIST_SUPPORTED)
  162352. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162353. png_uint_32 length));
  162354. #endif
  162355. #if defined(PNG_READ_iCCP_SUPPORTED)
  162356. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162357. png_uint_32 length));
  162358. #endif /* PNG_READ_iCCP_SUPPORTED */
  162359. #if defined(PNG_READ_iTXt_SUPPORTED)
  162360. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162361. png_uint_32 length));
  162362. #endif
  162363. #if defined(PNG_READ_oFFs_SUPPORTED)
  162364. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162365. png_uint_32 length));
  162366. #endif
  162367. #if defined(PNG_READ_pCAL_SUPPORTED)
  162368. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162369. png_uint_32 length));
  162370. #endif
  162371. #if defined(PNG_READ_pHYs_SUPPORTED)
  162372. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162373. png_uint_32 length));
  162374. #endif
  162375. #if defined(PNG_READ_sBIT_SUPPORTED)
  162376. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162377. png_uint_32 length));
  162378. #endif
  162379. #if defined(PNG_READ_sCAL_SUPPORTED)
  162380. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162381. png_uint_32 length));
  162382. #endif
  162383. #if defined(PNG_READ_sPLT_SUPPORTED)
  162384. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162385. png_uint_32 length));
  162386. #endif /* PNG_READ_sPLT_SUPPORTED */
  162387. #if defined(PNG_READ_sRGB_SUPPORTED)
  162388. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162389. png_uint_32 length));
  162390. #endif
  162391. #if defined(PNG_READ_tEXt_SUPPORTED)
  162392. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162393. png_uint_32 length));
  162394. #endif
  162395. #if defined(PNG_READ_tIME_SUPPORTED)
  162396. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162397. png_uint_32 length));
  162398. #endif
  162399. #if defined(PNG_READ_tRNS_SUPPORTED)
  162400. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162401. png_uint_32 length));
  162402. #endif
  162403. #if defined(PNG_READ_zTXt_SUPPORTED)
  162404. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162405. png_uint_32 length));
  162406. #endif
  162407. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162408. png_infop info_ptr, png_uint_32 length));
  162409. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162410. png_bytep chunk_name));
  162411. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162412. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162413. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162414. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162415. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162416. png_infop info_ptr));
  162417. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162418. png_infop info_ptr));
  162419. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162420. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162421. png_uint_32 length));
  162422. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162423. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162424. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162425. png_bytep buffer, png_size_t buffer_length));
  162426. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162427. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162428. png_bytep buffer, png_size_t buffer_length));
  162429. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162430. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162431. png_infop info_ptr, png_uint_32 length));
  162432. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162433. png_infop info_ptr));
  162434. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162435. png_infop info_ptr));
  162436. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162437. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162438. png_infop info_ptr));
  162439. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162440. png_infop info_ptr));
  162441. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162442. #if defined(PNG_READ_tEXt_SUPPORTED)
  162443. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162444. png_infop info_ptr, png_uint_32 length));
  162445. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162446. png_infop info_ptr));
  162447. #endif
  162448. #if defined(PNG_READ_zTXt_SUPPORTED)
  162449. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162450. png_infop info_ptr, png_uint_32 length));
  162451. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162452. png_infop info_ptr));
  162453. #endif
  162454. #if defined(PNG_READ_iTXt_SUPPORTED)
  162455. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162456. png_infop info_ptr, png_uint_32 length));
  162457. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162458. png_infop info_ptr));
  162459. #endif
  162460. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162461. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162462. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162463. png_bytep row));
  162464. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162465. png_bytep row));
  162466. #endif
  162467. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162468. #if defined(PNG_MMX_CODE_SUPPORTED)
  162469. /* PRIVATE */
  162470. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162471. #endif
  162472. #endif
  162473. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162474. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162475. png_infop info_ptr));
  162476. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162477. png_infop info_ptr));
  162478. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162479. png_infop info_ptr));
  162480. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162481. png_infop info_ptr));
  162482. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162483. png_infop info_ptr));
  162484. #if defined(PNG_pHYs_SUPPORTED)
  162485. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162486. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162487. #endif /* PNG_pHYs_SUPPORTED */
  162488. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162489. #endif /* PNG_INTERNAL */
  162490. #ifdef __cplusplus
  162491. }
  162492. #endif
  162493. #endif /* PNG_VERSION_INFO_ONLY */
  162494. #endif /* PNG_H */
  162495. /*** End of inlined file: png.h ***/
  162496. #define PNG_NO_EXTERN
  162497. /*** Start of inlined file: png.c ***/
  162498. #define PNG_INTERNAL
  162499. #define PNG_NO_EXTERN
  162500. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162501. #ifdef PNG_USE_GLOBAL_ARRAYS
  162502. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162503. #ifdef PNG_READ_SUPPORTED
  162504. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162505. #endif /* PNG_READ_SUPPORTED */
  162506. PNG_IHDR;
  162507. PNG_IDAT;
  162508. PNG_IEND;
  162509. PNG_PLTE;
  162510. PNG_bKGD;
  162511. PNG_cHRM;
  162512. PNG_gAMA;
  162513. PNG_hIST;
  162514. PNG_iCCP;
  162515. PNG_iTXt;
  162516. PNG_oFFs;
  162517. PNG_pCAL;
  162518. PNG_sCAL;
  162519. PNG_pHYs;
  162520. PNG_sBIT;
  162521. PNG_sPLT;
  162522. PNG_sRGB;
  162523. PNG_tEXt;
  162524. PNG_tIME;
  162525. PNG_tRNS;
  162526. PNG_zTXt;
  162527. #ifdef PNG_READ_SUPPORTED
  162528. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162529. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162530. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162531. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162532. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162533. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162534. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162535. #endif /* PNG_READ_SUPPORTED */
  162536. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162537. #ifdef PNG_READ_SUPPORTED
  162538. void PNGAPI
  162539. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162540. {
  162541. if(png_ptr == NULL) return;
  162542. png_debug(1, "in png_set_sig_bytes\n");
  162543. if (num_bytes > 8)
  162544. png_error(png_ptr, "Too many bytes for PNG signature.");
  162545. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162546. }
  162547. int PNGAPI
  162548. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162549. {
  162550. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162551. if (num_to_check > 8)
  162552. num_to_check = 8;
  162553. else if (num_to_check < 1)
  162554. return (-1);
  162555. if (start > 7)
  162556. return (-1);
  162557. if (start + num_to_check > 8)
  162558. num_to_check = 8 - start;
  162559. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162560. }
  162561. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162562. int PNGAPI
  162563. png_check_sig(png_bytep sig, int num)
  162564. {
  162565. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162566. }
  162567. #endif
  162568. #endif /* PNG_READ_SUPPORTED */
  162569. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162570. #ifdef PNG_1_0_X
  162571. voidpf PNGAPI
  162572. #else
  162573. voidpf /* private */
  162574. #endif
  162575. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162576. {
  162577. png_voidp ptr;
  162578. png_structp p=(png_structp)png_ptr;
  162579. png_uint_32 save_flags=p->flags;
  162580. png_uint_32 num_bytes;
  162581. if(png_ptr == NULL) return (NULL);
  162582. if (items > PNG_UINT_32_MAX/size)
  162583. {
  162584. png_warning (p, "Potential overflow in png_zalloc()");
  162585. return (NULL);
  162586. }
  162587. num_bytes = (png_uint_32)items * size;
  162588. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162589. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162590. p->flags=save_flags;
  162591. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162592. if (ptr == NULL)
  162593. return ((voidpf)ptr);
  162594. if (num_bytes > (png_uint_32)0x8000L)
  162595. {
  162596. png_memset(ptr, 0, (png_size_t)0x8000L);
  162597. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162598. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162599. }
  162600. else
  162601. {
  162602. png_memset(ptr, 0, (png_size_t)num_bytes);
  162603. }
  162604. #endif
  162605. return ((voidpf)ptr);
  162606. }
  162607. #ifdef PNG_1_0_X
  162608. void PNGAPI
  162609. #else
  162610. void /* private */
  162611. #endif
  162612. png_zfree(voidpf png_ptr, voidpf ptr)
  162613. {
  162614. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162615. }
  162616. void /* PRIVATE */
  162617. png_reset_crc(png_structp png_ptr)
  162618. {
  162619. png_ptr->crc = crc32(0, Z_NULL, 0);
  162620. }
  162621. void /* PRIVATE */
  162622. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162623. {
  162624. int need_crc = 1;
  162625. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162626. {
  162627. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162628. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162629. need_crc = 0;
  162630. }
  162631. else /* critical */
  162632. {
  162633. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162634. need_crc = 0;
  162635. }
  162636. if (need_crc)
  162637. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162638. }
  162639. png_infop PNGAPI
  162640. png_create_info_struct(png_structp png_ptr)
  162641. {
  162642. png_infop info_ptr;
  162643. png_debug(1, "in png_create_info_struct\n");
  162644. if(png_ptr == NULL) return (NULL);
  162645. #ifdef PNG_USER_MEM_SUPPORTED
  162646. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162647. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162648. #else
  162649. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162650. #endif
  162651. if (info_ptr != NULL)
  162652. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162653. return (info_ptr);
  162654. }
  162655. void PNGAPI
  162656. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162657. {
  162658. png_infop info_ptr = NULL;
  162659. if(png_ptr == NULL) return;
  162660. png_debug(1, "in png_destroy_info_struct\n");
  162661. if (info_ptr_ptr != NULL)
  162662. info_ptr = *info_ptr_ptr;
  162663. if (info_ptr != NULL)
  162664. {
  162665. png_info_destroy(png_ptr, info_ptr);
  162666. #ifdef PNG_USER_MEM_SUPPORTED
  162667. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162668. png_ptr->mem_ptr);
  162669. #else
  162670. png_destroy_struct((png_voidp)info_ptr);
  162671. #endif
  162672. *info_ptr_ptr = NULL;
  162673. }
  162674. }
  162675. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162676. #undef png_info_init
  162677. void PNGAPI
  162678. png_info_init(png_infop info_ptr)
  162679. {
  162680. png_info_init_3(&info_ptr, 0);
  162681. }
  162682. #endif
  162683. void PNGAPI
  162684. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162685. {
  162686. png_infop info_ptr = *ptr_ptr;
  162687. if(info_ptr == NULL) return;
  162688. png_debug(1, "in png_info_init_3\n");
  162689. if(png_sizeof(png_info) > png_info_struct_size)
  162690. {
  162691. png_destroy_struct(info_ptr);
  162692. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162693. *ptr_ptr = info_ptr;
  162694. }
  162695. png_memset(info_ptr, 0, png_sizeof (png_info));
  162696. }
  162697. #ifdef PNG_FREE_ME_SUPPORTED
  162698. void PNGAPI
  162699. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162700. int freer, png_uint_32 mask)
  162701. {
  162702. png_debug(1, "in png_data_freer\n");
  162703. if (png_ptr == NULL || info_ptr == NULL)
  162704. return;
  162705. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162706. info_ptr->free_me |= mask;
  162707. else if(freer == PNG_USER_WILL_FREE_DATA)
  162708. info_ptr->free_me &= ~mask;
  162709. else
  162710. png_warning(png_ptr,
  162711. "Unknown freer parameter in png_data_freer.");
  162712. }
  162713. #endif
  162714. void PNGAPI
  162715. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162716. int num)
  162717. {
  162718. png_debug(1, "in png_free_data\n");
  162719. if (png_ptr == NULL || info_ptr == NULL)
  162720. return;
  162721. #if defined(PNG_TEXT_SUPPORTED)
  162722. #ifdef PNG_FREE_ME_SUPPORTED
  162723. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162724. #else
  162725. if (mask & PNG_FREE_TEXT)
  162726. #endif
  162727. {
  162728. if (num != -1)
  162729. {
  162730. if (info_ptr->text && info_ptr->text[num].key)
  162731. {
  162732. png_free(png_ptr, info_ptr->text[num].key);
  162733. info_ptr->text[num].key = NULL;
  162734. }
  162735. }
  162736. else
  162737. {
  162738. int i;
  162739. for (i = 0; i < info_ptr->num_text; i++)
  162740. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162741. png_free(png_ptr, info_ptr->text);
  162742. info_ptr->text = NULL;
  162743. info_ptr->num_text=0;
  162744. }
  162745. }
  162746. #endif
  162747. #if defined(PNG_tRNS_SUPPORTED)
  162748. #ifdef PNG_FREE_ME_SUPPORTED
  162749. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162750. #else
  162751. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162752. #endif
  162753. {
  162754. png_free(png_ptr, info_ptr->trans);
  162755. info_ptr->valid &= ~PNG_INFO_tRNS;
  162756. #ifndef PNG_FREE_ME_SUPPORTED
  162757. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162758. #endif
  162759. info_ptr->trans = NULL;
  162760. }
  162761. #endif
  162762. #if defined(PNG_sCAL_SUPPORTED)
  162763. #ifdef PNG_FREE_ME_SUPPORTED
  162764. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162765. #else
  162766. if (mask & PNG_FREE_SCAL)
  162767. #endif
  162768. {
  162769. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162770. png_free(png_ptr, info_ptr->scal_s_width);
  162771. png_free(png_ptr, info_ptr->scal_s_height);
  162772. info_ptr->scal_s_width = NULL;
  162773. info_ptr->scal_s_height = NULL;
  162774. #endif
  162775. info_ptr->valid &= ~PNG_INFO_sCAL;
  162776. }
  162777. #endif
  162778. #if defined(PNG_pCAL_SUPPORTED)
  162779. #ifdef PNG_FREE_ME_SUPPORTED
  162780. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162781. #else
  162782. if (mask & PNG_FREE_PCAL)
  162783. #endif
  162784. {
  162785. png_free(png_ptr, info_ptr->pcal_purpose);
  162786. png_free(png_ptr, info_ptr->pcal_units);
  162787. info_ptr->pcal_purpose = NULL;
  162788. info_ptr->pcal_units = NULL;
  162789. if (info_ptr->pcal_params != NULL)
  162790. {
  162791. int i;
  162792. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162793. {
  162794. png_free(png_ptr, info_ptr->pcal_params[i]);
  162795. info_ptr->pcal_params[i]=NULL;
  162796. }
  162797. png_free(png_ptr, info_ptr->pcal_params);
  162798. info_ptr->pcal_params = NULL;
  162799. }
  162800. info_ptr->valid &= ~PNG_INFO_pCAL;
  162801. }
  162802. #endif
  162803. #if defined(PNG_iCCP_SUPPORTED)
  162804. #ifdef PNG_FREE_ME_SUPPORTED
  162805. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162806. #else
  162807. if (mask & PNG_FREE_ICCP)
  162808. #endif
  162809. {
  162810. png_free(png_ptr, info_ptr->iccp_name);
  162811. png_free(png_ptr, info_ptr->iccp_profile);
  162812. info_ptr->iccp_name = NULL;
  162813. info_ptr->iccp_profile = NULL;
  162814. info_ptr->valid &= ~PNG_INFO_iCCP;
  162815. }
  162816. #endif
  162817. #if defined(PNG_sPLT_SUPPORTED)
  162818. #ifdef PNG_FREE_ME_SUPPORTED
  162819. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162820. #else
  162821. if (mask & PNG_FREE_SPLT)
  162822. #endif
  162823. {
  162824. if (num != -1)
  162825. {
  162826. if(info_ptr->splt_palettes)
  162827. {
  162828. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162829. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162830. info_ptr->splt_palettes[num].name = NULL;
  162831. info_ptr->splt_palettes[num].entries = NULL;
  162832. }
  162833. }
  162834. else
  162835. {
  162836. if(info_ptr->splt_palettes_num)
  162837. {
  162838. int i;
  162839. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162840. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162841. png_free(png_ptr, info_ptr->splt_palettes);
  162842. info_ptr->splt_palettes = NULL;
  162843. info_ptr->splt_palettes_num = 0;
  162844. }
  162845. info_ptr->valid &= ~PNG_INFO_sPLT;
  162846. }
  162847. }
  162848. #endif
  162849. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162850. if(png_ptr->unknown_chunk.data)
  162851. {
  162852. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162853. png_ptr->unknown_chunk.data = NULL;
  162854. }
  162855. #ifdef PNG_FREE_ME_SUPPORTED
  162856. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162857. #else
  162858. if (mask & PNG_FREE_UNKN)
  162859. #endif
  162860. {
  162861. if (num != -1)
  162862. {
  162863. if(info_ptr->unknown_chunks)
  162864. {
  162865. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162866. info_ptr->unknown_chunks[num].data = NULL;
  162867. }
  162868. }
  162869. else
  162870. {
  162871. int i;
  162872. if(info_ptr->unknown_chunks_num)
  162873. {
  162874. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162875. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162876. png_free(png_ptr, info_ptr->unknown_chunks);
  162877. info_ptr->unknown_chunks = NULL;
  162878. info_ptr->unknown_chunks_num = 0;
  162879. }
  162880. }
  162881. }
  162882. #endif
  162883. #if defined(PNG_hIST_SUPPORTED)
  162884. #ifdef PNG_FREE_ME_SUPPORTED
  162885. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162886. #else
  162887. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162888. #endif
  162889. {
  162890. png_free(png_ptr, info_ptr->hist);
  162891. info_ptr->hist = NULL;
  162892. info_ptr->valid &= ~PNG_INFO_hIST;
  162893. #ifndef PNG_FREE_ME_SUPPORTED
  162894. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162895. #endif
  162896. }
  162897. #endif
  162898. #ifdef PNG_FREE_ME_SUPPORTED
  162899. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162900. #else
  162901. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162902. #endif
  162903. {
  162904. png_zfree(png_ptr, info_ptr->palette);
  162905. info_ptr->palette = NULL;
  162906. info_ptr->valid &= ~PNG_INFO_PLTE;
  162907. #ifndef PNG_FREE_ME_SUPPORTED
  162908. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162909. #endif
  162910. info_ptr->num_palette = 0;
  162911. }
  162912. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162913. #ifdef PNG_FREE_ME_SUPPORTED
  162914. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162915. #else
  162916. if (mask & PNG_FREE_ROWS)
  162917. #endif
  162918. {
  162919. if(info_ptr->row_pointers)
  162920. {
  162921. int row;
  162922. for (row = 0; row < (int)info_ptr->height; row++)
  162923. {
  162924. png_free(png_ptr, info_ptr->row_pointers[row]);
  162925. info_ptr->row_pointers[row]=NULL;
  162926. }
  162927. png_free(png_ptr, info_ptr->row_pointers);
  162928. info_ptr->row_pointers=NULL;
  162929. }
  162930. info_ptr->valid &= ~PNG_INFO_IDAT;
  162931. }
  162932. #endif
  162933. #ifdef PNG_FREE_ME_SUPPORTED
  162934. if(num == -1)
  162935. info_ptr->free_me &= ~mask;
  162936. else
  162937. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162938. #endif
  162939. }
  162940. void /* PRIVATE */
  162941. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162942. {
  162943. png_debug(1, "in png_info_destroy\n");
  162944. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162945. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162946. if (png_ptr->num_chunk_list)
  162947. {
  162948. png_free(png_ptr, png_ptr->chunk_list);
  162949. png_ptr->chunk_list=NULL;
  162950. png_ptr->num_chunk_list=0;
  162951. }
  162952. #endif
  162953. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162954. }
  162955. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162956. png_voidp PNGAPI
  162957. png_get_io_ptr(png_structp png_ptr)
  162958. {
  162959. if(png_ptr == NULL) return (NULL);
  162960. return (png_ptr->io_ptr);
  162961. }
  162962. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162963. #if !defined(PNG_NO_STDIO)
  162964. void PNGAPI
  162965. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162966. {
  162967. png_debug(1, "in png_init_io\n");
  162968. if(png_ptr == NULL) return;
  162969. png_ptr->io_ptr = (png_voidp)fp;
  162970. }
  162971. #endif
  162972. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162973. png_charp PNGAPI
  162974. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162975. {
  162976. static PNG_CONST char short_months[12][4] =
  162977. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162978. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162979. if(png_ptr == NULL) return (NULL);
  162980. if (png_ptr->time_buffer == NULL)
  162981. {
  162982. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162983. png_sizeof(char)));
  162984. }
  162985. #if defined(_WIN32_WCE)
  162986. {
  162987. wchar_t time_buf[29];
  162988. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162989. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162990. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162991. ptime->second % 61);
  162992. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162993. NULL, NULL);
  162994. }
  162995. #else
  162996. #ifdef USE_FAR_KEYWORD
  162997. {
  162998. char near_time_buf[29];
  162999. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  163000. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163001. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163002. ptime->second % 61);
  163003. png_memcpy(png_ptr->time_buffer, near_time_buf,
  163004. 29*png_sizeof(char));
  163005. }
  163006. #else
  163007. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  163008. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163009. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163010. ptime->second % 61);
  163011. #endif
  163012. #endif /* _WIN32_WCE */
  163013. return ((png_charp)png_ptr->time_buffer);
  163014. }
  163015. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  163016. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163017. png_charp PNGAPI
  163018. png_get_copyright(png_structp png_ptr)
  163019. {
  163020. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163021. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  163022. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  163023. Copyright (c) 1996-1997 Andreas Dilger\n\
  163024. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  163025. }
  163026. png_charp PNGAPI
  163027. png_get_libpng_ver(png_structp png_ptr)
  163028. {
  163029. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163030. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163031. }
  163032. png_charp PNGAPI
  163033. png_get_header_ver(png_structp png_ptr)
  163034. {
  163035. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163036. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163037. }
  163038. png_charp PNGAPI
  163039. png_get_header_version(png_structp png_ptr)
  163040. {
  163041. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163042. return ((png_charp) PNG_HEADER_VERSION_STRING
  163043. #ifndef PNG_READ_SUPPORTED
  163044. " (NO READ SUPPORT)"
  163045. #endif
  163046. "\n");
  163047. }
  163048. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163049. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  163050. int PNGAPI
  163051. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  163052. {
  163053. int i;
  163054. png_bytep p;
  163055. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  163056. return 0;
  163057. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  163058. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  163059. if (!png_memcmp(chunk_name, p, 4))
  163060. return ((int)*(p+4));
  163061. return 0;
  163062. }
  163063. #endif
  163064. int PNGAPI
  163065. png_reset_zstream(png_structp png_ptr)
  163066. {
  163067. if (png_ptr == NULL) return Z_STREAM_ERROR;
  163068. return (inflateReset(&png_ptr->zstream));
  163069. }
  163070. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163071. png_uint_32 PNGAPI
  163072. png_access_version_number(void)
  163073. {
  163074. return((png_uint_32) PNG_LIBPNG_VER);
  163075. }
  163076. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  163077. #if !defined(PNG_1_0_X)
  163078. int PNGAPI
  163079. png_mmx_support(void)
  163080. {
  163081. return -1;
  163082. }
  163083. #endif /* PNG_1_0_X */
  163084. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  163085. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163086. #ifdef PNG_SIZE_T
  163087. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  163088. png_size_t PNGAPI
  163089. png_convert_size(size_t size)
  163090. {
  163091. if (size > (png_size_t)-1)
  163092. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  163093. return ((png_size_t)size);
  163094. }
  163095. #endif /* PNG_SIZE_T */
  163096. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163097. /*** End of inlined file: png.c ***/
  163098. /*** Start of inlined file: pngerror.c ***/
  163099. #define PNG_INTERNAL
  163100. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163101. static void /* PRIVATE */
  163102. png_default_error PNGARG((png_structp png_ptr,
  163103. png_const_charp error_message));
  163104. #ifndef PNG_NO_WARNINGS
  163105. static void /* PRIVATE */
  163106. png_default_warning PNGARG((png_structp png_ptr,
  163107. png_const_charp warning_message));
  163108. #endif /* PNG_NO_WARNINGS */
  163109. #ifndef PNG_NO_ERROR_TEXT
  163110. void PNGAPI
  163111. png_error(png_structp png_ptr, png_const_charp error_message)
  163112. {
  163113. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163114. char msg[16];
  163115. if (png_ptr != NULL)
  163116. {
  163117. if (png_ptr->flags&
  163118. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163119. {
  163120. if (*error_message == '#')
  163121. {
  163122. int offset;
  163123. for (offset=1; offset<15; offset++)
  163124. if (*(error_message+offset) == ' ')
  163125. break;
  163126. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163127. {
  163128. int i;
  163129. for (i=0; i<offset-1; i++)
  163130. msg[i]=error_message[i+1];
  163131. msg[i]='\0';
  163132. error_message=msg;
  163133. }
  163134. else
  163135. error_message+=offset;
  163136. }
  163137. else
  163138. {
  163139. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163140. {
  163141. msg[0]='0';
  163142. msg[1]='\0';
  163143. error_message=msg;
  163144. }
  163145. }
  163146. }
  163147. }
  163148. #endif
  163149. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163150. (*(png_ptr->error_fn))(png_ptr, error_message);
  163151. png_default_error(png_ptr, error_message);
  163152. }
  163153. #else
  163154. void PNGAPI
  163155. png_err(png_structp png_ptr)
  163156. {
  163157. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163158. (*(png_ptr->error_fn))(png_ptr, '\0');
  163159. png_default_error(png_ptr, '\0');
  163160. }
  163161. #endif /* PNG_NO_ERROR_TEXT */
  163162. #ifndef PNG_NO_WARNINGS
  163163. void PNGAPI
  163164. png_warning(png_structp png_ptr, png_const_charp warning_message)
  163165. {
  163166. int offset = 0;
  163167. if (png_ptr != NULL)
  163168. {
  163169. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163170. if (png_ptr->flags&
  163171. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163172. #endif
  163173. {
  163174. if (*warning_message == '#')
  163175. {
  163176. for (offset=1; offset<15; offset++)
  163177. if (*(warning_message+offset) == ' ')
  163178. break;
  163179. }
  163180. }
  163181. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  163182. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  163183. }
  163184. else
  163185. png_default_warning(png_ptr, warning_message+offset);
  163186. }
  163187. #endif /* PNG_NO_WARNINGS */
  163188. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  163189. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  163190. static void /* PRIVATE */
  163191. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  163192. error_message)
  163193. {
  163194. int iout = 0, iin = 0;
  163195. while (iin < 4)
  163196. {
  163197. int c = png_ptr->chunk_name[iin++];
  163198. if (isnonalpha(c))
  163199. {
  163200. buffer[iout++] = '[';
  163201. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  163202. buffer[iout++] = png_digit[c & 0x0f];
  163203. buffer[iout++] = ']';
  163204. }
  163205. else
  163206. {
  163207. buffer[iout++] = (png_byte)c;
  163208. }
  163209. }
  163210. if (error_message == NULL)
  163211. buffer[iout] = 0;
  163212. else
  163213. {
  163214. buffer[iout++] = ':';
  163215. buffer[iout++] = ' ';
  163216. png_strncpy(buffer+iout, error_message, 63);
  163217. buffer[iout+63] = 0;
  163218. }
  163219. }
  163220. #ifdef PNG_READ_SUPPORTED
  163221. void PNGAPI
  163222. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  163223. {
  163224. char msg[18+64];
  163225. if (png_ptr == NULL)
  163226. png_error(png_ptr, error_message);
  163227. else
  163228. {
  163229. png_format_buffer(png_ptr, msg, error_message);
  163230. png_error(png_ptr, msg);
  163231. }
  163232. }
  163233. #endif /* PNG_READ_SUPPORTED */
  163234. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  163235. #ifndef PNG_NO_WARNINGS
  163236. void PNGAPI
  163237. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  163238. {
  163239. char msg[18+64];
  163240. if (png_ptr == NULL)
  163241. png_warning(png_ptr, warning_message);
  163242. else
  163243. {
  163244. png_format_buffer(png_ptr, msg, warning_message);
  163245. png_warning(png_ptr, msg);
  163246. }
  163247. }
  163248. #endif /* PNG_NO_WARNINGS */
  163249. static void /* PRIVATE */
  163250. png_default_error(png_structp png_ptr, png_const_charp error_message)
  163251. {
  163252. #ifndef PNG_NO_CONSOLE_IO
  163253. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163254. if (*error_message == '#')
  163255. {
  163256. int offset;
  163257. char error_number[16];
  163258. for (offset=0; offset<15; offset++)
  163259. {
  163260. error_number[offset] = *(error_message+offset+1);
  163261. if (*(error_message+offset) == ' ')
  163262. break;
  163263. }
  163264. if((offset > 1) && (offset < 15))
  163265. {
  163266. error_number[offset-1]='\0';
  163267. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  163268. error_message+offset);
  163269. }
  163270. else
  163271. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  163272. }
  163273. else
  163274. #endif
  163275. fprintf(stderr, "libpng error: %s\n", error_message);
  163276. #endif
  163277. #ifdef PNG_SETJMP_SUPPORTED
  163278. if (png_ptr)
  163279. {
  163280. # ifdef USE_FAR_KEYWORD
  163281. {
  163282. jmp_buf jmpbuf;
  163283. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  163284. longjmp(jmpbuf, 1);
  163285. }
  163286. # else
  163287. longjmp(png_ptr->jmpbuf, 1);
  163288. # endif
  163289. }
  163290. #else
  163291. PNG_ABORT();
  163292. #endif
  163293. #ifdef PNG_NO_CONSOLE_IO
  163294. error_message = error_message; /* make compiler happy */
  163295. #endif
  163296. }
  163297. #ifndef PNG_NO_WARNINGS
  163298. static void /* PRIVATE */
  163299. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163300. {
  163301. #ifndef PNG_NO_CONSOLE_IO
  163302. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163303. if (*warning_message == '#')
  163304. {
  163305. int offset;
  163306. char warning_number[16];
  163307. for (offset=0; offset<15; offset++)
  163308. {
  163309. warning_number[offset]=*(warning_message+offset+1);
  163310. if (*(warning_message+offset) == ' ')
  163311. break;
  163312. }
  163313. if((offset > 1) && (offset < 15))
  163314. {
  163315. warning_number[offset-1]='\0';
  163316. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163317. warning_message+offset);
  163318. }
  163319. else
  163320. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163321. }
  163322. else
  163323. # endif
  163324. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163325. #else
  163326. warning_message = warning_message; /* make compiler happy */
  163327. #endif
  163328. png_ptr = png_ptr; /* make compiler happy */
  163329. }
  163330. #endif /* PNG_NO_WARNINGS */
  163331. void PNGAPI
  163332. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163333. png_error_ptr error_fn, png_error_ptr warning_fn)
  163334. {
  163335. if (png_ptr == NULL)
  163336. return;
  163337. png_ptr->error_ptr = error_ptr;
  163338. png_ptr->error_fn = error_fn;
  163339. png_ptr->warning_fn = warning_fn;
  163340. }
  163341. png_voidp PNGAPI
  163342. png_get_error_ptr(png_structp png_ptr)
  163343. {
  163344. if (png_ptr == NULL)
  163345. return NULL;
  163346. return ((png_voidp)png_ptr->error_ptr);
  163347. }
  163348. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163349. void PNGAPI
  163350. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163351. {
  163352. if(png_ptr != NULL)
  163353. {
  163354. png_ptr->flags &=
  163355. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163356. }
  163357. }
  163358. #endif
  163359. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163360. /*** End of inlined file: pngerror.c ***/
  163361. /*** Start of inlined file: pngget.c ***/
  163362. #define PNG_INTERNAL
  163363. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163364. png_uint_32 PNGAPI
  163365. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163366. {
  163367. if (png_ptr != NULL && info_ptr != NULL)
  163368. return(info_ptr->valid & flag);
  163369. else
  163370. return(0);
  163371. }
  163372. png_uint_32 PNGAPI
  163373. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163374. {
  163375. if (png_ptr != NULL && info_ptr != NULL)
  163376. return(info_ptr->rowbytes);
  163377. else
  163378. return(0);
  163379. }
  163380. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163381. png_bytepp PNGAPI
  163382. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163383. {
  163384. if (png_ptr != NULL && info_ptr != NULL)
  163385. return(info_ptr->row_pointers);
  163386. else
  163387. return(0);
  163388. }
  163389. #endif
  163390. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163391. png_uint_32 PNGAPI
  163392. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163393. {
  163394. if (png_ptr != NULL && info_ptr != NULL)
  163395. {
  163396. return info_ptr->width;
  163397. }
  163398. return (0);
  163399. }
  163400. png_uint_32 PNGAPI
  163401. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163402. {
  163403. if (png_ptr != NULL && info_ptr != NULL)
  163404. {
  163405. return info_ptr->height;
  163406. }
  163407. return (0);
  163408. }
  163409. png_byte PNGAPI
  163410. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163411. {
  163412. if (png_ptr != NULL && info_ptr != NULL)
  163413. {
  163414. return info_ptr->bit_depth;
  163415. }
  163416. return (0);
  163417. }
  163418. png_byte PNGAPI
  163419. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163420. {
  163421. if (png_ptr != NULL && info_ptr != NULL)
  163422. {
  163423. return info_ptr->color_type;
  163424. }
  163425. return (0);
  163426. }
  163427. png_byte PNGAPI
  163428. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163429. {
  163430. if (png_ptr != NULL && info_ptr != NULL)
  163431. {
  163432. return info_ptr->filter_type;
  163433. }
  163434. return (0);
  163435. }
  163436. png_byte PNGAPI
  163437. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163438. {
  163439. if (png_ptr != NULL && info_ptr != NULL)
  163440. {
  163441. return info_ptr->interlace_type;
  163442. }
  163443. return (0);
  163444. }
  163445. png_byte PNGAPI
  163446. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163447. {
  163448. if (png_ptr != NULL && info_ptr != NULL)
  163449. {
  163450. return info_ptr->compression_type;
  163451. }
  163452. return (0);
  163453. }
  163454. png_uint_32 PNGAPI
  163455. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163456. {
  163457. if (png_ptr != NULL && info_ptr != NULL)
  163458. #if defined(PNG_pHYs_SUPPORTED)
  163459. if (info_ptr->valid & PNG_INFO_pHYs)
  163460. {
  163461. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163462. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163463. return (0);
  163464. else return (info_ptr->x_pixels_per_unit);
  163465. }
  163466. #else
  163467. return (0);
  163468. #endif
  163469. return (0);
  163470. }
  163471. png_uint_32 PNGAPI
  163472. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163473. {
  163474. if (png_ptr != NULL && info_ptr != NULL)
  163475. #if defined(PNG_pHYs_SUPPORTED)
  163476. if (info_ptr->valid & PNG_INFO_pHYs)
  163477. {
  163478. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163479. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163480. return (0);
  163481. else return (info_ptr->y_pixels_per_unit);
  163482. }
  163483. #else
  163484. return (0);
  163485. #endif
  163486. return (0);
  163487. }
  163488. png_uint_32 PNGAPI
  163489. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163490. {
  163491. if (png_ptr != NULL && info_ptr != NULL)
  163492. #if defined(PNG_pHYs_SUPPORTED)
  163493. if (info_ptr->valid & PNG_INFO_pHYs)
  163494. {
  163495. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163496. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163497. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163498. return (0);
  163499. else return (info_ptr->x_pixels_per_unit);
  163500. }
  163501. #else
  163502. return (0);
  163503. #endif
  163504. return (0);
  163505. }
  163506. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163507. float PNGAPI
  163508. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163509. {
  163510. if (png_ptr != NULL && info_ptr != NULL)
  163511. #if defined(PNG_pHYs_SUPPORTED)
  163512. if (info_ptr->valid & PNG_INFO_pHYs)
  163513. {
  163514. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163515. if (info_ptr->x_pixels_per_unit == 0)
  163516. return ((float)0.0);
  163517. else
  163518. return ((float)((float)info_ptr->y_pixels_per_unit
  163519. /(float)info_ptr->x_pixels_per_unit));
  163520. }
  163521. #else
  163522. return (0.0);
  163523. #endif
  163524. return ((float)0.0);
  163525. }
  163526. #endif
  163527. png_int_32 PNGAPI
  163528. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163529. {
  163530. if (png_ptr != NULL && info_ptr != NULL)
  163531. #if defined(PNG_oFFs_SUPPORTED)
  163532. if (info_ptr->valid & PNG_INFO_oFFs)
  163533. {
  163534. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163535. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163536. return (0);
  163537. else return (info_ptr->x_offset);
  163538. }
  163539. #else
  163540. return (0);
  163541. #endif
  163542. return (0);
  163543. }
  163544. png_int_32 PNGAPI
  163545. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163546. {
  163547. if (png_ptr != NULL && info_ptr != NULL)
  163548. #if defined(PNG_oFFs_SUPPORTED)
  163549. if (info_ptr->valid & PNG_INFO_oFFs)
  163550. {
  163551. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163552. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163553. return (0);
  163554. else return (info_ptr->y_offset);
  163555. }
  163556. #else
  163557. return (0);
  163558. #endif
  163559. return (0);
  163560. }
  163561. png_int_32 PNGAPI
  163562. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163563. {
  163564. if (png_ptr != NULL && info_ptr != NULL)
  163565. #if defined(PNG_oFFs_SUPPORTED)
  163566. if (info_ptr->valid & PNG_INFO_oFFs)
  163567. {
  163568. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163569. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163570. return (0);
  163571. else return (info_ptr->x_offset);
  163572. }
  163573. #else
  163574. return (0);
  163575. #endif
  163576. return (0);
  163577. }
  163578. png_int_32 PNGAPI
  163579. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163580. {
  163581. if (png_ptr != NULL && info_ptr != NULL)
  163582. #if defined(PNG_oFFs_SUPPORTED)
  163583. if (info_ptr->valid & PNG_INFO_oFFs)
  163584. {
  163585. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163586. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163587. return (0);
  163588. else return (info_ptr->y_offset);
  163589. }
  163590. #else
  163591. return (0);
  163592. #endif
  163593. return (0);
  163594. }
  163595. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163596. png_uint_32 PNGAPI
  163597. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163598. {
  163599. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163600. *.0254 +.5));
  163601. }
  163602. png_uint_32 PNGAPI
  163603. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163604. {
  163605. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163606. *.0254 +.5));
  163607. }
  163608. png_uint_32 PNGAPI
  163609. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163610. {
  163611. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163612. *.0254 +.5));
  163613. }
  163614. float PNGAPI
  163615. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163616. {
  163617. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163618. *.00003937);
  163619. }
  163620. float PNGAPI
  163621. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163622. {
  163623. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163624. *.00003937);
  163625. }
  163626. #if defined(PNG_pHYs_SUPPORTED)
  163627. png_uint_32 PNGAPI
  163628. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163629. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163630. {
  163631. png_uint_32 retval = 0;
  163632. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163633. {
  163634. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163635. if (res_x != NULL)
  163636. {
  163637. *res_x = info_ptr->x_pixels_per_unit;
  163638. retval |= PNG_INFO_pHYs;
  163639. }
  163640. if (res_y != NULL)
  163641. {
  163642. *res_y = info_ptr->y_pixels_per_unit;
  163643. retval |= PNG_INFO_pHYs;
  163644. }
  163645. if (unit_type != NULL)
  163646. {
  163647. *unit_type = (int)info_ptr->phys_unit_type;
  163648. retval |= PNG_INFO_pHYs;
  163649. if(*unit_type == 1)
  163650. {
  163651. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163652. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163653. }
  163654. }
  163655. }
  163656. return (retval);
  163657. }
  163658. #endif /* PNG_pHYs_SUPPORTED */
  163659. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163660. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163661. png_byte PNGAPI
  163662. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163663. {
  163664. if (png_ptr != NULL && info_ptr != NULL)
  163665. return(info_ptr->channels);
  163666. else
  163667. return (0);
  163668. }
  163669. png_bytep PNGAPI
  163670. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163671. {
  163672. if (png_ptr != NULL && info_ptr != NULL)
  163673. return(info_ptr->signature);
  163674. else
  163675. return (NULL);
  163676. }
  163677. #if defined(PNG_bKGD_SUPPORTED)
  163678. png_uint_32 PNGAPI
  163679. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163680. png_color_16p *background)
  163681. {
  163682. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163683. && background != NULL)
  163684. {
  163685. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163686. *background = &(info_ptr->background);
  163687. return (PNG_INFO_bKGD);
  163688. }
  163689. return (0);
  163690. }
  163691. #endif
  163692. #if defined(PNG_cHRM_SUPPORTED)
  163693. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163694. png_uint_32 PNGAPI
  163695. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163696. double *white_x, double *white_y, double *red_x, double *red_y,
  163697. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163698. {
  163699. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163700. {
  163701. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163702. if (white_x != NULL)
  163703. *white_x = (double)info_ptr->x_white;
  163704. if (white_y != NULL)
  163705. *white_y = (double)info_ptr->y_white;
  163706. if (red_x != NULL)
  163707. *red_x = (double)info_ptr->x_red;
  163708. if (red_y != NULL)
  163709. *red_y = (double)info_ptr->y_red;
  163710. if (green_x != NULL)
  163711. *green_x = (double)info_ptr->x_green;
  163712. if (green_y != NULL)
  163713. *green_y = (double)info_ptr->y_green;
  163714. if (blue_x != NULL)
  163715. *blue_x = (double)info_ptr->x_blue;
  163716. if (blue_y != NULL)
  163717. *blue_y = (double)info_ptr->y_blue;
  163718. return (PNG_INFO_cHRM);
  163719. }
  163720. return (0);
  163721. }
  163722. #endif
  163723. #ifdef PNG_FIXED_POINT_SUPPORTED
  163724. png_uint_32 PNGAPI
  163725. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163726. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163727. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163728. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163729. {
  163730. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163731. {
  163732. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163733. if (white_x != NULL)
  163734. *white_x = info_ptr->int_x_white;
  163735. if (white_y != NULL)
  163736. *white_y = info_ptr->int_y_white;
  163737. if (red_x != NULL)
  163738. *red_x = info_ptr->int_x_red;
  163739. if (red_y != NULL)
  163740. *red_y = info_ptr->int_y_red;
  163741. if (green_x != NULL)
  163742. *green_x = info_ptr->int_x_green;
  163743. if (green_y != NULL)
  163744. *green_y = info_ptr->int_y_green;
  163745. if (blue_x != NULL)
  163746. *blue_x = info_ptr->int_x_blue;
  163747. if (blue_y != NULL)
  163748. *blue_y = info_ptr->int_y_blue;
  163749. return (PNG_INFO_cHRM);
  163750. }
  163751. return (0);
  163752. }
  163753. #endif
  163754. #endif
  163755. #if defined(PNG_gAMA_SUPPORTED)
  163756. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163757. png_uint_32 PNGAPI
  163758. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163759. {
  163760. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163761. && file_gamma != NULL)
  163762. {
  163763. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163764. *file_gamma = (double)info_ptr->gamma;
  163765. return (PNG_INFO_gAMA);
  163766. }
  163767. return (0);
  163768. }
  163769. #endif
  163770. #ifdef PNG_FIXED_POINT_SUPPORTED
  163771. png_uint_32 PNGAPI
  163772. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163773. png_fixed_point *int_file_gamma)
  163774. {
  163775. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163776. && int_file_gamma != NULL)
  163777. {
  163778. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163779. *int_file_gamma = info_ptr->int_gamma;
  163780. return (PNG_INFO_gAMA);
  163781. }
  163782. return (0);
  163783. }
  163784. #endif
  163785. #endif
  163786. #if defined(PNG_sRGB_SUPPORTED)
  163787. png_uint_32 PNGAPI
  163788. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163789. {
  163790. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163791. && file_srgb_intent != NULL)
  163792. {
  163793. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163794. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163795. return (PNG_INFO_sRGB);
  163796. }
  163797. return (0);
  163798. }
  163799. #endif
  163800. #if defined(PNG_iCCP_SUPPORTED)
  163801. png_uint_32 PNGAPI
  163802. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163803. png_charpp name, int *compression_type,
  163804. png_charpp profile, png_uint_32 *proflen)
  163805. {
  163806. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163807. && name != NULL && profile != NULL && proflen != NULL)
  163808. {
  163809. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163810. *name = info_ptr->iccp_name;
  163811. *profile = info_ptr->iccp_profile;
  163812. *proflen = (int)info_ptr->iccp_proflen;
  163813. *compression_type = (int)info_ptr->iccp_compression;
  163814. return (PNG_INFO_iCCP);
  163815. }
  163816. return (0);
  163817. }
  163818. #endif
  163819. #if defined(PNG_sPLT_SUPPORTED)
  163820. png_uint_32 PNGAPI
  163821. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163822. png_sPLT_tpp spalettes)
  163823. {
  163824. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163825. {
  163826. *spalettes = info_ptr->splt_palettes;
  163827. return ((png_uint_32)info_ptr->splt_palettes_num);
  163828. }
  163829. return (0);
  163830. }
  163831. #endif
  163832. #if defined(PNG_hIST_SUPPORTED)
  163833. png_uint_32 PNGAPI
  163834. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163835. {
  163836. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163837. && hist != NULL)
  163838. {
  163839. png_debug1(1, "in %s retrieval function\n", "hIST");
  163840. *hist = info_ptr->hist;
  163841. return (PNG_INFO_hIST);
  163842. }
  163843. return (0);
  163844. }
  163845. #endif
  163846. png_uint_32 PNGAPI
  163847. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163848. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163849. int *color_type, int *interlace_type, int *compression_type,
  163850. int *filter_type)
  163851. {
  163852. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163853. bit_depth != NULL && color_type != NULL)
  163854. {
  163855. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163856. *width = info_ptr->width;
  163857. *height = info_ptr->height;
  163858. *bit_depth = info_ptr->bit_depth;
  163859. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163860. png_error(png_ptr, "Invalid bit depth");
  163861. *color_type = info_ptr->color_type;
  163862. if (info_ptr->color_type > 6)
  163863. png_error(png_ptr, "Invalid color type");
  163864. if (compression_type != NULL)
  163865. *compression_type = info_ptr->compression_type;
  163866. if (filter_type != NULL)
  163867. *filter_type = info_ptr->filter_type;
  163868. if (interlace_type != NULL)
  163869. *interlace_type = info_ptr->interlace_type;
  163870. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163871. png_error(png_ptr, "Invalid image width");
  163872. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163873. png_error(png_ptr, "Invalid image height");
  163874. if (info_ptr->width > (PNG_UINT_32_MAX
  163875. >> 3) /* 8-byte RGBA pixels */
  163876. - 64 /* bigrowbuf hack */
  163877. - 1 /* filter byte */
  163878. - 7*8 /* rounding of width to multiple of 8 pixels */
  163879. - 8) /* extra max_pixel_depth pad */
  163880. {
  163881. png_warning(png_ptr,
  163882. "Width too large for libpng to process image data.");
  163883. }
  163884. return (1);
  163885. }
  163886. return (0);
  163887. }
  163888. #if defined(PNG_oFFs_SUPPORTED)
  163889. png_uint_32 PNGAPI
  163890. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163891. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163892. {
  163893. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163894. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163895. {
  163896. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163897. *offset_x = info_ptr->x_offset;
  163898. *offset_y = info_ptr->y_offset;
  163899. *unit_type = (int)info_ptr->offset_unit_type;
  163900. return (PNG_INFO_oFFs);
  163901. }
  163902. return (0);
  163903. }
  163904. #endif
  163905. #if defined(PNG_pCAL_SUPPORTED)
  163906. png_uint_32 PNGAPI
  163907. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163908. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163909. png_charp *units, png_charpp *params)
  163910. {
  163911. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163912. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163913. nparams != NULL && units != NULL && params != NULL)
  163914. {
  163915. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163916. *purpose = info_ptr->pcal_purpose;
  163917. *X0 = info_ptr->pcal_X0;
  163918. *X1 = info_ptr->pcal_X1;
  163919. *type = (int)info_ptr->pcal_type;
  163920. *nparams = (int)info_ptr->pcal_nparams;
  163921. *units = info_ptr->pcal_units;
  163922. *params = info_ptr->pcal_params;
  163923. return (PNG_INFO_pCAL);
  163924. }
  163925. return (0);
  163926. }
  163927. #endif
  163928. #if defined(PNG_sCAL_SUPPORTED)
  163929. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163930. png_uint_32 PNGAPI
  163931. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163932. int *unit, double *width, double *height)
  163933. {
  163934. if (png_ptr != NULL && info_ptr != NULL &&
  163935. (info_ptr->valid & PNG_INFO_sCAL))
  163936. {
  163937. *unit = info_ptr->scal_unit;
  163938. *width = info_ptr->scal_pixel_width;
  163939. *height = info_ptr->scal_pixel_height;
  163940. return (PNG_INFO_sCAL);
  163941. }
  163942. return(0);
  163943. }
  163944. #else
  163945. #ifdef PNG_FIXED_POINT_SUPPORTED
  163946. png_uint_32 PNGAPI
  163947. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163948. int *unit, png_charpp width, png_charpp height)
  163949. {
  163950. if (png_ptr != NULL && info_ptr != NULL &&
  163951. (info_ptr->valid & PNG_INFO_sCAL))
  163952. {
  163953. *unit = info_ptr->scal_unit;
  163954. *width = info_ptr->scal_s_width;
  163955. *height = info_ptr->scal_s_height;
  163956. return (PNG_INFO_sCAL);
  163957. }
  163958. return(0);
  163959. }
  163960. #endif
  163961. #endif
  163962. #endif
  163963. #if defined(PNG_pHYs_SUPPORTED)
  163964. png_uint_32 PNGAPI
  163965. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163966. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163967. {
  163968. png_uint_32 retval = 0;
  163969. if (png_ptr != NULL && info_ptr != NULL &&
  163970. (info_ptr->valid & PNG_INFO_pHYs))
  163971. {
  163972. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163973. if (res_x != NULL)
  163974. {
  163975. *res_x = info_ptr->x_pixels_per_unit;
  163976. retval |= PNG_INFO_pHYs;
  163977. }
  163978. if (res_y != NULL)
  163979. {
  163980. *res_y = info_ptr->y_pixels_per_unit;
  163981. retval |= PNG_INFO_pHYs;
  163982. }
  163983. if (unit_type != NULL)
  163984. {
  163985. *unit_type = (int)info_ptr->phys_unit_type;
  163986. retval |= PNG_INFO_pHYs;
  163987. }
  163988. }
  163989. return (retval);
  163990. }
  163991. #endif
  163992. png_uint_32 PNGAPI
  163993. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163994. int *num_palette)
  163995. {
  163996. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163997. && palette != NULL)
  163998. {
  163999. png_debug1(1, "in %s retrieval function\n", "PLTE");
  164000. *palette = info_ptr->palette;
  164001. *num_palette = info_ptr->num_palette;
  164002. png_debug1(3, "num_palette = %d\n", *num_palette);
  164003. return (PNG_INFO_PLTE);
  164004. }
  164005. return (0);
  164006. }
  164007. #if defined(PNG_sBIT_SUPPORTED)
  164008. png_uint_32 PNGAPI
  164009. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  164010. {
  164011. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  164012. && sig_bit != NULL)
  164013. {
  164014. png_debug1(1, "in %s retrieval function\n", "sBIT");
  164015. *sig_bit = &(info_ptr->sig_bit);
  164016. return (PNG_INFO_sBIT);
  164017. }
  164018. return (0);
  164019. }
  164020. #endif
  164021. #if defined(PNG_TEXT_SUPPORTED)
  164022. png_uint_32 PNGAPI
  164023. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  164024. int *num_text)
  164025. {
  164026. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  164027. {
  164028. png_debug1(1, "in %s retrieval function\n",
  164029. (png_ptr->chunk_name[0] == '\0' ? "text"
  164030. : (png_const_charp)png_ptr->chunk_name));
  164031. if (text_ptr != NULL)
  164032. *text_ptr = info_ptr->text;
  164033. if (num_text != NULL)
  164034. *num_text = info_ptr->num_text;
  164035. return ((png_uint_32)info_ptr->num_text);
  164036. }
  164037. if (num_text != NULL)
  164038. *num_text = 0;
  164039. return(0);
  164040. }
  164041. #endif
  164042. #if defined(PNG_tIME_SUPPORTED)
  164043. png_uint_32 PNGAPI
  164044. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  164045. {
  164046. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  164047. && mod_time != NULL)
  164048. {
  164049. png_debug1(1, "in %s retrieval function\n", "tIME");
  164050. *mod_time = &(info_ptr->mod_time);
  164051. return (PNG_INFO_tIME);
  164052. }
  164053. return (0);
  164054. }
  164055. #endif
  164056. #if defined(PNG_tRNS_SUPPORTED)
  164057. png_uint_32 PNGAPI
  164058. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  164059. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  164060. {
  164061. png_uint_32 retval = 0;
  164062. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  164063. {
  164064. png_debug1(1, "in %s retrieval function\n", "tRNS");
  164065. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  164066. {
  164067. if (trans != NULL)
  164068. {
  164069. *trans = info_ptr->trans;
  164070. retval |= PNG_INFO_tRNS;
  164071. }
  164072. if (trans_values != NULL)
  164073. *trans_values = &(info_ptr->trans_values);
  164074. }
  164075. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  164076. {
  164077. if (trans_values != NULL)
  164078. {
  164079. *trans_values = &(info_ptr->trans_values);
  164080. retval |= PNG_INFO_tRNS;
  164081. }
  164082. if(trans != NULL)
  164083. *trans = NULL;
  164084. }
  164085. if(num_trans != NULL)
  164086. {
  164087. *num_trans = info_ptr->num_trans;
  164088. retval |= PNG_INFO_tRNS;
  164089. }
  164090. }
  164091. return (retval);
  164092. }
  164093. #endif
  164094. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  164095. png_uint_32 PNGAPI
  164096. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  164097. png_unknown_chunkpp unknowns)
  164098. {
  164099. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  164100. {
  164101. *unknowns = info_ptr->unknown_chunks;
  164102. return ((png_uint_32)info_ptr->unknown_chunks_num);
  164103. }
  164104. return (0);
  164105. }
  164106. #endif
  164107. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  164108. png_byte PNGAPI
  164109. png_get_rgb_to_gray_status (png_structp png_ptr)
  164110. {
  164111. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  164112. }
  164113. #endif
  164114. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  164115. png_voidp PNGAPI
  164116. png_get_user_chunk_ptr(png_structp png_ptr)
  164117. {
  164118. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  164119. }
  164120. #endif
  164121. #ifdef PNG_WRITE_SUPPORTED
  164122. png_uint_32 PNGAPI
  164123. png_get_compression_buffer_size(png_structp png_ptr)
  164124. {
  164125. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  164126. }
  164127. #endif
  164128. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  164129. #ifndef PNG_1_0_X
  164130. png_uint_32 PNGAPI
  164131. png_get_asm_flags (png_structp png_ptr)
  164132. {
  164133. return (png_ptr? 0L: 0L);
  164134. }
  164135. png_uint_32 PNGAPI
  164136. png_get_asm_flagmask (int flag_select)
  164137. {
  164138. flag_select=flag_select;
  164139. return 0L;
  164140. }
  164141. png_uint_32 PNGAPI
  164142. png_get_mmx_flagmask (int flag_select, int *compilerID)
  164143. {
  164144. flag_select=flag_select;
  164145. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  164146. return 0L;
  164147. }
  164148. png_byte PNGAPI
  164149. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  164150. {
  164151. return (png_ptr? 0: 0);
  164152. }
  164153. png_uint_32 PNGAPI
  164154. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  164155. {
  164156. return (png_ptr? 0L: 0L);
  164157. }
  164158. #endif /* ?PNG_1_0_X */
  164159. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  164160. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164161. png_uint_32 PNGAPI
  164162. png_get_user_width_max (png_structp png_ptr)
  164163. {
  164164. return (png_ptr? png_ptr->user_width_max : 0);
  164165. }
  164166. png_uint_32 PNGAPI
  164167. png_get_user_height_max (png_structp png_ptr)
  164168. {
  164169. return (png_ptr? png_ptr->user_height_max : 0);
  164170. }
  164171. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  164172. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164173. /*** End of inlined file: pngget.c ***/
  164174. /*** Start of inlined file: pngmem.c ***/
  164175. #define PNG_INTERNAL
  164176. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  164177. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  164178. png_voidp /* PRIVATE */
  164179. png_create_struct(int type)
  164180. {
  164181. #ifdef PNG_USER_MEM_SUPPORTED
  164182. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164183. }
  164184. png_voidp /* PRIVATE */
  164185. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164186. {
  164187. #endif /* PNG_USER_MEM_SUPPORTED */
  164188. png_size_t size;
  164189. png_voidp struct_ptr;
  164190. if (type == PNG_STRUCT_INFO)
  164191. size = png_sizeof(png_info);
  164192. else if (type == PNG_STRUCT_PNG)
  164193. size = png_sizeof(png_struct);
  164194. else
  164195. return (png_get_copyright(NULL));
  164196. #ifdef PNG_USER_MEM_SUPPORTED
  164197. if(malloc_fn != NULL)
  164198. {
  164199. png_struct dummy_struct;
  164200. png_structp png_ptr = &dummy_struct;
  164201. png_ptr->mem_ptr=mem_ptr;
  164202. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  164203. }
  164204. else
  164205. #endif /* PNG_USER_MEM_SUPPORTED */
  164206. struct_ptr = (png_voidp)farmalloc(size);
  164207. if (struct_ptr != NULL)
  164208. png_memset(struct_ptr, 0, size);
  164209. return (struct_ptr);
  164210. }
  164211. void /* PRIVATE */
  164212. png_destroy_struct(png_voidp struct_ptr)
  164213. {
  164214. #ifdef PNG_USER_MEM_SUPPORTED
  164215. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164216. }
  164217. void /* PRIVATE */
  164218. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164219. png_voidp mem_ptr)
  164220. {
  164221. #endif
  164222. if (struct_ptr != NULL)
  164223. {
  164224. #ifdef PNG_USER_MEM_SUPPORTED
  164225. if(free_fn != NULL)
  164226. {
  164227. png_struct dummy_struct;
  164228. png_structp png_ptr = &dummy_struct;
  164229. png_ptr->mem_ptr=mem_ptr;
  164230. (*(free_fn))(png_ptr, struct_ptr);
  164231. return;
  164232. }
  164233. #endif /* PNG_USER_MEM_SUPPORTED */
  164234. farfree (struct_ptr);
  164235. }
  164236. }
  164237. png_voidp PNGAPI
  164238. png_malloc(png_structp png_ptr, png_uint_32 size)
  164239. {
  164240. png_voidp ret;
  164241. if (png_ptr == NULL || size == 0)
  164242. return (NULL);
  164243. #ifdef PNG_USER_MEM_SUPPORTED
  164244. if(png_ptr->malloc_fn != NULL)
  164245. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164246. else
  164247. ret = (png_malloc_default(png_ptr, size));
  164248. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164249. png_error(png_ptr, "Out of memory!");
  164250. return (ret);
  164251. }
  164252. png_voidp PNGAPI
  164253. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164254. {
  164255. png_voidp ret;
  164256. #endif /* PNG_USER_MEM_SUPPORTED */
  164257. if (png_ptr == NULL || size == 0)
  164258. return (NULL);
  164259. #ifdef PNG_MAX_MALLOC_64K
  164260. if (size > (png_uint_32)65536L)
  164261. {
  164262. png_warning(png_ptr, "Cannot Allocate > 64K");
  164263. ret = NULL;
  164264. }
  164265. else
  164266. #endif
  164267. if (size != (size_t)size)
  164268. ret = NULL;
  164269. else if (size == (png_uint_32)65536L)
  164270. {
  164271. if (png_ptr->offset_table == NULL)
  164272. {
  164273. ret = farmalloc(size);
  164274. if (ret == NULL || ((png_size_t)ret & 0xffff))
  164275. {
  164276. int num_blocks;
  164277. png_uint_32 total_size;
  164278. png_bytep table;
  164279. int i;
  164280. png_byte huge * hptr;
  164281. if (ret != NULL)
  164282. {
  164283. farfree(ret);
  164284. ret = NULL;
  164285. }
  164286. if(png_ptr->zlib_window_bits > 14)
  164287. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164288. else
  164289. num_blocks = 1;
  164290. if (png_ptr->zlib_mem_level >= 7)
  164291. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164292. else
  164293. num_blocks++;
  164294. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164295. table = farmalloc(total_size);
  164296. if (table == NULL)
  164297. {
  164298. #ifndef PNG_USER_MEM_SUPPORTED
  164299. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164300. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164301. else
  164302. png_warning(png_ptr, "Out Of Memory.");
  164303. #endif
  164304. return (NULL);
  164305. }
  164306. if ((png_size_t)table & 0xfff0)
  164307. {
  164308. #ifndef PNG_USER_MEM_SUPPORTED
  164309. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164310. png_error(png_ptr,
  164311. "Farmalloc didn't return normalized pointer");
  164312. else
  164313. png_warning(png_ptr,
  164314. "Farmalloc didn't return normalized pointer");
  164315. #endif
  164316. return (NULL);
  164317. }
  164318. png_ptr->offset_table = table;
  164319. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164320. png_sizeof (png_bytep));
  164321. if (png_ptr->offset_table_ptr == NULL)
  164322. {
  164323. #ifndef PNG_USER_MEM_SUPPORTED
  164324. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164325. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164326. else
  164327. png_warning(png_ptr, "Out Of memory.");
  164328. #endif
  164329. return (NULL);
  164330. }
  164331. hptr = (png_byte huge *)table;
  164332. if ((png_size_t)hptr & 0xf)
  164333. {
  164334. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164335. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164336. }
  164337. for (i = 0; i < num_blocks; i++)
  164338. {
  164339. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164340. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164341. }
  164342. png_ptr->offset_table_number = num_blocks;
  164343. png_ptr->offset_table_count = 0;
  164344. png_ptr->offset_table_count_free = 0;
  164345. }
  164346. }
  164347. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164348. {
  164349. #ifndef PNG_USER_MEM_SUPPORTED
  164350. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164351. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164352. else
  164353. png_warning(png_ptr, "Out of Memory.");
  164354. #endif
  164355. return (NULL);
  164356. }
  164357. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164358. }
  164359. else
  164360. ret = farmalloc(size);
  164361. #ifndef PNG_USER_MEM_SUPPORTED
  164362. if (ret == NULL)
  164363. {
  164364. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164365. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164366. else
  164367. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164368. }
  164369. #endif
  164370. return (ret);
  164371. }
  164372. void PNGAPI
  164373. png_free(png_structp png_ptr, png_voidp ptr)
  164374. {
  164375. if (png_ptr == NULL || ptr == NULL)
  164376. return;
  164377. #ifdef PNG_USER_MEM_SUPPORTED
  164378. if (png_ptr->free_fn != NULL)
  164379. {
  164380. (*(png_ptr->free_fn))(png_ptr, ptr);
  164381. return;
  164382. }
  164383. else png_free_default(png_ptr, ptr);
  164384. }
  164385. void PNGAPI
  164386. png_free_default(png_structp png_ptr, png_voidp ptr)
  164387. {
  164388. #endif /* PNG_USER_MEM_SUPPORTED */
  164389. if(png_ptr == NULL) return;
  164390. if (png_ptr->offset_table != NULL)
  164391. {
  164392. int i;
  164393. for (i = 0; i < png_ptr->offset_table_count; i++)
  164394. {
  164395. if (ptr == png_ptr->offset_table_ptr[i])
  164396. {
  164397. ptr = NULL;
  164398. png_ptr->offset_table_count_free++;
  164399. break;
  164400. }
  164401. }
  164402. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164403. {
  164404. farfree(png_ptr->offset_table);
  164405. farfree(png_ptr->offset_table_ptr);
  164406. png_ptr->offset_table = NULL;
  164407. png_ptr->offset_table_ptr = NULL;
  164408. }
  164409. }
  164410. if (ptr != NULL)
  164411. {
  164412. farfree(ptr);
  164413. }
  164414. }
  164415. #else /* Not the Borland DOS special memory handler */
  164416. png_voidp /* PRIVATE */
  164417. png_create_struct(int type)
  164418. {
  164419. #ifdef PNG_USER_MEM_SUPPORTED
  164420. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164421. }
  164422. png_voidp /* PRIVATE */
  164423. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164424. {
  164425. #endif /* PNG_USER_MEM_SUPPORTED */
  164426. png_size_t size;
  164427. png_voidp struct_ptr;
  164428. if (type == PNG_STRUCT_INFO)
  164429. size = png_sizeof(png_info);
  164430. else if (type == PNG_STRUCT_PNG)
  164431. size = png_sizeof(png_struct);
  164432. else
  164433. return (NULL);
  164434. #ifdef PNG_USER_MEM_SUPPORTED
  164435. if(malloc_fn != NULL)
  164436. {
  164437. png_struct dummy_struct;
  164438. png_structp png_ptr = &dummy_struct;
  164439. png_ptr->mem_ptr=mem_ptr;
  164440. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164441. if (struct_ptr != NULL)
  164442. png_memset(struct_ptr, 0, size);
  164443. return (struct_ptr);
  164444. }
  164445. #endif /* PNG_USER_MEM_SUPPORTED */
  164446. #if defined(__TURBOC__) && !defined(__FLAT__)
  164447. struct_ptr = (png_voidp)farmalloc(size);
  164448. #else
  164449. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164450. struct_ptr = (png_voidp)halloc(size,1);
  164451. # else
  164452. struct_ptr = (png_voidp)malloc(size);
  164453. # endif
  164454. #endif
  164455. if (struct_ptr != NULL)
  164456. png_memset(struct_ptr, 0, size);
  164457. return (struct_ptr);
  164458. }
  164459. void /* PRIVATE */
  164460. png_destroy_struct(png_voidp struct_ptr)
  164461. {
  164462. #ifdef PNG_USER_MEM_SUPPORTED
  164463. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164464. }
  164465. void /* PRIVATE */
  164466. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164467. png_voidp mem_ptr)
  164468. {
  164469. #endif /* PNG_USER_MEM_SUPPORTED */
  164470. if (struct_ptr != NULL)
  164471. {
  164472. #ifdef PNG_USER_MEM_SUPPORTED
  164473. if(free_fn != NULL)
  164474. {
  164475. png_struct dummy_struct;
  164476. png_structp png_ptr = &dummy_struct;
  164477. png_ptr->mem_ptr=mem_ptr;
  164478. (*(free_fn))(png_ptr, struct_ptr);
  164479. return;
  164480. }
  164481. #endif /* PNG_USER_MEM_SUPPORTED */
  164482. #if defined(__TURBOC__) && !defined(__FLAT__)
  164483. farfree(struct_ptr);
  164484. #else
  164485. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164486. hfree(struct_ptr);
  164487. # else
  164488. free(struct_ptr);
  164489. # endif
  164490. #endif
  164491. }
  164492. }
  164493. png_voidp PNGAPI
  164494. png_malloc(png_structp png_ptr, png_uint_32 size)
  164495. {
  164496. png_voidp ret;
  164497. #ifdef PNG_USER_MEM_SUPPORTED
  164498. if (png_ptr == NULL || size == 0)
  164499. return (NULL);
  164500. if(png_ptr->malloc_fn != NULL)
  164501. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164502. else
  164503. ret = (png_malloc_default(png_ptr, size));
  164504. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164505. png_error(png_ptr, "Out of Memory!");
  164506. return (ret);
  164507. }
  164508. png_voidp PNGAPI
  164509. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164510. {
  164511. png_voidp ret;
  164512. #endif /* PNG_USER_MEM_SUPPORTED */
  164513. if (png_ptr == NULL || size == 0)
  164514. return (NULL);
  164515. #ifdef PNG_MAX_MALLOC_64K
  164516. if (size > (png_uint_32)65536L)
  164517. {
  164518. #ifndef PNG_USER_MEM_SUPPORTED
  164519. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164520. png_error(png_ptr, "Cannot Allocate > 64K");
  164521. else
  164522. #endif
  164523. return NULL;
  164524. }
  164525. #endif
  164526. #if defined(__TURBOC__) && !defined(__FLAT__)
  164527. if (size != (unsigned long)size)
  164528. ret = NULL;
  164529. else
  164530. ret = farmalloc(size);
  164531. #else
  164532. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164533. if (size != (unsigned long)size)
  164534. ret = NULL;
  164535. else
  164536. ret = halloc(size, 1);
  164537. # else
  164538. if (size != (size_t)size)
  164539. ret = NULL;
  164540. else
  164541. ret = malloc((size_t)size);
  164542. # endif
  164543. #endif
  164544. #ifndef PNG_USER_MEM_SUPPORTED
  164545. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164546. png_error(png_ptr, "Out of Memory");
  164547. #endif
  164548. return (ret);
  164549. }
  164550. void PNGAPI
  164551. png_free(png_structp png_ptr, png_voidp ptr)
  164552. {
  164553. if (png_ptr == NULL || ptr == NULL)
  164554. return;
  164555. #ifdef PNG_USER_MEM_SUPPORTED
  164556. if (png_ptr->free_fn != NULL)
  164557. {
  164558. (*(png_ptr->free_fn))(png_ptr, ptr);
  164559. return;
  164560. }
  164561. else png_free_default(png_ptr, ptr);
  164562. }
  164563. void PNGAPI
  164564. png_free_default(png_structp png_ptr, png_voidp ptr)
  164565. {
  164566. if (png_ptr == NULL || ptr == NULL)
  164567. return;
  164568. #endif /* PNG_USER_MEM_SUPPORTED */
  164569. #if defined(__TURBOC__) && !defined(__FLAT__)
  164570. farfree(ptr);
  164571. #else
  164572. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164573. hfree(ptr);
  164574. # else
  164575. free(ptr);
  164576. # endif
  164577. #endif
  164578. }
  164579. #endif /* Not Borland DOS special memory handler */
  164580. #if defined(PNG_1_0_X)
  164581. # define png_malloc_warn png_malloc
  164582. #else
  164583. png_voidp PNGAPI
  164584. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164585. {
  164586. png_voidp ptr;
  164587. png_uint_32 save_flags;
  164588. if(png_ptr == NULL) return (NULL);
  164589. save_flags=png_ptr->flags;
  164590. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164591. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164592. png_ptr->flags=save_flags;
  164593. return(ptr);
  164594. }
  164595. #endif
  164596. png_voidp PNGAPI
  164597. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164598. png_uint_32 length)
  164599. {
  164600. png_size_t size;
  164601. size = (png_size_t)length;
  164602. if ((png_uint_32)size != length)
  164603. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164604. return(png_memcpy (s1, s2, size));
  164605. }
  164606. png_voidp PNGAPI
  164607. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164608. png_uint_32 length)
  164609. {
  164610. png_size_t size;
  164611. size = (png_size_t)length;
  164612. if ((png_uint_32)size != length)
  164613. png_error(png_ptr,"Overflow in png_memset_check.");
  164614. return (png_memset (s1, value, size));
  164615. }
  164616. #ifdef PNG_USER_MEM_SUPPORTED
  164617. void PNGAPI
  164618. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164619. malloc_fn, png_free_ptr free_fn)
  164620. {
  164621. if(png_ptr != NULL) {
  164622. png_ptr->mem_ptr = mem_ptr;
  164623. png_ptr->malloc_fn = malloc_fn;
  164624. png_ptr->free_fn = free_fn;
  164625. }
  164626. }
  164627. png_voidp PNGAPI
  164628. png_get_mem_ptr(png_structp png_ptr)
  164629. {
  164630. if(png_ptr == NULL) return (NULL);
  164631. return ((png_voidp)png_ptr->mem_ptr);
  164632. }
  164633. #endif /* PNG_USER_MEM_SUPPORTED */
  164634. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164635. /*** End of inlined file: pngmem.c ***/
  164636. /*** Start of inlined file: pngread.c ***/
  164637. #define PNG_INTERNAL
  164638. #if defined(PNG_READ_SUPPORTED)
  164639. png_structp PNGAPI
  164640. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164641. png_error_ptr error_fn, png_error_ptr warn_fn)
  164642. {
  164643. #ifdef PNG_USER_MEM_SUPPORTED
  164644. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164645. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164646. }
  164647. png_structp PNGAPI
  164648. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164649. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164650. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164651. {
  164652. #endif /* PNG_USER_MEM_SUPPORTED */
  164653. png_structp png_ptr;
  164654. #ifdef PNG_SETJMP_SUPPORTED
  164655. #ifdef USE_FAR_KEYWORD
  164656. jmp_buf jmpbuf;
  164657. #endif
  164658. #endif
  164659. int i;
  164660. png_debug(1, "in png_create_read_struct\n");
  164661. #ifdef PNG_USER_MEM_SUPPORTED
  164662. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164663. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164664. #else
  164665. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164666. #endif
  164667. if (png_ptr == NULL)
  164668. return (NULL);
  164669. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164670. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164671. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164672. #endif
  164673. #ifdef PNG_SETJMP_SUPPORTED
  164674. #ifdef USE_FAR_KEYWORD
  164675. if (setjmp(jmpbuf))
  164676. #else
  164677. if (setjmp(png_ptr->jmpbuf))
  164678. #endif
  164679. {
  164680. png_free(png_ptr, png_ptr->zbuf);
  164681. png_ptr->zbuf=NULL;
  164682. #ifdef PNG_USER_MEM_SUPPORTED
  164683. png_destroy_struct_2((png_voidp)png_ptr,
  164684. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164685. #else
  164686. png_destroy_struct((png_voidp)png_ptr);
  164687. #endif
  164688. return (NULL);
  164689. }
  164690. #ifdef USE_FAR_KEYWORD
  164691. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164692. #endif
  164693. #endif
  164694. #ifdef PNG_USER_MEM_SUPPORTED
  164695. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164696. #endif
  164697. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164698. i=0;
  164699. do
  164700. {
  164701. if(user_png_ver[i] != png_libpng_ver[i])
  164702. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164703. } while (png_libpng_ver[i++]);
  164704. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164705. {
  164706. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164707. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164708. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164709. {
  164710. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164711. char msg[80];
  164712. if (user_png_ver)
  164713. {
  164714. png_snprintf(msg, 80,
  164715. "Application was compiled with png.h from libpng-%.20s",
  164716. user_png_ver);
  164717. png_warning(png_ptr, msg);
  164718. }
  164719. png_snprintf(msg, 80,
  164720. "Application is running with png.c from libpng-%.20s",
  164721. png_libpng_ver);
  164722. png_warning(png_ptr, msg);
  164723. #endif
  164724. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164725. png_ptr->flags=0;
  164726. #endif
  164727. png_error(png_ptr,
  164728. "Incompatible libpng version in application and library");
  164729. }
  164730. }
  164731. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164732. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164733. (png_uint_32)png_ptr->zbuf_size);
  164734. png_ptr->zstream.zalloc = png_zalloc;
  164735. png_ptr->zstream.zfree = png_zfree;
  164736. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164737. switch (inflateInit(&png_ptr->zstream))
  164738. {
  164739. case Z_OK: /* Do nothing */ break;
  164740. case Z_MEM_ERROR:
  164741. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164742. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164743. default: png_error(png_ptr, "Unknown zlib error");
  164744. }
  164745. png_ptr->zstream.next_out = png_ptr->zbuf;
  164746. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164747. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164748. #ifdef PNG_SETJMP_SUPPORTED
  164749. #ifdef USE_FAR_KEYWORD
  164750. if (setjmp(jmpbuf))
  164751. PNG_ABORT();
  164752. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164753. #else
  164754. if (setjmp(png_ptr->jmpbuf))
  164755. PNG_ABORT();
  164756. #endif
  164757. #endif
  164758. return (png_ptr);
  164759. }
  164760. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164761. #undef png_read_init
  164762. void PNGAPI
  164763. png_read_init(png_structp png_ptr)
  164764. {
  164765. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164766. }
  164767. void PNGAPI
  164768. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164769. png_size_t png_struct_size, png_size_t png_info_size)
  164770. {
  164771. if(png_ptr == NULL) return;
  164772. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164773. if(png_sizeof(png_struct) > png_struct_size ||
  164774. png_sizeof(png_info) > png_info_size)
  164775. {
  164776. char msg[80];
  164777. png_ptr->warning_fn=NULL;
  164778. if (user_png_ver)
  164779. {
  164780. png_snprintf(msg, 80,
  164781. "Application was compiled with png.h from libpng-%.20s",
  164782. user_png_ver);
  164783. png_warning(png_ptr, msg);
  164784. }
  164785. png_snprintf(msg, 80,
  164786. "Application is running with png.c from libpng-%.20s",
  164787. png_libpng_ver);
  164788. png_warning(png_ptr, msg);
  164789. }
  164790. #endif
  164791. if(png_sizeof(png_struct) > png_struct_size)
  164792. {
  164793. png_ptr->error_fn=NULL;
  164794. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164795. png_ptr->flags=0;
  164796. #endif
  164797. png_error(png_ptr,
  164798. "The png struct allocated by the application for reading is too small.");
  164799. }
  164800. if(png_sizeof(png_info) > png_info_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 info struct allocated by application for reading is too small.");
  164808. }
  164809. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164810. }
  164811. #endif /* PNG_1_0_X || PNG_1_2_X */
  164812. void PNGAPI
  164813. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164814. png_size_t png_struct_size)
  164815. {
  164816. #ifdef PNG_SETJMP_SUPPORTED
  164817. jmp_buf tmp_jmp; /* to save current jump buffer */
  164818. #endif
  164819. int i=0;
  164820. png_structp png_ptr=*ptr_ptr;
  164821. if(png_ptr == NULL) return;
  164822. do
  164823. {
  164824. if(user_png_ver[i] != png_libpng_ver[i])
  164825. {
  164826. #ifdef PNG_LEGACY_SUPPORTED
  164827. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164828. #else
  164829. png_ptr->warning_fn=NULL;
  164830. png_warning(png_ptr,
  164831. "Application uses deprecated png_read_init() and should be recompiled.");
  164832. break;
  164833. #endif
  164834. }
  164835. } while (png_libpng_ver[i++]);
  164836. png_debug(1, "in png_read_init_3\n");
  164837. #ifdef PNG_SETJMP_SUPPORTED
  164838. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164839. #endif
  164840. if(png_sizeof(png_struct) > png_struct_size)
  164841. {
  164842. png_destroy_struct(png_ptr);
  164843. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164844. png_ptr = *ptr_ptr;
  164845. }
  164846. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164847. #ifdef PNG_SETJMP_SUPPORTED
  164848. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164849. #endif
  164850. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164851. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164852. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164853. #endif
  164854. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164855. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164856. (png_uint_32)png_ptr->zbuf_size);
  164857. png_ptr->zstream.zalloc = png_zalloc;
  164858. png_ptr->zstream.zfree = png_zfree;
  164859. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164860. switch (inflateInit(&png_ptr->zstream))
  164861. {
  164862. case Z_OK: /* Do nothing */ break;
  164863. case Z_MEM_ERROR:
  164864. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164865. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164866. default: png_error(png_ptr, "Unknown zlib error");
  164867. }
  164868. png_ptr->zstream.next_out = png_ptr->zbuf;
  164869. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164870. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164871. }
  164872. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164873. void PNGAPI
  164874. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164875. {
  164876. if(png_ptr == NULL) return;
  164877. png_debug(1, "in png_read_info\n");
  164878. if (png_ptr->sig_bytes < 8)
  164879. {
  164880. png_size_t num_checked = png_ptr->sig_bytes,
  164881. num_to_check = 8 - num_checked;
  164882. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164883. png_ptr->sig_bytes = 8;
  164884. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164885. {
  164886. if (num_checked < 4 &&
  164887. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164888. png_error(png_ptr, "Not a PNG file");
  164889. else
  164890. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164891. }
  164892. if (num_checked < 3)
  164893. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164894. }
  164895. for(;;)
  164896. {
  164897. #ifdef PNG_USE_LOCAL_ARRAYS
  164898. PNG_CONST PNG_IHDR;
  164899. PNG_CONST PNG_IDAT;
  164900. PNG_CONST PNG_IEND;
  164901. PNG_CONST PNG_PLTE;
  164902. #if defined(PNG_READ_bKGD_SUPPORTED)
  164903. PNG_CONST PNG_bKGD;
  164904. #endif
  164905. #if defined(PNG_READ_cHRM_SUPPORTED)
  164906. PNG_CONST PNG_cHRM;
  164907. #endif
  164908. #if defined(PNG_READ_gAMA_SUPPORTED)
  164909. PNG_CONST PNG_gAMA;
  164910. #endif
  164911. #if defined(PNG_READ_hIST_SUPPORTED)
  164912. PNG_CONST PNG_hIST;
  164913. #endif
  164914. #if defined(PNG_READ_iCCP_SUPPORTED)
  164915. PNG_CONST PNG_iCCP;
  164916. #endif
  164917. #if defined(PNG_READ_iTXt_SUPPORTED)
  164918. PNG_CONST PNG_iTXt;
  164919. #endif
  164920. #if defined(PNG_READ_oFFs_SUPPORTED)
  164921. PNG_CONST PNG_oFFs;
  164922. #endif
  164923. #if defined(PNG_READ_pCAL_SUPPORTED)
  164924. PNG_CONST PNG_pCAL;
  164925. #endif
  164926. #if defined(PNG_READ_pHYs_SUPPORTED)
  164927. PNG_CONST PNG_pHYs;
  164928. #endif
  164929. #if defined(PNG_READ_sBIT_SUPPORTED)
  164930. PNG_CONST PNG_sBIT;
  164931. #endif
  164932. #if defined(PNG_READ_sCAL_SUPPORTED)
  164933. PNG_CONST PNG_sCAL;
  164934. #endif
  164935. #if defined(PNG_READ_sPLT_SUPPORTED)
  164936. PNG_CONST PNG_sPLT;
  164937. #endif
  164938. #if defined(PNG_READ_sRGB_SUPPORTED)
  164939. PNG_CONST PNG_sRGB;
  164940. #endif
  164941. #if defined(PNG_READ_tEXt_SUPPORTED)
  164942. PNG_CONST PNG_tEXt;
  164943. #endif
  164944. #if defined(PNG_READ_tIME_SUPPORTED)
  164945. PNG_CONST PNG_tIME;
  164946. #endif
  164947. #if defined(PNG_READ_tRNS_SUPPORTED)
  164948. PNG_CONST PNG_tRNS;
  164949. #endif
  164950. #if defined(PNG_READ_zTXt_SUPPORTED)
  164951. PNG_CONST PNG_zTXt;
  164952. #endif
  164953. #endif /* PNG_USE_LOCAL_ARRAYS */
  164954. png_byte chunk_length[4];
  164955. png_uint_32 length;
  164956. png_read_data(png_ptr, chunk_length, 4);
  164957. length = png_get_uint_31(png_ptr,chunk_length);
  164958. png_reset_crc(png_ptr);
  164959. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164960. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164961. length);
  164962. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164963. if(png_ptr->mode & PNG_AFTER_IDAT)
  164964. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164965. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164966. png_handle_IHDR(png_ptr, info_ptr, length);
  164967. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164968. png_handle_IEND(png_ptr, info_ptr, length);
  164969. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164970. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164971. {
  164972. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164973. png_ptr->mode |= PNG_HAVE_IDAT;
  164974. png_handle_unknown(png_ptr, info_ptr, length);
  164975. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164976. png_ptr->mode |= PNG_HAVE_PLTE;
  164977. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164978. {
  164979. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164980. png_error(png_ptr, "Missing IHDR before IDAT");
  164981. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164982. !(png_ptr->mode & PNG_HAVE_PLTE))
  164983. png_error(png_ptr, "Missing PLTE before IDAT");
  164984. break;
  164985. }
  164986. }
  164987. #endif
  164988. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164989. png_handle_PLTE(png_ptr, info_ptr, length);
  164990. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164991. {
  164992. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164993. png_error(png_ptr, "Missing IHDR before IDAT");
  164994. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164995. !(png_ptr->mode & PNG_HAVE_PLTE))
  164996. png_error(png_ptr, "Missing PLTE before IDAT");
  164997. png_ptr->idat_size = length;
  164998. png_ptr->mode |= PNG_HAVE_IDAT;
  164999. break;
  165000. }
  165001. #if defined(PNG_READ_bKGD_SUPPORTED)
  165002. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165003. png_handle_bKGD(png_ptr, info_ptr, length);
  165004. #endif
  165005. #if defined(PNG_READ_cHRM_SUPPORTED)
  165006. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165007. png_handle_cHRM(png_ptr, info_ptr, length);
  165008. #endif
  165009. #if defined(PNG_READ_gAMA_SUPPORTED)
  165010. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165011. png_handle_gAMA(png_ptr, info_ptr, length);
  165012. #endif
  165013. #if defined(PNG_READ_hIST_SUPPORTED)
  165014. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165015. png_handle_hIST(png_ptr, info_ptr, length);
  165016. #endif
  165017. #if defined(PNG_READ_oFFs_SUPPORTED)
  165018. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165019. png_handle_oFFs(png_ptr, info_ptr, length);
  165020. #endif
  165021. #if defined(PNG_READ_pCAL_SUPPORTED)
  165022. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165023. png_handle_pCAL(png_ptr, info_ptr, length);
  165024. #endif
  165025. #if defined(PNG_READ_sCAL_SUPPORTED)
  165026. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165027. png_handle_sCAL(png_ptr, info_ptr, length);
  165028. #endif
  165029. #if defined(PNG_READ_pHYs_SUPPORTED)
  165030. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165031. png_handle_pHYs(png_ptr, info_ptr, length);
  165032. #endif
  165033. #if defined(PNG_READ_sBIT_SUPPORTED)
  165034. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165035. png_handle_sBIT(png_ptr, info_ptr, length);
  165036. #endif
  165037. #if defined(PNG_READ_sRGB_SUPPORTED)
  165038. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165039. png_handle_sRGB(png_ptr, info_ptr, length);
  165040. #endif
  165041. #if defined(PNG_READ_iCCP_SUPPORTED)
  165042. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165043. png_handle_iCCP(png_ptr, info_ptr, length);
  165044. #endif
  165045. #if defined(PNG_READ_sPLT_SUPPORTED)
  165046. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165047. png_handle_sPLT(png_ptr, info_ptr, length);
  165048. #endif
  165049. #if defined(PNG_READ_tEXt_SUPPORTED)
  165050. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165051. png_handle_tEXt(png_ptr, info_ptr, length);
  165052. #endif
  165053. #if defined(PNG_READ_tIME_SUPPORTED)
  165054. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165055. png_handle_tIME(png_ptr, info_ptr, length);
  165056. #endif
  165057. #if defined(PNG_READ_tRNS_SUPPORTED)
  165058. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165059. png_handle_tRNS(png_ptr, info_ptr, length);
  165060. #endif
  165061. #if defined(PNG_READ_zTXt_SUPPORTED)
  165062. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165063. png_handle_zTXt(png_ptr, info_ptr, length);
  165064. #endif
  165065. #if defined(PNG_READ_iTXt_SUPPORTED)
  165066. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165067. png_handle_iTXt(png_ptr, info_ptr, length);
  165068. #endif
  165069. else
  165070. png_handle_unknown(png_ptr, info_ptr, length);
  165071. }
  165072. }
  165073. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165074. void PNGAPI
  165075. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  165076. {
  165077. png_debug(1, "in png_read_update_info\n");
  165078. if(png_ptr == NULL) return;
  165079. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165080. png_read_start_row(png_ptr);
  165081. else
  165082. png_warning(png_ptr,
  165083. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  165084. png_read_transform_info(png_ptr, info_ptr);
  165085. }
  165086. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165087. void PNGAPI
  165088. png_start_read_image(png_structp png_ptr)
  165089. {
  165090. png_debug(1, "in png_start_read_image\n");
  165091. if(png_ptr == NULL) return;
  165092. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165093. png_read_start_row(png_ptr);
  165094. }
  165095. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165096. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165097. void PNGAPI
  165098. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  165099. {
  165100. #ifdef PNG_USE_LOCAL_ARRAYS
  165101. PNG_CONST PNG_IDAT;
  165102. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  165103. 0xff};
  165104. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  165105. #endif
  165106. int ret;
  165107. if(png_ptr == NULL) return;
  165108. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  165109. png_ptr->row_number, png_ptr->pass);
  165110. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165111. png_read_start_row(png_ptr);
  165112. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  165113. {
  165114. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  165115. if (png_ptr->transformations & PNG_INVERT_MONO)
  165116. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  165117. #endif
  165118. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  165119. if (png_ptr->transformations & PNG_FILLER)
  165120. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  165121. #endif
  165122. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  165123. if (png_ptr->transformations & PNG_PACKSWAP)
  165124. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  165125. #endif
  165126. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  165127. if (png_ptr->transformations & PNG_PACK)
  165128. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  165129. #endif
  165130. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  165131. if (png_ptr->transformations & PNG_SHIFT)
  165132. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  165133. #endif
  165134. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  165135. if (png_ptr->transformations & PNG_BGR)
  165136. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  165137. #endif
  165138. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  165139. if (png_ptr->transformations & PNG_SWAP_BYTES)
  165140. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  165141. #endif
  165142. }
  165143. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165144. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  165145. {
  165146. switch (png_ptr->pass)
  165147. {
  165148. case 0:
  165149. if (png_ptr->row_number & 0x07)
  165150. {
  165151. if (dsp_row != NULL)
  165152. png_combine_row(png_ptr, dsp_row,
  165153. png_pass_dsp_mask[png_ptr->pass]);
  165154. png_read_finish_row(png_ptr);
  165155. return;
  165156. }
  165157. break;
  165158. case 1:
  165159. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  165160. {
  165161. if (dsp_row != NULL)
  165162. png_combine_row(png_ptr, dsp_row,
  165163. png_pass_dsp_mask[png_ptr->pass]);
  165164. png_read_finish_row(png_ptr);
  165165. return;
  165166. }
  165167. break;
  165168. case 2:
  165169. if ((png_ptr->row_number & 0x07) != 4)
  165170. {
  165171. if (dsp_row != NULL && (png_ptr->row_number & 4))
  165172. png_combine_row(png_ptr, dsp_row,
  165173. png_pass_dsp_mask[png_ptr->pass]);
  165174. png_read_finish_row(png_ptr);
  165175. return;
  165176. }
  165177. break;
  165178. case 3:
  165179. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  165180. {
  165181. if (dsp_row != NULL)
  165182. png_combine_row(png_ptr, dsp_row,
  165183. png_pass_dsp_mask[png_ptr->pass]);
  165184. png_read_finish_row(png_ptr);
  165185. return;
  165186. }
  165187. break;
  165188. case 4:
  165189. if ((png_ptr->row_number & 3) != 2)
  165190. {
  165191. if (dsp_row != NULL && (png_ptr->row_number & 2))
  165192. png_combine_row(png_ptr, dsp_row,
  165193. png_pass_dsp_mask[png_ptr->pass]);
  165194. png_read_finish_row(png_ptr);
  165195. return;
  165196. }
  165197. break;
  165198. case 5:
  165199. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  165200. {
  165201. if (dsp_row != NULL)
  165202. png_combine_row(png_ptr, dsp_row,
  165203. png_pass_dsp_mask[png_ptr->pass]);
  165204. png_read_finish_row(png_ptr);
  165205. return;
  165206. }
  165207. break;
  165208. case 6:
  165209. if (!(png_ptr->row_number & 1))
  165210. {
  165211. png_read_finish_row(png_ptr);
  165212. return;
  165213. }
  165214. break;
  165215. }
  165216. }
  165217. #endif
  165218. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  165219. png_error(png_ptr, "Invalid attempt to read row data");
  165220. png_ptr->zstream.next_out = png_ptr->row_buf;
  165221. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165222. do
  165223. {
  165224. if (!(png_ptr->zstream.avail_in))
  165225. {
  165226. while (!png_ptr->idat_size)
  165227. {
  165228. png_byte chunk_length[4];
  165229. png_crc_finish(png_ptr, 0);
  165230. png_read_data(png_ptr, chunk_length, 4);
  165231. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  165232. png_reset_crc(png_ptr);
  165233. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165234. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165235. png_error(png_ptr, "Not enough image data");
  165236. }
  165237. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  165238. png_ptr->zstream.next_in = png_ptr->zbuf;
  165239. if (png_ptr->zbuf_size > png_ptr->idat_size)
  165240. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  165241. png_crc_read(png_ptr, png_ptr->zbuf,
  165242. (png_size_t)png_ptr->zstream.avail_in);
  165243. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  165244. }
  165245. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  165246. if (ret == Z_STREAM_END)
  165247. {
  165248. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  165249. png_ptr->idat_size)
  165250. png_error(png_ptr, "Extra compressed data");
  165251. png_ptr->mode |= PNG_AFTER_IDAT;
  165252. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165253. break;
  165254. }
  165255. if (ret != Z_OK)
  165256. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  165257. "Decompression error");
  165258. } while (png_ptr->zstream.avail_out);
  165259. png_ptr->row_info.color_type = png_ptr->color_type;
  165260. png_ptr->row_info.width = png_ptr->iwidth;
  165261. png_ptr->row_info.channels = png_ptr->channels;
  165262. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165263. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165264. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165265. png_ptr->row_info.width);
  165266. if(png_ptr->row_buf[0])
  165267. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165268. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165269. (int)(png_ptr->row_buf[0]));
  165270. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165271. png_ptr->rowbytes + 1);
  165272. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  165273. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  165274. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  165275. {
  165276. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  165277. }
  165278. #endif
  165279. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165280. png_do_read_transformations(png_ptr);
  165281. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165282. if (png_ptr->interlaced &&
  165283. (png_ptr->transformations & PNG_INTERLACE))
  165284. {
  165285. if (png_ptr->pass < 6)
  165286. png_do_read_interlace(png_ptr);
  165287. if (dsp_row != NULL)
  165288. png_combine_row(png_ptr, dsp_row,
  165289. png_pass_dsp_mask[png_ptr->pass]);
  165290. if (row != NULL)
  165291. png_combine_row(png_ptr, row,
  165292. png_pass_mask[png_ptr->pass]);
  165293. }
  165294. else
  165295. #endif
  165296. {
  165297. if (row != NULL)
  165298. png_combine_row(png_ptr, row, 0xff);
  165299. if (dsp_row != NULL)
  165300. png_combine_row(png_ptr, dsp_row, 0xff);
  165301. }
  165302. png_read_finish_row(png_ptr);
  165303. if (png_ptr->read_row_fn != NULL)
  165304. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165305. }
  165306. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165307. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165308. void PNGAPI
  165309. png_read_rows(png_structp png_ptr, png_bytepp row,
  165310. png_bytepp display_row, png_uint_32 num_rows)
  165311. {
  165312. png_uint_32 i;
  165313. png_bytepp rp;
  165314. png_bytepp dp;
  165315. png_debug(1, "in png_read_rows\n");
  165316. if(png_ptr == NULL) return;
  165317. rp = row;
  165318. dp = display_row;
  165319. if (rp != NULL && dp != NULL)
  165320. for (i = 0; i < num_rows; i++)
  165321. {
  165322. png_bytep rptr = *rp++;
  165323. png_bytep dptr = *dp++;
  165324. png_read_row(png_ptr, rptr, dptr);
  165325. }
  165326. else if(rp != NULL)
  165327. for (i = 0; i < num_rows; i++)
  165328. {
  165329. png_bytep rptr = *rp;
  165330. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165331. rp++;
  165332. }
  165333. else if(dp != NULL)
  165334. for (i = 0; i < num_rows; i++)
  165335. {
  165336. png_bytep dptr = *dp;
  165337. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165338. dp++;
  165339. }
  165340. }
  165341. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165342. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165343. void PNGAPI
  165344. png_read_image(png_structp png_ptr, png_bytepp image)
  165345. {
  165346. png_uint_32 i,image_height;
  165347. int pass, j;
  165348. png_bytepp rp;
  165349. png_debug(1, "in png_read_image\n");
  165350. if(png_ptr == NULL) return;
  165351. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165352. pass = png_set_interlace_handling(png_ptr);
  165353. #else
  165354. if (png_ptr->interlaced)
  165355. png_error(png_ptr,
  165356. "Cannot read interlaced image -- interlace handler disabled.");
  165357. pass = 1;
  165358. #endif
  165359. image_height=png_ptr->height;
  165360. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165361. for (j = 0; j < pass; j++)
  165362. {
  165363. rp = image;
  165364. for (i = 0; i < image_height; i++)
  165365. {
  165366. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165367. rp++;
  165368. }
  165369. }
  165370. }
  165371. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165372. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165373. void PNGAPI
  165374. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165375. {
  165376. png_byte chunk_length[4];
  165377. png_uint_32 length;
  165378. png_debug(1, "in png_read_end\n");
  165379. if(png_ptr == NULL) return;
  165380. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165381. do
  165382. {
  165383. #ifdef PNG_USE_LOCAL_ARRAYS
  165384. PNG_CONST PNG_IHDR;
  165385. PNG_CONST PNG_IDAT;
  165386. PNG_CONST PNG_IEND;
  165387. PNG_CONST PNG_PLTE;
  165388. #if defined(PNG_READ_bKGD_SUPPORTED)
  165389. PNG_CONST PNG_bKGD;
  165390. #endif
  165391. #if defined(PNG_READ_cHRM_SUPPORTED)
  165392. PNG_CONST PNG_cHRM;
  165393. #endif
  165394. #if defined(PNG_READ_gAMA_SUPPORTED)
  165395. PNG_CONST PNG_gAMA;
  165396. #endif
  165397. #if defined(PNG_READ_hIST_SUPPORTED)
  165398. PNG_CONST PNG_hIST;
  165399. #endif
  165400. #if defined(PNG_READ_iCCP_SUPPORTED)
  165401. PNG_CONST PNG_iCCP;
  165402. #endif
  165403. #if defined(PNG_READ_iTXt_SUPPORTED)
  165404. PNG_CONST PNG_iTXt;
  165405. #endif
  165406. #if defined(PNG_READ_oFFs_SUPPORTED)
  165407. PNG_CONST PNG_oFFs;
  165408. #endif
  165409. #if defined(PNG_READ_pCAL_SUPPORTED)
  165410. PNG_CONST PNG_pCAL;
  165411. #endif
  165412. #if defined(PNG_READ_pHYs_SUPPORTED)
  165413. PNG_CONST PNG_pHYs;
  165414. #endif
  165415. #if defined(PNG_READ_sBIT_SUPPORTED)
  165416. PNG_CONST PNG_sBIT;
  165417. #endif
  165418. #if defined(PNG_READ_sCAL_SUPPORTED)
  165419. PNG_CONST PNG_sCAL;
  165420. #endif
  165421. #if defined(PNG_READ_sPLT_SUPPORTED)
  165422. PNG_CONST PNG_sPLT;
  165423. #endif
  165424. #if defined(PNG_READ_sRGB_SUPPORTED)
  165425. PNG_CONST PNG_sRGB;
  165426. #endif
  165427. #if defined(PNG_READ_tEXt_SUPPORTED)
  165428. PNG_CONST PNG_tEXt;
  165429. #endif
  165430. #if defined(PNG_READ_tIME_SUPPORTED)
  165431. PNG_CONST PNG_tIME;
  165432. #endif
  165433. #if defined(PNG_READ_tRNS_SUPPORTED)
  165434. PNG_CONST PNG_tRNS;
  165435. #endif
  165436. #if defined(PNG_READ_zTXt_SUPPORTED)
  165437. PNG_CONST PNG_zTXt;
  165438. #endif
  165439. #endif /* PNG_USE_LOCAL_ARRAYS */
  165440. png_read_data(png_ptr, chunk_length, 4);
  165441. length = png_get_uint_31(png_ptr,chunk_length);
  165442. png_reset_crc(png_ptr);
  165443. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165444. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165445. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165446. png_handle_IHDR(png_ptr, info_ptr, length);
  165447. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165448. png_handle_IEND(png_ptr, info_ptr, length);
  165449. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165450. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165451. {
  165452. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165453. {
  165454. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165455. png_error(png_ptr, "Too many IDAT's found");
  165456. }
  165457. png_handle_unknown(png_ptr, info_ptr, length);
  165458. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165459. png_ptr->mode |= PNG_HAVE_PLTE;
  165460. }
  165461. #endif
  165462. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165463. {
  165464. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165465. png_error(png_ptr, "Too many IDAT's found");
  165466. png_crc_finish(png_ptr, length);
  165467. }
  165468. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165469. png_handle_PLTE(png_ptr, info_ptr, length);
  165470. #if defined(PNG_READ_bKGD_SUPPORTED)
  165471. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165472. png_handle_bKGD(png_ptr, info_ptr, length);
  165473. #endif
  165474. #if defined(PNG_READ_cHRM_SUPPORTED)
  165475. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165476. png_handle_cHRM(png_ptr, info_ptr, length);
  165477. #endif
  165478. #if defined(PNG_READ_gAMA_SUPPORTED)
  165479. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165480. png_handle_gAMA(png_ptr, info_ptr, length);
  165481. #endif
  165482. #if defined(PNG_READ_hIST_SUPPORTED)
  165483. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165484. png_handle_hIST(png_ptr, info_ptr, length);
  165485. #endif
  165486. #if defined(PNG_READ_oFFs_SUPPORTED)
  165487. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165488. png_handle_oFFs(png_ptr, info_ptr, length);
  165489. #endif
  165490. #if defined(PNG_READ_pCAL_SUPPORTED)
  165491. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165492. png_handle_pCAL(png_ptr, info_ptr, length);
  165493. #endif
  165494. #if defined(PNG_READ_sCAL_SUPPORTED)
  165495. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165496. png_handle_sCAL(png_ptr, info_ptr, length);
  165497. #endif
  165498. #if defined(PNG_READ_pHYs_SUPPORTED)
  165499. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165500. png_handle_pHYs(png_ptr, info_ptr, length);
  165501. #endif
  165502. #if defined(PNG_READ_sBIT_SUPPORTED)
  165503. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165504. png_handle_sBIT(png_ptr, info_ptr, length);
  165505. #endif
  165506. #if defined(PNG_READ_sRGB_SUPPORTED)
  165507. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165508. png_handle_sRGB(png_ptr, info_ptr, length);
  165509. #endif
  165510. #if defined(PNG_READ_iCCP_SUPPORTED)
  165511. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165512. png_handle_iCCP(png_ptr, info_ptr, length);
  165513. #endif
  165514. #if defined(PNG_READ_sPLT_SUPPORTED)
  165515. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165516. png_handle_sPLT(png_ptr, info_ptr, length);
  165517. #endif
  165518. #if defined(PNG_READ_tEXt_SUPPORTED)
  165519. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165520. png_handle_tEXt(png_ptr, info_ptr, length);
  165521. #endif
  165522. #if defined(PNG_READ_tIME_SUPPORTED)
  165523. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165524. png_handle_tIME(png_ptr, info_ptr, length);
  165525. #endif
  165526. #if defined(PNG_READ_tRNS_SUPPORTED)
  165527. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165528. png_handle_tRNS(png_ptr, info_ptr, length);
  165529. #endif
  165530. #if defined(PNG_READ_zTXt_SUPPORTED)
  165531. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165532. png_handle_zTXt(png_ptr, info_ptr, length);
  165533. #endif
  165534. #if defined(PNG_READ_iTXt_SUPPORTED)
  165535. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165536. png_handle_iTXt(png_ptr, info_ptr, length);
  165537. #endif
  165538. else
  165539. png_handle_unknown(png_ptr, info_ptr, length);
  165540. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165541. }
  165542. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165543. void PNGAPI
  165544. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165545. png_infopp end_info_ptr_ptr)
  165546. {
  165547. png_structp png_ptr = NULL;
  165548. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165549. #ifdef PNG_USER_MEM_SUPPORTED
  165550. png_free_ptr free_fn;
  165551. png_voidp mem_ptr;
  165552. #endif
  165553. png_debug(1, "in png_destroy_read_struct\n");
  165554. if (png_ptr_ptr != NULL)
  165555. png_ptr = *png_ptr_ptr;
  165556. if (info_ptr_ptr != NULL)
  165557. info_ptr = *info_ptr_ptr;
  165558. if (end_info_ptr_ptr != NULL)
  165559. end_info_ptr = *end_info_ptr_ptr;
  165560. #ifdef PNG_USER_MEM_SUPPORTED
  165561. free_fn = png_ptr->free_fn;
  165562. mem_ptr = png_ptr->mem_ptr;
  165563. #endif
  165564. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165565. if (info_ptr != NULL)
  165566. {
  165567. #if defined(PNG_TEXT_SUPPORTED)
  165568. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165569. #endif
  165570. #ifdef PNG_USER_MEM_SUPPORTED
  165571. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165572. (png_voidp)mem_ptr);
  165573. #else
  165574. png_destroy_struct((png_voidp)info_ptr);
  165575. #endif
  165576. *info_ptr_ptr = NULL;
  165577. }
  165578. if (end_info_ptr != NULL)
  165579. {
  165580. #if defined(PNG_READ_TEXT_SUPPORTED)
  165581. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165582. #endif
  165583. #ifdef PNG_USER_MEM_SUPPORTED
  165584. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165585. (png_voidp)mem_ptr);
  165586. #else
  165587. png_destroy_struct((png_voidp)end_info_ptr);
  165588. #endif
  165589. *end_info_ptr_ptr = NULL;
  165590. }
  165591. if (png_ptr != NULL)
  165592. {
  165593. #ifdef PNG_USER_MEM_SUPPORTED
  165594. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165595. (png_voidp)mem_ptr);
  165596. #else
  165597. png_destroy_struct((png_voidp)png_ptr);
  165598. #endif
  165599. *png_ptr_ptr = NULL;
  165600. }
  165601. }
  165602. void /* PRIVATE */
  165603. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165604. {
  165605. #ifdef PNG_SETJMP_SUPPORTED
  165606. jmp_buf tmp_jmp;
  165607. #endif
  165608. png_error_ptr error_fn;
  165609. png_error_ptr warning_fn;
  165610. png_voidp error_ptr;
  165611. #ifdef PNG_USER_MEM_SUPPORTED
  165612. png_free_ptr free_fn;
  165613. #endif
  165614. png_debug(1, "in png_read_destroy\n");
  165615. if (info_ptr != NULL)
  165616. png_info_destroy(png_ptr, info_ptr);
  165617. if (end_info_ptr != NULL)
  165618. png_info_destroy(png_ptr, end_info_ptr);
  165619. png_free(png_ptr, png_ptr->zbuf);
  165620. png_free(png_ptr, png_ptr->big_row_buf);
  165621. png_free(png_ptr, png_ptr->prev_row);
  165622. #if defined(PNG_READ_DITHER_SUPPORTED)
  165623. png_free(png_ptr, png_ptr->palette_lookup);
  165624. png_free(png_ptr, png_ptr->dither_index);
  165625. #endif
  165626. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165627. png_free(png_ptr, png_ptr->gamma_table);
  165628. #endif
  165629. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165630. png_free(png_ptr, png_ptr->gamma_from_1);
  165631. png_free(png_ptr, png_ptr->gamma_to_1);
  165632. #endif
  165633. #ifdef PNG_FREE_ME_SUPPORTED
  165634. if (png_ptr->free_me & PNG_FREE_PLTE)
  165635. png_zfree(png_ptr, png_ptr->palette);
  165636. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165637. #else
  165638. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165639. png_zfree(png_ptr, png_ptr->palette);
  165640. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165641. #endif
  165642. #if defined(PNG_tRNS_SUPPORTED) || \
  165643. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165644. #ifdef PNG_FREE_ME_SUPPORTED
  165645. if (png_ptr->free_me & PNG_FREE_TRNS)
  165646. png_free(png_ptr, png_ptr->trans);
  165647. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165648. #else
  165649. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165650. png_free(png_ptr, png_ptr->trans);
  165651. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165652. #endif
  165653. #endif
  165654. #if defined(PNG_READ_hIST_SUPPORTED)
  165655. #ifdef PNG_FREE_ME_SUPPORTED
  165656. if (png_ptr->free_me & PNG_FREE_HIST)
  165657. png_free(png_ptr, png_ptr->hist);
  165658. png_ptr->free_me &= ~PNG_FREE_HIST;
  165659. #else
  165660. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165661. png_free(png_ptr, png_ptr->hist);
  165662. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165663. #endif
  165664. #endif
  165665. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165666. if (png_ptr->gamma_16_table != NULL)
  165667. {
  165668. int i;
  165669. int istop = (1 << (8 - png_ptr->gamma_shift));
  165670. for (i = 0; i < istop; i++)
  165671. {
  165672. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165673. }
  165674. png_free(png_ptr, png_ptr->gamma_16_table);
  165675. }
  165676. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165677. if (png_ptr->gamma_16_from_1 != NULL)
  165678. {
  165679. int i;
  165680. int istop = (1 << (8 - png_ptr->gamma_shift));
  165681. for (i = 0; i < istop; i++)
  165682. {
  165683. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165684. }
  165685. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165686. }
  165687. if (png_ptr->gamma_16_to_1 != NULL)
  165688. {
  165689. int i;
  165690. int istop = (1 << (8 - png_ptr->gamma_shift));
  165691. for (i = 0; i < istop; i++)
  165692. {
  165693. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165694. }
  165695. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165696. }
  165697. #endif
  165698. #endif
  165699. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165700. png_free(png_ptr, png_ptr->time_buffer);
  165701. #endif
  165702. inflateEnd(&png_ptr->zstream);
  165703. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165704. png_free(png_ptr, png_ptr->save_buffer);
  165705. #endif
  165706. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165707. #ifdef PNG_TEXT_SUPPORTED
  165708. png_free(png_ptr, png_ptr->current_text);
  165709. #endif /* PNG_TEXT_SUPPORTED */
  165710. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165711. #ifdef PNG_SETJMP_SUPPORTED
  165712. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165713. #endif
  165714. error_fn = png_ptr->error_fn;
  165715. warning_fn = png_ptr->warning_fn;
  165716. error_ptr = png_ptr->error_ptr;
  165717. #ifdef PNG_USER_MEM_SUPPORTED
  165718. free_fn = png_ptr->free_fn;
  165719. #endif
  165720. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165721. png_ptr->error_fn = error_fn;
  165722. png_ptr->warning_fn = warning_fn;
  165723. png_ptr->error_ptr = error_ptr;
  165724. #ifdef PNG_USER_MEM_SUPPORTED
  165725. png_ptr->free_fn = free_fn;
  165726. #endif
  165727. #ifdef PNG_SETJMP_SUPPORTED
  165728. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165729. #endif
  165730. }
  165731. void PNGAPI
  165732. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165733. {
  165734. if(png_ptr == NULL) return;
  165735. png_ptr->read_row_fn = read_row_fn;
  165736. }
  165737. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165738. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165739. void PNGAPI
  165740. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165741. int transforms,
  165742. voidp params)
  165743. {
  165744. int row;
  165745. if(png_ptr == NULL) return;
  165746. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165747. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165748. png_set_invert_alpha(png_ptr);
  165749. #endif
  165750. png_read_info(png_ptr, info_ptr);
  165751. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165752. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165753. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165754. if (transforms & PNG_TRANSFORM_STRIP_16)
  165755. png_set_strip_16(png_ptr);
  165756. #endif
  165757. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165758. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165759. png_set_strip_alpha(png_ptr);
  165760. #endif
  165761. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165762. if (transforms & PNG_TRANSFORM_PACKING)
  165763. png_set_packing(png_ptr);
  165764. #endif
  165765. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165766. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165767. png_set_packswap(png_ptr);
  165768. #endif
  165769. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165770. if (transforms & PNG_TRANSFORM_EXPAND)
  165771. if ((png_ptr->bit_depth < 8) ||
  165772. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165773. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165774. png_set_expand(png_ptr);
  165775. #endif
  165776. #if defined(PNG_READ_INVERT_SUPPORTED)
  165777. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165778. png_set_invert_mono(png_ptr);
  165779. #endif
  165780. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165781. if ((transforms & PNG_TRANSFORM_SHIFT)
  165782. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165783. {
  165784. png_color_8p sig_bit;
  165785. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165786. png_set_shift(png_ptr, sig_bit);
  165787. }
  165788. #endif
  165789. #if defined(PNG_READ_BGR_SUPPORTED)
  165790. if (transforms & PNG_TRANSFORM_BGR)
  165791. png_set_bgr(png_ptr);
  165792. #endif
  165793. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165794. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165795. png_set_swap_alpha(png_ptr);
  165796. #endif
  165797. #if defined(PNG_READ_SWAP_SUPPORTED)
  165798. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165799. png_set_swap(png_ptr);
  165800. #endif
  165801. png_read_update_info(png_ptr, info_ptr);
  165802. #ifdef PNG_FREE_ME_SUPPORTED
  165803. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165804. #endif
  165805. if(info_ptr->row_pointers == NULL)
  165806. {
  165807. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165808. info_ptr->height * png_sizeof(png_bytep));
  165809. #ifdef PNG_FREE_ME_SUPPORTED
  165810. info_ptr->free_me |= PNG_FREE_ROWS;
  165811. #endif
  165812. for (row = 0; row < (int)info_ptr->height; row++)
  165813. {
  165814. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165815. png_get_rowbytes(png_ptr, info_ptr));
  165816. }
  165817. }
  165818. png_read_image(png_ptr, info_ptr->row_pointers);
  165819. info_ptr->valid |= PNG_INFO_IDAT;
  165820. png_read_end(png_ptr, info_ptr);
  165821. transforms = transforms; /* quiet compiler warnings */
  165822. params = params;
  165823. }
  165824. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165825. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165826. #endif /* PNG_READ_SUPPORTED */
  165827. /*** End of inlined file: pngread.c ***/
  165828. /*** Start of inlined file: pngpread.c ***/
  165829. #define PNG_INTERNAL
  165830. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165831. #define PNG_READ_SIG_MODE 0
  165832. #define PNG_READ_CHUNK_MODE 1
  165833. #define PNG_READ_IDAT_MODE 2
  165834. #define PNG_SKIP_MODE 3
  165835. #define PNG_READ_tEXt_MODE 4
  165836. #define PNG_READ_zTXt_MODE 5
  165837. #define PNG_READ_DONE_MODE 6
  165838. #define PNG_READ_iTXt_MODE 7
  165839. #define PNG_ERROR_MODE 8
  165840. void PNGAPI
  165841. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165842. png_bytep buffer, png_size_t buffer_size)
  165843. {
  165844. if(png_ptr == NULL) return;
  165845. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165846. while (png_ptr->buffer_size)
  165847. {
  165848. png_process_some_data(png_ptr, info_ptr);
  165849. }
  165850. }
  165851. void /* PRIVATE */
  165852. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165853. {
  165854. if(png_ptr == NULL) return;
  165855. switch (png_ptr->process_mode)
  165856. {
  165857. case PNG_READ_SIG_MODE:
  165858. {
  165859. png_push_read_sig(png_ptr, info_ptr);
  165860. break;
  165861. }
  165862. case PNG_READ_CHUNK_MODE:
  165863. {
  165864. png_push_read_chunk(png_ptr, info_ptr);
  165865. break;
  165866. }
  165867. case PNG_READ_IDAT_MODE:
  165868. {
  165869. png_push_read_IDAT(png_ptr);
  165870. break;
  165871. }
  165872. #if defined(PNG_READ_tEXt_SUPPORTED)
  165873. case PNG_READ_tEXt_MODE:
  165874. {
  165875. png_push_read_tEXt(png_ptr, info_ptr);
  165876. break;
  165877. }
  165878. #endif
  165879. #if defined(PNG_READ_zTXt_SUPPORTED)
  165880. case PNG_READ_zTXt_MODE:
  165881. {
  165882. png_push_read_zTXt(png_ptr, info_ptr);
  165883. break;
  165884. }
  165885. #endif
  165886. #if defined(PNG_READ_iTXt_SUPPORTED)
  165887. case PNG_READ_iTXt_MODE:
  165888. {
  165889. png_push_read_iTXt(png_ptr, info_ptr);
  165890. break;
  165891. }
  165892. #endif
  165893. case PNG_SKIP_MODE:
  165894. {
  165895. png_push_crc_finish(png_ptr);
  165896. break;
  165897. }
  165898. default:
  165899. {
  165900. png_ptr->buffer_size = 0;
  165901. break;
  165902. }
  165903. }
  165904. }
  165905. void /* PRIVATE */
  165906. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165907. {
  165908. png_size_t num_checked = png_ptr->sig_bytes,
  165909. num_to_check = 8 - num_checked;
  165910. if (png_ptr->buffer_size < num_to_check)
  165911. {
  165912. num_to_check = png_ptr->buffer_size;
  165913. }
  165914. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165915. num_to_check);
  165916. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165917. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165918. {
  165919. if (num_checked < 4 &&
  165920. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165921. png_error(png_ptr, "Not a PNG file");
  165922. else
  165923. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165924. }
  165925. else
  165926. {
  165927. if (png_ptr->sig_bytes >= 8)
  165928. {
  165929. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165930. }
  165931. }
  165932. }
  165933. void /* PRIVATE */
  165934. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165935. {
  165936. #ifdef PNG_USE_LOCAL_ARRAYS
  165937. PNG_CONST PNG_IHDR;
  165938. PNG_CONST PNG_IDAT;
  165939. PNG_CONST PNG_IEND;
  165940. PNG_CONST PNG_PLTE;
  165941. #if defined(PNG_READ_bKGD_SUPPORTED)
  165942. PNG_CONST PNG_bKGD;
  165943. #endif
  165944. #if defined(PNG_READ_cHRM_SUPPORTED)
  165945. PNG_CONST PNG_cHRM;
  165946. #endif
  165947. #if defined(PNG_READ_gAMA_SUPPORTED)
  165948. PNG_CONST PNG_gAMA;
  165949. #endif
  165950. #if defined(PNG_READ_hIST_SUPPORTED)
  165951. PNG_CONST PNG_hIST;
  165952. #endif
  165953. #if defined(PNG_READ_iCCP_SUPPORTED)
  165954. PNG_CONST PNG_iCCP;
  165955. #endif
  165956. #if defined(PNG_READ_iTXt_SUPPORTED)
  165957. PNG_CONST PNG_iTXt;
  165958. #endif
  165959. #if defined(PNG_READ_oFFs_SUPPORTED)
  165960. PNG_CONST PNG_oFFs;
  165961. #endif
  165962. #if defined(PNG_READ_pCAL_SUPPORTED)
  165963. PNG_CONST PNG_pCAL;
  165964. #endif
  165965. #if defined(PNG_READ_pHYs_SUPPORTED)
  165966. PNG_CONST PNG_pHYs;
  165967. #endif
  165968. #if defined(PNG_READ_sBIT_SUPPORTED)
  165969. PNG_CONST PNG_sBIT;
  165970. #endif
  165971. #if defined(PNG_READ_sCAL_SUPPORTED)
  165972. PNG_CONST PNG_sCAL;
  165973. #endif
  165974. #if defined(PNG_READ_sRGB_SUPPORTED)
  165975. PNG_CONST PNG_sRGB;
  165976. #endif
  165977. #if defined(PNG_READ_sPLT_SUPPORTED)
  165978. PNG_CONST PNG_sPLT;
  165979. #endif
  165980. #if defined(PNG_READ_tEXt_SUPPORTED)
  165981. PNG_CONST PNG_tEXt;
  165982. #endif
  165983. #if defined(PNG_READ_tIME_SUPPORTED)
  165984. PNG_CONST PNG_tIME;
  165985. #endif
  165986. #if defined(PNG_READ_tRNS_SUPPORTED)
  165987. PNG_CONST PNG_tRNS;
  165988. #endif
  165989. #if defined(PNG_READ_zTXt_SUPPORTED)
  165990. PNG_CONST PNG_zTXt;
  165991. #endif
  165992. #endif /* PNG_USE_LOCAL_ARRAYS */
  165993. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165994. {
  165995. png_byte chunk_length[4];
  165996. if (png_ptr->buffer_size < 8)
  165997. {
  165998. png_push_save_buffer(png_ptr);
  165999. return;
  166000. }
  166001. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166002. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166003. png_reset_crc(png_ptr);
  166004. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166005. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166006. }
  166007. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166008. if(png_ptr->mode & PNG_AFTER_IDAT)
  166009. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  166010. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  166011. {
  166012. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166013. {
  166014. png_push_save_buffer(png_ptr);
  166015. return;
  166016. }
  166017. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  166018. }
  166019. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 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_IEND(png_ptr, info_ptr, png_ptr->push_length);
  166027. png_ptr->process_mode = PNG_READ_DONE_MODE;
  166028. png_push_have_end(png_ptr, info_ptr);
  166029. }
  166030. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  166031. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  166032. {
  166033. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166034. {
  166035. png_push_save_buffer(png_ptr);
  166036. return;
  166037. }
  166038. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166039. png_ptr->mode |= PNG_HAVE_IDAT;
  166040. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166041. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166042. png_ptr->mode |= PNG_HAVE_PLTE;
  166043. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166044. {
  166045. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166046. png_error(png_ptr, "Missing IHDR before IDAT");
  166047. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166048. !(png_ptr->mode & PNG_HAVE_PLTE))
  166049. png_error(png_ptr, "Missing PLTE before IDAT");
  166050. }
  166051. }
  166052. #endif
  166053. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166054. {
  166055. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166056. {
  166057. png_push_save_buffer(png_ptr);
  166058. return;
  166059. }
  166060. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  166061. }
  166062. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166063. {
  166064. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166065. png_error(png_ptr, "Missing IHDR before IDAT");
  166066. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166067. !(png_ptr->mode & PNG_HAVE_PLTE))
  166068. png_error(png_ptr, "Missing PLTE before IDAT");
  166069. if (png_ptr->mode & PNG_HAVE_IDAT)
  166070. {
  166071. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  166072. if (png_ptr->push_length == 0)
  166073. return;
  166074. if (png_ptr->mode & PNG_AFTER_IDAT)
  166075. png_error(png_ptr, "Too many IDAT's found");
  166076. }
  166077. png_ptr->idat_size = png_ptr->push_length;
  166078. png_ptr->mode |= PNG_HAVE_IDAT;
  166079. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  166080. png_push_have_info(png_ptr, info_ptr);
  166081. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166082. png_ptr->zstream.next_out = png_ptr->row_buf;
  166083. return;
  166084. }
  166085. #if defined(PNG_READ_gAMA_SUPPORTED)
  166086. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  166087. {
  166088. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166089. {
  166090. png_push_save_buffer(png_ptr);
  166091. return;
  166092. }
  166093. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  166094. }
  166095. #endif
  166096. #if defined(PNG_READ_sBIT_SUPPORTED)
  166097. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  166098. {
  166099. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166100. {
  166101. png_push_save_buffer(png_ptr);
  166102. return;
  166103. }
  166104. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  166105. }
  166106. #endif
  166107. #if defined(PNG_READ_cHRM_SUPPORTED)
  166108. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  166109. {
  166110. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166111. {
  166112. png_push_save_buffer(png_ptr);
  166113. return;
  166114. }
  166115. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  166116. }
  166117. #endif
  166118. #if defined(PNG_READ_sRGB_SUPPORTED)
  166119. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  166120. {
  166121. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166122. {
  166123. png_push_save_buffer(png_ptr);
  166124. return;
  166125. }
  166126. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  166127. }
  166128. #endif
  166129. #if defined(PNG_READ_iCCP_SUPPORTED)
  166130. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  166131. {
  166132. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166133. {
  166134. png_push_save_buffer(png_ptr);
  166135. return;
  166136. }
  166137. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  166138. }
  166139. #endif
  166140. #if defined(PNG_READ_sPLT_SUPPORTED)
  166141. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  166142. {
  166143. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166144. {
  166145. png_push_save_buffer(png_ptr);
  166146. return;
  166147. }
  166148. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  166149. }
  166150. #endif
  166151. #if defined(PNG_READ_tRNS_SUPPORTED)
  166152. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  166153. {
  166154. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166155. {
  166156. png_push_save_buffer(png_ptr);
  166157. return;
  166158. }
  166159. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  166160. }
  166161. #endif
  166162. #if defined(PNG_READ_bKGD_SUPPORTED)
  166163. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  166164. {
  166165. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166166. {
  166167. png_push_save_buffer(png_ptr);
  166168. return;
  166169. }
  166170. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  166171. }
  166172. #endif
  166173. #if defined(PNG_READ_hIST_SUPPORTED)
  166174. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  166175. {
  166176. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166177. {
  166178. png_push_save_buffer(png_ptr);
  166179. return;
  166180. }
  166181. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  166182. }
  166183. #endif
  166184. #if defined(PNG_READ_pHYs_SUPPORTED)
  166185. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  166186. {
  166187. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166188. {
  166189. png_push_save_buffer(png_ptr);
  166190. return;
  166191. }
  166192. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  166193. }
  166194. #endif
  166195. #if defined(PNG_READ_oFFs_SUPPORTED)
  166196. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  166197. {
  166198. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166199. {
  166200. png_push_save_buffer(png_ptr);
  166201. return;
  166202. }
  166203. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  166204. }
  166205. #endif
  166206. #if defined(PNG_READ_pCAL_SUPPORTED)
  166207. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  166208. {
  166209. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166210. {
  166211. png_push_save_buffer(png_ptr);
  166212. return;
  166213. }
  166214. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  166215. }
  166216. #endif
  166217. #if defined(PNG_READ_sCAL_SUPPORTED)
  166218. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  166219. {
  166220. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166221. {
  166222. png_push_save_buffer(png_ptr);
  166223. return;
  166224. }
  166225. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  166226. }
  166227. #endif
  166228. #if defined(PNG_READ_tIME_SUPPORTED)
  166229. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  166230. {
  166231. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166232. {
  166233. png_push_save_buffer(png_ptr);
  166234. return;
  166235. }
  166236. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  166237. }
  166238. #endif
  166239. #if defined(PNG_READ_tEXt_SUPPORTED)
  166240. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  166241. {
  166242. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166243. {
  166244. png_push_save_buffer(png_ptr);
  166245. return;
  166246. }
  166247. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  166248. }
  166249. #endif
  166250. #if defined(PNG_READ_zTXt_SUPPORTED)
  166251. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  166252. {
  166253. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166254. {
  166255. png_push_save_buffer(png_ptr);
  166256. return;
  166257. }
  166258. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  166259. }
  166260. #endif
  166261. #if defined(PNG_READ_iTXt_SUPPORTED)
  166262. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  166263. {
  166264. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166265. {
  166266. png_push_save_buffer(png_ptr);
  166267. return;
  166268. }
  166269. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  166270. }
  166271. #endif
  166272. else
  166273. {
  166274. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166275. {
  166276. png_push_save_buffer(png_ptr);
  166277. return;
  166278. }
  166279. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166280. }
  166281. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166282. }
  166283. void /* PRIVATE */
  166284. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  166285. {
  166286. png_ptr->process_mode = PNG_SKIP_MODE;
  166287. png_ptr->skip_length = skip;
  166288. }
  166289. void /* PRIVATE */
  166290. png_push_crc_finish(png_structp png_ptr)
  166291. {
  166292. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166293. {
  166294. png_size_t save_size;
  166295. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166296. save_size = (png_size_t)png_ptr->skip_length;
  166297. else
  166298. save_size = png_ptr->save_buffer_size;
  166299. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166300. png_ptr->skip_length -= save_size;
  166301. png_ptr->buffer_size -= save_size;
  166302. png_ptr->save_buffer_size -= save_size;
  166303. png_ptr->save_buffer_ptr += save_size;
  166304. }
  166305. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166306. {
  166307. png_size_t save_size;
  166308. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166309. save_size = (png_size_t)png_ptr->skip_length;
  166310. else
  166311. save_size = png_ptr->current_buffer_size;
  166312. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166313. png_ptr->skip_length -= save_size;
  166314. png_ptr->buffer_size -= save_size;
  166315. png_ptr->current_buffer_size -= save_size;
  166316. png_ptr->current_buffer_ptr += save_size;
  166317. }
  166318. if (!png_ptr->skip_length)
  166319. {
  166320. if (png_ptr->buffer_size < 4)
  166321. {
  166322. png_push_save_buffer(png_ptr);
  166323. return;
  166324. }
  166325. png_crc_finish(png_ptr, 0);
  166326. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166327. }
  166328. }
  166329. void PNGAPI
  166330. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166331. {
  166332. png_bytep ptr;
  166333. if(png_ptr == NULL) return;
  166334. ptr = buffer;
  166335. if (png_ptr->save_buffer_size)
  166336. {
  166337. png_size_t save_size;
  166338. if (length < png_ptr->save_buffer_size)
  166339. save_size = length;
  166340. else
  166341. save_size = png_ptr->save_buffer_size;
  166342. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166343. length -= save_size;
  166344. ptr += save_size;
  166345. png_ptr->buffer_size -= save_size;
  166346. png_ptr->save_buffer_size -= save_size;
  166347. png_ptr->save_buffer_ptr += save_size;
  166348. }
  166349. if (length && png_ptr->current_buffer_size)
  166350. {
  166351. png_size_t save_size;
  166352. if (length < png_ptr->current_buffer_size)
  166353. save_size = length;
  166354. else
  166355. save_size = png_ptr->current_buffer_size;
  166356. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166357. png_ptr->buffer_size -= save_size;
  166358. png_ptr->current_buffer_size -= save_size;
  166359. png_ptr->current_buffer_ptr += save_size;
  166360. }
  166361. }
  166362. void /* PRIVATE */
  166363. png_push_save_buffer(png_structp png_ptr)
  166364. {
  166365. if (png_ptr->save_buffer_size)
  166366. {
  166367. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166368. {
  166369. png_size_t i,istop;
  166370. png_bytep sp;
  166371. png_bytep dp;
  166372. istop = png_ptr->save_buffer_size;
  166373. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166374. i < istop; i++, sp++, dp++)
  166375. {
  166376. *dp = *sp;
  166377. }
  166378. }
  166379. }
  166380. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166381. png_ptr->save_buffer_max)
  166382. {
  166383. png_size_t new_max;
  166384. png_bytep old_buffer;
  166385. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166386. (png_ptr->current_buffer_size + 256))
  166387. {
  166388. png_error(png_ptr, "Potential overflow of save_buffer");
  166389. }
  166390. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166391. old_buffer = png_ptr->save_buffer;
  166392. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166393. (png_uint_32)new_max);
  166394. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166395. png_free(png_ptr, old_buffer);
  166396. png_ptr->save_buffer_max = new_max;
  166397. }
  166398. if (png_ptr->current_buffer_size)
  166399. {
  166400. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166401. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166402. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166403. png_ptr->current_buffer_size = 0;
  166404. }
  166405. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166406. png_ptr->buffer_size = 0;
  166407. }
  166408. void /* PRIVATE */
  166409. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166410. png_size_t buffer_length)
  166411. {
  166412. png_ptr->current_buffer = buffer;
  166413. png_ptr->current_buffer_size = buffer_length;
  166414. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166415. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166416. }
  166417. void /* PRIVATE */
  166418. png_push_read_IDAT(png_structp png_ptr)
  166419. {
  166420. #ifdef PNG_USE_LOCAL_ARRAYS
  166421. PNG_CONST PNG_IDAT;
  166422. #endif
  166423. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166424. {
  166425. png_byte chunk_length[4];
  166426. if (png_ptr->buffer_size < 8)
  166427. {
  166428. png_push_save_buffer(png_ptr);
  166429. return;
  166430. }
  166431. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166432. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166433. png_reset_crc(png_ptr);
  166434. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166435. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166436. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166437. {
  166438. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166439. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166440. png_error(png_ptr, "Not enough compressed data");
  166441. return;
  166442. }
  166443. png_ptr->idat_size = png_ptr->push_length;
  166444. }
  166445. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166446. {
  166447. png_size_t save_size;
  166448. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166449. {
  166450. save_size = (png_size_t)png_ptr->idat_size;
  166451. if((png_uint_32)save_size != png_ptr->idat_size)
  166452. png_error(png_ptr, "save_size overflowed in pngpread");
  166453. }
  166454. else
  166455. save_size = png_ptr->save_buffer_size;
  166456. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166457. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166458. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166459. png_ptr->idat_size -= save_size;
  166460. png_ptr->buffer_size -= save_size;
  166461. png_ptr->save_buffer_size -= save_size;
  166462. png_ptr->save_buffer_ptr += save_size;
  166463. }
  166464. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166465. {
  166466. png_size_t save_size;
  166467. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166468. {
  166469. save_size = (png_size_t)png_ptr->idat_size;
  166470. if((png_uint_32)save_size != png_ptr->idat_size)
  166471. png_error(png_ptr, "save_size overflowed in pngpread");
  166472. }
  166473. else
  166474. save_size = png_ptr->current_buffer_size;
  166475. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166476. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166477. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166478. png_ptr->idat_size -= save_size;
  166479. png_ptr->buffer_size -= save_size;
  166480. png_ptr->current_buffer_size -= save_size;
  166481. png_ptr->current_buffer_ptr += save_size;
  166482. }
  166483. if (!png_ptr->idat_size)
  166484. {
  166485. if (png_ptr->buffer_size < 4)
  166486. {
  166487. png_push_save_buffer(png_ptr);
  166488. return;
  166489. }
  166490. png_crc_finish(png_ptr, 0);
  166491. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166492. png_ptr->mode |= PNG_AFTER_IDAT;
  166493. }
  166494. }
  166495. void /* PRIVATE */
  166496. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166497. png_size_t buffer_length)
  166498. {
  166499. int ret;
  166500. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166501. png_error(png_ptr, "Extra compression data");
  166502. png_ptr->zstream.next_in = buffer;
  166503. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166504. for(;;)
  166505. {
  166506. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166507. if (ret != Z_OK)
  166508. {
  166509. if (ret == Z_STREAM_END)
  166510. {
  166511. if (png_ptr->zstream.avail_in)
  166512. png_error(png_ptr, "Extra compressed data");
  166513. if (!(png_ptr->zstream.avail_out))
  166514. {
  166515. png_push_process_row(png_ptr);
  166516. }
  166517. png_ptr->mode |= PNG_AFTER_IDAT;
  166518. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166519. break;
  166520. }
  166521. else if (ret == Z_BUF_ERROR)
  166522. break;
  166523. else
  166524. png_error(png_ptr, "Decompression Error");
  166525. }
  166526. if (!(png_ptr->zstream.avail_out))
  166527. {
  166528. if ((
  166529. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166530. png_ptr->interlaced && png_ptr->pass > 6) ||
  166531. (!png_ptr->interlaced &&
  166532. #endif
  166533. png_ptr->row_number == png_ptr->num_rows))
  166534. {
  166535. if (png_ptr->zstream.avail_in)
  166536. {
  166537. png_warning(png_ptr, "Too much data in IDAT chunks");
  166538. }
  166539. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166540. break;
  166541. }
  166542. png_push_process_row(png_ptr);
  166543. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166544. png_ptr->zstream.next_out = png_ptr->row_buf;
  166545. }
  166546. else
  166547. break;
  166548. }
  166549. }
  166550. void /* PRIVATE */
  166551. png_push_process_row(png_structp png_ptr)
  166552. {
  166553. png_ptr->row_info.color_type = png_ptr->color_type;
  166554. png_ptr->row_info.width = png_ptr->iwidth;
  166555. png_ptr->row_info.channels = png_ptr->channels;
  166556. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166557. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166558. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166559. png_ptr->row_info.width);
  166560. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166561. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166562. (int)(png_ptr->row_buf[0]));
  166563. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166564. png_ptr->rowbytes + 1);
  166565. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166566. png_do_read_transformations(png_ptr);
  166567. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166568. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166569. {
  166570. if (png_ptr->pass < 6)
  166571. png_do_read_interlace(png_ptr);
  166572. switch (png_ptr->pass)
  166573. {
  166574. case 0:
  166575. {
  166576. int i;
  166577. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166578. {
  166579. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166580. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166581. }
  166582. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166583. {
  166584. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166585. {
  166586. png_push_have_row(png_ptr, png_bytep_NULL);
  166587. png_read_push_finish_row(png_ptr);
  166588. }
  166589. }
  166590. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166591. {
  166592. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166593. {
  166594. png_push_have_row(png_ptr, png_bytep_NULL);
  166595. png_read_push_finish_row(png_ptr);
  166596. }
  166597. }
  166598. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166599. {
  166600. png_push_have_row(png_ptr, png_bytep_NULL);
  166601. png_read_push_finish_row(png_ptr);
  166602. }
  166603. break;
  166604. }
  166605. case 1:
  166606. {
  166607. int i;
  166608. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166609. {
  166610. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166611. png_read_push_finish_row(png_ptr);
  166612. }
  166613. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166614. {
  166615. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166616. {
  166617. png_push_have_row(png_ptr, png_bytep_NULL);
  166618. png_read_push_finish_row(png_ptr);
  166619. }
  166620. }
  166621. break;
  166622. }
  166623. case 2:
  166624. {
  166625. int i;
  166626. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166627. {
  166628. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166629. png_read_push_finish_row(png_ptr);
  166630. }
  166631. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166632. {
  166633. png_push_have_row(png_ptr, png_bytep_NULL);
  166634. png_read_push_finish_row(png_ptr);
  166635. }
  166636. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166637. {
  166638. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166639. {
  166640. png_push_have_row(png_ptr, png_bytep_NULL);
  166641. png_read_push_finish_row(png_ptr);
  166642. }
  166643. }
  166644. break;
  166645. }
  166646. case 3:
  166647. {
  166648. int i;
  166649. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166650. {
  166651. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166652. png_read_push_finish_row(png_ptr);
  166653. }
  166654. if (png_ptr->pass == 4) /* skip top two generated rows */
  166655. {
  166656. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166657. {
  166658. png_push_have_row(png_ptr, png_bytep_NULL);
  166659. png_read_push_finish_row(png_ptr);
  166660. }
  166661. }
  166662. break;
  166663. }
  166664. case 4:
  166665. {
  166666. int i;
  166667. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166668. {
  166669. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166670. png_read_push_finish_row(png_ptr);
  166671. }
  166672. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166673. {
  166674. png_push_have_row(png_ptr, png_bytep_NULL);
  166675. png_read_push_finish_row(png_ptr);
  166676. }
  166677. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166678. {
  166679. png_push_have_row(png_ptr, png_bytep_NULL);
  166680. png_read_push_finish_row(png_ptr);
  166681. }
  166682. break;
  166683. }
  166684. case 5:
  166685. {
  166686. int i;
  166687. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166688. {
  166689. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166690. png_read_push_finish_row(png_ptr);
  166691. }
  166692. if (png_ptr->pass == 6) /* skip top generated row */
  166693. {
  166694. png_push_have_row(png_ptr, png_bytep_NULL);
  166695. png_read_push_finish_row(png_ptr);
  166696. }
  166697. break;
  166698. }
  166699. case 6:
  166700. {
  166701. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166702. png_read_push_finish_row(png_ptr);
  166703. if (png_ptr->pass != 6)
  166704. break;
  166705. png_push_have_row(png_ptr, png_bytep_NULL);
  166706. png_read_push_finish_row(png_ptr);
  166707. }
  166708. }
  166709. }
  166710. else
  166711. #endif
  166712. {
  166713. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166714. png_read_push_finish_row(png_ptr);
  166715. }
  166716. }
  166717. void /* PRIVATE */
  166718. png_read_push_finish_row(png_structp png_ptr)
  166719. {
  166720. #ifdef PNG_USE_LOCAL_ARRAYS
  166721. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166722. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166723. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166724. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166725. #endif
  166726. png_ptr->row_number++;
  166727. if (png_ptr->row_number < png_ptr->num_rows)
  166728. return;
  166729. if (png_ptr->interlaced)
  166730. {
  166731. png_ptr->row_number = 0;
  166732. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166733. png_ptr->rowbytes + 1);
  166734. do
  166735. {
  166736. png_ptr->pass++;
  166737. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166738. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166739. (png_ptr->pass == 5 && png_ptr->width < 2))
  166740. png_ptr->pass++;
  166741. if (png_ptr->pass > 7)
  166742. png_ptr->pass--;
  166743. if (png_ptr->pass >= 7)
  166744. break;
  166745. png_ptr->iwidth = (png_ptr->width +
  166746. png_pass_inc[png_ptr->pass] - 1 -
  166747. png_pass_start[png_ptr->pass]) /
  166748. png_pass_inc[png_ptr->pass];
  166749. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166750. png_ptr->iwidth) + 1;
  166751. if (png_ptr->transformations & PNG_INTERLACE)
  166752. break;
  166753. png_ptr->num_rows = (png_ptr->height +
  166754. png_pass_yinc[png_ptr->pass] - 1 -
  166755. png_pass_ystart[png_ptr->pass]) /
  166756. png_pass_yinc[png_ptr->pass];
  166757. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166758. }
  166759. }
  166760. #if defined(PNG_READ_tEXt_SUPPORTED)
  166761. void /* PRIVATE */
  166762. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166763. length)
  166764. {
  166765. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166766. {
  166767. png_error(png_ptr, "Out of place tEXt");
  166768. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166769. }
  166770. #ifdef PNG_MAX_MALLOC_64K
  166771. png_ptr->skip_length = 0; /* This may not be necessary */
  166772. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166773. {
  166774. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166775. png_ptr->skip_length = length - (png_uint_32)65535L;
  166776. length = (png_uint_32)65535L;
  166777. }
  166778. #endif
  166779. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166780. (png_uint_32)(length+1));
  166781. png_ptr->current_text[length] = '\0';
  166782. png_ptr->current_text_ptr = png_ptr->current_text;
  166783. png_ptr->current_text_size = (png_size_t)length;
  166784. png_ptr->current_text_left = (png_size_t)length;
  166785. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166786. }
  166787. void /* PRIVATE */
  166788. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166789. {
  166790. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166791. {
  166792. png_size_t text_size;
  166793. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166794. text_size = png_ptr->buffer_size;
  166795. else
  166796. text_size = png_ptr->current_text_left;
  166797. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166798. png_ptr->current_text_left -= text_size;
  166799. png_ptr->current_text_ptr += text_size;
  166800. }
  166801. if (!(png_ptr->current_text_left))
  166802. {
  166803. png_textp text_ptr;
  166804. png_charp text;
  166805. png_charp key;
  166806. int ret;
  166807. if (png_ptr->buffer_size < 4)
  166808. {
  166809. png_push_save_buffer(png_ptr);
  166810. return;
  166811. }
  166812. png_push_crc_finish(png_ptr);
  166813. #if defined(PNG_MAX_MALLOC_64K)
  166814. if (png_ptr->skip_length)
  166815. return;
  166816. #endif
  166817. key = png_ptr->current_text;
  166818. for (text = key; *text; text++)
  166819. ;
  166820. if (text < key + png_ptr->current_text_size)
  166821. text++;
  166822. text_ptr = (png_textp)png_malloc(png_ptr,
  166823. (png_uint_32)png_sizeof(png_text));
  166824. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166825. text_ptr->key = key;
  166826. #ifdef PNG_iTXt_SUPPORTED
  166827. text_ptr->lang = NULL;
  166828. text_ptr->lang_key = NULL;
  166829. #endif
  166830. text_ptr->text = text;
  166831. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166832. png_free(png_ptr, key);
  166833. png_free(png_ptr, text_ptr);
  166834. png_ptr->current_text = NULL;
  166835. if (ret)
  166836. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166837. }
  166838. }
  166839. #endif
  166840. #if defined(PNG_READ_zTXt_SUPPORTED)
  166841. void /* PRIVATE */
  166842. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166843. length)
  166844. {
  166845. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166846. {
  166847. png_error(png_ptr, "Out of place zTXt");
  166848. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166849. }
  166850. #ifdef PNG_MAX_MALLOC_64K
  166851. if (length > (png_uint_32)65535L)
  166852. {
  166853. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166854. png_push_crc_skip(png_ptr, length);
  166855. return;
  166856. }
  166857. #endif
  166858. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166859. (png_uint_32)(length+1));
  166860. png_ptr->current_text[length] = '\0';
  166861. png_ptr->current_text_ptr = png_ptr->current_text;
  166862. png_ptr->current_text_size = (png_size_t)length;
  166863. png_ptr->current_text_left = (png_size_t)length;
  166864. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166865. }
  166866. void /* PRIVATE */
  166867. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166868. {
  166869. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166870. {
  166871. png_size_t text_size;
  166872. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166873. text_size = png_ptr->buffer_size;
  166874. else
  166875. text_size = png_ptr->current_text_left;
  166876. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166877. png_ptr->current_text_left -= text_size;
  166878. png_ptr->current_text_ptr += text_size;
  166879. }
  166880. if (!(png_ptr->current_text_left))
  166881. {
  166882. png_textp text_ptr;
  166883. png_charp text;
  166884. png_charp key;
  166885. int ret;
  166886. png_size_t text_size, key_size;
  166887. if (png_ptr->buffer_size < 4)
  166888. {
  166889. png_push_save_buffer(png_ptr);
  166890. return;
  166891. }
  166892. png_push_crc_finish(png_ptr);
  166893. key = png_ptr->current_text;
  166894. for (text = key; *text; text++)
  166895. ;
  166896. if (text >= key + png_ptr->current_text_size)
  166897. {
  166898. png_ptr->current_text = NULL;
  166899. png_free(png_ptr, key);
  166900. return;
  166901. }
  166902. text++;
  166903. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166904. {
  166905. png_ptr->current_text = NULL;
  166906. png_free(png_ptr, key);
  166907. return;
  166908. }
  166909. text++;
  166910. png_ptr->zstream.next_in = (png_bytep )text;
  166911. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166912. (text - key));
  166913. png_ptr->zstream.next_out = png_ptr->zbuf;
  166914. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166915. key_size = text - key;
  166916. text_size = 0;
  166917. text = NULL;
  166918. ret = Z_STREAM_END;
  166919. while (png_ptr->zstream.avail_in)
  166920. {
  166921. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166922. if (ret != Z_OK && ret != Z_STREAM_END)
  166923. {
  166924. inflateReset(&png_ptr->zstream);
  166925. png_ptr->zstream.avail_in = 0;
  166926. png_ptr->current_text = NULL;
  166927. png_free(png_ptr, key);
  166928. png_free(png_ptr, text);
  166929. return;
  166930. }
  166931. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166932. {
  166933. if (text == NULL)
  166934. {
  166935. text = (png_charp)png_malloc(png_ptr,
  166936. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166937. + key_size + 1));
  166938. png_memcpy(text + key_size, png_ptr->zbuf,
  166939. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166940. png_memcpy(text, key, key_size);
  166941. text_size = key_size + png_ptr->zbuf_size -
  166942. png_ptr->zstream.avail_out;
  166943. *(text + text_size) = '\0';
  166944. }
  166945. else
  166946. {
  166947. png_charp tmp;
  166948. tmp = text;
  166949. text = (png_charp)png_malloc(png_ptr, text_size +
  166950. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166951. + 1));
  166952. png_memcpy(text, tmp, text_size);
  166953. png_free(png_ptr, tmp);
  166954. png_memcpy(text + text_size, png_ptr->zbuf,
  166955. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166956. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166957. *(text + text_size) = '\0';
  166958. }
  166959. if (ret != Z_STREAM_END)
  166960. {
  166961. png_ptr->zstream.next_out = png_ptr->zbuf;
  166962. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166963. }
  166964. }
  166965. else
  166966. {
  166967. break;
  166968. }
  166969. if (ret == Z_STREAM_END)
  166970. break;
  166971. }
  166972. inflateReset(&png_ptr->zstream);
  166973. png_ptr->zstream.avail_in = 0;
  166974. if (ret != Z_STREAM_END)
  166975. {
  166976. png_ptr->current_text = NULL;
  166977. png_free(png_ptr, key);
  166978. png_free(png_ptr, text);
  166979. return;
  166980. }
  166981. png_ptr->current_text = NULL;
  166982. png_free(png_ptr, key);
  166983. key = text;
  166984. text += key_size;
  166985. text_ptr = (png_textp)png_malloc(png_ptr,
  166986. (png_uint_32)png_sizeof(png_text));
  166987. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166988. text_ptr->key = key;
  166989. #ifdef PNG_iTXt_SUPPORTED
  166990. text_ptr->lang = NULL;
  166991. text_ptr->lang_key = NULL;
  166992. #endif
  166993. text_ptr->text = text;
  166994. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166995. png_free(png_ptr, key);
  166996. png_free(png_ptr, text_ptr);
  166997. if (ret)
  166998. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166999. }
  167000. }
  167001. #endif
  167002. #if defined(PNG_READ_iTXt_SUPPORTED)
  167003. void /* PRIVATE */
  167004. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167005. length)
  167006. {
  167007. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167008. {
  167009. png_error(png_ptr, "Out of place iTXt");
  167010. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167011. }
  167012. #ifdef PNG_MAX_MALLOC_64K
  167013. png_ptr->skip_length = 0; /* This may not be necessary */
  167014. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  167015. {
  167016. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  167017. png_ptr->skip_length = length - (png_uint_32)65535L;
  167018. length = (png_uint_32)65535L;
  167019. }
  167020. #endif
  167021. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167022. (png_uint_32)(length+1));
  167023. png_ptr->current_text[length] = '\0';
  167024. png_ptr->current_text_ptr = png_ptr->current_text;
  167025. png_ptr->current_text_size = (png_size_t)length;
  167026. png_ptr->current_text_left = (png_size_t)length;
  167027. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  167028. }
  167029. void /* PRIVATE */
  167030. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  167031. {
  167032. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167033. {
  167034. png_size_t text_size;
  167035. if (png_ptr->buffer_size < png_ptr->current_text_left)
  167036. text_size = png_ptr->buffer_size;
  167037. else
  167038. text_size = png_ptr->current_text_left;
  167039. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167040. png_ptr->current_text_left -= text_size;
  167041. png_ptr->current_text_ptr += text_size;
  167042. }
  167043. if (!(png_ptr->current_text_left))
  167044. {
  167045. png_textp text_ptr;
  167046. png_charp key;
  167047. int comp_flag;
  167048. png_charp lang;
  167049. png_charp lang_key;
  167050. png_charp text;
  167051. int ret;
  167052. if (png_ptr->buffer_size < 4)
  167053. {
  167054. png_push_save_buffer(png_ptr);
  167055. return;
  167056. }
  167057. png_push_crc_finish(png_ptr);
  167058. #if defined(PNG_MAX_MALLOC_64K)
  167059. if (png_ptr->skip_length)
  167060. return;
  167061. #endif
  167062. key = png_ptr->current_text;
  167063. for (lang = key; *lang; lang++)
  167064. ;
  167065. if (lang < key + png_ptr->current_text_size - 3)
  167066. lang++;
  167067. comp_flag = *lang++;
  167068. lang++; /* skip comp_type, always zero */
  167069. for (lang_key = lang; *lang_key; lang_key++)
  167070. ;
  167071. lang_key++; /* skip NUL separator */
  167072. text=lang_key;
  167073. if (lang_key < key + png_ptr->current_text_size - 1)
  167074. {
  167075. for (; *text; text++)
  167076. ;
  167077. }
  167078. if (text < key + png_ptr->current_text_size)
  167079. text++;
  167080. text_ptr = (png_textp)png_malloc(png_ptr,
  167081. (png_uint_32)png_sizeof(png_text));
  167082. text_ptr->compression = comp_flag + 2;
  167083. text_ptr->key = key;
  167084. text_ptr->lang = lang;
  167085. text_ptr->lang_key = lang_key;
  167086. text_ptr->text = text;
  167087. text_ptr->text_length = 0;
  167088. text_ptr->itxt_length = png_strlen(text);
  167089. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167090. png_ptr->current_text = NULL;
  167091. png_free(png_ptr, text_ptr);
  167092. if (ret)
  167093. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  167094. }
  167095. }
  167096. #endif
  167097. void /* PRIVATE */
  167098. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167099. length)
  167100. {
  167101. png_uint_32 skip=0;
  167102. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  167103. if (!(png_ptr->chunk_name[0] & 0x20))
  167104. {
  167105. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167106. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167107. PNG_HANDLE_CHUNK_ALWAYS
  167108. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167109. && png_ptr->read_user_chunk_fn == NULL
  167110. #endif
  167111. )
  167112. #endif
  167113. png_chunk_error(png_ptr, "unknown critical chunk");
  167114. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167115. }
  167116. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167117. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  167118. {
  167119. #ifdef PNG_MAX_MALLOC_64K
  167120. if (length > (png_uint_32)65535L)
  167121. {
  167122. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  167123. skip = length - (png_uint_32)65535L;
  167124. length = (png_uint_32)65535L;
  167125. }
  167126. #endif
  167127. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  167128. (png_charp)png_ptr->chunk_name, 5);
  167129. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  167130. png_ptr->unknown_chunk.size = (png_size_t)length;
  167131. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  167132. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167133. if(png_ptr->read_user_chunk_fn != NULL)
  167134. {
  167135. int ret;
  167136. ret = (*(png_ptr->read_user_chunk_fn))
  167137. (png_ptr, &png_ptr->unknown_chunk);
  167138. if (ret < 0)
  167139. png_chunk_error(png_ptr, "error in user chunk");
  167140. if (ret == 0)
  167141. {
  167142. if (!(png_ptr->chunk_name[0] & 0x20))
  167143. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167144. PNG_HANDLE_CHUNK_ALWAYS)
  167145. png_chunk_error(png_ptr, "unknown critical chunk");
  167146. png_set_unknown_chunks(png_ptr, info_ptr,
  167147. &png_ptr->unknown_chunk, 1);
  167148. }
  167149. }
  167150. #else
  167151. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  167152. #endif
  167153. png_free(png_ptr, png_ptr->unknown_chunk.data);
  167154. png_ptr->unknown_chunk.data = NULL;
  167155. }
  167156. else
  167157. #endif
  167158. skip=length;
  167159. png_push_crc_skip(png_ptr, skip);
  167160. }
  167161. void /* PRIVATE */
  167162. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  167163. {
  167164. if (png_ptr->info_fn != NULL)
  167165. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  167166. }
  167167. void /* PRIVATE */
  167168. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  167169. {
  167170. if (png_ptr->end_fn != NULL)
  167171. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  167172. }
  167173. void /* PRIVATE */
  167174. png_push_have_row(png_structp png_ptr, png_bytep row)
  167175. {
  167176. if (png_ptr->row_fn != NULL)
  167177. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  167178. (int)png_ptr->pass);
  167179. }
  167180. void PNGAPI
  167181. png_progressive_combine_row (png_structp png_ptr,
  167182. png_bytep old_row, png_bytep new_row)
  167183. {
  167184. #ifdef PNG_USE_LOCAL_ARRAYS
  167185. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  167186. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  167187. #endif
  167188. if(png_ptr == NULL) return;
  167189. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  167190. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  167191. }
  167192. void PNGAPI
  167193. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  167194. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  167195. png_progressive_end_ptr end_fn)
  167196. {
  167197. if(png_ptr == NULL) return;
  167198. png_ptr->info_fn = info_fn;
  167199. png_ptr->row_fn = row_fn;
  167200. png_ptr->end_fn = end_fn;
  167201. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  167202. }
  167203. png_voidp PNGAPI
  167204. png_get_progressive_ptr(png_structp png_ptr)
  167205. {
  167206. if(png_ptr == NULL) return (NULL);
  167207. return png_ptr->io_ptr;
  167208. }
  167209. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  167210. /*** End of inlined file: pngpread.c ***/
  167211. /*** Start of inlined file: pngrio.c ***/
  167212. #define PNG_INTERNAL
  167213. #if defined(PNG_READ_SUPPORTED)
  167214. void /* PRIVATE */
  167215. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167216. {
  167217. png_debug1(4,"reading %d bytes\n", (int)length);
  167218. if (png_ptr->read_data_fn != NULL)
  167219. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  167220. else
  167221. png_error(png_ptr, "Call to NULL read function");
  167222. }
  167223. #if !defined(PNG_NO_STDIO)
  167224. #ifndef USE_FAR_KEYWORD
  167225. void PNGAPI
  167226. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167227. {
  167228. png_size_t check;
  167229. if(png_ptr == NULL) return;
  167230. #if defined(_WIN32_WCE)
  167231. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167232. check = 0;
  167233. #else
  167234. check = (png_size_t)fread(data, (png_size_t)1, length,
  167235. (png_FILE_p)png_ptr->io_ptr);
  167236. #endif
  167237. if (check != length)
  167238. png_error(png_ptr, "Read Error");
  167239. }
  167240. #else
  167241. #define NEAR_BUF_SIZE 1024
  167242. #define MIN(a,b) (a <= b ? a : b)
  167243. static void PNGAPI
  167244. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167245. {
  167246. int check;
  167247. png_byte *n_data;
  167248. png_FILE_p io_ptr;
  167249. if(png_ptr == NULL) return;
  167250. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  167251. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  167252. if ((png_bytep)n_data == data)
  167253. {
  167254. #if defined(_WIN32_WCE)
  167255. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167256. check = 0;
  167257. #else
  167258. check = fread(n_data, 1, length, io_ptr);
  167259. #endif
  167260. }
  167261. else
  167262. {
  167263. png_byte buf[NEAR_BUF_SIZE];
  167264. png_size_t read, remaining, err;
  167265. check = 0;
  167266. remaining = length;
  167267. do
  167268. {
  167269. read = MIN(NEAR_BUF_SIZE, remaining);
  167270. #if defined(_WIN32_WCE)
  167271. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  167272. err = 0;
  167273. #else
  167274. err = fread(buf, (png_size_t)1, read, io_ptr);
  167275. #endif
  167276. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  167277. if(err != read)
  167278. break;
  167279. else
  167280. check += err;
  167281. data += read;
  167282. remaining -= read;
  167283. }
  167284. while (remaining != 0);
  167285. }
  167286. if ((png_uint_32)check != (png_uint_32)length)
  167287. png_error(png_ptr, "read Error");
  167288. }
  167289. #endif
  167290. #endif
  167291. void PNGAPI
  167292. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167293. png_rw_ptr read_data_fn)
  167294. {
  167295. if(png_ptr == NULL) return;
  167296. png_ptr->io_ptr = io_ptr;
  167297. #if !defined(PNG_NO_STDIO)
  167298. if (read_data_fn != NULL)
  167299. png_ptr->read_data_fn = read_data_fn;
  167300. else
  167301. png_ptr->read_data_fn = png_default_read_data;
  167302. #else
  167303. png_ptr->read_data_fn = read_data_fn;
  167304. #endif
  167305. if (png_ptr->write_data_fn != NULL)
  167306. {
  167307. png_ptr->write_data_fn = NULL;
  167308. png_warning(png_ptr,
  167309. "It's an error to set both read_data_fn and write_data_fn in the ");
  167310. png_warning(png_ptr,
  167311. "same structure. Resetting write_data_fn to NULL.");
  167312. }
  167313. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167314. png_ptr->output_flush_fn = NULL;
  167315. #endif
  167316. }
  167317. #endif /* PNG_READ_SUPPORTED */
  167318. /*** End of inlined file: pngrio.c ***/
  167319. /*** Start of inlined file: pngrtran.c ***/
  167320. #define PNG_INTERNAL
  167321. #if defined(PNG_READ_SUPPORTED)
  167322. void PNGAPI
  167323. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167324. {
  167325. png_debug(1, "in png_set_crc_action\n");
  167326. if(png_ptr == NULL) return;
  167327. switch (crit_action)
  167328. {
  167329. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167330. break;
  167331. case PNG_CRC_WARN_USE: /* warn/use data */
  167332. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167333. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167334. break;
  167335. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167336. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167337. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167338. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167339. break;
  167340. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167341. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167342. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167343. case PNG_CRC_DEFAULT:
  167344. default:
  167345. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167346. break;
  167347. }
  167348. switch (ancil_action)
  167349. {
  167350. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167351. break;
  167352. case PNG_CRC_WARN_USE: /* warn/use data */
  167353. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167354. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167355. break;
  167356. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167357. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167358. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167359. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167360. break;
  167361. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167362. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167363. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167364. break;
  167365. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167366. case PNG_CRC_DEFAULT:
  167367. default:
  167368. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167369. break;
  167370. }
  167371. }
  167372. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167373. defined(PNG_FLOATING_POINT_SUPPORTED)
  167374. void PNGAPI
  167375. png_set_background(png_structp png_ptr,
  167376. png_color_16p background_color, int background_gamma_code,
  167377. int need_expand, double background_gamma)
  167378. {
  167379. png_debug(1, "in png_set_background\n");
  167380. if(png_ptr == NULL) return;
  167381. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167382. {
  167383. png_warning(png_ptr, "Application must supply a known background gamma");
  167384. return;
  167385. }
  167386. png_ptr->transformations |= PNG_BACKGROUND;
  167387. png_memcpy(&(png_ptr->background), background_color,
  167388. png_sizeof(png_color_16));
  167389. png_ptr->background_gamma = (float)background_gamma;
  167390. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167391. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167392. }
  167393. #endif
  167394. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167395. void PNGAPI
  167396. png_set_strip_16(png_structp png_ptr)
  167397. {
  167398. png_debug(1, "in png_set_strip_16\n");
  167399. if(png_ptr == NULL) return;
  167400. png_ptr->transformations |= PNG_16_TO_8;
  167401. }
  167402. #endif
  167403. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167404. void PNGAPI
  167405. png_set_strip_alpha(png_structp png_ptr)
  167406. {
  167407. png_debug(1, "in png_set_strip_alpha\n");
  167408. if(png_ptr == NULL) return;
  167409. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167410. }
  167411. #endif
  167412. #if defined(PNG_READ_DITHER_SUPPORTED)
  167413. typedef struct png_dsort_struct
  167414. {
  167415. struct png_dsort_struct FAR * next;
  167416. png_byte left;
  167417. png_byte right;
  167418. } png_dsort;
  167419. typedef png_dsort FAR * png_dsortp;
  167420. typedef png_dsort FAR * FAR * png_dsortpp;
  167421. void PNGAPI
  167422. png_set_dither(png_structp png_ptr, png_colorp palette,
  167423. int num_palette, int maximum_colors, png_uint_16p histogram,
  167424. int full_dither)
  167425. {
  167426. png_debug(1, "in png_set_dither\n");
  167427. if(png_ptr == NULL) return;
  167428. png_ptr->transformations |= PNG_DITHER;
  167429. if (!full_dither)
  167430. {
  167431. int i;
  167432. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167433. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167434. for (i = 0; i < num_palette; i++)
  167435. png_ptr->dither_index[i] = (png_byte)i;
  167436. }
  167437. if (num_palette > maximum_colors)
  167438. {
  167439. if (histogram != NULL)
  167440. {
  167441. int i;
  167442. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167443. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167444. for (i = 0; i < num_palette; i++)
  167445. png_ptr->dither_sort[i] = (png_byte)i;
  167446. for (i = num_palette - 1; i >= maximum_colors; i--)
  167447. {
  167448. int done; /* to stop early if the list is pre-sorted */
  167449. int j;
  167450. done = 1;
  167451. for (j = 0; j < i; j++)
  167452. {
  167453. if (histogram[png_ptr->dither_sort[j]]
  167454. < histogram[png_ptr->dither_sort[j + 1]])
  167455. {
  167456. png_byte t;
  167457. t = png_ptr->dither_sort[j];
  167458. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167459. png_ptr->dither_sort[j + 1] = t;
  167460. done = 0;
  167461. }
  167462. }
  167463. if (done)
  167464. break;
  167465. }
  167466. if (full_dither)
  167467. {
  167468. int j = num_palette;
  167469. for (i = 0; i < maximum_colors; i++)
  167470. {
  167471. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167472. {
  167473. do
  167474. j--;
  167475. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167476. palette[i] = palette[j];
  167477. }
  167478. }
  167479. }
  167480. else
  167481. {
  167482. int j = num_palette;
  167483. for (i = 0; i < maximum_colors; i++)
  167484. {
  167485. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167486. {
  167487. png_color tmp_color;
  167488. do
  167489. j--;
  167490. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167491. tmp_color = palette[j];
  167492. palette[j] = palette[i];
  167493. palette[i] = tmp_color;
  167494. png_ptr->dither_index[j] = (png_byte)i;
  167495. png_ptr->dither_index[i] = (png_byte)j;
  167496. }
  167497. }
  167498. for (i = 0; i < num_palette; i++)
  167499. {
  167500. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167501. {
  167502. int min_d, k, min_k, d_index;
  167503. d_index = png_ptr->dither_index[i];
  167504. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167505. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167506. {
  167507. int d;
  167508. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167509. if (d < min_d)
  167510. {
  167511. min_d = d;
  167512. min_k = k;
  167513. }
  167514. }
  167515. png_ptr->dither_index[i] = (png_byte)min_k;
  167516. }
  167517. }
  167518. }
  167519. png_free(png_ptr, png_ptr->dither_sort);
  167520. png_ptr->dither_sort=NULL;
  167521. }
  167522. else
  167523. {
  167524. int i;
  167525. int max_d;
  167526. int num_new_palette;
  167527. png_dsortp t;
  167528. png_dsortpp hash;
  167529. t=NULL;
  167530. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167531. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167532. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167533. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167534. for (i = 0; i < num_palette; i++)
  167535. {
  167536. png_ptr->index_to_palette[i] = (png_byte)i;
  167537. png_ptr->palette_to_index[i] = (png_byte)i;
  167538. }
  167539. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167540. png_sizeof (png_dsortp)));
  167541. for (i = 0; i < 769; i++)
  167542. hash[i] = NULL;
  167543. num_new_palette = num_palette;
  167544. max_d = 96;
  167545. while (num_new_palette > maximum_colors)
  167546. {
  167547. for (i = 0; i < num_new_palette - 1; i++)
  167548. {
  167549. int j;
  167550. for (j = i + 1; j < num_new_palette; j++)
  167551. {
  167552. int d;
  167553. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167554. if (d <= max_d)
  167555. {
  167556. t = (png_dsortp)png_malloc_warn(png_ptr,
  167557. (png_uint_32)(png_sizeof(png_dsort)));
  167558. if (t == NULL)
  167559. break;
  167560. t->next = hash[d];
  167561. t->left = (png_byte)i;
  167562. t->right = (png_byte)j;
  167563. hash[d] = t;
  167564. }
  167565. }
  167566. if (t == NULL)
  167567. break;
  167568. }
  167569. if (t != NULL)
  167570. for (i = 0; i <= max_d; i++)
  167571. {
  167572. if (hash[i] != NULL)
  167573. {
  167574. png_dsortp p;
  167575. for (p = hash[i]; p; p = p->next)
  167576. {
  167577. if ((int)png_ptr->index_to_palette[p->left]
  167578. < num_new_palette &&
  167579. (int)png_ptr->index_to_palette[p->right]
  167580. < num_new_palette)
  167581. {
  167582. int j, next_j;
  167583. if (num_new_palette & 0x01)
  167584. {
  167585. j = p->left;
  167586. next_j = p->right;
  167587. }
  167588. else
  167589. {
  167590. j = p->right;
  167591. next_j = p->left;
  167592. }
  167593. num_new_palette--;
  167594. palette[png_ptr->index_to_palette[j]]
  167595. = palette[num_new_palette];
  167596. if (!full_dither)
  167597. {
  167598. int k;
  167599. for (k = 0; k < num_palette; k++)
  167600. {
  167601. if (png_ptr->dither_index[k] ==
  167602. png_ptr->index_to_palette[j])
  167603. png_ptr->dither_index[k] =
  167604. png_ptr->index_to_palette[next_j];
  167605. if ((int)png_ptr->dither_index[k] ==
  167606. num_new_palette)
  167607. png_ptr->dither_index[k] =
  167608. png_ptr->index_to_palette[j];
  167609. }
  167610. }
  167611. png_ptr->index_to_palette[png_ptr->palette_to_index
  167612. [num_new_palette]] = png_ptr->index_to_palette[j];
  167613. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167614. = png_ptr->palette_to_index[num_new_palette];
  167615. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167616. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167617. }
  167618. if (num_new_palette <= maximum_colors)
  167619. break;
  167620. }
  167621. if (num_new_palette <= maximum_colors)
  167622. break;
  167623. }
  167624. }
  167625. for (i = 0; i < 769; i++)
  167626. {
  167627. if (hash[i] != NULL)
  167628. {
  167629. png_dsortp p = hash[i];
  167630. while (p)
  167631. {
  167632. t = p->next;
  167633. png_free(png_ptr, p);
  167634. p = t;
  167635. }
  167636. }
  167637. hash[i] = 0;
  167638. }
  167639. max_d += 96;
  167640. }
  167641. png_free(png_ptr, hash);
  167642. png_free(png_ptr, png_ptr->palette_to_index);
  167643. png_free(png_ptr, png_ptr->index_to_palette);
  167644. png_ptr->palette_to_index=NULL;
  167645. png_ptr->index_to_palette=NULL;
  167646. }
  167647. num_palette = maximum_colors;
  167648. }
  167649. if (png_ptr->palette == NULL)
  167650. {
  167651. png_ptr->palette = palette;
  167652. }
  167653. png_ptr->num_palette = (png_uint_16)num_palette;
  167654. if (full_dither)
  167655. {
  167656. int i;
  167657. png_bytep distance;
  167658. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167659. PNG_DITHER_BLUE_BITS;
  167660. int num_red = (1 << PNG_DITHER_RED_BITS);
  167661. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167662. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167663. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167664. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167665. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167666. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167667. png_sizeof (png_byte));
  167668. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167669. png_sizeof(png_byte)));
  167670. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167671. for (i = 0; i < num_palette; i++)
  167672. {
  167673. int ir, ig, ib;
  167674. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167675. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167676. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167677. for (ir = 0; ir < num_red; ir++)
  167678. {
  167679. int dr = ((ir > r) ? ir - r : r - ir);
  167680. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167681. for (ig = 0; ig < num_green; ig++)
  167682. {
  167683. int dg = ((ig > g) ? ig - g : g - ig);
  167684. int dt = dr + dg;
  167685. int dm = ((dr > dg) ? dr : dg);
  167686. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167687. for (ib = 0; ib < num_blue; ib++)
  167688. {
  167689. int d_index = index_g | ib;
  167690. int db = ((ib > b) ? ib - b : b - ib);
  167691. int dmax = ((dm > db) ? dm : db);
  167692. int d = dmax + dt + db;
  167693. if (d < (int)distance[d_index])
  167694. {
  167695. distance[d_index] = (png_byte)d;
  167696. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167697. }
  167698. }
  167699. }
  167700. }
  167701. }
  167702. png_free(png_ptr, distance);
  167703. }
  167704. }
  167705. #endif
  167706. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167707. void PNGAPI
  167708. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167709. {
  167710. png_debug(1, "in png_set_gamma\n");
  167711. if(png_ptr == NULL) return;
  167712. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167713. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167714. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167715. png_ptr->transformations |= PNG_GAMMA;
  167716. png_ptr->gamma = (float)file_gamma;
  167717. png_ptr->screen_gamma = (float)scrn_gamma;
  167718. }
  167719. #endif
  167720. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167721. void PNGAPI
  167722. png_set_expand(png_structp png_ptr)
  167723. {
  167724. png_debug(1, "in png_set_expand\n");
  167725. if(png_ptr == NULL) return;
  167726. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167727. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167728. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167729. #endif
  167730. }
  167731. void PNGAPI
  167732. png_set_palette_to_rgb(png_structp png_ptr)
  167733. {
  167734. png_debug(1, "in png_set_palette_to_rgb\n");
  167735. if(png_ptr == NULL) return;
  167736. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167737. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167738. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167739. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167740. #endif
  167741. }
  167742. #if !defined(PNG_1_0_X)
  167743. void PNGAPI
  167744. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167745. {
  167746. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167747. if(png_ptr == NULL) return;
  167748. png_ptr->transformations |= PNG_EXPAND;
  167749. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167750. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167751. #endif
  167752. }
  167753. #endif
  167754. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167755. void PNGAPI
  167756. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167757. {
  167758. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167759. if(png_ptr == NULL) return;
  167760. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167761. }
  167762. #endif
  167763. void PNGAPI
  167764. png_set_tRNS_to_alpha(png_structp png_ptr)
  167765. {
  167766. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167767. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167768. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167769. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167770. #endif
  167771. }
  167772. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167773. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167774. void PNGAPI
  167775. png_set_gray_to_rgb(png_structp png_ptr)
  167776. {
  167777. png_debug(1, "in png_set_gray_to_rgb\n");
  167778. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167779. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167780. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167781. #endif
  167782. }
  167783. #endif
  167784. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167785. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167786. void PNGAPI
  167787. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167788. double green)
  167789. {
  167790. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167791. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167792. if(png_ptr == NULL) return;
  167793. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167794. }
  167795. #endif
  167796. void PNGAPI
  167797. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167798. png_fixed_point red, png_fixed_point green)
  167799. {
  167800. png_debug(1, "in png_set_rgb_to_gray\n");
  167801. if(png_ptr == NULL) return;
  167802. switch(error_action)
  167803. {
  167804. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167805. break;
  167806. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167807. break;
  167808. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167809. }
  167810. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167811. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167812. png_ptr->transformations |= PNG_EXPAND;
  167813. #else
  167814. {
  167815. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167816. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167817. }
  167818. #endif
  167819. {
  167820. png_uint_16 red_int, green_int;
  167821. if(red < 0 || green < 0)
  167822. {
  167823. red_int = 6968; /* .212671 * 32768 + .5 */
  167824. green_int = 23434; /* .715160 * 32768 + .5 */
  167825. }
  167826. else if(red + green < 100000L)
  167827. {
  167828. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167829. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167830. }
  167831. else
  167832. {
  167833. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167834. red_int = 6968;
  167835. green_int = 23434;
  167836. }
  167837. png_ptr->rgb_to_gray_red_coeff = red_int;
  167838. png_ptr->rgb_to_gray_green_coeff = green_int;
  167839. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167840. }
  167841. }
  167842. #endif
  167843. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167844. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167845. defined(PNG_LEGACY_SUPPORTED)
  167846. void PNGAPI
  167847. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167848. read_user_transform_fn)
  167849. {
  167850. png_debug(1, "in png_set_read_user_transform_fn\n");
  167851. if(png_ptr == NULL) return;
  167852. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167853. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167854. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167855. #endif
  167856. #ifdef PNG_LEGACY_SUPPORTED
  167857. if(read_user_transform_fn)
  167858. png_warning(png_ptr,
  167859. "This version of libpng does not support user transforms");
  167860. #endif
  167861. }
  167862. #endif
  167863. void /* PRIVATE */
  167864. png_init_read_transformations(png_structp png_ptr)
  167865. {
  167866. png_debug(1, "in png_init_read_transformations\n");
  167867. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167868. if(png_ptr != NULL)
  167869. #endif
  167870. {
  167871. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167872. || defined(PNG_READ_GAMMA_SUPPORTED)
  167873. int color_type = png_ptr->color_type;
  167874. #endif
  167875. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167876. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167877. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167878. !(color_type & PNG_COLOR_MASK_COLOR))
  167879. {
  167880. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167881. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167882. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167883. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167884. png_ptr->background.red == png_ptr->background.green &&
  167885. png_ptr->background.red == png_ptr->background.blue)
  167886. {
  167887. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167888. png_ptr->background.gray = png_ptr->background.red;
  167889. }
  167890. #endif
  167891. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167892. (png_ptr->transformations & PNG_EXPAND))
  167893. {
  167894. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167895. {
  167896. switch (png_ptr->bit_depth)
  167897. {
  167898. case 1:
  167899. png_ptr->background.gray *= (png_uint_16)0xff;
  167900. png_ptr->background.red = png_ptr->background.green
  167901. = png_ptr->background.blue = png_ptr->background.gray;
  167902. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167903. {
  167904. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167905. png_ptr->trans_values.red = png_ptr->trans_values.green
  167906. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167907. }
  167908. break;
  167909. case 2:
  167910. png_ptr->background.gray *= (png_uint_16)0x55;
  167911. png_ptr->background.red = png_ptr->background.green
  167912. = png_ptr->background.blue = png_ptr->background.gray;
  167913. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167914. {
  167915. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167916. png_ptr->trans_values.red = png_ptr->trans_values.green
  167917. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167918. }
  167919. break;
  167920. case 4:
  167921. png_ptr->background.gray *= (png_uint_16)0x11;
  167922. png_ptr->background.red = png_ptr->background.green
  167923. = png_ptr->background.blue = png_ptr->background.gray;
  167924. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167925. {
  167926. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167927. png_ptr->trans_values.red = png_ptr->trans_values.green
  167928. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167929. }
  167930. break;
  167931. case 8:
  167932. case 16:
  167933. png_ptr->background.red = png_ptr->background.green
  167934. = png_ptr->background.blue = png_ptr->background.gray;
  167935. break;
  167936. }
  167937. }
  167938. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167939. {
  167940. png_ptr->background.red =
  167941. png_ptr->palette[png_ptr->background.index].red;
  167942. png_ptr->background.green =
  167943. png_ptr->palette[png_ptr->background.index].green;
  167944. png_ptr->background.blue =
  167945. png_ptr->palette[png_ptr->background.index].blue;
  167946. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167947. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167948. {
  167949. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167950. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167951. #endif
  167952. {
  167953. int i,istop;
  167954. istop=(int)png_ptr->num_trans;
  167955. for (i=0; i<istop; i++)
  167956. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167957. }
  167958. }
  167959. #endif
  167960. }
  167961. }
  167962. #endif
  167963. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167964. png_ptr->background_1 = png_ptr->background;
  167965. #endif
  167966. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167967. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167968. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167969. < PNG_GAMMA_THRESHOLD))
  167970. {
  167971. int i,k;
  167972. k=0;
  167973. for (i=0; i<png_ptr->num_trans; i++)
  167974. {
  167975. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167976. k=1; /* partial transparency is present */
  167977. }
  167978. if (k == 0)
  167979. png_ptr->transformations &= (~PNG_GAMMA);
  167980. }
  167981. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167982. png_ptr->gamma != 0.0)
  167983. {
  167984. png_build_gamma_table(png_ptr);
  167985. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167986. if (png_ptr->transformations & PNG_BACKGROUND)
  167987. {
  167988. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167989. {
  167990. png_color back, back_1;
  167991. png_colorp palette = png_ptr->palette;
  167992. int num_palette = png_ptr->num_palette;
  167993. int i;
  167994. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167995. {
  167996. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167997. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167998. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167999. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168000. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168001. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168002. }
  168003. else
  168004. {
  168005. double g, gs;
  168006. switch (png_ptr->background_gamma_type)
  168007. {
  168008. case PNG_BACKGROUND_GAMMA_SCREEN:
  168009. g = (png_ptr->screen_gamma);
  168010. gs = 1.0;
  168011. break;
  168012. case PNG_BACKGROUND_GAMMA_FILE:
  168013. g = 1.0 / (png_ptr->gamma);
  168014. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168015. break;
  168016. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168017. g = 1.0 / (png_ptr->background_gamma);
  168018. gs = 1.0 / (png_ptr->background_gamma *
  168019. png_ptr->screen_gamma);
  168020. break;
  168021. default:
  168022. g = 1.0; /* back_1 */
  168023. gs = 1.0; /* back */
  168024. }
  168025. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  168026. {
  168027. back.red = (png_byte)png_ptr->background.red;
  168028. back.green = (png_byte)png_ptr->background.green;
  168029. back.blue = (png_byte)png_ptr->background.blue;
  168030. }
  168031. else
  168032. {
  168033. back.red = (png_byte)(pow(
  168034. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  168035. back.green = (png_byte)(pow(
  168036. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  168037. back.blue = (png_byte)(pow(
  168038. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  168039. }
  168040. back_1.red = (png_byte)(pow(
  168041. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  168042. back_1.green = (png_byte)(pow(
  168043. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  168044. back_1.blue = (png_byte)(pow(
  168045. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  168046. }
  168047. for (i = 0; i < num_palette; i++)
  168048. {
  168049. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168050. {
  168051. if (png_ptr->trans[i] == 0)
  168052. {
  168053. palette[i] = back;
  168054. }
  168055. else /* if (png_ptr->trans[i] != 0xff) */
  168056. {
  168057. png_byte v, w;
  168058. v = png_ptr->gamma_to_1[palette[i].red];
  168059. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168060. palette[i].red = png_ptr->gamma_from_1[w];
  168061. v = png_ptr->gamma_to_1[palette[i].green];
  168062. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168063. palette[i].green = png_ptr->gamma_from_1[w];
  168064. v = png_ptr->gamma_to_1[palette[i].blue];
  168065. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168066. palette[i].blue = png_ptr->gamma_from_1[w];
  168067. }
  168068. }
  168069. else
  168070. {
  168071. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168072. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168073. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168074. }
  168075. }
  168076. }
  168077. else
  168078. {
  168079. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  168080. double g = 1.0;
  168081. double gs = 1.0;
  168082. switch (png_ptr->background_gamma_type)
  168083. {
  168084. case PNG_BACKGROUND_GAMMA_SCREEN:
  168085. g = (png_ptr->screen_gamma);
  168086. gs = 1.0;
  168087. break;
  168088. case PNG_BACKGROUND_GAMMA_FILE:
  168089. g = 1.0 / (png_ptr->gamma);
  168090. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168091. break;
  168092. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168093. g = 1.0 / (png_ptr->background_gamma);
  168094. gs = 1.0 / (png_ptr->background_gamma *
  168095. png_ptr->screen_gamma);
  168096. break;
  168097. }
  168098. png_ptr->background_1.gray = (png_uint_16)(pow(
  168099. (double)png_ptr->background.gray / m, g) * m + .5);
  168100. png_ptr->background.gray = (png_uint_16)(pow(
  168101. (double)png_ptr->background.gray / m, gs) * m + .5);
  168102. if ((png_ptr->background.red != png_ptr->background.green) ||
  168103. (png_ptr->background.red != png_ptr->background.blue) ||
  168104. (png_ptr->background.red != png_ptr->background.gray))
  168105. {
  168106. png_ptr->background_1.red = (png_uint_16)(pow(
  168107. (double)png_ptr->background.red / m, g) * m + .5);
  168108. png_ptr->background_1.green = (png_uint_16)(pow(
  168109. (double)png_ptr->background.green / m, g) * m + .5);
  168110. png_ptr->background_1.blue = (png_uint_16)(pow(
  168111. (double)png_ptr->background.blue / m, g) * m + .5);
  168112. png_ptr->background.red = (png_uint_16)(pow(
  168113. (double)png_ptr->background.red / m, gs) * m + .5);
  168114. png_ptr->background.green = (png_uint_16)(pow(
  168115. (double)png_ptr->background.green / m, gs) * m + .5);
  168116. png_ptr->background.blue = (png_uint_16)(pow(
  168117. (double)png_ptr->background.blue / m, gs) * m + .5);
  168118. }
  168119. else
  168120. {
  168121. png_ptr->background_1.red = png_ptr->background_1.green
  168122. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  168123. png_ptr->background.red = png_ptr->background.green
  168124. = png_ptr->background.blue = png_ptr->background.gray;
  168125. }
  168126. }
  168127. }
  168128. else
  168129. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168130. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168131. {
  168132. png_colorp palette = png_ptr->palette;
  168133. int num_palette = png_ptr->num_palette;
  168134. int i;
  168135. for (i = 0; i < num_palette; i++)
  168136. {
  168137. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168138. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168139. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168140. }
  168141. }
  168142. }
  168143. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168144. else
  168145. #endif
  168146. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  168147. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168148. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168149. (color_type == PNG_COLOR_TYPE_PALETTE))
  168150. {
  168151. int i;
  168152. int istop = (int)png_ptr->num_trans;
  168153. png_color back;
  168154. png_colorp palette = png_ptr->palette;
  168155. back.red = (png_byte)png_ptr->background.red;
  168156. back.green = (png_byte)png_ptr->background.green;
  168157. back.blue = (png_byte)png_ptr->background.blue;
  168158. for (i = 0; i < istop; i++)
  168159. {
  168160. if (png_ptr->trans[i] == 0)
  168161. {
  168162. palette[i] = back;
  168163. }
  168164. else if (png_ptr->trans[i] != 0xff)
  168165. {
  168166. png_composite(palette[i].red, palette[i].red,
  168167. png_ptr->trans[i], back.red);
  168168. png_composite(palette[i].green, palette[i].green,
  168169. png_ptr->trans[i], back.green);
  168170. png_composite(palette[i].blue, palette[i].blue,
  168171. png_ptr->trans[i], back.blue);
  168172. }
  168173. }
  168174. }
  168175. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168176. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168177. if ((png_ptr->transformations & PNG_SHIFT) &&
  168178. (color_type == PNG_COLOR_TYPE_PALETTE))
  168179. {
  168180. png_uint_16 i;
  168181. png_uint_16 istop = png_ptr->num_palette;
  168182. int sr = 8 - png_ptr->sig_bit.red;
  168183. int sg = 8 - png_ptr->sig_bit.green;
  168184. int sb = 8 - png_ptr->sig_bit.blue;
  168185. if (sr < 0 || sr > 8)
  168186. sr = 0;
  168187. if (sg < 0 || sg > 8)
  168188. sg = 0;
  168189. if (sb < 0 || sb > 8)
  168190. sb = 0;
  168191. for (i = 0; i < istop; i++)
  168192. {
  168193. png_ptr->palette[i].red >>= sr;
  168194. png_ptr->palette[i].green >>= sg;
  168195. png_ptr->palette[i].blue >>= sb;
  168196. }
  168197. }
  168198. #endif /* PNG_READ_SHIFT_SUPPORTED */
  168199. }
  168200. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  168201. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  168202. if(png_ptr)
  168203. return;
  168204. #endif
  168205. }
  168206. void /* PRIVATE */
  168207. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  168208. {
  168209. png_debug(1, "in png_read_transform_info\n");
  168210. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168211. if (png_ptr->transformations & PNG_EXPAND)
  168212. {
  168213. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168214. {
  168215. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  168216. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  168217. else
  168218. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  168219. info_ptr->bit_depth = 8;
  168220. info_ptr->num_trans = 0;
  168221. }
  168222. else
  168223. {
  168224. if (png_ptr->num_trans)
  168225. {
  168226. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  168227. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168228. else
  168229. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168230. }
  168231. if (info_ptr->bit_depth < 8)
  168232. info_ptr->bit_depth = 8;
  168233. info_ptr->num_trans = 0;
  168234. }
  168235. }
  168236. #endif
  168237. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168238. if (png_ptr->transformations & PNG_BACKGROUND)
  168239. {
  168240. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168241. info_ptr->num_trans = 0;
  168242. info_ptr->background = png_ptr->background;
  168243. }
  168244. #endif
  168245. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168246. if (png_ptr->transformations & PNG_GAMMA)
  168247. {
  168248. #ifdef PNG_FLOATING_POINT_SUPPORTED
  168249. info_ptr->gamma = png_ptr->gamma;
  168250. #endif
  168251. #ifdef PNG_FIXED_POINT_SUPPORTED
  168252. info_ptr->int_gamma = png_ptr->int_gamma;
  168253. #endif
  168254. }
  168255. #endif
  168256. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168257. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  168258. info_ptr->bit_depth = 8;
  168259. #endif
  168260. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168261. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  168262. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168263. #endif
  168264. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168265. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168266. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  168267. #endif
  168268. #if defined(PNG_READ_DITHER_SUPPORTED)
  168269. if (png_ptr->transformations & PNG_DITHER)
  168270. {
  168271. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168272. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  168273. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  168274. {
  168275. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  168276. }
  168277. }
  168278. #endif
  168279. #if defined(PNG_READ_PACK_SUPPORTED)
  168280. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  168281. info_ptr->bit_depth = 8;
  168282. #endif
  168283. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168284. info_ptr->channels = 1;
  168285. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168286. info_ptr->channels = 3;
  168287. else
  168288. info_ptr->channels = 1;
  168289. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168290. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168291. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168292. #endif
  168293. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168294. info_ptr->channels++;
  168295. #if defined(PNG_READ_FILLER_SUPPORTED)
  168296. if ((png_ptr->transformations & PNG_FILLER) &&
  168297. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168298. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168299. {
  168300. info_ptr->channels++;
  168301. #if !defined(PNG_1_0_X)
  168302. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168303. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168304. #endif
  168305. }
  168306. #endif
  168307. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168308. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168309. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168310. {
  168311. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168312. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168313. if(info_ptr->channels < png_ptr->user_transform_channels)
  168314. info_ptr->channels = png_ptr->user_transform_channels;
  168315. }
  168316. #endif
  168317. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168318. info_ptr->bit_depth);
  168319. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168320. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168321. if(png_ptr)
  168322. return;
  168323. #endif
  168324. }
  168325. void /* PRIVATE */
  168326. png_do_read_transformations(png_structp png_ptr)
  168327. {
  168328. png_debug(1, "in png_do_read_transformations\n");
  168329. if (png_ptr->row_buf == NULL)
  168330. {
  168331. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168332. char msg[50];
  168333. png_snprintf2(msg, 50,
  168334. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168335. png_ptr->pass);
  168336. png_error(png_ptr, msg);
  168337. #else
  168338. png_error(png_ptr, "NULL row buffer");
  168339. #endif
  168340. }
  168341. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168342. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168343. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168344. png_error(png_ptr, "Uninitialized row");
  168345. #else
  168346. png_warning(png_ptr, "Uninitialized row");
  168347. #endif
  168348. #endif
  168349. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168350. if (png_ptr->transformations & PNG_EXPAND)
  168351. {
  168352. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168353. {
  168354. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168355. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168356. }
  168357. else
  168358. {
  168359. if (png_ptr->num_trans &&
  168360. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168361. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168362. &(png_ptr->trans_values));
  168363. else
  168364. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168365. NULL);
  168366. }
  168367. }
  168368. #endif
  168369. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168370. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168371. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168372. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168373. #endif
  168374. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168375. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168376. {
  168377. int rgb_error =
  168378. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168379. if(rgb_error)
  168380. {
  168381. png_ptr->rgb_to_gray_status=1;
  168382. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168383. PNG_RGB_TO_GRAY_WARN)
  168384. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168385. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168386. PNG_RGB_TO_GRAY_ERR)
  168387. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168388. }
  168389. }
  168390. #endif
  168391. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168392. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168393. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168394. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168395. #endif
  168396. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168397. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168398. ((png_ptr->num_trans != 0 ) ||
  168399. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168400. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168401. &(png_ptr->trans_values), &(png_ptr->background)
  168402. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168403. , &(png_ptr->background_1),
  168404. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168405. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168406. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168407. png_ptr->gamma_shift
  168408. #endif
  168409. );
  168410. #endif
  168411. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168412. if ((png_ptr->transformations & PNG_GAMMA) &&
  168413. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168414. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168415. ((png_ptr->num_trans != 0) ||
  168416. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168417. #endif
  168418. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168419. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168420. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168421. png_ptr->gamma_shift);
  168422. #endif
  168423. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168424. if (png_ptr->transformations & PNG_16_TO_8)
  168425. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168426. #endif
  168427. #if defined(PNG_READ_DITHER_SUPPORTED)
  168428. if (png_ptr->transformations & PNG_DITHER)
  168429. {
  168430. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168431. png_ptr->palette_lookup, png_ptr->dither_index);
  168432. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168433. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168434. }
  168435. #endif
  168436. #if defined(PNG_READ_INVERT_SUPPORTED)
  168437. if (png_ptr->transformations & PNG_INVERT_MONO)
  168438. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168439. #endif
  168440. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168441. if (png_ptr->transformations & PNG_SHIFT)
  168442. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168443. &(png_ptr->shift));
  168444. #endif
  168445. #if defined(PNG_READ_PACK_SUPPORTED)
  168446. if (png_ptr->transformations & PNG_PACK)
  168447. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168448. #endif
  168449. #if defined(PNG_READ_BGR_SUPPORTED)
  168450. if (png_ptr->transformations & PNG_BGR)
  168451. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168452. #endif
  168453. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168454. if (png_ptr->transformations & PNG_PACKSWAP)
  168455. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168456. #endif
  168457. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168458. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168459. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168460. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168461. #endif
  168462. #if defined(PNG_READ_FILLER_SUPPORTED)
  168463. if (png_ptr->transformations & PNG_FILLER)
  168464. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168465. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168466. #endif
  168467. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168468. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168469. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168470. #endif
  168471. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168472. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168473. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168474. #endif
  168475. #if defined(PNG_READ_SWAP_SUPPORTED)
  168476. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168477. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168478. #endif
  168479. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168480. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168481. {
  168482. if(png_ptr->read_user_transform_fn != NULL)
  168483. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168484. (png_ptr, /* png_ptr */
  168485. &(png_ptr->row_info), /* row_info: */
  168486. png_ptr->row_buf + 1); /* start of pixel data for row */
  168487. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168488. if(png_ptr->user_transform_depth)
  168489. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168490. if(png_ptr->user_transform_channels)
  168491. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168492. #endif
  168493. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168494. png_ptr->row_info.channels);
  168495. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168496. png_ptr->row_info.width);
  168497. }
  168498. #endif
  168499. }
  168500. #if defined(PNG_READ_PACK_SUPPORTED)
  168501. void /* PRIVATE */
  168502. png_do_unpack(png_row_infop row_info, png_bytep row)
  168503. {
  168504. png_debug(1, "in png_do_unpack\n");
  168505. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168506. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168507. #else
  168508. if (row_info->bit_depth < 8)
  168509. #endif
  168510. {
  168511. png_uint_32 i;
  168512. png_uint_32 row_width=row_info->width;
  168513. switch (row_info->bit_depth)
  168514. {
  168515. case 1:
  168516. {
  168517. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168518. png_bytep dp = row + (png_size_t)row_width - 1;
  168519. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168520. for (i = 0; i < row_width; i++)
  168521. {
  168522. *dp = (png_byte)((*sp >> shift) & 0x01);
  168523. if (shift == 7)
  168524. {
  168525. shift = 0;
  168526. sp--;
  168527. }
  168528. else
  168529. shift++;
  168530. dp--;
  168531. }
  168532. break;
  168533. }
  168534. case 2:
  168535. {
  168536. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168537. png_bytep dp = row + (png_size_t)row_width - 1;
  168538. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168539. for (i = 0; i < row_width; i++)
  168540. {
  168541. *dp = (png_byte)((*sp >> shift) & 0x03);
  168542. if (shift == 6)
  168543. {
  168544. shift = 0;
  168545. sp--;
  168546. }
  168547. else
  168548. shift += 2;
  168549. dp--;
  168550. }
  168551. break;
  168552. }
  168553. case 4:
  168554. {
  168555. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168556. png_bytep dp = row + (png_size_t)row_width - 1;
  168557. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168558. for (i = 0; i < row_width; i++)
  168559. {
  168560. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168561. if (shift == 4)
  168562. {
  168563. shift = 0;
  168564. sp--;
  168565. }
  168566. else
  168567. shift = 4;
  168568. dp--;
  168569. }
  168570. break;
  168571. }
  168572. }
  168573. row_info->bit_depth = 8;
  168574. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168575. row_info->rowbytes = row_width * row_info->channels;
  168576. }
  168577. }
  168578. #endif
  168579. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168580. void /* PRIVATE */
  168581. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168582. {
  168583. png_debug(1, "in png_do_unshift\n");
  168584. if (
  168585. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168586. row != NULL && row_info != NULL && sig_bits != NULL &&
  168587. #endif
  168588. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168589. {
  168590. int shift[4];
  168591. int channels = 0;
  168592. int c;
  168593. png_uint_16 value = 0;
  168594. png_uint_32 row_width = row_info->width;
  168595. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168596. {
  168597. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168598. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168599. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168600. }
  168601. else
  168602. {
  168603. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168604. }
  168605. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168606. {
  168607. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168608. }
  168609. for (c = 0; c < channels; c++)
  168610. {
  168611. if (shift[c] <= 0)
  168612. shift[c] = 0;
  168613. else
  168614. value = 1;
  168615. }
  168616. if (!value)
  168617. return;
  168618. switch (row_info->bit_depth)
  168619. {
  168620. case 2:
  168621. {
  168622. png_bytep bp;
  168623. png_uint_32 i;
  168624. png_uint_32 istop = row_info->rowbytes;
  168625. for (bp = row, i = 0; i < istop; i++)
  168626. {
  168627. *bp >>= 1;
  168628. *bp++ &= 0x55;
  168629. }
  168630. break;
  168631. }
  168632. case 4:
  168633. {
  168634. png_bytep bp = row;
  168635. png_uint_32 i;
  168636. png_uint_32 istop = row_info->rowbytes;
  168637. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168638. (png_byte)((int)0xf >> shift[0]));
  168639. for (i = 0; i < istop; i++)
  168640. {
  168641. *bp >>= shift[0];
  168642. *bp++ &= mask;
  168643. }
  168644. break;
  168645. }
  168646. case 8:
  168647. {
  168648. png_bytep bp = row;
  168649. png_uint_32 i;
  168650. png_uint_32 istop = row_width * channels;
  168651. for (i = 0; i < istop; i++)
  168652. {
  168653. *bp++ >>= shift[i%channels];
  168654. }
  168655. break;
  168656. }
  168657. case 16:
  168658. {
  168659. png_bytep bp = row;
  168660. png_uint_32 i;
  168661. png_uint_32 istop = channels * row_width;
  168662. for (i = 0; i < istop; i++)
  168663. {
  168664. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168665. value >>= shift[i%channels];
  168666. *bp++ = (png_byte)(value >> 8);
  168667. *bp++ = (png_byte)(value & 0xff);
  168668. }
  168669. break;
  168670. }
  168671. }
  168672. }
  168673. }
  168674. #endif
  168675. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168676. void /* PRIVATE */
  168677. png_do_chop(png_row_infop row_info, png_bytep row)
  168678. {
  168679. png_debug(1, "in png_do_chop\n");
  168680. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168681. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168682. #else
  168683. if (row_info->bit_depth == 16)
  168684. #endif
  168685. {
  168686. png_bytep sp = row;
  168687. png_bytep dp = row;
  168688. png_uint_32 i;
  168689. png_uint_32 istop = row_info->width * row_info->channels;
  168690. for (i = 0; i<istop; i++, sp += 2, dp++)
  168691. {
  168692. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168693. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168694. #else
  168695. *dp = *sp;
  168696. #endif
  168697. }
  168698. row_info->bit_depth = 8;
  168699. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168700. row_info->rowbytes = row_info->width * row_info->channels;
  168701. }
  168702. }
  168703. #endif
  168704. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168705. void /* PRIVATE */
  168706. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168707. {
  168708. png_debug(1, "in png_do_read_swap_alpha\n");
  168709. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168710. if (row != NULL && row_info != NULL)
  168711. #endif
  168712. {
  168713. png_uint_32 row_width = row_info->width;
  168714. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168715. {
  168716. if (row_info->bit_depth == 8)
  168717. {
  168718. png_bytep sp = row + row_info->rowbytes;
  168719. png_bytep dp = sp;
  168720. png_byte save;
  168721. png_uint_32 i;
  168722. for (i = 0; i < row_width; i++)
  168723. {
  168724. save = *(--sp);
  168725. *(--dp) = *(--sp);
  168726. *(--dp) = *(--sp);
  168727. *(--dp) = *(--sp);
  168728. *(--dp) = save;
  168729. }
  168730. }
  168731. else
  168732. {
  168733. png_bytep sp = row + row_info->rowbytes;
  168734. png_bytep dp = sp;
  168735. png_byte save[2];
  168736. png_uint_32 i;
  168737. for (i = 0; i < row_width; i++)
  168738. {
  168739. save[0] = *(--sp);
  168740. save[1] = *(--sp);
  168741. *(--dp) = *(--sp);
  168742. *(--dp) = *(--sp);
  168743. *(--dp) = *(--sp);
  168744. *(--dp) = *(--sp);
  168745. *(--dp) = *(--sp);
  168746. *(--dp) = *(--sp);
  168747. *(--dp) = save[0];
  168748. *(--dp) = save[1];
  168749. }
  168750. }
  168751. }
  168752. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168753. {
  168754. if (row_info->bit_depth == 8)
  168755. {
  168756. png_bytep sp = row + row_info->rowbytes;
  168757. png_bytep dp = sp;
  168758. png_byte save;
  168759. png_uint_32 i;
  168760. for (i = 0; i < row_width; i++)
  168761. {
  168762. save = *(--sp);
  168763. *(--dp) = *(--sp);
  168764. *(--dp) = save;
  168765. }
  168766. }
  168767. else
  168768. {
  168769. png_bytep sp = row + row_info->rowbytes;
  168770. png_bytep dp = sp;
  168771. png_byte save[2];
  168772. png_uint_32 i;
  168773. for (i = 0; i < row_width; i++)
  168774. {
  168775. save[0] = *(--sp);
  168776. save[1] = *(--sp);
  168777. *(--dp) = *(--sp);
  168778. *(--dp) = *(--sp);
  168779. *(--dp) = save[0];
  168780. *(--dp) = save[1];
  168781. }
  168782. }
  168783. }
  168784. }
  168785. }
  168786. #endif
  168787. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168788. void /* PRIVATE */
  168789. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168790. {
  168791. png_debug(1, "in png_do_read_invert_alpha\n");
  168792. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168793. if (row != NULL && row_info != NULL)
  168794. #endif
  168795. {
  168796. png_uint_32 row_width = row_info->width;
  168797. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168798. {
  168799. if (row_info->bit_depth == 8)
  168800. {
  168801. png_bytep sp = row + row_info->rowbytes;
  168802. png_bytep dp = sp;
  168803. png_uint_32 i;
  168804. for (i = 0; i < row_width; i++)
  168805. {
  168806. *(--dp) = (png_byte)(255 - *(--sp));
  168807. sp-=3;
  168808. dp=sp;
  168809. }
  168810. }
  168811. else
  168812. {
  168813. png_bytep sp = row + row_info->rowbytes;
  168814. png_bytep dp = sp;
  168815. png_uint_32 i;
  168816. for (i = 0; i < row_width; i++)
  168817. {
  168818. *(--dp) = (png_byte)(255 - *(--sp));
  168819. *(--dp) = (png_byte)(255 - *(--sp));
  168820. sp-=6;
  168821. dp=sp;
  168822. }
  168823. }
  168824. }
  168825. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168826. {
  168827. if (row_info->bit_depth == 8)
  168828. {
  168829. png_bytep sp = row + row_info->rowbytes;
  168830. png_bytep dp = sp;
  168831. png_uint_32 i;
  168832. for (i = 0; i < row_width; i++)
  168833. {
  168834. *(--dp) = (png_byte)(255 - *(--sp));
  168835. *(--dp) = *(--sp);
  168836. }
  168837. }
  168838. else
  168839. {
  168840. png_bytep sp = row + row_info->rowbytes;
  168841. png_bytep dp = sp;
  168842. png_uint_32 i;
  168843. for (i = 0; i < row_width; i++)
  168844. {
  168845. *(--dp) = (png_byte)(255 - *(--sp));
  168846. *(--dp) = (png_byte)(255 - *(--sp));
  168847. sp-=2;
  168848. dp=sp;
  168849. }
  168850. }
  168851. }
  168852. }
  168853. }
  168854. #endif
  168855. #if defined(PNG_READ_FILLER_SUPPORTED)
  168856. void /* PRIVATE */
  168857. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168858. png_uint_32 filler, png_uint_32 flags)
  168859. {
  168860. png_uint_32 i;
  168861. png_uint_32 row_width = row_info->width;
  168862. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168863. png_byte lo_filler = (png_byte)(filler & 0xff);
  168864. png_debug(1, "in png_do_read_filler\n");
  168865. if (
  168866. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168867. row != NULL && row_info != NULL &&
  168868. #endif
  168869. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168870. {
  168871. if(row_info->bit_depth == 8)
  168872. {
  168873. if (flags & PNG_FLAG_FILLER_AFTER)
  168874. {
  168875. png_bytep sp = row + (png_size_t)row_width;
  168876. png_bytep dp = sp + (png_size_t)row_width;
  168877. for (i = 1; i < row_width; i++)
  168878. {
  168879. *(--dp) = lo_filler;
  168880. *(--dp) = *(--sp);
  168881. }
  168882. *(--dp) = lo_filler;
  168883. row_info->channels = 2;
  168884. row_info->pixel_depth = 16;
  168885. row_info->rowbytes = row_width * 2;
  168886. }
  168887. else
  168888. {
  168889. png_bytep sp = row + (png_size_t)row_width;
  168890. png_bytep dp = sp + (png_size_t)row_width;
  168891. for (i = 0; i < row_width; i++)
  168892. {
  168893. *(--dp) = *(--sp);
  168894. *(--dp) = lo_filler;
  168895. }
  168896. row_info->channels = 2;
  168897. row_info->pixel_depth = 16;
  168898. row_info->rowbytes = row_width * 2;
  168899. }
  168900. }
  168901. else if(row_info->bit_depth == 16)
  168902. {
  168903. if (flags & PNG_FLAG_FILLER_AFTER)
  168904. {
  168905. png_bytep sp = row + (png_size_t)row_width * 2;
  168906. png_bytep dp = sp + (png_size_t)row_width * 2;
  168907. for (i = 1; i < row_width; i++)
  168908. {
  168909. *(--dp) = hi_filler;
  168910. *(--dp) = lo_filler;
  168911. *(--dp) = *(--sp);
  168912. *(--dp) = *(--sp);
  168913. }
  168914. *(--dp) = hi_filler;
  168915. *(--dp) = lo_filler;
  168916. row_info->channels = 2;
  168917. row_info->pixel_depth = 32;
  168918. row_info->rowbytes = row_width * 4;
  168919. }
  168920. else
  168921. {
  168922. png_bytep sp = row + (png_size_t)row_width * 2;
  168923. png_bytep dp = sp + (png_size_t)row_width * 2;
  168924. for (i = 0; i < row_width; i++)
  168925. {
  168926. *(--dp) = *(--sp);
  168927. *(--dp) = *(--sp);
  168928. *(--dp) = hi_filler;
  168929. *(--dp) = lo_filler;
  168930. }
  168931. row_info->channels = 2;
  168932. row_info->pixel_depth = 32;
  168933. row_info->rowbytes = row_width * 4;
  168934. }
  168935. }
  168936. } /* COLOR_TYPE == GRAY */
  168937. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168938. {
  168939. if(row_info->bit_depth == 8)
  168940. {
  168941. if (flags & PNG_FLAG_FILLER_AFTER)
  168942. {
  168943. png_bytep sp = row + (png_size_t)row_width * 3;
  168944. png_bytep dp = sp + (png_size_t)row_width;
  168945. for (i = 1; i < row_width; i++)
  168946. {
  168947. *(--dp) = lo_filler;
  168948. *(--dp) = *(--sp);
  168949. *(--dp) = *(--sp);
  168950. *(--dp) = *(--sp);
  168951. }
  168952. *(--dp) = lo_filler;
  168953. row_info->channels = 4;
  168954. row_info->pixel_depth = 32;
  168955. row_info->rowbytes = row_width * 4;
  168956. }
  168957. else
  168958. {
  168959. png_bytep sp = row + (png_size_t)row_width * 3;
  168960. png_bytep dp = sp + (png_size_t)row_width;
  168961. for (i = 0; i < row_width; i++)
  168962. {
  168963. *(--dp) = *(--sp);
  168964. *(--dp) = *(--sp);
  168965. *(--dp) = *(--sp);
  168966. *(--dp) = lo_filler;
  168967. }
  168968. row_info->channels = 4;
  168969. row_info->pixel_depth = 32;
  168970. row_info->rowbytes = row_width * 4;
  168971. }
  168972. }
  168973. else if(row_info->bit_depth == 16)
  168974. {
  168975. if (flags & PNG_FLAG_FILLER_AFTER)
  168976. {
  168977. png_bytep sp = row + (png_size_t)row_width * 6;
  168978. png_bytep dp = sp + (png_size_t)row_width * 2;
  168979. for (i = 1; i < row_width; i++)
  168980. {
  168981. *(--dp) = hi_filler;
  168982. *(--dp) = lo_filler;
  168983. *(--dp) = *(--sp);
  168984. *(--dp) = *(--sp);
  168985. *(--dp) = *(--sp);
  168986. *(--dp) = *(--sp);
  168987. *(--dp) = *(--sp);
  168988. *(--dp) = *(--sp);
  168989. }
  168990. *(--dp) = hi_filler;
  168991. *(--dp) = lo_filler;
  168992. row_info->channels = 4;
  168993. row_info->pixel_depth = 64;
  168994. row_info->rowbytes = row_width * 8;
  168995. }
  168996. else
  168997. {
  168998. png_bytep sp = row + (png_size_t)row_width * 6;
  168999. png_bytep dp = sp + (png_size_t)row_width * 2;
  169000. for (i = 0; i < row_width; i++)
  169001. {
  169002. *(--dp) = *(--sp);
  169003. *(--dp) = *(--sp);
  169004. *(--dp) = *(--sp);
  169005. *(--dp) = *(--sp);
  169006. *(--dp) = *(--sp);
  169007. *(--dp) = *(--sp);
  169008. *(--dp) = hi_filler;
  169009. *(--dp) = lo_filler;
  169010. }
  169011. row_info->channels = 4;
  169012. row_info->pixel_depth = 64;
  169013. row_info->rowbytes = row_width * 8;
  169014. }
  169015. }
  169016. } /* COLOR_TYPE == RGB */
  169017. }
  169018. #endif
  169019. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  169020. void /* PRIVATE */
  169021. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  169022. {
  169023. png_uint_32 i;
  169024. png_uint_32 row_width = row_info->width;
  169025. png_debug(1, "in png_do_gray_to_rgb\n");
  169026. if (row_info->bit_depth >= 8 &&
  169027. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169028. row != NULL && row_info != NULL &&
  169029. #endif
  169030. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  169031. {
  169032. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169033. {
  169034. if (row_info->bit_depth == 8)
  169035. {
  169036. png_bytep sp = row + (png_size_t)row_width - 1;
  169037. png_bytep dp = sp + (png_size_t)row_width * 2;
  169038. for (i = 0; i < row_width; i++)
  169039. {
  169040. *(dp--) = *sp;
  169041. *(dp--) = *sp;
  169042. *(dp--) = *(sp--);
  169043. }
  169044. }
  169045. else
  169046. {
  169047. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169048. png_bytep dp = sp + (png_size_t)row_width * 4;
  169049. for (i = 0; i < row_width; i++)
  169050. {
  169051. *(dp--) = *sp;
  169052. *(dp--) = *(sp - 1);
  169053. *(dp--) = *sp;
  169054. *(dp--) = *(sp - 1);
  169055. *(dp--) = *(sp--);
  169056. *(dp--) = *(sp--);
  169057. }
  169058. }
  169059. }
  169060. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169061. {
  169062. if (row_info->bit_depth == 8)
  169063. {
  169064. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169065. png_bytep dp = sp + (png_size_t)row_width * 2;
  169066. for (i = 0; i < row_width; i++)
  169067. {
  169068. *(dp--) = *(sp--);
  169069. *(dp--) = *sp;
  169070. *(dp--) = *sp;
  169071. *(dp--) = *(sp--);
  169072. }
  169073. }
  169074. else
  169075. {
  169076. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  169077. png_bytep dp = sp + (png_size_t)row_width * 4;
  169078. for (i = 0; i < row_width; i++)
  169079. {
  169080. *(dp--) = *(sp--);
  169081. *(dp--) = *(sp--);
  169082. *(dp--) = *sp;
  169083. *(dp--) = *(sp - 1);
  169084. *(dp--) = *sp;
  169085. *(dp--) = *(sp - 1);
  169086. *(dp--) = *(sp--);
  169087. *(dp--) = *(sp--);
  169088. }
  169089. }
  169090. }
  169091. row_info->channels += (png_byte)2;
  169092. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  169093. row_info->pixel_depth = (png_byte)(row_info->channels *
  169094. row_info->bit_depth);
  169095. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169096. }
  169097. }
  169098. #endif
  169099. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  169100. int /* PRIVATE */
  169101. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  169102. {
  169103. png_uint_32 i;
  169104. png_uint_32 row_width = row_info->width;
  169105. int rgb_error = 0;
  169106. png_debug(1, "in png_do_rgb_to_gray\n");
  169107. if (
  169108. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169109. row != NULL && row_info != NULL &&
  169110. #endif
  169111. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  169112. {
  169113. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  169114. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  169115. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  169116. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169117. {
  169118. if (row_info->bit_depth == 8)
  169119. {
  169120. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169121. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169122. {
  169123. png_bytep sp = row;
  169124. png_bytep dp = row;
  169125. for (i = 0; i < row_width; i++)
  169126. {
  169127. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169128. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169129. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169130. if(red != green || red != blue)
  169131. {
  169132. rgb_error |= 1;
  169133. *(dp++) = png_ptr->gamma_from_1[
  169134. (rc*red+gc*green+bc*blue)>>15];
  169135. }
  169136. else
  169137. *(dp++) = *(sp-1);
  169138. }
  169139. }
  169140. else
  169141. #endif
  169142. {
  169143. png_bytep sp = row;
  169144. png_bytep dp = row;
  169145. for (i = 0; i < row_width; i++)
  169146. {
  169147. png_byte red = *(sp++);
  169148. png_byte green = *(sp++);
  169149. png_byte blue = *(sp++);
  169150. if(red != green || red != blue)
  169151. {
  169152. rgb_error |= 1;
  169153. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  169154. }
  169155. else
  169156. *(dp++) = *(sp-1);
  169157. }
  169158. }
  169159. }
  169160. else /* RGB bit_depth == 16 */
  169161. {
  169162. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169163. if (png_ptr->gamma_16_to_1 != NULL &&
  169164. png_ptr->gamma_16_from_1 != NULL)
  169165. {
  169166. png_bytep sp = row;
  169167. png_bytep dp = row;
  169168. for (i = 0; i < row_width; i++)
  169169. {
  169170. png_uint_16 red, green, blue, w;
  169171. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169172. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169173. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169174. if(red == green && red == blue)
  169175. w = red;
  169176. else
  169177. {
  169178. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169179. png_ptr->gamma_shift][red>>8];
  169180. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169181. png_ptr->gamma_shift][green>>8];
  169182. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169183. png_ptr->gamma_shift][blue>>8];
  169184. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  169185. + bc*blue_1)>>15);
  169186. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169187. png_ptr->gamma_shift][gray16 >> 8];
  169188. rgb_error |= 1;
  169189. }
  169190. *(dp++) = (png_byte)((w>>8) & 0xff);
  169191. *(dp++) = (png_byte)(w & 0xff);
  169192. }
  169193. }
  169194. else
  169195. #endif
  169196. {
  169197. png_bytep sp = row;
  169198. png_bytep dp = row;
  169199. for (i = 0; i < row_width; i++)
  169200. {
  169201. png_uint_16 red, green, blue, gray16;
  169202. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169203. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169204. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169205. if(red != green || red != blue)
  169206. rgb_error |= 1;
  169207. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169208. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169209. *(dp++) = (png_byte)(gray16 & 0xff);
  169210. }
  169211. }
  169212. }
  169213. }
  169214. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169215. {
  169216. if (row_info->bit_depth == 8)
  169217. {
  169218. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169219. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169220. {
  169221. png_bytep sp = row;
  169222. png_bytep dp = row;
  169223. for (i = 0; i < row_width; i++)
  169224. {
  169225. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169226. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169227. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169228. if(red != green || red != blue)
  169229. rgb_error |= 1;
  169230. *(dp++) = png_ptr->gamma_from_1
  169231. [(rc*red + gc*green + bc*blue)>>15];
  169232. *(dp++) = *(sp++); /* alpha */
  169233. }
  169234. }
  169235. else
  169236. #endif
  169237. {
  169238. png_bytep sp = row;
  169239. png_bytep dp = row;
  169240. for (i = 0; i < row_width; i++)
  169241. {
  169242. png_byte red = *(sp++);
  169243. png_byte green = *(sp++);
  169244. png_byte blue = *(sp++);
  169245. if(red != green || red != blue)
  169246. rgb_error |= 1;
  169247. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  169248. *(dp++) = *(sp++); /* alpha */
  169249. }
  169250. }
  169251. }
  169252. else /* RGBA bit_depth == 16 */
  169253. {
  169254. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169255. if (png_ptr->gamma_16_to_1 != NULL &&
  169256. png_ptr->gamma_16_from_1 != NULL)
  169257. {
  169258. png_bytep sp = row;
  169259. png_bytep dp = row;
  169260. for (i = 0; i < row_width; i++)
  169261. {
  169262. png_uint_16 red, green, blue, w;
  169263. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169264. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169265. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169266. if(red == green && red == blue)
  169267. w = red;
  169268. else
  169269. {
  169270. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169271. png_ptr->gamma_shift][red>>8];
  169272. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169273. png_ptr->gamma_shift][green>>8];
  169274. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169275. png_ptr->gamma_shift][blue>>8];
  169276. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  169277. + gc * green_1 + bc * blue_1)>>15);
  169278. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169279. png_ptr->gamma_shift][gray16 >> 8];
  169280. rgb_error |= 1;
  169281. }
  169282. *(dp++) = (png_byte)((w>>8) & 0xff);
  169283. *(dp++) = (png_byte)(w & 0xff);
  169284. *(dp++) = *(sp++); /* alpha */
  169285. *(dp++) = *(sp++);
  169286. }
  169287. }
  169288. else
  169289. #endif
  169290. {
  169291. png_bytep sp = row;
  169292. png_bytep dp = row;
  169293. for (i = 0; i < row_width; i++)
  169294. {
  169295. png_uint_16 red, green, blue, gray16;
  169296. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169297. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169298. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169299. if(red != green || red != blue)
  169300. rgb_error |= 1;
  169301. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169302. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169303. *(dp++) = (png_byte)(gray16 & 0xff);
  169304. *(dp++) = *(sp++); /* alpha */
  169305. *(dp++) = *(sp++);
  169306. }
  169307. }
  169308. }
  169309. }
  169310. row_info->channels -= (png_byte)2;
  169311. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169312. row_info->pixel_depth = (png_byte)(row_info->channels *
  169313. row_info->bit_depth);
  169314. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169315. }
  169316. return rgb_error;
  169317. }
  169318. #endif
  169319. void PNGAPI
  169320. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169321. {
  169322. int num_palette;
  169323. int color_inc;
  169324. int i;
  169325. int v;
  169326. png_debug(1, "in png_do_build_grayscale_palette\n");
  169327. if (palette == NULL)
  169328. return;
  169329. switch (bit_depth)
  169330. {
  169331. case 1:
  169332. num_palette = 2;
  169333. color_inc = 0xff;
  169334. break;
  169335. case 2:
  169336. num_palette = 4;
  169337. color_inc = 0x55;
  169338. break;
  169339. case 4:
  169340. num_palette = 16;
  169341. color_inc = 0x11;
  169342. break;
  169343. case 8:
  169344. num_palette = 256;
  169345. color_inc = 1;
  169346. break;
  169347. default:
  169348. num_palette = 0;
  169349. color_inc = 0;
  169350. break;
  169351. }
  169352. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169353. {
  169354. palette[i].red = (png_byte)v;
  169355. palette[i].green = (png_byte)v;
  169356. palette[i].blue = (png_byte)v;
  169357. }
  169358. }
  169359. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169360. void /* PRIVATE */
  169361. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169362. int num_palette)
  169363. {
  169364. png_debug(1, "in png_correct_palette\n");
  169365. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169366. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169367. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169368. {
  169369. png_color back, back_1;
  169370. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169371. {
  169372. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169373. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169374. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169375. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169376. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169377. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169378. }
  169379. else
  169380. {
  169381. double g;
  169382. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169383. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169384. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169385. {
  169386. back.red = png_ptr->background.red;
  169387. back.green = png_ptr->background.green;
  169388. back.blue = png_ptr->background.blue;
  169389. }
  169390. else
  169391. {
  169392. back.red =
  169393. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169394. 255.0 + 0.5);
  169395. back.green =
  169396. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169397. 255.0 + 0.5);
  169398. back.blue =
  169399. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169400. 255.0 + 0.5);
  169401. }
  169402. g = 1.0 / png_ptr->background_gamma;
  169403. back_1.red =
  169404. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169405. 255.0 + 0.5);
  169406. back_1.green =
  169407. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169408. 255.0 + 0.5);
  169409. back_1.blue =
  169410. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169411. 255.0 + 0.5);
  169412. }
  169413. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169414. {
  169415. png_uint_32 i;
  169416. for (i = 0; i < (png_uint_32)num_palette; i++)
  169417. {
  169418. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169419. {
  169420. palette[i] = back;
  169421. }
  169422. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169423. {
  169424. png_byte v, w;
  169425. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169426. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169427. palette[i].red = png_ptr->gamma_from_1[w];
  169428. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169429. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169430. palette[i].green = png_ptr->gamma_from_1[w];
  169431. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169432. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169433. palette[i].blue = png_ptr->gamma_from_1[w];
  169434. }
  169435. else
  169436. {
  169437. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169438. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169439. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169440. }
  169441. }
  169442. }
  169443. else
  169444. {
  169445. int i;
  169446. for (i = 0; i < num_palette; i++)
  169447. {
  169448. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169449. {
  169450. palette[i] = back;
  169451. }
  169452. else
  169453. {
  169454. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169455. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169456. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169457. }
  169458. }
  169459. }
  169460. }
  169461. else
  169462. #endif
  169463. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169464. if (png_ptr->transformations & PNG_GAMMA)
  169465. {
  169466. int i;
  169467. for (i = 0; i < num_palette; i++)
  169468. {
  169469. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169470. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169471. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169472. }
  169473. }
  169474. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169475. else
  169476. #endif
  169477. #endif
  169478. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169479. if (png_ptr->transformations & PNG_BACKGROUND)
  169480. {
  169481. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169482. {
  169483. png_color back;
  169484. back.red = (png_byte)png_ptr->background.red;
  169485. back.green = (png_byte)png_ptr->background.green;
  169486. back.blue = (png_byte)png_ptr->background.blue;
  169487. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169488. {
  169489. if (png_ptr->trans[i] == 0)
  169490. {
  169491. palette[i].red = back.red;
  169492. palette[i].green = back.green;
  169493. palette[i].blue = back.blue;
  169494. }
  169495. else if (png_ptr->trans[i] != 0xff)
  169496. {
  169497. png_composite(palette[i].red, png_ptr->palette[i].red,
  169498. png_ptr->trans[i], back.red);
  169499. png_composite(palette[i].green, png_ptr->palette[i].green,
  169500. png_ptr->trans[i], back.green);
  169501. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169502. png_ptr->trans[i], back.blue);
  169503. }
  169504. }
  169505. }
  169506. else /* assume grayscale palette (what else could it be?) */
  169507. {
  169508. int i;
  169509. for (i = 0; i < num_palette; i++)
  169510. {
  169511. if (i == (png_byte)png_ptr->trans_values.gray)
  169512. {
  169513. palette[i].red = (png_byte)png_ptr->background.red;
  169514. palette[i].green = (png_byte)png_ptr->background.green;
  169515. palette[i].blue = (png_byte)png_ptr->background.blue;
  169516. }
  169517. }
  169518. }
  169519. }
  169520. #endif
  169521. }
  169522. #endif
  169523. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169524. void /* PRIVATE */
  169525. png_do_background(png_row_infop row_info, png_bytep row,
  169526. png_color_16p trans_values, png_color_16p background
  169527. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169528. , png_color_16p background_1,
  169529. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169530. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169531. png_uint_16pp gamma_16_to_1, int gamma_shift
  169532. #endif
  169533. )
  169534. {
  169535. png_bytep sp, dp;
  169536. png_uint_32 i;
  169537. png_uint_32 row_width=row_info->width;
  169538. int shift;
  169539. png_debug(1, "in png_do_background\n");
  169540. if (background != NULL &&
  169541. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169542. row != NULL && row_info != NULL &&
  169543. #endif
  169544. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169545. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169546. {
  169547. switch (row_info->color_type)
  169548. {
  169549. case PNG_COLOR_TYPE_GRAY:
  169550. {
  169551. switch (row_info->bit_depth)
  169552. {
  169553. case 1:
  169554. {
  169555. sp = row;
  169556. shift = 7;
  169557. for (i = 0; i < row_width; i++)
  169558. {
  169559. if ((png_uint_16)((*sp >> shift) & 0x01)
  169560. == trans_values->gray)
  169561. {
  169562. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169563. *sp |= (png_byte)(background->gray << shift);
  169564. }
  169565. if (!shift)
  169566. {
  169567. shift = 7;
  169568. sp++;
  169569. }
  169570. else
  169571. shift--;
  169572. }
  169573. break;
  169574. }
  169575. case 2:
  169576. {
  169577. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169578. if (gamma_table != NULL)
  169579. {
  169580. sp = row;
  169581. shift = 6;
  169582. for (i = 0; i < row_width; i++)
  169583. {
  169584. if ((png_uint_16)((*sp >> shift) & 0x03)
  169585. == trans_values->gray)
  169586. {
  169587. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169588. *sp |= (png_byte)(background->gray << shift);
  169589. }
  169590. else
  169591. {
  169592. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169593. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169594. (p << 4) | (p << 6)] >> 6) & 0x03);
  169595. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169596. *sp |= (png_byte)(g << shift);
  169597. }
  169598. if (!shift)
  169599. {
  169600. shift = 6;
  169601. sp++;
  169602. }
  169603. else
  169604. shift -= 2;
  169605. }
  169606. }
  169607. else
  169608. #endif
  169609. {
  169610. sp = row;
  169611. shift = 6;
  169612. for (i = 0; i < row_width; i++)
  169613. {
  169614. if ((png_uint_16)((*sp >> shift) & 0x03)
  169615. == trans_values->gray)
  169616. {
  169617. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169618. *sp |= (png_byte)(background->gray << shift);
  169619. }
  169620. if (!shift)
  169621. {
  169622. shift = 6;
  169623. sp++;
  169624. }
  169625. else
  169626. shift -= 2;
  169627. }
  169628. }
  169629. break;
  169630. }
  169631. case 4:
  169632. {
  169633. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169634. if (gamma_table != NULL)
  169635. {
  169636. sp = row;
  169637. shift = 4;
  169638. for (i = 0; i < row_width; i++)
  169639. {
  169640. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169641. == trans_values->gray)
  169642. {
  169643. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169644. *sp |= (png_byte)(background->gray << shift);
  169645. }
  169646. else
  169647. {
  169648. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169649. png_byte g = (png_byte)((gamma_table[p |
  169650. (p << 4)] >> 4) & 0x0f);
  169651. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169652. *sp |= (png_byte)(g << shift);
  169653. }
  169654. if (!shift)
  169655. {
  169656. shift = 4;
  169657. sp++;
  169658. }
  169659. else
  169660. shift -= 4;
  169661. }
  169662. }
  169663. else
  169664. #endif
  169665. {
  169666. sp = row;
  169667. shift = 4;
  169668. for (i = 0; i < row_width; i++)
  169669. {
  169670. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169671. == trans_values->gray)
  169672. {
  169673. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169674. *sp |= (png_byte)(background->gray << shift);
  169675. }
  169676. if (!shift)
  169677. {
  169678. shift = 4;
  169679. sp++;
  169680. }
  169681. else
  169682. shift -= 4;
  169683. }
  169684. }
  169685. break;
  169686. }
  169687. case 8:
  169688. {
  169689. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169690. if (gamma_table != NULL)
  169691. {
  169692. sp = row;
  169693. for (i = 0; i < row_width; i++, sp++)
  169694. {
  169695. if (*sp == trans_values->gray)
  169696. {
  169697. *sp = (png_byte)background->gray;
  169698. }
  169699. else
  169700. {
  169701. *sp = gamma_table[*sp];
  169702. }
  169703. }
  169704. }
  169705. else
  169706. #endif
  169707. {
  169708. sp = row;
  169709. for (i = 0; i < row_width; i++, sp++)
  169710. {
  169711. if (*sp == trans_values->gray)
  169712. {
  169713. *sp = (png_byte)background->gray;
  169714. }
  169715. }
  169716. }
  169717. break;
  169718. }
  169719. case 16:
  169720. {
  169721. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169722. if (gamma_16 != NULL)
  169723. {
  169724. sp = row;
  169725. for (i = 0; i < row_width; i++, sp += 2)
  169726. {
  169727. png_uint_16 v;
  169728. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169729. if (v == trans_values->gray)
  169730. {
  169731. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169732. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169733. }
  169734. else
  169735. {
  169736. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169737. *sp = (png_byte)((v >> 8) & 0xff);
  169738. *(sp + 1) = (png_byte)(v & 0xff);
  169739. }
  169740. }
  169741. }
  169742. else
  169743. #endif
  169744. {
  169745. sp = row;
  169746. for (i = 0; i < row_width; i++, sp += 2)
  169747. {
  169748. png_uint_16 v;
  169749. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169750. if (v == trans_values->gray)
  169751. {
  169752. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169753. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169754. }
  169755. }
  169756. }
  169757. break;
  169758. }
  169759. }
  169760. break;
  169761. }
  169762. case PNG_COLOR_TYPE_RGB:
  169763. {
  169764. if (row_info->bit_depth == 8)
  169765. {
  169766. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169767. if (gamma_table != NULL)
  169768. {
  169769. sp = row;
  169770. for (i = 0; i < row_width; i++, sp += 3)
  169771. {
  169772. if (*sp == trans_values->red &&
  169773. *(sp + 1) == trans_values->green &&
  169774. *(sp + 2) == trans_values->blue)
  169775. {
  169776. *sp = (png_byte)background->red;
  169777. *(sp + 1) = (png_byte)background->green;
  169778. *(sp + 2) = (png_byte)background->blue;
  169779. }
  169780. else
  169781. {
  169782. *sp = gamma_table[*sp];
  169783. *(sp + 1) = gamma_table[*(sp + 1)];
  169784. *(sp + 2) = gamma_table[*(sp + 2)];
  169785. }
  169786. }
  169787. }
  169788. else
  169789. #endif
  169790. {
  169791. sp = row;
  169792. for (i = 0; i < row_width; i++, sp += 3)
  169793. {
  169794. if (*sp == trans_values->red &&
  169795. *(sp + 1) == trans_values->green &&
  169796. *(sp + 2) == trans_values->blue)
  169797. {
  169798. *sp = (png_byte)background->red;
  169799. *(sp + 1) = (png_byte)background->green;
  169800. *(sp + 2) = (png_byte)background->blue;
  169801. }
  169802. }
  169803. }
  169804. }
  169805. else /* if (row_info->bit_depth == 16) */
  169806. {
  169807. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169808. if (gamma_16 != NULL)
  169809. {
  169810. sp = row;
  169811. for (i = 0; i < row_width; i++, sp += 6)
  169812. {
  169813. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169814. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169815. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169816. if (r == trans_values->red && g == trans_values->green &&
  169817. b == trans_values->blue)
  169818. {
  169819. *sp = (png_byte)((background->red >> 8) & 0xff);
  169820. *(sp + 1) = (png_byte)(background->red & 0xff);
  169821. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169822. *(sp + 3) = (png_byte)(background->green & 0xff);
  169823. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169824. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169825. }
  169826. else
  169827. {
  169828. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169829. *sp = (png_byte)((v >> 8) & 0xff);
  169830. *(sp + 1) = (png_byte)(v & 0xff);
  169831. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169832. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169833. *(sp + 3) = (png_byte)(v & 0xff);
  169834. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169835. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169836. *(sp + 5) = (png_byte)(v & 0xff);
  169837. }
  169838. }
  169839. }
  169840. else
  169841. #endif
  169842. {
  169843. sp = row;
  169844. for (i = 0; i < row_width; i++, sp += 6)
  169845. {
  169846. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169847. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169848. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169849. if (r == trans_values->red && g == trans_values->green &&
  169850. b == trans_values->blue)
  169851. {
  169852. *sp = (png_byte)((background->red >> 8) & 0xff);
  169853. *(sp + 1) = (png_byte)(background->red & 0xff);
  169854. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169855. *(sp + 3) = (png_byte)(background->green & 0xff);
  169856. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169857. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169858. }
  169859. }
  169860. }
  169861. }
  169862. break;
  169863. }
  169864. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169865. {
  169866. if (row_info->bit_depth == 8)
  169867. {
  169868. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169869. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169870. gamma_table != NULL)
  169871. {
  169872. sp = row;
  169873. dp = row;
  169874. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169875. {
  169876. png_uint_16 a = *(sp + 1);
  169877. if (a == 0xff)
  169878. {
  169879. *dp = gamma_table[*sp];
  169880. }
  169881. else if (a == 0)
  169882. {
  169883. *dp = (png_byte)background->gray;
  169884. }
  169885. else
  169886. {
  169887. png_byte v, w;
  169888. v = gamma_to_1[*sp];
  169889. png_composite(w, v, a, background_1->gray);
  169890. *dp = gamma_from_1[w];
  169891. }
  169892. }
  169893. }
  169894. else
  169895. #endif
  169896. {
  169897. sp = row;
  169898. dp = row;
  169899. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169900. {
  169901. png_byte a = *(sp + 1);
  169902. if (a == 0xff)
  169903. {
  169904. *dp = *sp;
  169905. }
  169906. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169907. else if (a == 0)
  169908. {
  169909. *dp = (png_byte)background->gray;
  169910. }
  169911. else
  169912. {
  169913. png_composite(*dp, *sp, a, background_1->gray);
  169914. }
  169915. #else
  169916. *dp = (png_byte)background->gray;
  169917. #endif
  169918. }
  169919. }
  169920. }
  169921. else /* if (png_ptr->bit_depth == 16) */
  169922. {
  169923. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169924. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169925. gamma_16_to_1 != NULL)
  169926. {
  169927. sp = row;
  169928. dp = row;
  169929. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169930. {
  169931. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169932. if (a == (png_uint_16)0xffff)
  169933. {
  169934. png_uint_16 v;
  169935. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169936. *dp = (png_byte)((v >> 8) & 0xff);
  169937. *(dp + 1) = (png_byte)(v & 0xff);
  169938. }
  169939. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169940. else if (a == 0)
  169941. #else
  169942. else
  169943. #endif
  169944. {
  169945. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169946. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169947. }
  169948. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169949. else
  169950. {
  169951. png_uint_16 g, v, w;
  169952. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169953. png_composite_16(v, g, a, background_1->gray);
  169954. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169955. *dp = (png_byte)((w >> 8) & 0xff);
  169956. *(dp + 1) = (png_byte)(w & 0xff);
  169957. }
  169958. #endif
  169959. }
  169960. }
  169961. else
  169962. #endif
  169963. {
  169964. sp = row;
  169965. dp = row;
  169966. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169967. {
  169968. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169969. if (a == (png_uint_16)0xffff)
  169970. {
  169971. png_memcpy(dp, sp, 2);
  169972. }
  169973. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169974. else if (a == 0)
  169975. #else
  169976. else
  169977. #endif
  169978. {
  169979. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169980. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169981. }
  169982. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169983. else
  169984. {
  169985. png_uint_16 g, v;
  169986. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169987. png_composite_16(v, g, a, background_1->gray);
  169988. *dp = (png_byte)((v >> 8) & 0xff);
  169989. *(dp + 1) = (png_byte)(v & 0xff);
  169990. }
  169991. #endif
  169992. }
  169993. }
  169994. }
  169995. break;
  169996. }
  169997. case PNG_COLOR_TYPE_RGB_ALPHA:
  169998. {
  169999. if (row_info->bit_depth == 8)
  170000. {
  170001. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170002. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170003. gamma_table != NULL)
  170004. {
  170005. sp = row;
  170006. dp = row;
  170007. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170008. {
  170009. png_byte a = *(sp + 3);
  170010. if (a == 0xff)
  170011. {
  170012. *dp = gamma_table[*sp];
  170013. *(dp + 1) = gamma_table[*(sp + 1)];
  170014. *(dp + 2) = gamma_table[*(sp + 2)];
  170015. }
  170016. else if (a == 0)
  170017. {
  170018. *dp = (png_byte)background->red;
  170019. *(dp + 1) = (png_byte)background->green;
  170020. *(dp + 2) = (png_byte)background->blue;
  170021. }
  170022. else
  170023. {
  170024. png_byte v, w;
  170025. v = gamma_to_1[*sp];
  170026. png_composite(w, v, a, background_1->red);
  170027. *dp = gamma_from_1[w];
  170028. v = gamma_to_1[*(sp + 1)];
  170029. png_composite(w, v, a, background_1->green);
  170030. *(dp + 1) = gamma_from_1[w];
  170031. v = gamma_to_1[*(sp + 2)];
  170032. png_composite(w, v, a, background_1->blue);
  170033. *(dp + 2) = gamma_from_1[w];
  170034. }
  170035. }
  170036. }
  170037. else
  170038. #endif
  170039. {
  170040. sp = row;
  170041. dp = row;
  170042. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170043. {
  170044. png_byte a = *(sp + 3);
  170045. if (a == 0xff)
  170046. {
  170047. *dp = *sp;
  170048. *(dp + 1) = *(sp + 1);
  170049. *(dp + 2) = *(sp + 2);
  170050. }
  170051. else if (a == 0)
  170052. {
  170053. *dp = (png_byte)background->red;
  170054. *(dp + 1) = (png_byte)background->green;
  170055. *(dp + 2) = (png_byte)background->blue;
  170056. }
  170057. else
  170058. {
  170059. png_composite(*dp, *sp, a, background->red);
  170060. png_composite(*(dp + 1), *(sp + 1), a,
  170061. background->green);
  170062. png_composite(*(dp + 2), *(sp + 2), a,
  170063. background->blue);
  170064. }
  170065. }
  170066. }
  170067. }
  170068. else /* if (row_info->bit_depth == 16) */
  170069. {
  170070. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170071. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170072. gamma_16_to_1 != NULL)
  170073. {
  170074. sp = row;
  170075. dp = row;
  170076. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170077. {
  170078. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170079. << 8) + (png_uint_16)(*(sp + 7)));
  170080. if (a == (png_uint_16)0xffff)
  170081. {
  170082. png_uint_16 v;
  170083. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170084. *dp = (png_byte)((v >> 8) & 0xff);
  170085. *(dp + 1) = (png_byte)(v & 0xff);
  170086. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170087. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170088. *(dp + 3) = (png_byte)(v & 0xff);
  170089. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170090. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170091. *(dp + 5) = (png_byte)(v & 0xff);
  170092. }
  170093. else if (a == 0)
  170094. {
  170095. *dp = (png_byte)((background->red >> 8) & 0xff);
  170096. *(dp + 1) = (png_byte)(background->red & 0xff);
  170097. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170098. *(dp + 3) = (png_byte)(background->green & 0xff);
  170099. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170100. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170101. }
  170102. else
  170103. {
  170104. png_uint_16 v, w, x;
  170105. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170106. png_composite_16(w, v, a, background_1->red);
  170107. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170108. *dp = (png_byte)((x >> 8) & 0xff);
  170109. *(dp + 1) = (png_byte)(x & 0xff);
  170110. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170111. png_composite_16(w, v, a, background_1->green);
  170112. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170113. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  170114. *(dp + 3) = (png_byte)(x & 0xff);
  170115. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170116. png_composite_16(w, v, a, background_1->blue);
  170117. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  170118. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  170119. *(dp + 5) = (png_byte)(x & 0xff);
  170120. }
  170121. }
  170122. }
  170123. else
  170124. #endif
  170125. {
  170126. sp = row;
  170127. dp = row;
  170128. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170129. {
  170130. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170131. << 8) + (png_uint_16)(*(sp + 7)));
  170132. if (a == (png_uint_16)0xffff)
  170133. {
  170134. png_memcpy(dp, sp, 6);
  170135. }
  170136. else if (a == 0)
  170137. {
  170138. *dp = (png_byte)((background->red >> 8) & 0xff);
  170139. *(dp + 1) = (png_byte)(background->red & 0xff);
  170140. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170141. *(dp + 3) = (png_byte)(background->green & 0xff);
  170142. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170143. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170144. }
  170145. else
  170146. {
  170147. png_uint_16 v;
  170148. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170149. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  170150. + *(sp + 3));
  170151. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  170152. + *(sp + 5));
  170153. png_composite_16(v, r, a, background->red);
  170154. *dp = (png_byte)((v >> 8) & 0xff);
  170155. *(dp + 1) = (png_byte)(v & 0xff);
  170156. png_composite_16(v, g, a, background->green);
  170157. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170158. *(dp + 3) = (png_byte)(v & 0xff);
  170159. png_composite_16(v, b, a, background->blue);
  170160. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170161. *(dp + 5) = (png_byte)(v & 0xff);
  170162. }
  170163. }
  170164. }
  170165. }
  170166. break;
  170167. }
  170168. }
  170169. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  170170. {
  170171. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  170172. row_info->channels--;
  170173. row_info->pixel_depth = (png_byte)(row_info->channels *
  170174. row_info->bit_depth);
  170175. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170176. }
  170177. }
  170178. }
  170179. #endif
  170180. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170181. void /* PRIVATE */
  170182. png_do_gamma(png_row_infop row_info, png_bytep row,
  170183. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  170184. int gamma_shift)
  170185. {
  170186. png_bytep sp;
  170187. png_uint_32 i;
  170188. png_uint_32 row_width=row_info->width;
  170189. png_debug(1, "in png_do_gamma\n");
  170190. if (
  170191. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170192. row != NULL && row_info != NULL &&
  170193. #endif
  170194. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  170195. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  170196. {
  170197. switch (row_info->color_type)
  170198. {
  170199. case PNG_COLOR_TYPE_RGB:
  170200. {
  170201. if (row_info->bit_depth == 8)
  170202. {
  170203. sp = row;
  170204. for (i = 0; i < row_width; i++)
  170205. {
  170206. *sp = gamma_table[*sp];
  170207. sp++;
  170208. *sp = gamma_table[*sp];
  170209. sp++;
  170210. *sp = gamma_table[*sp];
  170211. sp++;
  170212. }
  170213. }
  170214. else /* if (row_info->bit_depth == 16) */
  170215. {
  170216. sp = row;
  170217. for (i = 0; i < row_width; i++)
  170218. {
  170219. png_uint_16 v;
  170220. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170221. *sp = (png_byte)((v >> 8) & 0xff);
  170222. *(sp + 1) = (png_byte)(v & 0xff);
  170223. sp += 2;
  170224. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170225. *sp = (png_byte)((v >> 8) & 0xff);
  170226. *(sp + 1) = (png_byte)(v & 0xff);
  170227. sp += 2;
  170228. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170229. *sp = (png_byte)((v >> 8) & 0xff);
  170230. *(sp + 1) = (png_byte)(v & 0xff);
  170231. sp += 2;
  170232. }
  170233. }
  170234. break;
  170235. }
  170236. case PNG_COLOR_TYPE_RGB_ALPHA:
  170237. {
  170238. if (row_info->bit_depth == 8)
  170239. {
  170240. sp = row;
  170241. for (i = 0; i < row_width; i++)
  170242. {
  170243. *sp = gamma_table[*sp];
  170244. sp++;
  170245. *sp = gamma_table[*sp];
  170246. sp++;
  170247. *sp = gamma_table[*sp];
  170248. sp++;
  170249. sp++;
  170250. }
  170251. }
  170252. else /* if (row_info->bit_depth == 16) */
  170253. {
  170254. sp = row;
  170255. for (i = 0; i < row_width; i++)
  170256. {
  170257. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170258. *sp = (png_byte)((v >> 8) & 0xff);
  170259. *(sp + 1) = (png_byte)(v & 0xff);
  170260. sp += 2;
  170261. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170262. *sp = (png_byte)((v >> 8) & 0xff);
  170263. *(sp + 1) = (png_byte)(v & 0xff);
  170264. sp += 2;
  170265. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170266. *sp = (png_byte)((v >> 8) & 0xff);
  170267. *(sp + 1) = (png_byte)(v & 0xff);
  170268. sp += 4;
  170269. }
  170270. }
  170271. break;
  170272. }
  170273. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170274. {
  170275. if (row_info->bit_depth == 8)
  170276. {
  170277. sp = row;
  170278. for (i = 0; i < row_width; i++)
  170279. {
  170280. *sp = gamma_table[*sp];
  170281. sp += 2;
  170282. }
  170283. }
  170284. else /* if (row_info->bit_depth == 16) */
  170285. {
  170286. sp = row;
  170287. for (i = 0; i < row_width; i++)
  170288. {
  170289. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170290. *sp = (png_byte)((v >> 8) & 0xff);
  170291. *(sp + 1) = (png_byte)(v & 0xff);
  170292. sp += 4;
  170293. }
  170294. }
  170295. break;
  170296. }
  170297. case PNG_COLOR_TYPE_GRAY:
  170298. {
  170299. if (row_info->bit_depth == 2)
  170300. {
  170301. sp = row;
  170302. for (i = 0; i < row_width; i += 4)
  170303. {
  170304. int a = *sp & 0xc0;
  170305. int b = *sp & 0x30;
  170306. int c = *sp & 0x0c;
  170307. int d = *sp & 0x03;
  170308. *sp = (png_byte)(
  170309. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170310. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170311. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170312. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170313. sp++;
  170314. }
  170315. }
  170316. if (row_info->bit_depth == 4)
  170317. {
  170318. sp = row;
  170319. for (i = 0; i < row_width; i += 2)
  170320. {
  170321. int msb = *sp & 0xf0;
  170322. int lsb = *sp & 0x0f;
  170323. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170324. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170325. sp++;
  170326. }
  170327. }
  170328. else if (row_info->bit_depth == 8)
  170329. {
  170330. sp = row;
  170331. for (i = 0; i < row_width; i++)
  170332. {
  170333. *sp = gamma_table[*sp];
  170334. sp++;
  170335. }
  170336. }
  170337. else if (row_info->bit_depth == 16)
  170338. {
  170339. sp = row;
  170340. for (i = 0; i < row_width; i++)
  170341. {
  170342. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170343. *sp = (png_byte)((v >> 8) & 0xff);
  170344. *(sp + 1) = (png_byte)(v & 0xff);
  170345. sp += 2;
  170346. }
  170347. }
  170348. break;
  170349. }
  170350. }
  170351. }
  170352. }
  170353. #endif
  170354. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170355. void /* PRIVATE */
  170356. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170357. png_colorp palette, png_bytep trans, int num_trans)
  170358. {
  170359. int shift, value;
  170360. png_bytep sp, dp;
  170361. png_uint_32 i;
  170362. png_uint_32 row_width=row_info->width;
  170363. png_debug(1, "in png_do_expand_palette\n");
  170364. if (
  170365. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170366. row != NULL && row_info != NULL &&
  170367. #endif
  170368. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170369. {
  170370. if (row_info->bit_depth < 8)
  170371. {
  170372. switch (row_info->bit_depth)
  170373. {
  170374. case 1:
  170375. {
  170376. sp = row + (png_size_t)((row_width - 1) >> 3);
  170377. dp = row + (png_size_t)row_width - 1;
  170378. shift = 7 - (int)((row_width + 7) & 0x07);
  170379. for (i = 0; i < row_width; i++)
  170380. {
  170381. if ((*sp >> shift) & 0x01)
  170382. *dp = 1;
  170383. else
  170384. *dp = 0;
  170385. if (shift == 7)
  170386. {
  170387. shift = 0;
  170388. sp--;
  170389. }
  170390. else
  170391. shift++;
  170392. dp--;
  170393. }
  170394. break;
  170395. }
  170396. case 2:
  170397. {
  170398. sp = row + (png_size_t)((row_width - 1) >> 2);
  170399. dp = row + (png_size_t)row_width - 1;
  170400. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170401. for (i = 0; i < row_width; i++)
  170402. {
  170403. value = (*sp >> shift) & 0x03;
  170404. *dp = (png_byte)value;
  170405. if (shift == 6)
  170406. {
  170407. shift = 0;
  170408. sp--;
  170409. }
  170410. else
  170411. shift += 2;
  170412. dp--;
  170413. }
  170414. break;
  170415. }
  170416. case 4:
  170417. {
  170418. sp = row + (png_size_t)((row_width - 1) >> 1);
  170419. dp = row + (png_size_t)row_width - 1;
  170420. shift = (int)((row_width & 0x01) << 2);
  170421. for (i = 0; i < row_width; i++)
  170422. {
  170423. value = (*sp >> shift) & 0x0f;
  170424. *dp = (png_byte)value;
  170425. if (shift == 4)
  170426. {
  170427. shift = 0;
  170428. sp--;
  170429. }
  170430. else
  170431. shift += 4;
  170432. dp--;
  170433. }
  170434. break;
  170435. }
  170436. }
  170437. row_info->bit_depth = 8;
  170438. row_info->pixel_depth = 8;
  170439. row_info->rowbytes = row_width;
  170440. }
  170441. switch (row_info->bit_depth)
  170442. {
  170443. case 8:
  170444. {
  170445. if (trans != NULL)
  170446. {
  170447. sp = row + (png_size_t)row_width - 1;
  170448. dp = row + (png_size_t)(row_width << 2) - 1;
  170449. for (i = 0; i < row_width; i++)
  170450. {
  170451. if ((int)(*sp) >= num_trans)
  170452. *dp-- = 0xff;
  170453. else
  170454. *dp-- = trans[*sp];
  170455. *dp-- = palette[*sp].blue;
  170456. *dp-- = palette[*sp].green;
  170457. *dp-- = palette[*sp].red;
  170458. sp--;
  170459. }
  170460. row_info->bit_depth = 8;
  170461. row_info->pixel_depth = 32;
  170462. row_info->rowbytes = row_width * 4;
  170463. row_info->color_type = 6;
  170464. row_info->channels = 4;
  170465. }
  170466. else
  170467. {
  170468. sp = row + (png_size_t)row_width - 1;
  170469. dp = row + (png_size_t)(row_width * 3) - 1;
  170470. for (i = 0; i < row_width; i++)
  170471. {
  170472. *dp-- = palette[*sp].blue;
  170473. *dp-- = palette[*sp].green;
  170474. *dp-- = palette[*sp].red;
  170475. sp--;
  170476. }
  170477. row_info->bit_depth = 8;
  170478. row_info->pixel_depth = 24;
  170479. row_info->rowbytes = row_width * 3;
  170480. row_info->color_type = 2;
  170481. row_info->channels = 3;
  170482. }
  170483. break;
  170484. }
  170485. }
  170486. }
  170487. }
  170488. void /* PRIVATE */
  170489. png_do_expand(png_row_infop row_info, png_bytep row,
  170490. png_color_16p trans_value)
  170491. {
  170492. int shift, value;
  170493. png_bytep sp, dp;
  170494. png_uint_32 i;
  170495. png_uint_32 row_width=row_info->width;
  170496. png_debug(1, "in png_do_expand\n");
  170497. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170498. if (row != NULL && row_info != NULL)
  170499. #endif
  170500. {
  170501. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170502. {
  170503. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170504. if (row_info->bit_depth < 8)
  170505. {
  170506. switch (row_info->bit_depth)
  170507. {
  170508. case 1:
  170509. {
  170510. gray = (png_uint_16)((gray&0x01)*0xff);
  170511. sp = row + (png_size_t)((row_width - 1) >> 3);
  170512. dp = row + (png_size_t)row_width - 1;
  170513. shift = 7 - (int)((row_width + 7) & 0x07);
  170514. for (i = 0; i < row_width; i++)
  170515. {
  170516. if ((*sp >> shift) & 0x01)
  170517. *dp = 0xff;
  170518. else
  170519. *dp = 0;
  170520. if (shift == 7)
  170521. {
  170522. shift = 0;
  170523. sp--;
  170524. }
  170525. else
  170526. shift++;
  170527. dp--;
  170528. }
  170529. break;
  170530. }
  170531. case 2:
  170532. {
  170533. gray = (png_uint_16)((gray&0x03)*0x55);
  170534. sp = row + (png_size_t)((row_width - 1) >> 2);
  170535. dp = row + (png_size_t)row_width - 1;
  170536. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170537. for (i = 0; i < row_width; i++)
  170538. {
  170539. value = (*sp >> shift) & 0x03;
  170540. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170541. (value << 6));
  170542. if (shift == 6)
  170543. {
  170544. shift = 0;
  170545. sp--;
  170546. }
  170547. else
  170548. shift += 2;
  170549. dp--;
  170550. }
  170551. break;
  170552. }
  170553. case 4:
  170554. {
  170555. gray = (png_uint_16)((gray&0x0f)*0x11);
  170556. sp = row + (png_size_t)((row_width - 1) >> 1);
  170557. dp = row + (png_size_t)row_width - 1;
  170558. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170559. for (i = 0; i < row_width; i++)
  170560. {
  170561. value = (*sp >> shift) & 0x0f;
  170562. *dp = (png_byte)(value | (value << 4));
  170563. if (shift == 4)
  170564. {
  170565. shift = 0;
  170566. sp--;
  170567. }
  170568. else
  170569. shift = 4;
  170570. dp--;
  170571. }
  170572. break;
  170573. }
  170574. }
  170575. row_info->bit_depth = 8;
  170576. row_info->pixel_depth = 8;
  170577. row_info->rowbytes = row_width;
  170578. }
  170579. if (trans_value != NULL)
  170580. {
  170581. if (row_info->bit_depth == 8)
  170582. {
  170583. gray = gray & 0xff;
  170584. sp = row + (png_size_t)row_width - 1;
  170585. dp = row + (png_size_t)(row_width << 1) - 1;
  170586. for (i = 0; i < row_width; i++)
  170587. {
  170588. if (*sp == gray)
  170589. *dp-- = 0;
  170590. else
  170591. *dp-- = 0xff;
  170592. *dp-- = *sp--;
  170593. }
  170594. }
  170595. else if (row_info->bit_depth == 16)
  170596. {
  170597. png_byte gray_high = (gray >> 8) & 0xff;
  170598. png_byte gray_low = gray & 0xff;
  170599. sp = row + row_info->rowbytes - 1;
  170600. dp = row + (row_info->rowbytes << 1) - 1;
  170601. for (i = 0; i < row_width; i++)
  170602. {
  170603. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170604. {
  170605. *dp-- = 0;
  170606. *dp-- = 0;
  170607. }
  170608. else
  170609. {
  170610. *dp-- = 0xff;
  170611. *dp-- = 0xff;
  170612. }
  170613. *dp-- = *sp--;
  170614. *dp-- = *sp--;
  170615. }
  170616. }
  170617. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170618. row_info->channels = 2;
  170619. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170620. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170621. row_width);
  170622. }
  170623. }
  170624. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170625. {
  170626. if (row_info->bit_depth == 8)
  170627. {
  170628. png_byte red = trans_value->red & 0xff;
  170629. png_byte green = trans_value->green & 0xff;
  170630. png_byte blue = trans_value->blue & 0xff;
  170631. sp = row + (png_size_t)row_info->rowbytes - 1;
  170632. dp = row + (png_size_t)(row_width << 2) - 1;
  170633. for (i = 0; i < row_width; i++)
  170634. {
  170635. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170636. *dp-- = 0;
  170637. else
  170638. *dp-- = 0xff;
  170639. *dp-- = *sp--;
  170640. *dp-- = *sp--;
  170641. *dp-- = *sp--;
  170642. }
  170643. }
  170644. else if (row_info->bit_depth == 16)
  170645. {
  170646. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170647. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170648. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170649. png_byte red_low = trans_value->red & 0xff;
  170650. png_byte green_low = trans_value->green & 0xff;
  170651. png_byte blue_low = trans_value->blue & 0xff;
  170652. sp = row + row_info->rowbytes - 1;
  170653. dp = row + (png_size_t)(row_width << 3) - 1;
  170654. for (i = 0; i < row_width; i++)
  170655. {
  170656. if (*(sp - 5) == red_high &&
  170657. *(sp - 4) == red_low &&
  170658. *(sp - 3) == green_high &&
  170659. *(sp - 2) == green_low &&
  170660. *(sp - 1) == blue_high &&
  170661. *(sp ) == blue_low)
  170662. {
  170663. *dp-- = 0;
  170664. *dp-- = 0;
  170665. }
  170666. else
  170667. {
  170668. *dp-- = 0xff;
  170669. *dp-- = 0xff;
  170670. }
  170671. *dp-- = *sp--;
  170672. *dp-- = *sp--;
  170673. *dp-- = *sp--;
  170674. *dp-- = *sp--;
  170675. *dp-- = *sp--;
  170676. *dp-- = *sp--;
  170677. }
  170678. }
  170679. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170680. row_info->channels = 4;
  170681. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170682. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170683. }
  170684. }
  170685. }
  170686. #endif
  170687. #if defined(PNG_READ_DITHER_SUPPORTED)
  170688. void /* PRIVATE */
  170689. png_do_dither(png_row_infop row_info, png_bytep row,
  170690. png_bytep palette_lookup, png_bytep dither_lookup)
  170691. {
  170692. png_bytep sp, dp;
  170693. png_uint_32 i;
  170694. png_uint_32 row_width=row_info->width;
  170695. png_debug(1, "in png_do_dither\n");
  170696. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170697. if (row != NULL && row_info != NULL)
  170698. #endif
  170699. {
  170700. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170701. palette_lookup && row_info->bit_depth == 8)
  170702. {
  170703. int r, g, b, p;
  170704. sp = row;
  170705. dp = row;
  170706. for (i = 0; i < row_width; i++)
  170707. {
  170708. r = *sp++;
  170709. g = *sp++;
  170710. b = *sp++;
  170711. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170712. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170713. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170714. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170715. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170716. (PNG_DITHER_BLUE_BITS)) |
  170717. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170718. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170719. *dp++ = palette_lookup[p];
  170720. }
  170721. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170722. row_info->channels = 1;
  170723. row_info->pixel_depth = row_info->bit_depth;
  170724. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170725. }
  170726. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170727. palette_lookup != NULL && row_info->bit_depth == 8)
  170728. {
  170729. int r, g, b, p;
  170730. sp = row;
  170731. dp = row;
  170732. for (i = 0; i < row_width; i++)
  170733. {
  170734. r = *sp++;
  170735. g = *sp++;
  170736. b = *sp++;
  170737. sp++;
  170738. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170739. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170740. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170741. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170742. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170743. (PNG_DITHER_BLUE_BITS)) |
  170744. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170745. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170746. *dp++ = palette_lookup[p];
  170747. }
  170748. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170749. row_info->channels = 1;
  170750. row_info->pixel_depth = row_info->bit_depth;
  170751. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170752. }
  170753. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170754. dither_lookup && row_info->bit_depth == 8)
  170755. {
  170756. sp = row;
  170757. for (i = 0; i < row_width; i++, sp++)
  170758. {
  170759. *sp = dither_lookup[*sp];
  170760. }
  170761. }
  170762. }
  170763. }
  170764. #endif
  170765. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170766. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170767. static PNG_CONST int png_gamma_shift[] =
  170768. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170769. void /* PRIVATE */
  170770. png_build_gamma_table(png_structp png_ptr)
  170771. {
  170772. png_debug(1, "in png_build_gamma_table\n");
  170773. if (png_ptr->bit_depth <= 8)
  170774. {
  170775. int i;
  170776. double g;
  170777. if (png_ptr->screen_gamma > .000001)
  170778. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170779. else
  170780. g = 1.0;
  170781. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170782. (png_uint_32)256);
  170783. for (i = 0; i < 256; i++)
  170784. {
  170785. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170786. g) * 255.0 + .5);
  170787. }
  170788. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170789. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170790. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170791. {
  170792. g = 1.0 / (png_ptr->gamma);
  170793. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170794. (png_uint_32)256);
  170795. for (i = 0; i < 256; i++)
  170796. {
  170797. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170798. g) * 255.0 + .5);
  170799. }
  170800. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170801. (png_uint_32)256);
  170802. if(png_ptr->screen_gamma > 0.000001)
  170803. g = 1.0 / png_ptr->screen_gamma;
  170804. else
  170805. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170806. for (i = 0; i < 256; i++)
  170807. {
  170808. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170809. g) * 255.0 + .5);
  170810. }
  170811. }
  170812. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170813. }
  170814. else
  170815. {
  170816. double g;
  170817. int i, j, shift, num;
  170818. int sig_bit;
  170819. png_uint_32 ig;
  170820. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170821. {
  170822. sig_bit = (int)png_ptr->sig_bit.red;
  170823. if ((int)png_ptr->sig_bit.green > sig_bit)
  170824. sig_bit = png_ptr->sig_bit.green;
  170825. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170826. sig_bit = png_ptr->sig_bit.blue;
  170827. }
  170828. else
  170829. {
  170830. sig_bit = (int)png_ptr->sig_bit.gray;
  170831. }
  170832. if (sig_bit > 0)
  170833. shift = 16 - sig_bit;
  170834. else
  170835. shift = 0;
  170836. if (png_ptr->transformations & PNG_16_TO_8)
  170837. {
  170838. if (shift < (16 - PNG_MAX_GAMMA_8))
  170839. shift = (16 - PNG_MAX_GAMMA_8);
  170840. }
  170841. if (shift > 8)
  170842. shift = 8;
  170843. if (shift < 0)
  170844. shift = 0;
  170845. png_ptr->gamma_shift = (png_byte)shift;
  170846. num = (1 << (8 - shift));
  170847. if (png_ptr->screen_gamma > .000001)
  170848. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170849. else
  170850. g = 1.0;
  170851. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170852. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170853. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170854. {
  170855. double fin, fout;
  170856. png_uint_32 last, max;
  170857. for (i = 0; i < num; i++)
  170858. {
  170859. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170860. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170861. }
  170862. g = 1.0 / g;
  170863. last = 0;
  170864. for (i = 0; i < 256; i++)
  170865. {
  170866. fout = ((double)i + 0.5) / 256.0;
  170867. fin = pow(fout, g);
  170868. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170869. while (last <= max)
  170870. {
  170871. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170872. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170873. (png_uint_16)i | ((png_uint_16)i << 8));
  170874. last++;
  170875. }
  170876. }
  170877. while (last < ((png_uint_32)num << 8))
  170878. {
  170879. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170880. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170881. last++;
  170882. }
  170883. }
  170884. else
  170885. {
  170886. for (i = 0; i < num; i++)
  170887. {
  170888. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170889. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170890. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170891. for (j = 0; j < 256; j++)
  170892. {
  170893. png_ptr->gamma_16_table[i][j] =
  170894. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170895. 65535.0, g) * 65535.0 + .5);
  170896. }
  170897. }
  170898. }
  170899. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170900. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170901. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170902. {
  170903. g = 1.0 / (png_ptr->gamma);
  170904. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170905. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170906. for (i = 0; i < num; i++)
  170907. {
  170908. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170909. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170910. ig = (((png_uint_32)i *
  170911. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170912. for (j = 0; j < 256; j++)
  170913. {
  170914. png_ptr->gamma_16_to_1[i][j] =
  170915. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170916. 65535.0, g) * 65535.0 + .5);
  170917. }
  170918. }
  170919. if(png_ptr->screen_gamma > 0.000001)
  170920. g = 1.0 / png_ptr->screen_gamma;
  170921. else
  170922. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170923. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170924. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170925. for (i = 0; i < num; i++)
  170926. {
  170927. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170928. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170929. ig = (((png_uint_32)i *
  170930. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170931. for (j = 0; j < 256; j++)
  170932. {
  170933. png_ptr->gamma_16_from_1[i][j] =
  170934. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170935. 65535.0, g) * 65535.0 + .5);
  170936. }
  170937. }
  170938. }
  170939. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170940. }
  170941. }
  170942. #endif
  170943. #endif
  170944. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170945. void /* PRIVATE */
  170946. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170947. {
  170948. png_debug(1, "in png_do_read_intrapixel\n");
  170949. if (
  170950. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170951. row != NULL && row_info != NULL &&
  170952. #endif
  170953. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170954. {
  170955. int bytes_per_pixel;
  170956. png_uint_32 row_width = row_info->width;
  170957. if (row_info->bit_depth == 8)
  170958. {
  170959. png_bytep rp;
  170960. png_uint_32 i;
  170961. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170962. bytes_per_pixel = 3;
  170963. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170964. bytes_per_pixel = 4;
  170965. else
  170966. return;
  170967. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170968. {
  170969. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170970. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170971. }
  170972. }
  170973. else if (row_info->bit_depth == 16)
  170974. {
  170975. png_bytep rp;
  170976. png_uint_32 i;
  170977. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170978. bytes_per_pixel = 6;
  170979. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170980. bytes_per_pixel = 8;
  170981. else
  170982. return;
  170983. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170984. {
  170985. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170986. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170987. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170988. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170989. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170990. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170991. *(rp+1) = (png_byte)(red & 0xff);
  170992. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170993. *(rp+5) = (png_byte)(blue & 0xff);
  170994. }
  170995. }
  170996. }
  170997. }
  170998. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170999. #endif /* PNG_READ_SUPPORTED */
  171000. /*** End of inlined file: pngrtran.c ***/
  171001. /*** Start of inlined file: pngrutil.c ***/
  171002. #define PNG_INTERNAL
  171003. #if defined(PNG_READ_SUPPORTED)
  171004. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  171005. # define WIN32_WCE_OLD
  171006. #endif
  171007. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171008. # if defined(WIN32_WCE_OLD)
  171009. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  171010. {
  171011. double result = 0;
  171012. int len;
  171013. wchar_t *str, *end;
  171014. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  171015. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  171016. if ( NULL != str )
  171017. {
  171018. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  171019. result = wcstod(str, &end);
  171020. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  171021. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  171022. png_free(png_ptr, str);
  171023. }
  171024. return result;
  171025. }
  171026. # else
  171027. # define png_strtod(p,a,b) strtod(a,b)
  171028. # endif
  171029. #endif
  171030. png_uint_32 PNGAPI
  171031. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  171032. {
  171033. png_uint_32 i = png_get_uint_32(buf);
  171034. if (i > PNG_UINT_31_MAX)
  171035. png_error(png_ptr, "PNG unsigned integer out of range.");
  171036. return (i);
  171037. }
  171038. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  171039. png_uint_32 PNGAPI
  171040. png_get_uint_32(png_bytep buf)
  171041. {
  171042. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  171043. ((png_uint_32)(*(buf + 1)) << 16) +
  171044. ((png_uint_32)(*(buf + 2)) << 8) +
  171045. (png_uint_32)(*(buf + 3));
  171046. return (i);
  171047. }
  171048. png_int_32 PNGAPI
  171049. png_get_int_32(png_bytep buf)
  171050. {
  171051. png_int_32 i = ((png_int_32)(*buf) << 24) +
  171052. ((png_int_32)(*(buf + 1)) << 16) +
  171053. ((png_int_32)(*(buf + 2)) << 8) +
  171054. (png_int_32)(*(buf + 3));
  171055. return (i);
  171056. }
  171057. png_uint_16 PNGAPI
  171058. png_get_uint_16(png_bytep buf)
  171059. {
  171060. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  171061. (png_uint_16)(*(buf + 1)));
  171062. return (i);
  171063. }
  171064. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  171065. void /* PRIVATE */
  171066. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  171067. {
  171068. if(png_ptr == NULL) return;
  171069. png_read_data(png_ptr, buf, length);
  171070. png_calculate_crc(png_ptr, buf, length);
  171071. }
  171072. int /* PRIVATE */
  171073. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  171074. {
  171075. png_size_t i;
  171076. png_size_t istop = png_ptr->zbuf_size;
  171077. for (i = (png_size_t)skip; i > istop; i -= istop)
  171078. {
  171079. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  171080. }
  171081. if (i)
  171082. {
  171083. png_crc_read(png_ptr, png_ptr->zbuf, i);
  171084. }
  171085. if (png_crc_error(png_ptr))
  171086. {
  171087. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  171088. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  171089. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  171090. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  171091. {
  171092. png_chunk_warning(png_ptr, "CRC error");
  171093. }
  171094. else
  171095. {
  171096. png_chunk_error(png_ptr, "CRC error");
  171097. }
  171098. return (1);
  171099. }
  171100. return (0);
  171101. }
  171102. int /* PRIVATE */
  171103. png_crc_error(png_structp png_ptr)
  171104. {
  171105. png_byte crc_bytes[4];
  171106. png_uint_32 crc;
  171107. int need_crc = 1;
  171108. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  171109. {
  171110. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  171111. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171112. need_crc = 0;
  171113. }
  171114. else /* critical */
  171115. {
  171116. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  171117. need_crc = 0;
  171118. }
  171119. png_read_data(png_ptr, crc_bytes, 4);
  171120. if (need_crc)
  171121. {
  171122. crc = png_get_uint_32(crc_bytes);
  171123. return ((int)(crc != png_ptr->crc));
  171124. }
  171125. else
  171126. return (0);
  171127. }
  171128. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  171129. defined(PNG_READ_iCCP_SUPPORTED)
  171130. png_charp /* PRIVATE */
  171131. png_decompress_chunk(png_structp png_ptr, int comp_type,
  171132. png_charp chunkdata, png_size_t chunklength,
  171133. png_size_t prefix_size, png_size_t *newlength)
  171134. {
  171135. static PNG_CONST char msg[] = "Error decoding compressed text";
  171136. png_charp text;
  171137. png_size_t text_size;
  171138. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  171139. {
  171140. int ret = Z_OK;
  171141. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  171142. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  171143. png_ptr->zstream.next_out = png_ptr->zbuf;
  171144. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171145. text_size = 0;
  171146. text = NULL;
  171147. while (png_ptr->zstream.avail_in)
  171148. {
  171149. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  171150. if (ret != Z_OK && ret != Z_STREAM_END)
  171151. {
  171152. if (png_ptr->zstream.msg != NULL)
  171153. png_warning(png_ptr, png_ptr->zstream.msg);
  171154. else
  171155. png_warning(png_ptr, msg);
  171156. inflateReset(&png_ptr->zstream);
  171157. png_ptr->zstream.avail_in = 0;
  171158. if (text == NULL)
  171159. {
  171160. text_size = prefix_size + png_sizeof(msg) + 1;
  171161. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  171162. if (text == NULL)
  171163. {
  171164. png_free(png_ptr,chunkdata);
  171165. png_error(png_ptr,"Not enough memory to decompress chunk");
  171166. }
  171167. png_memcpy(text, chunkdata, prefix_size);
  171168. }
  171169. text[text_size - 1] = 0x00;
  171170. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  171171. text_size = png_sizeof(msg) > text_size ? text_size :
  171172. png_sizeof(msg);
  171173. png_memcpy(text + prefix_size, msg, text_size + 1);
  171174. break;
  171175. }
  171176. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  171177. {
  171178. if (text == NULL)
  171179. {
  171180. text_size = prefix_size +
  171181. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171182. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  171183. if (text == NULL)
  171184. {
  171185. png_free(png_ptr,chunkdata);
  171186. png_error(png_ptr,"Not enough memory to decompress chunk.");
  171187. }
  171188. png_memcpy(text + prefix_size, png_ptr->zbuf,
  171189. text_size - prefix_size);
  171190. png_memcpy(text, chunkdata, prefix_size);
  171191. *(text + text_size) = 0x00;
  171192. }
  171193. else
  171194. {
  171195. png_charp tmp;
  171196. tmp = text;
  171197. text = (png_charp)png_malloc_warn(png_ptr,
  171198. (png_uint_32)(text_size +
  171199. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  171200. if (text == NULL)
  171201. {
  171202. png_free(png_ptr, tmp);
  171203. png_free(png_ptr, chunkdata);
  171204. png_error(png_ptr,"Not enough memory to decompress chunk..");
  171205. }
  171206. png_memcpy(text, tmp, text_size);
  171207. png_free(png_ptr, tmp);
  171208. png_memcpy(text + text_size, png_ptr->zbuf,
  171209. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  171210. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171211. *(text + text_size) = 0x00;
  171212. }
  171213. if (ret == Z_STREAM_END)
  171214. break;
  171215. else
  171216. {
  171217. png_ptr->zstream.next_out = png_ptr->zbuf;
  171218. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171219. }
  171220. }
  171221. }
  171222. if (ret != Z_STREAM_END)
  171223. {
  171224. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171225. char umsg[52];
  171226. if (ret == Z_BUF_ERROR)
  171227. png_snprintf(umsg, 52,
  171228. "Buffer error in compressed datastream in %s chunk",
  171229. png_ptr->chunk_name);
  171230. else if (ret == Z_DATA_ERROR)
  171231. png_snprintf(umsg, 52,
  171232. "Data error in compressed datastream in %s chunk",
  171233. png_ptr->chunk_name);
  171234. else
  171235. png_snprintf(umsg, 52,
  171236. "Incomplete compressed datastream in %s chunk",
  171237. png_ptr->chunk_name);
  171238. png_warning(png_ptr, umsg);
  171239. #else
  171240. png_warning(png_ptr,
  171241. "Incomplete compressed datastream in chunk other than IDAT");
  171242. #endif
  171243. text_size=prefix_size;
  171244. if (text == NULL)
  171245. {
  171246. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  171247. if (text == NULL)
  171248. {
  171249. png_free(png_ptr, chunkdata);
  171250. png_error(png_ptr,"Not enough memory for text.");
  171251. }
  171252. png_memcpy(text, chunkdata, prefix_size);
  171253. }
  171254. *(text + text_size) = 0x00;
  171255. }
  171256. inflateReset(&png_ptr->zstream);
  171257. png_ptr->zstream.avail_in = 0;
  171258. png_free(png_ptr, chunkdata);
  171259. chunkdata = text;
  171260. *newlength=text_size;
  171261. }
  171262. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  171263. {
  171264. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171265. char umsg[50];
  171266. png_snprintf(umsg, 50,
  171267. "Unknown zTXt compression type %d", comp_type);
  171268. png_warning(png_ptr, umsg);
  171269. #else
  171270. png_warning(png_ptr, "Unknown zTXt compression type");
  171271. #endif
  171272. *(chunkdata + prefix_size) = 0x00;
  171273. *newlength=prefix_size;
  171274. }
  171275. return chunkdata;
  171276. }
  171277. #endif
  171278. void /* PRIVATE */
  171279. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171280. {
  171281. png_byte buf[13];
  171282. png_uint_32 width, height;
  171283. int bit_depth, color_type, compression_type, filter_type;
  171284. int interlace_type;
  171285. png_debug(1, "in png_handle_IHDR\n");
  171286. if (png_ptr->mode & PNG_HAVE_IHDR)
  171287. png_error(png_ptr, "Out of place IHDR");
  171288. if (length != 13)
  171289. png_error(png_ptr, "Invalid IHDR chunk");
  171290. png_ptr->mode |= PNG_HAVE_IHDR;
  171291. png_crc_read(png_ptr, buf, 13);
  171292. png_crc_finish(png_ptr, 0);
  171293. width = png_get_uint_31(png_ptr, buf);
  171294. height = png_get_uint_31(png_ptr, buf + 4);
  171295. bit_depth = buf[8];
  171296. color_type = buf[9];
  171297. compression_type = buf[10];
  171298. filter_type = buf[11];
  171299. interlace_type = buf[12];
  171300. png_ptr->width = width;
  171301. png_ptr->height = height;
  171302. png_ptr->bit_depth = (png_byte)bit_depth;
  171303. png_ptr->interlaced = (png_byte)interlace_type;
  171304. png_ptr->color_type = (png_byte)color_type;
  171305. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171306. png_ptr->filter_type = (png_byte)filter_type;
  171307. #endif
  171308. png_ptr->compression_type = (png_byte)compression_type;
  171309. switch (png_ptr->color_type)
  171310. {
  171311. case PNG_COLOR_TYPE_GRAY:
  171312. case PNG_COLOR_TYPE_PALETTE:
  171313. png_ptr->channels = 1;
  171314. break;
  171315. case PNG_COLOR_TYPE_RGB:
  171316. png_ptr->channels = 3;
  171317. break;
  171318. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171319. png_ptr->channels = 2;
  171320. break;
  171321. case PNG_COLOR_TYPE_RGB_ALPHA:
  171322. png_ptr->channels = 4;
  171323. break;
  171324. }
  171325. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171326. png_ptr->channels);
  171327. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171328. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171329. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171330. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171331. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171332. color_type, interlace_type, compression_type, filter_type);
  171333. }
  171334. void /* PRIVATE */
  171335. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171336. {
  171337. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171338. int num, i;
  171339. #ifndef PNG_NO_POINTER_INDEXING
  171340. png_colorp pal_ptr;
  171341. #endif
  171342. png_debug(1, "in png_handle_PLTE\n");
  171343. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171344. png_error(png_ptr, "Missing IHDR before PLTE");
  171345. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171346. {
  171347. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171348. png_crc_finish(png_ptr, length);
  171349. return;
  171350. }
  171351. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171352. png_error(png_ptr, "Duplicate PLTE chunk");
  171353. png_ptr->mode |= PNG_HAVE_PLTE;
  171354. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171355. {
  171356. png_warning(png_ptr,
  171357. "Ignoring PLTE chunk in grayscale PNG");
  171358. png_crc_finish(png_ptr, length);
  171359. return;
  171360. }
  171361. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171362. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171363. {
  171364. png_crc_finish(png_ptr, length);
  171365. return;
  171366. }
  171367. #endif
  171368. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171369. {
  171370. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171371. {
  171372. png_warning(png_ptr, "Invalid palette chunk");
  171373. png_crc_finish(png_ptr, length);
  171374. return;
  171375. }
  171376. else
  171377. {
  171378. png_error(png_ptr, "Invalid palette chunk");
  171379. }
  171380. }
  171381. num = (int)length / 3;
  171382. #ifndef PNG_NO_POINTER_INDEXING
  171383. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171384. {
  171385. png_byte buf[3];
  171386. png_crc_read(png_ptr, buf, 3);
  171387. pal_ptr->red = buf[0];
  171388. pal_ptr->green = buf[1];
  171389. pal_ptr->blue = buf[2];
  171390. }
  171391. #else
  171392. for (i = 0; i < num; i++)
  171393. {
  171394. png_byte buf[3];
  171395. png_crc_read(png_ptr, buf, 3);
  171396. palette[i].red = buf[0];
  171397. palette[i].green = buf[1];
  171398. palette[i].blue = buf[2];
  171399. }
  171400. #endif
  171401. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171402. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171403. #endif
  171404. {
  171405. png_crc_finish(png_ptr, 0);
  171406. }
  171407. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171408. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171409. {
  171410. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171411. {
  171412. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171413. {
  171414. png_chunk_error(png_ptr, "CRC error");
  171415. }
  171416. else
  171417. {
  171418. png_chunk_warning(png_ptr, "CRC error");
  171419. return;
  171420. }
  171421. }
  171422. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171423. {
  171424. png_chunk_warning(png_ptr, "CRC error");
  171425. }
  171426. }
  171427. #endif
  171428. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171429. #if defined(PNG_READ_tRNS_SUPPORTED)
  171430. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171431. {
  171432. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171433. {
  171434. if (png_ptr->num_trans > (png_uint_16)num)
  171435. {
  171436. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171437. png_ptr->num_trans = (png_uint_16)num;
  171438. }
  171439. if (info_ptr->num_trans > (png_uint_16)num)
  171440. {
  171441. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171442. info_ptr->num_trans = (png_uint_16)num;
  171443. }
  171444. }
  171445. }
  171446. #endif
  171447. }
  171448. void /* PRIVATE */
  171449. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171450. {
  171451. png_debug(1, "in png_handle_IEND\n");
  171452. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171453. {
  171454. png_error(png_ptr, "No image in file");
  171455. }
  171456. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171457. if (length != 0)
  171458. {
  171459. png_warning(png_ptr, "Incorrect IEND chunk length");
  171460. }
  171461. png_crc_finish(png_ptr, length);
  171462. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171463. }
  171464. #if defined(PNG_READ_gAMA_SUPPORTED)
  171465. void /* PRIVATE */
  171466. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171467. {
  171468. png_fixed_point igamma;
  171469. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171470. float file_gamma;
  171471. #endif
  171472. png_byte buf[4];
  171473. png_debug(1, "in png_handle_gAMA\n");
  171474. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171475. png_error(png_ptr, "Missing IHDR before gAMA");
  171476. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171477. {
  171478. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171479. png_crc_finish(png_ptr, length);
  171480. return;
  171481. }
  171482. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171483. png_warning(png_ptr, "Out of place gAMA chunk");
  171484. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171485. #if defined(PNG_READ_sRGB_SUPPORTED)
  171486. && !(info_ptr->valid & PNG_INFO_sRGB)
  171487. #endif
  171488. )
  171489. {
  171490. png_warning(png_ptr, "Duplicate gAMA chunk");
  171491. png_crc_finish(png_ptr, length);
  171492. return;
  171493. }
  171494. if (length != 4)
  171495. {
  171496. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171497. png_crc_finish(png_ptr, length);
  171498. return;
  171499. }
  171500. png_crc_read(png_ptr, buf, 4);
  171501. if (png_crc_finish(png_ptr, 0))
  171502. return;
  171503. igamma = (png_fixed_point)png_get_uint_32(buf);
  171504. if (igamma == 0)
  171505. {
  171506. png_warning(png_ptr,
  171507. "Ignoring gAMA chunk with gamma=0");
  171508. return;
  171509. }
  171510. #if defined(PNG_READ_sRGB_SUPPORTED)
  171511. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171512. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171513. {
  171514. png_warning(png_ptr,
  171515. "Ignoring incorrect gAMA value when sRGB is also present");
  171516. #ifndef PNG_NO_CONSOLE_IO
  171517. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171518. #endif
  171519. return;
  171520. }
  171521. #endif /* PNG_READ_sRGB_SUPPORTED */
  171522. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171523. file_gamma = (float)igamma / (float)100000.0;
  171524. # ifdef PNG_READ_GAMMA_SUPPORTED
  171525. png_ptr->gamma = file_gamma;
  171526. # endif
  171527. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171528. #endif
  171529. #ifdef PNG_FIXED_POINT_SUPPORTED
  171530. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171531. #endif
  171532. }
  171533. #endif
  171534. #if defined(PNG_READ_sBIT_SUPPORTED)
  171535. void /* PRIVATE */
  171536. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171537. {
  171538. png_size_t truelen;
  171539. png_byte buf[4];
  171540. png_debug(1, "in png_handle_sBIT\n");
  171541. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171542. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171543. png_error(png_ptr, "Missing IHDR before sBIT");
  171544. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171545. {
  171546. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171547. png_crc_finish(png_ptr, length);
  171548. return;
  171549. }
  171550. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171551. {
  171552. png_warning(png_ptr, "Out of place sBIT chunk");
  171553. }
  171554. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171555. {
  171556. png_warning(png_ptr, "Duplicate sBIT chunk");
  171557. png_crc_finish(png_ptr, length);
  171558. return;
  171559. }
  171560. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171561. truelen = 3;
  171562. else
  171563. truelen = (png_size_t)png_ptr->channels;
  171564. if (length != truelen || length > 4)
  171565. {
  171566. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171567. png_crc_finish(png_ptr, length);
  171568. return;
  171569. }
  171570. png_crc_read(png_ptr, buf, truelen);
  171571. if (png_crc_finish(png_ptr, 0))
  171572. return;
  171573. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171574. {
  171575. png_ptr->sig_bit.red = buf[0];
  171576. png_ptr->sig_bit.green = buf[1];
  171577. png_ptr->sig_bit.blue = buf[2];
  171578. png_ptr->sig_bit.alpha = buf[3];
  171579. }
  171580. else
  171581. {
  171582. png_ptr->sig_bit.gray = buf[0];
  171583. png_ptr->sig_bit.red = buf[0];
  171584. png_ptr->sig_bit.green = buf[0];
  171585. png_ptr->sig_bit.blue = buf[0];
  171586. png_ptr->sig_bit.alpha = buf[1];
  171587. }
  171588. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171589. }
  171590. #endif
  171591. #if defined(PNG_READ_cHRM_SUPPORTED)
  171592. void /* PRIVATE */
  171593. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171594. {
  171595. png_byte buf[4];
  171596. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171597. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171598. #endif
  171599. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171600. int_y_green, int_x_blue, int_y_blue;
  171601. png_uint_32 uint_x, uint_y;
  171602. png_debug(1, "in png_handle_cHRM\n");
  171603. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171604. png_error(png_ptr, "Missing IHDR before cHRM");
  171605. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171606. {
  171607. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171608. png_crc_finish(png_ptr, length);
  171609. return;
  171610. }
  171611. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171612. png_warning(png_ptr, "Missing PLTE before cHRM");
  171613. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171614. #if defined(PNG_READ_sRGB_SUPPORTED)
  171615. && !(info_ptr->valid & PNG_INFO_sRGB)
  171616. #endif
  171617. )
  171618. {
  171619. png_warning(png_ptr, "Duplicate cHRM chunk");
  171620. png_crc_finish(png_ptr, length);
  171621. return;
  171622. }
  171623. if (length != 32)
  171624. {
  171625. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171626. png_crc_finish(png_ptr, length);
  171627. return;
  171628. }
  171629. png_crc_read(png_ptr, buf, 4);
  171630. uint_x = png_get_uint_32(buf);
  171631. png_crc_read(png_ptr, buf, 4);
  171632. uint_y = png_get_uint_32(buf);
  171633. if (uint_x > 80000L || uint_y > 80000L ||
  171634. uint_x + uint_y > 100000L)
  171635. {
  171636. png_warning(png_ptr, "Invalid cHRM white point");
  171637. png_crc_finish(png_ptr, 24);
  171638. return;
  171639. }
  171640. int_x_white = (png_fixed_point)uint_x;
  171641. int_y_white = (png_fixed_point)uint_y;
  171642. png_crc_read(png_ptr, buf, 4);
  171643. uint_x = png_get_uint_32(buf);
  171644. png_crc_read(png_ptr, buf, 4);
  171645. uint_y = png_get_uint_32(buf);
  171646. if (uint_x + uint_y > 100000L)
  171647. {
  171648. png_warning(png_ptr, "Invalid cHRM red point");
  171649. png_crc_finish(png_ptr, 16);
  171650. return;
  171651. }
  171652. int_x_red = (png_fixed_point)uint_x;
  171653. int_y_red = (png_fixed_point)uint_y;
  171654. png_crc_read(png_ptr, buf, 4);
  171655. uint_x = png_get_uint_32(buf);
  171656. png_crc_read(png_ptr, buf, 4);
  171657. uint_y = png_get_uint_32(buf);
  171658. if (uint_x + uint_y > 100000L)
  171659. {
  171660. png_warning(png_ptr, "Invalid cHRM green point");
  171661. png_crc_finish(png_ptr, 8);
  171662. return;
  171663. }
  171664. int_x_green = (png_fixed_point)uint_x;
  171665. int_y_green = (png_fixed_point)uint_y;
  171666. png_crc_read(png_ptr, buf, 4);
  171667. uint_x = png_get_uint_32(buf);
  171668. png_crc_read(png_ptr, buf, 4);
  171669. uint_y = png_get_uint_32(buf);
  171670. if (uint_x + uint_y > 100000L)
  171671. {
  171672. png_warning(png_ptr, "Invalid cHRM blue point");
  171673. png_crc_finish(png_ptr, 0);
  171674. return;
  171675. }
  171676. int_x_blue = (png_fixed_point)uint_x;
  171677. int_y_blue = (png_fixed_point)uint_y;
  171678. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171679. white_x = (float)int_x_white / (float)100000.0;
  171680. white_y = (float)int_y_white / (float)100000.0;
  171681. red_x = (float)int_x_red / (float)100000.0;
  171682. red_y = (float)int_y_red / (float)100000.0;
  171683. green_x = (float)int_x_green / (float)100000.0;
  171684. green_y = (float)int_y_green / (float)100000.0;
  171685. blue_x = (float)int_x_blue / (float)100000.0;
  171686. blue_y = (float)int_y_blue / (float)100000.0;
  171687. #endif
  171688. #if defined(PNG_READ_sRGB_SUPPORTED)
  171689. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171690. {
  171691. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171692. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171693. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171694. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171695. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171696. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171697. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171698. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171699. {
  171700. png_warning(png_ptr,
  171701. "Ignoring incorrect cHRM value when sRGB is also present");
  171702. #ifndef PNG_NO_CONSOLE_IO
  171703. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171704. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171705. white_x, white_y, red_x, red_y);
  171706. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171707. green_x, green_y, blue_x, blue_y);
  171708. #else
  171709. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171710. int_x_white, int_y_white, int_x_red, int_y_red);
  171711. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171712. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171713. #endif
  171714. #endif /* PNG_NO_CONSOLE_IO */
  171715. }
  171716. png_crc_finish(png_ptr, 0);
  171717. return;
  171718. }
  171719. #endif /* PNG_READ_sRGB_SUPPORTED */
  171720. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171721. png_set_cHRM(png_ptr, info_ptr,
  171722. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171723. #endif
  171724. #ifdef PNG_FIXED_POINT_SUPPORTED
  171725. png_set_cHRM_fixed(png_ptr, info_ptr,
  171726. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171727. int_y_green, int_x_blue, int_y_blue);
  171728. #endif
  171729. if (png_crc_finish(png_ptr, 0))
  171730. return;
  171731. }
  171732. #endif
  171733. #if defined(PNG_READ_sRGB_SUPPORTED)
  171734. void /* PRIVATE */
  171735. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171736. {
  171737. int intent;
  171738. png_byte buf[1];
  171739. png_debug(1, "in png_handle_sRGB\n");
  171740. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171741. png_error(png_ptr, "Missing IHDR before sRGB");
  171742. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171743. {
  171744. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171745. png_crc_finish(png_ptr, length);
  171746. return;
  171747. }
  171748. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171749. png_warning(png_ptr, "Out of place sRGB chunk");
  171750. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171751. {
  171752. png_warning(png_ptr, "Duplicate sRGB chunk");
  171753. png_crc_finish(png_ptr, length);
  171754. return;
  171755. }
  171756. if (length != 1)
  171757. {
  171758. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171759. png_crc_finish(png_ptr, length);
  171760. return;
  171761. }
  171762. png_crc_read(png_ptr, buf, 1);
  171763. if (png_crc_finish(png_ptr, 0))
  171764. return;
  171765. intent = buf[0];
  171766. if (intent >= PNG_sRGB_INTENT_LAST)
  171767. {
  171768. png_warning(png_ptr, "Unknown sRGB intent");
  171769. return;
  171770. }
  171771. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171772. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171773. {
  171774. png_fixed_point igamma;
  171775. #ifdef PNG_FIXED_POINT_SUPPORTED
  171776. igamma=info_ptr->int_gamma;
  171777. #else
  171778. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171779. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171780. # endif
  171781. #endif
  171782. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171783. {
  171784. png_warning(png_ptr,
  171785. "Ignoring incorrect gAMA value when sRGB is also present");
  171786. #ifndef PNG_NO_CONSOLE_IO
  171787. # ifdef PNG_FIXED_POINT_SUPPORTED
  171788. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171789. # else
  171790. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171791. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171792. # endif
  171793. # endif
  171794. #endif
  171795. }
  171796. }
  171797. #endif /* PNG_READ_gAMA_SUPPORTED */
  171798. #ifdef PNG_READ_cHRM_SUPPORTED
  171799. #ifdef PNG_FIXED_POINT_SUPPORTED
  171800. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171801. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171802. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171803. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171804. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171805. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171806. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171807. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171808. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171809. {
  171810. png_warning(png_ptr,
  171811. "Ignoring incorrect cHRM value when sRGB is also present");
  171812. }
  171813. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171814. #endif /* PNG_READ_cHRM_SUPPORTED */
  171815. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171816. }
  171817. #endif /* PNG_READ_sRGB_SUPPORTED */
  171818. #if defined(PNG_READ_iCCP_SUPPORTED)
  171819. void /* PRIVATE */
  171820. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171821. {
  171822. png_charp chunkdata;
  171823. png_byte compression_type;
  171824. png_bytep pC;
  171825. png_charp profile;
  171826. png_uint_32 skip = 0;
  171827. png_uint_32 profile_size, profile_length;
  171828. png_size_t slength, prefix_length, data_length;
  171829. png_debug(1, "in png_handle_iCCP\n");
  171830. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171831. png_error(png_ptr, "Missing IHDR before iCCP");
  171832. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171833. {
  171834. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171835. png_crc_finish(png_ptr, length);
  171836. return;
  171837. }
  171838. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171839. png_warning(png_ptr, "Out of place iCCP chunk");
  171840. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171841. {
  171842. png_warning(png_ptr, "Duplicate iCCP chunk");
  171843. png_crc_finish(png_ptr, length);
  171844. return;
  171845. }
  171846. #ifdef PNG_MAX_MALLOC_64K
  171847. if (length > (png_uint_32)65535L)
  171848. {
  171849. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171850. skip = length - (png_uint_32)65535L;
  171851. length = (png_uint_32)65535L;
  171852. }
  171853. #endif
  171854. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171855. slength = (png_size_t)length;
  171856. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171857. if (png_crc_finish(png_ptr, skip))
  171858. {
  171859. png_free(png_ptr, chunkdata);
  171860. return;
  171861. }
  171862. chunkdata[slength] = 0x00;
  171863. for (profile = chunkdata; *profile; profile++)
  171864. ;
  171865. ++profile;
  171866. if ( profile >= chunkdata + slength - 1)
  171867. {
  171868. png_free(png_ptr, chunkdata);
  171869. png_warning(png_ptr, "Malformed iCCP chunk");
  171870. return;
  171871. }
  171872. compression_type = *profile++;
  171873. if (compression_type)
  171874. {
  171875. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171876. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171877. wrote nonzero) */
  171878. }
  171879. prefix_length = profile - chunkdata;
  171880. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171881. slength, prefix_length, &data_length);
  171882. profile_length = data_length - prefix_length;
  171883. if ( prefix_length > data_length || profile_length < 4)
  171884. {
  171885. png_free(png_ptr, chunkdata);
  171886. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171887. return;
  171888. }
  171889. pC = (png_bytep)(chunkdata+prefix_length);
  171890. profile_size = ((*(pC ))<<24) |
  171891. ((*(pC+1))<<16) |
  171892. ((*(pC+2))<< 8) |
  171893. ((*(pC+3)) );
  171894. if(profile_size < profile_length)
  171895. profile_length = profile_size;
  171896. if(profile_size > profile_length)
  171897. {
  171898. png_free(png_ptr, chunkdata);
  171899. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171900. return;
  171901. }
  171902. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171903. chunkdata + prefix_length, profile_length);
  171904. png_free(png_ptr, chunkdata);
  171905. }
  171906. #endif /* PNG_READ_iCCP_SUPPORTED */
  171907. #if defined(PNG_READ_sPLT_SUPPORTED)
  171908. void /* PRIVATE */
  171909. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171910. {
  171911. png_bytep chunkdata;
  171912. png_bytep entry_start;
  171913. png_sPLT_t new_palette;
  171914. #ifdef PNG_NO_POINTER_INDEXING
  171915. png_sPLT_entryp pp;
  171916. #endif
  171917. int data_length, entry_size, i;
  171918. png_uint_32 skip = 0;
  171919. png_size_t slength;
  171920. png_debug(1, "in png_handle_sPLT\n");
  171921. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171922. png_error(png_ptr, "Missing IHDR before sPLT");
  171923. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171924. {
  171925. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171926. png_crc_finish(png_ptr, length);
  171927. return;
  171928. }
  171929. #ifdef PNG_MAX_MALLOC_64K
  171930. if (length > (png_uint_32)65535L)
  171931. {
  171932. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171933. skip = length - (png_uint_32)65535L;
  171934. length = (png_uint_32)65535L;
  171935. }
  171936. #endif
  171937. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171938. slength = (png_size_t)length;
  171939. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171940. if (png_crc_finish(png_ptr, skip))
  171941. {
  171942. png_free(png_ptr, chunkdata);
  171943. return;
  171944. }
  171945. chunkdata[slength] = 0x00;
  171946. for (entry_start = chunkdata; *entry_start; entry_start++)
  171947. ;
  171948. ++entry_start;
  171949. if (entry_start > chunkdata + slength - 2)
  171950. {
  171951. png_free(png_ptr, chunkdata);
  171952. png_warning(png_ptr, "malformed sPLT chunk");
  171953. return;
  171954. }
  171955. new_palette.depth = *entry_start++;
  171956. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171957. data_length = (slength - (entry_start - chunkdata));
  171958. if (data_length % entry_size)
  171959. {
  171960. png_free(png_ptr, chunkdata);
  171961. png_warning(png_ptr, "sPLT chunk has bad length");
  171962. return;
  171963. }
  171964. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171965. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171966. png_sizeof(png_sPLT_entry)))
  171967. {
  171968. png_warning(png_ptr, "sPLT chunk too long");
  171969. return;
  171970. }
  171971. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171972. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171973. if (new_palette.entries == NULL)
  171974. {
  171975. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171976. return;
  171977. }
  171978. #ifndef PNG_NO_POINTER_INDEXING
  171979. for (i = 0; i < new_palette.nentries; i++)
  171980. {
  171981. png_sPLT_entryp pp = new_palette.entries + i;
  171982. if (new_palette.depth == 8)
  171983. {
  171984. pp->red = *entry_start++;
  171985. pp->green = *entry_start++;
  171986. pp->blue = *entry_start++;
  171987. pp->alpha = *entry_start++;
  171988. }
  171989. else
  171990. {
  171991. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171992. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171993. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171994. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171995. }
  171996. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171997. }
  171998. #else
  171999. pp = new_palette.entries;
  172000. for (i = 0; i < new_palette.nentries; i++)
  172001. {
  172002. if (new_palette.depth == 8)
  172003. {
  172004. pp[i].red = *entry_start++;
  172005. pp[i].green = *entry_start++;
  172006. pp[i].blue = *entry_start++;
  172007. pp[i].alpha = *entry_start++;
  172008. }
  172009. else
  172010. {
  172011. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  172012. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  172013. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  172014. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  172015. }
  172016. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172017. }
  172018. #endif
  172019. new_palette.name = (png_charp)chunkdata;
  172020. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  172021. png_free(png_ptr, chunkdata);
  172022. png_free(png_ptr, new_palette.entries);
  172023. }
  172024. #endif /* PNG_READ_sPLT_SUPPORTED */
  172025. #if defined(PNG_READ_tRNS_SUPPORTED)
  172026. void /* PRIVATE */
  172027. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172028. {
  172029. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  172030. int bit_mask;
  172031. png_debug(1, "in png_handle_tRNS\n");
  172032. bit_mask = (1 << png_ptr->bit_depth) - 1;
  172033. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172034. png_error(png_ptr, "Missing IHDR before tRNS");
  172035. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172036. {
  172037. png_warning(png_ptr, "Invalid tRNS after IDAT");
  172038. png_crc_finish(png_ptr, length);
  172039. return;
  172040. }
  172041. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  172042. {
  172043. png_warning(png_ptr, "Duplicate tRNS chunk");
  172044. png_crc_finish(png_ptr, length);
  172045. return;
  172046. }
  172047. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  172048. {
  172049. png_byte buf[2];
  172050. if (length != 2)
  172051. {
  172052. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172053. png_crc_finish(png_ptr, length);
  172054. return;
  172055. }
  172056. png_crc_read(png_ptr, buf, 2);
  172057. png_ptr->num_trans = 1;
  172058. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  172059. }
  172060. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  172061. {
  172062. png_byte buf[6];
  172063. if (length != 6)
  172064. {
  172065. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172066. png_crc_finish(png_ptr, length);
  172067. return;
  172068. }
  172069. png_crc_read(png_ptr, buf, (png_size_t)length);
  172070. png_ptr->num_trans = 1;
  172071. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  172072. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  172073. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  172074. }
  172075. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172076. {
  172077. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172078. {
  172079. png_warning(png_ptr, "Missing PLTE before tRNS");
  172080. }
  172081. if (length > (png_uint_32)png_ptr->num_palette ||
  172082. length > PNG_MAX_PALETTE_LENGTH)
  172083. {
  172084. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172085. png_crc_finish(png_ptr, length);
  172086. return;
  172087. }
  172088. if (length == 0)
  172089. {
  172090. png_warning(png_ptr, "Zero length tRNS chunk");
  172091. png_crc_finish(png_ptr, length);
  172092. return;
  172093. }
  172094. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  172095. png_ptr->num_trans = (png_uint_16)length;
  172096. }
  172097. else
  172098. {
  172099. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  172100. png_crc_finish(png_ptr, length);
  172101. return;
  172102. }
  172103. if (png_crc_finish(png_ptr, 0))
  172104. {
  172105. png_ptr->num_trans = 0;
  172106. return;
  172107. }
  172108. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  172109. &(png_ptr->trans_values));
  172110. }
  172111. #endif
  172112. #if defined(PNG_READ_bKGD_SUPPORTED)
  172113. void /* PRIVATE */
  172114. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172115. {
  172116. png_size_t truelen;
  172117. png_byte buf[6];
  172118. png_debug(1, "in png_handle_bKGD\n");
  172119. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172120. png_error(png_ptr, "Missing IHDR before bKGD");
  172121. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172122. {
  172123. png_warning(png_ptr, "Invalid bKGD after IDAT");
  172124. png_crc_finish(png_ptr, length);
  172125. return;
  172126. }
  172127. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  172128. !(png_ptr->mode & PNG_HAVE_PLTE))
  172129. {
  172130. png_warning(png_ptr, "Missing PLTE before bKGD");
  172131. png_crc_finish(png_ptr, length);
  172132. return;
  172133. }
  172134. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  172135. {
  172136. png_warning(png_ptr, "Duplicate bKGD chunk");
  172137. png_crc_finish(png_ptr, length);
  172138. return;
  172139. }
  172140. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172141. truelen = 1;
  172142. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  172143. truelen = 6;
  172144. else
  172145. truelen = 2;
  172146. if (length != truelen)
  172147. {
  172148. png_warning(png_ptr, "Incorrect bKGD chunk length");
  172149. png_crc_finish(png_ptr, length);
  172150. return;
  172151. }
  172152. png_crc_read(png_ptr, buf, truelen);
  172153. if (png_crc_finish(png_ptr, 0))
  172154. return;
  172155. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172156. {
  172157. png_ptr->background.index = buf[0];
  172158. if(info_ptr->num_palette)
  172159. {
  172160. if(buf[0] > info_ptr->num_palette)
  172161. {
  172162. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  172163. return;
  172164. }
  172165. png_ptr->background.red =
  172166. (png_uint_16)png_ptr->palette[buf[0]].red;
  172167. png_ptr->background.green =
  172168. (png_uint_16)png_ptr->palette[buf[0]].green;
  172169. png_ptr->background.blue =
  172170. (png_uint_16)png_ptr->palette[buf[0]].blue;
  172171. }
  172172. }
  172173. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  172174. {
  172175. png_ptr->background.red =
  172176. png_ptr->background.green =
  172177. png_ptr->background.blue =
  172178. png_ptr->background.gray = png_get_uint_16(buf);
  172179. }
  172180. else
  172181. {
  172182. png_ptr->background.red = png_get_uint_16(buf);
  172183. png_ptr->background.green = png_get_uint_16(buf + 2);
  172184. png_ptr->background.blue = png_get_uint_16(buf + 4);
  172185. }
  172186. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  172187. }
  172188. #endif
  172189. #if defined(PNG_READ_hIST_SUPPORTED)
  172190. void /* PRIVATE */
  172191. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172192. {
  172193. unsigned int num, i;
  172194. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  172195. png_debug(1, "in png_handle_hIST\n");
  172196. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172197. png_error(png_ptr, "Missing IHDR before hIST");
  172198. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172199. {
  172200. png_warning(png_ptr, "Invalid hIST after IDAT");
  172201. png_crc_finish(png_ptr, length);
  172202. return;
  172203. }
  172204. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172205. {
  172206. png_warning(png_ptr, "Missing PLTE before hIST");
  172207. png_crc_finish(png_ptr, length);
  172208. return;
  172209. }
  172210. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  172211. {
  172212. png_warning(png_ptr, "Duplicate hIST chunk");
  172213. png_crc_finish(png_ptr, length);
  172214. return;
  172215. }
  172216. num = length / 2 ;
  172217. if (num != (unsigned int) png_ptr->num_palette || num >
  172218. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  172219. {
  172220. png_warning(png_ptr, "Incorrect hIST chunk length");
  172221. png_crc_finish(png_ptr, length);
  172222. return;
  172223. }
  172224. for (i = 0; i < num; i++)
  172225. {
  172226. png_byte buf[2];
  172227. png_crc_read(png_ptr, buf, 2);
  172228. readbuf[i] = png_get_uint_16(buf);
  172229. }
  172230. if (png_crc_finish(png_ptr, 0))
  172231. return;
  172232. png_set_hIST(png_ptr, info_ptr, readbuf);
  172233. }
  172234. #endif
  172235. #if defined(PNG_READ_pHYs_SUPPORTED)
  172236. void /* PRIVATE */
  172237. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172238. {
  172239. png_byte buf[9];
  172240. png_uint_32 res_x, res_y;
  172241. int unit_type;
  172242. png_debug(1, "in png_handle_pHYs\n");
  172243. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172244. png_error(png_ptr, "Missing IHDR before pHYs");
  172245. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172246. {
  172247. png_warning(png_ptr, "Invalid pHYs after IDAT");
  172248. png_crc_finish(png_ptr, length);
  172249. return;
  172250. }
  172251. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  172252. {
  172253. png_warning(png_ptr, "Duplicate pHYs chunk");
  172254. png_crc_finish(png_ptr, length);
  172255. return;
  172256. }
  172257. if (length != 9)
  172258. {
  172259. png_warning(png_ptr, "Incorrect pHYs chunk length");
  172260. png_crc_finish(png_ptr, length);
  172261. return;
  172262. }
  172263. png_crc_read(png_ptr, buf, 9);
  172264. if (png_crc_finish(png_ptr, 0))
  172265. return;
  172266. res_x = png_get_uint_32(buf);
  172267. res_y = png_get_uint_32(buf + 4);
  172268. unit_type = buf[8];
  172269. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  172270. }
  172271. #endif
  172272. #if defined(PNG_READ_oFFs_SUPPORTED)
  172273. void /* PRIVATE */
  172274. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172275. {
  172276. png_byte buf[9];
  172277. png_int_32 offset_x, offset_y;
  172278. int unit_type;
  172279. png_debug(1, "in png_handle_oFFs\n");
  172280. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172281. png_error(png_ptr, "Missing IHDR before oFFs");
  172282. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172283. {
  172284. png_warning(png_ptr, "Invalid oFFs after IDAT");
  172285. png_crc_finish(png_ptr, length);
  172286. return;
  172287. }
  172288. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172289. {
  172290. png_warning(png_ptr, "Duplicate oFFs chunk");
  172291. png_crc_finish(png_ptr, length);
  172292. return;
  172293. }
  172294. if (length != 9)
  172295. {
  172296. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172297. png_crc_finish(png_ptr, length);
  172298. return;
  172299. }
  172300. png_crc_read(png_ptr, buf, 9);
  172301. if (png_crc_finish(png_ptr, 0))
  172302. return;
  172303. offset_x = png_get_int_32(buf);
  172304. offset_y = png_get_int_32(buf + 4);
  172305. unit_type = buf[8];
  172306. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172307. }
  172308. #endif
  172309. #if defined(PNG_READ_pCAL_SUPPORTED)
  172310. void /* PRIVATE */
  172311. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172312. {
  172313. png_charp purpose;
  172314. png_int_32 X0, X1;
  172315. png_byte type, nparams;
  172316. png_charp buf, units, endptr;
  172317. png_charpp params;
  172318. png_size_t slength;
  172319. int i;
  172320. png_debug(1, "in png_handle_pCAL\n");
  172321. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172322. png_error(png_ptr, "Missing IHDR before pCAL");
  172323. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172324. {
  172325. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172326. png_crc_finish(png_ptr, length);
  172327. return;
  172328. }
  172329. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172330. {
  172331. png_warning(png_ptr, "Duplicate pCAL chunk");
  172332. png_crc_finish(png_ptr, length);
  172333. return;
  172334. }
  172335. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172336. length + 1);
  172337. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172338. if (purpose == NULL)
  172339. {
  172340. png_warning(png_ptr, "No memory for pCAL purpose.");
  172341. return;
  172342. }
  172343. slength = (png_size_t)length;
  172344. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172345. if (png_crc_finish(png_ptr, 0))
  172346. {
  172347. png_free(png_ptr, purpose);
  172348. return;
  172349. }
  172350. purpose[slength] = 0x00; /* null terminate the last string */
  172351. png_debug(3, "Finding end of pCAL purpose string\n");
  172352. for (buf = purpose; *buf; buf++)
  172353. ;
  172354. endptr = purpose + slength;
  172355. if (endptr <= buf + 12)
  172356. {
  172357. png_warning(png_ptr, "Invalid pCAL data");
  172358. png_free(png_ptr, purpose);
  172359. return;
  172360. }
  172361. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172362. X0 = png_get_int_32((png_bytep)buf+1);
  172363. X1 = png_get_int_32((png_bytep)buf+5);
  172364. type = buf[9];
  172365. nparams = buf[10];
  172366. units = buf + 11;
  172367. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172368. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172369. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172370. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172371. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172372. {
  172373. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172374. png_free(png_ptr, purpose);
  172375. return;
  172376. }
  172377. else if (type >= PNG_EQUATION_LAST)
  172378. {
  172379. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172380. }
  172381. for (buf = units; *buf; buf++)
  172382. ;
  172383. png_debug(3, "Allocating pCAL parameters array\n");
  172384. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172385. *png_sizeof(png_charp))) ;
  172386. if (params == NULL)
  172387. {
  172388. png_free(png_ptr, purpose);
  172389. png_warning(png_ptr, "No memory for pCAL params.");
  172390. return;
  172391. }
  172392. for (i = 0; i < (int)nparams; i++)
  172393. {
  172394. buf++; /* Skip the null string terminator from previous parameter. */
  172395. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172396. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172397. ;
  172398. if (buf > endptr)
  172399. {
  172400. png_warning(png_ptr, "Invalid pCAL data");
  172401. png_free(png_ptr, purpose);
  172402. png_free(png_ptr, params);
  172403. return;
  172404. }
  172405. }
  172406. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172407. units, params);
  172408. png_free(png_ptr, purpose);
  172409. png_free(png_ptr, params);
  172410. }
  172411. #endif
  172412. #if defined(PNG_READ_sCAL_SUPPORTED)
  172413. void /* PRIVATE */
  172414. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172415. {
  172416. png_charp buffer, ep;
  172417. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172418. double width, height;
  172419. png_charp vp;
  172420. #else
  172421. #ifdef PNG_FIXED_POINT_SUPPORTED
  172422. png_charp swidth, sheight;
  172423. #endif
  172424. #endif
  172425. png_size_t slength;
  172426. png_debug(1, "in png_handle_sCAL\n");
  172427. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172428. png_error(png_ptr, "Missing IHDR before sCAL");
  172429. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172430. {
  172431. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172432. png_crc_finish(png_ptr, length);
  172433. return;
  172434. }
  172435. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172436. {
  172437. png_warning(png_ptr, "Duplicate sCAL chunk");
  172438. png_crc_finish(png_ptr, length);
  172439. return;
  172440. }
  172441. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172442. length + 1);
  172443. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172444. if (buffer == NULL)
  172445. {
  172446. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172447. return;
  172448. }
  172449. slength = (png_size_t)length;
  172450. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172451. if (png_crc_finish(png_ptr, 0))
  172452. {
  172453. png_free(png_ptr, buffer);
  172454. return;
  172455. }
  172456. buffer[slength] = 0x00; /* null terminate the last string */
  172457. ep = buffer + 1; /* skip unit byte */
  172458. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172459. width = png_strtod(png_ptr, ep, &vp);
  172460. if (*vp)
  172461. {
  172462. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172463. return;
  172464. }
  172465. #else
  172466. #ifdef PNG_FIXED_POINT_SUPPORTED
  172467. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172468. if (swidth == NULL)
  172469. {
  172470. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172471. return;
  172472. }
  172473. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172474. #endif
  172475. #endif
  172476. for (ep = buffer; *ep; ep++)
  172477. ;
  172478. ep++;
  172479. if (buffer + slength < ep)
  172480. {
  172481. png_warning(png_ptr, "Truncated sCAL chunk");
  172482. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172483. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172484. png_free(png_ptr, swidth);
  172485. #endif
  172486. png_free(png_ptr, buffer);
  172487. return;
  172488. }
  172489. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172490. height = png_strtod(png_ptr, ep, &vp);
  172491. if (*vp)
  172492. {
  172493. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172494. return;
  172495. }
  172496. #else
  172497. #ifdef PNG_FIXED_POINT_SUPPORTED
  172498. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172499. if (swidth == NULL)
  172500. {
  172501. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172502. return;
  172503. }
  172504. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172505. #endif
  172506. #endif
  172507. if (buffer + slength < ep
  172508. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172509. || width <= 0. || height <= 0.
  172510. #endif
  172511. )
  172512. {
  172513. png_warning(png_ptr, "Invalid sCAL data");
  172514. png_free(png_ptr, buffer);
  172515. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172516. png_free(png_ptr, swidth);
  172517. png_free(png_ptr, sheight);
  172518. #endif
  172519. return;
  172520. }
  172521. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172522. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172523. #else
  172524. #ifdef PNG_FIXED_POINT_SUPPORTED
  172525. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172526. #endif
  172527. #endif
  172528. png_free(png_ptr, buffer);
  172529. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172530. png_free(png_ptr, swidth);
  172531. png_free(png_ptr, sheight);
  172532. #endif
  172533. }
  172534. #endif
  172535. #if defined(PNG_READ_tIME_SUPPORTED)
  172536. void /* PRIVATE */
  172537. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172538. {
  172539. png_byte buf[7];
  172540. png_time mod_time;
  172541. png_debug(1, "in png_handle_tIME\n");
  172542. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172543. png_error(png_ptr, "Out of place tIME chunk");
  172544. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172545. {
  172546. png_warning(png_ptr, "Duplicate tIME chunk");
  172547. png_crc_finish(png_ptr, length);
  172548. return;
  172549. }
  172550. if (png_ptr->mode & PNG_HAVE_IDAT)
  172551. png_ptr->mode |= PNG_AFTER_IDAT;
  172552. if (length != 7)
  172553. {
  172554. png_warning(png_ptr, "Incorrect tIME chunk length");
  172555. png_crc_finish(png_ptr, length);
  172556. return;
  172557. }
  172558. png_crc_read(png_ptr, buf, 7);
  172559. if (png_crc_finish(png_ptr, 0))
  172560. return;
  172561. mod_time.second = buf[6];
  172562. mod_time.minute = buf[5];
  172563. mod_time.hour = buf[4];
  172564. mod_time.day = buf[3];
  172565. mod_time.month = buf[2];
  172566. mod_time.year = png_get_uint_16(buf);
  172567. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172568. }
  172569. #endif
  172570. #if defined(PNG_READ_tEXt_SUPPORTED)
  172571. void /* PRIVATE */
  172572. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172573. {
  172574. png_textp text_ptr;
  172575. png_charp key;
  172576. png_charp text;
  172577. png_uint_32 skip = 0;
  172578. png_size_t slength;
  172579. int ret;
  172580. png_debug(1, "in png_handle_tEXt\n");
  172581. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172582. png_error(png_ptr, "Missing IHDR before tEXt");
  172583. if (png_ptr->mode & PNG_HAVE_IDAT)
  172584. png_ptr->mode |= PNG_AFTER_IDAT;
  172585. #ifdef PNG_MAX_MALLOC_64K
  172586. if (length > (png_uint_32)65535L)
  172587. {
  172588. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172589. skip = length - (png_uint_32)65535L;
  172590. length = (png_uint_32)65535L;
  172591. }
  172592. #endif
  172593. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172594. if (key == NULL)
  172595. {
  172596. png_warning(png_ptr, "No memory to process text chunk.");
  172597. return;
  172598. }
  172599. slength = (png_size_t)length;
  172600. png_crc_read(png_ptr, (png_bytep)key, slength);
  172601. if (png_crc_finish(png_ptr, skip))
  172602. {
  172603. png_free(png_ptr, key);
  172604. return;
  172605. }
  172606. key[slength] = 0x00;
  172607. for (text = key; *text; text++)
  172608. ;
  172609. if (text != key + slength)
  172610. text++;
  172611. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172612. (png_uint_32)png_sizeof(png_text));
  172613. if (text_ptr == NULL)
  172614. {
  172615. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172616. png_free(png_ptr, key);
  172617. return;
  172618. }
  172619. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172620. text_ptr->key = key;
  172621. #ifdef PNG_iTXt_SUPPORTED
  172622. text_ptr->lang = NULL;
  172623. text_ptr->lang_key = NULL;
  172624. text_ptr->itxt_length = 0;
  172625. #endif
  172626. text_ptr->text = text;
  172627. text_ptr->text_length = png_strlen(text);
  172628. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172629. png_free(png_ptr, key);
  172630. png_free(png_ptr, text_ptr);
  172631. if (ret)
  172632. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172633. }
  172634. #endif
  172635. #if defined(PNG_READ_zTXt_SUPPORTED)
  172636. void /* PRIVATE */
  172637. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172638. {
  172639. png_textp text_ptr;
  172640. png_charp chunkdata;
  172641. png_charp text;
  172642. int comp_type;
  172643. int ret;
  172644. png_size_t slength, prefix_len, data_len;
  172645. png_debug(1, "in png_handle_zTXt\n");
  172646. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172647. png_error(png_ptr, "Missing IHDR before zTXt");
  172648. if (png_ptr->mode & PNG_HAVE_IDAT)
  172649. png_ptr->mode |= PNG_AFTER_IDAT;
  172650. #ifdef PNG_MAX_MALLOC_64K
  172651. if (length > (png_uint_32)65535L)
  172652. {
  172653. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172654. png_crc_finish(png_ptr, length);
  172655. return;
  172656. }
  172657. #endif
  172658. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172659. if (chunkdata == NULL)
  172660. {
  172661. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172662. return;
  172663. }
  172664. slength = (png_size_t)length;
  172665. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172666. if (png_crc_finish(png_ptr, 0))
  172667. {
  172668. png_free(png_ptr, chunkdata);
  172669. return;
  172670. }
  172671. chunkdata[slength] = 0x00;
  172672. for (text = chunkdata; *text; text++)
  172673. ;
  172674. if (text >= chunkdata + slength - 2)
  172675. {
  172676. png_warning(png_ptr, "Truncated zTXt chunk");
  172677. png_free(png_ptr, chunkdata);
  172678. return;
  172679. }
  172680. else
  172681. {
  172682. comp_type = *(++text);
  172683. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172684. {
  172685. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172686. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172687. }
  172688. text++; /* skip the compression_method byte */
  172689. }
  172690. prefix_len = text - chunkdata;
  172691. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172692. (png_size_t)length, prefix_len, &data_len);
  172693. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172694. (png_uint_32)png_sizeof(png_text));
  172695. if (text_ptr == NULL)
  172696. {
  172697. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172698. png_free(png_ptr, chunkdata);
  172699. return;
  172700. }
  172701. text_ptr->compression = comp_type;
  172702. text_ptr->key = chunkdata;
  172703. #ifdef PNG_iTXt_SUPPORTED
  172704. text_ptr->lang = NULL;
  172705. text_ptr->lang_key = NULL;
  172706. text_ptr->itxt_length = 0;
  172707. #endif
  172708. text_ptr->text = chunkdata + prefix_len;
  172709. text_ptr->text_length = data_len;
  172710. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172711. png_free(png_ptr, text_ptr);
  172712. png_free(png_ptr, chunkdata);
  172713. if (ret)
  172714. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172715. }
  172716. #endif
  172717. #if defined(PNG_READ_iTXt_SUPPORTED)
  172718. void /* PRIVATE */
  172719. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172720. {
  172721. png_textp text_ptr;
  172722. png_charp chunkdata;
  172723. png_charp key, lang, text, lang_key;
  172724. int comp_flag;
  172725. int comp_type = 0;
  172726. int ret;
  172727. png_size_t slength, prefix_len, data_len;
  172728. png_debug(1, "in png_handle_iTXt\n");
  172729. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172730. png_error(png_ptr, "Missing IHDR before iTXt");
  172731. if (png_ptr->mode & PNG_HAVE_IDAT)
  172732. png_ptr->mode |= PNG_AFTER_IDAT;
  172733. #ifdef PNG_MAX_MALLOC_64K
  172734. if (length > (png_uint_32)65535L)
  172735. {
  172736. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172737. png_crc_finish(png_ptr, length);
  172738. return;
  172739. }
  172740. #endif
  172741. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172742. if (chunkdata == NULL)
  172743. {
  172744. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172745. return;
  172746. }
  172747. slength = (png_size_t)length;
  172748. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172749. if (png_crc_finish(png_ptr, 0))
  172750. {
  172751. png_free(png_ptr, chunkdata);
  172752. return;
  172753. }
  172754. chunkdata[slength] = 0x00;
  172755. for (lang = chunkdata; *lang; lang++)
  172756. ;
  172757. lang++; /* skip NUL separator */
  172758. if (lang >= chunkdata + slength - 3)
  172759. {
  172760. png_warning(png_ptr, "Truncated iTXt chunk");
  172761. png_free(png_ptr, chunkdata);
  172762. return;
  172763. }
  172764. else
  172765. {
  172766. comp_flag = *lang++;
  172767. comp_type = *lang++;
  172768. }
  172769. for (lang_key = lang; *lang_key; lang_key++)
  172770. ;
  172771. lang_key++; /* skip NUL separator */
  172772. if (lang_key >= chunkdata + slength)
  172773. {
  172774. png_warning(png_ptr, "Truncated iTXt chunk");
  172775. png_free(png_ptr, chunkdata);
  172776. return;
  172777. }
  172778. for (text = lang_key; *text; text++)
  172779. ;
  172780. text++; /* skip NUL separator */
  172781. if (text >= chunkdata + slength)
  172782. {
  172783. png_warning(png_ptr, "Malformed iTXt chunk");
  172784. png_free(png_ptr, chunkdata);
  172785. return;
  172786. }
  172787. prefix_len = text - chunkdata;
  172788. key=chunkdata;
  172789. if (comp_flag)
  172790. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172791. (size_t)length, prefix_len, &data_len);
  172792. else
  172793. data_len=png_strlen(chunkdata + prefix_len);
  172794. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172795. (png_uint_32)png_sizeof(png_text));
  172796. if (text_ptr == NULL)
  172797. {
  172798. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172799. png_free(png_ptr, chunkdata);
  172800. return;
  172801. }
  172802. text_ptr->compression = (int)comp_flag + 1;
  172803. text_ptr->lang_key = chunkdata+(lang_key-key);
  172804. text_ptr->lang = chunkdata+(lang-key);
  172805. text_ptr->itxt_length = data_len;
  172806. text_ptr->text_length = 0;
  172807. text_ptr->key = chunkdata;
  172808. text_ptr->text = chunkdata + prefix_len;
  172809. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172810. png_free(png_ptr, text_ptr);
  172811. png_free(png_ptr, chunkdata);
  172812. if (ret)
  172813. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172814. }
  172815. #endif
  172816. void /* PRIVATE */
  172817. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172818. {
  172819. png_uint_32 skip = 0;
  172820. png_debug(1, "in png_handle_unknown\n");
  172821. if (png_ptr->mode & PNG_HAVE_IDAT)
  172822. {
  172823. #ifdef PNG_USE_LOCAL_ARRAYS
  172824. PNG_CONST PNG_IDAT;
  172825. #endif
  172826. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172827. png_ptr->mode |= PNG_AFTER_IDAT;
  172828. }
  172829. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172830. if (!(png_ptr->chunk_name[0] & 0x20))
  172831. {
  172832. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172833. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172834. PNG_HANDLE_CHUNK_ALWAYS
  172835. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172836. && png_ptr->read_user_chunk_fn == NULL
  172837. #endif
  172838. )
  172839. #endif
  172840. png_chunk_error(png_ptr, "unknown critical chunk");
  172841. }
  172842. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172843. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172844. (png_ptr->read_user_chunk_fn != NULL))
  172845. {
  172846. #ifdef PNG_MAX_MALLOC_64K
  172847. if (length > (png_uint_32)65535L)
  172848. {
  172849. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172850. skip = length - (png_uint_32)65535L;
  172851. length = (png_uint_32)65535L;
  172852. }
  172853. #endif
  172854. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172855. (png_charp)png_ptr->chunk_name, 5);
  172856. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172857. png_ptr->unknown_chunk.size = (png_size_t)length;
  172858. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172859. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172860. if(png_ptr->read_user_chunk_fn != NULL)
  172861. {
  172862. int ret;
  172863. ret = (*(png_ptr->read_user_chunk_fn))
  172864. (png_ptr, &png_ptr->unknown_chunk);
  172865. if (ret < 0)
  172866. png_chunk_error(png_ptr, "error in user chunk");
  172867. if (ret == 0)
  172868. {
  172869. if (!(png_ptr->chunk_name[0] & 0x20))
  172870. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172871. PNG_HANDLE_CHUNK_ALWAYS)
  172872. png_chunk_error(png_ptr, "unknown critical chunk");
  172873. png_set_unknown_chunks(png_ptr, info_ptr,
  172874. &png_ptr->unknown_chunk, 1);
  172875. }
  172876. }
  172877. #else
  172878. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172879. #endif
  172880. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172881. png_ptr->unknown_chunk.data = NULL;
  172882. }
  172883. else
  172884. #endif
  172885. skip = length;
  172886. png_crc_finish(png_ptr, skip);
  172887. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172888. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172889. #endif
  172890. }
  172891. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172892. void /* PRIVATE */
  172893. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172894. {
  172895. png_debug(1, "in png_check_chunk_name\n");
  172896. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172897. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172898. {
  172899. png_chunk_error(png_ptr, "invalid chunk type");
  172900. }
  172901. }
  172902. void /* PRIVATE */
  172903. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172904. {
  172905. png_debug(1,"in png_combine_row\n");
  172906. if (mask == 0xff)
  172907. {
  172908. png_memcpy(row, png_ptr->row_buf + 1,
  172909. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172910. }
  172911. else
  172912. {
  172913. switch (png_ptr->row_info.pixel_depth)
  172914. {
  172915. case 1:
  172916. {
  172917. png_bytep sp = png_ptr->row_buf + 1;
  172918. png_bytep dp = row;
  172919. int s_inc, s_start, s_end;
  172920. int m = 0x80;
  172921. int shift;
  172922. png_uint_32 i;
  172923. png_uint_32 row_width = png_ptr->width;
  172924. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172925. if (png_ptr->transformations & PNG_PACKSWAP)
  172926. {
  172927. s_start = 0;
  172928. s_end = 7;
  172929. s_inc = 1;
  172930. }
  172931. else
  172932. #endif
  172933. {
  172934. s_start = 7;
  172935. s_end = 0;
  172936. s_inc = -1;
  172937. }
  172938. shift = s_start;
  172939. for (i = 0; i < row_width; i++)
  172940. {
  172941. if (m & mask)
  172942. {
  172943. int value;
  172944. value = (*sp >> shift) & 0x01;
  172945. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172946. *dp |= (png_byte)(value << shift);
  172947. }
  172948. if (shift == s_end)
  172949. {
  172950. shift = s_start;
  172951. sp++;
  172952. dp++;
  172953. }
  172954. else
  172955. shift += s_inc;
  172956. if (m == 1)
  172957. m = 0x80;
  172958. else
  172959. m >>= 1;
  172960. }
  172961. break;
  172962. }
  172963. case 2:
  172964. {
  172965. png_bytep sp = png_ptr->row_buf + 1;
  172966. png_bytep dp = row;
  172967. int s_start, s_end, s_inc;
  172968. int m = 0x80;
  172969. int shift;
  172970. png_uint_32 i;
  172971. png_uint_32 row_width = png_ptr->width;
  172972. int value;
  172973. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172974. if (png_ptr->transformations & PNG_PACKSWAP)
  172975. {
  172976. s_start = 0;
  172977. s_end = 6;
  172978. s_inc = 2;
  172979. }
  172980. else
  172981. #endif
  172982. {
  172983. s_start = 6;
  172984. s_end = 0;
  172985. s_inc = -2;
  172986. }
  172987. shift = s_start;
  172988. for (i = 0; i < row_width; i++)
  172989. {
  172990. if (m & mask)
  172991. {
  172992. value = (*sp >> shift) & 0x03;
  172993. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172994. *dp |= (png_byte)(value << shift);
  172995. }
  172996. if (shift == s_end)
  172997. {
  172998. shift = s_start;
  172999. sp++;
  173000. dp++;
  173001. }
  173002. else
  173003. shift += s_inc;
  173004. if (m == 1)
  173005. m = 0x80;
  173006. else
  173007. m >>= 1;
  173008. }
  173009. break;
  173010. }
  173011. case 4:
  173012. {
  173013. png_bytep sp = png_ptr->row_buf + 1;
  173014. png_bytep dp = row;
  173015. int s_start, s_end, s_inc;
  173016. int m = 0x80;
  173017. int shift;
  173018. png_uint_32 i;
  173019. png_uint_32 row_width = png_ptr->width;
  173020. int value;
  173021. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173022. if (png_ptr->transformations & PNG_PACKSWAP)
  173023. {
  173024. s_start = 0;
  173025. s_end = 4;
  173026. s_inc = 4;
  173027. }
  173028. else
  173029. #endif
  173030. {
  173031. s_start = 4;
  173032. s_end = 0;
  173033. s_inc = -4;
  173034. }
  173035. shift = s_start;
  173036. for (i = 0; i < row_width; i++)
  173037. {
  173038. if (m & mask)
  173039. {
  173040. value = (*sp >> shift) & 0xf;
  173041. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  173042. *dp |= (png_byte)(value << shift);
  173043. }
  173044. if (shift == s_end)
  173045. {
  173046. shift = s_start;
  173047. sp++;
  173048. dp++;
  173049. }
  173050. else
  173051. shift += s_inc;
  173052. if (m == 1)
  173053. m = 0x80;
  173054. else
  173055. m >>= 1;
  173056. }
  173057. break;
  173058. }
  173059. default:
  173060. {
  173061. png_bytep sp = png_ptr->row_buf + 1;
  173062. png_bytep dp = row;
  173063. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  173064. png_uint_32 i;
  173065. png_uint_32 row_width = png_ptr->width;
  173066. png_byte m = 0x80;
  173067. for (i = 0; i < row_width; i++)
  173068. {
  173069. if (m & mask)
  173070. {
  173071. png_memcpy(dp, sp, pixel_bytes);
  173072. }
  173073. sp += pixel_bytes;
  173074. dp += pixel_bytes;
  173075. if (m == 1)
  173076. m = 0x80;
  173077. else
  173078. m >>= 1;
  173079. }
  173080. break;
  173081. }
  173082. }
  173083. }
  173084. }
  173085. #ifdef PNG_READ_INTERLACING_SUPPORTED
  173086. void /* PRIVATE */
  173087. png_do_read_interlace(png_structp png_ptr)
  173088. {
  173089. png_row_infop row_info = &(png_ptr->row_info);
  173090. png_bytep row = png_ptr->row_buf + 1;
  173091. int pass = png_ptr->pass;
  173092. png_uint_32 transformations = png_ptr->transformations;
  173093. #ifdef PNG_USE_LOCAL_ARRAYS
  173094. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173095. #endif
  173096. png_debug(1,"in png_do_read_interlace\n");
  173097. if (row != NULL && row_info != NULL)
  173098. {
  173099. png_uint_32 final_width;
  173100. final_width = row_info->width * png_pass_inc[pass];
  173101. switch (row_info->pixel_depth)
  173102. {
  173103. case 1:
  173104. {
  173105. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  173106. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  173107. int sshift, dshift;
  173108. int s_start, s_end, s_inc;
  173109. int jstop = png_pass_inc[pass];
  173110. png_byte v;
  173111. png_uint_32 i;
  173112. int j;
  173113. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173114. if (transformations & PNG_PACKSWAP)
  173115. {
  173116. sshift = (int)((row_info->width + 7) & 0x07);
  173117. dshift = (int)((final_width + 7) & 0x07);
  173118. s_start = 7;
  173119. s_end = 0;
  173120. s_inc = -1;
  173121. }
  173122. else
  173123. #endif
  173124. {
  173125. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  173126. dshift = 7 - (int)((final_width + 7) & 0x07);
  173127. s_start = 0;
  173128. s_end = 7;
  173129. s_inc = 1;
  173130. }
  173131. for (i = 0; i < row_info->width; i++)
  173132. {
  173133. v = (png_byte)((*sp >> sshift) & 0x01);
  173134. for (j = 0; j < jstop; j++)
  173135. {
  173136. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  173137. *dp |= (png_byte)(v << dshift);
  173138. if (dshift == s_end)
  173139. {
  173140. dshift = s_start;
  173141. dp--;
  173142. }
  173143. else
  173144. dshift += s_inc;
  173145. }
  173146. if (sshift == s_end)
  173147. {
  173148. sshift = s_start;
  173149. sp--;
  173150. }
  173151. else
  173152. sshift += s_inc;
  173153. }
  173154. break;
  173155. }
  173156. case 2:
  173157. {
  173158. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  173159. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  173160. int sshift, dshift;
  173161. int s_start, s_end, s_inc;
  173162. int jstop = png_pass_inc[pass];
  173163. png_uint_32 i;
  173164. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173165. if (transformations & PNG_PACKSWAP)
  173166. {
  173167. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  173168. dshift = (int)(((final_width + 3) & 0x03) << 1);
  173169. s_start = 6;
  173170. s_end = 0;
  173171. s_inc = -2;
  173172. }
  173173. else
  173174. #endif
  173175. {
  173176. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  173177. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  173178. s_start = 0;
  173179. s_end = 6;
  173180. s_inc = 2;
  173181. }
  173182. for (i = 0; i < row_info->width; i++)
  173183. {
  173184. png_byte v;
  173185. int j;
  173186. v = (png_byte)((*sp >> sshift) & 0x03);
  173187. for (j = 0; j < jstop; j++)
  173188. {
  173189. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  173190. *dp |= (png_byte)(v << dshift);
  173191. if (dshift == s_end)
  173192. {
  173193. dshift = s_start;
  173194. dp--;
  173195. }
  173196. else
  173197. dshift += s_inc;
  173198. }
  173199. if (sshift == s_end)
  173200. {
  173201. sshift = s_start;
  173202. sp--;
  173203. }
  173204. else
  173205. sshift += s_inc;
  173206. }
  173207. break;
  173208. }
  173209. case 4:
  173210. {
  173211. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  173212. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  173213. int sshift, dshift;
  173214. int s_start, s_end, s_inc;
  173215. png_uint_32 i;
  173216. int jstop = png_pass_inc[pass];
  173217. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173218. if (transformations & PNG_PACKSWAP)
  173219. {
  173220. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  173221. dshift = (int)(((final_width + 1) & 0x01) << 2);
  173222. s_start = 4;
  173223. s_end = 0;
  173224. s_inc = -4;
  173225. }
  173226. else
  173227. #endif
  173228. {
  173229. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  173230. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  173231. s_start = 0;
  173232. s_end = 4;
  173233. s_inc = 4;
  173234. }
  173235. for (i = 0; i < row_info->width; i++)
  173236. {
  173237. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  173238. int j;
  173239. for (j = 0; j < jstop; j++)
  173240. {
  173241. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  173242. *dp |= (png_byte)(v << dshift);
  173243. if (dshift == s_end)
  173244. {
  173245. dshift = s_start;
  173246. dp--;
  173247. }
  173248. else
  173249. dshift += s_inc;
  173250. }
  173251. if (sshift == s_end)
  173252. {
  173253. sshift = s_start;
  173254. sp--;
  173255. }
  173256. else
  173257. sshift += s_inc;
  173258. }
  173259. break;
  173260. }
  173261. default:
  173262. {
  173263. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  173264. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  173265. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  173266. int jstop = png_pass_inc[pass];
  173267. png_uint_32 i;
  173268. for (i = 0; i < row_info->width; i++)
  173269. {
  173270. png_byte v[8];
  173271. int j;
  173272. png_memcpy(v, sp, pixel_bytes);
  173273. for (j = 0; j < jstop; j++)
  173274. {
  173275. png_memcpy(dp, v, pixel_bytes);
  173276. dp -= pixel_bytes;
  173277. }
  173278. sp -= pixel_bytes;
  173279. }
  173280. break;
  173281. }
  173282. }
  173283. row_info->width = final_width;
  173284. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  173285. }
  173286. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173287. transformations = transformations; /* silence compiler warning */
  173288. #endif
  173289. }
  173290. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173291. void /* PRIVATE */
  173292. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173293. png_bytep prev_row, int filter)
  173294. {
  173295. png_debug(1, "in png_read_filter_row\n");
  173296. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173297. switch (filter)
  173298. {
  173299. case PNG_FILTER_VALUE_NONE:
  173300. break;
  173301. case PNG_FILTER_VALUE_SUB:
  173302. {
  173303. png_uint_32 i;
  173304. png_uint_32 istop = row_info->rowbytes;
  173305. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173306. png_bytep rp = row + bpp;
  173307. png_bytep lp = row;
  173308. for (i = bpp; i < istop; i++)
  173309. {
  173310. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173311. rp++;
  173312. }
  173313. break;
  173314. }
  173315. case PNG_FILTER_VALUE_UP:
  173316. {
  173317. png_uint_32 i;
  173318. png_uint_32 istop = row_info->rowbytes;
  173319. png_bytep rp = row;
  173320. png_bytep pp = prev_row;
  173321. for (i = 0; i < istop; i++)
  173322. {
  173323. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173324. rp++;
  173325. }
  173326. break;
  173327. }
  173328. case PNG_FILTER_VALUE_AVG:
  173329. {
  173330. png_uint_32 i;
  173331. png_bytep rp = row;
  173332. png_bytep pp = prev_row;
  173333. png_bytep lp = row;
  173334. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173335. png_uint_32 istop = row_info->rowbytes - bpp;
  173336. for (i = 0; i < bpp; i++)
  173337. {
  173338. *rp = (png_byte)(((int)(*rp) +
  173339. ((int)(*pp++) / 2 )) & 0xff);
  173340. rp++;
  173341. }
  173342. for (i = 0; i < istop; i++)
  173343. {
  173344. *rp = (png_byte)(((int)(*rp) +
  173345. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173346. rp++;
  173347. }
  173348. break;
  173349. }
  173350. case PNG_FILTER_VALUE_PAETH:
  173351. {
  173352. png_uint_32 i;
  173353. png_bytep rp = row;
  173354. png_bytep pp = prev_row;
  173355. png_bytep lp = row;
  173356. png_bytep cp = prev_row;
  173357. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173358. png_uint_32 istop=row_info->rowbytes - bpp;
  173359. for (i = 0; i < bpp; i++)
  173360. {
  173361. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173362. rp++;
  173363. }
  173364. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173365. {
  173366. int a, b, c, pa, pb, pc, p;
  173367. a = *lp++;
  173368. b = *pp++;
  173369. c = *cp++;
  173370. p = b - c;
  173371. pc = a - c;
  173372. #ifdef PNG_USE_ABS
  173373. pa = abs(p);
  173374. pb = abs(pc);
  173375. pc = abs(p + pc);
  173376. #else
  173377. pa = p < 0 ? -p : p;
  173378. pb = pc < 0 ? -pc : pc;
  173379. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173380. #endif
  173381. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173382. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173383. rp++;
  173384. }
  173385. break;
  173386. }
  173387. default:
  173388. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173389. *row=0;
  173390. break;
  173391. }
  173392. }
  173393. void /* PRIVATE */
  173394. png_read_finish_row(png_structp png_ptr)
  173395. {
  173396. #ifdef PNG_USE_LOCAL_ARRAYS
  173397. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173398. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173399. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173400. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173401. #endif
  173402. png_debug(1, "in png_read_finish_row\n");
  173403. png_ptr->row_number++;
  173404. if (png_ptr->row_number < png_ptr->num_rows)
  173405. return;
  173406. if (png_ptr->interlaced)
  173407. {
  173408. png_ptr->row_number = 0;
  173409. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173410. png_ptr->rowbytes + 1);
  173411. do
  173412. {
  173413. png_ptr->pass++;
  173414. if (png_ptr->pass >= 7)
  173415. break;
  173416. png_ptr->iwidth = (png_ptr->width +
  173417. png_pass_inc[png_ptr->pass] - 1 -
  173418. png_pass_start[png_ptr->pass]) /
  173419. png_pass_inc[png_ptr->pass];
  173420. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173421. png_ptr->iwidth) + 1;
  173422. if (!(png_ptr->transformations & PNG_INTERLACE))
  173423. {
  173424. png_ptr->num_rows = (png_ptr->height +
  173425. png_pass_yinc[png_ptr->pass] - 1 -
  173426. png_pass_ystart[png_ptr->pass]) /
  173427. png_pass_yinc[png_ptr->pass];
  173428. if (!(png_ptr->num_rows))
  173429. continue;
  173430. }
  173431. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173432. break;
  173433. } while (png_ptr->iwidth == 0);
  173434. if (png_ptr->pass < 7)
  173435. return;
  173436. }
  173437. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173438. {
  173439. #ifdef PNG_USE_LOCAL_ARRAYS
  173440. PNG_CONST PNG_IDAT;
  173441. #endif
  173442. char extra;
  173443. int ret;
  173444. png_ptr->zstream.next_out = (Bytef *)&extra;
  173445. png_ptr->zstream.avail_out = (uInt)1;
  173446. for(;;)
  173447. {
  173448. if (!(png_ptr->zstream.avail_in))
  173449. {
  173450. while (!png_ptr->idat_size)
  173451. {
  173452. png_byte chunk_length[4];
  173453. png_crc_finish(png_ptr, 0);
  173454. png_read_data(png_ptr, chunk_length, 4);
  173455. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173456. png_reset_crc(png_ptr);
  173457. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173458. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173459. png_error(png_ptr, "Not enough image data");
  173460. }
  173461. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173462. png_ptr->zstream.next_in = png_ptr->zbuf;
  173463. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173464. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173465. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173466. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173467. }
  173468. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173469. if (ret == Z_STREAM_END)
  173470. {
  173471. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173472. png_ptr->idat_size)
  173473. png_warning(png_ptr, "Extra compressed data");
  173474. png_ptr->mode |= PNG_AFTER_IDAT;
  173475. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173476. break;
  173477. }
  173478. if (ret != Z_OK)
  173479. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173480. "Decompression Error");
  173481. if (!(png_ptr->zstream.avail_out))
  173482. {
  173483. png_warning(png_ptr, "Extra compressed data.");
  173484. png_ptr->mode |= PNG_AFTER_IDAT;
  173485. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173486. break;
  173487. }
  173488. }
  173489. png_ptr->zstream.avail_out = 0;
  173490. }
  173491. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173492. png_warning(png_ptr, "Extra compression data");
  173493. inflateReset(&png_ptr->zstream);
  173494. png_ptr->mode |= PNG_AFTER_IDAT;
  173495. }
  173496. void /* PRIVATE */
  173497. png_read_start_row(png_structp png_ptr)
  173498. {
  173499. #ifdef PNG_USE_LOCAL_ARRAYS
  173500. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173501. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173502. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173503. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173504. #endif
  173505. int max_pixel_depth;
  173506. png_uint_32 row_bytes;
  173507. png_debug(1, "in png_read_start_row\n");
  173508. png_ptr->zstream.avail_in = 0;
  173509. png_init_read_transformations(png_ptr);
  173510. if (png_ptr->interlaced)
  173511. {
  173512. if (!(png_ptr->transformations & PNG_INTERLACE))
  173513. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173514. png_pass_ystart[0]) / png_pass_yinc[0];
  173515. else
  173516. png_ptr->num_rows = png_ptr->height;
  173517. png_ptr->iwidth = (png_ptr->width +
  173518. png_pass_inc[png_ptr->pass] - 1 -
  173519. png_pass_start[png_ptr->pass]) /
  173520. png_pass_inc[png_ptr->pass];
  173521. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173522. png_ptr->irowbytes = (png_size_t)row_bytes;
  173523. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173524. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173525. }
  173526. else
  173527. {
  173528. png_ptr->num_rows = png_ptr->height;
  173529. png_ptr->iwidth = png_ptr->width;
  173530. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173531. }
  173532. max_pixel_depth = png_ptr->pixel_depth;
  173533. #if defined(PNG_READ_PACK_SUPPORTED)
  173534. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173535. max_pixel_depth = 8;
  173536. #endif
  173537. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173538. if (png_ptr->transformations & PNG_EXPAND)
  173539. {
  173540. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173541. {
  173542. if (png_ptr->num_trans)
  173543. max_pixel_depth = 32;
  173544. else
  173545. max_pixel_depth = 24;
  173546. }
  173547. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173548. {
  173549. if (max_pixel_depth < 8)
  173550. max_pixel_depth = 8;
  173551. if (png_ptr->num_trans)
  173552. max_pixel_depth *= 2;
  173553. }
  173554. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173555. {
  173556. if (png_ptr->num_trans)
  173557. {
  173558. max_pixel_depth *= 4;
  173559. max_pixel_depth /= 3;
  173560. }
  173561. }
  173562. }
  173563. #endif
  173564. #if defined(PNG_READ_FILLER_SUPPORTED)
  173565. if (png_ptr->transformations & (PNG_FILLER))
  173566. {
  173567. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173568. max_pixel_depth = 32;
  173569. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173570. {
  173571. if (max_pixel_depth <= 8)
  173572. max_pixel_depth = 16;
  173573. else
  173574. max_pixel_depth = 32;
  173575. }
  173576. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173577. {
  173578. if (max_pixel_depth <= 32)
  173579. max_pixel_depth = 32;
  173580. else
  173581. max_pixel_depth = 64;
  173582. }
  173583. }
  173584. #endif
  173585. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173586. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173587. {
  173588. if (
  173589. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173590. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173591. #endif
  173592. #if defined(PNG_READ_FILLER_SUPPORTED)
  173593. (png_ptr->transformations & (PNG_FILLER)) ||
  173594. #endif
  173595. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173596. {
  173597. if (max_pixel_depth <= 16)
  173598. max_pixel_depth = 32;
  173599. else
  173600. max_pixel_depth = 64;
  173601. }
  173602. else
  173603. {
  173604. if (max_pixel_depth <= 8)
  173605. {
  173606. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173607. max_pixel_depth = 32;
  173608. else
  173609. max_pixel_depth = 24;
  173610. }
  173611. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173612. max_pixel_depth = 64;
  173613. else
  173614. max_pixel_depth = 48;
  173615. }
  173616. }
  173617. #endif
  173618. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173619. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173620. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173621. {
  173622. int user_pixel_depth=png_ptr->user_transform_depth*
  173623. png_ptr->user_transform_channels;
  173624. if(user_pixel_depth > max_pixel_depth)
  173625. max_pixel_depth=user_pixel_depth;
  173626. }
  173627. #endif
  173628. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173629. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173630. 1 + ((max_pixel_depth + 7) >> 3);
  173631. #ifdef PNG_MAX_MALLOC_64K
  173632. if (row_bytes > (png_uint_32)65536L)
  173633. png_error(png_ptr, "This image requires a row greater than 64KB");
  173634. #endif
  173635. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173636. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173637. #ifdef PNG_MAX_MALLOC_64K
  173638. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173639. png_error(png_ptr, "This image requires a row greater than 64KB");
  173640. #endif
  173641. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173642. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173643. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173644. png_ptr->rowbytes + 1));
  173645. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173646. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173647. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173648. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173649. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173650. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173651. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173652. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173653. }
  173654. #endif /* PNG_READ_SUPPORTED */
  173655. /*** End of inlined file: pngrutil.c ***/
  173656. /*** Start of inlined file: pngset.c ***/
  173657. #define PNG_INTERNAL
  173658. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173659. #if defined(PNG_bKGD_SUPPORTED)
  173660. void PNGAPI
  173661. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173662. {
  173663. png_debug1(1, "in %s storage function\n", "bKGD");
  173664. if (png_ptr == NULL || info_ptr == NULL)
  173665. return;
  173666. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173667. info_ptr->valid |= PNG_INFO_bKGD;
  173668. }
  173669. #endif
  173670. #if defined(PNG_cHRM_SUPPORTED)
  173671. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173672. void PNGAPI
  173673. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173674. double white_x, double white_y, double red_x, double red_y,
  173675. double green_x, double green_y, double blue_x, double blue_y)
  173676. {
  173677. png_debug1(1, "in %s storage function\n", "cHRM");
  173678. if (png_ptr == NULL || info_ptr == NULL)
  173679. return;
  173680. if (white_x < 0.0 || white_y < 0.0 ||
  173681. red_x < 0.0 || red_y < 0.0 ||
  173682. green_x < 0.0 || green_y < 0.0 ||
  173683. blue_x < 0.0 || blue_y < 0.0)
  173684. {
  173685. png_warning(png_ptr,
  173686. "Ignoring attempt to set negative chromaticity value");
  173687. return;
  173688. }
  173689. if (white_x > 21474.83 || white_y > 21474.83 ||
  173690. red_x > 21474.83 || red_y > 21474.83 ||
  173691. green_x > 21474.83 || green_y > 21474.83 ||
  173692. blue_x > 21474.83 || blue_y > 21474.83)
  173693. {
  173694. png_warning(png_ptr,
  173695. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173696. return;
  173697. }
  173698. info_ptr->x_white = (float)white_x;
  173699. info_ptr->y_white = (float)white_y;
  173700. info_ptr->x_red = (float)red_x;
  173701. info_ptr->y_red = (float)red_y;
  173702. info_ptr->x_green = (float)green_x;
  173703. info_ptr->y_green = (float)green_y;
  173704. info_ptr->x_blue = (float)blue_x;
  173705. info_ptr->y_blue = (float)blue_y;
  173706. #ifdef PNG_FIXED_POINT_SUPPORTED
  173707. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173708. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173709. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173710. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173711. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173712. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173713. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173714. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173715. #endif
  173716. info_ptr->valid |= PNG_INFO_cHRM;
  173717. }
  173718. #endif
  173719. #ifdef PNG_FIXED_POINT_SUPPORTED
  173720. void PNGAPI
  173721. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173722. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173723. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173724. png_fixed_point blue_x, png_fixed_point blue_y)
  173725. {
  173726. png_debug1(1, "in %s storage function\n", "cHRM");
  173727. if (png_ptr == NULL || info_ptr == NULL)
  173728. return;
  173729. if (white_x < 0 || white_y < 0 ||
  173730. red_x < 0 || red_y < 0 ||
  173731. green_x < 0 || green_y < 0 ||
  173732. blue_x < 0 || blue_y < 0)
  173733. {
  173734. png_warning(png_ptr,
  173735. "Ignoring attempt to set negative chromaticity value");
  173736. return;
  173737. }
  173738. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173739. if (white_x > (double) PNG_UINT_31_MAX ||
  173740. white_y > (double) PNG_UINT_31_MAX ||
  173741. red_x > (double) PNG_UINT_31_MAX ||
  173742. red_y > (double) PNG_UINT_31_MAX ||
  173743. green_x > (double) PNG_UINT_31_MAX ||
  173744. green_y > (double) PNG_UINT_31_MAX ||
  173745. blue_x > (double) PNG_UINT_31_MAX ||
  173746. blue_y > (double) PNG_UINT_31_MAX)
  173747. #else
  173748. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173749. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173750. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173751. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173752. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173753. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173754. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173755. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173756. #endif
  173757. {
  173758. png_warning(png_ptr,
  173759. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173760. return;
  173761. }
  173762. info_ptr->int_x_white = white_x;
  173763. info_ptr->int_y_white = white_y;
  173764. info_ptr->int_x_red = red_x;
  173765. info_ptr->int_y_red = red_y;
  173766. info_ptr->int_x_green = green_x;
  173767. info_ptr->int_y_green = green_y;
  173768. info_ptr->int_x_blue = blue_x;
  173769. info_ptr->int_y_blue = blue_y;
  173770. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173771. info_ptr->x_white = (float)(white_x/100000.);
  173772. info_ptr->y_white = (float)(white_y/100000.);
  173773. info_ptr->x_red = (float)( red_x/100000.);
  173774. info_ptr->y_red = (float)( red_y/100000.);
  173775. info_ptr->x_green = (float)(green_x/100000.);
  173776. info_ptr->y_green = (float)(green_y/100000.);
  173777. info_ptr->x_blue = (float)( blue_x/100000.);
  173778. info_ptr->y_blue = (float)( blue_y/100000.);
  173779. #endif
  173780. info_ptr->valid |= PNG_INFO_cHRM;
  173781. }
  173782. #endif
  173783. #endif
  173784. #if defined(PNG_gAMA_SUPPORTED)
  173785. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173786. void PNGAPI
  173787. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173788. {
  173789. double gamma;
  173790. png_debug1(1, "in %s storage function\n", "gAMA");
  173791. if (png_ptr == NULL || info_ptr == NULL)
  173792. return;
  173793. if (file_gamma > 21474.83)
  173794. {
  173795. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173796. gamma=21474.83;
  173797. }
  173798. else
  173799. gamma=file_gamma;
  173800. info_ptr->gamma = (float)gamma;
  173801. #ifdef PNG_FIXED_POINT_SUPPORTED
  173802. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173803. #endif
  173804. info_ptr->valid |= PNG_INFO_gAMA;
  173805. if(gamma == 0.0)
  173806. png_warning(png_ptr, "Setting gamma=0");
  173807. }
  173808. #endif
  173809. void PNGAPI
  173810. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173811. int_gamma)
  173812. {
  173813. png_fixed_point gamma;
  173814. png_debug1(1, "in %s storage function\n", "gAMA");
  173815. if (png_ptr == NULL || info_ptr == NULL)
  173816. return;
  173817. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173818. {
  173819. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173820. gamma=PNG_UINT_31_MAX;
  173821. }
  173822. else
  173823. {
  173824. if (int_gamma < 0)
  173825. {
  173826. png_warning(png_ptr, "Setting negative gamma to zero");
  173827. gamma=0;
  173828. }
  173829. else
  173830. gamma=int_gamma;
  173831. }
  173832. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173833. info_ptr->gamma = (float)(gamma/100000.);
  173834. #endif
  173835. #ifdef PNG_FIXED_POINT_SUPPORTED
  173836. info_ptr->int_gamma = gamma;
  173837. #endif
  173838. info_ptr->valid |= PNG_INFO_gAMA;
  173839. if(gamma == 0)
  173840. png_warning(png_ptr, "Setting gamma=0");
  173841. }
  173842. #endif
  173843. #if defined(PNG_hIST_SUPPORTED)
  173844. void PNGAPI
  173845. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173846. {
  173847. int i;
  173848. png_debug1(1, "in %s storage function\n", "hIST");
  173849. if (png_ptr == NULL || info_ptr == NULL)
  173850. return;
  173851. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173852. > PNG_MAX_PALETTE_LENGTH)
  173853. {
  173854. png_warning(png_ptr,
  173855. "Invalid palette size, hIST allocation skipped.");
  173856. return;
  173857. }
  173858. #ifdef PNG_FREE_ME_SUPPORTED
  173859. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173860. #endif
  173861. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173862. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173863. if (png_ptr->hist == NULL)
  173864. {
  173865. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173866. return;
  173867. }
  173868. for (i = 0; i < info_ptr->num_palette; i++)
  173869. png_ptr->hist[i] = hist[i];
  173870. info_ptr->hist = png_ptr->hist;
  173871. info_ptr->valid |= PNG_INFO_hIST;
  173872. #ifdef PNG_FREE_ME_SUPPORTED
  173873. info_ptr->free_me |= PNG_FREE_HIST;
  173874. #else
  173875. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173876. #endif
  173877. }
  173878. #endif
  173879. void PNGAPI
  173880. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173881. png_uint_32 width, png_uint_32 height, int bit_depth,
  173882. int color_type, int interlace_type, int compression_type,
  173883. int filter_type)
  173884. {
  173885. png_debug1(1, "in %s storage function\n", "IHDR");
  173886. if (png_ptr == NULL || info_ptr == NULL)
  173887. return;
  173888. if (width == 0 || height == 0)
  173889. png_error(png_ptr, "Image width or height is zero in IHDR");
  173890. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173891. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173892. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173893. #else
  173894. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173895. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173896. #endif
  173897. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173898. png_error(png_ptr, "Invalid image size in IHDR");
  173899. if ( width > (PNG_UINT_32_MAX
  173900. >> 3) /* 8-byte RGBA pixels */
  173901. - 64 /* bigrowbuf hack */
  173902. - 1 /* filter byte */
  173903. - 7*8 /* rounding of width to multiple of 8 pixels */
  173904. - 8) /* extra max_pixel_depth pad */
  173905. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173906. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173907. bit_depth != 8 && bit_depth != 16)
  173908. png_error(png_ptr, "Invalid bit depth in IHDR");
  173909. if (color_type < 0 || color_type == 1 ||
  173910. color_type == 5 || color_type > 6)
  173911. png_error(png_ptr, "Invalid color type in IHDR");
  173912. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173913. ((color_type == PNG_COLOR_TYPE_RGB ||
  173914. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173915. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173916. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173917. if (interlace_type >= PNG_INTERLACE_LAST)
  173918. png_error(png_ptr, "Unknown interlace method in IHDR");
  173919. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173920. png_error(png_ptr, "Unknown compression method in IHDR");
  173921. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173922. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173923. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173924. if(filter_type != PNG_FILTER_TYPE_BASE)
  173925. {
  173926. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173927. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173928. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173929. (color_type == PNG_COLOR_TYPE_RGB ||
  173930. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173931. png_error(png_ptr, "Unknown filter method in IHDR");
  173932. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173933. png_warning(png_ptr, "Invalid filter method in IHDR");
  173934. }
  173935. #else
  173936. if(filter_type != PNG_FILTER_TYPE_BASE)
  173937. png_error(png_ptr, "Unknown filter method in IHDR");
  173938. #endif
  173939. info_ptr->width = width;
  173940. info_ptr->height = height;
  173941. info_ptr->bit_depth = (png_byte)bit_depth;
  173942. info_ptr->color_type =(png_byte) color_type;
  173943. info_ptr->compression_type = (png_byte)compression_type;
  173944. info_ptr->filter_type = (png_byte)filter_type;
  173945. info_ptr->interlace_type = (png_byte)interlace_type;
  173946. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173947. info_ptr->channels = 1;
  173948. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173949. info_ptr->channels = 3;
  173950. else
  173951. info_ptr->channels = 1;
  173952. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173953. info_ptr->channels++;
  173954. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173955. if (width > (PNG_UINT_32_MAX
  173956. >> 3) /* 8-byte RGBA pixels */
  173957. - 64 /* bigrowbuf hack */
  173958. - 1 /* filter byte */
  173959. - 7*8 /* rounding of width to multiple of 8 pixels */
  173960. - 8) /* extra max_pixel_depth pad */
  173961. info_ptr->rowbytes = (png_size_t)0;
  173962. else
  173963. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173964. }
  173965. #if defined(PNG_oFFs_SUPPORTED)
  173966. void PNGAPI
  173967. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173968. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173969. {
  173970. png_debug1(1, "in %s storage function\n", "oFFs");
  173971. if (png_ptr == NULL || info_ptr == NULL)
  173972. return;
  173973. info_ptr->x_offset = offset_x;
  173974. info_ptr->y_offset = offset_y;
  173975. info_ptr->offset_unit_type = (png_byte)unit_type;
  173976. info_ptr->valid |= PNG_INFO_oFFs;
  173977. }
  173978. #endif
  173979. #if defined(PNG_pCAL_SUPPORTED)
  173980. void PNGAPI
  173981. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173982. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173983. png_charp units, png_charpp params)
  173984. {
  173985. png_uint_32 length;
  173986. int i;
  173987. png_debug1(1, "in %s storage function\n", "pCAL");
  173988. if (png_ptr == NULL || info_ptr == NULL)
  173989. return;
  173990. length = png_strlen(purpose) + 1;
  173991. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173992. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173993. if (info_ptr->pcal_purpose == NULL)
  173994. {
  173995. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173996. return;
  173997. }
  173998. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173999. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  174000. info_ptr->pcal_X0 = X0;
  174001. info_ptr->pcal_X1 = X1;
  174002. info_ptr->pcal_type = (png_byte)type;
  174003. info_ptr->pcal_nparams = (png_byte)nparams;
  174004. length = png_strlen(units) + 1;
  174005. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  174006. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  174007. if (info_ptr->pcal_units == NULL)
  174008. {
  174009. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  174010. return;
  174011. }
  174012. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  174013. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  174014. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  174015. if (info_ptr->pcal_params == NULL)
  174016. {
  174017. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  174018. return;
  174019. }
  174020. info_ptr->pcal_params[nparams] = NULL;
  174021. for (i = 0; i < nparams; i++)
  174022. {
  174023. length = png_strlen(params[i]) + 1;
  174024. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  174025. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  174026. if (info_ptr->pcal_params[i] == NULL)
  174027. {
  174028. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  174029. return;
  174030. }
  174031. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  174032. }
  174033. info_ptr->valid |= PNG_INFO_pCAL;
  174034. #ifdef PNG_FREE_ME_SUPPORTED
  174035. info_ptr->free_me |= PNG_FREE_PCAL;
  174036. #endif
  174037. }
  174038. #endif
  174039. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  174040. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174041. void PNGAPI
  174042. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  174043. int unit, double width, double height)
  174044. {
  174045. png_debug1(1, "in %s storage function\n", "sCAL");
  174046. if (png_ptr == NULL || info_ptr == NULL)
  174047. return;
  174048. info_ptr->scal_unit = (png_byte)unit;
  174049. info_ptr->scal_pixel_width = width;
  174050. info_ptr->scal_pixel_height = height;
  174051. info_ptr->valid |= PNG_INFO_sCAL;
  174052. }
  174053. #else
  174054. #ifdef PNG_FIXED_POINT_SUPPORTED
  174055. void PNGAPI
  174056. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  174057. int unit, png_charp swidth, png_charp sheight)
  174058. {
  174059. png_uint_32 length;
  174060. png_debug1(1, "in %s storage function\n", "sCAL");
  174061. if (png_ptr == NULL || info_ptr == NULL)
  174062. return;
  174063. info_ptr->scal_unit = (png_byte)unit;
  174064. length = png_strlen(swidth) + 1;
  174065. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174066. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  174067. if (info_ptr->scal_s_width == NULL)
  174068. {
  174069. png_warning(png_ptr,
  174070. "Memory allocation failed while processing sCAL.");
  174071. }
  174072. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  174073. length = png_strlen(sheight) + 1;
  174074. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174075. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  174076. if (info_ptr->scal_s_height == NULL)
  174077. {
  174078. png_free (png_ptr, info_ptr->scal_s_width);
  174079. png_warning(png_ptr,
  174080. "Memory allocation failed while processing sCAL.");
  174081. }
  174082. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  174083. info_ptr->valid |= PNG_INFO_sCAL;
  174084. #ifdef PNG_FREE_ME_SUPPORTED
  174085. info_ptr->free_me |= PNG_FREE_SCAL;
  174086. #endif
  174087. }
  174088. #endif
  174089. #endif
  174090. #endif
  174091. #if defined(PNG_pHYs_SUPPORTED)
  174092. void PNGAPI
  174093. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  174094. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  174095. {
  174096. png_debug1(1, "in %s storage function\n", "pHYs");
  174097. if (png_ptr == NULL || info_ptr == NULL)
  174098. return;
  174099. info_ptr->x_pixels_per_unit = res_x;
  174100. info_ptr->y_pixels_per_unit = res_y;
  174101. info_ptr->phys_unit_type = (png_byte)unit_type;
  174102. info_ptr->valid |= PNG_INFO_pHYs;
  174103. }
  174104. #endif
  174105. void PNGAPI
  174106. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  174107. png_colorp palette, int num_palette)
  174108. {
  174109. png_debug1(1, "in %s storage function\n", "PLTE");
  174110. if (png_ptr == NULL || info_ptr == NULL)
  174111. return;
  174112. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  174113. {
  174114. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174115. png_error(png_ptr, "Invalid palette length");
  174116. else
  174117. {
  174118. png_warning(png_ptr, "Invalid palette length");
  174119. return;
  174120. }
  174121. }
  174122. #ifdef PNG_FREE_ME_SUPPORTED
  174123. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  174124. #endif
  174125. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  174126. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  174127. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  174128. png_sizeof(png_color));
  174129. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  174130. info_ptr->palette = png_ptr->palette;
  174131. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  174132. #ifdef PNG_FREE_ME_SUPPORTED
  174133. info_ptr->free_me |= PNG_FREE_PLTE;
  174134. #else
  174135. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  174136. #endif
  174137. info_ptr->valid |= PNG_INFO_PLTE;
  174138. }
  174139. #if defined(PNG_sBIT_SUPPORTED)
  174140. void PNGAPI
  174141. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  174142. png_color_8p sig_bit)
  174143. {
  174144. png_debug1(1, "in %s storage function\n", "sBIT");
  174145. if (png_ptr == NULL || info_ptr == NULL)
  174146. return;
  174147. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  174148. info_ptr->valid |= PNG_INFO_sBIT;
  174149. }
  174150. #endif
  174151. #if defined(PNG_sRGB_SUPPORTED)
  174152. void PNGAPI
  174153. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  174154. {
  174155. png_debug1(1, "in %s storage function\n", "sRGB");
  174156. if (png_ptr == NULL || info_ptr == NULL)
  174157. return;
  174158. info_ptr->srgb_intent = (png_byte)intent;
  174159. info_ptr->valid |= PNG_INFO_sRGB;
  174160. }
  174161. void PNGAPI
  174162. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  174163. int intent)
  174164. {
  174165. #if defined(PNG_gAMA_SUPPORTED)
  174166. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174167. float file_gamma;
  174168. #endif
  174169. #ifdef PNG_FIXED_POINT_SUPPORTED
  174170. png_fixed_point int_file_gamma;
  174171. #endif
  174172. #endif
  174173. #if defined(PNG_cHRM_SUPPORTED)
  174174. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174175. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  174176. #endif
  174177. #ifdef PNG_FIXED_POINT_SUPPORTED
  174178. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  174179. int_green_y, int_blue_x, int_blue_y;
  174180. #endif
  174181. #endif
  174182. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  174183. if (png_ptr == NULL || info_ptr == NULL)
  174184. return;
  174185. png_set_sRGB(png_ptr, info_ptr, intent);
  174186. #if defined(PNG_gAMA_SUPPORTED)
  174187. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174188. file_gamma = (float).45455;
  174189. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  174190. #endif
  174191. #ifdef PNG_FIXED_POINT_SUPPORTED
  174192. int_file_gamma = 45455L;
  174193. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  174194. #endif
  174195. #endif
  174196. #if defined(PNG_cHRM_SUPPORTED)
  174197. #ifdef PNG_FIXED_POINT_SUPPORTED
  174198. int_white_x = 31270L;
  174199. int_white_y = 32900L;
  174200. int_red_x = 64000L;
  174201. int_red_y = 33000L;
  174202. int_green_x = 30000L;
  174203. int_green_y = 60000L;
  174204. int_blue_x = 15000L;
  174205. int_blue_y = 6000L;
  174206. png_set_cHRM_fixed(png_ptr, info_ptr,
  174207. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  174208. int_blue_x, int_blue_y);
  174209. #endif
  174210. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174211. white_x = (float).3127;
  174212. white_y = (float).3290;
  174213. red_x = (float).64;
  174214. red_y = (float).33;
  174215. green_x = (float).30;
  174216. green_y = (float).60;
  174217. blue_x = (float).15;
  174218. blue_y = (float).06;
  174219. png_set_cHRM(png_ptr, info_ptr,
  174220. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  174221. #endif
  174222. #endif
  174223. }
  174224. #endif
  174225. #if defined(PNG_iCCP_SUPPORTED)
  174226. void PNGAPI
  174227. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  174228. png_charp name, int compression_type,
  174229. png_charp profile, png_uint_32 proflen)
  174230. {
  174231. png_charp new_iccp_name;
  174232. png_charp new_iccp_profile;
  174233. png_debug1(1, "in %s storage function\n", "iCCP");
  174234. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  174235. return;
  174236. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  174237. if (new_iccp_name == NULL)
  174238. {
  174239. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  174240. return;
  174241. }
  174242. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  174243. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  174244. if (new_iccp_profile == NULL)
  174245. {
  174246. png_free (png_ptr, new_iccp_name);
  174247. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  174248. return;
  174249. }
  174250. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  174251. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  174252. info_ptr->iccp_proflen = proflen;
  174253. info_ptr->iccp_name = new_iccp_name;
  174254. info_ptr->iccp_profile = new_iccp_profile;
  174255. info_ptr->iccp_compression = (png_byte)compression_type;
  174256. #ifdef PNG_FREE_ME_SUPPORTED
  174257. info_ptr->free_me |= PNG_FREE_ICCP;
  174258. #endif
  174259. info_ptr->valid |= PNG_INFO_iCCP;
  174260. }
  174261. #endif
  174262. #if defined(PNG_TEXT_SUPPORTED)
  174263. void PNGAPI
  174264. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174265. int num_text)
  174266. {
  174267. int ret;
  174268. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  174269. if (ret)
  174270. png_error(png_ptr, "Insufficient memory to store text");
  174271. }
  174272. int /* PRIVATE */
  174273. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174274. int num_text)
  174275. {
  174276. int i;
  174277. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  174278. "text" : (png_const_charp)png_ptr->chunk_name));
  174279. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  174280. return(0);
  174281. if (info_ptr->num_text + num_text > info_ptr->max_text)
  174282. {
  174283. if (info_ptr->text != NULL)
  174284. {
  174285. png_textp old_text;
  174286. int old_max;
  174287. old_max = info_ptr->max_text;
  174288. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174289. old_text = info_ptr->text;
  174290. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174291. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174292. if (info_ptr->text == NULL)
  174293. {
  174294. png_free(png_ptr, old_text);
  174295. return(1);
  174296. }
  174297. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174298. png_sizeof(png_text)));
  174299. png_free(png_ptr, old_text);
  174300. }
  174301. else
  174302. {
  174303. info_ptr->max_text = num_text + 8;
  174304. info_ptr->num_text = 0;
  174305. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174306. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174307. if (info_ptr->text == NULL)
  174308. return(1);
  174309. #ifdef PNG_FREE_ME_SUPPORTED
  174310. info_ptr->free_me |= PNG_FREE_TEXT;
  174311. #endif
  174312. }
  174313. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174314. info_ptr->max_text);
  174315. }
  174316. for (i = 0; i < num_text; i++)
  174317. {
  174318. png_size_t text_length,key_len;
  174319. png_size_t lang_len,lang_key_len;
  174320. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174321. if (text_ptr[i].key == NULL)
  174322. continue;
  174323. key_len = png_strlen(text_ptr[i].key);
  174324. if(text_ptr[i].compression <= 0)
  174325. {
  174326. lang_len = 0;
  174327. lang_key_len = 0;
  174328. }
  174329. else
  174330. #ifdef PNG_iTXt_SUPPORTED
  174331. {
  174332. if (text_ptr[i].lang != NULL)
  174333. lang_len = png_strlen(text_ptr[i].lang);
  174334. else
  174335. lang_len = 0;
  174336. if (text_ptr[i].lang_key != NULL)
  174337. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174338. else
  174339. lang_key_len = 0;
  174340. }
  174341. #else
  174342. {
  174343. png_warning(png_ptr, "iTXt chunk not supported.");
  174344. continue;
  174345. }
  174346. #endif
  174347. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174348. {
  174349. text_length = 0;
  174350. #ifdef PNG_iTXt_SUPPORTED
  174351. if(text_ptr[i].compression > 0)
  174352. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174353. else
  174354. #endif
  174355. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174356. }
  174357. else
  174358. {
  174359. text_length = png_strlen(text_ptr[i].text);
  174360. textp->compression = text_ptr[i].compression;
  174361. }
  174362. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174363. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174364. if (textp->key == NULL)
  174365. return(1);
  174366. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174367. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174368. (int)textp->key);
  174369. png_memcpy(textp->key, text_ptr[i].key,
  174370. (png_size_t)(key_len));
  174371. *(textp->key+key_len) = '\0';
  174372. #ifdef PNG_iTXt_SUPPORTED
  174373. if (text_ptr[i].compression > 0)
  174374. {
  174375. textp->lang=textp->key + key_len + 1;
  174376. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174377. *(textp->lang+lang_len) = '\0';
  174378. textp->lang_key=textp->lang + lang_len + 1;
  174379. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174380. *(textp->lang_key+lang_key_len) = '\0';
  174381. textp->text=textp->lang_key + lang_key_len + 1;
  174382. }
  174383. else
  174384. #endif
  174385. {
  174386. #ifdef PNG_iTXt_SUPPORTED
  174387. textp->lang=NULL;
  174388. textp->lang_key=NULL;
  174389. #endif
  174390. textp->text=textp->key + key_len + 1;
  174391. }
  174392. if(text_length)
  174393. png_memcpy(textp->text, text_ptr[i].text,
  174394. (png_size_t)(text_length));
  174395. *(textp->text+text_length) = '\0';
  174396. #ifdef PNG_iTXt_SUPPORTED
  174397. if(textp->compression > 0)
  174398. {
  174399. textp->text_length = 0;
  174400. textp->itxt_length = text_length;
  174401. }
  174402. else
  174403. #endif
  174404. {
  174405. textp->text_length = text_length;
  174406. #ifdef PNG_iTXt_SUPPORTED
  174407. textp->itxt_length = 0;
  174408. #endif
  174409. }
  174410. info_ptr->num_text++;
  174411. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174412. }
  174413. return(0);
  174414. }
  174415. #endif
  174416. #if defined(PNG_tIME_SUPPORTED)
  174417. void PNGAPI
  174418. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174419. {
  174420. png_debug1(1, "in %s storage function\n", "tIME");
  174421. if (png_ptr == NULL || info_ptr == NULL ||
  174422. (png_ptr->mode & PNG_WROTE_tIME))
  174423. return;
  174424. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174425. info_ptr->valid |= PNG_INFO_tIME;
  174426. }
  174427. #endif
  174428. #if defined(PNG_tRNS_SUPPORTED)
  174429. void PNGAPI
  174430. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174431. png_bytep trans, int num_trans, png_color_16p trans_values)
  174432. {
  174433. png_debug1(1, "in %s storage function\n", "tRNS");
  174434. if (png_ptr == NULL || info_ptr == NULL)
  174435. return;
  174436. if (trans != NULL)
  174437. {
  174438. #ifdef PNG_FREE_ME_SUPPORTED
  174439. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174440. #endif
  174441. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174442. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174443. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174444. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174445. #ifdef PNG_FREE_ME_SUPPORTED
  174446. info_ptr->free_me |= PNG_FREE_TRNS;
  174447. #else
  174448. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174449. #endif
  174450. }
  174451. if (trans_values != NULL)
  174452. {
  174453. png_memcpy(&(info_ptr->trans_values), trans_values,
  174454. png_sizeof(png_color_16));
  174455. if (num_trans == 0)
  174456. num_trans = 1;
  174457. }
  174458. info_ptr->num_trans = (png_uint_16)num_trans;
  174459. info_ptr->valid |= PNG_INFO_tRNS;
  174460. }
  174461. #endif
  174462. #if defined(PNG_sPLT_SUPPORTED)
  174463. void PNGAPI
  174464. png_set_sPLT(png_structp png_ptr,
  174465. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174466. {
  174467. png_sPLT_tp np;
  174468. int i;
  174469. if (png_ptr == NULL || info_ptr == NULL)
  174470. return;
  174471. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174472. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174473. if (np == NULL)
  174474. {
  174475. png_warning(png_ptr, "No memory for sPLT palettes.");
  174476. return;
  174477. }
  174478. png_memcpy(np, info_ptr->splt_palettes,
  174479. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174480. png_free(png_ptr, info_ptr->splt_palettes);
  174481. info_ptr->splt_palettes=NULL;
  174482. for (i = 0; i < nentries; i++)
  174483. {
  174484. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174485. png_sPLT_tp from = entries + i;
  174486. to->name = (png_charp)png_malloc_warn(png_ptr,
  174487. png_strlen(from->name) + 1);
  174488. if (to->name == NULL)
  174489. {
  174490. png_warning(png_ptr,
  174491. "Out of memory while processing sPLT chunk");
  174492. }
  174493. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174494. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174495. from->nentries * png_sizeof(png_sPLT_entry));
  174496. png_memcpy(to->entries, from->entries,
  174497. from->nentries * png_sizeof(png_sPLT_entry));
  174498. if (to->entries == NULL)
  174499. {
  174500. png_warning(png_ptr,
  174501. "Out of memory while processing sPLT chunk");
  174502. png_free(png_ptr,to->name);
  174503. to->name = NULL;
  174504. }
  174505. to->nentries = from->nentries;
  174506. to->depth = from->depth;
  174507. }
  174508. info_ptr->splt_palettes = np;
  174509. info_ptr->splt_palettes_num += nentries;
  174510. info_ptr->valid |= PNG_INFO_sPLT;
  174511. #ifdef PNG_FREE_ME_SUPPORTED
  174512. info_ptr->free_me |= PNG_FREE_SPLT;
  174513. #endif
  174514. }
  174515. #endif /* PNG_sPLT_SUPPORTED */
  174516. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174517. void PNGAPI
  174518. png_set_unknown_chunks(png_structp png_ptr,
  174519. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174520. {
  174521. png_unknown_chunkp np;
  174522. int i;
  174523. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174524. return;
  174525. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174526. (info_ptr->unknown_chunks_num + num_unknowns) *
  174527. png_sizeof(png_unknown_chunk));
  174528. if (np == NULL)
  174529. {
  174530. png_warning(png_ptr,
  174531. "Out of memory while processing unknown chunk.");
  174532. return;
  174533. }
  174534. png_memcpy(np, info_ptr->unknown_chunks,
  174535. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174536. png_free(png_ptr, info_ptr->unknown_chunks);
  174537. info_ptr->unknown_chunks=NULL;
  174538. for (i = 0; i < num_unknowns; i++)
  174539. {
  174540. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174541. png_unknown_chunkp from = unknowns + i;
  174542. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174543. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174544. if (to->data == NULL)
  174545. {
  174546. png_warning(png_ptr,
  174547. "Out of memory while processing unknown chunk.");
  174548. }
  174549. else
  174550. {
  174551. png_memcpy(to->data, from->data, from->size);
  174552. to->size = from->size;
  174553. to->location = (png_byte)(png_ptr->mode & 0xff);
  174554. }
  174555. }
  174556. info_ptr->unknown_chunks = np;
  174557. info_ptr->unknown_chunks_num += num_unknowns;
  174558. #ifdef PNG_FREE_ME_SUPPORTED
  174559. info_ptr->free_me |= PNG_FREE_UNKN;
  174560. #endif
  174561. }
  174562. void PNGAPI
  174563. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174564. int chunk, int location)
  174565. {
  174566. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174567. (int)info_ptr->unknown_chunks_num)
  174568. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174569. }
  174570. #endif
  174571. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174572. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174573. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174574. void PNGAPI
  174575. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174576. {
  174577. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174578. if (png_ptr == NULL)
  174579. return;
  174580. png_ptr->mng_features_permitted = (png_byte)
  174581. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174582. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174583. }
  174584. #endif
  174585. #endif
  174586. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174587. png_uint_32 PNGAPI
  174588. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174589. {
  174590. png_debug(1, "in png_permit_mng_features\n");
  174591. if (png_ptr == NULL)
  174592. return (png_uint_32)0;
  174593. png_ptr->mng_features_permitted =
  174594. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174595. return (png_uint_32)png_ptr->mng_features_permitted;
  174596. }
  174597. #endif
  174598. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174599. void PNGAPI
  174600. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174601. chunk_list, int num_chunks)
  174602. {
  174603. png_bytep new_list, p;
  174604. int i, old_num_chunks;
  174605. if (png_ptr == NULL)
  174606. return;
  174607. if (num_chunks == 0)
  174608. {
  174609. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174610. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174611. else
  174612. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174613. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174614. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174615. else
  174616. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174617. return;
  174618. }
  174619. if (chunk_list == NULL)
  174620. return;
  174621. old_num_chunks=png_ptr->num_chunk_list;
  174622. new_list=(png_bytep)png_malloc(png_ptr,
  174623. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174624. if(png_ptr->chunk_list != NULL)
  174625. {
  174626. png_memcpy(new_list, png_ptr->chunk_list,
  174627. (png_size_t)(5*old_num_chunks));
  174628. png_free(png_ptr, png_ptr->chunk_list);
  174629. png_ptr->chunk_list=NULL;
  174630. }
  174631. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174632. (png_size_t)(5*num_chunks));
  174633. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174634. *p=(png_byte)keep;
  174635. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174636. png_ptr->chunk_list=new_list;
  174637. #ifdef PNG_FREE_ME_SUPPORTED
  174638. png_ptr->free_me |= PNG_FREE_LIST;
  174639. #endif
  174640. }
  174641. #endif
  174642. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174643. void PNGAPI
  174644. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174645. png_user_chunk_ptr read_user_chunk_fn)
  174646. {
  174647. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174648. if (png_ptr == NULL)
  174649. return;
  174650. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174651. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174652. }
  174653. #endif
  174654. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174655. void PNGAPI
  174656. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174657. {
  174658. png_debug1(1, "in %s storage function\n", "rows");
  174659. if (png_ptr == NULL || info_ptr == NULL)
  174660. return;
  174661. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174662. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174663. info_ptr->row_pointers = row_pointers;
  174664. if(row_pointers)
  174665. info_ptr->valid |= PNG_INFO_IDAT;
  174666. }
  174667. #endif
  174668. #ifdef PNG_WRITE_SUPPORTED
  174669. void PNGAPI
  174670. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174671. {
  174672. if (png_ptr == NULL)
  174673. return;
  174674. if(png_ptr->zbuf)
  174675. png_free(png_ptr, png_ptr->zbuf);
  174676. png_ptr->zbuf_size = (png_size_t)size;
  174677. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174678. png_ptr->zstream.next_out = png_ptr->zbuf;
  174679. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174680. }
  174681. #endif
  174682. void PNGAPI
  174683. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174684. {
  174685. if (png_ptr && info_ptr)
  174686. info_ptr->valid &= ~(mask);
  174687. }
  174688. #ifndef PNG_1_0_X
  174689. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174690. void PNGAPI
  174691. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174692. {
  174693. if (png_ptr != NULL)
  174694. png_ptr->asm_flags = 0;
  174695. }
  174696. void PNGAPI
  174697. png_set_mmx_thresholds (png_structp png_ptr,
  174698. png_byte mmx_bitdepth_threshold,
  174699. png_uint_32 mmx_rowbytes_threshold)
  174700. {
  174701. if (png_ptr == NULL)
  174702. return;
  174703. }
  174704. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174705. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174706. void PNGAPI
  174707. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174708. png_uint_32 user_height_max)
  174709. {
  174710. if(png_ptr == NULL) return;
  174711. png_ptr->user_width_max = user_width_max;
  174712. png_ptr->user_height_max = user_height_max;
  174713. }
  174714. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174715. #endif /* ?PNG_1_0_X */
  174716. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174717. /*** End of inlined file: pngset.c ***/
  174718. /*** Start of inlined file: pngtrans.c ***/
  174719. #define PNG_INTERNAL
  174720. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174721. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174722. void PNGAPI
  174723. png_set_bgr(png_structp png_ptr)
  174724. {
  174725. png_debug(1, "in png_set_bgr\n");
  174726. if(png_ptr == NULL) return;
  174727. png_ptr->transformations |= PNG_BGR;
  174728. }
  174729. #endif
  174730. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174731. void PNGAPI
  174732. png_set_swap(png_structp png_ptr)
  174733. {
  174734. png_debug(1, "in png_set_swap\n");
  174735. if(png_ptr == NULL) return;
  174736. if (png_ptr->bit_depth == 16)
  174737. png_ptr->transformations |= PNG_SWAP_BYTES;
  174738. }
  174739. #endif
  174740. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174741. void PNGAPI
  174742. png_set_packing(png_structp png_ptr)
  174743. {
  174744. png_debug(1, "in png_set_packing\n");
  174745. if(png_ptr == NULL) return;
  174746. if (png_ptr->bit_depth < 8)
  174747. {
  174748. png_ptr->transformations |= PNG_PACK;
  174749. png_ptr->usr_bit_depth = 8;
  174750. }
  174751. }
  174752. #endif
  174753. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174754. void PNGAPI
  174755. png_set_packswap(png_structp png_ptr)
  174756. {
  174757. png_debug(1, "in png_set_packswap\n");
  174758. if(png_ptr == NULL) return;
  174759. if (png_ptr->bit_depth < 8)
  174760. png_ptr->transformations |= PNG_PACKSWAP;
  174761. }
  174762. #endif
  174763. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174764. void PNGAPI
  174765. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174766. {
  174767. png_debug(1, "in png_set_shift\n");
  174768. if(png_ptr == NULL) return;
  174769. png_ptr->transformations |= PNG_SHIFT;
  174770. png_ptr->shift = *true_bits;
  174771. }
  174772. #endif
  174773. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174774. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174775. int PNGAPI
  174776. png_set_interlace_handling(png_structp png_ptr)
  174777. {
  174778. png_debug(1, "in png_set_interlace handling\n");
  174779. if (png_ptr && png_ptr->interlaced)
  174780. {
  174781. png_ptr->transformations |= PNG_INTERLACE;
  174782. return (7);
  174783. }
  174784. return (1);
  174785. }
  174786. #endif
  174787. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174788. void PNGAPI
  174789. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174790. {
  174791. png_debug(1, "in png_set_filler\n");
  174792. if(png_ptr == NULL) return;
  174793. png_ptr->transformations |= PNG_FILLER;
  174794. png_ptr->filler = (png_byte)filler;
  174795. if (filler_loc == PNG_FILLER_AFTER)
  174796. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174797. else
  174798. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174799. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174800. {
  174801. png_ptr->usr_channels = 4;
  174802. }
  174803. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174804. {
  174805. png_ptr->usr_channels = 2;
  174806. }
  174807. }
  174808. #if !defined(PNG_1_0_X)
  174809. void PNGAPI
  174810. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174811. {
  174812. png_debug(1, "in png_set_add_alpha\n");
  174813. if(png_ptr == NULL) return;
  174814. png_set_filler(png_ptr, filler, filler_loc);
  174815. png_ptr->transformations |= PNG_ADD_ALPHA;
  174816. }
  174817. #endif
  174818. #endif
  174819. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174820. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174821. void PNGAPI
  174822. png_set_swap_alpha(png_structp png_ptr)
  174823. {
  174824. png_debug(1, "in png_set_swap_alpha\n");
  174825. if(png_ptr == NULL) return;
  174826. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174827. }
  174828. #endif
  174829. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174830. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174831. void PNGAPI
  174832. png_set_invert_alpha(png_structp png_ptr)
  174833. {
  174834. png_debug(1, "in png_set_invert_alpha\n");
  174835. if(png_ptr == NULL) return;
  174836. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174837. }
  174838. #endif
  174839. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174840. void PNGAPI
  174841. png_set_invert_mono(png_structp png_ptr)
  174842. {
  174843. png_debug(1, "in png_set_invert_mono\n");
  174844. if(png_ptr == NULL) return;
  174845. png_ptr->transformations |= PNG_INVERT_MONO;
  174846. }
  174847. void /* PRIVATE */
  174848. png_do_invert(png_row_infop row_info, png_bytep row)
  174849. {
  174850. png_debug(1, "in png_do_invert\n");
  174851. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174852. if (row == NULL || row_info == NULL)
  174853. return;
  174854. #endif
  174855. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174856. {
  174857. png_bytep rp = row;
  174858. png_uint_32 i;
  174859. png_uint_32 istop = row_info->rowbytes;
  174860. for (i = 0; i < istop; i++)
  174861. {
  174862. *rp = (png_byte)(~(*rp));
  174863. rp++;
  174864. }
  174865. }
  174866. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174867. row_info->bit_depth == 8)
  174868. {
  174869. png_bytep rp = row;
  174870. png_uint_32 i;
  174871. png_uint_32 istop = row_info->rowbytes;
  174872. for (i = 0; i < istop; i+=2)
  174873. {
  174874. *rp = (png_byte)(~(*rp));
  174875. rp+=2;
  174876. }
  174877. }
  174878. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174879. row_info->bit_depth == 16)
  174880. {
  174881. png_bytep rp = row;
  174882. png_uint_32 i;
  174883. png_uint_32 istop = row_info->rowbytes;
  174884. for (i = 0; i < istop; i+=4)
  174885. {
  174886. *rp = (png_byte)(~(*rp));
  174887. *(rp+1) = (png_byte)(~(*(rp+1)));
  174888. rp+=4;
  174889. }
  174890. }
  174891. }
  174892. #endif
  174893. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174894. void /* PRIVATE */
  174895. png_do_swap(png_row_infop row_info, png_bytep row)
  174896. {
  174897. png_debug(1, "in png_do_swap\n");
  174898. if (
  174899. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174900. row != NULL && row_info != NULL &&
  174901. #endif
  174902. row_info->bit_depth == 16)
  174903. {
  174904. png_bytep rp = row;
  174905. png_uint_32 i;
  174906. png_uint_32 istop= row_info->width * row_info->channels;
  174907. for (i = 0; i < istop; i++, rp += 2)
  174908. {
  174909. png_byte t = *rp;
  174910. *rp = *(rp + 1);
  174911. *(rp + 1) = t;
  174912. }
  174913. }
  174914. }
  174915. #endif
  174916. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174917. static PNG_CONST png_byte onebppswaptable[256] = {
  174918. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174919. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174920. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174921. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174922. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174923. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174924. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174925. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174926. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174927. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174928. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174929. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174930. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174931. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174932. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174933. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174934. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174935. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174936. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174937. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174938. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174939. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174940. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174941. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174942. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174943. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174944. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174945. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174946. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174947. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174948. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174949. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174950. };
  174951. static PNG_CONST png_byte twobppswaptable[256] = {
  174952. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174953. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174954. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174955. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174956. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174957. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174958. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174959. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174960. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174961. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174962. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174963. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174964. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174965. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174966. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174967. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174968. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174969. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174970. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174971. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174972. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174973. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174974. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174975. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174976. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174977. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174978. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174979. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174980. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174981. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174982. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174983. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174984. };
  174985. static PNG_CONST png_byte fourbppswaptable[256] = {
  174986. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174987. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174988. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174989. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174990. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174991. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174992. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174993. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174994. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174995. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174996. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174997. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174998. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174999. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  175000. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  175001. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  175002. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  175003. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  175004. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  175005. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  175006. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  175007. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  175008. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  175009. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  175010. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  175011. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  175012. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  175013. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  175014. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  175015. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  175016. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  175017. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  175018. };
  175019. void /* PRIVATE */
  175020. png_do_packswap(png_row_infop row_info, png_bytep row)
  175021. {
  175022. png_debug(1, "in png_do_packswap\n");
  175023. if (
  175024. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175025. row != NULL && row_info != NULL &&
  175026. #endif
  175027. row_info->bit_depth < 8)
  175028. {
  175029. png_bytep rp, end, table;
  175030. end = row + row_info->rowbytes;
  175031. if (row_info->bit_depth == 1)
  175032. table = (png_bytep)onebppswaptable;
  175033. else if (row_info->bit_depth == 2)
  175034. table = (png_bytep)twobppswaptable;
  175035. else if (row_info->bit_depth == 4)
  175036. table = (png_bytep)fourbppswaptable;
  175037. else
  175038. return;
  175039. for (rp = row; rp < end; rp++)
  175040. *rp = table[*rp];
  175041. }
  175042. }
  175043. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  175044. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  175045. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  175046. void /* PRIVATE */
  175047. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  175048. {
  175049. png_debug(1, "in png_do_strip_filler\n");
  175050. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175051. if (row != NULL && row_info != NULL)
  175052. #endif
  175053. {
  175054. png_bytep sp=row;
  175055. png_bytep dp=row;
  175056. png_uint_32 row_width=row_info->width;
  175057. png_uint_32 i;
  175058. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  175059. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  175060. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175061. row_info->channels == 4)
  175062. {
  175063. if (row_info->bit_depth == 8)
  175064. {
  175065. if (flags & PNG_FLAG_FILLER_AFTER)
  175066. {
  175067. dp+=3; sp+=4;
  175068. for (i = 1; i < row_width; i++)
  175069. {
  175070. *dp++ = *sp++;
  175071. *dp++ = *sp++;
  175072. *dp++ = *sp++;
  175073. sp++;
  175074. }
  175075. }
  175076. else
  175077. {
  175078. for (i = 0; i < row_width; i++)
  175079. {
  175080. sp++;
  175081. *dp++ = *sp++;
  175082. *dp++ = *sp++;
  175083. *dp++ = *sp++;
  175084. }
  175085. }
  175086. row_info->pixel_depth = 24;
  175087. row_info->rowbytes = row_width * 3;
  175088. }
  175089. else /* if (row_info->bit_depth == 16) */
  175090. {
  175091. if (flags & PNG_FLAG_FILLER_AFTER)
  175092. {
  175093. sp += 8; dp += 6;
  175094. for (i = 1; i < row_width; i++)
  175095. {
  175096. *dp++ = *sp++;
  175097. *dp++ = *sp++;
  175098. *dp++ = *sp++;
  175099. *dp++ = *sp++;
  175100. *dp++ = *sp++;
  175101. *dp++ = *sp++;
  175102. sp += 2;
  175103. }
  175104. }
  175105. else
  175106. {
  175107. for (i = 0; i < row_width; i++)
  175108. {
  175109. sp+=2;
  175110. *dp++ = *sp++;
  175111. *dp++ = *sp++;
  175112. *dp++ = *sp++;
  175113. *dp++ = *sp++;
  175114. *dp++ = *sp++;
  175115. *dp++ = *sp++;
  175116. }
  175117. }
  175118. row_info->pixel_depth = 48;
  175119. row_info->rowbytes = row_width * 6;
  175120. }
  175121. row_info->channels = 3;
  175122. }
  175123. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  175124. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175125. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175126. row_info->channels == 2)
  175127. {
  175128. if (row_info->bit_depth == 8)
  175129. {
  175130. if (flags & PNG_FLAG_FILLER_AFTER)
  175131. {
  175132. for (i = 0; i < row_width; i++)
  175133. {
  175134. *dp++ = *sp++;
  175135. sp++;
  175136. }
  175137. }
  175138. else
  175139. {
  175140. for (i = 0; i < row_width; i++)
  175141. {
  175142. sp++;
  175143. *dp++ = *sp++;
  175144. }
  175145. }
  175146. row_info->pixel_depth = 8;
  175147. row_info->rowbytes = row_width;
  175148. }
  175149. else /* if (row_info->bit_depth == 16) */
  175150. {
  175151. if (flags & PNG_FLAG_FILLER_AFTER)
  175152. {
  175153. sp += 4; dp += 2;
  175154. for (i = 1; i < row_width; i++)
  175155. {
  175156. *dp++ = *sp++;
  175157. *dp++ = *sp++;
  175158. sp += 2;
  175159. }
  175160. }
  175161. else
  175162. {
  175163. for (i = 0; i < row_width; i++)
  175164. {
  175165. sp += 2;
  175166. *dp++ = *sp++;
  175167. *dp++ = *sp++;
  175168. }
  175169. }
  175170. row_info->pixel_depth = 16;
  175171. row_info->rowbytes = row_width * 2;
  175172. }
  175173. row_info->channels = 1;
  175174. }
  175175. if (flags & PNG_FLAG_STRIP_ALPHA)
  175176. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  175177. }
  175178. }
  175179. #endif
  175180. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  175181. void /* PRIVATE */
  175182. png_do_bgr(png_row_infop row_info, png_bytep row)
  175183. {
  175184. png_debug(1, "in png_do_bgr\n");
  175185. if (
  175186. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175187. row != NULL && row_info != NULL &&
  175188. #endif
  175189. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  175190. {
  175191. png_uint_32 row_width = row_info->width;
  175192. if (row_info->bit_depth == 8)
  175193. {
  175194. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175195. {
  175196. png_bytep rp;
  175197. png_uint_32 i;
  175198. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  175199. {
  175200. png_byte save = *rp;
  175201. *rp = *(rp + 2);
  175202. *(rp + 2) = save;
  175203. }
  175204. }
  175205. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175206. {
  175207. png_bytep rp;
  175208. png_uint_32 i;
  175209. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  175210. {
  175211. png_byte save = *rp;
  175212. *rp = *(rp + 2);
  175213. *(rp + 2) = save;
  175214. }
  175215. }
  175216. }
  175217. else if (row_info->bit_depth == 16)
  175218. {
  175219. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175220. {
  175221. png_bytep rp;
  175222. png_uint_32 i;
  175223. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  175224. {
  175225. png_byte save = *rp;
  175226. *rp = *(rp + 4);
  175227. *(rp + 4) = save;
  175228. save = *(rp + 1);
  175229. *(rp + 1) = *(rp + 5);
  175230. *(rp + 5) = save;
  175231. }
  175232. }
  175233. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175234. {
  175235. png_bytep rp;
  175236. png_uint_32 i;
  175237. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  175238. {
  175239. png_byte save = *rp;
  175240. *rp = *(rp + 4);
  175241. *(rp + 4) = save;
  175242. save = *(rp + 1);
  175243. *(rp + 1) = *(rp + 5);
  175244. *(rp + 5) = save;
  175245. }
  175246. }
  175247. }
  175248. }
  175249. }
  175250. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  175251. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  175252. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  175253. defined(PNG_LEGACY_SUPPORTED)
  175254. void PNGAPI
  175255. png_set_user_transform_info(png_structp png_ptr, png_voidp
  175256. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  175257. {
  175258. png_debug(1, "in png_set_user_transform_info\n");
  175259. if(png_ptr == NULL) return;
  175260. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175261. png_ptr->user_transform_ptr = user_transform_ptr;
  175262. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  175263. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  175264. #else
  175265. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  175266. png_warning(png_ptr,
  175267. "This version of libpng does not support user transform info");
  175268. #endif
  175269. }
  175270. #endif
  175271. png_voidp PNGAPI
  175272. png_get_user_transform_ptr(png_structp png_ptr)
  175273. {
  175274. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175275. if (png_ptr == NULL) return (NULL);
  175276. return ((png_voidp)png_ptr->user_transform_ptr);
  175277. #else
  175278. return (NULL);
  175279. #endif
  175280. }
  175281. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175282. /*** End of inlined file: pngtrans.c ***/
  175283. /*** Start of inlined file: pngwio.c ***/
  175284. #define PNG_INTERNAL
  175285. #ifdef PNG_WRITE_SUPPORTED
  175286. void /* PRIVATE */
  175287. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175288. {
  175289. if (png_ptr->write_data_fn != NULL )
  175290. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175291. else
  175292. png_error(png_ptr, "Call to NULL write function");
  175293. }
  175294. #if !defined(PNG_NO_STDIO)
  175295. #ifndef USE_FAR_KEYWORD
  175296. void PNGAPI
  175297. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175298. {
  175299. png_uint_32 check;
  175300. if(png_ptr == NULL) return;
  175301. #if defined(_WIN32_WCE)
  175302. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175303. check = 0;
  175304. #else
  175305. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175306. #endif
  175307. if (check != length)
  175308. png_error(png_ptr, "Write Error");
  175309. }
  175310. #else
  175311. #define NEAR_BUF_SIZE 1024
  175312. #define MIN(a,b) (a <= b ? a : b)
  175313. void PNGAPI
  175314. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175315. {
  175316. png_uint_32 check;
  175317. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175318. png_FILE_p io_ptr;
  175319. if(png_ptr == NULL) return;
  175320. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175321. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175322. if ((png_bytep)near_data == data)
  175323. {
  175324. #if defined(_WIN32_WCE)
  175325. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175326. check = 0;
  175327. #else
  175328. check = fwrite(near_data, 1, length, io_ptr);
  175329. #endif
  175330. }
  175331. else
  175332. {
  175333. png_byte buf[NEAR_BUF_SIZE];
  175334. png_size_t written, remaining, err;
  175335. check = 0;
  175336. remaining = length;
  175337. do
  175338. {
  175339. written = MIN(NEAR_BUF_SIZE, remaining);
  175340. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175341. #if defined(_WIN32_WCE)
  175342. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175343. err = 0;
  175344. #else
  175345. err = fwrite(buf, 1, written, io_ptr);
  175346. #endif
  175347. if (err != written)
  175348. break;
  175349. else
  175350. check += err;
  175351. data += written;
  175352. remaining -= written;
  175353. }
  175354. while (remaining != 0);
  175355. }
  175356. if (check != length)
  175357. png_error(png_ptr, "Write Error");
  175358. }
  175359. #endif
  175360. #endif
  175361. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175362. void /* PRIVATE */
  175363. png_flush(png_structp png_ptr)
  175364. {
  175365. if (png_ptr->output_flush_fn != NULL)
  175366. (*(png_ptr->output_flush_fn))(png_ptr);
  175367. }
  175368. #if !defined(PNG_NO_STDIO)
  175369. void PNGAPI
  175370. png_default_flush(png_structp png_ptr)
  175371. {
  175372. #if !defined(_WIN32_WCE)
  175373. png_FILE_p io_ptr;
  175374. #endif
  175375. if(png_ptr == NULL) return;
  175376. #if !defined(_WIN32_WCE)
  175377. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175378. if (io_ptr != NULL)
  175379. fflush(io_ptr);
  175380. #endif
  175381. }
  175382. #endif
  175383. #endif
  175384. void PNGAPI
  175385. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175386. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175387. {
  175388. if(png_ptr == NULL) return;
  175389. png_ptr->io_ptr = io_ptr;
  175390. #if !defined(PNG_NO_STDIO)
  175391. if (write_data_fn != NULL)
  175392. png_ptr->write_data_fn = write_data_fn;
  175393. else
  175394. png_ptr->write_data_fn = png_default_write_data;
  175395. #else
  175396. png_ptr->write_data_fn = write_data_fn;
  175397. #endif
  175398. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175399. #if !defined(PNG_NO_STDIO)
  175400. if (output_flush_fn != NULL)
  175401. png_ptr->output_flush_fn = output_flush_fn;
  175402. else
  175403. png_ptr->output_flush_fn = png_default_flush;
  175404. #else
  175405. png_ptr->output_flush_fn = output_flush_fn;
  175406. #endif
  175407. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175408. if (png_ptr->read_data_fn != NULL)
  175409. {
  175410. png_ptr->read_data_fn = NULL;
  175411. png_warning(png_ptr,
  175412. "Attempted to set both read_data_fn and write_data_fn in");
  175413. png_warning(png_ptr,
  175414. "the same structure. Resetting read_data_fn to NULL.");
  175415. }
  175416. }
  175417. #if defined(USE_FAR_KEYWORD)
  175418. #if defined(_MSC_VER)
  175419. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175420. {
  175421. void *near_ptr;
  175422. void FAR *far_ptr;
  175423. FP_OFF(near_ptr) = FP_OFF(ptr);
  175424. far_ptr = (void FAR *)near_ptr;
  175425. if(check != 0)
  175426. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175427. png_error(png_ptr,"segment lost in conversion");
  175428. return(near_ptr);
  175429. }
  175430. # else
  175431. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175432. {
  175433. void *near_ptr;
  175434. void FAR *far_ptr;
  175435. near_ptr = (void FAR *)ptr;
  175436. far_ptr = (void FAR *)near_ptr;
  175437. if(check != 0)
  175438. if(far_ptr != ptr)
  175439. png_error(png_ptr,"segment lost in conversion");
  175440. return(near_ptr);
  175441. }
  175442. # endif
  175443. # endif
  175444. #endif /* PNG_WRITE_SUPPORTED */
  175445. /*** End of inlined file: pngwio.c ***/
  175446. /*** Start of inlined file: pngwrite.c ***/
  175447. #define PNG_INTERNAL
  175448. #ifdef PNG_WRITE_SUPPORTED
  175449. void PNGAPI
  175450. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175451. {
  175452. png_debug(1, "in png_write_info_before_PLTE\n");
  175453. if (png_ptr == NULL || info_ptr == NULL)
  175454. return;
  175455. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175456. {
  175457. png_write_sig(png_ptr); /* write PNG signature */
  175458. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175459. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175460. {
  175461. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175462. png_ptr->mng_features_permitted=0;
  175463. }
  175464. #endif
  175465. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175466. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175467. info_ptr->filter_type,
  175468. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175469. info_ptr->interlace_type);
  175470. #else
  175471. 0);
  175472. #endif
  175473. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175474. if (info_ptr->valid & PNG_INFO_gAMA)
  175475. {
  175476. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175477. png_write_gAMA(png_ptr, info_ptr->gamma);
  175478. #else
  175479. #ifdef PNG_FIXED_POINT_SUPPORTED
  175480. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175481. # endif
  175482. #endif
  175483. }
  175484. #endif
  175485. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175486. if (info_ptr->valid & PNG_INFO_sRGB)
  175487. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175488. #endif
  175489. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175490. if (info_ptr->valid & PNG_INFO_iCCP)
  175491. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175492. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175493. #endif
  175494. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175495. if (info_ptr->valid & PNG_INFO_sBIT)
  175496. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175497. #endif
  175498. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175499. if (info_ptr->valid & PNG_INFO_cHRM)
  175500. {
  175501. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175502. png_write_cHRM(png_ptr,
  175503. info_ptr->x_white, info_ptr->y_white,
  175504. info_ptr->x_red, info_ptr->y_red,
  175505. info_ptr->x_green, info_ptr->y_green,
  175506. info_ptr->x_blue, info_ptr->y_blue);
  175507. #else
  175508. # ifdef PNG_FIXED_POINT_SUPPORTED
  175509. png_write_cHRM_fixed(png_ptr,
  175510. info_ptr->int_x_white, info_ptr->int_y_white,
  175511. info_ptr->int_x_red, info_ptr->int_y_red,
  175512. info_ptr->int_x_green, info_ptr->int_y_green,
  175513. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175514. # endif
  175515. #endif
  175516. }
  175517. #endif
  175518. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175519. if (info_ptr->unknown_chunks_num)
  175520. {
  175521. png_unknown_chunk *up;
  175522. png_debug(5, "writing extra chunks\n");
  175523. for (up = info_ptr->unknown_chunks;
  175524. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175525. up++)
  175526. {
  175527. int keep=png_handle_as_unknown(png_ptr, up->name);
  175528. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175529. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175530. !(up->location & PNG_HAVE_IDAT) &&
  175531. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175532. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175533. {
  175534. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175535. }
  175536. }
  175537. }
  175538. #endif
  175539. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175540. }
  175541. }
  175542. void PNGAPI
  175543. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175544. {
  175545. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175546. int i;
  175547. #endif
  175548. png_debug(1, "in png_write_info\n");
  175549. if (png_ptr == NULL || info_ptr == NULL)
  175550. return;
  175551. png_write_info_before_PLTE(png_ptr, info_ptr);
  175552. if (info_ptr->valid & PNG_INFO_PLTE)
  175553. png_write_PLTE(png_ptr, info_ptr->palette,
  175554. (png_uint_32)info_ptr->num_palette);
  175555. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175556. png_error(png_ptr, "Valid palette required for paletted images");
  175557. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175558. if (info_ptr->valid & PNG_INFO_tRNS)
  175559. {
  175560. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175561. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175562. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175563. {
  175564. int j;
  175565. for (j=0; j<(int)info_ptr->num_trans; j++)
  175566. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175567. }
  175568. #endif
  175569. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175570. info_ptr->num_trans, info_ptr->color_type);
  175571. }
  175572. #endif
  175573. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175574. if (info_ptr->valid & PNG_INFO_bKGD)
  175575. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175576. #endif
  175577. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175578. if (info_ptr->valid & PNG_INFO_hIST)
  175579. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175580. #endif
  175581. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175582. if (info_ptr->valid & PNG_INFO_oFFs)
  175583. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175584. info_ptr->offset_unit_type);
  175585. #endif
  175586. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175587. if (info_ptr->valid & PNG_INFO_pCAL)
  175588. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175589. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175590. info_ptr->pcal_units, info_ptr->pcal_params);
  175591. #endif
  175592. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175593. if (info_ptr->valid & PNG_INFO_sCAL)
  175594. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175595. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175596. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175597. #else
  175598. #ifdef PNG_FIXED_POINT_SUPPORTED
  175599. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175600. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175601. #else
  175602. png_warning(png_ptr,
  175603. "png_write_sCAL not supported; sCAL chunk not written.");
  175604. #endif
  175605. #endif
  175606. #endif
  175607. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175608. if (info_ptr->valid & PNG_INFO_pHYs)
  175609. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175610. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175611. #endif
  175612. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175613. if (info_ptr->valid & PNG_INFO_tIME)
  175614. {
  175615. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175616. png_ptr->mode |= PNG_WROTE_tIME;
  175617. }
  175618. #endif
  175619. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175620. if (info_ptr->valid & PNG_INFO_sPLT)
  175621. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175622. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175623. #endif
  175624. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175625. for (i = 0; i < info_ptr->num_text; i++)
  175626. {
  175627. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175628. info_ptr->text[i].compression);
  175629. if (info_ptr->text[i].compression > 0)
  175630. {
  175631. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175632. png_write_iTXt(png_ptr,
  175633. info_ptr->text[i].compression,
  175634. info_ptr->text[i].key,
  175635. info_ptr->text[i].lang,
  175636. info_ptr->text[i].lang_key,
  175637. info_ptr->text[i].text);
  175638. #else
  175639. png_warning(png_ptr, "Unable to write international text");
  175640. #endif
  175641. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175642. }
  175643. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175644. {
  175645. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175646. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175647. info_ptr->text[i].text, 0,
  175648. info_ptr->text[i].compression);
  175649. #else
  175650. png_warning(png_ptr, "Unable to write compressed text");
  175651. #endif
  175652. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175653. }
  175654. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175655. {
  175656. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175657. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175658. info_ptr->text[i].text,
  175659. 0);
  175660. #else
  175661. png_warning(png_ptr, "Unable to write uncompressed text");
  175662. #endif
  175663. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175664. }
  175665. }
  175666. #endif
  175667. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175668. if (info_ptr->unknown_chunks_num)
  175669. {
  175670. png_unknown_chunk *up;
  175671. png_debug(5, "writing extra chunks\n");
  175672. for (up = info_ptr->unknown_chunks;
  175673. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175674. up++)
  175675. {
  175676. int keep=png_handle_as_unknown(png_ptr, up->name);
  175677. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175678. up->location && (up->location & PNG_HAVE_PLTE) &&
  175679. !(up->location & PNG_HAVE_IDAT) &&
  175680. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175681. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175682. {
  175683. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175684. }
  175685. }
  175686. }
  175687. #endif
  175688. }
  175689. void PNGAPI
  175690. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175691. {
  175692. png_debug(1, "in png_write_end\n");
  175693. if (png_ptr == NULL)
  175694. return;
  175695. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175696. png_error(png_ptr, "No IDATs written into file");
  175697. if (info_ptr != NULL)
  175698. {
  175699. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175700. int i; /* local index variable */
  175701. #endif
  175702. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175703. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175704. !(png_ptr->mode & PNG_WROTE_tIME))
  175705. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175706. #endif
  175707. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175708. for (i = 0; i < info_ptr->num_text; i++)
  175709. {
  175710. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175711. info_ptr->text[i].compression);
  175712. if (info_ptr->text[i].compression > 0)
  175713. {
  175714. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175715. png_write_iTXt(png_ptr,
  175716. info_ptr->text[i].compression,
  175717. info_ptr->text[i].key,
  175718. info_ptr->text[i].lang,
  175719. info_ptr->text[i].lang_key,
  175720. info_ptr->text[i].text);
  175721. #else
  175722. png_warning(png_ptr, "Unable to write international text");
  175723. #endif
  175724. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175725. }
  175726. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175727. {
  175728. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175729. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175730. info_ptr->text[i].text, 0,
  175731. info_ptr->text[i].compression);
  175732. #else
  175733. png_warning(png_ptr, "Unable to write compressed text");
  175734. #endif
  175735. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175736. }
  175737. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175738. {
  175739. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175740. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175741. info_ptr->text[i].text, 0);
  175742. #else
  175743. png_warning(png_ptr, "Unable to write uncompressed text");
  175744. #endif
  175745. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175746. }
  175747. }
  175748. #endif
  175749. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175750. if (info_ptr->unknown_chunks_num)
  175751. {
  175752. png_unknown_chunk *up;
  175753. png_debug(5, "writing extra chunks\n");
  175754. for (up = info_ptr->unknown_chunks;
  175755. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175756. up++)
  175757. {
  175758. int keep=png_handle_as_unknown(png_ptr, up->name);
  175759. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175760. up->location && (up->location & PNG_AFTER_IDAT) &&
  175761. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175762. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175763. {
  175764. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175765. }
  175766. }
  175767. }
  175768. #endif
  175769. }
  175770. png_ptr->mode |= PNG_AFTER_IDAT;
  175771. png_write_IEND(png_ptr);
  175772. }
  175773. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175774. #if !defined(_WIN32_WCE)
  175775. void PNGAPI
  175776. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175777. {
  175778. png_debug(1, "in png_convert_from_struct_tm\n");
  175779. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175780. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175781. ptime->day = (png_byte)ttime->tm_mday;
  175782. ptime->hour = (png_byte)ttime->tm_hour;
  175783. ptime->minute = (png_byte)ttime->tm_min;
  175784. ptime->second = (png_byte)ttime->tm_sec;
  175785. }
  175786. void PNGAPI
  175787. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175788. {
  175789. struct tm *tbuf;
  175790. png_debug(1, "in png_convert_from_time_t\n");
  175791. tbuf = gmtime(&ttime);
  175792. png_convert_from_struct_tm(ptime, tbuf);
  175793. }
  175794. #endif
  175795. #endif
  175796. png_structp PNGAPI
  175797. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175798. png_error_ptr error_fn, png_error_ptr warn_fn)
  175799. {
  175800. #ifdef PNG_USER_MEM_SUPPORTED
  175801. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175802. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175803. }
  175804. png_structp PNGAPI
  175805. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175806. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175807. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175808. {
  175809. #endif /* PNG_USER_MEM_SUPPORTED */
  175810. png_structp png_ptr;
  175811. #ifdef PNG_SETJMP_SUPPORTED
  175812. #ifdef USE_FAR_KEYWORD
  175813. jmp_buf jmpbuf;
  175814. #endif
  175815. #endif
  175816. int i;
  175817. png_debug(1, "in png_create_write_struct\n");
  175818. #ifdef PNG_USER_MEM_SUPPORTED
  175819. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175820. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175821. #else
  175822. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175823. #endif /* PNG_USER_MEM_SUPPORTED */
  175824. if (png_ptr == NULL)
  175825. return (NULL);
  175826. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175827. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175828. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175829. #endif
  175830. #ifdef PNG_SETJMP_SUPPORTED
  175831. #ifdef USE_FAR_KEYWORD
  175832. if (setjmp(jmpbuf))
  175833. #else
  175834. if (setjmp(png_ptr->jmpbuf))
  175835. #endif
  175836. {
  175837. png_free(png_ptr, png_ptr->zbuf);
  175838. png_ptr->zbuf=NULL;
  175839. png_destroy_struct(png_ptr);
  175840. return (NULL);
  175841. }
  175842. #ifdef USE_FAR_KEYWORD
  175843. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175844. #endif
  175845. #endif
  175846. #ifdef PNG_USER_MEM_SUPPORTED
  175847. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175848. #endif /* PNG_USER_MEM_SUPPORTED */
  175849. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175850. i=0;
  175851. do
  175852. {
  175853. if(user_png_ver[i] != png_libpng_ver[i])
  175854. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175855. } while (png_libpng_ver[i++]);
  175856. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175857. {
  175858. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175859. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175860. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175861. {
  175862. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175863. char msg[80];
  175864. if (user_png_ver)
  175865. {
  175866. png_snprintf(msg, 80,
  175867. "Application was compiled with png.h from libpng-%.20s",
  175868. user_png_ver);
  175869. png_warning(png_ptr, msg);
  175870. }
  175871. png_snprintf(msg, 80,
  175872. "Application is running with png.c from libpng-%.20s",
  175873. png_libpng_ver);
  175874. png_warning(png_ptr, msg);
  175875. #endif
  175876. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175877. png_ptr->flags=0;
  175878. #endif
  175879. png_error(png_ptr,
  175880. "Incompatible libpng version in application and library");
  175881. }
  175882. }
  175883. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175884. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175885. (png_uint_32)png_ptr->zbuf_size);
  175886. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175887. png_flush_ptr_NULL);
  175888. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175889. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175890. 1, png_doublep_NULL, png_doublep_NULL);
  175891. #endif
  175892. #ifdef PNG_SETJMP_SUPPORTED
  175893. #ifdef USE_FAR_KEYWORD
  175894. if (setjmp(jmpbuf))
  175895. PNG_ABORT();
  175896. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175897. #else
  175898. if (setjmp(png_ptr->jmpbuf))
  175899. PNG_ABORT();
  175900. #endif
  175901. #endif
  175902. return (png_ptr);
  175903. }
  175904. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175905. #undef png_write_init
  175906. void PNGAPI
  175907. png_write_init(png_structp png_ptr)
  175908. {
  175909. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175910. }
  175911. void PNGAPI
  175912. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175913. png_size_t png_struct_size, png_size_t png_info_size)
  175914. {
  175915. if(png_ptr == NULL) return;
  175916. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175917. if(png_sizeof(png_struct) > png_struct_size ||
  175918. png_sizeof(png_info) > png_info_size)
  175919. {
  175920. char msg[80];
  175921. png_ptr->warning_fn=NULL;
  175922. if (user_png_ver)
  175923. {
  175924. png_snprintf(msg, 80,
  175925. "Application was compiled with png.h from libpng-%.20s",
  175926. user_png_ver);
  175927. png_warning(png_ptr, msg);
  175928. }
  175929. png_snprintf(msg, 80,
  175930. "Application is running with png.c from libpng-%.20s",
  175931. png_libpng_ver);
  175932. png_warning(png_ptr, msg);
  175933. }
  175934. #endif
  175935. if(png_sizeof(png_struct) > png_struct_size)
  175936. {
  175937. png_ptr->error_fn=NULL;
  175938. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175939. png_ptr->flags=0;
  175940. #endif
  175941. png_error(png_ptr,
  175942. "The png struct allocated by the application for writing is too small.");
  175943. }
  175944. if(png_sizeof(png_info) > png_info_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 info struct allocated by the application for writing is too small.");
  175952. }
  175953. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175954. }
  175955. #endif /* PNG_1_0_X || PNG_1_2_X */
  175956. void PNGAPI
  175957. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175958. png_size_t png_struct_size)
  175959. {
  175960. png_structp png_ptr=*ptr_ptr;
  175961. #ifdef PNG_SETJMP_SUPPORTED
  175962. jmp_buf tmp_jmp; /* to save current jump buffer */
  175963. #endif
  175964. int i = 0;
  175965. if (png_ptr == NULL)
  175966. return;
  175967. do
  175968. {
  175969. if (user_png_ver[i] != png_libpng_ver[i])
  175970. {
  175971. #ifdef PNG_LEGACY_SUPPORTED
  175972. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175973. #else
  175974. png_ptr->warning_fn=NULL;
  175975. png_warning(png_ptr,
  175976. "Application uses deprecated png_write_init() and should be recompiled.");
  175977. break;
  175978. #endif
  175979. }
  175980. } while (png_libpng_ver[i++]);
  175981. png_debug(1, "in png_write_init_3\n");
  175982. #ifdef PNG_SETJMP_SUPPORTED
  175983. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175984. #endif
  175985. if (png_sizeof(png_struct) > png_struct_size)
  175986. {
  175987. png_destroy_struct(png_ptr);
  175988. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175989. *ptr_ptr = png_ptr;
  175990. }
  175991. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175992. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175993. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175994. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175995. #endif
  175996. #ifdef PNG_SETJMP_SUPPORTED
  175997. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175998. #endif
  175999. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176000. png_flush_ptr_NULL);
  176001. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176002. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176003. (png_uint_32)png_ptr->zbuf_size);
  176004. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176005. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176006. 1, png_doublep_NULL, png_doublep_NULL);
  176007. #endif
  176008. }
  176009. void PNGAPI
  176010. png_write_rows(png_structp png_ptr, png_bytepp row,
  176011. png_uint_32 num_rows)
  176012. {
  176013. png_uint_32 i; /* row counter */
  176014. png_bytepp rp; /* row pointer */
  176015. png_debug(1, "in png_write_rows\n");
  176016. if (png_ptr == NULL)
  176017. return;
  176018. for (i = 0, rp = row; i < num_rows; i++, rp++)
  176019. {
  176020. png_write_row(png_ptr, *rp);
  176021. }
  176022. }
  176023. void PNGAPI
  176024. png_write_image(png_structp png_ptr, png_bytepp image)
  176025. {
  176026. png_uint_32 i; /* row index */
  176027. int pass, num_pass; /* pass variables */
  176028. png_bytepp rp; /* points to current row */
  176029. if (png_ptr == NULL)
  176030. return;
  176031. png_debug(1, "in png_write_image\n");
  176032. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176033. num_pass = png_set_interlace_handling(png_ptr);
  176034. #else
  176035. num_pass = 1;
  176036. #endif
  176037. for (pass = 0; pass < num_pass; pass++)
  176038. {
  176039. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  176040. {
  176041. png_write_row(png_ptr, *rp);
  176042. }
  176043. }
  176044. }
  176045. void PNGAPI
  176046. png_write_row(png_structp png_ptr, png_bytep row)
  176047. {
  176048. if (png_ptr == NULL)
  176049. return;
  176050. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  176051. png_ptr->row_number, png_ptr->pass);
  176052. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  176053. {
  176054. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  176055. png_error(png_ptr,
  176056. "png_write_info was never called before png_write_row.");
  176057. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  176058. if (png_ptr->transformations & PNG_INVERT_MONO)
  176059. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  176060. #endif
  176061. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  176062. if (png_ptr->transformations & PNG_FILLER)
  176063. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  176064. #endif
  176065. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  176066. if (png_ptr->transformations & PNG_PACKSWAP)
  176067. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  176068. #endif
  176069. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  176070. if (png_ptr->transformations & PNG_PACK)
  176071. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  176072. #endif
  176073. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  176074. if (png_ptr->transformations & PNG_SHIFT)
  176075. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  176076. #endif
  176077. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  176078. if (png_ptr->transformations & PNG_BGR)
  176079. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  176080. #endif
  176081. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  176082. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176083. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  176084. #endif
  176085. png_write_start_row(png_ptr);
  176086. }
  176087. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176088. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  176089. {
  176090. switch (png_ptr->pass)
  176091. {
  176092. case 0:
  176093. if (png_ptr->row_number & 0x07)
  176094. {
  176095. png_write_finish_row(png_ptr);
  176096. return;
  176097. }
  176098. break;
  176099. case 1:
  176100. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  176101. {
  176102. png_write_finish_row(png_ptr);
  176103. return;
  176104. }
  176105. break;
  176106. case 2:
  176107. if ((png_ptr->row_number & 0x07) != 4)
  176108. {
  176109. png_write_finish_row(png_ptr);
  176110. return;
  176111. }
  176112. break;
  176113. case 3:
  176114. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  176115. {
  176116. png_write_finish_row(png_ptr);
  176117. return;
  176118. }
  176119. break;
  176120. case 4:
  176121. if ((png_ptr->row_number & 0x03) != 2)
  176122. {
  176123. png_write_finish_row(png_ptr);
  176124. return;
  176125. }
  176126. break;
  176127. case 5:
  176128. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  176129. {
  176130. png_write_finish_row(png_ptr);
  176131. return;
  176132. }
  176133. break;
  176134. case 6:
  176135. if (!(png_ptr->row_number & 0x01))
  176136. {
  176137. png_write_finish_row(png_ptr);
  176138. return;
  176139. }
  176140. break;
  176141. }
  176142. }
  176143. #endif
  176144. png_ptr->row_info.color_type = png_ptr->color_type;
  176145. png_ptr->row_info.width = png_ptr->usr_width;
  176146. png_ptr->row_info.channels = png_ptr->usr_channels;
  176147. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  176148. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  176149. png_ptr->row_info.channels);
  176150. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  176151. png_ptr->row_info.width);
  176152. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  176153. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  176154. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  176155. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  176156. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  176157. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  176158. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  176159. png_ptr->row_info.rowbytes);
  176160. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176161. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  176162. (png_ptr->transformations & PNG_INTERLACE))
  176163. {
  176164. png_do_write_interlace(&(png_ptr->row_info),
  176165. png_ptr->row_buf + 1, png_ptr->pass);
  176166. if (!(png_ptr->row_info.width))
  176167. {
  176168. png_write_finish_row(png_ptr);
  176169. return;
  176170. }
  176171. }
  176172. #endif
  176173. if (png_ptr->transformations)
  176174. png_do_write_transformations(png_ptr);
  176175. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176176. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176177. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  176178. {
  176179. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176180. }
  176181. #endif
  176182. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  176183. if (png_ptr->write_row_fn != NULL)
  176184. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  176185. }
  176186. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  176187. void PNGAPI
  176188. png_set_flush(png_structp png_ptr, int nrows)
  176189. {
  176190. png_debug(1, "in png_set_flush\n");
  176191. if (png_ptr == NULL)
  176192. return;
  176193. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  176194. }
  176195. void PNGAPI
  176196. png_write_flush(png_structp png_ptr)
  176197. {
  176198. int wrote_IDAT;
  176199. png_debug(1, "in png_write_flush\n");
  176200. if (png_ptr == NULL)
  176201. return;
  176202. if (png_ptr->row_number >= png_ptr->num_rows)
  176203. return;
  176204. do
  176205. {
  176206. int ret;
  176207. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  176208. wrote_IDAT = 0;
  176209. if (ret != Z_OK)
  176210. {
  176211. if (png_ptr->zstream.msg != NULL)
  176212. png_error(png_ptr, png_ptr->zstream.msg);
  176213. else
  176214. png_error(png_ptr, "zlib error");
  176215. }
  176216. if (!(png_ptr->zstream.avail_out))
  176217. {
  176218. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176219. png_ptr->zbuf_size);
  176220. png_ptr->zstream.next_out = png_ptr->zbuf;
  176221. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176222. wrote_IDAT = 1;
  176223. }
  176224. } while(wrote_IDAT == 1);
  176225. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  176226. {
  176227. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176228. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176229. png_ptr->zstream.next_out = png_ptr->zbuf;
  176230. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176231. }
  176232. png_ptr->flush_rows = 0;
  176233. png_flush(png_ptr);
  176234. }
  176235. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  176236. void PNGAPI
  176237. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  176238. {
  176239. png_structp png_ptr = NULL;
  176240. png_infop info_ptr = NULL;
  176241. #ifdef PNG_USER_MEM_SUPPORTED
  176242. png_free_ptr free_fn = NULL;
  176243. png_voidp mem_ptr = NULL;
  176244. #endif
  176245. png_debug(1, "in png_destroy_write_struct\n");
  176246. if (png_ptr_ptr != NULL)
  176247. {
  176248. png_ptr = *png_ptr_ptr;
  176249. #ifdef PNG_USER_MEM_SUPPORTED
  176250. free_fn = png_ptr->free_fn;
  176251. mem_ptr = png_ptr->mem_ptr;
  176252. #endif
  176253. }
  176254. if (info_ptr_ptr != NULL)
  176255. info_ptr = *info_ptr_ptr;
  176256. if (info_ptr != NULL)
  176257. {
  176258. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  176259. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  176260. if (png_ptr->num_chunk_list)
  176261. {
  176262. png_free(png_ptr, png_ptr->chunk_list);
  176263. png_ptr->chunk_list=NULL;
  176264. png_ptr->num_chunk_list=0;
  176265. }
  176266. #endif
  176267. #ifdef PNG_USER_MEM_SUPPORTED
  176268. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  176269. (png_voidp)mem_ptr);
  176270. #else
  176271. png_destroy_struct((png_voidp)info_ptr);
  176272. #endif
  176273. *info_ptr_ptr = NULL;
  176274. }
  176275. if (png_ptr != NULL)
  176276. {
  176277. png_write_destroy(png_ptr);
  176278. #ifdef PNG_USER_MEM_SUPPORTED
  176279. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  176280. (png_voidp)mem_ptr);
  176281. #else
  176282. png_destroy_struct((png_voidp)png_ptr);
  176283. #endif
  176284. *png_ptr_ptr = NULL;
  176285. }
  176286. }
  176287. void /* PRIVATE */
  176288. png_write_destroy(png_structp png_ptr)
  176289. {
  176290. #ifdef PNG_SETJMP_SUPPORTED
  176291. jmp_buf tmp_jmp; /* save jump buffer */
  176292. #endif
  176293. png_error_ptr error_fn;
  176294. png_error_ptr warning_fn;
  176295. png_voidp error_ptr;
  176296. #ifdef PNG_USER_MEM_SUPPORTED
  176297. png_free_ptr free_fn;
  176298. #endif
  176299. png_debug(1, "in png_write_destroy\n");
  176300. deflateEnd(&png_ptr->zstream);
  176301. png_free(png_ptr, png_ptr->zbuf);
  176302. png_free(png_ptr, png_ptr->row_buf);
  176303. png_free(png_ptr, png_ptr->prev_row);
  176304. png_free(png_ptr, png_ptr->sub_row);
  176305. png_free(png_ptr, png_ptr->up_row);
  176306. png_free(png_ptr, png_ptr->avg_row);
  176307. png_free(png_ptr, png_ptr->paeth_row);
  176308. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176309. png_free(png_ptr, png_ptr->time_buffer);
  176310. #endif
  176311. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176312. png_free(png_ptr, png_ptr->prev_filters);
  176313. png_free(png_ptr, png_ptr->filter_weights);
  176314. png_free(png_ptr, png_ptr->inv_filter_weights);
  176315. png_free(png_ptr, png_ptr->filter_costs);
  176316. png_free(png_ptr, png_ptr->inv_filter_costs);
  176317. #endif
  176318. #ifdef PNG_SETJMP_SUPPORTED
  176319. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176320. #endif
  176321. error_fn = png_ptr->error_fn;
  176322. warning_fn = png_ptr->warning_fn;
  176323. error_ptr = png_ptr->error_ptr;
  176324. #ifdef PNG_USER_MEM_SUPPORTED
  176325. free_fn = png_ptr->free_fn;
  176326. #endif
  176327. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176328. png_ptr->error_fn = error_fn;
  176329. png_ptr->warning_fn = warning_fn;
  176330. png_ptr->error_ptr = error_ptr;
  176331. #ifdef PNG_USER_MEM_SUPPORTED
  176332. png_ptr->free_fn = free_fn;
  176333. #endif
  176334. #ifdef PNG_SETJMP_SUPPORTED
  176335. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176336. #endif
  176337. }
  176338. void PNGAPI
  176339. png_set_filter(png_structp png_ptr, int method, int filters)
  176340. {
  176341. png_debug(1, "in png_set_filter\n");
  176342. if (png_ptr == NULL)
  176343. return;
  176344. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176345. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176346. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176347. method = PNG_FILTER_TYPE_BASE;
  176348. #endif
  176349. if (method == PNG_FILTER_TYPE_BASE)
  176350. {
  176351. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176352. {
  176353. #ifndef PNG_NO_WRITE_FILTER
  176354. case 5:
  176355. case 6:
  176356. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176357. #endif /* PNG_NO_WRITE_FILTER */
  176358. case PNG_FILTER_VALUE_NONE:
  176359. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176360. #ifndef PNG_NO_WRITE_FILTER
  176361. case PNG_FILTER_VALUE_SUB:
  176362. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176363. case PNG_FILTER_VALUE_UP:
  176364. png_ptr->do_filter=PNG_FILTER_UP; break;
  176365. case PNG_FILTER_VALUE_AVG:
  176366. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176367. case PNG_FILTER_VALUE_PAETH:
  176368. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176369. default: png_ptr->do_filter = (png_byte)filters; break;
  176370. #else
  176371. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176372. #endif /* PNG_NO_WRITE_FILTER */
  176373. }
  176374. if (png_ptr->row_buf != NULL)
  176375. {
  176376. #ifndef PNG_NO_WRITE_FILTER
  176377. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176378. {
  176379. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176380. (png_ptr->rowbytes + 1));
  176381. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176382. }
  176383. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176384. {
  176385. if (png_ptr->prev_row == NULL)
  176386. {
  176387. png_warning(png_ptr, "Can't add Up filter after starting");
  176388. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176389. }
  176390. else
  176391. {
  176392. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176393. (png_ptr->rowbytes + 1));
  176394. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176395. }
  176396. }
  176397. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176398. {
  176399. if (png_ptr->prev_row == NULL)
  176400. {
  176401. png_warning(png_ptr, "Can't add Average filter after starting");
  176402. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176403. }
  176404. else
  176405. {
  176406. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176407. (png_ptr->rowbytes + 1));
  176408. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176409. }
  176410. }
  176411. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176412. png_ptr->paeth_row == NULL)
  176413. {
  176414. if (png_ptr->prev_row == NULL)
  176415. {
  176416. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176417. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176418. }
  176419. else
  176420. {
  176421. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176422. (png_ptr->rowbytes + 1));
  176423. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176424. }
  176425. }
  176426. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176427. #endif /* PNG_NO_WRITE_FILTER */
  176428. png_ptr->do_filter = PNG_FILTER_NONE;
  176429. }
  176430. }
  176431. else
  176432. png_error(png_ptr, "Unknown custom filter method");
  176433. }
  176434. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176435. void PNGAPI
  176436. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176437. int num_weights, png_doublep filter_weights,
  176438. png_doublep filter_costs)
  176439. {
  176440. int i;
  176441. png_debug(1, "in png_set_filter_heuristics\n");
  176442. if (png_ptr == NULL)
  176443. return;
  176444. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176445. {
  176446. png_warning(png_ptr, "Unknown filter heuristic method");
  176447. return;
  176448. }
  176449. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176450. {
  176451. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176452. }
  176453. if (num_weights < 0 || filter_weights == NULL ||
  176454. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176455. {
  176456. num_weights = 0;
  176457. }
  176458. png_ptr->num_prev_filters = (png_byte)num_weights;
  176459. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176460. if (num_weights > 0)
  176461. {
  176462. if (png_ptr->prev_filters == NULL)
  176463. {
  176464. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176465. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176466. for (i = 0; i < num_weights; i++)
  176467. {
  176468. png_ptr->prev_filters[i] = 255;
  176469. }
  176470. }
  176471. if (png_ptr->filter_weights == NULL)
  176472. {
  176473. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176474. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176475. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176476. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176477. for (i = 0; i < num_weights; i++)
  176478. {
  176479. png_ptr->inv_filter_weights[i] =
  176480. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176481. }
  176482. }
  176483. for (i = 0; i < num_weights; i++)
  176484. {
  176485. if (filter_weights[i] < 0.0)
  176486. {
  176487. png_ptr->inv_filter_weights[i] =
  176488. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176489. }
  176490. else
  176491. {
  176492. png_ptr->inv_filter_weights[i] =
  176493. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176494. png_ptr->filter_weights[i] =
  176495. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176496. }
  176497. }
  176498. }
  176499. if (png_ptr->filter_costs == NULL)
  176500. {
  176501. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176502. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176503. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176504. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176505. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176506. {
  176507. png_ptr->inv_filter_costs[i] =
  176508. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176509. }
  176510. }
  176511. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176512. {
  176513. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176514. {
  176515. png_ptr->inv_filter_costs[i] =
  176516. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176517. }
  176518. else if (filter_costs[i] >= 1.0)
  176519. {
  176520. png_ptr->inv_filter_costs[i] =
  176521. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176522. png_ptr->filter_costs[i] =
  176523. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176524. }
  176525. }
  176526. }
  176527. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176528. void PNGAPI
  176529. png_set_compression_level(png_structp png_ptr, int level)
  176530. {
  176531. png_debug(1, "in png_set_compression_level\n");
  176532. if (png_ptr == NULL)
  176533. return;
  176534. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176535. png_ptr->zlib_level = level;
  176536. }
  176537. void PNGAPI
  176538. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176539. {
  176540. png_debug(1, "in png_set_compression_mem_level\n");
  176541. if (png_ptr == NULL)
  176542. return;
  176543. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176544. png_ptr->zlib_mem_level = mem_level;
  176545. }
  176546. void PNGAPI
  176547. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176548. {
  176549. png_debug(1, "in png_set_compression_strategy\n");
  176550. if (png_ptr == NULL)
  176551. return;
  176552. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176553. png_ptr->zlib_strategy = strategy;
  176554. }
  176555. void PNGAPI
  176556. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176557. {
  176558. if (png_ptr == NULL)
  176559. return;
  176560. if (window_bits > 15)
  176561. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176562. else if (window_bits < 8)
  176563. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176564. #ifndef WBITS_8_OK
  176565. if (window_bits == 8)
  176566. {
  176567. png_warning(png_ptr, "Compression window is being reset to 512");
  176568. window_bits=9;
  176569. }
  176570. #endif
  176571. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176572. png_ptr->zlib_window_bits = window_bits;
  176573. }
  176574. void PNGAPI
  176575. png_set_compression_method(png_structp png_ptr, int method)
  176576. {
  176577. png_debug(1, "in png_set_compression_method\n");
  176578. if (png_ptr == NULL)
  176579. return;
  176580. if (method != 8)
  176581. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176582. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176583. png_ptr->zlib_method = method;
  176584. }
  176585. void PNGAPI
  176586. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176587. {
  176588. if (png_ptr == NULL)
  176589. return;
  176590. png_ptr->write_row_fn = write_row_fn;
  176591. }
  176592. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176593. void PNGAPI
  176594. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176595. write_user_transform_fn)
  176596. {
  176597. png_debug(1, "in png_set_write_user_transform_fn\n");
  176598. if (png_ptr == NULL)
  176599. return;
  176600. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176601. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176602. }
  176603. #endif
  176604. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176605. void PNGAPI
  176606. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176607. int transforms, voidp params)
  176608. {
  176609. if (png_ptr == NULL || info_ptr == NULL)
  176610. return;
  176611. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176612. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176613. png_set_invert_alpha(png_ptr);
  176614. #endif
  176615. png_write_info(png_ptr, info_ptr);
  176616. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176617. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176618. png_set_invert_mono(png_ptr);
  176619. #endif
  176620. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176621. if ((transforms & PNG_TRANSFORM_SHIFT)
  176622. && (info_ptr->valid & PNG_INFO_sBIT))
  176623. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176624. #endif
  176625. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176626. if (transforms & PNG_TRANSFORM_PACKING)
  176627. png_set_packing(png_ptr);
  176628. #endif
  176629. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176630. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176631. png_set_swap_alpha(png_ptr);
  176632. #endif
  176633. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176634. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176635. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176636. #endif
  176637. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176638. if (transforms & PNG_TRANSFORM_BGR)
  176639. png_set_bgr(png_ptr);
  176640. #endif
  176641. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176642. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176643. png_set_swap(png_ptr);
  176644. #endif
  176645. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176646. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176647. png_set_packswap(png_ptr);
  176648. #endif
  176649. if (info_ptr->valid & PNG_INFO_IDAT)
  176650. png_write_image(png_ptr, info_ptr->row_pointers);
  176651. png_write_end(png_ptr, info_ptr);
  176652. transforms = transforms; /* quiet compiler warnings */
  176653. params = params;
  176654. }
  176655. #endif
  176656. #endif /* PNG_WRITE_SUPPORTED */
  176657. /*** End of inlined file: pngwrite.c ***/
  176658. /*** Start of inlined file: pngwtran.c ***/
  176659. #define PNG_INTERNAL
  176660. #ifdef PNG_WRITE_SUPPORTED
  176661. void /* PRIVATE */
  176662. png_do_write_transformations(png_structp png_ptr)
  176663. {
  176664. png_debug(1, "in png_do_write_transformations\n");
  176665. if (png_ptr == NULL)
  176666. return;
  176667. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176668. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176669. if(png_ptr->write_user_transform_fn != NULL)
  176670. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176671. (png_ptr, /* png_ptr */
  176672. &(png_ptr->row_info), /* row_info: */
  176673. png_ptr->row_buf + 1); /* start of pixel data for row */
  176674. #endif
  176675. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176676. if (png_ptr->transformations & PNG_FILLER)
  176677. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176678. png_ptr->flags);
  176679. #endif
  176680. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176681. if (png_ptr->transformations & PNG_PACKSWAP)
  176682. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176683. #endif
  176684. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176685. if (png_ptr->transformations & PNG_PACK)
  176686. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176687. (png_uint_32)png_ptr->bit_depth);
  176688. #endif
  176689. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176690. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176691. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176692. #endif
  176693. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176694. if (png_ptr->transformations & PNG_SHIFT)
  176695. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176696. &(png_ptr->shift));
  176697. #endif
  176698. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176699. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176700. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176701. #endif
  176702. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176703. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176704. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176705. #endif
  176706. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176707. if (png_ptr->transformations & PNG_BGR)
  176708. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176709. #endif
  176710. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176711. if (png_ptr->transformations & PNG_INVERT_MONO)
  176712. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176713. #endif
  176714. }
  176715. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176716. void /* PRIVATE */
  176717. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176718. {
  176719. png_debug(1, "in png_do_pack\n");
  176720. if (row_info->bit_depth == 8 &&
  176721. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176722. row != NULL && row_info != NULL &&
  176723. #endif
  176724. row_info->channels == 1)
  176725. {
  176726. switch ((int)bit_depth)
  176727. {
  176728. case 1:
  176729. {
  176730. png_bytep sp, dp;
  176731. int mask, v;
  176732. png_uint_32 i;
  176733. png_uint_32 row_width = row_info->width;
  176734. sp = row;
  176735. dp = row;
  176736. mask = 0x80;
  176737. v = 0;
  176738. for (i = 0; i < row_width; i++)
  176739. {
  176740. if (*sp != 0)
  176741. v |= mask;
  176742. sp++;
  176743. if (mask > 1)
  176744. mask >>= 1;
  176745. else
  176746. {
  176747. mask = 0x80;
  176748. *dp = (png_byte)v;
  176749. dp++;
  176750. v = 0;
  176751. }
  176752. }
  176753. if (mask != 0x80)
  176754. *dp = (png_byte)v;
  176755. break;
  176756. }
  176757. case 2:
  176758. {
  176759. png_bytep sp, dp;
  176760. int shift, v;
  176761. png_uint_32 i;
  176762. png_uint_32 row_width = row_info->width;
  176763. sp = row;
  176764. dp = row;
  176765. shift = 6;
  176766. v = 0;
  176767. for (i = 0; i < row_width; i++)
  176768. {
  176769. png_byte value;
  176770. value = (png_byte)(*sp & 0x03);
  176771. v |= (value << shift);
  176772. if (shift == 0)
  176773. {
  176774. shift = 6;
  176775. *dp = (png_byte)v;
  176776. dp++;
  176777. v = 0;
  176778. }
  176779. else
  176780. shift -= 2;
  176781. sp++;
  176782. }
  176783. if (shift != 6)
  176784. *dp = (png_byte)v;
  176785. break;
  176786. }
  176787. case 4:
  176788. {
  176789. png_bytep sp, dp;
  176790. int shift, v;
  176791. png_uint_32 i;
  176792. png_uint_32 row_width = row_info->width;
  176793. sp = row;
  176794. dp = row;
  176795. shift = 4;
  176796. v = 0;
  176797. for (i = 0; i < row_width; i++)
  176798. {
  176799. png_byte value;
  176800. value = (png_byte)(*sp & 0x0f);
  176801. v |= (value << shift);
  176802. if (shift == 0)
  176803. {
  176804. shift = 4;
  176805. *dp = (png_byte)v;
  176806. dp++;
  176807. v = 0;
  176808. }
  176809. else
  176810. shift -= 4;
  176811. sp++;
  176812. }
  176813. if (shift != 4)
  176814. *dp = (png_byte)v;
  176815. break;
  176816. }
  176817. }
  176818. row_info->bit_depth = (png_byte)bit_depth;
  176819. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176820. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176821. row_info->width);
  176822. }
  176823. }
  176824. #endif
  176825. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176826. void /* PRIVATE */
  176827. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176828. {
  176829. png_debug(1, "in png_do_shift\n");
  176830. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176831. if (row != NULL && row_info != NULL &&
  176832. #else
  176833. if (
  176834. #endif
  176835. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176836. {
  176837. int shift_start[4], shift_dec[4];
  176838. int channels = 0;
  176839. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176840. {
  176841. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176842. shift_dec[channels] = bit_depth->red;
  176843. channels++;
  176844. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176845. shift_dec[channels] = bit_depth->green;
  176846. channels++;
  176847. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176848. shift_dec[channels] = bit_depth->blue;
  176849. channels++;
  176850. }
  176851. else
  176852. {
  176853. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176854. shift_dec[channels] = bit_depth->gray;
  176855. channels++;
  176856. }
  176857. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176858. {
  176859. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176860. shift_dec[channels] = bit_depth->alpha;
  176861. channels++;
  176862. }
  176863. if (row_info->bit_depth < 8)
  176864. {
  176865. png_bytep bp = row;
  176866. png_uint_32 i;
  176867. png_byte mask;
  176868. png_uint_32 row_bytes = row_info->rowbytes;
  176869. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176870. mask = 0x55;
  176871. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176872. mask = 0x11;
  176873. else
  176874. mask = 0xff;
  176875. for (i = 0; i < row_bytes; i++, bp++)
  176876. {
  176877. png_uint_16 v;
  176878. int j;
  176879. v = *bp;
  176880. *bp = 0;
  176881. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176882. {
  176883. if (j > 0)
  176884. *bp |= (png_byte)((v << j) & 0xff);
  176885. else
  176886. *bp |= (png_byte)((v >> (-j)) & mask);
  176887. }
  176888. }
  176889. }
  176890. else if (row_info->bit_depth == 8)
  176891. {
  176892. png_bytep bp = row;
  176893. png_uint_32 i;
  176894. png_uint_32 istop = channels * row_info->width;
  176895. for (i = 0; i < istop; i++, bp++)
  176896. {
  176897. png_uint_16 v;
  176898. int j;
  176899. int c = (int)(i%channels);
  176900. v = *bp;
  176901. *bp = 0;
  176902. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176903. {
  176904. if (j > 0)
  176905. *bp |= (png_byte)((v << j) & 0xff);
  176906. else
  176907. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176908. }
  176909. }
  176910. }
  176911. else
  176912. {
  176913. png_bytep bp;
  176914. png_uint_32 i;
  176915. png_uint_32 istop = channels * row_info->width;
  176916. for (bp = row, i = 0; i < istop; i++)
  176917. {
  176918. int c = (int)(i%channels);
  176919. png_uint_16 value, v;
  176920. int j;
  176921. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176922. value = 0;
  176923. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176924. {
  176925. if (j > 0)
  176926. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176927. else
  176928. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176929. }
  176930. *bp++ = (png_byte)(value >> 8);
  176931. *bp++ = (png_byte)(value & 0xff);
  176932. }
  176933. }
  176934. }
  176935. }
  176936. #endif
  176937. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176938. void /* PRIVATE */
  176939. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176940. {
  176941. png_debug(1, "in png_do_write_swap_alpha\n");
  176942. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176943. if (row != NULL && row_info != NULL)
  176944. #endif
  176945. {
  176946. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176947. {
  176948. if (row_info->bit_depth == 8)
  176949. {
  176950. png_bytep sp, dp;
  176951. png_uint_32 i;
  176952. png_uint_32 row_width = row_info->width;
  176953. for (i = 0, sp = dp = row; i < row_width; i++)
  176954. {
  176955. png_byte save = *(sp++);
  176956. *(dp++) = *(sp++);
  176957. *(dp++) = *(sp++);
  176958. *(dp++) = *(sp++);
  176959. *(dp++) = save;
  176960. }
  176961. }
  176962. else
  176963. {
  176964. png_bytep sp, dp;
  176965. png_uint_32 i;
  176966. png_uint_32 row_width = row_info->width;
  176967. for (i = 0, sp = dp = row; i < row_width; i++)
  176968. {
  176969. png_byte save[2];
  176970. save[0] = *(sp++);
  176971. save[1] = *(sp++);
  176972. *(dp++) = *(sp++);
  176973. *(dp++) = *(sp++);
  176974. *(dp++) = *(sp++);
  176975. *(dp++) = *(sp++);
  176976. *(dp++) = *(sp++);
  176977. *(dp++) = *(sp++);
  176978. *(dp++) = save[0];
  176979. *(dp++) = save[1];
  176980. }
  176981. }
  176982. }
  176983. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176984. {
  176985. if (row_info->bit_depth == 8)
  176986. {
  176987. png_bytep sp, dp;
  176988. png_uint_32 i;
  176989. png_uint_32 row_width = row_info->width;
  176990. for (i = 0, sp = dp = row; i < row_width; i++)
  176991. {
  176992. png_byte save = *(sp++);
  176993. *(dp++) = *(sp++);
  176994. *(dp++) = save;
  176995. }
  176996. }
  176997. else
  176998. {
  176999. png_bytep sp, dp;
  177000. png_uint_32 i;
  177001. png_uint_32 row_width = row_info->width;
  177002. for (i = 0, sp = dp = row; i < row_width; i++)
  177003. {
  177004. png_byte save[2];
  177005. save[0] = *(sp++);
  177006. save[1] = *(sp++);
  177007. *(dp++) = *(sp++);
  177008. *(dp++) = *(sp++);
  177009. *(dp++) = save[0];
  177010. *(dp++) = save[1];
  177011. }
  177012. }
  177013. }
  177014. }
  177015. }
  177016. #endif
  177017. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177018. void /* PRIVATE */
  177019. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  177020. {
  177021. png_debug(1, "in png_do_write_invert_alpha\n");
  177022. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177023. if (row != NULL && row_info != NULL)
  177024. #endif
  177025. {
  177026. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177027. {
  177028. if (row_info->bit_depth == 8)
  177029. {
  177030. png_bytep sp, dp;
  177031. png_uint_32 i;
  177032. png_uint_32 row_width = row_info->width;
  177033. for (i = 0, sp = dp = row; i < row_width; i++)
  177034. {
  177035. sp+=3; dp = sp;
  177036. *(dp++) = (png_byte)(255 - *(sp++));
  177037. }
  177038. }
  177039. else
  177040. {
  177041. png_bytep sp, dp;
  177042. png_uint_32 i;
  177043. png_uint_32 row_width = row_info->width;
  177044. for (i = 0, sp = dp = row; i < row_width; i++)
  177045. {
  177046. sp+=6; dp = sp;
  177047. *(dp++) = (png_byte)(255 - *(sp++));
  177048. *(dp++) = (png_byte)(255 - *(sp++));
  177049. }
  177050. }
  177051. }
  177052. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177053. {
  177054. if (row_info->bit_depth == 8)
  177055. {
  177056. png_bytep sp, dp;
  177057. png_uint_32 i;
  177058. png_uint_32 row_width = row_info->width;
  177059. for (i = 0, sp = dp = row; i < row_width; i++)
  177060. {
  177061. *(dp++) = *(sp++);
  177062. *(dp++) = (png_byte)(255 - *(sp++));
  177063. }
  177064. }
  177065. else
  177066. {
  177067. png_bytep sp, dp;
  177068. png_uint_32 i;
  177069. png_uint_32 row_width = row_info->width;
  177070. for (i = 0, sp = dp = row; i < row_width; i++)
  177071. {
  177072. sp+=2; dp = sp;
  177073. *(dp++) = (png_byte)(255 - *(sp++));
  177074. *(dp++) = (png_byte)(255 - *(sp++));
  177075. }
  177076. }
  177077. }
  177078. }
  177079. }
  177080. #endif
  177081. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177082. void /* PRIVATE */
  177083. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  177084. {
  177085. png_debug(1, "in png_do_write_intrapixel\n");
  177086. if (
  177087. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177088. row != NULL && row_info != NULL &&
  177089. #endif
  177090. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  177091. {
  177092. int bytes_per_pixel;
  177093. png_uint_32 row_width = row_info->width;
  177094. if (row_info->bit_depth == 8)
  177095. {
  177096. png_bytep rp;
  177097. png_uint_32 i;
  177098. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177099. bytes_per_pixel = 3;
  177100. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177101. bytes_per_pixel = 4;
  177102. else
  177103. return;
  177104. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177105. {
  177106. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  177107. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  177108. }
  177109. }
  177110. else if (row_info->bit_depth == 16)
  177111. {
  177112. png_bytep rp;
  177113. png_uint_32 i;
  177114. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177115. bytes_per_pixel = 6;
  177116. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177117. bytes_per_pixel = 8;
  177118. else
  177119. return;
  177120. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177121. {
  177122. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  177123. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  177124. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  177125. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  177126. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  177127. *(rp ) = (png_byte)((red >> 8) & 0xff);
  177128. *(rp+1) = (png_byte)(red & 0xff);
  177129. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  177130. *(rp+5) = (png_byte)(blue & 0xff);
  177131. }
  177132. }
  177133. }
  177134. }
  177135. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  177136. #endif /* PNG_WRITE_SUPPORTED */
  177137. /*** End of inlined file: pngwtran.c ***/
  177138. /*** Start of inlined file: pngwutil.c ***/
  177139. #define PNG_INTERNAL
  177140. #ifdef PNG_WRITE_SUPPORTED
  177141. void PNGAPI
  177142. png_save_uint_32(png_bytep buf, png_uint_32 i)
  177143. {
  177144. buf[0] = (png_byte)((i >> 24) & 0xff);
  177145. buf[1] = (png_byte)((i >> 16) & 0xff);
  177146. buf[2] = (png_byte)((i >> 8) & 0xff);
  177147. buf[3] = (png_byte)(i & 0xff);
  177148. }
  177149. void PNGAPI
  177150. png_save_int_32(png_bytep buf, png_int_32 i)
  177151. {
  177152. buf[0] = (png_byte)((i >> 24) & 0xff);
  177153. buf[1] = (png_byte)((i >> 16) & 0xff);
  177154. buf[2] = (png_byte)((i >> 8) & 0xff);
  177155. buf[3] = (png_byte)(i & 0xff);
  177156. }
  177157. void PNGAPI
  177158. png_save_uint_16(png_bytep buf, unsigned int i)
  177159. {
  177160. buf[0] = (png_byte)((i >> 8) & 0xff);
  177161. buf[1] = (png_byte)(i & 0xff);
  177162. }
  177163. void PNGAPI
  177164. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  177165. png_bytep data, png_size_t length)
  177166. {
  177167. if(png_ptr == NULL) return;
  177168. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  177169. png_write_chunk_data(png_ptr, data, length);
  177170. png_write_chunk_end(png_ptr);
  177171. }
  177172. void PNGAPI
  177173. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  177174. png_uint_32 length)
  177175. {
  177176. png_byte buf[4];
  177177. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  177178. if(png_ptr == NULL) return;
  177179. png_save_uint_32(buf, length);
  177180. png_write_data(png_ptr, buf, (png_size_t)4);
  177181. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  177182. png_reset_crc(png_ptr);
  177183. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  177184. }
  177185. void PNGAPI
  177186. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  177187. {
  177188. if(png_ptr == NULL) return;
  177189. if (data != NULL && length > 0)
  177190. {
  177191. png_calculate_crc(png_ptr, data, length);
  177192. png_write_data(png_ptr, data, length);
  177193. }
  177194. }
  177195. void PNGAPI
  177196. png_write_chunk_end(png_structp png_ptr)
  177197. {
  177198. png_byte buf[4];
  177199. if(png_ptr == NULL) return;
  177200. png_save_uint_32(buf, png_ptr->crc);
  177201. png_write_data(png_ptr, buf, (png_size_t)4);
  177202. }
  177203. void /* PRIVATE */
  177204. png_write_sig(png_structp png_ptr)
  177205. {
  177206. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  177207. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  177208. (png_size_t)8 - png_ptr->sig_bytes);
  177209. if(png_ptr->sig_bytes < 3)
  177210. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  177211. }
  177212. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  177213. typedef struct
  177214. {
  177215. char *input; /* the uncompressed input data */
  177216. int input_len; /* its length */
  177217. int num_output_ptr; /* number of output pointers used */
  177218. int max_output_ptr; /* size of output_ptr */
  177219. png_charpp output_ptr; /* array of pointers to output */
  177220. } compression_state;
  177221. static int /* PRIVATE */
  177222. png_text_compress(png_structp png_ptr,
  177223. png_charp text, png_size_t text_len, int compression,
  177224. compression_state *comp)
  177225. {
  177226. int ret;
  177227. comp->num_output_ptr = 0;
  177228. comp->max_output_ptr = 0;
  177229. comp->output_ptr = NULL;
  177230. comp->input = NULL;
  177231. comp->input_len = 0;
  177232. if (compression == PNG_TEXT_COMPRESSION_NONE)
  177233. {
  177234. comp->input = text;
  177235. comp->input_len = text_len;
  177236. return((int)text_len);
  177237. }
  177238. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  177239. {
  177240. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177241. char msg[50];
  177242. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  177243. png_warning(png_ptr, msg);
  177244. #else
  177245. png_warning(png_ptr, "Unknown compression type");
  177246. #endif
  177247. }
  177248. png_ptr->zstream.avail_in = (uInt)text_len;
  177249. png_ptr->zstream.next_in = (Bytef *)text;
  177250. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177251. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  177252. do
  177253. {
  177254. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  177255. if (ret != Z_OK)
  177256. {
  177257. if (png_ptr->zstream.msg != NULL)
  177258. png_error(png_ptr, png_ptr->zstream.msg);
  177259. else
  177260. png_error(png_ptr, "zlib error");
  177261. }
  177262. if (!(png_ptr->zstream.avail_out))
  177263. {
  177264. if (comp->num_output_ptr >= comp->max_output_ptr)
  177265. {
  177266. int old_max;
  177267. old_max = comp->max_output_ptr;
  177268. comp->max_output_ptr = comp->num_output_ptr + 4;
  177269. if (comp->output_ptr != NULL)
  177270. {
  177271. png_charpp old_ptr;
  177272. old_ptr = comp->output_ptr;
  177273. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177274. (png_uint_32)(comp->max_output_ptr *
  177275. png_sizeof (png_charpp)));
  177276. png_memcpy(comp->output_ptr, old_ptr, old_max
  177277. * png_sizeof (png_charp));
  177278. png_free(png_ptr, old_ptr);
  177279. }
  177280. else
  177281. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177282. (png_uint_32)(comp->max_output_ptr *
  177283. png_sizeof (png_charp)));
  177284. }
  177285. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177286. (png_uint_32)png_ptr->zbuf_size);
  177287. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177288. png_ptr->zbuf_size);
  177289. comp->num_output_ptr++;
  177290. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177291. png_ptr->zstream.next_out = png_ptr->zbuf;
  177292. }
  177293. } while (png_ptr->zstream.avail_in);
  177294. do
  177295. {
  177296. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177297. if (ret == Z_OK)
  177298. {
  177299. if (!(png_ptr->zstream.avail_out))
  177300. {
  177301. if (comp->num_output_ptr >= comp->max_output_ptr)
  177302. {
  177303. int old_max;
  177304. old_max = comp->max_output_ptr;
  177305. comp->max_output_ptr = comp->num_output_ptr + 4;
  177306. if (comp->output_ptr != NULL)
  177307. {
  177308. png_charpp old_ptr;
  177309. old_ptr = comp->output_ptr;
  177310. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177311. (png_uint_32)(comp->max_output_ptr *
  177312. png_sizeof (png_charpp)));
  177313. png_memcpy(comp->output_ptr, old_ptr,
  177314. old_max * png_sizeof (png_charp));
  177315. png_free(png_ptr, old_ptr);
  177316. }
  177317. else
  177318. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177319. (png_uint_32)(comp->max_output_ptr *
  177320. png_sizeof (png_charp)));
  177321. }
  177322. comp->output_ptr[comp->num_output_ptr] =
  177323. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177324. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177325. png_ptr->zbuf_size);
  177326. comp->num_output_ptr++;
  177327. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177328. png_ptr->zstream.next_out = png_ptr->zbuf;
  177329. }
  177330. }
  177331. else if (ret != Z_STREAM_END)
  177332. {
  177333. if (png_ptr->zstream.msg != NULL)
  177334. png_error(png_ptr, png_ptr->zstream.msg);
  177335. else
  177336. png_error(png_ptr, "zlib error");
  177337. }
  177338. } while (ret != Z_STREAM_END);
  177339. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177340. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177341. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177342. return((int)text_len);
  177343. }
  177344. static void /* PRIVATE */
  177345. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177346. {
  177347. int i;
  177348. if (comp->input)
  177349. {
  177350. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177351. (png_size_t)comp->input_len);
  177352. return;
  177353. }
  177354. for (i = 0; i < comp->num_output_ptr; i++)
  177355. {
  177356. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177357. png_ptr->zbuf_size);
  177358. png_free(png_ptr, comp->output_ptr[i]);
  177359. comp->output_ptr[i]=NULL;
  177360. }
  177361. if (comp->max_output_ptr != 0)
  177362. png_free(png_ptr, comp->output_ptr);
  177363. comp->output_ptr=NULL;
  177364. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177365. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177366. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177367. deflateReset(&png_ptr->zstream);
  177368. png_ptr->zstream.data_type = Z_BINARY;
  177369. }
  177370. #endif
  177371. void /* PRIVATE */
  177372. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177373. int bit_depth, int color_type, int compression_type, int filter_type,
  177374. int interlace_type)
  177375. {
  177376. #ifdef PNG_USE_LOCAL_ARRAYS
  177377. PNG_IHDR;
  177378. #endif
  177379. png_byte buf[13]; /* buffer to store the IHDR info */
  177380. png_debug(1, "in png_write_IHDR\n");
  177381. switch (color_type)
  177382. {
  177383. case PNG_COLOR_TYPE_GRAY:
  177384. switch (bit_depth)
  177385. {
  177386. case 1:
  177387. case 2:
  177388. case 4:
  177389. case 8:
  177390. case 16: png_ptr->channels = 1; break;
  177391. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177392. }
  177393. break;
  177394. case PNG_COLOR_TYPE_RGB:
  177395. if (bit_depth != 8 && bit_depth != 16)
  177396. png_error(png_ptr, "Invalid bit depth for RGB image");
  177397. png_ptr->channels = 3;
  177398. break;
  177399. case PNG_COLOR_TYPE_PALETTE:
  177400. switch (bit_depth)
  177401. {
  177402. case 1:
  177403. case 2:
  177404. case 4:
  177405. case 8: png_ptr->channels = 1; break;
  177406. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177407. }
  177408. break;
  177409. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177410. if (bit_depth != 8 && bit_depth != 16)
  177411. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177412. png_ptr->channels = 2;
  177413. break;
  177414. case PNG_COLOR_TYPE_RGB_ALPHA:
  177415. if (bit_depth != 8 && bit_depth != 16)
  177416. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177417. png_ptr->channels = 4;
  177418. break;
  177419. default:
  177420. png_error(png_ptr, "Invalid image color type specified");
  177421. }
  177422. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177423. {
  177424. png_warning(png_ptr, "Invalid compression type specified");
  177425. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177426. }
  177427. if (
  177428. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177429. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177430. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177431. (color_type == PNG_COLOR_TYPE_RGB ||
  177432. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177433. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177434. #endif
  177435. filter_type != PNG_FILTER_TYPE_BASE)
  177436. {
  177437. png_warning(png_ptr, "Invalid filter type specified");
  177438. filter_type = PNG_FILTER_TYPE_BASE;
  177439. }
  177440. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177441. if (interlace_type != PNG_INTERLACE_NONE &&
  177442. interlace_type != PNG_INTERLACE_ADAM7)
  177443. {
  177444. png_warning(png_ptr, "Invalid interlace type specified");
  177445. interlace_type = PNG_INTERLACE_ADAM7;
  177446. }
  177447. #else
  177448. interlace_type=PNG_INTERLACE_NONE;
  177449. #endif
  177450. png_ptr->bit_depth = (png_byte)bit_depth;
  177451. png_ptr->color_type = (png_byte)color_type;
  177452. png_ptr->interlaced = (png_byte)interlace_type;
  177453. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177454. png_ptr->filter_type = (png_byte)filter_type;
  177455. #endif
  177456. png_ptr->compression_type = (png_byte)compression_type;
  177457. png_ptr->width = width;
  177458. png_ptr->height = height;
  177459. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177460. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177461. png_ptr->usr_width = png_ptr->width;
  177462. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177463. png_ptr->usr_channels = png_ptr->channels;
  177464. png_save_uint_32(buf, width);
  177465. png_save_uint_32(buf + 4, height);
  177466. buf[8] = (png_byte)bit_depth;
  177467. buf[9] = (png_byte)color_type;
  177468. buf[10] = (png_byte)compression_type;
  177469. buf[11] = (png_byte)filter_type;
  177470. buf[12] = (png_byte)interlace_type;
  177471. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177472. png_ptr->zstream.zalloc = png_zalloc;
  177473. png_ptr->zstream.zfree = png_zfree;
  177474. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177475. if (!(png_ptr->do_filter))
  177476. {
  177477. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177478. png_ptr->bit_depth < 8)
  177479. png_ptr->do_filter = PNG_FILTER_NONE;
  177480. else
  177481. png_ptr->do_filter = PNG_ALL_FILTERS;
  177482. }
  177483. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177484. {
  177485. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177486. png_ptr->zlib_strategy = Z_FILTERED;
  177487. else
  177488. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177489. }
  177490. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177491. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177492. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177493. png_ptr->zlib_mem_level = 8;
  177494. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177495. png_ptr->zlib_window_bits = 15;
  177496. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177497. png_ptr->zlib_method = 8;
  177498. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177499. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177500. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177501. png_error(png_ptr, "zlib failed to initialize compressor");
  177502. png_ptr->zstream.next_out = png_ptr->zbuf;
  177503. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177504. png_ptr->zstream.data_type = Z_BINARY;
  177505. png_ptr->mode = PNG_HAVE_IHDR;
  177506. }
  177507. void /* PRIVATE */
  177508. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177509. {
  177510. #ifdef PNG_USE_LOCAL_ARRAYS
  177511. PNG_PLTE;
  177512. #endif
  177513. png_uint_32 i;
  177514. png_colorp pal_ptr;
  177515. png_byte buf[3];
  177516. png_debug(1, "in png_write_PLTE\n");
  177517. if ((
  177518. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177519. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177520. #endif
  177521. num_pal == 0) || num_pal > 256)
  177522. {
  177523. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177524. {
  177525. png_error(png_ptr, "Invalid number of colors in palette");
  177526. }
  177527. else
  177528. {
  177529. png_warning(png_ptr, "Invalid number of colors in palette");
  177530. return;
  177531. }
  177532. }
  177533. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177534. {
  177535. png_warning(png_ptr,
  177536. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177537. return;
  177538. }
  177539. png_ptr->num_palette = (png_uint_16)num_pal;
  177540. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177541. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177542. #ifndef PNG_NO_POINTER_INDEXING
  177543. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177544. {
  177545. buf[0] = pal_ptr->red;
  177546. buf[1] = pal_ptr->green;
  177547. buf[2] = pal_ptr->blue;
  177548. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177549. }
  177550. #else
  177551. pal_ptr=palette;
  177552. for (i = 0; i < num_pal; i++)
  177553. {
  177554. buf[0] = pal_ptr[i].red;
  177555. buf[1] = pal_ptr[i].green;
  177556. buf[2] = pal_ptr[i].blue;
  177557. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177558. }
  177559. #endif
  177560. png_write_chunk_end(png_ptr);
  177561. png_ptr->mode |= PNG_HAVE_PLTE;
  177562. }
  177563. void /* PRIVATE */
  177564. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177565. {
  177566. #ifdef PNG_USE_LOCAL_ARRAYS
  177567. PNG_IDAT;
  177568. #endif
  177569. png_debug(1, "in png_write_IDAT\n");
  177570. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177571. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177572. {
  177573. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177574. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177575. {
  177576. if (length >= 2 &&
  177577. png_ptr->height < 16384 && png_ptr->width < 16384)
  177578. {
  177579. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177580. ((png_ptr->width *
  177581. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177582. unsigned int z_cinfo = z_cmf >> 4;
  177583. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177584. while (uncompressed_idat_size <= half_z_window_size &&
  177585. half_z_window_size >= 256)
  177586. {
  177587. z_cinfo--;
  177588. half_z_window_size >>= 1;
  177589. }
  177590. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177591. if (data[0] != (png_byte)z_cmf)
  177592. {
  177593. data[0] = (png_byte)z_cmf;
  177594. data[1] &= 0xe0;
  177595. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177596. }
  177597. }
  177598. }
  177599. else
  177600. png_error(png_ptr,
  177601. "Invalid zlib compression method or flags in IDAT");
  177602. }
  177603. png_write_chunk(png_ptr, png_IDAT, data, length);
  177604. png_ptr->mode |= PNG_HAVE_IDAT;
  177605. }
  177606. void /* PRIVATE */
  177607. png_write_IEND(png_structp png_ptr)
  177608. {
  177609. #ifdef PNG_USE_LOCAL_ARRAYS
  177610. PNG_IEND;
  177611. #endif
  177612. png_debug(1, "in png_write_IEND\n");
  177613. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177614. (png_size_t)0);
  177615. png_ptr->mode |= PNG_HAVE_IEND;
  177616. }
  177617. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177618. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177619. void /* PRIVATE */
  177620. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177621. {
  177622. #ifdef PNG_USE_LOCAL_ARRAYS
  177623. PNG_gAMA;
  177624. #endif
  177625. png_uint_32 igamma;
  177626. png_byte buf[4];
  177627. png_debug(1, "in png_write_gAMA\n");
  177628. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177629. png_save_uint_32(buf, igamma);
  177630. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177631. }
  177632. #endif
  177633. #ifdef PNG_FIXED_POINT_SUPPORTED
  177634. void /* PRIVATE */
  177635. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177636. {
  177637. #ifdef PNG_USE_LOCAL_ARRAYS
  177638. PNG_gAMA;
  177639. #endif
  177640. png_byte buf[4];
  177641. png_debug(1, "in png_write_gAMA\n");
  177642. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177643. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177644. }
  177645. #endif
  177646. #endif
  177647. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177648. void /* PRIVATE */
  177649. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177650. {
  177651. #ifdef PNG_USE_LOCAL_ARRAYS
  177652. PNG_sRGB;
  177653. #endif
  177654. png_byte buf[1];
  177655. png_debug(1, "in png_write_sRGB\n");
  177656. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177657. png_warning(png_ptr,
  177658. "Invalid sRGB rendering intent specified");
  177659. buf[0]=(png_byte)srgb_intent;
  177660. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177661. }
  177662. #endif
  177663. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177664. void /* PRIVATE */
  177665. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177666. png_charp profile, int profile_len)
  177667. {
  177668. #ifdef PNG_USE_LOCAL_ARRAYS
  177669. PNG_iCCP;
  177670. #endif
  177671. png_size_t name_len;
  177672. png_charp new_name;
  177673. compression_state comp;
  177674. int embedded_profile_len = 0;
  177675. png_debug(1, "in png_write_iCCP\n");
  177676. comp.num_output_ptr = 0;
  177677. comp.max_output_ptr = 0;
  177678. comp.output_ptr = NULL;
  177679. comp.input = NULL;
  177680. comp.input_len = 0;
  177681. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177682. &new_name)) == 0)
  177683. {
  177684. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177685. return;
  177686. }
  177687. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177688. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177689. if (profile == NULL)
  177690. profile_len = 0;
  177691. if (profile_len > 3)
  177692. embedded_profile_len =
  177693. ((*( (png_bytep)profile ))<<24) |
  177694. ((*( (png_bytep)profile+1))<<16) |
  177695. ((*( (png_bytep)profile+2))<< 8) |
  177696. ((*( (png_bytep)profile+3)) );
  177697. if (profile_len < embedded_profile_len)
  177698. {
  177699. png_warning(png_ptr,
  177700. "Embedded profile length too large in iCCP chunk");
  177701. return;
  177702. }
  177703. if (profile_len > embedded_profile_len)
  177704. {
  177705. png_warning(png_ptr,
  177706. "Truncating profile to actual length in iCCP chunk");
  177707. profile_len = embedded_profile_len;
  177708. }
  177709. if (profile_len)
  177710. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177711. PNG_COMPRESSION_TYPE_BASE, &comp);
  177712. png_write_chunk_start(png_ptr, png_iCCP,
  177713. (png_uint_32)name_len+profile_len+2);
  177714. new_name[name_len+1]=0x00;
  177715. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177716. if (profile_len)
  177717. png_write_compressed_data_out(png_ptr, &comp);
  177718. png_write_chunk_end(png_ptr);
  177719. png_free(png_ptr, new_name);
  177720. }
  177721. #endif
  177722. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177723. void /* PRIVATE */
  177724. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177725. {
  177726. #ifdef PNG_USE_LOCAL_ARRAYS
  177727. PNG_sPLT;
  177728. #endif
  177729. png_size_t name_len;
  177730. png_charp new_name;
  177731. png_byte entrybuf[10];
  177732. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177733. int palette_size = entry_size * spalette->nentries;
  177734. png_sPLT_entryp ep;
  177735. #ifdef PNG_NO_POINTER_INDEXING
  177736. int i;
  177737. #endif
  177738. png_debug(1, "in png_write_sPLT\n");
  177739. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177740. spalette->name, &new_name))==0)
  177741. {
  177742. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177743. return;
  177744. }
  177745. png_write_chunk_start(png_ptr, png_sPLT,
  177746. (png_uint_32)(name_len + 2 + palette_size));
  177747. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177748. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177749. #ifndef PNG_NO_POINTER_INDEXING
  177750. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177751. {
  177752. if (spalette->depth == 8)
  177753. {
  177754. entrybuf[0] = (png_byte)ep->red;
  177755. entrybuf[1] = (png_byte)ep->green;
  177756. entrybuf[2] = (png_byte)ep->blue;
  177757. entrybuf[3] = (png_byte)ep->alpha;
  177758. png_save_uint_16(entrybuf + 4, ep->frequency);
  177759. }
  177760. else
  177761. {
  177762. png_save_uint_16(entrybuf + 0, ep->red);
  177763. png_save_uint_16(entrybuf + 2, ep->green);
  177764. png_save_uint_16(entrybuf + 4, ep->blue);
  177765. png_save_uint_16(entrybuf + 6, ep->alpha);
  177766. png_save_uint_16(entrybuf + 8, ep->frequency);
  177767. }
  177768. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177769. }
  177770. #else
  177771. ep=spalette->entries;
  177772. for (i=0; i>spalette->nentries; i++)
  177773. {
  177774. if (spalette->depth == 8)
  177775. {
  177776. entrybuf[0] = (png_byte)ep[i].red;
  177777. entrybuf[1] = (png_byte)ep[i].green;
  177778. entrybuf[2] = (png_byte)ep[i].blue;
  177779. entrybuf[3] = (png_byte)ep[i].alpha;
  177780. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177781. }
  177782. else
  177783. {
  177784. png_save_uint_16(entrybuf + 0, ep[i].red);
  177785. png_save_uint_16(entrybuf + 2, ep[i].green);
  177786. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177787. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177788. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177789. }
  177790. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177791. }
  177792. #endif
  177793. png_write_chunk_end(png_ptr);
  177794. png_free(png_ptr, new_name);
  177795. }
  177796. #endif
  177797. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177798. void /* PRIVATE */
  177799. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177800. {
  177801. #ifdef PNG_USE_LOCAL_ARRAYS
  177802. PNG_sBIT;
  177803. #endif
  177804. png_byte buf[4];
  177805. png_size_t size;
  177806. png_debug(1, "in png_write_sBIT\n");
  177807. if (color_type & PNG_COLOR_MASK_COLOR)
  177808. {
  177809. png_byte maxbits;
  177810. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177811. png_ptr->usr_bit_depth);
  177812. if (sbit->red == 0 || sbit->red > maxbits ||
  177813. sbit->green == 0 || sbit->green > maxbits ||
  177814. sbit->blue == 0 || sbit->blue > maxbits)
  177815. {
  177816. png_warning(png_ptr, "Invalid sBIT depth specified");
  177817. return;
  177818. }
  177819. buf[0] = sbit->red;
  177820. buf[1] = sbit->green;
  177821. buf[2] = sbit->blue;
  177822. size = 3;
  177823. }
  177824. else
  177825. {
  177826. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177827. {
  177828. png_warning(png_ptr, "Invalid sBIT depth specified");
  177829. return;
  177830. }
  177831. buf[0] = sbit->gray;
  177832. size = 1;
  177833. }
  177834. if (color_type & PNG_COLOR_MASK_ALPHA)
  177835. {
  177836. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177837. {
  177838. png_warning(png_ptr, "Invalid sBIT depth specified");
  177839. return;
  177840. }
  177841. buf[size++] = sbit->alpha;
  177842. }
  177843. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177844. }
  177845. #endif
  177846. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177847. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177848. void /* PRIVATE */
  177849. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177850. double red_x, double red_y, double green_x, double green_y,
  177851. double blue_x, double blue_y)
  177852. {
  177853. #ifdef PNG_USE_LOCAL_ARRAYS
  177854. PNG_cHRM;
  177855. #endif
  177856. png_byte buf[32];
  177857. png_uint_32 itemp;
  177858. png_debug(1, "in png_write_cHRM\n");
  177859. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177860. white_x + white_y > 1.0)
  177861. {
  177862. png_warning(png_ptr, "Invalid cHRM white point specified");
  177863. #if !defined(PNG_NO_CONSOLE_IO)
  177864. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177865. #endif
  177866. return;
  177867. }
  177868. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177869. png_save_uint_32(buf, itemp);
  177870. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177871. png_save_uint_32(buf + 4, itemp);
  177872. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177873. {
  177874. png_warning(png_ptr, "Invalid cHRM red point specified");
  177875. return;
  177876. }
  177877. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177878. png_save_uint_32(buf + 8, itemp);
  177879. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177880. png_save_uint_32(buf + 12, itemp);
  177881. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177882. {
  177883. png_warning(png_ptr, "Invalid cHRM green point specified");
  177884. return;
  177885. }
  177886. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177887. png_save_uint_32(buf + 16, itemp);
  177888. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177889. png_save_uint_32(buf + 20, itemp);
  177890. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177891. {
  177892. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177893. return;
  177894. }
  177895. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177896. png_save_uint_32(buf + 24, itemp);
  177897. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177898. png_save_uint_32(buf + 28, itemp);
  177899. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177900. }
  177901. #endif
  177902. #ifdef PNG_FIXED_POINT_SUPPORTED
  177903. void /* PRIVATE */
  177904. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177905. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177906. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177907. png_fixed_point blue_y)
  177908. {
  177909. #ifdef PNG_USE_LOCAL_ARRAYS
  177910. PNG_cHRM;
  177911. #endif
  177912. png_byte buf[32];
  177913. png_debug(1, "in png_write_cHRM\n");
  177914. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177915. {
  177916. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177917. #if !defined(PNG_NO_CONSOLE_IO)
  177918. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177919. #endif
  177920. return;
  177921. }
  177922. png_save_uint_32(buf, (png_uint_32)white_x);
  177923. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177924. if (red_x + red_y > 100000L)
  177925. {
  177926. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177927. return;
  177928. }
  177929. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177930. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177931. if (green_x + green_y > 100000L)
  177932. {
  177933. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177934. return;
  177935. }
  177936. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177937. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177938. if (blue_x + blue_y > 100000L)
  177939. {
  177940. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177941. return;
  177942. }
  177943. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177944. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177945. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177946. }
  177947. #endif
  177948. #endif
  177949. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177950. void /* PRIVATE */
  177951. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177952. int num_trans, int color_type)
  177953. {
  177954. #ifdef PNG_USE_LOCAL_ARRAYS
  177955. PNG_tRNS;
  177956. #endif
  177957. png_byte buf[6];
  177958. png_debug(1, "in png_write_tRNS\n");
  177959. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177960. {
  177961. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177962. {
  177963. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177964. return;
  177965. }
  177966. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177967. }
  177968. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177969. {
  177970. if(tran->gray >= (1 << png_ptr->bit_depth))
  177971. {
  177972. png_warning(png_ptr,
  177973. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177974. return;
  177975. }
  177976. png_save_uint_16(buf, tran->gray);
  177977. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177978. }
  177979. else if (color_type == PNG_COLOR_TYPE_RGB)
  177980. {
  177981. png_save_uint_16(buf, tran->red);
  177982. png_save_uint_16(buf + 2, tran->green);
  177983. png_save_uint_16(buf + 4, tran->blue);
  177984. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177985. {
  177986. png_warning(png_ptr,
  177987. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177988. return;
  177989. }
  177990. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177991. }
  177992. else
  177993. {
  177994. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177995. }
  177996. }
  177997. #endif
  177998. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177999. void /* PRIVATE */
  178000. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  178001. {
  178002. #ifdef PNG_USE_LOCAL_ARRAYS
  178003. PNG_bKGD;
  178004. #endif
  178005. png_byte buf[6];
  178006. png_debug(1, "in png_write_bKGD\n");
  178007. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178008. {
  178009. if (
  178010. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  178011. (png_ptr->num_palette ||
  178012. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  178013. #endif
  178014. back->index > png_ptr->num_palette)
  178015. {
  178016. png_warning(png_ptr, "Invalid background palette index");
  178017. return;
  178018. }
  178019. buf[0] = back->index;
  178020. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  178021. }
  178022. else if (color_type & PNG_COLOR_MASK_COLOR)
  178023. {
  178024. png_save_uint_16(buf, back->red);
  178025. png_save_uint_16(buf + 2, back->green);
  178026. png_save_uint_16(buf + 4, back->blue);
  178027. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178028. {
  178029. png_warning(png_ptr,
  178030. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  178031. return;
  178032. }
  178033. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  178034. }
  178035. else
  178036. {
  178037. if(back->gray >= (1 << png_ptr->bit_depth))
  178038. {
  178039. png_warning(png_ptr,
  178040. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  178041. return;
  178042. }
  178043. png_save_uint_16(buf, back->gray);
  178044. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  178045. }
  178046. }
  178047. #endif
  178048. #if defined(PNG_WRITE_hIST_SUPPORTED)
  178049. void /* PRIVATE */
  178050. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  178051. {
  178052. #ifdef PNG_USE_LOCAL_ARRAYS
  178053. PNG_hIST;
  178054. #endif
  178055. int i;
  178056. png_byte buf[3];
  178057. png_debug(1, "in png_write_hIST\n");
  178058. if (num_hist > (int)png_ptr->num_palette)
  178059. {
  178060. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  178061. png_ptr->num_palette);
  178062. png_warning(png_ptr, "Invalid number of histogram entries specified");
  178063. return;
  178064. }
  178065. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  178066. for (i = 0; i < num_hist; i++)
  178067. {
  178068. png_save_uint_16(buf, hist[i]);
  178069. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  178070. }
  178071. png_write_chunk_end(png_ptr);
  178072. }
  178073. #endif
  178074. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  178075. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  178076. png_size_t /* PRIVATE */
  178077. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  178078. {
  178079. png_size_t key_len;
  178080. png_charp kp, dp;
  178081. int kflag;
  178082. int kwarn=0;
  178083. png_debug(1, "in png_check_keyword\n");
  178084. *new_key = NULL;
  178085. if (key == NULL || (key_len = png_strlen(key)) == 0)
  178086. {
  178087. png_warning(png_ptr, "zero length keyword");
  178088. return ((png_size_t)0);
  178089. }
  178090. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  178091. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  178092. if (*new_key == NULL)
  178093. {
  178094. png_warning(png_ptr, "Out of memory while procesing keyword");
  178095. return ((png_size_t)0);
  178096. }
  178097. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  178098. {
  178099. if ((png_byte)*kp < 0x20 ||
  178100. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  178101. {
  178102. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  178103. char msg[40];
  178104. png_snprintf(msg, 40,
  178105. "invalid keyword character 0x%02X", (png_byte)*kp);
  178106. png_warning(png_ptr, msg);
  178107. #else
  178108. png_warning(png_ptr, "invalid character in keyword");
  178109. #endif
  178110. *dp = ' ';
  178111. }
  178112. else
  178113. {
  178114. *dp = *kp;
  178115. }
  178116. }
  178117. *dp = '\0';
  178118. kp = *new_key + key_len - 1;
  178119. if (*kp == ' ')
  178120. {
  178121. png_warning(png_ptr, "trailing spaces removed from keyword");
  178122. while (*kp == ' ')
  178123. {
  178124. *(kp--) = '\0';
  178125. key_len--;
  178126. }
  178127. }
  178128. kp = *new_key;
  178129. if (*kp == ' ')
  178130. {
  178131. png_warning(png_ptr, "leading spaces removed from keyword");
  178132. while (*kp == ' ')
  178133. {
  178134. kp++;
  178135. key_len--;
  178136. }
  178137. }
  178138. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  178139. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  178140. {
  178141. if (*kp == ' ' && kflag == 0)
  178142. {
  178143. *(dp++) = *kp;
  178144. kflag = 1;
  178145. }
  178146. else if (*kp == ' ')
  178147. {
  178148. key_len--;
  178149. kwarn=1;
  178150. }
  178151. else
  178152. {
  178153. *(dp++) = *kp;
  178154. kflag = 0;
  178155. }
  178156. }
  178157. *dp = '\0';
  178158. if(kwarn)
  178159. png_warning(png_ptr, "extra interior spaces removed from keyword");
  178160. if (key_len == 0)
  178161. {
  178162. png_free(png_ptr, *new_key);
  178163. *new_key=NULL;
  178164. png_warning(png_ptr, "Zero length keyword");
  178165. }
  178166. if (key_len > 79)
  178167. {
  178168. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  178169. new_key[79] = '\0';
  178170. key_len = 79;
  178171. }
  178172. return (key_len);
  178173. }
  178174. #endif
  178175. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  178176. void /* PRIVATE */
  178177. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  178178. png_size_t text_len)
  178179. {
  178180. #ifdef PNG_USE_LOCAL_ARRAYS
  178181. PNG_tEXt;
  178182. #endif
  178183. png_size_t key_len;
  178184. png_charp new_key;
  178185. png_debug(1, "in png_write_tEXt\n");
  178186. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178187. {
  178188. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  178189. return;
  178190. }
  178191. if (text == NULL || *text == '\0')
  178192. text_len = 0;
  178193. else
  178194. text_len = png_strlen(text);
  178195. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  178196. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178197. if (text_len)
  178198. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  178199. png_write_chunk_end(png_ptr);
  178200. png_free(png_ptr, new_key);
  178201. }
  178202. #endif
  178203. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  178204. void /* PRIVATE */
  178205. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  178206. png_size_t text_len, int compression)
  178207. {
  178208. #ifdef PNG_USE_LOCAL_ARRAYS
  178209. PNG_zTXt;
  178210. #endif
  178211. png_size_t key_len;
  178212. char buf[1];
  178213. png_charp new_key;
  178214. compression_state comp;
  178215. png_debug(1, "in png_write_zTXt\n");
  178216. comp.num_output_ptr = 0;
  178217. comp.max_output_ptr = 0;
  178218. comp.output_ptr = NULL;
  178219. comp.input = NULL;
  178220. comp.input_len = 0;
  178221. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178222. {
  178223. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  178224. return;
  178225. }
  178226. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  178227. {
  178228. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  178229. png_free(png_ptr, new_key);
  178230. return;
  178231. }
  178232. text_len = png_strlen(text);
  178233. text_len = png_text_compress(png_ptr, text, text_len, compression,
  178234. &comp);
  178235. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  178236. (key_len+text_len+2));
  178237. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178238. png_free(png_ptr, new_key);
  178239. buf[0] = (png_byte)compression;
  178240. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  178241. png_write_compressed_data_out(png_ptr, &comp);
  178242. png_write_chunk_end(png_ptr);
  178243. }
  178244. #endif
  178245. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  178246. void /* PRIVATE */
  178247. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  178248. png_charp lang, png_charp lang_key, png_charp text)
  178249. {
  178250. #ifdef PNG_USE_LOCAL_ARRAYS
  178251. PNG_iTXt;
  178252. #endif
  178253. png_size_t lang_len, key_len, lang_key_len, text_len;
  178254. png_charp new_lang, new_key;
  178255. png_byte cbuf[2];
  178256. compression_state comp;
  178257. png_debug(1, "in png_write_iTXt\n");
  178258. comp.num_output_ptr = 0;
  178259. comp.max_output_ptr = 0;
  178260. comp.output_ptr = NULL;
  178261. comp.input = NULL;
  178262. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178263. {
  178264. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  178265. return;
  178266. }
  178267. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  178268. {
  178269. png_warning(png_ptr, "Empty language field in iTXt chunk");
  178270. new_lang = NULL;
  178271. lang_len = 0;
  178272. }
  178273. if (lang_key == NULL)
  178274. lang_key_len = 0;
  178275. else
  178276. lang_key_len = png_strlen(lang_key);
  178277. if (text == NULL)
  178278. text_len = 0;
  178279. else
  178280. text_len = png_strlen(text);
  178281. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  178282. &comp);
  178283. png_write_chunk_start(png_ptr, png_iTXt,
  178284. (png_uint_32)(
  178285. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178286. + key_len
  178287. + lang_len
  178288. + lang_key_len
  178289. + text_len));
  178290. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178291. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178292. compression == PNG_TEXT_COMPRESSION_NONE)
  178293. cbuf[0] = 0;
  178294. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178295. cbuf[0] = 1;
  178296. cbuf[1] = 0;
  178297. png_write_chunk_data(png_ptr, cbuf, 2);
  178298. cbuf[0] = 0;
  178299. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178300. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178301. png_write_compressed_data_out(png_ptr, &comp);
  178302. png_write_chunk_end(png_ptr);
  178303. png_free(png_ptr, new_key);
  178304. if (new_lang)
  178305. png_free(png_ptr, new_lang);
  178306. }
  178307. #endif
  178308. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178309. void /* PRIVATE */
  178310. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178311. int unit_type)
  178312. {
  178313. #ifdef PNG_USE_LOCAL_ARRAYS
  178314. PNG_oFFs;
  178315. #endif
  178316. png_byte buf[9];
  178317. png_debug(1, "in png_write_oFFs\n");
  178318. if (unit_type >= PNG_OFFSET_LAST)
  178319. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178320. png_save_int_32(buf, x_offset);
  178321. png_save_int_32(buf + 4, y_offset);
  178322. buf[8] = (png_byte)unit_type;
  178323. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178324. }
  178325. #endif
  178326. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178327. void /* PRIVATE */
  178328. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178329. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178330. {
  178331. #ifdef PNG_USE_LOCAL_ARRAYS
  178332. PNG_pCAL;
  178333. #endif
  178334. png_size_t purpose_len, units_len, total_len;
  178335. png_uint_32p params_len;
  178336. png_byte buf[10];
  178337. png_charp new_purpose;
  178338. int i;
  178339. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178340. if (type >= PNG_EQUATION_LAST)
  178341. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178342. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178343. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178344. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178345. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178346. total_len = purpose_len + units_len + 10;
  178347. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178348. *png_sizeof(png_uint_32)));
  178349. for (i = 0; i < nparams; i++)
  178350. {
  178351. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178352. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178353. total_len += (png_size_t)params_len[i];
  178354. }
  178355. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178356. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178357. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178358. png_save_int_32(buf, X0);
  178359. png_save_int_32(buf + 4, X1);
  178360. buf[8] = (png_byte)type;
  178361. buf[9] = (png_byte)nparams;
  178362. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178363. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178364. png_free(png_ptr, new_purpose);
  178365. for (i = 0; i < nparams; i++)
  178366. {
  178367. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178368. (png_size_t)params_len[i]);
  178369. }
  178370. png_free(png_ptr, params_len);
  178371. png_write_chunk_end(png_ptr);
  178372. }
  178373. #endif
  178374. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178375. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178376. void /* PRIVATE */
  178377. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178378. {
  178379. #ifdef PNG_USE_LOCAL_ARRAYS
  178380. PNG_sCAL;
  178381. #endif
  178382. char buf[64];
  178383. png_size_t total_len;
  178384. png_debug(1, "in png_write_sCAL\n");
  178385. buf[0] = (char)unit;
  178386. #if defined(_WIN32_WCE)
  178387. {
  178388. wchar_t wc_buf[32];
  178389. size_t wc_len;
  178390. swprintf(wc_buf, TEXT("%12.12e"), width);
  178391. wc_len = wcslen(wc_buf);
  178392. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178393. total_len = wc_len + 2;
  178394. swprintf(wc_buf, TEXT("%12.12e"), height);
  178395. wc_len = wcslen(wc_buf);
  178396. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178397. NULL, NULL);
  178398. total_len += wc_len;
  178399. }
  178400. #else
  178401. png_snprintf(buf + 1, 63, "%12.12e", width);
  178402. total_len = 1 + png_strlen(buf + 1) + 1;
  178403. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178404. total_len += png_strlen(buf + total_len);
  178405. #endif
  178406. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178407. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178408. }
  178409. #else
  178410. #ifdef PNG_FIXED_POINT_SUPPORTED
  178411. void /* PRIVATE */
  178412. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178413. png_charp height)
  178414. {
  178415. #ifdef PNG_USE_LOCAL_ARRAYS
  178416. PNG_sCAL;
  178417. #endif
  178418. png_byte buf[64];
  178419. png_size_t wlen, hlen, total_len;
  178420. png_debug(1, "in png_write_sCAL_s\n");
  178421. wlen = png_strlen(width);
  178422. hlen = png_strlen(height);
  178423. total_len = wlen + hlen + 2;
  178424. if (total_len > 64)
  178425. {
  178426. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178427. return;
  178428. }
  178429. buf[0] = (png_byte)unit;
  178430. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178431. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178432. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178433. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178434. }
  178435. #endif
  178436. #endif
  178437. #endif
  178438. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178439. void /* PRIVATE */
  178440. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178441. png_uint_32 y_pixels_per_unit,
  178442. int unit_type)
  178443. {
  178444. #ifdef PNG_USE_LOCAL_ARRAYS
  178445. PNG_pHYs;
  178446. #endif
  178447. png_byte buf[9];
  178448. png_debug(1, "in png_write_pHYs\n");
  178449. if (unit_type >= PNG_RESOLUTION_LAST)
  178450. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178451. png_save_uint_32(buf, x_pixels_per_unit);
  178452. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178453. buf[8] = (png_byte)unit_type;
  178454. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178455. }
  178456. #endif
  178457. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178458. void /* PRIVATE */
  178459. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178460. {
  178461. #ifdef PNG_USE_LOCAL_ARRAYS
  178462. PNG_tIME;
  178463. #endif
  178464. png_byte buf[7];
  178465. png_debug(1, "in png_write_tIME\n");
  178466. if (mod_time->month > 12 || mod_time->month < 1 ||
  178467. mod_time->day > 31 || mod_time->day < 1 ||
  178468. mod_time->hour > 23 || mod_time->second > 60)
  178469. {
  178470. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178471. return;
  178472. }
  178473. png_save_uint_16(buf, mod_time->year);
  178474. buf[2] = mod_time->month;
  178475. buf[3] = mod_time->day;
  178476. buf[4] = mod_time->hour;
  178477. buf[5] = mod_time->minute;
  178478. buf[6] = mod_time->second;
  178479. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178480. }
  178481. #endif
  178482. void /* PRIVATE */
  178483. png_write_start_row(png_structp png_ptr)
  178484. {
  178485. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178486. #ifdef PNG_USE_LOCAL_ARRAYS
  178487. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178488. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178489. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178490. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178491. #endif
  178492. #endif
  178493. png_size_t buf_size;
  178494. png_debug(1, "in png_write_start_row\n");
  178495. buf_size = (png_size_t)(PNG_ROWBYTES(
  178496. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178497. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178498. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178499. #ifndef PNG_NO_WRITE_FILTERING
  178500. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178501. {
  178502. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178503. (png_ptr->rowbytes + 1));
  178504. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178505. }
  178506. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178507. {
  178508. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178509. png_memset(png_ptr->prev_row, 0, buf_size);
  178510. if (png_ptr->do_filter & PNG_FILTER_UP)
  178511. {
  178512. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178513. (png_ptr->rowbytes + 1));
  178514. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178515. }
  178516. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178517. {
  178518. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178519. (png_ptr->rowbytes + 1));
  178520. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178521. }
  178522. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178523. {
  178524. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178525. (png_ptr->rowbytes + 1));
  178526. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178527. }
  178528. #endif /* PNG_NO_WRITE_FILTERING */
  178529. }
  178530. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178531. if (png_ptr->interlaced)
  178532. {
  178533. if (!(png_ptr->transformations & PNG_INTERLACE))
  178534. {
  178535. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178536. png_pass_ystart[0]) / png_pass_yinc[0];
  178537. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178538. png_pass_start[0]) / png_pass_inc[0];
  178539. }
  178540. else
  178541. {
  178542. png_ptr->num_rows = png_ptr->height;
  178543. png_ptr->usr_width = png_ptr->width;
  178544. }
  178545. }
  178546. else
  178547. #endif
  178548. {
  178549. png_ptr->num_rows = png_ptr->height;
  178550. png_ptr->usr_width = png_ptr->width;
  178551. }
  178552. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178553. png_ptr->zstream.next_out = png_ptr->zbuf;
  178554. }
  178555. void /* PRIVATE */
  178556. png_write_finish_row(png_structp png_ptr)
  178557. {
  178558. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178559. #ifdef PNG_USE_LOCAL_ARRAYS
  178560. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178561. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178562. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178563. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178564. #endif
  178565. #endif
  178566. int ret;
  178567. png_debug(1, "in png_write_finish_row\n");
  178568. png_ptr->row_number++;
  178569. if (png_ptr->row_number < png_ptr->num_rows)
  178570. return;
  178571. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178572. if (png_ptr->interlaced)
  178573. {
  178574. png_ptr->row_number = 0;
  178575. if (png_ptr->transformations & PNG_INTERLACE)
  178576. {
  178577. png_ptr->pass++;
  178578. }
  178579. else
  178580. {
  178581. do
  178582. {
  178583. png_ptr->pass++;
  178584. if (png_ptr->pass >= 7)
  178585. break;
  178586. png_ptr->usr_width = (png_ptr->width +
  178587. png_pass_inc[png_ptr->pass] - 1 -
  178588. png_pass_start[png_ptr->pass]) /
  178589. png_pass_inc[png_ptr->pass];
  178590. png_ptr->num_rows = (png_ptr->height +
  178591. png_pass_yinc[png_ptr->pass] - 1 -
  178592. png_pass_ystart[png_ptr->pass]) /
  178593. png_pass_yinc[png_ptr->pass];
  178594. if (png_ptr->transformations & PNG_INTERLACE)
  178595. break;
  178596. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178597. }
  178598. if (png_ptr->pass < 7)
  178599. {
  178600. if (png_ptr->prev_row != NULL)
  178601. png_memset(png_ptr->prev_row, 0,
  178602. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178603. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178604. return;
  178605. }
  178606. }
  178607. #endif
  178608. do
  178609. {
  178610. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178611. if (ret == Z_OK)
  178612. {
  178613. if (!(png_ptr->zstream.avail_out))
  178614. {
  178615. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178616. png_ptr->zstream.next_out = png_ptr->zbuf;
  178617. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178618. }
  178619. }
  178620. else if (ret != Z_STREAM_END)
  178621. {
  178622. if (png_ptr->zstream.msg != NULL)
  178623. png_error(png_ptr, png_ptr->zstream.msg);
  178624. else
  178625. png_error(png_ptr, "zlib error");
  178626. }
  178627. } while (ret != Z_STREAM_END);
  178628. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178629. {
  178630. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178631. png_ptr->zstream.avail_out);
  178632. }
  178633. deflateReset(&png_ptr->zstream);
  178634. png_ptr->zstream.data_type = Z_BINARY;
  178635. }
  178636. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178637. void /* PRIVATE */
  178638. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178639. {
  178640. #ifdef PNG_USE_LOCAL_ARRAYS
  178641. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178642. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178643. #endif
  178644. png_debug(1, "in png_do_write_interlace\n");
  178645. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178646. if (row != NULL && row_info != NULL && pass < 6)
  178647. #else
  178648. if (pass < 6)
  178649. #endif
  178650. {
  178651. switch (row_info->pixel_depth)
  178652. {
  178653. case 1:
  178654. {
  178655. png_bytep sp;
  178656. png_bytep dp;
  178657. int shift;
  178658. int d;
  178659. int value;
  178660. png_uint_32 i;
  178661. png_uint_32 row_width = row_info->width;
  178662. dp = row;
  178663. d = 0;
  178664. shift = 7;
  178665. for (i = png_pass_start[pass]; i < row_width;
  178666. i += png_pass_inc[pass])
  178667. {
  178668. sp = row + (png_size_t)(i >> 3);
  178669. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178670. d |= (value << shift);
  178671. if (shift == 0)
  178672. {
  178673. shift = 7;
  178674. *dp++ = (png_byte)d;
  178675. d = 0;
  178676. }
  178677. else
  178678. shift--;
  178679. }
  178680. if (shift != 7)
  178681. *dp = (png_byte)d;
  178682. break;
  178683. }
  178684. case 2:
  178685. {
  178686. png_bytep sp;
  178687. png_bytep dp;
  178688. int shift;
  178689. int d;
  178690. int value;
  178691. png_uint_32 i;
  178692. png_uint_32 row_width = row_info->width;
  178693. dp = row;
  178694. shift = 6;
  178695. d = 0;
  178696. for (i = png_pass_start[pass]; i < row_width;
  178697. i += png_pass_inc[pass])
  178698. {
  178699. sp = row + (png_size_t)(i >> 2);
  178700. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178701. d |= (value << shift);
  178702. if (shift == 0)
  178703. {
  178704. shift = 6;
  178705. *dp++ = (png_byte)d;
  178706. d = 0;
  178707. }
  178708. else
  178709. shift -= 2;
  178710. }
  178711. if (shift != 6)
  178712. *dp = (png_byte)d;
  178713. break;
  178714. }
  178715. case 4:
  178716. {
  178717. png_bytep sp;
  178718. png_bytep dp;
  178719. int shift;
  178720. int d;
  178721. int value;
  178722. png_uint_32 i;
  178723. png_uint_32 row_width = row_info->width;
  178724. dp = row;
  178725. shift = 4;
  178726. d = 0;
  178727. for (i = png_pass_start[pass]; i < row_width;
  178728. i += png_pass_inc[pass])
  178729. {
  178730. sp = row + (png_size_t)(i >> 1);
  178731. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178732. d |= (value << shift);
  178733. if (shift == 0)
  178734. {
  178735. shift = 4;
  178736. *dp++ = (png_byte)d;
  178737. d = 0;
  178738. }
  178739. else
  178740. shift -= 4;
  178741. }
  178742. if (shift != 4)
  178743. *dp = (png_byte)d;
  178744. break;
  178745. }
  178746. default:
  178747. {
  178748. png_bytep sp;
  178749. png_bytep dp;
  178750. png_uint_32 i;
  178751. png_uint_32 row_width = row_info->width;
  178752. png_size_t pixel_bytes;
  178753. dp = row;
  178754. pixel_bytes = (row_info->pixel_depth >> 3);
  178755. for (i = png_pass_start[pass]; i < row_width;
  178756. i += png_pass_inc[pass])
  178757. {
  178758. sp = row + (png_size_t)i * pixel_bytes;
  178759. if (dp != sp)
  178760. png_memcpy(dp, sp, pixel_bytes);
  178761. dp += pixel_bytes;
  178762. }
  178763. break;
  178764. }
  178765. }
  178766. row_info->width = (row_info->width +
  178767. png_pass_inc[pass] - 1 -
  178768. png_pass_start[pass]) /
  178769. png_pass_inc[pass];
  178770. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178771. row_info->width);
  178772. }
  178773. }
  178774. #endif
  178775. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178776. #define PNG_HISHIFT 10
  178777. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178778. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178779. void /* PRIVATE */
  178780. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178781. {
  178782. png_bytep best_row;
  178783. #ifndef PNG_NO_WRITE_FILTER
  178784. png_bytep prev_row, row_buf;
  178785. png_uint_32 mins, bpp;
  178786. png_byte filter_to_do = png_ptr->do_filter;
  178787. png_uint_32 row_bytes = row_info->rowbytes;
  178788. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178789. int num_p_filters = (int)png_ptr->num_prev_filters;
  178790. #endif
  178791. png_debug(1, "in png_write_find_filter\n");
  178792. bpp = (row_info->pixel_depth + 7) >> 3;
  178793. prev_row = png_ptr->prev_row;
  178794. #endif
  178795. best_row = png_ptr->row_buf;
  178796. #ifndef PNG_NO_WRITE_FILTER
  178797. row_buf = best_row;
  178798. mins = PNG_MAXSUM;
  178799. if ((filter_to_do & PNG_FILTER_NONE) &&
  178800. filter_to_do != PNG_FILTER_NONE)
  178801. {
  178802. png_bytep rp;
  178803. png_uint_32 sum = 0;
  178804. png_uint_32 i;
  178805. int v;
  178806. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178807. {
  178808. v = *rp;
  178809. sum += (v < 128) ? v : 256 - v;
  178810. }
  178811. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178812. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178813. {
  178814. png_uint_32 sumhi, sumlo;
  178815. int j;
  178816. sumlo = sum & PNG_LOMASK;
  178817. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178818. for (j = 0; j < num_p_filters; j++)
  178819. {
  178820. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178821. {
  178822. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178823. PNG_WEIGHT_SHIFT;
  178824. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178825. PNG_WEIGHT_SHIFT;
  178826. }
  178827. }
  178828. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178829. PNG_COST_SHIFT;
  178830. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178831. PNG_COST_SHIFT;
  178832. if (sumhi > PNG_HIMASK)
  178833. sum = PNG_MAXSUM;
  178834. else
  178835. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178836. }
  178837. #endif
  178838. mins = sum;
  178839. }
  178840. if (filter_to_do == PNG_FILTER_SUB)
  178841. {
  178842. png_bytep rp, lp, dp;
  178843. png_uint_32 i;
  178844. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178845. i++, rp++, dp++)
  178846. {
  178847. *dp = *rp;
  178848. }
  178849. for (lp = row_buf + 1; i < row_bytes;
  178850. i++, rp++, lp++, dp++)
  178851. {
  178852. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178853. }
  178854. best_row = png_ptr->sub_row;
  178855. }
  178856. else if (filter_to_do & PNG_FILTER_SUB)
  178857. {
  178858. png_bytep rp, dp, lp;
  178859. png_uint_32 sum = 0, lmins = mins;
  178860. png_uint_32 i;
  178861. int v;
  178862. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178863. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178864. {
  178865. int j;
  178866. png_uint_32 lmhi, lmlo;
  178867. lmlo = lmins & PNG_LOMASK;
  178868. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178869. for (j = 0; j < num_p_filters; j++)
  178870. {
  178871. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178872. {
  178873. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178874. PNG_WEIGHT_SHIFT;
  178875. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178876. PNG_WEIGHT_SHIFT;
  178877. }
  178878. }
  178879. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178880. PNG_COST_SHIFT;
  178881. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178882. PNG_COST_SHIFT;
  178883. if (lmhi > PNG_HIMASK)
  178884. lmins = PNG_MAXSUM;
  178885. else
  178886. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178887. }
  178888. #endif
  178889. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178890. i++, rp++, dp++)
  178891. {
  178892. v = *dp = *rp;
  178893. sum += (v < 128) ? v : 256 - v;
  178894. }
  178895. for (lp = row_buf + 1; i < row_bytes;
  178896. i++, rp++, lp++, dp++)
  178897. {
  178898. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178899. sum += (v < 128) ? v : 256 - v;
  178900. if (sum > lmins) /* We are already worse, don't continue. */
  178901. break;
  178902. }
  178903. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178904. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178905. {
  178906. int j;
  178907. png_uint_32 sumhi, sumlo;
  178908. sumlo = sum & PNG_LOMASK;
  178909. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178910. for (j = 0; j < num_p_filters; j++)
  178911. {
  178912. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178913. {
  178914. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178915. PNG_WEIGHT_SHIFT;
  178916. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178917. PNG_WEIGHT_SHIFT;
  178918. }
  178919. }
  178920. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178921. PNG_COST_SHIFT;
  178922. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178923. PNG_COST_SHIFT;
  178924. if (sumhi > PNG_HIMASK)
  178925. sum = PNG_MAXSUM;
  178926. else
  178927. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178928. }
  178929. #endif
  178930. if (sum < mins)
  178931. {
  178932. mins = sum;
  178933. best_row = png_ptr->sub_row;
  178934. }
  178935. }
  178936. if (filter_to_do == PNG_FILTER_UP)
  178937. {
  178938. png_bytep rp, dp, pp;
  178939. png_uint_32 i;
  178940. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178941. pp = prev_row + 1; i < row_bytes;
  178942. i++, rp++, pp++, dp++)
  178943. {
  178944. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178945. }
  178946. best_row = png_ptr->up_row;
  178947. }
  178948. else if (filter_to_do & PNG_FILTER_UP)
  178949. {
  178950. png_bytep rp, dp, pp;
  178951. png_uint_32 sum = 0, lmins = mins;
  178952. png_uint_32 i;
  178953. int v;
  178954. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178955. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178956. {
  178957. int j;
  178958. png_uint_32 lmhi, lmlo;
  178959. lmlo = lmins & PNG_LOMASK;
  178960. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178961. for (j = 0; j < num_p_filters; j++)
  178962. {
  178963. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178964. {
  178965. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178966. PNG_WEIGHT_SHIFT;
  178967. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178968. PNG_WEIGHT_SHIFT;
  178969. }
  178970. }
  178971. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178972. PNG_COST_SHIFT;
  178973. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178974. PNG_COST_SHIFT;
  178975. if (lmhi > PNG_HIMASK)
  178976. lmins = PNG_MAXSUM;
  178977. else
  178978. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178979. }
  178980. #endif
  178981. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178982. pp = prev_row + 1; i < row_bytes; i++)
  178983. {
  178984. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178985. sum += (v < 128) ? v : 256 - v;
  178986. if (sum > lmins) /* We are already worse, don't continue. */
  178987. break;
  178988. }
  178989. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178990. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178991. {
  178992. int j;
  178993. png_uint_32 sumhi, sumlo;
  178994. sumlo = sum & PNG_LOMASK;
  178995. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178996. for (j = 0; j < num_p_filters; j++)
  178997. {
  178998. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178999. {
  179000. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179001. PNG_WEIGHT_SHIFT;
  179002. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179003. PNG_WEIGHT_SHIFT;
  179004. }
  179005. }
  179006. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179007. PNG_COST_SHIFT;
  179008. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179009. PNG_COST_SHIFT;
  179010. if (sumhi > PNG_HIMASK)
  179011. sum = PNG_MAXSUM;
  179012. else
  179013. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179014. }
  179015. #endif
  179016. if (sum < mins)
  179017. {
  179018. mins = sum;
  179019. best_row = png_ptr->up_row;
  179020. }
  179021. }
  179022. if (filter_to_do == PNG_FILTER_AVG)
  179023. {
  179024. png_bytep rp, dp, pp, lp;
  179025. png_uint_32 i;
  179026. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179027. pp = prev_row + 1; i < bpp; i++)
  179028. {
  179029. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179030. }
  179031. for (lp = row_buf + 1; i < row_bytes; i++)
  179032. {
  179033. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  179034. & 0xff);
  179035. }
  179036. best_row = png_ptr->avg_row;
  179037. }
  179038. else if (filter_to_do & PNG_FILTER_AVG)
  179039. {
  179040. png_bytep rp, dp, pp, lp;
  179041. png_uint_32 sum = 0, lmins = mins;
  179042. png_uint_32 i;
  179043. int v;
  179044. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179045. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179046. {
  179047. int j;
  179048. png_uint_32 lmhi, lmlo;
  179049. lmlo = lmins & PNG_LOMASK;
  179050. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179051. for (j = 0; j < num_p_filters; j++)
  179052. {
  179053. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  179054. {
  179055. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179056. PNG_WEIGHT_SHIFT;
  179057. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179058. PNG_WEIGHT_SHIFT;
  179059. }
  179060. }
  179061. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179062. PNG_COST_SHIFT;
  179063. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179064. PNG_COST_SHIFT;
  179065. if (lmhi > PNG_HIMASK)
  179066. lmins = PNG_MAXSUM;
  179067. else
  179068. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179069. }
  179070. #endif
  179071. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179072. pp = prev_row + 1; i < bpp; i++)
  179073. {
  179074. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179075. sum += (v < 128) ? v : 256 - v;
  179076. }
  179077. for (lp = row_buf + 1; i < row_bytes; i++)
  179078. {
  179079. v = *dp++ =
  179080. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  179081. sum += (v < 128) ? v : 256 - v;
  179082. if (sum > lmins) /* We are already worse, don't continue. */
  179083. break;
  179084. }
  179085. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179086. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179087. {
  179088. int j;
  179089. png_uint_32 sumhi, sumlo;
  179090. sumlo = sum & PNG_LOMASK;
  179091. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179092. for (j = 0; j < num_p_filters; j++)
  179093. {
  179094. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  179095. {
  179096. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179097. PNG_WEIGHT_SHIFT;
  179098. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179099. PNG_WEIGHT_SHIFT;
  179100. }
  179101. }
  179102. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179103. PNG_COST_SHIFT;
  179104. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179105. PNG_COST_SHIFT;
  179106. if (sumhi > PNG_HIMASK)
  179107. sum = PNG_MAXSUM;
  179108. else
  179109. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179110. }
  179111. #endif
  179112. if (sum < mins)
  179113. {
  179114. mins = sum;
  179115. best_row = png_ptr->avg_row;
  179116. }
  179117. }
  179118. if (filter_to_do == PNG_FILTER_PAETH)
  179119. {
  179120. png_bytep rp, dp, pp, cp, lp;
  179121. png_uint_32 i;
  179122. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179123. pp = prev_row + 1; i < bpp; i++)
  179124. {
  179125. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179126. }
  179127. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179128. {
  179129. int a, b, c, pa, pb, pc, p;
  179130. b = *pp++;
  179131. c = *cp++;
  179132. a = *lp++;
  179133. p = b - c;
  179134. pc = a - c;
  179135. #ifdef PNG_USE_ABS
  179136. pa = abs(p);
  179137. pb = abs(pc);
  179138. pc = abs(p + pc);
  179139. #else
  179140. pa = p < 0 ? -p : p;
  179141. pb = pc < 0 ? -pc : pc;
  179142. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179143. #endif
  179144. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179145. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179146. }
  179147. best_row = png_ptr->paeth_row;
  179148. }
  179149. else if (filter_to_do & PNG_FILTER_PAETH)
  179150. {
  179151. png_bytep rp, dp, pp, cp, lp;
  179152. png_uint_32 sum = 0, lmins = mins;
  179153. png_uint_32 i;
  179154. int v;
  179155. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179156. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179157. {
  179158. int j;
  179159. png_uint_32 lmhi, lmlo;
  179160. lmlo = lmins & PNG_LOMASK;
  179161. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179162. for (j = 0; j < num_p_filters; j++)
  179163. {
  179164. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179165. {
  179166. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179167. PNG_WEIGHT_SHIFT;
  179168. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179169. PNG_WEIGHT_SHIFT;
  179170. }
  179171. }
  179172. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179173. PNG_COST_SHIFT;
  179174. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179175. PNG_COST_SHIFT;
  179176. if (lmhi > PNG_HIMASK)
  179177. lmins = PNG_MAXSUM;
  179178. else
  179179. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179180. }
  179181. #endif
  179182. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179183. pp = prev_row + 1; i < bpp; i++)
  179184. {
  179185. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179186. sum += (v < 128) ? v : 256 - v;
  179187. }
  179188. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179189. {
  179190. int a, b, c, pa, pb, pc, p;
  179191. b = *pp++;
  179192. c = *cp++;
  179193. a = *lp++;
  179194. #ifndef PNG_SLOW_PAETH
  179195. p = b - c;
  179196. pc = a - c;
  179197. #ifdef PNG_USE_ABS
  179198. pa = abs(p);
  179199. pb = abs(pc);
  179200. pc = abs(p + pc);
  179201. #else
  179202. pa = p < 0 ? -p : p;
  179203. pb = pc < 0 ? -pc : pc;
  179204. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179205. #endif
  179206. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179207. #else /* PNG_SLOW_PAETH */
  179208. p = a + b - c;
  179209. pa = abs(p - a);
  179210. pb = abs(p - b);
  179211. pc = abs(p - c);
  179212. if (pa <= pb && pa <= pc)
  179213. p = a;
  179214. else if (pb <= pc)
  179215. p = b;
  179216. else
  179217. p = c;
  179218. #endif /* PNG_SLOW_PAETH */
  179219. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179220. sum += (v < 128) ? v : 256 - v;
  179221. if (sum > lmins) /* We are already worse, don't continue. */
  179222. break;
  179223. }
  179224. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179225. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179226. {
  179227. int j;
  179228. png_uint_32 sumhi, sumlo;
  179229. sumlo = sum & PNG_LOMASK;
  179230. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179231. for (j = 0; j < num_p_filters; j++)
  179232. {
  179233. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179234. {
  179235. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179236. PNG_WEIGHT_SHIFT;
  179237. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179238. PNG_WEIGHT_SHIFT;
  179239. }
  179240. }
  179241. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179242. PNG_COST_SHIFT;
  179243. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179244. PNG_COST_SHIFT;
  179245. if (sumhi > PNG_HIMASK)
  179246. sum = PNG_MAXSUM;
  179247. else
  179248. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179249. }
  179250. #endif
  179251. if (sum < mins)
  179252. {
  179253. best_row = png_ptr->paeth_row;
  179254. }
  179255. }
  179256. #endif /* PNG_NO_WRITE_FILTER */
  179257. png_write_filtered_row(png_ptr, best_row);
  179258. #ifndef PNG_NO_WRITE_FILTER
  179259. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179260. if (png_ptr->num_prev_filters > 0)
  179261. {
  179262. int j;
  179263. for (j = 1; j < num_p_filters; j++)
  179264. {
  179265. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  179266. }
  179267. png_ptr->prev_filters[j] = best_row[0];
  179268. }
  179269. #endif
  179270. #endif /* PNG_NO_WRITE_FILTER */
  179271. }
  179272. void /* PRIVATE */
  179273. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  179274. {
  179275. png_debug(1, "in png_write_filtered_row\n");
  179276. png_debug1(2, "filter = %d\n", filtered_row[0]);
  179277. png_ptr->zstream.next_in = filtered_row;
  179278. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  179279. do
  179280. {
  179281. int ret; /* return of zlib */
  179282. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  179283. if (ret != Z_OK)
  179284. {
  179285. if (png_ptr->zstream.msg != NULL)
  179286. png_error(png_ptr, png_ptr->zstream.msg);
  179287. else
  179288. png_error(png_ptr, "zlib error");
  179289. }
  179290. if (!(png_ptr->zstream.avail_out))
  179291. {
  179292. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179293. png_ptr->zstream.next_out = png_ptr->zbuf;
  179294. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179295. }
  179296. } while (png_ptr->zstream.avail_in);
  179297. if (png_ptr->prev_row != NULL)
  179298. {
  179299. png_bytep tptr;
  179300. tptr = png_ptr->prev_row;
  179301. png_ptr->prev_row = png_ptr->row_buf;
  179302. png_ptr->row_buf = tptr;
  179303. }
  179304. png_write_finish_row(png_ptr);
  179305. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179306. png_ptr->flush_rows++;
  179307. if (png_ptr->flush_dist > 0 &&
  179308. png_ptr->flush_rows >= png_ptr->flush_dist)
  179309. {
  179310. png_write_flush(png_ptr);
  179311. }
  179312. #endif
  179313. }
  179314. #endif /* PNG_WRITE_SUPPORTED */
  179315. /*** End of inlined file: pngwutil.c ***/
  179316. }
  179317. #else
  179318. #define PNG_INTERNAL
  179319. #define PNG_SETJMP_NOT_SUPPORTED
  179320. #include <png.h>
  179321. #include <pngconf.h>
  179322. #endif
  179323. }
  179324. #ifdef _MSC_VER
  179325. #pragma warning (pop)
  179326. #endif
  179327. BEGIN_JUCE_NAMESPACE
  179328. using namespace pnglibNamespace;
  179329. using ::calloc;
  179330. using ::malloc;
  179331. using ::free;
  179332. static void pngReadCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179333. {
  179334. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179335. in->read (data, (int) length);
  179336. }
  179337. struct PNGErrorStruct {};
  179338. static void pngErrorCallback (png_structp, png_const_charp)
  179339. {
  179340. throw PNGErrorStruct();
  179341. }
  179342. Image* juce_loadPNGImageFromStream (InputStream& in)
  179343. {
  179344. Image* image = 0;
  179345. png_structp pngReadStruct;
  179346. png_infop pngInfoStruct;
  179347. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179348. if (pngReadStruct != 0)
  179349. {
  179350. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179351. if (pngInfoStruct == 0)
  179352. {
  179353. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179354. return 0;
  179355. }
  179356. png_set_error_fn (pngReadStruct, 0, pngErrorCallback, pngErrorCallback);
  179357. // read the header..
  179358. png_set_read_fn (pngReadStruct, &in, pngReadCallback);
  179359. png_uint_32 width, height;
  179360. int bitDepth, colorType, interlaceType;
  179361. png_read_info (pngReadStruct, pngInfoStruct);
  179362. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179363. &width, &height,
  179364. &bitDepth, &colorType,
  179365. &interlaceType, 0, 0);
  179366. if (bitDepth == 16)
  179367. png_set_strip_16 (pngReadStruct);
  179368. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179369. png_set_expand (pngReadStruct);
  179370. if (bitDepth < 8)
  179371. png_set_expand (pngReadStruct);
  179372. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179373. png_set_expand (pngReadStruct);
  179374. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179375. png_set_gray_to_rgb (pngReadStruct);
  179376. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179377. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179378. || pngInfoStruct->num_trans > 0;
  179379. // Load the image into a temp buffer in the pnglib format..
  179380. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179381. {
  179382. HeapBlock <png_bytep> rows (height);
  179383. for (int y = (int) height; --y >= 0;)
  179384. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179385. png_read_image (pngReadStruct, rows);
  179386. png_read_end (pngReadStruct, pngInfoStruct);
  179387. }
  179388. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179389. // now convert the data to a juce image format..
  179390. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179391. (int) width, (int) height, hasAlphaChan);
  179392. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179393. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179394. uint8* srcRow = tempBuffer;
  179395. uint8* destRow = destData.data;
  179396. for (int y = 0; y < (int) height; ++y)
  179397. {
  179398. const uint8* src = srcRow;
  179399. srcRow += (width << 2);
  179400. uint8* dest = destRow;
  179401. destRow += destData.lineStride;
  179402. if (hasAlphaChan)
  179403. {
  179404. for (int i = (int) width; --i >= 0;)
  179405. {
  179406. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179407. ((PixelARGB*) dest)->premultiply();
  179408. dest += destData.pixelStride;
  179409. src += 4;
  179410. }
  179411. }
  179412. else
  179413. {
  179414. for (int i = (int) width; --i >= 0;)
  179415. {
  179416. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179417. dest += destData.pixelStride;
  179418. src += 4;
  179419. }
  179420. }
  179421. }
  179422. }
  179423. return image;
  179424. }
  179425. static void pngWriteDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179426. {
  179427. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179428. const bool ok = out->write (data, (int) length);
  179429. (void) ok;
  179430. jassert (ok);
  179431. }
  179432. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179433. {
  179434. const int width = image.getWidth();
  179435. const int height = image.getHeight();
  179436. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179437. if (pngWriteStruct == 0)
  179438. return false;
  179439. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179440. if (pngInfoStruct == 0)
  179441. {
  179442. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179443. return false;
  179444. }
  179445. png_set_write_fn (pngWriteStruct, &out, pngWriteDataCallback, 0);
  179446. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179447. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179448. : PNG_COLOR_TYPE_RGB,
  179449. PNG_INTERLACE_NONE,
  179450. PNG_COMPRESSION_TYPE_BASE,
  179451. PNG_FILTER_TYPE_BASE);
  179452. HeapBlock <png_byte> rowData (width * 4);
  179453. png_color_8 sig_bit;
  179454. sig_bit.red = 8;
  179455. sig_bit.green = 8;
  179456. sig_bit.blue = 8;
  179457. sig_bit.alpha = 8;
  179458. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179459. png_write_info (pngWriteStruct, pngInfoStruct);
  179460. png_set_shift (pngWriteStruct, &sig_bit);
  179461. png_set_packing (pngWriteStruct);
  179462. const Image::BitmapData srcData (image, 0, 0, width, height);
  179463. for (int y = 0; y < height; ++y)
  179464. {
  179465. uint8* dst = (uint8*) rowData;
  179466. const uint8* src = srcData.getLinePointer (y);
  179467. if (image.hasAlphaChannel())
  179468. {
  179469. for (int i = width; --i >= 0;)
  179470. {
  179471. PixelARGB p (*(const PixelARGB*) src);
  179472. p.unpremultiply();
  179473. *dst++ = p.getRed();
  179474. *dst++ = p.getGreen();
  179475. *dst++ = p.getBlue();
  179476. *dst++ = p.getAlpha();
  179477. src += srcData.pixelStride;
  179478. }
  179479. }
  179480. else
  179481. {
  179482. for (int i = width; --i >= 0;)
  179483. {
  179484. *dst++ = ((const PixelRGB*) src)->getRed();
  179485. *dst++ = ((const PixelRGB*) src)->getGreen();
  179486. *dst++ = ((const PixelRGB*) src)->getBlue();
  179487. src += srcData.pixelStride;
  179488. }
  179489. }
  179490. png_write_rows (pngWriteStruct, &rowData, 1);
  179491. }
  179492. png_write_end (pngWriteStruct, pngInfoStruct);
  179493. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179494. out.flush();
  179495. return true;
  179496. }
  179497. END_JUCE_NAMESPACE
  179498. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179499. #endif
  179500. //==============================================================================
  179501. #if JUCE_BUILD_NATIVE
  179502. #if JUCE_WINDOWS
  179503. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179504. BEGIN_JUCE_NAMESPACE
  179505. #define JUCE_INCLUDED_FILE 1
  179506. // Now include the actual code files..
  179507. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179508. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179509. // compiled on its own).
  179510. #if JUCE_INCLUDED_FILE
  179511. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179512. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179513. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179514. #ifndef DOXYGEN
  179515. // use with DynamicLibraryLoader to simplify importing functions
  179516. //
  179517. // functionName: function to import
  179518. // localFunctionName: name you want to use to actually call it (must be different)
  179519. // returnType: the return type
  179520. // object: the DynamicLibraryLoader to use
  179521. // params: list of params (bracketed)
  179522. //
  179523. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179524. typedef returnType (WINAPI *type##localFunctionName) params; \
  179525. type##localFunctionName localFunctionName \
  179526. = (type##localFunctionName)object.findProcAddress (#functionName);
  179527. // loads and unloads a DLL automatically
  179528. class JUCE_API DynamicLibraryLoader
  179529. {
  179530. public:
  179531. DynamicLibraryLoader (const String& name);
  179532. ~DynamicLibraryLoader();
  179533. void* findProcAddress (const String& functionName);
  179534. private:
  179535. void* libHandle;
  179536. };
  179537. #endif
  179538. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179539. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179540. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179541. {
  179542. libHandle = LoadLibrary (name);
  179543. }
  179544. DynamicLibraryLoader::~DynamicLibraryLoader()
  179545. {
  179546. FreeLibrary ((HMODULE) libHandle);
  179547. }
  179548. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179549. {
  179550. return (void*) GetProcAddress ((HMODULE) libHandle, functionName);
  179551. }
  179552. #endif
  179553. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179554. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179555. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179556. // compiled on its own).
  179557. #if JUCE_INCLUDED_FILE
  179558. extern void juce_initialiseThreadEvents();
  179559. void Logger::outputDebugString (const String& text) throw()
  179560. {
  179561. OutputDebugString (text + T("\n"));
  179562. }
  179563. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  179564. {
  179565. String text;
  179566. va_list args;
  179567. va_start (args, format);
  179568. text.vprintf(format, args);
  179569. outputDebugString (text);
  179570. }
  179571. static int64 hiResTicksPerSecond;
  179572. static double hiResTicksScaleFactor;
  179573. #if JUCE_USE_INTRINSICS
  179574. // CPU info functions using intrinsics...
  179575. #pragma intrinsic (__cpuid)
  179576. #pragma intrinsic (__rdtsc)
  179577. const String SystemStats::getCpuVendor() throw()
  179578. {
  179579. int info [4];
  179580. __cpuid (info, 0);
  179581. char v [12];
  179582. memcpy (v, info + 1, 4);
  179583. memcpy (v + 4, info + 3, 4);
  179584. memcpy (v + 8, info + 2, 4);
  179585. return String (v, 12);
  179586. }
  179587. #else
  179588. // CPU info functions using old fashioned inline asm...
  179589. static void juce_getCpuVendor (char* const v)
  179590. {
  179591. int vendor[4];
  179592. zeromem (vendor, 16);
  179593. #ifdef JUCE_64BIT
  179594. #else
  179595. #ifndef __MINGW32__
  179596. __try
  179597. #endif
  179598. {
  179599. #if JUCE_GCC
  179600. unsigned int dummy = 0;
  179601. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179602. #else
  179603. __asm
  179604. {
  179605. mov eax, 0
  179606. cpuid
  179607. mov [vendor], ebx
  179608. mov [vendor + 4], edx
  179609. mov [vendor + 8], ecx
  179610. }
  179611. #endif
  179612. }
  179613. #ifndef __MINGW32__
  179614. __except (EXCEPTION_EXECUTE_HANDLER)
  179615. {
  179616. *v = 0;
  179617. }
  179618. #endif
  179619. #endif
  179620. memcpy (v, vendor, 16);
  179621. }
  179622. const String SystemStats::getCpuVendor() throw()
  179623. {
  179624. char v [16];
  179625. juce_getCpuVendor (v);
  179626. return String (v, 16);
  179627. }
  179628. #endif
  179629. struct CPUFlags
  179630. {
  179631. bool hasMMX : 1;
  179632. bool hasSSE : 1;
  179633. bool hasSSE2 : 1;
  179634. bool has3DNow : 1;
  179635. };
  179636. static CPUFlags cpuFlags;
  179637. bool SystemStats::hasMMX() throw()
  179638. {
  179639. return cpuFlags.hasMMX;
  179640. }
  179641. bool SystemStats::hasSSE() throw()
  179642. {
  179643. return cpuFlags.hasSSE;
  179644. }
  179645. bool SystemStats::hasSSE2() throw()
  179646. {
  179647. return cpuFlags.hasSSE2;
  179648. }
  179649. bool SystemStats::has3DNow() throw()
  179650. {
  179651. return cpuFlags.has3DNow;
  179652. }
  179653. void SystemStats::initialiseStats() throw()
  179654. {
  179655. juce_initialiseThreadEvents();
  179656. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179657. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179658. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179659. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179660. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179661. #else
  179662. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179663. #endif
  179664. LARGE_INTEGER f;
  179665. QueryPerformanceFrequency (&f);
  179666. hiResTicksPerSecond = f.QuadPart;
  179667. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179668. String s (SystemStats::getJUCEVersion());
  179669. #ifdef JUCE_DEBUG
  179670. const MMRESULT res = timeBeginPeriod (1);
  179671. jassert (res == TIMERR_NOERROR);
  179672. #else
  179673. timeBeginPeriod (1);
  179674. #endif
  179675. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179676. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179677. #endif
  179678. }
  179679. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179680. {
  179681. OSVERSIONINFO info;
  179682. info.dwOSVersionInfoSize = sizeof (info);
  179683. GetVersionEx (&info);
  179684. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179685. {
  179686. switch (info.dwMajorVersion)
  179687. {
  179688. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179689. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179690. default: jassertfalse; break; // !! not a supported OS!
  179691. }
  179692. }
  179693. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179694. {
  179695. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179696. return Win98;
  179697. }
  179698. return UnknownOS;
  179699. }
  179700. const String SystemStats::getOperatingSystemName() throw()
  179701. {
  179702. const char* name = "Unknown OS";
  179703. switch (getOperatingSystemType())
  179704. {
  179705. case Windows7: name = "Windows 7"; break;
  179706. case WinVista: name = "Windows Vista"; break;
  179707. case WinXP: name = "Windows XP"; break;
  179708. case Win2000: name = "Windows 2000"; break;
  179709. case Win98: name = "Windows 98"; break;
  179710. default: jassertfalse; break; // !! new type of OS?
  179711. }
  179712. return name;
  179713. }
  179714. bool SystemStats::isOperatingSystem64Bit() throw()
  179715. {
  179716. #ifdef _WIN64
  179717. return true;
  179718. #else
  179719. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179720. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179721. BOOL isWow64 = FALSE;
  179722. return (fnIsWow64Process != 0)
  179723. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179724. && (isWow64 != FALSE);
  179725. #endif
  179726. }
  179727. int SystemStats::getMemorySizeInMegabytes() throw()
  179728. {
  179729. MEMORYSTATUSEX mem;
  179730. mem.dwLength = sizeof (mem);
  179731. GlobalMemoryStatusEx (&mem);
  179732. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179733. }
  179734. int SystemStats::getNumCpus() throw()
  179735. {
  179736. SYSTEM_INFO systemInfo;
  179737. GetSystemInfo (&systemInfo);
  179738. return systemInfo.dwNumberOfProcessors;
  179739. }
  179740. uint32 juce_millisecondsSinceStartup() throw()
  179741. {
  179742. return (uint32) GetTickCount();
  179743. }
  179744. int64 Time::getHighResolutionTicks() throw()
  179745. {
  179746. LARGE_INTEGER ticks;
  179747. QueryPerformanceCounter (&ticks);
  179748. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179749. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179750. // fix for a very obscure PCI hardware bug that can make the counter
  179751. // sometimes jump forwards by a few seconds..
  179752. static int64 hiResTicksOffset = 0;
  179753. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179754. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179755. hiResTicksOffset = newOffset;
  179756. return ticks.QuadPart + hiResTicksOffset;
  179757. }
  179758. double Time::getMillisecondCounterHiRes() throw()
  179759. {
  179760. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179761. }
  179762. int64 Time::getHighResolutionTicksPerSecond() throw()
  179763. {
  179764. return hiResTicksPerSecond;
  179765. }
  179766. int64 SystemStats::getClockCycleCounter() throw()
  179767. {
  179768. #if JUCE_USE_INTRINSICS
  179769. // MS intrinsics version...
  179770. return __rdtsc();
  179771. #elif JUCE_GCC
  179772. // GNU inline asm version...
  179773. unsigned int hi = 0, lo = 0;
  179774. __asm__ __volatile__ (
  179775. "xor %%eax, %%eax \n\
  179776. xor %%edx, %%edx \n\
  179777. rdtsc \n\
  179778. movl %%eax, %[lo] \n\
  179779. movl %%edx, %[hi]"
  179780. :
  179781. : [hi] "m" (hi),
  179782. [lo] "m" (lo)
  179783. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179784. return (int64) ((((uint64) hi) << 32) | lo);
  179785. #else
  179786. // MSVC inline asm version...
  179787. unsigned int hi = 0, lo = 0;
  179788. __asm
  179789. {
  179790. xor eax, eax
  179791. xor edx, edx
  179792. rdtsc
  179793. mov lo, eax
  179794. mov hi, edx
  179795. }
  179796. return (int64) ((((uint64) hi) << 32) | lo);
  179797. #endif
  179798. }
  179799. int SystemStats::getCpuSpeedInMegaherz() throw()
  179800. {
  179801. const int64 cycles = SystemStats::getClockCycleCounter();
  179802. const uint32 millis = Time::getMillisecondCounter();
  179803. int lastResult = 0;
  179804. for (;;)
  179805. {
  179806. int n = 1000000;
  179807. while (--n > 0) {}
  179808. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179809. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179810. if (millisElapsed > 80)
  179811. {
  179812. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179813. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179814. return newResult;
  179815. lastResult = newResult;
  179816. }
  179817. }
  179818. }
  179819. bool Time::setSystemTimeToThisTime() const throw()
  179820. {
  179821. SYSTEMTIME st;
  179822. st.wDayOfWeek = 0;
  179823. st.wYear = (WORD) getYear();
  179824. st.wMonth = (WORD) (getMonth() + 1);
  179825. st.wDay = (WORD) getDayOfMonth();
  179826. st.wHour = (WORD) getHours();
  179827. st.wMinute = (WORD) getMinutes();
  179828. st.wSecond = (WORD) getSeconds();
  179829. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179830. // do this twice because of daylight saving conversion problems - the
  179831. // first one sets it up, the second one kicks it in.
  179832. return SetLocalTime (&st) != 0
  179833. && SetLocalTime (&st) != 0;
  179834. }
  179835. int SystemStats::getPageSize() throw()
  179836. {
  179837. SYSTEM_INFO systemInfo;
  179838. GetSystemInfo (&systemInfo);
  179839. return systemInfo.dwPageSize;
  179840. }
  179841. const String SystemStats::getLogonName()
  179842. {
  179843. TCHAR text [256];
  179844. DWORD len = numElementsInArray (text) - 2;
  179845. zerostruct (text);
  179846. GetUserName (text, &len);
  179847. return String (text, len);
  179848. }
  179849. const String SystemStats::getFullUserName()
  179850. {
  179851. return getLogonName();
  179852. }
  179853. #endif
  179854. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179855. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179856. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179857. // compiled on its own).
  179858. #if JUCE_INCLUDED_FILE
  179859. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179860. extern HWND juce_messageWindowHandle;
  179861. #endif
  179862. #if ! JUCE_USE_INTRINSICS
  179863. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179864. // older ones we have to actually call the ops as win32 functions..
  179865. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179866. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179867. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179868. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179869. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179870. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179871. #endif
  179872. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179873. CriticalSection::CriticalSection() throw()
  179874. {
  179875. // (just to check the MS haven't changed this structure and broken things...)
  179876. #if _MSC_VER >= 1400
  179877. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179878. #else
  179879. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179880. #endif
  179881. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179882. }
  179883. CriticalSection::~CriticalSection() throw()
  179884. {
  179885. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179886. }
  179887. void CriticalSection::enter() const throw()
  179888. {
  179889. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179890. }
  179891. bool CriticalSection::tryEnter() const throw()
  179892. {
  179893. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179894. }
  179895. void CriticalSection::exit() const throw()
  179896. {
  179897. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179898. }
  179899. WaitableEvent::WaitableEvent() throw()
  179900. : internal (CreateEvent (0, FALSE, FALSE, 0))
  179901. {
  179902. }
  179903. WaitableEvent::~WaitableEvent() throw()
  179904. {
  179905. CloseHandle (internal);
  179906. }
  179907. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179908. {
  179909. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179910. }
  179911. void WaitableEvent::signal() const throw()
  179912. {
  179913. SetEvent (internal);
  179914. }
  179915. void WaitableEvent::reset() const throw()
  179916. {
  179917. ResetEvent (internal);
  179918. }
  179919. void JUCE_API juce_threadEntryPoint (void*);
  179920. static unsigned int __stdcall threadEntryProc (void* userData)
  179921. {
  179922. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179923. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179924. GetCurrentThreadId(), TRUE);
  179925. #endif
  179926. juce_threadEntryPoint (userData);
  179927. _endthreadex (0);
  179928. return 0;
  179929. }
  179930. void juce_CloseThreadHandle (void* handle)
  179931. {
  179932. CloseHandle ((HANDLE) handle);
  179933. }
  179934. void* juce_createThread (void* userData)
  179935. {
  179936. unsigned int threadId;
  179937. return (void*) _beginthreadex (0, 0,
  179938. &threadEntryProc,
  179939. userData,
  179940. 0, &threadId);
  179941. }
  179942. void juce_killThread (void* handle)
  179943. {
  179944. if (handle != 0)
  179945. {
  179946. #ifdef JUCE_DEBUG
  179947. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179948. #endif
  179949. TerminateThread (handle, 0);
  179950. }
  179951. }
  179952. void juce_setCurrentThreadName (const String& name)
  179953. {
  179954. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179955. struct
  179956. {
  179957. DWORD dwType;
  179958. LPCSTR szName;
  179959. DWORD dwThreadID;
  179960. DWORD dwFlags;
  179961. } info;
  179962. info.dwType = 0x1000;
  179963. info.szName = name;
  179964. info.dwThreadID = GetCurrentThreadId();
  179965. info.dwFlags = 0;
  179966. #define MS_VC_EXCEPTION 0x406d1388
  179967. __try
  179968. {
  179969. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179970. }
  179971. __except (EXCEPTION_CONTINUE_EXECUTION)
  179972. {}
  179973. #else
  179974. (void) name;
  179975. #endif
  179976. }
  179977. Thread::ThreadID Thread::getCurrentThreadId()
  179978. {
  179979. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179980. }
  179981. // priority 1 to 10 where 5=normal, 1=low
  179982. bool juce_setThreadPriority (void* threadHandle, int priority)
  179983. {
  179984. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179985. if (priority < 1)
  179986. pri = THREAD_PRIORITY_IDLE;
  179987. else if (priority < 2)
  179988. pri = THREAD_PRIORITY_LOWEST;
  179989. else if (priority < 5)
  179990. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179991. else if (priority < 7)
  179992. pri = THREAD_PRIORITY_NORMAL;
  179993. else if (priority < 9)
  179994. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179995. else if (priority < 10)
  179996. pri = THREAD_PRIORITY_HIGHEST;
  179997. if (threadHandle == 0)
  179998. threadHandle = GetCurrentThread();
  179999. return SetThreadPriority (threadHandle, pri) != FALSE;
  180000. }
  180001. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  180002. {
  180003. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  180004. }
  180005. static HANDLE sleepEvent = 0;
  180006. void juce_initialiseThreadEvents()
  180007. {
  180008. if (sleepEvent == 0)
  180009. #ifdef JUCE_DEBUG
  180010. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  180011. #else
  180012. sleepEvent = CreateEvent (0, 0, 0, 0);
  180013. #endif
  180014. }
  180015. void Thread::yield()
  180016. {
  180017. Sleep (0);
  180018. }
  180019. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  180020. {
  180021. if (millisecs >= 10)
  180022. {
  180023. Sleep (millisecs);
  180024. }
  180025. else
  180026. {
  180027. jassert (sleepEvent != 0);
  180028. // unlike Sleep() this is guaranteed to return to the current thread after
  180029. // the time expires, so we'll use this for short waits, which are more likely
  180030. // to need to be accurate
  180031. WaitForSingleObject (sleepEvent, millisecs);
  180032. }
  180033. }
  180034. static int lastProcessPriority = -1;
  180035. // called by WindowDriver because Windows does wierd things to process priority
  180036. // when you swap apps, and this forces an update when the app is brought to the front.
  180037. void juce_repeatLastProcessPriority()
  180038. {
  180039. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  180040. {
  180041. DWORD p;
  180042. switch (lastProcessPriority)
  180043. {
  180044. case Process::LowPriority:
  180045. p = IDLE_PRIORITY_CLASS;
  180046. break;
  180047. case Process::NormalPriority:
  180048. p = NORMAL_PRIORITY_CLASS;
  180049. break;
  180050. case Process::HighPriority:
  180051. p = HIGH_PRIORITY_CLASS;
  180052. break;
  180053. case Process::RealtimePriority:
  180054. p = REALTIME_PRIORITY_CLASS;
  180055. break;
  180056. default:
  180057. jassertfalse // bad priority value
  180058. return;
  180059. }
  180060. SetPriorityClass (GetCurrentProcess(), p);
  180061. }
  180062. }
  180063. void Process::setPriority (ProcessPriority prior)
  180064. {
  180065. if (lastProcessPriority != (int) prior)
  180066. {
  180067. lastProcessPriority = (int) prior;
  180068. juce_repeatLastProcessPriority();
  180069. }
  180070. }
  180071. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  180072. {
  180073. return IsDebuggerPresent() != FALSE;
  180074. }
  180075. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  180076. {
  180077. return juce_isRunningUnderDebugger();
  180078. }
  180079. void Process::raisePrivilege()
  180080. {
  180081. jassertfalse // xxx not implemented
  180082. }
  180083. void Process::lowerPrivilege()
  180084. {
  180085. jassertfalse // xxx not implemented
  180086. }
  180087. void Process::terminate()
  180088. {
  180089. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  180090. _CrtDumpMemoryLeaks();
  180091. #endif
  180092. // bullet in the head in case there's a problem shutting down..
  180093. ExitProcess (0);
  180094. }
  180095. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  180096. {
  180097. void* result = 0;
  180098. JUCE_TRY
  180099. {
  180100. result = (void*) LoadLibrary (name);
  180101. }
  180102. JUCE_CATCH_ALL
  180103. return result;
  180104. }
  180105. void PlatformUtilities::freeDynamicLibrary (void* h)
  180106. {
  180107. JUCE_TRY
  180108. {
  180109. if (h != 0)
  180110. FreeLibrary ((HMODULE) h);
  180111. }
  180112. JUCE_CATCH_ALL
  180113. }
  180114. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  180115. {
  180116. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name)
  180117. : 0;
  180118. }
  180119. InterProcessLock::InterProcessLock (const String& name_)
  180120. : internal (0),
  180121. name (name_),
  180122. reentrancyLevel (0)
  180123. {
  180124. }
  180125. InterProcessLock::~InterProcessLock()
  180126. {
  180127. exit();
  180128. }
  180129. bool InterProcessLock::enter (const int timeOutMillisecs)
  180130. {
  180131. if (reentrancyLevel++ == 0)
  180132. {
  180133. internal = CreateMutex (0, TRUE, "Global\\" + name);
  180134. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  180135. {
  180136. if (timeOutMillisecs == 0
  180137. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  180138. == WAIT_TIMEOUT)
  180139. {
  180140. ReleaseMutex (internal);
  180141. CloseHandle (internal);
  180142. internal = 0;
  180143. }
  180144. }
  180145. }
  180146. return (internal != 0);
  180147. }
  180148. void InterProcessLock::exit()
  180149. {
  180150. if (--reentrancyLevel == 0 && internal != 0)
  180151. {
  180152. ReleaseMutex (internal);
  180153. CloseHandle (internal);
  180154. internal = 0;
  180155. }
  180156. }
  180157. #endif
  180158. /*** End of inlined file: juce_win32_Threads.cpp ***/
  180159. /*** Start of inlined file: juce_win32_Files.cpp ***/
  180160. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180161. // compiled on its own).
  180162. #if JUCE_INCLUDED_FILE
  180163. #ifndef CSIDL_MYMUSIC
  180164. #define CSIDL_MYMUSIC 0x000d
  180165. #endif
  180166. #ifndef CSIDL_MYVIDEO
  180167. #define CSIDL_MYVIDEO 0x000e
  180168. #endif
  180169. const tchar File::separator = T('\\');
  180170. const tchar* File::separatorString = T("\\");
  180171. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  180172. {
  180173. if (fileName.isEmpty())
  180174. return false;
  180175. const DWORD attr = GetFileAttributes (fileName);
  180176. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  180177. : (attr != 0xffffffff);
  180178. }
  180179. bool juce_isDirectory (const String& fileName)
  180180. {
  180181. const DWORD attr = GetFileAttributes (fileName);
  180182. return (attr != 0xffffffff)
  180183. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180184. }
  180185. bool juce_canWriteToFile (const String& fileName)
  180186. {
  180187. const DWORD attr = GetFileAttributes (fileName);
  180188. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  180189. }
  180190. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  180191. {
  180192. DWORD attr = GetFileAttributes (fileName);
  180193. if (attr == 0xffffffff)
  180194. return false;
  180195. if (isReadOnly != juce_canWriteToFile (fileName))
  180196. return true;
  180197. if (isReadOnly)
  180198. attr |= FILE_ATTRIBUTE_READONLY;
  180199. else
  180200. attr &= ~FILE_ATTRIBUTE_READONLY;
  180201. return SetFileAttributes (fileName, attr) != FALSE;
  180202. }
  180203. bool File::isHidden() const
  180204. {
  180205. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  180206. }
  180207. bool juce_deleteFile (const String& fileName)
  180208. {
  180209. if (juce_isDirectory (fileName))
  180210. return RemoveDirectory (fileName) != 0;
  180211. return DeleteFile (fileName) != 0;
  180212. }
  180213. bool File::moveToTrash() const
  180214. {
  180215. if (! exists())
  180216. return true;
  180217. SHFILEOPSTRUCT fos;
  180218. zerostruct (fos);
  180219. // The string we pass in must be double null terminated..
  180220. String doubleNullTermPath (getFullPathName() + " ");
  180221. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  180222. p [getFullPathName().length()] = 0;
  180223. fos.wFunc = FO_DELETE;
  180224. fos.hwnd = (HWND) 0;
  180225. fos.pFrom = p;
  180226. fos.pTo = NULL;
  180227. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  180228. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  180229. return SHFileOperation (&fos) == 0;
  180230. }
  180231. bool juce_moveFile (const String& source, const String& dest)
  180232. {
  180233. return MoveFile (source, dest) != 0;
  180234. }
  180235. bool juce_copyFile (const String& source, const String& dest)
  180236. {
  180237. return CopyFile (source, dest, false) != 0;
  180238. }
  180239. void juce_createDirectory (const String& fileName)
  180240. {
  180241. if (! juce_fileExists (fileName, true))
  180242. {
  180243. CreateDirectory (fileName, 0);
  180244. }
  180245. }
  180246. // return 0 if not possible
  180247. void* juce_fileOpen (const String& fileName, bool forWriting)
  180248. {
  180249. HANDLE h;
  180250. if (forWriting)
  180251. {
  180252. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  180253. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  180254. if (h != INVALID_HANDLE_VALUE)
  180255. SetFilePointer (h, 0, 0, FILE_END);
  180256. else
  180257. h = 0;
  180258. }
  180259. else
  180260. {
  180261. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  180262. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  180263. if (h == INVALID_HANDLE_VALUE)
  180264. h = 0;
  180265. }
  180266. return (void*) h;
  180267. }
  180268. void juce_fileClose (void* handle)
  180269. {
  180270. CloseHandle (handle);
  180271. }
  180272. int juce_fileRead (void* handle, void* buffer, int size)
  180273. {
  180274. DWORD num = 0;
  180275. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  180276. return num;
  180277. }
  180278. int juce_fileWrite (void* handle, const void* buffer, int size)
  180279. {
  180280. DWORD num;
  180281. WriteFile ((HANDLE) handle,
  180282. buffer, size,
  180283. &num, 0);
  180284. return num;
  180285. }
  180286. int64 juce_fileSetPosition (void* handle, int64 pos)
  180287. {
  180288. LARGE_INTEGER li;
  180289. li.QuadPart = pos;
  180290. li.LowPart = SetFilePointer ((HANDLE) handle,
  180291. li.LowPart,
  180292. &li.HighPart,
  180293. FILE_BEGIN); // (returns -1 if it fails)
  180294. return li.QuadPart;
  180295. }
  180296. int64 juce_fileGetPosition (void* handle)
  180297. {
  180298. LARGE_INTEGER li;
  180299. li.QuadPart = 0;
  180300. li.LowPart = SetFilePointer ((HANDLE) handle,
  180301. 0, &li.HighPart,
  180302. FILE_CURRENT); // (returns -1 if it fails)
  180303. return jmax ((int64) 0, li.QuadPart);
  180304. }
  180305. void juce_fileFlush (void* handle)
  180306. {
  180307. FlushFileBuffers ((HANDLE) handle);
  180308. }
  180309. int64 juce_getFileSize (const String& fileName)
  180310. {
  180311. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180312. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180313. {
  180314. return (((int64) attributes.nFileSizeHigh) << 32)
  180315. | attributes.nFileSizeLow;
  180316. }
  180317. return 0;
  180318. }
  180319. static int64 fileTimeToTime (const FILETIME* const ft)
  180320. {
  180321. // tell me if this fails!
  180322. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180323. #if JUCE_GCC
  180324. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180325. #else
  180326. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180327. #endif
  180328. }
  180329. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180330. {
  180331. #if JUCE_GCC
  180332. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180333. #else
  180334. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180335. #endif
  180336. }
  180337. void juce_getFileTimes (const String& fileName,
  180338. int64& modificationTime,
  180339. int64& accessTime,
  180340. int64& creationTime)
  180341. {
  180342. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180343. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180344. {
  180345. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180346. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180347. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180348. }
  180349. else
  180350. {
  180351. creationTime = accessTime = modificationTime = 0;
  180352. }
  180353. }
  180354. bool juce_setFileTimes (const String& fileName,
  180355. int64 modificationTime,
  180356. int64 accessTime,
  180357. int64 creationTime)
  180358. {
  180359. FILETIME m, a, c;
  180360. if (modificationTime > 0)
  180361. timeToFileTime (modificationTime, &m);
  180362. if (accessTime > 0)
  180363. timeToFileTime (accessTime, &a);
  180364. if (creationTime > 0)
  180365. timeToFileTime (creationTime, &c);
  180366. void* const h = juce_fileOpen (fileName, true);
  180367. bool ok = false;
  180368. if (h != 0)
  180369. {
  180370. ok = SetFileTime ((HANDLE) h,
  180371. (creationTime > 0) ? &c : 0,
  180372. (accessTime > 0) ? &a : 0,
  180373. (modificationTime > 0) ? &m : 0) != 0;
  180374. juce_fileClose (h);
  180375. }
  180376. return ok;
  180377. }
  180378. // return '\0' separated list of strings
  180379. const StringArray juce_getFileSystemRoots()
  180380. {
  180381. TCHAR buffer [2048];
  180382. buffer[0] = 0;
  180383. buffer[1] = 0;
  180384. GetLogicalDriveStrings (2048, buffer);
  180385. TCHAR* n = buffer;
  180386. StringArray roots;
  180387. while (*n != 0)
  180388. {
  180389. roots.add (String (n));
  180390. while (*n++ != 0)
  180391. {
  180392. }
  180393. }
  180394. roots.sort (true);
  180395. return roots;
  180396. }
  180397. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180398. int& volumeSerialNumber)
  180399. {
  180400. TCHAR n [4];
  180401. n[0] = *(const TCHAR*) filenameOnVolume;
  180402. n[1] = L':';
  180403. n[2] = L'\\';
  180404. n[3] = 0;
  180405. TCHAR dest [64];
  180406. DWORD serialNum;
  180407. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180408. {
  180409. dest[0] = 0;
  180410. serialNum = 0;
  180411. }
  180412. volumeSerialNumber = serialNum;
  180413. return String (dest);
  180414. }
  180415. static int64 getDiskSpaceInfo (String fn, const bool total)
  180416. {
  180417. if (fn[1] == T(':'))
  180418. fn = fn.substring (0, 2) + T("\\");
  180419. ULARGE_INTEGER spc, tot, totFree;
  180420. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180421. return (int64) (total ? tot.QuadPart
  180422. : spc.QuadPart);
  180423. return 0;
  180424. }
  180425. int64 File::getBytesFreeOnVolume() const
  180426. {
  180427. return getDiskSpaceInfo (getFullPathName(), false);
  180428. }
  180429. int64 File::getVolumeTotalSize() const
  180430. {
  180431. return getDiskSpaceInfo (getFullPathName(), true);
  180432. }
  180433. static unsigned int getWindowsDriveType (const String& fileName)
  180434. {
  180435. TCHAR n[4];
  180436. n[0] = *(const TCHAR*) fileName;
  180437. n[1] = L':';
  180438. n[2] = L'\\';
  180439. n[3] = 0;
  180440. return GetDriveType (n);
  180441. }
  180442. bool File::isOnCDRomDrive() const
  180443. {
  180444. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180445. }
  180446. bool File::isOnHardDisk() const
  180447. {
  180448. if (fullPath.isEmpty())
  180449. return false;
  180450. const unsigned int n = getWindowsDriveType (getFullPathName());
  180451. if (fullPath.toLowerCase()[0] <= 'b'
  180452. && fullPath[1] == T(':'))
  180453. {
  180454. return n != DRIVE_REMOVABLE;
  180455. }
  180456. else
  180457. {
  180458. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180459. }
  180460. }
  180461. bool File::isOnRemovableDrive() const
  180462. {
  180463. if (fullPath.isEmpty())
  180464. return false;
  180465. const unsigned int n = getWindowsDriveType (getFullPathName());
  180466. return n == DRIVE_CDROM
  180467. || n == DRIVE_REMOTE
  180468. || n == DRIVE_REMOVABLE
  180469. || n == DRIVE_RAMDISK;
  180470. }
  180471. #define MAX_PATH_CHARS (MAX_PATH + 256)
  180472. static const File juce_getSpecialFolderPath (int type)
  180473. {
  180474. WCHAR path [MAX_PATH_CHARS];
  180475. if (SHGetSpecialFolderPath (0, path, type, 0))
  180476. return File (String (path));
  180477. return File::nonexistent;
  180478. }
  180479. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180480. {
  180481. int csidlType = 0;
  180482. switch (type)
  180483. {
  180484. case userHomeDirectory:
  180485. csidlType = CSIDL_PROFILE;
  180486. break;
  180487. case userDocumentsDirectory:
  180488. csidlType = CSIDL_PERSONAL;
  180489. break;
  180490. case userDesktopDirectory:
  180491. csidlType = CSIDL_DESKTOP;
  180492. break;
  180493. case userApplicationDataDirectory:
  180494. csidlType = CSIDL_APPDATA;
  180495. break;
  180496. case commonApplicationDataDirectory:
  180497. csidlType = CSIDL_COMMON_APPDATA;
  180498. break;
  180499. case globalApplicationsDirectory:
  180500. csidlType = CSIDL_PROGRAM_FILES;
  180501. break;
  180502. case userMusicDirectory:
  180503. csidlType = CSIDL_MYMUSIC;
  180504. break;
  180505. case userMoviesDirectory:
  180506. csidlType = CSIDL_MYVIDEO;
  180507. break;
  180508. case tempDirectory:
  180509. {
  180510. WCHAR dest [2048];
  180511. dest[0] = 0;
  180512. GetTempPath (2048, dest);
  180513. return File (String (dest));
  180514. }
  180515. case invokedExecutableFile:
  180516. case currentExecutableFile:
  180517. case currentApplicationFile:
  180518. {
  180519. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180520. WCHAR dest [MAX_PATH_CHARS];
  180521. dest[0] = 0;
  180522. GetModuleFileName (moduleHandle, dest, MAX_PATH_CHARS);
  180523. return File (String (dest));
  180524. }
  180525. break;
  180526. default:
  180527. jassertfalse // unknown type?
  180528. return File::nonexistent;
  180529. }
  180530. return juce_getSpecialFolderPath (csidlType);
  180531. }
  180532. const File File::getCurrentWorkingDirectory()
  180533. {
  180534. WCHAR dest [MAX_PATH_CHARS];
  180535. dest[0] = 0;
  180536. GetCurrentDirectory (MAX_PATH_CHARS, dest);
  180537. return File (String (dest));
  180538. }
  180539. bool File::setAsCurrentWorkingDirectory() const
  180540. {
  180541. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180542. }
  180543. const String File::getVersion() const
  180544. {
  180545. String result;
  180546. DWORD handle = 0;
  180547. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180548. HeapBlock <char> buffer;
  180549. buffer.calloc (bufferSize);
  180550. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180551. {
  180552. VS_FIXEDFILEINFO* vffi;
  180553. UINT len = 0;
  180554. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180555. {
  180556. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180557. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180558. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180559. << (int) LOWORD (vffi->dwFileVersionLS);
  180560. }
  180561. }
  180562. return result;
  180563. }
  180564. const File File::getLinkedTarget() const
  180565. {
  180566. File result (*this);
  180567. String p (getFullPathName());
  180568. if (! exists())
  180569. p += T(".lnk");
  180570. else if (getFileExtension() != T(".lnk"))
  180571. return result;
  180572. ComSmartPtr <IShellLink> shellLink;
  180573. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180574. {
  180575. ComSmartPtr <IPersistFile> persistFile;
  180576. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180577. {
  180578. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180579. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180580. {
  180581. WIN32_FIND_DATA winFindData;
  180582. WCHAR resolvedPath [MAX_PATH];
  180583. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180584. result = File (resolvedPath);
  180585. }
  180586. }
  180587. }
  180588. return result;
  180589. }
  180590. template <class FindDataType>
  180591. static void getFindFileInfo (FindDataType& findData,
  180592. String& filename, bool* const isDir, bool* const isHidden,
  180593. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180594. bool* const isReadOnly)
  180595. {
  180596. filename = findData.cFileName;
  180597. if (isDir != 0)
  180598. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180599. if (isHidden != 0)
  180600. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180601. if (fileSize != 0)
  180602. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180603. if (modTime != 0)
  180604. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180605. if (creationTime != 0)
  180606. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180607. if (isReadOnly != 0)
  180608. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180609. }
  180610. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180611. bool* isDir, bool* isHidden, int64* fileSize,
  180612. Time* modTime, Time* creationTime, bool* isReadOnly)
  180613. {
  180614. String wc (directory);
  180615. if (! wc.endsWithChar (File::separator))
  180616. wc += File::separator;
  180617. wc += wildCard;
  180618. WIN32_FIND_DATA findData;
  180619. HANDLE h = FindFirstFile (wc, &findData);
  180620. if (h != INVALID_HANDLE_VALUE)
  180621. {
  180622. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180623. modTime, creationTime, isReadOnly);
  180624. return h;
  180625. }
  180626. firstResult = String::empty;
  180627. return 0;
  180628. }
  180629. bool juce_findFileNext (void* handle, String& resultFile,
  180630. bool* isDir, bool* isHidden, int64* fileSize,
  180631. Time* modTime, Time* creationTime, bool* isReadOnly)
  180632. {
  180633. WIN32_FIND_DATA findData;
  180634. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180635. {
  180636. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180637. modTime, creationTime, isReadOnly);
  180638. return true;
  180639. }
  180640. resultFile = String::empty;
  180641. return false;
  180642. }
  180643. void juce_findFileClose (void* handle)
  180644. {
  180645. FindClose (handle);
  180646. }
  180647. bool juce_launchFile (const String& fileName,
  180648. const String& parameters)
  180649. {
  180650. HINSTANCE hInstance = 0;
  180651. JUCE_TRY
  180652. {
  180653. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180654. }
  180655. JUCE_CATCH_ALL
  180656. return hInstance > (HINSTANCE) 32;
  180657. }
  180658. void File::revealToUser() const
  180659. {
  180660. if (isDirectory())
  180661. startAsProcess();
  180662. else if (getParentDirectory().exists())
  180663. getParentDirectory().startAsProcess();
  180664. }
  180665. struct NamedPipeInternal
  180666. {
  180667. HANDLE pipeH;
  180668. HANDLE cancelEvent;
  180669. bool connected, createdPipe;
  180670. NamedPipeInternal()
  180671. : pipeH (0),
  180672. cancelEvent (0),
  180673. connected (false),
  180674. createdPipe (false)
  180675. {
  180676. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180677. }
  180678. ~NamedPipeInternal()
  180679. {
  180680. disconnect();
  180681. if (pipeH != 0)
  180682. CloseHandle (pipeH);
  180683. CloseHandle (cancelEvent);
  180684. }
  180685. bool connect (const int timeOutMs)
  180686. {
  180687. if (! createdPipe)
  180688. return true;
  180689. if (! connected)
  180690. {
  180691. OVERLAPPED over;
  180692. zerostruct (over);
  180693. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180694. if (ConnectNamedPipe (pipeH, &over))
  180695. {
  180696. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180697. }
  180698. else
  180699. {
  180700. const int err = GetLastError();
  180701. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180702. {
  180703. HANDLE handles[] = { over.hEvent, cancelEvent };
  180704. if (WaitForMultipleObjects (2, handles, FALSE,
  180705. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180706. connected = true;
  180707. }
  180708. else if (err == ERROR_PIPE_CONNECTED)
  180709. {
  180710. connected = true;
  180711. }
  180712. }
  180713. CloseHandle (over.hEvent);
  180714. }
  180715. return connected;
  180716. }
  180717. void disconnect()
  180718. {
  180719. if (connected)
  180720. {
  180721. DisconnectNamedPipe (pipeH);
  180722. connected = false;
  180723. }
  180724. }
  180725. };
  180726. void NamedPipe::close()
  180727. {
  180728. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180729. delete intern;
  180730. internal = 0;
  180731. }
  180732. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180733. {
  180734. close();
  180735. NamedPipeInternal* const intern = new NamedPipeInternal();
  180736. String file ("\\\\.\\pipe\\");
  180737. file += pipeName;
  180738. intern->createdPipe = createPipe;
  180739. if (createPipe)
  180740. {
  180741. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180742. PIPE_UNLIMITED_INSTANCES,
  180743. 4096, 4096, 0, NULL);
  180744. }
  180745. else
  180746. {
  180747. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  180748. FILE_FLAG_OVERLAPPED, 0);
  180749. }
  180750. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180751. {
  180752. internal = intern;
  180753. return true;
  180754. }
  180755. delete intern;
  180756. return false;
  180757. }
  180758. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180759. {
  180760. int bytesRead = -1;
  180761. bool waitAgain = true;
  180762. while (waitAgain && internal != 0)
  180763. {
  180764. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180765. waitAgain = false;
  180766. if (! intern->connect (timeOutMilliseconds))
  180767. break;
  180768. if (maxBytesToRead <= 0)
  180769. return 0;
  180770. OVERLAPPED over;
  180771. zerostruct (over);
  180772. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180773. unsigned long numRead;
  180774. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180775. {
  180776. bytesRead = (int) numRead;
  180777. }
  180778. else if (GetLastError() == ERROR_IO_PENDING)
  180779. {
  180780. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180781. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180782. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180783. : INFINITE);
  180784. if (waitResult != WAIT_OBJECT_0)
  180785. {
  180786. // if the operation timed out, let's cancel it...
  180787. CancelIo (intern->pipeH);
  180788. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180789. }
  180790. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180791. {
  180792. bytesRead = (int) numRead;
  180793. }
  180794. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180795. {
  180796. intern->disconnect();
  180797. waitAgain = true;
  180798. }
  180799. }
  180800. else
  180801. {
  180802. waitAgain = internal != 0;
  180803. Sleep (5);
  180804. }
  180805. CloseHandle (over.hEvent);
  180806. }
  180807. return bytesRead;
  180808. }
  180809. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180810. {
  180811. int bytesWritten = -1;
  180812. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180813. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180814. {
  180815. if (numBytesToWrite <= 0)
  180816. return 0;
  180817. OVERLAPPED over;
  180818. zerostruct (over);
  180819. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180820. unsigned long numWritten;
  180821. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180822. {
  180823. bytesWritten = (int) numWritten;
  180824. }
  180825. else if (GetLastError() == ERROR_IO_PENDING)
  180826. {
  180827. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180828. DWORD waitResult;
  180829. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180830. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180831. : INFINITE);
  180832. if (waitResult != WAIT_OBJECT_0)
  180833. {
  180834. CancelIo (intern->pipeH);
  180835. WaitForSingleObject (over.hEvent, INFINITE);
  180836. }
  180837. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180838. {
  180839. bytesWritten = (int) numWritten;
  180840. }
  180841. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180842. {
  180843. intern->disconnect();
  180844. }
  180845. }
  180846. CloseHandle (over.hEvent);
  180847. }
  180848. return bytesWritten;
  180849. }
  180850. void NamedPipe::cancelPendingReads()
  180851. {
  180852. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180853. if (intern != 0)
  180854. SetEvent (intern->cancelEvent);
  180855. }
  180856. #endif
  180857. /*** End of inlined file: juce_win32_Files.cpp ***/
  180858. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180859. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180860. // compiled on its own).
  180861. #if JUCE_INCLUDED_FILE
  180862. #ifndef INTERNET_FLAG_NEED_FILE
  180863. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180864. #endif
  180865. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180866. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180867. #endif
  180868. bool juce_isOnLine()
  180869. {
  180870. DWORD connectionType;
  180871. return InternetGetConnectedState (&connectionType, 0) != 0
  180872. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180873. }
  180874. struct ConnectionAndRequestStruct
  180875. {
  180876. HINTERNET connection, request;
  180877. };
  180878. static HINTERNET sessionHandle = 0;
  180879. #ifndef WORKAROUND_TIMEOUT_BUG
  180880. //#define WORKAROUND_TIMEOUT_BUG 1
  180881. #endif
  180882. #if WORKAROUND_TIMEOUT_BUG
  180883. // Required because of a Microsoft bug in setting a timeout
  180884. class InternetConnectThread : public Thread
  180885. {
  180886. public:
  180887. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180888. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180889. {
  180890. startThread();
  180891. }
  180892. ~InternetConnectThread()
  180893. {
  180894. stopThread (60000);
  180895. }
  180896. void run()
  180897. {
  180898. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180899. uc.nPort, _T(""), _T(""),
  180900. isFtp ? INTERNET_SERVICE_FTP
  180901. : INTERNET_SERVICE_HTTP,
  180902. 0, 0);
  180903. notify();
  180904. }
  180905. juce_UseDebuggingNewOperator
  180906. private:
  180907. URL_COMPONENTS& uc;
  180908. HINTERNET& connection;
  180909. const bool isFtp;
  180910. InternetConnectThread (const InternetConnectThread&);
  180911. InternetConnectThread& operator= (const InternetConnectThread&);
  180912. };
  180913. #endif
  180914. void* juce_openInternetFile (const String& url,
  180915. const String& headers,
  180916. const MemoryBlock& postData,
  180917. const bool isPost,
  180918. URL::OpenStreamProgressCallback* callback,
  180919. void* callbackContext,
  180920. int timeOutMs)
  180921. {
  180922. if (sessionHandle == 0)
  180923. sessionHandle = InternetOpen (_T("juce"),
  180924. INTERNET_OPEN_TYPE_PRECONFIG,
  180925. 0, 0, 0);
  180926. if (sessionHandle != 0)
  180927. {
  180928. // break up the url..
  180929. TCHAR file[1024], server[1024];
  180930. URL_COMPONENTS uc;
  180931. zerostruct (uc);
  180932. uc.dwStructSize = sizeof (uc);
  180933. uc.dwUrlPathLength = sizeof (file);
  180934. uc.dwHostNameLength = sizeof (server);
  180935. uc.lpszUrlPath = file;
  180936. uc.lpszHostName = server;
  180937. if (InternetCrackUrl (url, 0, 0, &uc))
  180938. {
  180939. int disable = 1;
  180940. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180941. if (timeOutMs == 0)
  180942. timeOutMs = 30000;
  180943. else if (timeOutMs < 0)
  180944. timeOutMs = -1;
  180945. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180946. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  180947. #if WORKAROUND_TIMEOUT_BUG
  180948. HINTERNET connection = 0;
  180949. {
  180950. InternetConnectThread connectThread (uc, connection, isFtp);
  180951. connectThread.wait (timeOutMs);
  180952. if (connection == 0)
  180953. {
  180954. InternetCloseHandle (sessionHandle);
  180955. sessionHandle = 0;
  180956. }
  180957. }
  180958. #else
  180959. HINTERNET connection = InternetConnect (sessionHandle,
  180960. uc.lpszHostName,
  180961. uc.nPort,
  180962. _T(""), _T(""),
  180963. isFtp ? INTERNET_SERVICE_FTP
  180964. : INTERNET_SERVICE_HTTP,
  180965. 0, 0);
  180966. #endif
  180967. if (connection != 0)
  180968. {
  180969. if (isFtp)
  180970. {
  180971. HINTERNET request = FtpOpenFile (connection,
  180972. uc.lpszUrlPath,
  180973. GENERIC_READ,
  180974. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180975. 0);
  180976. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180977. result->connection = connection;
  180978. result->request = request;
  180979. return result;
  180980. }
  180981. else
  180982. {
  180983. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180984. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180985. if (url.startsWithIgnoreCase (T("https:")))
  180986. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180987. // IE7 seems to automatically work out when it's https)
  180988. HINTERNET request = HttpOpenRequest (connection,
  180989. isPost ? _T("POST")
  180990. : _T("GET"),
  180991. uc.lpszUrlPath,
  180992. 0, 0, mimeTypes, flags, 0);
  180993. if (request != 0)
  180994. {
  180995. INTERNET_BUFFERS buffers;
  180996. zerostruct (buffers);
  180997. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180998. buffers.lpcszHeader = (LPCTSTR) headers;
  180999. buffers.dwHeadersLength = headers.length();
  181000. buffers.dwBufferTotal = (DWORD) postData.getSize();
  181001. ConnectionAndRequestStruct* result = 0;
  181002. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  181003. {
  181004. int bytesSent = 0;
  181005. for (;;)
  181006. {
  181007. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  181008. DWORD bytesDone = 0;
  181009. if (bytesToDo > 0
  181010. && ! InternetWriteFile (request,
  181011. ((const char*) postData.getData()) + bytesSent,
  181012. bytesToDo, &bytesDone))
  181013. {
  181014. break;
  181015. }
  181016. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  181017. {
  181018. result = new ConnectionAndRequestStruct();
  181019. result->connection = connection;
  181020. result->request = request;
  181021. HttpEndRequest (request, 0, 0, 0);
  181022. return result;
  181023. }
  181024. bytesSent += bytesDone;
  181025. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  181026. break;
  181027. }
  181028. }
  181029. InternetCloseHandle (request);
  181030. }
  181031. InternetCloseHandle (connection);
  181032. }
  181033. }
  181034. }
  181035. }
  181036. return 0;
  181037. }
  181038. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  181039. {
  181040. DWORD bytesRead = 0;
  181041. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181042. if (crs != 0)
  181043. InternetReadFile (crs->request,
  181044. buffer, bytesToRead,
  181045. &bytesRead);
  181046. return bytesRead;
  181047. }
  181048. int juce_seekInInternetFile (void* handle, int newPosition)
  181049. {
  181050. if (handle != 0)
  181051. {
  181052. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181053. return InternetSetFilePointer (crs->request,
  181054. newPosition, 0,
  181055. FILE_BEGIN, 0);
  181056. }
  181057. else
  181058. {
  181059. return -1;
  181060. }
  181061. }
  181062. int64 juce_getInternetFileContentLength (void* handle)
  181063. {
  181064. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181065. if (crs != 0)
  181066. {
  181067. DWORD index = 0;
  181068. DWORD result = 0;
  181069. DWORD size = sizeof (result);
  181070. if (HttpQueryInfo (crs->request,
  181071. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  181072. &result,
  181073. &size,
  181074. &index))
  181075. {
  181076. return (int64) result;
  181077. }
  181078. }
  181079. return -1;
  181080. }
  181081. void juce_closeInternetFile (void* handle)
  181082. {
  181083. if (handle != 0)
  181084. {
  181085. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  181086. InternetCloseHandle (crs->request);
  181087. InternetCloseHandle (crs->connection);
  181088. delete crs;
  181089. }
  181090. }
  181091. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  181092. {
  181093. int numFound = 0;
  181094. DynamicLibraryLoader dll ("iphlpapi.dll");
  181095. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  181096. if (getAdaptersInfo != 0)
  181097. {
  181098. ULONG len = sizeof (IP_ADAPTER_INFO);
  181099. MemoryBlock mb;
  181100. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181101. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  181102. {
  181103. mb.setSize (len);
  181104. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181105. }
  181106. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  181107. {
  181108. PIP_ADAPTER_INFO adapter = adapterInfo;
  181109. while (adapter != 0)
  181110. {
  181111. int64 mac = 0;
  181112. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  181113. mac = (mac << 8) | adapter->Address[i];
  181114. if (littleEndian)
  181115. mac = (int64) ByteOrder::swap ((uint64) mac);
  181116. if (numFound < maxNum && mac != 0)
  181117. addresses [numFound++] = mac;
  181118. adapter = adapter->Next;
  181119. }
  181120. }
  181121. }
  181122. return numFound;
  181123. }
  181124. struct ASTAT
  181125. {
  181126. ADAPTER_STATUS adapt;
  181127. NAME_BUFFER NameBuff [30];
  181128. };
  181129. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  181130. {
  181131. int numFound = 0;
  181132. DynamicLibraryLoader dll ("netapi32.dll");
  181133. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  181134. if (NetbiosCall != 0)
  181135. {
  181136. NCB ncb;
  181137. zerostruct (ncb);
  181138. ASTAT astat;
  181139. zerostruct (astat);
  181140. LANA_ENUM enums;
  181141. zerostruct (enums);
  181142. ncb.ncb_command = NCBENUM;
  181143. ncb.ncb_buffer = (unsigned char*) &enums;
  181144. ncb.ncb_length = sizeof (LANA_ENUM);
  181145. NetbiosCall (&ncb);
  181146. for (int i = 0; i < enums.length; ++i)
  181147. {
  181148. zerostruct (ncb);
  181149. ncb.ncb_command = NCBRESET;
  181150. ncb.ncb_lana_num = enums.lana[i];
  181151. if (NetbiosCall (&ncb) == 0)
  181152. {
  181153. zerostruct (ncb);
  181154. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  181155. ncb.ncb_command = NCBASTAT;
  181156. ncb.ncb_lana_num = enums.lana[i];
  181157. ncb.ncb_buffer = (unsigned char*) &astat;
  181158. ncb.ncb_length = sizeof (ASTAT);
  181159. if (NetbiosCall (&ncb) == 0)
  181160. {
  181161. if (astat.adapt.adapter_type == 0xfe)
  181162. {
  181163. uint64 mac = 0;
  181164. for (int i = 6; --i >= 0;)
  181165. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  181166. if (numFound < maxNum && mac != 0)
  181167. addresses [numFound++] = mac;
  181168. }
  181169. }
  181170. }
  181171. }
  181172. }
  181173. return numFound;
  181174. }
  181175. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  181176. {
  181177. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  181178. if (numFound == 0)
  181179. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  181180. return numFound;
  181181. }
  181182. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  181183. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  181184. const String& emailSubject,
  181185. const String& bodyText,
  181186. const StringArray& filesToAttach)
  181187. {
  181188. HMODULE h = LoadLibraryA ("MAPI32.dll");
  181189. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  181190. bool ok = false;
  181191. if (mapiSendMail != 0)
  181192. {
  181193. MapiMessage message;
  181194. zerostruct (message);
  181195. message.lpszSubject = (LPSTR) (LPCSTR) emailSubject;
  181196. message.lpszNoteText = (LPSTR) (LPCSTR) bodyText;
  181197. MapiRecipDesc recip;
  181198. zerostruct (recip);
  181199. recip.ulRecipClass = MAPI_TO;
  181200. String targetEmailAddress_ (targetEmailAddress);
  181201. if (targetEmailAddress_.isEmpty())
  181202. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  181203. recip.lpszName = (LPSTR) (LPCSTR) targetEmailAddress_;
  181204. message.nRecipCount = 1;
  181205. message.lpRecips = &recip;
  181206. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  181207. mb.fillWith (0);
  181208. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  181209. message.nFileCount = filesToAttach.size();
  181210. message.lpFiles = files;
  181211. for (int i = 0; i < filesToAttach.size(); ++i)
  181212. {
  181213. files[i].nPosition = (ULONG) -1;
  181214. files[i].lpszPathName = (LPSTR) (LPCSTR) filesToAttach [i];
  181215. }
  181216. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  181217. }
  181218. FreeLibrary (h);
  181219. return ok;
  181220. }
  181221. #endif
  181222. /*** End of inlined file: juce_win32_Network.cpp ***/
  181223. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  181224. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181225. // compiled on its own).
  181226. #if JUCE_INCLUDED_FILE
  181227. static HKEY findKeyForPath (String name,
  181228. const bool createForWriting,
  181229. String& valueName)
  181230. {
  181231. HKEY rootKey = 0;
  181232. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  181233. rootKey = HKEY_CURRENT_USER;
  181234. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  181235. rootKey = HKEY_LOCAL_MACHINE;
  181236. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  181237. rootKey = HKEY_CLASSES_ROOT;
  181238. if (rootKey != 0)
  181239. {
  181240. name = name.substring (name.indexOfChar (T('\\')) + 1);
  181241. const int lastSlash = name.lastIndexOfChar (T('\\'));
  181242. valueName = name.substring (lastSlash + 1);
  181243. name = name.substring (0, lastSlash);
  181244. HKEY key;
  181245. DWORD result;
  181246. if (createForWriting)
  181247. {
  181248. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  181249. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  181250. return key;
  181251. }
  181252. else
  181253. {
  181254. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  181255. return key;
  181256. }
  181257. }
  181258. return 0;
  181259. }
  181260. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  181261. const String& defaultValue)
  181262. {
  181263. String valueName, result (defaultValue);
  181264. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181265. if (k != 0)
  181266. {
  181267. WCHAR buffer [2048];
  181268. unsigned long bufferSize = sizeof (buffer);
  181269. DWORD type = REG_SZ;
  181270. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  181271. {
  181272. if (type == REG_SZ)
  181273. result = buffer;
  181274. else if (type == REG_DWORD)
  181275. result = String ((int) *(DWORD*) buffer);
  181276. }
  181277. RegCloseKey (k);
  181278. }
  181279. return result;
  181280. }
  181281. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  181282. const String& value)
  181283. {
  181284. String valueName;
  181285. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181286. if (k != 0)
  181287. {
  181288. RegSetValueEx (k, valueName, 0, REG_SZ,
  181289. (const BYTE*) (const WCHAR*) value,
  181290. sizeof (WCHAR) * (value.length() + 1));
  181291. RegCloseKey (k);
  181292. }
  181293. }
  181294. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181295. {
  181296. bool exists = false;
  181297. String valueName;
  181298. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181299. if (k != 0)
  181300. {
  181301. unsigned char buffer [2048];
  181302. unsigned long bufferSize = sizeof (buffer);
  181303. DWORD type = 0;
  181304. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181305. exists = true;
  181306. RegCloseKey (k);
  181307. }
  181308. return exists;
  181309. }
  181310. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181311. {
  181312. String valueName;
  181313. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181314. if (k != 0)
  181315. {
  181316. RegDeleteValue (k, valueName);
  181317. RegCloseKey (k);
  181318. }
  181319. }
  181320. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181321. {
  181322. String valueName;
  181323. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181324. if (k != 0)
  181325. {
  181326. RegDeleteKey (k, valueName);
  181327. RegCloseKey (k);
  181328. }
  181329. }
  181330. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181331. const String& symbolicDescription,
  181332. const String& fullDescription,
  181333. const File& targetExecutable,
  181334. int iconResourceNumber)
  181335. {
  181336. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181337. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181338. if (iconResourceNumber != 0)
  181339. setRegistryValue (key + "\\DefaultIcon\\",
  181340. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181341. setRegistryValue (key + "\\", fullDescription);
  181342. setRegistryValue (key + "\\shell\\open\\command\\",
  181343. targetExecutable.getFullPathName() + " %1");
  181344. }
  181345. bool juce_IsRunningInWine()
  181346. {
  181347. HKEY key;
  181348. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181349. {
  181350. RegCloseKey (key);
  181351. return true;
  181352. }
  181353. return false;
  181354. }
  181355. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181356. {
  181357. String s (::GetCommandLineW());
  181358. StringArray tokens;
  181359. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181360. return tokens.joinIntoString (T(" "), 1);
  181361. }
  181362. static void* currentModuleHandle = 0;
  181363. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181364. {
  181365. if (currentModuleHandle == 0)
  181366. currentModuleHandle = GetModuleHandle (0);
  181367. return currentModuleHandle;
  181368. }
  181369. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181370. {
  181371. currentModuleHandle = newHandle;
  181372. }
  181373. void PlatformUtilities::fpuReset()
  181374. {
  181375. #if JUCE_MSVC
  181376. _clearfp();
  181377. #endif
  181378. }
  181379. void PlatformUtilities::beep()
  181380. {
  181381. MessageBeep (MB_OK);
  181382. }
  181383. #endif
  181384. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181385. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181386. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181387. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181388. // compiled on its own).
  181389. #if JUCE_INCLUDED_FILE
  181390. static const unsigned int specialId = WM_APP + 0x4400;
  181391. static const unsigned int broadcastId = WM_APP + 0x4403;
  181392. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181393. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181394. HWND juce_messageWindowHandle = 0;
  181395. extern long improbableWindowNumber; // defined in windowing.cpp
  181396. #ifndef WM_APPCOMMAND
  181397. #define WM_APPCOMMAND 0x0319
  181398. #endif
  181399. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181400. const UINT message,
  181401. const WPARAM wParam,
  181402. const LPARAM lParam) throw()
  181403. {
  181404. JUCE_TRY
  181405. {
  181406. if (h == juce_messageWindowHandle)
  181407. {
  181408. if (message == specialCallbackId)
  181409. {
  181410. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181411. return (LRESULT) (*func) ((void*) lParam);
  181412. }
  181413. else if (message == specialId)
  181414. {
  181415. // these are trapped early in the dispatch call, but must also be checked
  181416. // here in case there are windows modal dialog boxes doing their own
  181417. // dispatch loop and not calling our version
  181418. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181419. return 0;
  181420. }
  181421. else if (message == broadcastId)
  181422. {
  181423. const ScopedPointer <String> messageString ((String*) lParam);
  181424. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181425. return 0;
  181426. }
  181427. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181428. {
  181429. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181430. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181431. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181432. return 0;
  181433. }
  181434. }
  181435. }
  181436. JUCE_CATCH_EXCEPTION
  181437. return DefWindowProc (h, message, wParam, lParam);
  181438. }
  181439. static bool isEventBlockedByModalComps (MSG& m)
  181440. {
  181441. if (Component::getNumCurrentlyModalComponents() == 0
  181442. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181443. return false;
  181444. switch (m.message)
  181445. {
  181446. case WM_MOUSEMOVE:
  181447. case WM_NCMOUSEMOVE:
  181448. case 0x020A: /* WM_MOUSEWHEEL */
  181449. case 0x020E: /* WM_MOUSEHWHEEL */
  181450. case WM_KEYUP:
  181451. case WM_SYSKEYUP:
  181452. case WM_CHAR:
  181453. case WM_APPCOMMAND:
  181454. case WM_LBUTTONUP:
  181455. case WM_MBUTTONUP:
  181456. case WM_RBUTTONUP:
  181457. case WM_MOUSEACTIVATE:
  181458. case WM_NCMOUSEHOVER:
  181459. case WM_MOUSEHOVER:
  181460. return true;
  181461. case WM_NCLBUTTONDOWN:
  181462. case WM_NCLBUTTONDBLCLK:
  181463. case WM_NCRBUTTONDOWN:
  181464. case WM_NCRBUTTONDBLCLK:
  181465. case WM_NCMBUTTONDOWN:
  181466. case WM_NCMBUTTONDBLCLK:
  181467. case WM_LBUTTONDOWN:
  181468. case WM_LBUTTONDBLCLK:
  181469. case WM_MBUTTONDOWN:
  181470. case WM_MBUTTONDBLCLK:
  181471. case WM_RBUTTONDOWN:
  181472. case WM_RBUTTONDBLCLK:
  181473. case WM_KEYDOWN:
  181474. case WM_SYSKEYDOWN:
  181475. {
  181476. Component* const modal = Component::getCurrentlyModalComponent (0);
  181477. if (modal != 0)
  181478. modal->inputAttemptWhenModal();
  181479. return true;
  181480. }
  181481. default:
  181482. break;
  181483. }
  181484. return false;
  181485. }
  181486. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181487. {
  181488. MSG m;
  181489. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181490. return false;
  181491. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181492. {
  181493. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181494. {
  181495. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181496. }
  181497. else if (m.message == WM_QUIT)
  181498. {
  181499. if (JUCEApplication::getInstance())
  181500. JUCEApplication::getInstance()->systemRequestedQuit();
  181501. }
  181502. else if (! isEventBlockedByModalComps (m))
  181503. {
  181504. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181505. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181506. {
  181507. // if it's someone else's window being clicked on, and the focus is
  181508. // currently on a juce window, pass the kb focus over..
  181509. HWND currentFocus = GetFocus();
  181510. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181511. SetFocus (m.hwnd);
  181512. }
  181513. TranslateMessage (&m);
  181514. DispatchMessage (&m);
  181515. }
  181516. }
  181517. return true;
  181518. }
  181519. bool juce_postMessageToSystemQueue (void* message)
  181520. {
  181521. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181522. }
  181523. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181524. void* userData)
  181525. {
  181526. if (MessageManager::getInstance()->isThisTheMessageThread())
  181527. {
  181528. return (*callback) (userData);
  181529. }
  181530. else
  181531. {
  181532. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181533. // deadlock because the message manager is blocked from running, and can't
  181534. // call your function..
  181535. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181536. return (void*) SendMessage (juce_messageWindowHandle,
  181537. specialCallbackId,
  181538. (WPARAM) callback,
  181539. (LPARAM) userData);
  181540. }
  181541. }
  181542. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181543. {
  181544. if (hwnd != juce_messageWindowHandle)
  181545. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181546. return TRUE;
  181547. }
  181548. void MessageManager::broadcastMessage (const String& value) throw()
  181549. {
  181550. VoidArray windows;
  181551. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181552. const String localCopy (value);
  181553. COPYDATASTRUCT data;
  181554. data.dwData = broadcastId;
  181555. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181556. data.lpData = (void*) (const juce_wchar*) localCopy;
  181557. for (int i = windows.size(); --i >= 0;)
  181558. {
  181559. HWND hwnd = (HWND) windows.getUnchecked(i);
  181560. TCHAR windowName [64]; // no need to read longer strings than this
  181561. GetWindowText (hwnd, windowName, 64);
  181562. windowName [63] = 0;
  181563. if (String (windowName) == String (messageWindowName))
  181564. {
  181565. DWORD_PTR result;
  181566. SendMessageTimeout (hwnd, WM_COPYDATA,
  181567. (WPARAM) juce_messageWindowHandle,
  181568. (LPARAM) &data,
  181569. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181570. 8000,
  181571. &result);
  181572. }
  181573. }
  181574. }
  181575. static const String getMessageWindowClassName()
  181576. {
  181577. // this name has to be different for each app/dll instance because otherwise
  181578. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181579. // window class).
  181580. static int number = 0;
  181581. if (number == 0)
  181582. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181583. return T("JUCEcs_") + String (number);
  181584. }
  181585. void MessageManager::doPlatformSpecificInitialisation()
  181586. {
  181587. OleInitialize (0);
  181588. const String className (getMessageWindowClassName());
  181589. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181590. WNDCLASSEX wc;
  181591. zerostruct (wc);
  181592. wc.cbSize = sizeof (wc);
  181593. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181594. wc.cbWndExtra = 4;
  181595. wc.hInstance = hmod;
  181596. wc.lpszClassName = className;
  181597. RegisterClassEx (&wc);
  181598. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181599. messageWindowName,
  181600. 0, 0, 0, 0, 0, 0, 0,
  181601. hmod, 0);
  181602. }
  181603. void MessageManager::doPlatformSpecificShutdown()
  181604. {
  181605. DestroyWindow (juce_messageWindowHandle);
  181606. UnregisterClass (getMessageWindowClassName(), 0);
  181607. OleUninitialize();
  181608. }
  181609. #endif
  181610. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181611. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181612. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181613. // compiled on its own).
  181614. #if JUCE_INCLUDED_FILE
  181615. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181616. // these are in the windows SDK, but need to be repeated here for GCC..
  181617. #ifndef GET_APPCOMMAND_LPARAM
  181618. #define FAPPCOMMAND_MASK 0xF000
  181619. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181620. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181621. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181622. #define APPCOMMAND_MEDIA_STOP 13
  181623. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181624. #define WM_APPCOMMAND 0x0319
  181625. #endif
  181626. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181627. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181628. extern bool juce_IsRunningInWine();
  181629. #ifndef ULW_ALPHA
  181630. #define ULW_ALPHA 0x00000002
  181631. #endif
  181632. #ifndef AC_SRC_ALPHA
  181633. #define AC_SRC_ALPHA 0x01
  181634. #endif
  181635. #define DEBUG_REPAINT_TIMES 0
  181636. static HPALETTE palette = 0;
  181637. static bool createPaletteIfNeeded = true;
  181638. static bool shouldDeactivateTitleBar = true;
  181639. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181640. #define WM_TRAYNOTIFY WM_USER + 100
  181641. using ::abs;
  181642. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181643. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181644. bool Desktop::canUseSemiTransparentWindows() throw()
  181645. {
  181646. if (updateLayeredWindow == 0)
  181647. {
  181648. if (! juce_IsRunningInWine())
  181649. {
  181650. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181651. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181652. }
  181653. }
  181654. return updateLayeredWindow != 0;
  181655. }
  181656. #undef DefWindowProc
  181657. #define DefWindowProc DefWindowProcW
  181658. const int extendedKeyModifier = 0x10000;
  181659. const int KeyPress::spaceKey = VK_SPACE;
  181660. const int KeyPress::returnKey = VK_RETURN;
  181661. const int KeyPress::escapeKey = VK_ESCAPE;
  181662. const int KeyPress::backspaceKey = VK_BACK;
  181663. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181664. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181665. const int KeyPress::tabKey = VK_TAB;
  181666. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181667. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181668. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181669. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181670. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181671. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181672. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181673. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181674. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181675. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181676. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181677. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181678. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181679. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181680. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181681. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181682. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181683. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181684. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181685. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181686. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181687. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181688. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181689. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181690. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181691. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181692. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181693. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181694. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181695. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181696. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181697. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181698. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181699. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181700. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181701. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181702. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181703. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181704. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181705. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181706. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181707. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181708. const int KeyPress::playKey = 0x30000;
  181709. const int KeyPress::stopKey = 0x30001;
  181710. const int KeyPress::fastForwardKey = 0x30002;
  181711. const int KeyPress::rewindKey = 0x30003;
  181712. class WindowsBitmapImage : public Image
  181713. {
  181714. public:
  181715. HBITMAP hBitmap;
  181716. BITMAPV4HEADER bitmapInfo;
  181717. HDC hdc;
  181718. unsigned char* bitmapData;
  181719. WindowsBitmapImage (const PixelFormat format_,
  181720. const int w, const int h, const bool clearImage)
  181721. : Image (format_, w, h)
  181722. {
  181723. jassert (format_ == RGB || format_ == ARGB);
  181724. pixelStride = (format_ == RGB) ? 3 : 4;
  181725. zerostruct (bitmapInfo);
  181726. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181727. bitmapInfo.bV4Width = w;
  181728. bitmapInfo.bV4Height = h;
  181729. bitmapInfo.bV4Planes = 1;
  181730. bitmapInfo.bV4CSType = 1;
  181731. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181732. if (format_ == ARGB)
  181733. {
  181734. bitmapInfo.bV4AlphaMask = 0xff000000;
  181735. bitmapInfo.bV4RedMask = 0xff0000;
  181736. bitmapInfo.bV4GreenMask = 0xff00;
  181737. bitmapInfo.bV4BlueMask = 0xff;
  181738. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181739. }
  181740. else
  181741. {
  181742. bitmapInfo.bV4V4Compression = BI_RGB;
  181743. }
  181744. lineStride = -((w * pixelStride + 3) & ~3);
  181745. HDC dc = GetDC (0);
  181746. hdc = CreateCompatibleDC (dc);
  181747. ReleaseDC (0, dc);
  181748. SetMapMode (hdc, MM_TEXT);
  181749. hBitmap = CreateDIBSection (hdc,
  181750. (BITMAPINFO*) &(bitmapInfo),
  181751. DIB_RGB_COLORS,
  181752. (void**) &bitmapData,
  181753. 0, 0);
  181754. SelectObject (hdc, hBitmap);
  181755. if (format_ == ARGB && clearImage)
  181756. zeromem (bitmapData, abs (h * lineStride));
  181757. imageData = bitmapData - (lineStride * (h - 1));
  181758. }
  181759. ~WindowsBitmapImage()
  181760. {
  181761. DeleteDC (hdc);
  181762. DeleteObject (hBitmap);
  181763. }
  181764. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181765. const int x, const int y,
  181766. const RectangleList& maskedRegion) throw()
  181767. {
  181768. static HDRAWDIB hdd = 0;
  181769. static bool needToCreateDrawDib = true;
  181770. if (needToCreateDrawDib)
  181771. {
  181772. needToCreateDrawDib = false;
  181773. HDC dc = GetDC (0);
  181774. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181775. ReleaseDC (0, dc);
  181776. // only open if we're not palettised
  181777. if (n > 8)
  181778. hdd = DrawDibOpen();
  181779. }
  181780. if (createPaletteIfNeeded)
  181781. {
  181782. HDC dc = GetDC (0);
  181783. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181784. ReleaseDC (0, dc);
  181785. if (n <= 8)
  181786. palette = CreateHalftonePalette (dc);
  181787. createPaletteIfNeeded = false;
  181788. }
  181789. if (palette != 0)
  181790. {
  181791. SelectPalette (dc, palette, FALSE);
  181792. RealizePalette (dc);
  181793. SetStretchBltMode (dc, HALFTONE);
  181794. }
  181795. SetMapMode (dc, MM_TEXT);
  181796. if (transparent)
  181797. {
  181798. POINT p, pos;
  181799. SIZE size;
  181800. RECT windowBounds;
  181801. GetWindowRect (hwnd, &windowBounds);
  181802. p.x = -x;
  181803. p.y = -y;
  181804. pos.x = windowBounds.left;
  181805. pos.y = windowBounds.top;
  181806. size.cx = windowBounds.right - windowBounds.left;
  181807. size.cy = windowBounds.bottom - windowBounds.top;
  181808. BLENDFUNCTION bf;
  181809. bf.AlphaFormat = AC_SRC_ALPHA;
  181810. bf.BlendFlags = 0;
  181811. bf.BlendOp = AC_SRC_OVER;
  181812. bf.SourceConstantAlpha = 0xff;
  181813. if (! maskedRegion.isEmpty())
  181814. {
  181815. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181816. {
  181817. const Rectangle<int>& r = *i.getRectangle();
  181818. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181819. }
  181820. }
  181821. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181822. }
  181823. else
  181824. {
  181825. int savedDC = 0;
  181826. if (! maskedRegion.isEmpty())
  181827. {
  181828. savedDC = SaveDC (dc);
  181829. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181830. {
  181831. const Rectangle<int>& r = *i.getRectangle();
  181832. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181833. }
  181834. }
  181835. const int w = getWidth();
  181836. const int h = getHeight();
  181837. if (hdd == 0)
  181838. {
  181839. StretchDIBits (dc,
  181840. x, y, w, h,
  181841. 0, 0, w, h,
  181842. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181843. DIB_RGB_COLORS, SRCCOPY);
  181844. }
  181845. else
  181846. {
  181847. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181848. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181849. 0, 0, w, h, 0);
  181850. }
  181851. if (! maskedRegion.isEmpty())
  181852. RestoreDC (dc, savedDC);
  181853. }
  181854. }
  181855. juce_UseDebuggingNewOperator
  181856. private:
  181857. WindowsBitmapImage (const WindowsBitmapImage&);
  181858. const WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181859. };
  181860. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181861. static int currentModifiers = 0;
  181862. static int modifiersAtLastCallback = 0;
  181863. static void updateKeyModifiers() throw()
  181864. {
  181865. currentModifiers &= ~(ModifierKeys::shiftModifier
  181866. | ModifierKeys::ctrlModifier
  181867. | ModifierKeys::altModifier);
  181868. if ((GetKeyState (VK_SHIFT) & 0x8000) != 0)
  181869. currentModifiers |= ModifierKeys::shiftModifier;
  181870. if ((GetKeyState (VK_CONTROL) & 0x8000) != 0)
  181871. currentModifiers |= ModifierKeys::ctrlModifier;
  181872. if ((GetKeyState (VK_MENU) & 0x8000) != 0)
  181873. currentModifiers |= ModifierKeys::altModifier;
  181874. if ((GetKeyState (VK_RMENU) & 0x8000) != 0)
  181875. currentModifiers &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181876. }
  181877. void ModifierKeys::updateCurrentModifiers() throw()
  181878. {
  181879. currentModifierFlags = currentModifiers;
  181880. }
  181881. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  181882. {
  181883. SHORT k = (SHORT) keyCode;
  181884. if ((keyCode & extendedKeyModifier) == 0
  181885. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  181886. k += (SHORT) T('A') - (SHORT) T('a');
  181887. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181888. (SHORT) '+', VK_OEM_PLUS,
  181889. (SHORT) '-', VK_OEM_MINUS,
  181890. (SHORT) '.', VK_OEM_PERIOD,
  181891. (SHORT) ';', VK_OEM_1,
  181892. (SHORT) ':', VK_OEM_1,
  181893. (SHORT) '/', VK_OEM_2,
  181894. (SHORT) '?', VK_OEM_2,
  181895. (SHORT) '[', VK_OEM_4,
  181896. (SHORT) ']', VK_OEM_6 };
  181897. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181898. if (k == translatedValues [i])
  181899. k = translatedValues [i + 1];
  181900. return (GetKeyState (k) & 0x8000) != 0;
  181901. }
  181902. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  181903. {
  181904. updateKeyModifiers();
  181905. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  181906. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0)
  181907. currentModifiers |= ModifierKeys::leftButtonModifier;
  181908. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0)
  181909. currentModifiers |= ModifierKeys::rightButtonModifier;
  181910. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0)
  181911. currentModifiers |= ModifierKeys::middleButtonModifier;
  181912. return ModifierKeys (currentModifiers);
  181913. }
  181914. static int64 getMouseEventTime() throw()
  181915. {
  181916. static int64 eventTimeOffset = 0;
  181917. static DWORD lastMessageTime = 0;
  181918. const DWORD thisMessageTime = GetMessageTime();
  181919. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181920. {
  181921. lastMessageTime = thisMessageTime;
  181922. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181923. }
  181924. return eventTimeOffset + thisMessageTime;
  181925. }
  181926. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181927. {
  181928. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181929. return callback (userData);
  181930. else
  181931. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181932. }
  181933. class Win32ComponentPeer : public ComponentPeer
  181934. {
  181935. public:
  181936. Win32ComponentPeer (Component* const component,
  181937. const int windowStyleFlags)
  181938. : ComponentPeer (component, windowStyleFlags),
  181939. dontRepaint (false),
  181940. fullScreen (false),
  181941. isDragging (false),
  181942. isMouseOver (false),
  181943. hasCreatedCaret (false),
  181944. currentWindowIcon (0),
  181945. taskBarIcon (0),
  181946. dropTarget (0)
  181947. {
  181948. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  181949. setTitle (component->getName());
  181950. if ((windowStyleFlags & windowHasDropShadow) != 0
  181951. && Desktop::canUseSemiTransparentWindows())
  181952. {
  181953. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181954. if (shadower != 0)
  181955. shadower->setOwner (component);
  181956. }
  181957. else
  181958. {
  181959. shadower = 0;
  181960. }
  181961. }
  181962. ~Win32ComponentPeer()
  181963. {
  181964. setTaskBarIcon (0);
  181965. deleteAndZero (shadower);
  181966. // do this before the next bit to avoid messages arriving for this window
  181967. // before it's destroyed
  181968. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181969. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181970. if (currentWindowIcon != 0)
  181971. DestroyIcon (currentWindowIcon);
  181972. if (dropTarget != 0)
  181973. {
  181974. dropTarget->Release();
  181975. dropTarget = 0;
  181976. }
  181977. }
  181978. void* getNativeHandle() const
  181979. {
  181980. return (void*) hwnd;
  181981. }
  181982. void setVisible (bool shouldBeVisible)
  181983. {
  181984. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181985. if (shouldBeVisible)
  181986. InvalidateRect (hwnd, 0, 0);
  181987. else
  181988. lastPaintTime = 0;
  181989. }
  181990. void setTitle (const String& title)
  181991. {
  181992. SetWindowText (hwnd, title);
  181993. }
  181994. void setPosition (int x, int y)
  181995. {
  181996. offsetWithinParent (x, y);
  181997. SetWindowPos (hwnd, 0,
  181998. x - windowBorder.getLeft(),
  181999. y - windowBorder.getTop(),
  182000. 0, 0,
  182001. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182002. }
  182003. void repaintNowIfTransparent()
  182004. {
  182005. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  182006. handlePaintMessage();
  182007. }
  182008. void updateBorderSize()
  182009. {
  182010. WINDOWINFO info;
  182011. info.cbSize = sizeof (info);
  182012. if (GetWindowInfo (hwnd, &info))
  182013. {
  182014. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  182015. info.rcClient.left - info.rcWindow.left,
  182016. info.rcWindow.bottom - info.rcClient.bottom,
  182017. info.rcWindow.right - info.rcClient.right);
  182018. }
  182019. }
  182020. void setSize (int w, int h)
  182021. {
  182022. SetWindowPos (hwnd, 0, 0, 0,
  182023. w + windowBorder.getLeftAndRight(),
  182024. h + windowBorder.getTopAndBottom(),
  182025. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182026. updateBorderSize();
  182027. repaintNowIfTransparent();
  182028. }
  182029. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  182030. {
  182031. fullScreen = isNowFullScreen;
  182032. offsetWithinParent (x, y);
  182033. SetWindowPos (hwnd, 0,
  182034. x - windowBorder.getLeft(),
  182035. y - windowBorder.getTop(),
  182036. w + windowBorder.getLeftAndRight(),
  182037. h + windowBorder.getTopAndBottom(),
  182038. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182039. updateBorderSize();
  182040. repaintNowIfTransparent();
  182041. }
  182042. void getBounds (int& x, int& y, int& w, int& h) const
  182043. {
  182044. RECT r;
  182045. GetWindowRect (hwnd, &r);
  182046. x = r.left;
  182047. y = r.top;
  182048. w = r.right - x;
  182049. h = r.bottom - y;
  182050. HWND parentH = GetParent (hwnd);
  182051. if (parentH != 0)
  182052. {
  182053. GetWindowRect (parentH, &r);
  182054. x -= r.left;
  182055. y -= r.top;
  182056. }
  182057. x += windowBorder.getLeft();
  182058. y += windowBorder.getTop();
  182059. w -= windowBorder.getLeftAndRight();
  182060. h -= windowBorder.getTopAndBottom();
  182061. }
  182062. const Point<int> getScreenPosition() const
  182063. {
  182064. RECT r;
  182065. GetWindowRect (hwnd, &r);
  182066. return Point<int> (r.left + windowBorder.getLeft(),
  182067. r.top + windowBorder.getTop());
  182068. }
  182069. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  182070. {
  182071. return relativePosition + getScreenPosition();
  182072. }
  182073. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  182074. {
  182075. return screenPosition - getScreenPosition();
  182076. }
  182077. void setMinimised (bool shouldBeMinimised)
  182078. {
  182079. if (shouldBeMinimised != isMinimised())
  182080. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  182081. }
  182082. bool isMinimised() const
  182083. {
  182084. WINDOWPLACEMENT wp;
  182085. wp.length = sizeof (WINDOWPLACEMENT);
  182086. GetWindowPlacement (hwnd, &wp);
  182087. return wp.showCmd == SW_SHOWMINIMIZED;
  182088. }
  182089. void setFullScreen (bool shouldBeFullScreen)
  182090. {
  182091. setMinimised (false);
  182092. if (fullScreen != shouldBeFullScreen)
  182093. {
  182094. fullScreen = shouldBeFullScreen;
  182095. const ComponentDeletionWatcher deletionChecker (component);
  182096. if (! fullScreen)
  182097. {
  182098. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  182099. if (hasTitleBar())
  182100. ShowWindow (hwnd, SW_SHOWNORMAL);
  182101. if (! boundsCopy.isEmpty())
  182102. {
  182103. setBounds (boundsCopy.getX(),
  182104. boundsCopy.getY(),
  182105. boundsCopy.getWidth(),
  182106. boundsCopy.getHeight(),
  182107. false);
  182108. }
  182109. }
  182110. else
  182111. {
  182112. if (hasTitleBar())
  182113. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  182114. else
  182115. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  182116. }
  182117. if (! deletionChecker.hasBeenDeleted())
  182118. handleMovedOrResized();
  182119. }
  182120. }
  182121. bool isFullScreen() const
  182122. {
  182123. if (! hasTitleBar())
  182124. return fullScreen;
  182125. WINDOWPLACEMENT wp;
  182126. wp.length = sizeof (wp);
  182127. GetWindowPlacement (hwnd, &wp);
  182128. return wp.showCmd == SW_SHOWMAXIMIZED;
  182129. }
  182130. bool contains (int x, int y, bool trueIfInAChildWindow) const
  182131. {
  182132. RECT r;
  182133. GetWindowRect (hwnd, &r);
  182134. POINT p;
  182135. p.x = x + r.left + windowBorder.getLeft();
  182136. p.y = y + r.top + windowBorder.getTop();
  182137. HWND w = WindowFromPoint (p);
  182138. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  182139. }
  182140. const BorderSize getFrameSize() const
  182141. {
  182142. return windowBorder;
  182143. }
  182144. bool setAlwaysOnTop (bool alwaysOnTop)
  182145. {
  182146. const bool oldDeactivate = shouldDeactivateTitleBar;
  182147. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182148. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  182149. 0, 0, 0, 0,
  182150. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182151. shouldDeactivateTitleBar = oldDeactivate;
  182152. if (shadower != 0)
  182153. shadower->componentBroughtToFront (*component);
  182154. return true;
  182155. }
  182156. void toFront (bool makeActive)
  182157. {
  182158. setMinimised (false);
  182159. const bool oldDeactivate = shouldDeactivateTitleBar;
  182160. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182161. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  182162. : &toFrontCallback2,
  182163. (void*) hwnd);
  182164. shouldDeactivateTitleBar = oldDeactivate;
  182165. if (! makeActive)
  182166. {
  182167. // in this case a broughttofront call won't have occured, so do it now..
  182168. handleBroughtToFront();
  182169. }
  182170. }
  182171. void toBehind (ComponentPeer* other)
  182172. {
  182173. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  182174. jassert (otherPeer != 0); // wrong type of window?
  182175. if (otherPeer != 0)
  182176. {
  182177. setMinimised (false);
  182178. // must be careful not to try to put a topmost window behind a normal one, or win32
  182179. // promotes the normal one to be topmost!
  182180. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  182181. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  182182. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182183. else if (otherPeer->getComponent()->isAlwaysOnTop())
  182184. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  182185. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182186. }
  182187. }
  182188. bool isFocused() const
  182189. {
  182190. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  182191. }
  182192. void grabFocus()
  182193. {
  182194. const bool oldDeactivate = shouldDeactivateTitleBar;
  182195. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182196. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  182197. shouldDeactivateTitleBar = oldDeactivate;
  182198. }
  182199. void textInputRequired (const Point<int>&)
  182200. {
  182201. if (! hasCreatedCaret)
  182202. {
  182203. hasCreatedCaret = true;
  182204. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  182205. }
  182206. ShowCaret (hwnd);
  182207. SetCaretPos (0, 0);
  182208. }
  182209. void repaint (int x, int y, int w, int h)
  182210. {
  182211. const RECT r = { x, y, x + w, y + h };
  182212. InvalidateRect (hwnd, &r, FALSE);
  182213. }
  182214. void performAnyPendingRepaintsNow()
  182215. {
  182216. MSG m;
  182217. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  182218. DispatchMessage (&m);
  182219. }
  182220. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  182221. {
  182222. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  182223. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  182224. return 0;
  182225. }
  182226. void setTaskBarIcon (const Image* const image)
  182227. {
  182228. if (image != 0)
  182229. {
  182230. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  182231. if (taskBarIcon == 0)
  182232. {
  182233. taskBarIcon = new NOTIFYICONDATA();
  182234. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  182235. taskBarIcon->hWnd = (HWND) hwnd;
  182236. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  182237. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  182238. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  182239. taskBarIcon->hIcon = hicon;
  182240. taskBarIcon->szTip[0] = 0;
  182241. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  182242. }
  182243. else
  182244. {
  182245. HICON oldIcon = taskBarIcon->hIcon;
  182246. taskBarIcon->hIcon = hicon;
  182247. taskBarIcon->uFlags = NIF_ICON;
  182248. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182249. DestroyIcon (oldIcon);
  182250. }
  182251. DestroyIcon (hicon);
  182252. }
  182253. else if (taskBarIcon != 0)
  182254. {
  182255. taskBarIcon->uFlags = 0;
  182256. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  182257. DestroyIcon (taskBarIcon->hIcon);
  182258. deleteAndZero (taskBarIcon);
  182259. }
  182260. }
  182261. void setTaskBarIconToolTip (const String& toolTip) const
  182262. {
  182263. if (taskBarIcon != 0)
  182264. {
  182265. taskBarIcon->uFlags = NIF_TIP;
  182266. toolTip.copyToBuffer (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  182267. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182268. }
  182269. }
  182270. bool isInside (HWND h) const
  182271. {
  182272. return GetAncestor (hwnd, GA_ROOT) == h;
  182273. }
  182274. juce_UseDebuggingNewOperator
  182275. bool dontRepaint;
  182276. private:
  182277. HWND hwnd;
  182278. DropShadower* shadower;
  182279. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  182280. BorderSize windowBorder;
  182281. HICON currentWindowIcon;
  182282. NOTIFYICONDATA* taskBarIcon;
  182283. IDropTarget* dropTarget;
  182284. class TemporaryImage : public Timer
  182285. {
  182286. public:
  182287. TemporaryImage()
  182288. : image (0)
  182289. {
  182290. }
  182291. ~TemporaryImage()
  182292. {
  182293. delete image;
  182294. }
  182295. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  182296. {
  182297. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  182298. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  182299. {
  182300. delete image;
  182301. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  182302. }
  182303. startTimer (3000);
  182304. return image;
  182305. }
  182306. void timerCallback()
  182307. {
  182308. stopTimer();
  182309. deleteAndZero (image);
  182310. }
  182311. private:
  182312. WindowsBitmapImage* image;
  182313. TemporaryImage (const TemporaryImage&);
  182314. const TemporaryImage& operator= (const TemporaryImage&);
  182315. };
  182316. TemporaryImage offscreenImageGenerator;
  182317. class WindowClassHolder : public DeletedAtShutdown
  182318. {
  182319. public:
  182320. WindowClassHolder()
  182321. : windowClassName ("JUCE_")
  182322. {
  182323. // this name has to be different for each app/dll instance because otherwise
  182324. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182325. // window class).
  182326. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182327. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182328. TCHAR moduleFile [1024];
  182329. moduleFile[0] = 0;
  182330. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182331. WORD iconNum = 0;
  182332. WNDCLASSEX wcex;
  182333. wcex.cbSize = sizeof (wcex);
  182334. wcex.style = CS_OWNDC;
  182335. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182336. wcex.lpszClassName = windowClassName;
  182337. wcex.cbClsExtra = 0;
  182338. wcex.cbWndExtra = 32;
  182339. wcex.hInstance = moduleHandle;
  182340. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182341. iconNum = 1;
  182342. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182343. wcex.hCursor = 0;
  182344. wcex.hbrBackground = 0;
  182345. wcex.lpszMenuName = 0;
  182346. RegisterClassEx (&wcex);
  182347. }
  182348. ~WindowClassHolder()
  182349. {
  182350. if (ComponentPeer::getNumPeers() == 0)
  182351. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182352. clearSingletonInstance();
  182353. }
  182354. String windowClassName;
  182355. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182356. };
  182357. static void* createWindowCallback (void* userData)
  182358. {
  182359. ((Win32ComponentPeer*) userData)->createWindow();
  182360. return 0;
  182361. }
  182362. void createWindow()
  182363. {
  182364. DWORD exstyle = WS_EX_ACCEPTFILES;
  182365. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182366. if (hasTitleBar())
  182367. {
  182368. type |= WS_OVERLAPPED;
  182369. exstyle |= WS_EX_APPWINDOW;
  182370. if ((styleFlags & windowHasCloseButton) != 0)
  182371. {
  182372. type |= WS_SYSMENU;
  182373. }
  182374. else
  182375. {
  182376. // annoyingly, windows won't let you have a min/max button without a close button
  182377. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182378. }
  182379. if ((styleFlags & windowIsResizable) != 0)
  182380. type |= WS_THICKFRAME;
  182381. }
  182382. else
  182383. {
  182384. type |= WS_POPUP | WS_SYSMENU;
  182385. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182386. exstyle |= WS_EX_TOOLWINDOW;
  182387. else
  182388. exstyle |= WS_EX_APPWINDOW;
  182389. }
  182390. if ((styleFlags & windowHasMinimiseButton) != 0)
  182391. type |= WS_MINIMIZEBOX;
  182392. if ((styleFlags & windowHasMaximiseButton) != 0)
  182393. type |= WS_MAXIMIZEBOX;
  182394. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182395. exstyle |= WS_EX_TRANSPARENT;
  182396. if ((styleFlags & windowIsSemiTransparent) != 0
  182397. && Desktop::canUseSemiTransparentWindows())
  182398. exstyle |= WS_EX_LAYERED;
  182399. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182400. if (hwnd != 0)
  182401. {
  182402. SetWindowLongPtr (hwnd, 0, 0);
  182403. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182404. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182405. if (dropTarget == 0)
  182406. dropTarget = new JuceDropTarget (this);
  182407. RegisterDragDrop (hwnd, dropTarget);
  182408. updateBorderSize();
  182409. // Calling this function here is (for some reason) necessary to make Windows
  182410. // correctly enable the menu items that we specify in the wm_initmenu message.
  182411. GetSystemMenu (hwnd, false);
  182412. }
  182413. else
  182414. {
  182415. jassertfalse
  182416. }
  182417. }
  182418. static void* destroyWindowCallback (void* handle)
  182419. {
  182420. RevokeDragDrop ((HWND) handle);
  182421. DestroyWindow ((HWND) handle);
  182422. return 0;
  182423. }
  182424. static void* toFrontCallback1 (void* h)
  182425. {
  182426. SetForegroundWindow ((HWND) h);
  182427. return 0;
  182428. }
  182429. static void* toFrontCallback2 (void* h)
  182430. {
  182431. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182432. return 0;
  182433. }
  182434. static void* setFocusCallback (void* h)
  182435. {
  182436. SetFocus ((HWND) h);
  182437. return 0;
  182438. }
  182439. static void* getFocusCallback (void*)
  182440. {
  182441. return (void*) GetFocus();
  182442. }
  182443. void offsetWithinParent (int& x, int& y) const
  182444. {
  182445. if (isTransparent())
  182446. {
  182447. HWND parentHwnd = GetParent (hwnd);
  182448. if (parentHwnd != 0)
  182449. {
  182450. RECT parentRect;
  182451. GetWindowRect (parentHwnd, &parentRect);
  182452. x += parentRect.left;
  182453. y += parentRect.top;
  182454. }
  182455. }
  182456. }
  182457. bool isTransparent() const
  182458. {
  182459. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182460. }
  182461. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182462. void setIcon (const Image& newIcon)
  182463. {
  182464. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182465. if (hicon != 0)
  182466. {
  182467. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182468. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182469. if (currentWindowIcon != 0)
  182470. DestroyIcon (currentWindowIcon);
  182471. currentWindowIcon = hicon;
  182472. }
  182473. }
  182474. void handlePaintMessage()
  182475. {
  182476. #if DEBUG_REPAINT_TIMES
  182477. const double paintStart = Time::getMillisecondCounterHiRes();
  182478. #endif
  182479. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182480. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182481. PAINTSTRUCT paintStruct;
  182482. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182483. // message and become re-entrant, but that's OK
  182484. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182485. // corrupt the image it's using to paint into, so do a check here.
  182486. static bool reentrant = false;
  182487. if (reentrant)
  182488. {
  182489. DeleteObject (rgn);
  182490. EndPaint (hwnd, &paintStruct);
  182491. return;
  182492. }
  182493. reentrant = true;
  182494. // this is the rectangle to update..
  182495. int x = paintStruct.rcPaint.left;
  182496. int y = paintStruct.rcPaint.top;
  182497. int w = paintStruct.rcPaint.right - x;
  182498. int h = paintStruct.rcPaint.bottom - y;
  182499. const bool transparent = isTransparent();
  182500. if (transparent)
  182501. {
  182502. // it's not possible to have a transparent window with a title bar at the moment!
  182503. jassert (! hasTitleBar());
  182504. RECT r;
  182505. GetWindowRect (hwnd, &r);
  182506. x = y = 0;
  182507. w = r.right - r.left;
  182508. h = r.bottom - r.top;
  182509. }
  182510. if (w > 0 && h > 0)
  182511. {
  182512. clearMaskedRegion();
  182513. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182514. RectangleList contextClip;
  182515. bool needToPaintAll = true;
  182516. if (regionType == COMPLEXREGION && ! transparent)
  182517. {
  182518. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182519. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182520. DeleteObject (clipRgn);
  182521. char rgnData [8192];
  182522. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182523. if (res > 0 && res <= sizeof (rgnData))
  182524. {
  182525. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182526. if (hdr->iType == RDH_RECTANGLES
  182527. && hdr->rcBound.right - hdr->rcBound.left >= w
  182528. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182529. {
  182530. needToPaintAll = false;
  182531. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182532. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182533. while (--num >= 0)
  182534. {
  182535. // (need to move this one pixel to the left because of a win32 bug)
  182536. const int cx = jmax (x, (int) rects->left - 1);
  182537. const int cy = rects->top;
  182538. const int cw = rects->right - cx;
  182539. const int ch = rects->bottom - rects->top;
  182540. if (cx + cw - x <= w && cy + ch - y <= h)
  182541. {
  182542. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182543. }
  182544. else
  182545. {
  182546. needToPaintAll = true;
  182547. break;
  182548. }
  182549. ++rects;
  182550. }
  182551. }
  182552. }
  182553. }
  182554. if (needToPaintAll)
  182555. {
  182556. contextClip.clear();
  182557. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182558. }
  182559. if (transparent)
  182560. {
  182561. RectangleList::Iterator i (contextClip);
  182562. while (i.next())
  182563. {
  182564. const Rectangle<int>& r = *i.getRectangle();
  182565. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182566. }
  182567. }
  182568. // if the component's not opaque, this won't draw properly unless the platform can support this
  182569. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182570. updateCurrentModifiers();
  182571. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182572. context.clipToRectangleList (contextClip);
  182573. context.setOrigin (-x, -y);
  182574. handlePaint (context);
  182575. if (! dontRepaint)
  182576. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182577. }
  182578. DeleteObject (rgn);
  182579. EndPaint (hwnd, &paintStruct);
  182580. reentrant = false;
  182581. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182582. _fpreset(); // because some graphics cards can unmask FP exceptions
  182583. #endif
  182584. lastPaintTime = Time::getMillisecondCounter();
  182585. #if DEBUG_REPAINT_TIMES
  182586. const double elapsed = Time::getMillisecondCounterHiRes() - paintStart;
  182587. Logger::outputDebugString (T("repaint time: ") + String (elapsed, 2));
  182588. #endif
  182589. }
  182590. void doMouseMove (const int x, const int y)
  182591. {
  182592. static uint32 lastMouseTime = 0;
  182593. // this can be set to throttle the mouse-messages to less than a
  182594. // certain number per second, as things can get unresponsive
  182595. // if each drag or move callback has to do a lot of work.
  182596. const int maxMouseMovesPerSecond = 60;
  182597. const int64 mouseEventTime = getMouseEventTime();
  182598. if (! isMouseOver)
  182599. {
  182600. isMouseOver = true;
  182601. TRACKMOUSEEVENT tme;
  182602. tme.cbSize = sizeof (tme);
  182603. tme.dwFlags = TME_LEAVE;
  182604. tme.hwndTrack = hwnd;
  182605. tme.dwHoverTime = 0;
  182606. if (! TrackMouseEvent (&tme))
  182607. {
  182608. jassertfalse;
  182609. }
  182610. updateKeyModifiers();
  182611. handleMouseEnter (x, y, mouseEventTime);
  182612. }
  182613. else if (! isDragging)
  182614. {
  182615. if (((unsigned int) x) < (unsigned int) component->getWidth()
  182616. && ((unsigned int) y) < (unsigned int) component->getHeight())
  182617. {
  182618. RECT r;
  182619. GetWindowRect (hwnd, &r);
  182620. POINT p;
  182621. p.x = x + r.left + windowBorder.getLeft();
  182622. p.y = y + r.top + windowBorder.getTop();
  182623. if (WindowFromPoint (p) == hwnd)
  182624. {
  182625. const uint32 now = Time::getMillisecondCounter();
  182626. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182627. {
  182628. lastMouseTime = now;
  182629. handleMouseMove (x, y, mouseEventTime);
  182630. }
  182631. }
  182632. }
  182633. }
  182634. else
  182635. {
  182636. const uint32 now = Time::getMillisecondCounter();
  182637. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182638. {
  182639. lastMouseTime = now;
  182640. handleMouseDrag (x, y, mouseEventTime);
  182641. }
  182642. }
  182643. }
  182644. void doMouseDown (const int x, const int y, const WPARAM wParam)
  182645. {
  182646. if (GetCapture() != hwnd)
  182647. SetCapture (hwnd);
  182648. doMouseMove (x, y);
  182649. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182650. if ((wParam & MK_LBUTTON) != 0)
  182651. currentModifiers |= ModifierKeys::leftButtonModifier;
  182652. if ((wParam & MK_RBUTTON) != 0)
  182653. currentModifiers |= ModifierKeys::rightButtonModifier;
  182654. if ((wParam & MK_MBUTTON) != 0)
  182655. currentModifiers |= ModifierKeys::middleButtonModifier;
  182656. updateKeyModifiers();
  182657. isDragging = true;
  182658. handleMouseDown (x, y, getMouseEventTime());
  182659. }
  182660. void doMouseUp (const int x, const int y, const WPARAM wParam)
  182661. {
  182662. int numButtons = 0;
  182663. if ((wParam & MK_LBUTTON) != 0)
  182664. ++numButtons;
  182665. if ((wParam & MK_RBUTTON) != 0)
  182666. ++numButtons;
  182667. if ((wParam & MK_MBUTTON) != 0)
  182668. ++numButtons;
  182669. const int oldModifiers = currentModifiers;
  182670. // update the currentmodifiers only after the callback, so the callback
  182671. // knows which button was released.
  182672. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182673. if ((wParam & MK_LBUTTON) != 0)
  182674. currentModifiers |= ModifierKeys::leftButtonModifier;
  182675. if ((wParam & MK_RBUTTON) != 0)
  182676. currentModifiers |= ModifierKeys::rightButtonModifier;
  182677. if ((wParam & MK_MBUTTON) != 0)
  182678. currentModifiers |= ModifierKeys::middleButtonModifier;
  182679. updateKeyModifiers();
  182680. isDragging = false;
  182681. // release the mouse capture if the user's not still got a button down
  182682. if (numButtons == 0 && hwnd == GetCapture())
  182683. ReleaseCapture();
  182684. handleMouseUp (oldModifiers, x, y, getMouseEventTime());
  182685. }
  182686. void doCaptureChanged()
  182687. {
  182688. if (isDragging)
  182689. {
  182690. RECT wr;
  182691. GetWindowRect (hwnd, &wr);
  182692. const DWORD mp = GetMessagePos();
  182693. doMouseUp (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182694. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  182695. (WPARAM) getMouseEventTime());
  182696. }
  182697. }
  182698. void doMouseExit()
  182699. {
  182700. if (isMouseOver)
  182701. {
  182702. isMouseOver = false;
  182703. RECT wr;
  182704. GetWindowRect (hwnd, &wr);
  182705. const DWORD mp = GetMessagePos();
  182706. handleMouseExit (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182707. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  182708. getMouseEventTime());
  182709. }
  182710. }
  182711. void doMouseWheel (const WPARAM wParam, const bool isVertical)
  182712. {
  182713. updateKeyModifiers();
  182714. const int amount = jlimit (-1000, 1000, (int) (0.75f * (short) HIWORD (wParam)));
  182715. handleMouseWheel (isVertical ? 0 : amount,
  182716. isVertical ? amount : 0,
  182717. getMouseEventTime());
  182718. }
  182719. void sendModifierKeyChangeIfNeeded()
  182720. {
  182721. if (modifiersAtLastCallback != currentModifiers)
  182722. {
  182723. modifiersAtLastCallback = currentModifiers;
  182724. handleModifierKeysChange();
  182725. }
  182726. }
  182727. bool doKeyUp (const WPARAM key)
  182728. {
  182729. updateKeyModifiers();
  182730. switch (key)
  182731. {
  182732. case VK_SHIFT:
  182733. case VK_CONTROL:
  182734. case VK_MENU:
  182735. case VK_CAPITAL:
  182736. case VK_LWIN:
  182737. case VK_RWIN:
  182738. case VK_APPS:
  182739. case VK_NUMLOCK:
  182740. case VK_SCROLL:
  182741. case VK_LSHIFT:
  182742. case VK_RSHIFT:
  182743. case VK_LCONTROL:
  182744. case VK_LMENU:
  182745. case VK_RCONTROL:
  182746. case VK_RMENU:
  182747. sendModifierKeyChangeIfNeeded();
  182748. }
  182749. return handleKeyUpOrDown (false)
  182750. || Component::getCurrentlyModalComponent() != 0;
  182751. }
  182752. bool doKeyDown (const WPARAM key)
  182753. {
  182754. updateKeyModifiers();
  182755. bool used = false;
  182756. switch (key)
  182757. {
  182758. case VK_SHIFT:
  182759. case VK_LSHIFT:
  182760. case VK_RSHIFT:
  182761. case VK_CONTROL:
  182762. case VK_LCONTROL:
  182763. case VK_RCONTROL:
  182764. case VK_MENU:
  182765. case VK_LMENU:
  182766. case VK_RMENU:
  182767. case VK_LWIN:
  182768. case VK_RWIN:
  182769. case VK_CAPITAL:
  182770. case VK_NUMLOCK:
  182771. case VK_SCROLL:
  182772. case VK_APPS:
  182773. sendModifierKeyChangeIfNeeded();
  182774. break;
  182775. case VK_LEFT:
  182776. case VK_RIGHT:
  182777. case VK_UP:
  182778. case VK_DOWN:
  182779. case VK_PRIOR:
  182780. case VK_NEXT:
  182781. case VK_HOME:
  182782. case VK_END:
  182783. case VK_DELETE:
  182784. case VK_INSERT:
  182785. case VK_F1:
  182786. case VK_F2:
  182787. case VK_F3:
  182788. case VK_F4:
  182789. case VK_F5:
  182790. case VK_F6:
  182791. case VK_F7:
  182792. case VK_F8:
  182793. case VK_F9:
  182794. case VK_F10:
  182795. case VK_F11:
  182796. case VK_F12:
  182797. case VK_F13:
  182798. case VK_F14:
  182799. case VK_F15:
  182800. case VK_F16:
  182801. used = handleKeyUpOrDown (true);
  182802. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182803. break;
  182804. case VK_ADD:
  182805. case VK_SUBTRACT:
  182806. case VK_MULTIPLY:
  182807. case VK_DIVIDE:
  182808. case VK_SEPARATOR:
  182809. case VK_DECIMAL:
  182810. used = handleKeyUpOrDown (true);
  182811. break;
  182812. default:
  182813. used = handleKeyUpOrDown (true);
  182814. {
  182815. MSG msg;
  182816. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182817. {
  182818. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182819. // manually generate the key-press event that matches this key-down.
  182820. const UINT keyChar = MapVirtualKey (key, 2);
  182821. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182822. }
  182823. }
  182824. break;
  182825. }
  182826. if (Component::getCurrentlyModalComponent() != 0)
  182827. used = true;
  182828. return used;
  182829. }
  182830. bool doKeyChar (int key, const LPARAM flags)
  182831. {
  182832. updateKeyModifiers();
  182833. juce_wchar textChar = (juce_wchar) key;
  182834. const int virtualScanCode = (flags >> 16) & 0xff;
  182835. if (key >= '0' && key <= '9')
  182836. {
  182837. switch (virtualScanCode) // check for a numeric keypad scan-code
  182838. {
  182839. case 0x52:
  182840. case 0x4f:
  182841. case 0x50:
  182842. case 0x51:
  182843. case 0x4b:
  182844. case 0x4c:
  182845. case 0x4d:
  182846. case 0x47:
  182847. case 0x48:
  182848. case 0x49:
  182849. key = (key - '0') + KeyPress::numberPad0;
  182850. break;
  182851. default:
  182852. break;
  182853. }
  182854. }
  182855. else
  182856. {
  182857. // convert the scan code to an unmodified character code..
  182858. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182859. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182860. keyChar = LOWORD (keyChar);
  182861. if (keyChar != 0)
  182862. key = (int) keyChar;
  182863. // avoid sending junk text characters for some control-key combinations
  182864. if (textChar < ' ' && (currentModifiers & (ModifierKeys::ctrlModifier | ModifierKeys::altModifier)) != 0)
  182865. textChar = 0;
  182866. }
  182867. return handleKeyPress (key, textChar);
  182868. }
  182869. bool doAppCommand (const LPARAM lParam)
  182870. {
  182871. int key = 0;
  182872. switch (GET_APPCOMMAND_LPARAM (lParam))
  182873. {
  182874. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182875. key = KeyPress::playKey;
  182876. break;
  182877. case APPCOMMAND_MEDIA_STOP:
  182878. key = KeyPress::stopKey;
  182879. break;
  182880. case APPCOMMAND_MEDIA_NEXTTRACK:
  182881. key = KeyPress::fastForwardKey;
  182882. break;
  182883. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182884. key = KeyPress::rewindKey;
  182885. break;
  182886. }
  182887. if (key != 0)
  182888. {
  182889. updateKeyModifiers();
  182890. if (hwnd == GetActiveWindow())
  182891. {
  182892. handleKeyPress (key, 0);
  182893. return true;
  182894. }
  182895. }
  182896. return false;
  182897. }
  182898. class JuceDropTarget : public IDropTarget
  182899. {
  182900. public:
  182901. JuceDropTarget (Win32ComponentPeer* const owner_)
  182902. : owner (owner_),
  182903. refCount (1)
  182904. {
  182905. }
  182906. virtual ~JuceDropTarget()
  182907. {
  182908. jassert (refCount == 0);
  182909. }
  182910. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182911. {
  182912. if (id == IID_IUnknown || id == IID_IDropTarget)
  182913. {
  182914. AddRef();
  182915. *result = this;
  182916. return S_OK;
  182917. }
  182918. *result = 0;
  182919. return E_NOINTERFACE;
  182920. }
  182921. ULONG __stdcall AddRef() { return ++refCount; }
  182922. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182923. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182924. {
  182925. updateFileList (pDataObject);
  182926. const Point<int> pos (owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182927. owner->handleFileDragMove (files, pos.getX(), pos.getY());
  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. const Point<int> pos (owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182939. owner->handleFileDragMove (files, pos.getX(), pos.getY());
  182940. *pdwEffect = DROPEFFECT_COPY;
  182941. return S_OK;
  182942. }
  182943. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182944. {
  182945. updateFileList (pDataObject);
  182946. const Point<int> pos (owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182947. owner->handleFileDragDrop (files, pos.getX(), pos.getY());
  182948. *pdwEffect = DROPEFFECT_COPY;
  182949. return S_OK;
  182950. }
  182951. private:
  182952. Win32ComponentPeer* const owner;
  182953. int refCount;
  182954. StringArray files;
  182955. void updateFileList (IDataObject* const pDataObject)
  182956. {
  182957. files.clear();
  182958. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182959. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182960. if (pDataObject->GetData (&format, &medium) == S_OK)
  182961. {
  182962. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182963. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182964. unsigned int i = 0;
  182965. if (pDropFiles->fWide)
  182966. {
  182967. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182968. for (;;)
  182969. {
  182970. unsigned int len = 0;
  182971. while (i + len < totalLen && fname [i + len] != 0)
  182972. ++len;
  182973. if (len == 0)
  182974. break;
  182975. files.add (String (fname + i, len));
  182976. i += len + 1;
  182977. }
  182978. }
  182979. else
  182980. {
  182981. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182982. for (;;)
  182983. {
  182984. unsigned int len = 0;
  182985. while (i + len < totalLen && fname [i + len] != 0)
  182986. ++len;
  182987. if (len == 0)
  182988. break;
  182989. files.add (String (fname + i, len));
  182990. i += len + 1;
  182991. }
  182992. }
  182993. GlobalUnlock (medium.hGlobal);
  182994. }
  182995. }
  182996. JuceDropTarget (const JuceDropTarget&);
  182997. const JuceDropTarget& operator= (const JuceDropTarget&);
  182998. };
  182999. void doSettingChange()
  183000. {
  183001. Desktop::getInstance().refreshMonitorSizes();
  183002. if (fullScreen && ! isMinimised())
  183003. {
  183004. const Rectangle<int> r (component->getParentMonitorArea());
  183005. SetWindowPos (hwnd, 0,
  183006. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  183007. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  183008. }
  183009. }
  183010. public:
  183011. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183012. {
  183013. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  183014. if (peer != 0)
  183015. return peer->peerWindowProc (h, message, wParam, lParam);
  183016. return DefWindowProc (h, message, wParam, lParam);
  183017. }
  183018. private:
  183019. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183020. {
  183021. if (isValidPeer (this))
  183022. {
  183023. switch (message)
  183024. {
  183025. case WM_NCHITTEST:
  183026. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  183027. return HTTRANSPARENT;
  183028. if (hasTitleBar())
  183029. break;
  183030. return HTCLIENT;
  183031. case WM_PAINT:
  183032. handlePaintMessage();
  183033. return 0;
  183034. case WM_NCPAINT:
  183035. if (wParam != 1)
  183036. handlePaintMessage();
  183037. if (hasTitleBar())
  183038. break;
  183039. return 0;
  183040. case WM_ERASEBKGND:
  183041. case WM_NCCALCSIZE:
  183042. if (hasTitleBar())
  183043. break;
  183044. return 1;
  183045. case WM_MOUSEMOVE:
  183046. doMouseMove (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  183047. return 0;
  183048. case WM_MOUSELEAVE:
  183049. doMouseExit();
  183050. return 0;
  183051. case WM_LBUTTONDOWN:
  183052. case WM_MBUTTONDOWN:
  183053. case WM_RBUTTONDOWN:
  183054. doMouseDown (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183055. return 0;
  183056. case WM_LBUTTONUP:
  183057. case WM_MBUTTONUP:
  183058. case WM_RBUTTONUP:
  183059. doMouseUp (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183060. return 0;
  183061. case WM_CAPTURECHANGED:
  183062. doCaptureChanged();
  183063. return 0;
  183064. case WM_NCMOUSEMOVE:
  183065. if (hasTitleBar())
  183066. break;
  183067. return 0;
  183068. case 0x020A: /* WM_MOUSEWHEEL */
  183069. doMouseWheel (wParam, true);
  183070. return 0;
  183071. case 0x020E: /* WM_MOUSEHWHEEL */
  183072. doMouseWheel (wParam, false);
  183073. return 0;
  183074. case WM_WINDOWPOSCHANGING:
  183075. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  183076. {
  183077. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  183078. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  183079. {
  183080. if (constrainer != 0)
  183081. {
  183082. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  183083. component->getY() - windowBorder.getTop(),
  183084. component->getWidth() + windowBorder.getLeftAndRight(),
  183085. component->getHeight() + windowBorder.getTopAndBottom());
  183086. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  183087. constrainer->checkBounds (pos, current,
  183088. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  183089. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  183090. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  183091. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  183092. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  183093. wp->x = pos.getX();
  183094. wp->y = pos.getY();
  183095. wp->cx = pos.getWidth();
  183096. wp->cy = pos.getHeight();
  183097. }
  183098. }
  183099. }
  183100. return 0;
  183101. case WM_WINDOWPOSCHANGED:
  183102. handleMovedOrResized();
  183103. if (dontRepaint)
  183104. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  183105. return 0;
  183106. case WM_KEYDOWN:
  183107. case WM_SYSKEYDOWN:
  183108. if (doKeyDown (wParam))
  183109. return 0;
  183110. break;
  183111. case WM_KEYUP:
  183112. case WM_SYSKEYUP:
  183113. if (doKeyUp (wParam))
  183114. return 0;
  183115. break;
  183116. case WM_CHAR:
  183117. if (doKeyChar ((int) wParam, lParam))
  183118. return 0;
  183119. break;
  183120. case WM_APPCOMMAND:
  183121. if (doAppCommand (lParam))
  183122. return TRUE;
  183123. break;
  183124. case WM_SETFOCUS:
  183125. updateKeyModifiers();
  183126. handleFocusGain();
  183127. break;
  183128. case WM_KILLFOCUS:
  183129. if (hasCreatedCaret)
  183130. {
  183131. hasCreatedCaret = false;
  183132. DestroyCaret();
  183133. }
  183134. handleFocusLoss();
  183135. break;
  183136. case WM_ACTIVATEAPP:
  183137. // Windows does weird things to process priority when you swap apps,
  183138. // so this forces an update when the app is brought to the front
  183139. if (wParam != FALSE)
  183140. juce_repeatLastProcessPriority();
  183141. else
  183142. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  183143. juce_CheckCurrentlyFocusedTopLevelWindow();
  183144. modifiersAtLastCallback = -1;
  183145. return 0;
  183146. case WM_ACTIVATE:
  183147. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  183148. {
  183149. modifiersAtLastCallback = -1;
  183150. updateKeyModifiers();
  183151. if (isMinimised())
  183152. {
  183153. component->repaint();
  183154. handleMovedOrResized();
  183155. if (! isValidMessageListener())
  183156. return 0;
  183157. }
  183158. if (LOWORD (wParam) == WA_CLICKACTIVE
  183159. && component->isCurrentlyBlockedByAnotherModalComponent())
  183160. {
  183161. const Point<int> mousePos (component->getMouseXYRelative());
  183162. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  183163. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  183164. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  183165. return 0;
  183166. }
  183167. handleBroughtToFront();
  183168. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183169. Component::getCurrentlyModalComponent()->toFront (true);
  183170. return 0;
  183171. }
  183172. break;
  183173. case WM_NCACTIVATE:
  183174. // while a temporary window is being shown, prevent Windows from deactivating the
  183175. // title bars of our main windows.
  183176. if (wParam == 0 && ! shouldDeactivateTitleBar)
  183177. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  183178. break;
  183179. case WM_MOUSEACTIVATE:
  183180. if (! component->getMouseClickGrabsKeyboardFocus())
  183181. return MA_NOACTIVATE;
  183182. break;
  183183. case WM_SHOWWINDOW:
  183184. if (wParam != 0)
  183185. handleBroughtToFront();
  183186. break;
  183187. case WM_CLOSE:
  183188. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  183189. handleUserClosingWindow();
  183190. return 0;
  183191. case WM_QUERYENDSESSION:
  183192. if (JUCEApplication::getInstance() != 0)
  183193. {
  183194. JUCEApplication::getInstance()->systemRequestedQuit();
  183195. return MessageManager::getInstance()->hasStopMessageBeenSent();
  183196. }
  183197. return TRUE;
  183198. case WM_TRAYNOTIFY:
  183199. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183200. {
  183201. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  183202. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183203. {
  183204. Component* const current = Component::getCurrentlyModalComponent();
  183205. if (current != 0)
  183206. current->inputAttemptWhenModal();
  183207. }
  183208. }
  183209. else
  183210. {
  183211. const int oldModifiers = currentModifiers;
  183212. MouseEvent e (Point<int>(), ModifierKeys::getCurrentModifiersRealtime(), component,
  183213. getMouseEventTime(), Point<int>(), getMouseEventTime(), 1, false);
  183214. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  183215. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::leftButtonModifier);
  183216. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  183217. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::rightButtonModifier);
  183218. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  183219. {
  183220. SetFocus (hwnd);
  183221. SetForegroundWindow (hwnd);
  183222. component->mouseDown (e);
  183223. }
  183224. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  183225. {
  183226. e.mods = ModifierKeys (oldModifiers);
  183227. component->mouseUp (e);
  183228. }
  183229. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183230. {
  183231. e.mods = ModifierKeys (oldModifiers);
  183232. component->mouseDoubleClick (e);
  183233. }
  183234. else if (lParam == WM_MOUSEMOVE)
  183235. {
  183236. component->mouseMove (e);
  183237. }
  183238. }
  183239. break;
  183240. case WM_SYNCPAINT:
  183241. return 0;
  183242. case WM_PALETTECHANGED:
  183243. InvalidateRect (h, 0, 0);
  183244. break;
  183245. case WM_DISPLAYCHANGE:
  183246. InvalidateRect (h, 0, 0);
  183247. createPaletteIfNeeded = true;
  183248. // intentional fall-through...
  183249. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  183250. doSettingChange();
  183251. break;
  183252. case WM_INITMENU:
  183253. if (! hasTitleBar())
  183254. {
  183255. if (isFullScreen())
  183256. {
  183257. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  183258. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  183259. }
  183260. else if (! isMinimised())
  183261. {
  183262. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  183263. }
  183264. }
  183265. break;
  183266. case WM_SYSCOMMAND:
  183267. switch (wParam & 0xfff0)
  183268. {
  183269. case SC_CLOSE:
  183270. if (sendInputAttemptWhenModalMessage())
  183271. return 0;
  183272. if (hasTitleBar())
  183273. {
  183274. PostMessage (h, WM_CLOSE, 0, 0);
  183275. return 0;
  183276. }
  183277. break;
  183278. case SC_KEYMENU:
  183279. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  183280. // obscure situations that can arise if a modal loop is started from an alt-key
  183281. // keypress).
  183282. if (hasTitleBar() && h == GetCapture())
  183283. ReleaseCapture();
  183284. break;
  183285. case SC_MAXIMIZE:
  183286. if (sendInputAttemptWhenModalMessage())
  183287. return 0;
  183288. setFullScreen (true);
  183289. return 0;
  183290. case SC_MINIMIZE:
  183291. if (sendInputAttemptWhenModalMessage())
  183292. return 0;
  183293. if (! hasTitleBar())
  183294. {
  183295. setMinimised (true);
  183296. return 0;
  183297. }
  183298. break;
  183299. case SC_RESTORE:
  183300. if (sendInputAttemptWhenModalMessage())
  183301. return 0;
  183302. if (hasTitleBar())
  183303. {
  183304. if (isFullScreen())
  183305. {
  183306. setFullScreen (false);
  183307. return 0;
  183308. }
  183309. }
  183310. else
  183311. {
  183312. if (isMinimised())
  183313. setMinimised (false);
  183314. else if (isFullScreen())
  183315. setFullScreen (false);
  183316. return 0;
  183317. }
  183318. break;
  183319. }
  183320. break;
  183321. case WM_NCLBUTTONDOWN:
  183322. case WM_NCRBUTTONDOWN:
  183323. case WM_NCMBUTTONDOWN:
  183324. sendInputAttemptWhenModalMessage();
  183325. break;
  183326. //case WM_IME_STARTCOMPOSITION;
  183327. // return 0;
  183328. case WM_GETDLGCODE:
  183329. return DLGC_WANTALLKEYS;
  183330. default:
  183331. break;
  183332. }
  183333. }
  183334. return DefWindowProc (h, message, wParam, lParam);
  183335. }
  183336. bool sendInputAttemptWhenModalMessage()
  183337. {
  183338. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183339. {
  183340. Component* const current = Component::getCurrentlyModalComponent();
  183341. if (current != 0)
  183342. current->inputAttemptWhenModal();
  183343. return true;
  183344. }
  183345. return false;
  183346. }
  183347. Win32ComponentPeer (const Win32ComponentPeer&);
  183348. const Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  183349. };
  183350. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  183351. {
  183352. return new Win32ComponentPeer (this, styleFlags);
  183353. }
  183354. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  183355. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183356. {
  183357. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183358. if (wp != 0)
  183359. wp->setTaskBarIcon (&newImage);
  183360. }
  183361. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183362. {
  183363. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183364. if (wp != 0)
  183365. wp->setTaskBarIconToolTip (tooltip);
  183366. }
  183367. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183368. {
  183369. DWORD val = GetWindowLong (h, styleType);
  183370. if (bitIsSet)
  183371. val |= feature;
  183372. else
  183373. val &= ~feature;
  183374. SetWindowLongPtr (h, styleType, val);
  183375. SetWindowPos (h, 0, 0, 0, 0, 0,
  183376. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183377. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183378. }
  183379. bool Process::isForegroundProcess()
  183380. {
  183381. HWND fg = GetForegroundWindow();
  183382. if (fg == 0)
  183383. return true;
  183384. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183385. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183386. // have to see if any of our windows are children of the foreground window
  183387. fg = GetAncestor (fg, GA_ROOT);
  183388. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183389. {
  183390. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183391. if (wp != 0 && wp->isInside (fg))
  183392. return true;
  183393. }
  183394. return false;
  183395. }
  183396. bool AlertWindow::showNativeDialogBox (const String& title,
  183397. const String& bodyText,
  183398. bool isOkCancel)
  183399. {
  183400. return MessageBox (0, bodyText, title,
  183401. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183402. : MB_OK)) == IDOK;
  183403. }
  183404. const Point<int> Desktop::getMousePosition()
  183405. {
  183406. POINT mousePos;
  183407. GetCursorPos (&mousePos);
  183408. return Point<int> (mousePos.x, mousePos.y);
  183409. }
  183410. void Desktop::setMousePosition (const Point<int>& newPosition)
  183411. {
  183412. SetCursorPos (newPosition.getX(), newPosition.getY());
  183413. }
  183414. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183415. {
  183416. return new Image (format, imageWidth, imageHeight, clearImage);
  183417. }
  183418. class ScreenSaverDefeater : public Timer,
  183419. public DeletedAtShutdown
  183420. {
  183421. public:
  183422. ScreenSaverDefeater() throw()
  183423. {
  183424. startTimer (10000);
  183425. timerCallback();
  183426. }
  183427. ~ScreenSaverDefeater() {}
  183428. void timerCallback()
  183429. {
  183430. if (Process::isForegroundProcess())
  183431. {
  183432. // simulate a shift key getting pressed..
  183433. INPUT input[2];
  183434. input[0].type = INPUT_KEYBOARD;
  183435. input[0].ki.wVk = VK_SHIFT;
  183436. input[0].ki.dwFlags = 0;
  183437. input[0].ki.dwExtraInfo = 0;
  183438. input[1].type = INPUT_KEYBOARD;
  183439. input[1].ki.wVk = VK_SHIFT;
  183440. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183441. input[1].ki.dwExtraInfo = 0;
  183442. SendInput (2, input, sizeof (INPUT));
  183443. }
  183444. }
  183445. };
  183446. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183447. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183448. {
  183449. if (isEnabled)
  183450. {
  183451. deleteAndZero (screenSaverDefeater);
  183452. }
  183453. else if (screenSaverDefeater == 0)
  183454. {
  183455. screenSaverDefeater = new ScreenSaverDefeater();
  183456. }
  183457. }
  183458. bool Desktop::isScreenSaverEnabled() throw()
  183459. {
  183460. return screenSaverDefeater == 0;
  183461. }
  183462. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183463. {
  183464. if (enableOrDisable)
  183465. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183466. }
  183467. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183468. {
  183469. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183470. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183471. return TRUE;
  183472. }
  183473. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183474. {
  183475. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183476. // make sure the first in the list is the main monitor
  183477. for (int i = 1; i < monitorCoords.size(); ++i)
  183478. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183479. monitorCoords.swap (i, 0);
  183480. if (monitorCoords.size() == 0)
  183481. {
  183482. RECT r;
  183483. GetWindowRect (GetDesktopWindow(), &r);
  183484. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183485. }
  183486. if (clipToWorkArea)
  183487. {
  183488. // clip the main monitor to the active non-taskbar area
  183489. RECT r;
  183490. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183491. Rectangle<int>& screen = monitorCoords.getReference (0);
  183492. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183493. jmax (screen.getY(), (int) r.top));
  183494. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183495. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183496. }
  183497. }
  183498. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183499. {
  183500. Image* im = 0;
  183501. if (bitmap != 0)
  183502. {
  183503. BITMAP bm;
  183504. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183505. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183506. {
  183507. HDC tempDC = GetDC (0);
  183508. HDC dc = CreateCompatibleDC (tempDC);
  183509. ReleaseDC (0, tempDC);
  183510. SelectObject (dc, bitmap);
  183511. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183512. for (int y = bm.bmHeight; --y >= 0;)
  183513. {
  183514. for (int x = bm.bmWidth; --x >= 0;)
  183515. {
  183516. COLORREF col = GetPixel (dc, x, y);
  183517. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183518. (uint8) GetGValue (col),
  183519. (uint8) GetBValue (col)));
  183520. }
  183521. }
  183522. DeleteDC (dc);
  183523. }
  183524. }
  183525. return im;
  183526. }
  183527. static Image* createImageFromHICON (HICON icon) throw()
  183528. {
  183529. ICONINFO info;
  183530. if (GetIconInfo (icon, &info))
  183531. {
  183532. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183533. if (mask == 0)
  183534. return 0;
  183535. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183536. if (image == 0)
  183537. return mask;
  183538. for (int y = image->getHeight(); --y >= 0;)
  183539. {
  183540. for (int x = image->getWidth(); --x >= 0;)
  183541. {
  183542. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183543. if (brightness > 0.0f)
  183544. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183545. }
  183546. }
  183547. delete mask;
  183548. return image;
  183549. }
  183550. return 0;
  183551. }
  183552. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183553. {
  183554. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183555. ICONINFO info;
  183556. info.fIcon = isIcon;
  183557. info.xHotspot = hotspotX;
  183558. info.yHotspot = hotspotY;
  183559. info.hbmMask = mask;
  183560. HICON hi = 0;
  183561. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183562. {
  183563. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183564. Graphics g (bitmap);
  183565. g.drawImageAt (&image, 0, 0);
  183566. info.hbmColor = bitmap.hBitmap;
  183567. hi = CreateIconIndirect (&info);
  183568. }
  183569. else
  183570. {
  183571. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183572. HDC colDC = CreateCompatibleDC (GetDC (0));
  183573. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183574. SelectObject (colDC, colour);
  183575. SelectObject (alphaDC, mask);
  183576. for (int y = image.getHeight(); --y >= 0;)
  183577. {
  183578. for (int x = image.getWidth(); --x >= 0;)
  183579. {
  183580. const Colour c (image.getPixelAt (x, y));
  183581. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183582. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183583. }
  183584. }
  183585. DeleteDC (colDC);
  183586. DeleteDC (alphaDC);
  183587. info.hbmColor = colour;
  183588. hi = CreateIconIndirect (&info);
  183589. DeleteObject (colour);
  183590. }
  183591. DeleteObject (mask);
  183592. return hi;
  183593. }
  183594. Image* juce_createIconForFile (const File& file)
  183595. {
  183596. Image* image = 0;
  183597. TCHAR filename [1024];
  183598. file.getFullPathName().copyToBuffer (filename, 1023);
  183599. WORD iconNum = 0;
  183600. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183601. filename, &iconNum);
  183602. if (icon != 0)
  183603. {
  183604. image = createImageFromHICON (icon);
  183605. DestroyIcon (icon);
  183606. }
  183607. return image;
  183608. }
  183609. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183610. {
  183611. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183612. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183613. const Image* im = &image;
  183614. Image* newIm = 0;
  183615. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183616. {
  183617. im = newIm = image.createCopy (maxW, maxH);
  183618. hotspotX = (hotspotX * maxW) / image.getWidth();
  183619. hotspotY = (hotspotY * maxH) / image.getHeight();
  183620. }
  183621. void* cursorH = 0;
  183622. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183623. if (os == SystemStats::WinXP)
  183624. {
  183625. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183626. }
  183627. else
  183628. {
  183629. const int stride = (maxW + 7) >> 3;
  183630. HeapBlock <uint8> andPlane, xorPlane;
  183631. andPlane.calloc (stride * maxH);
  183632. xorPlane.calloc (stride * maxH);
  183633. int index = 0;
  183634. for (int y = 0; y < maxH; ++y)
  183635. {
  183636. for (int x = 0; x < maxW; ++x)
  183637. {
  183638. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183639. const Colour pixelColour (im->getPixelAt (x, y));
  183640. if (pixelColour.getAlpha() < 127)
  183641. andPlane [index + (x >> 3)] |= bit;
  183642. else if (pixelColour.getBrightness() >= 0.5f)
  183643. xorPlane [index + (x >> 3)] |= bit;
  183644. }
  183645. index += stride;
  183646. }
  183647. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183648. }
  183649. delete newIm;
  183650. return cursorH;
  183651. }
  183652. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183653. {
  183654. if (cursorHandle != 0 && ! isStandard)
  183655. DestroyCursor ((HCURSOR) cursorHandle);
  183656. }
  183657. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183658. {
  183659. LPCTSTR cursorName = IDC_ARROW;
  183660. switch (type)
  183661. {
  183662. case MouseCursor::NormalCursor:
  183663. cursorName = IDC_ARROW;
  183664. break;
  183665. case MouseCursor::NoCursor:
  183666. return 0;
  183667. case MouseCursor::DraggingHandCursor:
  183668. {
  183669. static void* dragHandCursor = 0;
  183670. if (dragHandCursor == 0)
  183671. {
  183672. static const unsigned char dragHandData[] =
  183673. { 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,
  183674. 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,
  183675. 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 };
  183676. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183677. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183678. }
  183679. return dragHandCursor;
  183680. }
  183681. case MouseCursor::WaitCursor:
  183682. cursorName = IDC_WAIT;
  183683. break;
  183684. case MouseCursor::IBeamCursor:
  183685. cursorName = IDC_IBEAM;
  183686. break;
  183687. case MouseCursor::PointingHandCursor:
  183688. cursorName = MAKEINTRESOURCE(32649);
  183689. break;
  183690. case MouseCursor::LeftRightResizeCursor:
  183691. case MouseCursor::LeftEdgeResizeCursor:
  183692. case MouseCursor::RightEdgeResizeCursor:
  183693. cursorName = IDC_SIZEWE;
  183694. break;
  183695. case MouseCursor::UpDownResizeCursor:
  183696. case MouseCursor::TopEdgeResizeCursor:
  183697. case MouseCursor::BottomEdgeResizeCursor:
  183698. cursorName = IDC_SIZENS;
  183699. break;
  183700. case MouseCursor::TopLeftCornerResizeCursor:
  183701. case MouseCursor::BottomRightCornerResizeCursor:
  183702. cursorName = IDC_SIZENWSE;
  183703. break;
  183704. case MouseCursor::TopRightCornerResizeCursor:
  183705. case MouseCursor::BottomLeftCornerResizeCursor:
  183706. cursorName = IDC_SIZENESW;
  183707. break;
  183708. case MouseCursor::UpDownLeftRightResizeCursor:
  183709. cursorName = IDC_SIZEALL;
  183710. break;
  183711. case MouseCursor::CrosshairCursor:
  183712. cursorName = IDC_CROSS;
  183713. break;
  183714. case MouseCursor::CopyingCursor:
  183715. // can't seem to find one of these in the win32 list..
  183716. break;
  183717. }
  183718. HCURSOR cursorH = LoadCursor (0, cursorName);
  183719. if (cursorH == 0)
  183720. cursorH = LoadCursor (0, IDC_ARROW);
  183721. return (void*) cursorH;
  183722. }
  183723. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183724. {
  183725. SetCursor ((HCURSOR) getHandle());
  183726. }
  183727. void MouseCursor::showInAllWindows() const throw()
  183728. {
  183729. showInWindow (0);
  183730. }
  183731. class JuceDropSource : public IDropSource
  183732. {
  183733. int refCount;
  183734. public:
  183735. JuceDropSource()
  183736. : refCount (1)
  183737. {
  183738. }
  183739. virtual ~JuceDropSource()
  183740. {
  183741. jassert (refCount == 0);
  183742. }
  183743. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183744. {
  183745. if (id == IID_IUnknown || id == IID_IDropSource)
  183746. {
  183747. AddRef();
  183748. *result = this;
  183749. return S_OK;
  183750. }
  183751. *result = 0;
  183752. return E_NOINTERFACE;
  183753. }
  183754. ULONG __stdcall AddRef() { return ++refCount; }
  183755. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183756. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183757. {
  183758. if (escapePressed)
  183759. return DRAGDROP_S_CANCEL;
  183760. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183761. return DRAGDROP_S_DROP;
  183762. return S_OK;
  183763. }
  183764. HRESULT __stdcall GiveFeedback (DWORD)
  183765. {
  183766. return DRAGDROP_S_USEDEFAULTCURSORS;
  183767. }
  183768. };
  183769. class JuceEnumFormatEtc : public IEnumFORMATETC
  183770. {
  183771. public:
  183772. JuceEnumFormatEtc (const FORMATETC* const format_)
  183773. : refCount (1),
  183774. format (format_),
  183775. index (0)
  183776. {
  183777. }
  183778. virtual ~JuceEnumFormatEtc()
  183779. {
  183780. jassert (refCount == 0);
  183781. }
  183782. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183783. {
  183784. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183785. {
  183786. AddRef();
  183787. *result = this;
  183788. return S_OK;
  183789. }
  183790. *result = 0;
  183791. return E_NOINTERFACE;
  183792. }
  183793. ULONG __stdcall AddRef() { return ++refCount; }
  183794. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183795. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183796. {
  183797. if (result == 0)
  183798. return E_POINTER;
  183799. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183800. newOne->index = index;
  183801. *result = newOne;
  183802. return S_OK;
  183803. }
  183804. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183805. {
  183806. if (pceltFetched != 0)
  183807. *pceltFetched = 0;
  183808. else if (celt != 1)
  183809. return S_FALSE;
  183810. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183811. {
  183812. copyFormatEtc (lpFormatEtc [0], *format);
  183813. ++index;
  183814. if (pceltFetched != 0)
  183815. *pceltFetched = 1;
  183816. return S_OK;
  183817. }
  183818. return S_FALSE;
  183819. }
  183820. HRESULT __stdcall Skip (ULONG celt)
  183821. {
  183822. if (index + (int) celt >= 1)
  183823. return S_FALSE;
  183824. index += celt;
  183825. return S_OK;
  183826. }
  183827. HRESULT __stdcall Reset()
  183828. {
  183829. index = 0;
  183830. return S_OK;
  183831. }
  183832. private:
  183833. int refCount;
  183834. const FORMATETC* const format;
  183835. int index;
  183836. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183837. {
  183838. dest = source;
  183839. if (source.ptd != 0)
  183840. {
  183841. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183842. *(dest.ptd) = *(source.ptd);
  183843. }
  183844. }
  183845. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183846. const JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183847. };
  183848. class JuceDataObject : public IDataObject
  183849. {
  183850. JuceDropSource* const dropSource;
  183851. const FORMATETC* const format;
  183852. const STGMEDIUM* const medium;
  183853. int refCount;
  183854. JuceDataObject (const JuceDataObject&);
  183855. const JuceDataObject& operator= (const JuceDataObject&);
  183856. public:
  183857. JuceDataObject (JuceDropSource* const dropSource_,
  183858. const FORMATETC* const format_,
  183859. const STGMEDIUM* const medium_)
  183860. : dropSource (dropSource_),
  183861. format (format_),
  183862. medium (medium_),
  183863. refCount (1)
  183864. {
  183865. }
  183866. virtual ~JuceDataObject()
  183867. {
  183868. jassert (refCount == 0);
  183869. }
  183870. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183871. {
  183872. if (id == IID_IUnknown || id == IID_IDataObject)
  183873. {
  183874. AddRef();
  183875. *result = this;
  183876. return S_OK;
  183877. }
  183878. *result = 0;
  183879. return E_NOINTERFACE;
  183880. }
  183881. ULONG __stdcall AddRef() { return ++refCount; }
  183882. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183883. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183884. {
  183885. if ((pFormatEtc->tymed & format->tymed) != 0
  183886. && pFormatEtc->cfFormat == format->cfFormat
  183887. && pFormatEtc->dwAspect == format->dwAspect)
  183888. {
  183889. pMedium->tymed = format->tymed;
  183890. pMedium->pUnkForRelease = 0;
  183891. if (format->tymed == TYMED_HGLOBAL)
  183892. {
  183893. const SIZE_T len = GlobalSize (medium->hGlobal);
  183894. void* const src = GlobalLock (medium->hGlobal);
  183895. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183896. memcpy (dst, src, len);
  183897. GlobalUnlock (medium->hGlobal);
  183898. pMedium->hGlobal = dst;
  183899. return S_OK;
  183900. }
  183901. }
  183902. return DV_E_FORMATETC;
  183903. }
  183904. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183905. {
  183906. if (f == 0)
  183907. return E_INVALIDARG;
  183908. if (f->tymed == format->tymed
  183909. && f->cfFormat == format->cfFormat
  183910. && f->dwAspect == format->dwAspect)
  183911. return S_OK;
  183912. return DV_E_FORMATETC;
  183913. }
  183914. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183915. {
  183916. pFormatEtcOut->ptd = 0;
  183917. return E_NOTIMPL;
  183918. }
  183919. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183920. {
  183921. if (result == 0)
  183922. return E_POINTER;
  183923. if (direction == DATADIR_GET)
  183924. {
  183925. *result = new JuceEnumFormatEtc (format);
  183926. return S_OK;
  183927. }
  183928. *result = 0;
  183929. return E_NOTIMPL;
  183930. }
  183931. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183932. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183933. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183934. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183935. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183936. };
  183937. static HDROP createHDrop (const StringArray& fileNames) throw()
  183938. {
  183939. int totalChars = 0;
  183940. for (int i = fileNames.size(); --i >= 0;)
  183941. totalChars += fileNames[i].length() + 1;
  183942. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183943. sizeof (DROPFILES)
  183944. + sizeof (WCHAR) * (totalChars + 2));
  183945. if (hDrop != 0)
  183946. {
  183947. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183948. pDropFiles->pFiles = sizeof (DROPFILES);
  183949. pDropFiles->fWide = true;
  183950. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183951. for (int i = 0; i < fileNames.size(); ++i)
  183952. {
  183953. fileNames[i].copyToBuffer (fname, 2048);
  183954. fname += fileNames[i].length() + 1;
  183955. }
  183956. *fname = 0;
  183957. GlobalUnlock (hDrop);
  183958. }
  183959. return hDrop;
  183960. }
  183961. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183962. {
  183963. JuceDropSource* const source = new JuceDropSource();
  183964. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183965. DWORD effect;
  183966. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183967. data->Release();
  183968. source->Release();
  183969. return res == DRAGDROP_S_DROP;
  183970. }
  183971. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183972. {
  183973. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183974. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183975. medium.hGlobal = createHDrop (files);
  183976. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183977. : DROPEFFECT_COPY);
  183978. }
  183979. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183980. {
  183981. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183982. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183983. const int numChars = text.length();
  183984. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183985. char* d = (char*) GlobalLock (medium.hGlobal);
  183986. text.copyToBuffer ((WCHAR*) d, numChars + 1);
  183987. format.cfFormat = CF_UNICODETEXT;
  183988. GlobalUnlock (medium.hGlobal);
  183989. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183990. }
  183991. #endif
  183992. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183993. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183994. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183995. // compiled on its own).
  183996. #if JUCE_INCLUDED_FILE
  183997. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183998. NEWTEXTMETRICEXW*,
  183999. int type,
  184000. LPARAM lParam)
  184001. {
  184002. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184003. {
  184004. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184005. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  184006. }
  184007. return 1;
  184008. }
  184009. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  184010. NEWTEXTMETRICEXW*,
  184011. int type,
  184012. LPARAM lParam)
  184013. {
  184014. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184015. {
  184016. LOGFONTW lf;
  184017. zerostruct (lf);
  184018. lf.lfWeight = FW_DONTCARE;
  184019. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184020. lf.lfQuality = DEFAULT_QUALITY;
  184021. lf.lfCharSet = DEFAULT_CHARSET;
  184022. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184023. lf.lfPitchAndFamily = FF_DONTCARE;
  184024. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184025. fontName.copyToBuffer (lf.lfFaceName, LF_FACESIZE - 1);
  184026. HDC dc = CreateCompatibleDC (0);
  184027. EnumFontFamiliesEx (dc, &lf,
  184028. (FONTENUMPROCW) &wfontEnum2,
  184029. lParam, 0);
  184030. DeleteDC (dc);
  184031. }
  184032. return 1;
  184033. }
  184034. const StringArray Font::findAllTypefaceNames() throw()
  184035. {
  184036. StringArray results;
  184037. HDC dc = CreateCompatibleDC (0);
  184038. {
  184039. LOGFONTW lf;
  184040. zerostruct (lf);
  184041. lf.lfWeight = FW_DONTCARE;
  184042. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184043. lf.lfQuality = DEFAULT_QUALITY;
  184044. lf.lfCharSet = DEFAULT_CHARSET;
  184045. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184046. lf.lfPitchAndFamily = FF_DONTCARE;
  184047. lf.lfFaceName[0] = 0;
  184048. EnumFontFamiliesEx (dc, &lf,
  184049. (FONTENUMPROCW) &wfontEnum1,
  184050. (LPARAM) &results, 0);
  184051. }
  184052. DeleteDC (dc);
  184053. results.sort (true);
  184054. return results;
  184055. }
  184056. extern bool juce_IsRunningInWine();
  184057. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  184058. {
  184059. if (juce_IsRunningInWine())
  184060. {
  184061. // If we're running in Wine, then use fonts that might be available on Linux..
  184062. defaultSans = "Bitstream Vera Sans";
  184063. defaultSerif = "Bitstream Vera Serif";
  184064. defaultFixed = "Bitstream Vera Sans Mono";
  184065. }
  184066. else
  184067. {
  184068. defaultSans = "Verdana";
  184069. defaultSerif = "Times";
  184070. defaultFixed = "Lucida Console";
  184071. }
  184072. }
  184073. class FontDCHolder : private DeletedAtShutdown
  184074. {
  184075. public:
  184076. FontDCHolder() throw()
  184077. : dc (0), numKPs (0), size (0),
  184078. bold (false), italic (false)
  184079. {
  184080. }
  184081. ~FontDCHolder() throw()
  184082. {
  184083. if (dc != 0)
  184084. {
  184085. DeleteDC (dc);
  184086. DeleteObject (fontH);
  184087. }
  184088. clearSingletonInstance();
  184089. }
  184090. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  184091. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  184092. {
  184093. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  184094. {
  184095. fontName = fontName_;
  184096. bold = bold_;
  184097. italic = italic_;
  184098. size = size_;
  184099. if (dc != 0)
  184100. {
  184101. DeleteDC (dc);
  184102. DeleteObject (fontH);
  184103. kps.free();
  184104. }
  184105. fontH = 0;
  184106. dc = CreateCompatibleDC (0);
  184107. SetMapperFlags (dc, 0);
  184108. SetMapMode (dc, MM_TEXT);
  184109. LOGFONTW lfw;
  184110. zerostruct (lfw);
  184111. lfw.lfCharSet = DEFAULT_CHARSET;
  184112. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184113. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184114. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  184115. lfw.lfQuality = PROOF_QUALITY;
  184116. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  184117. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  184118. fontName.copyToBuffer (lfw.lfFaceName, LF_FACESIZE - 1);
  184119. lfw.lfHeight = size > 0 ? size : -256;
  184120. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  184121. if (standardSizedFont != 0)
  184122. {
  184123. if (SelectObject (dc, standardSizedFont) != 0)
  184124. {
  184125. fontH = standardSizedFont;
  184126. if (size == 0)
  184127. {
  184128. OUTLINETEXTMETRIC otm;
  184129. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  184130. {
  184131. lfw.lfHeight = -(int) otm.otmEMSquare;
  184132. fontH = CreateFontIndirect (&lfw);
  184133. SelectObject (dc, fontH);
  184134. DeleteObject (standardSizedFont);
  184135. }
  184136. }
  184137. }
  184138. else
  184139. {
  184140. jassertfalse
  184141. }
  184142. }
  184143. else
  184144. {
  184145. jassertfalse
  184146. }
  184147. }
  184148. return dc;
  184149. }
  184150. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  184151. {
  184152. if (kps == 0)
  184153. {
  184154. numKPs = GetKerningPairs (dc, 0, 0);
  184155. kps.calloc (numKPs);
  184156. GetKerningPairs (dc, numKPs, kps);
  184157. }
  184158. numKPs_ = numKPs;
  184159. return kps;
  184160. }
  184161. private:
  184162. HFONT fontH;
  184163. HDC dc;
  184164. String fontName;
  184165. HeapBlock <KERNINGPAIR> kps;
  184166. int numKPs, size;
  184167. bool bold, italic;
  184168. FontDCHolder (const FontDCHolder&);
  184169. const FontDCHolder& operator= (const FontDCHolder&);
  184170. };
  184171. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  184172. class WindowsTypeface : public CustomTypeface
  184173. {
  184174. public:
  184175. WindowsTypeface (const Font& font)
  184176. {
  184177. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  184178. font.isBold(), font.isItalic(), 0);
  184179. TEXTMETRIC tm;
  184180. tm.tmAscent = tm.tmHeight = 1;
  184181. tm.tmDefaultChar = 0;
  184182. GetTextMetrics (dc, &tm);
  184183. setCharacteristics (font.getTypefaceName(),
  184184. tm.tmAscent / (float) tm.tmHeight,
  184185. font.isBold(), font.isItalic(),
  184186. tm.tmDefaultChar);
  184187. }
  184188. bool loadGlyphIfPossible (const juce_wchar character)
  184189. {
  184190. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  184191. GLYPHMETRICS gm;
  184192. {
  184193. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  184194. WORD index = 0;
  184195. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  184196. && index == 0xffff)
  184197. {
  184198. return false;
  184199. }
  184200. }
  184201. Path glyphPath;
  184202. TEXTMETRIC tm;
  184203. if (! GetTextMetrics (dc, &tm))
  184204. {
  184205. addGlyph (character, glyphPath, 0);
  184206. return true;
  184207. }
  184208. const float height = (float) tm.tmHeight;
  184209. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  184210. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  184211. &gm, 0, 0, &identityMatrix);
  184212. if (bufSize > 0)
  184213. {
  184214. HeapBlock <char> data (bufSize);
  184215. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  184216. bufSize, data, &identityMatrix);
  184217. const TTPOLYGONHEADER* pheader = (TTPOLYGONHEADER*) data;
  184218. const float scaleX = 1.0f / height;
  184219. const float scaleY = -1.0f / height;
  184220. while ((char*) pheader < data + bufSize)
  184221. {
  184222. #define remapX(v) (scaleX * (v).x.value)
  184223. #define remapY(v) (scaleY * (v).y.value)
  184224. float x = remapX (pheader->pfxStart);
  184225. float y = remapY (pheader->pfxStart);
  184226. glyphPath.startNewSubPath (x, y);
  184227. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  184228. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  184229. while ((const char*) curve < curveEnd)
  184230. {
  184231. if (curve->wType == TT_PRIM_LINE)
  184232. {
  184233. for (int i = 0; i < curve->cpfx; ++i)
  184234. {
  184235. x = remapX (curve->apfx [i]);
  184236. y = remapY (curve->apfx [i]);
  184237. glyphPath.lineTo (x, y);
  184238. }
  184239. }
  184240. else if (curve->wType == TT_PRIM_QSPLINE)
  184241. {
  184242. for (int i = 0; i < curve->cpfx - 1; ++i)
  184243. {
  184244. const float x2 = remapX (curve->apfx [i]);
  184245. const float y2 = remapY (curve->apfx [i]);
  184246. float x3, y3;
  184247. if (i < curve->cpfx - 2)
  184248. {
  184249. x3 = 0.5f * (x2 + remapX (curve->apfx [i + 1]));
  184250. y3 = 0.5f * (y2 + remapY (curve->apfx [i + 1]));
  184251. }
  184252. else
  184253. {
  184254. x3 = remapX (curve->apfx [i + 1]);
  184255. y3 = remapY (curve->apfx [i + 1]);
  184256. }
  184257. glyphPath.quadraticTo (x2, y2, x3, y3);
  184258. x = x3;
  184259. y = y3;
  184260. }
  184261. }
  184262. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  184263. }
  184264. pheader = (const TTPOLYGONHEADER*) curve;
  184265. glyphPath.closeSubPath();
  184266. }
  184267. }
  184268. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  184269. int numKPs;
  184270. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  184271. for (int i = 0; i < numKPs; ++i)
  184272. {
  184273. if (kps[i].wFirst == character)
  184274. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  184275. kps[i].iKernAmount / height);
  184276. }
  184277. return true;
  184278. }
  184279. };
  184280. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  184281. {
  184282. return new WindowsTypeface (font);
  184283. }
  184284. #endif
  184285. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  184286. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  184287. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184288. // compiled on its own).
  184289. #if JUCE_INCLUDED_FILE
  184290. static const void* defaultDirPath = 0;
  184291. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  184292. static Component* currentExtraFileWin = 0;
  184293. static bool areThereAnyAlwaysOnTopWindows()
  184294. {
  184295. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  184296. {
  184297. Component* c = Desktop::getInstance().getComponent (i);
  184298. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  184299. return true;
  184300. }
  184301. return false;
  184302. }
  184303. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  184304. {
  184305. if (msg == BFFM_INITIALIZED)
  184306. {
  184307. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  184308. }
  184309. else if (msg == BFFM_VALIDATEFAILEDW)
  184310. {
  184311. returnedString = (LPCWSTR) lParam;
  184312. }
  184313. else if (msg == BFFM_VALIDATEFAILEDA)
  184314. {
  184315. returnedString = (const char*) lParam;
  184316. }
  184317. return 0;
  184318. }
  184319. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  184320. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  184321. {
  184322. if (currentExtraFileWin != 0)
  184323. {
  184324. if (uiMsg == WM_INITDIALOG)
  184325. {
  184326. HWND dialogH = GetParent (hdlg);
  184327. jassert (dialogH != 0);
  184328. if (dialogH == 0)
  184329. dialogH = hdlg;
  184330. RECT r, cr;
  184331. GetWindowRect (dialogH, &r);
  184332. GetClientRect (dialogH, &cr);
  184333. SetWindowPos (dialogH, 0,
  184334. r.left, r.top,
  184335. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  184336. jmax (150, (int) (r.bottom - r.top)),
  184337. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  184338. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  184339. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  184340. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  184341. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  184342. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  184343. }
  184344. else if (uiMsg == WM_NOTIFY)
  184345. {
  184346. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  184347. if (ofn->hdr.code == CDN_SELCHANGE)
  184348. {
  184349. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  184350. if (comp != 0)
  184351. {
  184352. TCHAR path [MAX_PATH * 2];
  184353. path[0] = 0;
  184354. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184355. const String fn ((const WCHAR*) path);
  184356. comp->selectedFileChanged (File (fn));
  184357. }
  184358. }
  184359. }
  184360. }
  184361. return 0;
  184362. }
  184363. class FPComponentHolder : public Component
  184364. {
  184365. public:
  184366. FPComponentHolder()
  184367. {
  184368. setVisible (true);
  184369. setOpaque (true);
  184370. }
  184371. ~FPComponentHolder()
  184372. {
  184373. }
  184374. void paint (Graphics& g)
  184375. {
  184376. g.fillAll (Colours::lightgrey);
  184377. }
  184378. private:
  184379. FPComponentHolder (const FPComponentHolder&);
  184380. const FPComponentHolder& operator= (const FPComponentHolder&);
  184381. };
  184382. void FileChooser::showPlatformDialog (Array<File>& results,
  184383. const String& title,
  184384. const File& currentFileOrDirectory,
  184385. const String& filter,
  184386. bool selectsDirectory,
  184387. bool /*selectsFiles*/,
  184388. bool isSaveDialogue,
  184389. bool warnAboutOverwritingExistingFiles,
  184390. bool selectMultipleFiles,
  184391. FilePreviewComponent* extraInfoComponent)
  184392. {
  184393. const int numCharsAvailable = 32768;
  184394. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184395. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184396. int fnameIdx = 0;
  184397. JUCE_TRY
  184398. {
  184399. // use a modal window as the parent for this dialog box
  184400. // to block input from other app windows
  184401. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  184402. Component w (String::empty);
  184403. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184404. mainMon.getY() + mainMon.getHeight() / 4,
  184405. 0, 0);
  184406. w.setOpaque (true);
  184407. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184408. w.addToDesktop (0);
  184409. if (extraInfoComponent == 0)
  184410. w.enterModalState();
  184411. String initialDir;
  184412. if (currentFileOrDirectory.isDirectory())
  184413. {
  184414. initialDir = currentFileOrDirectory.getFullPathName();
  184415. }
  184416. else
  184417. {
  184418. currentFileOrDirectory.getFileName().copyToBuffer (fname, numCharsAvailable);
  184419. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184420. }
  184421. if (currentExtraFileWin->isValidComponent())
  184422. {
  184423. jassertfalse
  184424. return;
  184425. }
  184426. if (selectsDirectory)
  184427. {
  184428. LPITEMIDLIST list = 0;
  184429. filenameSpace.fillWith (0);
  184430. {
  184431. BROWSEINFO bi;
  184432. zerostruct (bi);
  184433. bi.hwndOwner = (HWND) w.getWindowHandle();
  184434. bi.pszDisplayName = fname;
  184435. bi.lpszTitle = title;
  184436. bi.lpfn = browseCallbackProc;
  184437. #ifdef BIF_USENEWUI
  184438. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184439. #else
  184440. bi.ulFlags = 0x50;
  184441. #endif
  184442. defaultDirPath = (const WCHAR*) initialDir;
  184443. list = SHBrowseForFolder (&bi);
  184444. if (! SHGetPathFromIDListW (list, fname))
  184445. {
  184446. fname[0] = 0;
  184447. returnedString = String::empty;
  184448. }
  184449. }
  184450. LPMALLOC al;
  184451. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184452. al->Free (list);
  184453. defaultDirPath = 0;
  184454. if (returnedString.isNotEmpty())
  184455. {
  184456. const String stringFName (fname);
  184457. results.add (File (stringFName).getSiblingFile (returnedString));
  184458. returnedString = String::empty;
  184459. return;
  184460. }
  184461. }
  184462. else
  184463. {
  184464. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184465. if (warnAboutOverwritingExistingFiles)
  184466. flags |= OFN_OVERWRITEPROMPT;
  184467. if (selectMultipleFiles)
  184468. flags |= OFN_ALLOWMULTISELECT;
  184469. if (extraInfoComponent != 0)
  184470. {
  184471. flags |= OFN_ENABLEHOOK;
  184472. currentExtraFileWin = new FPComponentHolder();
  184473. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184474. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184475. extraInfoComponent->getHeight());
  184476. currentExtraFileWin->addToDesktop (0);
  184477. currentExtraFileWin->enterModalState();
  184478. }
  184479. {
  184480. WCHAR filters [1024];
  184481. zeromem (filters, sizeof (filters));
  184482. filter.copyToBuffer (filters, 1024);
  184483. filter.copyToBuffer (filters + filter.length() + 1,
  184484. 1022 - filter.length());
  184485. OPENFILENAMEW of;
  184486. zerostruct (of);
  184487. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184488. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184489. #else
  184490. of.lStructSize = sizeof (of);
  184491. #endif
  184492. of.hwndOwner = (HWND) w.getWindowHandle();
  184493. of.lpstrFilter = filters;
  184494. of.nFilterIndex = 1;
  184495. of.lpstrFile = fname;
  184496. of.nMaxFile = numCharsAvailable;
  184497. of.lpstrInitialDir = initialDir;
  184498. of.lpstrTitle = title;
  184499. of.Flags = flags;
  184500. if (extraInfoComponent != 0)
  184501. of.lpfnHook = &openCallback;
  184502. if (isSaveDialogue)
  184503. {
  184504. if (! GetSaveFileName (&of))
  184505. fname[0] = 0;
  184506. else
  184507. fnameIdx = of.nFileOffset;
  184508. }
  184509. else
  184510. {
  184511. if (! GetOpenFileName (&of))
  184512. fname[0] = 0;
  184513. else
  184514. fnameIdx = of.nFileOffset;
  184515. }
  184516. }
  184517. }
  184518. }
  184519. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184520. catch (...)
  184521. {
  184522. fname[0] = 0;
  184523. }
  184524. #endif
  184525. deleteAndZero (currentExtraFileWin);
  184526. const WCHAR* const files = fname;
  184527. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184528. {
  184529. const WCHAR* filename = files + fnameIdx;
  184530. while (*filename != 0)
  184531. {
  184532. const String filepath (String (files) + T("\\") + String (filename));
  184533. results.add (File (filepath));
  184534. filename += CharacterFunctions::length (filename) + 1;
  184535. }
  184536. }
  184537. else if (files[0] != 0)
  184538. {
  184539. results.add (File (files));
  184540. }
  184541. }
  184542. #endif
  184543. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184544. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184545. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184546. // compiled on its own).
  184547. #if JUCE_INCLUDED_FILE
  184548. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184549. {
  184550. if (OpenClipboard (0) != 0)
  184551. {
  184552. if (EmptyClipboard() != 0)
  184553. {
  184554. const int len = text.length();
  184555. if (len > 0)
  184556. {
  184557. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184558. (len + 1) * sizeof (wchar_t));
  184559. if (bufH != 0)
  184560. {
  184561. wchar_t* const data = (wchar_t*) GlobalLock (bufH);
  184562. text.copyToBuffer (data, len);
  184563. GlobalUnlock (bufH);
  184564. SetClipboardData (CF_UNICODETEXT, bufH);
  184565. }
  184566. }
  184567. }
  184568. CloseClipboard();
  184569. }
  184570. }
  184571. const String SystemClipboard::getTextFromClipboard() throw()
  184572. {
  184573. String result;
  184574. if (OpenClipboard (0) != 0)
  184575. {
  184576. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184577. if (bufH != 0)
  184578. {
  184579. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184580. if (data != 0)
  184581. {
  184582. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184583. GlobalUnlock (bufH);
  184584. }
  184585. }
  184586. CloseClipboard();
  184587. }
  184588. return result;
  184589. }
  184590. #endif
  184591. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184592. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184593. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184594. // compiled on its own).
  184595. #if JUCE_INCLUDED_FILE
  184596. class JuceIStorage : public IStorage
  184597. {
  184598. int refCount;
  184599. public:
  184600. JuceIStorage() : refCount (1) {}
  184601. virtual ~JuceIStorage()
  184602. {
  184603. jassert (refCount == 0);
  184604. }
  184605. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184606. {
  184607. if (id == IID_IUnknown || id == IID_IStorage)
  184608. {
  184609. AddRef();
  184610. *result = this;
  184611. return S_OK;
  184612. }
  184613. *result = 0;
  184614. return E_NOINTERFACE;
  184615. }
  184616. ULONG __stdcall AddRef() { return ++refCount; }
  184617. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184618. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184619. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184620. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184621. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184622. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184623. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184624. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184625. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184626. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184627. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184628. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184629. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184630. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184631. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184632. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184633. juce_UseDebuggingNewOperator
  184634. };
  184635. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184636. {
  184637. int refCount;
  184638. HWND window;
  184639. public:
  184640. JuceOleInPlaceFrame (HWND window_)
  184641. : refCount (1),
  184642. window (window_)
  184643. {
  184644. }
  184645. virtual ~JuceOleInPlaceFrame()
  184646. {
  184647. jassert (refCount == 0);
  184648. }
  184649. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184650. {
  184651. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184652. {
  184653. AddRef();
  184654. *result = this;
  184655. return S_OK;
  184656. }
  184657. *result = 0;
  184658. return E_NOINTERFACE;
  184659. }
  184660. ULONG __stdcall AddRef() { return ++refCount; }
  184661. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184662. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184663. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184664. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184665. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184666. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184667. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184668. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184669. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184670. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184671. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184672. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184673. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184674. juce_UseDebuggingNewOperator
  184675. };
  184676. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184677. {
  184678. int refCount;
  184679. HWND window;
  184680. JuceOleInPlaceFrame* frame;
  184681. public:
  184682. JuceIOleInPlaceSite (HWND window_)
  184683. : refCount (1),
  184684. window (window_)
  184685. {
  184686. frame = new JuceOleInPlaceFrame (window);
  184687. }
  184688. virtual ~JuceIOleInPlaceSite()
  184689. {
  184690. jassert (refCount == 0);
  184691. frame->Release();
  184692. }
  184693. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184694. {
  184695. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184696. {
  184697. AddRef();
  184698. *result = this;
  184699. return S_OK;
  184700. }
  184701. *result = 0;
  184702. return E_NOINTERFACE;
  184703. }
  184704. ULONG __stdcall AddRef() { return ++refCount; }
  184705. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184706. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184707. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184708. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184709. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184710. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184711. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184712. {
  184713. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184714. *lplpFrame = frame;
  184715. *lplpDoc = 0;
  184716. lpFrameInfo->fMDIApp = FALSE;
  184717. lpFrameInfo->hwndFrame = window;
  184718. lpFrameInfo->haccel = 0;
  184719. lpFrameInfo->cAccelEntries = 0;
  184720. return S_OK;
  184721. }
  184722. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184723. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184724. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184725. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184726. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184727. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184728. juce_UseDebuggingNewOperator
  184729. };
  184730. class JuceIOleClientSite : public IOleClientSite
  184731. {
  184732. int refCount;
  184733. JuceIOleInPlaceSite* inplaceSite;
  184734. public:
  184735. JuceIOleClientSite (HWND window)
  184736. : refCount (1)
  184737. {
  184738. inplaceSite = new JuceIOleInPlaceSite (window);
  184739. }
  184740. virtual ~JuceIOleClientSite()
  184741. {
  184742. jassert (refCount == 0);
  184743. inplaceSite->Release();
  184744. }
  184745. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184746. {
  184747. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184748. {
  184749. AddRef();
  184750. *result = this;
  184751. return S_OK;
  184752. }
  184753. else if (id == IID_IOleInPlaceSite)
  184754. {
  184755. inplaceSite->AddRef();
  184756. *result = inplaceSite;
  184757. return S_OK;
  184758. }
  184759. *result = 0;
  184760. return E_NOINTERFACE;
  184761. }
  184762. ULONG __stdcall AddRef() { return ++refCount; }
  184763. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184764. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184765. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184766. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184767. HRESULT __stdcall ShowObject() { return S_OK; }
  184768. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184769. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184770. juce_UseDebuggingNewOperator
  184771. };
  184772. class ActiveXControlData : public ComponentMovementWatcher
  184773. {
  184774. ActiveXControlComponent* const owner;
  184775. bool wasShowing;
  184776. public:
  184777. HWND controlHWND;
  184778. IStorage* storage;
  184779. IOleClientSite* clientSite;
  184780. IOleObject* control;
  184781. ActiveXControlData (HWND hwnd,
  184782. ActiveXControlComponent* const owner_)
  184783. : ComponentMovementWatcher (owner_),
  184784. owner (owner_),
  184785. wasShowing (owner_ != 0 && owner_->isShowing()),
  184786. controlHWND (0),
  184787. storage (new JuceIStorage()),
  184788. clientSite (new JuceIOleClientSite (hwnd)),
  184789. control (0)
  184790. {
  184791. }
  184792. ~ActiveXControlData()
  184793. {
  184794. if (control != 0)
  184795. {
  184796. control->Close (OLECLOSE_NOSAVE);
  184797. control->Release();
  184798. }
  184799. clientSite->Release();
  184800. storage->Release();
  184801. }
  184802. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184803. {
  184804. Component* const topComp = owner->getTopLevelComponent();
  184805. if (topComp->getPeer() != 0)
  184806. {
  184807. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184808. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184809. }
  184810. }
  184811. void componentPeerChanged()
  184812. {
  184813. const bool isShowingNow = owner->isShowing();
  184814. if (wasShowing != isShowingNow)
  184815. {
  184816. wasShowing = isShowingNow;
  184817. owner->setControlVisible (isShowingNow);
  184818. }
  184819. componentMovedOrResized (true, true);
  184820. }
  184821. void componentVisibilityChanged (Component&)
  184822. {
  184823. componentPeerChanged();
  184824. }
  184825. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184826. {
  184827. return ((ActiveXControlData*) ax->control) != 0
  184828. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184829. }
  184830. };
  184831. static VoidArray activeXComps;
  184832. static HWND getHWND (const ActiveXControlComponent* const component)
  184833. {
  184834. HWND hwnd = 0;
  184835. const IID iid = IID_IOleWindow;
  184836. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184837. if (window != 0)
  184838. {
  184839. window->GetWindow (&hwnd);
  184840. window->Release();
  184841. }
  184842. return hwnd;
  184843. }
  184844. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184845. {
  184846. RECT activeXRect, peerRect;
  184847. GetWindowRect (hwnd, &activeXRect);
  184848. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184849. const int mx = GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left;
  184850. const int my = GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top;
  184851. const int64 mouseEventTime = getMouseEventTime();
  184852. const int oldModifiers = currentModifiers;
  184853. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184854. switch (message)
  184855. {
  184856. case WM_MOUSEMOVE:
  184857. if (ModifierKeys (currentModifiers).isAnyMouseButtonDown())
  184858. peer->handleMouseDrag (mx, my, mouseEventTime);
  184859. else
  184860. peer->handleMouseMove (mx, my, mouseEventTime);
  184861. break;
  184862. case WM_LBUTTONDOWN:
  184863. case WM_MBUTTONDOWN:
  184864. case WM_RBUTTONDOWN:
  184865. peer->handleMouseDown (mx, my, mouseEventTime);
  184866. break;
  184867. case WM_LBUTTONUP:
  184868. case WM_MBUTTONUP:
  184869. case WM_RBUTTONUP:
  184870. peer->handleMouseUp (oldModifiers, mx, my, mouseEventTime);
  184871. break;
  184872. default:
  184873. break;
  184874. }
  184875. }
  184876. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184877. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184878. {
  184879. for (int i = activeXComps.size(); --i >= 0;)
  184880. {
  184881. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) activeXComps.getUnchecked(i);
  184882. if (ActiveXControlData::doesWindowMatch (ax, hwnd))
  184883. {
  184884. switch (message)
  184885. {
  184886. case WM_MOUSEMOVE:
  184887. case WM_LBUTTONDOWN:
  184888. case WM_MBUTTONDOWN:
  184889. case WM_RBUTTONDOWN:
  184890. case WM_LBUTTONUP:
  184891. case WM_MBUTTONUP:
  184892. case WM_RBUTTONUP:
  184893. case WM_LBUTTONDBLCLK:
  184894. case WM_MBUTTONDBLCLK:
  184895. case WM_RBUTTONDBLCLK:
  184896. if (ax->isShowing())
  184897. {
  184898. ComponentPeer* const peer = ax->getPeer();
  184899. if (peer != 0)
  184900. {
  184901. offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184902. if (! ax->areMouseEventsAllowed())
  184903. return 0;
  184904. }
  184905. }
  184906. break;
  184907. default:
  184908. break;
  184909. }
  184910. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184911. }
  184912. }
  184913. return DefWindowProc (hwnd, message, wParam, lParam);
  184914. }
  184915. ActiveXControlComponent::ActiveXControlComponent()
  184916. : originalWndProc (0),
  184917. control (0),
  184918. mouseEventsAllowed (true)
  184919. {
  184920. activeXComps.add (this);
  184921. }
  184922. ActiveXControlComponent::~ActiveXControlComponent()
  184923. {
  184924. deleteControl();
  184925. activeXComps.removeValue (this);
  184926. }
  184927. void ActiveXControlComponent::paint (Graphics& g)
  184928. {
  184929. if (control == 0)
  184930. g.fillAll (Colours::lightgrey);
  184931. }
  184932. bool ActiveXControlComponent::createControl (const void* controlIID)
  184933. {
  184934. deleteControl();
  184935. ComponentPeer* const peer = getPeer();
  184936. // the component must have already been added to a real window when you call this!
  184937. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184938. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184939. {
  184940. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184941. HWND hwnd = (HWND) peer->getNativeHandle();
  184942. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184943. HRESULT hr;
  184944. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184945. info->clientSite, info->storage,
  184946. (void**) &(info->control))) == S_OK)
  184947. {
  184948. info->control->SetHostNames (L"Juce", 0);
  184949. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184950. {
  184951. RECT rect;
  184952. rect.left = pos.getX();
  184953. rect.top = pos.getY();
  184954. rect.right = pos.getX() + getWidth();
  184955. rect.bottom = pos.getY() + getHeight();
  184956. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184957. {
  184958. control = info.release();
  184959. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184960. ((ActiveXControlData*) control)->controlHWND = getHWND (this);
  184961. if (((ActiveXControlData*) control)->controlHWND != 0)
  184962. {
  184963. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184964. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) activeXHookWndProc);
  184965. }
  184966. return true;
  184967. }
  184968. }
  184969. }
  184970. }
  184971. return false;
  184972. }
  184973. void ActiveXControlComponent::deleteControl()
  184974. {
  184975. ActiveXControlData* const info = (ActiveXControlData*) control;
  184976. if (info != 0)
  184977. {
  184978. delete info;
  184979. control = 0;
  184980. originalWndProc = 0;
  184981. }
  184982. }
  184983. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184984. {
  184985. ActiveXControlData* const info = (ActiveXControlData*) control;
  184986. void* result = 0;
  184987. if (info != 0 && info->control != 0
  184988. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184989. return result;
  184990. return 0;
  184991. }
  184992. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184993. {
  184994. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184995. if (hwnd != 0)
  184996. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184997. }
  184998. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184999. {
  185000. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185001. if (hwnd != 0)
  185002. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  185003. }
  185004. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  185005. {
  185006. mouseEventsAllowed = eventsCanReachControl;
  185007. }
  185008. #endif
  185009. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  185010. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185011. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185012. // compiled on its own).
  185013. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  185014. using namespace QTOLibrary;
  185015. using namespace QTOControlLib;
  185016. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  185017. static bool isQTAvailable = false;
  185018. struct QTMovieCompInternal
  185019. {
  185020. QTMovieCompInternal()
  185021. : dataHandle (0)
  185022. {
  185023. }
  185024. ~QTMovieCompInternal()
  185025. {
  185026. clearHandle();
  185027. }
  185028. IQTControlPtr qtControlInternal;
  185029. IQTMoviePtr qtMovieInternal;
  185030. Handle dataHandle;
  185031. void clearHandle()
  185032. {
  185033. if (dataHandle != 0)
  185034. {
  185035. DisposeHandle (dataHandle);
  185036. dataHandle = 0;
  185037. }
  185038. }
  185039. };
  185040. #define qtControl (((QTMovieCompInternal*) internal)->qtControlInternal)
  185041. #define qtMovie (((QTMovieCompInternal*) internal)->qtMovieInternal)
  185042. QuickTimeMovieComponent::QuickTimeMovieComponent()
  185043. : movieLoaded (false),
  185044. controllerVisible (true)
  185045. {
  185046. internal = new QTMovieCompInternal();
  185047. setMouseEventsAllowed (false);
  185048. }
  185049. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  185050. {
  185051. closeMovie();
  185052. qtControl = 0;
  185053. deleteControl();
  185054. delete internal;
  185055. internal = 0;
  185056. }
  185057. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  185058. {
  185059. if (! isQTAvailable)
  185060. {
  185061. isQTAvailable = (InitializeQTML (0) == noErr)
  185062. && (EnterMovies() == noErr);
  185063. }
  185064. return isQTAvailable;
  185065. }
  185066. void QuickTimeMovieComponent::createControlIfNeeded()
  185067. {
  185068. if (isShowing() && ! isControlCreated())
  185069. {
  185070. const IID qtIID = __uuidof (QTControl);
  185071. if (createControl (&qtIID))
  185072. {
  185073. const IID qtInterfaceIID = __uuidof (IQTControl);
  185074. qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  185075. if (qtControl != 0)
  185076. {
  185077. qtControl->Release(); // it has one ref too many at this point
  185078. qtControl->QuickTimeInitialize();
  185079. qtControl->PutSizing (qtMovieFitsControl);
  185080. if (movieFile != File::nonexistent)
  185081. loadMovie (movieFile, controllerVisible);
  185082. }
  185083. }
  185084. }
  185085. }
  185086. bool QuickTimeMovieComponent::isControlCreated() const
  185087. {
  185088. return isControlOpen();
  185089. }
  185090. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  185091. const bool isControllerVisible)
  185092. {
  185093. movieFile = File::nonexistent;
  185094. movieLoaded = false;
  185095. qtMovie = 0;
  185096. controllerVisible = isControllerVisible;
  185097. createControlIfNeeded();
  185098. if (isControlCreated())
  185099. {
  185100. if (qtControl != 0)
  185101. {
  185102. qtControl->Put_MovieHandle (0);
  185103. ((QTMovieCompInternal*) internal)->clearHandle();
  185104. Movie movie;
  185105. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, ((QTMovieCompInternal*) internal)->dataHandle))
  185106. {
  185107. qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  185108. qtMovie = qtControl->GetMovie();
  185109. if (qtMovie != 0)
  185110. qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  185111. : qtMovieControllerTypeNone);
  185112. }
  185113. if (movie == 0)
  185114. ((QTMovieCompInternal*) internal)->clearHandle();
  185115. }
  185116. movieLoaded = (qtMovie != 0);
  185117. }
  185118. else
  185119. {
  185120. // You're trying to open a movie when the control hasn't yet been created, probably because
  185121. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  185122. jassertfalse
  185123. }
  185124. delete movieStream;
  185125. return movieLoaded;
  185126. }
  185127. void QuickTimeMovieComponent::closeMovie()
  185128. {
  185129. stop();
  185130. movieFile = File::nonexistent;
  185131. movieLoaded = false;
  185132. qtMovie = 0;
  185133. if (qtControl != 0)
  185134. qtControl->Put_MovieHandle (0);
  185135. ((QTMovieCompInternal*) internal)->clearHandle();
  185136. }
  185137. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  185138. {
  185139. return movieFile;
  185140. }
  185141. bool QuickTimeMovieComponent::isMovieOpen() const
  185142. {
  185143. return movieLoaded;
  185144. }
  185145. double QuickTimeMovieComponent::getMovieDuration() const
  185146. {
  185147. if (qtMovie != 0)
  185148. return qtMovie->GetDuration() / (double) qtMovie->GetTimeScale();
  185149. return 0.0;
  185150. }
  185151. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  185152. {
  185153. if (qtMovie != 0)
  185154. {
  185155. struct QTRECT r = qtMovie->GetNaturalRect();
  185156. width = r.right - r.left;
  185157. height = r.bottom - r.top;
  185158. }
  185159. else
  185160. {
  185161. width = height = 0;
  185162. }
  185163. }
  185164. void QuickTimeMovieComponent::play()
  185165. {
  185166. if (qtMovie != 0)
  185167. qtMovie->Play();
  185168. }
  185169. void QuickTimeMovieComponent::stop()
  185170. {
  185171. if (qtMovie != 0)
  185172. qtMovie->Stop();
  185173. }
  185174. bool QuickTimeMovieComponent::isPlaying() const
  185175. {
  185176. return qtMovie != 0 && qtMovie->GetRate() != 0.0f;
  185177. }
  185178. void QuickTimeMovieComponent::setPosition (const double seconds)
  185179. {
  185180. if (qtMovie != 0)
  185181. qtMovie->PutTime ((long) (seconds * qtMovie->GetTimeScale()));
  185182. }
  185183. double QuickTimeMovieComponent::getPosition() const
  185184. {
  185185. if (qtMovie != 0)
  185186. return qtMovie->GetTime() / (double) qtMovie->GetTimeScale();
  185187. return 0.0;
  185188. }
  185189. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  185190. {
  185191. if (qtMovie != 0)
  185192. qtMovie->PutRate (newSpeed);
  185193. }
  185194. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  185195. {
  185196. if (qtMovie != 0)
  185197. {
  185198. qtMovie->PutAudioVolume (newVolume);
  185199. qtMovie->PutAudioMute (newVolume <= 0);
  185200. }
  185201. }
  185202. float QuickTimeMovieComponent::getMovieVolume() const
  185203. {
  185204. if (qtMovie != 0)
  185205. return qtMovie->GetAudioVolume();
  185206. return 0.0f;
  185207. }
  185208. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  185209. {
  185210. if (qtMovie != 0)
  185211. qtMovie->PutLoop (shouldLoop);
  185212. }
  185213. bool QuickTimeMovieComponent::isLooping() const
  185214. {
  185215. return qtMovie != 0 && qtMovie->GetLoop();
  185216. }
  185217. bool QuickTimeMovieComponent::isControllerVisible() const
  185218. {
  185219. return controllerVisible;
  185220. }
  185221. void QuickTimeMovieComponent::parentHierarchyChanged()
  185222. {
  185223. createControlIfNeeded();
  185224. QTCompBaseClass::parentHierarchyChanged();
  185225. }
  185226. void QuickTimeMovieComponent::visibilityChanged()
  185227. {
  185228. createControlIfNeeded();
  185229. QTCompBaseClass::visibilityChanged();
  185230. }
  185231. void QuickTimeMovieComponent::paint (Graphics& g)
  185232. {
  185233. if (! isControlCreated())
  185234. g.fillAll (Colours::black);
  185235. }
  185236. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  185237. {
  185238. Handle dataRef = 0;
  185239. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  185240. if (err == noErr)
  185241. {
  185242. Str255 suffix;
  185243. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  185244. StringPtr name = suffix;
  185245. err = PtrAndHand (name, dataRef, name[0] + 1);
  185246. if (err == noErr)
  185247. {
  185248. long atoms[3];
  185249. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  185250. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  185251. atoms[2] = EndianU32_NtoB (MovieFileType);
  185252. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  185253. if (err == noErr)
  185254. return dataRef;
  185255. }
  185256. DisposeHandle (dataRef);
  185257. }
  185258. return 0;
  185259. }
  185260. static CFStringRef juceStringToCFString (const String& s)
  185261. {
  185262. const int len = s.length();
  185263. const juce_wchar* const t = (const juce_wchar*) s;
  185264. HeapBlock <UniChar> temp (len + 2);
  185265. for (int i = 0; i <= len; ++i)
  185266. temp[i] = t[i];
  185267. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  185268. }
  185269. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  185270. {
  185271. Boolean trueBool = true;
  185272. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185273. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  185274. props[prop].propValueSize = sizeof (trueBool);
  185275. props[prop].propValueAddress = &trueBool;
  185276. ++prop;
  185277. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185278. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  185279. props[prop].propValueSize = sizeof (trueBool);
  185280. props[prop].propValueAddress = &trueBool;
  185281. ++prop;
  185282. Boolean isActive = true;
  185283. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  185284. props[prop].propID = kQTNewMoviePropertyID_Active;
  185285. props[prop].propValueSize = sizeof (isActive);
  185286. props[prop].propValueAddress = &isActive;
  185287. ++prop;
  185288. MacSetPort (0);
  185289. jassert (prop <= 5);
  185290. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  185291. return err == noErr;
  185292. }
  185293. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  185294. {
  185295. if (input == 0)
  185296. return false;
  185297. dataHandle = 0;
  185298. bool ok = false;
  185299. QTNewMoviePropertyElement props[5];
  185300. zeromem (props, sizeof (props));
  185301. int prop = 0;
  185302. DataReferenceRecord dr;
  185303. props[prop].propClass = kQTPropertyClass_DataLocation;
  185304. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  185305. props[prop].propValueSize = sizeof (dr);
  185306. props[prop].propValueAddress = (void*) &dr;
  185307. ++prop;
  185308. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  185309. if (fin != 0)
  185310. {
  185311. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  185312. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  185313. &dr.dataRef, &dr.dataRefType);
  185314. ok = openMovie (props, prop, movie);
  185315. DisposeHandle (dr.dataRef);
  185316. CFRelease (filePath);
  185317. }
  185318. else
  185319. {
  185320. // sanity-check because this currently needs to load the whole stream into memory..
  185321. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  185322. dataHandle = NewHandle ((Size) input->getTotalLength());
  185323. HLock (dataHandle);
  185324. // read the entire stream into memory - this is a pain, but can't get it to work
  185325. // properly using a custom callback to supply the data.
  185326. input->read (*dataHandle, (int) input->getTotalLength());
  185327. HUnlock (dataHandle);
  185328. // different types to get QT to try. (We should really be a bit smarter here by
  185329. // working out in advance which one the stream contains, rather than just trying
  185330. // each one)
  185331. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  185332. "\04.avi", "\04.m4a" };
  185333. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  185334. {
  185335. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  185336. dr.dataRefType = HandleDataHandlerSubType;
  185337. ok = openMovie (props, prop, movie);
  185338. DisposeHandle (dr.dataRef);
  185339. }
  185340. }
  185341. return ok;
  185342. }
  185343. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  185344. const bool isControllerVisible)
  185345. {
  185346. const bool ok = loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible);
  185347. movieFile = movieFile_;
  185348. return ok;
  185349. }
  185350. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  185351. const bool isControllerVisible)
  185352. {
  185353. return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible);
  185354. }
  185355. void QuickTimeMovieComponent::goToStart()
  185356. {
  185357. setPosition (0.0);
  185358. }
  185359. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  185360. const RectanglePlacement& placement)
  185361. {
  185362. int normalWidth, normalHeight;
  185363. getMovieNormalSize (normalWidth, normalHeight);
  185364. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185365. {
  185366. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185367. placement.applyTo (x, y, w, h,
  185368. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185369. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185370. if (w > 0 && h > 0)
  185371. {
  185372. setBounds (roundToInt (x), roundToInt (y),
  185373. roundToInt (w), roundToInt (h));
  185374. }
  185375. }
  185376. else
  185377. {
  185378. setBounds (spaceToFitWithin);
  185379. }
  185380. }
  185381. #endif
  185382. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185383. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185384. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185385. // compiled on its own).
  185386. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185387. class WebBrowserComponentInternal : public ActiveXControlComponent
  185388. {
  185389. public:
  185390. WebBrowserComponentInternal()
  185391. : browser (0),
  185392. connectionPoint (0),
  185393. adviseCookie (0)
  185394. {
  185395. }
  185396. ~WebBrowserComponentInternal()
  185397. {
  185398. if (connectionPoint != 0)
  185399. connectionPoint->Unadvise (adviseCookie);
  185400. if (browser != 0)
  185401. browser->Release();
  185402. }
  185403. void createBrowser()
  185404. {
  185405. createControl (&CLSID_WebBrowser);
  185406. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185407. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185408. if (connectionPointContainer != 0)
  185409. {
  185410. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185411. &connectionPoint);
  185412. if (connectionPoint != 0)
  185413. {
  185414. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185415. jassert (owner != 0);
  185416. EventHandler* handler = new EventHandler (owner);
  185417. connectionPoint->Advise (handler, &adviseCookie);
  185418. }
  185419. }
  185420. }
  185421. void goToURL (const String& url,
  185422. const StringArray* headers,
  185423. const MemoryBlock* postData)
  185424. {
  185425. if (browser != 0)
  185426. {
  185427. LPSAFEARRAY sa = 0;
  185428. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185429. VariantInit (&flags);
  185430. VariantInit (&frame);
  185431. VariantInit (&postDataVar);
  185432. VariantInit (&headersVar);
  185433. if (headers != 0)
  185434. {
  185435. V_VT (&headersVar) = VT_BSTR;
  185436. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185437. }
  185438. if (postData != 0 && postData->getSize() > 0)
  185439. {
  185440. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185441. if (sa != 0)
  185442. {
  185443. void* data = 0;
  185444. SafeArrayAccessData (sa, &data);
  185445. jassert (data != 0);
  185446. if (data != 0)
  185447. {
  185448. postData->copyTo (data, 0, postData->getSize());
  185449. SafeArrayUnaccessData (sa);
  185450. VARIANT postDataVar2;
  185451. VariantInit (&postDataVar2);
  185452. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185453. V_ARRAY (&postDataVar2) = sa;
  185454. postDataVar = postDataVar2;
  185455. }
  185456. }
  185457. }
  185458. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185459. &flags, &frame,
  185460. &postDataVar, &headersVar);
  185461. if (sa != 0)
  185462. SafeArrayDestroy (sa);
  185463. VariantClear (&flags);
  185464. VariantClear (&frame);
  185465. VariantClear (&postDataVar);
  185466. VariantClear (&headersVar);
  185467. }
  185468. }
  185469. IWebBrowser2* browser;
  185470. juce_UseDebuggingNewOperator
  185471. private:
  185472. IConnectionPoint* connectionPoint;
  185473. DWORD adviseCookie;
  185474. class EventHandler : public IDispatch,
  185475. public ComponentMovementWatcher
  185476. {
  185477. public:
  185478. EventHandler (WebBrowserComponent* owner_)
  185479. : ComponentMovementWatcher (owner_),
  185480. owner (owner_),
  185481. refCount (0)
  185482. {
  185483. }
  185484. ~EventHandler()
  185485. {
  185486. }
  185487. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185488. {
  185489. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185490. {
  185491. AddRef();
  185492. *result = this;
  185493. return S_OK;
  185494. }
  185495. *result = 0;
  185496. return E_NOINTERFACE;
  185497. }
  185498. ULONG __stdcall AddRef() { return ++refCount; }
  185499. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185500. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185501. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185502. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185503. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185504. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185505. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185506. UINT __RPC_FAR* /*puArgErr*/)
  185507. {
  185508. switch (dispIdMember)
  185509. {
  185510. case DISPID_BEFORENAVIGATE2:
  185511. {
  185512. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185513. String url;
  185514. if ((vurl->vt & VT_BYREF) != 0)
  185515. url = *vurl->pbstrVal;
  185516. else
  185517. url = vurl->bstrVal;
  185518. *pDispParams->rgvarg->pboolVal
  185519. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185520. : VARIANT_TRUE;
  185521. return S_OK;
  185522. }
  185523. default:
  185524. break;
  185525. }
  185526. return E_NOTIMPL;
  185527. }
  185528. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185529. void componentPeerChanged() {}
  185530. void componentVisibilityChanged (Component&)
  185531. {
  185532. owner->visibilityChanged();
  185533. }
  185534. juce_UseDebuggingNewOperator
  185535. private:
  185536. WebBrowserComponent* const owner;
  185537. int refCount;
  185538. EventHandler (const EventHandler&);
  185539. const EventHandler& operator= (const EventHandler&);
  185540. };
  185541. };
  185542. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185543. : browser (0),
  185544. blankPageShown (false),
  185545. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185546. {
  185547. setOpaque (true);
  185548. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185549. }
  185550. WebBrowserComponent::~WebBrowserComponent()
  185551. {
  185552. delete browser;
  185553. }
  185554. void WebBrowserComponent::goToURL (const String& url,
  185555. const StringArray* headers,
  185556. const MemoryBlock* postData)
  185557. {
  185558. lastURL = url;
  185559. lastHeaders.clear();
  185560. if (headers != 0)
  185561. lastHeaders = *headers;
  185562. lastPostData.setSize (0);
  185563. if (postData != 0)
  185564. lastPostData = *postData;
  185565. blankPageShown = false;
  185566. browser->goToURL (url, headers, postData);
  185567. }
  185568. void WebBrowserComponent::stop()
  185569. {
  185570. if (browser->browser != 0)
  185571. browser->browser->Stop();
  185572. }
  185573. void WebBrowserComponent::goBack()
  185574. {
  185575. lastURL = String::empty;
  185576. blankPageShown = false;
  185577. if (browser->browser != 0)
  185578. browser->browser->GoBack();
  185579. }
  185580. void WebBrowserComponent::goForward()
  185581. {
  185582. lastURL = String::empty;
  185583. if (browser->browser != 0)
  185584. browser->browser->GoForward();
  185585. }
  185586. void WebBrowserComponent::refresh()
  185587. {
  185588. if (browser->browser != 0)
  185589. browser->browser->Refresh();
  185590. }
  185591. void WebBrowserComponent::paint (Graphics& g)
  185592. {
  185593. if (browser->browser == 0)
  185594. g.fillAll (Colours::white);
  185595. }
  185596. void WebBrowserComponent::checkWindowAssociation()
  185597. {
  185598. if (isShowing())
  185599. {
  185600. if (browser->browser == 0 && getPeer() != 0)
  185601. {
  185602. browser->createBrowser();
  185603. reloadLastURL();
  185604. }
  185605. else
  185606. {
  185607. if (blankPageShown)
  185608. goBack();
  185609. }
  185610. }
  185611. else
  185612. {
  185613. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185614. {
  185615. // when the component becomes invisible, some stuff like flash
  185616. // carries on playing audio, so we need to force it onto a blank
  185617. // page to avoid this..
  185618. blankPageShown = true;
  185619. browser->goToURL ("about:blank", 0, 0);
  185620. }
  185621. }
  185622. }
  185623. void WebBrowserComponent::reloadLastURL()
  185624. {
  185625. if (lastURL.isNotEmpty())
  185626. {
  185627. goToURL (lastURL, &lastHeaders, &lastPostData);
  185628. lastURL = String::empty;
  185629. }
  185630. }
  185631. void WebBrowserComponent::parentHierarchyChanged()
  185632. {
  185633. checkWindowAssociation();
  185634. }
  185635. void WebBrowserComponent::resized()
  185636. {
  185637. browser->setSize (getWidth(), getHeight());
  185638. }
  185639. void WebBrowserComponent::visibilityChanged()
  185640. {
  185641. checkWindowAssociation();
  185642. }
  185643. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185644. {
  185645. return true;
  185646. }
  185647. #endif
  185648. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185649. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185650. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185651. // compiled on its own).
  185652. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185653. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185654. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185655. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185656. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185657. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185658. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185659. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185660. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185661. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185662. #define WGL_ACCELERATION_ARB 0x2003
  185663. #define WGL_SWAP_METHOD_ARB 0x2007
  185664. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185665. #define WGL_PIXEL_TYPE_ARB 0x2013
  185666. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185667. #define WGL_COLOR_BITS_ARB 0x2014
  185668. #define WGL_RED_BITS_ARB 0x2015
  185669. #define WGL_GREEN_BITS_ARB 0x2017
  185670. #define WGL_BLUE_BITS_ARB 0x2019
  185671. #define WGL_ALPHA_BITS_ARB 0x201B
  185672. #define WGL_DEPTH_BITS_ARB 0x2022
  185673. #define WGL_STENCIL_BITS_ARB 0x2023
  185674. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185675. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185676. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185677. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185678. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185679. #define WGL_STEREO_ARB 0x2012
  185680. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185681. #define WGL_SAMPLES_ARB 0x2042
  185682. #define WGL_TYPE_RGBA_ARB 0x202B
  185683. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185684. {
  185685. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185686. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185687. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185688. else
  185689. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185690. }
  185691. class WindowedGLContext : public OpenGLContext
  185692. {
  185693. public:
  185694. WindowedGLContext (Component* const component_,
  185695. HGLRC contextToShareWith,
  185696. const OpenGLPixelFormat& pixelFormat)
  185697. : renderContext (0),
  185698. nativeWindow (0),
  185699. dc (0),
  185700. component (component_)
  185701. {
  185702. jassert (component != 0);
  185703. createNativeWindow();
  185704. // Use a default pixel format that should be supported everywhere
  185705. PIXELFORMATDESCRIPTOR pfd;
  185706. zerostruct (pfd);
  185707. pfd.nSize = sizeof (pfd);
  185708. pfd.nVersion = 1;
  185709. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185710. pfd.iPixelType = PFD_TYPE_RGBA;
  185711. pfd.cColorBits = 24;
  185712. pfd.cDepthBits = 16;
  185713. const int format = ChoosePixelFormat (dc, &pfd);
  185714. if (format != 0)
  185715. SetPixelFormat (dc, format, &pfd);
  185716. renderContext = wglCreateContext (dc);
  185717. makeActive();
  185718. setPixelFormat (pixelFormat);
  185719. if (contextToShareWith != 0 && renderContext != 0)
  185720. wglShareLists (contextToShareWith, renderContext);
  185721. }
  185722. ~WindowedGLContext()
  185723. {
  185724. makeInactive();
  185725. wglDeleteContext (renderContext);
  185726. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185727. delete nativeWindow;
  185728. }
  185729. bool makeActive() const throw()
  185730. {
  185731. jassert (renderContext != 0);
  185732. return wglMakeCurrent (dc, renderContext) != 0;
  185733. }
  185734. bool makeInactive() const throw()
  185735. {
  185736. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185737. }
  185738. bool isActive() const throw()
  185739. {
  185740. return wglGetCurrentContext() == renderContext;
  185741. }
  185742. const OpenGLPixelFormat getPixelFormat() const
  185743. {
  185744. OpenGLPixelFormat pf;
  185745. makeActive();
  185746. StringArray availableExtensions;
  185747. getWglExtensions (dc, availableExtensions);
  185748. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185749. return pf;
  185750. }
  185751. void* getRawContext() const throw()
  185752. {
  185753. return renderContext;
  185754. }
  185755. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185756. {
  185757. makeActive();
  185758. PIXELFORMATDESCRIPTOR pfd;
  185759. zerostruct (pfd);
  185760. pfd.nSize = sizeof (pfd);
  185761. pfd.nVersion = 1;
  185762. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185763. pfd.iPixelType = PFD_TYPE_RGBA;
  185764. pfd.iLayerType = PFD_MAIN_PLANE;
  185765. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185766. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185767. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185768. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185769. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185770. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185771. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185772. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185773. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185774. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185775. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185776. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185777. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185778. int format = 0;
  185779. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185780. StringArray availableExtensions;
  185781. getWglExtensions (dc, availableExtensions);
  185782. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185783. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185784. {
  185785. int attributes[64];
  185786. int n = 0;
  185787. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185788. attributes[n++] = GL_TRUE;
  185789. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185790. attributes[n++] = GL_TRUE;
  185791. attributes[n++] = WGL_ACCELERATION_ARB;
  185792. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185793. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185794. attributes[n++] = GL_TRUE;
  185795. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185796. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185797. attributes[n++] = WGL_COLOR_BITS_ARB;
  185798. attributes[n++] = pfd.cColorBits;
  185799. attributes[n++] = WGL_RED_BITS_ARB;
  185800. attributes[n++] = pixelFormat.redBits;
  185801. attributes[n++] = WGL_GREEN_BITS_ARB;
  185802. attributes[n++] = pixelFormat.greenBits;
  185803. attributes[n++] = WGL_BLUE_BITS_ARB;
  185804. attributes[n++] = pixelFormat.blueBits;
  185805. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185806. attributes[n++] = pixelFormat.alphaBits;
  185807. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185808. attributes[n++] = pixelFormat.depthBufferBits;
  185809. if (pixelFormat.stencilBufferBits > 0)
  185810. {
  185811. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185812. attributes[n++] = pixelFormat.stencilBufferBits;
  185813. }
  185814. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185815. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185816. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185817. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185818. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185819. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185820. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185821. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185822. if (availableExtensions.contains ("WGL_ARB_multisample")
  185823. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185824. {
  185825. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185826. attributes[n++] = 1;
  185827. attributes[n++] = WGL_SAMPLES_ARB;
  185828. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185829. }
  185830. attributes[n++] = 0;
  185831. UINT formatsCount;
  185832. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185833. (void) ok;
  185834. jassert (ok);
  185835. }
  185836. else
  185837. {
  185838. format = ChoosePixelFormat (dc, &pfd);
  185839. }
  185840. if (format != 0)
  185841. {
  185842. makeInactive();
  185843. // win32 can't change the pixel format of a window, so need to delete the
  185844. // old one and create a new one..
  185845. jassert (nativeWindow != 0);
  185846. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185847. delete nativeWindow;
  185848. createNativeWindow();
  185849. if (SetPixelFormat (dc, format, &pfd))
  185850. {
  185851. wglDeleteContext (renderContext);
  185852. renderContext = wglCreateContext (dc);
  185853. jassert (renderContext != 0);
  185854. return renderContext != 0;
  185855. }
  185856. }
  185857. return false;
  185858. }
  185859. void updateWindowPosition (int x, int y, int w, int h, int)
  185860. {
  185861. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185862. x, y, w, h,
  185863. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185864. }
  185865. void repaint()
  185866. {
  185867. int x, y, w, h;
  185868. nativeWindow->getBounds (x, y, w, h);
  185869. nativeWindow->repaint (0, 0, w, h);
  185870. }
  185871. void swapBuffers()
  185872. {
  185873. SwapBuffers (dc);
  185874. }
  185875. bool setSwapInterval (const int numFramesPerSwap)
  185876. {
  185877. makeActive();
  185878. StringArray availableExtensions;
  185879. getWglExtensions (dc, availableExtensions);
  185880. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185881. return availableExtensions.contains ("WGL_EXT_swap_control")
  185882. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185883. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185884. }
  185885. int getSwapInterval() const
  185886. {
  185887. makeActive();
  185888. StringArray availableExtensions;
  185889. getWglExtensions (dc, availableExtensions);
  185890. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185891. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185892. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185893. return wglGetSwapIntervalEXT();
  185894. return 0;
  185895. }
  185896. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185897. {
  185898. jassert (isActive());
  185899. StringArray availableExtensions;
  185900. getWglExtensions (dc, availableExtensions);
  185901. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185902. int numTypes = 0;
  185903. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185904. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185905. {
  185906. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185907. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185908. jassertfalse
  185909. }
  185910. else
  185911. {
  185912. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185913. }
  185914. OpenGLPixelFormat pf;
  185915. for (int i = 0; i < numTypes; ++i)
  185916. {
  185917. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185918. {
  185919. bool alreadyListed = false;
  185920. for (int j = results.size(); --j >= 0;)
  185921. if (pf == *results.getUnchecked(j))
  185922. alreadyListed = true;
  185923. if (! alreadyListed)
  185924. results.add (new OpenGLPixelFormat (pf));
  185925. }
  185926. }
  185927. }
  185928. void* getNativeWindowHandle() const
  185929. {
  185930. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185931. }
  185932. juce_UseDebuggingNewOperator
  185933. HGLRC renderContext;
  185934. private:
  185935. Win32ComponentPeer* nativeWindow;
  185936. Component* const component;
  185937. HDC dc;
  185938. void createNativeWindow()
  185939. {
  185940. nativeWindow = new Win32ComponentPeer (component, 0);
  185941. nativeWindow->dontRepaint = true;
  185942. nativeWindow->setVisible (true);
  185943. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185944. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185945. if (peer != 0)
  185946. {
  185947. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185948. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185949. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185950. }
  185951. dc = GetDC (hwnd);
  185952. }
  185953. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185954. OpenGLPixelFormat& result,
  185955. const StringArray& availableExtensions) const throw()
  185956. {
  185957. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185958. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185959. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185960. {
  185961. int attributes[32];
  185962. int numAttributes = 0;
  185963. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185964. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185965. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185966. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185967. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185968. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185969. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185970. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185971. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185972. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185973. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185974. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185975. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185976. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185977. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185978. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185979. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185980. int values[32];
  185981. zeromem (values, sizeof (values));
  185982. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185983. {
  185984. int n = 0;
  185985. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185986. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185987. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185988. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185989. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185990. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185991. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185992. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185993. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185994. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185995. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185996. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185997. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185998. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185999. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  186000. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  186001. return isValidFormat;
  186002. }
  186003. else
  186004. {
  186005. jassertfalse
  186006. }
  186007. }
  186008. else
  186009. {
  186010. PIXELFORMATDESCRIPTOR pfd;
  186011. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  186012. {
  186013. result.redBits = pfd.cRedBits;
  186014. result.greenBits = pfd.cGreenBits;
  186015. result.blueBits = pfd.cBlueBits;
  186016. result.alphaBits = pfd.cAlphaBits;
  186017. result.depthBufferBits = pfd.cDepthBits;
  186018. result.stencilBufferBits = pfd.cStencilBits;
  186019. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  186020. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  186021. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  186022. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  186023. result.fullSceneAntiAliasingNumSamples = 0;
  186024. return true;
  186025. }
  186026. else
  186027. {
  186028. jassertfalse
  186029. }
  186030. }
  186031. return false;
  186032. }
  186033. WindowedGLContext (const WindowedGLContext&);
  186034. const WindowedGLContext& operator= (const WindowedGLContext&);
  186035. };
  186036. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  186037. const OpenGLPixelFormat& pixelFormat,
  186038. const OpenGLContext* const contextToShareWith)
  186039. {
  186040. WindowedGLContext* c = new WindowedGLContext (component,
  186041. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  186042. pixelFormat);
  186043. if (c->renderContext == 0)
  186044. deleteAndZero (c);
  186045. return c;
  186046. }
  186047. void* OpenGLComponent::getNativeWindowHandle() const
  186048. {
  186049. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  186050. }
  186051. void juce_glViewport (const int w, const int h)
  186052. {
  186053. glViewport (0, 0, w, h);
  186054. }
  186055. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  186056. OwnedArray <OpenGLPixelFormat>& results)
  186057. {
  186058. Component tempComp;
  186059. {
  186060. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  186061. wc.makeActive();
  186062. wc.findAlternativeOpenGLPixelFormats (results);
  186063. }
  186064. }
  186065. #endif
  186066. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  186067. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  186068. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  186069. // compiled on its own).
  186070. #if JUCE_INCLUDED_FILE
  186071. #if JUCE_USE_CDREADER
  186072. //***************************************************************************
  186073. // %%% TARGET STATUS VALUES %%%
  186074. //***************************************************************************
  186075. #define STATUS_GOOD 0x00 // Status Good
  186076. #define STATUS_CHKCOND 0x02 // Check Condition
  186077. #define STATUS_CONDMET 0x04 // Condition Met
  186078. #define STATUS_BUSY 0x08 // Busy
  186079. #define STATUS_INTERM 0x10 // Intermediate
  186080. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  186081. #define STATUS_RESCONF 0x18 // Reservation conflict
  186082. #define STATUS_COMTERM 0x22 // Command Terminated
  186083. #define STATUS_QFULL 0x28 // Queue full
  186084. //***************************************************************************
  186085. // %%% SCSI MISCELLANEOUS EQUATES %%%
  186086. //***************************************************************************
  186087. #define MAXLUN 7 // Maximum Logical Unit Id
  186088. #define MAXTARG 7 // Maximum Target Id
  186089. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  186090. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  186091. //***************************************************************************
  186092. // %%% Commands for all Device Types %%%
  186093. //***************************************************************************
  186094. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  186095. #define SCSI_COMPARE 0x39 // Compare (O)
  186096. #define SCSI_COPY 0x18 // Copy (O)
  186097. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  186098. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  186099. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  186100. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  186101. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  186102. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  186103. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  186104. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  186105. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  186106. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  186107. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  186108. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  186109. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  186110. //***************************************************************************
  186111. // %%% Commands Unique to Direct Access Devices %%%
  186112. //***************************************************************************
  186113. #define SCSI_COMPARE 0x39 // Compare (O)
  186114. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  186115. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  186116. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  186117. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  186118. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  186119. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  186120. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  186121. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  186122. #define SCSI_READ_LONG 0x3E // Read Long (O)
  186123. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  186124. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  186125. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  186126. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  186127. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  186128. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  186129. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  186130. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  186131. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  186132. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  186133. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  186134. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  186135. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  186136. #define SCSI_VERIFY 0x2F // Verify (O)
  186137. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  186138. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  186139. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  186140. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  186141. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  186142. //***************************************************************************
  186143. // %%% Commands Unique to Sequential Access Devices %%%
  186144. //***************************************************************************
  186145. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  186146. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  186147. #define SCSI_LOCATE 0x2B // Locate (O)
  186148. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  186149. #define SCSI_READ_POS 0x34 // Read Position (O)
  186150. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  186151. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  186152. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  186153. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  186154. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  186155. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  186156. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  186157. //***************************************************************************
  186158. // %%% Commands Unique to Printer Devices %%%
  186159. //***************************************************************************
  186160. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  186161. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  186162. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  186163. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  186164. //***************************************************************************
  186165. // %%% Commands Unique to Processor Devices %%%
  186166. //***************************************************************************
  186167. #define SCSI_RECEIVE 0x08 // Receive (O)
  186168. #define SCSI_SEND 0x0A // Send (O)
  186169. //***************************************************************************
  186170. // %%% Commands Unique to Write-Once Devices %%%
  186171. //***************************************************************************
  186172. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  186173. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  186174. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  186175. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  186176. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  186177. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  186178. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  186179. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  186180. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  186181. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  186182. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  186183. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  186184. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  186185. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  186186. //***************************************************************************
  186187. // %%% Commands Unique to CD-ROM Devices %%%
  186188. //***************************************************************************
  186189. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  186190. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  186191. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  186192. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  186193. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  186194. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  186195. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  186196. #define SCSI_READHEADER 0x44 // Read Header (O)
  186197. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  186198. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  186199. //***************************************************************************
  186200. // %%% Commands Unique to Scanner Devices %%%
  186201. //***************************************************************************
  186202. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  186203. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  186204. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  186205. #define SCSI_SCAN 0x1B // Scan (O)
  186206. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  186207. //***************************************************************************
  186208. // %%% Commands Unique to Optical Memory Devices %%%
  186209. //***************************************************************************
  186210. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  186211. //***************************************************************************
  186212. // %%% Commands Unique to Medium Changer Devices %%%
  186213. //***************************************************************************
  186214. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  186215. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  186216. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  186217. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  186218. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  186219. //***************************************************************************
  186220. // %%% Commands Unique to Communication Devices %%%
  186221. //***************************************************************************
  186222. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  186223. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  186224. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  186225. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  186226. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  186227. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  186228. //***************************************************************************
  186229. // %%% Request Sense Data Format %%%
  186230. //***************************************************************************
  186231. typedef struct {
  186232. BYTE ErrorCode; // Error Code (70H or 71H)
  186233. BYTE SegmentNum; // Number of current segment descriptor
  186234. BYTE SenseKey; // Sense Key(See bit definitions too)
  186235. BYTE InfoByte0; // Information MSB
  186236. BYTE InfoByte1; // Information MID
  186237. BYTE InfoByte2; // Information MID
  186238. BYTE InfoByte3; // Information LSB
  186239. BYTE AddSenLen; // Additional Sense Length
  186240. BYTE ComSpecInf0; // Command Specific Information MSB
  186241. BYTE ComSpecInf1; // Command Specific Information MID
  186242. BYTE ComSpecInf2; // Command Specific Information MID
  186243. BYTE ComSpecInf3; // Command Specific Information LSB
  186244. BYTE AddSenseCode; // Additional Sense Code
  186245. BYTE AddSenQual; // Additional Sense Code Qualifier
  186246. BYTE FieldRepUCode; // Field Replaceable Unit Code
  186247. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  186248. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  186249. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  186250. BYTE AddSenseBytes; // Additional Sense Bytes
  186251. } SENSE_DATA_FMT;
  186252. //***************************************************************************
  186253. // %%% REQUEST SENSE ERROR CODE %%%
  186254. //***************************************************************************
  186255. #define SERROR_CURRENT 0x70 // Current Errors
  186256. #define SERROR_DEFERED 0x71 // Deferred Errors
  186257. //***************************************************************************
  186258. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  186259. //***************************************************************************
  186260. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  186261. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  186262. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  186263. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  186264. //***************************************************************************
  186265. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  186266. //***************************************************************************
  186267. #define KEY_NOSENSE 0x00 // No Sense
  186268. #define KEY_RECERROR 0x01 // Recovered Error
  186269. #define KEY_NOTREADY 0x02 // Not Ready
  186270. #define KEY_MEDIUMERR 0x03 // Medium Error
  186271. #define KEY_HARDERROR 0x04 // Hardware Error
  186272. #define KEY_ILLGLREQ 0x05 // Illegal Request
  186273. #define KEY_UNITATT 0x06 // Unit Attention
  186274. #define KEY_DATAPROT 0x07 // Data Protect
  186275. #define KEY_BLANKCHK 0x08 // Blank Check
  186276. #define KEY_VENDSPEC 0x09 // Vendor Specific
  186277. #define KEY_COPYABORT 0x0A // Copy Abort
  186278. #define KEY_EQUAL 0x0C // Equal (Search)
  186279. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  186280. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  186281. #define KEY_RESERVED 0x0F // Reserved
  186282. //***************************************************************************
  186283. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  186284. //***************************************************************************
  186285. #define DTYPE_DASD 0x00 // Disk Device
  186286. #define DTYPE_SEQD 0x01 // Tape Device
  186287. #define DTYPE_PRNT 0x02 // Printer
  186288. #define DTYPE_PROC 0x03 // Processor
  186289. #define DTYPE_WORM 0x04 // Write-once read-multiple
  186290. #define DTYPE_CROM 0x05 // CD-ROM device
  186291. #define DTYPE_SCAN 0x06 // Scanner device
  186292. #define DTYPE_OPTI 0x07 // Optical memory device
  186293. #define DTYPE_JUKE 0x08 // Medium Changer device
  186294. #define DTYPE_COMM 0x09 // Communications device
  186295. #define DTYPE_RESL 0x0A // Reserved (low)
  186296. #define DTYPE_RESH 0x1E // Reserved (high)
  186297. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  186298. //***************************************************************************
  186299. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  186300. //***************************************************************************
  186301. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  186302. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  186303. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  186304. #define ANSI_RESLO 0x3 // Reserved (low)
  186305. #define ANSI_RESHI 0x7 // Reserved (high)
  186306. typedef struct
  186307. {
  186308. USHORT Length;
  186309. UCHAR ScsiStatus;
  186310. UCHAR PathId;
  186311. UCHAR TargetId;
  186312. UCHAR Lun;
  186313. UCHAR CdbLength;
  186314. UCHAR SenseInfoLength;
  186315. UCHAR DataIn;
  186316. ULONG DataTransferLength;
  186317. ULONG TimeOutValue;
  186318. ULONG DataBufferOffset;
  186319. ULONG SenseInfoOffset;
  186320. UCHAR Cdb[16];
  186321. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  186322. typedef struct
  186323. {
  186324. USHORT Length;
  186325. UCHAR ScsiStatus;
  186326. UCHAR PathId;
  186327. UCHAR TargetId;
  186328. UCHAR Lun;
  186329. UCHAR CdbLength;
  186330. UCHAR SenseInfoLength;
  186331. UCHAR DataIn;
  186332. ULONG DataTransferLength;
  186333. ULONG TimeOutValue;
  186334. PVOID DataBuffer;
  186335. ULONG SenseInfoOffset;
  186336. UCHAR Cdb[16];
  186337. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  186338. typedef struct
  186339. {
  186340. SCSI_PASS_THROUGH_DIRECT spt;
  186341. ULONG Filler;
  186342. UCHAR ucSenseBuf[32];
  186343. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  186344. typedef struct
  186345. {
  186346. ULONG Length;
  186347. UCHAR PortNumber;
  186348. UCHAR PathId;
  186349. UCHAR TargetId;
  186350. UCHAR Lun;
  186351. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  186352. #define METHOD_BUFFERED 0
  186353. #define METHOD_IN_DIRECT 1
  186354. #define METHOD_OUT_DIRECT 2
  186355. #define METHOD_NEITHER 3
  186356. #define FILE_ANY_ACCESS 0
  186357. #ifndef FILE_READ_ACCESS
  186358. #define FILE_READ_ACCESS (0x0001)
  186359. #endif
  186360. #ifndef FILE_WRITE_ACCESS
  186361. #define FILE_WRITE_ACCESS (0x0002)
  186362. #endif
  186363. #define IOCTL_SCSI_BASE 0x00000004
  186364. #define SCSI_IOCTL_DATA_OUT 0
  186365. #define SCSI_IOCTL_DATA_IN 1
  186366. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186367. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186368. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186369. )
  186370. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186371. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186372. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186373. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186374. #define SENSE_LEN 14
  186375. #define SRB_DIR_SCSI 0x00
  186376. #define SRB_POSTING 0x01
  186377. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186378. #define SRB_DIR_IN 0x08
  186379. #define SRB_DIR_OUT 0x10
  186380. #define SRB_EVENT_NOTIFY 0x40
  186381. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186382. #define MAX_SRB_TIMEOUT 1080001u
  186383. #define DEFAULT_SRB_TIMEOUT 1080001u
  186384. #define SC_HA_INQUIRY 0x00
  186385. #define SC_GET_DEV_TYPE 0x01
  186386. #define SC_EXEC_SCSI_CMD 0x02
  186387. #define SC_ABORT_SRB 0x03
  186388. #define SC_RESET_DEV 0x04
  186389. #define SC_SET_HA_PARMS 0x05
  186390. #define SC_GET_DISK_INFO 0x06
  186391. #define SC_RESCAN_SCSI_BUS 0x07
  186392. #define SC_GETSET_TIMEOUTS 0x08
  186393. #define SS_PENDING 0x00
  186394. #define SS_COMP 0x01
  186395. #define SS_ABORTED 0x02
  186396. #define SS_ABORT_FAIL 0x03
  186397. #define SS_ERR 0x04
  186398. #define SS_INVALID_CMD 0x80
  186399. #define SS_INVALID_HA 0x81
  186400. #define SS_NO_DEVICE 0x82
  186401. #define SS_INVALID_SRB 0xE0
  186402. #define SS_OLD_MANAGER 0xE1
  186403. #define SS_BUFFER_ALIGN 0xE1
  186404. #define SS_ILLEGAL_MODE 0xE2
  186405. #define SS_NO_ASPI 0xE3
  186406. #define SS_FAILED_INIT 0xE4
  186407. #define SS_ASPI_IS_BUSY 0xE5
  186408. #define SS_BUFFER_TO_BIG 0xE6
  186409. #define SS_BUFFER_TOO_BIG 0xE6
  186410. #define SS_MISMATCHED_COMPONENTS 0xE7
  186411. #define SS_NO_ADAPTERS 0xE8
  186412. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186413. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186414. #define SS_BAD_INSTALL 0xEB
  186415. #define HASTAT_OK 0x00
  186416. #define HASTAT_SEL_TO 0x11
  186417. #define HASTAT_DO_DU 0x12
  186418. #define HASTAT_BUS_FREE 0x13
  186419. #define HASTAT_PHASE_ERR 0x14
  186420. #define HASTAT_TIMEOUT 0x09
  186421. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186422. #define HASTAT_MESSAGE_REJECT 0x0D
  186423. #define HASTAT_BUS_RESET 0x0E
  186424. #define HASTAT_PARITY_ERROR 0x0F
  186425. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186426. #define PACKED
  186427. #pragma pack(1)
  186428. typedef struct
  186429. {
  186430. BYTE SRB_Cmd;
  186431. BYTE SRB_Status;
  186432. BYTE SRB_HaID;
  186433. BYTE SRB_Flags;
  186434. DWORD SRB_Hdr_Rsvd;
  186435. BYTE HA_Count;
  186436. BYTE HA_SCSI_ID;
  186437. BYTE HA_ManagerId[16];
  186438. BYTE HA_Identifier[16];
  186439. BYTE HA_Unique[16];
  186440. WORD HA_Rsvd1;
  186441. BYTE pad[20];
  186442. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186443. typedef struct
  186444. {
  186445. BYTE SRB_Cmd;
  186446. BYTE SRB_Status;
  186447. BYTE SRB_HaID;
  186448. BYTE SRB_Flags;
  186449. DWORD SRB_Hdr_Rsvd;
  186450. BYTE SRB_Target;
  186451. BYTE SRB_Lun;
  186452. BYTE SRB_DeviceType;
  186453. BYTE SRB_Rsvd1;
  186454. BYTE pad[68];
  186455. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186456. typedef struct
  186457. {
  186458. BYTE SRB_Cmd;
  186459. BYTE SRB_Status;
  186460. BYTE SRB_HaID;
  186461. BYTE SRB_Flags;
  186462. DWORD SRB_Hdr_Rsvd;
  186463. BYTE SRB_Target;
  186464. BYTE SRB_Lun;
  186465. WORD SRB_Rsvd1;
  186466. DWORD SRB_BufLen;
  186467. BYTE FAR *SRB_BufPointer;
  186468. BYTE SRB_SenseLen;
  186469. BYTE SRB_CDBLen;
  186470. BYTE SRB_HaStat;
  186471. BYTE SRB_TargStat;
  186472. VOID FAR *SRB_PostProc;
  186473. BYTE SRB_Rsvd2[20];
  186474. BYTE CDBByte[16];
  186475. BYTE SenseArea[SENSE_LEN+2];
  186476. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186477. typedef struct
  186478. {
  186479. BYTE SRB_Cmd;
  186480. BYTE SRB_Status;
  186481. BYTE SRB_HaId;
  186482. BYTE SRB_Flags;
  186483. DWORD SRB_Hdr_Rsvd;
  186484. } PACKED SRB, *PSRB, FAR *LPSRB;
  186485. #pragma pack()
  186486. struct CDDeviceInfo
  186487. {
  186488. char vendor[9];
  186489. char productId[17];
  186490. char rev[5];
  186491. char vendorSpec[21];
  186492. BYTE ha;
  186493. BYTE tgt;
  186494. BYTE lun;
  186495. char scsiDriveLetter; // will be 0 if not using scsi
  186496. };
  186497. class CDReadBuffer
  186498. {
  186499. public:
  186500. int startFrame;
  186501. int numFrames;
  186502. int dataStartOffset;
  186503. int dataLength;
  186504. BYTE* buffer;
  186505. int bufferSize;
  186506. int index;
  186507. bool wantsIndex;
  186508. CDReadBuffer (const int numberOfFrames)
  186509. : startFrame (0),
  186510. numFrames (0),
  186511. dataStartOffset (0),
  186512. dataLength (0),
  186513. index (0),
  186514. wantsIndex (false)
  186515. {
  186516. bufferSize = 2352 * numberOfFrames;
  186517. buffer = (BYTE*) malloc (bufferSize);
  186518. }
  186519. ~CDReadBuffer()
  186520. {
  186521. free (buffer);
  186522. }
  186523. bool isZero() const
  186524. {
  186525. BYTE* p = buffer + dataStartOffset;
  186526. for (int i = dataLength; --i >= 0;)
  186527. if (*p++ != 0)
  186528. return false;
  186529. return true;
  186530. }
  186531. };
  186532. class CDDeviceHandle;
  186533. class CDController
  186534. {
  186535. public:
  186536. CDController();
  186537. virtual ~CDController();
  186538. virtual bool read (CDReadBuffer* t) = 0;
  186539. virtual void shutDown();
  186540. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186541. int getLastIndex();
  186542. public:
  186543. bool initialised;
  186544. CDDeviceHandle* deviceInfo;
  186545. int framesToCheck, framesOverlap;
  186546. void prepare (SRB_ExecSCSICmd& s);
  186547. void perform (SRB_ExecSCSICmd& s);
  186548. void setPaused (bool paused);
  186549. };
  186550. #pragma pack(1)
  186551. struct TOCTRACK
  186552. {
  186553. BYTE rsvd;
  186554. BYTE ADR;
  186555. BYTE trackNumber;
  186556. BYTE rsvd2;
  186557. BYTE addr[4];
  186558. };
  186559. struct TOC
  186560. {
  186561. WORD tocLen;
  186562. BYTE firstTrack;
  186563. BYTE lastTrack;
  186564. TOCTRACK tracks[100];
  186565. };
  186566. #pragma pack()
  186567. enum
  186568. {
  186569. READTYPE_ANY = 0,
  186570. READTYPE_ATAPI1 = 1,
  186571. READTYPE_ATAPI2 = 2,
  186572. READTYPE_READ6 = 3,
  186573. READTYPE_READ10 = 4,
  186574. READTYPE_READ_D8 = 5,
  186575. READTYPE_READ_D4 = 6,
  186576. READTYPE_READ_D4_1 = 7,
  186577. READTYPE_READ10_2 = 8
  186578. };
  186579. class CDDeviceHandle
  186580. {
  186581. public:
  186582. CDDeviceHandle (const CDDeviceInfo* const device)
  186583. : scsiHandle (0),
  186584. readType (READTYPE_ANY),
  186585. controller (0)
  186586. {
  186587. memcpy (&info, device, sizeof (info));
  186588. }
  186589. ~CDDeviceHandle()
  186590. {
  186591. if (controller != 0)
  186592. {
  186593. controller->shutDown();
  186594. delete controller;
  186595. }
  186596. if (scsiHandle != 0)
  186597. CloseHandle (scsiHandle);
  186598. }
  186599. bool readTOC (TOC* lpToc, bool useMSF);
  186600. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186601. void openDrawer (bool shouldBeOpen);
  186602. CDDeviceInfo info;
  186603. HANDLE scsiHandle;
  186604. BYTE readType;
  186605. private:
  186606. CDController* controller;
  186607. bool testController (const int readType,
  186608. CDController* const newController,
  186609. CDReadBuffer* const bufferToUse);
  186610. };
  186611. DWORD (*fGetASPI32SupportInfo)(void);
  186612. DWORD (*fSendASPI32Command)(LPSRB);
  186613. static HINSTANCE winAspiLib = 0;
  186614. static bool usingScsi = false;
  186615. static bool initialised = false;
  186616. static bool InitialiseCDRipper()
  186617. {
  186618. if (! initialised)
  186619. {
  186620. initialised = true;
  186621. OSVERSIONINFO info;
  186622. info.dwOSVersionInfoSize = sizeof (info);
  186623. GetVersionEx (&info);
  186624. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186625. if (! usingScsi)
  186626. {
  186627. fGetASPI32SupportInfo = 0;
  186628. fSendASPI32Command = 0;
  186629. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186630. if (winAspiLib != 0)
  186631. {
  186632. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186633. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186634. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186635. return false;
  186636. }
  186637. else
  186638. {
  186639. usingScsi = true;
  186640. }
  186641. }
  186642. }
  186643. return true;
  186644. }
  186645. static void DeinitialiseCDRipper()
  186646. {
  186647. if (winAspiLib != 0)
  186648. {
  186649. fGetASPI32SupportInfo = 0;
  186650. fSendASPI32Command = 0;
  186651. FreeLibrary (winAspiLib);
  186652. winAspiLib = 0;
  186653. }
  186654. initialised = false;
  186655. }
  186656. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186657. {
  186658. TCHAR devicePath[8];
  186659. devicePath[0] = '\\';
  186660. devicePath[1] = '\\';
  186661. devicePath[2] = '.';
  186662. devicePath[3] = '\\';
  186663. devicePath[4] = driveLetter;
  186664. devicePath[5] = ':';
  186665. devicePath[6] = 0;
  186666. OSVERSIONINFO info;
  186667. info.dwOSVersionInfoSize = sizeof (info);
  186668. GetVersionEx (&info);
  186669. DWORD flags = GENERIC_READ;
  186670. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186671. flags = GENERIC_READ | GENERIC_WRITE;
  186672. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186673. if (h == INVALID_HANDLE_VALUE)
  186674. {
  186675. flags ^= GENERIC_WRITE;
  186676. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186677. }
  186678. return h;
  186679. }
  186680. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186681. const char driveLetter,
  186682. HANDLE& deviceHandle,
  186683. const bool retryOnFailure = true)
  186684. {
  186685. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186686. zerostruct (s);
  186687. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186688. s.spt.CdbLength = srb->SRB_CDBLen;
  186689. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186690. ? SCSI_IOCTL_DATA_IN
  186691. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186692. ? SCSI_IOCTL_DATA_OUT
  186693. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186694. s.spt.DataTransferLength = srb->SRB_BufLen;
  186695. s.spt.TimeOutValue = 5;
  186696. s.spt.DataBuffer = srb->SRB_BufPointer;
  186697. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186698. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186699. srb->SRB_Status = SS_ERR;
  186700. srb->SRB_TargStat = 0x0004;
  186701. DWORD bytesReturned = 0;
  186702. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186703. &s, sizeof (s),
  186704. &s, sizeof (s),
  186705. &bytesReturned, 0) != 0)
  186706. {
  186707. srb->SRB_Status = SS_COMP;
  186708. }
  186709. else if (retryOnFailure)
  186710. {
  186711. const DWORD error = GetLastError();
  186712. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186713. {
  186714. if (error != ERROR_INVALID_HANDLE)
  186715. CloseHandle (deviceHandle);
  186716. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186717. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186718. }
  186719. }
  186720. return srb->SRB_Status;
  186721. }
  186722. // Controller types..
  186723. class ControllerType1 : public CDController
  186724. {
  186725. public:
  186726. ControllerType1() {}
  186727. ~ControllerType1() {}
  186728. bool read (CDReadBuffer* rb)
  186729. {
  186730. if (rb->numFrames * 2352 > rb->bufferSize)
  186731. return false;
  186732. SRB_ExecSCSICmd s;
  186733. prepare (s);
  186734. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186735. s.SRB_BufLen = rb->bufferSize;
  186736. s.SRB_BufPointer = rb->buffer;
  186737. s.SRB_CDBLen = 12;
  186738. s.CDBByte[0] = 0xBE;
  186739. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186740. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186741. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186742. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186743. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186744. perform (s);
  186745. if (s.SRB_Status != SS_COMP)
  186746. return false;
  186747. rb->dataLength = rb->numFrames * 2352;
  186748. rb->dataStartOffset = 0;
  186749. return true;
  186750. }
  186751. };
  186752. class ControllerType2 : public CDController
  186753. {
  186754. public:
  186755. ControllerType2() {}
  186756. ~ControllerType2() {}
  186757. void shutDown()
  186758. {
  186759. if (initialised)
  186760. {
  186761. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186762. SRB_ExecSCSICmd s;
  186763. prepare (s);
  186764. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186765. s.SRB_BufLen = 0x0C;
  186766. s.SRB_BufPointer = bufPointer;
  186767. s.SRB_CDBLen = 6;
  186768. s.CDBByte[0] = 0x15;
  186769. s.CDBByte[4] = 0x0C;
  186770. perform (s);
  186771. }
  186772. }
  186773. bool init()
  186774. {
  186775. SRB_ExecSCSICmd s;
  186776. s.SRB_Status = SS_ERR;
  186777. if (deviceInfo->readType == READTYPE_READ10_2)
  186778. {
  186779. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186780. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186781. for (int i = 0; i < 2; ++i)
  186782. {
  186783. prepare (s);
  186784. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186785. s.SRB_BufLen = 0x14;
  186786. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186787. s.SRB_CDBLen = 6;
  186788. s.CDBByte[0] = 0x15;
  186789. s.CDBByte[1] = 0x10;
  186790. s.CDBByte[4] = 0x14;
  186791. perform (s);
  186792. if (s.SRB_Status != SS_COMP)
  186793. return false;
  186794. }
  186795. }
  186796. else
  186797. {
  186798. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186799. prepare (s);
  186800. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186801. s.SRB_BufLen = 0x0C;
  186802. s.SRB_BufPointer = bufPointer;
  186803. s.SRB_CDBLen = 6;
  186804. s.CDBByte[0] = 0x15;
  186805. s.CDBByte[4] = 0x0C;
  186806. perform (s);
  186807. }
  186808. return s.SRB_Status == SS_COMP;
  186809. }
  186810. bool read (CDReadBuffer* rb)
  186811. {
  186812. if (rb->numFrames * 2352 > rb->bufferSize)
  186813. return false;
  186814. if (!initialised)
  186815. {
  186816. initialised = init();
  186817. if (!initialised)
  186818. return false;
  186819. }
  186820. SRB_ExecSCSICmd s;
  186821. prepare (s);
  186822. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186823. s.SRB_BufLen = rb->bufferSize;
  186824. s.SRB_BufPointer = rb->buffer;
  186825. s.SRB_CDBLen = 10;
  186826. s.CDBByte[0] = 0x28;
  186827. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186828. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186829. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186830. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186831. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186832. perform (s);
  186833. if (s.SRB_Status != SS_COMP)
  186834. return false;
  186835. rb->dataLength = rb->numFrames * 2352;
  186836. rb->dataStartOffset = 0;
  186837. return true;
  186838. }
  186839. };
  186840. class ControllerType3 : public CDController
  186841. {
  186842. public:
  186843. ControllerType3() {}
  186844. ~ControllerType3() {}
  186845. bool read (CDReadBuffer* rb)
  186846. {
  186847. if (rb->numFrames * 2352 > rb->bufferSize)
  186848. return false;
  186849. if (!initialised)
  186850. {
  186851. setPaused (false);
  186852. initialised = true;
  186853. }
  186854. SRB_ExecSCSICmd s;
  186855. prepare (s);
  186856. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186857. s.SRB_BufLen = rb->numFrames * 2352;
  186858. s.SRB_BufPointer = rb->buffer;
  186859. s.SRB_CDBLen = 12;
  186860. s.CDBByte[0] = 0xD8;
  186861. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186862. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186863. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186864. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186865. perform (s);
  186866. if (s.SRB_Status != SS_COMP)
  186867. return false;
  186868. rb->dataLength = rb->numFrames * 2352;
  186869. rb->dataStartOffset = 0;
  186870. return true;
  186871. }
  186872. };
  186873. class ControllerType4 : public CDController
  186874. {
  186875. public:
  186876. ControllerType4() {}
  186877. ~ControllerType4() {}
  186878. bool selectD4Mode()
  186879. {
  186880. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186881. SRB_ExecSCSICmd s;
  186882. prepare (s);
  186883. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186884. s.SRB_CDBLen = 6;
  186885. s.SRB_BufLen = 12;
  186886. s.SRB_BufPointer = bufPointer;
  186887. s.CDBByte[0] = 0x15;
  186888. s.CDBByte[1] = 0x10;
  186889. s.CDBByte[4] = 0x08;
  186890. perform (s);
  186891. return s.SRB_Status == SS_COMP;
  186892. }
  186893. bool read (CDReadBuffer* rb)
  186894. {
  186895. if (rb->numFrames * 2352 > rb->bufferSize)
  186896. return false;
  186897. if (!initialised)
  186898. {
  186899. setPaused (true);
  186900. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186901. selectD4Mode();
  186902. initialised = true;
  186903. }
  186904. SRB_ExecSCSICmd s;
  186905. prepare (s);
  186906. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186907. s.SRB_BufLen = rb->bufferSize;
  186908. s.SRB_BufPointer = rb->buffer;
  186909. s.SRB_CDBLen = 10;
  186910. s.CDBByte[0] = 0xD4;
  186911. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186912. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186913. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186914. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186915. perform (s);
  186916. if (s.SRB_Status != SS_COMP)
  186917. return false;
  186918. rb->dataLength = rb->numFrames * 2352;
  186919. rb->dataStartOffset = 0;
  186920. return true;
  186921. }
  186922. };
  186923. CDController::CDController() : initialised (false)
  186924. {
  186925. }
  186926. CDController::~CDController()
  186927. {
  186928. }
  186929. void CDController::prepare (SRB_ExecSCSICmd& s)
  186930. {
  186931. zerostruct (s);
  186932. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186933. s.SRB_HaID = deviceInfo->info.ha;
  186934. s.SRB_Target = deviceInfo->info.tgt;
  186935. s.SRB_Lun = deviceInfo->info.lun;
  186936. s.SRB_SenseLen = SENSE_LEN;
  186937. }
  186938. void CDController::perform (SRB_ExecSCSICmd& s)
  186939. {
  186940. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186941. s.SRB_PostProc = (void*)event;
  186942. ResetEvent (event);
  186943. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186944. deviceInfo->info.scsiDriveLetter,
  186945. deviceInfo->scsiHandle)
  186946. : fSendASPI32Command ((LPSRB)&s);
  186947. if (status == SS_PENDING)
  186948. WaitForSingleObject (event, 4000);
  186949. CloseHandle (event);
  186950. }
  186951. void CDController::setPaused (bool paused)
  186952. {
  186953. SRB_ExecSCSICmd s;
  186954. prepare (s);
  186955. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186956. s.SRB_CDBLen = 10;
  186957. s.CDBByte[0] = 0x4B;
  186958. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186959. perform (s);
  186960. }
  186961. void CDController::shutDown()
  186962. {
  186963. }
  186964. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186965. {
  186966. if (overlapBuffer != 0)
  186967. {
  186968. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186969. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186970. if (doJitter
  186971. && overlapBuffer->startFrame > 0
  186972. && overlapBuffer->numFrames > 0
  186973. && overlapBuffer->dataLength > 0)
  186974. {
  186975. const int numFrames = rb->numFrames;
  186976. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186977. {
  186978. rb->startFrame -= framesOverlap;
  186979. if (framesToCheck < framesOverlap
  186980. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186981. rb->numFrames += framesOverlap;
  186982. }
  186983. else
  186984. {
  186985. overlapBuffer->dataLength = 0;
  186986. overlapBuffer->startFrame = 0;
  186987. overlapBuffer->numFrames = 0;
  186988. }
  186989. }
  186990. if (! read (rb))
  186991. return false;
  186992. if (doJitter)
  186993. {
  186994. const int checkLen = framesToCheck * 2352;
  186995. const int maxToCheck = rb->dataLength - checkLen;
  186996. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186997. return true;
  186998. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186999. bool found = false;
  187000. for (int i = 0; i < maxToCheck; ++i)
  187001. {
  187002. if (!memcmp (p, rb->buffer + i, checkLen))
  187003. {
  187004. i += checkLen;
  187005. rb->dataStartOffset = i;
  187006. rb->dataLength -= i;
  187007. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  187008. found = true;
  187009. break;
  187010. }
  187011. }
  187012. rb->numFrames = rb->dataLength / 2352;
  187013. rb->dataLength = 2352 * rb->numFrames;
  187014. if (!found)
  187015. return false;
  187016. }
  187017. if (canDoJitter)
  187018. {
  187019. memcpy (overlapBuffer->buffer,
  187020. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  187021. 2352 * framesToCheck);
  187022. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  187023. overlapBuffer->numFrames = framesToCheck;
  187024. overlapBuffer->dataLength = 2352 * framesToCheck;
  187025. overlapBuffer->dataStartOffset = 0;
  187026. }
  187027. else
  187028. {
  187029. overlapBuffer->startFrame = 0;
  187030. overlapBuffer->numFrames = 0;
  187031. overlapBuffer->dataLength = 0;
  187032. }
  187033. return true;
  187034. }
  187035. else
  187036. {
  187037. return read (rb);
  187038. }
  187039. }
  187040. int CDController::getLastIndex()
  187041. {
  187042. char qdata[100];
  187043. SRB_ExecSCSICmd s;
  187044. prepare (s);
  187045. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187046. s.SRB_BufLen = sizeof (qdata);
  187047. s.SRB_BufPointer = (BYTE*)qdata;
  187048. s.SRB_CDBLen = 12;
  187049. s.CDBByte[0] = 0x42;
  187050. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  187051. s.CDBByte[2] = 64;
  187052. s.CDBByte[3] = 1; // get current position
  187053. s.CDBByte[7] = 0;
  187054. s.CDBByte[8] = (BYTE)sizeof (qdata);
  187055. perform (s);
  187056. if (s.SRB_Status == SS_COMP)
  187057. return qdata[7];
  187058. return 0;
  187059. }
  187060. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  187061. {
  187062. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187063. SRB_ExecSCSICmd s;
  187064. zerostruct (s);
  187065. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187066. s.SRB_HaID = info.ha;
  187067. s.SRB_Target = info.tgt;
  187068. s.SRB_Lun = info.lun;
  187069. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187070. s.SRB_BufLen = 0x324;
  187071. s.SRB_BufPointer = (BYTE*)lpToc;
  187072. s.SRB_SenseLen = 0x0E;
  187073. s.SRB_CDBLen = 0x0A;
  187074. s.SRB_PostProc = (void*)event;
  187075. s.CDBByte[0] = 0x43;
  187076. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  187077. s.CDBByte[7] = 0x03;
  187078. s.CDBByte[8] = 0x24;
  187079. ResetEvent (event);
  187080. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187081. : fSendASPI32Command ((LPSRB)&s);
  187082. if (status == SS_PENDING)
  187083. WaitForSingleObject (event, 4000);
  187084. CloseHandle (event);
  187085. return (s.SRB_Status == SS_COMP);
  187086. }
  187087. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  187088. CDReadBuffer* const overlapBuffer)
  187089. {
  187090. if (controller == 0)
  187091. {
  187092. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  187093. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  187094. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  187095. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  187096. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  187097. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  187098. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  187099. }
  187100. buffer->index = 0;
  187101. if ((controller != 0)
  187102. && controller->readAudio (buffer, overlapBuffer))
  187103. {
  187104. if (buffer->wantsIndex)
  187105. buffer->index = controller->getLastIndex();
  187106. return true;
  187107. }
  187108. return false;
  187109. }
  187110. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  187111. {
  187112. if (shouldBeOpen)
  187113. {
  187114. if (controller != 0)
  187115. {
  187116. controller->shutDown();
  187117. delete controller;
  187118. controller = 0;
  187119. }
  187120. if (scsiHandle != 0)
  187121. {
  187122. CloseHandle (scsiHandle);
  187123. scsiHandle = 0;
  187124. }
  187125. }
  187126. SRB_ExecSCSICmd s;
  187127. zerostruct (s);
  187128. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187129. s.SRB_HaID = info.ha;
  187130. s.SRB_Target = info.tgt;
  187131. s.SRB_Lun = info.lun;
  187132. s.SRB_SenseLen = SENSE_LEN;
  187133. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187134. s.SRB_BufLen = 0;
  187135. s.SRB_BufPointer = 0;
  187136. s.SRB_CDBLen = 12;
  187137. s.CDBByte[0] = 0x1b;
  187138. s.CDBByte[1] = (BYTE)(info.lun << 5);
  187139. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  187140. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187141. s.SRB_PostProc = (void*)event;
  187142. ResetEvent (event);
  187143. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187144. : fSendASPI32Command ((LPSRB)&s);
  187145. if (status == SS_PENDING)
  187146. WaitForSingleObject (event, 4000);
  187147. CloseHandle (event);
  187148. }
  187149. bool CDDeviceHandle::testController (const int type,
  187150. CDController* const newController,
  187151. CDReadBuffer* const rb)
  187152. {
  187153. controller = newController;
  187154. readType = (BYTE)type;
  187155. controller->deviceInfo = this;
  187156. controller->framesToCheck = 1;
  187157. controller->framesOverlap = 3;
  187158. bool passed = false;
  187159. memset (rb->buffer, 0xcd, rb->bufferSize);
  187160. if (controller->read (rb))
  187161. {
  187162. passed = true;
  187163. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  187164. int wrong = 0;
  187165. for (int i = rb->dataLength / 4; --i >= 0;)
  187166. {
  187167. if (*p++ == (int) 0xcdcdcdcd)
  187168. {
  187169. if (++wrong == 4)
  187170. {
  187171. passed = false;
  187172. break;
  187173. }
  187174. }
  187175. else
  187176. {
  187177. wrong = 0;
  187178. }
  187179. }
  187180. }
  187181. if (! passed)
  187182. {
  187183. controller->shutDown();
  187184. delete controller;
  187185. controller = 0;
  187186. }
  187187. return passed;
  187188. }
  187189. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  187190. {
  187191. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187192. const int bufSize = 128;
  187193. BYTE buffer[bufSize];
  187194. zeromem (buffer, bufSize);
  187195. SRB_ExecSCSICmd s;
  187196. zerostruct (s);
  187197. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187198. s.SRB_HaID = ha;
  187199. s.SRB_Target = tgt;
  187200. s.SRB_Lun = lun;
  187201. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187202. s.SRB_BufLen = bufSize;
  187203. s.SRB_BufPointer = buffer;
  187204. s.SRB_SenseLen = SENSE_LEN;
  187205. s.SRB_CDBLen = 6;
  187206. s.SRB_PostProc = (void*)event;
  187207. s.CDBByte[0] = SCSI_INQUIRY;
  187208. s.CDBByte[4] = 100;
  187209. ResetEvent (event);
  187210. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  187211. WaitForSingleObject (event, 4000);
  187212. CloseHandle (event);
  187213. if (s.SRB_Status == SS_COMP)
  187214. {
  187215. memcpy (dev->vendor, &buffer[8], 8);
  187216. memcpy (dev->productId, &buffer[16], 16);
  187217. memcpy (dev->rev, &buffer[32], 4);
  187218. memcpy (dev->vendorSpec, &buffer[36], 20);
  187219. }
  187220. }
  187221. static int FindCDDevices (CDDeviceInfo* const list,
  187222. int maxItems)
  187223. {
  187224. int count = 0;
  187225. if (usingScsi)
  187226. {
  187227. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  187228. {
  187229. TCHAR drivePath[8];
  187230. drivePath[0] = driveLetter;
  187231. drivePath[1] = ':';
  187232. drivePath[2] = '\\';
  187233. drivePath[3] = 0;
  187234. if (GetDriveType (drivePath) == DRIVE_CDROM)
  187235. {
  187236. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  187237. if (h != INVALID_HANDLE_VALUE)
  187238. {
  187239. BYTE buffer[100], passThroughStruct[1024];
  187240. zeromem (buffer, sizeof (buffer));
  187241. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187242. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  187243. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  187244. p->spt.CdbLength = 6;
  187245. p->spt.SenseInfoLength = 24;
  187246. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  187247. p->spt.DataTransferLength = 100;
  187248. p->spt.TimeOutValue = 2;
  187249. p->spt.DataBuffer = buffer;
  187250. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  187251. p->spt.Cdb[0] = 0x12;
  187252. p->spt.Cdb[4] = 100;
  187253. DWORD bytesReturned = 0;
  187254. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  187255. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187256. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187257. &bytesReturned, 0) != 0)
  187258. {
  187259. zeromem (&list[count], sizeof (CDDeviceInfo));
  187260. list[count].scsiDriveLetter = driveLetter;
  187261. memcpy (list[count].vendor, &buffer[8], 8);
  187262. memcpy (list[count].productId, &buffer[16], 16);
  187263. memcpy (list[count].rev, &buffer[32], 4);
  187264. memcpy (list[count].vendorSpec, &buffer[36], 20);
  187265. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187266. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  187267. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  187268. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  187269. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  187270. &bytesReturned, 0) != 0)
  187271. {
  187272. list[count].ha = scsiAddr->PortNumber;
  187273. list[count].tgt = scsiAddr->TargetId;
  187274. list[count].lun = scsiAddr->Lun;
  187275. ++count;
  187276. }
  187277. }
  187278. CloseHandle (h);
  187279. }
  187280. }
  187281. }
  187282. }
  187283. else
  187284. {
  187285. const DWORD d = fGetASPI32SupportInfo();
  187286. BYTE status = HIBYTE (LOWORD (d));
  187287. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  187288. return 0;
  187289. const int numAdapters = LOBYTE (LOWORD (d));
  187290. for (BYTE ha = 0; ha < numAdapters; ++ha)
  187291. {
  187292. SRB_HAInquiry s;
  187293. zerostruct (s);
  187294. s.SRB_Cmd = SC_HA_INQUIRY;
  187295. s.SRB_HaID = ha;
  187296. fSendASPI32Command ((LPSRB)&s);
  187297. if (s.SRB_Status == SS_COMP)
  187298. {
  187299. maxItems = (int)s.HA_Unique[3];
  187300. if (maxItems == 0)
  187301. maxItems = 8;
  187302. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  187303. {
  187304. for (BYTE lun = 0; lun < 8; ++lun)
  187305. {
  187306. SRB_GDEVBlock sb;
  187307. zerostruct (sb);
  187308. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  187309. sb.SRB_HaID = ha;
  187310. sb.SRB_Target = tgt;
  187311. sb.SRB_Lun = lun;
  187312. fSendASPI32Command ((LPSRB) &sb);
  187313. if (sb.SRB_Status == SS_COMP
  187314. && sb.SRB_DeviceType == DTYPE_CROM)
  187315. {
  187316. zeromem (&list[count], sizeof (CDDeviceInfo));
  187317. list[count].ha = ha;
  187318. list[count].tgt = tgt;
  187319. list[count].lun = lun;
  187320. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  187321. ++count;
  187322. }
  187323. }
  187324. }
  187325. }
  187326. }
  187327. }
  187328. return count;
  187329. }
  187330. static int ripperUsers = 0;
  187331. static bool initialisedOk = false;
  187332. class DeinitialiseTimer : private Timer,
  187333. private DeletedAtShutdown
  187334. {
  187335. DeinitialiseTimer (const DeinitialiseTimer&);
  187336. const DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  187337. public:
  187338. DeinitialiseTimer()
  187339. {
  187340. startTimer (4000);
  187341. }
  187342. ~DeinitialiseTimer()
  187343. {
  187344. if (--ripperUsers == 0)
  187345. DeinitialiseCDRipper();
  187346. }
  187347. void timerCallback()
  187348. {
  187349. delete this;
  187350. }
  187351. juce_UseDebuggingNewOperator
  187352. };
  187353. static void incUserCount()
  187354. {
  187355. if (ripperUsers++ == 0)
  187356. initialisedOk = InitialiseCDRipper();
  187357. }
  187358. static void decUserCount()
  187359. {
  187360. new DeinitialiseTimer();
  187361. }
  187362. struct CDDeviceWrapper
  187363. {
  187364. CDDeviceHandle* cdH;
  187365. CDReadBuffer* overlapBuffer;
  187366. bool jitter;
  187367. };
  187368. static int getAddressOf (const TOCTRACK* const t)
  187369. {
  187370. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187371. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187372. }
  187373. static int getMSFAddressOf (const TOCTRACK* const t)
  187374. {
  187375. return 60 * t->addr[1] + t->addr[2];
  187376. }
  187377. static const int samplesPerFrame = 44100 / 75;
  187378. static const int bytesPerFrame = samplesPerFrame * 4;
  187379. const StringArray AudioCDReader::getAvailableCDNames()
  187380. {
  187381. StringArray results;
  187382. incUserCount();
  187383. if (initialisedOk)
  187384. {
  187385. CDDeviceInfo list[8];
  187386. const int num = FindCDDevices (list, 8);
  187387. decUserCount();
  187388. for (int i = 0; i < num; ++i)
  187389. {
  187390. String s;
  187391. if (list[i].scsiDriveLetter > 0)
  187392. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187393. s << String (list[i].vendor).trim()
  187394. << T(" ") << String (list[i].productId).trim()
  187395. << T(" ") << String (list[i].rev).trim();
  187396. results.add (s);
  187397. }
  187398. }
  187399. return results;
  187400. }
  187401. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187402. {
  187403. SRB_GDEVBlock s;
  187404. zerostruct (s);
  187405. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187406. s.SRB_HaID = device->ha;
  187407. s.SRB_Target = device->tgt;
  187408. s.SRB_Lun = device->lun;
  187409. if (usingScsi)
  187410. {
  187411. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187412. if (h != INVALID_HANDLE_VALUE)
  187413. {
  187414. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187415. cdh->scsiHandle = h;
  187416. return cdh;
  187417. }
  187418. }
  187419. else
  187420. {
  187421. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187422. && s.SRB_DeviceType == DTYPE_CROM)
  187423. {
  187424. return new CDDeviceHandle (device);
  187425. }
  187426. }
  187427. return 0;
  187428. }
  187429. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187430. {
  187431. incUserCount();
  187432. if (initialisedOk)
  187433. {
  187434. CDDeviceInfo list[8];
  187435. const int num = FindCDDevices (list, 8);
  187436. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187437. {
  187438. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187439. if (handle != 0)
  187440. {
  187441. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187442. d->cdH = handle;
  187443. d->overlapBuffer = new CDReadBuffer(3);
  187444. return new AudioCDReader (d);
  187445. }
  187446. }
  187447. }
  187448. decUserCount();
  187449. return 0;
  187450. }
  187451. AudioCDReader::AudioCDReader (void* handle_)
  187452. : AudioFormatReader (0, T("CD Audio")),
  187453. handle (handle_),
  187454. indexingEnabled (false),
  187455. lastIndex (0),
  187456. firstFrameInBuffer (0),
  187457. samplesInBuffer (0)
  187458. {
  187459. jassert (handle_ != 0);
  187460. refreshTrackLengths();
  187461. sampleRate = 44100.0;
  187462. bitsPerSample = 16;
  187463. lengthInSamples = getPositionOfTrackStart (numTracks);
  187464. numChannels = 2;
  187465. usesFloatingPointData = false;
  187466. buffer.setSize (4 * bytesPerFrame, true);
  187467. }
  187468. AudioCDReader::~AudioCDReader()
  187469. {
  187470. CDDeviceWrapper* const device = (CDDeviceWrapper*)handle;
  187471. delete device->cdH;
  187472. delete device->overlapBuffer;
  187473. delete device;
  187474. decUserCount();
  187475. }
  187476. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187477. int64 startSampleInFile, int numSamples)
  187478. {
  187479. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187480. bool ok = true;
  187481. while (numSamples > 0)
  187482. {
  187483. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187484. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187485. if (startSampleInFile >= bufferStartSample
  187486. && startSampleInFile < bufferEndSample)
  187487. {
  187488. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187489. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187490. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187491. const short* src = (const short*) buffer.getData();
  187492. src += 2 * (startSampleInFile - bufferStartSample);
  187493. for (int i = 0; i < toDo; ++i)
  187494. {
  187495. l[i] = src [i << 1] << 16;
  187496. if (r != 0)
  187497. r[i] = src [(i << 1) + 1] << 16;
  187498. }
  187499. startOffsetInDestBuffer += toDo;
  187500. startSampleInFile += toDo;
  187501. numSamples -= toDo;
  187502. }
  187503. else
  187504. {
  187505. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187506. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187507. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187508. {
  187509. device->overlapBuffer->dataLength = 0;
  187510. device->overlapBuffer->startFrame = 0;
  187511. device->overlapBuffer->numFrames = 0;
  187512. device->jitter = false;
  187513. }
  187514. firstFrameInBuffer = frameNeeded;
  187515. lastIndex = 0;
  187516. CDReadBuffer readBuffer (framesInBuffer + 4);
  187517. readBuffer.wantsIndex = indexingEnabled;
  187518. int i;
  187519. for (i = 5; --i >= 0;)
  187520. {
  187521. readBuffer.startFrame = frameNeeded;
  187522. readBuffer.numFrames = framesInBuffer;
  187523. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187524. break;
  187525. else
  187526. device->overlapBuffer->dataLength = 0;
  187527. }
  187528. if (i >= 0)
  187529. {
  187530. memcpy ((char*) buffer.getData(),
  187531. readBuffer.buffer + readBuffer.dataStartOffset,
  187532. readBuffer.dataLength);
  187533. samplesInBuffer = readBuffer.dataLength >> 2;
  187534. lastIndex = readBuffer.index;
  187535. }
  187536. else
  187537. {
  187538. int* l = destSamples[0] + startOffsetInDestBuffer;
  187539. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187540. while (--numSamples >= 0)
  187541. {
  187542. *l++ = 0;
  187543. if (r != 0)
  187544. *r++ = 0;
  187545. }
  187546. // sometimes the read fails for just the very last couple of blocks, so
  187547. // we'll ignore and errors in the last half-second of the disk..
  187548. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187549. break;
  187550. }
  187551. }
  187552. }
  187553. return ok;
  187554. }
  187555. bool AudioCDReader::isCDStillPresent() const
  187556. {
  187557. TOC toc;
  187558. zerostruct (toc);
  187559. return ((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false);
  187560. }
  187561. int AudioCDReader::getNumTracks() const
  187562. {
  187563. return numTracks;
  187564. }
  187565. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187566. {
  187567. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187568. : 0;
  187569. }
  187570. void AudioCDReader::refreshTrackLengths()
  187571. {
  187572. zeromem (trackStarts, sizeof (trackStarts));
  187573. zeromem (audioTracks, sizeof (audioTracks));
  187574. TOC toc;
  187575. zerostruct (toc);
  187576. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187577. {
  187578. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187579. for (int i = 0; i <= numTracks; ++i)
  187580. {
  187581. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187582. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187583. }
  187584. }
  187585. else
  187586. {
  187587. numTracks = 0;
  187588. }
  187589. }
  187590. bool AudioCDReader::isTrackAudio (int trackNum) const
  187591. {
  187592. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187593. : false;
  187594. }
  187595. void AudioCDReader::enableIndexScanning (bool b)
  187596. {
  187597. indexingEnabled = b;
  187598. }
  187599. int AudioCDReader::getLastIndex() const
  187600. {
  187601. return lastIndex;
  187602. }
  187603. const int framesPerIndexRead = 4;
  187604. int AudioCDReader::getIndexAt (int samplePos)
  187605. {
  187606. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187607. const int frameNeeded = samplePos / samplesPerFrame;
  187608. device->overlapBuffer->dataLength = 0;
  187609. device->overlapBuffer->startFrame = 0;
  187610. device->overlapBuffer->numFrames = 0;
  187611. device->jitter = false;
  187612. firstFrameInBuffer = 0;
  187613. lastIndex = 0;
  187614. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187615. readBuffer.wantsIndex = true;
  187616. int i;
  187617. for (i = 5; --i >= 0;)
  187618. {
  187619. readBuffer.startFrame = frameNeeded;
  187620. readBuffer.numFrames = framesPerIndexRead;
  187621. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187622. break;
  187623. }
  187624. if (i >= 0)
  187625. return readBuffer.index;
  187626. return -1;
  187627. }
  187628. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187629. {
  187630. Array <int> indexes;
  187631. const int trackStart = getPositionOfTrackStart (trackNumber);
  187632. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187633. bool needToScan = true;
  187634. if (trackEnd - trackStart > 20 * 44100)
  187635. {
  187636. // check the end of the track for indexes before scanning the whole thing
  187637. needToScan = false;
  187638. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187639. bool seenAnIndex = false;
  187640. while (pos <= trackEnd - samplesPerFrame)
  187641. {
  187642. const int index = getIndexAt (pos);
  187643. if (index == 0)
  187644. {
  187645. // lead-out, so skip back a bit if we've not found any indexes yet..
  187646. if (seenAnIndex)
  187647. break;
  187648. pos -= 44100 * 5;
  187649. if (pos < trackStart)
  187650. break;
  187651. }
  187652. else
  187653. {
  187654. if (index > 0)
  187655. seenAnIndex = true;
  187656. if (index > 1)
  187657. {
  187658. needToScan = true;
  187659. break;
  187660. }
  187661. pos += samplesPerFrame * framesPerIndexRead;
  187662. }
  187663. }
  187664. }
  187665. if (needToScan)
  187666. {
  187667. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187668. int pos = trackStart;
  187669. int last = -1;
  187670. while (pos < trackEnd - samplesPerFrame * 10)
  187671. {
  187672. const int frameNeeded = pos / samplesPerFrame;
  187673. device->overlapBuffer->dataLength = 0;
  187674. device->overlapBuffer->startFrame = 0;
  187675. device->overlapBuffer->numFrames = 0;
  187676. device->jitter = false;
  187677. firstFrameInBuffer = 0;
  187678. CDReadBuffer readBuffer (4);
  187679. readBuffer.wantsIndex = true;
  187680. int i;
  187681. for (i = 5; --i >= 0;)
  187682. {
  187683. readBuffer.startFrame = frameNeeded;
  187684. readBuffer.numFrames = framesPerIndexRead;
  187685. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187686. break;
  187687. }
  187688. if (i < 0)
  187689. break;
  187690. if (readBuffer.index > last && readBuffer.index > 1)
  187691. {
  187692. last = readBuffer.index;
  187693. indexes.add (pos);
  187694. }
  187695. pos += samplesPerFrame * framesPerIndexRead;
  187696. }
  187697. indexes.removeValue (trackStart);
  187698. }
  187699. return indexes;
  187700. }
  187701. int AudioCDReader::getCDDBId()
  187702. {
  187703. refreshTrackLengths();
  187704. if (numTracks > 0)
  187705. {
  187706. TOC toc;
  187707. zerostruct (toc);
  187708. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187709. {
  187710. int n = 0;
  187711. for (int i = numTracks; --i >= 0;)
  187712. {
  187713. int j = getMSFAddressOf (&toc.tracks[i]);
  187714. while (j > 0)
  187715. {
  187716. n += (j % 10);
  187717. j /= 10;
  187718. }
  187719. }
  187720. if (n != 0)
  187721. {
  187722. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187723. - getMSFAddressOf (&toc.tracks[0]);
  187724. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187725. }
  187726. }
  187727. }
  187728. return 0;
  187729. }
  187730. void AudioCDReader::ejectDisk()
  187731. {
  187732. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187733. }
  187734. #endif
  187735. #if JUCE_USE_CDBURNER
  187736. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187737. {
  187738. CoInitialize (0);
  187739. IDiscMaster* dm;
  187740. IDiscRecorder* result = 0;
  187741. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187742. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187743. IID_IDiscMaster,
  187744. (void**) &dm)))
  187745. {
  187746. if (SUCCEEDED (dm->Open()))
  187747. {
  187748. IEnumDiscRecorders* drEnum = 0;
  187749. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187750. {
  187751. IDiscRecorder* dr = 0;
  187752. DWORD dummy;
  187753. int index = 0;
  187754. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187755. {
  187756. if (indexToOpen == index)
  187757. {
  187758. result = dr;
  187759. break;
  187760. }
  187761. else if (list != 0)
  187762. {
  187763. BSTR path;
  187764. if (SUCCEEDED (dr->GetPath (&path)))
  187765. list->add ((const WCHAR*) path);
  187766. }
  187767. ++index;
  187768. dr->Release();
  187769. }
  187770. drEnum->Release();
  187771. }
  187772. if (master == 0)
  187773. dm->Close();
  187774. }
  187775. if (master != 0)
  187776. *master = dm;
  187777. else
  187778. dm->Release();
  187779. }
  187780. return result;
  187781. }
  187782. const StringArray AudioCDBurner::findAvailableDevices()
  187783. {
  187784. StringArray devs;
  187785. enumCDBurners (&devs, -1, 0);
  187786. return devs;
  187787. }
  187788. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187789. {
  187790. AudioCDBurner* b = new AudioCDBurner (deviceIndex);
  187791. if (b->internal == 0)
  187792. deleteAndZero (b);
  187793. return b;
  187794. }
  187795. class CDBurnerInfo : public IDiscMasterProgressEvents
  187796. {
  187797. public:
  187798. CDBurnerInfo()
  187799. : refCount (1),
  187800. progress (0),
  187801. shouldCancel (false),
  187802. listener (0)
  187803. {
  187804. }
  187805. ~CDBurnerInfo()
  187806. {
  187807. }
  187808. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187809. {
  187810. if (result == 0)
  187811. return E_POINTER;
  187812. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187813. {
  187814. AddRef();
  187815. *result = this;
  187816. return S_OK;
  187817. }
  187818. *result = 0;
  187819. return E_NOINTERFACE;
  187820. }
  187821. ULONG __stdcall AddRef() { return ++refCount; }
  187822. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187823. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187824. {
  187825. if (listener != 0 && ! shouldCancel)
  187826. shouldCancel = listener->audioCDBurnProgress (progress);
  187827. *pbCancel = shouldCancel;
  187828. return S_OK;
  187829. }
  187830. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187831. {
  187832. progress = nCompleted / (float) nTotal;
  187833. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187834. return E_NOTIMPL;
  187835. }
  187836. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187837. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187838. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187839. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187840. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187841. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187842. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187843. IDiscMaster* discMaster;
  187844. IDiscRecorder* discRecorder;
  187845. IRedbookDiscMaster* redbook;
  187846. AudioCDBurner::BurnProgressListener* listener;
  187847. float progress;
  187848. bool shouldCancel;
  187849. private:
  187850. int refCount;
  187851. };
  187852. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187853. : internal (0)
  187854. {
  187855. IDiscMaster* discMaster;
  187856. IDiscRecorder* dr = enumCDBurners (0, deviceIndex, &discMaster);
  187857. if (dr != 0)
  187858. {
  187859. IRedbookDiscMaster* redbook;
  187860. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187861. hr = discMaster->SetActiveDiscRecorder (dr);
  187862. CDBurnerInfo* const info = new CDBurnerInfo();
  187863. internal = info;
  187864. info->discMaster = discMaster;
  187865. info->discRecorder = dr;
  187866. info->redbook = redbook;
  187867. }
  187868. }
  187869. AudioCDBurner::~AudioCDBurner()
  187870. {
  187871. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  187872. if (info != 0)
  187873. {
  187874. info->discRecorder->Close();
  187875. info->redbook->Release();
  187876. info->discRecorder->Release();
  187877. info->discMaster->Release();
  187878. info->Release();
  187879. }
  187880. }
  187881. bool AudioCDBurner::isDiskPresent() const
  187882. {
  187883. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  187884. HRESULT hr = info->discRecorder->OpenExclusive();
  187885. long type, flags;
  187886. hr = info->discRecorder->QueryMediaType (&type, &flags);
  187887. info->discRecorder->Close();
  187888. return hr == S_OK && type != 0 && (flags & MEDIA_WRITABLE) != 0;
  187889. }
  187890. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187891. {
  187892. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  187893. long blocksFree = 0;
  187894. info->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187895. return blocksFree;
  187896. }
  187897. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener,
  187898. const bool ejectDiscAfterwards,
  187899. const bool performFakeBurnForTesting)
  187900. {
  187901. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  187902. info->listener = listener;
  187903. info->progress = 0;
  187904. info->shouldCancel = false;
  187905. UINT_PTR cookie;
  187906. HRESULT hr = info->discMaster->ProgressAdvise (info, &cookie);
  187907. hr = info->discMaster->RecordDisc (performFakeBurnForTesting,
  187908. ejectDiscAfterwards);
  187909. String error;
  187910. if (hr != S_OK)
  187911. {
  187912. const char* e = "Couldn't open or write to the CD device";
  187913. if (hr == IMAPI_E_USERABORT)
  187914. e = "User cancelled the write operation";
  187915. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187916. e = "No Disk present";
  187917. error = e;
  187918. }
  187919. info->discMaster->ProgressUnadvise (cookie);
  187920. info->listener = 0;
  187921. return error;
  187922. }
  187923. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamples)
  187924. {
  187925. if (source == 0)
  187926. return false;
  187927. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  187928. long bytesPerBlock;
  187929. HRESULT hr = info->redbook->GetAudioBlockSize (&bytesPerBlock);
  187930. const int samplesPerBlock = bytesPerBlock / 4;
  187931. bool ok = true;
  187932. hr = info->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187933. HeapBlock <byte> buffer (bytesPerBlock);
  187934. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187935. int samplesDone = 0;
  187936. source->prepareToPlay (samplesPerBlock, 44100.0);
  187937. while (ok)
  187938. {
  187939. {
  187940. AudioSourceChannelInfo info;
  187941. info.buffer = &sourceBuffer;
  187942. info.numSamples = samplesPerBlock;
  187943. info.startSample = 0;
  187944. sourceBuffer.clear();
  187945. source->getNextAudioBlock (info);
  187946. }
  187947. zeromem (buffer, bytesPerBlock);
  187948. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187949. buffer, samplesPerBlock, 4);
  187950. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187951. buffer + 2, samplesPerBlock, 4);
  187952. hr = info->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187953. if (hr != S_OK)
  187954. ok = false;
  187955. samplesDone += samplesPerBlock;
  187956. if (samplesDone >= numSamples)
  187957. break;
  187958. }
  187959. hr = info->redbook->CloseAudioTrack();
  187960. delete source;
  187961. return ok && hr == S_OK;
  187962. }
  187963. #endif
  187964. #endif
  187965. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187966. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187967. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187968. // compiled on its own).
  187969. #if JUCE_INCLUDED_FILE
  187970. static const int midiBufferSize = 1024 * 10;
  187971. static const int numInHeaders = 32;
  187972. static const int inBufferSize = 256;
  187973. static Array <void*, CriticalSection> activeMidiThreads;
  187974. using ::free;
  187975. class MidiInThread : public Thread
  187976. {
  187977. public:
  187978. MidiInThread (MidiInput* const input_,
  187979. MidiInputCallback* const callback_)
  187980. : Thread ("Juce Midi"),
  187981. hIn (0),
  187982. input (input_),
  187983. callback (callback_),
  187984. isStarted (false),
  187985. startTime (0),
  187986. pendingLength(0)
  187987. {
  187988. for (int i = numInHeaders; --i >= 0;)
  187989. {
  187990. zeromem (&hdr[i], sizeof (MIDIHDR));
  187991. hdr[i].lpData = inData[i];
  187992. hdr[i].dwBufferLength = inBufferSize;
  187993. }
  187994. };
  187995. ~MidiInThread()
  187996. {
  187997. stop();
  187998. if (hIn != 0)
  187999. {
  188000. int count = 5;
  188001. while (--count >= 0)
  188002. {
  188003. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  188004. break;
  188005. Sleep (20);
  188006. }
  188007. }
  188008. }
  188009. void handle (const uint32 message, const uint32 timeStamp) throw()
  188010. {
  188011. const int byte = message & 0xff;
  188012. if (byte < 0x80)
  188013. return;
  188014. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  188015. const double time = timeStampToTime (timeStamp);
  188016. lock.enter();
  188017. if (pendingLength < midiBufferSize - 12)
  188018. {
  188019. char* const p = pending + pendingLength;
  188020. *(double*) p = time;
  188021. *(uint32*) (p + 8) = numBytes;
  188022. *(uint32*) (p + 12) = message;
  188023. pendingLength += 12 + numBytes;
  188024. }
  188025. else
  188026. {
  188027. jassertfalse // midi buffer overflow! You might need to increase the size..
  188028. }
  188029. lock.exit();
  188030. notify();
  188031. }
  188032. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  188033. {
  188034. const int num = hdr->dwBytesRecorded;
  188035. if (num > 0)
  188036. {
  188037. const double time = timeStampToTime (timeStamp);
  188038. lock.enter();
  188039. if (pendingLength < midiBufferSize - (8 + num))
  188040. {
  188041. char* const p = pending + pendingLength;
  188042. *(double*) p = time;
  188043. *(uint32*) (p + 8) = num;
  188044. memcpy (p + 12, hdr->lpData, num);
  188045. pendingLength += 12 + num;
  188046. }
  188047. else
  188048. {
  188049. jassertfalse // midi buffer overflow! You might need to increase the size..
  188050. }
  188051. lock.exit();
  188052. notify();
  188053. }
  188054. }
  188055. void writeBlock (const int i) throw()
  188056. {
  188057. hdr[i].dwBytesRecorded = 0;
  188058. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188059. jassert (res == MMSYSERR_NOERROR);
  188060. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  188061. jassert (res == MMSYSERR_NOERROR);
  188062. }
  188063. void run()
  188064. {
  188065. MemoryBlock pendingCopy (64);
  188066. while (! threadShouldExit())
  188067. {
  188068. for (int i = 0; i < numInHeaders; ++i)
  188069. {
  188070. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188071. {
  188072. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188073. (void) res;
  188074. jassert (res == MMSYSERR_NOERROR);
  188075. writeBlock (i);
  188076. }
  188077. }
  188078. lock.enter();
  188079. int len = pendingLength;
  188080. if (len > 0)
  188081. {
  188082. pendingCopy.ensureSize (len);
  188083. pendingCopy.copyFrom (pending, 0, len);
  188084. pendingLength = 0;
  188085. }
  188086. lock.exit();
  188087. //xxx needs to figure out if blocks are broken up or not
  188088. if (len == 0)
  188089. {
  188090. wait (500);
  188091. }
  188092. else
  188093. {
  188094. const char* p = (const char*) pendingCopy.getData();
  188095. while (len > 0)
  188096. {
  188097. const double time = *(const double*) p;
  188098. const int messageLen = *(const int*) (p + 8);
  188099. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  188100. callback->handleIncomingMidiMessage (input, message);
  188101. p += 12 + messageLen;
  188102. len -= 12 + messageLen;
  188103. }
  188104. }
  188105. }
  188106. }
  188107. void start() throw()
  188108. {
  188109. jassert (hIn != 0);
  188110. if (hIn != 0 && ! isStarted)
  188111. {
  188112. stop();
  188113. activeMidiThreads.addIfNotAlreadyThere (this);
  188114. int i;
  188115. for (i = 0; i < numInHeaders; ++i)
  188116. writeBlock (i);
  188117. startTime = Time::getMillisecondCounter();
  188118. MMRESULT res = midiInStart (hIn);
  188119. jassert (res == MMSYSERR_NOERROR);
  188120. if (res == MMSYSERR_NOERROR)
  188121. {
  188122. isStarted = true;
  188123. pendingLength = 0;
  188124. startThread (6);
  188125. }
  188126. }
  188127. }
  188128. void stop() throw()
  188129. {
  188130. if (isStarted)
  188131. {
  188132. stopThread (5000);
  188133. midiInReset (hIn);
  188134. midiInStop (hIn);
  188135. activeMidiThreads.removeValue (this);
  188136. lock.enter();
  188137. lock.exit();
  188138. for (int i = numInHeaders; --i >= 0;)
  188139. {
  188140. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188141. {
  188142. int c = 10;
  188143. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  188144. Sleep (20);
  188145. jassert (c >= 0);
  188146. }
  188147. }
  188148. isStarted = false;
  188149. pendingLength = 0;
  188150. }
  188151. }
  188152. juce_UseDebuggingNewOperator
  188153. HMIDIIN hIn;
  188154. private:
  188155. MidiInput* input;
  188156. MidiInputCallback* callback;
  188157. bool isStarted;
  188158. uint32 startTime;
  188159. CriticalSection lock;
  188160. MIDIHDR hdr [numInHeaders];
  188161. char inData [numInHeaders] [inBufferSize];
  188162. int pendingLength;
  188163. char pending [midiBufferSize];
  188164. double timeStampToTime (uint32 timeStamp) throw()
  188165. {
  188166. timeStamp += startTime;
  188167. const uint32 now = Time::getMillisecondCounter();
  188168. if (timeStamp > now)
  188169. {
  188170. if (timeStamp > now + 2)
  188171. --startTime;
  188172. timeStamp = now;
  188173. }
  188174. return 0.001 * timeStamp;
  188175. }
  188176. MidiInThread (const MidiInThread&);
  188177. const MidiInThread& operator= (const MidiInThread&);
  188178. };
  188179. static void CALLBACK midiInCallback (HMIDIIN,
  188180. UINT uMsg,
  188181. DWORD_PTR dwInstance,
  188182. DWORD_PTR midiMessage,
  188183. DWORD_PTR timeStamp)
  188184. {
  188185. MidiInThread* const thread = (MidiInThread*) dwInstance;
  188186. if (thread != 0 && activeMidiThreads.contains (thread))
  188187. {
  188188. if (uMsg == MIM_DATA)
  188189. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  188190. else if (uMsg == MIM_LONGDATA)
  188191. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  188192. }
  188193. }
  188194. const StringArray MidiInput::getDevices()
  188195. {
  188196. StringArray s;
  188197. const int num = midiInGetNumDevs();
  188198. for (int i = 0; i < num; ++i)
  188199. {
  188200. MIDIINCAPS mc;
  188201. zerostruct (mc);
  188202. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188203. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188204. }
  188205. return s;
  188206. }
  188207. int MidiInput::getDefaultDeviceIndex()
  188208. {
  188209. return 0;
  188210. }
  188211. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  188212. {
  188213. if (callback == 0)
  188214. return 0;
  188215. UINT deviceId = MIDI_MAPPER;
  188216. int n = 0;
  188217. String name;
  188218. const int num = midiInGetNumDevs();
  188219. for (int i = 0; i < num; ++i)
  188220. {
  188221. MIDIINCAPS mc;
  188222. zerostruct (mc);
  188223. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188224. {
  188225. if (index == n)
  188226. {
  188227. deviceId = i;
  188228. name = String (mc.szPname, sizeof (mc.szPname));
  188229. break;
  188230. }
  188231. ++n;
  188232. }
  188233. }
  188234. ScopedPointer <MidiInput> in (new MidiInput (name));
  188235. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  188236. HMIDIIN h;
  188237. HRESULT err = midiInOpen (&h, deviceId,
  188238. (DWORD_PTR) &midiInCallback,
  188239. (DWORD_PTR) (MidiInThread*) thread,
  188240. CALLBACK_FUNCTION);
  188241. if (err == MMSYSERR_NOERROR)
  188242. {
  188243. thread->hIn = h;
  188244. in->internal = (void*) thread.release();
  188245. return in.release();
  188246. }
  188247. return 0;
  188248. }
  188249. MidiInput::MidiInput (const String& name_)
  188250. : name (name_),
  188251. internal (0)
  188252. {
  188253. }
  188254. MidiInput::~MidiInput()
  188255. {
  188256. if (internal != 0)
  188257. {
  188258. MidiInThread* const thread = (MidiInThread*) internal;
  188259. delete thread;
  188260. }
  188261. }
  188262. void MidiInput::start()
  188263. {
  188264. ((MidiInThread*) internal)->start();
  188265. }
  188266. void MidiInput::stop()
  188267. {
  188268. ((MidiInThread*) internal)->stop();
  188269. }
  188270. struct MidiOutHandle
  188271. {
  188272. int refCount;
  188273. UINT deviceId;
  188274. HMIDIOUT handle;
  188275. juce_UseDebuggingNewOperator
  188276. };
  188277. static Array <MidiOutHandle*> midiOutputHandles;
  188278. const StringArray MidiOutput::getDevices()
  188279. {
  188280. StringArray s;
  188281. const int num = midiOutGetNumDevs();
  188282. for (int i = 0; i < num; ++i)
  188283. {
  188284. MIDIOUTCAPS mc;
  188285. zerostruct (mc);
  188286. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188287. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188288. }
  188289. return s;
  188290. }
  188291. int MidiOutput::getDefaultDeviceIndex()
  188292. {
  188293. const int num = midiOutGetNumDevs();
  188294. int n = 0;
  188295. for (int i = 0; i < num; ++i)
  188296. {
  188297. MIDIOUTCAPS mc;
  188298. zerostruct (mc);
  188299. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188300. {
  188301. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188302. return n;
  188303. ++n;
  188304. }
  188305. }
  188306. return 0;
  188307. }
  188308. MidiOutput* MidiOutput::openDevice (int index)
  188309. {
  188310. UINT deviceId = MIDI_MAPPER;
  188311. const int num = midiOutGetNumDevs();
  188312. int i, n = 0;
  188313. for (i = 0; i < num; ++i)
  188314. {
  188315. MIDIOUTCAPS mc;
  188316. zerostruct (mc);
  188317. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188318. {
  188319. // use the microsoft sw synth as a default - best not to allow deviceId
  188320. // to be MIDI_MAPPER, or else device sharing breaks
  188321. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188322. deviceId = i;
  188323. if (index == n)
  188324. {
  188325. deviceId = i;
  188326. break;
  188327. }
  188328. ++n;
  188329. }
  188330. }
  188331. for (i = midiOutputHandles.size(); --i >= 0;)
  188332. {
  188333. MidiOutHandle* const han = midiOutputHandles.getUnchecked(i);
  188334. if (han != 0 && han->deviceId == deviceId)
  188335. {
  188336. han->refCount++;
  188337. MidiOutput* const out = new MidiOutput();
  188338. out->internal = (void*) han;
  188339. return out;
  188340. }
  188341. }
  188342. for (i = 4; --i >= 0;)
  188343. {
  188344. HMIDIOUT h = 0;
  188345. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188346. if (res == MMSYSERR_NOERROR)
  188347. {
  188348. MidiOutHandle* const han = new MidiOutHandle();
  188349. han->deviceId = deviceId;
  188350. han->refCount = 1;
  188351. han->handle = h;
  188352. midiOutputHandles.add (han);
  188353. MidiOutput* const out = new MidiOutput();
  188354. out->internal = (void*) han;
  188355. return out;
  188356. }
  188357. else if (res == MMSYSERR_ALLOCATED)
  188358. {
  188359. Sleep (100);
  188360. }
  188361. else
  188362. {
  188363. break;
  188364. }
  188365. }
  188366. return 0;
  188367. }
  188368. MidiOutput::~MidiOutput()
  188369. {
  188370. MidiOutHandle* const h = (MidiOutHandle*) internal;
  188371. if (midiOutputHandles.contains (h) && --(h->refCount) == 0)
  188372. {
  188373. midiOutClose (h->handle);
  188374. midiOutputHandles.removeValue (h);
  188375. delete h;
  188376. }
  188377. }
  188378. void MidiOutput::reset()
  188379. {
  188380. const MidiOutHandle* const h = (MidiOutHandle*) internal;
  188381. midiOutReset (h->handle);
  188382. }
  188383. bool MidiOutput::getVolume (float& leftVol,
  188384. float& rightVol)
  188385. {
  188386. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188387. DWORD n;
  188388. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188389. {
  188390. const unsigned short* const nn = (const unsigned short*) &n;
  188391. rightVol = nn[0] / (float) 0xffff;
  188392. leftVol = nn[1] / (float) 0xffff;
  188393. return true;
  188394. }
  188395. else
  188396. {
  188397. rightVol = leftVol = 1.0f;
  188398. return false;
  188399. }
  188400. }
  188401. void MidiOutput::setVolume (float leftVol,
  188402. float rightVol)
  188403. {
  188404. const MidiOutHandle* const handle = (MidiOutHandle*) internal;
  188405. DWORD n;
  188406. unsigned short* const nn = (unsigned short*) &n;
  188407. nn[0] = (unsigned short) jlimit (0, 0xffff, (int)(rightVol * 0xffff));
  188408. nn[1] = (unsigned short) jlimit (0, 0xffff, (int)(leftVol * 0xffff));
  188409. midiOutSetVolume (handle->handle, n);
  188410. }
  188411. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188412. {
  188413. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188414. if (message.getRawDataSize() > 3
  188415. || message.isSysEx())
  188416. {
  188417. MIDIHDR h;
  188418. zerostruct (h);
  188419. h.lpData = (char*) message.getRawData();
  188420. h.dwBufferLength = message.getRawDataSize();
  188421. h.dwBytesRecorded = message.getRawDataSize();
  188422. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188423. {
  188424. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188425. if (res == MMSYSERR_NOERROR)
  188426. {
  188427. while ((h.dwFlags & MHDR_DONE) == 0)
  188428. Sleep (1);
  188429. int count = 500; // 1 sec timeout
  188430. while (--count >= 0)
  188431. {
  188432. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188433. if (res == MIDIERR_STILLPLAYING)
  188434. Sleep (2);
  188435. else
  188436. break;
  188437. }
  188438. }
  188439. }
  188440. }
  188441. else
  188442. {
  188443. midiOutShortMsg (handle->handle,
  188444. *(unsigned int*) message.getRawData());
  188445. }
  188446. }
  188447. #endif
  188448. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188449. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188450. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188451. // compiled on its own).
  188452. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188453. #undef WINDOWS
  188454. // #define ASIO_DEBUGGING
  188455. #ifdef ASIO_DEBUGGING
  188456. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188457. #else
  188458. #define log(a) {}
  188459. #endif
  188460. #ifdef ASIO_DEBUGGING
  188461. static void logError (const String& context, long error)
  188462. {
  188463. String err ("unknown error");
  188464. if (error == ASE_NotPresent)
  188465. err = "Not Present";
  188466. else if (error == ASE_HWMalfunction)
  188467. err = "Hardware Malfunction";
  188468. else if (error == ASE_InvalidParameter)
  188469. err = "Invalid Parameter";
  188470. else if (error == ASE_InvalidMode)
  188471. err = "Invalid Mode";
  188472. else if (error == ASE_SPNotAdvancing)
  188473. err = "Sample position not advancing";
  188474. else if (error == ASE_NoClock)
  188475. err = "No Clock";
  188476. else if (error == ASE_NoMemory)
  188477. err = "Out of memory";
  188478. log (T("!!error: ") + context + T(" - ") + err);
  188479. }
  188480. #else
  188481. #define logError(a, b) {}
  188482. #endif
  188483. class ASIOAudioIODevice;
  188484. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188485. static const int maxASIOChannels = 160;
  188486. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188487. private Timer
  188488. {
  188489. public:
  188490. Component ourWindow;
  188491. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188492. const String& optionalDllForDirectLoading_)
  188493. : AudioIODevice (name_, T("ASIO")),
  188494. asioObject (0),
  188495. classId (classId_),
  188496. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188497. currentBitDepth (16),
  188498. currentSampleRate (0),
  188499. isOpen_ (false),
  188500. isStarted (false),
  188501. postOutput (true),
  188502. insideControlPanelModalLoop (false),
  188503. shouldUsePreferredSize (false)
  188504. {
  188505. name = name_;
  188506. ourWindow.addToDesktop (0);
  188507. windowHandle = ourWindow.getWindowHandle();
  188508. jassert (currentASIODev [slotNumber] == 0);
  188509. currentASIODev [slotNumber] = this;
  188510. openDevice();
  188511. }
  188512. ~ASIOAudioIODevice()
  188513. {
  188514. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188515. if (currentASIODev[i] == this)
  188516. currentASIODev[i] = 0;
  188517. close();
  188518. log ("ASIO - exiting");
  188519. removeCurrentDriver();
  188520. }
  188521. void updateSampleRates()
  188522. {
  188523. // find a list of sample rates..
  188524. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188525. sampleRates.clear();
  188526. if (asioObject != 0)
  188527. {
  188528. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188529. {
  188530. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188531. if (err == 0)
  188532. {
  188533. sampleRates.add ((int) possibleSampleRates[index]);
  188534. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188535. }
  188536. else if (err != ASE_NoClock)
  188537. {
  188538. logError (T("CanSampleRate"), err);
  188539. }
  188540. }
  188541. if (sampleRates.size() == 0)
  188542. {
  188543. double cr = 0;
  188544. const long err = asioObject->getSampleRate (&cr);
  188545. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188546. if (err == 0)
  188547. sampleRates.add ((int) cr);
  188548. }
  188549. }
  188550. }
  188551. const StringArray getOutputChannelNames()
  188552. {
  188553. return outputChannelNames;
  188554. }
  188555. const StringArray getInputChannelNames()
  188556. {
  188557. return inputChannelNames;
  188558. }
  188559. int getNumSampleRates()
  188560. {
  188561. return sampleRates.size();
  188562. }
  188563. double getSampleRate (int index)
  188564. {
  188565. return sampleRates [index];
  188566. }
  188567. int getNumBufferSizesAvailable()
  188568. {
  188569. return bufferSizes.size();
  188570. }
  188571. int getBufferSizeSamples (int index)
  188572. {
  188573. return bufferSizes [index];
  188574. }
  188575. int getDefaultBufferSize()
  188576. {
  188577. return preferredSize;
  188578. }
  188579. const String open (const BitArray& inputChannels,
  188580. const BitArray& outputChannels,
  188581. double sr,
  188582. int bufferSizeSamples)
  188583. {
  188584. close();
  188585. currentCallback = 0;
  188586. if (bufferSizeSamples <= 0)
  188587. shouldUsePreferredSize = true;
  188588. if (asioObject == 0 || ! isASIOOpen)
  188589. {
  188590. log ("Warning: device not open");
  188591. const String err (openDevice());
  188592. if (asioObject == 0 || ! isASIOOpen)
  188593. return err;
  188594. }
  188595. isStarted = false;
  188596. bufferIndex = -1;
  188597. long err = 0;
  188598. long newPreferredSize = 0;
  188599. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188600. minSize = 0;
  188601. maxSize = 0;
  188602. newPreferredSize = 0;
  188603. granularity = 0;
  188604. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188605. {
  188606. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188607. shouldUsePreferredSize = true;
  188608. preferredSize = newPreferredSize;
  188609. }
  188610. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188611. // dynamic changes to the buffer size...
  188612. shouldUsePreferredSize = shouldUsePreferredSize
  188613. || getName().containsIgnoreCase (T("Digidesign"));
  188614. if (shouldUsePreferredSize)
  188615. {
  188616. log ("Using preferred size for buffer..");
  188617. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188618. {
  188619. bufferSizeSamples = preferredSize;
  188620. }
  188621. else
  188622. {
  188623. bufferSizeSamples = 1024;
  188624. logError ("GetBufferSize1", err);
  188625. }
  188626. shouldUsePreferredSize = false;
  188627. }
  188628. int sampleRate = roundDoubleToInt (sr);
  188629. currentSampleRate = sampleRate;
  188630. currentBlockSizeSamples = bufferSizeSamples;
  188631. currentChansOut.clear();
  188632. currentChansIn.clear();
  188633. zeromem (inBuffers, sizeof (inBuffers));
  188634. zeromem (outBuffers, sizeof (outBuffers));
  188635. updateSampleRates();
  188636. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188637. sampleRate = sampleRates[0];
  188638. jassert (sampleRate != 0);
  188639. if (sampleRate == 0)
  188640. sampleRate = 44100;
  188641. long numSources = 32;
  188642. ASIOClockSource clocks[32];
  188643. zeromem (clocks, sizeof (clocks));
  188644. asioObject->getClockSources (clocks, &numSources);
  188645. bool isSourceSet = false;
  188646. // careful not to remove this loop because it does more than just logging!
  188647. int i;
  188648. for (i = 0; i < numSources; ++i)
  188649. {
  188650. String s ("clock: ");
  188651. s += clocks[i].name;
  188652. if (clocks[i].isCurrentSource)
  188653. {
  188654. isSourceSet = true;
  188655. s << " (cur)";
  188656. }
  188657. log (s);
  188658. }
  188659. if (numSources > 1 && ! isSourceSet)
  188660. {
  188661. log ("setting clock source");
  188662. asioObject->setClockSource (clocks[0].index);
  188663. Thread::sleep (20);
  188664. }
  188665. else
  188666. {
  188667. if (numSources == 0)
  188668. {
  188669. log ("ASIO - no clock sources!");
  188670. }
  188671. }
  188672. double cr = 0;
  188673. err = asioObject->getSampleRate (&cr);
  188674. if (err == 0)
  188675. {
  188676. currentSampleRate = cr;
  188677. }
  188678. else
  188679. {
  188680. logError ("GetSampleRate", err);
  188681. currentSampleRate = 0;
  188682. }
  188683. error = String::empty;
  188684. needToReset = false;
  188685. isReSync = false;
  188686. err = 0;
  188687. bool buffersCreated = false;
  188688. if (currentSampleRate != sampleRate)
  188689. {
  188690. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188691. err = asioObject->setSampleRate (sampleRate);
  188692. if (err == ASE_NoClock && numSources > 0)
  188693. {
  188694. log ("trying to set a clock source..");
  188695. Thread::sleep (10);
  188696. err = asioObject->setClockSource (clocks[0].index);
  188697. if (err != 0)
  188698. {
  188699. logError ("SetClock", err);
  188700. }
  188701. Thread::sleep (10);
  188702. err = asioObject->setSampleRate (sampleRate);
  188703. }
  188704. }
  188705. if (err == 0)
  188706. {
  188707. currentSampleRate = sampleRate;
  188708. if (needToReset)
  188709. {
  188710. if (isReSync)
  188711. {
  188712. log ("Resync request");
  188713. }
  188714. log ("! Resetting ASIO after sample rate change");
  188715. removeCurrentDriver();
  188716. loadDriver();
  188717. const String error (initDriver());
  188718. if (error.isNotEmpty())
  188719. {
  188720. log (T("ASIOInit: ") + error);
  188721. }
  188722. needToReset = false;
  188723. isReSync = false;
  188724. }
  188725. numActiveInputChans = 0;
  188726. numActiveOutputChans = 0;
  188727. ASIOBufferInfo* info = bufferInfos;
  188728. int i;
  188729. for (i = 0; i < totalNumInputChans; ++i)
  188730. {
  188731. if (inputChannels[i])
  188732. {
  188733. currentChansIn.setBit (i);
  188734. info->isInput = 1;
  188735. info->channelNum = i;
  188736. info->buffers[0] = info->buffers[1] = 0;
  188737. ++info;
  188738. ++numActiveInputChans;
  188739. }
  188740. }
  188741. for (i = 0; i < totalNumOutputChans; ++i)
  188742. {
  188743. if (outputChannels[i])
  188744. {
  188745. currentChansOut.setBit (i);
  188746. info->isInput = 0;
  188747. info->channelNum = i;
  188748. info->buffers[0] = info->buffers[1] = 0;
  188749. ++info;
  188750. ++numActiveOutputChans;
  188751. }
  188752. }
  188753. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188754. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188755. if (currentASIODev[0] == this)
  188756. {
  188757. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188758. callbacks.asioMessage = &asioMessagesCallback0;
  188759. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188760. }
  188761. else if (currentASIODev[1] == this)
  188762. {
  188763. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188764. callbacks.asioMessage = &asioMessagesCallback1;
  188765. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188766. }
  188767. else if (currentASIODev[2] == this)
  188768. {
  188769. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188770. callbacks.asioMessage = &asioMessagesCallback2;
  188771. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188772. }
  188773. else
  188774. {
  188775. jassertfalse
  188776. }
  188777. log ("disposing buffers");
  188778. err = asioObject->disposeBuffers();
  188779. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188780. err = asioObject->createBuffers (bufferInfos,
  188781. totalBuffers,
  188782. currentBlockSizeSamples,
  188783. &callbacks);
  188784. if (err != 0)
  188785. {
  188786. currentBlockSizeSamples = preferredSize;
  188787. logError ("create buffers 2", err);
  188788. asioObject->disposeBuffers();
  188789. err = asioObject->createBuffers (bufferInfos,
  188790. totalBuffers,
  188791. currentBlockSizeSamples,
  188792. &callbacks);
  188793. }
  188794. if (err == 0)
  188795. {
  188796. buffersCreated = true;
  188797. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188798. int n = 0;
  188799. Array <int> types;
  188800. currentBitDepth = 16;
  188801. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188802. {
  188803. if (inputChannels[i])
  188804. {
  188805. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188806. ASIOChannelInfo channelInfo;
  188807. zerostruct (channelInfo);
  188808. channelInfo.channel = i;
  188809. channelInfo.isInput = 1;
  188810. asioObject->getChannelInfo (&channelInfo);
  188811. types.addIfNotAlreadyThere (channelInfo.type);
  188812. typeToFormatParameters (channelInfo.type,
  188813. inputChannelBitDepths[n],
  188814. inputChannelBytesPerSample[n],
  188815. inputChannelIsFloat[n],
  188816. inputChannelLittleEndian[n]);
  188817. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188818. ++n;
  188819. }
  188820. }
  188821. jassert (numActiveInputChans == n);
  188822. n = 0;
  188823. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188824. {
  188825. if (outputChannels[i])
  188826. {
  188827. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188828. ASIOChannelInfo channelInfo;
  188829. zerostruct (channelInfo);
  188830. channelInfo.channel = i;
  188831. channelInfo.isInput = 0;
  188832. asioObject->getChannelInfo (&channelInfo);
  188833. types.addIfNotAlreadyThere (channelInfo.type);
  188834. typeToFormatParameters (channelInfo.type,
  188835. outputChannelBitDepths[n],
  188836. outputChannelBytesPerSample[n],
  188837. outputChannelIsFloat[n],
  188838. outputChannelLittleEndian[n]);
  188839. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188840. ++n;
  188841. }
  188842. }
  188843. jassert (numActiveOutputChans == n);
  188844. for (i = types.size(); --i >= 0;)
  188845. {
  188846. log (T("channel format: ") + String (types[i]));
  188847. }
  188848. jassert (n <= totalBuffers);
  188849. for (i = 0; i < numActiveOutputChans; ++i)
  188850. {
  188851. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188852. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188853. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188854. {
  188855. log ("!! Null buffers");
  188856. }
  188857. else
  188858. {
  188859. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188860. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188861. }
  188862. }
  188863. inputLatency = outputLatency = 0;
  188864. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188865. {
  188866. log ("ASIO - no latencies");
  188867. }
  188868. else
  188869. {
  188870. log (T("ASIO latencies: ")
  188871. + String ((int) outputLatency)
  188872. + T(", ")
  188873. + String ((int) inputLatency));
  188874. }
  188875. isOpen_ = true;
  188876. log ("starting ASIO");
  188877. calledback = false;
  188878. err = asioObject->start();
  188879. if (err != 0)
  188880. {
  188881. isOpen_ = false;
  188882. log ("ASIO - stop on failure");
  188883. Thread::sleep (10);
  188884. asioObject->stop();
  188885. error = "Can't start device";
  188886. Thread::sleep (10);
  188887. }
  188888. else
  188889. {
  188890. int count = 300;
  188891. while (--count > 0 && ! calledback)
  188892. Thread::sleep (10);
  188893. isStarted = true;
  188894. if (! calledback)
  188895. {
  188896. error = "Device didn't start correctly";
  188897. log ("ASIO didn't callback - stopping..");
  188898. asioObject->stop();
  188899. }
  188900. }
  188901. }
  188902. else
  188903. {
  188904. error = "Can't create i/o buffers";
  188905. }
  188906. }
  188907. else
  188908. {
  188909. error = "Can't set sample rate: ";
  188910. error << sampleRate;
  188911. }
  188912. if (error.isNotEmpty())
  188913. {
  188914. logError (error, err);
  188915. if (asioObject != 0 && buffersCreated)
  188916. asioObject->disposeBuffers();
  188917. Thread::sleep (20);
  188918. isStarted = false;
  188919. isOpen_ = false;
  188920. close();
  188921. }
  188922. needToReset = false;
  188923. isReSync = false;
  188924. return error;
  188925. }
  188926. void close()
  188927. {
  188928. error = String::empty;
  188929. stopTimer();
  188930. stop();
  188931. if (isASIOOpen && isOpen_)
  188932. {
  188933. const ScopedLock sl (callbackLock);
  188934. isOpen_ = false;
  188935. isStarted = false;
  188936. needToReset = false;
  188937. isReSync = false;
  188938. log ("ASIO - stopping");
  188939. if (asioObject != 0)
  188940. {
  188941. Thread::sleep (20);
  188942. asioObject->stop();
  188943. Thread::sleep (10);
  188944. asioObject->disposeBuffers();
  188945. }
  188946. Thread::sleep (10);
  188947. }
  188948. }
  188949. bool isOpen()
  188950. {
  188951. return isOpen_ || insideControlPanelModalLoop;
  188952. }
  188953. int getCurrentBufferSizeSamples()
  188954. {
  188955. return currentBlockSizeSamples;
  188956. }
  188957. double getCurrentSampleRate()
  188958. {
  188959. return currentSampleRate;
  188960. }
  188961. const BitArray getActiveOutputChannels() const
  188962. {
  188963. return currentChansOut;
  188964. }
  188965. const BitArray getActiveInputChannels() const
  188966. {
  188967. return currentChansIn;
  188968. }
  188969. int getCurrentBitDepth()
  188970. {
  188971. return currentBitDepth;
  188972. }
  188973. int getOutputLatencyInSamples()
  188974. {
  188975. return outputLatency + currentBlockSizeSamples / 4;
  188976. }
  188977. int getInputLatencyInSamples()
  188978. {
  188979. return inputLatency + currentBlockSizeSamples / 4;
  188980. }
  188981. void start (AudioIODeviceCallback* callback)
  188982. {
  188983. if (callback != 0)
  188984. {
  188985. callback->audioDeviceAboutToStart (this);
  188986. const ScopedLock sl (callbackLock);
  188987. currentCallback = callback;
  188988. }
  188989. }
  188990. void stop()
  188991. {
  188992. AudioIODeviceCallback* const lastCallback = currentCallback;
  188993. {
  188994. const ScopedLock sl (callbackLock);
  188995. currentCallback = 0;
  188996. }
  188997. if (lastCallback != 0)
  188998. lastCallback->audioDeviceStopped();
  188999. }
  189000. bool isPlaying()
  189001. {
  189002. return isASIOOpen && (currentCallback != 0);
  189003. }
  189004. const String getLastError()
  189005. {
  189006. return error;
  189007. }
  189008. bool hasControlPanel() const
  189009. {
  189010. return true;
  189011. }
  189012. bool showControlPanel()
  189013. {
  189014. log ("ASIO - showing control panel");
  189015. Component modalWindow (String::empty);
  189016. modalWindow.setOpaque (true);
  189017. modalWindow.addToDesktop (0);
  189018. modalWindow.enterModalState();
  189019. bool done = false;
  189020. JUCE_TRY
  189021. {
  189022. // are there are devices that need to be closed before showing their control panel?
  189023. // close();
  189024. insideControlPanelModalLoop = true;
  189025. const uint32 started = Time::getMillisecondCounter();
  189026. if (asioObject != 0)
  189027. {
  189028. asioObject->controlPanel();
  189029. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  189030. log (T("spent: ") + String (spent));
  189031. if (spent > 300)
  189032. {
  189033. shouldUsePreferredSize = true;
  189034. done = true;
  189035. }
  189036. }
  189037. }
  189038. JUCE_CATCH_ALL
  189039. insideControlPanelModalLoop = false;
  189040. return done;
  189041. }
  189042. void resetRequest() throw()
  189043. {
  189044. needToReset = true;
  189045. }
  189046. void resyncRequest() throw()
  189047. {
  189048. needToReset = true;
  189049. isReSync = true;
  189050. }
  189051. void timerCallback()
  189052. {
  189053. if (! insideControlPanelModalLoop)
  189054. {
  189055. stopTimer();
  189056. // used to cause a reset
  189057. log ("! ASIO restart request!");
  189058. if (isOpen_)
  189059. {
  189060. AudioIODeviceCallback* const oldCallback = currentCallback;
  189061. close();
  189062. open (BitArray (currentChansIn), BitArray (currentChansOut),
  189063. currentSampleRate, currentBlockSizeSamples);
  189064. if (oldCallback != 0)
  189065. start (oldCallback);
  189066. }
  189067. }
  189068. else
  189069. {
  189070. startTimer (100);
  189071. }
  189072. }
  189073. juce_UseDebuggingNewOperator
  189074. private:
  189075. IASIO* volatile asioObject;
  189076. ASIOCallbacks callbacks;
  189077. void* windowHandle;
  189078. CLSID classId;
  189079. const String optionalDllForDirectLoading;
  189080. String error;
  189081. long totalNumInputChans, totalNumOutputChans;
  189082. StringArray inputChannelNames, outputChannelNames;
  189083. Array<int> sampleRates, bufferSizes;
  189084. long inputLatency, outputLatency;
  189085. long minSize, maxSize, preferredSize, granularity;
  189086. int volatile currentBlockSizeSamples;
  189087. int volatile currentBitDepth;
  189088. double volatile currentSampleRate;
  189089. BitArray currentChansOut, currentChansIn;
  189090. AudioIODeviceCallback* volatile currentCallback;
  189091. CriticalSection callbackLock;
  189092. ASIOBufferInfo bufferInfos [maxASIOChannels];
  189093. float* inBuffers [maxASIOChannels];
  189094. float* outBuffers [maxASIOChannels];
  189095. int inputChannelBitDepths [maxASIOChannels];
  189096. int outputChannelBitDepths [maxASIOChannels];
  189097. int inputChannelBytesPerSample [maxASIOChannels];
  189098. int outputChannelBytesPerSample [maxASIOChannels];
  189099. bool inputChannelIsFloat [maxASIOChannels];
  189100. bool outputChannelIsFloat [maxASIOChannels];
  189101. bool inputChannelLittleEndian [maxASIOChannels];
  189102. bool outputChannelLittleEndian [maxASIOChannels];
  189103. WaitableEvent event1;
  189104. HeapBlock <float> tempBuffer;
  189105. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  189106. bool isOpen_, isStarted;
  189107. bool volatile isASIOOpen;
  189108. bool volatile calledback;
  189109. bool volatile littleEndian, postOutput, needToReset, isReSync;
  189110. bool volatile insideControlPanelModalLoop;
  189111. bool volatile shouldUsePreferredSize;
  189112. void removeCurrentDriver()
  189113. {
  189114. if (asioObject != 0)
  189115. {
  189116. asioObject->Release();
  189117. asioObject = 0;
  189118. }
  189119. }
  189120. bool loadDriver()
  189121. {
  189122. removeCurrentDriver();
  189123. JUCE_TRY
  189124. {
  189125. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  189126. classId, (void**) &asioObject) == S_OK)
  189127. {
  189128. return true;
  189129. }
  189130. // If a class isn't registered but we have a path for it, we can fallback to
  189131. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  189132. if (optionalDllForDirectLoading.isNotEmpty())
  189133. {
  189134. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  189135. if (h != 0)
  189136. {
  189137. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  189138. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  189139. if (dllGetClassObject != 0)
  189140. {
  189141. IClassFactory* classFactory = 0;
  189142. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  189143. if (classFactory != 0)
  189144. {
  189145. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  189146. classFactory->Release();
  189147. }
  189148. return asioObject != 0;
  189149. }
  189150. }
  189151. }
  189152. }
  189153. JUCE_CATCH_ALL
  189154. asioObject = 0;
  189155. return false;
  189156. }
  189157. const String initDriver()
  189158. {
  189159. if (asioObject != 0)
  189160. {
  189161. char buffer [256];
  189162. zeromem (buffer, sizeof (buffer));
  189163. if (! asioObject->init (windowHandle))
  189164. {
  189165. asioObject->getErrorMessage (buffer);
  189166. return String (buffer, sizeof (buffer) - 1);
  189167. }
  189168. // just in case any daft drivers expect this to be called..
  189169. asioObject->getDriverName (buffer);
  189170. return String::empty;
  189171. }
  189172. return "No Driver";
  189173. }
  189174. const String openDevice()
  189175. {
  189176. // use this in case the driver starts opening dialog boxes..
  189177. Component modalWindow (String::empty);
  189178. modalWindow.setOpaque (true);
  189179. modalWindow.addToDesktop (0);
  189180. modalWindow.enterModalState();
  189181. // open the device and get its info..
  189182. log (T("opening ASIO device: ") + getName());
  189183. needToReset = false;
  189184. isReSync = false;
  189185. outputChannelNames.clear();
  189186. inputChannelNames.clear();
  189187. bufferSizes.clear();
  189188. sampleRates.clear();
  189189. isASIOOpen = false;
  189190. isOpen_ = false;
  189191. totalNumInputChans = 0;
  189192. totalNumOutputChans = 0;
  189193. numActiveInputChans = 0;
  189194. numActiveOutputChans = 0;
  189195. currentCallback = 0;
  189196. error = String::empty;
  189197. if (getName().isEmpty())
  189198. return error;
  189199. long err = 0;
  189200. if (loadDriver())
  189201. {
  189202. if ((error = initDriver()).isEmpty())
  189203. {
  189204. numActiveInputChans = 0;
  189205. numActiveOutputChans = 0;
  189206. totalNumInputChans = 0;
  189207. totalNumOutputChans = 0;
  189208. if (asioObject != 0
  189209. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  189210. {
  189211. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  189212. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  189213. {
  189214. // find a list of buffer sizes..
  189215. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  189216. if (granularity >= 0)
  189217. {
  189218. granularity = jmax (1, (int) granularity);
  189219. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  189220. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  189221. }
  189222. else if (granularity < 0)
  189223. {
  189224. for (int i = 0; i < 18; ++i)
  189225. {
  189226. const int s = (1 << i);
  189227. if (s >= minSize && s <= maxSize)
  189228. bufferSizes.add (s);
  189229. }
  189230. }
  189231. if (! bufferSizes.contains (preferredSize))
  189232. bufferSizes.insert (0, preferredSize);
  189233. double currentRate = 0;
  189234. asioObject->getSampleRate (&currentRate);
  189235. if (currentRate <= 0.0 || currentRate > 192001.0)
  189236. {
  189237. log ("setting sample rate");
  189238. err = asioObject->setSampleRate (44100.0);
  189239. if (err != 0)
  189240. {
  189241. logError ("setting sample rate", err);
  189242. }
  189243. asioObject->getSampleRate (&currentRate);
  189244. }
  189245. currentSampleRate = currentRate;
  189246. postOutput = (asioObject->outputReady() == 0);
  189247. if (postOutput)
  189248. {
  189249. log ("ASIO outputReady = ok");
  189250. }
  189251. updateSampleRates();
  189252. // ..because cubase does it at this point
  189253. inputLatency = outputLatency = 0;
  189254. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189255. {
  189256. log ("ASIO - no latencies");
  189257. }
  189258. log (String ("latencies: ")
  189259. + String ((int) inputLatency)
  189260. + T(", ") + String ((int) outputLatency));
  189261. // create some dummy buffers now.. because cubase does..
  189262. numActiveInputChans = 0;
  189263. numActiveOutputChans = 0;
  189264. ASIOBufferInfo* info = bufferInfos;
  189265. int i, numChans = 0;
  189266. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  189267. {
  189268. info->isInput = 1;
  189269. info->channelNum = i;
  189270. info->buffers[0] = info->buffers[1] = 0;
  189271. ++info;
  189272. ++numChans;
  189273. }
  189274. const int outputBufferIndex = numChans;
  189275. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189276. {
  189277. info->isInput = 0;
  189278. info->channelNum = i;
  189279. info->buffers[0] = info->buffers[1] = 0;
  189280. ++info;
  189281. ++numChans;
  189282. }
  189283. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189284. if (currentASIODev[0] == this)
  189285. {
  189286. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189287. callbacks.asioMessage = &asioMessagesCallback0;
  189288. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189289. }
  189290. else if (currentASIODev[1] == this)
  189291. {
  189292. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189293. callbacks.asioMessage = &asioMessagesCallback1;
  189294. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189295. }
  189296. else if (currentASIODev[2] == this)
  189297. {
  189298. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189299. callbacks.asioMessage = &asioMessagesCallback2;
  189300. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189301. }
  189302. else
  189303. {
  189304. jassertfalse
  189305. }
  189306. log (T("creating buffers (dummy): ") + String (numChans)
  189307. + T(", ") + String ((int) preferredSize));
  189308. if (preferredSize > 0)
  189309. {
  189310. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189311. if (err != 0)
  189312. {
  189313. logError ("dummy buffers", err);
  189314. }
  189315. }
  189316. long newInps = 0, newOuts = 0;
  189317. asioObject->getChannels (&newInps, &newOuts);
  189318. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189319. {
  189320. totalNumInputChans = newInps;
  189321. totalNumOutputChans = newOuts;
  189322. log (String ((int) totalNumInputChans) + T(" in; ")
  189323. + String ((int) totalNumOutputChans) + T(" out"));
  189324. }
  189325. updateSampleRates();
  189326. ASIOChannelInfo channelInfo;
  189327. channelInfo.type = 0;
  189328. for (i = 0; i < totalNumInputChans; ++i)
  189329. {
  189330. zerostruct (channelInfo);
  189331. channelInfo.channel = i;
  189332. channelInfo.isInput = 1;
  189333. asioObject->getChannelInfo (&channelInfo);
  189334. inputChannelNames.add (String (channelInfo.name));
  189335. }
  189336. for (i = 0; i < totalNumOutputChans; ++i)
  189337. {
  189338. zerostruct (channelInfo);
  189339. channelInfo.channel = i;
  189340. channelInfo.isInput = 0;
  189341. asioObject->getChannelInfo (&channelInfo);
  189342. outputChannelNames.add (String (channelInfo.name));
  189343. typeToFormatParameters (channelInfo.type,
  189344. outputChannelBitDepths[i],
  189345. outputChannelBytesPerSample[i],
  189346. outputChannelIsFloat[i],
  189347. outputChannelLittleEndian[i]);
  189348. if (i < 2)
  189349. {
  189350. // clear the channels that are used with the dummy stuff
  189351. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189352. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189353. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189354. }
  189355. }
  189356. outputChannelNames.trim();
  189357. inputChannelNames.trim();
  189358. outputChannelNames.appendNumbersToDuplicates (false, true);
  189359. inputChannelNames.appendNumbersToDuplicates (false, true);
  189360. // start and stop because cubase does it..
  189361. asioObject->getLatencies (&inputLatency, &outputLatency);
  189362. if ((err = asioObject->start()) != 0)
  189363. {
  189364. // ignore an error here, as it might start later after setting other stuff up
  189365. logError ("ASIO start", err);
  189366. }
  189367. Thread::sleep (100);
  189368. asioObject->stop();
  189369. }
  189370. else
  189371. {
  189372. error = "Can't detect buffer sizes";
  189373. }
  189374. }
  189375. else
  189376. {
  189377. error = "Can't detect asio channels";
  189378. }
  189379. }
  189380. }
  189381. else
  189382. {
  189383. error = "No such device";
  189384. }
  189385. if (error.isNotEmpty())
  189386. {
  189387. logError (error, err);
  189388. if (asioObject != 0)
  189389. asioObject->disposeBuffers();
  189390. removeCurrentDriver();
  189391. isASIOOpen = false;
  189392. }
  189393. else
  189394. {
  189395. isASIOOpen = true;
  189396. log ("ASIO device open");
  189397. }
  189398. isOpen_ = false;
  189399. needToReset = false;
  189400. isReSync = false;
  189401. return error;
  189402. }
  189403. void callback (const long index) throw()
  189404. {
  189405. if (isStarted)
  189406. {
  189407. bufferIndex = index;
  189408. processBuffer();
  189409. }
  189410. else
  189411. {
  189412. if (postOutput && (asioObject != 0))
  189413. asioObject->outputReady();
  189414. }
  189415. calledback = true;
  189416. }
  189417. void processBuffer() throw()
  189418. {
  189419. const ASIOBufferInfo* const infos = bufferInfos;
  189420. const int bi = bufferIndex;
  189421. const ScopedLock sl (callbackLock);
  189422. if (needToReset)
  189423. {
  189424. needToReset = false;
  189425. if (isReSync)
  189426. {
  189427. log ("! ASIO resync");
  189428. isReSync = false;
  189429. }
  189430. else
  189431. {
  189432. startTimer (20);
  189433. }
  189434. }
  189435. if (bi >= 0)
  189436. {
  189437. const int samps = currentBlockSizeSamples;
  189438. if (currentCallback != 0)
  189439. {
  189440. int i;
  189441. for (i = 0; i < numActiveInputChans; ++i)
  189442. {
  189443. float* const dst = inBuffers[i];
  189444. jassert (dst != 0);
  189445. const char* const src = (const char*) (infos[i].buffers[bi]);
  189446. if (inputChannelIsFloat[i])
  189447. {
  189448. memcpy (dst, src, samps * sizeof (float));
  189449. }
  189450. else
  189451. {
  189452. jassert (dst == tempBuffer + (samps * i));
  189453. switch (inputChannelBitDepths[i])
  189454. {
  189455. case 16:
  189456. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189457. samps, inputChannelLittleEndian[i]);
  189458. break;
  189459. case 24:
  189460. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189461. samps, inputChannelLittleEndian[i]);
  189462. break;
  189463. case 32:
  189464. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189465. samps, inputChannelLittleEndian[i]);
  189466. break;
  189467. case 64:
  189468. jassertfalse
  189469. break;
  189470. }
  189471. }
  189472. }
  189473. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189474. numActiveInputChans,
  189475. outBuffers,
  189476. numActiveOutputChans,
  189477. samps);
  189478. for (i = 0; i < numActiveOutputChans; ++i)
  189479. {
  189480. float* const src = outBuffers[i];
  189481. jassert (src != 0);
  189482. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189483. if (outputChannelIsFloat[i])
  189484. {
  189485. memcpy (dst, src, samps * sizeof (float));
  189486. }
  189487. else
  189488. {
  189489. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189490. switch (outputChannelBitDepths[i])
  189491. {
  189492. case 16:
  189493. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189494. samps, outputChannelLittleEndian[i]);
  189495. break;
  189496. case 24:
  189497. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189498. samps, outputChannelLittleEndian[i]);
  189499. break;
  189500. case 32:
  189501. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189502. samps, outputChannelLittleEndian[i]);
  189503. break;
  189504. case 64:
  189505. jassertfalse
  189506. break;
  189507. }
  189508. }
  189509. }
  189510. }
  189511. else
  189512. {
  189513. for (int i = 0; i < numActiveOutputChans; ++i)
  189514. {
  189515. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189516. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189517. }
  189518. }
  189519. }
  189520. if (postOutput)
  189521. asioObject->outputReady();
  189522. }
  189523. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189524. {
  189525. if (currentASIODev[0] != 0)
  189526. currentASIODev[0]->callback (index);
  189527. return 0;
  189528. }
  189529. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189530. {
  189531. if (currentASIODev[1] != 0)
  189532. currentASIODev[1]->callback (index);
  189533. return 0;
  189534. }
  189535. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189536. {
  189537. if (currentASIODev[2] != 0)
  189538. currentASIODev[2]->callback (index);
  189539. return 0;
  189540. }
  189541. static void bufferSwitchCallback0 (long index, long) throw()
  189542. {
  189543. if (currentASIODev[0] != 0)
  189544. currentASIODev[0]->callback (index);
  189545. }
  189546. static void bufferSwitchCallback1 (long index, long) throw()
  189547. {
  189548. if (currentASIODev[1] != 0)
  189549. currentASIODev[1]->callback (index);
  189550. }
  189551. static void bufferSwitchCallback2 (long index, long) throw()
  189552. {
  189553. if (currentASIODev[2] != 0)
  189554. currentASIODev[2]->callback (index);
  189555. }
  189556. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189557. {
  189558. return asioMessagesCallback (selector, value, 0);
  189559. }
  189560. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189561. {
  189562. return asioMessagesCallback (selector, value, 1);
  189563. }
  189564. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189565. {
  189566. return asioMessagesCallback (selector, value, 2);
  189567. }
  189568. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189569. {
  189570. switch (selector)
  189571. {
  189572. case kAsioSelectorSupported:
  189573. if (value == kAsioResetRequest
  189574. || value == kAsioEngineVersion
  189575. || value == kAsioResyncRequest
  189576. || value == kAsioLatenciesChanged
  189577. || value == kAsioSupportsInputMonitor)
  189578. return 1;
  189579. break;
  189580. case kAsioBufferSizeChange:
  189581. break;
  189582. case kAsioResetRequest:
  189583. if (currentASIODev[deviceIndex] != 0)
  189584. currentASIODev[deviceIndex]->resetRequest();
  189585. return 1;
  189586. case kAsioResyncRequest:
  189587. if (currentASIODev[deviceIndex] != 0)
  189588. currentASIODev[deviceIndex]->resyncRequest();
  189589. return 1;
  189590. case kAsioLatenciesChanged:
  189591. return 1;
  189592. case kAsioEngineVersion:
  189593. return 2;
  189594. case kAsioSupportsTimeInfo:
  189595. case kAsioSupportsTimeCode:
  189596. return 0;
  189597. }
  189598. return 0;
  189599. }
  189600. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189601. {
  189602. }
  189603. static void convertInt16ToFloat (const char* src,
  189604. float* dest,
  189605. const int srcStrideBytes,
  189606. int numSamples,
  189607. const bool littleEndian) throw()
  189608. {
  189609. const double g = 1.0 / 32768.0;
  189610. if (littleEndian)
  189611. {
  189612. while (--numSamples >= 0)
  189613. {
  189614. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189615. src += srcStrideBytes;
  189616. }
  189617. }
  189618. else
  189619. {
  189620. while (--numSamples >= 0)
  189621. {
  189622. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189623. src += srcStrideBytes;
  189624. }
  189625. }
  189626. }
  189627. static void convertFloatToInt16 (const float* src,
  189628. char* dest,
  189629. const int dstStrideBytes,
  189630. int numSamples,
  189631. const bool littleEndian) throw()
  189632. {
  189633. const double maxVal = (double) 0x7fff;
  189634. if (littleEndian)
  189635. {
  189636. while (--numSamples >= 0)
  189637. {
  189638. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189639. dest += dstStrideBytes;
  189640. }
  189641. }
  189642. else
  189643. {
  189644. while (--numSamples >= 0)
  189645. {
  189646. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189647. dest += dstStrideBytes;
  189648. }
  189649. }
  189650. }
  189651. static void convertInt24ToFloat (const char* src,
  189652. float* dest,
  189653. const int srcStrideBytes,
  189654. int numSamples,
  189655. const bool littleEndian) throw()
  189656. {
  189657. const double g = 1.0 / 0x7fffff;
  189658. if (littleEndian)
  189659. {
  189660. while (--numSamples >= 0)
  189661. {
  189662. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189663. src += srcStrideBytes;
  189664. }
  189665. }
  189666. else
  189667. {
  189668. while (--numSamples >= 0)
  189669. {
  189670. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189671. src += srcStrideBytes;
  189672. }
  189673. }
  189674. }
  189675. static void convertFloatToInt24 (const float* src,
  189676. char* dest,
  189677. const int dstStrideBytes,
  189678. int numSamples,
  189679. const bool littleEndian) throw()
  189680. {
  189681. const double maxVal = (double) 0x7fffff;
  189682. if (littleEndian)
  189683. {
  189684. while (--numSamples >= 0)
  189685. {
  189686. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189687. dest += dstStrideBytes;
  189688. }
  189689. }
  189690. else
  189691. {
  189692. while (--numSamples >= 0)
  189693. {
  189694. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189695. dest += dstStrideBytes;
  189696. }
  189697. }
  189698. }
  189699. static void convertInt32ToFloat (const char* src,
  189700. float* dest,
  189701. const int srcStrideBytes,
  189702. int numSamples,
  189703. const bool littleEndian) throw()
  189704. {
  189705. const double g = 1.0 / 0x7fffffff;
  189706. if (littleEndian)
  189707. {
  189708. while (--numSamples >= 0)
  189709. {
  189710. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189711. src += srcStrideBytes;
  189712. }
  189713. }
  189714. else
  189715. {
  189716. while (--numSamples >= 0)
  189717. {
  189718. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189719. src += srcStrideBytes;
  189720. }
  189721. }
  189722. }
  189723. static void convertFloatToInt32 (const float* src,
  189724. char* dest,
  189725. const int dstStrideBytes,
  189726. int numSamples,
  189727. const bool littleEndian) throw()
  189728. {
  189729. const double maxVal = (double) 0x7fffffff;
  189730. if (littleEndian)
  189731. {
  189732. while (--numSamples >= 0)
  189733. {
  189734. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189735. dest += dstStrideBytes;
  189736. }
  189737. }
  189738. else
  189739. {
  189740. while (--numSamples >= 0)
  189741. {
  189742. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189743. dest += dstStrideBytes;
  189744. }
  189745. }
  189746. }
  189747. static void typeToFormatParameters (const long type,
  189748. int& bitDepth,
  189749. int& byteStride,
  189750. bool& formatIsFloat,
  189751. bool& littleEndian) throw()
  189752. {
  189753. bitDepth = 0;
  189754. littleEndian = false;
  189755. formatIsFloat = false;
  189756. switch (type)
  189757. {
  189758. case ASIOSTInt16MSB:
  189759. case ASIOSTInt16LSB:
  189760. case ASIOSTInt32MSB16:
  189761. case ASIOSTInt32LSB16:
  189762. bitDepth = 16; break;
  189763. case ASIOSTFloat32MSB:
  189764. case ASIOSTFloat32LSB:
  189765. formatIsFloat = true;
  189766. bitDepth = 32; break;
  189767. case ASIOSTInt32MSB:
  189768. case ASIOSTInt32LSB:
  189769. bitDepth = 32; break;
  189770. case ASIOSTInt24MSB:
  189771. case ASIOSTInt24LSB:
  189772. case ASIOSTInt32MSB24:
  189773. case ASIOSTInt32LSB24:
  189774. case ASIOSTInt32MSB18:
  189775. case ASIOSTInt32MSB20:
  189776. case ASIOSTInt32LSB18:
  189777. case ASIOSTInt32LSB20:
  189778. bitDepth = 24; break;
  189779. case ASIOSTFloat64MSB:
  189780. case ASIOSTFloat64LSB:
  189781. default:
  189782. bitDepth = 64;
  189783. break;
  189784. }
  189785. switch (type)
  189786. {
  189787. case ASIOSTInt16MSB:
  189788. case ASIOSTInt32MSB16:
  189789. case ASIOSTFloat32MSB:
  189790. case ASIOSTFloat64MSB:
  189791. case ASIOSTInt32MSB:
  189792. case ASIOSTInt32MSB18:
  189793. case ASIOSTInt32MSB20:
  189794. case ASIOSTInt32MSB24:
  189795. case ASIOSTInt24MSB:
  189796. littleEndian = false; break;
  189797. case ASIOSTInt16LSB:
  189798. case ASIOSTInt32LSB16:
  189799. case ASIOSTFloat32LSB:
  189800. case ASIOSTFloat64LSB:
  189801. case ASIOSTInt32LSB:
  189802. case ASIOSTInt32LSB18:
  189803. case ASIOSTInt32LSB20:
  189804. case ASIOSTInt32LSB24:
  189805. case ASIOSTInt24LSB:
  189806. littleEndian = true; break;
  189807. default:
  189808. break;
  189809. }
  189810. switch (type)
  189811. {
  189812. case ASIOSTInt16LSB:
  189813. case ASIOSTInt16MSB:
  189814. byteStride = 2; break;
  189815. case ASIOSTInt24LSB:
  189816. case ASIOSTInt24MSB:
  189817. byteStride = 3; break;
  189818. case ASIOSTInt32MSB16:
  189819. case ASIOSTInt32LSB16:
  189820. case ASIOSTInt32MSB:
  189821. case ASIOSTInt32MSB18:
  189822. case ASIOSTInt32MSB20:
  189823. case ASIOSTInt32MSB24:
  189824. case ASIOSTInt32LSB:
  189825. case ASIOSTInt32LSB18:
  189826. case ASIOSTInt32LSB20:
  189827. case ASIOSTInt32LSB24:
  189828. case ASIOSTFloat32LSB:
  189829. case ASIOSTFloat32MSB:
  189830. byteStride = 4; break;
  189831. case ASIOSTFloat64MSB:
  189832. case ASIOSTFloat64LSB:
  189833. byteStride = 8; break;
  189834. default:
  189835. break;
  189836. }
  189837. }
  189838. };
  189839. class ASIOAudioIODeviceType : public AudioIODeviceType
  189840. {
  189841. public:
  189842. ASIOAudioIODeviceType()
  189843. : AudioIODeviceType (T("ASIO")),
  189844. hasScanned (false)
  189845. {
  189846. CoInitialize (0);
  189847. }
  189848. ~ASIOAudioIODeviceType()
  189849. {
  189850. }
  189851. void scanForDevices()
  189852. {
  189853. hasScanned = true;
  189854. deviceNames.clear();
  189855. classIds.clear();
  189856. HKEY hk = 0;
  189857. int index = 0;
  189858. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189859. {
  189860. for (;;)
  189861. {
  189862. char name [256];
  189863. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189864. {
  189865. addDriverInfo (name, hk);
  189866. }
  189867. else
  189868. {
  189869. break;
  189870. }
  189871. }
  189872. RegCloseKey (hk);
  189873. }
  189874. }
  189875. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  189876. {
  189877. jassert (hasScanned); // need to call scanForDevices() before doing this
  189878. return deviceNames;
  189879. }
  189880. int getDefaultDeviceIndex (const bool) const
  189881. {
  189882. jassert (hasScanned); // need to call scanForDevices() before doing this
  189883. for (int i = deviceNames.size(); --i >= 0;)
  189884. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  189885. return i; // asio4all is a safe choice for a default..
  189886. #if JUCE_DEBUG
  189887. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  189888. return 1; // (the digi m-box driver crashes the app when you run
  189889. // it in the debugger, which can be a bit annoying)
  189890. #endif
  189891. return 0;
  189892. }
  189893. static int findFreeSlot()
  189894. {
  189895. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189896. if (currentASIODev[i] == 0)
  189897. return i;
  189898. jassertfalse; // unfortunately you can only have a finite number
  189899. // of ASIO devices open at the same time..
  189900. return -1;
  189901. }
  189902. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  189903. {
  189904. jassert (hasScanned); // need to call scanForDevices() before doing this
  189905. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189906. }
  189907. bool hasSeparateInputsAndOutputs() const { return false; }
  189908. AudioIODevice* createDevice (const String& outputDeviceName,
  189909. const String& inputDeviceName)
  189910. {
  189911. // ASIO can't open two different devices for input and output - they must be the same one.
  189912. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189913. jassert (hasScanned); // need to call scanForDevices() before doing this
  189914. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189915. : inputDeviceName);
  189916. if (index >= 0)
  189917. {
  189918. const int freeSlot = findFreeSlot();
  189919. if (freeSlot >= 0)
  189920. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189921. }
  189922. return 0;
  189923. }
  189924. juce_UseDebuggingNewOperator
  189925. private:
  189926. StringArray deviceNames;
  189927. OwnedArray <CLSID> classIds;
  189928. bool hasScanned;
  189929. static bool checkClassIsOk (const String& classId)
  189930. {
  189931. HKEY hk = 0;
  189932. bool ok = false;
  189933. if (RegOpenKeyA (HKEY_CLASSES_ROOT, "clsid", &hk) == ERROR_SUCCESS)
  189934. {
  189935. int index = 0;
  189936. for (;;)
  189937. {
  189938. char buf [512];
  189939. if (RegEnumKeyA (hk, index++, buf, 512) == ERROR_SUCCESS)
  189940. {
  189941. if (classId.equalsIgnoreCase (buf))
  189942. {
  189943. HKEY subKey, pathKey;
  189944. if (RegOpenKeyExA (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189945. {
  189946. if (RegOpenKeyExA (subKey, "InprocServer32", 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189947. {
  189948. char pathName [600];
  189949. DWORD dtype = REG_SZ;
  189950. DWORD dsize = sizeof (pathName);
  189951. if (RegQueryValueExA (pathKey, 0, 0, &dtype,
  189952. (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189953. {
  189954. OFSTRUCT of;
  189955. zerostruct (of);
  189956. of.cBytes = sizeof (of);
  189957. ok = (OpenFile (String (pathName), &of, OF_EXIST) != 0);
  189958. }
  189959. RegCloseKey (pathKey);
  189960. }
  189961. RegCloseKey (subKey);
  189962. }
  189963. break;
  189964. }
  189965. }
  189966. else
  189967. {
  189968. break;
  189969. }
  189970. }
  189971. RegCloseKey (hk);
  189972. }
  189973. return ok;
  189974. }
  189975. void addDriverInfo (const String& keyName, HKEY hk)
  189976. {
  189977. HKEY subKey;
  189978. if (RegOpenKeyExA (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189979. {
  189980. char buf [256];
  189981. DWORD dtype = REG_SZ;
  189982. DWORD dsize = sizeof (buf);
  189983. zeromem (buf, dsize);
  189984. if (RegQueryValueExA (subKey, "clsid", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189985. {
  189986. if (dsize > 0 && checkClassIsOk (buf))
  189987. {
  189988. wchar_t classIdStr [130];
  189989. MultiByteToWideChar (CP_ACP, 0, buf, -1, classIdStr, 128);
  189990. String deviceName;
  189991. CLSID classId;
  189992. if (CLSIDFromString ((LPOLESTR) classIdStr, &classId) == S_OK)
  189993. {
  189994. dtype = REG_SZ;
  189995. dsize = sizeof (buf);
  189996. if (RegQueryValueExA (subKey, "description", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189997. deviceName = buf;
  189998. else
  189999. deviceName = keyName;
  190000. log (T("found ") + deviceName);
  190001. deviceNames.add (deviceName);
  190002. classIds.add (new CLSID (classId));
  190003. }
  190004. }
  190005. RegCloseKey (subKey);
  190006. }
  190007. }
  190008. }
  190009. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  190010. const ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  190011. };
  190012. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  190013. {
  190014. return new ASIOAudioIODeviceType();
  190015. }
  190016. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  190017. void* guid,
  190018. const String& optionalDllForDirectLoading)
  190019. {
  190020. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  190021. if (freeSlot < 0)
  190022. return 0;
  190023. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  190024. }
  190025. #undef log
  190026. #endif
  190027. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  190028. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  190029. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190030. // compiled on its own).
  190031. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  190032. END_JUCE_NAMESPACE
  190033. extern "C"
  190034. {
  190035. // Declare just the minimum number of interfaces for the DSound objects that we need..
  190036. typedef struct typeDSBUFFERDESC
  190037. {
  190038. DWORD dwSize;
  190039. DWORD dwFlags;
  190040. DWORD dwBufferBytes;
  190041. DWORD dwReserved;
  190042. LPWAVEFORMATEX lpwfxFormat;
  190043. GUID guid3DAlgorithm;
  190044. } DSBUFFERDESC;
  190045. struct IDirectSoundBuffer;
  190046. #undef INTERFACE
  190047. #define INTERFACE IDirectSound
  190048. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  190049. {
  190050. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190051. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190052. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190053. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  190054. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190055. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  190056. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  190057. STDMETHOD(Compact) (THIS) PURE;
  190058. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  190059. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  190060. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190061. };
  190062. #undef INTERFACE
  190063. #define INTERFACE IDirectSoundBuffer
  190064. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  190065. {
  190066. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190067. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190068. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190069. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190070. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190071. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190072. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  190073. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  190074. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  190075. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190076. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  190077. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190078. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  190079. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  190080. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  190081. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  190082. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  190083. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  190084. STDMETHOD(Stop) (THIS) PURE;
  190085. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190086. STDMETHOD(Restore) (THIS) PURE;
  190087. };
  190088. typedef struct typeDSCBUFFERDESC
  190089. {
  190090. DWORD dwSize;
  190091. DWORD dwFlags;
  190092. DWORD dwBufferBytes;
  190093. DWORD dwReserved;
  190094. LPWAVEFORMATEX lpwfxFormat;
  190095. } DSCBUFFERDESC;
  190096. struct IDirectSoundCaptureBuffer;
  190097. #undef INTERFACE
  190098. #define INTERFACE IDirectSoundCapture
  190099. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  190100. {
  190101. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190102. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190103. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190104. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  190105. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190106. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190107. };
  190108. #undef INTERFACE
  190109. #define INTERFACE IDirectSoundCaptureBuffer
  190110. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  190111. {
  190112. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190113. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190114. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190115. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190116. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190117. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190118. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190119. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  190120. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190121. STDMETHOD(Start) (THIS_ DWORD) PURE;
  190122. STDMETHOD(Stop) (THIS) PURE;
  190123. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190124. };
  190125. };
  190126. BEGIN_JUCE_NAMESPACE
  190127. static const String getDSErrorMessage (HRESULT hr)
  190128. {
  190129. const char* result = 0;
  190130. switch (hr)
  190131. {
  190132. case MAKE_HRESULT(1, 0x878, 10):
  190133. result = "Device already allocated";
  190134. break;
  190135. case MAKE_HRESULT(1, 0x878, 30):
  190136. result = "Control unavailable";
  190137. break;
  190138. case E_INVALIDARG:
  190139. result = "Invalid parameter";
  190140. break;
  190141. case MAKE_HRESULT(1, 0x878, 50):
  190142. result = "Invalid call";
  190143. break;
  190144. case E_FAIL:
  190145. result = "Generic error";
  190146. break;
  190147. case MAKE_HRESULT(1, 0x878, 70):
  190148. result = "Priority level error";
  190149. break;
  190150. case E_OUTOFMEMORY:
  190151. result = "Out of memory";
  190152. break;
  190153. case MAKE_HRESULT(1, 0x878, 100):
  190154. result = "Bad format";
  190155. break;
  190156. case E_NOTIMPL:
  190157. result = "Unsupported function";
  190158. break;
  190159. case MAKE_HRESULT(1, 0x878, 120):
  190160. result = "No driver";
  190161. break;
  190162. case MAKE_HRESULT(1, 0x878, 130):
  190163. result = "Already initialised";
  190164. break;
  190165. case CLASS_E_NOAGGREGATION:
  190166. result = "No aggregation";
  190167. break;
  190168. case MAKE_HRESULT(1, 0x878, 150):
  190169. result = "Buffer lost";
  190170. break;
  190171. case MAKE_HRESULT(1, 0x878, 160):
  190172. result = "Another app has priority";
  190173. break;
  190174. case MAKE_HRESULT(1, 0x878, 170):
  190175. result = "Uninitialised";
  190176. break;
  190177. case E_NOINTERFACE:
  190178. result = "No interface";
  190179. break;
  190180. case S_OK:
  190181. result = "No error";
  190182. break;
  190183. default:
  190184. return "Unknown error: " + String ((int) hr);
  190185. }
  190186. return result;
  190187. }
  190188. #define DS_DEBUGGING 1
  190189. #ifdef DS_DEBUGGING
  190190. #define CATCH JUCE_CATCH_EXCEPTION
  190191. #undef log
  190192. #define log(a) Logger::writeToLog(a);
  190193. #undef logError
  190194. #define logError(a) logDSError(a, __LINE__);
  190195. static void logDSError (HRESULT hr, int lineNum)
  190196. {
  190197. if (hr != S_OK)
  190198. {
  190199. String error ("DS error at line ");
  190200. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  190201. log (error);
  190202. }
  190203. }
  190204. #else
  190205. #define CATCH JUCE_CATCH_ALL
  190206. #define log(a)
  190207. #define logError(a)
  190208. #endif
  190209. #define DSOUND_FUNCTION(functionName, params) \
  190210. typedef HRESULT (WINAPI *type##functionName) params; \
  190211. static type##functionName ds##functionName = 0;
  190212. #define DSOUND_FUNCTION_LOAD(functionName) \
  190213. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  190214. jassert (ds##functionName != 0);
  190215. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  190216. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  190217. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  190218. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  190219. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190220. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190221. static void initialiseDSoundFunctions()
  190222. {
  190223. if (dsDirectSoundCreate == 0)
  190224. {
  190225. HMODULE h = LoadLibraryA ("dsound.dll");
  190226. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  190227. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  190228. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  190229. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  190230. }
  190231. }
  190232. class DSoundInternalOutChannel
  190233. {
  190234. String name;
  190235. LPGUID guid;
  190236. int sampleRate, bufferSizeSamples;
  190237. float* leftBuffer;
  190238. float* rightBuffer;
  190239. IDirectSound* pDirectSound;
  190240. IDirectSoundBuffer* pOutputBuffer;
  190241. DWORD writeOffset;
  190242. int totalBytesPerBuffer;
  190243. int bytesPerBuffer;
  190244. unsigned int lastPlayCursor;
  190245. public:
  190246. int bitDepth;
  190247. bool doneFlag;
  190248. DSoundInternalOutChannel (const String& name_,
  190249. LPGUID guid_,
  190250. int rate,
  190251. int bufferSize,
  190252. float* left,
  190253. float* right)
  190254. : name (name_),
  190255. guid (guid_),
  190256. sampleRate (rate),
  190257. bufferSizeSamples (bufferSize),
  190258. leftBuffer (left),
  190259. rightBuffer (right),
  190260. pDirectSound (0),
  190261. pOutputBuffer (0),
  190262. bitDepth (16)
  190263. {
  190264. }
  190265. ~DSoundInternalOutChannel()
  190266. {
  190267. close();
  190268. }
  190269. void close()
  190270. {
  190271. HRESULT hr;
  190272. if (pOutputBuffer != 0)
  190273. {
  190274. JUCE_TRY
  190275. {
  190276. log (T("closing dsound out: ") + name);
  190277. hr = pOutputBuffer->Stop();
  190278. logError (hr);
  190279. }
  190280. CATCH
  190281. JUCE_TRY
  190282. {
  190283. hr = pOutputBuffer->Release();
  190284. logError (hr);
  190285. }
  190286. CATCH
  190287. pOutputBuffer = 0;
  190288. }
  190289. if (pDirectSound != 0)
  190290. {
  190291. JUCE_TRY
  190292. {
  190293. hr = pDirectSound->Release();
  190294. logError (hr);
  190295. }
  190296. CATCH
  190297. pDirectSound = 0;
  190298. }
  190299. }
  190300. const String open()
  190301. {
  190302. log (T("opening dsound out device: ") + name
  190303. + T(" rate=") + String (sampleRate)
  190304. + T(" bits=") + String (bitDepth)
  190305. + T(" buf=") + String (bufferSizeSamples));
  190306. pDirectSound = 0;
  190307. pOutputBuffer = 0;
  190308. writeOffset = 0;
  190309. String error;
  190310. HRESULT hr = E_NOINTERFACE;
  190311. if (dsDirectSoundCreate != 0)
  190312. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190313. if (hr == S_OK)
  190314. {
  190315. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190316. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190317. const int numChannels = 2;
  190318. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190319. logError (hr);
  190320. if (hr == S_OK)
  190321. {
  190322. IDirectSoundBuffer* pPrimaryBuffer;
  190323. DSBUFFERDESC primaryDesc;
  190324. zerostruct (primaryDesc);
  190325. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190326. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190327. primaryDesc.dwBufferBytes = 0;
  190328. primaryDesc.lpwfxFormat = 0;
  190329. log ("opening dsound out step 2");
  190330. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190331. logError (hr);
  190332. if (hr == S_OK)
  190333. {
  190334. WAVEFORMATEX wfFormat;
  190335. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190336. wfFormat.nChannels = (unsigned short) numChannels;
  190337. wfFormat.nSamplesPerSec = sampleRate;
  190338. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190339. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190340. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190341. wfFormat.cbSize = 0;
  190342. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190343. logError (hr);
  190344. if (hr == S_OK)
  190345. {
  190346. DSBUFFERDESC secondaryDesc;
  190347. zerostruct (secondaryDesc);
  190348. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190349. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190350. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190351. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190352. secondaryDesc.lpwfxFormat = &wfFormat;
  190353. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190354. logError (hr);
  190355. if (hr == S_OK)
  190356. {
  190357. log ("opening dsound out step 3");
  190358. DWORD dwDataLen;
  190359. unsigned char* pDSBuffData;
  190360. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190361. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190362. logError (hr);
  190363. if (hr == S_OK)
  190364. {
  190365. zeromem (pDSBuffData, dwDataLen);
  190366. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190367. if (hr == S_OK)
  190368. {
  190369. hr = pOutputBuffer->SetCurrentPosition (0);
  190370. if (hr == S_OK)
  190371. {
  190372. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190373. if (hr == S_OK)
  190374. return String::empty;
  190375. }
  190376. }
  190377. }
  190378. }
  190379. }
  190380. }
  190381. }
  190382. }
  190383. error = getDSErrorMessage (hr);
  190384. close();
  190385. return error;
  190386. }
  190387. void synchronisePosition()
  190388. {
  190389. if (pOutputBuffer != 0)
  190390. {
  190391. DWORD playCursor;
  190392. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190393. }
  190394. }
  190395. bool service()
  190396. {
  190397. if (pOutputBuffer == 0)
  190398. return true;
  190399. DWORD playCursor, writeCursor;
  190400. for (;;)
  190401. {
  190402. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190403. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190404. {
  190405. pOutputBuffer->Restore();
  190406. continue;
  190407. }
  190408. if (hr == S_OK)
  190409. break;
  190410. logError (hr);
  190411. jassertfalse
  190412. return true;
  190413. }
  190414. int playWriteGap = writeCursor - playCursor;
  190415. if (playWriteGap < 0)
  190416. playWriteGap += totalBytesPerBuffer;
  190417. int bytesEmpty = playCursor - writeOffset;
  190418. if (bytesEmpty < 0)
  190419. bytesEmpty += totalBytesPerBuffer;
  190420. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190421. {
  190422. writeOffset = writeCursor;
  190423. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190424. }
  190425. if (bytesEmpty >= bytesPerBuffer)
  190426. {
  190427. LPBYTE lpbuf1 = 0;
  190428. LPBYTE lpbuf2 = 0;
  190429. DWORD dwSize1 = 0;
  190430. DWORD dwSize2 = 0;
  190431. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190432. bytesPerBuffer,
  190433. (void**) &lpbuf1, &dwSize1,
  190434. (void**) &lpbuf2, &dwSize2, 0);
  190435. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190436. {
  190437. pOutputBuffer->Restore();
  190438. hr = pOutputBuffer->Lock (writeOffset,
  190439. bytesPerBuffer,
  190440. (void**) &lpbuf1, &dwSize1,
  190441. (void**) &lpbuf2, &dwSize2, 0);
  190442. }
  190443. if (hr == S_OK)
  190444. {
  190445. if (bitDepth == 16)
  190446. {
  190447. const float gainL = 32767.0f;
  190448. const float gainR = 32767.0f;
  190449. int* dest = (int*)lpbuf1;
  190450. const float* left = leftBuffer;
  190451. const float* right = rightBuffer;
  190452. int samples1 = dwSize1 >> 2;
  190453. int samples2 = dwSize2 >> 2;
  190454. if (left == 0)
  190455. {
  190456. while (--samples1 >= 0)
  190457. {
  190458. int r = roundToInt (gainR * *right++);
  190459. if (r < -32768)
  190460. r = -32768;
  190461. else if (r > 32767)
  190462. r = 32767;
  190463. *dest++ = (r << 16);
  190464. }
  190465. dest = (int*)lpbuf2;
  190466. while (--samples2 >= 0)
  190467. {
  190468. int r = roundToInt (gainR * *right++);
  190469. if (r < -32768)
  190470. r = -32768;
  190471. else if (r > 32767)
  190472. r = 32767;
  190473. *dest++ = (r << 16);
  190474. }
  190475. }
  190476. else if (right == 0)
  190477. {
  190478. while (--samples1 >= 0)
  190479. {
  190480. int l = roundToInt (gainL * *left++);
  190481. if (l < -32768)
  190482. l = -32768;
  190483. else if (l > 32767)
  190484. l = 32767;
  190485. l &= 0xffff;
  190486. *dest++ = l;
  190487. }
  190488. dest = (int*)lpbuf2;
  190489. while (--samples2 >= 0)
  190490. {
  190491. int l = roundToInt (gainL * *left++);
  190492. if (l < -32768)
  190493. l = -32768;
  190494. else if (l > 32767)
  190495. l = 32767;
  190496. l &= 0xffff;
  190497. *dest++ = l;
  190498. }
  190499. }
  190500. else
  190501. {
  190502. while (--samples1 >= 0)
  190503. {
  190504. int l = roundToInt (gainL * *left++);
  190505. if (l < -32768)
  190506. l = -32768;
  190507. else if (l > 32767)
  190508. l = 32767;
  190509. l &= 0xffff;
  190510. int r = roundToInt (gainR * *right++);
  190511. if (r < -32768)
  190512. r = -32768;
  190513. else if (r > 32767)
  190514. r = 32767;
  190515. *dest++ = (r << 16) | l;
  190516. }
  190517. dest = (int*)lpbuf2;
  190518. while (--samples2 >= 0)
  190519. {
  190520. int l = roundToInt (gainL * *left++);
  190521. if (l < -32768)
  190522. l = -32768;
  190523. else if (l > 32767)
  190524. l = 32767;
  190525. l &= 0xffff;
  190526. int r = roundToInt (gainR * *right++);
  190527. if (r < -32768)
  190528. r = -32768;
  190529. else if (r > 32767)
  190530. r = 32767;
  190531. *dest++ = (r << 16) | l;
  190532. }
  190533. }
  190534. }
  190535. else
  190536. {
  190537. jassertfalse
  190538. }
  190539. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190540. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190541. }
  190542. else
  190543. {
  190544. jassertfalse
  190545. logError (hr);
  190546. }
  190547. bytesEmpty -= bytesPerBuffer;
  190548. return true;
  190549. }
  190550. else
  190551. {
  190552. return false;
  190553. }
  190554. }
  190555. };
  190556. struct DSoundInternalInChannel
  190557. {
  190558. String name;
  190559. LPGUID guid;
  190560. int sampleRate, bufferSizeSamples;
  190561. float* leftBuffer;
  190562. float* rightBuffer;
  190563. IDirectSound* pDirectSound;
  190564. IDirectSoundCapture* pDirectSoundCapture;
  190565. IDirectSoundCaptureBuffer* pInputBuffer;
  190566. public:
  190567. unsigned int readOffset;
  190568. int bytesPerBuffer, totalBytesPerBuffer;
  190569. int bitDepth;
  190570. bool doneFlag;
  190571. DSoundInternalInChannel (const String& name_,
  190572. LPGUID guid_,
  190573. int rate,
  190574. int bufferSize,
  190575. float* left,
  190576. float* right)
  190577. : name (name_),
  190578. guid (guid_),
  190579. sampleRate (rate),
  190580. bufferSizeSamples (bufferSize),
  190581. leftBuffer (left),
  190582. rightBuffer (right),
  190583. pDirectSound (0),
  190584. pDirectSoundCapture (0),
  190585. pInputBuffer (0),
  190586. bitDepth (16)
  190587. {
  190588. }
  190589. ~DSoundInternalInChannel()
  190590. {
  190591. close();
  190592. }
  190593. void close()
  190594. {
  190595. HRESULT hr;
  190596. if (pInputBuffer != 0)
  190597. {
  190598. JUCE_TRY
  190599. {
  190600. log (T("closing dsound in: ") + name);
  190601. hr = pInputBuffer->Stop();
  190602. logError (hr);
  190603. }
  190604. CATCH
  190605. JUCE_TRY
  190606. {
  190607. hr = pInputBuffer->Release();
  190608. logError (hr);
  190609. }
  190610. CATCH
  190611. pInputBuffer = 0;
  190612. }
  190613. if (pDirectSoundCapture != 0)
  190614. {
  190615. JUCE_TRY
  190616. {
  190617. hr = pDirectSoundCapture->Release();
  190618. logError (hr);
  190619. }
  190620. CATCH
  190621. pDirectSoundCapture = 0;
  190622. }
  190623. if (pDirectSound != 0)
  190624. {
  190625. JUCE_TRY
  190626. {
  190627. hr = pDirectSound->Release();
  190628. logError (hr);
  190629. }
  190630. CATCH
  190631. pDirectSound = 0;
  190632. }
  190633. }
  190634. const String open()
  190635. {
  190636. log (T("opening dsound in device: ") + name
  190637. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190638. pDirectSound = 0;
  190639. pDirectSoundCapture = 0;
  190640. pInputBuffer = 0;
  190641. readOffset = 0;
  190642. totalBytesPerBuffer = 0;
  190643. String error;
  190644. HRESULT hr = E_NOINTERFACE;
  190645. if (dsDirectSoundCaptureCreate != 0)
  190646. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190647. logError (hr);
  190648. if (hr == S_OK)
  190649. {
  190650. const int numChannels = 2;
  190651. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190652. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190653. WAVEFORMATEX wfFormat;
  190654. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190655. wfFormat.nChannels = (unsigned short)numChannels;
  190656. wfFormat.nSamplesPerSec = sampleRate;
  190657. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190658. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190659. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190660. wfFormat.cbSize = 0;
  190661. DSCBUFFERDESC captureDesc;
  190662. zerostruct (captureDesc);
  190663. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190664. captureDesc.dwFlags = 0;
  190665. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190666. captureDesc.lpwfxFormat = &wfFormat;
  190667. log (T("opening dsound in step 2"));
  190668. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190669. logError (hr);
  190670. if (hr == S_OK)
  190671. {
  190672. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190673. logError (hr);
  190674. if (hr == S_OK)
  190675. return String::empty;
  190676. }
  190677. }
  190678. error = getDSErrorMessage (hr);
  190679. close();
  190680. return error;
  190681. }
  190682. void synchronisePosition()
  190683. {
  190684. if (pInputBuffer != 0)
  190685. {
  190686. DWORD capturePos;
  190687. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190688. }
  190689. }
  190690. bool service()
  190691. {
  190692. if (pInputBuffer == 0)
  190693. return true;
  190694. DWORD capturePos, readPos;
  190695. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190696. logError (hr);
  190697. if (hr != S_OK)
  190698. return true;
  190699. int bytesFilled = readPos - readOffset;
  190700. if (bytesFilled < 0)
  190701. bytesFilled += totalBytesPerBuffer;
  190702. if (bytesFilled >= bytesPerBuffer)
  190703. {
  190704. LPBYTE lpbuf1 = 0;
  190705. LPBYTE lpbuf2 = 0;
  190706. DWORD dwsize1 = 0;
  190707. DWORD dwsize2 = 0;
  190708. HRESULT hr = pInputBuffer->Lock (readOffset,
  190709. bytesPerBuffer,
  190710. (void**) &lpbuf1, &dwsize1,
  190711. (void**) &lpbuf2, &dwsize2, 0);
  190712. if (hr == S_OK)
  190713. {
  190714. if (bitDepth == 16)
  190715. {
  190716. const float g = 1.0f / 32768.0f;
  190717. float* destL = leftBuffer;
  190718. float* destR = rightBuffer;
  190719. int samples1 = dwsize1 >> 2;
  190720. int samples2 = dwsize2 >> 2;
  190721. const short* src = (const short*)lpbuf1;
  190722. if (destL == 0)
  190723. {
  190724. while (--samples1 >= 0)
  190725. {
  190726. ++src;
  190727. *destR++ = *src++ * g;
  190728. }
  190729. src = (const short*)lpbuf2;
  190730. while (--samples2 >= 0)
  190731. {
  190732. ++src;
  190733. *destR++ = *src++ * g;
  190734. }
  190735. }
  190736. else if (destR == 0)
  190737. {
  190738. while (--samples1 >= 0)
  190739. {
  190740. *destL++ = *src++ * g;
  190741. ++src;
  190742. }
  190743. src = (const short*)lpbuf2;
  190744. while (--samples2 >= 0)
  190745. {
  190746. *destL++ = *src++ * g;
  190747. ++src;
  190748. }
  190749. }
  190750. else
  190751. {
  190752. while (--samples1 >= 0)
  190753. {
  190754. *destL++ = *src++ * g;
  190755. *destR++ = *src++ * g;
  190756. }
  190757. src = (const short*)lpbuf2;
  190758. while (--samples2 >= 0)
  190759. {
  190760. *destL++ = *src++ * g;
  190761. *destR++ = *src++ * g;
  190762. }
  190763. }
  190764. }
  190765. else
  190766. {
  190767. jassertfalse
  190768. }
  190769. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190770. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190771. }
  190772. else
  190773. {
  190774. logError (hr);
  190775. jassertfalse
  190776. }
  190777. bytesFilled -= bytesPerBuffer;
  190778. return true;
  190779. }
  190780. else
  190781. {
  190782. return false;
  190783. }
  190784. }
  190785. };
  190786. class DSoundAudioIODevice : public AudioIODevice,
  190787. public Thread
  190788. {
  190789. public:
  190790. DSoundAudioIODevice (const String& deviceName,
  190791. const int outputDeviceIndex_,
  190792. const int inputDeviceIndex_)
  190793. : AudioIODevice (deviceName, "DirectSound"),
  190794. Thread ("Juce DSound"),
  190795. isOpen_ (false),
  190796. isStarted (false),
  190797. outputDeviceIndex (outputDeviceIndex_),
  190798. inputDeviceIndex (inputDeviceIndex_),
  190799. numInputBuffers (0),
  190800. numOutputBuffers (0),
  190801. totalSamplesOut (0),
  190802. sampleRate (0.0),
  190803. inputBuffers (0),
  190804. outputBuffers (0),
  190805. callback (0),
  190806. bufferSizeSamples (0)
  190807. {
  190808. if (outputDeviceIndex_ >= 0)
  190809. {
  190810. outChannels.add (TRANS("Left"));
  190811. outChannels.add (TRANS("Right"));
  190812. }
  190813. if (inputDeviceIndex_ >= 0)
  190814. {
  190815. inChannels.add (TRANS("Left"));
  190816. inChannels.add (TRANS("Right"));
  190817. }
  190818. }
  190819. ~DSoundAudioIODevice()
  190820. {
  190821. close();
  190822. }
  190823. const StringArray getOutputChannelNames()
  190824. {
  190825. return outChannels;
  190826. }
  190827. const StringArray getInputChannelNames()
  190828. {
  190829. return inChannels;
  190830. }
  190831. int getNumSampleRates()
  190832. {
  190833. return 4;
  190834. }
  190835. double getSampleRate (int index)
  190836. {
  190837. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190838. return samps [jlimit (0, 3, index)];
  190839. }
  190840. int getNumBufferSizesAvailable()
  190841. {
  190842. return 50;
  190843. }
  190844. int getBufferSizeSamples (int index)
  190845. {
  190846. int n = 64;
  190847. for (int i = 0; i < index; ++i)
  190848. n += (n < 512) ? 32
  190849. : ((n < 1024) ? 64
  190850. : ((n < 2048) ? 128 : 256));
  190851. return n;
  190852. }
  190853. int getDefaultBufferSize()
  190854. {
  190855. return 2560;
  190856. }
  190857. const String open (const BitArray& inputChannels,
  190858. const BitArray& outputChannels,
  190859. double sampleRate,
  190860. int bufferSizeSamples)
  190861. {
  190862. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190863. isOpen_ = lastError.isEmpty();
  190864. return lastError;
  190865. }
  190866. void close()
  190867. {
  190868. stop();
  190869. if (isOpen_)
  190870. {
  190871. closeDevice();
  190872. isOpen_ = false;
  190873. }
  190874. }
  190875. bool isOpen()
  190876. {
  190877. return isOpen_ && isThreadRunning();
  190878. }
  190879. int getCurrentBufferSizeSamples()
  190880. {
  190881. return bufferSizeSamples;
  190882. }
  190883. double getCurrentSampleRate()
  190884. {
  190885. return sampleRate;
  190886. }
  190887. int getCurrentBitDepth()
  190888. {
  190889. int i, bits = 256;
  190890. for (i = inChans.size(); --i >= 0;)
  190891. bits = jmin (bits, inChans[i]->bitDepth);
  190892. for (i = outChans.size(); --i >= 0;)
  190893. bits = jmin (bits, outChans[i]->bitDepth);
  190894. if (bits > 32)
  190895. bits = 16;
  190896. return bits;
  190897. }
  190898. const BitArray getActiveOutputChannels() const
  190899. {
  190900. return enabledOutputs;
  190901. }
  190902. const BitArray getActiveInputChannels() const
  190903. {
  190904. return enabledInputs;
  190905. }
  190906. int getOutputLatencyInSamples()
  190907. {
  190908. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190909. }
  190910. int getInputLatencyInSamples()
  190911. {
  190912. return getOutputLatencyInSamples();
  190913. }
  190914. void start (AudioIODeviceCallback* call)
  190915. {
  190916. if (isOpen_ && call != 0 && ! isStarted)
  190917. {
  190918. if (! isThreadRunning())
  190919. {
  190920. // something gone wrong and the thread's stopped..
  190921. isOpen_ = false;
  190922. return;
  190923. }
  190924. call->audioDeviceAboutToStart (this);
  190925. const ScopedLock sl (startStopLock);
  190926. callback = call;
  190927. isStarted = true;
  190928. }
  190929. }
  190930. void stop()
  190931. {
  190932. if (isStarted)
  190933. {
  190934. AudioIODeviceCallback* const callbackLocal = callback;
  190935. {
  190936. const ScopedLock sl (startStopLock);
  190937. isStarted = false;
  190938. }
  190939. if (callbackLocal != 0)
  190940. callbackLocal->audioDeviceStopped();
  190941. }
  190942. }
  190943. bool isPlaying()
  190944. {
  190945. return isStarted && isOpen_ && isThreadRunning();
  190946. }
  190947. const String getLastError()
  190948. {
  190949. return lastError;
  190950. }
  190951. juce_UseDebuggingNewOperator
  190952. StringArray inChannels, outChannels;
  190953. int outputDeviceIndex, inputDeviceIndex;
  190954. private:
  190955. bool isOpen_;
  190956. bool isStarted;
  190957. String lastError;
  190958. OwnedArray <DSoundInternalInChannel> inChans;
  190959. OwnedArray <DSoundInternalOutChannel> outChans;
  190960. WaitableEvent startEvent;
  190961. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190962. int volatile totalSamplesOut;
  190963. int64 volatile lastBlockTime;
  190964. double sampleRate;
  190965. BitArray enabledInputs, enabledOutputs;
  190966. HeapBlock <float*> inputBuffers, outputBuffers;
  190967. AudioIODeviceCallback* callback;
  190968. CriticalSection startStopLock;
  190969. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190970. const DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190971. const String openDevice (const BitArray& inputChannels,
  190972. const BitArray& outputChannels,
  190973. double sampleRate_,
  190974. int bufferSizeSamples_);
  190975. void closeDevice()
  190976. {
  190977. isStarted = false;
  190978. stopThread (5000);
  190979. inChans.clear();
  190980. outChans.clear();
  190981. int i;
  190982. for (i = 0; i < numInputBuffers; ++i)
  190983. juce_free (inputBuffers[i]);
  190984. inputBuffers.free();
  190985. numInputBuffers = 0;
  190986. for (i = 0; i < numOutputBuffers; ++i)
  190987. juce_free (outputBuffers[i]);
  190988. outputBuffers.free();
  190989. numOutputBuffers = 0;
  190990. }
  190991. void resync()
  190992. {
  190993. if (! threadShouldExit())
  190994. {
  190995. sleep (5);
  190996. int i;
  190997. for (i = 0; i < outChans.size(); ++i)
  190998. outChans.getUnchecked(i)->synchronisePosition();
  190999. for (i = 0; i < inChans.size(); ++i)
  191000. inChans.getUnchecked(i)->synchronisePosition();
  191001. }
  191002. }
  191003. public:
  191004. void run()
  191005. {
  191006. while (! threadShouldExit())
  191007. {
  191008. if (wait (100))
  191009. break;
  191010. }
  191011. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  191012. const int maxTimeMS = jmax (5, 3 * latencyMs);
  191013. while (! threadShouldExit())
  191014. {
  191015. int numToDo = 0;
  191016. uint32 startTime = Time::getMillisecondCounter();
  191017. int i;
  191018. for (i = inChans.size(); --i >= 0;)
  191019. {
  191020. inChans.getUnchecked(i)->doneFlag = false;
  191021. ++numToDo;
  191022. }
  191023. for (i = outChans.size(); --i >= 0;)
  191024. {
  191025. outChans.getUnchecked(i)->doneFlag = false;
  191026. ++numToDo;
  191027. }
  191028. if (numToDo > 0)
  191029. {
  191030. const int maxCount = 3;
  191031. int count = maxCount;
  191032. for (;;)
  191033. {
  191034. for (i = inChans.size(); --i >= 0;)
  191035. {
  191036. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  191037. if ((! in->doneFlag) && in->service())
  191038. {
  191039. in->doneFlag = true;
  191040. --numToDo;
  191041. }
  191042. }
  191043. for (i = outChans.size(); --i >= 0;)
  191044. {
  191045. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  191046. if ((! out->doneFlag) && out->service())
  191047. {
  191048. out->doneFlag = true;
  191049. --numToDo;
  191050. }
  191051. }
  191052. if (numToDo <= 0)
  191053. break;
  191054. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  191055. {
  191056. resync();
  191057. break;
  191058. }
  191059. if (--count <= 0)
  191060. {
  191061. Sleep (1);
  191062. count = maxCount;
  191063. }
  191064. if (threadShouldExit())
  191065. return;
  191066. }
  191067. }
  191068. else
  191069. {
  191070. sleep (1);
  191071. }
  191072. const ScopedLock sl (startStopLock);
  191073. if (isStarted)
  191074. {
  191075. JUCE_TRY
  191076. {
  191077. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191078. numInputBuffers,
  191079. outputBuffers,
  191080. numOutputBuffers,
  191081. bufferSizeSamples);
  191082. }
  191083. JUCE_CATCH_EXCEPTION
  191084. totalSamplesOut += bufferSizeSamples;
  191085. }
  191086. else
  191087. {
  191088. for (i = 0; i < numOutputBuffers; ++i)
  191089. if (outputBuffers[i] != 0)
  191090. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  191091. totalSamplesOut = 0;
  191092. sleep (1);
  191093. }
  191094. }
  191095. }
  191096. };
  191097. class DSoundAudioIODeviceType : public AudioIODeviceType
  191098. {
  191099. public:
  191100. DSoundAudioIODeviceType()
  191101. : AudioIODeviceType (T("DirectSound")),
  191102. hasScanned (false)
  191103. {
  191104. initialiseDSoundFunctions();
  191105. }
  191106. ~DSoundAudioIODeviceType()
  191107. {
  191108. }
  191109. void scanForDevices()
  191110. {
  191111. hasScanned = true;
  191112. outputDeviceNames.clear();
  191113. outputGuids.clear();
  191114. inputDeviceNames.clear();
  191115. inputGuids.clear();
  191116. if (dsDirectSoundEnumerateW != 0)
  191117. {
  191118. dsDirectSoundEnumerateW (outputEnumProcW, this);
  191119. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  191120. }
  191121. }
  191122. const StringArray getDeviceNames (const bool wantInputNames) const
  191123. {
  191124. jassert (hasScanned); // need to call scanForDevices() before doing this
  191125. return wantInputNames ? inputDeviceNames
  191126. : outputDeviceNames;
  191127. }
  191128. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191129. {
  191130. jassert (hasScanned); // need to call scanForDevices() before doing this
  191131. return 0;
  191132. }
  191133. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191134. {
  191135. jassert (hasScanned); // need to call scanForDevices() before doing this
  191136. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  191137. if (d == 0)
  191138. return -1;
  191139. return asInput ? d->inputDeviceIndex
  191140. : d->outputDeviceIndex;
  191141. }
  191142. bool hasSeparateInputsAndOutputs() const { return true; }
  191143. AudioIODevice* createDevice (const String& outputDeviceName,
  191144. const String& inputDeviceName)
  191145. {
  191146. jassert (hasScanned); // need to call scanForDevices() before doing this
  191147. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191148. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191149. if (outputIndex >= 0 || inputIndex >= 0)
  191150. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191151. : inputDeviceName,
  191152. outputIndex, inputIndex);
  191153. return 0;
  191154. }
  191155. juce_UseDebuggingNewOperator
  191156. StringArray outputDeviceNames;
  191157. OwnedArray <GUID> outputGuids;
  191158. StringArray inputDeviceNames;
  191159. OwnedArray <GUID> inputGuids;
  191160. private:
  191161. bool hasScanned;
  191162. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  191163. {
  191164. desc = desc.trim();
  191165. if (desc.isNotEmpty())
  191166. {
  191167. const String origDesc (desc);
  191168. int n = 2;
  191169. while (outputDeviceNames.contains (desc))
  191170. desc = origDesc + T(" (") + String (n++) + T(")");
  191171. outputDeviceNames.add (desc);
  191172. if (lpGUID != 0)
  191173. outputGuids.add (new GUID (*lpGUID));
  191174. else
  191175. outputGuids.add (0);
  191176. }
  191177. return TRUE;
  191178. }
  191179. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191180. {
  191181. return ((DSoundAudioIODeviceType*) object)
  191182. ->outputEnumProc (lpGUID, String (description));
  191183. }
  191184. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191185. {
  191186. return ((DSoundAudioIODeviceType*) object)
  191187. ->outputEnumProc (lpGUID, String (description));
  191188. }
  191189. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  191190. {
  191191. desc = desc.trim();
  191192. if (desc.isNotEmpty())
  191193. {
  191194. const String origDesc (desc);
  191195. int n = 2;
  191196. while (inputDeviceNames.contains (desc))
  191197. desc = origDesc + T(" (") + String (n++) + T(")");
  191198. inputDeviceNames.add (desc);
  191199. if (lpGUID != 0)
  191200. inputGuids.add (new GUID (*lpGUID));
  191201. else
  191202. inputGuids.add (0);
  191203. }
  191204. return TRUE;
  191205. }
  191206. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191207. {
  191208. return ((DSoundAudioIODeviceType*) object)
  191209. ->inputEnumProc (lpGUID, String (description));
  191210. }
  191211. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191212. {
  191213. return ((DSoundAudioIODeviceType*) object)
  191214. ->inputEnumProc (lpGUID, String (description));
  191215. }
  191216. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  191217. const DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  191218. };
  191219. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  191220. const BitArray& outputChannels,
  191221. double sampleRate_,
  191222. int bufferSizeSamples_)
  191223. {
  191224. closeDevice();
  191225. totalSamplesOut = 0;
  191226. sampleRate = sampleRate_;
  191227. if (bufferSizeSamples_ <= 0)
  191228. bufferSizeSamples_ = 960; // use as a default size if none is set.
  191229. bufferSizeSamples = bufferSizeSamples_ & ~7;
  191230. DSoundAudioIODeviceType dlh;
  191231. dlh.scanForDevices();
  191232. enabledInputs = inputChannels;
  191233. enabledInputs.setRange (inChannels.size(),
  191234. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  191235. false);
  191236. numInputBuffers = enabledInputs.countNumberOfSetBits();
  191237. inputBuffers.calloc (numInputBuffers + 2);
  191238. int i, numIns = 0;
  191239. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  191240. {
  191241. float* left = 0;
  191242. float* right = 0;
  191243. if (enabledInputs[i])
  191244. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191245. if (enabledInputs[i + 1])
  191246. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191247. if (left != 0 || right != 0)
  191248. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  191249. dlh.inputGuids [inputDeviceIndex],
  191250. (int) sampleRate, bufferSizeSamples,
  191251. left, right));
  191252. }
  191253. enabledOutputs = outputChannels;
  191254. enabledOutputs.setRange (outChannels.size(),
  191255. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  191256. false);
  191257. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  191258. outputBuffers.calloc (numOutputBuffers + 2);
  191259. int numOuts = 0;
  191260. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  191261. {
  191262. float* left = 0;
  191263. float* right = 0;
  191264. if (enabledOutputs[i])
  191265. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191266. if (enabledOutputs[i + 1])
  191267. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191268. if (left != 0 || right != 0)
  191269. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  191270. dlh.outputGuids [outputDeviceIndex],
  191271. (int) sampleRate, bufferSizeSamples,
  191272. left, right));
  191273. }
  191274. String error;
  191275. // boost our priority while opening the devices to try to get better sync between them
  191276. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  191277. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  191278. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191279. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191280. for (i = 0; i < outChans.size(); ++i)
  191281. {
  191282. error = outChans[i]->open();
  191283. if (error.isNotEmpty())
  191284. {
  191285. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191286. + T(": \"") + error + T("\"");
  191287. break;
  191288. }
  191289. }
  191290. if (error.isEmpty())
  191291. {
  191292. for (i = 0; i < inChans.size(); ++i)
  191293. {
  191294. error = inChans[i]->open();
  191295. if (error.isNotEmpty())
  191296. {
  191297. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191298. + T(": \"") + error + T("\"");
  191299. break;
  191300. }
  191301. }
  191302. }
  191303. if (error.isEmpty())
  191304. {
  191305. totalSamplesOut = 0;
  191306. for (i = 0; i < outChans.size(); ++i)
  191307. outChans.getUnchecked(i)->synchronisePosition();
  191308. for (i = 0; i < inChans.size(); ++i)
  191309. inChans.getUnchecked(i)->synchronisePosition();
  191310. startThread (9);
  191311. sleep (10);
  191312. notify();
  191313. }
  191314. else
  191315. {
  191316. log (error);
  191317. }
  191318. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191319. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191320. return error;
  191321. }
  191322. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191323. {
  191324. return new DSoundAudioIODeviceType();
  191325. }
  191326. #undef log
  191327. #endif
  191328. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  191329. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  191330. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191331. // compiled on its own).
  191332. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191333. #if 1
  191334. const String getAudioErrorDesc (HRESULT hr)
  191335. {
  191336. const char* e = 0;
  191337. switch (hr)
  191338. {
  191339. case E_POINTER: e = "E_POINTER"; break;
  191340. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191341. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191342. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191343. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191344. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191345. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191346. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191347. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191348. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191349. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191350. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191351. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191352. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191353. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191354. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191355. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191356. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191357. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191358. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191359. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191360. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191361. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191362. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191363. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191364. default: return String::toHexString ((int) hr);
  191365. }
  191366. return e;
  191367. }
  191368. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191369. #define OK(a) wasapi_checkResult(a)
  191370. static bool wasapi_checkResult (HRESULT hr)
  191371. {
  191372. logFailure (hr);
  191373. return SUCCEEDED (hr);
  191374. }
  191375. #else
  191376. #define logFailure(hr) {}
  191377. #define OK(a) SUCCEEDED(a)
  191378. #endif
  191379. static const String wasapi_getDeviceID (IMMDevice* const device)
  191380. {
  191381. String s;
  191382. WCHAR* deviceId = 0;
  191383. if (OK (device->GetId (&deviceId)))
  191384. {
  191385. s = String (deviceId);
  191386. CoTaskMemFree (deviceId);
  191387. }
  191388. return s;
  191389. }
  191390. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191391. {
  191392. EDataFlow flow = eRender;
  191393. ComSmartPtr <IMMEndpoint> endPoint;
  191394. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191395. (void) OK (endPoint->GetDataFlow (&flow));
  191396. return flow;
  191397. }
  191398. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191399. {
  191400. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191401. }
  191402. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191403. {
  191404. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191405. : sizeof (WAVEFORMATEX));
  191406. }
  191407. class WASAPIDeviceBase
  191408. {
  191409. public:
  191410. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191411. : device (device_),
  191412. sampleRate (0),
  191413. numChannels (0),
  191414. actualNumChannels (0),
  191415. defaultSampleRate (0),
  191416. minBufferSize (0),
  191417. defaultBufferSize (0),
  191418. latencySamples (0),
  191419. useExclusiveMode (useExclusiveMode_)
  191420. {
  191421. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191422. ComSmartPtr <IAudioClient> tempClient (createClient());
  191423. if (tempClient == 0)
  191424. return;
  191425. REFERENCE_TIME defaultPeriod, minPeriod;
  191426. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191427. return;
  191428. WAVEFORMATEX* mixFormat = 0;
  191429. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191430. return;
  191431. WAVEFORMATEXTENSIBLE format;
  191432. wasapi_copyWavFormat (format, mixFormat);
  191433. CoTaskMemFree (mixFormat);
  191434. actualNumChannels = numChannels = format.Format.nChannels;
  191435. defaultSampleRate = format.Format.nSamplesPerSec;
  191436. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191437. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191438. FloatElementComparator<double> comparator;
  191439. rates.addSorted (comparator, defaultSampleRate);
  191440. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191441. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191442. {
  191443. if (ratesToTest[i] == defaultSampleRate)
  191444. continue;
  191445. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191446. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191447. (WAVEFORMATEX*) &format, 0)))
  191448. if (! rates.contains (ratesToTest[i]))
  191449. rates.addSorted (comparator, ratesToTest[i]);
  191450. }
  191451. }
  191452. ~WASAPIDeviceBase()
  191453. {
  191454. device = 0;
  191455. CloseHandle (clientEvent);
  191456. }
  191457. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191458. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191459. {
  191460. sampleRate = newSampleRate;
  191461. channels = newChannels;
  191462. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191463. numChannels = channels.getHighestBit() + 1;
  191464. if (numChannels == 0)
  191465. return true;
  191466. client = createClient();
  191467. if (client != 0
  191468. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191469. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191470. {
  191471. channelMaps.clear();
  191472. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191473. if (channels[i])
  191474. channelMaps.add (i);
  191475. REFERENCE_TIME latency;
  191476. if (OK (client->GetStreamLatency (&latency)))
  191477. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191478. (void) OK (client->GetBufferSize (&actualBufferSize));
  191479. return OK (client->SetEventHandle (clientEvent));
  191480. }
  191481. return false;
  191482. }
  191483. void closeClient()
  191484. {
  191485. if (client != 0)
  191486. client->Stop();
  191487. client = 0;
  191488. ResetEvent (clientEvent);
  191489. }
  191490. ComSmartPtr <IMMDevice> device;
  191491. ComSmartPtr <IAudioClient> client;
  191492. double sampleRate, defaultSampleRate;
  191493. int numChannels, actualNumChannels;
  191494. int minBufferSize, defaultBufferSize, latencySamples;
  191495. const bool useExclusiveMode;
  191496. Array <double> rates;
  191497. HANDLE clientEvent;
  191498. BitArray channels;
  191499. AudioDataConverters::DataFormat dataFormat;
  191500. Array <int> channelMaps;
  191501. UINT32 actualBufferSize;
  191502. int bytesPerSample;
  191503. private:
  191504. const ComSmartPtr <IAudioClient> createClient()
  191505. {
  191506. ComSmartPtr <IAudioClient> client;
  191507. if (device != 0)
  191508. {
  191509. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191510. logFailure (hr);
  191511. }
  191512. return client;
  191513. }
  191514. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191515. {
  191516. WAVEFORMATEXTENSIBLE format;
  191517. zerostruct (format);
  191518. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191519. {
  191520. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191521. }
  191522. else
  191523. {
  191524. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191525. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191526. }
  191527. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191528. format.Format.nChannels = (WORD) numChannels;
  191529. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191530. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191531. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191532. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191533. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191534. switch (numChannels)
  191535. {
  191536. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191537. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191538. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191539. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191540. 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;
  191541. default: break;
  191542. }
  191543. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191544. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191545. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191546. logFailure (hr);
  191547. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191548. {
  191549. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191550. hr = S_OK;
  191551. }
  191552. CoTaskMemFree (nearestFormat);
  191553. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191554. if (useExclusiveMode)
  191555. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191556. GUID session;
  191557. if (hr == S_OK
  191558. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191559. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191560. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191561. {
  191562. actualNumChannels = format.Format.nChannels;
  191563. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191564. bytesPerSample = format.Format.wBitsPerSample / 8;
  191565. dataFormat = isFloat ? AudioDataConverters::float32LE
  191566. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191567. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191568. : AudioDataConverters::int16LE)));
  191569. return true;
  191570. }
  191571. return false;
  191572. }
  191573. };
  191574. class WASAPIInputDevice : public WASAPIDeviceBase
  191575. {
  191576. public:
  191577. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191578. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191579. reservoir (1, 1)
  191580. {
  191581. }
  191582. ~WASAPIInputDevice()
  191583. {
  191584. close();
  191585. }
  191586. bool open (const double newSampleRate, const BitArray& newChannels)
  191587. {
  191588. reservoirSize = 0;
  191589. reservoirCapacity = 16384;
  191590. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191591. return openClient (newSampleRate, newChannels)
  191592. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191593. }
  191594. void close()
  191595. {
  191596. closeClient();
  191597. captureClient = 0;
  191598. reservoir.setSize (0);
  191599. }
  191600. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191601. {
  191602. if (numChannels <= 0)
  191603. return;
  191604. int offset = 0;
  191605. while (bufferSize > 0)
  191606. {
  191607. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191608. {
  191609. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191610. for (int i = 0; i < numDestBuffers; ++i)
  191611. {
  191612. float* const dest = destBuffers[i] + offset;
  191613. const int srcChan = channelMaps.getUnchecked(i);
  191614. switch (dataFormat)
  191615. {
  191616. case AudioDataConverters::float32LE:
  191617. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191618. break;
  191619. case AudioDataConverters::int32LE:
  191620. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191621. break;
  191622. case AudioDataConverters::int24LE:
  191623. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191624. break;
  191625. case AudioDataConverters::int16LE:
  191626. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191627. break;
  191628. default: jassertfalse; break;
  191629. }
  191630. }
  191631. bufferSize -= samplesToDo;
  191632. offset += samplesToDo;
  191633. reservoirSize -= samplesToDo;
  191634. }
  191635. else
  191636. {
  191637. UINT32 packetLength = 0;
  191638. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191639. break;
  191640. if (packetLength == 0)
  191641. {
  191642. if (thread.threadShouldExit())
  191643. break;
  191644. Thread::sleep (1);
  191645. continue;
  191646. }
  191647. uint8* inputData = 0;
  191648. UINT32 numSamplesAvailable;
  191649. DWORD flags;
  191650. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191651. {
  191652. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191653. for (int i = 0; i < numDestBuffers; ++i)
  191654. {
  191655. float* const dest = destBuffers[i] + offset;
  191656. const int srcChan = channelMaps.getUnchecked(i);
  191657. switch (dataFormat)
  191658. {
  191659. case AudioDataConverters::float32LE:
  191660. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191661. break;
  191662. case AudioDataConverters::int32LE:
  191663. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191664. break;
  191665. case AudioDataConverters::int24LE:
  191666. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191667. break;
  191668. case AudioDataConverters::int16LE:
  191669. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191670. break;
  191671. default: jassertfalse; break;
  191672. }
  191673. }
  191674. bufferSize -= samplesToDo;
  191675. offset += samplesToDo;
  191676. if (samplesToDo < (int) numSamplesAvailable)
  191677. {
  191678. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191679. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191680. bytesPerSample * actualNumChannels * reservoirSize);
  191681. }
  191682. captureClient->ReleaseBuffer (numSamplesAvailable);
  191683. }
  191684. }
  191685. }
  191686. }
  191687. ComSmartPtr <IAudioCaptureClient> captureClient;
  191688. MemoryBlock reservoir;
  191689. int reservoirSize, reservoirCapacity;
  191690. };
  191691. class WASAPIOutputDevice : public WASAPIDeviceBase
  191692. {
  191693. public:
  191694. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191695. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191696. {
  191697. }
  191698. ~WASAPIOutputDevice()
  191699. {
  191700. close();
  191701. }
  191702. bool open (const double newSampleRate, const BitArray& newChannels)
  191703. {
  191704. return openClient (newSampleRate, newChannels)
  191705. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191706. }
  191707. void close()
  191708. {
  191709. closeClient();
  191710. renderClient = 0;
  191711. }
  191712. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191713. {
  191714. if (numChannels <= 0)
  191715. return;
  191716. int offset = 0;
  191717. while (bufferSize > 0)
  191718. {
  191719. UINT32 padding = 0;
  191720. if (! OK (client->GetCurrentPadding (&padding)))
  191721. return;
  191722. int samplesToDo = useExclusiveMode ? bufferSize
  191723. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191724. if (samplesToDo <= 0)
  191725. {
  191726. if (thread.threadShouldExit())
  191727. break;
  191728. Thread::sleep (0);
  191729. continue;
  191730. }
  191731. uint8* outputData = 0;
  191732. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191733. {
  191734. for (int i = 0; i < numSrcBuffers; ++i)
  191735. {
  191736. const float* const source = srcBuffers[i] + offset;
  191737. const int destChan = channelMaps.getUnchecked(i);
  191738. switch (dataFormat)
  191739. {
  191740. case AudioDataConverters::float32LE:
  191741. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191742. break;
  191743. case AudioDataConverters::int32LE:
  191744. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191745. break;
  191746. case AudioDataConverters::int24LE:
  191747. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191748. break;
  191749. case AudioDataConverters::int16LE:
  191750. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191751. break;
  191752. default: jassertfalse; break;
  191753. }
  191754. }
  191755. renderClient->ReleaseBuffer (samplesToDo, 0);
  191756. offset += samplesToDo;
  191757. bufferSize -= samplesToDo;
  191758. }
  191759. }
  191760. }
  191761. ComSmartPtr <IAudioRenderClient> renderClient;
  191762. };
  191763. class WASAPIAudioIODevice : public AudioIODevice,
  191764. public Thread
  191765. {
  191766. public:
  191767. WASAPIAudioIODevice (const String& deviceName,
  191768. const String& outputDeviceId_,
  191769. const String& inputDeviceId_,
  191770. const bool useExclusiveMode_)
  191771. : AudioIODevice (deviceName, "Windows Audio"),
  191772. Thread ("Juce WASAPI"),
  191773. isOpen_ (false),
  191774. isStarted (false),
  191775. outputDevice (0),
  191776. outputDeviceId (outputDeviceId_),
  191777. inputDevice (0),
  191778. inputDeviceId (inputDeviceId_),
  191779. useExclusiveMode (useExclusiveMode_),
  191780. currentBufferSizeSamples (0),
  191781. currentSampleRate (0),
  191782. callback (0)
  191783. {
  191784. }
  191785. ~WASAPIAudioIODevice()
  191786. {
  191787. close();
  191788. deleteAndZero (inputDevice);
  191789. deleteAndZero (outputDevice);
  191790. }
  191791. bool initialise()
  191792. {
  191793. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191794. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191795. latencyIn = latencyOut = 0;
  191796. Array <double> ratesIn, ratesOut;
  191797. if (createDevices())
  191798. {
  191799. jassert (inputDevice != 0 || outputDevice != 0);
  191800. if (inputDevice != 0 && outputDevice != 0)
  191801. {
  191802. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191803. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191804. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191805. sampleRates = inputDevice->rates;
  191806. sampleRates.removeValuesNotIn (outputDevice->rates);
  191807. }
  191808. else
  191809. {
  191810. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191811. defaultSampleRate = d->defaultSampleRate;
  191812. minBufferSize = d->minBufferSize;
  191813. defaultBufferSize = d->defaultBufferSize;
  191814. sampleRates = d->rates;
  191815. }
  191816. IntegerElementComparator<int> comparator;
  191817. bufferSizes.addSorted (comparator, defaultBufferSize);
  191818. if (minBufferSize != defaultBufferSize)
  191819. bufferSizes.addSorted (comparator, minBufferSize);
  191820. int n = 64;
  191821. for (int i = 0; i < 40; ++i)
  191822. {
  191823. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191824. bufferSizes.addSorted (comparator, n);
  191825. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191826. }
  191827. return true;
  191828. }
  191829. return false;
  191830. }
  191831. const StringArray getOutputChannelNames()
  191832. {
  191833. StringArray outChannels;
  191834. if (outputDevice != 0)
  191835. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191836. outChannels.add ("Output channel " + String (i));
  191837. return outChannels;
  191838. }
  191839. const StringArray getInputChannelNames()
  191840. {
  191841. StringArray inChannels;
  191842. if (inputDevice != 0)
  191843. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191844. inChannels.add ("Input channel " + String (i));
  191845. return inChannels;
  191846. }
  191847. int getNumSampleRates() { return sampleRates.size(); }
  191848. double getSampleRate (int index) { return sampleRates [index]; }
  191849. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191850. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191851. int getDefaultBufferSize() { return defaultBufferSize; }
  191852. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191853. double getCurrentSampleRate() { return currentSampleRate; }
  191854. int getCurrentBitDepth() { return 32; }
  191855. int getOutputLatencyInSamples() { return latencyOut; }
  191856. int getInputLatencyInSamples() { return latencyIn; }
  191857. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  191858. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  191859. const String getLastError() { return lastError; }
  191860. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  191861. double sampleRate, int bufferSizeSamples)
  191862. {
  191863. close();
  191864. lastError = String::empty;
  191865. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191866. {
  191867. lastError = "The input and output devices don't share a common sample rate!";
  191868. return lastError;
  191869. }
  191870. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191871. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191872. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191873. {
  191874. lastError = "Couldn't open the input device!";
  191875. return lastError;
  191876. }
  191877. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191878. {
  191879. close();
  191880. lastError = "Couldn't open the output device!";
  191881. return lastError;
  191882. }
  191883. if (inputDevice != 0)
  191884. ResetEvent (inputDevice->clientEvent);
  191885. if (outputDevice != 0)
  191886. ResetEvent (outputDevice->clientEvent);
  191887. startThread (8);
  191888. Thread::sleep (5);
  191889. if (inputDevice != 0 && inputDevice->client != 0)
  191890. {
  191891. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191892. HRESULT hr = inputDevice->client->Start();
  191893. logFailure (hr); //xxx handle this
  191894. }
  191895. if (outputDevice != 0 && outputDevice->client != 0)
  191896. {
  191897. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191898. HRESULT hr = outputDevice->client->Start();
  191899. logFailure (hr); //xxx handle this
  191900. }
  191901. isOpen_ = true;
  191902. return lastError;
  191903. }
  191904. void close()
  191905. {
  191906. stop();
  191907. if (inputDevice != 0)
  191908. SetEvent (inputDevice->clientEvent);
  191909. if (outputDevice != 0)
  191910. SetEvent (outputDevice->clientEvent);
  191911. stopThread (5000);
  191912. if (inputDevice != 0)
  191913. inputDevice->close();
  191914. if (outputDevice != 0)
  191915. outputDevice->close();
  191916. isOpen_ = false;
  191917. }
  191918. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191919. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191920. void start (AudioIODeviceCallback* call)
  191921. {
  191922. if (isOpen_ && call != 0 && ! isStarted)
  191923. {
  191924. if (! isThreadRunning())
  191925. {
  191926. // something's gone wrong and the thread's stopped..
  191927. isOpen_ = false;
  191928. return;
  191929. }
  191930. call->audioDeviceAboutToStart (this);
  191931. const ScopedLock sl (startStopLock);
  191932. callback = call;
  191933. isStarted = true;
  191934. }
  191935. }
  191936. void stop()
  191937. {
  191938. if (isStarted)
  191939. {
  191940. AudioIODeviceCallback* const callbackLocal = callback;
  191941. {
  191942. const ScopedLock sl (startStopLock);
  191943. isStarted = false;
  191944. }
  191945. if (callbackLocal != 0)
  191946. callbackLocal->audioDeviceStopped();
  191947. }
  191948. }
  191949. void setMMThreadPriority()
  191950. {
  191951. DynamicLibraryLoader dll ("avrt.dll");
  191952. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191953. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191954. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191955. {
  191956. DWORD dummy = 0;
  191957. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191958. if (h != 0)
  191959. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191960. }
  191961. }
  191962. void run()
  191963. {
  191964. setMMThreadPriority();
  191965. const int bufferSize = currentBufferSizeSamples;
  191966. HANDLE events[2];
  191967. int numEvents = 0;
  191968. if (inputDevice != 0)
  191969. events [numEvents++] = inputDevice->clientEvent;
  191970. if (outputDevice != 0)
  191971. events [numEvents++] = outputDevice->clientEvent;
  191972. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191973. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191974. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191975. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191976. float** const inputBuffers = ins.getArrayOfChannels();
  191977. float** const outputBuffers = outs.getArrayOfChannels();
  191978. ins.clear();
  191979. while (! threadShouldExit())
  191980. {
  191981. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191982. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191983. if (result == WAIT_TIMEOUT)
  191984. continue;
  191985. if (threadShouldExit())
  191986. break;
  191987. if (inputDevice != 0)
  191988. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191989. // Make the callback..
  191990. {
  191991. const ScopedLock sl (startStopLock);
  191992. if (isStarted)
  191993. {
  191994. JUCE_TRY
  191995. {
  191996. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191997. numInputBuffers,
  191998. outputBuffers,
  191999. numOutputBuffers,
  192000. bufferSize);
  192001. }
  192002. JUCE_CATCH_EXCEPTION
  192003. }
  192004. else
  192005. {
  192006. outs.clear();
  192007. }
  192008. }
  192009. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  192010. continue;
  192011. if (outputDevice != 0)
  192012. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  192013. }
  192014. }
  192015. juce_UseDebuggingNewOperator
  192016. String outputDeviceId, inputDeviceId;
  192017. String lastError;
  192018. private:
  192019. // Device stats...
  192020. WASAPIInputDevice* inputDevice;
  192021. WASAPIOutputDevice* outputDevice;
  192022. const bool useExclusiveMode;
  192023. double defaultSampleRate;
  192024. int minBufferSize, defaultBufferSize;
  192025. int latencyIn, latencyOut;
  192026. Array <double> sampleRates;
  192027. Array <int> bufferSizes;
  192028. // Active state...
  192029. bool isOpen_, isStarted;
  192030. int currentBufferSizeSamples;
  192031. double currentSampleRate;
  192032. AudioIODeviceCallback* callback;
  192033. CriticalSection startStopLock;
  192034. bool createDevices()
  192035. {
  192036. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192037. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192038. return false;
  192039. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192040. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  192041. return false;
  192042. UINT32 numDevices = 0;
  192043. if (! OK (deviceCollection->GetCount (&numDevices)))
  192044. return false;
  192045. for (UINT32 i = 0; i < numDevices; ++i)
  192046. {
  192047. ComSmartPtr <IMMDevice> device;
  192048. if (! OK (deviceCollection->Item (i, &device)))
  192049. continue;
  192050. const String deviceId (wasapi_getDeviceID (device));
  192051. if (deviceId.isEmpty())
  192052. continue;
  192053. const EDataFlow flow = wasapi_getDataFlow (device);
  192054. if (deviceId == inputDeviceId && flow == eCapture)
  192055. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  192056. else if (deviceId == outputDeviceId && flow == eRender)
  192057. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  192058. }
  192059. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  192060. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  192061. }
  192062. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  192063. const WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  192064. };
  192065. class WASAPIAudioIODeviceType : public AudioIODeviceType
  192066. {
  192067. public:
  192068. WASAPIAudioIODeviceType()
  192069. : AudioIODeviceType (T("Windows Audio")),
  192070. hasScanned (false)
  192071. {
  192072. }
  192073. ~WASAPIAudioIODeviceType()
  192074. {
  192075. }
  192076. void scanForDevices()
  192077. {
  192078. hasScanned = true;
  192079. outputDeviceNames.clear();
  192080. inputDeviceNames.clear();
  192081. outputDeviceIds.clear();
  192082. inputDeviceIds.clear();
  192083. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192084. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192085. return;
  192086. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  192087. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  192088. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192089. UINT32 numDevices = 0;
  192090. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  192091. && OK (deviceCollection->GetCount (&numDevices))))
  192092. return;
  192093. for (UINT32 i = 0; i < numDevices; ++i)
  192094. {
  192095. ComSmartPtr <IMMDevice> device;
  192096. if (! OK (deviceCollection->Item (i, &device)))
  192097. continue;
  192098. const String deviceId (wasapi_getDeviceID (device));
  192099. DWORD state = 0;
  192100. if (! OK (device->GetState (&state)))
  192101. continue;
  192102. if (state != DEVICE_STATE_ACTIVE)
  192103. continue;
  192104. String name;
  192105. {
  192106. ComSmartPtr <IPropertyStore> properties;
  192107. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  192108. continue;
  192109. PROPVARIANT value;
  192110. PropVariantInit (&value);
  192111. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  192112. name = value.pwszVal;
  192113. PropVariantClear (&value);
  192114. }
  192115. const EDataFlow flow = wasapi_getDataFlow (device);
  192116. if (flow == eRender)
  192117. {
  192118. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  192119. outputDeviceIds.insert (index, deviceId);
  192120. outputDeviceNames.insert (index, name);
  192121. }
  192122. else if (flow == eCapture)
  192123. {
  192124. const int index = (deviceId == defaultCapture) ? 0 : -1;
  192125. inputDeviceIds.insert (index, deviceId);
  192126. inputDeviceNames.insert (index, name);
  192127. }
  192128. }
  192129. inputDeviceNames.appendNumbersToDuplicates (false, false);
  192130. outputDeviceNames.appendNumbersToDuplicates (false, false);
  192131. }
  192132. const StringArray getDeviceNames (const bool wantInputNames) const
  192133. {
  192134. jassert (hasScanned); // need to call scanForDevices() before doing this
  192135. return wantInputNames ? inputDeviceNames
  192136. : outputDeviceNames;
  192137. }
  192138. int getDefaultDeviceIndex (const bool /*forInput*/) const
  192139. {
  192140. jassert (hasScanned); // need to call scanForDevices() before doing this
  192141. return 0;
  192142. }
  192143. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  192144. {
  192145. jassert (hasScanned); // need to call scanForDevices() before doing this
  192146. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  192147. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  192148. : outputDeviceIds.indexOf (d->outputDeviceId));
  192149. }
  192150. bool hasSeparateInputsAndOutputs() const { return true; }
  192151. AudioIODevice* createDevice (const String& outputDeviceName,
  192152. const String& inputDeviceName)
  192153. {
  192154. jassert (hasScanned); // need to call scanForDevices() before doing this
  192155. const bool useExclusiveMode = false;
  192156. WASAPIAudioIODevice* d = 0;
  192157. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  192158. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  192159. if (outputIndex >= 0 || inputIndex >= 0)
  192160. {
  192161. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  192162. : inputDeviceName,
  192163. outputDeviceIds [outputIndex],
  192164. inputDeviceIds [inputIndex],
  192165. useExclusiveMode);
  192166. if (! d->initialise())
  192167. deleteAndZero (d);
  192168. }
  192169. return d;
  192170. }
  192171. juce_UseDebuggingNewOperator
  192172. StringArray outputDeviceNames, outputDeviceIds;
  192173. StringArray inputDeviceNames, inputDeviceIds;
  192174. private:
  192175. bool hasScanned;
  192176. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  192177. {
  192178. String s;
  192179. IMMDevice* dev = 0;
  192180. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  192181. eMultimedia, &dev)))
  192182. {
  192183. WCHAR* deviceId = 0;
  192184. if (OK (dev->GetId (&deviceId)))
  192185. {
  192186. s = String (deviceId);
  192187. CoTaskMemFree (deviceId);
  192188. }
  192189. dev->Release();
  192190. }
  192191. return s;
  192192. }
  192193. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  192194. const WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  192195. };
  192196. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  192197. {
  192198. return new WASAPIAudioIODeviceType();
  192199. }
  192200. #undef logFailure
  192201. #undef OK
  192202. #endif
  192203. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  192204. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  192205. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  192206. // compiled on its own).
  192207. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  192208. class DShowCameraDeviceInteral : public ChangeBroadcaster
  192209. {
  192210. public:
  192211. DShowCameraDeviceInteral (CameraDevice* const owner_,
  192212. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  192213. const ComSmartPtr <IBaseFilter>& filter_,
  192214. int minWidth, int minHeight,
  192215. int maxWidth, int maxHeight)
  192216. : owner (owner_),
  192217. captureGraphBuilder (captureGraphBuilder_),
  192218. filter (filter_),
  192219. ok (false),
  192220. imageNeedsFlipping (false),
  192221. width (0),
  192222. height (0),
  192223. activeUsers (0),
  192224. recordNextFrameTime (false),
  192225. activeImage (0),
  192226. loadingImage (0)
  192227. {
  192228. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  192229. if (FAILED (hr))
  192230. return;
  192231. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  192232. if (FAILED (hr))
  192233. return;
  192234. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  192235. if (FAILED (hr))
  192236. return;
  192237. {
  192238. ComSmartPtr <IAMStreamConfig> streamConfig;
  192239. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE,
  192240. 0,
  192241. filter,
  192242. IID_IAMStreamConfig,
  192243. (void**) &streamConfig);
  192244. if (streamConfig != 0)
  192245. {
  192246. getVideoSizes (streamConfig);
  192247. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  192248. return;
  192249. }
  192250. }
  192251. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  192252. if (FAILED (hr))
  192253. return;
  192254. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  192255. if (FAILED (hr))
  192256. return;
  192257. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  192258. if (FAILED (hr))
  192259. return;
  192260. if (! connectFilters (filter, smartTee))
  192261. return;
  192262. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  192263. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  192264. if (FAILED (hr))
  192265. return;
  192266. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  192267. if (FAILED (hr))
  192268. return;
  192269. AM_MEDIA_TYPE mt;
  192270. zerostruct (mt);
  192271. mt.majortype = MEDIATYPE_Video;
  192272. mt.subtype = MEDIASUBTYPE_RGB24;
  192273. mt.formattype = FORMAT_VideoInfo;
  192274. sampleGrabber->SetMediaType (&mt);
  192275. callback = new GrabberCallback (*this);
  192276. sampleGrabber->SetCallback (callback, 1);
  192277. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  192278. if (FAILED (hr))
  192279. return;
  192280. ComSmartPtr <IPin> grabberInputPin;
  192281. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192282. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192283. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192284. return;
  192285. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192286. if (FAILED (hr))
  192287. return;
  192288. zerostruct (mt);
  192289. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192290. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192291. width = pVih->bmiHeader.biWidth;
  192292. height = pVih->bmiHeader.biHeight;
  192293. ComSmartPtr <IBaseFilter> nullFilter;
  192294. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192295. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192296. if (connectFilters (sampleGrabberBase, nullFilter)
  192297. && addGraphToRot())
  192298. {
  192299. activeImage = new Image (Image::RGB, width, height, true);
  192300. loadingImage = new Image (Image::RGB, width, height, true);
  192301. ok = true;
  192302. }
  192303. }
  192304. ~DShowCameraDeviceInteral()
  192305. {
  192306. if (mediaControl != 0)
  192307. mediaControl->Stop();
  192308. removeGraphFromRot();
  192309. for (int i = viewerComps.size(); --i >= 0;)
  192310. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192311. callback = 0;
  192312. graphBuilder = 0;
  192313. sampleGrabber = 0;
  192314. mediaControl = 0;
  192315. filter = 0;
  192316. captureGraphBuilder = 0;
  192317. smartTee = 0;
  192318. smartTeePreviewOutputPin = 0;
  192319. smartTeeCaptureOutputPin = 0;
  192320. mux = 0;
  192321. fileWriter = 0;
  192322. delete activeImage;
  192323. delete loadingImage;
  192324. }
  192325. void addUser()
  192326. {
  192327. if (ok && activeUsers++ == 0)
  192328. mediaControl->Run();
  192329. }
  192330. void removeUser()
  192331. {
  192332. if (ok && --activeUsers == 0)
  192333. mediaControl->Stop();
  192334. }
  192335. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192336. {
  192337. if (recordNextFrameTime)
  192338. {
  192339. const double defaultCameraLatency = 0.1;
  192340. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192341. recordNextFrameTime = false;
  192342. ComSmartPtr <IPin> pin;
  192343. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192344. {
  192345. ComSmartPtr <IAMPushSource> pushSource;
  192346. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192347. if (pushSource != 0)
  192348. {
  192349. REFERENCE_TIME latency = 0;
  192350. hr = pushSource->GetLatency (&latency);
  192351. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192352. }
  192353. }
  192354. }
  192355. imageSwapLock.enter();
  192356. const int lineStride = width * 3;
  192357. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192358. for (int i = 0; i < height; ++i)
  192359. memcpy (destData.getLinePointer ((height - 1) - i),
  192360. buffer + lineStride * i,
  192361. lineStride);
  192362. imageNeedsFlipping = true;
  192363. imageSwapLock.exit();
  192364. callListeners (*loadingImage);
  192365. sendChangeMessage (this);
  192366. }
  192367. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192368. {
  192369. if (imageNeedsFlipping)
  192370. {
  192371. imageSwapLock.enter();
  192372. swapVariables (loadingImage, activeImage);
  192373. imageNeedsFlipping = false;
  192374. imageSwapLock.exit();
  192375. }
  192376. RectanglePlacement rp (RectanglePlacement::centred);
  192377. double dx = 0, dy = 0, dw = width, dh = height;
  192378. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192379. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192380. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192381. g.saveState();
  192382. g.excludeClipRegion (rx, ry, rw, rh);
  192383. g.fillAll (Colours::black);
  192384. g.restoreState();
  192385. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192386. }
  192387. bool createFileCaptureFilter (const File& file)
  192388. {
  192389. removeFileCaptureFilter();
  192390. file.deleteFile();
  192391. mediaControl->Stop();
  192392. firstRecordedTime = Time();
  192393. recordNextFrameTime = true;
  192394. HRESULT hr = mux.CoCreateInstance (CLSID_AviDest, CLSCTX_INPROC_SERVER);
  192395. if (SUCCEEDED (hr))
  192396. {
  192397. hr = graphBuilder->AddFilter (mux, _T("AVI Mux"));
  192398. if (SUCCEEDED (hr))
  192399. {
  192400. fileWriter.CoCreateInstance (CLSID_FileWriter, CLSCTX_INPROC_SERVER);
  192401. if (SUCCEEDED (hr))
  192402. {
  192403. ComSmartPtr <IFileSinkFilter> fileSink;
  192404. hr = fileWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192405. if (SUCCEEDED (hr))
  192406. {
  192407. AM_MEDIA_TYPE mt;
  192408. zerostruct (mt);
  192409. mt.majortype = MEDIATYPE_Stream;
  192410. mt.subtype = MEDIASUBTYPE_Avi;
  192411. mt.formattype = FORMAT_VideoInfo;
  192412. hr = fileSink->SetFileName (file.getFullPathName(), &mt);
  192413. if (SUCCEEDED (hr))
  192414. {
  192415. hr = graphBuilder->AddFilter (fileWriter, _T("File Writer"));
  192416. if (SUCCEEDED (hr))
  192417. {
  192418. ComSmartPtr <IPin> muxInputPin, muxOutputPin, writerInput;
  192419. if (getPin (mux, PINDIR_INPUT, &muxInputPin)
  192420. && getPin (mux, PINDIR_OUTPUT, &muxOutputPin)
  192421. && getPin (fileWriter, PINDIR_INPUT, &writerInput))
  192422. {
  192423. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, muxInputPin);
  192424. if (SUCCEEDED (hr))
  192425. {
  192426. hr = graphBuilder->Connect (muxOutputPin, writerInput);
  192427. if (SUCCEEDED (hr))
  192428. {
  192429. if (ok && activeUsers > 0)
  192430. mediaControl->Run();
  192431. return true;
  192432. }
  192433. }
  192434. }
  192435. }
  192436. }
  192437. }
  192438. }
  192439. }
  192440. }
  192441. removeFileCaptureFilter();
  192442. if (ok && activeUsers > 0)
  192443. mediaControl->Run();
  192444. return false;
  192445. }
  192446. void removeFileCaptureFilter()
  192447. {
  192448. mediaControl->Stop();
  192449. if (mux != 0)
  192450. {
  192451. graphBuilder->RemoveFilter (mux);
  192452. mux = 0;
  192453. }
  192454. if (fileWriter != 0)
  192455. {
  192456. graphBuilder->RemoveFilter (fileWriter);
  192457. fileWriter = 0;
  192458. }
  192459. if (ok && activeUsers > 0)
  192460. mediaControl->Run();
  192461. }
  192462. void addListener (CameraImageListener* listenerToAdd)
  192463. {
  192464. const ScopedLock sl (listenerLock);
  192465. if (listeners.size() == 0)
  192466. addUser();
  192467. listeners.addIfNotAlreadyThere (listenerToAdd);
  192468. }
  192469. void removeListener (CameraImageListener* listenerToRemove)
  192470. {
  192471. const ScopedLock sl (listenerLock);
  192472. listeners.removeValue (listenerToRemove);
  192473. if (listeners.size() == 0)
  192474. removeUser();
  192475. }
  192476. void callListeners (Image& image)
  192477. {
  192478. const ScopedLock sl (listenerLock);
  192479. for (int i = listeners.size(); --i >= 0;)
  192480. {
  192481. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192482. if (l != 0)
  192483. l->imageReceived (image);
  192484. }
  192485. }
  192486. class DShowCaptureViewerComp : public Component,
  192487. public ChangeListener
  192488. {
  192489. public:
  192490. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192491. : owner (owner_)
  192492. {
  192493. setOpaque (true);
  192494. owner->addChangeListener (this);
  192495. owner->addUser();
  192496. owner->viewerComps.add (this);
  192497. setSize (owner_->width, owner_->height);
  192498. }
  192499. ~DShowCaptureViewerComp()
  192500. {
  192501. if (owner != 0)
  192502. {
  192503. owner->viewerComps.removeValue (this);
  192504. owner->removeUser();
  192505. owner->removeChangeListener (this);
  192506. }
  192507. }
  192508. void ownerDeleted()
  192509. {
  192510. owner = 0;
  192511. }
  192512. void paint (Graphics& g)
  192513. {
  192514. g.setColour (Colours::black);
  192515. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192516. if (owner != 0)
  192517. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192518. else
  192519. g.fillAll (Colours::black);
  192520. }
  192521. void changeListenerCallback (void*)
  192522. {
  192523. repaint();
  192524. }
  192525. private:
  192526. DShowCameraDeviceInteral* owner;
  192527. };
  192528. bool ok;
  192529. int width, height;
  192530. Time firstRecordedTime;
  192531. VoidArray viewerComps;
  192532. private:
  192533. CameraDevice* const owner;
  192534. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192535. ComSmartPtr <IBaseFilter> filter;
  192536. ComSmartPtr <IBaseFilter> smartTee;
  192537. ComSmartPtr <IGraphBuilder> graphBuilder;
  192538. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192539. ComSmartPtr <IMediaControl> mediaControl;
  192540. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192541. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192542. ComSmartPtr <IBaseFilter> mux, fileWriter;
  192543. int activeUsers;
  192544. Array <int> widths, heights;
  192545. DWORD graphRegistrationID;
  192546. CriticalSection imageSwapLock;
  192547. bool imageNeedsFlipping;
  192548. Image* loadingImage;
  192549. Image* activeImage;
  192550. bool recordNextFrameTime;
  192551. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192552. {
  192553. widths.clear();
  192554. heights.clear();
  192555. int count = 0, size = 0;
  192556. streamConfig->GetNumberOfCapabilities (&count, &size);
  192557. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192558. {
  192559. for (int i = 0; i < count; ++i)
  192560. {
  192561. VIDEO_STREAM_CONFIG_CAPS scc;
  192562. AM_MEDIA_TYPE* config;
  192563. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192564. if (SUCCEEDED (hr))
  192565. {
  192566. const int w = scc.InputSize.cx;
  192567. const int h = scc.InputSize.cy;
  192568. bool duplicate = false;
  192569. for (int j = widths.size(); --j >= 0;)
  192570. {
  192571. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192572. {
  192573. duplicate = true;
  192574. break;
  192575. }
  192576. }
  192577. if (! duplicate)
  192578. {
  192579. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192580. widths.add (w);
  192581. heights.add (h);
  192582. }
  192583. deleteMediaType (config);
  192584. }
  192585. }
  192586. }
  192587. }
  192588. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192589. const int minWidth, const int minHeight,
  192590. const int maxWidth, const int maxHeight)
  192591. {
  192592. int count = 0, size = 0;
  192593. streamConfig->GetNumberOfCapabilities (&count, &size);
  192594. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192595. {
  192596. for (int i = 0; i < count; ++i)
  192597. {
  192598. VIDEO_STREAM_CONFIG_CAPS scc;
  192599. AM_MEDIA_TYPE* config;
  192600. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192601. if (SUCCEEDED (hr))
  192602. {
  192603. if (scc.InputSize.cx >= minWidth
  192604. && scc.InputSize.cy >= minHeight
  192605. && scc.InputSize.cx <= maxWidth
  192606. && scc.InputSize.cy <= maxHeight)
  192607. {
  192608. hr = streamConfig->SetFormat (config);
  192609. deleteMediaType (config);
  192610. return SUCCEEDED (hr);
  192611. }
  192612. deleteMediaType (config);
  192613. }
  192614. }
  192615. }
  192616. return false;
  192617. }
  192618. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192619. {
  192620. ComSmartPtr <IEnumPins> enumerator;
  192621. ComSmartPtr <IPin> pin;
  192622. filter->EnumPins (&enumerator);
  192623. while (enumerator->Next (1, &pin, 0) == S_OK)
  192624. {
  192625. PIN_DIRECTION dir;
  192626. pin->QueryDirection (&dir);
  192627. if (wantedDirection == dir)
  192628. {
  192629. PIN_INFO info;
  192630. zerostruct (info);
  192631. pin->QueryPinInfo (&info);
  192632. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192633. {
  192634. pin.p->AddRef();
  192635. *result = pin;
  192636. return true;
  192637. }
  192638. }
  192639. }
  192640. return false;
  192641. }
  192642. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192643. {
  192644. ComSmartPtr <IPin> in, out;
  192645. return getPin (first, PINDIR_OUTPUT, &out)
  192646. && getPin (second, PINDIR_INPUT, &in)
  192647. && SUCCEEDED (graphBuilder->Connect (out, in));
  192648. }
  192649. bool addGraphToRot()
  192650. {
  192651. ComSmartPtr <IRunningObjectTable> rot;
  192652. if (FAILED (GetRunningObjectTable (0, &rot)))
  192653. return false;
  192654. ComSmartPtr <IMoniker> moniker;
  192655. WCHAR buffer[128];
  192656. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192657. if (FAILED (hr))
  192658. return false;
  192659. graphRegistrationID = 0;
  192660. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192661. }
  192662. void removeGraphFromRot()
  192663. {
  192664. ComSmartPtr <IRunningObjectTable> rot;
  192665. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192666. rot->Revoke (graphRegistrationID);
  192667. }
  192668. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192669. {
  192670. if (pmt->cbFormat != 0)
  192671. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192672. if (pmt->pUnk != 0)
  192673. pmt->pUnk->Release();
  192674. CoTaskMemFree (pmt);
  192675. }
  192676. class GrabberCallback : public ISampleGrabberCB
  192677. {
  192678. public:
  192679. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192680. : owner (owner_)
  192681. {
  192682. }
  192683. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192684. {
  192685. if (id == IID_IUnknown)
  192686. *result = dynamic_cast <IUnknown*> (this);
  192687. else if (id == IID_ISampleGrabberCB)
  192688. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192689. else
  192690. {
  192691. *result = 0;
  192692. return E_NOINTERFACE;
  192693. }
  192694. AddRef();
  192695. return S_OK;
  192696. }
  192697. ULONG __stdcall AddRef() { return ++refCount; }
  192698. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192699. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192700. {
  192701. return E_FAIL;
  192702. }
  192703. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192704. {
  192705. owner.handleFrame (time, buffer, bufferSize);
  192706. return S_OK;
  192707. }
  192708. private:
  192709. int refCount;
  192710. DShowCameraDeviceInteral& owner;
  192711. GrabberCallback (const GrabberCallback&);
  192712. const GrabberCallback& operator= (const GrabberCallback&);
  192713. };
  192714. ComSmartPtr <GrabberCallback> callback;
  192715. VoidArray listeners;
  192716. CriticalSection listenerLock;
  192717. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192718. const DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192719. };
  192720. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192721. : name (name_)
  192722. {
  192723. isRecording = false;
  192724. }
  192725. CameraDevice::~CameraDevice()
  192726. {
  192727. stopRecording();
  192728. delete (DShowCameraDeviceInteral*) internal;
  192729. internal = 0;
  192730. }
  192731. Component* CameraDevice::createViewerComponent()
  192732. {
  192733. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192734. }
  192735. const String CameraDevice::getFileExtension()
  192736. {
  192737. return ".avi";
  192738. }
  192739. void CameraDevice::startRecordingToFile (const File& file)
  192740. {
  192741. stopRecording();
  192742. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192743. d->addUser();
  192744. isRecording = d->createFileCaptureFilter (file);
  192745. }
  192746. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192747. {
  192748. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192749. return d->firstRecordedTime;
  192750. }
  192751. void CameraDevice::stopRecording()
  192752. {
  192753. if (isRecording)
  192754. {
  192755. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192756. d->removeFileCaptureFilter();
  192757. d->removeUser();
  192758. isRecording = false;
  192759. }
  192760. }
  192761. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192762. {
  192763. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192764. if (listenerToAdd != 0)
  192765. d->addListener (listenerToAdd);
  192766. }
  192767. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192768. {
  192769. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192770. if (listenerToRemove != 0)
  192771. d->removeListener (listenerToRemove);
  192772. }
  192773. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192774. const int deviceIndexToOpen,
  192775. String& name)
  192776. {
  192777. int index = 0;
  192778. ComSmartPtr <IBaseFilter> result;
  192779. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192780. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192781. if (SUCCEEDED (hr))
  192782. {
  192783. ComSmartPtr <IEnumMoniker> enumerator;
  192784. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192785. if (SUCCEEDED (hr) && enumerator != 0)
  192786. {
  192787. ComSmartPtr <IBaseFilter> captureFilter;
  192788. ComSmartPtr <IMoniker> moniker;
  192789. ULONG fetched;
  192790. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192791. {
  192792. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192793. if (SUCCEEDED (hr))
  192794. {
  192795. ComSmartPtr <IPropertyBag> propertyBag;
  192796. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192797. if (SUCCEEDED (hr))
  192798. {
  192799. VARIANT var;
  192800. var.vt = VT_BSTR;
  192801. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192802. propertyBag = 0;
  192803. if (SUCCEEDED (hr))
  192804. {
  192805. if (names != 0)
  192806. names->add (var.bstrVal);
  192807. if (index == deviceIndexToOpen)
  192808. {
  192809. name = var.bstrVal;
  192810. result = captureFilter;
  192811. captureFilter = 0;
  192812. break;
  192813. }
  192814. ++index;
  192815. }
  192816. moniker = 0;
  192817. }
  192818. captureFilter = 0;
  192819. }
  192820. }
  192821. }
  192822. }
  192823. return result;
  192824. }
  192825. const StringArray CameraDevice::getAvailableDevices()
  192826. {
  192827. StringArray devs;
  192828. String dummy;
  192829. enumerateCameras (&devs, -1, dummy);
  192830. return devs;
  192831. }
  192832. CameraDevice* CameraDevice::openDevice (int index,
  192833. int minWidth, int minHeight,
  192834. int maxWidth, int maxHeight)
  192835. {
  192836. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192837. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192838. if (SUCCEEDED (hr))
  192839. {
  192840. String name;
  192841. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192842. if (filter != 0)
  192843. {
  192844. CameraDevice* const cam = new CameraDevice (name, index);
  192845. DShowCameraDeviceInteral* const intern
  192846. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192847. minWidth, minHeight, maxWidth, maxHeight);
  192848. cam->internal = intern;
  192849. if (intern->ok)
  192850. return cam;
  192851. else
  192852. delete cam;
  192853. }
  192854. }
  192855. return 0;
  192856. }
  192857. #endif
  192858. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192859. #endif
  192860. // Auto-link the other win32 libs that are needed by library calls..
  192861. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192862. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192863. // Auto-links to various win32 libs that are needed by library calls..
  192864. #pragma comment(lib, "kernel32.lib")
  192865. #pragma comment(lib, "user32.lib")
  192866. #pragma comment(lib, "shell32.lib")
  192867. #pragma comment(lib, "gdi32.lib")
  192868. #pragma comment(lib, "vfw32.lib")
  192869. #pragma comment(lib, "comdlg32.lib")
  192870. #pragma comment(lib, "winmm.lib")
  192871. #pragma comment(lib, "wininet.lib")
  192872. #pragma comment(lib, "ole32.lib")
  192873. #pragma comment(lib, "oleaut32.lib")
  192874. #pragma comment(lib, "advapi32.lib")
  192875. #pragma comment(lib, "ws2_32.lib")
  192876. #pragma comment(lib, "comsupp.lib")
  192877. #pragma comment(lib, "version.lib")
  192878. #if JUCE_OPENGL
  192879. #pragma comment(lib, "OpenGL32.Lib")
  192880. #pragma comment(lib, "GlU32.Lib")
  192881. #endif
  192882. #if JUCE_QUICKTIME
  192883. #pragma comment (lib, "QTMLClient.lib")
  192884. #endif
  192885. #if JUCE_USE_CAMERA
  192886. #pragma comment (lib, "Strmiids.lib")
  192887. #endif
  192888. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192889. #endif
  192890. END_JUCE_NAMESPACE
  192891. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192892. #endif
  192893. #if JUCE_LINUX
  192894. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192895. BEGIN_JUCE_NAMESPACE
  192896. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192897. #define SUPPORT_AFFINITIES 1
  192898. #endif
  192899. #define JUCE_INCLUDED_FILE 1
  192900. // Now include the actual code files..
  192901. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192902. CriticalSection::CriticalSection() throw()
  192903. {
  192904. pthread_mutexattr_t atts;
  192905. pthread_mutexattr_init (&atts);
  192906. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192907. pthread_mutex_init (&internal, &atts);
  192908. }
  192909. CriticalSection::~CriticalSection() throw()
  192910. {
  192911. pthread_mutex_destroy (&internal);
  192912. }
  192913. void CriticalSection::enter() const throw()
  192914. {
  192915. pthread_mutex_lock (&internal);
  192916. }
  192917. bool CriticalSection::tryEnter() const throw()
  192918. {
  192919. return pthread_mutex_trylock (&internal) == 0;
  192920. }
  192921. void CriticalSection::exit() const throw()
  192922. {
  192923. pthread_mutex_unlock (&internal);
  192924. }
  192925. struct EventStruct
  192926. {
  192927. pthread_cond_t condition;
  192928. pthread_mutex_t mutex;
  192929. bool triggered;
  192930. };
  192931. WaitableEvent::WaitableEvent() throw()
  192932. {
  192933. EventStruct* const es = new EventStruct();
  192934. es->triggered = false;
  192935. pthread_cond_init (&es->condition, 0);
  192936. pthread_mutex_init (&es->mutex, 0);
  192937. internal = es;
  192938. }
  192939. WaitableEvent::~WaitableEvent() throw()
  192940. {
  192941. EventStruct* const es = (EventStruct*) internal;
  192942. pthread_cond_destroy (&es->condition);
  192943. pthread_mutex_destroy (&es->mutex);
  192944. delete es;
  192945. }
  192946. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192947. {
  192948. EventStruct* const es = (EventStruct*) internal;
  192949. pthread_mutex_lock (&es->mutex);
  192950. if (timeOutMillisecs < 0)
  192951. {
  192952. while (! es->triggered)
  192953. pthread_cond_wait (&es->condition, &es->mutex);
  192954. }
  192955. else
  192956. {
  192957. while (! es->triggered)
  192958. {
  192959. struct timeval t;
  192960. gettimeofday (&t, 0);
  192961. struct timespec time;
  192962. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  192963. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192964. if (time.tv_nsec >= 1000000000)
  192965. {
  192966. time.tv_nsec -= 1000000000;
  192967. time.tv_sec++;
  192968. }
  192969. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  192970. {
  192971. pthread_mutex_unlock (&es->mutex);
  192972. return false;
  192973. }
  192974. }
  192975. }
  192976. es->triggered = false;
  192977. pthread_mutex_unlock (&es->mutex);
  192978. return true;
  192979. }
  192980. void WaitableEvent::signal() const throw()
  192981. {
  192982. EventStruct* const es = (EventStruct*) internal;
  192983. pthread_mutex_lock (&es->mutex);
  192984. es->triggered = true;
  192985. pthread_cond_broadcast (&es->condition);
  192986. pthread_mutex_unlock (&es->mutex);
  192987. }
  192988. void WaitableEvent::reset() const throw()
  192989. {
  192990. EventStruct* const es = (EventStruct*) internal;
  192991. pthread_mutex_lock (&es->mutex);
  192992. es->triggered = false;
  192993. pthread_mutex_unlock (&es->mutex);
  192994. }
  192995. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192996. {
  192997. struct timespec time;
  192998. time.tv_sec = millisecs / 1000;
  192999. time.tv_nsec = (millisecs % 1000) * 1000000;
  193000. nanosleep (&time, 0);
  193001. }
  193002. const tchar File::separator = T('/');
  193003. const tchar* File::separatorString = T("/");
  193004. bool juce_copyFile (const String& s, const String& d);
  193005. static bool juce_stat (const String& fileName, struct stat& info)
  193006. {
  193007. return fileName.isNotEmpty()
  193008. && (stat (fileName.toUTF8(), &info) == 0);
  193009. }
  193010. bool juce_isDirectory (const String& fileName)
  193011. {
  193012. struct stat info;
  193013. return fileName.isEmpty()
  193014. || (juce_stat (fileName, info)
  193015. && ((info.st_mode & S_IFDIR) != 0));
  193016. }
  193017. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  193018. {
  193019. if (fileName.isEmpty())
  193020. return false;
  193021. const char* const fileNameUTF8 = fileName.toUTF8();
  193022. bool exists = access (fileNameUTF8, F_OK) == 0;
  193023. if (exists && dontCountDirectories)
  193024. {
  193025. struct stat info;
  193026. const int res = stat (fileNameUTF8, &info);
  193027. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  193028. exists = false;
  193029. }
  193030. return exists;
  193031. }
  193032. int64 juce_getFileSize (const String& fileName)
  193033. {
  193034. struct stat info;
  193035. return juce_stat (fileName, info) ? info.st_size : 0;
  193036. }
  193037. bool juce_canWriteToFile (const String& fileName)
  193038. {
  193039. return access (fileName.toUTF8(), W_OK) == 0;
  193040. }
  193041. bool juce_deleteFile (const String& fileName)
  193042. {
  193043. if (juce_isDirectory (fileName))
  193044. return rmdir ((const char*) fileName.toUTF8()) == 0;
  193045. else
  193046. return remove ((const char*) fileName.toUTF8()) == 0;
  193047. }
  193048. bool juce_moveFile (const String& source, const String& dest)
  193049. {
  193050. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  193051. return true;
  193052. if (juce_canWriteToFile (source)
  193053. && juce_copyFile (source, dest))
  193054. {
  193055. if (juce_deleteFile (source))
  193056. return true;
  193057. juce_deleteFile (dest);
  193058. }
  193059. return false;
  193060. }
  193061. void juce_createDirectory (const String& fileName)
  193062. {
  193063. mkdir (fileName.toUTF8(), 0777);
  193064. }
  193065. void* juce_fileOpen (const String& fileName, bool forWriting)
  193066. {
  193067. int flags = O_RDONLY;
  193068. if (forWriting)
  193069. {
  193070. if (juce_fileExists (fileName, false))
  193071. {
  193072. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  193073. if (f != -1)
  193074. lseek (f, 0, SEEK_END);
  193075. return (void*) f;
  193076. }
  193077. else
  193078. {
  193079. flags = O_RDWR + O_CREAT;
  193080. }
  193081. }
  193082. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  193083. }
  193084. void juce_fileClose (void* handle)
  193085. {
  193086. if (handle != 0)
  193087. close ((int) (pointer_sized_int) handle);
  193088. }
  193089. int juce_fileRead (void* handle, void* buffer, int size)
  193090. {
  193091. if (handle != 0)
  193092. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  193093. return 0;
  193094. }
  193095. int juce_fileWrite (void* handle, const void* buffer, int size)
  193096. {
  193097. if (handle != 0)
  193098. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  193099. return 0;
  193100. }
  193101. int64 juce_fileSetPosition (void* handle, int64 pos)
  193102. {
  193103. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  193104. return pos;
  193105. return -1;
  193106. }
  193107. int64 juce_fileGetPosition (void* handle)
  193108. {
  193109. if (handle != 0)
  193110. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  193111. else
  193112. return -1;
  193113. }
  193114. void juce_fileFlush (void* handle)
  193115. {
  193116. if (handle != 0)
  193117. fsync ((int) (pointer_sized_int) handle);
  193118. }
  193119. const File juce_getExecutableFile()
  193120. {
  193121. Dl_info exeInfo;
  193122. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  193123. return File (exeInfo.dli_fname);
  193124. }
  193125. // if this file doesn't exist, find a parent of it that does..
  193126. static bool doStatFS (const File* file, struct statfs& result)
  193127. {
  193128. File f (*file);
  193129. for (int i = 5; --i >= 0;)
  193130. {
  193131. if (f.exists())
  193132. break;
  193133. f = f.getParentDirectory();
  193134. }
  193135. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  193136. }
  193137. int64 File::getBytesFreeOnVolume() const
  193138. {
  193139. struct statfs buf;
  193140. if (doStatFS (this, buf))
  193141. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  193142. return 0;
  193143. }
  193144. int64 File::getVolumeTotalSize() const
  193145. {
  193146. struct statfs buf;
  193147. if (doStatFS (this, buf))
  193148. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  193149. return 0;
  193150. }
  193151. const String juce_getVolumeLabel (const String& filenameOnVolume,
  193152. int& volumeSerialNumber)
  193153. {
  193154. volumeSerialNumber = 0;
  193155. #if JUCE_MAC
  193156. struct VolAttrBuf
  193157. {
  193158. u_int32_t length;
  193159. attrreference_t mountPointRef;
  193160. char mountPointSpace [MAXPATHLEN];
  193161. } attrBuf;
  193162. struct attrlist attrList;
  193163. zerostruct (attrList);
  193164. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  193165. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  193166. File f (filenameOnVolume);
  193167. for (;;)
  193168. {
  193169. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  193170. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  193171. {
  193172. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  193173. (int) attrBuf.mountPointRef.attr_length);
  193174. }
  193175. const File parent (f.getParentDirectory());
  193176. if (f == parent)
  193177. break;
  193178. f = parent;
  193179. }
  193180. #endif
  193181. return String::empty;
  193182. }
  193183. void juce_runSystemCommand (const String& command)
  193184. {
  193185. int result = system ((const char*) command.toUTF8());
  193186. (void) result;
  193187. }
  193188. const String juce_getOutputFromCommand (const String& command)
  193189. {
  193190. // slight bodge here, as we just pipe the output into a temp file and read it...
  193191. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  193192. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  193193. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  193194. String result (tempFile.loadFileAsString());
  193195. tempFile.deleteFile();
  193196. return result;
  193197. }
  193198. InterProcessLock::InterProcessLock (const String& name_)
  193199. : internal (0),
  193200. name (name_),
  193201. reentrancyLevel (0)
  193202. {
  193203. #if JUCE_MAC
  193204. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  193205. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  193206. #else
  193207. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  193208. #endif
  193209. temp.create();
  193210. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  193211. }
  193212. InterProcessLock::~InterProcessLock()
  193213. {
  193214. while (reentrancyLevel > 0)
  193215. this->exit();
  193216. close (internal);
  193217. }
  193218. bool InterProcessLock::enter (const int timeOutMillisecs)
  193219. {
  193220. if (internal == 0)
  193221. return false;
  193222. if (reentrancyLevel != 0)
  193223. return true;
  193224. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  193225. struct flock fl;
  193226. zerostruct (fl);
  193227. fl.l_whence = SEEK_SET;
  193228. fl.l_type = F_WRLCK;
  193229. for (;;)
  193230. {
  193231. const int result = fcntl (internal, F_SETLK, &fl);
  193232. if (result >= 0)
  193233. {
  193234. ++reentrancyLevel;
  193235. return true;
  193236. }
  193237. if (errno != EINTR)
  193238. {
  193239. if (timeOutMillisecs == 0
  193240. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  193241. break;
  193242. Thread::sleep (10);
  193243. }
  193244. }
  193245. return false;
  193246. }
  193247. void InterProcessLock::exit()
  193248. {
  193249. if (reentrancyLevel > 0 && internal != 0)
  193250. {
  193251. --reentrancyLevel;
  193252. struct flock fl;
  193253. zerostruct (fl);
  193254. fl.l_whence = SEEK_SET;
  193255. fl.l_type = F_UNLCK;
  193256. for (;;)
  193257. {
  193258. const int result = fcntl (internal, F_SETLKW, &fl);
  193259. if (result >= 0 || errno != EINTR)
  193260. break;
  193261. }
  193262. }
  193263. }
  193264. /*** End of inlined file: juce_posix_SharedCode.h ***/
  193265. /*** Start of inlined file: juce_linux_Files.cpp ***/
  193266. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193267. // compiled on its own).
  193268. #if JUCE_INCLUDED_FILE
  193269. #define U_ISOFS_SUPER_MAGIC (short) 0x9660 // linux/iso_fs.h
  193270. #define U_MSDOS_SUPER_MAGIC (short) 0x4d44 // linux/msdos_fs.h
  193271. #define U_NFS_SUPER_MAGIC (short) 0x6969 // linux/nfs_fs.h
  193272. #define U_SMB_SUPER_MAGIC (short) 0x517B // linux/smb_fs.h
  193273. void juce_getFileTimes (const String& fileName,
  193274. int64& modificationTime,
  193275. int64& accessTime,
  193276. int64& creationTime)
  193277. {
  193278. modificationTime = 0;
  193279. accessTime = 0;
  193280. creationTime = 0;
  193281. struct stat info;
  193282. const int res = stat (fileName.toUTF8(), &info);
  193283. if (res == 0)
  193284. {
  193285. modificationTime = (int64) info.st_mtime * 1000;
  193286. accessTime = (int64) info.st_atime * 1000;
  193287. creationTime = (int64) info.st_ctime * 1000;
  193288. }
  193289. }
  193290. bool juce_setFileTimes (const String& fileName,
  193291. int64 modificationTime,
  193292. int64 accessTime,
  193293. int64 creationTime)
  193294. {
  193295. struct utimbuf times;
  193296. times.actime = (time_t) (accessTime / 1000);
  193297. times.modtime = (time_t) (modificationTime / 1000);
  193298. return utime (fileName.toUTF8(), &times) == 0;
  193299. }
  193300. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193301. {
  193302. struct stat info;
  193303. const int res = stat (fileName.toUTF8(), &info);
  193304. if (res != 0)
  193305. return false;
  193306. info.st_mode &= 0777; // Just permissions
  193307. if( isReadOnly )
  193308. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193309. else
  193310. // Give everybody write permission?
  193311. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193312. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193313. }
  193314. bool juce_copyFile (const String& s, const String& d)
  193315. {
  193316. const File source (s), dest (d);
  193317. FileInputStream* in = source.createInputStream();
  193318. bool ok = false;
  193319. if (in != 0)
  193320. {
  193321. if (dest.deleteFile())
  193322. {
  193323. FileOutputStream* const out = dest.createOutputStream();
  193324. if (out != 0)
  193325. {
  193326. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193327. delete out;
  193328. ok = (bytesCopied == source.getSize());
  193329. if (! ok)
  193330. dest.deleteFile();
  193331. }
  193332. }
  193333. delete in;
  193334. }
  193335. return ok;
  193336. }
  193337. const StringArray juce_getFileSystemRoots()
  193338. {
  193339. StringArray s;
  193340. s.add (T("/"));
  193341. return s;
  193342. }
  193343. bool File::isOnCDRomDrive() const
  193344. {
  193345. struct statfs buf;
  193346. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193347. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193348. // Assume not if this fails for some reason
  193349. return false;
  193350. }
  193351. bool File::isOnHardDisk() const
  193352. {
  193353. struct statfs buf;
  193354. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193355. {
  193356. switch (buf.f_type)
  193357. {
  193358. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193359. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193360. case U_NFS_SUPER_MAGIC: // Network NFS
  193361. case U_SMB_SUPER_MAGIC: // Network Samba
  193362. return false;
  193363. default:
  193364. // Assume anything else is a hard-disk (but note it could
  193365. // be a RAM disk. There isn't a good way of determining
  193366. // this for sure)
  193367. return true;
  193368. }
  193369. }
  193370. // Assume so if this fails for some reason
  193371. return true;
  193372. }
  193373. bool File::isOnRemovableDrive() const
  193374. {
  193375. jassertfalse // xxx not implemented for linux!
  193376. return false;
  193377. }
  193378. bool File::isHidden() const
  193379. {
  193380. return getFileName().startsWithChar (T('.'));
  193381. }
  193382. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193383. const File File::getSpecialLocation (const SpecialLocationType type)
  193384. {
  193385. switch (type)
  193386. {
  193387. case userHomeDirectory:
  193388. {
  193389. const char* homeDir = getenv ("HOME");
  193390. if (homeDir == 0)
  193391. {
  193392. struct passwd* const pw = getpwuid (getuid());
  193393. if (pw != 0)
  193394. homeDir = pw->pw_dir;
  193395. }
  193396. return File (String::fromUTF8 ((const uint8*) homeDir));
  193397. }
  193398. case userDocumentsDirectory:
  193399. case userMusicDirectory:
  193400. case userMoviesDirectory:
  193401. case userApplicationDataDirectory:
  193402. return File ("~");
  193403. case userDesktopDirectory:
  193404. return File ("~/Desktop");
  193405. case commonApplicationDataDirectory:
  193406. return File ("/var");
  193407. case globalApplicationsDirectory:
  193408. return File ("/usr");
  193409. case tempDirectory:
  193410. {
  193411. File tmp ("/var/tmp");
  193412. if (! tmp.isDirectory())
  193413. {
  193414. tmp = T("/tmp");
  193415. if (! tmp.isDirectory())
  193416. tmp = File::getCurrentWorkingDirectory();
  193417. }
  193418. return tmp;
  193419. }
  193420. case invokedExecutableFile:
  193421. if (juce_Argv0 != 0)
  193422. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  193423. // deliberate fall-through...
  193424. case currentExecutableFile:
  193425. case currentApplicationFile:
  193426. return juce_getExecutableFile();
  193427. default:
  193428. jassertfalse // unknown type?
  193429. break;
  193430. }
  193431. return File::nonexistent;
  193432. }
  193433. const File File::getCurrentWorkingDirectory()
  193434. {
  193435. char buf [2048];
  193436. return File (String::fromUTF8 ((const uint8*) getcwd (buf, sizeof (buf))));
  193437. }
  193438. bool File::setAsCurrentWorkingDirectory() const
  193439. {
  193440. return chdir (getFullPathName().toUTF8()) == 0;
  193441. }
  193442. const String File::getVersion() const
  193443. {
  193444. return String::empty; // xxx not yet implemented
  193445. }
  193446. const File File::getLinkedTarget() const
  193447. {
  193448. char buffer [4096];
  193449. size_t numChars = readlink ((const char*) getFullPathName().toUTF8(),
  193450. buffer, sizeof (buffer));
  193451. if (numChars > 0 && numChars <= sizeof (buffer))
  193452. return File (String::fromUTF8 ((const uint8*) buffer, (int) numChars));
  193453. return *this;
  193454. }
  193455. bool File::moveToTrash() const
  193456. {
  193457. if (! exists())
  193458. return true;
  193459. File trashCan (T("~/.Trash"));
  193460. if (! trashCan.isDirectory())
  193461. trashCan = T("~/.local/share/Trash/files");
  193462. if (! trashCan.isDirectory())
  193463. return false;
  193464. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193465. getFileExtension()));
  193466. }
  193467. struct FindFileStruct
  193468. {
  193469. String parentDir, wildCard;
  193470. DIR* dir;
  193471. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193472. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193473. {
  193474. const char* const wildcardUTF8 = wildCard.toUTF8();
  193475. for (;;)
  193476. {
  193477. struct dirent* const de = readdir (dir);
  193478. if (de == 0)
  193479. break;
  193480. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193481. {
  193482. result = String::fromUTF8 ((const uint8*) de->d_name);
  193483. const String path (parentDir + result);
  193484. if (isDir != 0 || fileSize != 0)
  193485. {
  193486. struct stat info;
  193487. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193488. if (isDir != 0)
  193489. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193490. if (isHidden != 0)
  193491. *isHidden = (de->d_name[0] == '.');
  193492. if (fileSize != 0)
  193493. *fileSize = statOk ? info.st_size : 0;
  193494. }
  193495. if (modTime != 0 || creationTime != 0)
  193496. {
  193497. int64 m, a, c;
  193498. juce_getFileTimes (path, m, a, c);
  193499. if (modTime != 0)
  193500. *modTime = m;
  193501. if (creationTime != 0)
  193502. *creationTime = c;
  193503. }
  193504. if (isReadOnly != 0)
  193505. *isReadOnly = ! juce_canWriteToFile (path);
  193506. return true;
  193507. }
  193508. }
  193509. return false;
  193510. }
  193511. };
  193512. // returns 0 on failure
  193513. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193514. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193515. Time* creationTime, bool* isReadOnly)
  193516. {
  193517. DIR* d = opendir (directory.toUTF8());
  193518. if (d != 0)
  193519. {
  193520. FindFileStruct* ff = new FindFileStruct();
  193521. ff->parentDir = directory;
  193522. if (!ff->parentDir.endsWithChar (File::separator))
  193523. ff->parentDir += File::separator;
  193524. ff->wildCard = wildCard;
  193525. if (wildCard == T("*.*"))
  193526. ff->wildCard = T("*");
  193527. ff->dir = d;
  193528. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193529. {
  193530. return ff;
  193531. }
  193532. else
  193533. {
  193534. firstResultFile = String::empty;
  193535. isDir = false;
  193536. isHidden = false;
  193537. closedir (d);
  193538. delete ff;
  193539. }
  193540. }
  193541. return 0;
  193542. }
  193543. bool juce_findFileNext (void* handle, String& resultFile,
  193544. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193545. {
  193546. FindFileStruct* const ff = (FindFileStruct*) handle;
  193547. if (ff != 0)
  193548. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193549. return false;
  193550. }
  193551. void juce_findFileClose (void* handle)
  193552. {
  193553. FindFileStruct* const ff = (FindFileStruct*) handle;
  193554. if (ff != 0)
  193555. {
  193556. closedir (ff->dir);
  193557. delete ff;
  193558. }
  193559. }
  193560. bool juce_launchFile (const String& fileName,
  193561. const String& parameters)
  193562. {
  193563. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193564. cmdString << " " << parameters;
  193565. if (URL::isProbablyAWebsiteURL (fileName)
  193566. || cmdString.startsWithIgnoreCase (T("file:"))
  193567. || URL::isProbablyAnEmailAddress (fileName))
  193568. {
  193569. // create a command that tries to launch a bunch of likely browsers
  193570. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193571. StringArray cmdLines;
  193572. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193573. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193574. cmdString = cmdLines.joinIntoString (T(" || "));
  193575. }
  193576. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193577. const int cpid = fork();
  193578. if (cpid == 0)
  193579. {
  193580. setsid();
  193581. // Child process
  193582. execve (argv[0], (char**) argv, environ);
  193583. exit (0);
  193584. }
  193585. return cpid >= 0;
  193586. }
  193587. void File::revealToUser() const
  193588. {
  193589. if (isDirectory())
  193590. startAsProcess();
  193591. else if (getParentDirectory().exists())
  193592. getParentDirectory().startAsProcess();
  193593. }
  193594. #endif
  193595. /*** End of inlined file: juce_linux_Files.cpp ***/
  193596. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193597. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193598. // compiled on its own).
  193599. #if JUCE_INCLUDED_FILE
  193600. struct NamedPipeInternal
  193601. {
  193602. String pipeInName, pipeOutName;
  193603. int pipeIn, pipeOut;
  193604. bool volatile createdPipe, blocked, stopReadOperation;
  193605. static void signalHandler (int) {}
  193606. };
  193607. void NamedPipe::cancelPendingReads()
  193608. {
  193609. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193610. {
  193611. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193612. intern->stopReadOperation = true;
  193613. char buffer [1] = { 0 };
  193614. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193615. (void) bytesWritten;
  193616. int timeout = 2000;
  193617. while (intern->blocked && --timeout >= 0)
  193618. Thread::sleep (2);
  193619. intern->stopReadOperation = false;
  193620. }
  193621. }
  193622. void NamedPipe::close()
  193623. {
  193624. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193625. if (intern != 0)
  193626. {
  193627. internal = 0;
  193628. if (intern->pipeIn != -1)
  193629. ::close (intern->pipeIn);
  193630. if (intern->pipeOut != -1)
  193631. ::close (intern->pipeOut);
  193632. if (intern->createdPipe)
  193633. {
  193634. unlink (intern->pipeInName);
  193635. unlink (intern->pipeOutName);
  193636. }
  193637. delete intern;
  193638. }
  193639. }
  193640. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193641. {
  193642. close();
  193643. NamedPipeInternal* const intern = new NamedPipeInternal();
  193644. internal = intern;
  193645. intern->createdPipe = createPipe;
  193646. intern->blocked = false;
  193647. intern->stopReadOperation = false;
  193648. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193649. siginterrupt (SIGPIPE, 1);
  193650. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193651. intern->pipeInName = pipePath + T("_in");
  193652. intern->pipeOutName = pipePath + T("_out");
  193653. intern->pipeIn = -1;
  193654. intern->pipeOut = -1;
  193655. if (createPipe)
  193656. {
  193657. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  193658. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  193659. {
  193660. delete intern;
  193661. internal = 0;
  193662. return false;
  193663. }
  193664. }
  193665. return true;
  193666. }
  193667. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193668. {
  193669. int bytesRead = -1;
  193670. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193671. if (intern != 0)
  193672. {
  193673. intern->blocked = true;
  193674. if (intern->pipeIn == -1)
  193675. {
  193676. if (intern->createdPipe)
  193677. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  193678. else
  193679. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  193680. if (intern->pipeIn == -1)
  193681. {
  193682. intern->blocked = false;
  193683. return -1;
  193684. }
  193685. }
  193686. bytesRead = 0;
  193687. char* p = (char*) destBuffer;
  193688. while (bytesRead < maxBytesToRead)
  193689. {
  193690. const int bytesThisTime = maxBytesToRead - bytesRead;
  193691. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193692. if (numRead <= 0 || intern->stopReadOperation)
  193693. {
  193694. bytesRead = -1;
  193695. break;
  193696. }
  193697. bytesRead += numRead;
  193698. p += bytesRead;
  193699. }
  193700. intern->blocked = false;
  193701. }
  193702. return bytesRead;
  193703. }
  193704. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193705. {
  193706. int bytesWritten = -1;
  193707. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193708. if (intern != 0)
  193709. {
  193710. if (intern->pipeOut == -1)
  193711. {
  193712. if (intern->createdPipe)
  193713. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  193714. else
  193715. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  193716. if (intern->pipeOut == -1)
  193717. {
  193718. return -1;
  193719. }
  193720. }
  193721. const char* p = (const char*) sourceBuffer;
  193722. bytesWritten = 0;
  193723. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193724. while (bytesWritten < numBytesToWrite
  193725. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193726. {
  193727. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193728. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193729. if (numWritten <= 0)
  193730. {
  193731. bytesWritten = -1;
  193732. break;
  193733. }
  193734. bytesWritten += numWritten;
  193735. p += bytesWritten;
  193736. }
  193737. }
  193738. return bytesWritten;
  193739. }
  193740. #endif
  193741. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193742. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193743. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193744. // compiled on its own).
  193745. #if JUCE_INCLUDED_FILE
  193746. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  193747. {
  193748. int numResults = 0;
  193749. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193750. if (s != -1)
  193751. {
  193752. char buf [1024];
  193753. struct ifconf ifc;
  193754. ifc.ifc_len = sizeof (buf);
  193755. ifc.ifc_buf = buf;
  193756. ioctl (s, SIOCGIFCONF, &ifc);
  193757. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193758. {
  193759. struct ifreq ifr;
  193760. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193761. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193762. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193763. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193764. && numResults < maxNum)
  193765. {
  193766. int64 a = 0;
  193767. for (int j = 6; --j >= 0;)
  193768. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193769. *addresses++ = a;
  193770. ++numResults;
  193771. }
  193772. }
  193773. close (s);
  193774. }
  193775. return numResults;
  193776. }
  193777. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193778. const String& emailSubject,
  193779. const String& bodyText,
  193780. const StringArray& filesToAttach)
  193781. {
  193782. jassertfalse // xxx todo
  193783. return false;
  193784. }
  193785. class JUCE_HTTPSocketStream
  193786. {
  193787. public:
  193788. JUCE_HTTPSocketStream()
  193789. : readPosition (0),
  193790. socketHandle (-1),
  193791. levelsOfRedirection (0),
  193792. timeoutSeconds (15)
  193793. {
  193794. }
  193795. ~JUCE_HTTPSocketStream()
  193796. {
  193797. closeSocket();
  193798. }
  193799. bool open (const String& url,
  193800. const String& headers,
  193801. const MemoryBlock& postData,
  193802. const bool isPost,
  193803. URL::OpenStreamProgressCallback* callback,
  193804. void* callbackContext,
  193805. int timeOutMs)
  193806. {
  193807. closeSocket();
  193808. uint32 timeOutTime = Time::getMillisecondCounter();
  193809. if (timeOutMs == 0)
  193810. timeOutTime += 60000;
  193811. else if (timeOutMs < 0)
  193812. timeOutTime = 0xffffffff;
  193813. else
  193814. timeOutTime += timeOutMs;
  193815. String hostName, hostPath;
  193816. int hostPort;
  193817. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193818. return false;
  193819. const struct hostent* host = 0;
  193820. int port = 0;
  193821. String proxyName, proxyPath;
  193822. int proxyPort = 0;
  193823. String proxyURL (getenv ("http_proxy"));
  193824. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193825. {
  193826. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193827. return false;
  193828. host = gethostbyname ((const char*) proxyName.toUTF8());
  193829. port = proxyPort;
  193830. }
  193831. else
  193832. {
  193833. host = gethostbyname ((const char*) hostName.toUTF8());
  193834. port = hostPort;
  193835. }
  193836. if (host == 0)
  193837. return false;
  193838. struct sockaddr_in address;
  193839. zerostruct (address);
  193840. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193841. address.sin_family = host->h_addrtype;
  193842. address.sin_port = htons (port);
  193843. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193844. if (socketHandle == -1)
  193845. return false;
  193846. int receiveBufferSize = 16384;
  193847. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193848. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193849. #if JUCE_MAC
  193850. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193851. #endif
  193852. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193853. {
  193854. closeSocket();
  193855. return false;
  193856. }
  193857. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193858. proxyName, proxyPort,
  193859. hostPath, url,
  193860. headers, postData,
  193861. isPost));
  193862. size_t totalHeaderSent = 0;
  193863. while (totalHeaderSent < requestHeader.getSize())
  193864. {
  193865. if (Time::getMillisecondCounter() > timeOutTime)
  193866. {
  193867. closeSocket();
  193868. return false;
  193869. }
  193870. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193871. if (send (socketHandle,
  193872. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193873. numToSend, 0)
  193874. != numToSend)
  193875. {
  193876. closeSocket();
  193877. return false;
  193878. }
  193879. totalHeaderSent += numToSend;
  193880. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193881. {
  193882. closeSocket();
  193883. return false;
  193884. }
  193885. }
  193886. const String responseHeader (readResponse (timeOutTime));
  193887. if (responseHeader.isNotEmpty())
  193888. {
  193889. //DBG (responseHeader);
  193890. StringArray lines;
  193891. lines.addLines (responseHeader);
  193892. // NB - using charToString() here instead of just T(" "), because that was
  193893. // causing a mysterious gcc internal compiler error...
  193894. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  193895. .substring (0, 3).getIntValue();
  193896. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  193897. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  193898. String location (findHeaderItem (lines, T("Location:")));
  193899. if (statusCode >= 300 && statusCode < 400
  193900. && location.isNotEmpty())
  193901. {
  193902. if (! location.startsWithIgnoreCase (T("http://")))
  193903. location = T("http://") + location;
  193904. if (levelsOfRedirection++ < 3)
  193905. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193906. }
  193907. else
  193908. {
  193909. levelsOfRedirection = 0;
  193910. return true;
  193911. }
  193912. }
  193913. closeSocket();
  193914. return false;
  193915. }
  193916. int read (void* buffer, int bytesToRead)
  193917. {
  193918. fd_set readbits;
  193919. FD_ZERO (&readbits);
  193920. FD_SET (socketHandle, &readbits);
  193921. struct timeval tv;
  193922. tv.tv_sec = timeoutSeconds;
  193923. tv.tv_usec = 0;
  193924. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193925. return 0; // (timeout)
  193926. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193927. readPosition += bytesRead;
  193928. return bytesRead;
  193929. }
  193930. int readPosition;
  193931. juce_UseDebuggingNewOperator
  193932. private:
  193933. int socketHandle, levelsOfRedirection;
  193934. const int timeoutSeconds;
  193935. void closeSocket()
  193936. {
  193937. if (socketHandle >= 0)
  193938. close (socketHandle);
  193939. socketHandle = -1;
  193940. }
  193941. const MemoryBlock createRequestHeader (const String& hostName,
  193942. const int hostPort,
  193943. const String& proxyName,
  193944. const int proxyPort,
  193945. const String& hostPath,
  193946. const String& originalURL,
  193947. const String& headers,
  193948. const MemoryBlock& postData,
  193949. const bool isPost)
  193950. {
  193951. String header (isPost ? "POST " : "GET ");
  193952. if (proxyName.isEmpty())
  193953. {
  193954. header << hostPath << " HTTP/1.0\r\nHost: "
  193955. << hostName << ':' << hostPort;
  193956. }
  193957. else
  193958. {
  193959. header << originalURL << " HTTP/1.0\r\nHost: "
  193960. << proxyName << ':' << proxyPort;
  193961. }
  193962. header << "\r\nUser-Agent: JUCE/"
  193963. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193964. << "\r\nConnection: Close\r\nContent-Length: "
  193965. << postData.getSize() << "\r\n"
  193966. << headers << "\r\n";
  193967. MemoryBlock mb;
  193968. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193969. mb.append (postData.getData(), postData.getSize());
  193970. return mb;
  193971. }
  193972. const String readResponse (const uint32 timeOutTime)
  193973. {
  193974. int bytesRead = 0, numConsecutiveLFs = 0;
  193975. MemoryBlock buffer (1024, true);
  193976. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193977. && Time::getMillisecondCounter() <= timeOutTime)
  193978. {
  193979. fd_set readbits;
  193980. FD_ZERO (&readbits);
  193981. FD_SET (socketHandle, &readbits);
  193982. struct timeval tv;
  193983. tv.tv_sec = timeoutSeconds;
  193984. tv.tv_usec = 0;
  193985. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193986. return String::empty; // (timeout)
  193987. buffer.ensureSize (bytesRead + 8, true);
  193988. char* const dest = (char*) buffer.getData() + bytesRead;
  193989. if (recv (socketHandle, dest, 1, 0) == -1)
  193990. return String::empty;
  193991. const char lastByte = *dest;
  193992. ++bytesRead;
  193993. if (lastByte == '\n')
  193994. ++numConsecutiveLFs;
  193995. else if (lastByte != '\r')
  193996. numConsecutiveLFs = 0;
  193997. }
  193998. const String header (String::fromUTF8 ((const uint8*) buffer.getData()));
  193999. if (header.startsWithIgnoreCase (T("HTTP/")))
  194000. return header.trimEnd();
  194001. return String::empty;
  194002. }
  194003. static bool decomposeURL (const String& url,
  194004. String& host, String& path, int& port)
  194005. {
  194006. if (! url.startsWithIgnoreCase (T("http://")))
  194007. return false;
  194008. const int nextSlash = url.indexOfChar (7, '/');
  194009. int nextColon = url.indexOfChar (7, ':');
  194010. if (nextColon > nextSlash && nextSlash > 0)
  194011. nextColon = -1;
  194012. if (nextColon >= 0)
  194013. {
  194014. host = url.substring (7, nextColon);
  194015. if (nextSlash >= 0)
  194016. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  194017. else
  194018. port = url.substring (nextColon + 1).getIntValue();
  194019. }
  194020. else
  194021. {
  194022. port = 80;
  194023. if (nextSlash >= 0)
  194024. host = url.substring (7, nextSlash);
  194025. else
  194026. host = url.substring (7);
  194027. }
  194028. if (nextSlash >= 0)
  194029. path = url.substring (nextSlash);
  194030. else
  194031. path = T("/");
  194032. return true;
  194033. }
  194034. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  194035. {
  194036. for (int i = 0; i < lines.size(); ++i)
  194037. if (lines[i].startsWithIgnoreCase (itemName))
  194038. return lines[i].substring (itemName.length()).trim();
  194039. return String::empty;
  194040. }
  194041. };
  194042. bool juce_isOnLine()
  194043. {
  194044. return true;
  194045. }
  194046. void* juce_openInternetFile (const String& url,
  194047. const String& headers,
  194048. const MemoryBlock& postData,
  194049. const bool isPost,
  194050. URL::OpenStreamProgressCallback* callback,
  194051. void* callbackContext,
  194052. int timeOutMs)
  194053. {
  194054. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  194055. if (s->open (url, headers, postData, isPost,
  194056. callback, callbackContext, timeOutMs))
  194057. return s;
  194058. delete s;
  194059. return 0;
  194060. }
  194061. void juce_closeInternetFile (void* handle)
  194062. {
  194063. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194064. if (s != 0)
  194065. delete s;
  194066. }
  194067. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  194068. {
  194069. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194070. if (s != 0)
  194071. return s->read (buffer, bytesToRead);
  194072. return 0;
  194073. }
  194074. int64 juce_getInternetFileContentLength (void* handle)
  194075. {
  194076. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194077. if (s != 0)
  194078. {
  194079. //xxx todo
  194080. jassertfalse
  194081. }
  194082. return -1;
  194083. }
  194084. int juce_seekInInternetFile (void* handle, int newPosition)
  194085. {
  194086. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194087. if (s != 0)
  194088. return s->readPosition;
  194089. return 0;
  194090. }
  194091. #endif
  194092. /*** End of inlined file: juce_linux_Network.cpp ***/
  194093. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  194094. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194095. // compiled on its own).
  194096. #if JUCE_INCLUDED_FILE
  194097. void Logger::outputDebugString (const String& text) throw()
  194098. {
  194099. fputs (text.toUTF8(), stdout);
  194100. fputs ("\n", stdout);
  194101. }
  194102. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  194103. {
  194104. String text;
  194105. va_list args;
  194106. va_start (args, format);
  194107. text.vprintf(format, args);
  194108. outputDebugString(text);
  194109. }
  194110. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  194111. {
  194112. return Linux;
  194113. }
  194114. const String SystemStats::getOperatingSystemName() throw()
  194115. {
  194116. return T("Linux");
  194117. }
  194118. bool SystemStats::isOperatingSystem64Bit() throw()
  194119. {
  194120. #if JUCE_64BIT
  194121. return true;
  194122. #else
  194123. //xxx not sure how to find this out?..
  194124. return false;
  194125. #endif
  194126. }
  194127. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  194128. {
  194129. String info;
  194130. char buf [256];
  194131. FILE* f = fopen ("/proc/cpuinfo", "r");
  194132. while (f != 0 && fgets (buf, sizeof(buf), f))
  194133. {
  194134. if (strncmp (buf, key, strlen (key)) == 0)
  194135. {
  194136. char* p = buf;
  194137. while (*p && *p != '\n')
  194138. ++p;
  194139. if (*p != 0)
  194140. *p = 0;
  194141. p = buf;
  194142. while (*p != 0 && *p != ':')
  194143. ++p;
  194144. if (*p != 0 && *(p + 1) != 0)
  194145. info = p + 2;
  194146. if (! lastOne)
  194147. break;
  194148. }
  194149. }
  194150. fclose (f);
  194151. return info;
  194152. }
  194153. bool SystemStats::hasMMX() throw()
  194154. {
  194155. return getCpuInfo ("flags").contains (T("mmx"));
  194156. }
  194157. bool SystemStats::hasSSE() throw()
  194158. {
  194159. return getCpuInfo ("flags").contains (T("sse"));
  194160. }
  194161. bool SystemStats::hasSSE2() throw()
  194162. {
  194163. return getCpuInfo ("flags").contains (T("sse2"));
  194164. }
  194165. bool SystemStats::has3DNow() throw()
  194166. {
  194167. return getCpuInfo ("flags").contains (T("3dnow"));
  194168. }
  194169. const String SystemStats::getCpuVendor() throw()
  194170. {
  194171. return getCpuInfo ("vendor_id");
  194172. }
  194173. int SystemStats::getCpuSpeedInMegaherz() throw()
  194174. {
  194175. const String speed (getCpuInfo ("cpu MHz"));
  194176. return (int) (speed.getFloatValue() + 0.5f);
  194177. }
  194178. int SystemStats::getMemorySizeInMegabytes() throw()
  194179. {
  194180. struct sysinfo sysi;
  194181. if (sysinfo (&sysi) == 0)
  194182. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  194183. return 0;
  194184. }
  194185. uint32 juce_millisecondsSinceStartup() throw()
  194186. {
  194187. static unsigned int calibrate = 0;
  194188. static bool calibrated = false;
  194189. timeval t;
  194190. unsigned int ret = 0;
  194191. if (! gettimeofday (&t, 0))
  194192. {
  194193. if (! calibrated)
  194194. {
  194195. struct sysinfo sysi;
  194196. if (sysinfo (&sysi) == 0)
  194197. // Safe to assume system was not brought up earlier than 1970!
  194198. calibrate = t.tv_sec - sysi.uptime;
  194199. calibrated = true;
  194200. }
  194201. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  194202. }
  194203. return ret;
  194204. }
  194205. double Time::getMillisecondCounterHiRes() throw()
  194206. {
  194207. return getHighResolutionTicks() * 0.001;
  194208. }
  194209. int64 Time::getHighResolutionTicks() throw()
  194210. {
  194211. timeval t;
  194212. if (gettimeofday (&t, 0))
  194213. return 0;
  194214. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  194215. }
  194216. int64 Time::getHighResolutionTicksPerSecond() throw()
  194217. {
  194218. // Microseconds
  194219. return 1000000;
  194220. }
  194221. bool Time::setSystemTimeToThisTime() const throw()
  194222. {
  194223. timeval t;
  194224. t.tv_sec = millisSinceEpoch % 1000000;
  194225. t.tv_usec = millisSinceEpoch - t.tv_sec;
  194226. return settimeofday (&t, NULL) ? false : true;
  194227. }
  194228. int SystemStats::getPageSize() throw()
  194229. {
  194230. static int systemPageSize = 0;
  194231. if (systemPageSize == 0)
  194232. systemPageSize = sysconf (_SC_PAGESIZE);
  194233. return systemPageSize;
  194234. }
  194235. int SystemStats::getNumCpus() throw()
  194236. {
  194237. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  194238. return lastCpu + 1;
  194239. }
  194240. const String SystemStats::getLogonName()
  194241. {
  194242. const char* user = getenv ("USER");
  194243. if (user == 0)
  194244. {
  194245. struct passwd* const pw = getpwuid (getuid());
  194246. if (pw != 0)
  194247. user = pw->pw_name;
  194248. }
  194249. return String::fromUTF8 ((const uint8*) user);
  194250. }
  194251. const String SystemStats::getFullUserName()
  194252. {
  194253. return getLogonName();
  194254. }
  194255. void SystemStats::initialiseStats() throw()
  194256. {
  194257. // Process starts off as root when running suid
  194258. Process::lowerPrivilege();
  194259. String s (SystemStats::getJUCEVersion());
  194260. }
  194261. void PlatformUtilities::fpuReset()
  194262. {
  194263. }
  194264. #endif
  194265. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  194266. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  194267. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194268. // compiled on its own).
  194269. #if JUCE_INCLUDED_FILE
  194270. void JUCE_API juce_threadEntryPoint (void*);
  194271. void* threadEntryProc (void* value)
  194272. {
  194273. // New threads start off as root when running suid
  194274. Process::lowerPrivilege();
  194275. juce_threadEntryPoint (value);
  194276. return 0;
  194277. }
  194278. void* juce_createThread (void* userData)
  194279. {
  194280. pthread_t handle = 0;
  194281. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194282. {
  194283. pthread_detach (handle);
  194284. return (void*)handle;
  194285. }
  194286. return 0;
  194287. }
  194288. void juce_killThread (void* handle)
  194289. {
  194290. if (handle != 0)
  194291. pthread_cancel ((pthread_t)handle);
  194292. }
  194293. void juce_setCurrentThreadName (const String& /*name*/)
  194294. {
  194295. }
  194296. Thread::ThreadID Thread::getCurrentThreadId()
  194297. {
  194298. return (ThreadID) pthread_self();
  194299. }
  194300. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194301. // priority of the current thread
  194302. bool juce_setThreadPriority (void* handle, int priority)
  194303. {
  194304. struct sched_param param;
  194305. int policy, maxp, minp, pri;
  194306. if (handle == 0)
  194307. handle = (void*) pthread_self();
  194308. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194309. && policy != SCHED_OTHER)
  194310. {
  194311. minp = sched_get_priority_min(policy);
  194312. maxp = sched_get_priority_max(policy);
  194313. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194314. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194315. // Realtime process priority
  194316. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194317. else
  194318. // High process priority
  194319. param.__sched_priority = minp + pri;
  194320. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194321. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194322. }
  194323. return false;
  194324. }
  194325. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194326. {
  194327. #if SUPPORT_AFFINITIES
  194328. cpu_set_t affinity;
  194329. CPU_ZERO (&affinity);
  194330. for (int i = 0; i < 32; ++i)
  194331. if ((affinityMask & (1 << i)) != 0)
  194332. CPU_SET (i, &affinity);
  194333. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194334. sched_yield();
  194335. #else
  194336. /* affinities aren't supported because either the appropriate header files weren't found,
  194337. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194338. */
  194339. jassertfalse
  194340. #endif
  194341. }
  194342. void Thread::yield()
  194343. {
  194344. sched_yield();
  194345. }
  194346. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194347. void Process::setPriority (ProcessPriority prior)
  194348. {
  194349. struct sched_param param;
  194350. int policy, maxp, minp;
  194351. const int p = (int) prior;
  194352. if (p <= 1)
  194353. policy = SCHED_OTHER;
  194354. else
  194355. policy = SCHED_RR;
  194356. minp = sched_get_priority_min (policy);
  194357. maxp = sched_get_priority_max (policy);
  194358. if (p < 2)
  194359. param.__sched_priority = 0;
  194360. else if (p == 2 )
  194361. // Set to middle of lower realtime priority range
  194362. param.__sched_priority = minp + (maxp - minp) / 4;
  194363. else
  194364. // Set to middle of higher realtime priority range
  194365. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194366. pthread_setschedparam (pthread_self(), policy, &param);
  194367. }
  194368. void Process::terminate()
  194369. {
  194370. exit (0);
  194371. }
  194372. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194373. {
  194374. static char testResult = 0;
  194375. if (testResult == 0)
  194376. {
  194377. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194378. if (testResult >= 0)
  194379. {
  194380. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194381. testResult = 1;
  194382. }
  194383. }
  194384. return testResult < 0;
  194385. }
  194386. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194387. {
  194388. return juce_isRunningUnderDebugger();
  194389. }
  194390. void Process::raisePrivilege()
  194391. {
  194392. // If running suid root, change effective user
  194393. // to root
  194394. if (geteuid() != 0 && getuid() == 0)
  194395. {
  194396. setreuid (geteuid(), getuid());
  194397. setregid (getegid(), getgid());
  194398. }
  194399. }
  194400. void Process::lowerPrivilege()
  194401. {
  194402. // If runing suid root, change effective user
  194403. // back to real user
  194404. if (geteuid() == 0 && getuid() != 0)
  194405. {
  194406. setreuid (geteuid(), getuid());
  194407. setregid (getegid(), getgid());
  194408. }
  194409. }
  194410. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194411. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194412. {
  194413. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194414. }
  194415. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194416. {
  194417. dlclose(handle);
  194418. }
  194419. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194420. {
  194421. return dlsym (libraryHandle, (const char*) procedureName);
  194422. }
  194423. #endif
  194424. #endif
  194425. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194426. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194427. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194428. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194429. // compiled on its own).
  194430. #if JUCE_INCLUDED_FILE
  194431. #ifdef JUCE_DEBUG
  194432. #define JUCE_DEBUG_XERRORS 1
  194433. #endif
  194434. extern Display* display;
  194435. extern Window juce_messageWindowHandle;
  194436. static String localClipboardContent;
  194437. static Atom atom_UTF8_STRING;
  194438. static Atom atom_CLIPBOARD;
  194439. static Atom atom_TARGETS;
  194440. static void initSelectionAtoms()
  194441. {
  194442. static bool isInitialised = false;
  194443. if (! isInitialised)
  194444. {
  194445. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194446. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194447. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194448. }
  194449. }
  194450. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194451. // works only for strings shorter than 1000000 bytes
  194452. static String juce_readWindowProperty (Window window, Atom prop,
  194453. Atom fmt, // XA_STRING or UTF8_STRING
  194454. bool deleteAfterReading)
  194455. {
  194456. String returnData;
  194457. uint8 *clipData;
  194458. Atom actualType;
  194459. int actualFormat;
  194460. unsigned long numItems, bytesLeft;
  194461. if (XGetWindowProperty (display, window, prop,
  194462. 0L /* offset */, 1000000 /* length (max) */, False,
  194463. AnyPropertyType /* format */,
  194464. &actualType, &actualFormat, &numItems, &bytesLeft,
  194465. &clipData) == Success)
  194466. {
  194467. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194468. {
  194469. returnData = String::fromUTF8 (clipData, numItems);
  194470. }
  194471. else if (actualType == XA_STRING && actualFormat == 8)
  194472. {
  194473. returnData = String ((const char*) clipData, numItems);
  194474. }
  194475. if (clipData != 0)
  194476. XFree (clipData);
  194477. jassert (bytesLeft == 0 || numItems == 1000000);
  194478. }
  194479. if (deleteAfterReading)
  194480. XDeleteProperty (display, window, prop);
  194481. return returnData;
  194482. }
  194483. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194484. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194485. {
  194486. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194487. // The selection owner will be asked to set the JUCE_SEL property on the
  194488. // juce_messageWindowHandle with the selection content
  194489. XConvertSelection (display, selection, requested_format, property_name,
  194490. juce_messageWindowHandle, CurrentTime);
  194491. int timeoutMs = 200; // will wait at most for 200 ms
  194492. do
  194493. {
  194494. XEvent event;
  194495. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194496. {
  194497. if (event.xselection.property == property_name)
  194498. {
  194499. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194500. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194501. event.xselection.property,
  194502. requested_format, true);
  194503. return true;
  194504. }
  194505. else
  194506. {
  194507. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194508. }
  194509. }
  194510. // not very elegant.. we could do a select() or something like that...
  194511. // however clipboard content requesting is inherently slow on x11, it
  194512. // often takes 50ms or more so...
  194513. Thread::sleep (4);
  194514. timeoutMs -= 4;
  194515. }
  194516. while (timeoutMs > 0);
  194517. DBG("timeout for juce_requestSelectionContent");
  194518. return false;
  194519. }
  194520. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194521. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194522. {
  194523. initSelectionAtoms();
  194524. // the selection content is sent to the target window as a window property
  194525. XSelectionEvent reply;
  194526. reply.type = SelectionNotify;
  194527. reply.display = evt.display;
  194528. reply.requestor = evt.requestor;
  194529. reply.selection = evt.selection;
  194530. reply.target = evt.target;
  194531. reply.property = None; // == "fail"
  194532. reply.time = evt.time;
  194533. HeapBlock <char> data;
  194534. int propertyFormat = 0, numDataItems = 0;
  194535. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194536. {
  194537. if (evt.target == XA_STRING)
  194538. {
  194539. // format data according to system locale
  194540. numDataItems = localClipboardContent.length();
  194541. data.calloc (numDataItems + 2);
  194542. localClipboardContent.copyToBuffer ((char*) data, numDataItems + 1);
  194543. propertyFormat = 8; // bits/item
  194544. }
  194545. else if (evt.target == atom_UTF8_STRING)
  194546. {
  194547. // translate to utf8
  194548. numDataItems = localClipboardContent.copyToUTF8 (0);
  194549. data.calloc (numDataItems + 2);
  194550. localClipboardContent.copyToUTF8 (data, numDataItems + 1);
  194551. propertyFormat = 8; // bits/item
  194552. }
  194553. else if (evt.target == atom_TARGETS)
  194554. {
  194555. // another application wants to know what we are able to send
  194556. numDataItems = 2;
  194557. propertyFormat = 32; // atoms are 32-bit
  194558. data.calloc (numDataItems * 4);
  194559. ((Atom*) data)[0] = atom_UTF8_STRING;
  194560. ((Atom*) data)[1] = XA_STRING;
  194561. }
  194562. }
  194563. else
  194564. {
  194565. DBG ("requested unsupported clipboard");
  194566. }
  194567. if (data != 0)
  194568. {
  194569. const int maxReasonableSelectionSize = 1000000;
  194570. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194571. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194572. {
  194573. XChangeProperty (evt.display, evt.requestor,
  194574. evt.property, evt.target,
  194575. propertyFormat /* 8 or 32 */, PropModeReplace,
  194576. (const unsigned char*) data, numDataItems);
  194577. reply.property = evt.property; // " == success"
  194578. }
  194579. }
  194580. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194581. }
  194582. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194583. {
  194584. initSelectionAtoms();
  194585. localClipboardContent = clipText;
  194586. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194587. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194588. }
  194589. const String SystemClipboard::getTextFromClipboard() throw()
  194590. {
  194591. initSelectionAtoms();
  194592. String content;
  194593. Atom selection = XA_PRIMARY;
  194594. Window selectionOwner = None;
  194595. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194596. {
  194597. selection = atom_CLIPBOARD;
  194598. selectionOwner = XGetSelectionOwner (display, selection);
  194599. }
  194600. if (selectionOwner != None)
  194601. {
  194602. if (selectionOwner == juce_messageWindowHandle)
  194603. {
  194604. content = localClipboardContent;
  194605. }
  194606. else
  194607. {
  194608. // first try: we want an utf8 string
  194609. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194610. if (! ok)
  194611. {
  194612. // second chance, ask for a good old locale-dependent string ..
  194613. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194614. }
  194615. }
  194616. }
  194617. return content;
  194618. }
  194619. #endif
  194620. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194621. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194622. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194623. // compiled on its own).
  194624. #if JUCE_INCLUDED_FILE
  194625. #ifdef JUCE_DEBUG
  194626. #define JUCE_DEBUG_XERRORS 1
  194627. #endif
  194628. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194629. Window juce_messageWindowHandle = None;
  194630. #define SpecialAtom "JUCESpecialAtom"
  194631. #define BroadcastAtom "JUCEBroadcastAtom"
  194632. #define SpecialCallbackAtom "JUCESpecialCallbackAtom"
  194633. static Atom specialId;
  194634. static Atom broadcastId;
  194635. static Atom specialCallbackId;
  194636. // This is referenced from Windowing.cpp
  194637. XContext improbableNumber;
  194638. // Defined in Windowing.cpp
  194639. extern void juce_windowMessageReceive (XEvent* event);
  194640. // Defined in Clipboard.cpp
  194641. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt);
  194642. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194643. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194644. class InternalMessageQueue
  194645. {
  194646. public:
  194647. InternalMessageQueue()
  194648. : bytesInSocket (0)
  194649. {
  194650. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194651. (void) ret; jassert (ret == 0);
  194652. setNonBlocking (fd[0]);
  194653. setNonBlocking (fd[1]);
  194654. }
  194655. ~InternalMessageQueue()
  194656. {
  194657. close (fd[0]);
  194658. close (fd[1]);
  194659. }
  194660. void postMessage (Message* msg)
  194661. {
  194662. const int maxBytesInSocketQueue = 128;
  194663. ScopedLock sl (lock);
  194664. queue.add (msg);
  194665. if (bytesInSocket < maxBytesInSocketQueue)
  194666. {
  194667. ++bytesInSocket;
  194668. ScopedUnlock ul (lock);
  194669. const unsigned char x = 0xff;
  194670. size_t bytesWritten = write (fd[0], &x, 1);
  194671. (void) bytesWritten;
  194672. }
  194673. }
  194674. bool isEmpty() const
  194675. {
  194676. ScopedLock sl (lock);
  194677. return queue.size() == 0;
  194678. }
  194679. Message* popNextMessage()
  194680. {
  194681. ScopedLock sl (lock);
  194682. if (bytesInSocket > 0)
  194683. {
  194684. --bytesInSocket;
  194685. ScopedUnlock ul (lock);
  194686. unsigned char x;
  194687. size_t numBytes = read (fd[1], &x, 1);
  194688. (void) numBytes;
  194689. }
  194690. Message* m = queue[0];
  194691. queue.remove (0, false /* deleteObject */);
  194692. return m;
  194693. }
  194694. int getWaitHandle() const { return fd[1]; }
  194695. private:
  194696. CriticalSection lock;
  194697. OwnedArray <Message> queue;
  194698. int fd[2];
  194699. int bytesInSocket;
  194700. static bool setNonBlocking (int handle)
  194701. {
  194702. int socketFlags = fcntl (handle, F_GETFL, 0);
  194703. if (socketFlags == -1)
  194704. return false;
  194705. socketFlags |= O_NONBLOCK;
  194706. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194707. }
  194708. };
  194709. struct MessageThreadFuncCall
  194710. {
  194711. enum { uniqueID = 0x73774623 };
  194712. MessageCallbackFunction* func;
  194713. void* parameter;
  194714. void* result;
  194715. CriticalSection lock;
  194716. WaitableEvent event;
  194717. };
  194718. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194719. // error handling in X11
  194720. static bool errorOccurred = false;
  194721. static bool keyboardBreakOccurred = false;
  194722. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194723. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194724. // Usually happens when client-server connection is broken
  194725. static int ioErrorHandler (Display* display)
  194726. {
  194727. DBG (T("ERROR: connection to X server broken.. terminating."));
  194728. errorOccurred = true;
  194729. if (JUCEApplication::getInstance() != 0)
  194730. Process::terminate();
  194731. return 0;
  194732. }
  194733. // A protocol error has occurred
  194734. static int errorHandler (Display* display, XErrorEvent* event)
  194735. {
  194736. #ifdef JUCE_DEBUG_XERRORS
  194737. char errorStr[64] = { 0 };
  194738. char requestStr[64] = { 0 };
  194739. XGetErrorText (display, event->error_code, errorStr, 64);
  194740. XGetErrorDatabaseText (display,
  194741. "XRequest",
  194742. (const char*) String (event->request_code),
  194743. "Unknown",
  194744. requestStr,
  194745. 64);
  194746. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194747. #endif
  194748. return 0;
  194749. }
  194750. // Breakin from keyboard
  194751. static void signalHandler (int sig)
  194752. {
  194753. if (sig == SIGINT)
  194754. {
  194755. keyboardBreakOccurred = true;
  194756. return;
  194757. }
  194758. static bool reentrant = false;
  194759. if (! reentrant)
  194760. {
  194761. reentrant = true;
  194762. // Illegal instruction
  194763. fflush (stdout);
  194764. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194765. errorOccurred = true;
  194766. if (JUCEApplication::getInstance() != 0)
  194767. Process::terminate();
  194768. }
  194769. else
  194770. {
  194771. if (JUCEApplication::getInstance() != 0)
  194772. exit(0);
  194773. }
  194774. }
  194775. void MessageManager::doPlatformSpecificInitialisation()
  194776. {
  194777. // Initialise xlib for multiple thread support
  194778. static bool initThreadCalled = false;
  194779. if (! initThreadCalled)
  194780. {
  194781. if (! XInitThreads())
  194782. {
  194783. // This is fatal! Print error and closedown
  194784. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194785. if (JUCEApplication::getInstance() != 0)
  194786. Process::terminate();
  194787. return;
  194788. }
  194789. initThreadCalled = true;
  194790. }
  194791. // This is called if the client/server connection is broken
  194792. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194793. // This is called if a protocol error occurs
  194794. oldErrorHandler = XSetErrorHandler (errorHandler);
  194795. // Install signal handler for break-in
  194796. struct sigaction saction;
  194797. sigset_t maskSet;
  194798. sigemptyset (&maskSet);
  194799. saction.sa_handler = signalHandler;
  194800. saction.sa_mask = maskSet;
  194801. saction.sa_flags = 0;
  194802. sigaction (SIGINT, &saction, NULL);
  194803. #ifndef _DEBUG
  194804. // Setup signal handlers for various fatal errors
  194805. sigaction (SIGILL, &saction, NULL);
  194806. sigaction (SIGBUS, &saction, NULL);
  194807. sigaction (SIGFPE, &saction, NULL);
  194808. sigaction (SIGSEGV, &saction, NULL);
  194809. sigaction (SIGSYS, &saction, NULL);
  194810. #endif
  194811. // Create the internal message queue
  194812. juce_internalMessageQueue = new InternalMessageQueue();
  194813. // Try to connect to a display
  194814. String displayName (getenv ("DISPLAY"));
  194815. if (displayName.isEmpty())
  194816. displayName = T(":0.0");
  194817. display = XOpenDisplay (displayName);
  194818. if (display == 0)
  194819. {
  194820. // This is not fatal! we can run headless.
  194821. return;
  194822. }
  194823. // Get defaults for various properties
  194824. int screen = DefaultScreen (display);
  194825. Window root = RootWindow (display, screen);
  194826. Visual* visual = DefaultVisual (display, screen);
  194827. // Create atoms for our ClientMessages (these cannot be deleted)
  194828. specialId = XInternAtom (display, SpecialAtom, false);
  194829. broadcastId = XInternAtom (display, BroadcastAtom, false);
  194830. specialCallbackId = XInternAtom (display, SpecialCallbackAtom, false);
  194831. // Create a context to store user data associated with Windows we
  194832. // create in WindowDriver
  194833. improbableNumber = XUniqueContext();
  194834. // We're only interested in client messages for this window
  194835. // which are always sent
  194836. XSetWindowAttributes swa;
  194837. swa.event_mask = NoEventMask;
  194838. // Create our message window (this will never be mapped)
  194839. juce_messageWindowHandle = XCreateWindow (display, root,
  194840. 0, 0, 1, 1, 0, 0, InputOnly,
  194841. visual, CWEventMask, &swa);
  194842. }
  194843. void MessageManager::doPlatformSpecificShutdown()
  194844. {
  194845. deleteAndZero (juce_internalMessageQueue);
  194846. if (display != 0 && ! errorOccurred)
  194847. {
  194848. XDestroyWindow (display, juce_messageWindowHandle);
  194849. XCloseDisplay (display);
  194850. // reset pointers
  194851. juce_messageWindowHandle = 0;
  194852. display = 0;
  194853. // Restore original error handlers
  194854. XSetIOErrorHandler (oldIOErrorHandler);
  194855. oldIOErrorHandler = 0;
  194856. XSetErrorHandler (oldErrorHandler);
  194857. oldErrorHandler = 0;
  194858. }
  194859. }
  194860. bool juce_postMessageToSystemQueue (void* message)
  194861. {
  194862. if (errorOccurred)
  194863. return false;
  194864. juce_internalMessageQueue->postMessage ((Message*) message);
  194865. return true;
  194866. }
  194867. void MessageManager::broadcastMessage (const String& value) throw()
  194868. {
  194869. }
  194870. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194871. void* parameter)
  194872. {
  194873. if (errorOccurred)
  194874. return 0;
  194875. if (! isThisTheMessageThread())
  194876. {
  194877. MessageThreadFuncCall messageCallContext;
  194878. messageCallContext.func = func;
  194879. messageCallContext.parameter = parameter;
  194880. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194881. 0, 0, &messageCallContext));
  194882. // Wait for it to complete before continuing
  194883. messageCallContext.event.wait();
  194884. return messageCallContext.result;
  194885. }
  194886. else
  194887. {
  194888. // Just call the function directly
  194889. return func (parameter);
  194890. }
  194891. }
  194892. // Wait for an event (either XEvent, or an internal Message)
  194893. static bool juce_sleepUntilEvent (const int timeoutMs)
  194894. {
  194895. if (! juce_internalMessageQueue->isEmpty())
  194896. return true;
  194897. if (display != 0)
  194898. {
  194899. ScopedXLock xlock;
  194900. if (XPending (display))
  194901. return true;
  194902. }
  194903. struct timeval tv;
  194904. tv.tv_sec = 0;
  194905. tv.tv_usec = timeoutMs * 1000;
  194906. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194907. int fdmax = fd0;
  194908. fd_set readset;
  194909. FD_ZERO (&readset);
  194910. FD_SET (fd0, &readset);
  194911. if (display != 0)
  194912. {
  194913. ScopedXLock xlock;
  194914. int fd1 = XConnectionNumber (display);
  194915. FD_SET (fd1, &readset);
  194916. fdmax = jmax (fd0, fd1);
  194917. }
  194918. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194919. return (ret > 0); // ret <= 0 if error or timeout
  194920. }
  194921. // Handle next XEvent (if any)
  194922. static bool juce_dispatchNextXEvent()
  194923. {
  194924. if (display == 0)
  194925. return false;
  194926. XEvent evt;
  194927. {
  194928. ScopedXLock xlock;
  194929. if (! XPending (display))
  194930. return false;
  194931. XNextEvent (display, &evt);
  194932. }
  194933. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194934. {
  194935. juce_handleSelectionRequest (evt.xselectionrequest);
  194936. }
  194937. else if (evt.xany.window != juce_messageWindowHandle)
  194938. {
  194939. juce_windowMessageReceive (&evt);
  194940. }
  194941. return true;
  194942. }
  194943. // Handle next internal Message (if any)
  194944. static bool juce_dispatchNextInternalMessage()
  194945. {
  194946. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194947. if (msg == 0)
  194948. return false;
  194949. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194950. {
  194951. // Handle callback message
  194952. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194953. call->result = (*(call->func)) (call->parameter);
  194954. call->event.signal();
  194955. }
  194956. else
  194957. {
  194958. // Handle "normal" messages
  194959. MessageManager::getInstance()->deliverMessage (msg.release());
  194960. }
  194961. return true;
  194962. }
  194963. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194964. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194965. {
  194966. for (;;)
  194967. {
  194968. if (errorOccurred)
  194969. break;
  194970. if (keyboardBreakOccurred)
  194971. {
  194972. errorOccurred = true;
  194973. if (JUCEApplication::getInstance() != 0)
  194974. Process::terminate();
  194975. break;
  194976. }
  194977. static int totalEventCount = 0;
  194978. ++totalEventCount;
  194979. // The purpose here is to give either priority to XEvents or
  194980. // to internal messages This is necessary to keep a "good"
  194981. // behaviour when the cpu is overloaded
  194982. if (totalEventCount & 1)
  194983. {
  194984. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194985. return true;
  194986. }
  194987. else
  194988. {
  194989. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194990. return true;
  194991. }
  194992. if (returnIfNoPendingMessages) // early exit
  194993. break;
  194994. // the timeout is to be on the safe side, but it does not seem to be useful
  194995. juce_sleepUntilEvent (2000);
  194996. }
  194997. return false;
  194998. }
  194999. #endif
  195000. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  195001. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  195002. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195003. // compiled on its own).
  195004. #if JUCE_INCLUDED_FILE
  195005. class FreeTypeFontFace
  195006. {
  195007. public:
  195008. enum FontStyle
  195009. {
  195010. Plain = 0,
  195011. Bold = 1,
  195012. Italic = 2
  195013. };
  195014. struct FontNameIndex
  195015. {
  195016. String fileName;
  195017. int faceIndex;
  195018. };
  195019. FreeTypeFontFace (const String& familyName) throw()
  195020. : hasSerif (false),
  195021. monospaced (false)
  195022. {
  195023. family = familyName;
  195024. }
  195025. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  195026. {
  195027. if (names [(int) style].fileName.isEmpty())
  195028. {
  195029. names [(int) style].fileName = name;
  195030. names [(int) style].faceIndex = faceIndex;
  195031. }
  195032. }
  195033. const String& getFamilyName() const throw() { return family; }
  195034. const String& getFileName (const int style, int& faceIndex) const throw()
  195035. {
  195036. faceIndex = names[style].faceIndex;
  195037. return names[style].fileName;
  195038. }
  195039. void setMonospaced (bool mono) throw() { monospaced = mono; }
  195040. bool getMonospaced() const throw() { return monospaced; }
  195041. void setSerif (const bool serif) throw() { hasSerif = serif; }
  195042. bool getSerif() const throw() { return hasSerif; }
  195043. private:
  195044. String family;
  195045. FontNameIndex names[4];
  195046. bool hasSerif, monospaced;
  195047. };
  195048. class FreeTypeInterface : public DeletedAtShutdown
  195049. {
  195050. public:
  195051. FreeTypeInterface() throw()
  195052. : lastFace (0),
  195053. lastBold (false),
  195054. lastItalic (false)
  195055. {
  195056. if (FT_Init_FreeType (&ftLib) != 0)
  195057. {
  195058. ftLib = 0;
  195059. DBG (T("Failed to initialize FreeType"));
  195060. }
  195061. StringArray fontDirs;
  195062. fontDirs.addTokens (String (getenv ("JUCE_FONT_PATH")), T(";,"), 0);
  195063. fontDirs.removeEmptyStrings (true);
  195064. if (fontDirs.size() == 0)
  195065. {
  195066. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  195067. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  195068. if (fontsInfo != 0)
  195069. {
  195070. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  195071. {
  195072. fontDirs.add (e->getAllSubText().trim());
  195073. }
  195074. delete fontsInfo;
  195075. }
  195076. }
  195077. if (fontDirs.size() == 0)
  195078. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  195079. for (int i = 0; i < fontDirs.size(); ++i)
  195080. enumerateFaces (fontDirs[i]);
  195081. }
  195082. ~FreeTypeInterface() throw()
  195083. {
  195084. if (lastFace != 0)
  195085. FT_Done_Face (lastFace);
  195086. if (ftLib != 0)
  195087. FT_Done_FreeType (ftLib);
  195088. clearSingletonInstance();
  195089. }
  195090. FreeTypeFontFace* findOrCreate (const String& familyName,
  195091. const bool create = false) throw()
  195092. {
  195093. for (int i = 0; i < faces.size(); i++)
  195094. if (faces[i]->getFamilyName() == familyName)
  195095. return faces[i];
  195096. if (! create)
  195097. return NULL;
  195098. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  195099. faces.add (newFace);
  195100. return newFace;
  195101. }
  195102. // Enumerate all font faces available in a given directory
  195103. void enumerateFaces (const String& path) throw()
  195104. {
  195105. File dirPath (path);
  195106. if (path.isEmpty() || ! dirPath.isDirectory())
  195107. return;
  195108. DirectoryIterator di (dirPath, true);
  195109. while (di.next())
  195110. {
  195111. File possible (di.getFile());
  195112. if (possible.hasFileExtension (T("ttf"))
  195113. || possible.hasFileExtension (T("pfb"))
  195114. || possible.hasFileExtension (T("pcf")))
  195115. {
  195116. FT_Face face;
  195117. int faceIndex = 0;
  195118. int numFaces = 0;
  195119. do
  195120. {
  195121. if (FT_New_Face (ftLib,
  195122. possible.getFullPathName(),
  195123. faceIndex,
  195124. &face) == 0)
  195125. {
  195126. if (faceIndex == 0)
  195127. numFaces = face->num_faces;
  195128. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  195129. {
  195130. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  195131. int style = (int) FreeTypeFontFace::Plain;
  195132. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  195133. style |= (int) FreeTypeFontFace::Bold;
  195134. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  195135. style |= (int) FreeTypeFontFace::Italic;
  195136. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  195137. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  195138. // Surely there must be a better way to do this?
  195139. const String name (face->family_name);
  195140. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  195141. || name.containsIgnoreCase (T("Verdana"))
  195142. || name.containsIgnoreCase (T("Arial"))));
  195143. }
  195144. FT_Done_Face (face);
  195145. }
  195146. ++faceIndex;
  195147. }
  195148. while (faceIndex < numFaces);
  195149. }
  195150. }
  195151. }
  195152. // Create a FreeType face object for a given font
  195153. FT_Face createFT_Face (const String& fontName,
  195154. const bool bold,
  195155. const bool italic) throw()
  195156. {
  195157. FT_Face face = 0;
  195158. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  195159. {
  195160. face = lastFace;
  195161. }
  195162. else
  195163. {
  195164. if (lastFace != 0)
  195165. {
  195166. FT_Done_Face (lastFace);
  195167. lastFace = 0;
  195168. }
  195169. lastFontName = fontName;
  195170. lastBold = bold;
  195171. lastItalic = italic;
  195172. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  195173. if (ftFace != 0)
  195174. {
  195175. int style = (int) FreeTypeFontFace::Plain;
  195176. if (bold)
  195177. style |= (int) FreeTypeFontFace::Bold;
  195178. if (italic)
  195179. style |= (int) FreeTypeFontFace::Italic;
  195180. int faceIndex;
  195181. String fileName (ftFace->getFileName (style, faceIndex));
  195182. if (fileName.isEmpty())
  195183. {
  195184. style ^= (int) FreeTypeFontFace::Bold;
  195185. fileName = ftFace->getFileName (style, faceIndex);
  195186. if (fileName.isEmpty())
  195187. {
  195188. style ^= (int) FreeTypeFontFace::Bold;
  195189. style ^= (int) FreeTypeFontFace::Italic;
  195190. fileName = ftFace->getFileName (style, faceIndex);
  195191. if (! fileName.length())
  195192. {
  195193. style ^= (int) FreeTypeFontFace::Bold;
  195194. fileName = ftFace->getFileName (style, faceIndex);
  195195. }
  195196. }
  195197. }
  195198. if (! FT_New_Face (ftLib, (const char*) fileName, faceIndex, &lastFace))
  195199. {
  195200. face = lastFace;
  195201. // If there isn't a unicode charmap then select the first one.
  195202. if (FT_Select_Charmap (face, ft_encoding_unicode))
  195203. FT_Set_Charmap (face, face->charmaps[0]);
  195204. }
  195205. }
  195206. }
  195207. return face;
  195208. }
  195209. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  195210. {
  195211. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  195212. const float height = (float) (face->ascender - face->descender);
  195213. const float scaleX = 1.0f / height;
  195214. const float scaleY = -1.0f / height;
  195215. Path destShape;
  195216. #define CONVERTX(val) (scaleX * (val).x)
  195217. #define CONVERTY(val) (scaleY * (val).y)
  195218. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  195219. || face->glyph->format != ft_glyph_format_outline)
  195220. {
  195221. return false;
  195222. }
  195223. const FT_Outline* const outline = &face->glyph->outline;
  195224. const short* const contours = outline->contours;
  195225. const char* const tags = outline->tags;
  195226. FT_Vector* const points = outline->points;
  195227. for (int c = 0; c < outline->n_contours; c++)
  195228. {
  195229. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  195230. const int endPoint = contours[c];
  195231. for (int p = startPoint; p <= endPoint; p++)
  195232. {
  195233. const float x = CONVERTX (points[p]);
  195234. const float y = CONVERTY (points[p]);
  195235. if (p == startPoint)
  195236. {
  195237. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195238. {
  195239. float x2 = CONVERTX (points [endPoint]);
  195240. float y2 = CONVERTY (points [endPoint]);
  195241. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  195242. {
  195243. x2 = (x + x2) * 0.5f;
  195244. y2 = (y + y2) * 0.5f;
  195245. }
  195246. destShape.startNewSubPath (x2, y2);
  195247. }
  195248. else
  195249. {
  195250. destShape.startNewSubPath (x, y);
  195251. }
  195252. }
  195253. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  195254. {
  195255. if (p != startPoint)
  195256. destShape.lineTo (x, y);
  195257. }
  195258. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195259. {
  195260. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  195261. float x2 = CONVERTX (points [nextIndex]);
  195262. float y2 = CONVERTY (points [nextIndex]);
  195263. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  195264. {
  195265. x2 = (x + x2) * 0.5f;
  195266. y2 = (y + y2) * 0.5f;
  195267. }
  195268. else
  195269. {
  195270. ++p;
  195271. }
  195272. destShape.quadraticTo (x, y, x2, y2);
  195273. }
  195274. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  195275. {
  195276. if (p >= endPoint)
  195277. return false;
  195278. const int next1 = p + 1;
  195279. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  195280. const float x2 = CONVERTX (points [next1]);
  195281. const float y2 = CONVERTY (points [next1]);
  195282. const float x3 = CONVERTX (points [next2]);
  195283. const float y3 = CONVERTY (points [next2]);
  195284. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  195285. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  195286. return false;
  195287. destShape.cubicTo (x, y, x2, y2, x3, y3);
  195288. p += 2;
  195289. }
  195290. }
  195291. destShape.closeSubPath();
  195292. }
  195293. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195294. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195295. addKerning (face, dest, character, glyphIndex);
  195296. return true;
  195297. }
  195298. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195299. {
  195300. const float height = (float) (face->ascender - face->descender);
  195301. uint32 rightGlyphIndex;
  195302. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195303. while (rightGlyphIndex != 0)
  195304. {
  195305. FT_Vector kerning;
  195306. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195307. {
  195308. if (kerning.x != 0)
  195309. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195310. }
  195311. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195312. }
  195313. }
  195314. // Add a glyph to a font
  195315. bool addGlyphToFont (const uint32 character,
  195316. const tchar* fontName, bool bold, bool italic,
  195317. CustomTypeface& dest) throw()
  195318. {
  195319. FT_Face face = createFT_Face (fontName, bold, italic);
  195320. if (face != 0)
  195321. return addGlyph (face, dest, character);
  195322. return false;
  195323. }
  195324. void getFamilyNames (StringArray& familyNames) const throw()
  195325. {
  195326. for (int i = 0; i < faces.size(); i++)
  195327. familyNames.add (faces[i]->getFamilyName());
  195328. }
  195329. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195330. {
  195331. for (int i = 0; i < faces.size(); i++)
  195332. if (faces[i]->getMonospaced())
  195333. monoSpaced.add (faces[i]->getFamilyName());
  195334. }
  195335. void getSerifNames (StringArray& serif) const throw()
  195336. {
  195337. for (int i = 0; i < faces.size(); i++)
  195338. if (faces[i]->getSerif())
  195339. serif.add (faces[i]->getFamilyName());
  195340. }
  195341. void getSansSerifNames (StringArray& sansSerif) const throw()
  195342. {
  195343. for (int i = 0; i < faces.size(); i++)
  195344. if (! faces[i]->getSerif())
  195345. sansSerif.add (faces[i]->getFamilyName());
  195346. }
  195347. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195348. private:
  195349. FT_Library ftLib;
  195350. FT_Face lastFace;
  195351. String lastFontName;
  195352. bool lastBold, lastItalic;
  195353. OwnedArray<FreeTypeFontFace> faces;
  195354. };
  195355. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195356. class FreetypeTypeface : public CustomTypeface
  195357. {
  195358. public:
  195359. FreetypeTypeface (const Font& font)
  195360. {
  195361. FT_Face face = FreeTypeInterface::getInstance()
  195362. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195363. if (face == 0)
  195364. {
  195365. #ifdef JUCE_DEBUG
  195366. String msg (T("Failed to create typeface: "));
  195367. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195368. DBG (msg);
  195369. #endif
  195370. }
  195371. else
  195372. {
  195373. setCharacteristics (font.getTypefaceName(),
  195374. face->ascender / (float) (face->ascender - face->descender),
  195375. font.isBold(), font.isItalic(),
  195376. L' ');
  195377. }
  195378. }
  195379. bool loadGlyphIfPossible (const juce_wchar character)
  195380. {
  195381. return FreeTypeInterface::getInstance()
  195382. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195383. }
  195384. };
  195385. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195386. {
  195387. return new FreetypeTypeface (font);
  195388. }
  195389. const StringArray Font::findAllTypefaceNames() throw()
  195390. {
  195391. StringArray s;
  195392. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195393. s.sort (true);
  195394. return s;
  195395. }
  195396. static const String pickBestFont (const StringArray& names,
  195397. const char* const choicesString)
  195398. {
  195399. StringArray choices;
  195400. choices.addTokens (String (choicesString), T(","), 0);
  195401. choices.trim();
  195402. choices.removeEmptyStrings();
  195403. int i, j;
  195404. for (j = 0; j < choices.size(); ++j)
  195405. if (names.contains (choices[j], true))
  195406. return choices[j];
  195407. for (j = 0; j < choices.size(); ++j)
  195408. for (i = 0; i < names.size(); i++)
  195409. if (names[i].startsWithIgnoreCase (choices[j]))
  195410. return names[i];
  195411. for (j = 0; j < choices.size(); ++j)
  195412. for (i = 0; i < names.size(); i++)
  195413. if (names[i].containsIgnoreCase (choices[j]))
  195414. return names[i];
  195415. return names[0];
  195416. }
  195417. static const String linux_getDefaultSansSerifFontName()
  195418. {
  195419. StringArray allFonts;
  195420. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195421. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195422. }
  195423. static const String linux_getDefaultSerifFontName()
  195424. {
  195425. StringArray allFonts;
  195426. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195427. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195428. }
  195429. static const String linux_getDefaultMonospacedFontName()
  195430. {
  195431. StringArray allFonts;
  195432. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195433. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195434. }
  195435. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195436. {
  195437. defaultSans = linux_getDefaultSansSerifFontName();
  195438. defaultSerif = linux_getDefaultSerifFontName();
  195439. defaultFixed = linux_getDefaultMonospacedFontName();
  195440. }
  195441. #endif
  195442. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195443. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195444. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195445. // compiled on its own).
  195446. #if JUCE_INCLUDED_FILE
  195447. #define TAKE_FOCUS 0
  195448. #define DELETE_WINDOW 1
  195449. #define SYSTEM_TRAY_REQUEST_DOCK 0
  195450. #define SYSTEM_TRAY_BEGIN_MESSAGE 1
  195451. #define SYSTEM_TRAY_CANCEL_MESSAGE 2
  195452. static const int repaintTimerPeriod = 1000 / 100; // 100 fps maximum
  195453. static Atom wm_ChangeState = None;
  195454. static Atom wm_State = None;
  195455. static Atom wm_Protocols = None;
  195456. static Atom wm_ProtocolList [2] = { None, None };
  195457. static Atom wm_ActiveWin = None;
  195458. #define ourDndVersion 3
  195459. static Atom XA_XdndAware = None;
  195460. static Atom XA_XdndEnter = None;
  195461. static Atom XA_XdndLeave = None;
  195462. static Atom XA_XdndPosition = None;
  195463. static Atom XA_XdndStatus = None;
  195464. static Atom XA_XdndDrop = None;
  195465. static Atom XA_XdndFinished = None;
  195466. static Atom XA_XdndSelection = None;
  195467. static Atom XA_XdndProxy = None;
  195468. static Atom XA_XdndTypeList = None;
  195469. static Atom XA_XdndActionList = None;
  195470. static Atom XA_XdndActionDescription = None;
  195471. static Atom XA_XdndActionCopy = None;
  195472. static Atom XA_XdndActionMove = None;
  195473. static Atom XA_XdndActionLink = None;
  195474. static Atom XA_XdndActionAsk = None;
  195475. static Atom XA_XdndActionPrivate = None;
  195476. static Atom XA_JXSelectionWindowProperty = None;
  195477. static Atom XA_MimeTextPlain = None;
  195478. static Atom XA_MimeTextUriList = None;
  195479. static Atom XA_MimeRootDrop = None;
  195480. static XErrorHandler oldHandler = 0;
  195481. static int trappedErrorCode = 0;
  195482. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195483. {
  195484. trappedErrorCode = err->error_code;
  195485. return 0;
  195486. }
  195487. static void trapErrors()
  195488. {
  195489. trappedErrorCode = 0;
  195490. oldHandler = XSetErrorHandler (errorTrapHandler);
  195491. }
  195492. static bool untrapErrors()
  195493. {
  195494. XSetErrorHandler (oldHandler);
  195495. return (trappedErrorCode == 0);
  195496. }
  195497. static bool isActiveApplication = false;
  195498. bool Process::isForegroundProcess()
  195499. {
  195500. return isActiveApplication;
  195501. }
  195502. // These are defined in juce_linux_Messaging.cpp
  195503. extern Display* display;
  195504. extern XContext improbableNumber;
  195505. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195506. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195507. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195508. static int pointerMap[5];
  195509. static Point<int> lastMousePos;
  195510. enum MouseButtons
  195511. {
  195512. NoButton = 0,
  195513. LeftButton = 1,
  195514. MiddleButton = 2,
  195515. RightButton = 3,
  195516. WheelUp = 4,
  195517. WheelDown = 5
  195518. };
  195519. static void getMousePos (int& x, int& y, int& mouseMods) throw()
  195520. {
  195521. Window root, child;
  195522. int winx, winy;
  195523. unsigned int mask;
  195524. mouseMods = 0;
  195525. ScopedXLock xlock;
  195526. if (XQueryPointer (display,
  195527. RootWindow (display, DefaultScreen (display)),
  195528. &root, &child,
  195529. &x, &y, &winx, &winy, &mask) == False)
  195530. {
  195531. // Pointer not on the default screen
  195532. x = y = -1;
  195533. }
  195534. else
  195535. {
  195536. if ((mask & Button1Mask) != 0)
  195537. mouseMods |= ModifierKeys::leftButtonModifier;
  195538. if ((mask & Button2Mask) != 0)
  195539. mouseMods |= ModifierKeys::middleButtonModifier;
  195540. if ((mask & Button3Mask) != 0)
  195541. mouseMods |= ModifierKeys::rightButtonModifier;
  195542. }
  195543. }
  195544. static int AltMask = 0;
  195545. static int NumLockMask = 0;
  195546. static bool numLock = 0;
  195547. static bool capsLock = 0;
  195548. static char keyStates [32];
  195549. static void updateKeyStates (const int keycode, const bool press) throw()
  195550. {
  195551. const int keybyte = keycode >> 3;
  195552. const int keybit = (1 << (keycode & 7));
  195553. if (press)
  195554. keyStates [keybyte] |= keybit;
  195555. else
  195556. keyStates [keybyte] &= ~keybit;
  195557. }
  195558. static bool keyDown (const int keycode) throw()
  195559. {
  195560. const int keybyte = keycode >> 3;
  195561. const int keybit = (1 << (keycode & 7));
  195562. return (keyStates [keybyte] & keybit) != 0;
  195563. }
  195564. static const int extendedKeyModifier = 0x10000000;
  195565. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195566. {
  195567. int keysym;
  195568. if (keyCode & extendedKeyModifier)
  195569. {
  195570. keysym = 0xff00 | (keyCode & 0xff);
  195571. }
  195572. else
  195573. {
  195574. keysym = keyCode;
  195575. if (keysym == (XK_Tab & 0xff)
  195576. || keysym == (XK_Return & 0xff)
  195577. || keysym == (XK_Escape & 0xff)
  195578. || keysym == (XK_BackSpace & 0xff))
  195579. {
  195580. keysym |= 0xff00;
  195581. }
  195582. }
  195583. ScopedXLock xlock;
  195584. return keyDown (XKeysymToKeycode (display, keysym));
  195585. }
  195586. // Alt and Num lock are not defined by standard X
  195587. // modifier constants: check what they're mapped to
  195588. static void getModifierMapping() throw()
  195589. {
  195590. ScopedXLock xlock;
  195591. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  195592. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  195593. AltMask = 0;
  195594. NumLockMask = 0;
  195595. XModifierKeymap* mapping = XGetModifierMapping (display);
  195596. if (mapping)
  195597. {
  195598. for (int i = 0; i < 8; i++)
  195599. {
  195600. if (mapping->modifiermap [i << 1] == altLeftCode)
  195601. AltMask = 1 << i;
  195602. else if (mapping->modifiermap [i << 1] == numLockCode)
  195603. NumLockMask = 1 << i;
  195604. }
  195605. XFreeModifiermap (mapping);
  195606. }
  195607. }
  195608. static int currentModifiers = 0;
  195609. void ModifierKeys::updateCurrentModifiers() throw()
  195610. {
  195611. currentModifierFlags = currentModifiers;
  195612. }
  195613. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  195614. {
  195615. int x, y, mouseMods;
  195616. getMousePos (x, y, mouseMods);
  195617. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  195618. currentModifiers |= mouseMods;
  195619. return ModifierKeys (currentModifiers);
  195620. }
  195621. static void updateKeyModifiers (const int status) throw()
  195622. {
  195623. currentModifiers &= ~(ModifierKeys::shiftModifier
  195624. | ModifierKeys::ctrlModifier
  195625. | ModifierKeys::altModifier);
  195626. if (status & ShiftMask)
  195627. currentModifiers |= ModifierKeys::shiftModifier;
  195628. if (status & ControlMask)
  195629. currentModifiers |= ModifierKeys::ctrlModifier;
  195630. if (status & AltMask)
  195631. currentModifiers |= ModifierKeys::altModifier;
  195632. numLock = ((status & NumLockMask) != 0);
  195633. capsLock = ((status & LockMask) != 0);
  195634. }
  195635. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  195636. {
  195637. int modifier = 0;
  195638. bool isModifier = true;
  195639. switch (sym)
  195640. {
  195641. case XK_Shift_L:
  195642. case XK_Shift_R:
  195643. modifier = ModifierKeys::shiftModifier;
  195644. break;
  195645. case XK_Control_L:
  195646. case XK_Control_R:
  195647. modifier = ModifierKeys::ctrlModifier;
  195648. break;
  195649. case XK_Alt_L:
  195650. case XK_Alt_R:
  195651. modifier = ModifierKeys::altModifier;
  195652. break;
  195653. case XK_Num_Lock:
  195654. if (press)
  195655. numLock = ! numLock;
  195656. break;
  195657. case XK_Caps_Lock:
  195658. if (press)
  195659. capsLock = ! capsLock;
  195660. break;
  195661. case XK_Scroll_Lock:
  195662. break;
  195663. default:
  195664. isModifier = false;
  195665. break;
  195666. }
  195667. if (modifier != 0)
  195668. {
  195669. if (press)
  195670. currentModifiers |= modifier;
  195671. else
  195672. currentModifiers &= ~modifier;
  195673. }
  195674. return isModifier;
  195675. }
  195676. #if JUCE_USE_XSHM
  195677. static bool isShmAvailable() throw()
  195678. {
  195679. ScopedXLock xlock;
  195680. static bool isChecked = false;
  195681. static bool isAvailable = false;
  195682. if (! isChecked)
  195683. {
  195684. isChecked = true;
  195685. int major, minor;
  195686. Bool pixmaps;
  195687. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195688. {
  195689. trapErrors();
  195690. XShmSegmentInfo segmentInfo;
  195691. zerostruct (segmentInfo);
  195692. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195693. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195694. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195695. xImage->bytes_per_line * xImage->height,
  195696. IPC_CREAT | 0777)) >= 0)
  195697. {
  195698. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195699. if (segmentInfo.shmaddr != (void*) -1)
  195700. {
  195701. segmentInfo.readOnly = False;
  195702. xImage->data = segmentInfo.shmaddr;
  195703. XSync (display, False);
  195704. if (XShmAttach (display, &segmentInfo) != 0)
  195705. {
  195706. XSync (display, False);
  195707. XShmDetach (display, &segmentInfo);
  195708. isAvailable = true;
  195709. }
  195710. }
  195711. XFlush (display);
  195712. XDestroyImage (xImage);
  195713. shmdt (segmentInfo.shmaddr);
  195714. }
  195715. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195716. isAvailable &= untrapErrors();
  195717. }
  195718. }
  195719. return isAvailable;
  195720. }
  195721. #endif
  195722. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195723. {
  195724. ScopedXLock xlock;
  195725. const int width = image.getWidth();
  195726. const int height = image.getHeight();
  195727. HeapBlock <uint32> colour (width * height);
  195728. int index = 0;
  195729. for (int y = 0; y < height; ++y)
  195730. for (int x = 0; x < width; ++x)
  195731. colour[index++] = image.getPixelAt (x, y).getARGB();
  195732. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195733. 0, (char*) colour, width, height, 32, 0);
  195734. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195735. width, height, 24);
  195736. GC gc = XCreateGC (display, pixmap, 0, 0);
  195737. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195738. XFreeGC (display, gc);
  195739. return pixmap;
  195740. }
  195741. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195742. {
  195743. ScopedXLock xlock;
  195744. const int width = image.getWidth();
  195745. const int height = image.getHeight();
  195746. const int stride = (width + 7) >> 3;
  195747. HeapBlock <uint8> mask;
  195748. mask.calloc (stride * height);
  195749. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195750. for (int y = 0; y < height; ++y)
  195751. {
  195752. for (int x = 0; x < width; ++x)
  195753. {
  195754. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195755. const int offset = y * stride + (x >> 3);
  195756. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195757. mask[offset] |= bit;
  195758. }
  195759. }
  195760. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195761. (char*) mask, width, height, 1, 0, 1);
  195762. }
  195763. class XBitmapImage : public Image
  195764. {
  195765. public:
  195766. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195767. const bool clearImage, const bool is16Bit_)
  195768. : Image (format_, w, h),
  195769. is16Bit (is16Bit_)
  195770. {
  195771. jassert (format_ == RGB || format_ == ARGB);
  195772. pixelStride = (format_ == RGB) ? 3 : 4;
  195773. lineStride = ((w * pixelStride + 3) & ~3);
  195774. ScopedXLock xlock;
  195775. Visual* const visual = DefaultVisual (display, DefaultScreen (display));
  195776. #if JUCE_USE_XSHM
  195777. usingXShm = false;
  195778. if ((! is16Bit) && isShmAvailable())
  195779. {
  195780. zerostruct (segmentInfo);
  195781. xImage = XShmCreateImage (display, visual, 24, ZPixmap, 0, &segmentInfo, w, h);
  195782. if (xImage != 0)
  195783. {
  195784. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195785. xImage->bytes_per_line * xImage->height,
  195786. IPC_CREAT | 0777)) >= 0)
  195787. {
  195788. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195789. if (segmentInfo.shmaddr != (void*) -1)
  195790. {
  195791. segmentInfo.readOnly = False;
  195792. xImage->data = segmentInfo.shmaddr;
  195793. imageData = (uint8*) segmentInfo.shmaddr;
  195794. XSync (display, False);
  195795. if (XShmAttach (display, &segmentInfo) != 0)
  195796. {
  195797. XSync (display, False);
  195798. usingXShm = true;
  195799. }
  195800. else
  195801. {
  195802. jassertfalse
  195803. }
  195804. }
  195805. else
  195806. {
  195807. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195808. }
  195809. }
  195810. }
  195811. }
  195812. if (! usingXShm)
  195813. #endif
  195814. {
  195815. imageDataAllocated.malloc (lineStride * h);
  195816. imageData = imageDataAllocated;
  195817. if (format_ == ARGB && clearImage)
  195818. zeromem (imageData, h * lineStride);
  195819. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195820. xImage->width = w;
  195821. xImage->height = h;
  195822. xImage->xoffset = 0;
  195823. xImage->format = ZPixmap;
  195824. xImage->data = (char*) imageData;
  195825. xImage->byte_order = ImageByteOrder (display);
  195826. xImage->bitmap_unit = BitmapUnit (display);
  195827. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195828. xImage->bitmap_pad = 32;
  195829. xImage->depth = pixelStride * 8;
  195830. xImage->bytes_per_line = lineStride;
  195831. xImage->bits_per_pixel = pixelStride * 8;
  195832. xImage->red_mask = 0x00FF0000;
  195833. xImage->green_mask = 0x0000FF00;
  195834. xImage->blue_mask = 0x000000FF;
  195835. if (is16Bit)
  195836. {
  195837. const int pixelStride = 2;
  195838. const int lineStride = ((w * pixelStride + 3) & ~3);
  195839. imageData16Bit.malloc (lineStride * h);
  195840. xImage->data = imageData16Bit;
  195841. xImage->bitmap_pad = 16;
  195842. xImage->depth = pixelStride * 8;
  195843. xImage->bytes_per_line = lineStride;
  195844. xImage->bits_per_pixel = pixelStride * 8;
  195845. xImage->red_mask = visual->red_mask;
  195846. xImage->green_mask = visual->green_mask;
  195847. xImage->blue_mask = visual->blue_mask;
  195848. }
  195849. if (! XInitImage (xImage))
  195850. {
  195851. jassertfalse
  195852. }
  195853. }
  195854. }
  195855. ~XBitmapImage()
  195856. {
  195857. ScopedXLock xlock;
  195858. #if JUCE_USE_XSHM
  195859. if (usingXShm)
  195860. {
  195861. XShmDetach (display, &segmentInfo);
  195862. XFlush (display);
  195863. XDestroyImage (xImage);
  195864. shmdt (segmentInfo.shmaddr);
  195865. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195866. }
  195867. else
  195868. #endif
  195869. {
  195870. xImage->data = 0;
  195871. XDestroyImage (xImage);
  195872. }
  195873. }
  195874. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195875. {
  195876. ScopedXLock xlock;
  195877. static GC gc = 0;
  195878. if (gc == 0)
  195879. gc = DefaultGC (display, DefaultScreen (display));
  195880. if (is16Bit)
  195881. {
  195882. const uint32 rMask = xImage->red_mask;
  195883. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195884. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195885. const uint32 gMask = xImage->green_mask;
  195886. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195887. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195888. const uint32 bMask = xImage->blue_mask;
  195889. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195890. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195891. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195892. for (int y = sy; y < sy + dh; ++y)
  195893. {
  195894. const uint8* p = srcData.getPixelPointer (sx, y);
  195895. for (int x = sx; x < sx + dw; ++x)
  195896. {
  195897. const PixelRGB* const pixel = (const PixelRGB*) p;
  195898. p += srcData.pixelStride;
  195899. XPutPixel (xImage, x, y,
  195900. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195901. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195902. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195903. }
  195904. }
  195905. }
  195906. // blit results to screen.
  195907. #if JUCE_USE_XSHM
  195908. if (usingXShm)
  195909. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195910. else
  195911. #endif
  195912. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195913. }
  195914. juce_UseDebuggingNewOperator
  195915. private:
  195916. XImage* xImage;
  195917. const bool is16Bit;
  195918. HeapBlock <char> imageData16Bit;
  195919. #if JUCE_USE_XSHM
  195920. XShmSegmentInfo segmentInfo;
  195921. bool usingXShm;
  195922. #endif
  195923. static int getShiftNeeded (const uint32 mask) throw()
  195924. {
  195925. for (int i = 32; --i >= 0;)
  195926. if (((mask >> i) & 1) != 0)
  195927. return i - 7;
  195928. jassertfalse
  195929. return 0;
  195930. }
  195931. };
  195932. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195933. class LinuxComponentPeer : public ComponentPeer
  195934. {
  195935. public:
  195936. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195937. : ComponentPeer (component, windowStyleFlags),
  195938. windowH (0),
  195939. parentWindow (0),
  195940. wx (0),
  195941. wy (0),
  195942. ww (0),
  195943. wh (0),
  195944. taskbarImage (0),
  195945. fullScreen (false),
  195946. entered (false),
  195947. mapped (false)
  195948. {
  195949. // it's dangerous to create a window on a thread other than the message thread..
  195950. checkMessageManagerIsLocked
  195951. repainter = new LinuxRepaintManager (this);
  195952. createWindow();
  195953. setTitle (component->getName());
  195954. }
  195955. ~LinuxComponentPeer()
  195956. {
  195957. // it's dangerous to delete a window on a thread other than the message thread..
  195958. checkMessageManagerIsLocked
  195959. deleteTaskBarIcon();
  195960. deleteIconPixmaps();
  195961. destroyWindow();
  195962. windowH = 0;
  195963. }
  195964. void* getNativeHandle() const
  195965. {
  195966. return (void*) windowH;
  195967. }
  195968. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195969. {
  195970. XPointer peer = 0;
  195971. ScopedXLock xlock;
  195972. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195973. {
  195974. if (peer != 0 && ! ((LinuxComponentPeer*) peer)->isValidMessageListener())
  195975. peer = 0;
  195976. }
  195977. return (LinuxComponentPeer*) peer;
  195978. }
  195979. void setVisible (bool shouldBeVisible)
  195980. {
  195981. ScopedXLock xlock;
  195982. if (shouldBeVisible)
  195983. XMapWindow (display, windowH);
  195984. else
  195985. XUnmapWindow (display, windowH);
  195986. }
  195987. void setTitle (const String& title)
  195988. {
  195989. setWindowTitle (windowH, title);
  195990. }
  195991. void setPosition (int x, int y)
  195992. {
  195993. setBounds (x, y, ww, wh, false);
  195994. }
  195995. void setSize (int w, int h)
  195996. {
  195997. setBounds (wx, wy, w, h, false);
  195998. }
  195999. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  196000. {
  196001. fullScreen = isNowFullScreen;
  196002. if (windowH != 0)
  196003. {
  196004. const ComponentDeletionWatcher deletionChecker (component);
  196005. wx = x;
  196006. wy = y;
  196007. ww = jmax (1, w);
  196008. wh = jmax (1, h);
  196009. ScopedXLock xlock;
  196010. // Make sure the Window manager does what we want
  196011. XSizeHints* hints = XAllocSizeHints();
  196012. hints->flags = USSize | USPosition;
  196013. hints->width = ww;
  196014. hints->height = wh;
  196015. hints->x = wx;
  196016. hints->y = wy;
  196017. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  196018. {
  196019. hints->min_width = hints->max_width = hints->width;
  196020. hints->min_height = hints->max_height = hints->height;
  196021. hints->flags |= PMinSize | PMaxSize;
  196022. }
  196023. XSetWMNormalHints (display, windowH, hints);
  196024. XFree (hints);
  196025. XMoveResizeWindow (display, windowH,
  196026. wx - windowBorder.getLeft(),
  196027. wy - windowBorder.getTop(), ww, wh);
  196028. if (! deletionChecker.hasBeenDeleted())
  196029. {
  196030. updateBorderSize();
  196031. handleMovedOrResized();
  196032. }
  196033. }
  196034. }
  196035. void getBounds (int& x, int& y, int& w, int& h) const
  196036. {
  196037. x = wx;
  196038. y = wy;
  196039. w = ww;
  196040. h = wh;
  196041. }
  196042. const Point<int> getScreenPosition() const
  196043. {
  196044. return Point<int> (wx, wy);
  196045. }
  196046. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  196047. {
  196048. return relativePosition + getScreenPosition();
  196049. }
  196050. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  196051. {
  196052. return screenPosition - getScreenPosition();
  196053. }
  196054. void setMinimised (bool shouldBeMinimised)
  196055. {
  196056. if (shouldBeMinimised)
  196057. {
  196058. Window root = RootWindow (display, DefaultScreen (display));
  196059. XClientMessageEvent clientMsg;
  196060. clientMsg.display = display;
  196061. clientMsg.window = windowH;
  196062. clientMsg.type = ClientMessage;
  196063. clientMsg.format = 32;
  196064. clientMsg.message_type = wm_ChangeState;
  196065. clientMsg.data.l[0] = IconicState;
  196066. ScopedXLock xlock;
  196067. XSendEvent (display, root, false,
  196068. SubstructureRedirectMask | SubstructureNotifyMask,
  196069. (XEvent*) &clientMsg);
  196070. }
  196071. else
  196072. {
  196073. setVisible (true);
  196074. }
  196075. }
  196076. bool isMinimised() const
  196077. {
  196078. bool minimised = false;
  196079. unsigned char* stateProp;
  196080. unsigned long nitems, bytesLeft;
  196081. Atom actualType;
  196082. int actualFormat;
  196083. ScopedXLock xlock;
  196084. if (XGetWindowProperty (display, windowH, wm_State, 0, 64, False,
  196085. wm_State, &actualType, &actualFormat, &nitems, &bytesLeft,
  196086. &stateProp) == Success
  196087. && actualType == wm_State
  196088. && actualFormat == 32
  196089. && nitems > 0)
  196090. {
  196091. if (((unsigned long*) stateProp)[0] == IconicState)
  196092. minimised = true;
  196093. XFree (stateProp);
  196094. }
  196095. return minimised;
  196096. }
  196097. void setFullScreen (const bool shouldBeFullScreen)
  196098. {
  196099. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  196100. setMinimised (false);
  196101. if (fullScreen != shouldBeFullScreen)
  196102. {
  196103. if (shouldBeFullScreen)
  196104. r = Desktop::getInstance().getMainMonitorArea();
  196105. if (! r.isEmpty())
  196106. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  196107. getComponent()->repaint();
  196108. }
  196109. }
  196110. bool isFullScreen() const
  196111. {
  196112. return fullScreen;
  196113. }
  196114. bool isChildWindowOf (Window possibleParent) const
  196115. {
  196116. Window* windowList = 0;
  196117. uint32 windowListSize = 0;
  196118. Window parent, root;
  196119. ScopedXLock xlock;
  196120. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  196121. {
  196122. if (windowList != 0)
  196123. XFree (windowList);
  196124. return parent == possibleParent;
  196125. }
  196126. return false;
  196127. }
  196128. bool isFrontWindow() const
  196129. {
  196130. Window* windowList = 0;
  196131. uint32 windowListSize = 0;
  196132. bool result = false;
  196133. ScopedXLock xlock;
  196134. Window parent, root = RootWindow (display, DefaultScreen (display));
  196135. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  196136. {
  196137. for (int i = windowListSize; --i >= 0;)
  196138. {
  196139. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  196140. if (peer != 0)
  196141. {
  196142. result = (peer == this);
  196143. break;
  196144. }
  196145. }
  196146. }
  196147. if (windowList != 0)
  196148. XFree (windowList);
  196149. return result;
  196150. }
  196151. bool contains (int x, int y, bool trueIfInAChildWindow) const
  196152. {
  196153. jassert (x >= 0 && y >= 0 && x < ww && y < wh); // should only be called for points that are actually inside the bounds
  196154. if (((unsigned int) x) >= (unsigned int) ww
  196155. || ((unsigned int) y) >= (unsigned int) wh)
  196156. return false;
  196157. bool inFront = false;
  196158. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  196159. {
  196160. Component* const c = Desktop::getInstance().getComponent (i);
  196161. if (inFront)
  196162. {
  196163. if (c->contains (x + wx - c->getScreenX(),
  196164. y + wy - c->getScreenY()))
  196165. {
  196166. return false;
  196167. }
  196168. }
  196169. else if (c == getComponent())
  196170. {
  196171. inFront = true;
  196172. }
  196173. }
  196174. if (trueIfInAChildWindow)
  196175. return true;
  196176. ::Window root, child;
  196177. unsigned int bw, depth;
  196178. int wx, wy, w, h;
  196179. ScopedXLock xlock;
  196180. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196181. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  196182. &bw, &depth))
  196183. {
  196184. return false;
  196185. }
  196186. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  196187. return false;
  196188. return child == None;
  196189. }
  196190. const BorderSize getFrameSize() const
  196191. {
  196192. return BorderSize();
  196193. }
  196194. bool setAlwaysOnTop (bool alwaysOnTop)
  196195. {
  196196. if (windowH != 0)
  196197. {
  196198. const bool wasVisible = component->isVisible();
  196199. if (wasVisible)
  196200. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  196201. {
  196202. ScopedXLock xlock;
  196203. XSetWindowAttributes swa;
  196204. swa.override_redirect = alwaysOnTop ? True : False;
  196205. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  196206. }
  196207. if (wasVisible)
  196208. setVisible (true);
  196209. }
  196210. return true;
  196211. }
  196212. void toFront (bool makeActive)
  196213. {
  196214. if (makeActive)
  196215. {
  196216. setVisible (true);
  196217. grabFocus();
  196218. }
  196219. XEvent ev;
  196220. ev.xclient.type = ClientMessage;
  196221. ev.xclient.serial = 0;
  196222. ev.xclient.send_event = True;
  196223. ev.xclient.message_type = wm_ActiveWin;
  196224. ev.xclient.window = windowH;
  196225. ev.xclient.format = 32;
  196226. ev.xclient.data.l[0] = 2;
  196227. ev.xclient.data.l[1] = CurrentTime;
  196228. ev.xclient.data.l[2] = 0;
  196229. ev.xclient.data.l[3] = 0;
  196230. ev.xclient.data.l[4] = 0;
  196231. {
  196232. ScopedXLock xlock;
  196233. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  196234. False,
  196235. SubstructureRedirectMask | SubstructureNotifyMask,
  196236. &ev);
  196237. XWindowAttributes attr;
  196238. XGetWindowAttributes (display, windowH, &attr);
  196239. if (attr.override_redirect)
  196240. XRaiseWindow (display, windowH);
  196241. XSync (display, False);
  196242. }
  196243. handleBroughtToFront();
  196244. }
  196245. void toBehind (ComponentPeer* other)
  196246. {
  196247. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196248. jassert (otherPeer != 0); // wrong type of window?
  196249. if (otherPeer != 0)
  196250. {
  196251. setMinimised (false);
  196252. Window newStack[] = { otherPeer->windowH, windowH };
  196253. ScopedXLock xlock;
  196254. XRestackWindows (display, newStack, 2);
  196255. }
  196256. }
  196257. bool isFocused() const
  196258. {
  196259. int revert;
  196260. Window focusedWindow = 0;
  196261. ScopedXLock xlock;
  196262. XGetInputFocus (display, &focusedWindow, &revert);
  196263. return focusedWindow == windowH;
  196264. }
  196265. void grabFocus()
  196266. {
  196267. XWindowAttributes atts;
  196268. ScopedXLock xlock;
  196269. if (windowH != 0
  196270. && XGetWindowAttributes (display, windowH, &atts)
  196271. && atts.map_state == IsViewable
  196272. && ! isFocused())
  196273. {
  196274. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196275. isActiveApplication = true;
  196276. }
  196277. }
  196278. void textInputRequired (const Point<int>&)
  196279. {
  196280. }
  196281. void repaint (int x, int y, int w, int h)
  196282. {
  196283. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  196284. 0, 0,
  196285. getComponent()->getWidth(),
  196286. getComponent()->getHeight()))
  196287. {
  196288. repainter->repaint (x, y, w, h);
  196289. }
  196290. }
  196291. void performAnyPendingRepaintsNow()
  196292. {
  196293. repainter->performAnyPendingRepaintsNow();
  196294. }
  196295. void setIcon (const Image& newIcon)
  196296. {
  196297. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196298. HeapBlock <unsigned long> data (dataSize);
  196299. int index = 0;
  196300. data[index++] = newIcon.getWidth();
  196301. data[index++] = newIcon.getHeight();
  196302. for (int y = 0; y < newIcon.getHeight(); ++y)
  196303. for (int x = 0; x < newIcon.getWidth(); ++x)
  196304. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196305. ScopedXLock xlock;
  196306. XChangeProperty (display, windowH,
  196307. XInternAtom (display, "_NET_WM_ICON", False),
  196308. XA_CARDINAL, 32, PropModeReplace,
  196309. (unsigned char*) data, dataSize);
  196310. deleteIconPixmaps();
  196311. XWMHints* wmHints = XGetWMHints (display, windowH);
  196312. if (wmHints == 0)
  196313. wmHints = XAllocWMHints();
  196314. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196315. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196316. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196317. XSetWMHints (display, windowH, wmHints);
  196318. XFree (wmHints);
  196319. XSync (display, False);
  196320. }
  196321. void deleteIconPixmaps()
  196322. {
  196323. ScopedXLock xlock;
  196324. XWMHints* wmHints = XGetWMHints (display, windowH);
  196325. if (wmHints != 0)
  196326. {
  196327. if ((wmHints->flags & IconPixmapHint) != 0)
  196328. {
  196329. wmHints->flags &= ~IconPixmapHint;
  196330. XFreePixmap (display, wmHints->icon_pixmap);
  196331. }
  196332. if ((wmHints->flags & IconMaskHint) != 0)
  196333. {
  196334. wmHints->flags &= ~IconMaskHint;
  196335. XFreePixmap (display, wmHints->icon_mask);
  196336. }
  196337. XSetWMHints (display, windowH, wmHints);
  196338. XFree (wmHints);
  196339. }
  196340. }
  196341. void handleWindowMessage (XEvent* event)
  196342. {
  196343. switch (event->xany.type)
  196344. {
  196345. case 2: // 'KeyPress'
  196346. {
  196347. ScopedXLock xlock;
  196348. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196349. updateKeyStates (keyEvent->keycode, true);
  196350. char utf8 [64];
  196351. zeromem (utf8, sizeof (utf8));
  196352. KeySym sym;
  196353. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196354. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 ((const uint8*) utf8, sizeof (utf8) - 1);
  196355. int keyCode = (int) unicodeChar;
  196356. if (keyCode < 0x20)
  196357. keyCode = XKeycodeToKeysym (display, keyEvent->keycode,
  196358. (currentModifiers & ModifierKeys::shiftModifier) != 0 ? 1 : 0);
  196359. const int oldMods = currentModifiers;
  196360. bool keyPressed = false;
  196361. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196362. if ((sym & 0xff00) == 0xff00)
  196363. {
  196364. // Translate keypad
  196365. if (sym == XK_KP_Divide)
  196366. keyCode = XK_slash;
  196367. else if (sym == XK_KP_Multiply)
  196368. keyCode = XK_asterisk;
  196369. else if (sym == XK_KP_Subtract)
  196370. keyCode = XK_hyphen;
  196371. else if (sym == XK_KP_Add)
  196372. keyCode = XK_plus;
  196373. else if (sym == XK_KP_Enter)
  196374. keyCode = XK_Return;
  196375. else if (sym == XK_KP_Decimal)
  196376. keyCode = numLock ? XK_period : XK_Delete;
  196377. else if (sym == XK_KP_0)
  196378. keyCode = numLock ? XK_0 : XK_Insert;
  196379. else if (sym == XK_KP_1)
  196380. keyCode = numLock ? XK_1 : XK_End;
  196381. else if (sym == XK_KP_2)
  196382. keyCode = numLock ? XK_2 : XK_Down;
  196383. else if (sym == XK_KP_3)
  196384. keyCode = numLock ? XK_3 : XK_Page_Down;
  196385. else if (sym == XK_KP_4)
  196386. keyCode = numLock ? XK_4 : XK_Left;
  196387. else if (sym == XK_KP_5)
  196388. keyCode = XK_5;
  196389. else if (sym == XK_KP_6)
  196390. keyCode = numLock ? XK_6 : XK_Right;
  196391. else if (sym == XK_KP_7)
  196392. keyCode = numLock ? XK_7 : XK_Home;
  196393. else if (sym == XK_KP_8)
  196394. keyCode = numLock ? XK_8 : XK_Up;
  196395. else if (sym == XK_KP_9)
  196396. keyCode = numLock ? XK_9 : XK_Page_Up;
  196397. switch (sym)
  196398. {
  196399. case XK_Left:
  196400. case XK_Right:
  196401. case XK_Up:
  196402. case XK_Down:
  196403. case XK_Page_Up:
  196404. case XK_Page_Down:
  196405. case XK_End:
  196406. case XK_Home:
  196407. case XK_Delete:
  196408. case XK_Insert:
  196409. keyPressed = true;
  196410. keyCode = (sym & 0xff) | extendedKeyModifier;
  196411. break;
  196412. case XK_Tab:
  196413. case XK_Return:
  196414. case XK_Escape:
  196415. case XK_BackSpace:
  196416. keyPressed = true;
  196417. keyCode &= 0xff;
  196418. break;
  196419. default:
  196420. {
  196421. if (sym >= XK_F1 && sym <= XK_F16)
  196422. {
  196423. keyPressed = true;
  196424. keyCode = (sym & 0xff) | extendedKeyModifier;
  196425. }
  196426. break;
  196427. }
  196428. }
  196429. }
  196430. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196431. keyPressed = true;
  196432. if (oldMods != currentModifiers)
  196433. handleModifierKeysChange();
  196434. if (keyDownChange)
  196435. handleKeyUpOrDown (true);
  196436. if (keyPressed)
  196437. handleKeyPress (keyCode, unicodeChar);
  196438. break;
  196439. }
  196440. case KeyRelease:
  196441. {
  196442. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196443. updateKeyStates (keyEvent->keycode, false);
  196444. ScopedXLock xlock;
  196445. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196446. const int oldMods = currentModifiers;
  196447. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196448. if (oldMods != currentModifiers)
  196449. handleModifierKeysChange();
  196450. if (keyDownChange)
  196451. handleKeyUpOrDown (false);
  196452. break;
  196453. }
  196454. case ButtonPress:
  196455. {
  196456. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196457. bool buttonMsg = false;
  196458. bool wheelUpMsg = false;
  196459. bool wheelDownMsg = false;
  196460. const int map = pointerMap [buttonPressEvent->button - Button1];
  196461. if (map == LeftButton)
  196462. {
  196463. currentModifiers |= ModifierKeys::leftButtonModifier;
  196464. buttonMsg = true;
  196465. }
  196466. else if (map == RightButton)
  196467. {
  196468. currentModifiers |= ModifierKeys::rightButtonModifier;
  196469. buttonMsg = true;
  196470. }
  196471. else if (map == MiddleButton)
  196472. {
  196473. currentModifiers |= ModifierKeys::middleButtonModifier;
  196474. buttonMsg = true;
  196475. }
  196476. else if (map == WheelUp)
  196477. {
  196478. wheelUpMsg = true;
  196479. }
  196480. else if (map == WheelDown)
  196481. {
  196482. wheelDownMsg = true;
  196483. }
  196484. updateKeyModifiers (buttonPressEvent->state);
  196485. if (buttonMsg)
  196486. {
  196487. toFront (true);
  196488. handleMouseDown (buttonPressEvent->x, buttonPressEvent->y,
  196489. getEventTime (buttonPressEvent->time));
  196490. }
  196491. else if (wheelUpMsg || wheelDownMsg)
  196492. {
  196493. handleMouseWheel (0, wheelDownMsg ? -84 : 84,
  196494. getEventTime (buttonPressEvent->time));
  196495. }
  196496. lastMousePos = Point<int> (0x100000, 0x100000);
  196497. break;
  196498. }
  196499. case ButtonRelease:
  196500. {
  196501. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196502. const int oldModifiers = currentModifiers;
  196503. const int map = pointerMap [buttonRelEvent->button - Button1];
  196504. if (map == LeftButton)
  196505. currentModifiers &= ~ModifierKeys::leftButtonModifier;
  196506. else if (map == RightButton)
  196507. currentModifiers &= ~ModifierKeys::rightButtonModifier;
  196508. else if (map == MiddleButton)
  196509. currentModifiers &= ~ModifierKeys::middleButtonModifier;
  196510. updateKeyModifiers (buttonRelEvent->state);
  196511. handleMouseUp (oldModifiers,
  196512. buttonRelEvent->x, buttonRelEvent->y,
  196513. getEventTime (buttonRelEvent->time));
  196514. lastMousePos = Point<int> (0x100000, 0x100000);
  196515. break;
  196516. }
  196517. case MotionNotify:
  196518. {
  196519. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196520. updateKeyModifiers (movedEvent->state);
  196521. Point<int> mousePos (Desktop::getMousePosition());
  196522. if (lastMousePos != mousePos)
  196523. {
  196524. lastMousePos = mousePos;
  196525. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196526. {
  196527. Window wRoot = 0, wParent = 0;
  196528. Window* wChild = 0;
  196529. unsigned int numChildren;
  196530. {
  196531. ScopedXLock xlock;
  196532. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196533. }
  196534. if (wParent != 0
  196535. && wParent != windowH
  196536. && wParent != wRoot)
  196537. {
  196538. parentWindow = wParent;
  196539. updateBounds();
  196540. mousePos -= getScreenPosition();
  196541. }
  196542. else
  196543. {
  196544. parentWindow = 0;
  196545. mousePos -= getScreenPosition();
  196546. }
  196547. }
  196548. else
  196549. {
  196550. mousePos -= getScreenPosition();
  196551. }
  196552. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0)
  196553. handleMouseMove (mousePos.getX(), mousePos.getY(), getEventTime (movedEvent->time));
  196554. else
  196555. handleMouseDrag (mousePos.getX(), mousePos.getY(), getEventTime (movedEvent->time));
  196556. }
  196557. break;
  196558. }
  196559. case EnterNotify:
  196560. {
  196561. lastMousePos = Point<int> (0x100000, 0x100000);
  196562. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196563. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196564. && ! entered)
  196565. {
  196566. updateKeyModifiers (enterEvent->state);
  196567. handleMouseEnter (enterEvent->x, enterEvent->y, getEventTime (enterEvent->time));
  196568. entered = true;
  196569. }
  196570. break;
  196571. }
  196572. case LeaveNotify:
  196573. {
  196574. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196575. // Suppress the normal leave if we've got a pointer grab, or if
  196576. // it's a bogus one caused by clicking a mouse button when running
  196577. // in a Window manager
  196578. if (((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196579. && leaveEvent->mode == NotifyNormal)
  196580. || leaveEvent->mode == NotifyUngrab)
  196581. {
  196582. updateKeyModifiers (leaveEvent->state);
  196583. handleMouseExit (leaveEvent->x, leaveEvent->y, getEventTime (leaveEvent->time));
  196584. entered = false;
  196585. }
  196586. break;
  196587. }
  196588. case FocusIn:
  196589. {
  196590. isActiveApplication = true;
  196591. if (isFocused())
  196592. handleFocusGain();
  196593. break;
  196594. }
  196595. case FocusOut:
  196596. {
  196597. isActiveApplication = false;
  196598. if (! isFocused())
  196599. handleFocusLoss();
  196600. break;
  196601. }
  196602. case Expose:
  196603. {
  196604. // Batch together all pending expose events
  196605. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196606. XEvent nextEvent;
  196607. ScopedXLock xlock;
  196608. if (exposeEvent->window != windowH)
  196609. {
  196610. Window child;
  196611. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196612. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196613. &child);
  196614. }
  196615. repaint (exposeEvent->x, exposeEvent->y,
  196616. exposeEvent->width, exposeEvent->height);
  196617. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196618. {
  196619. XPeekEvent (display, (XEvent*) &nextEvent);
  196620. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196621. break;
  196622. XNextEvent (display, (XEvent*) &nextEvent);
  196623. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196624. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196625. nextExposeEvent->width, nextExposeEvent->height);
  196626. }
  196627. break;
  196628. }
  196629. case CirculateNotify:
  196630. case CreateNotify:
  196631. case DestroyNotify:
  196632. // Think we can ignore these
  196633. break;
  196634. case ConfigureNotify:
  196635. {
  196636. updateBounds();
  196637. updateBorderSize();
  196638. handleMovedOrResized();
  196639. // if the native title bar is dragged, need to tell any active menus, etc.
  196640. if ((styleFlags & windowHasTitleBar) != 0
  196641. && component->isCurrentlyBlockedByAnotherModalComponent())
  196642. {
  196643. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196644. if (currentModalComp != 0)
  196645. currentModalComp->inputAttemptWhenModal();
  196646. }
  196647. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196648. if (confEvent->window == windowH
  196649. && confEvent->above != 0
  196650. && isFrontWindow())
  196651. {
  196652. handleBroughtToFront();
  196653. }
  196654. break;
  196655. }
  196656. case ReparentNotify:
  196657. case GravityNotify:
  196658. {
  196659. parentWindow = 0;
  196660. Window wRoot = 0;
  196661. Window* wChild = 0;
  196662. unsigned int numChildren;
  196663. {
  196664. ScopedXLock xlock;
  196665. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196666. }
  196667. if (parentWindow == windowH || parentWindow == wRoot)
  196668. parentWindow = 0;
  196669. updateBounds();
  196670. updateBorderSize();
  196671. handleMovedOrResized();
  196672. break;
  196673. }
  196674. case MapNotify:
  196675. mapped = true;
  196676. handleBroughtToFront();
  196677. break;
  196678. case UnmapNotify:
  196679. mapped = false;
  196680. break;
  196681. case MappingNotify:
  196682. {
  196683. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196684. if (mappingEvent->request != MappingPointer)
  196685. {
  196686. // Deal with modifier/keyboard mapping
  196687. ScopedXLock xlock;
  196688. XRefreshKeyboardMapping (mappingEvent);
  196689. getModifierMapping();
  196690. }
  196691. break;
  196692. }
  196693. case ClientMessage:
  196694. {
  196695. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196696. if (clientMsg->message_type == wm_Protocols && clientMsg->format == 32)
  196697. {
  196698. const Atom atom = (Atom) clientMsg->data.l[0];
  196699. if (atom == wm_ProtocolList [TAKE_FOCUS])
  196700. {
  196701. XWindowAttributes atts;
  196702. ScopedXLock xlock;
  196703. if (clientMsg->window != 0
  196704. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196705. {
  196706. if (atts.map_state == IsViewable)
  196707. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196708. }
  196709. }
  196710. else if (atom == wm_ProtocolList [DELETE_WINDOW])
  196711. {
  196712. handleUserClosingWindow();
  196713. }
  196714. }
  196715. else if (clientMsg->message_type == XA_XdndEnter)
  196716. {
  196717. handleDragAndDropEnter (clientMsg);
  196718. }
  196719. else if (clientMsg->message_type == XA_XdndLeave)
  196720. {
  196721. resetDragAndDrop();
  196722. }
  196723. else if (clientMsg->message_type == XA_XdndPosition)
  196724. {
  196725. handleDragAndDropPosition (clientMsg);
  196726. }
  196727. else if (clientMsg->message_type == XA_XdndDrop)
  196728. {
  196729. handleDragAndDropDrop (clientMsg);
  196730. }
  196731. else if (clientMsg->message_type == XA_XdndStatus)
  196732. {
  196733. handleDragAndDropStatus (clientMsg);
  196734. }
  196735. else if (clientMsg->message_type == XA_XdndFinished)
  196736. {
  196737. resetDragAndDrop();
  196738. }
  196739. break;
  196740. }
  196741. case SelectionNotify:
  196742. handleDragAndDropSelection (event);
  196743. break;
  196744. case SelectionClear:
  196745. case SelectionRequest:
  196746. break;
  196747. default:
  196748. #if JUCE_USE_XSHM
  196749. {
  196750. ScopedXLock xlock;
  196751. if (event->xany.type == XShmGetEventBase (display))
  196752. repainter->notifyPaintCompleted();
  196753. }
  196754. #endif
  196755. break;
  196756. }
  196757. }
  196758. void showMouseCursor (Cursor cursor) throw()
  196759. {
  196760. ScopedXLock xlock;
  196761. XDefineCursor (display, windowH, cursor);
  196762. }
  196763. void setTaskBarIcon (const Image& image)
  196764. {
  196765. ScopedXLock xlock;
  196766. deleteTaskBarIcon();
  196767. taskbarImage = image.createCopy();
  196768. Screen* const screen = XDefaultScreenOfDisplay (display);
  196769. const int screenNumber = XScreenNumberOfScreen (screen);
  196770. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196771. screenAtom << screenNumber;
  196772. Atom selectionAtom = XInternAtom (display, (const char*) screenAtom, false);
  196773. XGrabServer (display);
  196774. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196775. if (managerWin != None)
  196776. XSelectInput (display, managerWin, StructureNotifyMask);
  196777. XUngrabServer (display);
  196778. XFlush (display);
  196779. if (managerWin != None)
  196780. {
  196781. XEvent ev;
  196782. zerostruct (ev);
  196783. ev.xclient.type = ClientMessage;
  196784. ev.xclient.window = managerWin;
  196785. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196786. ev.xclient.format = 32;
  196787. ev.xclient.data.l[0] = CurrentTime;
  196788. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196789. ev.xclient.data.l[2] = windowH;
  196790. ev.xclient.data.l[3] = 0;
  196791. ev.xclient.data.l[4] = 0;
  196792. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196793. XSync (display, False);
  196794. }
  196795. // For older KDE's ...
  196796. long atomData = 1;
  196797. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196798. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196799. // For more recent KDE's...
  196800. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196801. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196802. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196803. XSizeHints* hints = XAllocSizeHints();
  196804. hints->flags = PMinSize;
  196805. hints->min_width = 22;
  196806. hints->min_height = 22;
  196807. XSetWMNormalHints (display, windowH, hints);
  196808. XFree (hints);
  196809. }
  196810. void deleteTaskBarIcon()
  196811. {
  196812. deleteAndZero (taskbarImage);
  196813. }
  196814. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196815. juce_UseDebuggingNewOperator
  196816. bool dontRepaint;
  196817. private:
  196818. class LinuxRepaintManager : public Timer
  196819. {
  196820. public:
  196821. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196822. : peer (peer_),
  196823. lastTimeImageUsed (0)
  196824. {
  196825. #if JUCE_USE_XSHM
  196826. shmCompletedDrawing = true;
  196827. useARGBImagesForRendering = isShmAvailable();
  196828. if (useARGBImagesForRendering)
  196829. {
  196830. ScopedXLock xlock;
  196831. XShmSegmentInfo segmentinfo;
  196832. XImage* const testImage
  196833. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196834. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196835. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196836. XDestroyImage (testImage);
  196837. }
  196838. #endif
  196839. }
  196840. ~LinuxRepaintManager()
  196841. {
  196842. }
  196843. void timerCallback()
  196844. {
  196845. #if JUCE_USE_XSHM
  196846. if (! shmCompletedDrawing)
  196847. return;
  196848. #endif
  196849. if (! regionsNeedingRepaint.isEmpty())
  196850. {
  196851. stopTimer();
  196852. performAnyPendingRepaintsNow();
  196853. }
  196854. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196855. {
  196856. stopTimer();
  196857. image = 0;
  196858. }
  196859. }
  196860. void repaint (int x, int y, int w, int h)
  196861. {
  196862. if (! isTimerRunning())
  196863. startTimer (repaintTimerPeriod);
  196864. regionsNeedingRepaint.add (x, y, w, h);
  196865. }
  196866. void performAnyPendingRepaintsNow()
  196867. {
  196868. #if JUCE_USE_XSHM
  196869. if (! shmCompletedDrawing)
  196870. {
  196871. startTimer (repaintTimerPeriod);
  196872. return;
  196873. }
  196874. #endif
  196875. peer->clearMaskedRegion();
  196876. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196877. regionsNeedingRepaint.clear();
  196878. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196879. if (! totalArea.isEmpty())
  196880. {
  196881. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196882. || image->getHeight() < totalArea.getHeight())
  196883. {
  196884. #if JUCE_USE_XSHM
  196885. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196886. : Image::RGB,
  196887. #else
  196888. image = new XBitmapImage (Image::RGB,
  196889. #endif
  196890. (totalArea.getWidth() + 31) & ~31,
  196891. (totalArea.getHeight() + 31) & ~31,
  196892. false,
  196893. peer->depthIs16Bit);
  196894. }
  196895. startTimer (repaintTimerPeriod);
  196896. LowLevelGraphicsSoftwareRenderer context (*image);
  196897. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196898. if (context.clipToRectangleList (originalRepaintRegion))
  196899. peer->handlePaint (context);
  196900. if (! peer->maskedRegion.isEmpty())
  196901. originalRepaintRegion.subtract (peer->maskedRegion);
  196902. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196903. {
  196904. #if JUCE_USE_XSHM
  196905. shmCompletedDrawing = false;
  196906. #endif
  196907. const Rectangle<int>& r = *i.getRectangle();
  196908. image->blitToWindow (peer->windowH,
  196909. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196910. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196911. }
  196912. }
  196913. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196914. startTimer (repaintTimerPeriod);
  196915. }
  196916. #if JUCE_USE_XSHM
  196917. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196918. #endif
  196919. private:
  196920. LinuxComponentPeer* const peer;
  196921. ScopedPointer <XBitmapImage> image;
  196922. uint32 lastTimeImageUsed;
  196923. RectangleList regionsNeedingRepaint;
  196924. #if JUCE_USE_XSHM
  196925. bool useARGBImagesForRendering, shmCompletedDrawing;
  196926. #endif
  196927. LinuxRepaintManager (const LinuxRepaintManager&);
  196928. const LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196929. };
  196930. ScopedPointer <LinuxRepaintManager> repainter;
  196931. friend class LinuxRepaintManager;
  196932. Window windowH, parentWindow;
  196933. int wx, wy, ww, wh;
  196934. Image* taskbarImage;
  196935. bool fullScreen, entered, mapped, depthIs16Bit;
  196936. BorderSize windowBorder;
  196937. struct MotifWmHints
  196938. {
  196939. unsigned long flags;
  196940. unsigned long functions;
  196941. unsigned long decorations;
  196942. long input_mode;
  196943. unsigned long status;
  196944. };
  196945. void removeWindowDecorations (Window wndH)
  196946. {
  196947. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196948. if (hints != None)
  196949. {
  196950. MotifWmHints motifHints;
  196951. zerostruct (motifHints);
  196952. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196953. motifHints.decorations = 0;
  196954. ScopedXLock xlock;
  196955. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196956. (unsigned char*) &motifHints, 4);
  196957. }
  196958. hints = XInternAtom (display, "_WIN_HINTS", True);
  196959. if (hints != None)
  196960. {
  196961. long gnomeHints = 0;
  196962. ScopedXLock xlock;
  196963. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196964. (unsigned char*) &gnomeHints, 1);
  196965. }
  196966. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196967. if (hints != None)
  196968. {
  196969. long kwmHints = 2; /*KDE_tinyDecoration*/
  196970. ScopedXLock xlock;
  196971. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196972. (unsigned char*) &kwmHints, 1);
  196973. }
  196974. hints = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  196975. if (hints != None)
  196976. {
  196977. ScopedXLock xlock;
  196978. int netHints [2];
  196979. int numHints = 0;
  196980. if ((styleFlags & windowIsTemporary) != 0)
  196981. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_MENU", True);
  196982. else
  196983. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196984. if (netHints [numHints] != 0)
  196985. ++numHints;
  196986. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196987. if (netHints [numHints] != 0)
  196988. ++numHints;
  196989. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196990. (unsigned char*) &netHints, numHints);
  196991. }
  196992. }
  196993. void addWindowButtons (Window wndH)
  196994. {
  196995. ScopedXLock xlock;
  196996. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196997. if (hints != None)
  196998. {
  196999. MotifWmHints motifHints;
  197000. zerostruct (motifHints);
  197001. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  197002. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  197003. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  197004. if ((styleFlags & windowHasCloseButton) != 0)
  197005. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  197006. if ((styleFlags & windowHasMinimiseButton) != 0)
  197007. {
  197008. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  197009. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  197010. }
  197011. if ((styleFlags & windowHasMaximiseButton) != 0)
  197012. {
  197013. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  197014. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  197015. }
  197016. if ((styleFlags & windowIsResizable) != 0)
  197017. {
  197018. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  197019. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  197020. }
  197021. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  197022. }
  197023. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  197024. if (hints != None)
  197025. {
  197026. int netHints [6];
  197027. int num = 0;
  197028. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  197029. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  197030. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  197031. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  197032. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197033. (unsigned char*) &netHints, num);
  197034. }
  197035. }
  197036. void createWindow()
  197037. {
  197038. ScopedXLock xlock;
  197039. static bool atomsInitialised = false;
  197040. if (! atomsInitialised)
  197041. {
  197042. atomsInitialised = true;
  197043. wm_Protocols = XInternAtom (display, "WM_PROTOCOLS", 1);
  197044. wm_ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", 1);
  197045. wm_ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", 1);
  197046. wm_ChangeState = XInternAtom (display, "WM_CHANGE_STATE", 1);
  197047. wm_State = XInternAtom (display, "WM_STATE", 1);
  197048. wm_ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  197049. XA_XdndAware = XInternAtom (display, "XdndAware", 0);
  197050. XA_XdndEnter = XInternAtom (display, "XdndEnter", 0);
  197051. XA_XdndLeave = XInternAtom (display, "XdndLeave", 0);
  197052. XA_XdndPosition = XInternAtom (display, "XdndPosition", 0);
  197053. XA_XdndStatus = XInternAtom (display, "XdndStatus", 0);
  197054. XA_XdndDrop = XInternAtom (display, "XdndDrop", 0);
  197055. XA_XdndFinished = XInternAtom (display, "XdndFinished", 0);
  197056. XA_XdndSelection = XInternAtom (display, "XdndSelection", 0);
  197057. XA_XdndProxy = XInternAtom (display, "XdndProxy", 0);
  197058. XA_XdndTypeList = XInternAtom (display, "XdndTypeList", 0);
  197059. XA_XdndActionList = XInternAtom (display, "XdndActionList", 0);
  197060. XA_XdndActionCopy = XInternAtom (display, "XdndActionCopy", 0);
  197061. XA_XdndActionMove = XInternAtom (display, "XdndActionMove", 0);
  197062. XA_XdndActionLink = XInternAtom (display, "XdndActionLink", 0);
  197063. XA_XdndActionAsk = XInternAtom (display, "XdndActionAsk", 0);
  197064. XA_XdndActionPrivate = XInternAtom (display, "XdndActionPrivate", 0);
  197065. XA_XdndActionDescription = XInternAtom (display, "XdndActionDescription", 0);
  197066. XA_JXSelectionWindowProperty = XInternAtom (display, "JXSelectionWindowProperty", 0);
  197067. XA_MimeTextPlain = XInternAtom (display, "text/plain", 0);
  197068. XA_MimeTextUriList = XInternAtom (display, "text/uri-list", 0);
  197069. XA_MimeRootDrop = XInternAtom (display, "application/x-rootwindow-drop", 0);
  197070. }
  197071. resetDragAndDrop();
  197072. XA_OtherMime = XA_MimeTextPlain; // xxx why??
  197073. allowedMimeTypeAtoms [0] = XA_MimeTextPlain;
  197074. allowedMimeTypeAtoms [1] = XA_OtherMime;
  197075. allowedMimeTypeAtoms [2] = XA_MimeTextUriList;
  197076. allowedActions [0] = XA_XdndActionMove;
  197077. allowedActions [1] = XA_XdndActionCopy;
  197078. allowedActions [2] = XA_XdndActionLink;
  197079. allowedActions [3] = XA_XdndActionAsk;
  197080. allowedActions [4] = XA_XdndActionPrivate;
  197081. // Get defaults for various properties
  197082. const int screen = DefaultScreen (display);
  197083. Window root = RootWindow (display, screen);
  197084. // Attempt to create a 24-bit window on the default screen. If this is not
  197085. // possible then exit
  197086. XVisualInfo desiredVisual;
  197087. desiredVisual.screen = screen;
  197088. desiredVisual.depth = 24;
  197089. depthIs16Bit = false;
  197090. int numVisuals;
  197091. XVisualInfo* visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197092. &desiredVisual, &numVisuals);
  197093. if (numVisuals < 1 || visuals == 0)
  197094. {
  197095. XFree (visuals);
  197096. desiredVisual.depth = 16;
  197097. visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197098. &desiredVisual, &numVisuals);
  197099. if (numVisuals < 1 || visuals == 0)
  197100. {
  197101. Logger::outputDebugString ("ERROR: System doesn't support 24 or 16 bit RGB display.\n");
  197102. Process::terminate();
  197103. }
  197104. depthIs16Bit = true;
  197105. }
  197106. XFree (visuals);
  197107. // Set up the window attributes
  197108. XSetWindowAttributes swa;
  197109. swa.border_pixel = 0;
  197110. swa.background_pixmap = None;
  197111. swa.colormap = DefaultColormap (display, screen);
  197112. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  197113. swa.event_mask = eventMask;
  197114. Window wndH = XCreateWindow (display, root,
  197115. 0, 0, 1, 1,
  197116. 0, 0, InputOutput, (Visual*) CopyFromParent,
  197117. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  197118. &swa);
  197119. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  197120. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  197121. GrabModeAsync, GrabModeAsync, None, None);
  197122. // Set the window context to identify the window handle object
  197123. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  197124. {
  197125. // Failed
  197126. jassertfalse
  197127. Logger::outputDebugString ("Failed to create context information for window.\n");
  197128. XDestroyWindow (display, wndH);
  197129. wndH = 0;
  197130. }
  197131. // Set window manager hints
  197132. XWMHints* wmHints = XAllocWMHints();
  197133. wmHints->flags = InputHint | StateHint;
  197134. wmHints->input = True; // Locally active input model
  197135. wmHints->initial_state = NormalState;
  197136. XSetWMHints (display, wndH, wmHints);
  197137. XFree (wmHints);
  197138. if ((styleFlags & windowIsSemiTransparent) != 0)
  197139. {
  197140. //xxx
  197141. }
  197142. if ((styleFlags & windowAppearsOnTaskbar) != 0)
  197143. {
  197144. //xxx
  197145. }
  197146. //XSetTransientForHint (display, wndH, RootWindow (display, DefaultScreen (display)));
  197147. if ((styleFlags & windowHasTitleBar) == 0)
  197148. removeWindowDecorations (wndH);
  197149. else
  197150. addWindowButtons (wndH);
  197151. // Set window manager protocols
  197152. XChangeProperty (display, wndH, wm_Protocols, XA_ATOM, 32, PropModeReplace,
  197153. (unsigned char*) wm_ProtocolList, 2);
  197154. // Set drag and drop flags
  197155. XChangeProperty (display, wndH, XA_XdndTypeList, XA_ATOM, 32, PropModeReplace,
  197156. (const unsigned char*) allowedMimeTypeAtoms, numElementsInArray (allowedMimeTypeAtoms));
  197157. XChangeProperty (display, wndH, XA_XdndActionList, XA_ATOM, 32, PropModeReplace,
  197158. (const unsigned char*) allowedActions, numElementsInArray (allowedActions));
  197159. XChangeProperty (display, wndH, XA_XdndActionDescription, XA_STRING, 8, PropModeReplace,
  197160. (const unsigned char*) "", 0);
  197161. unsigned long dndVersion = ourDndVersion;
  197162. XChangeProperty (display, wndH, XA_XdndAware, XA_ATOM, 32, PropModeReplace,
  197163. (const unsigned char*) &dndVersion, 1);
  197164. // Set window name
  197165. setWindowTitle (wndH, getComponent()->getName());
  197166. // Initialise the pointer and keyboard mapping
  197167. // This is not the same as the logical pointer mapping the X server uses:
  197168. // we don't mess with this.
  197169. static bool mappingInitialised = false;
  197170. if (! mappingInitialised)
  197171. {
  197172. mappingInitialised = true;
  197173. const int numButtons = XGetPointerMapping (display, 0, 0);
  197174. if (numButtons == 2)
  197175. {
  197176. pointerMap[0] = LeftButton;
  197177. pointerMap[1] = RightButton;
  197178. pointerMap[2] = pointerMap[3] = pointerMap[4] = NoButton;
  197179. }
  197180. else if (numButtons >= 3)
  197181. {
  197182. pointerMap[0] = LeftButton;
  197183. pointerMap[1] = MiddleButton;
  197184. pointerMap[2] = RightButton;
  197185. if (numButtons >= 5)
  197186. {
  197187. pointerMap[3] = WheelUp;
  197188. pointerMap[4] = WheelDown;
  197189. }
  197190. }
  197191. getModifierMapping();
  197192. }
  197193. windowH = wndH;
  197194. }
  197195. void destroyWindow()
  197196. {
  197197. ScopedXLock xlock;
  197198. XPointer handlePointer;
  197199. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197200. XDeleteContext (display, (XID) windowH, improbableNumber);
  197201. XDestroyWindow (display, windowH);
  197202. // Wait for it to complete and then remove any events for this
  197203. // window from the event queue.
  197204. XSync (display, false);
  197205. XEvent event;
  197206. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197207. {}
  197208. }
  197209. static int64 getEventTime (::Time t) throw()
  197210. {
  197211. static int64 eventTimeOffset = 0x12345678;
  197212. const int64 thisMessageTime = t;
  197213. if (eventTimeOffset == 0x12345678)
  197214. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197215. return eventTimeOffset + thisMessageTime;
  197216. }
  197217. static void setWindowTitle (Window xwin, const char* const title) throw()
  197218. {
  197219. XTextProperty nameProperty;
  197220. char* strings[] = { (char*) title };
  197221. ScopedXLock xlock;
  197222. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197223. {
  197224. XSetWMName (display, xwin, &nameProperty);
  197225. XSetWMIconName (display, xwin, &nameProperty);
  197226. XFree (nameProperty.value);
  197227. }
  197228. }
  197229. void updateBorderSize()
  197230. {
  197231. if ((styleFlags & windowHasTitleBar) == 0)
  197232. {
  197233. windowBorder = BorderSize (0);
  197234. }
  197235. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197236. {
  197237. ScopedXLock xlock;
  197238. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197239. if (hints != None)
  197240. {
  197241. unsigned char* data = 0;
  197242. unsigned long nitems, bytesLeft;
  197243. Atom actualType;
  197244. int actualFormat;
  197245. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197246. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197247. &data) == Success)
  197248. {
  197249. const unsigned long* const sizes = (const unsigned long*) data;
  197250. if (actualFormat == 32)
  197251. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197252. (int) sizes[3], (int) sizes[1]);
  197253. XFree (data);
  197254. }
  197255. }
  197256. }
  197257. }
  197258. void updateBounds()
  197259. {
  197260. jassert (windowH != 0);
  197261. if (windowH != 0)
  197262. {
  197263. Window root, child;
  197264. unsigned int bw, depth;
  197265. ScopedXLock xlock;
  197266. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197267. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197268. &bw, &depth))
  197269. {
  197270. wx = wy = ww = wh = 0;
  197271. }
  197272. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197273. {
  197274. wx = wy = 0;
  197275. }
  197276. }
  197277. }
  197278. void resetDragAndDrop()
  197279. {
  197280. dragAndDropFiles.clear();
  197281. lastDropPos = Point<int> (-1, -1);
  197282. dragAndDropCurrentMimeType = 0;
  197283. dragAndDropSourceWindow = 0;
  197284. srcMimeTypeAtomList.clear();
  197285. }
  197286. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197287. {
  197288. msg.type = ClientMessage;
  197289. msg.display = display;
  197290. msg.window = dragAndDropSourceWindow;
  197291. msg.format = 32;
  197292. msg.data.l[0] = windowH;
  197293. ScopedXLock xlock;
  197294. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197295. }
  197296. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197297. {
  197298. XClientMessageEvent msg;
  197299. zerostruct (msg);
  197300. msg.message_type = XA_XdndStatus;
  197301. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197302. msg.data.l[4] = dropAction;
  197303. sendDragAndDropMessage (msg);
  197304. }
  197305. void sendDragAndDropLeave()
  197306. {
  197307. XClientMessageEvent msg;
  197308. zerostruct (msg);
  197309. msg.message_type = XA_XdndLeave;
  197310. sendDragAndDropMessage (msg);
  197311. }
  197312. void sendDragAndDropFinish()
  197313. {
  197314. XClientMessageEvent msg;
  197315. zerostruct (msg);
  197316. msg.message_type = XA_XdndFinished;
  197317. sendDragAndDropMessage (msg);
  197318. }
  197319. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197320. {
  197321. if ((clientMsg->data.l[1] & 1) == 0)
  197322. {
  197323. sendDragAndDropLeave();
  197324. if (dragAndDropFiles.size() > 0)
  197325. handleFileDragExit (dragAndDropFiles);
  197326. dragAndDropFiles.clear();
  197327. }
  197328. }
  197329. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197330. {
  197331. if (dragAndDropSourceWindow == 0)
  197332. return;
  197333. dragAndDropSourceWindow = clientMsg->data.l[0];
  197334. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  197335. (int) clientMsg->data.l[2] & 0xffff);
  197336. dropPos -= getScreenPosition();
  197337. if (lastDropPos != dropPos)
  197338. {
  197339. lastDropPos = dropPos;
  197340. dragAndDropTimestamp = clientMsg->data.l[3];
  197341. Atom targetAction = XA_XdndActionCopy;
  197342. for (int i = numElementsInArray (allowedActions); --i >= 0;)
  197343. {
  197344. if ((Atom) clientMsg->data.l[4] == allowedActions[i])
  197345. {
  197346. targetAction = allowedActions[i];
  197347. break;
  197348. }
  197349. }
  197350. sendDragAndDropStatus (true, targetAction);
  197351. if (dragAndDropFiles.size() == 0)
  197352. updateDraggedFileList (clientMsg);
  197353. if (dragAndDropFiles.size() > 0)
  197354. handleFileDragMove (dragAndDropFiles, dropPos.getX(), dropPos.getY());
  197355. }
  197356. }
  197357. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197358. {
  197359. if (dragAndDropFiles.size() == 0)
  197360. updateDraggedFileList (clientMsg);
  197361. const StringArray files (dragAndDropFiles);
  197362. const Point<int> lastPos (lastDropPos);
  197363. sendDragAndDropFinish();
  197364. resetDragAndDrop();
  197365. if (files.size() > 0)
  197366. handleFileDragDrop (files, lastPos.getX(), lastPos.getY());
  197367. }
  197368. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197369. {
  197370. dragAndDropFiles.clear();
  197371. srcMimeTypeAtomList.clear();
  197372. dragAndDropCurrentMimeType = 0;
  197373. const int dndCurrentVersion = (int) (clientMsg->data.l[1] & 0xff000000) >> 24;
  197374. if (dndCurrentVersion < 3 || dndCurrentVersion > ourDndVersion)
  197375. {
  197376. dragAndDropSourceWindow = 0;
  197377. return;
  197378. }
  197379. dragAndDropSourceWindow = clientMsg->data.l[0];
  197380. if ((clientMsg->data.l[1] & 1) != 0)
  197381. {
  197382. Atom actual;
  197383. int format;
  197384. unsigned long count = 0, remaining = 0;
  197385. unsigned char* data = 0;
  197386. ScopedXLock xlock;
  197387. XGetWindowProperty (display, dragAndDropSourceWindow, XA_XdndTypeList,
  197388. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197389. &count, &remaining, &data);
  197390. if (data != 0)
  197391. {
  197392. if (actual == XA_ATOM && format == 32 && count != 0)
  197393. {
  197394. const unsigned long* const types = (const unsigned long*) data;
  197395. for (unsigned int i = 0; i < count; ++i)
  197396. if (types[i] != None)
  197397. srcMimeTypeAtomList.add (types[i]);
  197398. }
  197399. XFree (data);
  197400. }
  197401. }
  197402. if (srcMimeTypeAtomList.size() == 0)
  197403. {
  197404. for (int i = 2; i < 5; ++i)
  197405. if (clientMsg->data.l[i] != None)
  197406. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197407. if (srcMimeTypeAtomList.size() == 0)
  197408. {
  197409. dragAndDropSourceWindow = 0;
  197410. return;
  197411. }
  197412. }
  197413. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197414. for (int j = 0; j < numElementsInArray (allowedMimeTypeAtoms); ++j)
  197415. if (srcMimeTypeAtomList[i] == allowedMimeTypeAtoms[j])
  197416. dragAndDropCurrentMimeType = allowedMimeTypeAtoms[j];
  197417. handleDragAndDropPosition (clientMsg);
  197418. }
  197419. void handleDragAndDropSelection (const XEvent* const evt)
  197420. {
  197421. dragAndDropFiles.clear();
  197422. if (evt->xselection.property != 0)
  197423. {
  197424. StringArray lines;
  197425. {
  197426. MemoryBlock dropData;
  197427. for (;;)
  197428. {
  197429. Atom actual;
  197430. uint8* data = 0;
  197431. unsigned long count = 0, remaining = 0;
  197432. int format = 0;
  197433. ScopedXLock xlock;
  197434. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197435. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197436. &format, &count, &remaining, &data) == Success)
  197437. {
  197438. dropData.append (data, count * format / 8);
  197439. XFree (data);
  197440. if (remaining == 0)
  197441. break;
  197442. }
  197443. else
  197444. {
  197445. XFree (data);
  197446. break;
  197447. }
  197448. }
  197449. lines.addLines (dropData.toString());
  197450. }
  197451. for (int i = 0; i < lines.size(); ++i)
  197452. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197453. dragAndDropFiles.trim();
  197454. dragAndDropFiles.removeEmptyStrings();
  197455. }
  197456. }
  197457. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197458. {
  197459. dragAndDropFiles.clear();
  197460. if (dragAndDropSourceWindow != None
  197461. && dragAndDropCurrentMimeType != 0)
  197462. {
  197463. dragAndDropTimestamp = clientMsg->data.l[2];
  197464. ScopedXLock xlock;
  197465. XConvertSelection (display,
  197466. XA_XdndSelection,
  197467. dragAndDropCurrentMimeType,
  197468. XA_JXSelectionWindowProperty,
  197469. windowH,
  197470. dragAndDropTimestamp);
  197471. }
  197472. }
  197473. StringArray dragAndDropFiles;
  197474. int dragAndDropTimestamp;
  197475. Point<int> lastDropPos;
  197476. Atom XA_OtherMime, dragAndDropCurrentMimeType;
  197477. Window dragAndDropSourceWindow;
  197478. unsigned int allowedActions [5];
  197479. unsigned int allowedMimeTypeAtoms [3];
  197480. Array <Atom> srcMimeTypeAtomList;
  197481. };
  197482. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197483. {
  197484. if (enableOrDisable)
  197485. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197486. }
  197487. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197488. {
  197489. return new LinuxComponentPeer (this, styleFlags);
  197490. }
  197491. // (this callback is hooked up in the messaging code)
  197492. void juce_windowMessageReceive (XEvent* event)
  197493. {
  197494. if (event->xany.window != None)
  197495. {
  197496. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197497. if (ComponentPeer::isValidPeer (peer))
  197498. peer->handleWindowMessage (event);
  197499. }
  197500. else
  197501. {
  197502. switch (event->xany.type)
  197503. {
  197504. case KeymapNotify:
  197505. {
  197506. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197507. memcpy (keyStates, keymapEvent->key_vector, 32);
  197508. break;
  197509. }
  197510. default:
  197511. break;
  197512. }
  197513. }
  197514. }
  197515. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197516. {
  197517. if (display == 0)
  197518. return;
  197519. #if JUCE_USE_XINERAMA
  197520. int major_opcode, first_event, first_error;
  197521. ScopedXLock xlock;
  197522. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197523. {
  197524. typedef Bool (*tXineramaIsActive) (Display*);
  197525. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197526. static tXineramaIsActive xXineramaIsActive = 0;
  197527. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197528. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197529. {
  197530. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197531. if (h != 0)
  197532. {
  197533. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197534. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197535. }
  197536. }
  197537. if (xXineramaIsActive != 0
  197538. && xXineramaQueryScreens != 0
  197539. && xXineramaIsActive (display))
  197540. {
  197541. int numMonitors = 0;
  197542. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197543. if (screens != 0)
  197544. {
  197545. for (int i = numMonitors; --i >= 0;)
  197546. {
  197547. int index = screens[i].screen_number;
  197548. if (index >= 0)
  197549. {
  197550. while (monitorCoords.size() < index)
  197551. monitorCoords.add (Rectangle<int>());
  197552. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197553. screens[i].y_org,
  197554. screens[i].width,
  197555. screens[i].height));
  197556. }
  197557. }
  197558. XFree (screens);
  197559. }
  197560. }
  197561. }
  197562. if (monitorCoords.size() == 0)
  197563. #endif
  197564. {
  197565. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197566. if (hints != None)
  197567. {
  197568. const int numMonitors = ScreenCount (display);
  197569. for (int i = 0; i < numMonitors; ++i)
  197570. {
  197571. Window root = RootWindow (display, i);
  197572. unsigned long nitems, bytesLeft;
  197573. Atom actualType;
  197574. int actualFormat;
  197575. unsigned char* data = 0;
  197576. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197577. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197578. &data) == Success)
  197579. {
  197580. const long* const position = (const long*) data;
  197581. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197582. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197583. position[2], position[3]));
  197584. XFree (data);
  197585. }
  197586. }
  197587. }
  197588. if (monitorCoords.size() == 0)
  197589. {
  197590. monitorCoords.add (Rectangle<int> (0, 0,
  197591. DisplayWidth (display, DefaultScreen (display)),
  197592. DisplayHeight (display, DefaultScreen (display))));
  197593. }
  197594. }
  197595. }
  197596. bool Desktop::canUseSemiTransparentWindows() throw()
  197597. {
  197598. return false;
  197599. }
  197600. const Point<int> Desktop::getMousePosition()
  197601. {
  197602. int x, y, mouseMods;
  197603. getMousePos (x, y, mouseMods);
  197604. return Point<int> (x, y);
  197605. }
  197606. void Desktop::setMousePosition (const Point<int>& newPosition)
  197607. {
  197608. ScopedXLock xlock;
  197609. Window root = RootWindow (display, DefaultScreen (display));
  197610. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197611. }
  197612. static bool screenSaverAllowed = true;
  197613. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197614. {
  197615. if (screenSaverAllowed != isEnabled)
  197616. {
  197617. screenSaverAllowed = isEnabled;
  197618. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197619. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197620. if (xScreenSaverSuspend == 0)
  197621. {
  197622. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197623. if (h != 0)
  197624. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197625. }
  197626. ScopedXLock xlock;
  197627. if (xScreenSaverSuspend != 0)
  197628. xScreenSaverSuspend (display, ! isEnabled);
  197629. }
  197630. }
  197631. bool Desktop::isScreenSaverEnabled() throw()
  197632. {
  197633. return screenSaverAllowed;
  197634. }
  197635. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197636. {
  197637. ScopedXLock xlock;
  197638. Window root = RootWindow (display, DefaultScreen (display));
  197639. const unsigned int imageW = image.getWidth();
  197640. const unsigned int imageH = image.getHeight();
  197641. unsigned int cursorW, cursorH;
  197642. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197643. return 0;
  197644. Image im (Image::ARGB, cursorW, cursorH, true);
  197645. Graphics g (im);
  197646. if (imageW > cursorW || imageH > cursorH)
  197647. {
  197648. hotspotX = (hotspotX * cursorW) / imageW;
  197649. hotspotY = (hotspotY * cursorH) / imageH;
  197650. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197651. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197652. false);
  197653. }
  197654. else
  197655. {
  197656. g.drawImageAt (&image, 0, 0);
  197657. }
  197658. const int stride = (cursorW + 7) >> 3;
  197659. HeapBlock <uint8> maskPlane, sourcePlane;
  197660. maskPlane.calloc (stride * cursorH);
  197661. sourcePlane.calloc (stride * cursorH);
  197662. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197663. for (int y = cursorH; --y >= 0;)
  197664. {
  197665. for (int x = cursorW; --x >= 0;)
  197666. {
  197667. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197668. const int offset = y * stride + (x >> 3);
  197669. const Colour c (im.getPixelAt (x, y));
  197670. if (c.getAlpha() >= 128)
  197671. maskPlane[offset] |= mask;
  197672. if (c.getBrightness() >= 0.5f)
  197673. sourcePlane[offset] |= mask;
  197674. }
  197675. }
  197676. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, (char*) sourcePlane, cursorW, cursorH, 0xffff, 0, 1);
  197677. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, (char*) maskPlane, cursorW, cursorH, 0xffff, 0, 1);
  197678. XColor white, black;
  197679. black.red = black.green = black.blue = 0;
  197680. white.red = white.green = white.blue = 0xffff;
  197681. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197682. XFreePixmap (display, sourcePixmap);
  197683. XFreePixmap (display, maskPixmap);
  197684. return result;
  197685. }
  197686. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197687. {
  197688. ScopedXLock xlock;
  197689. if (cursorHandle != None)
  197690. XFreeCursor (display, (Cursor) cursorHandle);
  197691. }
  197692. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197693. {
  197694. unsigned int shape;
  197695. switch (type)
  197696. {
  197697. case MouseCursor::NoCursor:
  197698. {
  197699. const Image im (Image::ARGB, 16, 16, true);
  197700. return juce_createMouseCursorFromImage (im, 0, 0);
  197701. }
  197702. case MouseCursor::NormalCursor:
  197703. return (void*) None; // Use parent cursor
  197704. case MouseCursor::DraggingHandCursor:
  197705. {
  197706. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197707. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197708. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197709. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197710. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197711. const int dragHandDataSize = 99;
  197712. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197713. return juce_createMouseCursorFromImage (*im, 8, 7);
  197714. }
  197715. case MouseCursor::CopyingCursor:
  197716. {
  197717. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197718. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197719. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197720. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197721. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197722. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197723. const int copyCursorSize = 119;
  197724. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197725. return juce_createMouseCursorFromImage (*im, 1, 3);
  197726. }
  197727. case MouseCursor::WaitCursor:
  197728. shape = XC_watch;
  197729. break;
  197730. case MouseCursor::IBeamCursor:
  197731. shape = XC_xterm;
  197732. break;
  197733. case MouseCursor::PointingHandCursor:
  197734. shape = XC_hand2;
  197735. break;
  197736. case MouseCursor::LeftRightResizeCursor:
  197737. shape = XC_sb_h_double_arrow;
  197738. break;
  197739. case MouseCursor::UpDownResizeCursor:
  197740. shape = XC_sb_v_double_arrow;
  197741. break;
  197742. case MouseCursor::UpDownLeftRightResizeCursor:
  197743. shape = XC_fleur;
  197744. break;
  197745. case MouseCursor::TopEdgeResizeCursor:
  197746. shape = XC_top_side;
  197747. break;
  197748. case MouseCursor::BottomEdgeResizeCursor:
  197749. shape = XC_bottom_side;
  197750. break;
  197751. case MouseCursor::LeftEdgeResizeCursor:
  197752. shape = XC_left_side;
  197753. break;
  197754. case MouseCursor::RightEdgeResizeCursor:
  197755. shape = XC_right_side;
  197756. break;
  197757. case MouseCursor::TopLeftCornerResizeCursor:
  197758. shape = XC_top_left_corner;
  197759. break;
  197760. case MouseCursor::TopRightCornerResizeCursor:
  197761. shape = XC_top_right_corner;
  197762. break;
  197763. case MouseCursor::BottomLeftCornerResizeCursor:
  197764. shape = XC_bottom_left_corner;
  197765. break;
  197766. case MouseCursor::BottomRightCornerResizeCursor:
  197767. shape = XC_bottom_right_corner;
  197768. break;
  197769. case MouseCursor::CrosshairCursor:
  197770. shape = XC_crosshair;
  197771. break;
  197772. default:
  197773. return (void*) None; // Use parent cursor
  197774. }
  197775. ScopedXLock xlock;
  197776. return (void*) XCreateFontCursor (display, shape);
  197777. }
  197778. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197779. {
  197780. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197781. if (lp != 0)
  197782. lp->showMouseCursor ((Cursor) getHandle());
  197783. }
  197784. void MouseCursor::showInAllWindows() const throw()
  197785. {
  197786. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197787. showInWindow (ComponentPeer::getPeer (i));
  197788. }
  197789. Image* juce_createIconForFile (const File& file)
  197790. {
  197791. return 0;
  197792. }
  197793. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197794. {
  197795. return new Image (format, imageWidth, imageHeight, clearImage);
  197796. }
  197797. #if JUCE_OPENGL
  197798. class WindowedGLContext : public OpenGLContext
  197799. {
  197800. public:
  197801. WindowedGLContext (Component* const component,
  197802. const OpenGLPixelFormat& pixelFormat_,
  197803. GLXContext sharedContext)
  197804. : renderContext (0),
  197805. embeddedWindow (0),
  197806. pixelFormat (pixelFormat_)
  197807. {
  197808. jassert (component != 0);
  197809. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197810. if (peer == 0)
  197811. return;
  197812. ScopedXLock xlock;
  197813. XSync (display, False);
  197814. GLint attribs [64];
  197815. int n = 0;
  197816. attribs[n++] = GLX_RGBA;
  197817. attribs[n++] = GLX_DOUBLEBUFFER;
  197818. attribs[n++] = GLX_RED_SIZE;
  197819. attribs[n++] = pixelFormat.redBits;
  197820. attribs[n++] = GLX_GREEN_SIZE;
  197821. attribs[n++] = pixelFormat.greenBits;
  197822. attribs[n++] = GLX_BLUE_SIZE;
  197823. attribs[n++] = pixelFormat.blueBits;
  197824. attribs[n++] = GLX_ALPHA_SIZE;
  197825. attribs[n++] = pixelFormat.alphaBits;
  197826. attribs[n++] = GLX_DEPTH_SIZE;
  197827. attribs[n++] = pixelFormat.depthBufferBits;
  197828. attribs[n++] = GLX_STENCIL_SIZE;
  197829. attribs[n++] = pixelFormat.stencilBufferBits;
  197830. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197831. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197832. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197833. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197834. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197835. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197836. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197837. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197838. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197839. attribs[n++] = None;
  197840. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197841. if (bestVisual == 0)
  197842. return;
  197843. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197844. Window windowH = (Window) peer->getNativeHandle();
  197845. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197846. XSetWindowAttributes swa;
  197847. swa.colormap = colourMap;
  197848. swa.border_pixel = 0;
  197849. swa.event_mask = ExposureMask | StructureNotifyMask;
  197850. embeddedWindow = XCreateWindow (display, windowH,
  197851. 0, 0, 1, 1, 0,
  197852. bestVisual->depth,
  197853. InputOutput,
  197854. bestVisual->visual,
  197855. CWBorderPixel | CWColormap | CWEventMask,
  197856. &swa);
  197857. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197858. XMapWindow (display, embeddedWindow);
  197859. XFreeColormap (display, colourMap);
  197860. XFree (bestVisual);
  197861. XSync (display, False);
  197862. }
  197863. ~WindowedGLContext()
  197864. {
  197865. makeInactive();
  197866. ScopedXLock xlock;
  197867. glXDestroyContext (display, renderContext);
  197868. XUnmapWindow (display, embeddedWindow);
  197869. XDestroyWindow (display, embeddedWindow);
  197870. }
  197871. bool makeActive() const throw()
  197872. {
  197873. jassert (renderContext != 0);
  197874. ScopedXLock xlock;
  197875. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197876. && XSync (display, False);
  197877. }
  197878. bool makeInactive() const throw()
  197879. {
  197880. ScopedXLock xlock;
  197881. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197882. }
  197883. bool isActive() const throw()
  197884. {
  197885. ScopedXLock xlock;
  197886. return glXGetCurrentContext() == renderContext;
  197887. }
  197888. const OpenGLPixelFormat getPixelFormat() const
  197889. {
  197890. return pixelFormat;
  197891. }
  197892. void* getRawContext() const throw()
  197893. {
  197894. return renderContext;
  197895. }
  197896. void updateWindowPosition (int x, int y, int w, int h, int)
  197897. {
  197898. ScopedXLock xlock;
  197899. XMoveResizeWindow (display, embeddedWindow,
  197900. x, y, jmax (1, w), jmax (1, h));
  197901. }
  197902. void swapBuffers()
  197903. {
  197904. ScopedXLock xlock;
  197905. glXSwapBuffers (display, embeddedWindow);
  197906. }
  197907. bool setSwapInterval (const int numFramesPerSwap)
  197908. {
  197909. // xxx needs doing..
  197910. return false;
  197911. }
  197912. int getSwapInterval() const
  197913. {
  197914. // xxx needs doing..
  197915. return 0;
  197916. }
  197917. void repaint()
  197918. {
  197919. }
  197920. juce_UseDebuggingNewOperator
  197921. GLXContext renderContext;
  197922. private:
  197923. Window embeddedWindow;
  197924. OpenGLPixelFormat pixelFormat;
  197925. WindowedGLContext (const WindowedGLContext&);
  197926. const WindowedGLContext& operator= (const WindowedGLContext&);
  197927. };
  197928. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  197929. const OpenGLPixelFormat& pixelFormat,
  197930. const OpenGLContext* const contextToShareWith)
  197931. {
  197932. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  197933. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  197934. if (c->renderContext == 0)
  197935. deleteAndZero (c);
  197936. return c;
  197937. }
  197938. void juce_glViewport (const int w, const int h)
  197939. {
  197940. glViewport (0, 0, w, h);
  197941. }
  197942. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197943. OwnedArray <OpenGLPixelFormat>& results)
  197944. {
  197945. results.add (new OpenGLPixelFormat()); // xxx
  197946. }
  197947. #endif
  197948. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197949. {
  197950. jassertfalse // not implemented!
  197951. return false;
  197952. }
  197953. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197954. {
  197955. jassertfalse // not implemented!
  197956. return false;
  197957. }
  197958. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197959. {
  197960. if (! isOnDesktop ())
  197961. addToDesktop (0);
  197962. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197963. if (wp != 0)
  197964. {
  197965. wp->setTaskBarIcon (newImage);
  197966. setVisible (true);
  197967. toFront (false);
  197968. repaint();
  197969. }
  197970. }
  197971. void SystemTrayIconComponent::paint (Graphics& g)
  197972. {
  197973. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197974. if (wp != 0)
  197975. {
  197976. const Image* const image = wp->getTaskbarIcon();
  197977. if (image != 0)
  197978. {
  197979. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197980. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197981. false);
  197982. }
  197983. }
  197984. }
  197985. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197986. {
  197987. // xxx not yet implemented!
  197988. }
  197989. void PlatformUtilities::beep()
  197990. {
  197991. std::cout << "\a" << std::flush;
  197992. }
  197993. bool AlertWindow::showNativeDialogBox (const String& title,
  197994. const String& bodyText,
  197995. bool isOkCancel)
  197996. {
  197997. // xxx this is supposed to pop up an alert!
  197998. Logger::outputDebugString (title + ": " + bodyText);
  197999. // use a non-native one for the time being..
  198000. if (isOkCancel)
  198001. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  198002. else
  198003. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  198004. return true;
  198005. }
  198006. const int KeyPress::spaceKey = XK_space & 0xff;
  198007. const int KeyPress::returnKey = XK_Return & 0xff;
  198008. const int KeyPress::escapeKey = XK_Escape & 0xff;
  198009. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  198010. const int KeyPress::leftKey = (XK_Left & 0xff) | extendedKeyModifier;
  198011. const int KeyPress::rightKey = (XK_Right & 0xff) | extendedKeyModifier;
  198012. const int KeyPress::upKey = (XK_Up & 0xff) | extendedKeyModifier;
  198013. const int KeyPress::downKey = (XK_Down & 0xff) | extendedKeyModifier;
  198014. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | extendedKeyModifier;
  198015. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | extendedKeyModifier;
  198016. const int KeyPress::endKey = (XK_End & 0xff) | extendedKeyModifier;
  198017. const int KeyPress::homeKey = (XK_Home & 0xff) | extendedKeyModifier;
  198018. const int KeyPress::insertKey = (XK_Insert & 0xff) | extendedKeyModifier;
  198019. const int KeyPress::deleteKey = (XK_Delete & 0xff) | extendedKeyModifier;
  198020. const int KeyPress::tabKey = XK_Tab & 0xff;
  198021. const int KeyPress::F1Key = (XK_F1 & 0xff) | extendedKeyModifier;
  198022. const int KeyPress::F2Key = (XK_F2 & 0xff) | extendedKeyModifier;
  198023. const int KeyPress::F3Key = (XK_F3 & 0xff) | extendedKeyModifier;
  198024. const int KeyPress::F4Key = (XK_F4 & 0xff) | extendedKeyModifier;
  198025. const int KeyPress::F5Key = (XK_F5 & 0xff) | extendedKeyModifier;
  198026. const int KeyPress::F6Key = (XK_F6 & 0xff) | extendedKeyModifier;
  198027. const int KeyPress::F7Key = (XK_F7 & 0xff) | extendedKeyModifier;
  198028. const int KeyPress::F8Key = (XK_F8 & 0xff) | extendedKeyModifier;
  198029. const int KeyPress::F9Key = (XK_F9 & 0xff) | extendedKeyModifier;
  198030. const int KeyPress::F10Key = (XK_F10 & 0xff) | extendedKeyModifier;
  198031. const int KeyPress::F11Key = (XK_F11 & 0xff) | extendedKeyModifier;
  198032. const int KeyPress::F12Key = (XK_F12 & 0xff) | extendedKeyModifier;
  198033. const int KeyPress::F13Key = (XK_F13 & 0xff) | extendedKeyModifier;
  198034. const int KeyPress::F14Key = (XK_F14 & 0xff) | extendedKeyModifier;
  198035. const int KeyPress::F15Key = (XK_F15 & 0xff) | extendedKeyModifier;
  198036. const int KeyPress::F16Key = (XK_F16 & 0xff) | extendedKeyModifier;
  198037. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | extendedKeyModifier;
  198038. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | extendedKeyModifier;
  198039. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | extendedKeyModifier;
  198040. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | extendedKeyModifier;
  198041. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | extendedKeyModifier;
  198042. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | extendedKeyModifier;
  198043. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | extendedKeyModifier;
  198044. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| extendedKeyModifier;
  198045. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| extendedKeyModifier;
  198046. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| extendedKeyModifier;
  198047. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| extendedKeyModifier;
  198048. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| extendedKeyModifier;
  198049. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| extendedKeyModifier;
  198050. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| extendedKeyModifier;
  198051. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| extendedKeyModifier;
  198052. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| extendedKeyModifier;
  198053. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| extendedKeyModifier;
  198054. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| extendedKeyModifier;
  198055. const int KeyPress::playKey = (0xffeeff00) | extendedKeyModifier;
  198056. const int KeyPress::stopKey = (0xffeeff01) | extendedKeyModifier;
  198057. const int KeyPress::fastForwardKey = (0xffeeff02) | extendedKeyModifier;
  198058. const int KeyPress::rewindKey = (0xffeeff03) | extendedKeyModifier;
  198059. #endif
  198060. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  198061. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  198062. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198063. // compiled on its own).
  198064. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  198065. static const int maxNumChans = 64;
  198066. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  198067. {
  198068. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  198069. snd_pcm_hw_params_t* hwParams;
  198070. snd_pcm_hw_params_alloca (&hwParams);
  198071. for (int i = 0; ratesToTry[i] != 0; ++i)
  198072. {
  198073. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  198074. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  198075. {
  198076. rates.addIfNotAlreadyThere (ratesToTry[i]);
  198077. }
  198078. }
  198079. }
  198080. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  198081. {
  198082. snd_pcm_hw_params_t *params;
  198083. snd_pcm_hw_params_alloca (&params);
  198084. if (snd_pcm_hw_params_any (handle, params) >= 0)
  198085. {
  198086. snd_pcm_hw_params_get_channels_min (params, minChans);
  198087. snd_pcm_hw_params_get_channels_max (params, maxChans);
  198088. }
  198089. }
  198090. static void getDeviceProperties (const String& id,
  198091. unsigned int& minChansOut,
  198092. unsigned int& maxChansOut,
  198093. unsigned int& minChansIn,
  198094. unsigned int& maxChansIn,
  198095. Array <int>& rates)
  198096. {
  198097. if (id.isEmpty())
  198098. return;
  198099. snd_ctl_t* handle;
  198100. if (snd_ctl_open (&handle, id.upToLastOccurrenceOf (T(","), false, false), SND_CTL_NONBLOCK) >= 0)
  198101. {
  198102. snd_pcm_info_t* info;
  198103. snd_pcm_info_alloca (&info);
  198104. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  198105. snd_pcm_info_set_device (info, id.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  198106. snd_pcm_info_set_subdevice (info, 0);
  198107. if (snd_ctl_pcm_info (handle, info) >= 0)
  198108. {
  198109. snd_pcm_t* pcmHandle;
  198110. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198111. {
  198112. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  198113. getDeviceSampleRates (pcmHandle, rates);
  198114. snd_pcm_close (pcmHandle);
  198115. }
  198116. }
  198117. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  198118. if (snd_ctl_pcm_info (handle, info) >= 0)
  198119. {
  198120. snd_pcm_t* pcmHandle;
  198121. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198122. {
  198123. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  198124. if (rates.size() == 0)
  198125. getDeviceSampleRates (pcmHandle, rates);
  198126. snd_pcm_close (pcmHandle);
  198127. }
  198128. }
  198129. snd_ctl_close (handle);
  198130. }
  198131. }
  198132. class ALSADevice
  198133. {
  198134. public:
  198135. ALSADevice (const String& id,
  198136. const bool forInput)
  198137. : handle (0),
  198138. bitDepth (16),
  198139. numChannelsRunning (0),
  198140. isInput (forInput),
  198141. sampleFormat (AudioDataConverters::int16LE)
  198142. {
  198143. failed (snd_pcm_open (&handle, id,
  198144. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198145. SND_PCM_ASYNC));
  198146. }
  198147. ~ALSADevice()
  198148. {
  198149. if (handle != 0)
  198150. snd_pcm_close (handle);
  198151. }
  198152. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198153. {
  198154. if (handle == 0)
  198155. return false;
  198156. snd_pcm_hw_params_t* hwParams;
  198157. snd_pcm_hw_params_alloca (&hwParams);
  198158. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198159. return false;
  198160. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198161. isInterleaved = false;
  198162. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198163. isInterleaved = true;
  198164. else
  198165. {
  198166. jassertfalse
  198167. return false;
  198168. }
  198169. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198170. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198171. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198172. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198173. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198174. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198175. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198176. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198177. bitDepth = 0;
  198178. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198179. {
  198180. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198181. {
  198182. bitDepth = formatsToTry [i + 1];
  198183. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198184. break;
  198185. }
  198186. }
  198187. if (bitDepth == 0)
  198188. {
  198189. error = "device doesn't support a compatible PCM format";
  198190. DBG (T("ALSA error: ") + error + T("\n"));
  198191. return false;
  198192. }
  198193. int dir = 0;
  198194. unsigned int periods = 4;
  198195. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198196. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198197. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198198. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198199. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198200. || failed (snd_pcm_hw_params (handle, hwParams)))
  198201. {
  198202. return false;
  198203. }
  198204. snd_pcm_sw_params_t* swParams;
  198205. snd_pcm_sw_params_alloca (&swParams);
  198206. snd_pcm_uframes_t boundary;
  198207. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198208. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198209. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198210. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198211. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198212. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198213. || failed (snd_pcm_sw_params (handle, swParams)))
  198214. {
  198215. return false;
  198216. }
  198217. numChannelsRunning = numChannels;
  198218. return true;
  198219. }
  198220. bool write (float** const data, const int numSamples)
  198221. {
  198222. if (isInterleaved)
  198223. {
  198224. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198225. float* interleaved = (float*) scratch;
  198226. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198227. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198228. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198229. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198230. return false;
  198231. }
  198232. else
  198233. {
  198234. for (int i = 0; i < numChannelsRunning; ++i)
  198235. if (data[i] != 0)
  198236. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198237. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198238. if (failed (num))
  198239. {
  198240. if (num == -EPIPE)
  198241. {
  198242. if (failed (snd_pcm_prepare (handle)))
  198243. return false;
  198244. }
  198245. else if (num != -ESTRPIPE)
  198246. return false;
  198247. }
  198248. }
  198249. return true;
  198250. }
  198251. bool read (float** const data, const int numSamples)
  198252. {
  198253. if (isInterleaved)
  198254. {
  198255. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198256. float* interleaved = (float*) scratch;
  198257. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198258. if (failed (num))
  198259. {
  198260. if (num == -EPIPE)
  198261. {
  198262. if (failed (snd_pcm_prepare (handle)))
  198263. return false;
  198264. }
  198265. else if (num != -ESTRPIPE)
  198266. return false;
  198267. }
  198268. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198269. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198270. }
  198271. else
  198272. {
  198273. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198274. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198275. return false;
  198276. for (int i = 0; i < numChannelsRunning; ++i)
  198277. if (data[i] != 0)
  198278. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198279. }
  198280. return true;
  198281. }
  198282. juce_UseDebuggingNewOperator
  198283. snd_pcm_t* handle;
  198284. String error;
  198285. int bitDepth, numChannelsRunning;
  198286. private:
  198287. const bool isInput;
  198288. bool isInterleaved;
  198289. MemoryBlock scratch;
  198290. AudioDataConverters::DataFormat sampleFormat;
  198291. bool failed (const int errorNum)
  198292. {
  198293. if (errorNum >= 0)
  198294. return false;
  198295. error = snd_strerror (errorNum);
  198296. DBG (T("ALSA error: ") + error + T("\n"));
  198297. return true;
  198298. }
  198299. };
  198300. class ALSAThread : public Thread
  198301. {
  198302. public:
  198303. ALSAThread (const String& inputId_,
  198304. const String& outputId_)
  198305. : Thread ("Juce ALSA"),
  198306. sampleRate (0),
  198307. bufferSize (0),
  198308. callback (0),
  198309. inputId (inputId_),
  198310. outputId (outputId_),
  198311. outputDevice (0),
  198312. inputDevice (0),
  198313. numCallbacks (0),
  198314. totalNumInputChannels (0),
  198315. totalNumOutputChannels (0)
  198316. {
  198317. zeromem (outputChannelData, sizeof (outputChannelData));
  198318. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198319. zeromem (inputChannelData, sizeof (inputChannelData));
  198320. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198321. initialiseRatesAndChannels();
  198322. }
  198323. ~ALSAThread()
  198324. {
  198325. close();
  198326. }
  198327. void open (BitArray inputChannels,
  198328. BitArray outputChannels,
  198329. const double sampleRate_,
  198330. const int bufferSize_)
  198331. {
  198332. close();
  198333. error = String::empty;
  198334. sampleRate = sampleRate_;
  198335. bufferSize = bufferSize_;
  198336. currentInputChans.clear();
  198337. currentOutputChans.clear();
  198338. if (inputChannels.getHighestBit() >= 0)
  198339. {
  198340. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198341. {
  198342. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198343. if (inputChannels[i])
  198344. {
  198345. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198346. currentInputChans.setBit (i);
  198347. }
  198348. }
  198349. }
  198350. if (outputChannels.getHighestBit() >= 0)
  198351. {
  198352. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198353. {
  198354. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198355. if (outputChannels[i])
  198356. {
  198357. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198358. currentOutputChans.setBit (i);
  198359. }
  198360. }
  198361. }
  198362. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198363. {
  198364. outputDevice = new ALSADevice (outputId, false);
  198365. if (outputDevice->error.isNotEmpty())
  198366. {
  198367. error = outputDevice->error;
  198368. deleteAndZero (outputDevice);
  198369. return;
  198370. }
  198371. currentOutputChans.setRange (0, minChansOut, true);
  198372. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198373. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198374. bufferSize))
  198375. {
  198376. error = outputDevice->error;
  198377. deleteAndZero (outputDevice);
  198378. return;
  198379. }
  198380. }
  198381. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198382. {
  198383. inputDevice = new ALSADevice (inputId, true);
  198384. if (inputDevice->error.isNotEmpty())
  198385. {
  198386. error = inputDevice->error;
  198387. deleteAndZero (inputDevice);
  198388. return;
  198389. }
  198390. currentInputChans.setRange (0, minChansIn, true);
  198391. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198392. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198393. bufferSize))
  198394. {
  198395. error = inputDevice->error;
  198396. deleteAndZero (inputDevice);
  198397. return;
  198398. }
  198399. }
  198400. if (outputDevice == 0 && inputDevice == 0)
  198401. {
  198402. error = "no channels";
  198403. return;
  198404. }
  198405. if (outputDevice != 0 && inputDevice != 0)
  198406. {
  198407. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198408. }
  198409. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198410. return;
  198411. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198412. return;
  198413. startThread (9);
  198414. int count = 1000;
  198415. while (numCallbacks == 0)
  198416. {
  198417. sleep (5);
  198418. if (--count < 0 || ! isThreadRunning())
  198419. {
  198420. error = "device didn't start";
  198421. break;
  198422. }
  198423. }
  198424. }
  198425. void close()
  198426. {
  198427. stopThread (6000);
  198428. deleteAndZero (inputDevice);
  198429. deleteAndZero (outputDevice);
  198430. for (int i = 0; i < maxNumChans; ++i)
  198431. {
  198432. juce_free (inputChannelData [i]);
  198433. juce_free (outputChannelData [i]);
  198434. }
  198435. zeromem (outputChannelData, sizeof (outputChannelData));
  198436. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198437. zeromem (inputChannelData, sizeof (inputChannelData));
  198438. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198439. totalNumOutputChannels = 0;
  198440. totalNumInputChannels = 0;
  198441. numCallbacks = 0;
  198442. }
  198443. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198444. {
  198445. const ScopedLock sl (callbackLock);
  198446. callback = newCallback;
  198447. }
  198448. void run()
  198449. {
  198450. while (! threadShouldExit())
  198451. {
  198452. if (inputDevice != 0)
  198453. {
  198454. if (! inputDevice->read (inputChannelData, bufferSize))
  198455. {
  198456. DBG ("ALSA: read failure");
  198457. break;
  198458. }
  198459. }
  198460. if (threadShouldExit())
  198461. break;
  198462. {
  198463. const ScopedLock sl (callbackLock);
  198464. ++numCallbacks;
  198465. if (callback != 0)
  198466. {
  198467. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198468. totalNumInputChannels,
  198469. outputChannelDataForCallback,
  198470. totalNumOutputChannels,
  198471. bufferSize);
  198472. }
  198473. else
  198474. {
  198475. for (int i = 0; i < totalNumOutputChannels; ++i)
  198476. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198477. }
  198478. }
  198479. if (outputDevice != 0)
  198480. {
  198481. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198482. if (threadShouldExit())
  198483. break;
  198484. failed (snd_pcm_avail_update (outputDevice->handle));
  198485. if (! outputDevice->write (outputChannelData, bufferSize))
  198486. {
  198487. DBG ("ALSA: write failure");
  198488. break;
  198489. }
  198490. }
  198491. }
  198492. }
  198493. int getBitDepth() const throw()
  198494. {
  198495. if (outputDevice != 0)
  198496. return outputDevice->bitDepth;
  198497. if (inputDevice != 0)
  198498. return inputDevice->bitDepth;
  198499. return 16;
  198500. }
  198501. juce_UseDebuggingNewOperator
  198502. String error;
  198503. double sampleRate;
  198504. int bufferSize;
  198505. BitArray currentInputChans, currentOutputChans;
  198506. Array <int> sampleRates;
  198507. StringArray channelNamesOut, channelNamesIn;
  198508. AudioIODeviceCallback* callback;
  198509. private:
  198510. const String inputId, outputId;
  198511. ALSADevice* outputDevice;
  198512. ALSADevice* inputDevice;
  198513. int numCallbacks;
  198514. CriticalSection callbackLock;
  198515. float* outputChannelData [maxNumChans];
  198516. float* outputChannelDataForCallback [maxNumChans];
  198517. int totalNumInputChannels;
  198518. float* inputChannelData [maxNumChans];
  198519. float* inputChannelDataForCallback [maxNumChans];
  198520. int totalNumOutputChannels;
  198521. unsigned int minChansOut, maxChansOut;
  198522. unsigned int minChansIn, maxChansIn;
  198523. bool failed (const int errorNum) throw()
  198524. {
  198525. if (errorNum >= 0)
  198526. return false;
  198527. error = snd_strerror (errorNum);
  198528. DBG (T("ALSA error: ") + error + T("\n"));
  198529. return true;
  198530. }
  198531. void initialiseRatesAndChannels() throw()
  198532. {
  198533. sampleRates.clear();
  198534. channelNamesOut.clear();
  198535. channelNamesIn.clear();
  198536. minChansOut = 0;
  198537. maxChansOut = 0;
  198538. minChansIn = 0;
  198539. maxChansIn = 0;
  198540. unsigned int dummy = 0;
  198541. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198542. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198543. unsigned int i;
  198544. for (i = 0; i < maxChansOut; ++i)
  198545. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198546. for (i = 0; i < maxChansIn; ++i)
  198547. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198548. }
  198549. };
  198550. class ALSAAudioIODevice : public AudioIODevice
  198551. {
  198552. public:
  198553. ALSAAudioIODevice (const String& deviceName,
  198554. const String& inputId_,
  198555. const String& outputId_)
  198556. : AudioIODevice (deviceName, T("ALSA")),
  198557. inputId (inputId_),
  198558. outputId (outputId_),
  198559. isOpen_ (false),
  198560. isStarted (false),
  198561. internal (0)
  198562. {
  198563. internal = new ALSAThread (inputId, outputId);
  198564. }
  198565. ~ALSAAudioIODevice()
  198566. {
  198567. delete internal;
  198568. }
  198569. const StringArray getOutputChannelNames()
  198570. {
  198571. return internal->channelNamesOut;
  198572. }
  198573. const StringArray getInputChannelNames()
  198574. {
  198575. return internal->channelNamesIn;
  198576. }
  198577. int getNumSampleRates()
  198578. {
  198579. return internal->sampleRates.size();
  198580. }
  198581. double getSampleRate (int index)
  198582. {
  198583. return internal->sampleRates [index];
  198584. }
  198585. int getNumBufferSizesAvailable()
  198586. {
  198587. return 50;
  198588. }
  198589. int getBufferSizeSamples (int index)
  198590. {
  198591. int n = 16;
  198592. for (int i = 0; i < index; ++i)
  198593. n += n < 64 ? 16
  198594. : (n < 512 ? 32
  198595. : (n < 1024 ? 64
  198596. : (n < 2048 ? 128 : 256)));
  198597. return n;
  198598. }
  198599. int getDefaultBufferSize()
  198600. {
  198601. return 512;
  198602. }
  198603. const String open (const BitArray& inputChannels,
  198604. const BitArray& outputChannels,
  198605. double sampleRate,
  198606. int bufferSizeSamples)
  198607. {
  198608. close();
  198609. if (bufferSizeSamples <= 0)
  198610. bufferSizeSamples = getDefaultBufferSize();
  198611. if (sampleRate <= 0)
  198612. {
  198613. for (int i = 0; i < getNumSampleRates(); ++i)
  198614. {
  198615. if (getSampleRate (i) >= 44100)
  198616. {
  198617. sampleRate = getSampleRate (i);
  198618. break;
  198619. }
  198620. }
  198621. }
  198622. internal->open (inputChannels, outputChannels,
  198623. sampleRate, bufferSizeSamples);
  198624. isOpen_ = internal->error.isEmpty();
  198625. return internal->error;
  198626. }
  198627. void close()
  198628. {
  198629. stop();
  198630. internal->close();
  198631. isOpen_ = false;
  198632. }
  198633. bool isOpen()
  198634. {
  198635. return isOpen_;
  198636. }
  198637. int getCurrentBufferSizeSamples()
  198638. {
  198639. return internal->bufferSize;
  198640. }
  198641. double getCurrentSampleRate()
  198642. {
  198643. return internal->sampleRate;
  198644. }
  198645. int getCurrentBitDepth()
  198646. {
  198647. return internal->getBitDepth();
  198648. }
  198649. const BitArray getActiveOutputChannels() const
  198650. {
  198651. return internal->currentOutputChans;
  198652. }
  198653. const BitArray getActiveInputChannels() const
  198654. {
  198655. return internal->currentInputChans;
  198656. }
  198657. int getOutputLatencyInSamples()
  198658. {
  198659. return 0;
  198660. }
  198661. int getInputLatencyInSamples()
  198662. {
  198663. return 0;
  198664. }
  198665. void start (AudioIODeviceCallback* callback)
  198666. {
  198667. if (! isOpen_)
  198668. callback = 0;
  198669. internal->setCallback (callback);
  198670. if (callback != 0)
  198671. callback->audioDeviceAboutToStart (this);
  198672. isStarted = (callback != 0);
  198673. }
  198674. void stop()
  198675. {
  198676. AudioIODeviceCallback* const oldCallback = internal->callback;
  198677. start (0);
  198678. if (oldCallback != 0)
  198679. oldCallback->audioDeviceStopped();
  198680. }
  198681. bool isPlaying()
  198682. {
  198683. return isStarted && internal->error.isEmpty();
  198684. }
  198685. const String getLastError()
  198686. {
  198687. return internal->error;
  198688. }
  198689. String inputId, outputId;
  198690. private:
  198691. bool isOpen_, isStarted;
  198692. ALSAThread* internal;
  198693. };
  198694. class ALSAAudioIODeviceType : public AudioIODeviceType
  198695. {
  198696. public:
  198697. ALSAAudioIODeviceType()
  198698. : AudioIODeviceType (T("ALSA")),
  198699. hasScanned (false)
  198700. {
  198701. }
  198702. ~ALSAAudioIODeviceType()
  198703. {
  198704. }
  198705. void scanForDevices()
  198706. {
  198707. if (hasScanned)
  198708. return;
  198709. hasScanned = true;
  198710. inputNames.clear();
  198711. inputIds.clear();
  198712. outputNames.clear();
  198713. outputIds.clear();
  198714. snd_ctl_t* handle;
  198715. snd_ctl_card_info_t* info;
  198716. snd_ctl_card_info_alloca (&info);
  198717. int cardNum = -1;
  198718. while (outputIds.size() + inputIds.size() <= 32)
  198719. {
  198720. snd_card_next (&cardNum);
  198721. if (cardNum < 0)
  198722. break;
  198723. if (snd_ctl_open (&handle, T("hw:") + String (cardNum), SND_CTL_NONBLOCK) >= 0)
  198724. {
  198725. if (snd_ctl_card_info (handle, info) >= 0)
  198726. {
  198727. String cardId (snd_ctl_card_info_get_id (info));
  198728. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198729. cardId = String (cardNum);
  198730. int device = -1;
  198731. for (;;)
  198732. {
  198733. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198734. break;
  198735. String id, name;
  198736. id << "hw:" << cardId << ',' << device;
  198737. bool isInput, isOutput;
  198738. if (testDevice (id, isInput, isOutput))
  198739. {
  198740. name << snd_ctl_card_info_get_name (info);
  198741. if (name.isEmpty())
  198742. name = id;
  198743. if (isInput)
  198744. {
  198745. inputNames.add (name);
  198746. inputIds.add (id);
  198747. }
  198748. if (isOutput)
  198749. {
  198750. outputNames.add (name);
  198751. outputIds.add (id);
  198752. }
  198753. }
  198754. }
  198755. }
  198756. snd_ctl_close (handle);
  198757. }
  198758. }
  198759. inputNames.appendNumbersToDuplicates (false, true);
  198760. outputNames.appendNumbersToDuplicates (false, true);
  198761. }
  198762. const StringArray getDeviceNames (const bool wantInputNames) const
  198763. {
  198764. jassert (hasScanned); // need to call scanForDevices() before doing this
  198765. return wantInputNames ? inputNames : outputNames;
  198766. }
  198767. int getDefaultDeviceIndex (const bool forInput) const
  198768. {
  198769. jassert (hasScanned); // need to call scanForDevices() before doing this
  198770. return 0;
  198771. }
  198772. bool hasSeparateInputsAndOutputs() const { return true; }
  198773. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198774. {
  198775. jassert (hasScanned); // need to call scanForDevices() before doing this
  198776. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198777. if (d == 0)
  198778. return -1;
  198779. return asInput ? inputIds.indexOf (d->inputId)
  198780. : outputIds.indexOf (d->outputId);
  198781. }
  198782. AudioIODevice* createDevice (const String& outputDeviceName,
  198783. const String& inputDeviceName)
  198784. {
  198785. jassert (hasScanned); // need to call scanForDevices() before doing this
  198786. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198787. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198788. String deviceName (outputIndex >= 0 ? outputDeviceName
  198789. : inputDeviceName);
  198790. if (inputIndex >= 0 || outputIndex >= 0)
  198791. return new ALSAAudioIODevice (deviceName,
  198792. inputIds [inputIndex],
  198793. outputIds [outputIndex]);
  198794. return 0;
  198795. }
  198796. juce_UseDebuggingNewOperator
  198797. private:
  198798. StringArray inputNames, outputNames, inputIds, outputIds;
  198799. bool hasScanned;
  198800. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198801. {
  198802. unsigned int minChansOut = 0, maxChansOut = 0;
  198803. unsigned int minChansIn = 0, maxChansIn = 0;
  198804. Array <int> rates;
  198805. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198806. DBG (T("ALSA device: ") + id
  198807. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198808. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198809. + T(" rates=") + String (rates.size()));
  198810. isInput = maxChansIn > 0;
  198811. isOutput = maxChansOut > 0;
  198812. return (isInput || isOutput) && rates.size() > 0;
  198813. }
  198814. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198815. const ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198816. };
  198817. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198818. {
  198819. return new ALSAAudioIODeviceType();
  198820. }
  198821. #endif
  198822. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198823. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198824. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198825. // compiled on its own).
  198826. #ifdef JUCE_INCLUDED_FILE
  198827. #if JUCE_JACK
  198828. static void* juce_libjack_handle = 0;
  198829. void* juce_load_jack_function (const char* const name)
  198830. {
  198831. if (juce_libjack_handle == 0)
  198832. return 0;
  198833. return dlsym (juce_libjack_handle, name);
  198834. }
  198835. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198836. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198837. return_type fn_name argument_types { \
  198838. static fn_name##_ptr_t fn = 0; \
  198839. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198840. if (fn) return (*fn)arguments; \
  198841. else return 0; \
  198842. }
  198843. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198844. typedef void (*fn_name##_ptr_t)argument_types; \
  198845. void fn_name argument_types { \
  198846. static fn_name##_ptr_t fn = 0; \
  198847. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198848. if (fn) (*fn)arguments; \
  198849. }
  198850. 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));
  198851. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198852. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198853. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198854. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198855. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198856. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198857. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198858. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198859. 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));
  198860. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198861. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198862. 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));
  198863. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198864. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198865. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198866. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198867. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198868. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198869. #if JUCE_DEBUG
  198870. #define JACK_LOGGING_ENABLED 1
  198871. #endif
  198872. #if JACK_LOGGING_ENABLED
  198873. static void jack_Log (const String& s)
  198874. {
  198875. puts (s);
  198876. }
  198877. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198878. {
  198879. if (status & JackServerFailed || status & JackServerError)
  198880. jack_Log ("Unable to connect to JACK server");
  198881. if (status & JackVersionError)
  198882. jack_Log ("Client's protocol version does not match");
  198883. if (status & JackInvalidOption)
  198884. jack_Log ("The operation contained an invalid or unsupported option");
  198885. if (status & JackNameNotUnique)
  198886. jack_Log ("The desired client name was not unique");
  198887. if (status & JackNoSuchClient)
  198888. jack_Log ("Requested client does not exist");
  198889. if (status & JackInitFailure)
  198890. jack_Log ("Unable to initialize client");
  198891. }
  198892. #else
  198893. #define dumpJackErrorMessage(a) {}
  198894. #define jack_Log(...) {}
  198895. #endif
  198896. #ifndef JUCE_JACK_CLIENT_NAME
  198897. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198898. #endif
  198899. class JackAudioIODevice : public AudioIODevice
  198900. {
  198901. public:
  198902. JackAudioIODevice (const String& deviceName,
  198903. const String& inputId_,
  198904. const String& outputId_)
  198905. : AudioIODevice (deviceName, T("JACK")),
  198906. inputId (inputId_),
  198907. outputId (outputId_),
  198908. isOpen_ (false),
  198909. callback (0),
  198910. totalNumberOfInputChannels (0),
  198911. totalNumberOfOutputChannels (0)
  198912. {
  198913. jassert (deviceName.isNotEmpty());
  198914. jack_status_t status;
  198915. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198916. if (client == 0)
  198917. {
  198918. dumpJackErrorMessage (status);
  198919. }
  198920. else
  198921. {
  198922. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198923. // open input ports
  198924. const StringArray inputChannels (getInputChannelNames());
  198925. for (int i = 0; i < inputChannels.size(); i++)
  198926. {
  198927. String inputName;
  198928. inputName << "in_" << (++totalNumberOfInputChannels);
  198929. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) inputName,
  198930. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198931. }
  198932. // open output ports
  198933. const StringArray outputChannels (getOutputChannelNames());
  198934. for (int i = 0; i < outputChannels.size (); i++)
  198935. {
  198936. String outputName;
  198937. outputName << "out_" << (++totalNumberOfOutputChannels);
  198938. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) outputName,
  198939. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198940. }
  198941. inChans.calloc (totalNumberOfInputChannels + 2);
  198942. outChans.calloc (totalNumberOfOutputChannels + 2);
  198943. }
  198944. }
  198945. ~JackAudioIODevice()
  198946. {
  198947. close();
  198948. if (client != 0)
  198949. {
  198950. JUCE_NAMESPACE::jack_client_close (client);
  198951. client = 0;
  198952. }
  198953. }
  198954. const StringArray getChannelNames (bool forInput) const
  198955. {
  198956. StringArray names;
  198957. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198958. forInput ? JackPortIsInput : JackPortIsOutput);
  198959. if (ports != 0)
  198960. {
  198961. int j = 0;
  198962. while (ports[j] != 0)
  198963. {
  198964. const String portName (ports [j++]);
  198965. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198966. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  198967. }
  198968. free (ports);
  198969. }
  198970. return names;
  198971. }
  198972. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198973. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198974. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198975. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198976. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198977. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198978. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198979. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  198980. double sampleRate, int bufferSizeSamples)
  198981. {
  198982. if (client == 0)
  198983. {
  198984. lastError = T("No JACK client running");
  198985. return lastError;
  198986. }
  198987. lastError = String::empty;
  198988. close();
  198989. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198990. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198991. JUCE_NAMESPACE::jack_activate (client);
  198992. isOpen_ = true;
  198993. if (! inputChannels.isEmpty())
  198994. {
  198995. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198996. if (ports != 0)
  198997. {
  198998. const int numInputChannels = inputChannels.getHighestBit () + 1;
  198999. for (int i = 0; i < numInputChannels; ++i)
  199000. {
  199001. const String portName (ports[i]);
  199002. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199003. {
  199004. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  199005. if (error != 0)
  199006. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199007. }
  199008. }
  199009. free (ports);
  199010. }
  199011. }
  199012. if (! outputChannels.isEmpty())
  199013. {
  199014. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199015. if (ports != 0)
  199016. {
  199017. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  199018. for (int i = 0; i < numOutputChannels; ++i)
  199019. {
  199020. const String portName (ports[i]);
  199021. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199022. {
  199023. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  199024. if (error != 0)
  199025. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199026. }
  199027. }
  199028. free (ports);
  199029. }
  199030. }
  199031. return lastError;
  199032. }
  199033. void close()
  199034. {
  199035. stop();
  199036. if (client != 0)
  199037. {
  199038. JUCE_NAMESPACE::jack_deactivate (client);
  199039. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  199040. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  199041. }
  199042. isOpen_ = false;
  199043. }
  199044. void start (AudioIODeviceCallback* newCallback)
  199045. {
  199046. if (isOpen_ && newCallback != callback)
  199047. {
  199048. if (newCallback != 0)
  199049. newCallback->audioDeviceAboutToStart (this);
  199050. AudioIODeviceCallback* const oldCallback = callback;
  199051. {
  199052. const ScopedLock sl (callbackLock);
  199053. callback = newCallback;
  199054. }
  199055. if (oldCallback != 0)
  199056. oldCallback->audioDeviceStopped();
  199057. }
  199058. }
  199059. void stop()
  199060. {
  199061. start (0);
  199062. }
  199063. bool isOpen() { return isOpen_; }
  199064. bool isPlaying() { return callback != 0; }
  199065. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  199066. double getCurrentSampleRate() { return getSampleRate (0); }
  199067. int getCurrentBitDepth() { return 32; }
  199068. const String getLastError() { return lastError; }
  199069. const BitArray getActiveOutputChannels() const
  199070. {
  199071. BitArray outputBits;
  199072. for (int i = 0; i < outputPorts.size(); i++)
  199073. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  199074. outputBits.setBit (i);
  199075. return outputBits;
  199076. }
  199077. const BitArray getActiveInputChannels() const
  199078. {
  199079. BitArray inputBits;
  199080. for (int i = 0; i < inputPorts.size(); i++)
  199081. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  199082. inputBits.setBit (i);
  199083. return inputBits;
  199084. }
  199085. int getOutputLatencyInSamples()
  199086. {
  199087. int latency = 0;
  199088. for (int i = 0; i < outputPorts.size(); i++)
  199089. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  199090. return latency;
  199091. }
  199092. int getInputLatencyInSamples()
  199093. {
  199094. int latency = 0;
  199095. for (int i = 0; i < inputPorts.size(); i++)
  199096. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  199097. return latency;
  199098. }
  199099. String inputId, outputId;
  199100. private:
  199101. void process (const int numSamples)
  199102. {
  199103. int i, numActiveInChans = 0, numActiveOutChans = 0;
  199104. for (i = 0; i < totalNumberOfInputChannels; ++i)
  199105. {
  199106. jack_default_audio_sample_t* in
  199107. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  199108. if (in != 0)
  199109. inChans [numActiveInChans++] = (float*) in;
  199110. }
  199111. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  199112. {
  199113. jack_default_audio_sample_t* out
  199114. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  199115. if (out != 0)
  199116. outChans [numActiveOutChans++] = (float*) out;
  199117. }
  199118. const ScopedLock sl (callbackLock);
  199119. if (callback != 0)
  199120. {
  199121. callback->audioDeviceIOCallback ((const float**) inChans, numActiveInChans,
  199122. outChans, numActiveOutChans, numSamples);
  199123. }
  199124. else
  199125. {
  199126. for (i = 0; i < numActiveOutChans; ++i)
  199127. zeromem (outChans[i], sizeof (float) * numSamples);
  199128. }
  199129. }
  199130. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199131. {
  199132. if (callbackArgument != 0)
  199133. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199134. return 0;
  199135. }
  199136. static void threadInitCallback (void* callbackArgument)
  199137. {
  199138. jack_Log ("JackAudioIODevice::initialise");
  199139. }
  199140. static void shutdownCallback (void* callbackArgument)
  199141. {
  199142. jack_Log ("JackAudioIODevice::shutdown");
  199143. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199144. if (device != 0)
  199145. {
  199146. device->client = 0;
  199147. device->close();
  199148. }
  199149. }
  199150. static void errorCallback (const char* msg)
  199151. {
  199152. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199153. }
  199154. bool isOpen_;
  199155. jack_client_t* client;
  199156. String lastError;
  199157. AudioIODeviceCallback* callback;
  199158. CriticalSection callbackLock;
  199159. HeapBlock <float*> inChans, outChans;
  199160. int totalNumberOfInputChannels;
  199161. int totalNumberOfOutputChannels;
  199162. VoidArray inputPorts, outputPorts;
  199163. };
  199164. class JackAudioIODeviceType : public AudioIODeviceType
  199165. {
  199166. public:
  199167. JackAudioIODeviceType()
  199168. : AudioIODeviceType (T("JACK")),
  199169. hasScanned (false)
  199170. {
  199171. }
  199172. ~JackAudioIODeviceType()
  199173. {
  199174. }
  199175. void scanForDevices()
  199176. {
  199177. hasScanned = true;
  199178. inputNames.clear();
  199179. inputIds.clear();
  199180. outputNames.clear();
  199181. outputIds.clear();
  199182. if (juce_libjack_handle == 0)
  199183. {
  199184. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199185. if (juce_libjack_handle == 0)
  199186. return;
  199187. }
  199188. // open a dummy client
  199189. jack_status_t status;
  199190. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199191. if (client == 0)
  199192. {
  199193. dumpJackErrorMessage (status);
  199194. }
  199195. else
  199196. {
  199197. // scan for output devices
  199198. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199199. if (ports != 0)
  199200. {
  199201. int j = 0;
  199202. while (ports[j] != 0)
  199203. {
  199204. String clientName (ports[j]);
  199205. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199206. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199207. && ! inputNames.contains (clientName))
  199208. {
  199209. inputNames.add (clientName);
  199210. inputIds.add (ports [j]);
  199211. }
  199212. ++j;
  199213. }
  199214. free (ports);
  199215. }
  199216. // scan for input devices
  199217. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199218. if (ports != 0)
  199219. {
  199220. int j = 0;
  199221. while (ports[j] != 0)
  199222. {
  199223. String clientName (ports[j]);
  199224. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199225. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199226. && ! outputNames.contains (clientName))
  199227. {
  199228. outputNames.add (clientName);
  199229. outputIds.add (ports [j]);
  199230. }
  199231. ++j;
  199232. }
  199233. free (ports);
  199234. }
  199235. JUCE_NAMESPACE::jack_client_close (client);
  199236. }
  199237. }
  199238. const StringArray getDeviceNames (const bool wantInputNames) const
  199239. {
  199240. jassert (hasScanned); // need to call scanForDevices() before doing this
  199241. return wantInputNames ? inputNames : outputNames;
  199242. }
  199243. int getDefaultDeviceIndex (const bool forInput) const
  199244. {
  199245. jassert (hasScanned); // need to call scanForDevices() before doing this
  199246. return 0;
  199247. }
  199248. bool hasSeparateInputsAndOutputs() const { return true; }
  199249. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199250. {
  199251. jassert (hasScanned); // need to call scanForDevices() before doing this
  199252. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199253. if (d == 0)
  199254. return -1;
  199255. return asInput ? inputIds.indexOf (d->inputId)
  199256. : outputIds.indexOf (d->outputId);
  199257. }
  199258. AudioIODevice* createDevice (const String& outputDeviceName,
  199259. const String& inputDeviceName)
  199260. {
  199261. jassert (hasScanned); // need to call scanForDevices() before doing this
  199262. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199263. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199264. if (inputIndex >= 0 || outputIndex >= 0)
  199265. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199266. : inputDeviceName,
  199267. inputIds [inputIndex],
  199268. outputIds [outputIndex]);
  199269. return 0;
  199270. }
  199271. juce_UseDebuggingNewOperator
  199272. private:
  199273. StringArray inputNames, outputNames, inputIds, outputIds;
  199274. bool hasScanned;
  199275. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199276. const JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199277. };
  199278. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199279. {
  199280. return new JackAudioIODeviceType();
  199281. }
  199282. #else // if JACK is turned off..
  199283. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199284. #endif
  199285. #endif
  199286. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199287. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199288. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199289. // compiled on its own).
  199290. #if JUCE_INCLUDED_FILE
  199291. #if JUCE_ALSA
  199292. static snd_seq_t* iterateDevices (const bool forInput,
  199293. StringArray& deviceNamesFound,
  199294. const int deviceIndexToOpen)
  199295. {
  199296. snd_seq_t* returnedHandle = 0;
  199297. snd_seq_t* seqHandle;
  199298. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199299. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199300. {
  199301. snd_seq_system_info_t* systemInfo;
  199302. snd_seq_client_info_t* clientInfo;
  199303. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199304. {
  199305. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199306. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199307. {
  199308. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199309. while (--numClients >= 0 && returnedHandle == 0)
  199310. {
  199311. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199312. {
  199313. snd_seq_port_info_t* portInfo;
  199314. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199315. {
  199316. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199317. const int client = snd_seq_client_info_get_client (clientInfo);
  199318. snd_seq_port_info_set_client (portInfo, client);
  199319. snd_seq_port_info_set_port (portInfo, -1);
  199320. while (--numPorts >= 0)
  199321. {
  199322. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199323. && (snd_seq_port_info_get_capability (portInfo)
  199324. & (forInput ? SND_SEQ_PORT_CAP_READ
  199325. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199326. {
  199327. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199328. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199329. {
  199330. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199331. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199332. if (sourcePort != -1)
  199333. {
  199334. snd_seq_set_client_name (seqHandle,
  199335. forInput ? "Juce Midi Input"
  199336. : "Juce Midi Output");
  199337. const int portId
  199338. = snd_seq_create_simple_port (seqHandle,
  199339. forInput ? "Juce Midi In Port"
  199340. : "Juce Midi Out Port",
  199341. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199342. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199343. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199344. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199345. returnedHandle = seqHandle;
  199346. }
  199347. }
  199348. }
  199349. }
  199350. snd_seq_port_info_free (portInfo);
  199351. }
  199352. }
  199353. }
  199354. snd_seq_client_info_free (clientInfo);
  199355. }
  199356. snd_seq_system_info_free (systemInfo);
  199357. }
  199358. if (returnedHandle == 0)
  199359. snd_seq_close (seqHandle);
  199360. }
  199361. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199362. return returnedHandle;
  199363. }
  199364. static snd_seq_t* createDevice (const bool forInput,
  199365. const String& deviceNameToOpen)
  199366. {
  199367. snd_seq_t* seqHandle = 0;
  199368. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199369. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199370. {
  199371. snd_seq_set_client_name (seqHandle,
  199372. (const char*) (forInput ? (deviceNameToOpen + T(" Input"))
  199373. : (deviceNameToOpen + T(" Output"))));
  199374. const int portId
  199375. = snd_seq_create_simple_port (seqHandle,
  199376. forInput ? "in"
  199377. : "out",
  199378. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199379. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199380. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199381. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199382. if (portId < 0)
  199383. {
  199384. snd_seq_close (seqHandle);
  199385. seqHandle = 0;
  199386. }
  199387. }
  199388. return seqHandle;
  199389. }
  199390. class MidiOutputDevice
  199391. {
  199392. public:
  199393. MidiOutputDevice (MidiOutput* const midiOutput_,
  199394. snd_seq_t* const seqHandle_)
  199395. :
  199396. midiOutput (midiOutput_),
  199397. seqHandle (seqHandle_),
  199398. maxEventSize (16 * 1024)
  199399. {
  199400. jassert (seqHandle != 0 && midiOutput != 0);
  199401. snd_midi_event_new (maxEventSize, &midiParser);
  199402. }
  199403. ~MidiOutputDevice()
  199404. {
  199405. snd_midi_event_free (midiParser);
  199406. snd_seq_close (seqHandle);
  199407. }
  199408. void sendMessageNow (const MidiMessage& message)
  199409. {
  199410. if (message.getRawDataSize() > maxEventSize)
  199411. {
  199412. maxEventSize = message.getRawDataSize();
  199413. snd_midi_event_free (midiParser);
  199414. snd_midi_event_new (maxEventSize, &midiParser);
  199415. }
  199416. snd_seq_event_t event;
  199417. snd_seq_ev_clear (&event);
  199418. snd_midi_event_encode (midiParser,
  199419. message.getRawData(),
  199420. message.getRawDataSize(),
  199421. &event);
  199422. snd_midi_event_reset_encode (midiParser);
  199423. snd_seq_ev_set_source (&event, 0);
  199424. snd_seq_ev_set_subs (&event);
  199425. snd_seq_ev_set_direct (&event);
  199426. snd_seq_event_output (seqHandle, &event);
  199427. snd_seq_drain_output (seqHandle);
  199428. }
  199429. juce_UseDebuggingNewOperator
  199430. private:
  199431. MidiOutput* const midiOutput;
  199432. snd_seq_t* const seqHandle;
  199433. snd_midi_event_t* midiParser;
  199434. int maxEventSize;
  199435. };
  199436. const StringArray MidiOutput::getDevices()
  199437. {
  199438. StringArray devices;
  199439. iterateDevices (false, devices, -1);
  199440. return devices;
  199441. }
  199442. int MidiOutput::getDefaultDeviceIndex()
  199443. {
  199444. return 0;
  199445. }
  199446. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199447. {
  199448. MidiOutput* newDevice = 0;
  199449. StringArray devices;
  199450. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199451. if (handle != 0)
  199452. {
  199453. newDevice = new MidiOutput();
  199454. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199455. }
  199456. return newDevice;
  199457. }
  199458. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199459. {
  199460. MidiOutput* newDevice = 0;
  199461. snd_seq_t* const handle = createDevice (false, deviceName);
  199462. if (handle != 0)
  199463. {
  199464. newDevice = new MidiOutput();
  199465. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199466. }
  199467. return newDevice;
  199468. }
  199469. MidiOutput::~MidiOutput()
  199470. {
  199471. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199472. delete device;
  199473. }
  199474. void MidiOutput::reset()
  199475. {
  199476. }
  199477. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199478. {
  199479. return false;
  199480. }
  199481. void MidiOutput::setVolume (float leftVol, float rightVol)
  199482. {
  199483. }
  199484. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199485. {
  199486. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199487. }
  199488. class MidiInputThread : public Thread
  199489. {
  199490. public:
  199491. MidiInputThread (MidiInput* const midiInput_,
  199492. snd_seq_t* const seqHandle_,
  199493. MidiInputCallback* const callback_)
  199494. : Thread (T("Juce MIDI Input")),
  199495. midiInput (midiInput_),
  199496. seqHandle (seqHandle_),
  199497. callback (callback_)
  199498. {
  199499. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199500. }
  199501. ~MidiInputThread()
  199502. {
  199503. snd_seq_close (seqHandle);
  199504. }
  199505. void run()
  199506. {
  199507. const int maxEventSize = 16 * 1024;
  199508. snd_midi_event_t* midiParser;
  199509. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199510. {
  199511. HeapBlock <uint8> buffer (maxEventSize);
  199512. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199513. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199514. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199515. while (! threadShouldExit())
  199516. {
  199517. if (poll (pfd, numPfds, 500) > 0)
  199518. {
  199519. snd_seq_event_t* inputEvent = 0;
  199520. snd_seq_nonblock (seqHandle, 1);
  199521. do
  199522. {
  199523. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199524. {
  199525. // xxx what about SYSEXes that are too big for the buffer?
  199526. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199527. snd_midi_event_reset_decode (midiParser);
  199528. if (numBytes > 0)
  199529. {
  199530. const MidiMessage message ((const uint8*) buffer,
  199531. numBytes,
  199532. Time::getMillisecondCounter() * 0.001);
  199533. callback->handleIncomingMidiMessage (midiInput, message);
  199534. }
  199535. snd_seq_free_event (inputEvent);
  199536. }
  199537. }
  199538. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199539. snd_seq_free_event (inputEvent);
  199540. }
  199541. }
  199542. snd_midi_event_free (midiParser);
  199543. }
  199544. };
  199545. juce_UseDebuggingNewOperator
  199546. private:
  199547. MidiInput* const midiInput;
  199548. snd_seq_t* const seqHandle;
  199549. MidiInputCallback* const callback;
  199550. };
  199551. MidiInput::MidiInput (const String& name_)
  199552. : name (name_),
  199553. internal (0)
  199554. {
  199555. }
  199556. MidiInput::~MidiInput()
  199557. {
  199558. stop();
  199559. MidiInputThread* const thread = (MidiInputThread*) internal;
  199560. delete thread;
  199561. }
  199562. void MidiInput::start()
  199563. {
  199564. ((MidiInputThread*) internal)->startThread();
  199565. }
  199566. void MidiInput::stop()
  199567. {
  199568. ((MidiInputThread*) internal)->stopThread (3000);
  199569. }
  199570. int MidiInput::getDefaultDeviceIndex()
  199571. {
  199572. return 0;
  199573. }
  199574. const StringArray MidiInput::getDevices()
  199575. {
  199576. StringArray devices;
  199577. iterateDevices (true, devices, -1);
  199578. return devices;
  199579. }
  199580. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199581. {
  199582. MidiInput* newDevice = 0;
  199583. StringArray devices;
  199584. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199585. if (handle != 0)
  199586. {
  199587. newDevice = new MidiInput (devices [deviceIndex]);
  199588. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199589. }
  199590. return newDevice;
  199591. }
  199592. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199593. {
  199594. MidiInput* newDevice = 0;
  199595. snd_seq_t* const handle = createDevice (true, deviceName);
  199596. if (handle != 0)
  199597. {
  199598. newDevice = new MidiInput (deviceName);
  199599. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199600. }
  199601. return newDevice;
  199602. }
  199603. #else
  199604. // (These are just stub functions if ALSA is unavailable...)
  199605. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199606. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199607. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199608. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199609. MidiOutput::~MidiOutput() {}
  199610. void MidiOutput::reset() {}
  199611. bool MidiOutput::getVolume (float&, float&) { return false; }
  199612. void MidiOutput::setVolume (float, float) {}
  199613. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199614. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199615. MidiInput::~MidiInput() {}
  199616. void MidiInput::start() {}
  199617. void MidiInput::stop() {}
  199618. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199619. const StringArray MidiInput::getDevices() { return StringArray(); }
  199620. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199621. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199622. #endif
  199623. #endif
  199624. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199625. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199626. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199627. // compiled on its own).
  199628. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199629. AudioCDReader::AudioCDReader()
  199630. : AudioFormatReader (0, T("CD Audio"))
  199631. {
  199632. }
  199633. const StringArray AudioCDReader::getAvailableCDNames()
  199634. {
  199635. StringArray names;
  199636. return names;
  199637. }
  199638. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199639. {
  199640. return 0;
  199641. }
  199642. AudioCDReader::~AudioCDReader()
  199643. {
  199644. }
  199645. void AudioCDReader::refreshTrackLengths()
  199646. {
  199647. }
  199648. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199649. int64 startSampleInFile, int numSamples)
  199650. {
  199651. return false;
  199652. }
  199653. bool AudioCDReader::isCDStillPresent() const
  199654. {
  199655. return false;
  199656. }
  199657. int AudioCDReader::getNumTracks() const
  199658. {
  199659. return 0;
  199660. }
  199661. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199662. {
  199663. return 0;
  199664. }
  199665. bool AudioCDReader::isTrackAudio (int trackNum) const
  199666. {
  199667. return false;
  199668. }
  199669. void AudioCDReader::enableIndexScanning (bool b)
  199670. {
  199671. }
  199672. int AudioCDReader::getLastIndex() const
  199673. {
  199674. return 0;
  199675. }
  199676. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199677. {
  199678. return Array<int>();
  199679. }
  199680. int AudioCDReader::getCDDBId()
  199681. {
  199682. return 0;
  199683. }
  199684. #endif
  199685. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199686. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199687. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199688. // compiled on its own).
  199689. #if JUCE_INCLUDED_FILE
  199690. void FileChooser::showPlatformDialog (Array<File>& results,
  199691. const String& title,
  199692. const File& file,
  199693. const String& filters,
  199694. bool isDirectory,
  199695. bool selectsFiles,
  199696. bool isSave,
  199697. bool warnAboutOverwritingExistingFiles,
  199698. bool selectMultipleFiles,
  199699. FilePreviewComponent* previewComponent)
  199700. {
  199701. const tchar* const separator = T(":");
  199702. String command ("zenity --file-selection");
  199703. if (title.isNotEmpty())
  199704. command << " --title=\"" << title << "\"";
  199705. if (file != File::nonexistent)
  199706. command << " --filename=\"" << file.getFullPathName () << "\"";
  199707. if (isDirectory)
  199708. command << " --directory";
  199709. if (isSave)
  199710. command << " --save";
  199711. if (selectMultipleFiles)
  199712. command << " --multiple --separator=\"" << separator << "\"";
  199713. command << " 2>&1";
  199714. MemoryOutputStream result;
  199715. int status = -1;
  199716. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  199717. if (stream != 0)
  199718. {
  199719. for (;;)
  199720. {
  199721. char buffer [1024];
  199722. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199723. if (bytesRead <= 0)
  199724. break;
  199725. result.write (buffer, bytesRead);
  199726. }
  199727. status = pclose (stream);
  199728. }
  199729. if (status == 0)
  199730. {
  199731. String resultString (String::fromUTF8 ((const uint8*) result.getData(), result.getDataSize()));
  199732. StringArray tokens;
  199733. if (selectMultipleFiles)
  199734. tokens.addTokens (resultString, separator, 0);
  199735. else
  199736. tokens.add (resultString);
  199737. for (int i = 0; i < tokens.size(); i++)
  199738. results.add (File (tokens[i]));
  199739. return;
  199740. }
  199741. //xxx ain't got one!
  199742. jassertfalse
  199743. }
  199744. #endif
  199745. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199746. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199747. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199748. // compiled on its own).
  199749. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199750. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199751. : browser (0),
  199752. blankPageShown (false),
  199753. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199754. {
  199755. setOpaque (true);
  199756. }
  199757. WebBrowserComponent::~WebBrowserComponent()
  199758. {
  199759. }
  199760. void WebBrowserComponent::goToURL (const String& url,
  199761. const StringArray* headers,
  199762. const MemoryBlock* postData)
  199763. {
  199764. lastURL = url;
  199765. lastHeaders.clear();
  199766. if (headers != 0)
  199767. lastHeaders = *headers;
  199768. lastPostData.setSize (0);
  199769. if (postData != 0)
  199770. lastPostData = *postData;
  199771. blankPageShown = false;
  199772. }
  199773. void WebBrowserComponent::stop()
  199774. {
  199775. }
  199776. void WebBrowserComponent::goBack()
  199777. {
  199778. lastURL = String::empty;
  199779. blankPageShown = false;
  199780. }
  199781. void WebBrowserComponent::goForward()
  199782. {
  199783. lastURL = String::empty;
  199784. }
  199785. void WebBrowserComponent::refresh()
  199786. {
  199787. }
  199788. void WebBrowserComponent::paint (Graphics& g)
  199789. {
  199790. g.fillAll (Colours::white);
  199791. }
  199792. void WebBrowserComponent::checkWindowAssociation()
  199793. {
  199794. }
  199795. void WebBrowserComponent::reloadLastURL()
  199796. {
  199797. if (lastURL.isNotEmpty())
  199798. {
  199799. goToURL (lastURL, &lastHeaders, &lastPostData);
  199800. lastURL = String::empty;
  199801. }
  199802. }
  199803. void WebBrowserComponent::parentHierarchyChanged()
  199804. {
  199805. checkWindowAssociation();
  199806. }
  199807. void WebBrowserComponent::resized()
  199808. {
  199809. }
  199810. void WebBrowserComponent::visibilityChanged()
  199811. {
  199812. checkWindowAssociation();
  199813. }
  199814. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199815. {
  199816. return true;
  199817. }
  199818. #endif
  199819. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199820. #endif
  199821. END_JUCE_NAMESPACE
  199822. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199823. #endif
  199824. #if JUCE_MAC || JUCE_IPHONE
  199825. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199826. BEGIN_JUCE_NAMESPACE
  199827. #undef Point
  199828. #define JUCE_INCLUDED_FILE 1
  199829. // Now include the actual code files..
  199830. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199831. #ifndef JUCE_ObjCExtraSuffix
  199832. #define JUCE_ObjCExtraSuffix 3
  199833. #endif
  199834. #define appendMacro1(a, b, c, d) a ## _ ## b ## _ ## c ## _ ## d
  199835. #define appendMacro2(a, b, c, d) appendMacro1(a, b, c, d)
  199836. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_ObjCExtraSuffix)
  199837. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199838. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199839. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199840. // compiled on its own).
  199841. #if JUCE_INCLUDED_FILE
  199842. static const String nsStringToJuce (NSString* s)
  199843. {
  199844. return String::fromUTF8 ((uint8*) [s UTF8String]);
  199845. }
  199846. static NSString* juceStringToNS (const String& s)
  199847. {
  199848. return [NSString stringWithUTF8String: (const char*) s.toUTF8()];
  199849. }
  199850. static const String convertUTF16ToString (const UniChar* utf16)
  199851. {
  199852. String s;
  199853. while (*utf16 != 0)
  199854. s += (juce_wchar) *utf16++;
  199855. return s;
  199856. }
  199857. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199858. {
  199859. String result;
  199860. if (cfString != 0)
  199861. {
  199862. #if JUCE_STRINGS_ARE_UNICODE
  199863. CFRange range = { 0, CFStringGetLength (cfString) };
  199864. HeapBlock <UniChar> u (range.length + 1);
  199865. CFStringGetCharacters (cfString, range, u);
  199866. u[range.length] = 0;
  199867. result = convertUTF16ToString (u);
  199868. #else
  199869. const int len = CFStringGetLength (cfString);
  199870. HeapBlock <char> buffer (len + 1);
  199871. CFStringGetCString (cfString, buffer, len + 1, CFStringGetSystemEncoding());
  199872. result = buffer;
  199873. #endif
  199874. }
  199875. return result;
  199876. }
  199877. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199878. {
  199879. #if JUCE_STRINGS_ARE_UNICODE
  199880. const int len = s.length();
  199881. const juce_wchar* t = (const juce_wchar*) s;
  199882. HeapBlock <UniChar> temp (len + 2);
  199883. for (int i = 0; i <= len; ++i)
  199884. temp[i] = t[i];
  199885. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199886. #else
  199887. return CFStringCreateWithCString (kCFAllocatorDefault,
  199888. (const char*) s,
  199889. CFStringGetSystemEncoding());
  199890. #endif
  199891. }
  199892. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199893. {
  199894. #if JUCE_IPHONE
  199895. const ScopedAutoReleasePool pool;
  199896. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199897. #else
  199898. UnicodeMapping map;
  199899. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199900. kUnicodeNoSubset,
  199901. kTextEncodingDefaultFormat);
  199902. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199903. kUnicodeCanonicalCompVariant,
  199904. kTextEncodingDefaultFormat);
  199905. map.mappingVersion = kUnicodeUseLatestMapping;
  199906. UnicodeToTextInfo conversionInfo = 0;
  199907. String result;
  199908. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199909. {
  199910. const int len = s.length();
  199911. HeapBlock <UniChar> tempIn, tempOut;
  199912. tempIn.calloc (len + 2);
  199913. tempOut.calloc (len + 2);
  199914. for (int i = 0; i <= len; ++i)
  199915. tempIn[i] = s[i];
  199916. ByteCount bytesRead = 0;
  199917. ByteCount outputBufferSize = 0;
  199918. if (ConvertFromUnicodeToText (conversionInfo,
  199919. len * sizeof (UniChar), tempIn,
  199920. kUnicodeDefaultDirectionMask,
  199921. 0, 0, 0, 0,
  199922. len * sizeof (UniChar), &bytesRead,
  199923. &outputBufferSize, tempOut) == noErr)
  199924. {
  199925. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199926. tchar* t = const_cast <tchar*> ((const tchar*) result);
  199927. unsigned int i;
  199928. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199929. t[i] = (tchar) tempOut[i];
  199930. t[i] = 0;
  199931. }
  199932. DisposeUnicodeToTextInfo (&conversionInfo);
  199933. }
  199934. return result;
  199935. #endif
  199936. }
  199937. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199938. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  199939. {
  199940. #if JUCE_IPHONE
  199941. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199942. forPasteboardType: @"public.text"];
  199943. #else
  199944. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199945. owner: nil];
  199946. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199947. forType: NSStringPboardType];
  199948. #endif
  199949. }
  199950. const String SystemClipboard::getTextFromClipboard() throw()
  199951. {
  199952. #if JUCE_IPHONE
  199953. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199954. #else
  199955. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199956. #endif
  199957. return text == 0 ? String::empty
  199958. : nsStringToJuce (text);
  199959. }
  199960. #endif
  199961. #endif
  199962. /*** End of inlined file: juce_mac_Strings.mm ***/
  199963. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199964. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199965. // compiled on its own).
  199966. #if JUCE_INCLUDED_FILE
  199967. static int64 highResTimerFrequency = 0;
  199968. static double highResTimerToMillisecRatio = 0;
  199969. #if JUCE_INTEL
  199970. static void juce_getCpuVendor (char* const v) throw()
  199971. {
  199972. int vendor[4];
  199973. zerostruct (vendor);
  199974. int dummy = 0;
  199975. asm ("mov %%ebx, %%esi \n\t"
  199976. "cpuid \n\t"
  199977. "xchg %%esi, %%ebx"
  199978. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199979. memcpy (v, vendor, 16);
  199980. }
  199981. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199982. {
  199983. unsigned int cpu = 0;
  199984. unsigned int ext = 0;
  199985. unsigned int family = 0;
  199986. unsigned int dummy = 0;
  199987. asm ("mov %%ebx, %%esi \n\t"
  199988. "cpuid \n\t"
  199989. "xchg %%esi, %%ebx"
  199990. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199991. familyModel = family;
  199992. extFeatures = ext;
  199993. return cpu;
  199994. }
  199995. struct CPUFlags
  199996. {
  199997. bool hasMMX : 1;
  199998. bool hasSSE : 1;
  199999. bool hasSSE2 : 1;
  200000. bool has3DNow : 1;
  200001. };
  200002. static CPUFlags cpuFlags;
  200003. #endif
  200004. void SystemStats::initialiseStats() throw()
  200005. {
  200006. static bool initialised = false;
  200007. if (! initialised)
  200008. {
  200009. initialised = true;
  200010. #if JUCE_MAC
  200011. // extremely annoying: adding this line stops the apple menu items from working. Of
  200012. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  200013. // any events.
  200014. //NSApplicationLoad();
  200015. [NSApplication sharedApplication];
  200016. #endif
  200017. #if JUCE_INTEL
  200018. {
  200019. unsigned int familyModel, extFeatures;
  200020. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  200021. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  200022. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  200023. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  200024. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  200025. }
  200026. #endif
  200027. mach_timebase_info_data_t timebase;
  200028. (void) mach_timebase_info (&timebase);
  200029. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  200030. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  200031. String s (SystemStats::getJUCEVersion());
  200032. rlimit lim;
  200033. getrlimit (RLIMIT_NOFILE, &lim);
  200034. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  200035. setrlimit (RLIMIT_NOFILE, &lim);
  200036. }
  200037. }
  200038. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  200039. {
  200040. return MacOSX;
  200041. }
  200042. const String SystemStats::getOperatingSystemName() throw()
  200043. {
  200044. return T("Mac OS X");
  200045. }
  200046. bool SystemStats::isOperatingSystem64Bit() throw()
  200047. {
  200048. #if JUCE_64BIT
  200049. return true;
  200050. #else
  200051. //xxx not sure how to find this out?..
  200052. return false;
  200053. #endif
  200054. }
  200055. int SystemStats::getMemorySizeInMegabytes() throw()
  200056. {
  200057. uint64 mem = 0;
  200058. size_t memSize = sizeof (mem);
  200059. int mib[] = { CTL_HW, HW_MEMSIZE };
  200060. sysctl (mib, 2, &mem, &memSize, 0, 0);
  200061. return (int) (mem / (1024 * 1024));
  200062. }
  200063. bool SystemStats::hasMMX() throw()
  200064. {
  200065. #if JUCE_INTEL
  200066. return cpuFlags.hasMMX;
  200067. #else
  200068. return false;
  200069. #endif
  200070. }
  200071. bool SystemStats::hasSSE() throw()
  200072. {
  200073. #if JUCE_INTEL
  200074. return cpuFlags.hasSSE;
  200075. #else
  200076. return false;
  200077. #endif
  200078. }
  200079. bool SystemStats::hasSSE2() throw()
  200080. {
  200081. #if JUCE_INTEL
  200082. return cpuFlags.hasSSE2;
  200083. #else
  200084. return false;
  200085. #endif
  200086. }
  200087. bool SystemStats::has3DNow() throw()
  200088. {
  200089. #if JUCE_INTEL
  200090. return cpuFlags.has3DNow;
  200091. #else
  200092. return false;
  200093. #endif
  200094. }
  200095. const String SystemStats::getCpuVendor() throw()
  200096. {
  200097. #if JUCE_INTEL
  200098. char v [16];
  200099. juce_getCpuVendor (v);
  200100. return String (v, 16);
  200101. #else
  200102. return String::empty;
  200103. #endif
  200104. }
  200105. int SystemStats::getCpuSpeedInMegaherz() throw()
  200106. {
  200107. uint64 speedHz = 0;
  200108. size_t speedSize = sizeof (speedHz);
  200109. int mib[] = { CTL_HW, HW_CPU_FREQ };
  200110. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  200111. #if JUCE_BIG_ENDIAN
  200112. if (speedSize == 4)
  200113. speedHz >>= 32;
  200114. #endif
  200115. return (int) (speedHz / 1000000);
  200116. }
  200117. int SystemStats::getNumCpus() throw()
  200118. {
  200119. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  200120. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  200121. #else
  200122. return MPProcessors();
  200123. #endif
  200124. }
  200125. const String SystemStats::getLogonName()
  200126. {
  200127. return nsStringToJuce (NSUserName());
  200128. }
  200129. const String SystemStats::getFullUserName()
  200130. {
  200131. return nsStringToJuce (NSFullUserName());
  200132. }
  200133. uint32 juce_millisecondsSinceStartup() throw()
  200134. {
  200135. return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);
  200136. }
  200137. double Time::getMillisecondCounterHiRes() throw()
  200138. {
  200139. return mach_absolute_time() * highResTimerToMillisecRatio;
  200140. }
  200141. int64 Time::getHighResolutionTicks() throw()
  200142. {
  200143. return (int64) mach_absolute_time();
  200144. }
  200145. int64 Time::getHighResolutionTicksPerSecond() throw()
  200146. {
  200147. return highResTimerFrequency;
  200148. }
  200149. int64 SystemStats::getClockCycleCounter() throw()
  200150. {
  200151. return (int64) mach_absolute_time();
  200152. }
  200153. bool Time::setSystemTimeToThisTime() const throw()
  200154. {
  200155. jassertfalse
  200156. return false;
  200157. }
  200158. int SystemStats::getPageSize() throw()
  200159. {
  200160. return (int) NSPageSize();
  200161. }
  200162. void PlatformUtilities::fpuReset()
  200163. {
  200164. }
  200165. #endif
  200166. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  200167. /*** Start of inlined file: juce_mac_Network.mm ***/
  200168. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200169. // compiled on its own).
  200170. #if JUCE_INCLUDED_FILE
  200171. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  200172. {
  200173. #ifndef IFT_ETHER
  200174. #define IFT_ETHER 6
  200175. #endif
  200176. ifaddrs* addrs = 0;
  200177. int numResults = 0;
  200178. if (getifaddrs (&addrs) == 0)
  200179. {
  200180. const ifaddrs* cursor = addrs;
  200181. while (cursor != 0 && numResults < maxNum)
  200182. {
  200183. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  200184. if (sto->ss_family == AF_LINK)
  200185. {
  200186. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200187. if (sadd->sdl_type == IFT_ETHER)
  200188. {
  200189. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200190. uint64 a = 0;
  200191. for (int i = 6; --i >= 0;)
  200192. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200193. *addresses++ = (int64) a;
  200194. ++numResults;
  200195. }
  200196. }
  200197. cursor = cursor->ifa_next;
  200198. }
  200199. freeifaddrs (addrs);
  200200. }
  200201. return numResults;
  200202. }
  200203. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200204. const String& emailSubject,
  200205. const String& bodyText,
  200206. const StringArray& filesToAttach)
  200207. {
  200208. #if JUCE_IPHONE
  200209. //xxx probably need to use MFMailComposeViewController
  200210. jassertfalse
  200211. return false;
  200212. #else
  200213. const ScopedAutoReleasePool pool;
  200214. String script;
  200215. script << "tell application \"Mail\"\r\n"
  200216. "set newMessage to make new outgoing message with properties {subject:\""
  200217. << emailSubject.replace (T("\""), T("\\\""))
  200218. << "\", content:\""
  200219. << bodyText.replace (T("\""), T("\\\""))
  200220. << "\" & return & return}\r\n"
  200221. "tell newMessage\r\n"
  200222. "set visible to true\r\n"
  200223. "set sender to \"sdfsdfsdfewf\"\r\n"
  200224. "make new to recipient at end of to recipients with properties {address:\""
  200225. << targetEmailAddress
  200226. << "\"}\r\n";
  200227. for (int i = 0; i < filesToAttach.size(); ++i)
  200228. {
  200229. script << "tell content\r\n"
  200230. "make new attachment with properties {file name:\""
  200231. << filesToAttach[i].replace (T("\""), T("\\\""))
  200232. << "\"} at after the last paragraph\r\n"
  200233. "end tell\r\n";
  200234. }
  200235. script << "end tell\r\n"
  200236. "end tell\r\n";
  200237. NSAppleScript* s = [[NSAppleScript alloc]
  200238. initWithSource: juceStringToNS (script)];
  200239. NSDictionary* error = 0;
  200240. const bool ok = [s executeAndReturnError: &error] != nil;
  200241. [s release];
  200242. return ok;
  200243. #endif
  200244. }
  200245. END_JUCE_NAMESPACE
  200246. using namespace JUCE_NAMESPACE;
  200247. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200248. @interface JuceURLConnection : NSObject
  200249. {
  200250. @public
  200251. NSURLRequest* request;
  200252. NSURLConnection* connection;
  200253. NSMutableData* data;
  200254. Thread* runLoopThread;
  200255. bool initialised, hasFailed, hasFinished;
  200256. int position;
  200257. int64 contentLength;
  200258. NSLock* dataLock;
  200259. }
  200260. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200261. - (void) dealloc;
  200262. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200263. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200264. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200265. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200266. - (BOOL) isOpen;
  200267. - (int) read: (char*) dest numBytes: (int) num;
  200268. - (int) readPosition;
  200269. - (void) stop;
  200270. - (void) createConnection;
  200271. @end
  200272. class JuceURLConnectionMessageThread : public Thread
  200273. {
  200274. JuceURLConnection* owner;
  200275. public:
  200276. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200277. : Thread (T("http connection")),
  200278. owner (owner_)
  200279. {
  200280. }
  200281. ~JuceURLConnectionMessageThread()
  200282. {
  200283. stopThread (10000);
  200284. }
  200285. void run()
  200286. {
  200287. [owner createConnection];
  200288. while (! threadShouldExit())
  200289. {
  200290. const ScopedAutoReleasePool pool;
  200291. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200292. }
  200293. }
  200294. };
  200295. @implementation JuceURLConnection
  200296. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200297. withCallback: (URL::OpenStreamProgressCallback*) callback
  200298. withContext: (void*) context;
  200299. {
  200300. [super init];
  200301. request = req;
  200302. [request retain];
  200303. data = [[NSMutableData data] retain];
  200304. dataLock = [[NSLock alloc] init];
  200305. connection = 0;
  200306. initialised = false;
  200307. hasFailed = false;
  200308. hasFinished = false;
  200309. contentLength = -1;
  200310. runLoopThread = new JuceURLConnectionMessageThread (self);
  200311. runLoopThread->startThread();
  200312. while (runLoopThread->isThreadRunning() && ! initialised)
  200313. {
  200314. if (callback != 0)
  200315. callback (context, -1, (int) [[request HTTPBody] length]);
  200316. Thread::sleep (1);
  200317. }
  200318. return self;
  200319. }
  200320. - (void) dealloc
  200321. {
  200322. [self stop];
  200323. delete runLoopThread;
  200324. [connection release];
  200325. [data release];
  200326. [dataLock release];
  200327. [request release];
  200328. [super dealloc];
  200329. }
  200330. - (void) createConnection
  200331. {
  200332. connection = [[NSURLConnection alloc] initWithRequest: request
  200333. delegate: [self retain]];
  200334. if (connection == nil)
  200335. runLoopThread->signalThreadShouldExit();
  200336. }
  200337. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200338. {
  200339. [dataLock lock];
  200340. [data setLength: 0];
  200341. [dataLock unlock];
  200342. initialised = true;
  200343. contentLength = [response expectedContentLength];
  200344. }
  200345. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200346. {
  200347. DBG (nsStringToJuce ([error description]));
  200348. hasFailed = true;
  200349. initialised = true;
  200350. runLoopThread->signalThreadShouldExit();
  200351. }
  200352. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200353. {
  200354. [dataLock lock];
  200355. [data appendData: newData];
  200356. [dataLock unlock];
  200357. initialised = true;
  200358. }
  200359. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200360. {
  200361. hasFinished = true;
  200362. initialised = true;
  200363. runLoopThread->signalThreadShouldExit();
  200364. }
  200365. - (BOOL) isOpen
  200366. {
  200367. return connection != 0 && ! hasFailed;
  200368. }
  200369. - (int) readPosition
  200370. {
  200371. return position;
  200372. }
  200373. - (int) read: (char*) dest numBytes: (int) numNeeded
  200374. {
  200375. int numDone = 0;
  200376. while (numNeeded > 0)
  200377. {
  200378. int available = jmin (numNeeded, (int) [data length]);
  200379. if (available > 0)
  200380. {
  200381. [dataLock lock];
  200382. [data getBytes: dest length: available];
  200383. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200384. [dataLock unlock];
  200385. numDone += available;
  200386. numNeeded -= available;
  200387. dest += available;
  200388. }
  200389. else
  200390. {
  200391. if (hasFailed || hasFinished)
  200392. break;
  200393. Thread::sleep (1);
  200394. }
  200395. }
  200396. position += numDone;
  200397. return numDone;
  200398. }
  200399. - (void) stop
  200400. {
  200401. [connection cancel];
  200402. runLoopThread->stopThread (10000);
  200403. }
  200404. @end
  200405. BEGIN_JUCE_NAMESPACE
  200406. bool juce_isOnLine()
  200407. {
  200408. return true;
  200409. }
  200410. void* juce_openInternetFile (const String& url,
  200411. const String& headers,
  200412. const MemoryBlock& postData,
  200413. const bool isPost,
  200414. URL::OpenStreamProgressCallback* callback,
  200415. void* callbackContext,
  200416. int timeOutMs)
  200417. {
  200418. const ScopedAutoReleasePool pool;
  200419. NSMutableURLRequest* req = [NSMutableURLRequest
  200420. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200421. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200422. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200423. if (req == nil)
  200424. return 0;
  200425. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200426. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200427. StringArray headerLines;
  200428. headerLines.addLines (headers);
  200429. headerLines.removeEmptyStrings (true);
  200430. for (int i = 0; i < headerLines.size(); ++i)
  200431. {
  200432. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200433. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200434. if (key.isNotEmpty() && value.isNotEmpty())
  200435. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200436. }
  200437. if (isPost && postData.getSize() > 0)
  200438. {
  200439. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200440. length: postData.getSize()]];
  200441. }
  200442. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200443. withCallback: callback
  200444. withContext: callbackContext];
  200445. if ([s isOpen])
  200446. return s;
  200447. [s release];
  200448. return 0;
  200449. }
  200450. void juce_closeInternetFile (void* handle)
  200451. {
  200452. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200453. if (s != 0)
  200454. {
  200455. const ScopedAutoReleasePool pool;
  200456. [s stop];
  200457. [s release];
  200458. }
  200459. }
  200460. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200461. {
  200462. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200463. if (s != 0)
  200464. {
  200465. const ScopedAutoReleasePool pool;
  200466. return [s read: (char*) buffer numBytes: bytesToRead];
  200467. }
  200468. return 0;
  200469. }
  200470. int64 juce_getInternetFileContentLength (void* handle)
  200471. {
  200472. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200473. if (s != 0)
  200474. return s->contentLength;
  200475. return -1;
  200476. }
  200477. int juce_seekInInternetFile (void* handle, int newPosition)
  200478. {
  200479. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200480. if (s != 0)
  200481. return [s readPosition];
  200482. return 0;
  200483. }
  200484. #endif
  200485. /*** End of inlined file: juce_mac_Network.mm ***/
  200486. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200487. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200488. // compiled on its own).
  200489. #if JUCE_INCLUDED_FILE
  200490. struct NamedPipeInternal
  200491. {
  200492. String pipeInName, pipeOutName;
  200493. int pipeIn, pipeOut;
  200494. bool volatile createdPipe, blocked, stopReadOperation;
  200495. static void signalHandler (int) {}
  200496. };
  200497. void NamedPipe::cancelPendingReads()
  200498. {
  200499. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200500. {
  200501. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200502. intern->stopReadOperation = true;
  200503. char buffer [1] = { 0 };
  200504. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200505. (void) bytesWritten;
  200506. int timeout = 2000;
  200507. while (intern->blocked && --timeout >= 0)
  200508. Thread::sleep (2);
  200509. intern->stopReadOperation = false;
  200510. }
  200511. }
  200512. void NamedPipe::close()
  200513. {
  200514. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200515. if (intern != 0)
  200516. {
  200517. internal = 0;
  200518. if (intern->pipeIn != -1)
  200519. ::close (intern->pipeIn);
  200520. if (intern->pipeOut != -1)
  200521. ::close (intern->pipeOut);
  200522. if (intern->createdPipe)
  200523. {
  200524. unlink (intern->pipeInName);
  200525. unlink (intern->pipeOutName);
  200526. }
  200527. delete intern;
  200528. }
  200529. }
  200530. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200531. {
  200532. close();
  200533. NamedPipeInternal* const intern = new NamedPipeInternal();
  200534. internal = intern;
  200535. intern->createdPipe = createPipe;
  200536. intern->blocked = false;
  200537. intern->stopReadOperation = false;
  200538. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200539. siginterrupt (SIGPIPE, 1);
  200540. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200541. intern->pipeInName = pipePath + T("_in");
  200542. intern->pipeOutName = pipePath + T("_out");
  200543. intern->pipeIn = -1;
  200544. intern->pipeOut = -1;
  200545. if (createPipe)
  200546. {
  200547. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  200548. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  200549. {
  200550. delete intern;
  200551. internal = 0;
  200552. return false;
  200553. }
  200554. }
  200555. return true;
  200556. }
  200557. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200558. {
  200559. int bytesRead = -1;
  200560. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200561. if (intern != 0)
  200562. {
  200563. intern->blocked = true;
  200564. if (intern->pipeIn == -1)
  200565. {
  200566. if (intern->createdPipe)
  200567. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  200568. else
  200569. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  200570. if (intern->pipeIn == -1)
  200571. {
  200572. intern->blocked = false;
  200573. return -1;
  200574. }
  200575. }
  200576. bytesRead = 0;
  200577. char* p = (char*) destBuffer;
  200578. while (bytesRead < maxBytesToRead)
  200579. {
  200580. const int bytesThisTime = maxBytesToRead - bytesRead;
  200581. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200582. if (numRead <= 0 || intern->stopReadOperation)
  200583. {
  200584. bytesRead = -1;
  200585. break;
  200586. }
  200587. bytesRead += numRead;
  200588. p += bytesRead;
  200589. }
  200590. intern->blocked = false;
  200591. }
  200592. return bytesRead;
  200593. }
  200594. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200595. {
  200596. int bytesWritten = -1;
  200597. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200598. if (intern != 0)
  200599. {
  200600. if (intern->pipeOut == -1)
  200601. {
  200602. if (intern->createdPipe)
  200603. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  200604. else
  200605. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  200606. if (intern->pipeOut == -1)
  200607. {
  200608. return -1;
  200609. }
  200610. }
  200611. const char* p = (const char*) sourceBuffer;
  200612. bytesWritten = 0;
  200613. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200614. while (bytesWritten < numBytesToWrite
  200615. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200616. {
  200617. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200618. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200619. if (numWritten <= 0)
  200620. {
  200621. bytesWritten = -1;
  200622. break;
  200623. }
  200624. bytesWritten += numWritten;
  200625. p += bytesWritten;
  200626. }
  200627. }
  200628. return bytesWritten;
  200629. }
  200630. #endif
  200631. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200632. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200633. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200634. // compiled on its own).
  200635. #if JUCE_INCLUDED_FILE
  200636. void JUCE_API juce_threadEntryPoint (void*);
  200637. void* threadEntryProc (void* userData)
  200638. {
  200639. const ScopedAutoReleasePool pool;
  200640. juce_threadEntryPoint (userData);
  200641. return 0;
  200642. }
  200643. void* juce_createThread (void* userData)
  200644. {
  200645. pthread_t handle = 0;
  200646. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200647. {
  200648. pthread_detach (handle);
  200649. return (void*) handle;
  200650. }
  200651. return 0;
  200652. }
  200653. void juce_killThread (void* handle)
  200654. {
  200655. if (handle != 0)
  200656. pthread_cancel ((pthread_t) handle);
  200657. }
  200658. void juce_setCurrentThreadName (const String& /*name*/)
  200659. {
  200660. }
  200661. Thread::ThreadID Thread::getCurrentThreadId()
  200662. {
  200663. return (ThreadID) pthread_self();
  200664. }
  200665. bool juce_setThreadPriority (void* handle, int priority)
  200666. {
  200667. if (handle == 0)
  200668. handle = (void*) pthread_self();
  200669. struct sched_param param;
  200670. int policy;
  200671. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200672. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200673. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200674. }
  200675. void Thread::yield()
  200676. {
  200677. sched_yield();
  200678. }
  200679. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200680. {
  200681. // xxx
  200682. jassertfalse
  200683. }
  200684. bool Process::isForegroundProcess()
  200685. {
  200686. #if JUCE_MAC
  200687. return [NSApp isActive];
  200688. #else
  200689. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200690. #endif
  200691. }
  200692. void Process::raisePrivilege()
  200693. {
  200694. jassertfalse
  200695. }
  200696. void Process::lowerPrivilege()
  200697. {
  200698. jassertfalse
  200699. }
  200700. void Process::terminate()
  200701. {
  200702. exit (0);
  200703. }
  200704. void Process::setPriority (ProcessPriority p)
  200705. {
  200706. // xxx
  200707. }
  200708. #endif
  200709. /*** End of inlined file: juce_mac_Threads.mm ***/
  200710. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200711. CriticalSection::CriticalSection() throw()
  200712. {
  200713. pthread_mutexattr_t atts;
  200714. pthread_mutexattr_init (&atts);
  200715. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200716. pthread_mutex_init (&internal, &atts);
  200717. }
  200718. CriticalSection::~CriticalSection() throw()
  200719. {
  200720. pthread_mutex_destroy (&internal);
  200721. }
  200722. void CriticalSection::enter() const throw()
  200723. {
  200724. pthread_mutex_lock (&internal);
  200725. }
  200726. bool CriticalSection::tryEnter() const throw()
  200727. {
  200728. return pthread_mutex_trylock (&internal) == 0;
  200729. }
  200730. void CriticalSection::exit() const throw()
  200731. {
  200732. pthread_mutex_unlock (&internal);
  200733. }
  200734. struct EventStruct
  200735. {
  200736. pthread_cond_t condition;
  200737. pthread_mutex_t mutex;
  200738. bool triggered;
  200739. };
  200740. WaitableEvent::WaitableEvent() throw()
  200741. {
  200742. EventStruct* const es = new EventStruct();
  200743. es->triggered = false;
  200744. pthread_cond_init (&es->condition, 0);
  200745. pthread_mutex_init (&es->mutex, 0);
  200746. internal = es;
  200747. }
  200748. WaitableEvent::~WaitableEvent() throw()
  200749. {
  200750. EventStruct* const es = (EventStruct*) internal;
  200751. pthread_cond_destroy (&es->condition);
  200752. pthread_mutex_destroy (&es->mutex);
  200753. delete es;
  200754. }
  200755. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200756. {
  200757. EventStruct* const es = (EventStruct*) internal;
  200758. pthread_mutex_lock (&es->mutex);
  200759. if (timeOutMillisecs < 0)
  200760. {
  200761. while (! es->triggered)
  200762. pthread_cond_wait (&es->condition, &es->mutex);
  200763. }
  200764. else
  200765. {
  200766. while (! es->triggered)
  200767. {
  200768. struct timeval t;
  200769. gettimeofday (&t, 0);
  200770. struct timespec time;
  200771. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  200772. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200773. if (time.tv_nsec >= 1000000000)
  200774. {
  200775. time.tv_nsec -= 1000000000;
  200776. time.tv_sec++;
  200777. }
  200778. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  200779. {
  200780. pthread_mutex_unlock (&es->mutex);
  200781. return false;
  200782. }
  200783. }
  200784. }
  200785. es->triggered = false;
  200786. pthread_mutex_unlock (&es->mutex);
  200787. return true;
  200788. }
  200789. void WaitableEvent::signal() const throw()
  200790. {
  200791. EventStruct* const es = (EventStruct*) internal;
  200792. pthread_mutex_lock (&es->mutex);
  200793. es->triggered = true;
  200794. pthread_cond_broadcast (&es->condition);
  200795. pthread_mutex_unlock (&es->mutex);
  200796. }
  200797. void WaitableEvent::reset() const throw()
  200798. {
  200799. EventStruct* const es = (EventStruct*) internal;
  200800. pthread_mutex_lock (&es->mutex);
  200801. es->triggered = false;
  200802. pthread_mutex_unlock (&es->mutex);
  200803. }
  200804. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200805. {
  200806. struct timespec time;
  200807. time.tv_sec = millisecs / 1000;
  200808. time.tv_nsec = (millisecs % 1000) * 1000000;
  200809. nanosleep (&time, 0);
  200810. }
  200811. const tchar File::separator = T('/');
  200812. const tchar* File::separatorString = T("/");
  200813. bool juce_copyFile (const String& s, const String& d);
  200814. static bool juce_stat (const String& fileName, struct stat& info)
  200815. {
  200816. return fileName.isNotEmpty()
  200817. && (stat (fileName.toUTF8(), &info) == 0);
  200818. }
  200819. bool juce_isDirectory (const String& fileName)
  200820. {
  200821. struct stat info;
  200822. return fileName.isEmpty()
  200823. || (juce_stat (fileName, info)
  200824. && ((info.st_mode & S_IFDIR) != 0));
  200825. }
  200826. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200827. {
  200828. if (fileName.isEmpty())
  200829. return false;
  200830. const char* const fileNameUTF8 = fileName.toUTF8();
  200831. bool exists = access (fileNameUTF8, F_OK) == 0;
  200832. if (exists && dontCountDirectories)
  200833. {
  200834. struct stat info;
  200835. const int res = stat (fileNameUTF8, &info);
  200836. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200837. exists = false;
  200838. }
  200839. return exists;
  200840. }
  200841. int64 juce_getFileSize (const String& fileName)
  200842. {
  200843. struct stat info;
  200844. return juce_stat (fileName, info) ? info.st_size : 0;
  200845. }
  200846. bool juce_canWriteToFile (const String& fileName)
  200847. {
  200848. return access (fileName.toUTF8(), W_OK) == 0;
  200849. }
  200850. bool juce_deleteFile (const String& fileName)
  200851. {
  200852. if (juce_isDirectory (fileName))
  200853. return rmdir ((const char*) fileName.toUTF8()) == 0;
  200854. else
  200855. return remove ((const char*) fileName.toUTF8()) == 0;
  200856. }
  200857. bool juce_moveFile (const String& source, const String& dest)
  200858. {
  200859. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200860. return true;
  200861. if (juce_canWriteToFile (source)
  200862. && juce_copyFile (source, dest))
  200863. {
  200864. if (juce_deleteFile (source))
  200865. return true;
  200866. juce_deleteFile (dest);
  200867. }
  200868. return false;
  200869. }
  200870. void juce_createDirectory (const String& fileName)
  200871. {
  200872. mkdir (fileName.toUTF8(), 0777);
  200873. }
  200874. void* juce_fileOpen (const String& fileName, bool forWriting)
  200875. {
  200876. int flags = O_RDONLY;
  200877. if (forWriting)
  200878. {
  200879. if (juce_fileExists (fileName, false))
  200880. {
  200881. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  200882. if (f != -1)
  200883. lseek (f, 0, SEEK_END);
  200884. return (void*) f;
  200885. }
  200886. else
  200887. {
  200888. flags = O_RDWR + O_CREAT;
  200889. }
  200890. }
  200891. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  200892. }
  200893. void juce_fileClose (void* handle)
  200894. {
  200895. if (handle != 0)
  200896. close ((int) (pointer_sized_int) handle);
  200897. }
  200898. int juce_fileRead (void* handle, void* buffer, int size)
  200899. {
  200900. if (handle != 0)
  200901. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  200902. return 0;
  200903. }
  200904. int juce_fileWrite (void* handle, const void* buffer, int size)
  200905. {
  200906. if (handle != 0)
  200907. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200908. return 0;
  200909. }
  200910. int64 juce_fileSetPosition (void* handle, int64 pos)
  200911. {
  200912. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200913. return pos;
  200914. return -1;
  200915. }
  200916. int64 juce_fileGetPosition (void* handle)
  200917. {
  200918. if (handle != 0)
  200919. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200920. else
  200921. return -1;
  200922. }
  200923. void juce_fileFlush (void* handle)
  200924. {
  200925. if (handle != 0)
  200926. fsync ((int) (pointer_sized_int) handle);
  200927. }
  200928. const File juce_getExecutableFile()
  200929. {
  200930. Dl_info exeInfo;
  200931. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200932. return File (exeInfo.dli_fname);
  200933. }
  200934. // if this file doesn't exist, find a parent of it that does..
  200935. static bool doStatFS (const File* file, struct statfs& result)
  200936. {
  200937. File f (*file);
  200938. for (int i = 5; --i >= 0;)
  200939. {
  200940. if (f.exists())
  200941. break;
  200942. f = f.getParentDirectory();
  200943. }
  200944. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200945. }
  200946. int64 File::getBytesFreeOnVolume() const
  200947. {
  200948. struct statfs buf;
  200949. if (doStatFS (this, buf))
  200950. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200951. return 0;
  200952. }
  200953. int64 File::getVolumeTotalSize() const
  200954. {
  200955. struct statfs buf;
  200956. if (doStatFS (this, buf))
  200957. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200958. return 0;
  200959. }
  200960. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200961. int& volumeSerialNumber)
  200962. {
  200963. volumeSerialNumber = 0;
  200964. #if JUCE_MAC
  200965. struct VolAttrBuf
  200966. {
  200967. u_int32_t length;
  200968. attrreference_t mountPointRef;
  200969. char mountPointSpace [MAXPATHLEN];
  200970. } attrBuf;
  200971. struct attrlist attrList;
  200972. zerostruct (attrList);
  200973. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200974. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200975. File f (filenameOnVolume);
  200976. for (;;)
  200977. {
  200978. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  200979. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200980. {
  200981. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200982. (int) attrBuf.mountPointRef.attr_length);
  200983. }
  200984. const File parent (f.getParentDirectory());
  200985. if (f == parent)
  200986. break;
  200987. f = parent;
  200988. }
  200989. #endif
  200990. return String::empty;
  200991. }
  200992. void juce_runSystemCommand (const String& command)
  200993. {
  200994. int result = system ((const char*) command.toUTF8());
  200995. (void) result;
  200996. }
  200997. const String juce_getOutputFromCommand (const String& command)
  200998. {
  200999. // slight bodge here, as we just pipe the output into a temp file and read it...
  201000. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  201001. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  201002. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  201003. String result (tempFile.loadFileAsString());
  201004. tempFile.deleteFile();
  201005. return result;
  201006. }
  201007. InterProcessLock::InterProcessLock (const String& name_)
  201008. : internal (0),
  201009. name (name_),
  201010. reentrancyLevel (0)
  201011. {
  201012. #if JUCE_MAC
  201013. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  201014. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  201015. #else
  201016. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  201017. #endif
  201018. temp.create();
  201019. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  201020. }
  201021. InterProcessLock::~InterProcessLock()
  201022. {
  201023. while (reentrancyLevel > 0)
  201024. this->exit();
  201025. close (internal);
  201026. }
  201027. bool InterProcessLock::enter (const int timeOutMillisecs)
  201028. {
  201029. if (internal == 0)
  201030. return false;
  201031. if (reentrancyLevel != 0)
  201032. return true;
  201033. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  201034. struct flock fl;
  201035. zerostruct (fl);
  201036. fl.l_whence = SEEK_SET;
  201037. fl.l_type = F_WRLCK;
  201038. for (;;)
  201039. {
  201040. const int result = fcntl (internal, F_SETLK, &fl);
  201041. if (result >= 0)
  201042. {
  201043. ++reentrancyLevel;
  201044. return true;
  201045. }
  201046. if (errno != EINTR)
  201047. {
  201048. if (timeOutMillisecs == 0
  201049. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  201050. break;
  201051. Thread::sleep (10);
  201052. }
  201053. }
  201054. return false;
  201055. }
  201056. void InterProcessLock::exit()
  201057. {
  201058. if (reentrancyLevel > 0 && internal != 0)
  201059. {
  201060. --reentrancyLevel;
  201061. struct flock fl;
  201062. zerostruct (fl);
  201063. fl.l_whence = SEEK_SET;
  201064. fl.l_type = F_UNLCK;
  201065. for (;;)
  201066. {
  201067. const int result = fcntl (internal, F_SETLKW, &fl);
  201068. if (result >= 0 || errno != EINTR)
  201069. break;
  201070. }
  201071. }
  201072. }
  201073. /*** End of inlined file: juce_posix_SharedCode.h ***/
  201074. /*** Start of inlined file: juce_mac_Files.mm ***/
  201075. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201076. // compiled on its own).
  201077. #if JUCE_INCLUDED_FILE
  201078. void juce_getFileTimes (const String& fileName,
  201079. int64& modificationTime,
  201080. int64& accessTime,
  201081. int64& creationTime)
  201082. {
  201083. modificationTime = 0;
  201084. accessTime = 0;
  201085. creationTime = 0;
  201086. struct stat info;
  201087. const int res = stat (fileName.toUTF8(), &info);
  201088. if (res == 0)
  201089. {
  201090. modificationTime = (int64) info.st_mtime * 1000;
  201091. accessTime = (int64) info.st_atime * 1000;
  201092. creationTime = (int64) info.st_ctime * 1000;
  201093. }
  201094. }
  201095. bool juce_setFileTimes (const String& fileName,
  201096. int64 modificationTime,
  201097. int64 accessTime,
  201098. int64 creationTime)
  201099. {
  201100. struct utimbuf times;
  201101. times.actime = (time_t) (accessTime / 1000);
  201102. times.modtime = (time_t) (modificationTime / 1000);
  201103. return utime (fileName.toUTF8(), &times) == 0;
  201104. }
  201105. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  201106. {
  201107. struct stat info;
  201108. const int res = stat (fileName.toUTF8(), &info);
  201109. if (res != 0)
  201110. return false;
  201111. info.st_mode &= 0777; // Just permissions
  201112. if (isReadOnly)
  201113. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201114. else
  201115. // Give everybody write permission?
  201116. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201117. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201118. }
  201119. bool juce_copyFile (const String& src, const String& dst)
  201120. {
  201121. const ScopedAutoReleasePool pool;
  201122. NSFileManager* fm = [NSFileManager defaultManager];
  201123. return [fm fileExistsAtPath: juceStringToNS (src)]
  201124. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201125. && [fm copyItemAtPath: juceStringToNS (src)
  201126. toPath: juceStringToNS (dst)
  201127. error: nil];
  201128. #else
  201129. && [fm copyPath: juceStringToNS (src)
  201130. toPath: juceStringToNS (dst)
  201131. handler: nil];
  201132. #endif
  201133. }
  201134. const StringArray juce_getFileSystemRoots()
  201135. {
  201136. StringArray s;
  201137. s.add (T("/"));
  201138. return s;
  201139. }
  201140. static bool isFileOnDriveType (const File* const f, const char** types)
  201141. {
  201142. struct statfs buf;
  201143. if (doStatFS (f, buf))
  201144. {
  201145. const String type (buf.f_fstypename);
  201146. while (*types != 0)
  201147. if (type.equalsIgnoreCase (*types++))
  201148. return true;
  201149. }
  201150. return false;
  201151. }
  201152. bool File::isOnCDRomDrive() const
  201153. {
  201154. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201155. return isFileOnDriveType (this, (const char**) cdTypes);
  201156. }
  201157. bool File::isOnHardDisk() const
  201158. {
  201159. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201160. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201161. }
  201162. bool File::isOnRemovableDrive() const
  201163. {
  201164. #if JUCE_IPHONE
  201165. return false; // xxx is this possible?
  201166. #else
  201167. const ScopedAutoReleasePool pool;
  201168. BOOL removable = false;
  201169. [[NSWorkspace sharedWorkspace]
  201170. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201171. isRemovable: &removable
  201172. isWritable: nil
  201173. isUnmountable: nil
  201174. description: nil
  201175. type: nil];
  201176. return removable;
  201177. #endif
  201178. }
  201179. static bool juce_isHiddenFile (const String& path)
  201180. {
  201181. #if JUCE_IPHONE
  201182. return File (path).getFileName().startsWithChar (T('.'));
  201183. #else
  201184. FSRef ref;
  201185. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201186. return false;
  201187. FSCatalogInfo info;
  201188. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201189. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201190. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201191. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201192. #endif
  201193. }
  201194. bool File::isHidden() const
  201195. {
  201196. return juce_isHiddenFile (getFullPathName());
  201197. }
  201198. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201199. const File File::getSpecialLocation (const SpecialLocationType type)
  201200. {
  201201. const ScopedAutoReleasePool pool;
  201202. String resultPath;
  201203. switch (type)
  201204. {
  201205. case userHomeDirectory:
  201206. resultPath = nsStringToJuce (NSHomeDirectory());
  201207. break;
  201208. case userDocumentsDirectory:
  201209. resultPath = "~/Documents";
  201210. break;
  201211. case userDesktopDirectory:
  201212. resultPath = "~/Desktop";
  201213. break;
  201214. case userApplicationDataDirectory:
  201215. resultPath = "~/Library";
  201216. break;
  201217. case commonApplicationDataDirectory:
  201218. resultPath = "/Library";
  201219. break;
  201220. case globalApplicationsDirectory:
  201221. resultPath = "/Applications";
  201222. break;
  201223. case userMusicDirectory:
  201224. resultPath = "~/Music";
  201225. break;
  201226. case userMoviesDirectory:
  201227. resultPath = "~/Movies";
  201228. break;
  201229. case tempDirectory:
  201230. {
  201231. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201232. tmp.createDirectory();
  201233. return tmp.getFullPathName();
  201234. }
  201235. case invokedExecutableFile:
  201236. if (juce_Argv0 != 0)
  201237. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  201238. // deliberate fall-through...
  201239. case currentExecutableFile:
  201240. return juce_getExecutableFile();
  201241. case currentApplicationFile:
  201242. {
  201243. const File exe (juce_getExecutableFile());
  201244. const File parent (exe.getParentDirectory());
  201245. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201246. ? parent.getParentDirectory().getParentDirectory()
  201247. : exe;
  201248. }
  201249. default:
  201250. jassertfalse // unknown type?
  201251. break;
  201252. }
  201253. if (resultPath != 0)
  201254. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201255. return File::nonexistent;
  201256. }
  201257. const File File::getCurrentWorkingDirectory()
  201258. {
  201259. char buf [2048];
  201260. getcwd (buf, sizeof(buf));
  201261. return File (PlatformUtilities::convertToPrecomposedUnicode (buf));
  201262. }
  201263. bool File::setAsCurrentWorkingDirectory() const
  201264. {
  201265. return chdir (getFullPathName().toUTF8()) == 0;
  201266. }
  201267. const String File::getVersion() const
  201268. {
  201269. const ScopedAutoReleasePool pool;
  201270. String result;
  201271. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201272. if (bundle != 0)
  201273. {
  201274. NSDictionary* info = [bundle infoDictionary];
  201275. if (info != 0)
  201276. {
  201277. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201278. if (name != nil)
  201279. result = nsStringToJuce (name);
  201280. }
  201281. }
  201282. return result;
  201283. }
  201284. const File File::getLinkedTarget() const
  201285. {
  201286. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201287. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201288. #else
  201289. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201290. #endif
  201291. if (dest != nil)
  201292. return File (nsStringToJuce (dest));
  201293. return *this;
  201294. }
  201295. bool File::moveToTrash() const
  201296. {
  201297. if (! exists())
  201298. return true;
  201299. #if JUCE_IPHONE
  201300. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201301. #else
  201302. const ScopedAutoReleasePool pool;
  201303. NSString* p = juceStringToNS (getFullPathName());
  201304. return [[NSWorkspace sharedWorkspace]
  201305. performFileOperation: NSWorkspaceRecycleOperation
  201306. source: [p stringByDeletingLastPathComponent]
  201307. destination: @""
  201308. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201309. tag: nil ];
  201310. #endif
  201311. }
  201312. struct FindFileStruct
  201313. {
  201314. NSDirectoryEnumerator* enumerator;
  201315. String parentDir, wildCard;
  201316. };
  201317. bool juce_findFileNext (void* handle, String& resultFile,
  201318. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201319. {
  201320. ScopedAutoReleasePool pool;
  201321. FindFileStruct* ff = (FindFileStruct*) handle;
  201322. NSString* file;
  201323. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201324. for (;;)
  201325. {
  201326. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201327. return false;
  201328. [ff->enumerator skipDescendents];
  201329. resultFile = nsStringToJuce (file);
  201330. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201331. continue;
  201332. const String path (ff->parentDir + resultFile);
  201333. if (isDir != 0 || fileSize != 0)
  201334. {
  201335. struct stat info;
  201336. const bool statOk = juce_stat (path, info);
  201337. if (isDir != 0)
  201338. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201339. if (isHidden != 0)
  201340. *isHidden = juce_isHiddenFile (path);
  201341. if (fileSize != 0)
  201342. *fileSize = statOk ? info.st_size : 0;
  201343. }
  201344. if (modTime != 0 || creationTime != 0)
  201345. {
  201346. int64 m, a, c;
  201347. juce_getFileTimes (path, m, a, c);
  201348. if (modTime != 0)
  201349. *modTime = m;
  201350. if (creationTime != 0)
  201351. *creationTime = c;
  201352. }
  201353. if (isReadOnly != 0)
  201354. *isReadOnly = ! juce_canWriteToFile (path);
  201355. return true;
  201356. }
  201357. }
  201358. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201359. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201360. Time* creationTime, bool* isReadOnly)
  201361. {
  201362. ScopedAutoReleasePool pool;
  201363. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201364. if (e != 0)
  201365. {
  201366. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201367. ff->enumerator = [e retain];
  201368. ff->parentDir = directory;
  201369. ff->wildCard = wildCard;
  201370. if (! ff->parentDir.endsWithChar (File::separator))
  201371. ff->parentDir += File::separator;
  201372. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201373. return ff.release();
  201374. [e release];
  201375. }
  201376. return 0;
  201377. }
  201378. void juce_findFileClose (void* handle)
  201379. {
  201380. ScopedAutoReleasePool pool;
  201381. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201382. [ff->enumerator release];
  201383. }
  201384. bool juce_launchExecutable (const String& pathAndArguments)
  201385. {
  201386. const char* const argv[4] = { "/bin/sh", "-c", (const char*) pathAndArguments, 0 };
  201387. const int cpid = fork();
  201388. if (cpid == 0)
  201389. {
  201390. // Child process
  201391. if (execve (argv[0], (char**) argv, 0) < 0)
  201392. exit (0);
  201393. }
  201394. else
  201395. {
  201396. if (cpid < 0)
  201397. return false;
  201398. }
  201399. return true;
  201400. }
  201401. bool juce_launchFile (const String& fileName, const String& parameters)
  201402. {
  201403. #if JUCE_IPHONE
  201404. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201405. #else
  201406. const ScopedAutoReleasePool pool;
  201407. if (parameters.isEmpty())
  201408. {
  201409. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201410. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201411. }
  201412. bool ok = false;
  201413. FSRef ref;
  201414. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201415. {
  201416. if (PlatformUtilities::isBundle (fileName))
  201417. {
  201418. NSMutableArray* urls = [NSMutableArray array];
  201419. StringArray docs;
  201420. docs.addTokens (parameters, true);
  201421. for (int i = 0; i < docs.size(); ++i)
  201422. [urls addObject: juceStringToNS (docs[i])];
  201423. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201424. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201425. options: 0
  201426. additionalEventParamDescriptor: nil
  201427. launchIdentifiers: nil];
  201428. }
  201429. else
  201430. {
  201431. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201432. }
  201433. }
  201434. return ok;
  201435. #endif
  201436. }
  201437. void File::revealToUser() const
  201438. {
  201439. #if ! JUCE_IPHONE
  201440. if (exists())
  201441. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201442. else if (getParentDirectory().exists())
  201443. getParentDirectory().revealToUser();
  201444. #endif
  201445. }
  201446. #if ! JUCE_IPHONE
  201447. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201448. {
  201449. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201450. }
  201451. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201452. {
  201453. uint8 path [2048];
  201454. zeromem (path, sizeof (path));
  201455. String result;
  201456. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201457. result = String::fromUTF8 (path);
  201458. return PlatformUtilities::convertToPrecomposedUnicode (result);
  201459. }
  201460. #endif
  201461. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201462. {
  201463. const ScopedAutoReleasePool pool;
  201464. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201465. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201466. #else
  201467. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201468. #endif
  201469. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201470. return [fileDict fileHFSTypeCode];
  201471. }
  201472. bool PlatformUtilities::isBundle (const String& filename)
  201473. {
  201474. #if JUCE_IPHONE
  201475. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201476. #else
  201477. const ScopedAutoReleasePool pool;
  201478. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201479. #endif
  201480. }
  201481. #endif
  201482. /*** End of inlined file: juce_mac_Files.mm ***/
  201483. #if JUCE_IPHONE
  201484. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201485. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201486. // compiled on its own).
  201487. #if JUCE_INCLUDED_FILE
  201488. static JUCEApplication* juce_intialisingApp;
  201489. END_JUCE_NAMESPACE
  201490. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201491. {
  201492. }
  201493. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201494. - (void) applicationWillResignActive: (UIApplication*) application;
  201495. @end
  201496. @implementation JuceAppStartupDelegate
  201497. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201498. {
  201499. String dummy;
  201500. if (! juce_intialisingApp->initialiseApp (dummy))
  201501. exit (0);
  201502. }
  201503. - (void) applicationWillResignActive: (UIApplication*) application
  201504. {
  201505. JUCEApplication::shutdownAppAndClearUp();
  201506. }
  201507. @end
  201508. BEGIN_JUCE_NAMESPACE
  201509. int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app)
  201510. {
  201511. juce_intialisingApp = app;
  201512. return UIApplicationMain (argc, argv, nil, @"JuceAppStartupDelegate");
  201513. }
  201514. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201515. {
  201516. pool = [[NSAutoreleasePool alloc] init];
  201517. }
  201518. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201519. {
  201520. [((NSAutoreleasePool*) pool) release];
  201521. }
  201522. void PlatformUtilities::beep()
  201523. {
  201524. //xxx
  201525. //AudioServicesPlaySystemSound ();
  201526. }
  201527. void PlatformUtilities::addItemToDock (const File& file)
  201528. {
  201529. }
  201530. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201531. END_JUCE_NAMESPACE
  201532. @interface JuceAlertBoxDelegate : NSObject
  201533. {
  201534. @public
  201535. bool clickedOk;
  201536. }
  201537. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201538. @end
  201539. @implementation JuceAlertBoxDelegate
  201540. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201541. {
  201542. clickedOk = (buttonIndex == 0);
  201543. alertView.hidden = true;
  201544. }
  201545. @end
  201546. BEGIN_JUCE_NAMESPACE
  201547. // (This function is used directly by other bits of code)
  201548. bool juce_iPhoneShowModalAlert (const String& title,
  201549. const String& bodyText,
  201550. NSString* okButtonText,
  201551. NSString* cancelButtonText)
  201552. {
  201553. const ScopedAutoReleasePool pool;
  201554. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201555. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201556. message: juceStringToNS (bodyText)
  201557. delegate: callback
  201558. cancelButtonTitle: okButtonText
  201559. otherButtonTitles: cancelButtonText, nil];
  201560. [alert retain];
  201561. [alert show];
  201562. while (! alert.hidden && alert.superview != nil)
  201563. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201564. const bool result = callback->clickedOk;
  201565. [alert release];
  201566. [callback release];
  201567. return result;
  201568. }
  201569. bool AlertWindow::showNativeDialogBox (const String& title,
  201570. const String& bodyText,
  201571. bool isOkCancel)
  201572. {
  201573. return juce_iPhoneShowModalAlert (title, bodyText,
  201574. @"OK",
  201575. isOkCancel ? @"Cancel" : nil);
  201576. }
  201577. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201578. {
  201579. jassertfalse // no such thing on the iphone!
  201580. return false;
  201581. }
  201582. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201583. {
  201584. jassertfalse // no such thing on the iphone!
  201585. return false;
  201586. }
  201587. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201588. {
  201589. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201590. }
  201591. bool Desktop::isScreenSaverEnabled() throw()
  201592. {
  201593. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201594. }
  201595. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201596. {
  201597. const ScopedAutoReleasePool pool;
  201598. monitorCoords.clear();
  201599. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201600. : [[UIScreen mainScreen] bounds];
  201601. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201602. (int) r.origin.y,
  201603. (int) r.size.width,
  201604. (int) r.size.height));
  201605. }
  201606. #endif
  201607. #endif
  201608. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201609. #else
  201610. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201611. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201612. // compiled on its own).
  201613. #if JUCE_INCLUDED_FILE
  201614. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201615. {
  201616. pool = [[NSAutoreleasePool alloc] init];
  201617. }
  201618. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201619. {
  201620. [((NSAutoreleasePool*) pool) release];
  201621. }
  201622. void PlatformUtilities::beep()
  201623. {
  201624. NSBeep();
  201625. }
  201626. void PlatformUtilities::addItemToDock (const File& file)
  201627. {
  201628. // check that it's not already there...
  201629. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201630. .containsIgnoreCase (file.getFullPathName()))
  201631. {
  201632. 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>"
  201633. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201634. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201635. }
  201636. }
  201637. int PlatformUtilities::getOSXMinorVersionNumber()
  201638. {
  201639. SInt32 versionMinor = 0;
  201640. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201641. (void) err;
  201642. jassert (err == noErr);
  201643. return (int) versionMinor;
  201644. }
  201645. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201646. bool AlertWindow::showNativeDialogBox (const String& title,
  201647. const String& bodyText,
  201648. bool isOkCancel)
  201649. {
  201650. const ScopedAutoReleasePool pool;
  201651. return NSRunAlertPanel (juceStringToNS (title),
  201652. juceStringToNS (bodyText),
  201653. @"Ok",
  201654. isOkCancel ? @"Cancel" : nil,
  201655. nil) == NSAlertDefaultReturn;
  201656. }
  201657. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201658. {
  201659. if (files.size() == 0)
  201660. return false;
  201661. Component* sourceComp = Component::getComponentUnderMouse();
  201662. if (sourceComp == 0)
  201663. {
  201664. jassertfalse // this method must be called in response to a
  201665. // component's mouseDrag event!
  201666. return false;
  201667. }
  201668. const ScopedAutoReleasePool pool;
  201669. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201670. if (view == 0)
  201671. return false;
  201672. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201673. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201674. owner: nil];
  201675. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201676. for (int i = 0; i < files.size(); ++i)
  201677. [filesArray addObject: juceStringToNS (files[i])];
  201678. [pboard setPropertyList: filesArray
  201679. forType: NSFilenamesPboardType];
  201680. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201681. fromView: nil];
  201682. dragPosition.x -= 16;
  201683. dragPosition.y -= 16;
  201684. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201685. at: dragPosition
  201686. offset: NSMakeSize (0, 0)
  201687. event: [[view window] currentEvent]
  201688. pasteboard: pboard
  201689. source: view
  201690. slideBack: YES];
  201691. return true;
  201692. }
  201693. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201694. {
  201695. jassertfalse // not implemented!
  201696. return false;
  201697. }
  201698. bool Desktop::canUseSemiTransparentWindows() throw()
  201699. {
  201700. return true;
  201701. }
  201702. const Point<int> Desktop::getMousePosition()
  201703. {
  201704. const ScopedAutoReleasePool pool;
  201705. const NSPoint p ([NSEvent mouseLocation]);
  201706. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201707. }
  201708. void Desktop::setMousePosition (const Point<int>& newPosition)
  201709. {
  201710. // this rubbish needs to be done around the warp call, to avoid causing a
  201711. // bizarre glitch..
  201712. CGAssociateMouseAndMouseCursorPosition (false);
  201713. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201714. CGAssociateMouseAndMouseCursorPosition (true);
  201715. }
  201716. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201717. class ScreenSaverDefeater : public Timer,
  201718. public DeletedAtShutdown
  201719. {
  201720. public:
  201721. ScreenSaverDefeater() throw()
  201722. {
  201723. startTimer (10000);
  201724. timerCallback();
  201725. }
  201726. ~ScreenSaverDefeater() {}
  201727. void timerCallback()
  201728. {
  201729. if (Process::isForegroundProcess())
  201730. UpdateSystemActivity (UsrActivity);
  201731. }
  201732. };
  201733. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201734. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201735. {
  201736. if (isEnabled)
  201737. {
  201738. deleteAndZero (screenSaverDefeater);
  201739. }
  201740. else if (screenSaverDefeater == 0)
  201741. {
  201742. screenSaverDefeater = new ScreenSaverDefeater();
  201743. }
  201744. }
  201745. bool Desktop::isScreenSaverEnabled() throw()
  201746. {
  201747. return screenSaverDefeater == 0;
  201748. }
  201749. #else
  201750. static IOPMAssertionID screenSaverDisablerID = 0;
  201751. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201752. {
  201753. if (isEnabled)
  201754. {
  201755. if (screenSaverDisablerID != 0)
  201756. {
  201757. IOPMAssertionRelease (screenSaverDisablerID);
  201758. screenSaverDisablerID = 0;
  201759. }
  201760. }
  201761. else
  201762. {
  201763. if (screenSaverDisablerID == 0)
  201764. {
  201765. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201766. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201767. CFSTR ("Juce"), &screenSaverDisablerID);
  201768. #else
  201769. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201770. &screenSaverDisablerID);
  201771. #endif
  201772. }
  201773. }
  201774. }
  201775. bool Desktop::isScreenSaverEnabled() throw()
  201776. {
  201777. return screenSaverDisablerID == 0;
  201778. }
  201779. #endif
  201780. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201781. {
  201782. const ScopedAutoReleasePool pool;
  201783. monitorCoords.clear();
  201784. NSArray* screens = [NSScreen screens];
  201785. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201786. for (unsigned int i = 0; i < [screens count]; ++i)
  201787. {
  201788. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201789. NSRect r = clipToWorkArea ? [s visibleFrame]
  201790. : [s frame];
  201791. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201792. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201793. (int) r.size.width,
  201794. (int) r.size.height));
  201795. }
  201796. jassert (monitorCoords.size() > 0);
  201797. }
  201798. #endif
  201799. #endif
  201800. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201801. #endif
  201802. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201803. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201804. // compiled on its own).
  201805. #if JUCE_INCLUDED_FILE
  201806. void Logger::outputDebugString (const String& text) throw()
  201807. {
  201808. std::cerr << (const char*) text.toUTF8() << std::endl;
  201809. }
  201810. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  201811. {
  201812. String text;
  201813. va_list args;
  201814. va_start (args, format);
  201815. text.vprintf (format, args);
  201816. outputDebugString (text);
  201817. }
  201818. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201819. {
  201820. static char testResult = 0;
  201821. if (testResult == 0)
  201822. {
  201823. struct kinfo_proc info;
  201824. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201825. size_t sz = sizeof (info);
  201826. sysctl (m, 4, &info, &sz, 0, 0);
  201827. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201828. }
  201829. return testResult > 0;
  201830. }
  201831. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201832. {
  201833. return juce_isRunningUnderDebugger();
  201834. }
  201835. #endif
  201836. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201837. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201838. #if JUCE_IPHONE
  201839. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201840. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201841. // compiled on its own).
  201842. #if JUCE_INCLUDED_FILE
  201843. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201844. #define SUPPORT_10_4_FONTS 1
  201845. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201846. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201847. #define SUPPORT_ONLY_10_4_FONTS 1
  201848. #endif
  201849. END_JUCE_NAMESPACE
  201850. @interface NSFont (PrivateHack)
  201851. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201852. @end
  201853. BEGIN_JUCE_NAMESPACE
  201854. #endif
  201855. class MacTypeface : public Typeface
  201856. {
  201857. public:
  201858. MacTypeface (const Font& font)
  201859. : Typeface (font.getTypefaceName())
  201860. {
  201861. const ScopedAutoReleasePool pool;
  201862. renderingTransform = CGAffineTransformIdentity;
  201863. bool needsItalicTransform = false;
  201864. #if JUCE_IPHONE
  201865. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201866. if (font.isItalic() || font.isBold())
  201867. {
  201868. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201869. for (NSString* i in familyFonts)
  201870. {
  201871. const String fn (nsStringToJuce (i));
  201872. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  201873. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  201874. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  201875. || afterDash.containsIgnoreCase (T("italic"))
  201876. || fn.endsWithIgnoreCase (T("oblique"))
  201877. || fn.endsWithIgnoreCase (T("italic"));
  201878. if (probablyBold == font.isBold()
  201879. && probablyItalic == font.isItalic())
  201880. {
  201881. fontName = i;
  201882. needsItalicTransform = false;
  201883. break;
  201884. }
  201885. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201886. {
  201887. fontName = i;
  201888. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201889. }
  201890. }
  201891. if (needsItalicTransform)
  201892. renderingTransform.c = 0.15f;
  201893. }
  201894. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201895. const int ascender = abs (CGFontGetAscent (fontRef));
  201896. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201897. ascent = ascender / totalHeight;
  201898. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201899. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201900. #else
  201901. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201902. if (font.isItalic())
  201903. {
  201904. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201905. toHaveTrait: NSItalicFontMask];
  201906. if (newFont == nsFont)
  201907. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201908. nsFont = newFont;
  201909. }
  201910. if (font.isBold())
  201911. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201912. [nsFont retain];
  201913. ascent = fabsf ((float) [nsFont ascender]);
  201914. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201915. ascent /= totalSize;
  201916. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201917. if (needsItalicTransform)
  201918. {
  201919. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201920. renderingTransform.c = 0.15f;
  201921. }
  201922. #if SUPPORT_ONLY_10_4_FONTS
  201923. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201924. if (atsFont == 0)
  201925. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201926. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201927. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201928. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201929. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201930. #else
  201931. #if SUPPORT_10_4_FONTS
  201932. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201933. {
  201934. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201935. if (atsFont == 0)
  201936. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201937. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201938. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201939. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201940. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201941. }
  201942. else
  201943. #endif
  201944. {
  201945. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201946. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201947. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201948. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201949. }
  201950. #endif
  201951. #endif
  201952. }
  201953. ~MacTypeface()
  201954. {
  201955. #if ! JUCE_IPHONE
  201956. [nsFont release];
  201957. #endif
  201958. if (fontRef != 0)
  201959. CGFontRelease (fontRef);
  201960. }
  201961. float getAscent() const
  201962. {
  201963. return ascent;
  201964. }
  201965. float getDescent() const
  201966. {
  201967. return 1.0f - ascent;
  201968. }
  201969. float getStringWidth (const String& text)
  201970. {
  201971. if (fontRef == 0 || text.isEmpty())
  201972. return 0;
  201973. const int length = text.length();
  201974. HeapBlock <CGGlyph> glyphs;
  201975. createGlyphsForString (text, length, glyphs);
  201976. float x = 0;
  201977. #if SUPPORT_ONLY_10_4_FONTS
  201978. HeapBlock <NSSize> advances (length);
  201979. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  201980. for (int i = 0; i < length; ++i)
  201981. x += advances[i].width;
  201982. #else
  201983. #if SUPPORT_10_4_FONTS
  201984. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201985. {
  201986. HeapBlock <NSSize> advances (length);
  201987. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  201988. for (int i = 0; i < length; ++i)
  201989. x += advances[i].width;
  201990. }
  201991. else
  201992. #endif
  201993. {
  201994. HeapBlock <int> advances (length);
  201995. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201996. for (int i = 0; i < length; ++i)
  201997. x += advances[i];
  201998. }
  201999. #endif
  202000. return x * unitsToHeightScaleFactor;
  202001. }
  202002. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  202003. {
  202004. xOffsets.add (0);
  202005. if (fontRef == 0 || text.isEmpty())
  202006. return;
  202007. const int length = text.length();
  202008. HeapBlock <CGGlyph> glyphs;
  202009. createGlyphsForString (text, length, glyphs);
  202010. #if SUPPORT_ONLY_10_4_FONTS
  202011. HeapBlock <NSSize> advances (length);
  202012. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202013. int x = 0;
  202014. for (int i = 0; i < length; ++i)
  202015. {
  202016. x += advances[i].width;
  202017. xOffsets.add (x * unitsToHeightScaleFactor);
  202018. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202019. }
  202020. #else
  202021. #if SUPPORT_10_4_FONTS
  202022. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202023. {
  202024. HeapBlock <NSSize> advances (length);
  202025. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202026. float x = 0;
  202027. for (int i = 0; i < length; ++i)
  202028. {
  202029. x += advances[i].width;
  202030. xOffsets.add (x * unitsToHeightScaleFactor);
  202031. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202032. }
  202033. }
  202034. else
  202035. #endif
  202036. {
  202037. HeapBlock <int> advances (length);
  202038. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202039. {
  202040. int x = 0;
  202041. for (int i = 0; i < length; ++i)
  202042. {
  202043. x += advances [i];
  202044. xOffsets.add (x * unitsToHeightScaleFactor);
  202045. resultGlyphs.add (glyphs[i]);
  202046. }
  202047. }
  202048. }
  202049. #endif
  202050. }
  202051. bool getOutlineForGlyph (int glyphNumber, Path& path)
  202052. {
  202053. #if JUCE_IPHONE
  202054. return false;
  202055. #else
  202056. if (nsFont == 0)
  202057. return false;
  202058. // we might need to apply a transform to the path, so it mustn't have anything else in it
  202059. jassert (path.isEmpty());
  202060. const ScopedAutoReleasePool pool;
  202061. NSBezierPath* bez = [NSBezierPath bezierPath];
  202062. [bez moveToPoint: NSMakePoint (0, 0)];
  202063. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  202064. inFont: nsFont];
  202065. for (int i = 0; i < [bez elementCount]; ++i)
  202066. {
  202067. NSPoint p[3];
  202068. switch ([bez elementAtIndex: i associatedPoints: p])
  202069. {
  202070. case NSMoveToBezierPathElement:
  202071. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  202072. break;
  202073. case NSLineToBezierPathElement:
  202074. path.lineTo ((float) p[0].x, (float) -p[0].y);
  202075. break;
  202076. case NSCurveToBezierPathElement:
  202077. 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);
  202078. break;
  202079. case NSClosePathBezierPathElement:
  202080. path.closeSubPath();
  202081. break;
  202082. default:
  202083. jassertfalse
  202084. break;
  202085. }
  202086. }
  202087. path.applyTransform (pathTransform);
  202088. return true;
  202089. #endif
  202090. }
  202091. juce_UseDebuggingNewOperator
  202092. CGFontRef fontRef;
  202093. float fontHeightToCGSizeFactor;
  202094. CGAffineTransform renderingTransform;
  202095. private:
  202096. float ascent, unitsToHeightScaleFactor;
  202097. #if JUCE_IPHONE
  202098. #else
  202099. NSFont* nsFont;
  202100. AffineTransform pathTransform;
  202101. #endif
  202102. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  202103. {
  202104. #if SUPPORT_10_4_FONTS
  202105. #if ! SUPPORT_ONLY_10_4_FONTS
  202106. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202107. #endif
  202108. {
  202109. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  202110. NSGlyph* const g = (NSGlyph*) glyphs;
  202111. for (int i = 0; i < length; ++i)
  202112. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  202113. return;
  202114. }
  202115. #endif
  202116. #if ! SUPPORT_ONLY_10_4_FONTS
  202117. if (charToGlyphMapper == 0)
  202118. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  202119. glyphs.malloc (length);
  202120. for (int i = 0; i < length; ++i)
  202121. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202122. #endif
  202123. }
  202124. #if ! SUPPORT_ONLY_10_4_FONTS
  202125. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202126. class CharToGlyphMapper
  202127. {
  202128. public:
  202129. CharToGlyphMapper (CGFontRef fontRef)
  202130. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202131. idRangeOffset (0), glyphIndexes (0)
  202132. {
  202133. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202134. if (cmapTable != 0)
  202135. {
  202136. const int numSubtables = getValue16 (cmapTable, 2);
  202137. for (int i = 0; i < numSubtables; ++i)
  202138. {
  202139. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202140. {
  202141. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202142. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202143. {
  202144. const int length = getValue16 (cmapTable, offset + 2);
  202145. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202146. segCount = segCountX2 / 2;
  202147. const int endCodeOffset = offset + 14;
  202148. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202149. const int idDeltaOffset = startCodeOffset + segCountX2;
  202150. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202151. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202152. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202153. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202154. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202155. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202156. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202157. }
  202158. break;
  202159. }
  202160. }
  202161. CFRelease (cmapTable);
  202162. }
  202163. }
  202164. ~CharToGlyphMapper()
  202165. {
  202166. if (endCode != 0)
  202167. {
  202168. CFRelease (endCode);
  202169. CFRelease (startCode);
  202170. CFRelease (idDelta);
  202171. CFRelease (idRangeOffset);
  202172. CFRelease (glyphIndexes);
  202173. }
  202174. }
  202175. int getGlyphForCharacter (const juce_wchar c) const
  202176. {
  202177. for (int i = 0; i < segCount; ++i)
  202178. {
  202179. if (getValue16 (endCode, i * 2) >= c)
  202180. {
  202181. const int start = getValue16 (startCode, i * 2);
  202182. if (start > c)
  202183. break;
  202184. const int delta = getValue16 (idDelta, i * 2);
  202185. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202186. if (rangeOffset == 0)
  202187. return delta + c;
  202188. else
  202189. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202190. }
  202191. }
  202192. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202193. return jmax (-1, c - 29);
  202194. }
  202195. private:
  202196. int segCount;
  202197. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202198. static uint16 getValue16 (CFDataRef data, const int index)
  202199. {
  202200. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202201. }
  202202. static uint32 getValue32 (CFDataRef data, const int index)
  202203. {
  202204. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202205. }
  202206. };
  202207. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202208. #endif
  202209. };
  202210. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202211. {
  202212. return new MacTypeface (font);
  202213. }
  202214. const StringArray Font::findAllTypefaceNames() throw()
  202215. {
  202216. StringArray names;
  202217. const ScopedAutoReleasePool pool;
  202218. #if JUCE_IPHONE
  202219. NSArray* fonts = [UIFont familyNames];
  202220. #else
  202221. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202222. #endif
  202223. for (unsigned int i = 0; i < [fonts count]; ++i)
  202224. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202225. names.sort (true);
  202226. return names;
  202227. }
  202228. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202229. {
  202230. #if JUCE_IPHONE
  202231. defaultSans = "Helvetica";
  202232. defaultSerif = "Times New Roman";
  202233. defaultFixed = "Courier New";
  202234. #else
  202235. defaultSans = "Lucida Grande";
  202236. defaultSerif = "Times New Roman";
  202237. defaultFixed = "Monaco";
  202238. #endif
  202239. }
  202240. #endif
  202241. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202242. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202243. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202244. // compiled on its own).
  202245. #if JUCE_INCLUDED_FILE
  202246. class CoreGraphicsImage : public Image
  202247. {
  202248. public:
  202249. CoreGraphicsImage (const PixelFormat format_,
  202250. const int imageWidth_,
  202251. const int imageHeight_,
  202252. const bool clearImage)
  202253. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202254. {
  202255. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  202256. : CGColorSpaceCreateDeviceRGB();
  202257. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202258. colourSpace, getCGImageFlags (*this));
  202259. CGColorSpaceRelease (colourSpace);
  202260. }
  202261. ~CoreGraphicsImage()
  202262. {
  202263. CGContextRelease (context);
  202264. }
  202265. LowLevelGraphicsContext* createLowLevelContext();
  202266. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202267. {
  202268. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202269. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202270. {
  202271. return CGBitmapContextCreateImage (nativeImage->context);
  202272. }
  202273. else
  202274. {
  202275. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202276. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202277. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202278. 8, srcData.pixelStride * 8, srcData.lineStride,
  202279. colourSpace, getCGImageFlags (juceImage), provider,
  202280. 0, true, kCGRenderingIntentDefault);
  202281. CGDataProviderRelease (provider);
  202282. return imageRef;
  202283. }
  202284. }
  202285. #if JUCE_MAC
  202286. static NSImage* createNSImage (const Image& image)
  202287. {
  202288. const ScopedAutoReleasePool pool;
  202289. NSImage* im = [[NSImage alloc] init];
  202290. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202291. [im lockFocus];
  202292. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202293. CGImageRef imageRef = createImage (image, false, colourSpace);
  202294. CGColorSpaceRelease (colourSpace);
  202295. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202296. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202297. CGImageRelease (imageRef);
  202298. [im unlockFocus];
  202299. return im;
  202300. }
  202301. #endif
  202302. CGContextRef context;
  202303. private:
  202304. static CGBitmapInfo getCGImageFlags (const Image& image)
  202305. {
  202306. #if JUCE_BIG_ENDIAN
  202307. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202308. #else
  202309. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202310. #endif
  202311. }
  202312. };
  202313. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202314. {
  202315. #if USE_COREGRAPHICS_RENDERING
  202316. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202317. #else
  202318. return new Image (format, imageWidth, imageHeight, clearImage);
  202319. #endif
  202320. }
  202321. class CoreGraphicsContext : public LowLevelGraphicsContext
  202322. {
  202323. public:
  202324. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202325. : context (context_),
  202326. flipHeight (flipHeight_),
  202327. numGradientLookupEntries (0)
  202328. {
  202329. CGContextRetain (context);
  202330. CGContextSaveGState(context);
  202331. CGContextSetShouldSmoothFonts (context, true);
  202332. CGContextSetShouldAntialias (context, true);
  202333. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202334. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202335. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202336. gradientCallbacks.version = 0;
  202337. gradientCallbacks.evaluate = gradientCallback;
  202338. gradientCallbacks.releaseInfo = 0;
  202339. state = new SavedState();
  202340. }
  202341. ~CoreGraphicsContext()
  202342. {
  202343. CGContextRestoreGState (context);
  202344. CGContextRelease (context);
  202345. CGColorSpaceRelease (rgbColourSpace);
  202346. CGColorSpaceRelease (greyColourSpace);
  202347. }
  202348. bool isVectorDevice() const { return false; }
  202349. void setOrigin (int x, int y)
  202350. {
  202351. CGContextTranslateCTM (context, x, -y);
  202352. }
  202353. bool clipToRectangle (const Rectangle<int>& r)
  202354. {
  202355. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202356. return ! isClipEmpty();
  202357. }
  202358. bool clipToRectangleList (const RectangleList& clipRegion)
  202359. {
  202360. if (clipRegion.isEmpty())
  202361. {
  202362. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202363. return false;
  202364. }
  202365. else
  202366. {
  202367. const int numRects = clipRegion.getNumRectangles();
  202368. HeapBlock <CGRect> rects (numRects);
  202369. for (int i = 0; i < numRects; ++i)
  202370. {
  202371. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202372. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202373. }
  202374. CGContextClipToRects (context, rects, numRects);
  202375. return ! isClipEmpty();
  202376. }
  202377. }
  202378. void excludeClipRectangle (const Rectangle<int>& r)
  202379. {
  202380. RectangleList remaining (getClipBounds());
  202381. remaining.subtract (r);
  202382. clipToRectangleList (remaining);
  202383. }
  202384. void clipToPath (const Path& path, const AffineTransform& transform)
  202385. {
  202386. createPath (path, transform);
  202387. CGContextClip (context);
  202388. }
  202389. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202390. {
  202391. if (! transform.isSingularity())
  202392. {
  202393. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202394. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202395. flip();
  202396. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202397. applyTransform (t);
  202398. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202399. CGContextClipToMask (context, r, image);
  202400. applyTransform (t.inverted());
  202401. flip();
  202402. CGImageRelease (image);
  202403. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202404. }
  202405. }
  202406. bool clipRegionIntersects (const Rectangle<int>& r)
  202407. {
  202408. return getClipBounds().intersects (r);
  202409. }
  202410. const Rectangle<int> getClipBounds() const
  202411. {
  202412. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202413. return Rectangle<int> (roundToInt (bounds.origin.x),
  202414. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202415. roundToInt (bounds.size.width),
  202416. roundToInt (bounds.size.height));
  202417. }
  202418. bool isClipEmpty() const
  202419. {
  202420. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202421. }
  202422. void saveState()
  202423. {
  202424. CGContextSaveGState (context);
  202425. stateStack.add (new SavedState (*state));
  202426. }
  202427. void restoreState()
  202428. {
  202429. CGContextRestoreGState (context);
  202430. SavedState* const top = stateStack.getLast();
  202431. if (top != 0)
  202432. {
  202433. state = top;
  202434. stateStack.removeLast (1, false);
  202435. }
  202436. else
  202437. {
  202438. jassertfalse // trying to pop with an empty stack!
  202439. }
  202440. }
  202441. void setFill (const FillType& fillType)
  202442. {
  202443. state->fillType = fillType;
  202444. if (fillType.isColour())
  202445. {
  202446. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202447. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202448. CGContextSetAlpha (context, 1.0f);
  202449. }
  202450. }
  202451. void setOpacity (float newOpacity)
  202452. {
  202453. state->fillType.setOpacity (newOpacity);
  202454. setFill (state->fillType);
  202455. }
  202456. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202457. {
  202458. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202459. ? kCGInterpolationLow
  202460. : kCGInterpolationHigh);
  202461. }
  202462. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202463. {
  202464. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202465. if (replaceExistingContents)
  202466. {
  202467. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202468. CGContextClearRect (context, cgRect);
  202469. #else
  202470. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202471. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202472. CGContextClearRect (context, cgRect);
  202473. else
  202474. #endif
  202475. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202476. #endif
  202477. fillRect (r, false);
  202478. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202479. }
  202480. else
  202481. {
  202482. if (state->fillType.isColour())
  202483. {
  202484. CGContextFillRect (context, cgRect);
  202485. }
  202486. else if (state->fillType.isGradient())
  202487. {
  202488. CGContextSaveGState (context);
  202489. CGContextClipToRect (context, cgRect);
  202490. drawGradient();
  202491. CGContextRestoreGState (context);
  202492. }
  202493. else
  202494. {
  202495. CGContextSaveGState (context);
  202496. CGContextClipToRect (context, cgRect);
  202497. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202498. CGContextRestoreGState (context);
  202499. }
  202500. }
  202501. }
  202502. void fillPath (const Path& path, const AffineTransform& transform)
  202503. {
  202504. CGContextSaveGState (context);
  202505. if (state->fillType.isColour())
  202506. {
  202507. flip();
  202508. applyTransform (transform);
  202509. createPath (path);
  202510. if (path.isUsingNonZeroWinding())
  202511. CGContextFillPath (context);
  202512. else
  202513. CGContextEOFillPath (context);
  202514. }
  202515. else
  202516. {
  202517. createPath (path, transform);
  202518. if (path.isUsingNonZeroWinding())
  202519. CGContextClip (context);
  202520. else
  202521. CGContextEOClip (context);
  202522. if (state->fillType.isGradient())
  202523. drawGradient();
  202524. else
  202525. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202526. }
  202527. CGContextRestoreGState (context);
  202528. }
  202529. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202530. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202531. {
  202532. jassert (sourceImage.getBounds().contains (srcClip));
  202533. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202534. CGImageRef image = fullImage;
  202535. if (srcClip != sourceImage.getBounds())
  202536. {
  202537. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202538. srcClip.getWidth(), srcClip.getHeight()));
  202539. CGImageRelease (fullImage);
  202540. }
  202541. CGContextSaveGState (context);
  202542. CGContextSetAlpha (context, state->fillType.getOpacity());
  202543. flip();
  202544. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202545. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202546. if (fillEntireClipAsTiles)
  202547. {
  202548. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202549. CGContextDrawTiledImage (context, imageRect, image);
  202550. #else
  202551. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202552. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202553. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202554. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202555. CGContextDrawTiledImage (context, imageRect, image);
  202556. else
  202557. #endif
  202558. {
  202559. // Fallback to manually doing a tiled fill on 10.4
  202560. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202561. const int iw = srcClip.getWidth();
  202562. const int ih = srcClip.getHeight();
  202563. int x = 0, y = 0;
  202564. while (x > clip.origin.x) x -= iw;
  202565. while (y > clip.origin.y) y -= ih;
  202566. const int right = (int) (clip.origin.x + clip.size.width);
  202567. const int bottom = (int) (clip.origin.y + clip.size.height);
  202568. while (y < bottom)
  202569. {
  202570. for (int x2 = x; x2 < right; x2 += iw)
  202571. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202572. y += ih;
  202573. }
  202574. }
  202575. #endif
  202576. }
  202577. else
  202578. {
  202579. CGContextDrawImage (context, imageRect, image);
  202580. }
  202581. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202582. CGContextRestoreGState (context);
  202583. }
  202584. void drawLine (double x1, double y1, double x2, double y2)
  202585. {
  202586. CGContextSetLineCap (context, kCGLineCapSquare);
  202587. CGContextSetLineWidth (context, 1.0f);
  202588. CGContextSetRGBStrokeColor (context,
  202589. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202590. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202591. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  202592. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  202593. CGContextStrokeLineSegments (context, line, 1);
  202594. }
  202595. void drawVerticalLine (const int x, double top, double bottom)
  202596. {
  202597. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202598. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202599. #else
  202600. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202601. // the x co-ord slightly to trick it..
  202602. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202603. #endif
  202604. }
  202605. void drawHorizontalLine (const int y, double left, double right)
  202606. {
  202607. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202608. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202609. #else
  202610. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202611. // the x co-ord slightly to trick it..
  202612. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202613. #endif
  202614. }
  202615. void setFont (const Font& newFont)
  202616. {
  202617. if (state->font != newFont)
  202618. {
  202619. state->fontRef = 0;
  202620. state->font = newFont;
  202621. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202622. if (mf != 0)
  202623. {
  202624. state->fontRef = mf->fontRef;
  202625. CGContextSetFont (context, state->fontRef);
  202626. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202627. state->fontTransform = mf->renderingTransform;
  202628. state->fontTransform.a *= state->font.getHorizontalScale();
  202629. CGContextSetTextMatrix (context, state->fontTransform);
  202630. }
  202631. }
  202632. }
  202633. const Font getFont()
  202634. {
  202635. return state->font;
  202636. }
  202637. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202638. {
  202639. if (state->fontRef != 0 && state->fillType.isColour())
  202640. {
  202641. if (transform.isOnlyTranslation())
  202642. {
  202643. CGGlyph g = glyphNumber;
  202644. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202645. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202646. }
  202647. else
  202648. {
  202649. CGContextSaveGState (context);
  202650. flip();
  202651. applyTransform (transform);
  202652. CGAffineTransform t = state->fontTransform;
  202653. t.d = -t.d;
  202654. CGContextSetTextMatrix (context, t);
  202655. CGGlyph g = glyphNumber;
  202656. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202657. CGContextSetTextMatrix (context, state->fontTransform);
  202658. CGContextRestoreGState (context);
  202659. }
  202660. }
  202661. else
  202662. {
  202663. Path p;
  202664. Font& f = state->font;
  202665. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202666. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202667. .followedBy (transform));
  202668. }
  202669. }
  202670. private:
  202671. CGContextRef context;
  202672. const float flipHeight;
  202673. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202674. CGFunctionCallbacks gradientCallbacks;
  202675. struct SavedState
  202676. {
  202677. SavedState()
  202678. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202679. {
  202680. }
  202681. SavedState (const SavedState& other)
  202682. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202683. fontTransform (other.fontTransform)
  202684. {
  202685. }
  202686. ~SavedState()
  202687. {
  202688. }
  202689. FillType fillType;
  202690. Font font;
  202691. CGFontRef fontRef;
  202692. CGAffineTransform fontTransform;
  202693. };
  202694. ScopedPointer <SavedState> state;
  202695. OwnedArray <SavedState> stateStack;
  202696. HeapBlock <PixelARGB> gradientLookupTable;
  202697. int numGradientLookupEntries;
  202698. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202699. {
  202700. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202701. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202702. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202703. colour.unpremultiply();
  202704. outData[0] = colour.getRed() / 255.0f;
  202705. outData[1] = colour.getGreen() / 255.0f;
  202706. outData[2] = colour.getBlue() / 255.0f;
  202707. outData[3] = colour.getAlpha() / 255.0f;
  202708. }
  202709. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202710. {
  202711. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202712. --numGradientLookupEntries;
  202713. CGShadingRef result = 0;
  202714. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202715. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202716. if (gradient.isRadial)
  202717. {
  202718. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202719. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202720. function, true, true);
  202721. }
  202722. else
  202723. {
  202724. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202725. CGPointMake (gradient.x2, gradient.y2),
  202726. function, true, true);
  202727. }
  202728. CGFunctionRelease (function);
  202729. return result;
  202730. }
  202731. void drawGradient()
  202732. {
  202733. flip();
  202734. applyTransform (state->fillType.transform);
  202735. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202736. // you draw a gradient with high quality interp enabled).
  202737. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202738. CGContextSetAlpha (context, state->fillType.getOpacity());
  202739. CGContextDrawShading (context, shading);
  202740. CGShadingRelease (shading);
  202741. }
  202742. void createPath (const Path& path) const
  202743. {
  202744. CGContextBeginPath (context);
  202745. Path::Iterator i (path);
  202746. while (i.next())
  202747. {
  202748. switch (i.elementType)
  202749. {
  202750. case Path::Iterator::startNewSubPath:
  202751. CGContextMoveToPoint (context, i.x1, i.y1);
  202752. break;
  202753. case Path::Iterator::lineTo:
  202754. CGContextAddLineToPoint (context, i.x1, i.y1);
  202755. break;
  202756. case Path::Iterator::quadraticTo:
  202757. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202758. break;
  202759. case Path::Iterator::cubicTo:
  202760. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202761. break;
  202762. case Path::Iterator::closePath:
  202763. CGContextClosePath (context); break;
  202764. default:
  202765. jassertfalse
  202766. break;
  202767. }
  202768. }
  202769. }
  202770. void createPath (const Path& path, const AffineTransform& transform) const
  202771. {
  202772. CGContextBeginPath (context);
  202773. Path::Iterator i (path);
  202774. while (i.next())
  202775. {
  202776. switch (i.elementType)
  202777. {
  202778. case Path::Iterator::startNewSubPath:
  202779. transform.transformPoint (i.x1, i.y1);
  202780. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202781. break;
  202782. case Path::Iterator::lineTo:
  202783. transform.transformPoint (i.x1, i.y1);
  202784. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202785. break;
  202786. case Path::Iterator::quadraticTo:
  202787. transform.transformPoint (i.x1, i.y1);
  202788. transform.transformPoint (i.x2, i.y2);
  202789. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202790. break;
  202791. case Path::Iterator::cubicTo:
  202792. transform.transformPoint (i.x1, i.y1);
  202793. transform.transformPoint (i.x2, i.y2);
  202794. transform.transformPoint (i.x3, i.y3);
  202795. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202796. break;
  202797. case Path::Iterator::closePath:
  202798. CGContextClosePath (context); break;
  202799. default:
  202800. jassertfalse
  202801. break;
  202802. }
  202803. }
  202804. }
  202805. static Image* createAlphaChannelImage (const Image& im)
  202806. {
  202807. if (im.getFormat() == Image::SingleChannel)
  202808. return const_cast <Image*> (&im);
  202809. return im.createCopyOfAlphaChannel();
  202810. }
  202811. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202812. {
  202813. if (im.getFormat() != Image::SingleChannel)
  202814. delete alphaIm;
  202815. }
  202816. void flip() const
  202817. {
  202818. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202819. }
  202820. void applyTransform (const AffineTransform& transform) const
  202821. {
  202822. CGAffineTransform t;
  202823. t.a = transform.mat00;
  202824. t.b = transform.mat10;
  202825. t.c = transform.mat01;
  202826. t.d = transform.mat11;
  202827. t.tx = transform.mat02;
  202828. t.ty = transform.mat12;
  202829. CGContextConcatCTM (context, t);
  202830. }
  202831. float flipY (float y) const
  202832. {
  202833. return flipHeight - y;
  202834. }
  202835. };
  202836. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202837. {
  202838. return new CoreGraphicsContext (context, imageHeight);
  202839. }
  202840. #endif
  202841. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202842. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202843. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202844. // compiled on its own).
  202845. #if JUCE_INCLUDED_FILE
  202846. class UIViewComponentPeer;
  202847. END_JUCE_NAMESPACE
  202848. #define JuceUIView MakeObjCClassName(JuceUIView)
  202849. @interface JuceUIView : UIView
  202850. {
  202851. @public
  202852. UIViewComponentPeer* owner;
  202853. }
  202854. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202855. - (void) dealloc;
  202856. - (void) drawRect: (CGRect) r;
  202857. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202858. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202859. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202860. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202861. - (BOOL) becomeFirstResponder;
  202862. - (BOOL) resignFirstResponder;
  202863. - (BOOL) canBecomeFirstResponder;
  202864. - (void) asyncRepaint: (id) rect;
  202865. @end
  202866. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202867. @interface JuceUIWindow : UIWindow
  202868. {
  202869. @private
  202870. UIViewComponentPeer* owner;
  202871. bool isZooming;
  202872. }
  202873. - (void) setOwner: (UIViewComponentPeer*) owner;
  202874. - (void) becomeKeyWindow;
  202875. @end
  202876. BEGIN_JUCE_NAMESPACE
  202877. class UIViewComponentPeer : public ComponentPeer
  202878. {
  202879. public:
  202880. UIViewComponentPeer (Component* const component,
  202881. const int windowStyleFlags,
  202882. UIView* viewToAttachTo);
  202883. ~UIViewComponentPeer();
  202884. void* getNativeHandle() const;
  202885. void setVisible (bool shouldBeVisible);
  202886. void setTitle (const String& title);
  202887. void setPosition (int x, int y);
  202888. void setSize (int w, int h);
  202889. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  202890. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  202891. void getBounds (int& x, int& y, int& w, int& h) const;
  202892. const Point<int> getScreenPosition() const;
  202893. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202894. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202895. void setMinimised (bool shouldBeMinimised);
  202896. bool isMinimised() const;
  202897. void setFullScreen (bool shouldBeFullScreen);
  202898. bool isFullScreen() const;
  202899. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  202900. const BorderSize getFrameSize() const;
  202901. bool setAlwaysOnTop (bool alwaysOnTop);
  202902. void toFront (bool makeActiveWindow);
  202903. void toBehind (ComponentPeer* other);
  202904. void setIcon (const Image& newIcon);
  202905. virtual void drawRect (CGRect r);
  202906. virtual bool canBecomeKeyWindow();
  202907. virtual bool windowShouldClose();
  202908. virtual void redirectMovedOrResized();
  202909. virtual CGRect constrainRect (CGRect r);
  202910. virtual void viewFocusGain();
  202911. virtual void viewFocusLoss();
  202912. bool isFocused() const;
  202913. void grabFocus();
  202914. void textInputRequired (const Point<int>& position);
  202915. void repaint (int x, int y, int w, int h);
  202916. void performAnyPendingRepaintsNow();
  202917. juce_UseDebuggingNewOperator
  202918. UIWindow* window;
  202919. JuceUIView* view;
  202920. bool isSharedWindow, fullScreen, insideDrawRect;
  202921. };
  202922. END_JUCE_NAMESPACE
  202923. @implementation JuceUIView
  202924. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202925. withFrame: (CGRect) frame
  202926. {
  202927. [super initWithFrame: frame];
  202928. owner = owner_;
  202929. return self;
  202930. }
  202931. - (void) dealloc
  202932. {
  202933. [super dealloc];
  202934. }
  202935. - (void) drawRect: (CGRect) r
  202936. {
  202937. if (owner != 0)
  202938. owner->drawRect (r);
  202939. }
  202940. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  202941. {
  202942. return false;
  202943. }
  202944. static int currentModifiers = 0;
  202945. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202946. {
  202947. return ModifierKeys (currentModifiers);
  202948. }
  202949. void ModifierKeys::updateCurrentModifiers() throw()
  202950. {
  202951. currentModifierFlags = currentModifiers;
  202952. }
  202953. static int getModifierForButtonNumber (const int num)
  202954. {
  202955. return num == 0 ? ModifierKeys::leftButtonModifier
  202956. : (num == 1 ? ModifierKeys::rightButtonModifier
  202957. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  202958. }
  202959. static int64 getMouseTime (UIEvent* e)
  202960. {
  202961. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202962. + (int64) ([e timestamp] * 1000.0);
  202963. }
  202964. int juce_lastMouseX = 0, juce_lastMouseY = 0;
  202965. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202966. {
  202967. if (owner == 0)
  202968. return;
  202969. NSArray* const t = [[event touchesForView: self] allObjects];
  202970. switch ([t count])
  202971. {
  202972. case 1: // One finger..
  202973. {
  202974. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  202975. currentModifiers |= getModifierForButtonNumber (0);
  202976. int x, y, w, h;
  202977. owner->getBounds (x, y, w, h, true);
  202978. juce_lastMouseX = x + (int) p.x;
  202979. juce_lastMouseY = y + (int) p.y;
  202980. owner->handleMouseMove ((int) p.x, (int) p.y, getMouseTime (event));
  202981. if (owner != 0)
  202982. owner->handleMouseDown ((int) p.x, (int) p.y, getMouseTime (event));
  202983. }
  202984. default:
  202985. //xxx multi-touch..
  202986. break;
  202987. }
  202988. }
  202989. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202990. {
  202991. if (owner == 0)
  202992. return;
  202993. NSArray* const t = [[event touchesForView: self] allObjects];
  202994. switch ([t count])
  202995. {
  202996. case 1: // One finger..
  202997. {
  202998. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  202999. int x, y, w, h;
  203000. owner->getBounds (x, y, w, h, true);
  203001. juce_lastMouseX = x + (int) p.x;
  203002. juce_lastMouseY = y + (int) p.y;
  203003. owner->handleMouseDrag ((int) p.x, (int) p.y, getMouseTime (event));
  203004. }
  203005. default:
  203006. //xxx multi-touch..
  203007. break;
  203008. }
  203009. }
  203010. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  203011. {
  203012. if (owner == 0)
  203013. return;
  203014. NSArray* const t = [[event touchesForView: self] allObjects];
  203015. switch ([t count])
  203016. {
  203017. case 1: // One finger..
  203018. {
  203019. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203020. int x, y, w, h;
  203021. owner->getBounds (x, y, w, h, true);
  203022. juce_lastMouseX = x + (int) p.x;
  203023. juce_lastMouseY = y + (int) p.y;
  203024. const int oldMods = currentModifiers;
  203025. currentModifiers &= ~getModifierForButtonNumber (0);
  203026. owner->handleMouseUp (oldMods, (int) p.x, (int) p.y, getMouseTime (event));
  203027. }
  203028. default:
  203029. //xxx multi-touch..
  203030. break;
  203031. }
  203032. }
  203033. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  203034. {
  203035. [self touchesEnded: touches withEvent: event];
  203036. }
  203037. - (BOOL) becomeFirstResponder
  203038. {
  203039. if (owner != 0)
  203040. owner->viewFocusGain();
  203041. return true;
  203042. }
  203043. - (BOOL) resignFirstResponder
  203044. {
  203045. if (owner != 0)
  203046. owner->viewFocusLoss();
  203047. return true;
  203048. }
  203049. - (BOOL) canBecomeFirstResponder
  203050. {
  203051. return owner != 0 && owner->canBecomeKeyWindow();
  203052. }
  203053. - (void) asyncRepaint: (id) rect
  203054. {
  203055. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  203056. [self setNeedsDisplayInRect: *r];
  203057. }
  203058. @end
  203059. @implementation JuceUIWindow
  203060. - (void) setOwner: (UIViewComponentPeer*) owner_
  203061. {
  203062. owner = owner_;
  203063. isZooming = false;
  203064. }
  203065. - (void) becomeKeyWindow
  203066. {
  203067. [super becomeKeyWindow];
  203068. if (owner != 0)
  203069. owner->grabFocus();
  203070. }
  203071. @end
  203072. BEGIN_JUCE_NAMESPACE
  203073. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  203074. const int windowStyleFlags,
  203075. UIView* viewToAttachTo)
  203076. : ComponentPeer (component, windowStyleFlags),
  203077. window (0),
  203078. view (0),
  203079. isSharedWindow (viewToAttachTo != 0),
  203080. fullScreen (false),
  203081. insideDrawRect (false)
  203082. {
  203083. CGRect r;
  203084. r.origin.x = 0;
  203085. r.origin.y = 0;
  203086. r.size.width = (float) component->getWidth();
  203087. r.size.height = (float) component->getHeight();
  203088. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  203089. if (isSharedWindow)
  203090. {
  203091. window = [viewToAttachTo window];
  203092. [viewToAttachTo addSubview: view];
  203093. setVisible (component->isVisible());
  203094. }
  203095. else
  203096. {
  203097. r.origin.x = (float) component->getX();
  203098. r.origin.y = (float) component->getY();
  203099. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  203100. window = [[JuceUIWindow alloc] init];
  203101. window.frame = r;
  203102. window.opaque = component->isOpaque();
  203103. view.opaque = component->isOpaque();
  203104. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203105. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203106. [((JuceUIWindow*) window) setOwner: this];
  203107. if (component->isAlwaysOnTop())
  203108. window.windowLevel = UIWindowLevelAlert;
  203109. [window addSubview: view];
  203110. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203111. view.hidden = ! component->isVisible();
  203112. window.hidden = ! component->isVisible();
  203113. }
  203114. setTitle (component->getName());
  203115. }
  203116. UIViewComponentPeer::~UIViewComponentPeer()
  203117. {
  203118. view->owner = 0;
  203119. [view removeFromSuperview];
  203120. [view release];
  203121. if (! isSharedWindow)
  203122. {
  203123. [((JuceUIWindow*) window) setOwner: 0];
  203124. [window release];
  203125. }
  203126. }
  203127. void* UIViewComponentPeer::getNativeHandle() const
  203128. {
  203129. return view;
  203130. }
  203131. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  203132. {
  203133. view.hidden = ! shouldBeVisible;
  203134. if (! isSharedWindow)
  203135. window.hidden = ! shouldBeVisible;
  203136. }
  203137. void UIViewComponentPeer::setTitle (const String& title)
  203138. {
  203139. // xxx is this possible?
  203140. }
  203141. void UIViewComponentPeer::setPosition (int x, int y)
  203142. {
  203143. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  203144. }
  203145. void UIViewComponentPeer::setSize (int w, int h)
  203146. {
  203147. setBounds (component->getX(), component->getY(), w, h, false);
  203148. }
  203149. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  203150. {
  203151. fullScreen = isNowFullScreen;
  203152. w = jmax (0, w);
  203153. h = jmax (0, h);
  203154. CGRect r;
  203155. r.origin.x = (float) x;
  203156. r.origin.y = (float) y;
  203157. r.size.width = (float) w;
  203158. r.size.height = (float) h;
  203159. if (isSharedWindow)
  203160. {
  203161. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203162. if ([view frame].size.width != r.size.width
  203163. || [view frame].size.height != r.size.height)
  203164. [view setNeedsDisplay];
  203165. view.frame = r;
  203166. }
  203167. else
  203168. {
  203169. window.frame = r;
  203170. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203171. }
  203172. }
  203173. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  203174. {
  203175. CGRect r = [view frame];
  203176. if (global && [view window] != 0)
  203177. {
  203178. r = [view convertRect: r toView: nil];
  203179. CGRect wr = [[view window] frame];
  203180. r.origin.x += wr.origin.x;
  203181. r.origin.y += wr.origin.y;
  203182. }
  203183. x = (int) r.origin.x;
  203184. y = (int) r.origin.y;
  203185. w = (int) r.size.width;
  203186. h = (int) r.size.height;
  203187. }
  203188. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  203189. {
  203190. getBounds (x, y, w, h, ! isSharedWindow);
  203191. }
  203192. int UIViewComponentPeer::getScreenX() const
  203193. {
  203194. int x, y, w, h;
  203195. getBounds (x, y, w, h, true);
  203196. return x;
  203197. }
  203198. int UIViewComponentPeer::getScreenY() const
  203199. {
  203200. int x, y, w, h;
  203201. getBounds (x, y, w, h, true);
  203202. return y;
  203203. }
  203204. void UIViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  203205. {
  203206. int wx, wy, ww, wh;
  203207. getBounds (wx, wy, ww, wh, true);
  203208. x += wx;
  203209. y += wy;
  203210. }
  203211. void UIViewComponentPeer::globalPositionToRelative (int& x, int& y)
  203212. {
  203213. int wx, wy, ww, wh;
  203214. getBounds (wx, wy, ww, wh, true);
  203215. x -= wx;
  203216. y -= wy;
  203217. }
  203218. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203219. {
  203220. if (constrainer != 0)
  203221. {
  203222. CGRect current = [window frame];
  203223. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203224. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203225. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203226. (int) r.size.width, (int) r.size.height);
  203227. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203228. (int) current.size.width, (int) current.size.height);
  203229. constrainer->checkBounds (pos, original,
  203230. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203231. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203232. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203233. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203234. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203235. r.origin.x = pos.getX();
  203236. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203237. r.size.width = pos.getWidth();
  203238. r.size.height = pos.getHeight();
  203239. }
  203240. return r;
  203241. }
  203242. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203243. {
  203244. // xxx
  203245. }
  203246. bool UIViewComponentPeer::isMinimised() const
  203247. {
  203248. return false;
  203249. }
  203250. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203251. {
  203252. if (! isSharedWindow)
  203253. {
  203254. Rectangle<int> r (lastNonFullscreenBounds);
  203255. setMinimised (false);
  203256. if (fullScreen != shouldBeFullScreen)
  203257. {
  203258. if (shouldBeFullScreen)
  203259. r = Desktop::getInstance().getMainMonitorArea();
  203260. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203261. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203262. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203263. }
  203264. }
  203265. }
  203266. bool UIViewComponentPeer::isFullScreen() const
  203267. {
  203268. return fullScreen;
  203269. }
  203270. bool UIViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  203271. {
  203272. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  203273. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  203274. return false;
  203275. CGPoint p;
  203276. p.x = (float) x;
  203277. p.y = (float) y;
  203278. UIView* v = [view hitTest: p withEvent: nil];
  203279. if (trueIfInAChildWindow)
  203280. return v != nil;
  203281. return v == view;
  203282. }
  203283. const BorderSize UIViewComponentPeer::getFrameSize() const
  203284. {
  203285. BorderSize b;
  203286. if (! isSharedWindow)
  203287. {
  203288. CGRect v = [view convertRect: [view frame] toView: nil];
  203289. CGRect w = [window frame];
  203290. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203291. b.setBottom ((int) v.origin.y);
  203292. b.setLeft ((int) v.origin.x);
  203293. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203294. }
  203295. return b;
  203296. }
  203297. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203298. {
  203299. if (! isSharedWindow)
  203300. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203301. return true;
  203302. }
  203303. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203304. {
  203305. if (isSharedWindow)
  203306. [[view superview] bringSubviewToFront: view];
  203307. if (window != 0 && component->isVisible())
  203308. [window makeKeyAndVisible];
  203309. }
  203310. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203311. {
  203312. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203313. if (isSharedWindow)
  203314. {
  203315. [[view superview] insertSubview: view belowSubview: o->view];
  203316. }
  203317. else
  203318. {
  203319. jassertfalse // don't know how to do this
  203320. }
  203321. }
  203322. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203323. {
  203324. // to do..
  203325. }
  203326. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203327. void UIViewComponentPeer::viewFocusGain()
  203328. {
  203329. if (currentlyFocusedPeer != this)
  203330. {
  203331. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203332. currentlyFocusedPeer->handleFocusLoss();
  203333. currentlyFocusedPeer = this;
  203334. handleFocusGain();
  203335. }
  203336. }
  203337. void UIViewComponentPeer::viewFocusLoss()
  203338. {
  203339. if (currentlyFocusedPeer == this)
  203340. {
  203341. currentlyFocusedPeer = 0;
  203342. handleFocusLoss();
  203343. }
  203344. }
  203345. void juce_HandleProcessFocusChange()
  203346. {
  203347. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203348. {
  203349. if (Process::isForegroundProcess())
  203350. {
  203351. currentlyFocusedPeer->handleFocusGain();
  203352. ComponentPeer::bringModalComponentToFront();
  203353. }
  203354. else
  203355. {
  203356. currentlyFocusedPeer->handleFocusLoss();
  203357. // turn kiosk mode off if we lose focus..
  203358. Desktop::getInstance().setKioskModeComponent (0);
  203359. }
  203360. }
  203361. }
  203362. bool UIViewComponentPeer::isFocused() const
  203363. {
  203364. return isSharedWindow ? this == currentlyFocusedPeer
  203365. : (window != 0 && [window isKeyWindow]);
  203366. }
  203367. void UIViewComponentPeer::grabFocus()
  203368. {
  203369. if (window != 0)
  203370. {
  203371. [window makeKeyWindow];
  203372. viewFocusGain();
  203373. }
  203374. }
  203375. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203376. {
  203377. }
  203378. void UIViewComponentPeer::drawRect (CGRect r)
  203379. {
  203380. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203381. return;
  203382. CGContextRef cg = UIGraphicsGetCurrentContext();
  203383. if (! component->isOpaque())
  203384. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203385. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203386. CoreGraphicsContext g (cg, view.bounds.size.height);
  203387. insideDrawRect = true;
  203388. handlePaint (g);
  203389. insideDrawRect = false;
  203390. }
  203391. bool UIViewComponentPeer::canBecomeKeyWindow()
  203392. {
  203393. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203394. }
  203395. bool UIViewComponentPeer::windowShouldClose()
  203396. {
  203397. if (! isValidPeer (this))
  203398. return YES;
  203399. handleUserClosingWindow();
  203400. return NO;
  203401. }
  203402. void UIViewComponentPeer::redirectMovedOrResized()
  203403. {
  203404. handleMovedOrResized();
  203405. }
  203406. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203407. {
  203408. }
  203409. class AsyncRepaintMessage : public CallbackMessage
  203410. {
  203411. public:
  203412. UIViewComponentPeer* const peer;
  203413. const Rectangle<int> rect;
  203414. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203415. : peer (peer_), rect (rect_)
  203416. {
  203417. }
  203418. void messageCallback()
  203419. {
  203420. if (ComponentPeer::isValidPeer (peer))
  203421. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203422. }
  203423. };
  203424. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203425. {
  203426. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203427. {
  203428. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203429. }
  203430. else
  203431. {
  203432. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203433. }
  203434. }
  203435. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203436. {
  203437. }
  203438. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203439. {
  203440. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203441. }
  203442. Image* juce_createIconForFile (const File& file)
  203443. {
  203444. return 0;
  203445. }
  203446. bool Desktop::canUseSemiTransparentWindows() throw()
  203447. {
  203448. return true;
  203449. }
  203450. const Point<int> Desktop::getMousePosition()
  203451. {
  203452. return Point<int> (juce_lastMouseX, juce_lastMouseY);
  203453. }
  203454. void Desktop::setMousePosition (const Point<int>&)
  203455. {
  203456. }
  203457. const int KeyPress::spaceKey = ' ';
  203458. const int KeyPress::returnKey = 0x0d;
  203459. const int KeyPress::escapeKey = 0x1b;
  203460. const int KeyPress::backspaceKey = 0x7f;
  203461. const int KeyPress::leftKey = 0x1000;
  203462. const int KeyPress::rightKey = 0x1001;
  203463. const int KeyPress::upKey = 0x1002;
  203464. const int KeyPress::downKey = 0x1003;
  203465. const int KeyPress::pageUpKey = 0x1004;
  203466. const int KeyPress::pageDownKey = 0x1005;
  203467. const int KeyPress::endKey = 0x1006;
  203468. const int KeyPress::homeKey = 0x1007;
  203469. const int KeyPress::deleteKey = 0x1008;
  203470. const int KeyPress::insertKey = -1;
  203471. const int KeyPress::tabKey = 9;
  203472. const int KeyPress::F1Key = 0x2001;
  203473. const int KeyPress::F2Key = 0x2002;
  203474. const int KeyPress::F3Key = 0x2003;
  203475. const int KeyPress::F4Key = 0x2004;
  203476. const int KeyPress::F5Key = 0x2005;
  203477. const int KeyPress::F6Key = 0x2006;
  203478. const int KeyPress::F7Key = 0x2007;
  203479. const int KeyPress::F8Key = 0x2008;
  203480. const int KeyPress::F9Key = 0x2009;
  203481. const int KeyPress::F10Key = 0x200a;
  203482. const int KeyPress::F11Key = 0x200b;
  203483. const int KeyPress::F12Key = 0x200c;
  203484. const int KeyPress::F13Key = 0x200d;
  203485. const int KeyPress::F14Key = 0x200e;
  203486. const int KeyPress::F15Key = 0x200f;
  203487. const int KeyPress::F16Key = 0x2010;
  203488. const int KeyPress::numberPad0 = 0x30020;
  203489. const int KeyPress::numberPad1 = 0x30021;
  203490. const int KeyPress::numberPad2 = 0x30022;
  203491. const int KeyPress::numberPad3 = 0x30023;
  203492. const int KeyPress::numberPad4 = 0x30024;
  203493. const int KeyPress::numberPad5 = 0x30025;
  203494. const int KeyPress::numberPad6 = 0x30026;
  203495. const int KeyPress::numberPad7 = 0x30027;
  203496. const int KeyPress::numberPad8 = 0x30028;
  203497. const int KeyPress::numberPad9 = 0x30029;
  203498. const int KeyPress::numberPadAdd = 0x3002a;
  203499. const int KeyPress::numberPadSubtract = 0x3002b;
  203500. const int KeyPress::numberPadMultiply = 0x3002c;
  203501. const int KeyPress::numberPadDivide = 0x3002d;
  203502. const int KeyPress::numberPadSeparator = 0x3002e;
  203503. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203504. const int KeyPress::numberPadEquals = 0x30030;
  203505. const int KeyPress::numberPadDelete = 0x30031;
  203506. const int KeyPress::playKey = 0x30000;
  203507. const int KeyPress::stopKey = 0x30001;
  203508. const int KeyPress::fastForwardKey = 0x30002;
  203509. const int KeyPress::rewindKey = 0x30003;
  203510. #endif
  203511. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203512. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203513. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203514. // compiled on its own).
  203515. #if JUCE_INCLUDED_FILE
  203516. struct CallbackMessagePayload
  203517. {
  203518. MessageCallbackFunction* function;
  203519. void* parameter;
  203520. void* volatile result;
  203521. bool volatile hasBeenExecuted;
  203522. };
  203523. END_JUCE_NAMESPACE
  203524. using namespace JUCE_NAMESPACE;
  203525. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203526. {
  203527. }
  203528. - (JuceAppDelegate*) init;
  203529. - (void) dealloc;
  203530. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203531. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203532. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203533. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203534. - (void) customEvent: (id) data;
  203535. - (void) performCallback: (id) info;
  203536. @end
  203537. @implementation JuceAppDelegate
  203538. - (JuceAppDelegate*) init
  203539. {
  203540. [super init];
  203541. [[UIApplication sharedApplication] setDelegate: self];
  203542. return self;
  203543. }
  203544. - (void) dealloc
  203545. {
  203546. [[UIApplication sharedApplication] setDelegate: nil];
  203547. [super dealloc];
  203548. }
  203549. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203550. {
  203551. if (JUCEApplication::getInstance() != 0)
  203552. {
  203553. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203554. return YES;
  203555. }
  203556. return NO;
  203557. }
  203558. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203559. {
  203560. juce_HandleProcessFocusChange();
  203561. }
  203562. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203563. {
  203564. juce_HandleProcessFocusChange();
  203565. }
  203566. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203567. {
  203568. juce_HandleProcessFocusChange();
  203569. }
  203570. - (void) customEvent: (id) n
  203571. {
  203572. NSData* data = (NSData*) n;
  203573. void* message = 0;
  203574. [data getBytes: &message length: sizeof (message)];
  203575. [data release];
  203576. if (message != 0)
  203577. MessageManager::getInstance()->deliverMessage (message);
  203578. }
  203579. - (void) performCallback: (id) info
  203580. {
  203581. if ([info isKindOfClass: [NSData class]])
  203582. {
  203583. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203584. if (pl != 0)
  203585. {
  203586. pl->result = (*pl->function) (pl->parameter);
  203587. pl->hasBeenExecuted = true;
  203588. }
  203589. }
  203590. else
  203591. {
  203592. jassertfalse // should never get here!
  203593. }
  203594. }
  203595. @end
  203596. BEGIN_JUCE_NAMESPACE
  203597. static JuceAppDelegate* juceAppDelegate = 0;
  203598. void MessageManager::runDispatchLoop()
  203599. {
  203600. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203601. runDispatchLoopUntil (-1);
  203602. }
  203603. void MessageManager::stopDispatchLoop()
  203604. {
  203605. exit (0); // iPhone apps get no mercy..
  203606. }
  203607. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203608. {
  203609. const ScopedAutoReleasePool pool;
  203610. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203611. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203612. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203613. while (! quitMessagePosted)
  203614. {
  203615. const ScopedAutoReleasePool pool;
  203616. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203617. beforeDate: endDate];
  203618. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203619. break;
  203620. }
  203621. return ! quitMessagePosted;
  203622. }
  203623. static CFRunLoopRef runLoop = 0;
  203624. static CFRunLoopSourceRef runLoopSource = 0;
  203625. static Array <void*, CriticalSection>* pendingMessages = 0;
  203626. static void runLoopSourceCallback (void*)
  203627. {
  203628. if (pendingMessages != 0)
  203629. {
  203630. int numDispatched = 0;
  203631. do
  203632. {
  203633. void* const nextMessage = pendingMessages->remove (0);
  203634. if (nextMessage == 0)
  203635. return;
  203636. const ScopedAutoReleasePool pool;
  203637. MessageManager::getInstance()->deliverMessage (nextMessage);
  203638. } while (++numDispatched <= 4);
  203639. CFRunLoopSourceSignal (runLoopSource);
  203640. CFRunLoopWakeUp (runLoop);
  203641. }
  203642. }
  203643. void MessageManager::doPlatformSpecificInitialisation()
  203644. {
  203645. pendingMessages = new Array <void*, CriticalSection>();
  203646. runLoop = CFRunLoopGetCurrent();
  203647. CFRunLoopSourceContext sourceContext;
  203648. zerostruct (sourceContext);
  203649. sourceContext.perform = runLoopSourceCallback;
  203650. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203651. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203652. if (juceAppDelegate == 0)
  203653. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203654. }
  203655. void MessageManager::doPlatformSpecificShutdown()
  203656. {
  203657. CFRunLoopSourceInvalidate (runLoopSource);
  203658. CFRelease (runLoopSource);
  203659. runLoopSource = 0;
  203660. if (pendingMessages != 0)
  203661. {
  203662. while (pendingMessages->size() > 0)
  203663. delete ((Message*) pendingMessages->remove(0));
  203664. deleteAndZero (pendingMessages);
  203665. }
  203666. if (juceAppDelegate != 0)
  203667. {
  203668. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203669. [juceAppDelegate release];
  203670. juceAppDelegate = 0;
  203671. }
  203672. }
  203673. bool juce_postMessageToSystemQueue (void* message)
  203674. {
  203675. if (pendingMessages != 0)
  203676. {
  203677. pendingMessages->add (message);
  203678. CFRunLoopSourceSignal (runLoopSource);
  203679. CFRunLoopWakeUp (runLoop);
  203680. }
  203681. return true;
  203682. }
  203683. void MessageManager::broadcastMessage (const String& value) throw()
  203684. {
  203685. }
  203686. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203687. void* data)
  203688. {
  203689. if (isThisTheMessageThread())
  203690. {
  203691. return (*callback) (data);
  203692. }
  203693. else
  203694. {
  203695. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203696. // deadlock because the message manager is blocked from running, so can never
  203697. // call your function..
  203698. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203699. const ScopedAutoReleasePool pool;
  203700. CallbackMessagePayload cmp;
  203701. cmp.function = callback;
  203702. cmp.parameter = data;
  203703. cmp.result = 0;
  203704. cmp.hasBeenExecuted = false;
  203705. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203706. withObject: [NSData dataWithBytesNoCopy: &cmp
  203707. length: sizeof (cmp)
  203708. freeWhenDone: NO]
  203709. waitUntilDone: YES];
  203710. return cmp.result;
  203711. }
  203712. }
  203713. #endif
  203714. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203715. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203716. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203717. // compiled on its own).
  203718. #if JUCE_INCLUDED_FILE
  203719. #if JUCE_MAC
  203720. END_JUCE_NAMESPACE
  203721. using namespace JUCE_NAMESPACE;
  203722. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203723. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203724. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203725. #else
  203726. @interface JuceFileChooserDelegate : NSObject
  203727. #endif
  203728. {
  203729. StringArray* filters;
  203730. }
  203731. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203732. - (void) dealloc;
  203733. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203734. @end
  203735. @implementation JuceFileChooserDelegate
  203736. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203737. {
  203738. [super init];
  203739. filters = filters_;
  203740. return self;
  203741. }
  203742. - (void) dealloc
  203743. {
  203744. delete filters;
  203745. [super dealloc];
  203746. }
  203747. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203748. {
  203749. const File f (nsStringToJuce (filename));
  203750. for (int i = filters->size(); --i >= 0;)
  203751. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203752. return true;
  203753. return f.isDirectory();
  203754. }
  203755. @end
  203756. BEGIN_JUCE_NAMESPACE
  203757. void FileChooser::showPlatformDialog (Array<File>& results,
  203758. const String& title,
  203759. const File& currentFileOrDirectory,
  203760. const String& filter,
  203761. bool selectsDirectory,
  203762. bool selectsFiles,
  203763. bool isSaveDialogue,
  203764. bool warnAboutOverwritingExistingFiles,
  203765. bool selectMultipleFiles,
  203766. FilePreviewComponent* extraInfoComponent)
  203767. {
  203768. const ScopedAutoReleasePool pool;
  203769. StringArray* filters = new StringArray();
  203770. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  203771. filters->trim();
  203772. filters->removeEmptyStrings();
  203773. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203774. [delegate autorelease];
  203775. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203776. : [NSOpenPanel openPanel];
  203777. [panel setTitle: juceStringToNS (title)];
  203778. if (! isSaveDialogue)
  203779. {
  203780. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203781. [openPanel setCanChooseDirectories: selectsDirectory];
  203782. [openPanel setCanChooseFiles: selectsFiles];
  203783. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203784. }
  203785. [panel setDelegate: delegate];
  203786. if (isSaveDialogue || selectsDirectory)
  203787. [panel setCanCreateDirectories: YES];
  203788. String directory, filename;
  203789. if (currentFileOrDirectory.isDirectory())
  203790. {
  203791. directory = currentFileOrDirectory.getFullPathName();
  203792. }
  203793. else
  203794. {
  203795. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203796. filename = currentFileOrDirectory.getFileName();
  203797. }
  203798. if ([panel runModalForDirectory: juceStringToNS (directory)
  203799. file: juceStringToNS (filename)]
  203800. == NSOKButton)
  203801. {
  203802. if (isSaveDialogue)
  203803. {
  203804. results.add (File (nsStringToJuce ([panel filename])));
  203805. }
  203806. else
  203807. {
  203808. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203809. NSArray* urls = [openPanel filenames];
  203810. for (unsigned int i = 0; i < [urls count]; ++i)
  203811. {
  203812. NSString* f = [urls objectAtIndex: i];
  203813. results.add (File (nsStringToJuce (f)));
  203814. }
  203815. }
  203816. }
  203817. [panel setDelegate: nil];
  203818. }
  203819. #else
  203820. void FileChooser::showPlatformDialog (Array<File>& results,
  203821. const String& title,
  203822. const File& currentFileOrDirectory,
  203823. const String& filter,
  203824. bool selectsDirectory,
  203825. bool selectsFiles,
  203826. bool isSaveDialogue,
  203827. bool warnAboutOverwritingExistingFiles,
  203828. bool selectMultipleFiles,
  203829. FilePreviewComponent* extraInfoComponent)
  203830. {
  203831. const ScopedAutoReleasePool pool;
  203832. jassertfalse //xxx to do
  203833. }
  203834. #endif
  203835. #endif
  203836. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203837. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203838. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203839. // compiled on its own).
  203840. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203841. #if JUCE_MAC
  203842. END_JUCE_NAMESPACE
  203843. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203844. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203845. {
  203846. CriticalSection* contextLock;
  203847. bool needsUpdate;
  203848. }
  203849. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203850. - (bool) makeActive;
  203851. - (void) makeInactive;
  203852. - (void) reshape;
  203853. @end
  203854. @implementation ThreadSafeNSOpenGLView
  203855. - (id) initWithFrame: (NSRect) frameRect
  203856. pixelFormat: (NSOpenGLPixelFormat*) format
  203857. {
  203858. contextLock = new CriticalSection();
  203859. self = [super initWithFrame: frameRect pixelFormat: format];
  203860. if (self != nil)
  203861. [[NSNotificationCenter defaultCenter] addObserver: self
  203862. selector: @selector (_surfaceNeedsUpdate:)
  203863. name: NSViewGlobalFrameDidChangeNotification
  203864. object: self];
  203865. return self;
  203866. }
  203867. - (void) dealloc
  203868. {
  203869. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203870. delete contextLock;
  203871. [super dealloc];
  203872. }
  203873. - (bool) makeActive
  203874. {
  203875. const ScopedLock sl (*contextLock);
  203876. if ([self openGLContext] == 0)
  203877. return false;
  203878. [[self openGLContext] makeCurrentContext];
  203879. if (needsUpdate)
  203880. {
  203881. [super update];
  203882. needsUpdate = false;
  203883. }
  203884. return true;
  203885. }
  203886. - (void) makeInactive
  203887. {
  203888. const ScopedLock sl (*contextLock);
  203889. [NSOpenGLContext clearCurrentContext];
  203890. }
  203891. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203892. {
  203893. const ScopedLock sl (*contextLock);
  203894. needsUpdate = true;
  203895. }
  203896. - (void) update
  203897. {
  203898. const ScopedLock sl (*contextLock);
  203899. needsUpdate = true;
  203900. }
  203901. - (void) reshape
  203902. {
  203903. const ScopedLock sl (*contextLock);
  203904. needsUpdate = true;
  203905. }
  203906. @end
  203907. BEGIN_JUCE_NAMESPACE
  203908. class WindowedGLContext : public OpenGLContext
  203909. {
  203910. public:
  203911. WindowedGLContext (Component* const component,
  203912. const OpenGLPixelFormat& pixelFormat_,
  203913. NSOpenGLContext* sharedContext)
  203914. : renderContext (0),
  203915. pixelFormat (pixelFormat_)
  203916. {
  203917. jassert (component != 0);
  203918. NSOpenGLPixelFormatAttribute attribs [64];
  203919. int n = 0;
  203920. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203921. attribs[n++] = NSOpenGLPFAAccelerated;
  203922. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203923. attribs[n++] = NSOpenGLPFAColorSize;
  203924. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203925. pixelFormat.greenBits,
  203926. pixelFormat.blueBits);
  203927. attribs[n++] = NSOpenGLPFAAlphaSize;
  203928. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203929. attribs[n++] = NSOpenGLPFADepthSize;
  203930. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203931. attribs[n++] = NSOpenGLPFAStencilSize;
  203932. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203933. attribs[n++] = NSOpenGLPFAAccumSize;
  203934. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203935. pixelFormat.accumulationBufferGreenBits,
  203936. pixelFormat.accumulationBufferBlueBits,
  203937. pixelFormat.accumulationBufferAlphaBits);
  203938. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203939. attribs[n++] = NSOpenGLPFASampleBuffers;
  203940. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203941. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203942. attribs[n++] = NSOpenGLPFANoRecovery;
  203943. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203944. NSOpenGLPixelFormat* format
  203945. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203946. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203947. pixelFormat: format];
  203948. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203949. shareContext: sharedContext] autorelease];
  203950. const GLint swapInterval = 1;
  203951. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203952. [view setOpenGLContext: renderContext];
  203953. [renderContext setView: view];
  203954. [format release];
  203955. viewHolder = new NSViewComponentInternal (view, component);
  203956. }
  203957. ~WindowedGLContext()
  203958. {
  203959. makeInactive();
  203960. [renderContext clearDrawable];
  203961. viewHolder = 0;
  203962. }
  203963. bool makeActive() const throw()
  203964. {
  203965. jassert (renderContext != 0);
  203966. [view makeActive];
  203967. return isActive();
  203968. }
  203969. bool makeInactive() const throw()
  203970. {
  203971. [view makeInactive];
  203972. return true;
  203973. }
  203974. bool isActive() const throw()
  203975. {
  203976. return [NSOpenGLContext currentContext] == renderContext;
  203977. }
  203978. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203979. void* getRawContext() const throw() { return renderContext; }
  203980. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203981. {
  203982. }
  203983. void swapBuffers()
  203984. {
  203985. [renderContext flushBuffer];
  203986. }
  203987. bool setSwapInterval (const int numFramesPerSwap)
  203988. {
  203989. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203990. forParameter: NSOpenGLCPSwapInterval];
  203991. return true;
  203992. }
  203993. int getSwapInterval() const
  203994. {
  203995. GLint numFrames = 0;
  203996. [renderContext getValues: &numFrames
  203997. forParameter: NSOpenGLCPSwapInterval];
  203998. return numFrames;
  203999. }
  204000. void repaint()
  204001. {
  204002. // we need to invalidate the juce view that holds this gl view, to make it
  204003. // cause a repaint callback
  204004. NSView* v = (NSView*) viewHolder->view;
  204005. NSRect r = [v frame];
  204006. // bit of a bodge here.. if we only invalidate the area of the gl component,
  204007. // it's completely covered by the NSOpenGLView, so the OS throws away the
  204008. // repaint message, thus never causing our paint() callback, and never repainting
  204009. // the comp. So invalidating just a little bit around the edge helps..
  204010. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  204011. }
  204012. void* getNativeWindowHandle() const { return viewHolder->view; }
  204013. juce_UseDebuggingNewOperator
  204014. NSOpenGLContext* renderContext;
  204015. ThreadSafeNSOpenGLView* view;
  204016. private:
  204017. OpenGLPixelFormat pixelFormat;
  204018. ScopedPointer <NSViewComponentInternal> viewHolder;
  204019. WindowedGLContext (const WindowedGLContext&);
  204020. const WindowedGLContext& operator= (const WindowedGLContext&);
  204021. };
  204022. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204023. const OpenGLPixelFormat& pixelFormat,
  204024. const OpenGLContext* const contextToShareWith)
  204025. {
  204026. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  204027. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  204028. return (c->renderContext != 0) ? c.release() : 0;
  204029. }
  204030. void* OpenGLComponent::getNativeWindowHandle() const
  204031. {
  204032. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  204033. : 0;
  204034. }
  204035. void juce_glViewport (const int w, const int h)
  204036. {
  204037. glViewport (0, 0, w, h);
  204038. }
  204039. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204040. OwnedArray <OpenGLPixelFormat>& results)
  204041. {
  204042. /* GLint attribs [64];
  204043. int n = 0;
  204044. attribs[n++] = AGL_RGBA;
  204045. attribs[n++] = AGL_DOUBLEBUFFER;
  204046. attribs[n++] = AGL_ACCELERATED;
  204047. attribs[n++] = AGL_NO_RECOVERY;
  204048. attribs[n++] = AGL_NONE;
  204049. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  204050. while (p != 0)
  204051. {
  204052. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  204053. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  204054. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  204055. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  204056. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  204057. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  204058. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  204059. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  204060. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  204061. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  204062. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  204063. results.add (pf);
  204064. p = aglNextPixelFormat (p);
  204065. }*/
  204066. //jassertfalse //xxx can't see how you do this in cocoa!
  204067. }
  204068. #else
  204069. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204070. const OpenGLPixelFormat& pixelFormat,
  204071. const OpenGLContext* const contextToShareWith)
  204072. {
  204073. return 0;
  204074. }
  204075. void juce_glViewport (const int w, const int h)
  204076. {
  204077. //glViewport (0, 0, w, h);
  204078. }
  204079. #endif
  204080. #endif
  204081. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204082. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204083. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204084. // compiled on its own).
  204085. #if JUCE_INCLUDED_FILE
  204086. #if JUCE_MAC
  204087. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204088. {
  204089. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204090. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204091. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204092. [im release];
  204093. return (void*) c;
  204094. }
  204095. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204096. {
  204097. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  204098. jassert (im != 0);
  204099. if (im == 0)
  204100. return 0;
  204101. return juce_createMouseCursorFromImage (*im,
  204102. (int) (hx * im->getWidth()),
  204103. (int) (hy * im->getHeight()));
  204104. }
  204105. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204106. {
  204107. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204108. MemoryBlock mb;
  204109. if (f.getChildFile (filename).loadFileAsData (mb))
  204110. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204111. return 0;
  204112. }
  204113. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204114. {
  204115. const ScopedAutoReleasePool pool;
  204116. NSCursor* c = 0;
  204117. switch (type)
  204118. {
  204119. case MouseCursor::NormalCursor:
  204120. c = [NSCursor arrowCursor];
  204121. break;
  204122. case MouseCursor::NoCursor:
  204123. {
  204124. Image blank (Image::ARGB, 8, 8, true);
  204125. return juce_createMouseCursorFromImage (blank, 0, 0);
  204126. }
  204127. case MouseCursor::DraggingHandCursor:
  204128. c = [NSCursor openHandCursor];
  204129. break;
  204130. case MouseCursor::CopyingCursor:
  204131. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204132. case MouseCursor::WaitCursor:
  204133. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204134. break;
  204135. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204136. case MouseCursor::IBeamCursor:
  204137. c = [NSCursor IBeamCursor];
  204138. break;
  204139. case MouseCursor::PointingHandCursor:
  204140. c = [NSCursor pointingHandCursor];
  204141. break;
  204142. case MouseCursor::LeftRightResizeCursor:
  204143. c = [NSCursor resizeLeftRightCursor];
  204144. break;
  204145. case MouseCursor::LeftEdgeResizeCursor:
  204146. c = [NSCursor resizeLeftCursor];
  204147. break;
  204148. case MouseCursor::RightEdgeResizeCursor:
  204149. c = [NSCursor resizeRightCursor];
  204150. break;
  204151. case MouseCursor::UpDownResizeCursor:
  204152. case MouseCursor::TopEdgeResizeCursor:
  204153. case MouseCursor::BottomEdgeResizeCursor:
  204154. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204155. case MouseCursor::TopLeftCornerResizeCursor:
  204156. case MouseCursor::BottomRightCornerResizeCursor:
  204157. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204158. case MouseCursor::TopRightCornerResizeCursor:
  204159. case MouseCursor::BottomLeftCornerResizeCursor:
  204160. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204161. case MouseCursor::UpDownLeftRightResizeCursor:
  204162. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204163. case MouseCursor::CrosshairCursor:
  204164. c = [NSCursor crosshairCursor];
  204165. break;
  204166. }
  204167. [c retain];
  204168. return (void*) c;
  204169. }
  204170. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204171. {
  204172. NSCursor* c = (NSCursor*) cursorHandle;
  204173. [c release];
  204174. }
  204175. void MouseCursor::showInAllWindows() const throw()
  204176. {
  204177. showInWindow (0);
  204178. }
  204179. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204180. {
  204181. NSCursor* const c = (NSCursor*) getHandle();
  204182. [c set];
  204183. }
  204184. #else
  204185. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204186. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204187. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204188. void MouseCursor::showInAllWindows() const throw() {}
  204189. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204190. #endif
  204191. #endif
  204192. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204193. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204194. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204195. // compiled on its own).
  204196. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204197. #if JUCE_MAC
  204198. END_JUCE_NAMESPACE
  204199. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204200. @interface DownloadClickDetector : NSObject
  204201. {
  204202. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204203. }
  204204. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204205. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204206. request: (NSURLRequest*) request
  204207. frame: (WebFrame*) frame
  204208. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204209. @end
  204210. @implementation DownloadClickDetector
  204211. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204212. {
  204213. [super init];
  204214. ownerComponent = ownerComponent_;
  204215. return self;
  204216. }
  204217. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204218. request: (NSURLRequest*) request
  204219. frame: (WebFrame*) frame
  204220. decisionListener: (id <WebPolicyDecisionListener>) listener
  204221. {
  204222. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204223. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204224. [listener use];
  204225. else
  204226. [listener ignore];
  204227. }
  204228. @end
  204229. BEGIN_JUCE_NAMESPACE
  204230. class WebBrowserComponentInternal : public NSViewComponent
  204231. {
  204232. public:
  204233. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204234. {
  204235. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204236. frameName: @""
  204237. groupName: @""];
  204238. setView (webView);
  204239. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204240. [webView setPolicyDelegate: clickListener];
  204241. }
  204242. ~WebBrowserComponentInternal()
  204243. {
  204244. [webView setPolicyDelegate: nil];
  204245. [clickListener release];
  204246. setView (0);
  204247. }
  204248. void goToURL (const String& url,
  204249. const StringArray* headers,
  204250. const MemoryBlock* postData)
  204251. {
  204252. NSMutableURLRequest* r
  204253. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204254. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204255. timeoutInterval: 30.0];
  204256. if (postData != 0 && postData->getSize() > 0)
  204257. {
  204258. [r setHTTPMethod: @"POST"];
  204259. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204260. length: postData->getSize()]];
  204261. }
  204262. if (headers != 0)
  204263. {
  204264. for (int i = 0; i < headers->size(); ++i)
  204265. {
  204266. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204267. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204268. [r setValue: juceStringToNS (headerValue)
  204269. forHTTPHeaderField: juceStringToNS (headerName)];
  204270. }
  204271. }
  204272. stop();
  204273. [[webView mainFrame] loadRequest: r];
  204274. }
  204275. void goBack()
  204276. {
  204277. [webView goBack];
  204278. }
  204279. void goForward()
  204280. {
  204281. [webView goForward];
  204282. }
  204283. void stop()
  204284. {
  204285. [webView stopLoading: nil];
  204286. }
  204287. void refresh()
  204288. {
  204289. [webView reload: nil];
  204290. }
  204291. private:
  204292. WebView* webView;
  204293. DownloadClickDetector* clickListener;
  204294. };
  204295. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204296. : browser (0),
  204297. blankPageShown (false),
  204298. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204299. {
  204300. setOpaque (true);
  204301. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204302. }
  204303. WebBrowserComponent::~WebBrowserComponent()
  204304. {
  204305. deleteAndZero (browser);
  204306. }
  204307. void WebBrowserComponent::goToURL (const String& url,
  204308. const StringArray* headers,
  204309. const MemoryBlock* postData)
  204310. {
  204311. lastURL = url;
  204312. lastHeaders.clear();
  204313. if (headers != 0)
  204314. lastHeaders = *headers;
  204315. lastPostData.setSize (0);
  204316. if (postData != 0)
  204317. lastPostData = *postData;
  204318. blankPageShown = false;
  204319. browser->goToURL (url, headers, postData);
  204320. }
  204321. void WebBrowserComponent::stop()
  204322. {
  204323. browser->stop();
  204324. }
  204325. void WebBrowserComponent::goBack()
  204326. {
  204327. lastURL = String::empty;
  204328. blankPageShown = false;
  204329. browser->goBack();
  204330. }
  204331. void WebBrowserComponent::goForward()
  204332. {
  204333. lastURL = String::empty;
  204334. browser->goForward();
  204335. }
  204336. void WebBrowserComponent::refresh()
  204337. {
  204338. browser->refresh();
  204339. }
  204340. void WebBrowserComponent::paint (Graphics& g)
  204341. {
  204342. }
  204343. void WebBrowserComponent::checkWindowAssociation()
  204344. {
  204345. if (isShowing())
  204346. {
  204347. if (blankPageShown)
  204348. goBack();
  204349. }
  204350. else
  204351. {
  204352. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204353. {
  204354. // when the component becomes invisible, some stuff like flash
  204355. // carries on playing audio, so we need to force it onto a blank
  204356. // page to avoid this, (and send it back when it's made visible again).
  204357. blankPageShown = true;
  204358. browser->goToURL ("about:blank", 0, 0);
  204359. }
  204360. }
  204361. }
  204362. void WebBrowserComponent::reloadLastURL()
  204363. {
  204364. if (lastURL.isNotEmpty())
  204365. {
  204366. goToURL (lastURL, &lastHeaders, &lastPostData);
  204367. lastURL = String::empty;
  204368. }
  204369. }
  204370. void WebBrowserComponent::parentHierarchyChanged()
  204371. {
  204372. checkWindowAssociation();
  204373. }
  204374. void WebBrowserComponent::resized()
  204375. {
  204376. browser->setSize (getWidth(), getHeight());
  204377. }
  204378. void WebBrowserComponent::visibilityChanged()
  204379. {
  204380. checkWindowAssociation();
  204381. }
  204382. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204383. {
  204384. return true;
  204385. }
  204386. #else
  204387. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204388. {
  204389. }
  204390. WebBrowserComponent::~WebBrowserComponent()
  204391. {
  204392. }
  204393. void WebBrowserComponent::goToURL (const String& url,
  204394. const StringArray* headers,
  204395. const MemoryBlock* postData)
  204396. {
  204397. }
  204398. void WebBrowserComponent::stop()
  204399. {
  204400. }
  204401. void WebBrowserComponent::goBack()
  204402. {
  204403. }
  204404. void WebBrowserComponent::goForward()
  204405. {
  204406. }
  204407. void WebBrowserComponent::refresh()
  204408. {
  204409. }
  204410. void WebBrowserComponent::paint (Graphics& g)
  204411. {
  204412. }
  204413. void WebBrowserComponent::checkWindowAssociation()
  204414. {
  204415. }
  204416. void WebBrowserComponent::reloadLastURL()
  204417. {
  204418. }
  204419. void WebBrowserComponent::parentHierarchyChanged()
  204420. {
  204421. }
  204422. void WebBrowserComponent::resized()
  204423. {
  204424. }
  204425. void WebBrowserComponent::visibilityChanged()
  204426. {
  204427. }
  204428. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204429. {
  204430. return true;
  204431. }
  204432. #endif
  204433. #endif
  204434. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204435. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204436. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204437. // compiled on its own).
  204438. #if JUCE_INCLUDED_FILE
  204439. class IPhoneAudioIODevice : public AudioIODevice
  204440. {
  204441. public:
  204442. IPhoneAudioIODevice (const String& deviceName)
  204443. : AudioIODevice (deviceName, T("Audio")),
  204444. audioUnit (0),
  204445. isRunning (false),
  204446. callback (0),
  204447. actualBufferSize (0),
  204448. floatData (1, 2)
  204449. {
  204450. numInputChannels = 2;
  204451. numOutputChannels = 2;
  204452. preferredBufferSize = 0;
  204453. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204454. updateDeviceInfo();
  204455. }
  204456. ~IPhoneAudioIODevice()
  204457. {
  204458. close();
  204459. }
  204460. const StringArray getOutputChannelNames()
  204461. {
  204462. StringArray s;
  204463. s.add ("Left");
  204464. s.add ("Right");
  204465. return s;
  204466. }
  204467. const StringArray getInputChannelNames()
  204468. {
  204469. StringArray s;
  204470. if (audioInputIsAvailable)
  204471. {
  204472. s.add ("Left");
  204473. s.add ("Right");
  204474. }
  204475. return s;
  204476. }
  204477. int getNumSampleRates()
  204478. {
  204479. return 1;
  204480. }
  204481. double getSampleRate (int index)
  204482. {
  204483. return sampleRate;
  204484. }
  204485. int getNumBufferSizesAvailable()
  204486. {
  204487. return 1;
  204488. }
  204489. int getBufferSizeSamples (int index)
  204490. {
  204491. return getDefaultBufferSize();
  204492. }
  204493. int getDefaultBufferSize()
  204494. {
  204495. return 1024;
  204496. }
  204497. const String open (const BitArray& inputChannels,
  204498. const BitArray& outputChannels,
  204499. double sampleRate,
  204500. int bufferSize)
  204501. {
  204502. close();
  204503. lastError = String::empty;
  204504. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204505. // xxx set up channel mapping
  204506. activeOutputChans = outputChannels;
  204507. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204508. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204509. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204510. activeInputChans = inputChannels;
  204511. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204512. numInputChannels = activeInputChans.countNumberOfSetBits();
  204513. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204514. AudioSessionSetActive (true);
  204515. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204516. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204517. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204518. fixAudioRouteIfSetToReceiver();
  204519. updateDeviceInfo();
  204520. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204521. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204522. actualBufferSize = preferredBufferSize;
  204523. prepareFloatBuffers();
  204524. isRunning = true;
  204525. propertyChanged (0, 0, 0); // creates and starts the AU
  204526. lastError = audioUnit != 0 ? String::empty
  204527. : T("Couldn't open the device");
  204528. return lastError;
  204529. }
  204530. void close()
  204531. {
  204532. if (isRunning)
  204533. {
  204534. isRunning = false;
  204535. AudioSessionSetActive (false);
  204536. if (audioUnit != 0)
  204537. {
  204538. AudioComponentInstanceDispose (audioUnit);
  204539. audioUnit = 0;
  204540. }
  204541. }
  204542. }
  204543. bool isOpen()
  204544. {
  204545. return isRunning;
  204546. }
  204547. int getCurrentBufferSizeSamples()
  204548. {
  204549. return actualBufferSize;
  204550. }
  204551. double getCurrentSampleRate()
  204552. {
  204553. return sampleRate;
  204554. }
  204555. int getCurrentBitDepth()
  204556. {
  204557. return 16;
  204558. }
  204559. const BitArray getActiveOutputChannels() const
  204560. {
  204561. return activeOutputChans;
  204562. }
  204563. const BitArray getActiveInputChannels() const
  204564. {
  204565. return activeInputChans;
  204566. }
  204567. int getOutputLatencyInSamples()
  204568. {
  204569. return 0; //xxx
  204570. }
  204571. int getInputLatencyInSamples()
  204572. {
  204573. return 0; //xxx
  204574. }
  204575. void start (AudioIODeviceCallback* callback_)
  204576. {
  204577. if (isRunning && callback != callback_)
  204578. {
  204579. if (callback_ != 0)
  204580. callback_->audioDeviceAboutToStart (this);
  204581. callbackLock.enter();
  204582. callback = callback_;
  204583. callbackLock.exit();
  204584. }
  204585. }
  204586. void stop()
  204587. {
  204588. if (isRunning)
  204589. {
  204590. callbackLock.enter();
  204591. AudioIODeviceCallback* const lastCallback = callback;
  204592. callback = 0;
  204593. callbackLock.exit();
  204594. if (lastCallback != 0)
  204595. lastCallback->audioDeviceStopped();
  204596. }
  204597. }
  204598. bool isPlaying()
  204599. {
  204600. return isRunning && callback != 0;
  204601. }
  204602. const String getLastError()
  204603. {
  204604. return lastError;
  204605. }
  204606. private:
  204607. CriticalSection callbackLock;
  204608. Float64 sampleRate;
  204609. int numInputChannels, numOutputChannels;
  204610. int preferredBufferSize;
  204611. int actualBufferSize;
  204612. bool isRunning;
  204613. String lastError;
  204614. AudioStreamBasicDescription format;
  204615. AudioUnit audioUnit;
  204616. UInt32 audioInputIsAvailable;
  204617. AudioIODeviceCallback* callback;
  204618. BitArray activeOutputChans, activeInputChans;
  204619. AudioSampleBuffer floatData;
  204620. float* inputChannels[3];
  204621. float* outputChannels[3];
  204622. bool monoInputChannelNumber, monoOutputChannelNumber;
  204623. void prepareFloatBuffers()
  204624. {
  204625. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204626. zerostruct (inputChannels);
  204627. zerostruct (outputChannels);
  204628. for (int i = 0; i < numInputChannels; ++i)
  204629. inputChannels[i] = floatData.getSampleData (i);
  204630. for (int i = 0; i < numOutputChannels; ++i)
  204631. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204632. }
  204633. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204634. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204635. {
  204636. OSStatus err = noErr;
  204637. if (audioInputIsAvailable)
  204638. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204639. const ScopedLock sl (callbackLock);
  204640. if (callback != 0)
  204641. {
  204642. if (audioInputIsAvailable && numInputChannels > 0)
  204643. {
  204644. short* shortData = (short*) ioData->mBuffers[0].mData;
  204645. if (numInputChannels >= 2)
  204646. {
  204647. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204648. {
  204649. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204650. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204651. }
  204652. }
  204653. else
  204654. {
  204655. if (monoInputChannelNumber > 0)
  204656. ++shortData;
  204657. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204658. {
  204659. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204660. ++shortData;
  204661. }
  204662. }
  204663. }
  204664. else
  204665. {
  204666. for (int i = numInputChannels; --i >= 0;)
  204667. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204668. }
  204669. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204670. outputChannels, numOutputChannels,
  204671. (int) inNumberFrames);
  204672. short* shortData = (short*) ioData->mBuffers[0].mData;
  204673. int n = 0;
  204674. if (numOutputChannels >= 2)
  204675. {
  204676. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204677. {
  204678. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204679. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204680. }
  204681. }
  204682. else if (numOutputChannels == 1)
  204683. {
  204684. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204685. {
  204686. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204687. shortData [n++] = s;
  204688. shortData [n++] = s;
  204689. }
  204690. }
  204691. else
  204692. {
  204693. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204694. }
  204695. }
  204696. else
  204697. {
  204698. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204699. }
  204700. return err;
  204701. }
  204702. void updateDeviceInfo()
  204703. {
  204704. UInt32 size = sizeof (sampleRate);
  204705. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204706. size = sizeof (audioInputIsAvailable);
  204707. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204708. }
  204709. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204710. {
  204711. if (! isRunning)
  204712. return;
  204713. if (inPropertyValue != 0)
  204714. {
  204715. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204716. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204717. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204718. SInt32 routeChangeReason;
  204719. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204720. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204721. fixAudioRouteIfSetToReceiver();
  204722. }
  204723. updateDeviceInfo();
  204724. createAudioUnit();
  204725. AudioSessionSetActive (true);
  204726. if (audioUnit != 0)
  204727. {
  204728. UInt32 formatSize = sizeof (format);
  204729. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204730. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204731. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204732. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204733. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204734. AudioOutputUnitStart (audioUnit);
  204735. }
  204736. }
  204737. void interruptionListener (UInt32 inInterruption)
  204738. {
  204739. if (inInterruption == kAudioSessionEndInterruption)
  204740. {
  204741. isRunning = true;
  204742. AudioSessionSetActive (true);
  204743. AudioOutputUnitStart (audioUnit);
  204744. }
  204745. }
  204746. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204747. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204748. {
  204749. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204750. }
  204751. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204752. {
  204753. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204754. }
  204755. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204756. {
  204757. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204758. }
  204759. void resetFormat (const int numChannels)
  204760. {
  204761. memset (&format, 0, sizeof (format));
  204762. format.mFormatID = kAudioFormatLinearPCM;
  204763. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204764. format.mBitsPerChannel = 8 * sizeof (short);
  204765. format.mChannelsPerFrame = 2;
  204766. format.mFramesPerPacket = 1;
  204767. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204768. }
  204769. bool createAudioUnit()
  204770. {
  204771. if (audioUnit != 0)
  204772. {
  204773. AudioComponentInstanceDispose (audioUnit);
  204774. audioUnit = 0;
  204775. }
  204776. resetFormat (2);
  204777. AudioComponentDescription desc;
  204778. desc.componentType = kAudioUnitType_Output;
  204779. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204780. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204781. desc.componentFlags = 0;
  204782. desc.componentFlagsMask = 0;
  204783. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204784. AudioComponentInstanceNew (comp, &audioUnit);
  204785. if (audioUnit == 0)
  204786. return false;
  204787. const UInt32 one = 1;
  204788. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204789. AudioChannelLayout layout;
  204790. layout.mChannelBitmap = 0;
  204791. layout.mNumberChannelDescriptions = 0;
  204792. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204793. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204794. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204795. AURenderCallbackStruct inputProc;
  204796. inputProc.inputProc = processStatic;
  204797. inputProc.inputProcRefCon = this;
  204798. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204799. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204800. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204801. AudioUnitInitialize (audioUnit);
  204802. return true;
  204803. }
  204804. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204805. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204806. static void fixAudioRouteIfSetToReceiver()
  204807. {
  204808. CFStringRef audioRoute = 0;
  204809. UInt32 propertySize = sizeof (audioRoute);
  204810. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204811. {
  204812. NSString* route = (NSString*) audioRoute;
  204813. //DBG ("audio route: " + nsStringToJuce (route));
  204814. if ([route hasPrefix: @"Receiver"])
  204815. {
  204816. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204817. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204818. }
  204819. CFRelease (audioRoute);
  204820. }
  204821. }
  204822. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204823. const IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204824. };
  204825. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204826. {
  204827. public:
  204828. IPhoneAudioIODeviceType()
  204829. : AudioIODeviceType (T("iPhone Audio"))
  204830. {
  204831. }
  204832. ~IPhoneAudioIODeviceType()
  204833. {
  204834. }
  204835. void scanForDevices()
  204836. {
  204837. }
  204838. const StringArray getDeviceNames (const bool wantInputNames) const
  204839. {
  204840. StringArray s;
  204841. s.add ("iPhone Audio");
  204842. return s;
  204843. }
  204844. int getDefaultDeviceIndex (const bool forInput) const
  204845. {
  204846. return 0;
  204847. }
  204848. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  204849. {
  204850. return device != 0 ? 0 : -1;
  204851. }
  204852. bool hasSeparateInputsAndOutputs() const { return false; }
  204853. AudioIODevice* createDevice (const String& outputDeviceName,
  204854. const String& inputDeviceName)
  204855. {
  204856. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204857. {
  204858. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204859. : inputDeviceName);
  204860. }
  204861. return 0;
  204862. }
  204863. juce_UseDebuggingNewOperator
  204864. private:
  204865. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204866. const IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204867. };
  204868. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204869. {
  204870. return new IPhoneAudioIODeviceType();
  204871. }
  204872. #endif
  204873. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204874. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204875. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204876. // compiled on its own).
  204877. #if JUCE_INCLUDED_FILE
  204878. #if JUCE_MAC
  204879. #undef log
  204880. #define log(a) Logger::writeToLog(a)
  204881. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204882. {
  204883. if (err == noErr)
  204884. return true;
  204885. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  204886. jassertfalse
  204887. return false;
  204888. }
  204889. #undef OK
  204890. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204891. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204892. {
  204893. String result;
  204894. CFStringRef str = 0;
  204895. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204896. if (str != 0)
  204897. {
  204898. result = PlatformUtilities::cfStringToJuceString (str);
  204899. CFRelease (str);
  204900. str = 0;
  204901. }
  204902. MIDIEntityRef entity = 0;
  204903. MIDIEndpointGetEntity (endpoint, &entity);
  204904. if (entity == 0)
  204905. return result; // probably virtual
  204906. if (result.isEmpty())
  204907. {
  204908. // endpoint name has zero length - try the entity
  204909. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204910. if (str != 0)
  204911. {
  204912. result += PlatformUtilities::cfStringToJuceString (str);
  204913. CFRelease (str);
  204914. str = 0;
  204915. }
  204916. }
  204917. // now consider the device's name
  204918. MIDIDeviceRef device = 0;
  204919. MIDIEntityGetDevice (entity, &device);
  204920. if (device == 0)
  204921. return result;
  204922. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204923. if (str != 0)
  204924. {
  204925. const String s (PlatformUtilities::cfStringToJuceString (str));
  204926. CFRelease (str);
  204927. // if an external device has only one entity, throw away
  204928. // the endpoint name and just use the device name
  204929. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204930. {
  204931. result = s;
  204932. }
  204933. else if (! result.startsWithIgnoreCase (s))
  204934. {
  204935. // prepend the device name to the entity name
  204936. result = (s + T(" ") + result).trimEnd();
  204937. }
  204938. }
  204939. return result;
  204940. }
  204941. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204942. {
  204943. String result;
  204944. // Does the endpoint have connections?
  204945. CFDataRef connections = 0;
  204946. int numConnections = 0;
  204947. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204948. if (connections != 0)
  204949. {
  204950. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204951. if (numConnections > 0)
  204952. {
  204953. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204954. for (int i = 0; i < numConnections; ++i, ++pid)
  204955. {
  204956. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204957. MIDIObjectRef connObject;
  204958. MIDIObjectType connObjectType;
  204959. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204960. if (err == noErr)
  204961. {
  204962. String s;
  204963. if (connObjectType == kMIDIObjectType_ExternalSource
  204964. || connObjectType == kMIDIObjectType_ExternalDestination)
  204965. {
  204966. // Connected to an external device's endpoint (10.3 and later).
  204967. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204968. }
  204969. else
  204970. {
  204971. // Connected to an external device (10.2) (or something else, catch-all)
  204972. CFStringRef str = 0;
  204973. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204974. if (str != 0)
  204975. {
  204976. s = PlatformUtilities::cfStringToJuceString (str);
  204977. CFRelease (str);
  204978. }
  204979. }
  204980. if (s.isNotEmpty())
  204981. {
  204982. if (result.isNotEmpty())
  204983. result += (", ");
  204984. result += s;
  204985. }
  204986. }
  204987. }
  204988. }
  204989. CFRelease (connections);
  204990. }
  204991. if (result.isNotEmpty())
  204992. return result;
  204993. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204994. return getEndpointName (endpoint, false);
  204995. }
  204996. const StringArray MidiOutput::getDevices()
  204997. {
  204998. StringArray s;
  204999. const ItemCount num = MIDIGetNumberOfDestinations();
  205000. for (ItemCount i = 0; i < num; ++i)
  205001. {
  205002. MIDIEndpointRef dest = MIDIGetDestination (i);
  205003. if (dest != 0)
  205004. {
  205005. String name (getConnectedEndpointName (dest));
  205006. if (name.isEmpty())
  205007. name = "<error>";
  205008. s.add (name);
  205009. }
  205010. else
  205011. {
  205012. s.add ("<error>");
  205013. }
  205014. }
  205015. return s;
  205016. }
  205017. int MidiOutput::getDefaultDeviceIndex()
  205018. {
  205019. return 0;
  205020. }
  205021. static MIDIClientRef globalMidiClient;
  205022. static bool hasGlobalClientBeenCreated = false;
  205023. static bool makeSureClientExists()
  205024. {
  205025. if (! hasGlobalClientBeenCreated)
  205026. {
  205027. String name (T("JUCE"));
  205028. if (JUCEApplication::getInstance() != 0)
  205029. name = JUCEApplication::getInstance()->getApplicationName();
  205030. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205031. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205032. CFRelease (appName);
  205033. }
  205034. return hasGlobalClientBeenCreated;
  205035. }
  205036. class MidiPortAndEndpoint
  205037. {
  205038. public:
  205039. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205040. : port (port_), endPoint (endPoint_)
  205041. {
  205042. }
  205043. ~MidiPortAndEndpoint()
  205044. {
  205045. if (port != 0)
  205046. MIDIPortDispose (port);
  205047. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205048. MIDIEndpointDispose (endPoint);
  205049. }
  205050. MIDIPortRef port;
  205051. MIDIEndpointRef endPoint;
  205052. };
  205053. MidiOutput* MidiOutput::openDevice (int index)
  205054. {
  205055. MidiOutput* mo = 0;
  205056. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205057. {
  205058. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205059. CFStringRef pname;
  205060. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205061. {
  205062. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205063. if (makeSureClientExists())
  205064. {
  205065. MIDIPortRef port;
  205066. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205067. {
  205068. mo = new MidiOutput();
  205069. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205070. }
  205071. }
  205072. CFRelease (pname);
  205073. }
  205074. }
  205075. return mo;
  205076. }
  205077. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205078. {
  205079. MidiOutput* mo = 0;
  205080. if (makeSureClientExists())
  205081. {
  205082. MIDIEndpointRef endPoint;
  205083. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205084. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205085. {
  205086. mo = new MidiOutput();
  205087. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205088. }
  205089. CFRelease (name);
  205090. }
  205091. return mo;
  205092. }
  205093. MidiOutput::~MidiOutput()
  205094. {
  205095. delete (MidiPortAndEndpoint*) internal;
  205096. }
  205097. void MidiOutput::reset()
  205098. {
  205099. }
  205100. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205101. {
  205102. return false;
  205103. }
  205104. void MidiOutput::setVolume (float leftVol, float rightVol)
  205105. {
  205106. }
  205107. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205108. {
  205109. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205110. if (message.isSysEx())
  205111. {
  205112. const int maxPacketSize = 256;
  205113. int pos = 0, bytesLeft = message.getRawDataSize();
  205114. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205115. HeapBlock <MIDIPacketList> packets;
  205116. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205117. packets->numPackets = numPackets;
  205118. MIDIPacket* p = packets->packet;
  205119. for (int i = 0; i < numPackets; ++i)
  205120. {
  205121. p->timeStamp = 0;
  205122. p->length = jmin (maxPacketSize, bytesLeft);
  205123. memcpy (p->data, message.getRawData() + pos, p->length);
  205124. pos += p->length;
  205125. bytesLeft -= p->length;
  205126. p = MIDIPacketNext (p);
  205127. }
  205128. if (mpe->port != 0)
  205129. MIDISend (mpe->port, mpe->endPoint, packets);
  205130. else
  205131. MIDIReceived (mpe->endPoint, packets);
  205132. }
  205133. else
  205134. {
  205135. MIDIPacketList packets;
  205136. packets.numPackets = 1;
  205137. packets.packet[0].timeStamp = 0;
  205138. packets.packet[0].length = message.getRawDataSize();
  205139. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205140. if (mpe->port != 0)
  205141. MIDISend (mpe->port, mpe->endPoint, &packets);
  205142. else
  205143. MIDIReceived (mpe->endPoint, &packets);
  205144. }
  205145. }
  205146. const StringArray MidiInput::getDevices()
  205147. {
  205148. StringArray s;
  205149. const ItemCount num = MIDIGetNumberOfSources();
  205150. for (ItemCount i = 0; i < num; ++i)
  205151. {
  205152. MIDIEndpointRef source = MIDIGetSource (i);
  205153. if (source != 0)
  205154. {
  205155. String name (getConnectedEndpointName (source));
  205156. if (name.isEmpty())
  205157. name = "<error>";
  205158. s.add (name);
  205159. }
  205160. else
  205161. {
  205162. s.add ("<error>");
  205163. }
  205164. }
  205165. return s;
  205166. }
  205167. int MidiInput::getDefaultDeviceIndex()
  205168. {
  205169. return 0;
  205170. }
  205171. struct MidiPortAndCallback
  205172. {
  205173. MidiInput* input;
  205174. MidiPortAndEndpoint* portAndEndpoint;
  205175. MidiInputCallback* callback;
  205176. MemoryBlock pendingData;
  205177. int pendingBytes;
  205178. double pendingDataTime;
  205179. bool active;
  205180. };
  205181. static CriticalSection callbackLock;
  205182. static VoidArray activeCallbacks;
  205183. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  205184. {
  205185. if (*d == 0xf0)
  205186. {
  205187. mpc->pendingBytes = 0;
  205188. mpc->pendingDataTime = time;
  205189. }
  205190. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  205191. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  205192. uint8* dest = totalMessage + mpc->pendingBytes;
  205193. while (size > 0)
  205194. {
  205195. if (mpc->pendingBytes > 0 && *d >= 0x80)
  205196. {
  205197. if (*d >= 0xfa || *d == 0xf8)
  205198. {
  205199. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  205200. ++d;
  205201. --size;
  205202. }
  205203. else
  205204. {
  205205. if (*d == 0xf7)
  205206. {
  205207. *dest++ = *d++;
  205208. mpc->pendingBytes++;
  205209. --size;
  205210. }
  205211. break;
  205212. }
  205213. }
  205214. else
  205215. {
  205216. *dest++ = *d++;
  205217. mpc->pendingBytes++;
  205218. --size;
  205219. }
  205220. }
  205221. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  205222. {
  205223. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  205224. mpc->pendingBytes,
  205225. mpc->pendingDataTime));
  205226. mpc->pendingBytes = 0;
  205227. }
  205228. else
  205229. {
  205230. mpc->callback->handlePartialSysexMessage (mpc->input,
  205231. totalMessage,
  205232. mpc->pendingBytes,
  205233. mpc->pendingDataTime);
  205234. }
  205235. }
  205236. static void midiInputProc (const MIDIPacketList* pktlist,
  205237. void* readProcRefCon,
  205238. void* srcConnRefCon)
  205239. {
  205240. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205241. const double originalTime = time;
  205242. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205243. const ScopedLock sl (callbackLock);
  205244. if (activeCallbacks.contains (mpc) && mpc->active)
  205245. {
  205246. const MIDIPacket* packet = &pktlist->packet[0];
  205247. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205248. {
  205249. const uint8* d = (const uint8*) (packet->data);
  205250. int size = packet->length;
  205251. while (size > 0)
  205252. {
  205253. time = originalTime;
  205254. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205255. {
  205256. processSysex (mpc, d, size, time);
  205257. }
  205258. else
  205259. {
  205260. int used = 0;
  205261. const MidiMessage m (d, size, used, 0, time);
  205262. if (used <= 0)
  205263. {
  205264. jassertfalse // malformed midi message
  205265. break;
  205266. }
  205267. else
  205268. {
  205269. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205270. }
  205271. size -= used;
  205272. d += used;
  205273. }
  205274. }
  205275. packet = MIDIPacketNext (packet);
  205276. }
  205277. }
  205278. }
  205279. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205280. {
  205281. MidiInput* mi = 0;
  205282. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205283. {
  205284. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205285. if (endPoint != 0)
  205286. {
  205287. CFStringRef pname;
  205288. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205289. {
  205290. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205291. if (makeSureClientExists())
  205292. {
  205293. MIDIPortRef port;
  205294. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205295. mpc->active = false;
  205296. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205297. {
  205298. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205299. {
  205300. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205301. mpc->callback = callback;
  205302. mpc->pendingBytes = 0;
  205303. mpc->pendingData.ensureSize (128);
  205304. mi = new MidiInput (getDevices() [index]);
  205305. mpc->input = mi;
  205306. mi->internal = (void*) mpc;
  205307. const ScopedLock sl (callbackLock);
  205308. activeCallbacks.add (mpc.release());
  205309. }
  205310. else
  205311. {
  205312. OK (MIDIPortDispose (port));
  205313. }
  205314. }
  205315. }
  205316. }
  205317. CFRelease (pname);
  205318. }
  205319. }
  205320. return mi;
  205321. }
  205322. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205323. {
  205324. MidiInput* mi = 0;
  205325. if (makeSureClientExists())
  205326. {
  205327. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205328. mpc->active = false;
  205329. MIDIEndpointRef endPoint;
  205330. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205331. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205332. {
  205333. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205334. mpc->callback = callback;
  205335. mpc->pendingBytes = 0;
  205336. mpc->pendingData.ensureSize (128);
  205337. mi = new MidiInput (deviceName);
  205338. mpc->input = mi;
  205339. mi->internal = (void*) mpc;
  205340. const ScopedLock sl (callbackLock);
  205341. activeCallbacks.add (mpc.release());
  205342. }
  205343. CFRelease (name);
  205344. }
  205345. return mi;
  205346. }
  205347. MidiInput::MidiInput (const String& name_)
  205348. : name (name_)
  205349. {
  205350. }
  205351. MidiInput::~MidiInput()
  205352. {
  205353. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205354. mpc->active = false;
  205355. callbackLock.enter();
  205356. activeCallbacks.removeValue (mpc);
  205357. callbackLock.exit();
  205358. if (mpc->portAndEndpoint->port != 0)
  205359. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205360. delete mpc->portAndEndpoint;
  205361. delete mpc;
  205362. }
  205363. void MidiInput::start()
  205364. {
  205365. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205366. const ScopedLock sl (callbackLock);
  205367. mpc->active = true;
  205368. }
  205369. void MidiInput::stop()
  205370. {
  205371. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205372. const ScopedLock sl (callbackLock);
  205373. mpc->active = false;
  205374. }
  205375. #undef log
  205376. #else
  205377. MidiOutput::~MidiOutput()
  205378. {
  205379. }
  205380. void MidiOutput::reset()
  205381. {
  205382. }
  205383. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205384. {
  205385. return false;
  205386. }
  205387. void MidiOutput::setVolume (float leftVol, float rightVol)
  205388. {
  205389. }
  205390. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205391. {
  205392. }
  205393. const StringArray MidiOutput::getDevices()
  205394. {
  205395. return StringArray();
  205396. }
  205397. MidiOutput* MidiOutput::openDevice (int index)
  205398. {
  205399. return 0;
  205400. }
  205401. const StringArray MidiInput::getDevices()
  205402. {
  205403. return StringArray();
  205404. }
  205405. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205406. {
  205407. return 0;
  205408. }
  205409. #endif
  205410. #endif
  205411. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205412. #else
  205413. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205414. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205415. // compiled on its own).
  205416. #if JUCE_INCLUDED_FILE
  205417. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205418. #define SUPPORT_10_4_FONTS 1
  205419. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205420. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205421. #define SUPPORT_ONLY_10_4_FONTS 1
  205422. #endif
  205423. END_JUCE_NAMESPACE
  205424. @interface NSFont (PrivateHack)
  205425. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205426. @end
  205427. BEGIN_JUCE_NAMESPACE
  205428. #endif
  205429. class MacTypeface : public Typeface
  205430. {
  205431. public:
  205432. MacTypeface (const Font& font)
  205433. : Typeface (font.getTypefaceName())
  205434. {
  205435. const ScopedAutoReleasePool pool;
  205436. renderingTransform = CGAffineTransformIdentity;
  205437. bool needsItalicTransform = false;
  205438. #if JUCE_IPHONE
  205439. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205440. if (font.isItalic() || font.isBold())
  205441. {
  205442. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205443. for (NSString* i in familyFonts)
  205444. {
  205445. const String fn (nsStringToJuce (i));
  205446. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205447. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205448. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205449. || afterDash.containsIgnoreCase (T("italic"))
  205450. || fn.endsWithIgnoreCase (T("oblique"))
  205451. || fn.endsWithIgnoreCase (T("italic"));
  205452. if (probablyBold == font.isBold()
  205453. && probablyItalic == font.isItalic())
  205454. {
  205455. fontName = i;
  205456. needsItalicTransform = false;
  205457. break;
  205458. }
  205459. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205460. {
  205461. fontName = i;
  205462. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205463. }
  205464. }
  205465. if (needsItalicTransform)
  205466. renderingTransform.c = 0.15f;
  205467. }
  205468. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205469. const int ascender = abs (CGFontGetAscent (fontRef));
  205470. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205471. ascent = ascender / totalHeight;
  205472. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205473. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205474. #else
  205475. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205476. if (font.isItalic())
  205477. {
  205478. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205479. toHaveTrait: NSItalicFontMask];
  205480. if (newFont == nsFont)
  205481. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205482. nsFont = newFont;
  205483. }
  205484. if (font.isBold())
  205485. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205486. [nsFont retain];
  205487. ascent = fabsf ((float) [nsFont ascender]);
  205488. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205489. ascent /= totalSize;
  205490. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205491. if (needsItalicTransform)
  205492. {
  205493. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205494. renderingTransform.c = 0.15f;
  205495. }
  205496. #if SUPPORT_ONLY_10_4_FONTS
  205497. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205498. if (atsFont == 0)
  205499. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205500. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205501. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205502. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205503. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205504. #else
  205505. #if SUPPORT_10_4_FONTS
  205506. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205507. {
  205508. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205509. if (atsFont == 0)
  205510. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205511. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205512. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205513. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205514. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205515. }
  205516. else
  205517. #endif
  205518. {
  205519. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205520. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205521. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205522. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205523. }
  205524. #endif
  205525. #endif
  205526. }
  205527. ~MacTypeface()
  205528. {
  205529. #if ! JUCE_IPHONE
  205530. [nsFont release];
  205531. #endif
  205532. if (fontRef != 0)
  205533. CGFontRelease (fontRef);
  205534. }
  205535. float getAscent() const
  205536. {
  205537. return ascent;
  205538. }
  205539. float getDescent() const
  205540. {
  205541. return 1.0f - ascent;
  205542. }
  205543. float getStringWidth (const String& text)
  205544. {
  205545. if (fontRef == 0 || text.isEmpty())
  205546. return 0;
  205547. const int length = text.length();
  205548. HeapBlock <CGGlyph> glyphs;
  205549. createGlyphsForString (text, length, glyphs);
  205550. float x = 0;
  205551. #if SUPPORT_ONLY_10_4_FONTS
  205552. HeapBlock <NSSize> advances (length);
  205553. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205554. for (int i = 0; i < length; ++i)
  205555. x += advances[i].width;
  205556. #else
  205557. #if SUPPORT_10_4_FONTS
  205558. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205559. {
  205560. HeapBlock <NSSize> advances (length);
  205561. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205562. for (int i = 0; i < length; ++i)
  205563. x += advances[i].width;
  205564. }
  205565. else
  205566. #endif
  205567. {
  205568. HeapBlock <int> advances (length);
  205569. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205570. for (int i = 0; i < length; ++i)
  205571. x += advances[i];
  205572. }
  205573. #endif
  205574. return x * unitsToHeightScaleFactor;
  205575. }
  205576. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205577. {
  205578. xOffsets.add (0);
  205579. if (fontRef == 0 || text.isEmpty())
  205580. return;
  205581. const int length = text.length();
  205582. HeapBlock <CGGlyph> glyphs;
  205583. createGlyphsForString (text, length, glyphs);
  205584. #if SUPPORT_ONLY_10_4_FONTS
  205585. HeapBlock <NSSize> advances (length);
  205586. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205587. int x = 0;
  205588. for (int i = 0; i < length; ++i)
  205589. {
  205590. x += advances[i].width;
  205591. xOffsets.add (x * unitsToHeightScaleFactor);
  205592. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205593. }
  205594. #else
  205595. #if SUPPORT_10_4_FONTS
  205596. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205597. {
  205598. HeapBlock <NSSize> advances (length);
  205599. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205600. float x = 0;
  205601. for (int i = 0; i < length; ++i)
  205602. {
  205603. x += advances[i].width;
  205604. xOffsets.add (x * unitsToHeightScaleFactor);
  205605. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205606. }
  205607. }
  205608. else
  205609. #endif
  205610. {
  205611. HeapBlock <int> advances (length);
  205612. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205613. {
  205614. int x = 0;
  205615. for (int i = 0; i < length; ++i)
  205616. {
  205617. x += advances [i];
  205618. xOffsets.add (x * unitsToHeightScaleFactor);
  205619. resultGlyphs.add (glyphs[i]);
  205620. }
  205621. }
  205622. }
  205623. #endif
  205624. }
  205625. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205626. {
  205627. #if JUCE_IPHONE
  205628. return false;
  205629. #else
  205630. if (nsFont == 0)
  205631. return false;
  205632. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205633. jassert (path.isEmpty());
  205634. const ScopedAutoReleasePool pool;
  205635. NSBezierPath* bez = [NSBezierPath bezierPath];
  205636. [bez moveToPoint: NSMakePoint (0, 0)];
  205637. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205638. inFont: nsFont];
  205639. for (int i = 0; i < [bez elementCount]; ++i)
  205640. {
  205641. NSPoint p[3];
  205642. switch ([bez elementAtIndex: i associatedPoints: p])
  205643. {
  205644. case NSMoveToBezierPathElement:
  205645. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205646. break;
  205647. case NSLineToBezierPathElement:
  205648. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205649. break;
  205650. case NSCurveToBezierPathElement:
  205651. 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);
  205652. break;
  205653. case NSClosePathBezierPathElement:
  205654. path.closeSubPath();
  205655. break;
  205656. default:
  205657. jassertfalse
  205658. break;
  205659. }
  205660. }
  205661. path.applyTransform (pathTransform);
  205662. return true;
  205663. #endif
  205664. }
  205665. juce_UseDebuggingNewOperator
  205666. CGFontRef fontRef;
  205667. float fontHeightToCGSizeFactor;
  205668. CGAffineTransform renderingTransform;
  205669. private:
  205670. float ascent, unitsToHeightScaleFactor;
  205671. #if JUCE_IPHONE
  205672. #else
  205673. NSFont* nsFont;
  205674. AffineTransform pathTransform;
  205675. #endif
  205676. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205677. {
  205678. #if SUPPORT_10_4_FONTS
  205679. #if ! SUPPORT_ONLY_10_4_FONTS
  205680. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205681. #endif
  205682. {
  205683. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205684. NSGlyph* const g = (NSGlyph*) glyphs;
  205685. for (int i = 0; i < length; ++i)
  205686. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205687. return;
  205688. }
  205689. #endif
  205690. #if ! SUPPORT_ONLY_10_4_FONTS
  205691. if (charToGlyphMapper == 0)
  205692. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205693. glyphs.malloc (length);
  205694. for (int i = 0; i < length; ++i)
  205695. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205696. #endif
  205697. }
  205698. #if ! SUPPORT_ONLY_10_4_FONTS
  205699. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205700. class CharToGlyphMapper
  205701. {
  205702. public:
  205703. CharToGlyphMapper (CGFontRef fontRef)
  205704. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205705. idRangeOffset (0), glyphIndexes (0)
  205706. {
  205707. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205708. if (cmapTable != 0)
  205709. {
  205710. const int numSubtables = getValue16 (cmapTable, 2);
  205711. for (int i = 0; i < numSubtables; ++i)
  205712. {
  205713. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205714. {
  205715. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205716. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205717. {
  205718. const int length = getValue16 (cmapTable, offset + 2);
  205719. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205720. segCount = segCountX2 / 2;
  205721. const int endCodeOffset = offset + 14;
  205722. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205723. const int idDeltaOffset = startCodeOffset + segCountX2;
  205724. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205725. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205726. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205727. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205728. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205729. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205730. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205731. }
  205732. break;
  205733. }
  205734. }
  205735. CFRelease (cmapTable);
  205736. }
  205737. }
  205738. ~CharToGlyphMapper()
  205739. {
  205740. if (endCode != 0)
  205741. {
  205742. CFRelease (endCode);
  205743. CFRelease (startCode);
  205744. CFRelease (idDelta);
  205745. CFRelease (idRangeOffset);
  205746. CFRelease (glyphIndexes);
  205747. }
  205748. }
  205749. int getGlyphForCharacter (const juce_wchar c) const
  205750. {
  205751. for (int i = 0; i < segCount; ++i)
  205752. {
  205753. if (getValue16 (endCode, i * 2) >= c)
  205754. {
  205755. const int start = getValue16 (startCode, i * 2);
  205756. if (start > c)
  205757. break;
  205758. const int delta = getValue16 (idDelta, i * 2);
  205759. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205760. if (rangeOffset == 0)
  205761. return delta + c;
  205762. else
  205763. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205764. }
  205765. }
  205766. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205767. return jmax (-1, c - 29);
  205768. }
  205769. private:
  205770. int segCount;
  205771. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205772. static uint16 getValue16 (CFDataRef data, const int index)
  205773. {
  205774. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205775. }
  205776. static uint32 getValue32 (CFDataRef data, const int index)
  205777. {
  205778. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205779. }
  205780. };
  205781. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205782. #endif
  205783. };
  205784. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205785. {
  205786. return new MacTypeface (font);
  205787. }
  205788. const StringArray Font::findAllTypefaceNames() throw()
  205789. {
  205790. StringArray names;
  205791. const ScopedAutoReleasePool pool;
  205792. #if JUCE_IPHONE
  205793. NSArray* fonts = [UIFont familyNames];
  205794. #else
  205795. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205796. #endif
  205797. for (unsigned int i = 0; i < [fonts count]; ++i)
  205798. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205799. names.sort (true);
  205800. return names;
  205801. }
  205802. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205803. {
  205804. #if JUCE_IPHONE
  205805. defaultSans = "Helvetica";
  205806. defaultSerif = "Times New Roman";
  205807. defaultFixed = "Courier New";
  205808. #else
  205809. defaultSans = "Lucida Grande";
  205810. defaultSerif = "Times New Roman";
  205811. defaultFixed = "Monaco";
  205812. #endif
  205813. }
  205814. #endif
  205815. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205816. // (must go before juce_mac_CoreGraphicsContext.mm)
  205817. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205818. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205819. // compiled on its own).
  205820. #if JUCE_INCLUDED_FILE
  205821. class CoreGraphicsImage : public Image
  205822. {
  205823. public:
  205824. CoreGraphicsImage (const PixelFormat format_,
  205825. const int imageWidth_,
  205826. const int imageHeight_,
  205827. const bool clearImage)
  205828. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205829. {
  205830. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  205831. : CGColorSpaceCreateDeviceRGB();
  205832. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205833. colourSpace, getCGImageFlags (*this));
  205834. CGColorSpaceRelease (colourSpace);
  205835. }
  205836. ~CoreGraphicsImage()
  205837. {
  205838. CGContextRelease (context);
  205839. }
  205840. LowLevelGraphicsContext* createLowLevelContext();
  205841. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205842. {
  205843. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205844. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205845. {
  205846. return CGBitmapContextCreateImage (nativeImage->context);
  205847. }
  205848. else
  205849. {
  205850. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205851. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205852. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205853. 8, srcData.pixelStride * 8, srcData.lineStride,
  205854. colourSpace, getCGImageFlags (juceImage), provider,
  205855. 0, true, kCGRenderingIntentDefault);
  205856. CGDataProviderRelease (provider);
  205857. return imageRef;
  205858. }
  205859. }
  205860. #if JUCE_MAC
  205861. static NSImage* createNSImage (const Image& image)
  205862. {
  205863. const ScopedAutoReleasePool pool;
  205864. NSImage* im = [[NSImage alloc] init];
  205865. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205866. [im lockFocus];
  205867. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205868. CGImageRef imageRef = createImage (image, false, colourSpace);
  205869. CGColorSpaceRelease (colourSpace);
  205870. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205871. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205872. CGImageRelease (imageRef);
  205873. [im unlockFocus];
  205874. return im;
  205875. }
  205876. #endif
  205877. CGContextRef context;
  205878. private:
  205879. static CGBitmapInfo getCGImageFlags (const Image& image)
  205880. {
  205881. #if JUCE_BIG_ENDIAN
  205882. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205883. #else
  205884. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205885. #endif
  205886. }
  205887. };
  205888. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205889. {
  205890. #if USE_COREGRAPHICS_RENDERING
  205891. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205892. #else
  205893. return new Image (format, imageWidth, imageHeight, clearImage);
  205894. #endif
  205895. }
  205896. class CoreGraphicsContext : public LowLevelGraphicsContext
  205897. {
  205898. public:
  205899. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205900. : context (context_),
  205901. flipHeight (flipHeight_),
  205902. numGradientLookupEntries (0)
  205903. {
  205904. CGContextRetain (context);
  205905. CGContextSaveGState(context);
  205906. CGContextSetShouldSmoothFonts (context, true);
  205907. CGContextSetShouldAntialias (context, true);
  205908. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205909. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205910. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205911. gradientCallbacks.version = 0;
  205912. gradientCallbacks.evaluate = gradientCallback;
  205913. gradientCallbacks.releaseInfo = 0;
  205914. state = new SavedState();
  205915. }
  205916. ~CoreGraphicsContext()
  205917. {
  205918. CGContextRestoreGState (context);
  205919. CGContextRelease (context);
  205920. CGColorSpaceRelease (rgbColourSpace);
  205921. CGColorSpaceRelease (greyColourSpace);
  205922. }
  205923. bool isVectorDevice() const { return false; }
  205924. void setOrigin (int x, int y)
  205925. {
  205926. CGContextTranslateCTM (context, x, -y);
  205927. }
  205928. bool clipToRectangle (const Rectangle<int>& r)
  205929. {
  205930. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205931. return ! isClipEmpty();
  205932. }
  205933. bool clipToRectangleList (const RectangleList& clipRegion)
  205934. {
  205935. if (clipRegion.isEmpty())
  205936. {
  205937. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205938. return false;
  205939. }
  205940. else
  205941. {
  205942. const int numRects = clipRegion.getNumRectangles();
  205943. HeapBlock <CGRect> rects (numRects);
  205944. for (int i = 0; i < numRects; ++i)
  205945. {
  205946. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205947. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205948. }
  205949. CGContextClipToRects (context, rects, numRects);
  205950. return ! isClipEmpty();
  205951. }
  205952. }
  205953. void excludeClipRectangle (const Rectangle<int>& r)
  205954. {
  205955. RectangleList remaining (getClipBounds());
  205956. remaining.subtract (r);
  205957. clipToRectangleList (remaining);
  205958. }
  205959. void clipToPath (const Path& path, const AffineTransform& transform)
  205960. {
  205961. createPath (path, transform);
  205962. CGContextClip (context);
  205963. }
  205964. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205965. {
  205966. if (! transform.isSingularity())
  205967. {
  205968. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  205969. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205970. flip();
  205971. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205972. applyTransform (t);
  205973. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205974. CGContextClipToMask (context, r, image);
  205975. applyTransform (t.inverted());
  205976. flip();
  205977. CGImageRelease (image);
  205978. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  205979. }
  205980. }
  205981. bool clipRegionIntersects (const Rectangle<int>& r)
  205982. {
  205983. return getClipBounds().intersects (r);
  205984. }
  205985. const Rectangle<int> getClipBounds() const
  205986. {
  205987. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205988. return Rectangle<int> (roundToInt (bounds.origin.x),
  205989. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205990. roundToInt (bounds.size.width),
  205991. roundToInt (bounds.size.height));
  205992. }
  205993. bool isClipEmpty() const
  205994. {
  205995. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205996. }
  205997. void saveState()
  205998. {
  205999. CGContextSaveGState (context);
  206000. stateStack.add (new SavedState (*state));
  206001. }
  206002. void restoreState()
  206003. {
  206004. CGContextRestoreGState (context);
  206005. SavedState* const top = stateStack.getLast();
  206006. if (top != 0)
  206007. {
  206008. state = top;
  206009. stateStack.removeLast (1, false);
  206010. }
  206011. else
  206012. {
  206013. jassertfalse // trying to pop with an empty stack!
  206014. }
  206015. }
  206016. void setFill (const FillType& fillType)
  206017. {
  206018. state->fillType = fillType;
  206019. if (fillType.isColour())
  206020. {
  206021. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206022. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206023. CGContextSetAlpha (context, 1.0f);
  206024. }
  206025. }
  206026. void setOpacity (float newOpacity)
  206027. {
  206028. state->fillType.setOpacity (newOpacity);
  206029. setFill (state->fillType);
  206030. }
  206031. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206032. {
  206033. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206034. ? kCGInterpolationLow
  206035. : kCGInterpolationHigh);
  206036. }
  206037. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206038. {
  206039. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206040. if (replaceExistingContents)
  206041. {
  206042. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206043. CGContextClearRect (context, cgRect);
  206044. #else
  206045. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206046. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206047. CGContextClearRect (context, cgRect);
  206048. else
  206049. #endif
  206050. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206051. #endif
  206052. fillRect (r, false);
  206053. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206054. }
  206055. else
  206056. {
  206057. if (state->fillType.isColour())
  206058. {
  206059. CGContextFillRect (context, cgRect);
  206060. }
  206061. else if (state->fillType.isGradient())
  206062. {
  206063. CGContextSaveGState (context);
  206064. CGContextClipToRect (context, cgRect);
  206065. drawGradient();
  206066. CGContextRestoreGState (context);
  206067. }
  206068. else
  206069. {
  206070. CGContextSaveGState (context);
  206071. CGContextClipToRect (context, cgRect);
  206072. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206073. CGContextRestoreGState (context);
  206074. }
  206075. }
  206076. }
  206077. void fillPath (const Path& path, const AffineTransform& transform)
  206078. {
  206079. CGContextSaveGState (context);
  206080. if (state->fillType.isColour())
  206081. {
  206082. flip();
  206083. applyTransform (transform);
  206084. createPath (path);
  206085. if (path.isUsingNonZeroWinding())
  206086. CGContextFillPath (context);
  206087. else
  206088. CGContextEOFillPath (context);
  206089. }
  206090. else
  206091. {
  206092. createPath (path, transform);
  206093. if (path.isUsingNonZeroWinding())
  206094. CGContextClip (context);
  206095. else
  206096. CGContextEOClip (context);
  206097. if (state->fillType.isGradient())
  206098. drawGradient();
  206099. else
  206100. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206101. }
  206102. CGContextRestoreGState (context);
  206103. }
  206104. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206105. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206106. {
  206107. jassert (sourceImage.getBounds().contains (srcClip));
  206108. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206109. CGImageRef image = fullImage;
  206110. if (srcClip != sourceImage.getBounds())
  206111. {
  206112. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206113. srcClip.getWidth(), srcClip.getHeight()));
  206114. CGImageRelease (fullImage);
  206115. }
  206116. CGContextSaveGState (context);
  206117. CGContextSetAlpha (context, state->fillType.getOpacity());
  206118. flip();
  206119. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206120. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206121. if (fillEntireClipAsTiles)
  206122. {
  206123. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206124. CGContextDrawTiledImage (context, imageRect, image);
  206125. #else
  206126. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206127. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206128. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206129. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206130. CGContextDrawTiledImage (context, imageRect, image);
  206131. else
  206132. #endif
  206133. {
  206134. // Fallback to manually doing a tiled fill on 10.4
  206135. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206136. const int iw = srcClip.getWidth();
  206137. const int ih = srcClip.getHeight();
  206138. int x = 0, y = 0;
  206139. while (x > clip.origin.x) x -= iw;
  206140. while (y > clip.origin.y) y -= ih;
  206141. const int right = (int) (clip.origin.x + clip.size.width);
  206142. const int bottom = (int) (clip.origin.y + clip.size.height);
  206143. while (y < bottom)
  206144. {
  206145. for (int x2 = x; x2 < right; x2 += iw)
  206146. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206147. y += ih;
  206148. }
  206149. }
  206150. #endif
  206151. }
  206152. else
  206153. {
  206154. CGContextDrawImage (context, imageRect, image);
  206155. }
  206156. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206157. CGContextRestoreGState (context);
  206158. }
  206159. void drawLine (double x1, double y1, double x2, double y2)
  206160. {
  206161. CGContextSetLineCap (context, kCGLineCapSquare);
  206162. CGContextSetLineWidth (context, 1.0f);
  206163. CGContextSetRGBStrokeColor (context,
  206164. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206165. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206166. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  206167. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  206168. CGContextStrokeLineSegments (context, line, 1);
  206169. }
  206170. void drawVerticalLine (const int x, double top, double bottom)
  206171. {
  206172. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206173. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206174. #else
  206175. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206176. // the x co-ord slightly to trick it..
  206177. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206178. #endif
  206179. }
  206180. void drawHorizontalLine (const int y, double left, double right)
  206181. {
  206182. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206183. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206184. #else
  206185. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206186. // the x co-ord slightly to trick it..
  206187. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206188. #endif
  206189. }
  206190. void setFont (const Font& newFont)
  206191. {
  206192. if (state->font != newFont)
  206193. {
  206194. state->fontRef = 0;
  206195. state->font = newFont;
  206196. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206197. if (mf != 0)
  206198. {
  206199. state->fontRef = mf->fontRef;
  206200. CGContextSetFont (context, state->fontRef);
  206201. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206202. state->fontTransform = mf->renderingTransform;
  206203. state->fontTransform.a *= state->font.getHorizontalScale();
  206204. CGContextSetTextMatrix (context, state->fontTransform);
  206205. }
  206206. }
  206207. }
  206208. const Font getFont()
  206209. {
  206210. return state->font;
  206211. }
  206212. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206213. {
  206214. if (state->fontRef != 0 && state->fillType.isColour())
  206215. {
  206216. if (transform.isOnlyTranslation())
  206217. {
  206218. CGGlyph g = glyphNumber;
  206219. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206220. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206221. }
  206222. else
  206223. {
  206224. CGContextSaveGState (context);
  206225. flip();
  206226. applyTransform (transform);
  206227. CGAffineTransform t = state->fontTransform;
  206228. t.d = -t.d;
  206229. CGContextSetTextMatrix (context, t);
  206230. CGGlyph g = glyphNumber;
  206231. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206232. CGContextSetTextMatrix (context, state->fontTransform);
  206233. CGContextRestoreGState (context);
  206234. }
  206235. }
  206236. else
  206237. {
  206238. Path p;
  206239. Font& f = state->font;
  206240. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206241. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206242. .followedBy (transform));
  206243. }
  206244. }
  206245. private:
  206246. CGContextRef context;
  206247. const float flipHeight;
  206248. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206249. CGFunctionCallbacks gradientCallbacks;
  206250. struct SavedState
  206251. {
  206252. SavedState()
  206253. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206254. {
  206255. }
  206256. SavedState (const SavedState& other)
  206257. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206258. fontTransform (other.fontTransform)
  206259. {
  206260. }
  206261. ~SavedState()
  206262. {
  206263. }
  206264. FillType fillType;
  206265. Font font;
  206266. CGFontRef fontRef;
  206267. CGAffineTransform fontTransform;
  206268. };
  206269. ScopedPointer <SavedState> state;
  206270. OwnedArray <SavedState> stateStack;
  206271. HeapBlock <PixelARGB> gradientLookupTable;
  206272. int numGradientLookupEntries;
  206273. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206274. {
  206275. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206276. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206277. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206278. colour.unpremultiply();
  206279. outData[0] = colour.getRed() / 255.0f;
  206280. outData[1] = colour.getGreen() / 255.0f;
  206281. outData[2] = colour.getBlue() / 255.0f;
  206282. outData[3] = colour.getAlpha() / 255.0f;
  206283. }
  206284. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206285. {
  206286. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206287. --numGradientLookupEntries;
  206288. CGShadingRef result = 0;
  206289. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206290. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206291. if (gradient.isRadial)
  206292. {
  206293. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206294. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206295. function, true, true);
  206296. }
  206297. else
  206298. {
  206299. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206300. CGPointMake (gradient.x2, gradient.y2),
  206301. function, true, true);
  206302. }
  206303. CGFunctionRelease (function);
  206304. return result;
  206305. }
  206306. void drawGradient()
  206307. {
  206308. flip();
  206309. applyTransform (state->fillType.transform);
  206310. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206311. // you draw a gradient with high quality interp enabled).
  206312. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206313. CGContextSetAlpha (context, state->fillType.getOpacity());
  206314. CGContextDrawShading (context, shading);
  206315. CGShadingRelease (shading);
  206316. }
  206317. void createPath (const Path& path) const
  206318. {
  206319. CGContextBeginPath (context);
  206320. Path::Iterator i (path);
  206321. while (i.next())
  206322. {
  206323. switch (i.elementType)
  206324. {
  206325. case Path::Iterator::startNewSubPath:
  206326. CGContextMoveToPoint (context, i.x1, i.y1);
  206327. break;
  206328. case Path::Iterator::lineTo:
  206329. CGContextAddLineToPoint (context, i.x1, i.y1);
  206330. break;
  206331. case Path::Iterator::quadraticTo:
  206332. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206333. break;
  206334. case Path::Iterator::cubicTo:
  206335. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206336. break;
  206337. case Path::Iterator::closePath:
  206338. CGContextClosePath (context); break;
  206339. default:
  206340. jassertfalse
  206341. break;
  206342. }
  206343. }
  206344. }
  206345. void createPath (const Path& path, const AffineTransform& transform) const
  206346. {
  206347. CGContextBeginPath (context);
  206348. Path::Iterator i (path);
  206349. while (i.next())
  206350. {
  206351. switch (i.elementType)
  206352. {
  206353. case Path::Iterator::startNewSubPath:
  206354. transform.transformPoint (i.x1, i.y1);
  206355. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206356. break;
  206357. case Path::Iterator::lineTo:
  206358. transform.transformPoint (i.x1, i.y1);
  206359. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206360. break;
  206361. case Path::Iterator::quadraticTo:
  206362. transform.transformPoint (i.x1, i.y1);
  206363. transform.transformPoint (i.x2, i.y2);
  206364. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206365. break;
  206366. case Path::Iterator::cubicTo:
  206367. transform.transformPoint (i.x1, i.y1);
  206368. transform.transformPoint (i.x2, i.y2);
  206369. transform.transformPoint (i.x3, i.y3);
  206370. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206371. break;
  206372. case Path::Iterator::closePath:
  206373. CGContextClosePath (context); break;
  206374. default:
  206375. jassertfalse
  206376. break;
  206377. }
  206378. }
  206379. }
  206380. static Image* createAlphaChannelImage (const Image& im)
  206381. {
  206382. if (im.getFormat() == Image::SingleChannel)
  206383. return const_cast <Image*> (&im);
  206384. return im.createCopyOfAlphaChannel();
  206385. }
  206386. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206387. {
  206388. if (im.getFormat() != Image::SingleChannel)
  206389. delete alphaIm;
  206390. }
  206391. void flip() const
  206392. {
  206393. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206394. }
  206395. void applyTransform (const AffineTransform& transform) const
  206396. {
  206397. CGAffineTransform t;
  206398. t.a = transform.mat00;
  206399. t.b = transform.mat10;
  206400. t.c = transform.mat01;
  206401. t.d = transform.mat11;
  206402. t.tx = transform.mat02;
  206403. t.ty = transform.mat12;
  206404. CGContextConcatCTM (context, t);
  206405. }
  206406. float flipY (float y) const
  206407. {
  206408. return flipHeight - y;
  206409. }
  206410. };
  206411. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206412. {
  206413. return new CoreGraphicsContext (context, imageHeight);
  206414. }
  206415. #endif
  206416. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206417. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206418. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206419. // compiled on its own).
  206420. #if JUCE_INCLUDED_FILE
  206421. class NSViewComponentPeer;
  206422. END_JUCE_NAMESPACE
  206423. #define JuceNSView MakeObjCClassName(JuceNSView)
  206424. @interface JuceNSView : NSView
  206425. {
  206426. @public
  206427. NSViewComponentPeer* owner;
  206428. NSNotificationCenter* notificationCenter;
  206429. }
  206430. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206431. - (void) dealloc;
  206432. - (BOOL) isOpaque;
  206433. - (void) drawRect: (NSRect) r;
  206434. - (void) mouseDown: (NSEvent*) ev;
  206435. - (void) asyncMouseDown: (NSEvent*) ev;
  206436. - (void) mouseUp: (NSEvent*) ev;
  206437. - (void) asyncMouseUp: (NSEvent*) ev;
  206438. - (void) mouseDragged: (NSEvent*) ev;
  206439. - (void) mouseMoved: (NSEvent*) ev;
  206440. - (void) mouseEntered: (NSEvent*) ev;
  206441. - (void) mouseExited: (NSEvent*) ev;
  206442. - (void) rightMouseDown: (NSEvent*) ev;
  206443. - (void) rightMouseDragged: (NSEvent*) ev;
  206444. - (void) rightMouseUp: (NSEvent*) ev;
  206445. - (void) otherMouseDown: (NSEvent*) ev;
  206446. - (void) otherMouseDragged: (NSEvent*) ev;
  206447. - (void) otherMouseUp: (NSEvent*) ev;
  206448. - (void) scrollWheel: (NSEvent*) ev;
  206449. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206450. - (void) frameChanged: (NSNotification*) n;
  206451. - (void) viewDidMoveToWindow;
  206452. - (void) keyDown: (NSEvent*) ev;
  206453. - (void) keyUp: (NSEvent*) ev;
  206454. - (void) flagsChanged: (NSEvent*) ev;
  206455. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206456. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206457. #endif
  206458. - (BOOL) becomeFirstResponder;
  206459. - (BOOL) resignFirstResponder;
  206460. - (BOOL) acceptsFirstResponder;
  206461. - (void) asyncRepaint: (id) rect;
  206462. - (NSArray*) getSupportedDragTypes;
  206463. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206464. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206465. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206466. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206467. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206468. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206469. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206470. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206471. @end
  206472. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206473. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206474. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206475. #else
  206476. @interface JuceNSWindow : NSWindow
  206477. #endif
  206478. {
  206479. @private
  206480. NSViewComponentPeer* owner;
  206481. bool isZooming;
  206482. }
  206483. - (void) setOwner: (NSViewComponentPeer*) owner;
  206484. - (BOOL) canBecomeKeyWindow;
  206485. - (void) becomeKeyWindow;
  206486. - (BOOL) windowShouldClose: (id) window;
  206487. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206488. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206489. - (void) zoom: (id) sender;
  206490. @end
  206491. BEGIN_JUCE_NAMESPACE
  206492. class NSViewComponentPeer : public ComponentPeer
  206493. {
  206494. public:
  206495. NSViewComponentPeer (Component* const component,
  206496. const int windowStyleFlags,
  206497. NSView* viewToAttachTo);
  206498. ~NSViewComponentPeer();
  206499. void* getNativeHandle() const;
  206500. void setVisible (bool shouldBeVisible);
  206501. void setTitle (const String& title);
  206502. void setPosition (int x, int y);
  206503. void setSize (int w, int h);
  206504. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206505. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  206506. void getBounds (int& x, int& y, int& w, int& h) const;
  206507. const Point<int> getScreenPosition() const;
  206508. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206509. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206510. void setMinimised (bool shouldBeMinimised);
  206511. bool isMinimised() const;
  206512. void setFullScreen (bool shouldBeFullScreen);
  206513. bool isFullScreen() const;
  206514. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  206515. const BorderSize getFrameSize() const;
  206516. bool setAlwaysOnTop (bool alwaysOnTop);
  206517. void toFront (bool makeActiveWindow);
  206518. void toBehind (ComponentPeer* other);
  206519. void setIcon (const Image& newIcon);
  206520. const StringArray getAvailableRenderingEngines() throw();
  206521. int getCurrentRenderingEngine() throw();
  206522. void setCurrentRenderingEngine (int index) throw();
  206523. virtual void redirectMouseDown (NSEvent* ev);
  206524. virtual void redirectMouseUp (NSEvent* ev);
  206525. virtual void redirectMouseDrag (NSEvent* ev);
  206526. virtual void redirectMouseMove (NSEvent* ev);
  206527. virtual void redirectMouseEnter (NSEvent* ev);
  206528. virtual void redirectMouseExit (NSEvent* ev);
  206529. virtual void redirectMouseWheel (NSEvent* ev);
  206530. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206531. virtual bool redirectKeyDown (NSEvent* ev);
  206532. virtual bool redirectKeyUp (NSEvent* ev);
  206533. virtual void redirectModKeyChange (NSEvent* ev);
  206534. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206535. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206536. #endif
  206537. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206538. virtual bool isOpaque();
  206539. virtual void drawRect (NSRect r);
  206540. virtual bool canBecomeKeyWindow();
  206541. virtual bool windowShouldClose();
  206542. virtual void redirectMovedOrResized();
  206543. virtual void viewMovedToWindow();
  206544. virtual NSRect constrainRect (NSRect r);
  206545. static void showArrowCursorIfNeeded();
  206546. virtual void viewFocusGain();
  206547. virtual void viewFocusLoss();
  206548. bool isFocused() const;
  206549. void grabFocus();
  206550. void textInputRequired (const Point<int>& position);
  206551. void repaint (int x, int y, int w, int h);
  206552. void performAnyPendingRepaintsNow();
  206553. juce_UseDebuggingNewOperator
  206554. NSWindow* window;
  206555. JuceNSView* view;
  206556. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206557. };
  206558. END_JUCE_NAMESPACE
  206559. @implementation JuceNSView
  206560. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206561. withFrame: (NSRect) frame
  206562. {
  206563. [super initWithFrame: frame];
  206564. owner = owner_;
  206565. notificationCenter = [NSNotificationCenter defaultCenter];
  206566. [notificationCenter addObserver: self
  206567. selector: @selector (frameChanged:)
  206568. name: NSViewFrameDidChangeNotification
  206569. object: self];
  206570. if (! owner_->isSharedWindow)
  206571. {
  206572. [notificationCenter addObserver: self
  206573. selector: @selector (frameChanged:)
  206574. name: NSWindowDidMoveNotification
  206575. object: owner_->window];
  206576. }
  206577. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206578. return self;
  206579. }
  206580. - (void) dealloc
  206581. {
  206582. [notificationCenter removeObserver: self];
  206583. [super dealloc];
  206584. }
  206585. - (void) drawRect: (NSRect) r
  206586. {
  206587. if (owner != 0)
  206588. owner->drawRect (r);
  206589. }
  206590. - (BOOL) isOpaque
  206591. {
  206592. return owner == 0 || owner->isOpaque();
  206593. }
  206594. - (void) mouseDown: (NSEvent*) ev
  206595. {
  206596. // In some host situations, the host will stop modal loops from working
  206597. // correctly if they're called from a mouse event, so we'll trigger
  206598. // the event asynchronously..
  206599. if (JUCEApplication::getInstance() == 0)
  206600. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206601. withObject: ev
  206602. waitUntilDone: NO];
  206603. else
  206604. [self asyncMouseDown: ev];
  206605. }
  206606. - (void) asyncMouseDown: (NSEvent*) ev
  206607. {
  206608. if (owner != 0)
  206609. owner->redirectMouseDown (ev);
  206610. }
  206611. - (void) mouseUp: (NSEvent*) ev
  206612. {
  206613. // In some host situations, the host will stop modal loops from working
  206614. // correctly if they're called from a mouse event, so we'll trigger
  206615. // the event asynchronously..
  206616. if (JUCEApplication::getInstance() == 0)
  206617. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206618. withObject: ev
  206619. waitUntilDone: NO];
  206620. else
  206621. [self asyncMouseUp: ev];
  206622. }
  206623. - (void) asyncMouseUp: (NSEvent*) ev
  206624. {
  206625. if (owner != 0)
  206626. owner->redirectMouseUp (ev);
  206627. }
  206628. - (void) mouseDragged: (NSEvent*) ev
  206629. {
  206630. if (owner != 0)
  206631. owner->redirectMouseDrag (ev);
  206632. }
  206633. - (void) mouseMoved: (NSEvent*) ev
  206634. {
  206635. if (owner != 0)
  206636. owner->redirectMouseMove (ev);
  206637. }
  206638. - (void) mouseEntered: (NSEvent*) ev
  206639. {
  206640. if (owner != 0)
  206641. owner->redirectMouseEnter (ev);
  206642. }
  206643. - (void) mouseExited: (NSEvent*) ev
  206644. {
  206645. if (owner != 0)
  206646. owner->redirectMouseExit (ev);
  206647. }
  206648. - (void) rightMouseDown: (NSEvent*) ev
  206649. {
  206650. [self mouseDown: ev];
  206651. }
  206652. - (void) rightMouseDragged: (NSEvent*) ev
  206653. {
  206654. [self mouseDragged: ev];
  206655. }
  206656. - (void) rightMouseUp: (NSEvent*) ev
  206657. {
  206658. [self mouseUp: ev];
  206659. }
  206660. - (void) otherMouseDown: (NSEvent*) ev
  206661. {
  206662. [self mouseDown: ev];
  206663. }
  206664. - (void) otherMouseDragged: (NSEvent*) ev
  206665. {
  206666. [self mouseDragged: ev];
  206667. }
  206668. - (void) otherMouseUp: (NSEvent*) ev
  206669. {
  206670. [self mouseUp: ev];
  206671. }
  206672. - (void) scrollWheel: (NSEvent*) ev
  206673. {
  206674. if (owner != 0)
  206675. owner->redirectMouseWheel (ev);
  206676. }
  206677. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206678. {
  206679. return YES;
  206680. }
  206681. - (void) frameChanged: (NSNotification*) n
  206682. {
  206683. if (owner != 0)
  206684. owner->redirectMovedOrResized();
  206685. }
  206686. - (void) viewDidMoveToWindow
  206687. {
  206688. if (owner != 0)
  206689. owner->viewMovedToWindow();
  206690. }
  206691. - (void) asyncRepaint: (id) rect
  206692. {
  206693. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206694. [self setNeedsDisplayInRect: *r];
  206695. }
  206696. - (void) keyDown: (NSEvent*) ev
  206697. {
  206698. if (owner == 0 || ! owner->redirectKeyDown (ev))
  206699. [super keyDown: ev];
  206700. }
  206701. - (void) keyUp: (NSEvent*) ev
  206702. {
  206703. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206704. [super keyUp: ev];
  206705. }
  206706. - (void) flagsChanged: (NSEvent*) ev
  206707. {
  206708. if (owner != 0)
  206709. owner->redirectModKeyChange (ev);
  206710. }
  206711. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206712. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206713. {
  206714. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206715. return true;
  206716. return [super performKeyEquivalent: ev];
  206717. }
  206718. #endif
  206719. - (BOOL) becomeFirstResponder
  206720. {
  206721. if (owner != 0)
  206722. owner->viewFocusGain();
  206723. return true;
  206724. }
  206725. - (BOOL) resignFirstResponder
  206726. {
  206727. if (owner != 0)
  206728. owner->viewFocusLoss();
  206729. return true;
  206730. }
  206731. - (BOOL) acceptsFirstResponder
  206732. {
  206733. return owner != 0 && owner->canBecomeKeyWindow();
  206734. }
  206735. - (NSArray*) getSupportedDragTypes
  206736. {
  206737. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206738. }
  206739. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206740. {
  206741. return owner != 0 && owner->sendDragCallback (type, sender);
  206742. }
  206743. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206744. {
  206745. if ([self sendDragCallback: 0 sender: sender])
  206746. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206747. else
  206748. return NSDragOperationNone;
  206749. }
  206750. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206751. {
  206752. if ([self sendDragCallback: 0 sender: sender])
  206753. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206754. else
  206755. return NSDragOperationNone;
  206756. }
  206757. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206758. {
  206759. [self sendDragCallback: 1 sender: sender];
  206760. }
  206761. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206762. {
  206763. [self sendDragCallback: 1 sender: sender];
  206764. }
  206765. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206766. {
  206767. return YES;
  206768. }
  206769. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206770. {
  206771. return [self sendDragCallback: 2 sender: sender];
  206772. }
  206773. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206774. {
  206775. }
  206776. @end
  206777. @implementation JuceNSWindow
  206778. - (void) setOwner: (NSViewComponentPeer*) owner_
  206779. {
  206780. owner = owner_;
  206781. isZooming = false;
  206782. }
  206783. - (BOOL) canBecomeKeyWindow
  206784. {
  206785. return owner != 0 && owner->canBecomeKeyWindow();
  206786. }
  206787. - (void) becomeKeyWindow
  206788. {
  206789. [super becomeKeyWindow];
  206790. if (owner != 0)
  206791. owner->grabFocus();
  206792. }
  206793. - (BOOL) windowShouldClose: (id) window
  206794. {
  206795. return owner == 0 || owner->windowShouldClose();
  206796. }
  206797. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206798. {
  206799. if (owner != 0)
  206800. frameRect = owner->constrainRect (frameRect);
  206801. return frameRect;
  206802. }
  206803. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206804. {
  206805. if (isZooming)
  206806. return proposedFrameSize;
  206807. NSRect frameRect = [self frame];
  206808. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206809. frameRect.size = proposedFrameSize;
  206810. if (owner != 0)
  206811. frameRect = owner->constrainRect (frameRect);
  206812. return frameRect.size;
  206813. }
  206814. - (void) zoom: (id) sender
  206815. {
  206816. isZooming = true;
  206817. [super zoom: sender];
  206818. isZooming = false;
  206819. }
  206820. - (void) windowWillMove: (NSNotification*) notification
  206821. {
  206822. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206823. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206824. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206825. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206826. }
  206827. @end
  206828. BEGIN_JUCE_NAMESPACE
  206829. static ComponentPeer* currentlyFocusedPeer = 0;
  206830. static VoidArray keysCurrentlyDown;
  206831. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206832. {
  206833. if (keysCurrentlyDown.contains ((void*) keyCode))
  206834. return true;
  206835. if (keyCode >= 'A' && keyCode <= 'Z'
  206836. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206837. return true;
  206838. if (keyCode >= 'a' && keyCode <= 'z'
  206839. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  206840. return true;
  206841. return false;
  206842. }
  206843. static int getKeyCodeFromEvent (NSEvent* ev)
  206844. {
  206845. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206846. int keyCode = unmodified[0];
  206847. if (keyCode == 0x19) // (backwards-tab)
  206848. keyCode = '\t';
  206849. else if (keyCode == 0x03) // (enter)
  206850. keyCode = '\r';
  206851. return keyCode;
  206852. }
  206853. static int currentModifiers = 0;
  206854. static void updateModifiers (NSEvent* e)
  206855. {
  206856. int m = currentModifiers & ~(ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier
  206857. | ModifierKeys::altModifier | ModifierKeys::commandModifier);
  206858. if (([e modifierFlags] & NSShiftKeyMask) != 0)
  206859. m |= ModifierKeys::shiftModifier;
  206860. if (([e modifierFlags] & NSControlKeyMask) != 0)
  206861. m |= ModifierKeys::ctrlModifier;
  206862. if (([e modifierFlags] & NSAlternateKeyMask) != 0)
  206863. m |= ModifierKeys::altModifier;
  206864. if (([e modifierFlags] & NSCommandKeyMask) != 0)
  206865. m |= ModifierKeys::commandModifier;
  206866. currentModifiers = m;
  206867. }
  206868. static void updateKeysDown (NSEvent* ev, bool isKeyDown)
  206869. {
  206870. updateModifiers (ev);
  206871. int keyCode = getKeyCodeFromEvent (ev);
  206872. if (keyCode != 0)
  206873. {
  206874. if (isKeyDown)
  206875. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  206876. else
  206877. keysCurrentlyDown.removeValue ((void*) keyCode);
  206878. }
  206879. }
  206880. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  206881. {
  206882. return ModifierKeys (currentModifiers);
  206883. }
  206884. void ModifierKeys::updateCurrentModifiers() throw()
  206885. {
  206886. currentModifierFlags = currentModifiers;
  206887. }
  206888. static int64 getMouseTime (NSEvent* e)
  206889. {
  206890. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206891. + (int64) ([e timestamp] * 1000.0);
  206892. }
  206893. static void getMousePos (NSEvent* e, NSView* view, int& x, int& y)
  206894. {
  206895. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206896. x = roundToInt (p.x);
  206897. y = roundToInt ([view frame].size.height - p.y);
  206898. }
  206899. static int getModifierForButtonNumber (const NSInteger num)
  206900. {
  206901. return num == 0 ? ModifierKeys::leftButtonModifier
  206902. : (num == 1 ? ModifierKeys::rightButtonModifier
  206903. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206904. }
  206905. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  206906. const int windowStyleFlags,
  206907. NSView* viewToAttachTo)
  206908. : ComponentPeer (component_, windowStyleFlags),
  206909. window (0),
  206910. view (0),
  206911. isSharedWindow (viewToAttachTo != 0),
  206912. fullScreen (false),
  206913. insideDrawRect (false),
  206914. #if USE_COREGRAPHICS_RENDERING
  206915. usingCoreGraphics (true),
  206916. #else
  206917. usingCoreGraphics (false),
  206918. #endif
  206919. recursiveToFrontCall (false)
  206920. {
  206921. NSRect r;
  206922. r.origin.x = 0;
  206923. r.origin.y = 0;
  206924. r.size.width = (float) component->getWidth();
  206925. r.size.height = (float) component->getHeight();
  206926. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  206927. [view setPostsFrameChangedNotifications: YES];
  206928. if (isSharedWindow)
  206929. {
  206930. window = [viewToAttachTo window];
  206931. [viewToAttachTo addSubview: view];
  206932. setVisible (component->isVisible());
  206933. }
  206934. else
  206935. {
  206936. r.origin.x = (float) component->getX();
  206937. r.origin.y = (float) component->getY();
  206938. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  206939. unsigned int style = 0;
  206940. if ((windowStyleFlags & windowHasTitleBar) == 0)
  206941. style = NSBorderlessWindowMask;
  206942. else
  206943. style = NSTitledWindowMask;
  206944. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  206945. style |= NSMiniaturizableWindowMask;
  206946. if ((windowStyleFlags & windowHasCloseButton) != 0)
  206947. style |= NSClosableWindowMask;
  206948. if ((windowStyleFlags & windowIsResizable) != 0)
  206949. style |= NSResizableWindowMask;
  206950. window = [[JuceNSWindow alloc] initWithContentRect: r
  206951. styleMask: style
  206952. backing: NSBackingStoreBuffered
  206953. defer: YES];
  206954. [((JuceNSWindow*) window) setOwner: this];
  206955. [window orderOut: nil];
  206956. [window setDelegate: (JuceNSWindow*) window];
  206957. [window setOpaque: component->isOpaque()];
  206958. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  206959. if (component->isAlwaysOnTop())
  206960. [window setLevel: NSFloatingWindowLevel];
  206961. [window setContentView: view];
  206962. [window setAutodisplay: YES];
  206963. [window setAcceptsMouseMovedEvents: YES];
  206964. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  206965. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  206966. [window setReleasedWhenClosed: YES];
  206967. [window retain];
  206968. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  206969. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  206970. }
  206971. setTitle (component->getName());
  206972. }
  206973. NSViewComponentPeer::~NSViewComponentPeer()
  206974. {
  206975. view->owner = 0;
  206976. [view removeFromSuperview];
  206977. [view release];
  206978. if (! isSharedWindow)
  206979. {
  206980. [((JuceNSWindow*) window) setOwner: 0];
  206981. [window close];
  206982. [window release];
  206983. }
  206984. }
  206985. void* NSViewComponentPeer::getNativeHandle() const
  206986. {
  206987. return view;
  206988. }
  206989. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  206990. {
  206991. if (isSharedWindow)
  206992. {
  206993. [view setHidden: ! shouldBeVisible];
  206994. }
  206995. else
  206996. {
  206997. if (shouldBeVisible)
  206998. {
  206999. [window orderFront: nil];
  207000. handleBroughtToFront();
  207001. }
  207002. else
  207003. {
  207004. [window orderOut: nil];
  207005. }
  207006. }
  207007. }
  207008. void NSViewComponentPeer::setTitle (const String& title)
  207009. {
  207010. const ScopedAutoReleasePool pool;
  207011. if (! isSharedWindow)
  207012. [window setTitle: juceStringToNS (title)];
  207013. }
  207014. void NSViewComponentPeer::setPosition (int x, int y)
  207015. {
  207016. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207017. }
  207018. void NSViewComponentPeer::setSize (int w, int h)
  207019. {
  207020. setBounds (component->getX(), component->getY(), w, h, false);
  207021. }
  207022. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207023. {
  207024. fullScreen = isNowFullScreen;
  207025. w = jmax (0, w);
  207026. h = jmax (0, h);
  207027. NSRect r;
  207028. r.origin.x = (float) x;
  207029. r.origin.y = (float) y;
  207030. r.size.width = (float) w;
  207031. r.size.height = (float) h;
  207032. if (isSharedWindow)
  207033. {
  207034. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207035. if ([view frame].size.width != r.size.width
  207036. || [view frame].size.height != r.size.height)
  207037. [view setNeedsDisplay: true];
  207038. [view setFrame: r];
  207039. }
  207040. else
  207041. {
  207042. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207043. [window setFrame: [window frameRectForContentRect: r]
  207044. display: true];
  207045. }
  207046. }
  207047. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  207048. {
  207049. NSRect r = [view frame];
  207050. if (global && [view window] != 0)
  207051. {
  207052. r = [view convertRect: r toView: nil];
  207053. NSRect wr = [[view window] frame];
  207054. r.origin.x += wr.origin.x;
  207055. r.origin.y += wr.origin.y;
  207056. y = (int) ([[[NSScreen screens] objectAtIndex:0] frame].size.height - r.origin.y - r.size.height);
  207057. }
  207058. else
  207059. {
  207060. y = (int) ([[view superview] frame].size.height - r.origin.y - r.size.height);
  207061. }
  207062. x = (int) r.origin.x;
  207063. w = (int) r.size.width;
  207064. h = (int) r.size.height;
  207065. }
  207066. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  207067. {
  207068. getBounds (x, y, w, h, ! isSharedWindow);
  207069. }
  207070. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207071. {
  207072. int x, y, w, h;
  207073. getBounds (x, y, w, h, true);
  207074. return Point<int> (x, y);
  207075. }
  207076. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207077. {
  207078. return relativePosition + getScreenPosition();
  207079. }
  207080. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207081. {
  207082. return screenPosition - getScreenPosition();
  207083. }
  207084. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207085. {
  207086. if (constrainer != 0)
  207087. {
  207088. NSRect current = [window frame];
  207089. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207090. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207091. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207092. (int) r.size.width, (int) r.size.height);
  207093. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207094. (int) current.size.width, (int) current.size.height);
  207095. constrainer->checkBounds (pos, original,
  207096. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207097. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207098. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207099. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207100. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207101. r.origin.x = pos.getX();
  207102. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207103. r.size.width = pos.getWidth();
  207104. r.size.height = pos.getHeight();
  207105. }
  207106. return r;
  207107. }
  207108. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207109. {
  207110. if (! isSharedWindow)
  207111. {
  207112. if (shouldBeMinimised)
  207113. [window miniaturize: nil];
  207114. else
  207115. [window deminiaturize: nil];
  207116. }
  207117. }
  207118. bool NSViewComponentPeer::isMinimised() const
  207119. {
  207120. return window != 0 && [window isMiniaturized];
  207121. }
  207122. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207123. {
  207124. if (! isSharedWindow)
  207125. {
  207126. Rectangle<int> r (lastNonFullscreenBounds);
  207127. setMinimised (false);
  207128. if (fullScreen != shouldBeFullScreen)
  207129. {
  207130. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207131. {
  207132. fullScreen = true;
  207133. [window performZoom: nil];
  207134. }
  207135. else
  207136. {
  207137. if (shouldBeFullScreen)
  207138. r = Desktop::getInstance().getMainMonitorArea();
  207139. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207140. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207141. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207142. }
  207143. }
  207144. }
  207145. }
  207146. bool NSViewComponentPeer::isFullScreen() const
  207147. {
  207148. return fullScreen;
  207149. }
  207150. bool NSViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  207151. {
  207152. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  207153. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  207154. return false;
  207155. NSPoint p;
  207156. p.x = (float) x;
  207157. p.y = (float) y;
  207158. NSView* v = [view hitTest: p];
  207159. if (trueIfInAChildWindow)
  207160. return v != nil;
  207161. return v == view;
  207162. }
  207163. const BorderSize NSViewComponentPeer::getFrameSize() const
  207164. {
  207165. BorderSize b;
  207166. if (! isSharedWindow)
  207167. {
  207168. NSRect v = [view convertRect: [view frame] toView: nil];
  207169. NSRect w = [window frame];
  207170. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207171. b.setBottom ((int) v.origin.y);
  207172. b.setLeft ((int) v.origin.x);
  207173. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207174. }
  207175. return b;
  207176. }
  207177. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207178. {
  207179. if (! isSharedWindow)
  207180. {
  207181. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207182. : NSNormalWindowLevel];
  207183. }
  207184. return true;
  207185. }
  207186. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207187. {
  207188. if (isSharedWindow)
  207189. {
  207190. [[view superview] addSubview: view
  207191. positioned: NSWindowAbove
  207192. relativeTo: nil];
  207193. }
  207194. if (window != 0 && component->isVisible())
  207195. {
  207196. if (makeActiveWindow)
  207197. [window makeKeyAndOrderFront: nil];
  207198. else
  207199. [window orderFront: nil];
  207200. if (! recursiveToFrontCall)
  207201. {
  207202. recursiveToFrontCall = true;
  207203. handleBroughtToFront();
  207204. recursiveToFrontCall = false;
  207205. }
  207206. }
  207207. }
  207208. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207209. {
  207210. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207211. if (isSharedWindow)
  207212. {
  207213. [[view superview] addSubview: view
  207214. positioned: NSWindowBelow
  207215. relativeTo: o->view];
  207216. }
  207217. else
  207218. {
  207219. [window orderWindow: NSWindowBelow
  207220. relativeTo: o->window != 0 ? [o->window windowNumber]
  207221. : nil ];
  207222. }
  207223. }
  207224. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207225. {
  207226. // to do..
  207227. }
  207228. void NSViewComponentPeer::viewFocusGain()
  207229. {
  207230. if (currentlyFocusedPeer != this)
  207231. {
  207232. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207233. currentlyFocusedPeer->handleFocusLoss();
  207234. currentlyFocusedPeer = this;
  207235. handleFocusGain();
  207236. }
  207237. }
  207238. void NSViewComponentPeer::viewFocusLoss()
  207239. {
  207240. if (currentlyFocusedPeer == this)
  207241. {
  207242. currentlyFocusedPeer = 0;
  207243. handleFocusLoss();
  207244. }
  207245. }
  207246. void juce_HandleProcessFocusChange()
  207247. {
  207248. keysCurrentlyDown.clear();
  207249. if (NSViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  207250. {
  207251. if (Process::isForegroundProcess())
  207252. {
  207253. currentlyFocusedPeer->handleFocusGain();
  207254. ComponentPeer::bringModalComponentToFront();
  207255. }
  207256. else
  207257. {
  207258. currentlyFocusedPeer->handleFocusLoss();
  207259. // turn kiosk mode off if we lose focus..
  207260. Desktop::getInstance().setKioskModeComponent (0);
  207261. }
  207262. }
  207263. }
  207264. bool NSViewComponentPeer::isFocused() const
  207265. {
  207266. return isSharedWindow ? this == currentlyFocusedPeer
  207267. : (window != 0 && [window isKeyWindow]);
  207268. }
  207269. void NSViewComponentPeer::grabFocus()
  207270. {
  207271. if (window != 0)
  207272. {
  207273. [window makeKeyWindow];
  207274. [window makeFirstResponder: view];
  207275. viewFocusGain();
  207276. }
  207277. }
  207278. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207279. {
  207280. }
  207281. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207282. {
  207283. String unicode (nsStringToJuce ([ev characters]));
  207284. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207285. int keyCode = getKeyCodeFromEvent (ev);
  207286. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207287. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207288. if (unicode.isNotEmpty() || keyCode != 0)
  207289. {
  207290. if (isKeyDown)
  207291. {
  207292. bool used = false;
  207293. while (unicode.length() > 0)
  207294. {
  207295. juce_wchar textCharacter = unicode[0];
  207296. unicode = unicode.substring (1);
  207297. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207298. textCharacter = 0;
  207299. used = handleKeyUpOrDown (true) || used;
  207300. used = handleKeyPress (keyCode, textCharacter) || used;
  207301. }
  207302. return used;
  207303. }
  207304. else
  207305. {
  207306. if (handleKeyUpOrDown (false))
  207307. return true;
  207308. }
  207309. }
  207310. return false;
  207311. }
  207312. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207313. {
  207314. updateKeysDown (ev, true);
  207315. bool used = handleKeyEvent (ev, true);
  207316. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207317. {
  207318. // for command keys, the key-up event is thrown away, so simulate one..
  207319. updateKeysDown (ev, false);
  207320. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207321. }
  207322. // (If we're running modally, don't allow unused keystrokes to be passed
  207323. // along to other blocked views..)
  207324. if (Component::getCurrentlyModalComponent() != 0)
  207325. used = true;
  207326. return used;
  207327. }
  207328. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207329. {
  207330. updateKeysDown (ev, false);
  207331. return handleKeyEvent (ev, false)
  207332. || Component::getCurrentlyModalComponent() != 0;
  207333. }
  207334. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207335. {
  207336. keysCurrentlyDown.clear();
  207337. handleKeyUpOrDown (true);
  207338. updateModifiers (ev);
  207339. handleModifierKeysChange();
  207340. }
  207341. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207342. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207343. {
  207344. if ([ev type] == NSKeyDown)
  207345. return redirectKeyDown (ev);
  207346. else if ([ev type] == NSKeyUp)
  207347. return redirectKeyUp (ev);
  207348. return false;
  207349. }
  207350. #endif
  207351. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207352. {
  207353. updateModifiers (ev);
  207354. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207355. int x, y;
  207356. getMousePos (ev, view, x, y);
  207357. handleMouseDown (x, y, getMouseTime (ev));
  207358. }
  207359. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207360. {
  207361. const int oldMods = currentModifiers;
  207362. updateModifiers (ev);
  207363. currentModifiers &= ~getModifierForButtonNumber ([ev buttonNumber]);
  207364. int x, y;
  207365. getMousePos (ev, view, x, y);
  207366. handleMouseUp (oldMods, x, y, getMouseTime (ev));
  207367. showArrowCursorIfNeeded();
  207368. }
  207369. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207370. {
  207371. updateModifiers (ev);
  207372. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207373. int x, y;
  207374. getMousePos (ev, view, x, y);
  207375. handleMouseDrag (x, y, getMouseTime (ev));
  207376. }
  207377. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207378. {
  207379. updateModifiers (ev);
  207380. int x, y;
  207381. getMousePos (ev, view, x, y);
  207382. handleMouseMove (x, y, getMouseTime (ev));
  207383. showArrowCursorIfNeeded();
  207384. }
  207385. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207386. {
  207387. updateModifiers (ev);
  207388. int x, y;
  207389. getMousePos (ev, view, x, y);
  207390. handleMouseEnter (x, y, getMouseTime (ev));
  207391. }
  207392. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207393. {
  207394. updateModifiers (ev);
  207395. int x, y;
  207396. getMousePos (ev, view, x, y);
  207397. handleMouseExit (x, y, getMouseTime (ev));
  207398. }
  207399. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207400. {
  207401. updateModifiers (ev);
  207402. handleMouseWheel (roundToInt ([ev deltaX] * 10.0f),
  207403. roundToInt ([ev deltaY] * 10.0f),
  207404. getMouseTime (ev));
  207405. }
  207406. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207407. {
  207408. if (Component::getComponentUnderMouse() == 0
  207409. && Desktop::getInstance().findComponentAt (Desktop::getInstance().getMousePosition()) == 0)
  207410. {
  207411. [[NSCursor arrowCursor] set];
  207412. }
  207413. }
  207414. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207415. {
  207416. NSString* bestType
  207417. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207418. if (bestType == nil)
  207419. return false;
  207420. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207421. int x = (int) p.x;
  207422. int y = (int) ([view frame].size.height - p.y);
  207423. StringArray files;
  207424. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207425. if (list == nil)
  207426. return false;
  207427. if ([list isKindOfClass: [NSArray class]])
  207428. {
  207429. NSArray* items = (NSArray*) list;
  207430. for (unsigned int i = 0; i < [items count]; ++i)
  207431. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207432. }
  207433. if (files.size() == 0)
  207434. return false;
  207435. if (type == 0)
  207436. handleFileDragMove (files, x, y);
  207437. else if (type == 1)
  207438. handleFileDragExit (files);
  207439. else if (type == 2)
  207440. handleFileDragDrop (files, x, y);
  207441. return true;
  207442. }
  207443. bool NSViewComponentPeer::isOpaque()
  207444. {
  207445. if (! getComponent()->isValidComponent())
  207446. return true;
  207447. return getComponent()->isOpaque();
  207448. }
  207449. void NSViewComponentPeer::drawRect (NSRect r)
  207450. {
  207451. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207452. return;
  207453. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207454. if (! component->isOpaque())
  207455. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207456. #if USE_COREGRAPHICS_RENDERING
  207457. if (usingCoreGraphics)
  207458. {
  207459. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207460. insideDrawRect = true;
  207461. handlePaint (context);
  207462. insideDrawRect = false;
  207463. }
  207464. else
  207465. #endif
  207466. {
  207467. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207468. (int) (r.size.width + 0.5f),
  207469. (int) (r.size.height + 0.5f),
  207470. ! getComponent()->isOpaque());
  207471. LowLevelGraphicsSoftwareRenderer context (temp);
  207472. context.setOrigin (-roundToInt (r.origin.x),
  207473. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207474. const NSRect* rects = 0;
  207475. NSInteger numRects = 0;
  207476. [view getRectsBeingDrawn: &rects count: &numRects];
  207477. RectangleList clip;
  207478. for (int i = 0; i < numRects; ++i)
  207479. {
  207480. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207481. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207482. roundToInt (rects[i].size.width),
  207483. roundToInt (rects[i].size.height)));
  207484. }
  207485. if (context.clipToRectangleList (clip))
  207486. {
  207487. insideDrawRect = true;
  207488. handlePaint (context);
  207489. insideDrawRect = false;
  207490. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207491. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207492. CGColorSpaceRelease (colourSpace);
  207493. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207494. CGImageRelease (image);
  207495. }
  207496. }
  207497. }
  207498. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207499. {
  207500. StringArray s;
  207501. s.add ("Software Renderer");
  207502. #if USE_COREGRAPHICS_RENDERING
  207503. s.add ("CoreGraphics Renderer");
  207504. #endif
  207505. return s;
  207506. }
  207507. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207508. {
  207509. return usingCoreGraphics ? 1 : 0;
  207510. }
  207511. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207512. {
  207513. #if USE_COREGRAPHICS_RENDERING
  207514. if (usingCoreGraphics != (index > 0))
  207515. {
  207516. usingCoreGraphics = index > 0;
  207517. [view setNeedsDisplay: true];
  207518. }
  207519. #endif
  207520. }
  207521. bool NSViewComponentPeer::canBecomeKeyWindow()
  207522. {
  207523. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207524. }
  207525. bool NSViewComponentPeer::windowShouldClose()
  207526. {
  207527. if (! isValidPeer (this))
  207528. return YES;
  207529. handleUserClosingWindow();
  207530. return NO;
  207531. }
  207532. void NSViewComponentPeer::redirectMovedOrResized()
  207533. {
  207534. handleMovedOrResized();
  207535. }
  207536. void NSViewComponentPeer::viewMovedToWindow()
  207537. {
  207538. if (isSharedWindow)
  207539. window = [view window];
  207540. }
  207541. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207542. {
  207543. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207544. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207545. // is apparently still available in 64-bit apps..
  207546. if (enableOrDisable)
  207547. {
  207548. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207549. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207550. }
  207551. else
  207552. {
  207553. SetSystemUIMode (kUIModeNormal, 0);
  207554. }
  207555. }
  207556. class AsyncRepaintMessage : public CallbackMessage
  207557. {
  207558. public:
  207559. NSViewComponentPeer* const peer;
  207560. const Rectangle<int> rect;
  207561. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207562. : peer (peer_), rect (rect_)
  207563. {
  207564. }
  207565. void messageCallback()
  207566. {
  207567. if (ComponentPeer::isValidPeer (peer))
  207568. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207569. }
  207570. };
  207571. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207572. {
  207573. if (insideDrawRect)
  207574. {
  207575. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207576. }
  207577. else
  207578. {
  207579. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207580. (float) w, (float) h)];
  207581. }
  207582. }
  207583. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207584. {
  207585. [view displayIfNeeded];
  207586. }
  207587. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207588. {
  207589. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207590. }
  207591. Image* juce_createIconForFile (const File& file)
  207592. {
  207593. const ScopedAutoReleasePool pool;
  207594. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207595. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207596. [NSGraphicsContext saveGraphicsState];
  207597. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207598. [image drawAtPoint: NSMakePoint (0, 0)
  207599. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207600. operation: NSCompositeSourceOver fraction: 1.0f];
  207601. [[NSGraphicsContext currentContext] flushGraphics];
  207602. [NSGraphicsContext restoreGraphicsState];
  207603. return result;
  207604. }
  207605. const int KeyPress::spaceKey = ' ';
  207606. const int KeyPress::returnKey = 0x0d;
  207607. const int KeyPress::escapeKey = 0x1b;
  207608. const int KeyPress::backspaceKey = 0x7f;
  207609. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207610. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207611. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207612. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207613. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207614. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207615. const int KeyPress::endKey = NSEndFunctionKey;
  207616. const int KeyPress::homeKey = NSHomeFunctionKey;
  207617. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207618. const int KeyPress::insertKey = -1;
  207619. const int KeyPress::tabKey = 9;
  207620. const int KeyPress::F1Key = NSF1FunctionKey;
  207621. const int KeyPress::F2Key = NSF2FunctionKey;
  207622. const int KeyPress::F3Key = NSF3FunctionKey;
  207623. const int KeyPress::F4Key = NSF4FunctionKey;
  207624. const int KeyPress::F5Key = NSF5FunctionKey;
  207625. const int KeyPress::F6Key = NSF6FunctionKey;
  207626. const int KeyPress::F7Key = NSF7FunctionKey;
  207627. const int KeyPress::F8Key = NSF8FunctionKey;
  207628. const int KeyPress::F9Key = NSF9FunctionKey;
  207629. const int KeyPress::F10Key = NSF10FunctionKey;
  207630. const int KeyPress::F11Key = NSF1FunctionKey;
  207631. const int KeyPress::F12Key = NSF12FunctionKey;
  207632. const int KeyPress::F13Key = NSF13FunctionKey;
  207633. const int KeyPress::F14Key = NSF14FunctionKey;
  207634. const int KeyPress::F15Key = NSF15FunctionKey;
  207635. const int KeyPress::F16Key = NSF16FunctionKey;
  207636. const int KeyPress::numberPad0 = 0x30020;
  207637. const int KeyPress::numberPad1 = 0x30021;
  207638. const int KeyPress::numberPad2 = 0x30022;
  207639. const int KeyPress::numberPad3 = 0x30023;
  207640. const int KeyPress::numberPad4 = 0x30024;
  207641. const int KeyPress::numberPad5 = 0x30025;
  207642. const int KeyPress::numberPad6 = 0x30026;
  207643. const int KeyPress::numberPad7 = 0x30027;
  207644. const int KeyPress::numberPad8 = 0x30028;
  207645. const int KeyPress::numberPad9 = 0x30029;
  207646. const int KeyPress::numberPadAdd = 0x3002a;
  207647. const int KeyPress::numberPadSubtract = 0x3002b;
  207648. const int KeyPress::numberPadMultiply = 0x3002c;
  207649. const int KeyPress::numberPadDivide = 0x3002d;
  207650. const int KeyPress::numberPadSeparator = 0x3002e;
  207651. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207652. const int KeyPress::numberPadEquals = 0x30030;
  207653. const int KeyPress::numberPadDelete = 0x30031;
  207654. const int KeyPress::playKey = 0x30000;
  207655. const int KeyPress::stopKey = 0x30001;
  207656. const int KeyPress::fastForwardKey = 0x30002;
  207657. const int KeyPress::rewindKey = 0x30003;
  207658. #endif
  207659. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207660. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207661. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207662. // compiled on its own).
  207663. #if JUCE_INCLUDED_FILE
  207664. #if JUCE_MAC
  207665. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207666. {
  207667. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207668. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207669. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207670. [im release];
  207671. return (void*) c;
  207672. }
  207673. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207674. {
  207675. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  207676. jassert (im != 0);
  207677. if (im == 0)
  207678. return 0;
  207679. return juce_createMouseCursorFromImage (*im,
  207680. (int) (hx * im->getWidth()),
  207681. (int) (hy * im->getHeight()));
  207682. }
  207683. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207684. {
  207685. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207686. MemoryBlock mb;
  207687. if (f.getChildFile (filename).loadFileAsData (mb))
  207688. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207689. return 0;
  207690. }
  207691. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207692. {
  207693. const ScopedAutoReleasePool pool;
  207694. NSCursor* c = 0;
  207695. switch (type)
  207696. {
  207697. case MouseCursor::NormalCursor:
  207698. c = [NSCursor arrowCursor];
  207699. break;
  207700. case MouseCursor::NoCursor:
  207701. {
  207702. Image blank (Image::ARGB, 8, 8, true);
  207703. return juce_createMouseCursorFromImage (blank, 0, 0);
  207704. }
  207705. case MouseCursor::DraggingHandCursor:
  207706. c = [NSCursor openHandCursor];
  207707. break;
  207708. case MouseCursor::CopyingCursor:
  207709. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207710. case MouseCursor::WaitCursor:
  207711. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207712. break;
  207713. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207714. case MouseCursor::IBeamCursor:
  207715. c = [NSCursor IBeamCursor];
  207716. break;
  207717. case MouseCursor::PointingHandCursor:
  207718. c = [NSCursor pointingHandCursor];
  207719. break;
  207720. case MouseCursor::LeftRightResizeCursor:
  207721. c = [NSCursor resizeLeftRightCursor];
  207722. break;
  207723. case MouseCursor::LeftEdgeResizeCursor:
  207724. c = [NSCursor resizeLeftCursor];
  207725. break;
  207726. case MouseCursor::RightEdgeResizeCursor:
  207727. c = [NSCursor resizeRightCursor];
  207728. break;
  207729. case MouseCursor::UpDownResizeCursor:
  207730. case MouseCursor::TopEdgeResizeCursor:
  207731. case MouseCursor::BottomEdgeResizeCursor:
  207732. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207733. case MouseCursor::TopLeftCornerResizeCursor:
  207734. case MouseCursor::BottomRightCornerResizeCursor:
  207735. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207736. case MouseCursor::TopRightCornerResizeCursor:
  207737. case MouseCursor::BottomLeftCornerResizeCursor:
  207738. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207739. case MouseCursor::UpDownLeftRightResizeCursor:
  207740. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207741. case MouseCursor::CrosshairCursor:
  207742. c = [NSCursor crosshairCursor];
  207743. break;
  207744. }
  207745. [c retain];
  207746. return (void*) c;
  207747. }
  207748. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207749. {
  207750. NSCursor* c = (NSCursor*) cursorHandle;
  207751. [c release];
  207752. }
  207753. void MouseCursor::showInAllWindows() const throw()
  207754. {
  207755. showInWindow (0);
  207756. }
  207757. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207758. {
  207759. NSCursor* const c = (NSCursor*) getHandle();
  207760. [c set];
  207761. }
  207762. #else
  207763. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207764. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207765. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207766. void MouseCursor::showInAllWindows() const throw() {}
  207767. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207768. #endif
  207769. #endif
  207770. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207771. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207772. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207773. // compiled on its own).
  207774. #if JUCE_INCLUDED_FILE
  207775. class NSViewComponentInternal : public ComponentMovementWatcher
  207776. {
  207777. Component* const owner;
  207778. NSViewComponentPeer* currentPeer;
  207779. bool wasShowing;
  207780. public:
  207781. NSView* const view;
  207782. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207783. : ComponentMovementWatcher (owner_),
  207784. owner (owner_),
  207785. currentPeer (0),
  207786. wasShowing (false),
  207787. view (view_)
  207788. {
  207789. [view_ retain];
  207790. if (owner_->isShowing())
  207791. componentPeerChanged();
  207792. }
  207793. ~NSViewComponentInternal()
  207794. {
  207795. [view removeFromSuperview];
  207796. [view release];
  207797. }
  207798. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207799. {
  207800. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207801. // The ComponentMovementWatcher version of this method avoids calling
  207802. // us when the top-level comp is resized, but for an NSView we need to know this
  207803. // because with inverted co-ords, we need to update the position even if the
  207804. // top-left pos hasn't changed
  207805. if (comp.isOnDesktop() && wasResized)
  207806. componentMovedOrResized (wasMoved, wasResized);
  207807. }
  207808. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207809. {
  207810. Component* const topComp = owner->getTopLevelComponent();
  207811. if (topComp->getPeer() != 0)
  207812. {
  207813. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207814. NSRect r;
  207815. r.origin.x = (float) pos.getX();
  207816. r.origin.y = (float) pos.getY();
  207817. r.size.width = (float) owner->getWidth();
  207818. r.size.height = (float) owner->getHeight();
  207819. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207820. [view setFrame: r];
  207821. }
  207822. }
  207823. void componentPeerChanged()
  207824. {
  207825. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207826. if (currentPeer != peer)
  207827. {
  207828. [view removeFromSuperview];
  207829. currentPeer = peer;
  207830. if (peer != 0)
  207831. {
  207832. [peer->view addSubview: view];
  207833. componentMovedOrResized (false, false);
  207834. }
  207835. }
  207836. [view setHidden: ! owner->isShowing()];
  207837. }
  207838. void componentVisibilityChanged (Component&)
  207839. {
  207840. componentPeerChanged();
  207841. }
  207842. juce_UseDebuggingNewOperator
  207843. private:
  207844. NSViewComponentInternal (const NSViewComponentInternal&);
  207845. const NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207846. };
  207847. NSViewComponent::NSViewComponent()
  207848. {
  207849. }
  207850. NSViewComponent::~NSViewComponent()
  207851. {
  207852. }
  207853. void NSViewComponent::setView (void* view)
  207854. {
  207855. if (view != getView())
  207856. {
  207857. if (view != 0)
  207858. info = new NSViewComponentInternal ((NSView*) view, this);
  207859. else
  207860. info = 0;
  207861. }
  207862. }
  207863. void* NSViewComponent::getView() const
  207864. {
  207865. return info == 0 ? 0 : info->view;
  207866. }
  207867. void NSViewComponent::paint (Graphics& g)
  207868. {
  207869. }
  207870. #endif
  207871. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207872. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207873. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207874. // compiled on its own).
  207875. #if JUCE_INCLUDED_FILE
  207876. AppleRemoteDevice::AppleRemoteDevice()
  207877. : device (0),
  207878. queue (0),
  207879. remoteId (0)
  207880. {
  207881. }
  207882. AppleRemoteDevice::~AppleRemoteDevice()
  207883. {
  207884. stop();
  207885. }
  207886. static io_object_t getAppleRemoteDevice()
  207887. {
  207888. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207889. io_iterator_t iter = 0;
  207890. io_object_t iod = 0;
  207891. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207892. && iter != 0)
  207893. {
  207894. iod = IOIteratorNext (iter);
  207895. }
  207896. IOObjectRelease (iter);
  207897. return iod;
  207898. }
  207899. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  207900. {
  207901. jassert (*device == 0);
  207902. io_name_t classname;
  207903. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  207904. {
  207905. IOCFPlugInInterface** cfPlugInInterface = 0;
  207906. SInt32 score = 0;
  207907. if (IOCreatePlugInInterfaceForService (iod,
  207908. kIOHIDDeviceUserClientTypeID,
  207909. kIOCFPlugInInterfaceID,
  207910. &cfPlugInInterface,
  207911. &score) == kIOReturnSuccess)
  207912. {
  207913. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  207914. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  207915. device);
  207916. (void) hr;
  207917. (*cfPlugInInterface)->Release (cfPlugInInterface);
  207918. }
  207919. }
  207920. return *device != 0;
  207921. }
  207922. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  207923. {
  207924. if (queue != 0)
  207925. return true;
  207926. stop();
  207927. bool result = false;
  207928. io_object_t iod = getAppleRemoteDevice();
  207929. if (iod != 0)
  207930. {
  207931. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  207932. result = true;
  207933. else
  207934. stop();
  207935. IOObjectRelease (iod);
  207936. }
  207937. return result;
  207938. }
  207939. void AppleRemoteDevice::stop()
  207940. {
  207941. if (queue != 0)
  207942. {
  207943. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  207944. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  207945. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  207946. queue = 0;
  207947. }
  207948. if (device != 0)
  207949. {
  207950. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  207951. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  207952. device = 0;
  207953. }
  207954. }
  207955. bool AppleRemoteDevice::isActive() const
  207956. {
  207957. return queue != 0;
  207958. }
  207959. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  207960. {
  207961. if (result == kIOReturnSuccess)
  207962. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  207963. }
  207964. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  207965. {
  207966. Array <int> cookies;
  207967. CFArrayRef elements;
  207968. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  207969. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  207970. return false;
  207971. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  207972. {
  207973. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  207974. // get the cookie
  207975. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  207976. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  207977. continue;
  207978. long number;
  207979. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  207980. continue;
  207981. cookies.add ((int) number);
  207982. }
  207983. CFRelease (elements);
  207984. if ((*(IOHIDDeviceInterface**) device)
  207985. ->open ((IOHIDDeviceInterface**) device,
  207986. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  207987. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  207988. {
  207989. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  207990. if (queue != 0)
  207991. {
  207992. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  207993. for (int i = 0; i < cookies.size(); ++i)
  207994. {
  207995. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  207996. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  207997. }
  207998. CFRunLoopSourceRef eventSource;
  207999. if ((*(IOHIDQueueInterface**) queue)
  208000. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208001. {
  208002. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208003. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208004. {
  208005. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208006. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208007. return true;
  208008. }
  208009. }
  208010. }
  208011. }
  208012. return false;
  208013. }
  208014. void AppleRemoteDevice::handleCallbackInternal()
  208015. {
  208016. int totalValues = 0;
  208017. AbsoluteTime nullTime = { 0, 0 };
  208018. char cookies [12];
  208019. int numCookies = 0;
  208020. while (numCookies < numElementsInArray (cookies))
  208021. {
  208022. IOHIDEventStruct e;
  208023. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208024. break;
  208025. if ((int) e.elementCookie == 19)
  208026. {
  208027. remoteId = e.value;
  208028. buttonPressed (switched, false);
  208029. }
  208030. else
  208031. {
  208032. totalValues += e.value;
  208033. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208034. }
  208035. }
  208036. cookies [numCookies++] = 0;
  208037. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208038. static const char buttonPatterns[] =
  208039. {
  208040. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208041. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208042. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208043. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208044. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208045. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208046. 0x1f, 0x12, 0x04, 0x02, 0,
  208047. 0x1f, 0x12, 0x03, 0x02, 0,
  208048. 0x1f, 0x12, 0x1f, 0x12, 0,
  208049. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208050. 19, 0
  208051. };
  208052. int buttonNum = (int) menuButton;
  208053. int i = 0;
  208054. while (i < numElementsInArray (buttonPatterns))
  208055. {
  208056. if (strcmp (cookies, buttonPatterns + i) == 0)
  208057. {
  208058. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208059. break;
  208060. }
  208061. i += (int) strlen (buttonPatterns + i) + 1;
  208062. ++buttonNum;
  208063. }
  208064. }
  208065. #endif
  208066. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208067. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208068. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208069. // compiled on its own).
  208070. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208071. #if JUCE_MAC
  208072. END_JUCE_NAMESPACE
  208073. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208074. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208075. {
  208076. CriticalSection* contextLock;
  208077. bool needsUpdate;
  208078. }
  208079. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208080. - (bool) makeActive;
  208081. - (void) makeInactive;
  208082. - (void) reshape;
  208083. @end
  208084. @implementation ThreadSafeNSOpenGLView
  208085. - (id) initWithFrame: (NSRect) frameRect
  208086. pixelFormat: (NSOpenGLPixelFormat*) format
  208087. {
  208088. contextLock = new CriticalSection();
  208089. self = [super initWithFrame: frameRect pixelFormat: format];
  208090. if (self != nil)
  208091. [[NSNotificationCenter defaultCenter] addObserver: self
  208092. selector: @selector (_surfaceNeedsUpdate:)
  208093. name: NSViewGlobalFrameDidChangeNotification
  208094. object: self];
  208095. return self;
  208096. }
  208097. - (void) dealloc
  208098. {
  208099. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208100. delete contextLock;
  208101. [super dealloc];
  208102. }
  208103. - (bool) makeActive
  208104. {
  208105. const ScopedLock sl (*contextLock);
  208106. if ([self openGLContext] == 0)
  208107. return false;
  208108. [[self openGLContext] makeCurrentContext];
  208109. if (needsUpdate)
  208110. {
  208111. [super update];
  208112. needsUpdate = false;
  208113. }
  208114. return true;
  208115. }
  208116. - (void) makeInactive
  208117. {
  208118. const ScopedLock sl (*contextLock);
  208119. [NSOpenGLContext clearCurrentContext];
  208120. }
  208121. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208122. {
  208123. const ScopedLock sl (*contextLock);
  208124. needsUpdate = true;
  208125. }
  208126. - (void) update
  208127. {
  208128. const ScopedLock sl (*contextLock);
  208129. needsUpdate = true;
  208130. }
  208131. - (void) reshape
  208132. {
  208133. const ScopedLock sl (*contextLock);
  208134. needsUpdate = true;
  208135. }
  208136. @end
  208137. BEGIN_JUCE_NAMESPACE
  208138. class WindowedGLContext : public OpenGLContext
  208139. {
  208140. public:
  208141. WindowedGLContext (Component* const component,
  208142. const OpenGLPixelFormat& pixelFormat_,
  208143. NSOpenGLContext* sharedContext)
  208144. : renderContext (0),
  208145. pixelFormat (pixelFormat_)
  208146. {
  208147. jassert (component != 0);
  208148. NSOpenGLPixelFormatAttribute attribs [64];
  208149. int n = 0;
  208150. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208151. attribs[n++] = NSOpenGLPFAAccelerated;
  208152. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208153. attribs[n++] = NSOpenGLPFAColorSize;
  208154. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208155. pixelFormat.greenBits,
  208156. pixelFormat.blueBits);
  208157. attribs[n++] = NSOpenGLPFAAlphaSize;
  208158. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208159. attribs[n++] = NSOpenGLPFADepthSize;
  208160. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208161. attribs[n++] = NSOpenGLPFAStencilSize;
  208162. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208163. attribs[n++] = NSOpenGLPFAAccumSize;
  208164. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208165. pixelFormat.accumulationBufferGreenBits,
  208166. pixelFormat.accumulationBufferBlueBits,
  208167. pixelFormat.accumulationBufferAlphaBits);
  208168. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208169. attribs[n++] = NSOpenGLPFASampleBuffers;
  208170. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208171. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208172. attribs[n++] = NSOpenGLPFANoRecovery;
  208173. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208174. NSOpenGLPixelFormat* format
  208175. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208176. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208177. pixelFormat: format];
  208178. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208179. shareContext: sharedContext] autorelease];
  208180. const GLint swapInterval = 1;
  208181. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208182. [view setOpenGLContext: renderContext];
  208183. [renderContext setView: view];
  208184. [format release];
  208185. viewHolder = new NSViewComponentInternal (view, component);
  208186. }
  208187. ~WindowedGLContext()
  208188. {
  208189. makeInactive();
  208190. [renderContext clearDrawable];
  208191. viewHolder = 0;
  208192. }
  208193. bool makeActive() const throw()
  208194. {
  208195. jassert (renderContext != 0);
  208196. [view makeActive];
  208197. return isActive();
  208198. }
  208199. bool makeInactive() const throw()
  208200. {
  208201. [view makeInactive];
  208202. return true;
  208203. }
  208204. bool isActive() const throw()
  208205. {
  208206. return [NSOpenGLContext currentContext] == renderContext;
  208207. }
  208208. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208209. void* getRawContext() const throw() { return renderContext; }
  208210. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208211. {
  208212. }
  208213. void swapBuffers()
  208214. {
  208215. [renderContext flushBuffer];
  208216. }
  208217. bool setSwapInterval (const int numFramesPerSwap)
  208218. {
  208219. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208220. forParameter: NSOpenGLCPSwapInterval];
  208221. return true;
  208222. }
  208223. int getSwapInterval() const
  208224. {
  208225. GLint numFrames = 0;
  208226. [renderContext getValues: &numFrames
  208227. forParameter: NSOpenGLCPSwapInterval];
  208228. return numFrames;
  208229. }
  208230. void repaint()
  208231. {
  208232. // we need to invalidate the juce view that holds this gl view, to make it
  208233. // cause a repaint callback
  208234. NSView* v = (NSView*) viewHolder->view;
  208235. NSRect r = [v frame];
  208236. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208237. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208238. // repaint message, thus never causing our paint() callback, and never repainting
  208239. // the comp. So invalidating just a little bit around the edge helps..
  208240. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208241. }
  208242. void* getNativeWindowHandle() const { return viewHolder->view; }
  208243. juce_UseDebuggingNewOperator
  208244. NSOpenGLContext* renderContext;
  208245. ThreadSafeNSOpenGLView* view;
  208246. private:
  208247. OpenGLPixelFormat pixelFormat;
  208248. ScopedPointer <NSViewComponentInternal> viewHolder;
  208249. WindowedGLContext (const WindowedGLContext&);
  208250. const WindowedGLContext& operator= (const WindowedGLContext&);
  208251. };
  208252. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208253. const OpenGLPixelFormat& pixelFormat,
  208254. const OpenGLContext* const contextToShareWith)
  208255. {
  208256. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208257. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208258. return (c->renderContext != 0) ? c.release() : 0;
  208259. }
  208260. void* OpenGLComponent::getNativeWindowHandle() const
  208261. {
  208262. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208263. : 0;
  208264. }
  208265. void juce_glViewport (const int w, const int h)
  208266. {
  208267. glViewport (0, 0, w, h);
  208268. }
  208269. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208270. OwnedArray <OpenGLPixelFormat>& results)
  208271. {
  208272. /* GLint attribs [64];
  208273. int n = 0;
  208274. attribs[n++] = AGL_RGBA;
  208275. attribs[n++] = AGL_DOUBLEBUFFER;
  208276. attribs[n++] = AGL_ACCELERATED;
  208277. attribs[n++] = AGL_NO_RECOVERY;
  208278. attribs[n++] = AGL_NONE;
  208279. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208280. while (p != 0)
  208281. {
  208282. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208283. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208284. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208285. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208286. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208287. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208288. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208289. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208290. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208291. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208292. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208293. results.add (pf);
  208294. p = aglNextPixelFormat (p);
  208295. }*/
  208296. //jassertfalse //xxx can't see how you do this in cocoa!
  208297. }
  208298. #else
  208299. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208300. const OpenGLPixelFormat& pixelFormat,
  208301. const OpenGLContext* const contextToShareWith)
  208302. {
  208303. return 0;
  208304. }
  208305. void juce_glViewport (const int w, const int h)
  208306. {
  208307. //glViewport (0, 0, w, h);
  208308. }
  208309. #endif
  208310. #endif
  208311. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208312. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208313. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208314. // compiled on its own).
  208315. #if JUCE_INCLUDED_FILE
  208316. class JuceMainMenuHandler;
  208317. END_JUCE_NAMESPACE
  208318. using namespace JUCE_NAMESPACE;
  208319. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208320. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208321. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208322. #else
  208323. @interface JuceMenuCallback : NSObject
  208324. #endif
  208325. {
  208326. JuceMainMenuHandler* owner;
  208327. }
  208328. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208329. - (void) dealloc;
  208330. - (void) menuItemInvoked: (id) menu;
  208331. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208332. @end
  208333. BEGIN_JUCE_NAMESPACE
  208334. class JuceMainMenuHandler : private MenuBarModelListener,
  208335. private DeletedAtShutdown
  208336. {
  208337. public:
  208338. static JuceMainMenuHandler* instance;
  208339. JuceMainMenuHandler()
  208340. : currentModel (0),
  208341. lastUpdateTime (0)
  208342. {
  208343. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208344. }
  208345. ~JuceMainMenuHandler()
  208346. {
  208347. setMenu (0);
  208348. jassert (instance == this);
  208349. instance = 0;
  208350. [callback release];
  208351. }
  208352. void setMenu (MenuBarModel* const newMenuBarModel)
  208353. {
  208354. if (currentModel != newMenuBarModel)
  208355. {
  208356. if (currentModel != 0)
  208357. currentModel->removeListener (this);
  208358. currentModel = newMenuBarModel;
  208359. if (currentModel != 0)
  208360. currentModel->addListener (this);
  208361. menuBarItemsChanged (0);
  208362. }
  208363. }
  208364. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208365. const String& name, const int menuId, const int tag)
  208366. {
  208367. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208368. action: nil
  208369. keyEquivalent: @""];
  208370. [item setTag: tag];
  208371. NSMenu* sub = createMenu (child, name, menuId, tag);
  208372. [parent setSubmenu: sub forItem: item];
  208373. [sub setAutoenablesItems: false];
  208374. [sub release];
  208375. }
  208376. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208377. const String& name, const int menuId, const int tag)
  208378. {
  208379. [parentItem setTag: tag];
  208380. NSMenu* menu = [parentItem submenu];
  208381. [menu setTitle: juceStringToNS (name)];
  208382. while ([menu numberOfItems] > 0)
  208383. [menu removeItemAtIndex: 0];
  208384. PopupMenu::MenuItemIterator iter (menuToCopy);
  208385. while (iter.next())
  208386. addMenuItem (iter, menu, menuId, tag);
  208387. [menu setAutoenablesItems: false];
  208388. [menu update];
  208389. }
  208390. void menuBarItemsChanged (MenuBarModel*)
  208391. {
  208392. lastUpdateTime = Time::getMillisecondCounter();
  208393. StringArray menuNames;
  208394. if (currentModel != 0)
  208395. menuNames = currentModel->getMenuBarNames();
  208396. NSMenu* menuBar = [NSApp mainMenu];
  208397. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208398. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208399. int menuId = 1;
  208400. for (int i = 0; i < menuNames.size(); ++i)
  208401. {
  208402. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208403. if (i >= [menuBar numberOfItems] - 1)
  208404. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208405. else
  208406. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208407. }
  208408. }
  208409. static void flashMenuBar (NSMenu* menu)
  208410. {
  208411. [menu retain];
  208412. const unichar f35Key = NSF35FunctionKey;
  208413. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208414. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208415. action: nil
  208416. keyEquivalent: f35String];
  208417. [item setTarget: nil];
  208418. [menu insertItem: item atIndex: [menu numberOfItems]];
  208419. [item release];
  208420. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208421. location: NSZeroPoint
  208422. modifierFlags: NSCommandKeyMask
  208423. timestamp: 0
  208424. windowNumber: 0
  208425. context: [NSGraphicsContext currentContext]
  208426. characters: f35String
  208427. charactersIgnoringModifiers: f35String
  208428. isARepeat: NO
  208429. keyCode: 0];
  208430. [menu performKeyEquivalent: f35Event];
  208431. if ([menu indexOfItem: item] >= 0)
  208432. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208433. [menu release];
  208434. }
  208435. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208436. {
  208437. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208438. {
  208439. NSMenuItem* m = [menu itemAtIndex: i];
  208440. if ([m tag] == info.commandID)
  208441. return m;
  208442. if ([m submenu] != 0)
  208443. {
  208444. NSMenuItem* found = findMenuItem ([m submenu], info);
  208445. if (found != 0)
  208446. return found;
  208447. }
  208448. }
  208449. return 0;
  208450. }
  208451. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208452. {
  208453. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208454. if (item != 0)
  208455. flashMenuBar ([item menu]);
  208456. }
  208457. void updateMenus()
  208458. {
  208459. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208460. menuBarItemsChanged (0);
  208461. }
  208462. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208463. {
  208464. if (currentModel != 0)
  208465. {
  208466. if (commandManager != 0)
  208467. {
  208468. ApplicationCommandTarget::InvocationInfo info (commandId);
  208469. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208470. commandManager->invoke (info, true);
  208471. }
  208472. currentModel->menuItemSelected (commandId, topLevelIndex);
  208473. }
  208474. }
  208475. MenuBarModel* currentModel;
  208476. uint32 lastUpdateTime;
  208477. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208478. const int topLevelMenuId, const int topLevelIndex)
  208479. {
  208480. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208481. if (text == 0)
  208482. text = @"";
  208483. if (iter.isSeparator)
  208484. {
  208485. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208486. }
  208487. else if (iter.isSectionHeader)
  208488. {
  208489. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208490. action: nil
  208491. keyEquivalent: @""];
  208492. [item setEnabled: false];
  208493. }
  208494. else if (iter.subMenu != 0)
  208495. {
  208496. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208497. action: nil
  208498. keyEquivalent: @""];
  208499. [item setTag: iter.itemId];
  208500. [item setEnabled: iter.isEnabled];
  208501. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208502. [sub setDelegate: nil];
  208503. [menuToAddTo setSubmenu: sub forItem: item];
  208504. [sub release];
  208505. }
  208506. else
  208507. {
  208508. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208509. action: @selector (menuItemInvoked:)
  208510. keyEquivalent: @""];
  208511. [item setTag: iter.itemId];
  208512. [item setEnabled: iter.isEnabled];
  208513. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208514. [item setTarget: (id) callback];
  208515. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208516. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208517. [item setRepresentedObject: info];
  208518. if (iter.commandManager != 0)
  208519. {
  208520. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208521. ->getKeyPressesAssignedToCommand (iter.itemId));
  208522. if (keyPresses.size() > 0)
  208523. {
  208524. const KeyPress& kp = keyPresses.getReference(0);
  208525. juce_wchar key = kp.getTextCharacter();
  208526. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208527. key = NSBackspaceCharacter;
  208528. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208529. key = NSDeleteCharacter;
  208530. else if (key == 0)
  208531. key = (juce_wchar) kp.getKeyCode();
  208532. unsigned int mods = 0;
  208533. if (kp.getModifiers().isShiftDown())
  208534. mods |= NSShiftKeyMask;
  208535. if (kp.getModifiers().isCtrlDown())
  208536. mods |= NSControlKeyMask;
  208537. if (kp.getModifiers().isAltDown())
  208538. mods |= NSAlternateKeyMask;
  208539. if (kp.getModifiers().isCommandDown())
  208540. mods |= NSCommandKeyMask;
  208541. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208542. [item setKeyEquivalentModifierMask: mods];
  208543. }
  208544. }
  208545. }
  208546. }
  208547. JuceMenuCallback* callback;
  208548. private:
  208549. NSMenu* createMenu (const PopupMenu menu,
  208550. const String& menuName,
  208551. const int topLevelMenuId,
  208552. const int topLevelIndex)
  208553. {
  208554. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208555. [m setAutoenablesItems: false];
  208556. [m setDelegate: callback];
  208557. PopupMenu::MenuItemIterator iter (menu);
  208558. while (iter.next())
  208559. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208560. [m update];
  208561. return m;
  208562. }
  208563. };
  208564. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208565. END_JUCE_NAMESPACE
  208566. @implementation JuceMenuCallback
  208567. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208568. {
  208569. [super init];
  208570. owner = owner_;
  208571. return self;
  208572. }
  208573. - (void) dealloc
  208574. {
  208575. [super dealloc];
  208576. }
  208577. - (void) menuItemInvoked: (id) menu
  208578. {
  208579. NSMenuItem* item = (NSMenuItem*) menu;
  208580. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208581. {
  208582. // 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
  208583. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208584. // into the focused component and let it trigger the menu item indirectly.
  208585. NSEvent* e = [NSApp currentEvent];
  208586. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208587. {
  208588. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->isValidComponent())
  208589. {
  208590. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208591. if (peer != 0)
  208592. {
  208593. if ([e type] == NSKeyDown)
  208594. peer->redirectKeyDown (e);
  208595. else
  208596. peer->redirectKeyUp (e);
  208597. return;
  208598. }
  208599. }
  208600. }
  208601. NSArray* info = (NSArray*) [item representedObject];
  208602. owner->invoke ((int) [item tag],
  208603. (ApplicationCommandManager*) (pointer_sized_int)
  208604. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208605. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208606. }
  208607. }
  208608. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208609. {
  208610. if (JuceMainMenuHandler::instance != 0)
  208611. JuceMainMenuHandler::instance->updateMenus();
  208612. }
  208613. @end
  208614. BEGIN_JUCE_NAMESPACE
  208615. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208616. const PopupMenu* extraItems)
  208617. {
  208618. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208619. {
  208620. PopupMenu::MenuItemIterator iter (*extraItems);
  208621. while (iter.next())
  208622. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208623. [menu addItem: [NSMenuItem separatorItem]];
  208624. }
  208625. NSMenuItem* item;
  208626. // Services...
  208627. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208628. action: nil keyEquivalent: @""];
  208629. [menu addItem: item];
  208630. [item release];
  208631. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208632. [menu setSubmenu: servicesMenu forItem: item];
  208633. [NSApp setServicesMenu: servicesMenu];
  208634. [servicesMenu release];
  208635. [menu addItem: [NSMenuItem separatorItem]];
  208636. // Hide + Show stuff...
  208637. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208638. action: @selector (hide:) keyEquivalent: @"h"];
  208639. [item setTarget: NSApp];
  208640. [menu addItem: item];
  208641. [item release];
  208642. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208643. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208644. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208645. [item setTarget: NSApp];
  208646. [menu addItem: item];
  208647. [item release];
  208648. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208649. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208650. [item setTarget: NSApp];
  208651. [menu addItem: item];
  208652. [item release];
  208653. [menu addItem: [NSMenuItem separatorItem]];
  208654. // Quit item....
  208655. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208656. action: @selector (terminate:) keyEquivalent: @"q"];
  208657. [item setTarget: NSApp];
  208658. [menu addItem: item];
  208659. [item release];
  208660. return menu;
  208661. }
  208662. // Since our app has no NIB, this initialises a standard app menu...
  208663. static void rebuildMainMenu (const PopupMenu* extraItems)
  208664. {
  208665. // this can't be used in a plugin!
  208666. jassert (JUCEApplication::getInstance() != 0);
  208667. if (JUCEApplication::getInstance() != 0)
  208668. {
  208669. const ScopedAutoReleasePool pool;
  208670. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208671. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208672. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208673. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208674. [mainMenu setSubmenu: appMenu forItem: item];
  208675. [NSApp setMainMenu: mainMenu];
  208676. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208677. [appMenu release];
  208678. [mainMenu release];
  208679. }
  208680. }
  208681. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208682. const PopupMenu* extraAppleMenuItems)
  208683. {
  208684. if (getMacMainMenu() != newMenuBarModel)
  208685. {
  208686. const ScopedAutoReleasePool pool;
  208687. if (newMenuBarModel == 0)
  208688. {
  208689. delete JuceMainMenuHandler::instance;
  208690. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208691. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208692. extraAppleMenuItems = 0;
  208693. }
  208694. else
  208695. {
  208696. if (JuceMainMenuHandler::instance == 0)
  208697. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208698. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208699. }
  208700. }
  208701. rebuildMainMenu (extraAppleMenuItems);
  208702. if (newMenuBarModel != 0)
  208703. newMenuBarModel->menuItemsChanged();
  208704. }
  208705. MenuBarModel* MenuBarModel::getMacMainMenu()
  208706. {
  208707. return JuceMainMenuHandler::instance != 0
  208708. ? JuceMainMenuHandler::instance->currentModel : 0;
  208709. }
  208710. void initialiseMainMenu()
  208711. {
  208712. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208713. rebuildMainMenu (0);
  208714. }
  208715. #endif
  208716. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208717. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208718. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208719. // compiled on its own).
  208720. #if JUCE_INCLUDED_FILE
  208721. #if JUCE_MAC
  208722. END_JUCE_NAMESPACE
  208723. using namespace JUCE_NAMESPACE;
  208724. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208725. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208726. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208727. #else
  208728. @interface JuceFileChooserDelegate : NSObject
  208729. #endif
  208730. {
  208731. StringArray* filters;
  208732. }
  208733. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208734. - (void) dealloc;
  208735. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208736. @end
  208737. @implementation JuceFileChooserDelegate
  208738. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208739. {
  208740. [super init];
  208741. filters = filters_;
  208742. return self;
  208743. }
  208744. - (void) dealloc
  208745. {
  208746. delete filters;
  208747. [super dealloc];
  208748. }
  208749. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208750. {
  208751. const File f (nsStringToJuce (filename));
  208752. for (int i = filters->size(); --i >= 0;)
  208753. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208754. return true;
  208755. return f.isDirectory();
  208756. }
  208757. @end
  208758. BEGIN_JUCE_NAMESPACE
  208759. void FileChooser::showPlatformDialog (Array<File>& results,
  208760. const String& title,
  208761. const File& currentFileOrDirectory,
  208762. const String& filter,
  208763. bool selectsDirectory,
  208764. bool selectsFiles,
  208765. bool isSaveDialogue,
  208766. bool warnAboutOverwritingExistingFiles,
  208767. bool selectMultipleFiles,
  208768. FilePreviewComponent* extraInfoComponent)
  208769. {
  208770. const ScopedAutoReleasePool pool;
  208771. StringArray* filters = new StringArray();
  208772. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  208773. filters->trim();
  208774. filters->removeEmptyStrings();
  208775. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208776. [delegate autorelease];
  208777. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208778. : [NSOpenPanel openPanel];
  208779. [panel setTitle: juceStringToNS (title)];
  208780. if (! isSaveDialogue)
  208781. {
  208782. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208783. [openPanel setCanChooseDirectories: selectsDirectory];
  208784. [openPanel setCanChooseFiles: selectsFiles];
  208785. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208786. }
  208787. [panel setDelegate: delegate];
  208788. if (isSaveDialogue || selectsDirectory)
  208789. [panel setCanCreateDirectories: YES];
  208790. String directory, filename;
  208791. if (currentFileOrDirectory.isDirectory())
  208792. {
  208793. directory = currentFileOrDirectory.getFullPathName();
  208794. }
  208795. else
  208796. {
  208797. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208798. filename = currentFileOrDirectory.getFileName();
  208799. }
  208800. if ([panel runModalForDirectory: juceStringToNS (directory)
  208801. file: juceStringToNS (filename)]
  208802. == NSOKButton)
  208803. {
  208804. if (isSaveDialogue)
  208805. {
  208806. results.add (File (nsStringToJuce ([panel filename])));
  208807. }
  208808. else
  208809. {
  208810. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208811. NSArray* urls = [openPanel filenames];
  208812. for (unsigned int i = 0; i < [urls count]; ++i)
  208813. {
  208814. NSString* f = [urls objectAtIndex: i];
  208815. results.add (File (nsStringToJuce (f)));
  208816. }
  208817. }
  208818. }
  208819. [panel setDelegate: nil];
  208820. }
  208821. #else
  208822. void FileChooser::showPlatformDialog (Array<File>& results,
  208823. const String& title,
  208824. const File& currentFileOrDirectory,
  208825. const String& filter,
  208826. bool selectsDirectory,
  208827. bool selectsFiles,
  208828. bool isSaveDialogue,
  208829. bool warnAboutOverwritingExistingFiles,
  208830. bool selectMultipleFiles,
  208831. FilePreviewComponent* extraInfoComponent)
  208832. {
  208833. const ScopedAutoReleasePool pool;
  208834. jassertfalse //xxx to do
  208835. }
  208836. #endif
  208837. #endif
  208838. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  208839. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  208840. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208841. // compiled on its own).
  208842. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  208843. #define theMovie ((QTMovie*) movie)
  208844. QuickTimeMovieComponent::QuickTimeMovieComponent()
  208845. : movie (0)
  208846. {
  208847. setOpaque (true);
  208848. setVisible (true);
  208849. QTMovieView* view = [[QTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  208850. setView (view);
  208851. }
  208852. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  208853. {
  208854. closeMovie();
  208855. setView (0);
  208856. }
  208857. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  208858. {
  208859. return true;
  208860. }
  208861. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  208862. {
  208863. // unfortunately, QTMovie objects can only be created on the main thread..
  208864. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  208865. QTMovie* movie = 0;
  208866. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  208867. if (fin != 0)
  208868. {
  208869. movieFile = fin->getFile();
  208870. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  208871. error: nil];
  208872. }
  208873. else
  208874. {
  208875. MemoryBlock temp;
  208876. movieStream->readIntoMemoryBlock (temp);
  208877. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  208878. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  208879. {
  208880. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  208881. length: temp.getSize()]
  208882. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  208883. MIMEType: @""]
  208884. error: nil];
  208885. if (movie != 0)
  208886. break;
  208887. }
  208888. }
  208889. return movie;
  208890. }
  208891. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  208892. const bool isControllerVisible_)
  208893. {
  208894. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  208895. }
  208896. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  208897. const bool controllerVisible_)
  208898. {
  208899. closeMovie();
  208900. if (getPeer() == 0)
  208901. {
  208902. // To open a movie, this component must be visible inside a functioning window, so that
  208903. // the QT control can be assigned to the window.
  208904. jassertfalse
  208905. return false;
  208906. }
  208907. movie = openMovieFromStream (movieStream, movieFile);
  208908. [theMovie retain];
  208909. QTMovieView* view = (QTMovieView*) getView();
  208910. [view setMovie: theMovie];
  208911. [view setControllerVisible: controllerVisible_];
  208912. setLooping (looping);
  208913. return movie != nil;
  208914. }
  208915. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  208916. const bool isControllerVisible_)
  208917. {
  208918. // unfortunately, QTMovie objects can only be created on the main thread..
  208919. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  208920. closeMovie();
  208921. if (getPeer() == 0)
  208922. {
  208923. // To open a movie, this component must be visible inside a functioning window, so that
  208924. // the QT control can be assigned to the window.
  208925. jassertfalse
  208926. return false;
  208927. }
  208928. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  208929. NSError* err;
  208930. if ([QTMovie canInitWithURL: url])
  208931. movie = [QTMovie movieWithURL: url error: &err];
  208932. [theMovie retain];
  208933. QTMovieView* view = (QTMovieView*) getView();
  208934. [view setMovie: theMovie];
  208935. [view setControllerVisible: controllerVisible];
  208936. setLooping (looping);
  208937. return movie != nil;
  208938. }
  208939. void QuickTimeMovieComponent::closeMovie()
  208940. {
  208941. stop();
  208942. QTMovieView* view = (QTMovieView*) getView();
  208943. [view setMovie: nil];
  208944. [theMovie release];
  208945. movie = 0;
  208946. movieFile = File::nonexistent;
  208947. }
  208948. bool QuickTimeMovieComponent::isMovieOpen() const
  208949. {
  208950. return movie != nil;
  208951. }
  208952. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  208953. {
  208954. return movieFile;
  208955. }
  208956. void QuickTimeMovieComponent::play()
  208957. {
  208958. [theMovie play];
  208959. }
  208960. void QuickTimeMovieComponent::stop()
  208961. {
  208962. [theMovie stop];
  208963. }
  208964. bool QuickTimeMovieComponent::isPlaying() const
  208965. {
  208966. return movie != 0 && [theMovie rate] != 0;
  208967. }
  208968. void QuickTimeMovieComponent::setPosition (const double seconds)
  208969. {
  208970. if (movie != 0)
  208971. {
  208972. QTTime t;
  208973. t.timeValue = (uint64) (100000.0 * seconds);
  208974. t.timeScale = 100000;
  208975. t.flags = 0;
  208976. [theMovie setCurrentTime: t];
  208977. }
  208978. }
  208979. double QuickTimeMovieComponent::getPosition() const
  208980. {
  208981. if (movie == 0)
  208982. return 0.0;
  208983. QTTime t = [theMovie currentTime];
  208984. return t.timeValue / (double) t.timeScale;
  208985. }
  208986. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  208987. {
  208988. [theMovie setRate: newSpeed];
  208989. }
  208990. double QuickTimeMovieComponent::getMovieDuration() const
  208991. {
  208992. if (movie == 0)
  208993. return 0.0;
  208994. QTTime t = [theMovie duration];
  208995. return t.timeValue / (double) t.timeScale;
  208996. }
  208997. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  208998. {
  208999. looping = shouldLoop;
  209000. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209001. forKey: QTMovieLoopsAttribute];
  209002. }
  209003. bool QuickTimeMovieComponent::isLooping() const
  209004. {
  209005. return looping;
  209006. }
  209007. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209008. {
  209009. [theMovie setVolume: newVolume];
  209010. }
  209011. float QuickTimeMovieComponent::getMovieVolume() const
  209012. {
  209013. return movie != 0 ? [theMovie volume] : 0.0f;
  209014. }
  209015. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209016. {
  209017. width = 0;
  209018. height = 0;
  209019. if (movie != 0)
  209020. {
  209021. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209022. width = (int) s.width;
  209023. height = (int) s.height;
  209024. }
  209025. }
  209026. void QuickTimeMovieComponent::paint (Graphics& g)
  209027. {
  209028. if (movie == 0)
  209029. g.fillAll (Colours::black);
  209030. }
  209031. bool QuickTimeMovieComponent::isControllerVisible() const
  209032. {
  209033. return controllerVisible;
  209034. }
  209035. void QuickTimeMovieComponent::goToStart()
  209036. {
  209037. setPosition (0.0);
  209038. }
  209039. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209040. const RectanglePlacement& placement)
  209041. {
  209042. int normalWidth, normalHeight;
  209043. getMovieNormalSize (normalWidth, normalHeight);
  209044. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209045. {
  209046. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209047. placement.applyTo (x, y, w, h,
  209048. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209049. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209050. if (w > 0 && h > 0)
  209051. {
  209052. setBounds (roundToInt (x), roundToInt (y),
  209053. roundToInt (w), roundToInt (h));
  209054. }
  209055. }
  209056. else
  209057. {
  209058. setBounds (spaceToFitWithin);
  209059. }
  209060. }
  209061. #if ! (JUCE_MAC && JUCE_64BIT)
  209062. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209063. {
  209064. if (movieStream == 0)
  209065. return false;
  209066. File file;
  209067. QTMovie* movie = openMovieFromStream (movieStream, file);
  209068. if (movie != nil)
  209069. result = [movie quickTimeMovie];
  209070. return movie != nil;
  209071. }
  209072. #endif
  209073. #endif
  209074. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209075. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209076. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209077. // compiled on its own).
  209078. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209079. END_JUCE_NAMESPACE
  209080. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209081. @interface OpenDiskDevice : NSObject
  209082. {
  209083. DRDevice* device;
  209084. NSMutableArray* tracks;
  209085. }
  209086. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device;
  209087. - (void) dealloc;
  209088. - (bool) isDiskPresent;
  209089. - (int) getNumAvailableAudioBlocks;
  209090. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209091. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209092. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting;
  209093. @end
  209094. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209095. @interface AudioTrackProducer : NSObject
  209096. {
  209097. JUCE_NAMESPACE::AudioSource* source;
  209098. int readPosition, lengthInFrames;
  209099. }
  209100. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209101. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209102. - (void) dealloc;
  209103. - (void) setupTrackProperties: (DRTrack*) track;
  209104. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209105. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209106. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209107. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209108. toMedia:(NSDictionary*)mediaInfo;
  209109. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209110. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209111. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209112. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209113. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209114. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209115. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209116. ioFlags:(uint32_t*)flags;
  209117. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209118. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209119. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209120. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209121. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209122. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209123. ioFlags:(uint32_t*)flags;
  209124. @end
  209125. @implementation OpenDiskDevice
  209126. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device_
  209127. {
  209128. [super init];
  209129. device = device_;
  209130. tracks = [[NSMutableArray alloc] init];
  209131. return self;
  209132. }
  209133. - (void) dealloc
  209134. {
  209135. [tracks release];
  209136. [super dealloc];
  209137. }
  209138. - (bool) isDiskPresent
  209139. {
  209140. return [device isValid]
  209141. && [[[device status] objectForKey: DRDeviceMediaStateKey]
  209142. isEqualTo: DRDeviceMediaStateMediaPresent];
  209143. }
  209144. - (int) getNumAvailableAudioBlocks
  209145. {
  209146. return [[[[device status] objectForKey: DRDeviceMediaInfoKey]
  209147. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209148. }
  209149. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209150. {
  209151. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209152. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209153. [p setupTrackProperties: t];
  209154. [tracks addObject: t];
  209155. [t release];
  209156. [p release];
  209157. }
  209158. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209159. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting
  209160. {
  209161. DRBurn* burn = [DRBurn burnForDevice: device];
  209162. if (! [device acquireExclusiveAccess])
  209163. {
  209164. *error = "Couldn't open or write to the CD device";
  209165. return;
  209166. }
  209167. [device acquireMediaReservation];
  209168. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209169. [d autorelease];
  209170. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209171. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209172. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount)
  209173. forKey: DRBurnCompletionActionKey];
  209174. [burn setProperties: d];
  209175. [burn writeLayout: tracks];
  209176. for (;;)
  209177. {
  209178. JUCE_NAMESPACE::Thread::sleep (300);
  209179. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209180. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209181. {
  209182. [burn abort];
  209183. *error = "User cancelled the write operation";
  209184. break;
  209185. }
  209186. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209187. {
  209188. *error = "Write operation failed";
  209189. break;
  209190. }
  209191. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209192. {
  209193. break;
  209194. }
  209195. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209196. objectForKey: DRErrorStatusErrorStringKey];
  209197. if ([err length] > 0)
  209198. {
  209199. *error = JUCE_NAMESPACE::String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [err UTF8String]);
  209200. break;
  209201. }
  209202. }
  209203. [device releaseMediaReservation];
  209204. [device releaseExclusiveAccess];
  209205. }
  209206. @end
  209207. @implementation AudioTrackProducer
  209208. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209209. {
  209210. lengthInFrames = lengthInFrames_;
  209211. readPosition = 0;
  209212. return self;
  209213. }
  209214. - (void) setupTrackProperties: (DRTrack*) track
  209215. {
  209216. NSMutableDictionary* p = [[track properties] mutableCopy];
  209217. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209218. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209219. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209220. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209221. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209222. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209223. [track setProperties: p];
  209224. [p release];
  209225. }
  209226. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209227. {
  209228. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209229. if (s != nil)
  209230. s->source = source_;
  209231. return s;
  209232. }
  209233. - (void) dealloc
  209234. {
  209235. if (source != 0)
  209236. {
  209237. source->releaseResources();
  209238. delete source;
  209239. }
  209240. [super dealloc];
  209241. }
  209242. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209243. {
  209244. }
  209245. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209246. {
  209247. return true;
  209248. }
  209249. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209250. {
  209251. return lengthInFrames;
  209252. }
  209253. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209254. toMedia: (NSDictionary*) mediaInfo
  209255. {
  209256. if (source != 0)
  209257. source->prepareToPlay (44100 / 75, 44100);
  209258. readPosition = 0;
  209259. return true;
  209260. }
  209261. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209262. {
  209263. if (source != 0)
  209264. source->prepareToPlay (44100 / 75, 44100);
  209265. return true;
  209266. }
  209267. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209268. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209269. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209270. {
  209271. if (source != 0)
  209272. {
  209273. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209274. if (numSamples > 0)
  209275. {
  209276. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209277. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209278. info.buffer = &tempBuffer;
  209279. info.startSample = 0;
  209280. info.numSamples = numSamples;
  209281. source->getNextAudioBlock (info);
  209282. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209283. buffer, numSamples, 4);
  209284. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209285. buffer + 2, numSamples, 4);
  209286. readPosition += numSamples;
  209287. }
  209288. return numSamples * 4;
  209289. }
  209290. return 0;
  209291. }
  209292. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209293. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209294. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209295. ioFlags: (uint32_t*) flags
  209296. {
  209297. zeromem (buffer, bufferLength);
  209298. return bufferLength;
  209299. }
  209300. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209301. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209302. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209303. {
  209304. return true;
  209305. }
  209306. @end
  209307. BEGIN_JUCE_NAMESPACE
  209308. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209309. : internal (0)
  209310. {
  209311. OpenDiskDevice* dev = [[OpenDiskDevice alloc] initWithDevice: [[DRDevice devices] objectAtIndex: deviceIndex]];
  209312. internal = (void*) dev;
  209313. }
  209314. AudioCDBurner::~AudioCDBurner()
  209315. {
  209316. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209317. if (dev != 0)
  209318. [dev release];
  209319. }
  209320. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209321. {
  209322. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209323. if (b->internal == 0)
  209324. b = 0;
  209325. return b.release();
  209326. }
  209327. static NSArray* findDiskBurnerDevices()
  209328. {
  209329. NSMutableArray* results = [NSMutableArray array];
  209330. NSArray* devs = [DRDevice devices];
  209331. if (devs != 0)
  209332. {
  209333. int num = [devs count];
  209334. int i;
  209335. for (i = 0; i < num; ++i)
  209336. {
  209337. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209338. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209339. if (name != nil)
  209340. [results addObject: name];
  209341. }
  209342. }
  209343. return results;
  209344. }
  209345. const StringArray AudioCDBurner::findAvailableDevices()
  209346. {
  209347. NSArray* names = findDiskBurnerDevices();
  209348. StringArray s;
  209349. for (unsigned int i = 0; i < [names count]; ++i)
  209350. s.add (String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [[names objectAtIndex: i] UTF8String]));
  209351. return s;
  209352. }
  209353. bool AudioCDBurner::isDiskPresent() const
  209354. {
  209355. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209356. return dev != 0 && [dev isDiskPresent];
  209357. }
  209358. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209359. {
  209360. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209361. return [dev getNumAvailableAudioBlocks];
  209362. }
  209363. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209364. {
  209365. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209366. if (dev != 0)
  209367. {
  209368. [dev addSourceTrack: source numSamples: numSamps];
  209369. return true;
  209370. }
  209371. return false;
  209372. }
  209373. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209374. const bool ejectDiscAfterwards,
  209375. const bool peformFakeBurnForTesting)
  209376. {
  209377. String error ("Couldn't open or write to the CD device");
  209378. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209379. if (dev != 0)
  209380. {
  209381. error = String::empty;
  209382. [dev burn: listener
  209383. errorString: &error
  209384. ejectAfterwards: ejectDiscAfterwards
  209385. isFake: peformFakeBurnForTesting];
  209386. }
  209387. return error;
  209388. }
  209389. void AudioCDReader::ejectDisk()
  209390. {
  209391. const ScopedAutoReleasePool p;
  209392. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209393. }
  209394. #endif
  209395. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209396. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209397. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209398. // compiled on its own).
  209399. #if JUCE_INCLUDED_FILE
  209400. struct CallbackMessagePayload
  209401. {
  209402. MessageCallbackFunction* function;
  209403. void* parameter;
  209404. void* volatile result;
  209405. bool volatile hasBeenExecuted;
  209406. };
  209407. class AppDelegateRedirector
  209408. {
  209409. public:
  209410. AppDelegateRedirector()
  209411. {
  209412. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209413. runLoop = CFRunLoopGetMain();
  209414. #else
  209415. runLoop = CFRunLoopGetCurrent();
  209416. #endif
  209417. CFRunLoopSourceContext sourceContext;
  209418. zerostruct (sourceContext);
  209419. sourceContext.info = this;
  209420. sourceContext.perform = runLoopSourceCallback;
  209421. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209422. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209423. }
  209424. virtual ~AppDelegateRedirector()
  209425. {
  209426. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209427. CFRunLoopSourceInvalidate (runLoopSource);
  209428. CFRelease (runLoopSource);
  209429. while (messages.size() > 0)
  209430. delete ((Message*) messages.remove(0));
  209431. }
  209432. virtual NSApplicationTerminateReply shouldTerminate()
  209433. {
  209434. if (JUCEApplication::getInstance() != 0)
  209435. {
  209436. JUCEApplication::getInstance()->systemRequestedQuit();
  209437. return NSTerminateCancel;
  209438. }
  209439. return NSTerminateNow;
  209440. }
  209441. virtual BOOL openFile (const NSString* filename)
  209442. {
  209443. if (JUCEApplication::getInstance() != 0)
  209444. {
  209445. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209446. return YES;
  209447. }
  209448. return NO;
  209449. }
  209450. virtual void openFiles (NSArray* filenames)
  209451. {
  209452. StringArray files;
  209453. for (unsigned int i = 0; i < [filenames count]; ++i)
  209454. {
  209455. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209456. if (filename.containsChar (T(' ')))
  209457. filename = filename.quoted('"');
  209458. files.add (filename);
  209459. }
  209460. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209461. {
  209462. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209463. }
  209464. }
  209465. virtual void focusChanged()
  209466. {
  209467. juce_HandleProcessFocusChange();
  209468. }
  209469. virtual void performCallback (CallbackMessagePayload* pl)
  209470. {
  209471. pl->result = (*pl->function) (pl->parameter);
  209472. pl->hasBeenExecuted = true;
  209473. }
  209474. virtual void deleteSelf()
  209475. {
  209476. delete this;
  209477. }
  209478. void postMessage (void* m)
  209479. {
  209480. messages.add (m);
  209481. CFRunLoopSourceSignal (runLoopSource);
  209482. CFRunLoopWakeUp (runLoop);
  209483. }
  209484. private:
  209485. CFRunLoopRef runLoop;
  209486. CFRunLoopSourceRef runLoopSource;
  209487. Array <void*, CriticalSection> messages;
  209488. void runLoopCallback()
  209489. {
  209490. int numDispatched = 0;
  209491. do
  209492. {
  209493. void* const nextMessage = messages.remove (0);
  209494. if (nextMessage == 0)
  209495. return;
  209496. const ScopedAutoReleasePool pool;
  209497. MessageManager::getInstance()->deliverMessage (nextMessage);
  209498. } while (++numDispatched <= 4);
  209499. CFRunLoopSourceSignal (runLoopSource);
  209500. CFRunLoopWakeUp (runLoop);
  209501. }
  209502. static void runLoopSourceCallback (void* info)
  209503. {
  209504. ((AppDelegateRedirector*) info)->runLoopCallback();
  209505. }
  209506. };
  209507. END_JUCE_NAMESPACE
  209508. using namespace JUCE_NAMESPACE;
  209509. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209510. @interface JuceAppDelegate : NSObject
  209511. {
  209512. @private
  209513. id oldDelegate;
  209514. @public
  209515. AppDelegateRedirector* redirector;
  209516. }
  209517. - (JuceAppDelegate*) init;
  209518. - (void) dealloc;
  209519. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209520. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209521. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209522. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209523. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209524. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209525. - (void) performCallback: (id) info;
  209526. - (void) dummyMethod;
  209527. @end
  209528. @implementation JuceAppDelegate
  209529. - (JuceAppDelegate*) init
  209530. {
  209531. [super init];
  209532. redirector = new AppDelegateRedirector();
  209533. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209534. if (JUCEApplication::getInstance() != 0)
  209535. {
  209536. oldDelegate = [NSApp delegate];
  209537. [NSApp setDelegate: self];
  209538. }
  209539. else
  209540. {
  209541. oldDelegate = 0;
  209542. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209543. name: NSApplicationDidResignActiveNotification object: NSApp];
  209544. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209545. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209546. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209547. name: NSApplicationWillUnhideNotification object: NSApp];
  209548. }
  209549. return self;
  209550. }
  209551. - (void) dealloc
  209552. {
  209553. if (oldDelegate != 0)
  209554. [NSApp setDelegate: oldDelegate];
  209555. redirector->deleteSelf();
  209556. [super dealloc];
  209557. }
  209558. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209559. {
  209560. return redirector->shouldTerminate();
  209561. }
  209562. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209563. {
  209564. return redirector->openFile (filename);
  209565. }
  209566. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209567. {
  209568. return redirector->openFiles (filenames);
  209569. }
  209570. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209571. {
  209572. redirector->focusChanged();
  209573. }
  209574. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209575. {
  209576. redirector->focusChanged();
  209577. }
  209578. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209579. {
  209580. redirector->focusChanged();
  209581. }
  209582. - (void) performCallback: (id) info
  209583. {
  209584. if ([info isKindOfClass: [NSData class]])
  209585. {
  209586. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  209587. if (pl != 0)
  209588. redirector->performCallback (pl);
  209589. }
  209590. else
  209591. {
  209592. jassertfalse // should never get here!
  209593. }
  209594. }
  209595. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209596. @end
  209597. BEGIN_JUCE_NAMESPACE
  209598. static JuceAppDelegate* juceAppDelegate = 0;
  209599. void MessageManager::runDispatchLoop()
  209600. {
  209601. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209602. {
  209603. const ScopedAutoReleasePool pool;
  209604. // must only be called by the message thread!
  209605. jassert (isThisTheMessageThread());
  209606. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209607. @try
  209608. {
  209609. [NSApp run];
  209610. }
  209611. @catch (NSException* e)
  209612. {
  209613. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209614. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209615. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209616. }
  209617. @finally
  209618. {
  209619. }
  209620. #else
  209621. [NSApp run];
  209622. #endif
  209623. }
  209624. }
  209625. void MessageManager::stopDispatchLoop()
  209626. {
  209627. quitMessagePosted = true;
  209628. [NSApp stop: nil];
  209629. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209630. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209631. }
  209632. static bool isEventBlockedByModalComps (NSEvent* e)
  209633. {
  209634. if (Component::getNumCurrentlyModalComponents() == 0)
  209635. return false;
  209636. NSWindow* const w = [e window];
  209637. if (w == 0 || [w worksWhenModal])
  209638. return false;
  209639. bool isKey = false, isInputAttempt = false;
  209640. switch ([e type])
  209641. {
  209642. case NSKeyDown:
  209643. case NSKeyUp:
  209644. isKey = isInputAttempt = true;
  209645. break;
  209646. case NSLeftMouseDown:
  209647. case NSRightMouseDown:
  209648. case NSOtherMouseDown:
  209649. isInputAttempt = true;
  209650. break;
  209651. case NSLeftMouseDragged:
  209652. case NSRightMouseDragged:
  209653. case NSLeftMouseUp:
  209654. case NSRightMouseUp:
  209655. case NSOtherMouseUp:
  209656. case NSOtherMouseDragged:
  209657. if (Component::getComponentUnderMouse() != 0)
  209658. return false;
  209659. break;
  209660. case NSMouseMoved:
  209661. case NSMouseEntered:
  209662. case NSMouseExited:
  209663. case NSCursorUpdate:
  209664. case NSScrollWheel:
  209665. case NSTabletPoint:
  209666. case NSTabletProximity:
  209667. break;
  209668. default:
  209669. return false;
  209670. }
  209671. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209672. {
  209673. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209674. NSView* const compView = (NSView*) peer->getNativeHandle();
  209675. if ([compView window] == w)
  209676. {
  209677. if (isKey)
  209678. {
  209679. if (compView == [w firstResponder])
  209680. return false;
  209681. }
  209682. else
  209683. {
  209684. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209685. [compView bounds]))
  209686. return false;
  209687. }
  209688. }
  209689. }
  209690. if (isInputAttempt)
  209691. {
  209692. if (! [NSApp isActive])
  209693. [NSApp activateIgnoringOtherApps: YES];
  209694. Component* const modal = Component::getCurrentlyModalComponent (0);
  209695. if (modal != 0)
  209696. modal->inputAttemptWhenModal();
  209697. }
  209698. return true;
  209699. }
  209700. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  209701. {
  209702. const ScopedAutoReleasePool pool;
  209703. jassert (isThisTheMessageThread()); // must only be called by the message thread
  209704. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  209705. while (! quitMessagePosted)
  209706. {
  209707. const ScopedAutoReleasePool pool2;
  209708. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  209709. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  209710. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  209711. inMode: NSDefaultRunLoopMode
  209712. dequeue: YES];
  209713. if (e != 0 && ! isEventBlockedByModalComps (e))
  209714. [NSApp sendEvent: e];
  209715. if (Time::getMillisecondCounter() >= endTime)
  209716. break;
  209717. }
  209718. return ! quitMessagePosted;
  209719. }
  209720. void MessageManager::doPlatformSpecificInitialisation()
  209721. {
  209722. if (juceAppDelegate == 0)
  209723. juceAppDelegate = [[JuceAppDelegate alloc] init];
  209724. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  209725. // correctly (needed prior to 10.5)
  209726. if (! [NSThread isMultiThreaded])
  209727. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  209728. toTarget: juceAppDelegate
  209729. withObject: nil];
  209730. initialiseMainMenu();
  209731. }
  209732. void MessageManager::doPlatformSpecificShutdown()
  209733. {
  209734. if (juceAppDelegate != 0)
  209735. {
  209736. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  209737. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  209738. [juceAppDelegate release];
  209739. juceAppDelegate = 0;
  209740. }
  209741. }
  209742. bool juce_postMessageToSystemQueue (void* message)
  209743. {
  209744. juceAppDelegate->redirector->postMessage (message);
  209745. return true;
  209746. }
  209747. void MessageManager::broadcastMessage (const String& value) throw()
  209748. {
  209749. }
  209750. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  209751. void* data)
  209752. {
  209753. if (isThisTheMessageThread())
  209754. {
  209755. return (*callback) (data);
  209756. }
  209757. else
  209758. {
  209759. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  209760. // deadlock because the message manager is blocked from running, so can never
  209761. // call your function..
  209762. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  209763. const ScopedAutoReleasePool pool;
  209764. CallbackMessagePayload cmp;
  209765. cmp.function = callback;
  209766. cmp.parameter = data;
  209767. cmp.result = 0;
  209768. cmp.hasBeenExecuted = false;
  209769. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  209770. withObject: [NSData dataWithBytesNoCopy: &cmp
  209771. length: sizeof (cmp)
  209772. freeWhenDone: NO]
  209773. waitUntilDone: YES];
  209774. return cmp.result;
  209775. }
  209776. }
  209777. #endif
  209778. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  209779. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  209780. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209781. // compiled on its own).
  209782. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  209783. #if JUCE_MAC
  209784. END_JUCE_NAMESPACE
  209785. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  209786. @interface DownloadClickDetector : NSObject
  209787. {
  209788. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  209789. }
  209790. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  209791. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209792. request: (NSURLRequest*) request
  209793. frame: (WebFrame*) frame
  209794. decisionListener: (id<WebPolicyDecisionListener>) listener;
  209795. @end
  209796. @implementation DownloadClickDetector
  209797. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  209798. {
  209799. [super init];
  209800. ownerComponent = ownerComponent_;
  209801. return self;
  209802. }
  209803. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209804. request: (NSURLRequest*) request
  209805. frame: (WebFrame*) frame
  209806. decisionListener: (id <WebPolicyDecisionListener>) listener
  209807. {
  209808. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  209809. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  209810. [listener use];
  209811. else
  209812. [listener ignore];
  209813. }
  209814. @end
  209815. BEGIN_JUCE_NAMESPACE
  209816. class WebBrowserComponentInternal : public NSViewComponent
  209817. {
  209818. public:
  209819. WebBrowserComponentInternal (WebBrowserComponent* owner)
  209820. {
  209821. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  209822. frameName: @""
  209823. groupName: @""];
  209824. setView (webView);
  209825. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  209826. [webView setPolicyDelegate: clickListener];
  209827. }
  209828. ~WebBrowserComponentInternal()
  209829. {
  209830. [webView setPolicyDelegate: nil];
  209831. [clickListener release];
  209832. setView (0);
  209833. }
  209834. void goToURL (const String& url,
  209835. const StringArray* headers,
  209836. const MemoryBlock* postData)
  209837. {
  209838. NSMutableURLRequest* r
  209839. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  209840. cachePolicy: NSURLRequestUseProtocolCachePolicy
  209841. timeoutInterval: 30.0];
  209842. if (postData != 0 && postData->getSize() > 0)
  209843. {
  209844. [r setHTTPMethod: @"POST"];
  209845. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  209846. length: postData->getSize()]];
  209847. }
  209848. if (headers != 0)
  209849. {
  209850. for (int i = 0; i < headers->size(); ++i)
  209851. {
  209852. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  209853. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  209854. [r setValue: juceStringToNS (headerValue)
  209855. forHTTPHeaderField: juceStringToNS (headerName)];
  209856. }
  209857. }
  209858. stop();
  209859. [[webView mainFrame] loadRequest: r];
  209860. }
  209861. void goBack()
  209862. {
  209863. [webView goBack];
  209864. }
  209865. void goForward()
  209866. {
  209867. [webView goForward];
  209868. }
  209869. void stop()
  209870. {
  209871. [webView stopLoading: nil];
  209872. }
  209873. void refresh()
  209874. {
  209875. [webView reload: nil];
  209876. }
  209877. private:
  209878. WebView* webView;
  209879. DownloadClickDetector* clickListener;
  209880. };
  209881. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  209882. : browser (0),
  209883. blankPageShown (false),
  209884. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  209885. {
  209886. setOpaque (true);
  209887. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  209888. }
  209889. WebBrowserComponent::~WebBrowserComponent()
  209890. {
  209891. deleteAndZero (browser);
  209892. }
  209893. void WebBrowserComponent::goToURL (const String& url,
  209894. const StringArray* headers,
  209895. const MemoryBlock* postData)
  209896. {
  209897. lastURL = url;
  209898. lastHeaders.clear();
  209899. if (headers != 0)
  209900. lastHeaders = *headers;
  209901. lastPostData.setSize (0);
  209902. if (postData != 0)
  209903. lastPostData = *postData;
  209904. blankPageShown = false;
  209905. browser->goToURL (url, headers, postData);
  209906. }
  209907. void WebBrowserComponent::stop()
  209908. {
  209909. browser->stop();
  209910. }
  209911. void WebBrowserComponent::goBack()
  209912. {
  209913. lastURL = String::empty;
  209914. blankPageShown = false;
  209915. browser->goBack();
  209916. }
  209917. void WebBrowserComponent::goForward()
  209918. {
  209919. lastURL = String::empty;
  209920. browser->goForward();
  209921. }
  209922. void WebBrowserComponent::refresh()
  209923. {
  209924. browser->refresh();
  209925. }
  209926. void WebBrowserComponent::paint (Graphics& g)
  209927. {
  209928. }
  209929. void WebBrowserComponent::checkWindowAssociation()
  209930. {
  209931. if (isShowing())
  209932. {
  209933. if (blankPageShown)
  209934. goBack();
  209935. }
  209936. else
  209937. {
  209938. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  209939. {
  209940. // when the component becomes invisible, some stuff like flash
  209941. // carries on playing audio, so we need to force it onto a blank
  209942. // page to avoid this, (and send it back when it's made visible again).
  209943. blankPageShown = true;
  209944. browser->goToURL ("about:blank", 0, 0);
  209945. }
  209946. }
  209947. }
  209948. void WebBrowserComponent::reloadLastURL()
  209949. {
  209950. if (lastURL.isNotEmpty())
  209951. {
  209952. goToURL (lastURL, &lastHeaders, &lastPostData);
  209953. lastURL = String::empty;
  209954. }
  209955. }
  209956. void WebBrowserComponent::parentHierarchyChanged()
  209957. {
  209958. checkWindowAssociation();
  209959. }
  209960. void WebBrowserComponent::resized()
  209961. {
  209962. browser->setSize (getWidth(), getHeight());
  209963. }
  209964. void WebBrowserComponent::visibilityChanged()
  209965. {
  209966. checkWindowAssociation();
  209967. }
  209968. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  209969. {
  209970. return true;
  209971. }
  209972. #else
  209973. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  209974. {
  209975. }
  209976. WebBrowserComponent::~WebBrowserComponent()
  209977. {
  209978. }
  209979. void WebBrowserComponent::goToURL (const String& url,
  209980. const StringArray* headers,
  209981. const MemoryBlock* postData)
  209982. {
  209983. }
  209984. void WebBrowserComponent::stop()
  209985. {
  209986. }
  209987. void WebBrowserComponent::goBack()
  209988. {
  209989. }
  209990. void WebBrowserComponent::goForward()
  209991. {
  209992. }
  209993. void WebBrowserComponent::refresh()
  209994. {
  209995. }
  209996. void WebBrowserComponent::paint (Graphics& g)
  209997. {
  209998. }
  209999. void WebBrowserComponent::checkWindowAssociation()
  210000. {
  210001. }
  210002. void WebBrowserComponent::reloadLastURL()
  210003. {
  210004. }
  210005. void WebBrowserComponent::parentHierarchyChanged()
  210006. {
  210007. }
  210008. void WebBrowserComponent::resized()
  210009. {
  210010. }
  210011. void WebBrowserComponent::visibilityChanged()
  210012. {
  210013. }
  210014. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210015. {
  210016. return true;
  210017. }
  210018. #endif
  210019. #endif
  210020. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210021. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210022. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210023. // compiled on its own).
  210024. #if JUCE_INCLUDED_FILE
  210025. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210026. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210027. #endif
  210028. #undef log
  210029. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210030. #define log(a) Logger::writeToLog (a)
  210031. #else
  210032. #define log(a)
  210033. #endif
  210034. #undef OK
  210035. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210036. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210037. {
  210038. if (err == noErr)
  210039. return true;
  210040. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210041. jassertfalse
  210042. return false;
  210043. }
  210044. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210045. #else
  210046. #define OK(a) (a == noErr)
  210047. #endif
  210048. class CoreAudioInternal : public Timer
  210049. {
  210050. public:
  210051. CoreAudioInternal (AudioDeviceID id)
  210052. : inputLatency (0),
  210053. outputLatency (0),
  210054. callback (0),
  210055. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210056. audioProcID (0),
  210057. #endif
  210058. inputDevice (0),
  210059. isSlaveDevice (false),
  210060. deviceID (id),
  210061. started (false),
  210062. sampleRate (0),
  210063. bufferSize (512),
  210064. numInputChans (0),
  210065. numOutputChans (0),
  210066. callbacksAllowed (true),
  210067. numInputChannelInfos (0),
  210068. numOutputChannelInfos (0)
  210069. {
  210070. jassert (deviceID != 0);
  210071. updateDetailsFromDevice();
  210072. AudioObjectPropertyAddress pa;
  210073. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210074. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210075. pa.mElement = kAudioObjectPropertyElementWildcard;
  210076. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210077. }
  210078. ~CoreAudioInternal()
  210079. {
  210080. AudioObjectPropertyAddress pa;
  210081. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210082. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210083. pa.mElement = kAudioObjectPropertyElementWildcard;
  210084. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210085. stop (false);
  210086. delete inputDevice;
  210087. }
  210088. void allocateTempBuffers()
  210089. {
  210090. const int tempBufSize = bufferSize + 4;
  210091. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210092. tempInputBuffers.calloc (numInputChans + 2);
  210093. tempOutputBuffers.calloc (numOutputChans + 2);
  210094. int i, count = 0;
  210095. for (i = 0; i < numInputChans; ++i)
  210096. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210097. for (i = 0; i < numOutputChans; ++i)
  210098. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210099. }
  210100. // returns the number of actual available channels
  210101. void fillInChannelInfo (const bool input)
  210102. {
  210103. int chanNum = 0;
  210104. UInt32 size;
  210105. AudioObjectPropertyAddress pa;
  210106. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210107. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210108. pa.mElement = kAudioObjectPropertyElementMaster;
  210109. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210110. {
  210111. HeapBlock <AudioBufferList> bufList;
  210112. bufList.calloc (size, 1);
  210113. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210114. {
  210115. const int numStreams = bufList->mNumberBuffers;
  210116. for (int i = 0; i < numStreams; ++i)
  210117. {
  210118. const AudioBuffer& b = bufList->mBuffers[i];
  210119. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210120. {
  210121. String name;
  210122. {
  210123. uint8 channelName [256];
  210124. zerostruct (channelName);
  210125. UInt32 nameSize = sizeof (channelName);
  210126. UInt32 channelNum = chanNum + 1;
  210127. pa.mSelector = kAudioDevicePropertyChannelName;
  210128. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210129. name = String::fromUTF8 (channelName, nameSize);
  210130. }
  210131. if (input)
  210132. {
  210133. if (activeInputChans[chanNum])
  210134. {
  210135. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210136. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210137. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210138. ++numInputChannelInfos;
  210139. }
  210140. if (name.isEmpty())
  210141. name << "Input " << (chanNum + 1);
  210142. inChanNames.add (name);
  210143. }
  210144. else
  210145. {
  210146. if (activeOutputChans[chanNum])
  210147. {
  210148. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210149. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210150. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210151. ++numOutputChannelInfos;
  210152. }
  210153. if (name.isEmpty())
  210154. name << "Output " << (chanNum + 1);
  210155. outChanNames.add (name);
  210156. }
  210157. ++chanNum;
  210158. }
  210159. }
  210160. }
  210161. }
  210162. }
  210163. void updateDetailsFromDevice()
  210164. {
  210165. stopTimer();
  210166. if (deviceID == 0)
  210167. return;
  210168. const ScopedLock sl (callbackLock);
  210169. Float64 sr;
  210170. UInt32 size = sizeof (Float64);
  210171. AudioObjectPropertyAddress pa;
  210172. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210173. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210174. pa.mElement = kAudioObjectPropertyElementMaster;
  210175. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210176. sampleRate = sr;
  210177. UInt32 framesPerBuf;
  210178. size = sizeof (framesPerBuf);
  210179. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210180. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210181. {
  210182. bufferSize = framesPerBuf;
  210183. allocateTempBuffers();
  210184. }
  210185. bufferSizes.clear();
  210186. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210187. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210188. {
  210189. HeapBlock <AudioValueRange> ranges;
  210190. ranges.calloc (size, 1);
  210191. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210192. {
  210193. bufferSizes.add ((int) ranges[0].mMinimum);
  210194. for (int i = 32; i < 8192; i += 32)
  210195. {
  210196. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210197. {
  210198. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210199. {
  210200. bufferSizes.addIfNotAlreadyThere (i);
  210201. break;
  210202. }
  210203. }
  210204. }
  210205. if (bufferSize > 0)
  210206. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210207. }
  210208. }
  210209. if (bufferSizes.size() == 0 && bufferSize > 0)
  210210. bufferSizes.add (bufferSize);
  210211. sampleRates.clear();
  210212. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210213. String rates;
  210214. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210215. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210216. {
  210217. HeapBlock <AudioValueRange> ranges;
  210218. ranges.calloc (size, 1);
  210219. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210220. {
  210221. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210222. {
  210223. bool ok = false;
  210224. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210225. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210226. ok = true;
  210227. if (ok)
  210228. {
  210229. sampleRates.add (possibleRates[i]);
  210230. rates << possibleRates[i] << T(" ");
  210231. }
  210232. }
  210233. }
  210234. }
  210235. if (sampleRates.size() == 0 && sampleRate > 0)
  210236. {
  210237. sampleRates.add (sampleRate);
  210238. rates << sampleRate;
  210239. }
  210240. log (T("sr: ") + rates);
  210241. inputLatency = 0;
  210242. outputLatency = 0;
  210243. UInt32 lat;
  210244. size = sizeof (lat);
  210245. pa.mSelector = kAudioDevicePropertyLatency;
  210246. pa.mScope = kAudioDevicePropertyScopeInput;
  210247. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210248. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210249. inputLatency = (int) lat;
  210250. pa.mScope = kAudioDevicePropertyScopeOutput;
  210251. size = sizeof (lat);
  210252. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210253. outputLatency = (int) lat;
  210254. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210255. inChanNames.clear();
  210256. outChanNames.clear();
  210257. inputChannelInfo.calloc (numInputChans + 2);
  210258. numInputChannelInfos = 0;
  210259. outputChannelInfo.calloc (numOutputChans + 2);
  210260. numOutputChannelInfos = 0;
  210261. fillInChannelInfo (true);
  210262. fillInChannelInfo (false);
  210263. }
  210264. const StringArray getSources (bool input)
  210265. {
  210266. StringArray s;
  210267. HeapBlock <OSType> types;
  210268. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210269. for (int i = 0; i < num; ++i)
  210270. {
  210271. AudioValueTranslation avt;
  210272. char buffer[256];
  210273. avt.mInputData = (void*) &(types[i]);
  210274. avt.mInputDataSize = sizeof (UInt32);
  210275. avt.mOutputData = buffer;
  210276. avt.mOutputDataSize = 256;
  210277. UInt32 transSize = sizeof (avt);
  210278. AudioObjectPropertyAddress pa;
  210279. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210280. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210281. pa.mElement = kAudioObjectPropertyElementMaster;
  210282. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210283. {
  210284. DBG (buffer);
  210285. s.add (buffer);
  210286. }
  210287. }
  210288. return s;
  210289. }
  210290. int getCurrentSourceIndex (bool input) const
  210291. {
  210292. OSType currentSourceID = 0;
  210293. UInt32 size = sizeof (currentSourceID);
  210294. int result = -1;
  210295. AudioObjectPropertyAddress pa;
  210296. pa.mSelector = kAudioDevicePropertyDataSource;
  210297. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210298. pa.mElement = kAudioObjectPropertyElementMaster;
  210299. if (deviceID != 0)
  210300. {
  210301. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210302. {
  210303. HeapBlock <OSType> types;
  210304. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210305. for (int i = 0; i < num; ++i)
  210306. {
  210307. if (types[num] == currentSourceID)
  210308. {
  210309. result = i;
  210310. break;
  210311. }
  210312. }
  210313. }
  210314. }
  210315. return result;
  210316. }
  210317. void setCurrentSourceIndex (int index, bool input)
  210318. {
  210319. if (deviceID != 0)
  210320. {
  210321. HeapBlock <OSType> types;
  210322. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210323. if (((unsigned int) index) < (unsigned int) num)
  210324. {
  210325. AudioObjectPropertyAddress pa;
  210326. pa.mSelector = kAudioDevicePropertyDataSource;
  210327. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210328. pa.mElement = kAudioObjectPropertyElementMaster;
  210329. OSType typeId = types[index];
  210330. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210331. }
  210332. }
  210333. }
  210334. const String reopen (const BitArray& inputChannels,
  210335. const BitArray& outputChannels,
  210336. double newSampleRate,
  210337. int bufferSizeSamples)
  210338. {
  210339. String error;
  210340. log ("CoreAudio reopen");
  210341. callbacksAllowed = false;
  210342. stopTimer();
  210343. stop (false);
  210344. activeInputChans = inputChannels;
  210345. activeInputChans.setRange (inChanNames.size(),
  210346. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210347. false);
  210348. activeOutputChans = outputChannels;
  210349. activeOutputChans.setRange (outChanNames.size(),
  210350. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210351. false);
  210352. numInputChans = activeInputChans.countNumberOfSetBits();
  210353. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210354. // set sample rate
  210355. AudioObjectPropertyAddress pa;
  210356. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210357. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210358. pa.mElement = kAudioObjectPropertyElementMaster;
  210359. Float64 sr = newSampleRate;
  210360. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210361. {
  210362. error = "Couldn't change sample rate";
  210363. }
  210364. else
  210365. {
  210366. // change buffer size
  210367. UInt32 framesPerBuf = bufferSizeSamples;
  210368. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210369. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210370. {
  210371. error = "Couldn't change buffer size";
  210372. }
  210373. else
  210374. {
  210375. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210376. // correctly report their new settings until some random time in the future, so
  210377. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210378. // to make sure we're using the correct numbers..
  210379. updateDetailsFromDevice();
  210380. sampleRate = newSampleRate;
  210381. bufferSize = bufferSizeSamples;
  210382. if (sampleRates.size() == 0)
  210383. error = "Device has no available sample-rates";
  210384. else if (bufferSizes.size() == 0)
  210385. error = "Device has no available buffer-sizes";
  210386. else if (inputDevice != 0)
  210387. error = inputDevice->reopen (inputChannels,
  210388. outputChannels,
  210389. newSampleRate,
  210390. bufferSizeSamples);
  210391. }
  210392. }
  210393. callbacksAllowed = true;
  210394. return error;
  210395. }
  210396. bool start (AudioIODeviceCallback* cb)
  210397. {
  210398. if (! started)
  210399. {
  210400. callback = 0;
  210401. if (deviceID != 0)
  210402. {
  210403. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210404. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210405. #else
  210406. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210407. #endif
  210408. {
  210409. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210410. {
  210411. started = true;
  210412. }
  210413. else
  210414. {
  210415. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210416. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210417. #else
  210418. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210419. audioProcID = 0;
  210420. #endif
  210421. }
  210422. }
  210423. }
  210424. }
  210425. if (started)
  210426. {
  210427. const ScopedLock sl (callbackLock);
  210428. callback = cb;
  210429. }
  210430. if (inputDevice != 0)
  210431. return started && inputDevice->start (cb);
  210432. else
  210433. return started;
  210434. }
  210435. void stop (bool leaveInterruptRunning)
  210436. {
  210437. callbackLock.enter();
  210438. callback = 0;
  210439. callbackLock.exit();
  210440. if (started
  210441. && (deviceID != 0)
  210442. && ! leaveInterruptRunning)
  210443. {
  210444. OK (AudioDeviceStop (deviceID, audioIOProc));
  210445. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210446. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210447. #else
  210448. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210449. audioProcID = 0;
  210450. #endif
  210451. started = false;
  210452. callbackLock.enter();
  210453. callbackLock.exit();
  210454. // wait until it's definately stopped calling back..
  210455. for (int i = 40; --i >= 0;)
  210456. {
  210457. Thread::sleep (50);
  210458. UInt32 running = 0;
  210459. UInt32 size = sizeof (running);
  210460. AudioObjectPropertyAddress pa;
  210461. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210462. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210463. pa.mElement = kAudioObjectPropertyElementMaster;
  210464. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210465. if (running == 0)
  210466. break;
  210467. }
  210468. callbackLock.enter();
  210469. callbackLock.exit();
  210470. }
  210471. if (inputDevice != 0)
  210472. inputDevice->stop (leaveInterruptRunning);
  210473. }
  210474. double getSampleRate() const
  210475. {
  210476. return sampleRate;
  210477. }
  210478. int getBufferSize() const
  210479. {
  210480. return bufferSize;
  210481. }
  210482. void audioCallback (const AudioBufferList* inInputData,
  210483. AudioBufferList* outOutputData)
  210484. {
  210485. int i;
  210486. const ScopedLock sl (callbackLock);
  210487. if (callback != 0)
  210488. {
  210489. if (inputDevice == 0)
  210490. {
  210491. for (i = numInputChans; --i >= 0;)
  210492. {
  210493. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210494. float* dest = tempInputBuffers [i];
  210495. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210496. + info.dataOffsetSamples;
  210497. const int stride = info.dataStrideSamples;
  210498. if (stride != 0) // if this is zero, info is invalid
  210499. {
  210500. for (int j = bufferSize; --j >= 0;)
  210501. {
  210502. *dest++ = *src;
  210503. src += stride;
  210504. }
  210505. }
  210506. }
  210507. }
  210508. if (! isSlaveDevice)
  210509. {
  210510. if (inputDevice == 0)
  210511. {
  210512. callback->audioDeviceIOCallback ((const float**) tempInputBuffers,
  210513. numInputChans,
  210514. tempOutputBuffers,
  210515. numOutputChans,
  210516. bufferSize);
  210517. }
  210518. else
  210519. {
  210520. jassert (inputDevice->bufferSize == bufferSize);
  210521. // Sometimes the two linked devices seem to get their callbacks in
  210522. // parallel, so we need to lock both devices to stop the input data being
  210523. // changed while inside our callback..
  210524. const ScopedLock sl2 (inputDevice->callbackLock);
  210525. callback->audioDeviceIOCallback ((const float**) inputDevice->tempInputBuffers,
  210526. inputDevice->numInputChans,
  210527. tempOutputBuffers,
  210528. numOutputChans,
  210529. bufferSize);
  210530. }
  210531. for (i = numOutputChans; --i >= 0;)
  210532. {
  210533. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210534. const float* src = tempOutputBuffers [i];
  210535. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210536. + info.dataOffsetSamples;
  210537. const int stride = info.dataStrideSamples;
  210538. if (stride != 0) // if this is zero, info is invalid
  210539. {
  210540. for (int j = bufferSize; --j >= 0;)
  210541. {
  210542. *dest = *src++;
  210543. dest += stride;
  210544. }
  210545. }
  210546. }
  210547. }
  210548. }
  210549. else
  210550. {
  210551. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210552. {
  210553. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210554. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210555. + info.dataOffsetSamples;
  210556. const int stride = info.dataStrideSamples;
  210557. if (stride != 0) // if this is zero, info is invalid
  210558. {
  210559. for (int j = bufferSize; --j >= 0;)
  210560. {
  210561. *dest = 0.0f;
  210562. dest += stride;
  210563. }
  210564. }
  210565. }
  210566. }
  210567. }
  210568. // called by callbacks
  210569. void deviceDetailsChanged()
  210570. {
  210571. if (callbacksAllowed)
  210572. startTimer (100);
  210573. }
  210574. void timerCallback()
  210575. {
  210576. stopTimer();
  210577. log ("CoreAudio device changed callback");
  210578. const double oldSampleRate = sampleRate;
  210579. const int oldBufferSize = bufferSize;
  210580. updateDetailsFromDevice();
  210581. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210582. {
  210583. callbacksAllowed = false;
  210584. stop (false);
  210585. updateDetailsFromDevice();
  210586. callbacksAllowed = true;
  210587. }
  210588. }
  210589. CoreAudioInternal* getRelatedDevice() const
  210590. {
  210591. UInt32 size = 0;
  210592. ScopedPointer <CoreAudioInternal> result;
  210593. AudioObjectPropertyAddress pa;
  210594. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210595. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210596. pa.mElement = kAudioObjectPropertyElementMaster;
  210597. if (deviceID != 0
  210598. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210599. && size > 0)
  210600. {
  210601. HeapBlock <AudioDeviceID> devs;
  210602. devs.calloc (size, 1);
  210603. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210604. {
  210605. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210606. {
  210607. if (devs[i] != deviceID && devs[i] != 0)
  210608. {
  210609. result = new CoreAudioInternal (devs[i]);
  210610. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210611. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210612. if (thisIsInput != otherIsInput
  210613. || (inChanNames.size() + outChanNames.size() == 0)
  210614. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210615. break;
  210616. result = 0;
  210617. }
  210618. }
  210619. }
  210620. }
  210621. return result.release();
  210622. }
  210623. juce_UseDebuggingNewOperator
  210624. int inputLatency, outputLatency;
  210625. BitArray activeInputChans, activeOutputChans;
  210626. StringArray inChanNames, outChanNames;
  210627. Array <double> sampleRates;
  210628. Array <int> bufferSizes;
  210629. AudioIODeviceCallback* callback;
  210630. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210631. AudioDeviceIOProcID audioProcID;
  210632. #endif
  210633. CoreAudioInternal* inputDevice;
  210634. bool isSlaveDevice;
  210635. private:
  210636. CriticalSection callbackLock;
  210637. AudioDeviceID deviceID;
  210638. bool started;
  210639. double sampleRate;
  210640. int bufferSize;
  210641. HeapBlock <float> audioBuffer;
  210642. int numInputChans, numOutputChans;
  210643. bool callbacksAllowed;
  210644. struct CallbackDetailsForChannel
  210645. {
  210646. int streamNum;
  210647. int dataOffsetSamples;
  210648. int dataStrideSamples;
  210649. };
  210650. int numInputChannelInfos, numOutputChannelInfos;
  210651. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210652. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210653. CoreAudioInternal (const CoreAudioInternal&);
  210654. const CoreAudioInternal& operator= (const CoreAudioInternal&);
  210655. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210656. const AudioTimeStamp* inNow,
  210657. const AudioBufferList* inInputData,
  210658. const AudioTimeStamp* inInputTime,
  210659. AudioBufferList* outOutputData,
  210660. const AudioTimeStamp* inOutputTime,
  210661. void* device)
  210662. {
  210663. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210664. return noErr;
  210665. }
  210666. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210667. {
  210668. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210669. switch (pa->mSelector)
  210670. {
  210671. case kAudioDevicePropertyBufferSize:
  210672. case kAudioDevicePropertyBufferFrameSize:
  210673. case kAudioDevicePropertyNominalSampleRate:
  210674. case kAudioDevicePropertyStreamFormat:
  210675. case kAudioDevicePropertyDeviceIsAlive:
  210676. intern->deviceDetailsChanged();
  210677. break;
  210678. case kAudioDevicePropertyBufferSizeRange:
  210679. case kAudioDevicePropertyVolumeScalar:
  210680. case kAudioDevicePropertyMute:
  210681. case kAudioDevicePropertyPlayThru:
  210682. case kAudioDevicePropertyDataSource:
  210683. case kAudioDevicePropertyDeviceIsRunning:
  210684. break;
  210685. }
  210686. return noErr;
  210687. }
  210688. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210689. {
  210690. AudioObjectPropertyAddress pa;
  210691. pa.mSelector = kAudioDevicePropertyDataSources;
  210692. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210693. pa.mElement = kAudioObjectPropertyElementMaster;
  210694. UInt32 size = 0;
  210695. if (deviceID != 0
  210696. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210697. {
  210698. types.calloc (size, 1);
  210699. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  210700. return size / (int) sizeof (OSType);
  210701. }
  210702. return 0;
  210703. }
  210704. };
  210705. class CoreAudioIODevice : public AudioIODevice
  210706. {
  210707. public:
  210708. CoreAudioIODevice (const String& deviceName,
  210709. AudioDeviceID inputDeviceId,
  210710. const int inputIndex_,
  210711. AudioDeviceID outputDeviceId,
  210712. const int outputIndex_)
  210713. : AudioIODevice (deviceName, "CoreAudio"),
  210714. inputIndex (inputIndex_),
  210715. outputIndex (outputIndex_),
  210716. isOpen_ (false),
  210717. isStarted (false)
  210718. {
  210719. internal = 0;
  210720. CoreAudioInternal* device = 0;
  210721. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  210722. {
  210723. jassert (inputDeviceId != 0);
  210724. device = new CoreAudioInternal (inputDeviceId);
  210725. }
  210726. else
  210727. {
  210728. device = new CoreAudioInternal (outputDeviceId);
  210729. if (inputDeviceId != 0)
  210730. {
  210731. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  210732. device->inputDevice = secondDevice;
  210733. secondDevice->isSlaveDevice = true;
  210734. }
  210735. }
  210736. internal = device;
  210737. AudioObjectPropertyAddress pa;
  210738. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210739. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210740. pa.mElement = kAudioObjectPropertyElementWildcard;
  210741. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210742. }
  210743. ~CoreAudioIODevice()
  210744. {
  210745. AudioObjectPropertyAddress pa;
  210746. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210747. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210748. pa.mElement = kAudioObjectPropertyElementWildcard;
  210749. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210750. delete internal;
  210751. }
  210752. const StringArray getOutputChannelNames()
  210753. {
  210754. return internal->outChanNames;
  210755. }
  210756. const StringArray getInputChannelNames()
  210757. {
  210758. if (internal->inputDevice != 0)
  210759. return internal->inputDevice->inChanNames;
  210760. else
  210761. return internal->inChanNames;
  210762. }
  210763. int getNumSampleRates()
  210764. {
  210765. return internal->sampleRates.size();
  210766. }
  210767. double getSampleRate (int index)
  210768. {
  210769. return internal->sampleRates [index];
  210770. }
  210771. int getNumBufferSizesAvailable()
  210772. {
  210773. return internal->bufferSizes.size();
  210774. }
  210775. int getBufferSizeSamples (int index)
  210776. {
  210777. return internal->bufferSizes [index];
  210778. }
  210779. int getDefaultBufferSize()
  210780. {
  210781. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  210782. if (getBufferSizeSamples(i) >= 512)
  210783. return getBufferSizeSamples(i);
  210784. return 512;
  210785. }
  210786. const String open (const BitArray& inputChannels,
  210787. const BitArray& outputChannels,
  210788. double sampleRate,
  210789. int bufferSizeSamples)
  210790. {
  210791. isOpen_ = true;
  210792. if (bufferSizeSamples <= 0)
  210793. bufferSizeSamples = getDefaultBufferSize();
  210794. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  210795. isOpen_ = lastError.isEmpty();
  210796. return lastError;
  210797. }
  210798. void close()
  210799. {
  210800. isOpen_ = false;
  210801. internal->stop (false);
  210802. }
  210803. bool isOpen()
  210804. {
  210805. return isOpen_;
  210806. }
  210807. int getCurrentBufferSizeSamples()
  210808. {
  210809. return internal != 0 ? internal->getBufferSize() : 512;
  210810. }
  210811. double getCurrentSampleRate()
  210812. {
  210813. return internal != 0 ? internal->getSampleRate() : 0;
  210814. }
  210815. int getCurrentBitDepth()
  210816. {
  210817. return 32; // no way to find out, so just assume it's high..
  210818. }
  210819. const BitArray getActiveOutputChannels() const
  210820. {
  210821. return internal != 0 ? internal->activeOutputChans : BitArray();
  210822. }
  210823. const BitArray getActiveInputChannels() const
  210824. {
  210825. BitArray chans;
  210826. if (internal != 0)
  210827. {
  210828. chans = internal->activeInputChans;
  210829. if (internal->inputDevice != 0)
  210830. chans.orWith (internal->inputDevice->activeInputChans);
  210831. }
  210832. return chans;
  210833. }
  210834. int getOutputLatencyInSamples()
  210835. {
  210836. if (internal == 0)
  210837. return 0;
  210838. // this seems like a good guess at getting the latency right - comparing
  210839. // this with a round-trip measurement, it gets it to within a few millisecs
  210840. // for the built-in mac soundcard
  210841. return internal->outputLatency + internal->getBufferSize() * 2;
  210842. }
  210843. int getInputLatencyInSamples()
  210844. {
  210845. if (internal == 0)
  210846. return 0;
  210847. return internal->inputLatency + internal->getBufferSize() * 2;
  210848. }
  210849. void start (AudioIODeviceCallback* callback)
  210850. {
  210851. if (internal != 0 && ! isStarted)
  210852. {
  210853. if (callback != 0)
  210854. callback->audioDeviceAboutToStart (this);
  210855. isStarted = true;
  210856. internal->start (callback);
  210857. }
  210858. }
  210859. void stop()
  210860. {
  210861. if (isStarted && internal != 0)
  210862. {
  210863. AudioIODeviceCallback* const lastCallback = internal->callback;
  210864. isStarted = false;
  210865. internal->stop (true);
  210866. if (lastCallback != 0)
  210867. lastCallback->audioDeviceStopped();
  210868. }
  210869. }
  210870. bool isPlaying()
  210871. {
  210872. if (internal->callback == 0)
  210873. isStarted = false;
  210874. return isStarted;
  210875. }
  210876. const String getLastError()
  210877. {
  210878. return lastError;
  210879. }
  210880. int inputIndex, outputIndex;
  210881. juce_UseDebuggingNewOperator
  210882. private:
  210883. CoreAudioInternal* internal;
  210884. bool isOpen_, isStarted;
  210885. String lastError;
  210886. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210887. {
  210888. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210889. switch (pa->mSelector)
  210890. {
  210891. case kAudioHardwarePropertyDevices:
  210892. intern->deviceDetailsChanged();
  210893. break;
  210894. case kAudioHardwarePropertyDefaultOutputDevice:
  210895. case kAudioHardwarePropertyDefaultInputDevice:
  210896. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  210897. break;
  210898. }
  210899. return noErr;
  210900. }
  210901. CoreAudioIODevice (const CoreAudioIODevice&);
  210902. const CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  210903. };
  210904. class CoreAudioIODeviceType : public AudioIODeviceType
  210905. {
  210906. public:
  210907. CoreAudioIODeviceType()
  210908. : AudioIODeviceType (T("CoreAudio")),
  210909. hasScanned (false)
  210910. {
  210911. }
  210912. ~CoreAudioIODeviceType()
  210913. {
  210914. }
  210915. void scanForDevices()
  210916. {
  210917. hasScanned = true;
  210918. inputDeviceNames.clear();
  210919. outputDeviceNames.clear();
  210920. inputIds.clear();
  210921. outputIds.clear();
  210922. UInt32 size;
  210923. AudioObjectPropertyAddress pa;
  210924. pa.mSelector = kAudioHardwarePropertyDevices;
  210925. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210926. pa.mElement = kAudioObjectPropertyElementMaster;
  210927. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  210928. {
  210929. HeapBlock <AudioDeviceID> devs;
  210930. devs.calloc (size, 1);
  210931. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  210932. {
  210933. static bool alreadyLogged = false;
  210934. const int num = size / (int) sizeof (AudioDeviceID);
  210935. for (int i = 0; i < num; ++i)
  210936. {
  210937. char name [1024];
  210938. size = sizeof (name);
  210939. pa.mSelector = kAudioDevicePropertyDeviceName;
  210940. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  210941. {
  210942. const String nameString (String::fromUTF8 ((const uint8*) name, (int) strlen (name)));
  210943. if (! alreadyLogged)
  210944. log (T("CoreAudio device: ") + nameString);
  210945. const int numIns = getNumChannels (devs[i], true);
  210946. const int numOuts = getNumChannels (devs[i], false);
  210947. if (numIns > 0)
  210948. {
  210949. inputDeviceNames.add (nameString);
  210950. inputIds.add (devs[i]);
  210951. }
  210952. if (numOuts > 0)
  210953. {
  210954. outputDeviceNames.add (nameString);
  210955. outputIds.add (devs[i]);
  210956. }
  210957. }
  210958. }
  210959. alreadyLogged = true;
  210960. }
  210961. }
  210962. inputDeviceNames.appendNumbersToDuplicates (false, true);
  210963. outputDeviceNames.appendNumbersToDuplicates (false, true);
  210964. }
  210965. const StringArray getDeviceNames (const bool wantInputNames) const
  210966. {
  210967. jassert (hasScanned); // need to call scanForDevices() before doing this
  210968. if (wantInputNames)
  210969. return inputDeviceNames;
  210970. else
  210971. return outputDeviceNames;
  210972. }
  210973. int getDefaultDeviceIndex (const bool forInput) const
  210974. {
  210975. jassert (hasScanned); // need to call scanForDevices() before doing this
  210976. AudioDeviceID deviceID;
  210977. UInt32 size = sizeof (deviceID);
  210978. // if they're asking for any input channels at all, use the default input, so we
  210979. // get the built-in mic rather than the built-in output with no inputs..
  210980. AudioObjectPropertyAddress pa;
  210981. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  210982. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210983. pa.mElement = kAudioObjectPropertyElementMaster;
  210984. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  210985. {
  210986. if (forInput)
  210987. {
  210988. for (int i = inputIds.size(); --i >= 0;)
  210989. if (inputIds[i] == deviceID)
  210990. return i;
  210991. }
  210992. else
  210993. {
  210994. for (int i = outputIds.size(); --i >= 0;)
  210995. if (outputIds[i] == deviceID)
  210996. return i;
  210997. }
  210998. }
  210999. return 0;
  211000. }
  211001. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211002. {
  211003. jassert (hasScanned); // need to call scanForDevices() before doing this
  211004. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211005. if (d == 0)
  211006. return -1;
  211007. return asInput ? d->inputIndex
  211008. : d->outputIndex;
  211009. }
  211010. bool hasSeparateInputsAndOutputs() const { return true; }
  211011. AudioIODevice* createDevice (const String& outputDeviceName,
  211012. const String& inputDeviceName)
  211013. {
  211014. jassert (hasScanned); // need to call scanForDevices() before doing this
  211015. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211016. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211017. String deviceName (outputDeviceName);
  211018. if (deviceName.isEmpty())
  211019. deviceName = inputDeviceName;
  211020. if (index >= 0)
  211021. return new CoreAudioIODevice (deviceName,
  211022. inputIds [inputIndex],
  211023. inputIndex,
  211024. outputIds [outputIndex],
  211025. outputIndex);
  211026. return 0;
  211027. }
  211028. juce_UseDebuggingNewOperator
  211029. private:
  211030. StringArray inputDeviceNames, outputDeviceNames;
  211031. Array <AudioDeviceID> inputIds, outputIds;
  211032. bool hasScanned;
  211033. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211034. {
  211035. int total = 0;
  211036. UInt32 size;
  211037. AudioObjectPropertyAddress pa;
  211038. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211039. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211040. pa.mElement = kAudioObjectPropertyElementMaster;
  211041. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211042. {
  211043. HeapBlock <AudioBufferList> bufList;
  211044. bufList.calloc (size, 1);
  211045. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211046. {
  211047. const int numStreams = bufList->mNumberBuffers;
  211048. for (int i = 0; i < numStreams; ++i)
  211049. {
  211050. const AudioBuffer& b = bufList->mBuffers[i];
  211051. total += b.mNumberChannels;
  211052. }
  211053. }
  211054. }
  211055. return total;
  211056. }
  211057. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211058. const CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211059. };
  211060. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211061. {
  211062. return new CoreAudioIODeviceType();
  211063. }
  211064. #undef log
  211065. #endif
  211066. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211067. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211068. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211069. // compiled on its own).
  211070. #if JUCE_INCLUDED_FILE
  211071. #if JUCE_MAC
  211072. #undef log
  211073. #define log(a) Logger::writeToLog(a)
  211074. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211075. {
  211076. if (err == noErr)
  211077. return true;
  211078. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211079. jassertfalse
  211080. return false;
  211081. }
  211082. #undef OK
  211083. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211084. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211085. {
  211086. String result;
  211087. CFStringRef str = 0;
  211088. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211089. if (str != 0)
  211090. {
  211091. result = PlatformUtilities::cfStringToJuceString (str);
  211092. CFRelease (str);
  211093. str = 0;
  211094. }
  211095. MIDIEntityRef entity = 0;
  211096. MIDIEndpointGetEntity (endpoint, &entity);
  211097. if (entity == 0)
  211098. return result; // probably virtual
  211099. if (result.isEmpty())
  211100. {
  211101. // endpoint name has zero length - try the entity
  211102. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211103. if (str != 0)
  211104. {
  211105. result += PlatformUtilities::cfStringToJuceString (str);
  211106. CFRelease (str);
  211107. str = 0;
  211108. }
  211109. }
  211110. // now consider the device's name
  211111. MIDIDeviceRef device = 0;
  211112. MIDIEntityGetDevice (entity, &device);
  211113. if (device == 0)
  211114. return result;
  211115. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211116. if (str != 0)
  211117. {
  211118. const String s (PlatformUtilities::cfStringToJuceString (str));
  211119. CFRelease (str);
  211120. // if an external device has only one entity, throw away
  211121. // the endpoint name and just use the device name
  211122. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211123. {
  211124. result = s;
  211125. }
  211126. else if (! result.startsWithIgnoreCase (s))
  211127. {
  211128. // prepend the device name to the entity name
  211129. result = (s + T(" ") + result).trimEnd();
  211130. }
  211131. }
  211132. return result;
  211133. }
  211134. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211135. {
  211136. String result;
  211137. // Does the endpoint have connections?
  211138. CFDataRef connections = 0;
  211139. int numConnections = 0;
  211140. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211141. if (connections != 0)
  211142. {
  211143. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211144. if (numConnections > 0)
  211145. {
  211146. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211147. for (int i = 0; i < numConnections; ++i, ++pid)
  211148. {
  211149. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211150. MIDIObjectRef connObject;
  211151. MIDIObjectType connObjectType;
  211152. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211153. if (err == noErr)
  211154. {
  211155. String s;
  211156. if (connObjectType == kMIDIObjectType_ExternalSource
  211157. || connObjectType == kMIDIObjectType_ExternalDestination)
  211158. {
  211159. // Connected to an external device's endpoint (10.3 and later).
  211160. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211161. }
  211162. else
  211163. {
  211164. // Connected to an external device (10.2) (or something else, catch-all)
  211165. CFStringRef str = 0;
  211166. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211167. if (str != 0)
  211168. {
  211169. s = PlatformUtilities::cfStringToJuceString (str);
  211170. CFRelease (str);
  211171. }
  211172. }
  211173. if (s.isNotEmpty())
  211174. {
  211175. if (result.isNotEmpty())
  211176. result += (", ");
  211177. result += s;
  211178. }
  211179. }
  211180. }
  211181. }
  211182. CFRelease (connections);
  211183. }
  211184. if (result.isNotEmpty())
  211185. return result;
  211186. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211187. return getEndpointName (endpoint, false);
  211188. }
  211189. const StringArray MidiOutput::getDevices()
  211190. {
  211191. StringArray s;
  211192. const ItemCount num = MIDIGetNumberOfDestinations();
  211193. for (ItemCount i = 0; i < num; ++i)
  211194. {
  211195. MIDIEndpointRef dest = MIDIGetDestination (i);
  211196. if (dest != 0)
  211197. {
  211198. String name (getConnectedEndpointName (dest));
  211199. if (name.isEmpty())
  211200. name = "<error>";
  211201. s.add (name);
  211202. }
  211203. else
  211204. {
  211205. s.add ("<error>");
  211206. }
  211207. }
  211208. return s;
  211209. }
  211210. int MidiOutput::getDefaultDeviceIndex()
  211211. {
  211212. return 0;
  211213. }
  211214. static MIDIClientRef globalMidiClient;
  211215. static bool hasGlobalClientBeenCreated = false;
  211216. static bool makeSureClientExists()
  211217. {
  211218. if (! hasGlobalClientBeenCreated)
  211219. {
  211220. String name (T("JUCE"));
  211221. if (JUCEApplication::getInstance() != 0)
  211222. name = JUCEApplication::getInstance()->getApplicationName();
  211223. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211224. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211225. CFRelease (appName);
  211226. }
  211227. return hasGlobalClientBeenCreated;
  211228. }
  211229. class MidiPortAndEndpoint
  211230. {
  211231. public:
  211232. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211233. : port (port_), endPoint (endPoint_)
  211234. {
  211235. }
  211236. ~MidiPortAndEndpoint()
  211237. {
  211238. if (port != 0)
  211239. MIDIPortDispose (port);
  211240. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211241. MIDIEndpointDispose (endPoint);
  211242. }
  211243. MIDIPortRef port;
  211244. MIDIEndpointRef endPoint;
  211245. };
  211246. MidiOutput* MidiOutput::openDevice (int index)
  211247. {
  211248. MidiOutput* mo = 0;
  211249. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211250. {
  211251. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211252. CFStringRef pname;
  211253. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211254. {
  211255. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211256. if (makeSureClientExists())
  211257. {
  211258. MIDIPortRef port;
  211259. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211260. {
  211261. mo = new MidiOutput();
  211262. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211263. }
  211264. }
  211265. CFRelease (pname);
  211266. }
  211267. }
  211268. return mo;
  211269. }
  211270. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211271. {
  211272. MidiOutput* mo = 0;
  211273. if (makeSureClientExists())
  211274. {
  211275. MIDIEndpointRef endPoint;
  211276. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211277. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211278. {
  211279. mo = new MidiOutput();
  211280. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211281. }
  211282. CFRelease (name);
  211283. }
  211284. return mo;
  211285. }
  211286. MidiOutput::~MidiOutput()
  211287. {
  211288. delete (MidiPortAndEndpoint*) internal;
  211289. }
  211290. void MidiOutput::reset()
  211291. {
  211292. }
  211293. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211294. {
  211295. return false;
  211296. }
  211297. void MidiOutput::setVolume (float leftVol, float rightVol)
  211298. {
  211299. }
  211300. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211301. {
  211302. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211303. if (message.isSysEx())
  211304. {
  211305. const int maxPacketSize = 256;
  211306. int pos = 0, bytesLeft = message.getRawDataSize();
  211307. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211308. HeapBlock <MIDIPacketList> packets;
  211309. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211310. packets->numPackets = numPackets;
  211311. MIDIPacket* p = packets->packet;
  211312. for (int i = 0; i < numPackets; ++i)
  211313. {
  211314. p->timeStamp = 0;
  211315. p->length = jmin (maxPacketSize, bytesLeft);
  211316. memcpy (p->data, message.getRawData() + pos, p->length);
  211317. pos += p->length;
  211318. bytesLeft -= p->length;
  211319. p = MIDIPacketNext (p);
  211320. }
  211321. if (mpe->port != 0)
  211322. MIDISend (mpe->port, mpe->endPoint, packets);
  211323. else
  211324. MIDIReceived (mpe->endPoint, packets);
  211325. }
  211326. else
  211327. {
  211328. MIDIPacketList packets;
  211329. packets.numPackets = 1;
  211330. packets.packet[0].timeStamp = 0;
  211331. packets.packet[0].length = message.getRawDataSize();
  211332. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211333. if (mpe->port != 0)
  211334. MIDISend (mpe->port, mpe->endPoint, &packets);
  211335. else
  211336. MIDIReceived (mpe->endPoint, &packets);
  211337. }
  211338. }
  211339. const StringArray MidiInput::getDevices()
  211340. {
  211341. StringArray s;
  211342. const ItemCount num = MIDIGetNumberOfSources();
  211343. for (ItemCount i = 0; i < num; ++i)
  211344. {
  211345. MIDIEndpointRef source = MIDIGetSource (i);
  211346. if (source != 0)
  211347. {
  211348. String name (getConnectedEndpointName (source));
  211349. if (name.isEmpty())
  211350. name = "<error>";
  211351. s.add (name);
  211352. }
  211353. else
  211354. {
  211355. s.add ("<error>");
  211356. }
  211357. }
  211358. return s;
  211359. }
  211360. int MidiInput::getDefaultDeviceIndex()
  211361. {
  211362. return 0;
  211363. }
  211364. struct MidiPortAndCallback
  211365. {
  211366. MidiInput* input;
  211367. MidiPortAndEndpoint* portAndEndpoint;
  211368. MidiInputCallback* callback;
  211369. MemoryBlock pendingData;
  211370. int pendingBytes;
  211371. double pendingDataTime;
  211372. bool active;
  211373. };
  211374. static CriticalSection callbackLock;
  211375. static VoidArray activeCallbacks;
  211376. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  211377. {
  211378. if (*d == 0xf0)
  211379. {
  211380. mpc->pendingBytes = 0;
  211381. mpc->pendingDataTime = time;
  211382. }
  211383. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  211384. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  211385. uint8* dest = totalMessage + mpc->pendingBytes;
  211386. while (size > 0)
  211387. {
  211388. if (mpc->pendingBytes > 0 && *d >= 0x80)
  211389. {
  211390. if (*d >= 0xfa || *d == 0xf8)
  211391. {
  211392. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  211393. ++d;
  211394. --size;
  211395. }
  211396. else
  211397. {
  211398. if (*d == 0xf7)
  211399. {
  211400. *dest++ = *d++;
  211401. mpc->pendingBytes++;
  211402. --size;
  211403. }
  211404. break;
  211405. }
  211406. }
  211407. else
  211408. {
  211409. *dest++ = *d++;
  211410. mpc->pendingBytes++;
  211411. --size;
  211412. }
  211413. }
  211414. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  211415. {
  211416. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  211417. mpc->pendingBytes,
  211418. mpc->pendingDataTime));
  211419. mpc->pendingBytes = 0;
  211420. }
  211421. else
  211422. {
  211423. mpc->callback->handlePartialSysexMessage (mpc->input,
  211424. totalMessage,
  211425. mpc->pendingBytes,
  211426. mpc->pendingDataTime);
  211427. }
  211428. }
  211429. static void midiInputProc (const MIDIPacketList* pktlist,
  211430. void* readProcRefCon,
  211431. void* srcConnRefCon)
  211432. {
  211433. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211434. const double originalTime = time;
  211435. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211436. const ScopedLock sl (callbackLock);
  211437. if (activeCallbacks.contains (mpc) && mpc->active)
  211438. {
  211439. const MIDIPacket* packet = &pktlist->packet[0];
  211440. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211441. {
  211442. const uint8* d = (const uint8*) (packet->data);
  211443. int size = packet->length;
  211444. while (size > 0)
  211445. {
  211446. time = originalTime;
  211447. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211448. {
  211449. processSysex (mpc, d, size, time);
  211450. }
  211451. else
  211452. {
  211453. int used = 0;
  211454. const MidiMessage m (d, size, used, 0, time);
  211455. if (used <= 0)
  211456. {
  211457. jassertfalse // malformed midi message
  211458. break;
  211459. }
  211460. else
  211461. {
  211462. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211463. }
  211464. size -= used;
  211465. d += used;
  211466. }
  211467. }
  211468. packet = MIDIPacketNext (packet);
  211469. }
  211470. }
  211471. }
  211472. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211473. {
  211474. MidiInput* mi = 0;
  211475. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211476. {
  211477. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211478. if (endPoint != 0)
  211479. {
  211480. CFStringRef pname;
  211481. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211482. {
  211483. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211484. if (makeSureClientExists())
  211485. {
  211486. MIDIPortRef port;
  211487. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211488. mpc->active = false;
  211489. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211490. {
  211491. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211492. {
  211493. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211494. mpc->callback = callback;
  211495. mpc->pendingBytes = 0;
  211496. mpc->pendingData.ensureSize (128);
  211497. mi = new MidiInput (getDevices() [index]);
  211498. mpc->input = mi;
  211499. mi->internal = (void*) mpc;
  211500. const ScopedLock sl (callbackLock);
  211501. activeCallbacks.add (mpc.release());
  211502. }
  211503. else
  211504. {
  211505. OK (MIDIPortDispose (port));
  211506. }
  211507. }
  211508. }
  211509. }
  211510. CFRelease (pname);
  211511. }
  211512. }
  211513. return mi;
  211514. }
  211515. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211516. {
  211517. MidiInput* mi = 0;
  211518. if (makeSureClientExists())
  211519. {
  211520. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211521. mpc->active = false;
  211522. MIDIEndpointRef endPoint;
  211523. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211524. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211525. {
  211526. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211527. mpc->callback = callback;
  211528. mpc->pendingBytes = 0;
  211529. mpc->pendingData.ensureSize (128);
  211530. mi = new MidiInput (deviceName);
  211531. mpc->input = mi;
  211532. mi->internal = (void*) mpc;
  211533. const ScopedLock sl (callbackLock);
  211534. activeCallbacks.add (mpc.release());
  211535. }
  211536. CFRelease (name);
  211537. }
  211538. return mi;
  211539. }
  211540. MidiInput::MidiInput (const String& name_)
  211541. : name (name_)
  211542. {
  211543. }
  211544. MidiInput::~MidiInput()
  211545. {
  211546. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211547. mpc->active = false;
  211548. callbackLock.enter();
  211549. activeCallbacks.removeValue (mpc);
  211550. callbackLock.exit();
  211551. if (mpc->portAndEndpoint->port != 0)
  211552. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211553. delete mpc->portAndEndpoint;
  211554. delete mpc;
  211555. }
  211556. void MidiInput::start()
  211557. {
  211558. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211559. const ScopedLock sl (callbackLock);
  211560. mpc->active = true;
  211561. }
  211562. void MidiInput::stop()
  211563. {
  211564. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211565. const ScopedLock sl (callbackLock);
  211566. mpc->active = false;
  211567. }
  211568. #undef log
  211569. #else
  211570. MidiOutput::~MidiOutput()
  211571. {
  211572. }
  211573. void MidiOutput::reset()
  211574. {
  211575. }
  211576. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211577. {
  211578. return false;
  211579. }
  211580. void MidiOutput::setVolume (float leftVol, float rightVol)
  211581. {
  211582. }
  211583. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211584. {
  211585. }
  211586. const StringArray MidiOutput::getDevices()
  211587. {
  211588. return StringArray();
  211589. }
  211590. MidiOutput* MidiOutput::openDevice (int index)
  211591. {
  211592. return 0;
  211593. }
  211594. const StringArray MidiInput::getDevices()
  211595. {
  211596. return StringArray();
  211597. }
  211598. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211599. {
  211600. return 0;
  211601. }
  211602. #endif
  211603. #endif
  211604. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211605. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211606. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211607. // compiled on its own).
  211608. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  211609. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211610. class QTCameraDeviceInteral;
  211611. END_JUCE_NAMESPACE
  211612. @interface QTCaptureCallbackDelegate : NSObject
  211613. {
  211614. @public
  211615. CameraDevice* owner;
  211616. QTCameraDeviceInteral* internal;
  211617. Time* firstRecordedTime;
  211618. }
  211619. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211620. - (void) dealloc;
  211621. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211622. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211623. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211624. fromConnection: (QTCaptureConnection*) connection;
  211625. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211626. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211627. fromConnection: (QTCaptureConnection*) connection;
  211628. @end
  211629. BEGIN_JUCE_NAMESPACE
  211630. class QTCameraDeviceInteral
  211631. {
  211632. public:
  211633. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211634. {
  211635. const ScopedAutoReleasePool pool;
  211636. session = [[QTCaptureSession alloc] init];
  211637. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211638. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211639. input = 0;
  211640. audioInput = 0;
  211641. audioDevice = 0;
  211642. fileOutput = 0;
  211643. imageOutput = 0;
  211644. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211645. internalDev: this];
  211646. NSError* err = 0;
  211647. [device retain];
  211648. [device open: &err];
  211649. if (err == 0)
  211650. {
  211651. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211652. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211653. [session addInput: input error: &err];
  211654. if (err == 0)
  211655. {
  211656. resetFile();
  211657. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211658. [imageOutput setDelegate: callbackDelegate];
  211659. if (err == 0)
  211660. {
  211661. [session startRunning];
  211662. return;
  211663. }
  211664. }
  211665. }
  211666. openingError = nsStringToJuce ([err description]);
  211667. DBG (openingError);
  211668. }
  211669. ~QTCameraDeviceInteral()
  211670. {
  211671. [session stopRunning];
  211672. [session removeOutput: imageOutput];
  211673. [session release];
  211674. [input release];
  211675. [device release];
  211676. [audioDevice release];
  211677. [audioInput release];
  211678. [fileOutput release];
  211679. [imageOutput release];
  211680. [callbackDelegate release];
  211681. }
  211682. void resetFile()
  211683. {
  211684. [fileOutput recordToOutputFileURL: nil];
  211685. [session removeOutput: fileOutput];
  211686. [fileOutput release];
  211687. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211688. [session removeInput: audioInput];
  211689. [audioInput release];
  211690. audioInput = 0;
  211691. [audioDevice release];
  211692. audioDevice = 0;
  211693. [fileOutput setDelegate: callbackDelegate];
  211694. }
  211695. void addDefaultAudioInput()
  211696. {
  211697. NSError* err = nil;
  211698. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  211699. if ([audioDevice open: &err])
  211700. [audioDevice retain];
  211701. else
  211702. audioDevice = nil;
  211703. if (audioDevice != 0)
  211704. {
  211705. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  211706. [session addInput: audioInput error: &err];
  211707. }
  211708. }
  211709. void addListener (CameraImageListener* listenerToAdd)
  211710. {
  211711. const ScopedLock sl (listenerLock);
  211712. if (listeners.size() == 0)
  211713. [session addOutput: imageOutput error: nil];
  211714. listeners.addIfNotAlreadyThere (listenerToAdd);
  211715. }
  211716. void removeListener (CameraImageListener* listenerToRemove)
  211717. {
  211718. const ScopedLock sl (listenerLock);
  211719. listeners.removeValue (listenerToRemove);
  211720. if (listeners.size() == 0)
  211721. [session removeOutput: imageOutput];
  211722. }
  211723. void callListeners (CIImage* frame, int w, int h)
  211724. {
  211725. CoreGraphicsImage image (Image::ARGB, w, h, false);
  211726. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  211727. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  211728. CGContextFlush (image.context);
  211729. const ScopedLock sl (listenerLock);
  211730. for (int i = listeners.size(); --i >= 0;)
  211731. {
  211732. CameraImageListener* l = (CameraImageListener*) listeners[i];
  211733. if (l != 0)
  211734. l->imageReceived (image);
  211735. }
  211736. }
  211737. QTCaptureDevice* device;
  211738. QTCaptureDeviceInput* input;
  211739. QTCaptureDevice* audioDevice;
  211740. QTCaptureDeviceInput* audioInput;
  211741. QTCaptureSession* session;
  211742. QTCaptureMovieFileOutput* fileOutput;
  211743. QTCaptureDecompressedVideoOutput* imageOutput;
  211744. QTCaptureCallbackDelegate* callbackDelegate;
  211745. String openingError;
  211746. VoidArray listeners;
  211747. CriticalSection listenerLock;
  211748. };
  211749. END_JUCE_NAMESPACE
  211750. @implementation QTCaptureCallbackDelegate
  211751. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  211752. internalDev: (QTCameraDeviceInteral*) d
  211753. {
  211754. [super init];
  211755. owner = owner_;
  211756. internal = d;
  211757. firstRecordedTime = 0;
  211758. return self;
  211759. }
  211760. - (void) dealloc
  211761. {
  211762. delete firstRecordedTime;
  211763. [super dealloc];
  211764. }
  211765. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211766. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211767. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211768. fromConnection: (QTCaptureConnection*) connection
  211769. {
  211770. if (internal->listeners.size() > 0)
  211771. {
  211772. const ScopedAutoReleasePool pool;
  211773. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  211774. CVPixelBufferGetWidth (videoFrame),
  211775. CVPixelBufferGetHeight (videoFrame));
  211776. }
  211777. }
  211778. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211779. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211780. fromConnection: (QTCaptureConnection*) connection
  211781. {
  211782. if (firstRecordedTime == 0)
  211783. {
  211784. const Time now (Time::getCurrentTime());
  211785. firstRecordedTime = new Time (now - RelativeTime (0.1));
  211786. }
  211787. }
  211788. @end
  211789. BEGIN_JUCE_NAMESPACE
  211790. class QTCaptureViewerComp : public NSViewComponent
  211791. {
  211792. public:
  211793. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  211794. {
  211795. const ScopedAutoReleasePool pool;
  211796. captureView = [[QTCaptureView alloc] init];
  211797. [captureView setCaptureSession: internal->session];
  211798. setSize (640, 480); // xxx need to somehow get the movie size - how?
  211799. setView (captureView);
  211800. }
  211801. ~QTCaptureViewerComp()
  211802. {
  211803. setView (0);
  211804. [captureView setCaptureSession: nil];
  211805. [captureView release];
  211806. }
  211807. QTCaptureView* captureView;
  211808. };
  211809. CameraDevice::CameraDevice (const String& name_, int index)
  211810. : name (name_)
  211811. {
  211812. isRecording = false;
  211813. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  211814. internal = d;
  211815. }
  211816. CameraDevice::~CameraDevice()
  211817. {
  211818. stopRecording();
  211819. delete (QTCameraDeviceInteral*) internal;
  211820. internal = 0;
  211821. }
  211822. Component* CameraDevice::createViewerComponent()
  211823. {
  211824. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  211825. }
  211826. const String CameraDevice::getFileExtension()
  211827. {
  211828. return ".mov";
  211829. }
  211830. void CameraDevice::startRecordingToFile (const File& file)
  211831. {
  211832. stopRecording();
  211833. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211834. deleteAndZero (d->callbackDelegate->firstRecordedTime);
  211835. file.deleteFile();
  211836. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  211837. // out wrong, so we'll put some audio in there too..,
  211838. d->addDefaultAudioInput();
  211839. [d->session addOutput: d->fileOutput error: nil];
  211840. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  211841. for (;;)
  211842. {
  211843. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  211844. if (connection == 0)
  211845. break;
  211846. QTCompressionOptions* options = 0;
  211847. NSString* mediaType = [connection mediaType];
  211848. if ([mediaType isEqualToString: QTMediaTypeVideo])
  211849. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsSD480SizeH264Video"];
  211850. else if ([mediaType isEqualToString: QTMediaTypeSound])
  211851. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  211852. [d->fileOutput setCompressionOptions: options forConnection: connection];
  211853. }
  211854. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  211855. isRecording = true;
  211856. }
  211857. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  211858. {
  211859. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211860. if (d->callbackDelegate->firstRecordedTime != 0)
  211861. return *d->callbackDelegate->firstRecordedTime;
  211862. return Time();
  211863. }
  211864. void CameraDevice::stopRecording()
  211865. {
  211866. if (isRecording)
  211867. {
  211868. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211869. d->resetFile();
  211870. isRecording = false;
  211871. }
  211872. }
  211873. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  211874. {
  211875. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211876. if (listenerToAdd != 0)
  211877. d->addListener (listenerToAdd);
  211878. }
  211879. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  211880. {
  211881. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211882. if (listenerToRemove != 0)
  211883. d->removeListener (listenerToRemove);
  211884. }
  211885. const StringArray CameraDevice::getAvailableDevices()
  211886. {
  211887. const ScopedAutoReleasePool pool;
  211888. StringArray results;
  211889. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211890. for (int i = 0; i < (int) [devs count]; ++i)
  211891. {
  211892. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  211893. results.add (nsStringToJuce ([dev localizedDisplayName]));
  211894. }
  211895. return results;
  211896. }
  211897. CameraDevice* CameraDevice::openDevice (int index,
  211898. int minWidth, int minHeight,
  211899. int maxWidth, int maxHeight)
  211900. {
  211901. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  211902. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  211903. return d.release();
  211904. return 0;
  211905. }
  211906. #endif
  211907. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  211908. #endif
  211909. #endif
  211910. END_JUCE_NAMESPACE
  211911. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  211912. #endif
  211913. #endif